aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/bus/bcma.txt21
-rw-r--r--MAINTAINERS15
-rw-r--r--drivers/bcma/bcma_private.h1
-rw-r--r--drivers/bcma/driver_chipcommon.c2
-rw-r--r--drivers/bcma/driver_gpio.c4
-rw-r--r--drivers/bcma/driver_mips.c11
-rw-r--r--drivers/bcma/driver_pci_host.c4
-rw-r--r--drivers/bcma/main.c79
-rw-r--r--drivers/bcma/scan.c1
-rw-r--r--drivers/bluetooth/ath3k.c2
-rw-r--r--drivers/bluetooth/btusb.c10
-rw-r--r--drivers/bluetooth/hci_ath.c2
-rw-r--r--drivers/bluetooth/hci_h5.c25
-rw-r--r--drivers/net/ieee802154/Kconfig10
-rw-r--r--drivers/net/ieee802154/Makefile1
-rw-r--r--drivers/net/ieee802154/at86rf230.c445
-rw-r--r--drivers/net/ieee802154/cc2520.c71
-rw-r--r--drivers/net/ieee802154/fakehard.c427
-rw-r--r--drivers/net/ieee802154/fakelb.c91
-rw-r--r--drivers/net/ieee802154/mrf24j40.c104
-rw-r--r--drivers/net/wireless/ath/ath.h13
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.c92
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.h21
-rw-r--r--drivers/net/wireless/ath/ath10k/core.c141
-rw-r--r--drivers/net/wireless/ath/ath10k/core.h87
-rw-r--r--drivers/net/wireless/ath/ath10k/debug.c898
-rw-r--r--drivers/net/wireless/ath/ath10k/debug.h40
-rw-r--r--drivers/net/wireless/ath/ath10k/hif.h10
-rw-r--r--drivers/net/wireless/ath/ath10k/htt.h2
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_rx.c109
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_tx.c4
-rw-r--r--drivers/net/wireless/ath/ath10k/hw.h17
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.c544
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.h2
-rw-r--r--drivers/net/wireless/ath/ath10k/pci.c553
-rw-r--r--drivers/net/wireless/ath/ath10k/spectral.c34
-rw-r--r--drivers/net/wireless/ath/ath10k/spectral.h8
-rw-r--r--drivers/net/wireless/ath/ath10k/trace.h196
-rw-r--r--drivers/net/wireless/ath/ath10k/txrx.c4
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.c1126
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.h273
-rw-r--r--drivers/net/wireless/ath/ath6kl/cfg80211.c4
-rw-r--r--drivers/net/wireless/ath/ath6kl/common.h2
-rw-r--r--drivers/net/wireless/ath/ath6kl/debug.c28
-rw-r--r--drivers/net/wireless/ath/ath6kl/debug.h13
-rw-r--r--drivers/net/wireless/ath/ath6kl/usb.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/Kconfig5
-rw-r--r--drivers/net/wireless/ath/ath9k/Makefile9
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c7
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_calib.c42
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_phy.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c11
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_hw.c54
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c7
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_rtt.h36
-rw-r--r--drivers/net/wireless/ath/ath9k/ar953x_initvals.h498
-rw-r--r--drivers/net/wireless/ath/ath9k/ar955x_1p0_initvals.h8
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h144
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h26
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.h2
-rw-r--r--drivers/net/wireless/ath/ath9k/channel.c336
-rw-r--r--drivers/net/wireless/ath/ath9k/common-spectral.c (renamed from drivers/net/wireless/ath/ath9k/spectral.c)165
-rw-r--r--drivers/net/wireless/ath/ath9k/common-spectral.h (renamed from drivers/net/wireless/ath/ath9k/spectral.h)29
-rw-r--r--drivers/net/wireless/ath/ath9k/common.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/common.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c60
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_def.c31
-rw-r--r--drivers/net/wireless/ath/ath9k/gpio.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/htc.h5
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_debug.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_init.c25
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_main.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_txrx.c16
-rw-r--r--drivers/net/wireless/ath/ath9k/hw-ops.h7
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c98
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h33
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c64
-rw-r--r--drivers/net/wireless/ath/ath9k/link.c12
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c336
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/reg.h36
-rw-r--r--drivers/net/wireless/ath/ath9k/tx99.c4
-rw-r--r--drivers/net/wireless/ath/carl9170/phy.c4
-rw-r--r--drivers/net/wireless/ath/wil6210/cfg80211.c5
-rw-r--r--drivers/net/wireless/ath/wil6210/main.c95
-rw-r--r--drivers/net/wireless/ath/wil6210/netdev.c2
-rw-r--r--drivers/net/wireless/ath/wil6210/txrx.c7
-rw-r--r--drivers/net/wireless/ath/wil6210/txrx.h4
-rw-r--r--drivers/net/wireless/ath/wil6210/wil6210.h13
-rw-r--r--drivers/net/wireless/ath/wil6210/wmi.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/Makefile10
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcdc.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c51
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/btcoex.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bus.h (renamed from drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h)11
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c (renamed from drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c)85
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/cfg80211.h (renamed from drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h)9
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/chip.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/common.c168
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/commonring.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/core.c (renamed from drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c)8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/core.h (renamed from drivers/net/wireless/brcm80211/brcmfmac/dhd.h)7
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/debug.c (renamed from drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c)6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/debug.h (renamed from drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h)6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c400
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/feature.c11
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/firmware.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/flowring.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/fweh.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/fwil.c84
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/fwil_types.h89
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/of.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/p2p.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/pcie.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/proto.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/sdio.c (renamed from drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c)55
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/sdio.h (renamed from drivers/net/wireless/brcm80211/brcmfmac/sdio_host.h)8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/tracepoint.c15
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c142
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb_rdl.h75
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/vendor.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/debug.c166
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/main.c18
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c2
-rw-r--r--drivers/net/wireless/ipw2x00/libipw.h5
-rw-r--r--drivers/net/wireless/ipw2x00/libipw_module.c15
-rw-r--r--drivers/net/wireless/ipw2x00/libipw_rx.c21
-rw-r--r--drivers/net/wireless/iwlegacy/4965-mac.c2
-rw-r--r--drivers/net/wireless/iwlegacy/4965.h5
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig1
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/lib.c4
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/mac80211.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-8000.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-config.h12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-drv.c3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fw.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans.h4
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/coex.c13
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/coex_legacy.c14
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/constants.h5
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/d3.c318
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/debugfs.c201
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c5
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mac80211.c120
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mvm.h18
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/ops.c15
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/rs.c80
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/rs.h2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c35
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/sta.c2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/tt.c4
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/tx.c6
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/utils.c37
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c45
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c462
-rw-r--r--drivers/net/wireless/mac80211_hwsim.h25
-rw-r--r--drivers/net/wireless/mwifiex/11n.h4
-rw-r--r--drivers/net/wireless/mwifiex/cfg80211.c81
-rw-r--r--drivers/net/wireless/mwifiex/decl.h15
-rw-r--r--drivers/net/wireless/mwifiex/fw.h17
-rw-r--r--drivers/net/wireless/mwifiex/init.c19
-rw-r--r--drivers/net/wireless/mwifiex/join.c4
-rw-r--r--drivers/net/wireless/mwifiex/main.c55
-rw-r--r--drivers/net/wireless/mwifiex/main.h50
-rw-r--r--drivers/net/wireless/mwifiex/scan.c76
-rw-r--r--drivers/net/wireless/mwifiex/sdio.c2
-rw-r--r--drivers/net/wireless/mwifiex/sdio.h7
-rw-r--r--drivers/net/wireless/mwifiex/sta_cmdresp.c2
-rw-r--r--drivers/net/wireless/mwifiex/sta_event.c9
-rw-r--r--drivers/net/wireless/mwifiex/sta_ioctl.c4
-rw-r--r--drivers/net/wireless/mwifiex/sta_rx.c3
-rw-r--r--drivers/net/wireless/mwifiex/tdls.c288
-rw-r--r--drivers/net/wireless/mwifiex/txrx.c4
-rw-r--r--drivers/net/wireless/mwifiex/uap_cmd.c2
-rw-r--r--drivers/net/wireless/mwifiex/usb.c38
-rw-r--r--drivers/net/wireless/mwifiex/util.c38
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c10
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.h39
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8821ae/phy.c12
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.c13
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.h2
-rw-r--r--drivers/net/wireless/ti/wlcore/main.c23
-rw-r--r--drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c4
-rw-r--r--include/linux/ath9k_platform.h3
-rw-r--r--include/linux/bcma/bcma.h2
-rw-r--r--include/linux/bcma/bcma_driver_mips.h4
-rw-r--r--include/linux/ieee80211.h22
-rw-r--r--include/linux/ieee802154.h (renamed from include/net/ieee802154.h)61
-rw-r--r--include/linux/netdevice.h3
-rw-r--r--include/linux/nl802154.h4
-rw-r--r--include/net/6lowpan.h12
-rw-r--r--include/net/af_ieee802154.h4
-rw-r--r--include/net/bluetooth/hci.h27
-rw-r--r--include/net/bluetooth/hci_core.h45
-rw-r--r--include/net/bluetooth/l2cap.h15
-rw-r--r--include/net/bluetooth/mgmt.h12
-rw-r--r--include/net/cfg80211.h84
-rw-r--r--include/net/cfg802154.h161
-rw-r--r--include/net/ieee802154_netdev.h18
-rw-r--r--include/net/mac80211.h138
-rw-r--r--include/net/mac802154.h158
-rw-r--r--include/net/nl802154.h226
-rw-r--r--include/net/wpan-phy.h105
-rw-r--r--include/uapi/linux/nl80211.h32
-rw-r--r--net/6lowpan/iphc.c100
-rw-r--r--net/bluetooth/6lowpan.c300
-rw-r--r--net/bluetooth/Kconfig20
-rw-r--r--net/bluetooth/amp.c25
-rw-r--r--net/bluetooth/bnep/Kconfig2
-rw-r--r--net/bluetooth/cmtp/Kconfig2
-rw-r--r--net/bluetooth/hci_conn.c14
-rw-r--r--net/bluetooth/hci_core.c200
-rw-r--r--net/bluetooth/hci_event.c141
-rw-r--r--net/bluetooth/hci_sock.c2
-rw-r--r--net/bluetooth/hidp/Kconfig2
-rw-r--r--net/bluetooth/hidp/core.c10
-rw-r--r--net/bluetooth/l2cap_core.c42
-rw-r--r--net/bluetooth/l2cap_sock.c29
-rw-r--r--net/bluetooth/mgmt.c191
-rw-r--r--net/bluetooth/rfcomm/Kconfig2
-rw-r--r--net/bluetooth/rfcomm/core.c12
-rw-r--r--net/bluetooth/smp.c95
-rw-r--r--net/bluetooth/smp.h9
-rw-r--r--net/ieee802154/6lowpan_rtnl.c146
-rw-r--r--net/ieee802154/Makefile4
-rw-r--r--net/ieee802154/af802154.h4
-rw-r--r--net/ieee802154/af_ieee802154.c4
-rw-r--r--net/ieee802154/core.c321
-rw-r--r--net/ieee802154/core.h46
-rw-r--r--net/ieee802154/dgram.c6
-rw-r--r--net/ieee802154/header_ops.c3
-rw-r--r--net/ieee802154/ieee802154.h6
-rw-r--r--net/ieee802154/netlink.c6
-rw-r--r--net/ieee802154/nl-mac.c253
-rw-r--r--net/ieee802154/nl-phy.c29
-rw-r--r--net/ieee802154/nl802154.c957
-rw-r--r--net/ieee802154/nl802154.h7
-rw-r--r--net/ieee802154/nl_policy.c4
-rw-r--r--net/ieee802154/raw.c4
-rw-r--r--net/ieee802154/rdev-ops.h89
-rw-r--r--net/ieee802154/reassembly.c8
-rw-r--r--net/ieee802154/reassembly.h4
-rw-r--r--net/ieee802154/sysfs.c128
-rw-r--r--net/ieee802154/sysfs.h9
-rw-r--r--net/ieee802154/wpan-class.c230
-rw-r--r--net/mac80211/Kconfig18
-rw-r--r--net/mac80211/Makefile3
-rw-r--r--net/mac80211/agg-tx.c5
-rw-r--r--net/mac80211/cfg.c178
-rw-r--r--net/mac80211/chan.c5
-rw-r--r--net/mac80211/debug.h10
-rw-r--r--net/mac80211/debugfs_key.c12
-rw-r--r--net/mac80211/driver-ops.h74
-rw-r--r--net/mac80211/ieee80211_i.h80
-rw-r--r--net/mac80211/iface.c30
-rw-r--r--net/mac80211/key.c11
-rw-r--r--net/mac80211/main.c38
-rw-r--r--net/mac80211/mesh.h3
-rw-r--r--net/mac80211/mesh_pathtbl.c31
-rw-r--r--net/mac80211/mlme.c281
-rw-r--r--net/mac80211/ocb.c250
-rw-r--r--net/mac80211/rc80211_minstrel.c2
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c313
-rw-r--r--net/mac80211/rc80211_minstrel_ht.h40
-rw-r--r--net/mac80211/rc80211_minstrel_ht_debugfs.c43
-rw-r--r--net/mac80211/rx.c35
-rw-r--r--net/mac80211/sta_info.c4
-rw-r--r--net/mac80211/status.c3
-rw-r--r--net/mac80211/tdls.c8
-rw-r--r--net/mac80211/trace.h100
-rw-r--r--net/mac80211/tx.c15
-rw-r--r--net/mac80211/util.c132
-rw-r--r--net/mac80211/wep.c2
-rw-r--r--net/mac80211/wme.c33
-rw-r--r--net/mac80211/wme.h2
-rw-r--r--net/mac80211/wpa.c5
-rw-r--r--net/mac802154/Kconfig2
-rw-r--r--net/mac802154/Makefile4
-rw-r--r--net/mac802154/cfg.c210
-rw-r--r--net/mac802154/cfg.h9
-rw-r--r--net/mac802154/driver-ops.h222
-rw-r--r--net/mac802154/ieee802154_dev.c415
-rw-r--r--net/mac802154/ieee802154_i.h (renamed from net/mac802154/mac802154.h)132
-rw-r--r--net/mac802154/iface.c588
-rw-r--r--net/mac802154/llsec.c4
-rw-r--r--net/mac802154/mac_cmd.c88
-rw-r--r--net/mac802154/main.c217
-rw-r--r--net/mac802154/mib.c265
-rw-r--r--net/mac802154/monitor.c117
-rw-r--r--net/mac802154/rx.c311
-rw-r--r--net/mac802154/tx.c154
-rw-r--r--net/mac802154/util.c84
-rw-r--r--net/mac802154/wpan.c599
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/chan.c10
-rw-r--r--net/wireless/core.c77
-rw-r--r--net/wireless/core.h12
-rw-r--r--net/wireless/nl80211.c196
-rw-r--r--net/wireless/ocb.c88
-rw-r--r--net/wireless/rdev-ops.h55
-rw-r--r--net/wireless/sme.c13
-rw-r--r--net/wireless/trace.h97
-rw-r--r--net/wireless/util.c5
310 files changed, 14511 insertions, 7491 deletions
diff --git a/Documentation/devicetree/bindings/bus/bcma.txt b/Documentation/devicetree/bindings/bus/bcma.txt
index 62a48348ac15..edd44d802139 100644
--- a/Documentation/devicetree/bindings/bus/bcma.txt
+++ b/Documentation/devicetree/bindings/bus/bcma.txt
@@ -8,6 +8,11 @@ Required properties:
8 8
9The cores on the AXI bus are automatically detected by bcma with the 9The cores on the AXI bus are automatically detected by bcma with the
10memory ranges they are using and they get registered afterwards. 10memory ranges they are using and they get registered afterwards.
11Automatic detection of the IRQ number is not working on
12BCM47xx/BCM53xx ARM SoCs. To assign IRQ numbers to the cores, provide
13them manually through device tree. Use an interrupt-map to specify the
14IRQ used by the devices on the bus. The first address is just an index,
15because we do not have any special register.
11 16
12The top-level axi bus may contain children representing attached cores 17The top-level axi bus may contain children representing attached cores
13(devices). This is needed since some hardware details can't be auto 18(devices). This is needed since some hardware details can't be auto
@@ -22,6 +27,22 @@ Example:
22 ranges = <0x00000000 0x18000000 0x00100000>; 27 ranges = <0x00000000 0x18000000 0x00100000>;
23 #address-cells = <1>; 28 #address-cells = <1>;
24 #size-cells = <1>; 29 #size-cells = <1>;
30 #interrupt-cells = <1>;
31 interrupt-map-mask = <0x000fffff 0xffff>;
32 interrupt-map =
33 /* Ethernet Controller 0 */
34 <0x00024000 0 &gic GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
35
36 /* Ethernet Controller 1 */
37 <0x00025000 0 &gic GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
38
39 /* PCIe Controller 0 */
40 <0x00012000 0 &gic GIC_SPI 126 IRQ_TYPE_LEVEL_HIGH>,
41 <0x00012000 1 &gic GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>,
42 <0x00012000 2 &gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH>,
43 <0x00012000 3 &gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH>,
44 <0x00012000 4 &gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>,
45 <0x00012000 5 &gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
25 46
26 chipcommon { 47 chipcommon {
27 reg = <0x00000000 0x1000>; 48 reg = <0x00000000 0x1000>;
diff --git a/MAINTAINERS b/MAINTAINERS
index 43898b1a8a2d..7ec37a396ffe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2302,6 +2302,14 @@ F: security/capability.c
2302F: security/commoncap.c 2302F: security/commoncap.c
2303F: kernel/capability.c 2303F: kernel/capability.c
2304 2304
2305CC2520 IEEE-802.15.4 RADIO DRIVER
2306M: Varka Bhadram <varkabhadram@gmail.com>
2307L: linux-wpan@vger.kernel.org
2308S: Maintained
2309F: drivers/net/ieee802154/cc2520.c
2310F: include/linux/spi/cc2520.h
2311F: Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
2312
2305CELL BROADBAND ENGINE ARCHITECTURE 2313CELL BROADBAND ENGINE ARCHITECTURE
2306M: Arnd Bergmann <arnd@arndb.de> 2314M: Arnd Bergmann <arnd@arndb.de>
2307L: linuxppc-dev@lists.ozlabs.org 2315L: linuxppc-dev@lists.ozlabs.org
@@ -4689,6 +4697,13 @@ S: Maintained
4689F: net/ieee802154/ 4697F: net/ieee802154/
4690F: net/mac802154/ 4698F: net/mac802154/
4691F: drivers/net/ieee802154/ 4699F: drivers/net/ieee802154/
4700F: include/linux/nl802154.h
4701F: include/linux/ieee802154.h
4702F: include/net/nl802154.h
4703F: include/net/mac802154.h
4704F: include/net/af_ieee802154.h
4705F: include/net/cfg802154.h
4706F: include/net/ieee802154_netdev.h
4692F: Documentation/networking/ieee802154.txt 4707F: Documentation/networking/ieee802154.txt
4693 4708
4694IGUANAWORKS USB IR TRANSCEIVER 4709IGUANAWORKS USB IR TRANSCEIVER
diff --git a/drivers/bcma/bcma_private.h b/drivers/bcma/bcma_private.h
index b6412b2d748d..314ae4032f3e 100644
--- a/drivers/bcma/bcma_private.h
+++ b/drivers/bcma/bcma_private.h
@@ -24,6 +24,7 @@ struct bcma_bus;
24/* main.c */ 24/* main.c */
25bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value, 25bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
26 int timeout); 26 int timeout);
27void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core);
27int bcma_bus_register(struct bcma_bus *bus); 28int bcma_bus_register(struct bcma_bus *bus);
28void bcma_bus_unregister(struct bcma_bus *bus); 29void bcma_bus_unregister(struct bcma_bus *bus);
29int __init bcma_bus_early_register(struct bcma_bus *bus, 30int __init bcma_bus_early_register(struct bcma_bus *bus,
diff --git a/drivers/bcma/driver_chipcommon.c b/drivers/bcma/driver_chipcommon.c
index b068f98920a8..19f679667ca4 100644
--- a/drivers/bcma/driver_chipcommon.c
+++ b/drivers/bcma/driver_chipcommon.c
@@ -339,7 +339,7 @@ void bcma_chipco_serial_init(struct bcma_drv_cc *cc)
339 return; 339 return;
340 } 340 }
341 341
342 irq = bcma_core_irq(cc->core); 342 irq = bcma_core_irq(cc->core, 0);
343 343
344 /* Determine the registers of the UARTs */ 344 /* Determine the registers of the UARTs */
345 cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART); 345 cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
diff --git a/drivers/bcma/driver_gpio.c b/drivers/bcma/driver_gpio.c
index 706b9ae0dcfb..598a6cd9028a 100644
--- a/drivers/bcma/driver_gpio.c
+++ b/drivers/bcma/driver_gpio.c
@@ -152,7 +152,7 @@ static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
152 handle_simple_irq); 152 handle_simple_irq);
153 } 153 }
154 154
155 hwirq = bcma_core_irq(cc->core); 155 hwirq = bcma_core_irq(cc->core, 0);
156 err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio", 156 err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
157 cc); 157 cc);
158 if (err) 158 if (err)
@@ -183,7 +183,7 @@ static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
183 return; 183 return;
184 184
185 bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO); 185 bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO);
186 free_irq(bcma_core_irq(cc->core), cc); 186 free_irq(bcma_core_irq(cc->core, 0), cc);
187 for (gpio = 0; gpio < chip->ngpio; gpio++) { 187 for (gpio = 0; gpio < chip->ngpio; gpio++) {
188 int irq = irq_find_mapping(cc->irq_domain, gpio); 188 int irq = irq_find_mapping(cc->irq_domain, gpio);
189 189
diff --git a/drivers/bcma/driver_mips.c b/drivers/bcma/driver_mips.c
index 004d6aa671ce..5ec69c3d409d 100644
--- a/drivers/bcma/driver_mips.c
+++ b/drivers/bcma/driver_mips.c
@@ -115,7 +115,7 @@ static u32 bcma_core_mips_irqflag(struct bcma_device *dev)
115 * If disabled, 5 is returned. 115 * If disabled, 5 is returned.
116 * If not supported, 6 is returned. 116 * If not supported, 6 is returned.
117 */ 117 */
118static unsigned int bcma_core_mips_irq(struct bcma_device *dev) 118unsigned int bcma_core_mips_irq(struct bcma_device *dev)
119{ 119{
120 struct bcma_device *mdev = dev->bus->drv_mips.core; 120 struct bcma_device *mdev = dev->bus->drv_mips.core;
121 u32 irqflag; 121 u32 irqflag;
@@ -133,13 +133,6 @@ static unsigned int bcma_core_mips_irq(struct bcma_device *dev)
133 return 5; 133 return 5;
134} 134}
135 135
136unsigned int bcma_core_irq(struct bcma_device *dev)
137{
138 unsigned int mips_irq = bcma_core_mips_irq(dev);
139 return mips_irq <= 4 ? mips_irq + 2 : 0;
140}
141EXPORT_SYMBOL(bcma_core_irq);
142
143static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq) 136static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
144{ 137{
145 unsigned int oldirq = bcma_core_mips_irq(dev); 138 unsigned int oldirq = bcma_core_mips_irq(dev);
@@ -423,7 +416,7 @@ void bcma_core_mips_init(struct bcma_drv_mips *mcore)
423 break; 416 break;
424 default: 417 default:
425 list_for_each_entry(core, &bus->cores, list) { 418 list_for_each_entry(core, &bus->cores, list) {
426 core->irq = bcma_core_irq(core); 419 core->irq = bcma_core_irq(core, 0);
427 } 420 }
428 bcma_err(bus, 421 bcma_err(bus,
429 "Unknown device (0x%x) found, can not configure IRQs\n", 422 "Unknown device (0x%x) found, can not configure IRQs\n",
diff --git a/drivers/bcma/driver_pci_host.c b/drivers/bcma/driver_pci_host.c
index c3d7b03c2fdc..c8a6b741967b 100644
--- a/drivers/bcma/driver_pci_host.c
+++ b/drivers/bcma/driver_pci_host.c
@@ -593,7 +593,7 @@ int bcma_core_pci_plat_dev_init(struct pci_dev *dev)
593 pr_info("PCI: Fixing up device %s\n", pci_name(dev)); 593 pr_info("PCI: Fixing up device %s\n", pci_name(dev));
594 594
595 /* Fix up interrupt lines */ 595 /* Fix up interrupt lines */
596 dev->irq = bcma_core_irq(pc_host->pdev->core); 596 dev->irq = bcma_core_irq(pc_host->pdev->core, 0);
597 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq); 597 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
598 598
599 readrq = pcie_get_readrq(dev); 599 readrq = pcie_get_readrq(dev);
@@ -617,6 +617,6 @@ int bcma_core_pci_pcibios_map_irq(const struct pci_dev *dev)
617 617
618 pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host, 618 pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host,
619 pci_ops); 619 pci_ops);
620 return bcma_core_irq(pc_host->pdev->core); 620 return bcma_core_irq(pc_host->pdev->core, 0);
621} 621}
622EXPORT_SYMBOL(bcma_core_pci_pcibios_map_irq); 622EXPORT_SYMBOL(bcma_core_pci_pcibios_map_irq);
diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
index 1000955ce09d..534e1337766d 100644
--- a/drivers/bcma/main.c
+++ b/drivers/bcma/main.c
@@ -11,6 +11,7 @@
11#include <linux/bcma/bcma.h> 11#include <linux/bcma/bcma.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/of_address.h> 13#include <linux/of_address.h>
14#include <linux/of_irq.h>
14 15
15MODULE_DESCRIPTION("Broadcom's specific AMBA driver"); 16MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
16MODULE_LICENSE("GPL"); 17MODULE_LICENSE("GPL");
@@ -153,6 +154,46 @@ static struct device_node *bcma_of_find_child_device(struct platform_device *par
153 return NULL; 154 return NULL;
154} 155}
155 156
157static int bcma_of_irq_parse(struct platform_device *parent,
158 struct bcma_device *core,
159 struct of_phandle_args *out_irq, int num)
160{
161 __be32 laddr[1];
162 int rc;
163
164 if (core->dev.of_node) {
165 rc = of_irq_parse_one(core->dev.of_node, num, out_irq);
166 if (!rc)
167 return rc;
168 }
169
170 out_irq->np = parent->dev.of_node;
171 out_irq->args_count = 1;
172 out_irq->args[0] = num;
173
174 laddr[0] = cpu_to_be32(core->addr);
175 return of_irq_parse_raw(laddr, out_irq);
176}
177
178static unsigned int bcma_of_get_irq(struct platform_device *parent,
179 struct bcma_device *core, int num)
180{
181 struct of_phandle_args out_irq;
182 int ret;
183
184 if (!parent || !parent->dev.of_node)
185 return 0;
186
187 ret = bcma_of_irq_parse(parent, core, &out_irq, num);
188 if (ret) {
189 bcma_debug(core->bus, "bcma_of_get_irq() failed with rc=%d\n",
190 ret);
191 return 0;
192 }
193
194 return irq_create_of_mapping(&out_irq);
195}
196
156static void bcma_of_fill_device(struct platform_device *parent, 197static void bcma_of_fill_device(struct platform_device *parent,
157 struct bcma_device *core) 198 struct bcma_device *core)
158{ 199{
@@ -161,18 +202,47 @@ static void bcma_of_fill_device(struct platform_device *parent,
161 node = bcma_of_find_child_device(parent, core); 202 node = bcma_of_find_child_device(parent, core);
162 if (node) 203 if (node)
163 core->dev.of_node = node; 204 core->dev.of_node = node;
205
206 core->irq = bcma_of_get_irq(parent, core, 0);
164} 207}
165#else 208#else
166static void bcma_of_fill_device(struct platform_device *parent, 209static void bcma_of_fill_device(struct platform_device *parent,
167 struct bcma_device *core) 210 struct bcma_device *core)
168{ 211{
169} 212}
213static inline unsigned int bcma_of_get_irq(struct platform_device *parent,
214 struct bcma_device *core, int num)
215{
216 return 0;
217}
170#endif /* CONFIG_OF */ 218#endif /* CONFIG_OF */
171 219
172static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core) 220unsigned int bcma_core_irq(struct bcma_device *core, int num)
173{ 221{
174 int err; 222 struct bcma_bus *bus = core->bus;
223 unsigned int mips_irq;
224
225 switch (bus->hosttype) {
226 case BCMA_HOSTTYPE_PCI:
227 return bus->host_pci->irq;
228 case BCMA_HOSTTYPE_SOC:
229 if (bus->drv_mips.core && num == 0) {
230 mips_irq = bcma_core_mips_irq(core);
231 return mips_irq <= 4 ? mips_irq + 2 : 0;
232 }
233 if (bus->host_pdev)
234 return bcma_of_get_irq(bus->host_pdev, core, num);
235 return 0;
236 case BCMA_HOSTTYPE_SDIO:
237 return 0;
238 }
175 239
240 return 0;
241}
242EXPORT_SYMBOL(bcma_core_irq);
243
244void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core)
245{
176 core->dev.release = bcma_release_core_dev; 246 core->dev.release = bcma_release_core_dev;
177 core->dev.bus = &bcma_bus_type; 247 core->dev.bus = &bcma_bus_type;
178 dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index); 248 dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index);
@@ -196,6 +266,11 @@ static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
196 case BCMA_HOSTTYPE_SDIO: 266 case BCMA_HOSTTYPE_SDIO:
197 break; 267 break;
198 } 268 }
269}
270
271static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
272{
273 int err;
199 274
200 err = device_register(&core->dev); 275 err = device_register(&core->dev);
201 if (err) { 276 if (err) {
diff --git a/drivers/bcma/scan.c b/drivers/bcma/scan.c
index 14b56561a36f..917520776879 100644
--- a/drivers/bcma/scan.c
+++ b/drivers/bcma/scan.c
@@ -505,6 +505,7 @@ int bcma_bus_scan(struct bcma_bus *bus)
505 bus->nr_cores++; 505 bus->nr_cores++;
506 other_core = bcma_find_core_reverse(bus, core->id.id); 506 other_core = bcma_find_core_reverse(bus, core->id.id);
507 core->core_unit = (other_core == NULL) ? 0 : other_core->core_unit + 1; 507 core->core_unit = (other_core == NULL) ? 0 : other_core->core_unit + 1;
508 bcma_prepare_core(bus, core);
508 509
509 bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n", 510 bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
510 core->core_index, bcma_device_name(&core->id), 511 core->core_index, bcma_device_name(&core->id),
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index d85ced27ebd5..25c874da5f2b 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -79,6 +79,7 @@ static const struct usb_device_id ath3k_table[] = {
79 { USB_DEVICE(0x0489, 0xe057) }, 79 { USB_DEVICE(0x0489, 0xe057) },
80 { USB_DEVICE(0x0489, 0xe056) }, 80 { USB_DEVICE(0x0489, 0xe056) },
81 { USB_DEVICE(0x0489, 0xe05f) }, 81 { USB_DEVICE(0x0489, 0xe05f) },
82 { USB_DEVICE(0x0489, 0xe078) },
82 { USB_DEVICE(0x04c5, 0x1330) }, 83 { USB_DEVICE(0x04c5, 0x1330) },
83 { USB_DEVICE(0x04CA, 0x3004) }, 84 { USB_DEVICE(0x04CA, 0x3004) },
84 { USB_DEVICE(0x04CA, 0x3005) }, 85 { USB_DEVICE(0x04CA, 0x3005) },
@@ -130,6 +131,7 @@ static const struct usb_device_id ath3k_blist_tbl[] = {
130 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 }, 131 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
131 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, 132 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
132 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 }, 133 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
134 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
133 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 }, 135 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
134 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 }, 136 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
135 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, 137 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index edfc17bfcd44..7c13d7a8d83c 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -106,6 +106,8 @@ static const struct usb_device_id btusb_table[] = {
106 { USB_DEVICE(0x0b05, 0x17b5) }, 106 { USB_DEVICE(0x0b05, 0x17b5) },
107 { USB_DEVICE(0x0b05, 0x17cb) }, 107 { USB_DEVICE(0x0b05, 0x17cb) },
108 { USB_DEVICE(0x413c, 0x8197) }, 108 { USB_DEVICE(0x413c, 0x8197) },
109 { USB_DEVICE(0x13d3, 0x3404),
110 .driver_info = BTUSB_BCM_PATCHRAM },
109 111
110 /* Foxconn - Hon Hai */ 112 /* Foxconn - Hon Hai */
111 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) }, 113 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
@@ -156,6 +158,7 @@ static const struct usb_device_id blacklist_table[] = {
156 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 }, 158 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
157 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, 159 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
158 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 }, 160 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
161 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
159 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 }, 162 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
160 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 }, 163 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
161 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, 164 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
@@ -298,6 +301,8 @@ struct btusb_data {
298 unsigned int sco_num; 301 unsigned int sco_num;
299 int isoc_altsetting; 302 int isoc_altsetting;
300 int suspend_count; 303 int suspend_count;
304
305 int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
301}; 306};
302 307
303static inline void btusb_free_frags(struct btusb_data *data) 308static inline void btusb_free_frags(struct btusb_data *data)
@@ -589,7 +594,7 @@ static void btusb_bulk_complete(struct urb *urb)
589 if (urb->status == 0) { 594 if (urb->status == 0) {
590 hdev->stat.byte_rx += urb->actual_length; 595 hdev->stat.byte_rx += urb->actual_length;
591 596
592 if (btusb_recv_bulk(data, urb->transfer_buffer, 597 if (data->recv_bulk(data, urb->transfer_buffer,
593 urb->actual_length) < 0) { 598 urb->actual_length) < 0) {
594 BT_ERR("%s corrupted ACL packet", hdev->name); 599 BT_ERR("%s corrupted ACL packet", hdev->name);
595 hdev->stat.err_rx++; 600 hdev->stat.err_rx++;
@@ -2011,6 +2016,8 @@ static int btusb_probe(struct usb_interface *intf,
2011 init_usb_anchor(&data->isoc_anchor); 2016 init_usb_anchor(&data->isoc_anchor);
2012 spin_lock_init(&data->rxlock); 2017 spin_lock_init(&data->rxlock);
2013 2018
2019 data->recv_bulk = btusb_recv_bulk;
2020
2014 hdev = hci_alloc_dev(); 2021 hdev = hci_alloc_dev();
2015 if (!hdev) 2022 if (!hdev)
2016 return -ENOMEM; 2023 return -ENOMEM;
@@ -2034,6 +2041,7 @@ static int btusb_probe(struct usb_interface *intf,
2034 if (id->driver_info & BTUSB_BCM_PATCHRAM) { 2041 if (id->driver_info & BTUSB_BCM_PATCHRAM) {
2035 hdev->setup = btusb_setup_bcm_patchram; 2042 hdev->setup = btusb_setup_bcm_patchram;
2036 hdev->set_bdaddr = btusb_set_bdaddr_bcm; 2043 hdev->set_bdaddr = btusb_set_bdaddr_bcm;
2044 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
2037 } 2045 }
2038 2046
2039 if (id->driver_info & BTUSB_INTEL) { 2047 if (id->driver_info & BTUSB_INTEL) {
diff --git a/drivers/bluetooth/hci_ath.c b/drivers/bluetooth/hci_ath.c
index 0bc8a6a6a148..2ff6dfd2d3f0 100644
--- a/drivers/bluetooth/hci_ath.c
+++ b/drivers/bluetooth/hci_ath.c
@@ -74,7 +74,7 @@ static int ath_wakeup_ar3k(struct tty_struct *tty)
74 74
75 status = tty->driver->ops->tiocmget(tty); 75 status = tty->driver->ops->tiocmget(tty);
76 76
77 /* Disable Automatic RTSCTS */ 77 /* Enable Automatic RTSCTS */
78 ktermios.c_cflag |= CRTSCTS; 78 ktermios.c_cflag |= CRTSCTS;
79 status = tty_set_termios(tty, &ktermios); 79 status = tty_set_termios(tty, &ktermios);
80 80
diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index a22838669b4e..ec0fa7732c0d 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -168,6 +168,27 @@ wakeup:
168 hci_uart_tx_wakeup(hu); 168 hci_uart_tx_wakeup(hu);
169} 169}
170 170
171static void h5_peer_reset(struct hci_uart *hu)
172{
173 struct h5 *h5 = hu->priv;
174
175 BT_ERR("Peer device has reset");
176
177 h5->state = H5_UNINITIALIZED;
178
179 del_timer(&h5->timer);
180
181 skb_queue_purge(&h5->rel);
182 skb_queue_purge(&h5->unrel);
183 skb_queue_purge(&h5->unack);
184
185 h5->tx_seq = 0;
186 h5->tx_ack = 0;
187
188 /* Send reset request to upper stack */
189 hci_reset_dev(hu->hdev);
190}
191
171static int h5_open(struct hci_uart *hu) 192static int h5_open(struct hci_uart *hu)
172{ 193{
173 struct h5 *h5; 194 struct h5 *h5;
@@ -283,8 +304,12 @@ static void h5_handle_internal_rx(struct hci_uart *hu)
283 conf_req[2] = h5_cfg_field(h5); 304 conf_req[2] = h5_cfg_field(h5);
284 305
285 if (memcmp(data, sync_req, 2) == 0) { 306 if (memcmp(data, sync_req, 2) == 0) {
307 if (h5->state == H5_ACTIVE)
308 h5_peer_reset(hu);
286 h5_link_control(hu, sync_rsp, 2); 309 h5_link_control(hu, sync_rsp, 2);
287 } else if (memcmp(data, sync_rsp, 2) == 0) { 310 } else if (memcmp(data, sync_rsp, 2) == 0) {
311 if (h5->state == H5_ACTIVE)
312 h5_peer_reset(hu);
288 h5->state = H5_INITIALIZED; 313 h5->state = H5_INITIALIZED;
289 h5_link_control(hu, conf_req, 3); 314 h5_link_control(hu, conf_req, 3);
290 } else if (memcmp(data, conf_req, 2) == 0) { 315 } else if (memcmp(data, conf_req, 2) == 0) {
diff --git a/drivers/net/ieee802154/Kconfig b/drivers/net/ieee802154/Kconfig
index 391a916622a9..1a3c3e57aa0b 100644
--- a/drivers/net/ieee802154/Kconfig
+++ b/drivers/net/ieee802154/Kconfig
@@ -10,16 +10,6 @@ menuconfig IEEE802154_DRIVERS
10 If you say N, all options in this submenu will be skipped and 10 If you say N, all options in this submenu will be skipped and
11 disabled. 11 disabled.
12 12
13config IEEE802154_FAKEHARD
14 tristate "Fake LR-WPAN driver with several interconnected devices"
15 depends on IEEE802154_DRIVERS
16 ---help---
17 Say Y here to enable the fake driver that serves as an example
18 of HardMAC device driver.
19
20 This driver can also be built as a module. To do so say M here.
21 The module will be called 'fakehard'.
22
23config IEEE802154_FAKELB 13config IEEE802154_FAKELB
24 depends on IEEE802154_DRIVERS && MAC802154 14 depends on IEEE802154_DRIVERS && MAC802154
25 tristate "IEEE 802.15.4 loopback driver" 15 tristate "IEEE 802.15.4 loopback driver"
diff --git a/drivers/net/ieee802154/Makefile b/drivers/net/ieee802154/Makefile
index 655cb95e6e24..d77fa4d77e27 100644
--- a/drivers/net/ieee802154/Makefile
+++ b/drivers/net/ieee802154/Makefile
@@ -1,4 +1,3 @@
1obj-$(CONFIG_IEEE802154_FAKEHARD) += fakehard.o
2obj-$(CONFIG_IEEE802154_FAKELB) += fakelb.o 1obj-$(CONFIG_IEEE802154_FAKELB) += fakelb.o
3obj-$(CONFIG_IEEE802154_AT86RF230) += at86rf230.o 2obj-$(CONFIG_IEEE802154_AT86RF230) += at86rf230.o
4obj-$(CONFIG_IEEE802154_MRF24J40) += mrf24j40.o 3obj-$(CONFIG_IEEE802154_MRF24J40) += mrf24j40.o
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index c9d2a752abd7..1c0135620c62 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 16 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 17 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
@@ -33,10 +29,10 @@
33#include <linux/regmap.h> 29#include <linux/regmap.h>
34#include <linux/skbuff.h> 30#include <linux/skbuff.h>
35#include <linux/of_gpio.h> 31#include <linux/of_gpio.h>
32#include <linux/ieee802154.h>
36 33
37#include <net/ieee802154.h>
38#include <net/mac802154.h> 34#include <net/mac802154.h>
39#include <net/wpan-phy.h> 35#include <net/cfg802154.h>
40 36
41struct at86rf230_local; 37struct at86rf230_local;
42/* at86rf2xx chip depend data. 38/* at86rf2xx chip depend data.
@@ -50,15 +46,11 @@ struct at86rf2xx_chip_data {
50 u16 t_off_to_tx_on; 46 u16 t_off_to_tx_on;
51 u16 t_frame; 47 u16 t_frame;
52 u16 t_p_ack; 48 u16 t_p_ack;
53 /* short interframe spacing time */
54 u16 t_sifs;
55 /* long interframe spacing time */
56 u16 t_lifs;
57 /* completion timeout for tx in msecs */ 49 /* completion timeout for tx in msecs */
58 u16 t_tx_timeout; 50 u16 t_tx_timeout;
59 int rssi_base_val; 51 int rssi_base_val;
60 52
61 int (*set_channel)(struct at86rf230_local *, int, int); 53 int (*set_channel)(struct at86rf230_local *, u8, u8);
62 int (*get_desense_steps)(struct at86rf230_local *, s32); 54 int (*get_desense_steps)(struct at86rf230_local *, s32);
63}; 55};
64 56
@@ -74,12 +66,14 @@ struct at86rf230_state_change {
74 void (*complete)(void *context); 66 void (*complete)(void *context);
75 u8 from_state; 67 u8 from_state;
76 u8 to_state; 68 u8 to_state;
69
70 bool irq_enable;
77}; 71};
78 72
79struct at86rf230_local { 73struct at86rf230_local {
80 struct spi_device *spi; 74 struct spi_device *spi;
81 75
82 struct ieee802154_dev *dev; 76 struct ieee802154_hw *hw;
83 struct at86rf2xx_chip_data *data; 77 struct at86rf2xx_chip_data *data;
84 struct regmap *regmap; 78 struct regmap *regmap;
85 79
@@ -89,10 +83,10 @@ struct at86rf230_local {
89 struct at86rf230_state_change irq; 83 struct at86rf230_state_change irq;
90 84
91 bool tx_aret; 85 bool tx_aret;
86 s8 max_frame_retries;
92 bool is_tx; 87 bool is_tx;
93 /* spinlock for is_tx protection */ 88 /* spinlock for is_tx protection */
94 spinlock_t lock; 89 spinlock_t lock;
95 struct completion tx_complete;
96 struct sk_buff *tx_skb; 90 struct sk_buff *tx_skb;
97 struct at86rf230_state_change tx; 91 struct at86rf230_state_change tx;
98}; 92};
@@ -291,10 +285,11 @@ struct at86rf230_local {
291 285
292#define AT86RF2XX_NUMREGS 0x3F 286#define AT86RF2XX_NUMREGS 0x3F
293 287
294static int 288static void
295at86rf230_async_state_change(struct at86rf230_local *lp, 289at86rf230_async_state_change(struct at86rf230_local *lp,
296 struct at86rf230_state_change *ctx, 290 struct at86rf230_state_change *ctx,
297 const u8 state, void (*complete)(void *context)); 291 const u8 state, void (*complete)(void *context),
292 const bool irq_enable);
298 293
299static inline int 294static inline int
300__at86rf230_write(struct at86rf230_local *lp, 295__at86rf230_write(struct at86rf230_local *lp,
@@ -451,7 +446,8 @@ at86rf230_async_error_recover(void *context)
451 struct at86rf230_state_change *ctx = context; 446 struct at86rf230_state_change *ctx = context;
452 struct at86rf230_local *lp = ctx->lp; 447 struct at86rf230_local *lp = ctx->lp;
453 448
454 at86rf230_async_state_change(lp, ctx, STATE_RX_AACK_ON, NULL); 449 at86rf230_async_state_change(lp, ctx, STATE_RX_AACK_ON, NULL, false);
450 ieee802154_wake_queue(lp->hw);
455} 451}
456 452
457static void 453static void
@@ -461,21 +457,31 @@ at86rf230_async_error(struct at86rf230_local *lp,
461 dev_err(&lp->spi->dev, "spi_async error %d\n", rc); 457 dev_err(&lp->spi->dev, "spi_async error %d\n", rc);
462 458
463 at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF, 459 at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF,
464 at86rf230_async_error_recover); 460 at86rf230_async_error_recover, false);
465} 461}
466 462
467/* Generic function to get some register value in async mode */ 463/* Generic function to get some register value in async mode */
468static int 464static void
469at86rf230_async_read_reg(struct at86rf230_local *lp, const u8 reg, 465at86rf230_async_read_reg(struct at86rf230_local *lp, const u8 reg,
470 struct at86rf230_state_change *ctx, 466 struct at86rf230_state_change *ctx,
471 void (*complete)(void *context)) 467 void (*complete)(void *context),
468 const bool irq_enable)
472{ 469{
470 int rc;
471
473 u8 *tx_buf = ctx->buf; 472 u8 *tx_buf = ctx->buf;
474 473
475 tx_buf[0] = (reg & CMD_REG_MASK) | CMD_REG; 474 tx_buf[0] = (reg & CMD_REG_MASK) | CMD_REG;
476 ctx->trx.len = 2; 475 ctx->trx.len = 2;
477 ctx->msg.complete = complete; 476 ctx->msg.complete = complete;
478 return spi_async(lp->spi, &ctx->msg); 477 ctx->irq_enable = irq_enable;
478 rc = spi_async(lp->spi, &ctx->msg);
479 if (rc) {
480 if (irq_enable)
481 enable_irq(lp->spi->irq);
482
483 at86rf230_async_error(lp, ctx, rc);
484 }
479} 485}
480 486
481static void 487static void
@@ -512,7 +518,8 @@ at86rf230_async_state_assert(void *context)
512 if (ctx->to_state == STATE_TX_ON) { 518 if (ctx->to_state == STATE_TX_ON) {
513 at86rf230_async_state_change(lp, ctx, 519 at86rf230_async_state_change(lp, ctx,
514 STATE_FORCE_TX_ON, 520 STATE_FORCE_TX_ON,
515 ctx->complete); 521 ctx->complete,
522 ctx->irq_enable);
516 return; 523 return;
517 } 524 }
518 } 525 }
@@ -535,7 +542,6 @@ at86rf230_async_state_delay(void *context)
535 struct at86rf230_local *lp = ctx->lp; 542 struct at86rf230_local *lp = ctx->lp;
536 struct at86rf2xx_chip_data *c = lp->data; 543 struct at86rf2xx_chip_data *c = lp->data;
537 bool force = false; 544 bool force = false;
538 int rc;
539 545
540 /* The force state changes are will show as normal states in the 546 /* The force state changes are will show as normal states in the
541 * state status subregister. We change the to_state to the 547 * state status subregister. We change the to_state to the
@@ -604,10 +610,9 @@ at86rf230_async_state_delay(void *context)
604 udelay(1); 610 udelay(1);
605 611
606change: 612change:
607 rc = at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx, 613 at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx,
608 at86rf230_async_state_assert); 614 at86rf230_async_state_assert,
609 if (rc) 615 ctx->irq_enable);
610 dev_err(&lp->spi->dev, "spi_async error %d\n", rc);
611} 616}
612 617
613static void 618static void
@@ -622,10 +627,9 @@ at86rf230_async_state_change_start(void *context)
622 /* Check for "possible" STATE_TRANSITION_IN_PROGRESS */ 627 /* Check for "possible" STATE_TRANSITION_IN_PROGRESS */
623 if (trx_state == STATE_TRANSITION_IN_PROGRESS) { 628 if (trx_state == STATE_TRANSITION_IN_PROGRESS) {
624 udelay(1); 629 udelay(1);
625 rc = at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx, 630 at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx,
626 at86rf230_async_state_change_start); 631 at86rf230_async_state_change_start,
627 if (rc) 632 ctx->irq_enable);
628 dev_err(&lp->spi->dev, "spi_async error %d\n", rc);
629 return; 633 return;
630 } 634 }
631 635
@@ -647,20 +651,27 @@ at86rf230_async_state_change_start(void *context)
647 ctx->trx.len = 2; 651 ctx->trx.len = 2;
648 ctx->msg.complete = at86rf230_async_state_delay; 652 ctx->msg.complete = at86rf230_async_state_delay;
649 rc = spi_async(lp->spi, &ctx->msg); 653 rc = spi_async(lp->spi, &ctx->msg);
650 if (rc) 654 if (rc) {
651 dev_err(&lp->spi->dev, "spi_async error %d\n", rc); 655 if (ctx->irq_enable)
656 enable_irq(lp->spi->irq);
657
658 at86rf230_async_error(lp, &lp->state, rc);
659 }
652} 660}
653 661
654static int 662static void
655at86rf230_async_state_change(struct at86rf230_local *lp, 663at86rf230_async_state_change(struct at86rf230_local *lp,
656 struct at86rf230_state_change *ctx, 664 struct at86rf230_state_change *ctx,
657 const u8 state, void (*complete)(void *context)) 665 const u8 state, void (*complete)(void *context),
666 const bool irq_enable)
658{ 667{
659 /* Initialization for the state change context */ 668 /* Initialization for the state change context */
660 ctx->to_state = state; 669 ctx->to_state = state;
661 ctx->complete = complete; 670 ctx->complete = complete;
662 return at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx, 671 ctx->irq_enable = irq_enable;
663 at86rf230_async_state_change_start); 672 at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx,
673 at86rf230_async_state_change_start,
674 irq_enable);
664} 675}
665 676
666static void 677static void
@@ -681,17 +692,16 @@ at86rf230_sync_state_change(struct at86rf230_local *lp, unsigned int state)
681{ 692{
682 int rc; 693 int rc;
683 694
684 rc = at86rf230_async_state_change(lp, &lp->state, state, 695 at86rf230_async_state_change(lp, &lp->state, state,
685 at86rf230_sync_state_change_complete); 696 at86rf230_sync_state_change_complete,
686 if (rc) { 697 false);
687 at86rf230_async_error(lp, &lp->state, rc);
688 return rc;
689 }
690 698
691 rc = wait_for_completion_timeout(&lp->state_complete, 699 rc = wait_for_completion_timeout(&lp->state_complete,
692 msecs_to_jiffies(100)); 700 msecs_to_jiffies(100));
693 if (!rc) 701 if (!rc) {
702 at86rf230_async_error(lp, &lp->state, -ETIMEDOUT);
694 return -ETIMEDOUT; 703 return -ETIMEDOUT;
704 }
695 705
696 return 0; 706 return 0;
697} 707}
@@ -701,8 +711,14 @@ at86rf230_tx_complete(void *context)
701{ 711{
702 struct at86rf230_state_change *ctx = context; 712 struct at86rf230_state_change *ctx = context;
703 struct at86rf230_local *lp = ctx->lp; 713 struct at86rf230_local *lp = ctx->lp;
714 struct sk_buff *skb = lp->tx_skb;
715
716 enable_irq(lp->spi->irq);
704 717
705 complete(&lp->tx_complete); 718 if (lp->max_frame_retries <= 0)
719 ieee802154_xmit_complete(lp->hw, skb, true);
720 else
721 ieee802154_xmit_complete(lp->hw, skb, false);
706} 722}
707 723
708static void 724static void
@@ -710,12 +726,9 @@ at86rf230_tx_on(void *context)
710{ 726{
711 struct at86rf230_state_change *ctx = context; 727 struct at86rf230_state_change *ctx = context;
712 struct at86rf230_local *lp = ctx->lp; 728 struct at86rf230_local *lp = ctx->lp;
713 int rc;
714 729
715 rc = at86rf230_async_state_change(lp, &lp->irq, STATE_RX_AACK_ON, 730 at86rf230_async_state_change(lp, &lp->irq, STATE_RX_AACK_ON,
716 at86rf230_tx_complete); 731 at86rf230_tx_complete, true);
717 if (rc)
718 at86rf230_async_error(lp, ctx, rc);
719} 732}
720 733
721static void 734static void
@@ -723,12 +736,9 @@ at86rf230_tx_trac_error(void *context)
723{ 736{
724 struct at86rf230_state_change *ctx = context; 737 struct at86rf230_state_change *ctx = context;
725 struct at86rf230_local *lp = ctx->lp; 738 struct at86rf230_local *lp = ctx->lp;
726 int rc;
727 739
728 rc = at86rf230_async_state_change(lp, ctx, STATE_TX_ON, 740 at86rf230_async_state_change(lp, ctx, STATE_TX_ON,
729 at86rf230_tx_on); 741 at86rf230_tx_on, true);
730 if (rc)
731 at86rf230_async_error(lp, ctx, rc);
732} 742}
733 743
734static void 744static void
@@ -738,17 +748,14 @@ at86rf230_tx_trac_check(void *context)
738 struct at86rf230_local *lp = ctx->lp; 748 struct at86rf230_local *lp = ctx->lp;
739 const u8 *buf = ctx->buf; 749 const u8 *buf = ctx->buf;
740 const u8 trac = (buf[1] & 0xe0) >> 5; 750 const u8 trac = (buf[1] & 0xe0) >> 5;
741 int rc;
742 751
743 /* If trac status is different than zero we need to do a state change 752 /* If trac status is different than zero we need to do a state change
744 * to STATE_FORCE_TRX_OFF then STATE_TX_ON to recover the transceiver 753 * to STATE_FORCE_TRX_OFF then STATE_TX_ON to recover the transceiver
745 * state to TX_ON. 754 * state to TX_ON.
746 */ 755 */
747 if (trac) { 756 if (trac) {
748 rc = at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF, 757 at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF,
749 at86rf230_tx_trac_error); 758 at86rf230_tx_trac_error, true);
750 if (rc)
751 at86rf230_async_error(lp, ctx, rc);
752 return; 759 return;
753 } 760 }
754 761
@@ -761,51 +768,29 @@ at86rf230_tx_trac_status(void *context)
761{ 768{
762 struct at86rf230_state_change *ctx = context; 769 struct at86rf230_state_change *ctx = context;
763 struct at86rf230_local *lp = ctx->lp; 770 struct at86rf230_local *lp = ctx->lp;
764 int rc;
765 771
766 rc = at86rf230_async_read_reg(lp, RG_TRX_STATE, ctx, 772 at86rf230_async_read_reg(lp, RG_TRX_STATE, ctx,
767 at86rf230_tx_trac_check); 773 at86rf230_tx_trac_check, true);
768 if (rc)
769 at86rf230_async_error(lp, ctx, rc);
770} 774}
771 775
772static void 776static void
773at86rf230_rx(struct at86rf230_local *lp, 777at86rf230_rx(struct at86rf230_local *lp,
774 const u8 *data, u8 len) 778 const u8 *data, const u8 len, const u8 lqi)
775{ 779{
776 u8 lqi;
777 struct sk_buff *skb; 780 struct sk_buff *skb;
778 u8 rx_local_buf[AT86RF2XX_MAX_BUF]; 781 u8 rx_local_buf[AT86RF2XX_MAX_BUF];
779 782
780 if (len < 2)
781 return;
782
783 /* read full frame buffer and invalid lqi value to lowest
784 * indicator if frame was is in a corrupted state.
785 */
786 if (len > IEEE802154_MTU) {
787 lqi = 0;
788 len = IEEE802154_MTU;
789 dev_vdbg(&lp->spi->dev, "corrupted frame received\n");
790 } else {
791 lqi = data[len];
792 }
793
794 memcpy(rx_local_buf, data, len); 783 memcpy(rx_local_buf, data, len);
795 enable_irq(lp->spi->irq); 784 enable_irq(lp->spi->irq);
796 785
797 skb = alloc_skb(IEEE802154_MTU, GFP_ATOMIC); 786 skb = dev_alloc_skb(IEEE802154_MTU);
798 if (!skb) { 787 if (!skb) {
799 dev_vdbg(&lp->spi->dev, "failed to allocate sk_buff\n"); 788 dev_vdbg(&lp->spi->dev, "failed to allocate sk_buff\n");
800 return; 789 return;
801 } 790 }
802 791
803 memcpy(skb_put(skb, len), rx_local_buf, len); 792 memcpy(skb_put(skb, len), rx_local_buf, len);
804 793 ieee802154_rx_irqsafe(lp->hw, skb, lqi);
805 /* We do not put CRC into the frame */
806 skb_trim(skb, len - 2);
807
808 ieee802154_rx_irqsafe(lp->dev, skb, lqi);
809} 794}
810 795
811static void 796static void
@@ -814,20 +799,31 @@ at86rf230_rx_read_frame_complete(void *context)
814 struct at86rf230_state_change *ctx = context; 799 struct at86rf230_state_change *ctx = context;
815 struct at86rf230_local *lp = ctx->lp; 800 struct at86rf230_local *lp = ctx->lp;
816 const u8 *buf = lp->irq.buf; 801 const u8 *buf = lp->irq.buf;
817 const u8 len = buf[1]; 802 u8 len = buf[1];
803
804 if (!ieee802154_is_valid_psdu_len(len)) {
805 dev_vdbg(&lp->spi->dev, "corrupted frame received\n");
806 len = IEEE802154_MTU;
807 }
818 808
819 at86rf230_rx(lp, buf + 2, len); 809 at86rf230_rx(lp, buf + 2, len, buf[2 + len]);
820} 810}
821 811
822static int 812static void
823at86rf230_rx_read_frame(struct at86rf230_local *lp) 813at86rf230_rx_read_frame(struct at86rf230_local *lp)
824{ 814{
815 int rc;
816
825 u8 *buf = lp->irq.buf; 817 u8 *buf = lp->irq.buf;
826 818
827 buf[0] = CMD_FB; 819 buf[0] = CMD_FB;
828 lp->irq.trx.len = AT86RF2XX_MAX_BUF; 820 lp->irq.trx.len = AT86RF2XX_MAX_BUF;
829 lp->irq.msg.complete = at86rf230_rx_read_frame_complete; 821 lp->irq.msg.complete = at86rf230_rx_read_frame_complete;
830 return spi_async(lp->spi, &lp->irq.msg); 822 rc = spi_async(lp->spi, &lp->irq.msg);
823 if (rc) {
824 enable_irq(lp->spi->irq);
825 at86rf230_async_error(lp, &lp->irq, rc);
826 }
831} 827}
832 828
833static void 829static void
@@ -835,7 +831,6 @@ at86rf230_rx_trac_check(void *context)
835{ 831{
836 struct at86rf230_state_change *ctx = context; 832 struct at86rf230_state_change *ctx = context;
837 struct at86rf230_local *lp = ctx->lp; 833 struct at86rf230_local *lp = ctx->lp;
838 int rc;
839 834
840 /* Possible check on trac status here. This could be useful to make 835 /* Possible check on trac status here. This could be useful to make
841 * some stats why receive is failed. Not used at the moment, but it's 836 * some stats why receive is failed. Not used at the moment, but it's
@@ -843,34 +838,31 @@ at86rf230_rx_trac_check(void *context)
843 * The programming guide say do it so. 838 * The programming guide say do it so.
844 */ 839 */
845 840
846 rc = at86rf230_rx_read_frame(lp); 841 at86rf230_rx_read_frame(lp);
847 if (rc) {
848 enable_irq(lp->spi->irq);
849 at86rf230_async_error(lp, ctx, rc);
850 }
851} 842}
852 843
853static int 844static void
854at86rf230_irq_trx_end(struct at86rf230_local *lp) 845at86rf230_irq_trx_end(struct at86rf230_local *lp)
855{ 846{
856 spin_lock(&lp->lock); 847 spin_lock(&lp->lock);
857 if (lp->is_tx) { 848 if (lp->is_tx) {
858 lp->is_tx = 0; 849 lp->is_tx = 0;
859 spin_unlock(&lp->lock); 850 spin_unlock(&lp->lock);
860 enable_irq(lp->spi->irq);
861 851
862 if (lp->tx_aret) 852 if (lp->tx_aret)
863 return at86rf230_async_state_change(lp, &lp->irq, 853 at86rf230_async_state_change(lp, &lp->irq,
864 STATE_FORCE_TX_ON, 854 STATE_FORCE_TX_ON,
865 at86rf230_tx_trac_status); 855 at86rf230_tx_trac_status,
856 true);
866 else 857 else
867 return at86rf230_async_state_change(lp, &lp->irq, 858 at86rf230_async_state_change(lp, &lp->irq,
868 STATE_RX_AACK_ON, 859 STATE_RX_AACK_ON,
869 at86rf230_tx_complete); 860 at86rf230_tx_complete,
861 true);
870 } else { 862 } else {
871 spin_unlock(&lp->lock); 863 spin_unlock(&lp->lock);
872 return at86rf230_async_read_reg(lp, RG_TRX_STATE, &lp->irq, 864 at86rf230_async_read_reg(lp, RG_TRX_STATE, &lp->irq,
873 at86rf230_rx_trac_check); 865 at86rf230_rx_trac_check, true);
874 } 866 }
875} 867}
876 868
@@ -881,12 +873,9 @@ at86rf230_irq_status(void *context)
881 struct at86rf230_local *lp = ctx->lp; 873 struct at86rf230_local *lp = ctx->lp;
882 const u8 *buf = lp->irq.buf; 874 const u8 *buf = lp->irq.buf;
883 const u8 irq = buf[1]; 875 const u8 irq = buf[1];
884 int rc;
885 876
886 if (irq & IRQ_TRX_END) { 877 if (irq & IRQ_TRX_END) {
887 rc = at86rf230_irq_trx_end(lp); 878 at86rf230_irq_trx_end(lp);
888 if (rc)
889 at86rf230_async_error(lp, ctx, rc);
890 } else { 879 } else {
891 enable_irq(lp->spi->irq); 880 enable_irq(lp->spi->irq);
892 dev_err(&lp->spi->dev, "not supported irq %02x received\n", 881 dev_err(&lp->spi->dev, "not supported irq %02x received\n",
@@ -901,13 +890,14 @@ static irqreturn_t at86rf230_isr(int irq, void *data)
901 u8 *buf = ctx->buf; 890 u8 *buf = ctx->buf;
902 int rc; 891 int rc;
903 892
904 disable_irq_nosync(lp->spi->irq); 893 disable_irq_nosync(irq);
905 894
906 buf[0] = (RG_IRQ_STATUS & CMD_REG_MASK) | CMD_REG; 895 buf[0] = (RG_IRQ_STATUS & CMD_REG_MASK) | CMD_REG;
907 ctx->trx.len = 2; 896 ctx->trx.len = 2;
908 ctx->msg.complete = at86rf230_irq_status; 897 ctx->msg.complete = at86rf230_irq_status;
909 rc = spi_async(lp->spi, &ctx->msg); 898 rc = spi_async(lp->spi, &ctx->msg);
910 if (rc) { 899 if (rc) {
900 enable_irq(irq);
911 at86rf230_async_error(lp, ctx, rc); 901 at86rf230_async_error(lp, ctx, rc);
912 return IRQ_NONE; 902 return IRQ_NONE;
913 } 903 }
@@ -960,22 +950,18 @@ at86rf230_xmit_tx_on(void *context)
960{ 950{
961 struct at86rf230_state_change *ctx = context; 951 struct at86rf230_state_change *ctx = context;
962 struct at86rf230_local *lp = ctx->lp; 952 struct at86rf230_local *lp = ctx->lp;
963 int rc;
964 953
965 rc = at86rf230_async_state_change(lp, ctx, STATE_TX_ARET_ON, 954 at86rf230_async_state_change(lp, ctx, STATE_TX_ARET_ON,
966 at86rf230_write_frame); 955 at86rf230_write_frame, false);
967 if (rc)
968 at86rf230_async_error(lp, ctx, rc);
969} 956}
970 957
971static int 958static int
972at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb) 959at86rf230_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)
973{ 960{
974 struct at86rf230_local *lp = dev->priv; 961 struct at86rf230_local *lp = hw->priv;
975 struct at86rf230_state_change *ctx = &lp->tx; 962 struct at86rf230_state_change *ctx = &lp->tx;
976 963
977 void (*tx_complete)(void *context) = at86rf230_write_frame; 964 void (*tx_complete)(void *context) = at86rf230_write_frame;
978 int rc;
979 965
980 lp->tx_skb = skb; 966 lp->tx_skb = skb;
981 967
@@ -986,61 +972,39 @@ at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
986 if (lp->tx_aret) 972 if (lp->tx_aret)
987 tx_complete = at86rf230_xmit_tx_on; 973 tx_complete = at86rf230_xmit_tx_on;
988 974
989 rc = at86rf230_async_state_change(lp, ctx, STATE_TX_ON, 975 at86rf230_async_state_change(lp, ctx, STATE_TX_ON, tx_complete, false);
990 tx_complete);
991 if (rc) {
992 at86rf230_async_error(lp, ctx, rc);
993 return rc;
994 }
995 rc = wait_for_completion_interruptible_timeout(&lp->tx_complete,
996 msecs_to_jiffies(lp->data->t_tx_timeout));
997 if (!rc) {
998 at86rf230_async_error(lp, ctx, rc);
999 return -ETIMEDOUT;
1000 }
1001
1002 /* Interfame spacing time, which is phy depend.
1003 * TODO
1004 * Move this handling in MAC 802.15.4 layer.
1005 * This is currently a workaround to avoid fragmenation issues.
1006 */
1007 if (skb->len > 18)
1008 usleep_range(lp->data->t_lifs, lp->data->t_lifs + 10);
1009 else
1010 usleep_range(lp->data->t_sifs, lp->data->t_sifs + 10);
1011 976
1012 return 0; 977 return 0;
1013} 978}
1014 979
1015static int 980static int
1016at86rf230_ed(struct ieee802154_dev *dev, u8 *level) 981at86rf230_ed(struct ieee802154_hw *hw, u8 *level)
1017{ 982{
1018 might_sleep();
1019 BUG_ON(!level); 983 BUG_ON(!level);
1020 *level = 0xbe; 984 *level = 0xbe;
1021 return 0; 985 return 0;
1022} 986}
1023 987
1024static int 988static int
1025at86rf230_start(struct ieee802154_dev *dev) 989at86rf230_start(struct ieee802154_hw *hw)
1026{ 990{
1027 return at86rf230_sync_state_change(dev->priv, STATE_RX_AACK_ON); 991 return at86rf230_sync_state_change(hw->priv, STATE_RX_AACK_ON);
1028} 992}
1029 993
1030static void 994static void
1031at86rf230_stop(struct ieee802154_dev *dev) 995at86rf230_stop(struct ieee802154_hw *hw)
1032{ 996{
1033 at86rf230_sync_state_change(dev->priv, STATE_FORCE_TRX_OFF); 997 at86rf230_sync_state_change(hw->priv, STATE_FORCE_TRX_OFF);
1034} 998}
1035 999
1036static int 1000static int
1037at86rf23x_set_channel(struct at86rf230_local *lp, int page, int channel) 1001at86rf23x_set_channel(struct at86rf230_local *lp, u8 page, u8 channel)
1038{ 1002{
1039 return at86rf230_write_subreg(lp, SR_CHANNEL, channel); 1003 return at86rf230_write_subreg(lp, SR_CHANNEL, channel);
1040} 1004}
1041 1005
1042static int 1006static int
1043at86rf212_set_channel(struct at86rf230_local *lp, int page, int channel) 1007at86rf212_set_channel(struct at86rf230_local *lp, u8 page, u8 channel)
1044{ 1008{
1045 int rc; 1009 int rc;
1046 1010
@@ -1061,44 +1025,60 @@ at86rf212_set_channel(struct at86rf230_local *lp, int page, int channel)
1061 if (rc < 0) 1025 if (rc < 0)
1062 return rc; 1026 return rc;
1063 1027
1028 /* This sets the symbol_duration according frequency on the 212.
1029 * TODO move this handling while set channel and page in cfg802154.
1030 * We can do that, this timings are according 802.15.4 standard.
1031 * If we do that in cfg802154, this is a more generic calculation.
1032 *
1033 * This should also protected from ifs_timer. Means cancel timer and
1034 * init with a new value. For now, this is okay.
1035 */
1036 if (channel == 0) {
1037 if (page == 0) {
1038 /* SUB:0 and BPSK:0 -> BPSK-20 */
1039 lp->hw->phy->symbol_duration = 50;
1040 } else {
1041 /* SUB:1 and BPSK:0 -> BPSK-40 */
1042 lp->hw->phy->symbol_duration = 25;
1043 }
1044 } else {
1045 if (page == 0)
1046 /* SUB:0 and BPSK:1 -> OQPSK-100/200/400 */
1047 lp->hw->phy->symbol_duration = 40;
1048 else
1049 /* SUB:1 and BPSK:1 -> OQPSK-250/500/1000 */
1050 lp->hw->phy->symbol_duration = 16;
1051 }
1052
1053 lp->hw->phy->lifs_period = IEEE802154_LIFS_PERIOD *
1054 lp->hw->phy->symbol_duration;
1055 lp->hw->phy->sifs_period = IEEE802154_SIFS_PERIOD *
1056 lp->hw->phy->symbol_duration;
1057
1064 return at86rf230_write_subreg(lp, SR_CHANNEL, channel); 1058 return at86rf230_write_subreg(lp, SR_CHANNEL, channel);
1065} 1059}
1066 1060
1067static int 1061static int
1068at86rf230_channel(struct ieee802154_dev *dev, int page, int channel) 1062at86rf230_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
1069{ 1063{
1070 struct at86rf230_local *lp = dev->priv; 1064 struct at86rf230_local *lp = hw->priv;
1071 int rc; 1065 int rc;
1072 1066
1073 might_sleep();
1074
1075 if (page < 0 || page > 31 ||
1076 !(lp->dev->phy->channels_supported[page] & BIT(channel))) {
1077 WARN_ON(1);
1078 return -EINVAL;
1079 }
1080
1081 rc = lp->data->set_channel(lp, page, channel); 1067 rc = lp->data->set_channel(lp, page, channel);
1082 if (rc < 0)
1083 return rc;
1084
1085 /* Wait for PLL */ 1068 /* Wait for PLL */
1086 usleep_range(lp->data->t_channel_switch, 1069 usleep_range(lp->data->t_channel_switch,
1087 lp->data->t_channel_switch + 10); 1070 lp->data->t_channel_switch + 10);
1088 dev->phy->current_channel = channel; 1071 return rc;
1089 dev->phy->current_page = page;
1090
1091 return 0;
1092} 1072}
1093 1073
1094static int 1074static int
1095at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev, 1075at86rf230_set_hw_addr_filt(struct ieee802154_hw *hw,
1096 struct ieee802154_hw_addr_filt *filt, 1076 struct ieee802154_hw_addr_filt *filt,
1097 unsigned long changed) 1077 unsigned long changed)
1098{ 1078{
1099 struct at86rf230_local *lp = dev->priv; 1079 struct at86rf230_local *lp = hw->priv;
1100 1080
1101 if (changed & IEEE802515_AFILT_SADDR_CHANGED) { 1081 if (changed & IEEE802154_AFILT_SADDR_CHANGED) {
1102 u16 addr = le16_to_cpu(filt->short_addr); 1082 u16 addr = le16_to_cpu(filt->short_addr);
1103 1083
1104 dev_vdbg(&lp->spi->dev, 1084 dev_vdbg(&lp->spi->dev,
@@ -1107,7 +1087,7 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev,
1107 __at86rf230_write(lp, RG_SHORT_ADDR_1, addr >> 8); 1087 __at86rf230_write(lp, RG_SHORT_ADDR_1, addr >> 8);
1108 } 1088 }
1109 1089
1110 if (changed & IEEE802515_AFILT_PANID_CHANGED) { 1090 if (changed & IEEE802154_AFILT_PANID_CHANGED) {
1111 u16 pan = le16_to_cpu(filt->pan_id); 1091 u16 pan = le16_to_cpu(filt->pan_id);
1112 1092
1113 dev_vdbg(&lp->spi->dev, 1093 dev_vdbg(&lp->spi->dev,
@@ -1116,7 +1096,7 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev,
1116 __at86rf230_write(lp, RG_PAN_ID_1, pan >> 8); 1096 __at86rf230_write(lp, RG_PAN_ID_1, pan >> 8);
1117 } 1097 }
1118 1098
1119 if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) { 1099 if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED) {
1120 u8 i, addr[8]; 1100 u8 i, addr[8];
1121 1101
1122 memcpy(addr, &filt->ieee_addr, 8); 1102 memcpy(addr, &filt->ieee_addr, 8);
@@ -1126,7 +1106,7 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev,
1126 __at86rf230_write(lp, RG_IEEE_ADDR_0 + i, addr[i]); 1106 __at86rf230_write(lp, RG_IEEE_ADDR_0 + i, addr[i]);
1127 } 1107 }
1128 1108
1129 if (changed & IEEE802515_AFILT_PANC_CHANGED) { 1109 if (changed & IEEE802154_AFILT_PANC_CHANGED) {
1130 dev_vdbg(&lp->spi->dev, 1110 dev_vdbg(&lp->spi->dev,
1131 "at86rf230_set_hw_addr_filt called for panc change\n"); 1111 "at86rf230_set_hw_addr_filt called for panc change\n");
1132 if (filt->pan_coord) 1112 if (filt->pan_coord)
@@ -1139,9 +1119,9 @@ at86rf230_set_hw_addr_filt(struct ieee802154_dev *dev,
1139} 1119}
1140 1120
1141static int 1121static int
1142at86rf230_set_txpower(struct ieee802154_dev *dev, int db) 1122at86rf230_set_txpower(struct ieee802154_hw *hw, int db)
1143{ 1123{
1144 struct at86rf230_local *lp = dev->priv; 1124 struct at86rf230_local *lp = hw->priv;
1145 1125
1146 /* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five 1126 /* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five
1147 * bits decrease power in 1dB steps. 0x60 represents extra PA gain of 1127 * bits decrease power in 1dB steps. 0x60 represents extra PA gain of
@@ -1158,17 +1138,17 @@ at86rf230_set_txpower(struct ieee802154_dev *dev, int db)
1158} 1138}
1159 1139
1160static int 1140static int
1161at86rf230_set_lbt(struct ieee802154_dev *dev, bool on) 1141at86rf230_set_lbt(struct ieee802154_hw *hw, bool on)
1162{ 1142{
1163 struct at86rf230_local *lp = dev->priv; 1143 struct at86rf230_local *lp = hw->priv;
1164 1144
1165 return at86rf230_write_subreg(lp, SR_CSMA_LBT_MODE, on); 1145 return at86rf230_write_subreg(lp, SR_CSMA_LBT_MODE, on);
1166} 1146}
1167 1147
1168static int 1148static int
1169at86rf230_set_cca_mode(struct ieee802154_dev *dev, u8 mode) 1149at86rf230_set_cca_mode(struct ieee802154_hw *hw, u8 mode)
1170{ 1150{
1171 struct at86rf230_local *lp = dev->priv; 1151 struct at86rf230_local *lp = hw->priv;
1172 1152
1173 return at86rf230_write_subreg(lp, SR_CCA_MODE, mode); 1153 return at86rf230_write_subreg(lp, SR_CCA_MODE, mode);
1174} 1154}
@@ -1186,9 +1166,9 @@ at86rf23x_get_desens_steps(struct at86rf230_local *lp, s32 level)
1186} 1166}
1187 1167
1188static int 1168static int
1189at86rf230_set_cca_ed_level(struct ieee802154_dev *dev, s32 level) 1169at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 level)
1190{ 1170{
1191 struct at86rf230_local *lp = dev->priv; 1171 struct at86rf230_local *lp = hw->priv;
1192 1172
1193 if (level < lp->data->rssi_base_val || level > 30) 1173 if (level < lp->data->rssi_base_val || level > 30)
1194 return -EINVAL; 1174 return -EINVAL;
@@ -1198,15 +1178,12 @@ at86rf230_set_cca_ed_level(struct ieee802154_dev *dev, s32 level)
1198} 1178}
1199 1179
1200static int 1180static int
1201at86rf230_set_csma_params(struct ieee802154_dev *dev, u8 min_be, u8 max_be, 1181at86rf230_set_csma_params(struct ieee802154_hw *hw, u8 min_be, u8 max_be,
1202 u8 retries) 1182 u8 retries)
1203{ 1183{
1204 struct at86rf230_local *lp = dev->priv; 1184 struct at86rf230_local *lp = hw->priv;
1205 int rc; 1185 int rc;
1206 1186
1207 if (min_be > max_be || max_be > 8 || retries > 5)
1208 return -EINVAL;
1209
1210 rc = at86rf230_write_subreg(lp, SR_MIN_BE, min_be); 1187 rc = at86rf230_write_subreg(lp, SR_MIN_BE, min_be);
1211 if (rc) 1188 if (rc)
1212 return rc; 1189 return rc;
@@ -1219,15 +1196,13 @@ at86rf230_set_csma_params(struct ieee802154_dev *dev, u8 min_be, u8 max_be,
1219} 1196}
1220 1197
1221static int 1198static int
1222at86rf230_set_frame_retries(struct ieee802154_dev *dev, s8 retries) 1199at86rf230_set_frame_retries(struct ieee802154_hw *hw, s8 retries)
1223{ 1200{
1224 struct at86rf230_local *lp = dev->priv; 1201 struct at86rf230_local *lp = hw->priv;
1225 int rc = 0; 1202 int rc = 0;
1226 1203
1227 if (retries < -1 || retries > 15)
1228 return -EINVAL;
1229
1230 lp->tx_aret = retries >= 0; 1204 lp->tx_aret = retries >= 0;
1205 lp->max_frame_retries = retries;
1231 1206
1232 if (retries >= 0) 1207 if (retries >= 0)
1233 rc = at86rf230_write_subreg(lp, SR_MAX_FRAME_RETRIES, retries); 1208 rc = at86rf230_write_subreg(lp, SR_MAX_FRAME_RETRIES, retries);
@@ -1235,9 +1210,36 @@ at86rf230_set_frame_retries(struct ieee802154_dev *dev, s8 retries)
1235 return rc; 1210 return rc;
1236} 1211}
1237 1212
1238static struct ieee802154_ops at86rf230_ops = { 1213static int
1214at86rf230_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
1215{
1216 struct at86rf230_local *lp = hw->priv;
1217 int rc;
1218
1219 if (on) {
1220 rc = at86rf230_write_subreg(lp, SR_AACK_DIS_ACK, 1);
1221 if (rc < 0)
1222 return rc;
1223
1224 rc = at86rf230_write_subreg(lp, SR_AACK_PROM_MODE, 1);
1225 if (rc < 0)
1226 return rc;
1227 } else {
1228 rc = at86rf230_write_subreg(lp, SR_AACK_PROM_MODE, 0);
1229 if (rc < 0)
1230 return rc;
1231
1232 rc = at86rf230_write_subreg(lp, SR_AACK_DIS_ACK, 0);
1233 if (rc < 0)
1234 return rc;
1235 }
1236
1237 return 0;
1238}
1239
1240static const struct ieee802154_ops at86rf230_ops = {
1239 .owner = THIS_MODULE, 1241 .owner = THIS_MODULE,
1240 .xmit = at86rf230_xmit, 1242 .xmit_async = at86rf230_xmit,
1241 .ed = at86rf230_ed, 1243 .ed = at86rf230_ed,
1242 .set_channel = at86rf230_channel, 1244 .set_channel = at86rf230_channel,
1243 .start = at86rf230_start, 1245 .start = at86rf230_start,
@@ -1249,6 +1251,7 @@ static struct ieee802154_ops at86rf230_ops = {
1249 .set_cca_ed_level = at86rf230_set_cca_ed_level, 1251 .set_cca_ed_level = at86rf230_set_cca_ed_level,
1250 .set_csma_params = at86rf230_set_csma_params, 1252 .set_csma_params = at86rf230_set_csma_params,
1251 .set_frame_retries = at86rf230_set_frame_retries, 1253 .set_frame_retries = at86rf230_set_frame_retries,
1254 .set_promiscuous_mode = at86rf230_set_promiscuous_mode,
1252}; 1255};
1253 1256
1254static struct at86rf2xx_chip_data at86rf233_data = { 1257static struct at86rf2xx_chip_data at86rf233_data = {
@@ -1259,8 +1262,6 @@ static struct at86rf2xx_chip_data at86rf233_data = {
1259 .t_off_to_tx_on = 80, 1262 .t_off_to_tx_on = 80,
1260 .t_frame = 4096, 1263 .t_frame = 4096,
1261 .t_p_ack = 545, 1264 .t_p_ack = 545,
1262 .t_sifs = 192,
1263 .t_lifs = 480,
1264 .t_tx_timeout = 2000, 1265 .t_tx_timeout = 2000,
1265 .rssi_base_val = -91, 1266 .rssi_base_val = -91,
1266 .set_channel = at86rf23x_set_channel, 1267 .set_channel = at86rf23x_set_channel,
@@ -1275,8 +1276,6 @@ static struct at86rf2xx_chip_data at86rf231_data = {
1275 .t_off_to_tx_on = 110, 1276 .t_off_to_tx_on = 110,
1276 .t_frame = 4096, 1277 .t_frame = 4096,
1277 .t_p_ack = 545, 1278 .t_p_ack = 545,
1278 .t_sifs = 192,
1279 .t_lifs = 480,
1280 .t_tx_timeout = 2000, 1279 .t_tx_timeout = 2000,
1281 .rssi_base_val = -91, 1280 .rssi_base_val = -91,
1282 .set_channel = at86rf23x_set_channel, 1281 .set_channel = at86rf23x_set_channel,
@@ -1291,8 +1290,6 @@ static struct at86rf2xx_chip_data at86rf212_data = {
1291 .t_off_to_tx_on = 200, 1290 .t_off_to_tx_on = 200,
1292 .t_frame = 4096, 1291 .t_frame = 4096,
1293 .t_p_ack = 545, 1292 .t_p_ack = 545,
1294 .t_sifs = 192,
1295 .t_lifs = 480,
1296 .t_tx_timeout = 2000, 1293 .t_tx_timeout = 2000,
1297 .rssi_base_val = -100, 1294 .rssi_base_val = -100,
1298 .set_channel = at86rf212_set_channel, 1295 .set_channel = at86rf212_set_channel,
@@ -1354,7 +1351,11 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
1354 return -EINVAL; 1351 return -EINVAL;
1355 } 1352 }
1356 1353
1357 return 0; 1354 /* Force setting slotted operation bit to 0. Sometimes the atben
1355 * sets this bit and I don't know why. We set this always force
1356 * to zero while probing.
1357 */
1358 return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0);
1358} 1359}
1359 1360
1360static struct at86rf230_platform_data * 1361static struct at86rf230_platform_data *
@@ -1409,9 +1410,10 @@ at86rf230_detect_device(struct at86rf230_local *lp)
1409 return -EINVAL; 1410 return -EINVAL;
1410 } 1411 }
1411 1412
1412 lp->dev->extra_tx_headroom = 0; 1413 lp->hw->extra_tx_headroom = 0;
1413 lp->dev->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK | 1414 lp->hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AACK |
1414 IEEE802154_HW_TXPOWER | IEEE802154_HW_CSMA; 1415 IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET |
1416 IEEE802154_HW_AFILT | IEEE802154_HW_PROMISCUOUS;
1415 1417
1416 switch (part) { 1418 switch (part) {
1417 case 2: 1419 case 2:
@@ -1421,15 +1423,19 @@ at86rf230_detect_device(struct at86rf230_local *lp)
1421 case 3: 1423 case 3:
1422 chip = "at86rf231"; 1424 chip = "at86rf231";
1423 lp->data = &at86rf231_data; 1425 lp->data = &at86rf231_data;
1424 lp->dev->phy->channels_supported[0] = 0x7FFF800; 1426 lp->hw->phy->channels_supported[0] = 0x7FFF800;
1427 lp->hw->phy->current_channel = 11;
1428 lp->hw->phy->symbol_duration = 16;
1425 break; 1429 break;
1426 case 7: 1430 case 7:
1427 chip = "at86rf212"; 1431 chip = "at86rf212";
1428 if (version == 1) { 1432 if (version == 1) {
1429 lp->data = &at86rf212_data; 1433 lp->data = &at86rf212_data;
1430 lp->dev->flags |= IEEE802154_HW_LBT; 1434 lp->hw->flags |= IEEE802154_HW_LBT;
1431 lp->dev->phy->channels_supported[0] = 0x00007FF; 1435 lp->hw->phy->channels_supported[0] = 0x00007FF;
1432 lp->dev->phy->channels_supported[2] = 0x00007FF; 1436 lp->hw->phy->channels_supported[2] = 0x00007FF;
1437 lp->hw->phy->current_channel = 5;
1438 lp->hw->phy->symbol_duration = 25;
1433 } else { 1439 } else {
1434 rc = -ENOTSUPP; 1440 rc = -ENOTSUPP;
1435 } 1441 }
@@ -1437,7 +1443,9 @@ at86rf230_detect_device(struct at86rf230_local *lp)
1437 case 11: 1443 case 11:
1438 chip = "at86rf233"; 1444 chip = "at86rf233";
1439 lp->data = &at86rf233_data; 1445 lp->data = &at86rf233_data;
1440 lp->dev->phy->channels_supported[0] = 0x7FFF800; 1446 lp->hw->phy->channels_supported[0] = 0x7FFF800;
1447 lp->hw->phy->current_channel = 13;
1448 lp->hw->phy->symbol_duration = 16;
1441 break; 1449 break;
1442 default: 1450 default:
1443 chip = "unkown"; 1451 chip = "unkown";
@@ -1478,7 +1486,7 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
1478static int at86rf230_probe(struct spi_device *spi) 1486static int at86rf230_probe(struct spi_device *spi)
1479{ 1487{
1480 struct at86rf230_platform_data *pdata; 1488 struct at86rf230_platform_data *pdata;
1481 struct ieee802154_dev *dev; 1489 struct ieee802154_hw *hw;
1482 struct at86rf230_local *lp; 1490 struct at86rf230_local *lp;
1483 unsigned int status; 1491 unsigned int status;
1484 int rc, irq_type; 1492 int rc, irq_type;
@@ -1517,14 +1525,16 @@ static int at86rf230_probe(struct spi_device *spi)
1517 usleep_range(120, 240); 1525 usleep_range(120, 240);
1518 } 1526 }
1519 1527
1520 dev = ieee802154_alloc_device(sizeof(*lp), &at86rf230_ops); 1528 hw = ieee802154_alloc_hw(sizeof(*lp), &at86rf230_ops);
1521 if (!dev) 1529 if (!hw)
1522 return -ENOMEM; 1530 return -ENOMEM;
1523 1531
1524 lp = dev->priv; 1532 lp = hw->priv;
1525 lp->dev = dev; 1533 lp->hw = hw;
1526 lp->spi = spi; 1534 lp->spi = spi;
1527 dev->parent = &spi->dev; 1535 hw->parent = &spi->dev;
1536 hw->vif_data_size = sizeof(*lp);
1537 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
1528 1538
1529 lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config); 1539 lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
1530 if (IS_ERR(lp->regmap)) { 1540 if (IS_ERR(lp->regmap)) {
@@ -1541,7 +1551,6 @@ static int at86rf230_probe(struct spi_device *spi)
1541 goto free_dev; 1551 goto free_dev;
1542 1552
1543 spin_lock_init(&lp->lock); 1553 spin_lock_init(&lp->lock);
1544 init_completion(&lp->tx_complete);
1545 init_completion(&lp->state_complete); 1554 init_completion(&lp->state_complete);
1546 1555
1547 spi_set_drvdata(spi, lp); 1556 spi_set_drvdata(spi, lp);
@@ -1564,14 +1573,14 @@ static int at86rf230_probe(struct spi_device *spi)
1564 if (rc) 1573 if (rc)
1565 goto free_dev; 1574 goto free_dev;
1566 1575
1567 rc = ieee802154_register_device(lp->dev); 1576 rc = ieee802154_register_hw(lp->hw);
1568 if (rc) 1577 if (rc)
1569 goto free_dev; 1578 goto free_dev;
1570 1579
1571 return rc; 1580 return rc;
1572 1581
1573free_dev: 1582free_dev:
1574 ieee802154_free_device(lp->dev); 1583 ieee802154_free_hw(lp->hw);
1575 1584
1576 return rc; 1585 return rc;
1577} 1586}
@@ -1582,8 +1591,8 @@ static int at86rf230_remove(struct spi_device *spi)
1582 1591
1583 /* mask all at86rf230 irq's */ 1592 /* mask all at86rf230 irq's */
1584 at86rf230_write_subreg(lp, SR_IRQ_MASK, 0); 1593 at86rf230_write_subreg(lp, SR_IRQ_MASK, 0);
1585 ieee802154_unregister_device(lp->dev); 1594 ieee802154_unregister_hw(lp->hw);
1586 ieee802154_free_device(lp->dev); 1595 ieee802154_free_hw(lp->hw);
1587 dev_dbg(&spi->dev, "unregistered at86rf230\n"); 1596 dev_dbg(&spi->dev, "unregistered at86rf230\n");
1588 1597
1589 return 0; 1598 return 0;
diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
index 8a5ac7ab2300..ccbb082f3391 100644
--- a/drivers/net/ieee802154/cc2520.c
+++ b/drivers/net/ieee802154/cc2520.c
@@ -21,10 +21,10 @@
21#include <linux/skbuff.h> 21#include <linux/skbuff.h>
22#include <linux/pinctrl/consumer.h> 22#include <linux/pinctrl/consumer.h>
23#include <linux/of_gpio.h> 23#include <linux/of_gpio.h>
24#include <linux/ieee802154.h>
24 25
25#include <net/mac802154.h> 26#include <net/mac802154.h>
26#include <net/wpan-phy.h> 27#include <net/cfg802154.h>
27#include <net/ieee802154.h>
28 28
29#define SPI_COMMAND_BUFFER 3 29#define SPI_COMMAND_BUFFER 3
30#define HIGH 1 30#define HIGH 1
@@ -193,7 +193,7 @@
193/* Driver private information */ 193/* Driver private information */
194struct cc2520_private { 194struct cc2520_private {
195 struct spi_device *spi; /* SPI device structure */ 195 struct spi_device *spi; /* SPI device structure */
196 struct ieee802154_dev *dev; /* IEEE-802.15.4 device */ 196 struct ieee802154_hw *hw; /* IEEE-802.15.4 device */
197 u8 *buf; /* SPI TX/Rx data buffer */ 197 u8 *buf; /* SPI TX/Rx data buffer */
198 struct mutex buffer_mutex; /* SPI buffer mutex */ 198 struct mutex buffer_mutex; /* SPI buffer mutex */
199 bool is_tx; /* Flag for sync b/w Tx and Rx */ 199 bool is_tx; /* Flag for sync b/w Tx and Rx */
@@ -453,20 +453,20 @@ cc2520_read_rxfifo(struct cc2520_private *priv, u8 *data, u8 len, u8 *lqi)
453 return status; 453 return status;
454} 454}
455 455
456static int cc2520_start(struct ieee802154_dev *dev) 456static int cc2520_start(struct ieee802154_hw *hw)
457{ 457{
458 return cc2520_cmd_strobe(dev->priv, CC2520_CMD_SRXON); 458 return cc2520_cmd_strobe(hw->priv, CC2520_CMD_SRXON);
459} 459}
460 460
461static void cc2520_stop(struct ieee802154_dev *dev) 461static void cc2520_stop(struct ieee802154_hw *hw)
462{ 462{
463 cc2520_cmd_strobe(dev->priv, CC2520_CMD_SRFOFF); 463 cc2520_cmd_strobe(hw->priv, CC2520_CMD_SRFOFF);
464} 464}
465 465
466static int 466static int
467cc2520_tx(struct ieee802154_dev *dev, struct sk_buff *skb) 467cc2520_tx(struct ieee802154_hw *hw, struct sk_buff *skb)
468{ 468{
469 struct cc2520_private *priv = dev->priv; 469 struct cc2520_private *priv = hw->priv;
470 unsigned long flags; 470 unsigned long flags;
471 int rc; 471 int rc;
472 u8 status = 0; 472 u8 status = 0;
@@ -524,7 +524,7 @@ static int cc2520_rx(struct cc2520_private *priv)
524 if (len < 2 || len > IEEE802154_MTU) 524 if (len < 2 || len > IEEE802154_MTU)
525 return -EINVAL; 525 return -EINVAL;
526 526
527 skb = alloc_skb(len, GFP_KERNEL); 527 skb = dev_alloc_skb(len);
528 if (!skb) 528 if (!skb)
529 return -ENOMEM; 529 return -ENOMEM;
530 530
@@ -536,7 +536,7 @@ static int cc2520_rx(struct cc2520_private *priv)
536 536
537 skb_trim(skb, skb->len - 2); 537 skb_trim(skb, skb->len - 2);
538 538
539 ieee802154_rx_irqsafe(priv->dev, skb, lqi); 539 ieee802154_rx_irqsafe(priv->hw, skb, lqi);
540 540
541 dev_vdbg(&priv->spi->dev, "RXFIFO: %x %x\n", len, lqi); 541 dev_vdbg(&priv->spi->dev, "RXFIFO: %x %x\n", len, lqi);
542 542
@@ -544,9 +544,9 @@ static int cc2520_rx(struct cc2520_private *priv)
544} 544}
545 545
546static int 546static int
547cc2520_ed(struct ieee802154_dev *dev, u8 *level) 547cc2520_ed(struct ieee802154_hw *hw, u8 *level)
548{ 548{
549 struct cc2520_private *priv = dev->priv; 549 struct cc2520_private *priv = hw->priv;
550 u8 status = 0xff; 550 u8 status = 0xff;
551 u8 rssi; 551 u8 rssi;
552 int ret; 552 int ret;
@@ -569,12 +569,11 @@ cc2520_ed(struct ieee802154_dev *dev, u8 *level)
569} 569}
570 570
571static int 571static int
572cc2520_set_channel(struct ieee802154_dev *dev, int page, int channel) 572cc2520_set_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
573{ 573{
574 struct cc2520_private *priv = dev->priv; 574 struct cc2520_private *priv = hw->priv;
575 int ret; 575 int ret;
576 576
577 might_sleep();
578 dev_dbg(&priv->spi->dev, "trying to set channel\n"); 577 dev_dbg(&priv->spi->dev, "trying to set channel\n");
579 578
580 BUG_ON(page != 0); 579 BUG_ON(page != 0);
@@ -588,12 +587,12 @@ cc2520_set_channel(struct ieee802154_dev *dev, int page, int channel)
588} 587}
589 588
590static int 589static int
591cc2520_filter(struct ieee802154_dev *dev, 590cc2520_filter(struct ieee802154_hw *hw,
592 struct ieee802154_hw_addr_filt *filt, unsigned long changed) 591 struct ieee802154_hw_addr_filt *filt, unsigned long changed)
593{ 592{
594 struct cc2520_private *priv = dev->priv; 593 struct cc2520_private *priv = hw->priv;
595 594
596 if (changed & IEEE802515_AFILT_PANID_CHANGED) { 595 if (changed & IEEE802154_AFILT_PANID_CHANGED) {
597 u16 panid = le16_to_cpu(filt->pan_id); 596 u16 panid = le16_to_cpu(filt->pan_id);
598 597
599 dev_vdbg(&priv->spi->dev, 598 dev_vdbg(&priv->spi->dev,
@@ -602,7 +601,7 @@ cc2520_filter(struct ieee802154_dev *dev,
602 sizeof(panid), (u8 *)&panid); 601 sizeof(panid), (u8 *)&panid);
603 } 602 }
604 603
605 if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) { 604 if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED) {
606 dev_vdbg(&priv->spi->dev, 605 dev_vdbg(&priv->spi->dev,
607 "cc2520_filter called for IEEE addr\n"); 606 "cc2520_filter called for IEEE addr\n");
608 cc2520_write_ram(priv, CC2520RAM_IEEEADDR, 607 cc2520_write_ram(priv, CC2520RAM_IEEEADDR,
@@ -610,7 +609,7 @@ cc2520_filter(struct ieee802154_dev *dev,
610 (u8 *)&filt->ieee_addr); 609 (u8 *)&filt->ieee_addr);
611 } 610 }
612 611
613 if (changed & IEEE802515_AFILT_SADDR_CHANGED) { 612 if (changed & IEEE802154_AFILT_SADDR_CHANGED) {
614 u16 addr = le16_to_cpu(filt->short_addr); 613 u16 addr = le16_to_cpu(filt->short_addr);
615 614
616 dev_vdbg(&priv->spi->dev, 615 dev_vdbg(&priv->spi->dev,
@@ -619,7 +618,7 @@ cc2520_filter(struct ieee802154_dev *dev,
619 sizeof(addr), (u8 *)&addr); 618 sizeof(addr), (u8 *)&addr);
620 } 619 }
621 620
622 if (changed & IEEE802515_AFILT_PANC_CHANGED) { 621 if (changed & IEEE802154_AFILT_PANC_CHANGED) {
623 dev_vdbg(&priv->spi->dev, 622 dev_vdbg(&priv->spi->dev,
624 "cc2520_filter called for panc change\n"); 623 "cc2520_filter called for panc change\n");
625 if (filt->pan_coord) 624 if (filt->pan_coord)
@@ -631,11 +630,11 @@ cc2520_filter(struct ieee802154_dev *dev,
631 return 0; 630 return 0;
632} 631}
633 632
634static struct ieee802154_ops cc2520_ops = { 633static const struct ieee802154_ops cc2520_ops = {
635 .owner = THIS_MODULE, 634 .owner = THIS_MODULE,
636 .start = cc2520_start, 635 .start = cc2520_start,
637 .stop = cc2520_stop, 636 .stop = cc2520_stop,
638 .xmit = cc2520_tx, 637 .xmit_sync = cc2520_tx,
639 .ed = cc2520_ed, 638 .ed = cc2520_ed,
640 .set_channel = cc2520_set_channel, 639 .set_channel = cc2520_set_channel,
641 .set_hw_addr_filt = cc2520_filter, 640 .set_hw_addr_filt = cc2520_filter,
@@ -645,27 +644,29 @@ static int cc2520_register(struct cc2520_private *priv)
645{ 644{
646 int ret = -ENOMEM; 645 int ret = -ENOMEM;
647 646
648 priv->dev = ieee802154_alloc_device(sizeof(*priv), &cc2520_ops); 647 priv->hw = ieee802154_alloc_hw(sizeof(*priv), &cc2520_ops);
649 if (!priv->dev) 648 if (!priv->hw)
650 goto err_ret; 649 goto err_ret;
651 650
652 priv->dev->priv = priv; 651 priv->hw->priv = priv;
653 priv->dev->parent = &priv->spi->dev; 652 priv->hw->parent = &priv->spi->dev;
654 priv->dev->extra_tx_headroom = 0; 653 priv->hw->extra_tx_headroom = 0;
654 priv->hw->vif_data_size = sizeof(*priv);
655 655
656 /* We do support only 2.4 Ghz */ 656 /* We do support only 2.4 Ghz */
657 priv->dev->phy->channels_supported[0] = 0x7FFF800; 657 priv->hw->phy->channels_supported[0] = 0x7FFF800;
658 priv->dev->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK; 658 priv->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
659 IEEE802154_HW_AFILT;
659 660
660 dev_vdbg(&priv->spi->dev, "registered cc2520\n"); 661 dev_vdbg(&priv->spi->dev, "registered cc2520\n");
661 ret = ieee802154_register_device(priv->dev); 662 ret = ieee802154_register_hw(priv->hw);
662 if (ret) 663 if (ret)
663 goto err_free_device; 664 goto err_free_device;
664 665
665 return 0; 666 return 0;
666 667
667err_free_device: 668err_free_device:
668 ieee802154_free_device(priv->dev); 669 ieee802154_free_hw(priv->hw);
669err_ret: 670err_ret:
670 return ret; 671 return ret;
671} 672}
@@ -1002,8 +1003,8 @@ static int cc2520_remove(struct spi_device *spi)
1002 mutex_destroy(&priv->buffer_mutex); 1003 mutex_destroy(&priv->buffer_mutex);
1003 flush_work(&priv->fifop_irqwork); 1004 flush_work(&priv->fifop_irqwork);
1004 1005
1005 ieee802154_unregister_device(priv->dev); 1006 ieee802154_unregister_hw(priv->hw);
1006 ieee802154_free_device(priv->dev); 1007 ieee802154_free_hw(priv->hw);
1007 1008
1008 return 0; 1009 return 0;
1009} 1010}
diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
deleted file mode 100644
index 9ce854f43917..000000000000
--- a/drivers/net/ieee802154/fakehard.c
+++ /dev/null
@@ -1,427 +0,0 @@
1/*
2 * Sample driver for HardMAC IEEE 802.15.4 devices
3 *
4 * Copyright (C) 2009 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by:
20 * Dmitry Eremin-Solenikov <dmitry.baryshkov@siemens.com>
21 */
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/netdevice.h>
26#include <linux/skbuff.h>
27#include <linux/if_arp.h>
28
29#include <net/af_ieee802154.h>
30#include <net/ieee802154_netdev.h>
31#include <net/ieee802154.h>
32#include <net/nl802154.h>
33#include <net/wpan-phy.h>
34
35struct fakehard_priv {
36 struct wpan_phy *phy;
37};
38
39static struct wpan_phy *fake_to_phy(const struct net_device *dev)
40{
41 struct fakehard_priv *priv = netdev_priv(dev);
42 return priv->phy;
43}
44
45/**
46 * fake_get_phy - Return a phy corresponding to this device.
47 * @dev: The network device for which to return the wan-phy object
48 *
49 * This function returns a wpan-phy object corresponding to the passed
50 * network device. Reference counter for wpan-phy object is incremented,
51 * so when the wpan-phy isn't necessary, you should drop the reference
52 * via @wpan_phy_put() call.
53 */
54static struct wpan_phy *fake_get_phy(const struct net_device *dev)
55{
56 struct wpan_phy *phy = fake_to_phy(dev);
57 return to_phy(get_device(&phy->dev));
58}
59
60/**
61 * fake_get_pan_id - Retrieve the PAN ID of the device.
62 * @dev: The network device to retrieve the PAN of.
63 *
64 * Return the ID of the PAN from the PIB.
65 */
66static __le16 fake_get_pan_id(const struct net_device *dev)
67{
68 BUG_ON(dev->type != ARPHRD_IEEE802154);
69
70 return cpu_to_le16(0xeba1);
71}
72
73/**
74 * fake_get_short_addr - Retrieve the short address of the device.
75 * @dev: The network device to retrieve the short address of.
76 *
77 * Returns the IEEE 802.15.4 short-form address cached for this
78 * device. If the device has not yet had a short address assigned
79 * then this should return 0xFFFF to indicate a lack of association.
80 */
81static __le16 fake_get_short_addr(const struct net_device *dev)
82{
83 BUG_ON(dev->type != ARPHRD_IEEE802154);
84
85 return cpu_to_le16(0x1);
86}
87
88/**
89 * fake_get_dsn - Retrieve the DSN of the device.
90 * @dev: The network device to retrieve the DSN for.
91 *
92 * Returns the IEEE 802.15.4 DSN for the network device.
93 * The DSN is the sequence number which will be added to each
94 * packet or MAC command frame by the MAC during transmission.
95 *
96 * DSN means 'Data Sequence Number'.
97 *
98 * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006
99 * document.
100 */
101static u8 fake_get_dsn(const struct net_device *dev)
102{
103 BUG_ON(dev->type != ARPHRD_IEEE802154);
104
105 return 0x00; /* DSN are implemented in HW, so return just 0 */
106}
107
108/**
109 * fake_assoc_req - Make an association request to the HW.
110 * @dev: The network device which we are associating to a network.
111 * @addr: The coordinator with which we wish to associate.
112 * @channel: The channel on which to associate.
113 * @cap: The capability information field to use in the association.
114 *
115 * Start an association with a coordinator. The coordinator's address
116 * and PAN ID can be found in @addr.
117 *
118 * Note: This is in section 7.3.1 and 7.5.3.1 of the IEEE
119 * 802.15.4-2006 document.
120 */
121static int fake_assoc_req(struct net_device *dev,
122 struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap)
123{
124 struct wpan_phy *phy = fake_to_phy(dev);
125
126 mutex_lock(&phy->pib_lock);
127 phy->current_channel = channel;
128 phy->current_page = page;
129 mutex_unlock(&phy->pib_lock);
130
131 /* We simply emulate it here */
132 return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev),
133 IEEE802154_SUCCESS);
134}
135
136/**
137 * fake_assoc_resp - Send an association response to a device.
138 * @dev: The network device on which to send the response.
139 * @addr: The address of the device to respond to.
140 * @short_addr: The assigned short address for the device (if any).
141 * @status: The result of the association request.
142 *
143 * Queue the association response of the coordinator to another
144 * device's attempt to associate with the network which we
145 * coordinate. This is then added to the indirect-send queue to be
146 * transmitted to the end device when it polls for data.
147 *
148 * Note: This is in section 7.3.2 and 7.5.3.1 of the IEEE
149 * 802.15.4-2006 document.
150 */
151static int fake_assoc_resp(struct net_device *dev,
152 struct ieee802154_addr *addr, __le16 short_addr, u8 status)
153{
154 return 0;
155}
156
157/**
158 * fake_disassoc_req - Disassociate a device from a network.
159 * @dev: The network device on which we're disassociating a device.
160 * @addr: The device to disassociate from the network.
161 * @reason: The reason to give to the device for being disassociated.
162 *
163 * This sends a disassociation notification to the device being
164 * disassociated from the network.
165 *
166 * Note: This is in section 7.5.3.2 of the IEEE 802.15.4-2006
167 * document, with the reason described in 7.3.3.2.
168 */
169static int fake_disassoc_req(struct net_device *dev,
170 struct ieee802154_addr *addr, u8 reason)
171{
172 return ieee802154_nl_disassoc_confirm(dev, IEEE802154_SUCCESS);
173}
174
175/**
176 * fake_start_req - Start an IEEE 802.15.4 PAN.
177 * @dev: The network device on which to start the PAN.
178 * @addr: The coordinator address to use when starting the PAN.
179 * @channel: The channel on which to start the PAN.
180 * @bcn_ord: Beacon order.
181 * @sf_ord: Superframe order.
182 * @pan_coord: Whether or not we are the PAN coordinator or just
183 * requesting a realignment perhaps?
184 * @blx: Battery Life Extension feature bitfield.
185 * @coord_realign: Something to realign something else.
186 *
187 * If pan_coord is non-zero then this starts a network with the
188 * provided parameters, otherwise it attempts a coordinator
189 * realignment of the stated network instead.
190 *
191 * Note: This is in section 7.5.2.3 of the IEEE 802.15.4-2006
192 * document, with 7.3.8 describing coordinator realignment.
193 */
194static int fake_start_req(struct net_device *dev,
195 struct ieee802154_addr *addr, u8 channel, u8 page,
196 u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
197 u8 coord_realign)
198{
199 struct wpan_phy *phy = fake_to_phy(dev);
200
201 mutex_lock(&phy->pib_lock);
202 phy->current_channel = channel;
203 phy->current_page = page;
204 mutex_unlock(&phy->pib_lock);
205
206 /* We don't emulate beacons here at all, so START should fail */
207 ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER);
208 return 0;
209}
210
211/**
212 * fake_scan_req - Start a channel scan.
213 * @dev: The network device on which to perform a channel scan.
214 * @type: The type of scan to perform.
215 * @channels: The channel bitmask to scan.
216 * @duration: How long to spend on each channel.
217 *
218 * This starts either a passive (energy) scan or an active (PAN) scan
219 * on the channels indicated in the @channels bitmask. The duration of
220 * the scan is measured in terms of superframe duration. Specifically,
221 * the scan will spend aBaseSuperFrameDuration * ((2^n) + 1) on each
222 * channel.
223 *
224 * Note: This is in section 7.5.2.1 of the IEEE 802.15.4-2006 document.
225 */
226static int fake_scan_req(struct net_device *dev, u8 type, u32 channels,
227 u8 page, u8 duration)
228{
229 u8 edl[27] = {};
230 return ieee802154_nl_scan_confirm(dev, IEEE802154_SUCCESS, type,
231 channels, page,
232 type == IEEE802154_MAC_SCAN_ED ? edl : NULL);
233}
234
235static struct ieee802154_mlme_ops fake_mlme = {
236 .assoc_req = fake_assoc_req,
237 .assoc_resp = fake_assoc_resp,
238 .disassoc_req = fake_disassoc_req,
239 .start_req = fake_start_req,
240 .scan_req = fake_scan_req,
241
242 .get_phy = fake_get_phy,
243
244 .get_pan_id = fake_get_pan_id,
245 .get_short_addr = fake_get_short_addr,
246 .get_dsn = fake_get_dsn,
247};
248
249static int ieee802154_fake_open(struct net_device *dev)
250{
251 netif_start_queue(dev);
252 return 0;
253}
254
255static int ieee802154_fake_close(struct net_device *dev)
256{
257 netif_stop_queue(dev);
258 return 0;
259}
260
261static netdev_tx_t ieee802154_fake_xmit(struct sk_buff *skb,
262 struct net_device *dev)
263{
264 dev->stats.tx_packets++;
265 dev->stats.tx_bytes += skb->len;
266
267 /* FIXME: do hardware work here ... */
268
269 dev_kfree_skb(skb);
270 return NETDEV_TX_OK;
271}
272
273
274static int ieee802154_fake_ioctl(struct net_device *dev, struct ifreq *ifr,
275 int cmd)
276{
277 struct sockaddr_ieee802154 *sa =
278 (struct sockaddr_ieee802154 *)&ifr->ifr_addr;
279 u16 pan_id, short_addr;
280
281 switch (cmd) {
282 case SIOCGIFADDR:
283 /* FIXME: fixed here, get from device IRL */
284 pan_id = le16_to_cpu(fake_get_pan_id(dev));
285 short_addr = le16_to_cpu(fake_get_short_addr(dev));
286 if (pan_id == IEEE802154_PANID_BROADCAST ||
287 short_addr == IEEE802154_ADDR_BROADCAST)
288 return -EADDRNOTAVAIL;
289
290 sa->family = AF_IEEE802154;
291 sa->addr.addr_type = IEEE802154_ADDR_SHORT;
292 sa->addr.pan_id = pan_id;
293 sa->addr.short_addr = short_addr;
294 return 0;
295 }
296 return -ENOIOCTLCMD;
297}
298
299static int ieee802154_fake_mac_addr(struct net_device *dev, void *p)
300{
301 return -EBUSY; /* HW address is built into the device */
302}
303
304static const struct net_device_ops fake_ops = {
305 .ndo_open = ieee802154_fake_open,
306 .ndo_stop = ieee802154_fake_close,
307 .ndo_start_xmit = ieee802154_fake_xmit,
308 .ndo_do_ioctl = ieee802154_fake_ioctl,
309 .ndo_set_mac_address = ieee802154_fake_mac_addr,
310};
311
312static void ieee802154_fake_destruct(struct net_device *dev)
313{
314 struct wpan_phy *phy = fake_to_phy(dev);
315
316 wpan_phy_unregister(phy);
317 free_netdev(dev);
318 wpan_phy_free(phy);
319}
320
321static void ieee802154_fake_setup(struct net_device *dev)
322{
323 dev->addr_len = IEEE802154_ADDR_LEN;
324 memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
325 dev->features = NETIF_F_HW_CSUM;
326 dev->needed_tailroom = 2; /* FCS */
327 dev->mtu = 127;
328 dev->tx_queue_len = 10;
329 dev->type = ARPHRD_IEEE802154;
330 dev->flags = IFF_NOARP | IFF_BROADCAST;
331 dev->watchdog_timeo = 0;
332 dev->destructor = ieee802154_fake_destruct;
333}
334
335
336static int ieee802154fake_probe(struct platform_device *pdev)
337{
338 struct net_device *dev;
339 struct fakehard_priv *priv;
340 struct wpan_phy *phy = wpan_phy_alloc(0);
341 int err;
342
343 if (!phy)
344 return -ENOMEM;
345
346 dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d",
347 NET_NAME_UNKNOWN, ieee802154_fake_setup);
348 if (!dev) {
349 wpan_phy_free(phy);
350 return -ENOMEM;
351 }
352
353 memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef",
354 dev->addr_len);
355
356 /*
357 * For now we'd like to emulate 2.4 GHz-only device,
358 * both O-QPSK and CSS
359 */
360 /* 2.4 GHz O-QPSK 802.15.4-2003 */
361 phy->channels_supported[0] |= 0x7FFF800;
362 /* 2.4 GHz CSS 802.15.4a-2007 */
363 phy->channels_supported[3] |= 0x3fff;
364
365 phy->transmit_power = 0xbf;
366
367 dev->netdev_ops = &fake_ops;
368 dev->ml_priv = &fake_mlme;
369
370 priv = netdev_priv(dev);
371 priv->phy = phy;
372
373 wpan_phy_set_dev(phy, &pdev->dev);
374 SET_NETDEV_DEV(dev, &phy->dev);
375
376 platform_set_drvdata(pdev, dev);
377
378 err = wpan_phy_register(phy);
379 if (err)
380 goto out;
381
382 err = register_netdev(dev);
383 if (err < 0)
384 goto out;
385
386 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
387 return 0;
388
389out:
390 unregister_netdev(dev);
391 return err;
392}
393
394static int ieee802154fake_remove(struct platform_device *pdev)
395{
396 struct net_device *dev = platform_get_drvdata(pdev);
397 unregister_netdev(dev);
398 return 0;
399}
400
401static struct platform_device *ieee802154fake_dev;
402
403static struct platform_driver ieee802154fake_driver = {
404 .probe = ieee802154fake_probe,
405 .remove = ieee802154fake_remove,
406 .driver = {
407 .name = "ieee802154hardmac",
408 .owner = THIS_MODULE,
409 },
410};
411
412static __init int fake_init(void)
413{
414 ieee802154fake_dev = platform_device_register_simple(
415 "ieee802154hardmac", -1, NULL, 0);
416 return platform_driver_register(&ieee802154fake_driver);
417}
418
419static __exit void fake_exit(void)
420{
421 platform_driver_unregister(&ieee802154fake_driver);
422 platform_device_unregister(ieee802154fake_dev);
423}
424
425module_init(fake_init);
426module_exit(fake_exit);
427MODULE_LICENSE("GPL");
diff --git a/drivers/net/ieee802154/fakelb.c b/drivers/net/ieee802154/fakelb.c
index 27d83207d24c..96947d724189 100644
--- a/drivers/net/ieee802154/fakelb.c
+++ b/drivers/net/ieee802154/fakelb.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
@@ -29,12 +25,12 @@
29#include <linux/device.h> 25#include <linux/device.h>
30#include <linux/spinlock.h> 26#include <linux/spinlock.h>
31#include <net/mac802154.h> 27#include <net/mac802154.h>
32#include <net/wpan-phy.h> 28#include <net/cfg802154.h>
33 29
34static int numlbs = 1; 30static int numlbs = 1;
35 31
36struct fakelb_dev_priv { 32struct fakelb_dev_priv {
37 struct ieee802154_dev *dev; 33 struct ieee802154_hw *hw;
38 34
39 struct list_head list; 35 struct list_head list;
40 struct fakelb_priv *fake; 36 struct fakelb_priv *fake;
@@ -49,9 +45,8 @@ struct fakelb_priv {
49}; 45};
50 46
51static int 47static int
52fakelb_hw_ed(struct ieee802154_dev *dev, u8 *level) 48fakelb_hw_ed(struct ieee802154_hw *hw, u8 *level)
53{ 49{
54 might_sleep();
55 BUG_ON(!level); 50 BUG_ON(!level);
56 *level = 0xbe; 51 *level = 0xbe;
57 52
@@ -59,14 +54,10 @@ fakelb_hw_ed(struct ieee802154_dev *dev, u8 *level)
59} 54}
60 55
61static int 56static int
62fakelb_hw_channel(struct ieee802154_dev *dev, int page, int channel) 57fakelb_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
63{ 58{
64 pr_debug("set channel to %d\n", channel); 59 pr_debug("set channel to %d\n", channel);
65 60
66 might_sleep();
67 dev->phy->current_page = page;
68 dev->phy->current_channel = channel;
69
70 return 0; 61 return 0;
71} 62}
72 63
@@ -78,19 +69,17 @@ fakelb_hw_deliver(struct fakelb_dev_priv *priv, struct sk_buff *skb)
78 spin_lock(&priv->lock); 69 spin_lock(&priv->lock);
79 if (priv->working) { 70 if (priv->working) {
80 newskb = pskb_copy(skb, GFP_ATOMIC); 71 newskb = pskb_copy(skb, GFP_ATOMIC);
81 ieee802154_rx_irqsafe(priv->dev, newskb, 0xcc); 72 ieee802154_rx_irqsafe(priv->hw, newskb, 0xcc);
82 } 73 }
83 spin_unlock(&priv->lock); 74 spin_unlock(&priv->lock);
84} 75}
85 76
86static int 77static int
87fakelb_hw_xmit(struct ieee802154_dev *dev, struct sk_buff *skb) 78fakelb_hw_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)
88{ 79{
89 struct fakelb_dev_priv *priv = dev->priv; 80 struct fakelb_dev_priv *priv = hw->priv;
90 struct fakelb_priv *fake = priv->fake; 81 struct fakelb_priv *fake = priv->fake;
91 82
92 might_sleep();
93
94 read_lock_bh(&fake->lock); 83 read_lock_bh(&fake->lock);
95 if (priv->list.next == priv->list.prev) { 84 if (priv->list.next == priv->list.prev) {
96 /* we are the only one device */ 85 /* we are the only one device */
@@ -99,8 +88,8 @@ fakelb_hw_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
99 struct fakelb_dev_priv *dp; 88 struct fakelb_dev_priv *dp;
100 list_for_each_entry(dp, &priv->fake->list, list) { 89 list_for_each_entry(dp, &priv->fake->list, list) {
101 if (dp != priv && 90 if (dp != priv &&
102 (dp->dev->phy->current_channel == 91 (dp->hw->phy->current_channel ==
103 priv->dev->phy->current_channel)) 92 priv->hw->phy->current_channel))
104 fakelb_hw_deliver(dp, skb); 93 fakelb_hw_deliver(dp, skb);
105 } 94 }
106 } 95 }
@@ -110,8 +99,8 @@ fakelb_hw_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
110} 99}
111 100
112static int 101static int
113fakelb_hw_start(struct ieee802154_dev *dev) { 102fakelb_hw_start(struct ieee802154_hw *hw) {
114 struct fakelb_dev_priv *priv = dev->priv; 103 struct fakelb_dev_priv *priv = hw->priv;
115 int ret = 0; 104 int ret = 0;
116 105
117 spin_lock(&priv->lock); 106 spin_lock(&priv->lock);
@@ -125,17 +114,17 @@ fakelb_hw_start(struct ieee802154_dev *dev) {
125} 114}
126 115
127static void 116static void
128fakelb_hw_stop(struct ieee802154_dev *dev) { 117fakelb_hw_stop(struct ieee802154_hw *hw) {
129 struct fakelb_dev_priv *priv = dev->priv; 118 struct fakelb_dev_priv *priv = hw->priv;
130 119
131 spin_lock(&priv->lock); 120 spin_lock(&priv->lock);
132 priv->working = 0; 121 priv->working = 0;
133 spin_unlock(&priv->lock); 122 spin_unlock(&priv->lock);
134} 123}
135 124
136static struct ieee802154_ops fakelb_ops = { 125static const struct ieee802154_ops fakelb_ops = {
137 .owner = THIS_MODULE, 126 .owner = THIS_MODULE,
138 .xmit = fakelb_hw_xmit, 127 .xmit_sync = fakelb_hw_xmit,
139 .ed = fakelb_hw_ed, 128 .ed = fakelb_hw_ed,
140 .set_channel = fakelb_hw_channel, 129 .set_channel = fakelb_hw_channel,
141 .start = fakelb_hw_start, 130 .start = fakelb_hw_start,
@@ -150,54 +139,54 @@ static int fakelb_add_one(struct device *dev, struct fakelb_priv *fake)
150{ 139{
151 struct fakelb_dev_priv *priv; 140 struct fakelb_dev_priv *priv;
152 int err; 141 int err;
153 struct ieee802154_dev *ieee; 142 struct ieee802154_hw *hw;
154 143
155 ieee = ieee802154_alloc_device(sizeof(*priv), &fakelb_ops); 144 hw = ieee802154_alloc_hw(sizeof(*priv), &fakelb_ops);
156 if (!ieee) 145 if (!hw)
157 return -ENOMEM; 146 return -ENOMEM;
158 147
159 priv = ieee->priv; 148 priv = hw->priv;
160 priv->dev = ieee; 149 priv->hw = hw;
161 150
162 /* 868 MHz BPSK 802.15.4-2003 */ 151 /* 868 MHz BPSK 802.15.4-2003 */
163 ieee->phy->channels_supported[0] |= 1; 152 hw->phy->channels_supported[0] |= 1;
164 /* 915 MHz BPSK 802.15.4-2003 */ 153 /* 915 MHz BPSK 802.15.4-2003 */
165 ieee->phy->channels_supported[0] |= 0x7fe; 154 hw->phy->channels_supported[0] |= 0x7fe;
166 /* 2.4 GHz O-QPSK 802.15.4-2003 */ 155 /* 2.4 GHz O-QPSK 802.15.4-2003 */
167 ieee->phy->channels_supported[0] |= 0x7FFF800; 156 hw->phy->channels_supported[0] |= 0x7FFF800;
168 /* 868 MHz ASK 802.15.4-2006 */ 157 /* 868 MHz ASK 802.15.4-2006 */
169 ieee->phy->channels_supported[1] |= 1; 158 hw->phy->channels_supported[1] |= 1;
170 /* 915 MHz ASK 802.15.4-2006 */ 159 /* 915 MHz ASK 802.15.4-2006 */
171 ieee->phy->channels_supported[1] |= 0x7fe; 160 hw->phy->channels_supported[1] |= 0x7fe;
172 /* 868 MHz O-QPSK 802.15.4-2006 */ 161 /* 868 MHz O-QPSK 802.15.4-2006 */
173 ieee->phy->channels_supported[2] |= 1; 162 hw->phy->channels_supported[2] |= 1;
174 /* 915 MHz O-QPSK 802.15.4-2006 */ 163 /* 915 MHz O-QPSK 802.15.4-2006 */
175 ieee->phy->channels_supported[2] |= 0x7fe; 164 hw->phy->channels_supported[2] |= 0x7fe;
176 /* 2.4 GHz CSS 802.15.4a-2007 */ 165 /* 2.4 GHz CSS 802.15.4a-2007 */
177 ieee->phy->channels_supported[3] |= 0x3fff; 166 hw->phy->channels_supported[3] |= 0x3fff;
178 /* UWB Sub-gigahertz 802.15.4a-2007 */ 167 /* UWB Sub-gigahertz 802.15.4a-2007 */
179 ieee->phy->channels_supported[4] |= 1; 168 hw->phy->channels_supported[4] |= 1;
180 /* UWB Low band 802.15.4a-2007 */ 169 /* UWB Low band 802.15.4a-2007 */
181 ieee->phy->channels_supported[4] |= 0x1e; 170 hw->phy->channels_supported[4] |= 0x1e;
182 /* UWB High band 802.15.4a-2007 */ 171 /* UWB High band 802.15.4a-2007 */
183 ieee->phy->channels_supported[4] |= 0xffe0; 172 hw->phy->channels_supported[4] |= 0xffe0;
184 /* 750 MHz O-QPSK 802.15.4c-2009 */ 173 /* 750 MHz O-QPSK 802.15.4c-2009 */
185 ieee->phy->channels_supported[5] |= 0xf; 174 hw->phy->channels_supported[5] |= 0xf;
186 /* 750 MHz MPSK 802.15.4c-2009 */ 175 /* 750 MHz MPSK 802.15.4c-2009 */
187 ieee->phy->channels_supported[5] |= 0xf0; 176 hw->phy->channels_supported[5] |= 0xf0;
188 /* 950 MHz BPSK 802.15.4d-2009 */ 177 /* 950 MHz BPSK 802.15.4d-2009 */
189 ieee->phy->channels_supported[6] |= 0x3ff; 178 hw->phy->channels_supported[6] |= 0x3ff;
190 /* 950 MHz GFSK 802.15.4d-2009 */ 179 /* 950 MHz GFSK 802.15.4d-2009 */
191 ieee->phy->channels_supported[6] |= 0x3ffc00; 180 hw->phy->channels_supported[6] |= 0x3ffc00;
192 181
193 INIT_LIST_HEAD(&priv->list); 182 INIT_LIST_HEAD(&priv->list);
194 priv->fake = fake; 183 priv->fake = fake;
195 184
196 spin_lock_init(&priv->lock); 185 spin_lock_init(&priv->lock);
197 186
198 ieee->parent = dev; 187 hw->parent = dev;
199 188
200 err = ieee802154_register_device(ieee); 189 err = ieee802154_register_hw(hw);
201 if (err) 190 if (err)
202 goto err_reg; 191 goto err_reg;
203 192
@@ -208,7 +197,7 @@ static int fakelb_add_one(struct device *dev, struct fakelb_priv *fake)
208 return 0; 197 return 0;
209 198
210err_reg: 199err_reg:
211 ieee802154_free_device(priv->dev); 200 ieee802154_free_hw(priv->hw);
212 return err; 201 return err;
213} 202}
214 203
@@ -218,8 +207,8 @@ static void fakelb_del(struct fakelb_dev_priv *priv)
218 list_del(&priv->list); 207 list_del(&priv->list);
219 write_unlock_bh(&priv->fake->lock); 208 write_unlock_bh(&priv->fake->lock);
220 209
221 ieee802154_unregister_device(priv->dev); 210 ieee802154_unregister_hw(priv->hw);
222 ieee802154_free_device(priv->dev); 211 ieee802154_free_hw(priv->hw);
223} 212}
224 213
225static int fakelb_probe(struct platform_device *pdev) 214static int fakelb_probe(struct platform_device *pdev)
diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
index 07e0b887c350..a200fa16beae 100644
--- a/drivers/net/ieee802154/mrf24j40.c
+++ b/drivers/net/ieee802154/mrf24j40.c
@@ -13,18 +13,14 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 16 */
21 17
22#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
23#include <linux/interrupt.h> 19#include <linux/interrupt.h>
24#include <linux/module.h> 20#include <linux/module.h>
25#include <net/wpan-phy.h> 21#include <linux/ieee802154.h>
22#include <net/cfg802154.h>
26#include <net/mac802154.h> 23#include <net/mac802154.h>
27#include <net/ieee802154.h>
28 24
29/* MRF24J40 Short Address Registers */ 25/* MRF24J40 Short Address Registers */
30#define REG_RXMCR 0x00 /* Receive MAC control */ 26#define REG_RXMCR 0x00 /* Receive MAC control */
@@ -43,6 +39,8 @@
43#define REG_TXSTBL 0x2E /* TX Stabilization */ 39#define REG_TXSTBL 0x2E /* TX Stabilization */
44#define REG_INTSTAT 0x31 /* Interrupt Status */ 40#define REG_INTSTAT 0x31 /* Interrupt Status */
45#define REG_INTCON 0x32 /* Interrupt Control */ 41#define REG_INTCON 0x32 /* Interrupt Control */
42#define REG_GPIO 0x33 /* GPIO */
43#define REG_TRISGPIO 0x34 /* GPIO direction */
46#define REG_RFCTL 0x36 /* RF Control Mode Register */ 44#define REG_RFCTL 0x36 /* RF Control Mode Register */
47#define REG_BBREG1 0x39 /* Baseband Registers */ 45#define REG_BBREG1 0x39 /* Baseband Registers */
48#define REG_BBREG2 0x3A /* */ 46#define REG_BBREG2 0x3A /* */
@@ -63,6 +61,7 @@
63#define REG_SLPCON1 0x220 61#define REG_SLPCON1 0x220
64#define REG_WAKETIMEL 0x222 /* Wake-up Time Match Value Low */ 62#define REG_WAKETIMEL 0x222 /* Wake-up Time Match Value Low */
65#define REG_WAKETIMEH 0x223 /* Wake-up Time Match Value High */ 63#define REG_WAKETIMEH 0x223 /* Wake-up Time Match Value High */
64#define REG_TESTMODE 0x22F /* Test mode */
66#define REG_RX_FIFO 0x300 /* Receive FIFO */ 65#define REG_RX_FIFO 0x300 /* Receive FIFO */
67 66
68/* Device configuration: Only channels 11-26 on page 0 are supported. */ 67/* Device configuration: Only channels 11-26 on page 0 are supported. */
@@ -75,10 +74,12 @@
75#define RX_FIFO_SIZE 144 /* From datasheet */ 74#define RX_FIFO_SIZE 144 /* From datasheet */
76#define SET_CHANNEL_DELAY_US 192 /* From datasheet */ 75#define SET_CHANNEL_DELAY_US 192 /* From datasheet */
77 76
77enum mrf24j40_modules { MRF24J40, MRF24J40MA, MRF24J40MC };
78
78/* Device Private Data */ 79/* Device Private Data */
79struct mrf24j40 { 80struct mrf24j40 {
80 struct spi_device *spi; 81 struct spi_device *spi;
81 struct ieee802154_dev *dev; 82 struct ieee802154_hw *hw;
82 83
83 struct mutex buffer_mutex; /* only used to protect buf */ 84 struct mutex buffer_mutex; /* only used to protect buf */
84 struct completion tx_complete; 85 struct completion tx_complete;
@@ -331,9 +332,9 @@ out:
331 return ret; 332 return ret;
332} 333}
333 334
334static int mrf24j40_tx(struct ieee802154_dev *dev, struct sk_buff *skb) 335static int mrf24j40_tx(struct ieee802154_hw *hw, struct sk_buff *skb)
335{ 336{
336 struct mrf24j40 *devrec = dev->priv; 337 struct mrf24j40 *devrec = hw->priv;
337 u8 val; 338 u8 val;
338 int ret = 0; 339 int ret = 0;
339 340
@@ -382,7 +383,7 @@ err:
382 return ret; 383 return ret;
383} 384}
384 385
385static int mrf24j40_ed(struct ieee802154_dev *dev, u8 *level) 386static int mrf24j40_ed(struct ieee802154_hw *hw, u8 *level)
386{ 387{
387 /* TODO: */ 388 /* TODO: */
388 pr_warn("mrf24j40: ed not implemented\n"); 389 pr_warn("mrf24j40: ed not implemented\n");
@@ -390,9 +391,9 @@ static int mrf24j40_ed(struct ieee802154_dev *dev, u8 *level)
390 return 0; 391 return 0;
391} 392}
392 393
393static int mrf24j40_start(struct ieee802154_dev *dev) 394static int mrf24j40_start(struct ieee802154_hw *hw)
394{ 395{
395 struct mrf24j40 *devrec = dev->priv; 396 struct mrf24j40 *devrec = hw->priv;
396 u8 val; 397 u8 val;
397 int ret; 398 int ret;
398 399
@@ -407,9 +408,9 @@ static int mrf24j40_start(struct ieee802154_dev *dev)
407 return 0; 408 return 0;
408} 409}
409 410
410static void mrf24j40_stop(struct ieee802154_dev *dev) 411static void mrf24j40_stop(struct ieee802154_hw *hw)
411{ 412{
412 struct mrf24j40 *devrec = dev->priv; 413 struct mrf24j40 *devrec = hw->priv;
413 u8 val; 414 u8 val;
414 int ret; 415 int ret;
415 416
@@ -422,10 +423,9 @@ static void mrf24j40_stop(struct ieee802154_dev *dev)
422 write_short_reg(devrec, REG_INTCON, val); 423 write_short_reg(devrec, REG_INTCON, val);
423} 424}
424 425
425static int mrf24j40_set_channel(struct ieee802154_dev *dev, 426static int mrf24j40_set_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
426 int page, int channel)
427{ 427{
428 struct mrf24j40 *devrec = dev->priv; 428 struct mrf24j40 *devrec = hw->priv;
429 u8 val; 429 u8 val;
430 int ret; 430 int ret;
431 431
@@ -453,15 +453,15 @@ static int mrf24j40_set_channel(struct ieee802154_dev *dev,
453 return 0; 453 return 0;
454} 454}
455 455
456static int mrf24j40_filter(struct ieee802154_dev *dev, 456static int mrf24j40_filter(struct ieee802154_hw *hw,
457 struct ieee802154_hw_addr_filt *filt, 457 struct ieee802154_hw_addr_filt *filt,
458 unsigned long changed) 458 unsigned long changed)
459{ 459{
460 struct mrf24j40 *devrec = dev->priv; 460 struct mrf24j40 *devrec = hw->priv;
461 461
462 dev_dbg(printdev(devrec), "filter\n"); 462 dev_dbg(printdev(devrec), "filter\n");
463 463
464 if (changed & IEEE802515_AFILT_SADDR_CHANGED) { 464 if (changed & IEEE802154_AFILT_SADDR_CHANGED) {
465 /* Short Addr */ 465 /* Short Addr */
466 u8 addrh, addrl; 466 u8 addrh, addrl;
467 467
@@ -474,7 +474,7 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
474 "Set short addr to %04hx\n", filt->short_addr); 474 "Set short addr to %04hx\n", filt->short_addr);
475 } 475 }
476 476
477 if (changed & IEEE802515_AFILT_IEEEADDR_CHANGED) { 477 if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED) {
478 /* Device Address */ 478 /* Device Address */
479 u8 i, addr[8]; 479 u8 i, addr[8];
480 480
@@ -490,7 +490,7 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
490#endif 490#endif
491 } 491 }
492 492
493 if (changed & IEEE802515_AFILT_PANID_CHANGED) { 493 if (changed & IEEE802154_AFILT_PANID_CHANGED) {
494 /* PAN ID */ 494 /* PAN ID */
495 u8 panidl, panidh; 495 u8 panidl, panidh;
496 496
@@ -502,7 +502,7 @@ static int mrf24j40_filter(struct ieee802154_dev *dev,
502 dev_dbg(printdev(devrec), "Set PANID to %04hx\n", filt->pan_id); 502 dev_dbg(printdev(devrec), "Set PANID to %04hx\n", filt->pan_id);
503 } 503 }
504 504
505 if (changed & IEEE802515_AFILT_PANC_CHANGED) { 505 if (changed & IEEE802154_AFILT_PANC_CHANGED) {
506 /* Pan Coordinator */ 506 /* Pan Coordinator */
507 u8 val; 507 u8 val;
508 int ret; 508 int ret;
@@ -543,7 +543,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
543 val |= 4; /* SET RXDECINV */ 543 val |= 4; /* SET RXDECINV */
544 write_short_reg(devrec, REG_BBREG1, val); 544 write_short_reg(devrec, REG_BBREG1, val);
545 545
546 skb = alloc_skb(len, GFP_KERNEL); 546 skb = dev_alloc_skb(len);
547 if (!skb) { 547 if (!skb) {
548 ret = -ENOMEM; 548 ret = -ENOMEM;
549 goto out; 549 goto out;
@@ -563,7 +563,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
563 /* TODO: Other drivers call ieee20154_rx_irqsafe() here (eg: cc2040, 563 /* TODO: Other drivers call ieee20154_rx_irqsafe() here (eg: cc2040,
564 * also from a workqueue). I think irqsafe is not necessary here. 564 * also from a workqueue). I think irqsafe is not necessary here.
565 * Can someone confirm? */ 565 * Can someone confirm? */
566 ieee802154_rx_irqsafe(devrec->dev, skb, lqi); 566 ieee802154_rx_irqsafe(devrec->hw, skb, lqi);
567 567
568 dev_dbg(printdev(devrec), "RX Handled\n"); 568 dev_dbg(printdev(devrec), "RX Handled\n");
569 569
@@ -578,9 +578,9 @@ out:
578 return ret; 578 return ret;
579} 579}
580 580
581static struct ieee802154_ops mrf24j40_ops = { 581static const struct ieee802154_ops mrf24j40_ops = {
582 .owner = THIS_MODULE, 582 .owner = THIS_MODULE,
583 .xmit = mrf24j40_tx, 583 .xmit_sync = mrf24j40_tx,
584 .ed = mrf24j40_ed, 584 .ed = mrf24j40_ed,
585 .start = mrf24j40_start, 585 .start = mrf24j40_start,
586 .stop = mrf24j40_stop, 586 .stop = mrf24j40_stop,
@@ -691,6 +691,28 @@ static int mrf24j40_hw_init(struct mrf24j40 *devrec)
691 if (ret) 691 if (ret)
692 goto err_ret; 692 goto err_ret;
693 693
694 if (spi_get_device_id(devrec->spi)->driver_data == MRF24J40MC) {
695 /* Enable external amplifier.
696 * From MRF24J40MC datasheet section 1.3: Operation.
697 */
698 read_long_reg(devrec, REG_TESTMODE, &val);
699 val |= 0x7; /* Configure GPIO 0-2 to control amplifier */
700 write_long_reg(devrec, REG_TESTMODE, val);
701
702 read_short_reg(devrec, REG_TRISGPIO, &val);
703 val |= 0x8; /* Set GPIO3 as output. */
704 write_short_reg(devrec, REG_TRISGPIO, val);
705
706 read_short_reg(devrec, REG_GPIO, &val);
707 val |= 0x8; /* Set GPIO3 HIGH to enable U5 voltage regulator */
708 write_short_reg(devrec, REG_GPIO, val);
709
710 /* Reduce TX pwr to meet FCC requirements.
711 * From MRF24J40MC datasheet section 3.1.1
712 */
713 write_long_reg(devrec, REG_RFCON3, 0x28);
714 }
715
694 return 0; 716 return 0;
695 717
696err_ret: 718err_ret:
@@ -722,17 +744,18 @@ static int mrf24j40_probe(struct spi_device *spi)
722 744
723 /* Register with the 802154 subsystem */ 745 /* Register with the 802154 subsystem */
724 746
725 devrec->dev = ieee802154_alloc_device(0, &mrf24j40_ops); 747 devrec->hw = ieee802154_alloc_hw(0, &mrf24j40_ops);
726 if (!devrec->dev) 748 if (!devrec->hw)
727 goto err_ret; 749 goto err_ret;
728 750
729 devrec->dev->priv = devrec; 751 devrec->hw->priv = devrec;
730 devrec->dev->parent = &devrec->spi->dev; 752 devrec->hw->parent = &devrec->spi->dev;
731 devrec->dev->phy->channels_supported[0] = CHANNEL_MASK; 753 devrec->hw->phy->channels_supported[0] = CHANNEL_MASK;
732 devrec->dev->flags = IEEE802154_HW_OMIT_CKSUM|IEEE802154_HW_AACK; 754 devrec->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
755 IEEE802154_HW_AFILT;
733 756
734 dev_dbg(printdev(devrec), "registered mrf24j40\n"); 757 dev_dbg(printdev(devrec), "registered mrf24j40\n");
735 ret = ieee802154_register_device(devrec->dev); 758 ret = ieee802154_register_hw(devrec->hw);
736 if (ret) 759 if (ret)
737 goto err_register_device; 760 goto err_register_device;
738 761
@@ -757,9 +780,9 @@ static int mrf24j40_probe(struct spi_device *spi)
757 780
758err_irq: 781err_irq:
759err_hw_init: 782err_hw_init:
760 ieee802154_unregister_device(devrec->dev); 783 ieee802154_unregister_hw(devrec->hw);
761err_register_device: 784err_register_device:
762 ieee802154_free_device(devrec->dev); 785 ieee802154_free_hw(devrec->hw);
763err_ret: 786err_ret:
764 return ret; 787 return ret;
765} 788}
@@ -770,8 +793,8 @@ static int mrf24j40_remove(struct spi_device *spi)
770 793
771 dev_dbg(printdev(devrec), "remove\n"); 794 dev_dbg(printdev(devrec), "remove\n");
772 795
773 ieee802154_unregister_device(devrec->dev); 796 ieee802154_unregister_hw(devrec->hw);
774 ieee802154_free_device(devrec->dev); 797 ieee802154_free_hw(devrec->hw);
775 /* TODO: Will ieee802154_free_device() wait until ->xmit() is 798 /* TODO: Will ieee802154_free_device() wait until ->xmit() is
776 * complete? */ 799 * complete? */
777 800
@@ -779,8 +802,9 @@ static int mrf24j40_remove(struct spi_device *spi)
779} 802}
780 803
781static const struct spi_device_id mrf24j40_ids[] = { 804static const struct spi_device_id mrf24j40_ids[] = {
782 { "mrf24j40", 0 }, 805 { "mrf24j40", MRF24J40 },
783 { "mrf24j40ma", 0 }, 806 { "mrf24j40ma", MRF24J40MA },
807 { "mrf24j40mc", MRF24J40MC },
784 { }, 808 { },
785}; 809};
786MODULE_DEVICE_TABLE(spi, mrf24j40_ids); 810MODULE_DEVICE_TABLE(spi, mrf24j40_ids);
diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index 86907e5ba6ca..ccba4fea7269 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -135,6 +135,11 @@ struct ath_ops {
135struct ath_common; 135struct ath_common;
136struct ath_bus_ops; 136struct ath_bus_ops;
137 137
138struct ath_ps_ops {
139 void (*wakeup)(struct ath_common *common);
140 void (*restore)(struct ath_common *common);
141};
142
138struct ath_common { 143struct ath_common {
139 void *ah; 144 void *ah;
140 void *priv; 145 void *priv;
@@ -148,7 +153,7 @@ struct ath_common {
148 u16 cachelsz; 153 u16 cachelsz;
149 u16 curaid; 154 u16 curaid;
150 u8 macaddr[ETH_ALEN]; 155 u8 macaddr[ETH_ALEN];
151 u8 curbssid[ETH_ALEN]; 156 u8 curbssid[ETH_ALEN] __aligned(2);
152 u8 bssidmask[ETH_ALEN]; 157 u8 bssidmask[ETH_ALEN];
153 158
154 u32 rx_bufsize; 159 u32 rx_bufsize;
@@ -169,6 +174,7 @@ struct ath_common {
169 struct ath_regulatory reg_world_copy; 174 struct ath_regulatory reg_world_copy;
170 const struct ath_ops *ops; 175 const struct ath_ops *ops;
171 const struct ath_bus_ops *bus_ops; 176 const struct ath_bus_ops *bus_ops;
177 const struct ath_ps_ops *ps_ops;
172 178
173 bool btcoex_enabled; 179 bool btcoex_enabled;
174 bool disable_ani; 180 bool disable_ani;
@@ -178,6 +184,11 @@ struct ath_common {
178 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; 184 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
179}; 185};
180 186
187static inline const struct ath_ps_ops *ath_ps_ops(struct ath_common *common)
188{
189 return common->ps_ops;
190}
191
181struct sk_buff *ath_rxbuf_alloc(struct ath_common *common, 192struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
182 u32 len, 193 u32 len,
183 gfp_t gfp_mask); 194 gfp_t gfp_mask);
diff --git a/drivers/net/wireless/ath/ath10k/ce.c b/drivers/net/wireless/ath/ath10k/ce.c
index 101cadb6e4ba..a156e6e48708 100644
--- a/drivers/net/wireless/ath/ath10k/ce.c
+++ b/drivers/net/wireless/ath/ath10k/ce.c
@@ -443,12 +443,12 @@ int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr)
443 * Guts of ath10k_ce_completed_recv_next. 443 * Guts of ath10k_ce_completed_recv_next.
444 * The caller takes responsibility for any necessary locking. 444 * The caller takes responsibility for any necessary locking.
445 */ 445 */
446static int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state, 446int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
447 void **per_transfer_contextp, 447 void **per_transfer_contextp,
448 u32 *bufferp, 448 u32 *bufferp,
449 unsigned int *nbytesp, 449 unsigned int *nbytesp,
450 unsigned int *transfer_idp, 450 unsigned int *transfer_idp,
451 unsigned int *flagsp) 451 unsigned int *flagsp)
452{ 452{
453 struct ath10k_ce_ring *dest_ring = ce_state->dest_ring; 453 struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
454 unsigned int nentries_mask = dest_ring->nentries_mask; 454 unsigned int nentries_mask = dest_ring->nentries_mask;
@@ -558,6 +558,7 @@ int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
558 558
559 /* sanity */ 559 /* sanity */
560 dest_ring->per_transfer_context[sw_index] = NULL; 560 dest_ring->per_transfer_context[sw_index] = NULL;
561 desc->nbytes = 0;
561 562
562 /* Update sw_index */ 563 /* Update sw_index */
563 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); 564 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
@@ -576,11 +577,11 @@ int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
576 * Guts of ath10k_ce_completed_send_next. 577 * Guts of ath10k_ce_completed_send_next.
577 * The caller takes responsibility for any necessary locking. 578 * The caller takes responsibility for any necessary locking.
578 */ 579 */
579static int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state, 580int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
580 void **per_transfer_contextp, 581 void **per_transfer_contextp,
581 u32 *bufferp, 582 u32 *bufferp,
582 unsigned int *nbytesp, 583 unsigned int *nbytesp,
583 unsigned int *transfer_idp) 584 unsigned int *transfer_idp)
584{ 585{
585 struct ath10k_ce_ring *src_ring = ce_state->src_ring; 586 struct ath10k_ce_ring *src_ring = ce_state->src_ring;
586 u32 ctrl_addr = ce_state->ctrl_addr; 587 u32 ctrl_addr = ce_state->ctrl_addr;
@@ -817,7 +818,10 @@ void ath10k_ce_enable_interrupts(struct ath10k *ar)
817 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 818 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
818 int ce_id; 819 int ce_id;
819 820
820 for (ce_id = 0; ce_id < CE_COUNT; ce_id++) 821 /* Skip the last copy engine, CE7 the diagnostic window, as that
822 * uses polling and isn't initialized for interrupts.
823 */
824 for (ce_id = 0; ce_id < CE_COUNT - 1; ce_id++)
821 ath10k_ce_per_engine_handler_adjust(&ar_pci->ce_states[ce_id]); 825 ath10k_ce_per_engine_handler_adjust(&ar_pci->ce_states[ce_id]);
822} 826}
823 827
@@ -832,8 +836,8 @@ static int ath10k_ce_init_src_ring(struct ath10k *ar,
832 836
833 nentries = roundup_pow_of_two(attr->src_nentries); 837 nentries = roundup_pow_of_two(attr->src_nentries);
834 838
835 memset(src_ring->per_transfer_context, 0, 839 memset(src_ring->base_addr_owner_space, 0,
836 nentries * sizeof(*src_ring->per_transfer_context)); 840 nentries * sizeof(struct ce_desc));
837 841
838 src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr); 842 src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
839 src_ring->sw_index &= src_ring->nentries_mask; 843 src_ring->sw_index &= src_ring->nentries_mask;
@@ -869,8 +873,8 @@ static int ath10k_ce_init_dest_ring(struct ath10k *ar,
869 873
870 nentries = roundup_pow_of_two(attr->dest_nentries); 874 nentries = roundup_pow_of_two(attr->dest_nentries);
871 875
872 memset(dest_ring->per_transfer_context, 0, 876 memset(dest_ring->base_addr_owner_space, 0,
873 nentries * sizeof(*dest_ring->per_transfer_context)); 877 nentries * sizeof(struct ce_desc));
874 878
875 dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr); 879 dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
876 dest_ring->sw_index &= dest_ring->nentries_mask; 880 dest_ring->sw_index &= dest_ring->nentries_mask;
@@ -1020,37 +1024,10 @@ ath10k_ce_alloc_dest_ring(struct ath10k *ar, unsigned int ce_id,
1020 * initialized by software/firmware. 1024 * initialized by software/firmware.
1021 */ 1025 */
1022int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id, 1026int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
1023 const struct ce_attr *attr, 1027 const struct ce_attr *attr)
1024 void (*send_cb)(struct ath10k_ce_pipe *),
1025 void (*recv_cb)(struct ath10k_ce_pipe *))
1026{ 1028{
1027 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1028 struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
1029 int ret; 1029 int ret;
1030 1030
1031 /*
1032 * Make sure there's enough CE ringbuffer entries for HTT TX to avoid
1033 * additional TX locking checks.
1034 *
1035 * For the lack of a better place do the check here.
1036 */
1037 BUILD_BUG_ON(2*TARGET_NUM_MSDU_DESC >
1038 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1039 BUILD_BUG_ON(2*TARGET_10X_NUM_MSDU_DESC >
1040 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1041
1042 spin_lock_bh(&ar_pci->ce_lock);
1043 ce_state->ar = ar;
1044 ce_state->id = ce_id;
1045 ce_state->ctrl_addr = ath10k_ce_base_address(ce_id);
1046 ce_state->attr_flags = attr->flags;
1047 ce_state->src_sz_max = attr->src_sz_max;
1048 if (attr->src_nentries)
1049 ce_state->send_cb = send_cb;
1050 if (attr->dest_nentries)
1051 ce_state->recv_cb = recv_cb;
1052 spin_unlock_bh(&ar_pci->ce_lock);
1053
1054 if (attr->src_nentries) { 1031 if (attr->src_nentries) {
1055 ret = ath10k_ce_init_src_ring(ar, ce_id, attr); 1032 ret = ath10k_ce_init_src_ring(ar, ce_id, attr);
1056 if (ret) { 1033 if (ret) {
@@ -1098,12 +1075,37 @@ void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id)
1098} 1075}
1099 1076
1100int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id, 1077int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
1101 const struct ce_attr *attr) 1078 const struct ce_attr *attr,
1079 void (*send_cb)(struct ath10k_ce_pipe *),
1080 void (*recv_cb)(struct ath10k_ce_pipe *))
1102{ 1081{
1103 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1082 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1104 struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id]; 1083 struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
1105 int ret; 1084 int ret;
1106 1085
1086 /*
1087 * Make sure there's enough CE ringbuffer entries for HTT TX to avoid
1088 * additional TX locking checks.
1089 *
1090 * For the lack of a better place do the check here.
1091 */
1092 BUILD_BUG_ON(2*TARGET_NUM_MSDU_DESC >
1093 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1094 BUILD_BUG_ON(2*TARGET_10X_NUM_MSDU_DESC >
1095 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1096
1097 ce_state->ar = ar;
1098 ce_state->id = ce_id;
1099 ce_state->ctrl_addr = ath10k_ce_base_address(ce_id);
1100 ce_state->attr_flags = attr->flags;
1101 ce_state->src_sz_max = attr->src_sz_max;
1102
1103 if (attr->src_nentries)
1104 ce_state->send_cb = send_cb;
1105
1106 if (attr->dest_nentries)
1107 ce_state->recv_cb = recv_cb;
1108
1107 if (attr->src_nentries) { 1109 if (attr->src_nentries) {
1108 ce_state->src_ring = ath10k_ce_alloc_src_ring(ar, ce_id, attr); 1110 ce_state->src_ring = ath10k_ce_alloc_src_ring(ar, ce_id, attr);
1109 if (IS_ERR(ce_state->src_ring)) { 1111 if (IS_ERR(ce_state->src_ring)) {
diff --git a/drivers/net/wireless/ath/ath10k/ce.h b/drivers/net/wireless/ath/ath10k/ce.h
index 329b7340fa72..617a151e8ce4 100644
--- a/drivers/net/wireless/ath/ath10k/ce.h
+++ b/drivers/net/wireless/ath/ath10k/ce.h
@@ -192,15 +192,21 @@ int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
192 unsigned int *nbytesp, 192 unsigned int *nbytesp,
193 unsigned int *transfer_idp); 193 unsigned int *transfer_idp);
194 194
195int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
196 void **per_transfer_contextp,
197 u32 *bufferp,
198 unsigned int *nbytesp,
199 unsigned int *transfer_idp);
200
195/*==================CE Engine Initialization=======================*/ 201/*==================CE Engine Initialization=======================*/
196 202
197int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id, 203int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
198 const struct ce_attr *attr, 204 const struct ce_attr *attr);
199 void (*send_cb)(struct ath10k_ce_pipe *),
200 void (*recv_cb)(struct ath10k_ce_pipe *));
201void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id); 205void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
202int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id, 206int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
203 const struct ce_attr *attr); 207 const struct ce_attr *attr,
208 void (*send_cb)(struct ath10k_ce_pipe *),
209 void (*recv_cb)(struct ath10k_ce_pipe *));
204void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id); 210void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
205 211
206/*==================CE Engine Shutdown=======================*/ 212/*==================CE Engine Shutdown=======================*/
@@ -213,6 +219,13 @@ int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
213 void **per_transfer_contextp, 219 void **per_transfer_contextp,
214 u32 *bufferp); 220 u32 *bufferp);
215 221
222int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
223 void **per_transfer_contextp,
224 u32 *bufferp,
225 unsigned int *nbytesp,
226 unsigned int *transfer_idp,
227 unsigned int *flagsp);
228
216/* 229/*
217 * Support clean shutdown by allowing the caller to cancel 230 * Support clean shutdown by allowing the caller to cancel
218 * pending sends. Target DMA must be stopped before using 231 * pending sends. Target DMA must be stopped before using
diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index cee18c89d7f2..f660553c6c48 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -31,12 +31,17 @@
31unsigned int ath10k_debug_mask; 31unsigned int ath10k_debug_mask;
32static bool uart_print; 32static bool uart_print;
33static unsigned int ath10k_p2p; 33static unsigned int ath10k_p2p;
34static bool skip_otp;
35
34module_param_named(debug_mask, ath10k_debug_mask, uint, 0644); 36module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
35module_param(uart_print, bool, 0644); 37module_param(uart_print, bool, 0644);
36module_param_named(p2p, ath10k_p2p, uint, 0644); 38module_param_named(p2p, ath10k_p2p, uint, 0644);
39module_param(skip_otp, bool, 0644);
40
37MODULE_PARM_DESC(debug_mask, "Debugging mask"); 41MODULE_PARM_DESC(debug_mask, "Debugging mask");
38MODULE_PARM_DESC(uart_print, "Uart target debugging"); 42MODULE_PARM_DESC(uart_print, "Uart target debugging");
39MODULE_PARM_DESC(p2p, "Enable ath10k P2P support"); 43MODULE_PARM_DESC(p2p, "Enable ath10k P2P support");
44MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
40 45
41static const struct ath10k_hw_params ath10k_hw_params_list[] = { 46static const struct ath10k_hw_params ath10k_hw_params_list[] = {
42 { 47 {
@@ -138,7 +143,8 @@ static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
138 return fw; 143 return fw;
139} 144}
140 145
141static int ath10k_push_board_ext_data(struct ath10k *ar) 146static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
147 size_t data_len)
142{ 148{
143 u32 board_data_size = QCA988X_BOARD_DATA_SZ; 149 u32 board_data_size = QCA988X_BOARD_DATA_SZ;
144 u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ; 150 u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ;
@@ -159,14 +165,14 @@ static int ath10k_push_board_ext_data(struct ath10k *ar)
159 if (board_ext_data_addr == 0) 165 if (board_ext_data_addr == 0)
160 return 0; 166 return 0;
161 167
162 if (ar->board_len != (board_data_size + board_ext_data_size)) { 168 if (data_len != (board_data_size + board_ext_data_size)) {
163 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n", 169 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
164 ar->board_len, board_data_size, board_ext_data_size); 170 data_len, board_data_size, board_ext_data_size);
165 return -EINVAL; 171 return -EINVAL;
166 } 172 }
167 173
168 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr, 174 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
169 ar->board_data + board_data_size, 175 data + board_data_size,
170 board_ext_data_size); 176 board_ext_data_size);
171 if (ret) { 177 if (ret) {
172 ath10k_err(ar, "could not write board ext data (%d)\n", ret); 178 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
@@ -184,13 +190,14 @@ static int ath10k_push_board_ext_data(struct ath10k *ar)
184 return 0; 190 return 0;
185} 191}
186 192
187static int ath10k_download_board_data(struct ath10k *ar) 193static int ath10k_download_board_data(struct ath10k *ar, const void *data,
194 size_t data_len)
188{ 195{
189 u32 board_data_size = QCA988X_BOARD_DATA_SZ; 196 u32 board_data_size = QCA988X_BOARD_DATA_SZ;
190 u32 address; 197 u32 address;
191 int ret; 198 int ret;
192 199
193 ret = ath10k_push_board_ext_data(ar); 200 ret = ath10k_push_board_ext_data(ar, data, data_len);
194 if (ret) { 201 if (ret) {
195 ath10k_err(ar, "could not push board ext data (%d)\n", ret); 202 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
196 goto exit; 203 goto exit;
@@ -202,9 +209,9 @@ static int ath10k_download_board_data(struct ath10k *ar)
202 goto exit; 209 goto exit;
203 } 210 }
204 211
205 ret = ath10k_bmi_write_memory(ar, address, ar->board_data, 212 ret = ath10k_bmi_write_memory(ar, address, data,
206 min_t(u32, board_data_size, 213 min_t(u32, board_data_size,
207 ar->board_len)); 214 data_len));
208 if (ret) { 215 if (ret) {
209 ath10k_err(ar, "could not write board data (%d)\n", ret); 216 ath10k_err(ar, "could not write board data (%d)\n", ret);
210 goto exit; 217 goto exit;
@@ -220,11 +227,39 @@ exit:
220 return ret; 227 return ret;
221} 228}
222 229
230static int ath10k_download_cal_file(struct ath10k *ar)
231{
232 int ret;
233
234 if (!ar->cal_file)
235 return -ENOENT;
236
237 if (IS_ERR(ar->cal_file))
238 return PTR_ERR(ar->cal_file);
239
240 ret = ath10k_download_board_data(ar, ar->cal_file->data,
241 ar->cal_file->size);
242 if (ret) {
243 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
244 return ret;
245 }
246
247 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
248
249 return 0;
250}
251
223static int ath10k_download_and_run_otp(struct ath10k *ar) 252static int ath10k_download_and_run_otp(struct ath10k *ar)
224{ 253{
225 u32 result, address = ar->hw_params.patch_load_addr; 254 u32 result, address = ar->hw_params.patch_load_addr;
226 int ret; 255 int ret;
227 256
257 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
258 if (ret) {
259 ath10k_err(ar, "failed to download board data: %d\n", ret);
260 return ret;
261 }
262
228 /* OTP is optional */ 263 /* OTP is optional */
229 264
230 if (!ar->otp_data || !ar->otp_len) { 265 if (!ar->otp_data || !ar->otp_len) {
@@ -250,7 +285,7 @@ static int ath10k_download_and_run_otp(struct ath10k *ar)
250 285
251 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result); 286 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
252 287
253 if (result != 0) { 288 if (!skip_otp && result != 0) {
254 ath10k_err(ar, "otp calibration failed: %d", result); 289 ath10k_err(ar, "otp calibration failed: %d", result);
255 return -EINVAL; 290 return -EINVAL;
256 } 291 }
@@ -308,6 +343,9 @@ static void ath10k_core_free_firmware_files(struct ath10k *ar)
308 if (ar->firmware && !IS_ERR(ar->firmware)) 343 if (ar->firmware && !IS_ERR(ar->firmware))
309 release_firmware(ar->firmware); 344 release_firmware(ar->firmware);
310 345
346 if (ar->cal_file && !IS_ERR(ar->cal_file))
347 release_firmware(ar->cal_file);
348
311 ar->board = NULL; 349 ar->board = NULL;
312 ar->board_data = NULL; 350 ar->board_data = NULL;
313 ar->board_len = 0; 351 ar->board_len = 0;
@@ -319,6 +357,27 @@ static void ath10k_core_free_firmware_files(struct ath10k *ar)
319 ar->firmware = NULL; 357 ar->firmware = NULL;
320 ar->firmware_data = NULL; 358 ar->firmware_data = NULL;
321 ar->firmware_len = 0; 359 ar->firmware_len = 0;
360
361 ar->cal_file = NULL;
362}
363
364static int ath10k_fetch_cal_file(struct ath10k *ar)
365{
366 char filename[100];
367
368 /* cal-<bus>-<id>.bin */
369 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
370 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
371
372 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
373 if (IS_ERR(ar->cal_file))
374 /* calibration file is optional, don't print any warnings */
375 return PTR_ERR(ar->cal_file);
376
377 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
378 ATH10K_FW_DIR, filename);
379
380 return 0;
322} 381}
323 382
324static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar) 383static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
@@ -562,6 +621,9 @@ static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
562{ 621{
563 int ret; 622 int ret;
564 623
624 /* calibration file is optional, don't check for any errors */
625 ath10k_fetch_cal_file(ar);
626
565 ar->fw_api = 3; 627 ar->fw_api = 3;
566 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); 628 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
567 629
@@ -589,30 +651,32 @@ success:
589 return 0; 651 return 0;
590} 652}
591 653
592static int ath10k_init_download_firmware(struct ath10k *ar, 654static int ath10k_download_cal_data(struct ath10k *ar)
593 enum ath10k_firmware_mode mode)
594{ 655{
595 int ret; 656 int ret;
596 657
597 ret = ath10k_download_board_data(ar); 658 ret = ath10k_download_cal_file(ar);
598 if (ret) { 659 if (ret == 0) {
599 ath10k_err(ar, "failed to download board data: %d\n", ret); 660 ar->cal_mode = ATH10K_CAL_MODE_FILE;
600 return ret; 661 goto done;
601 } 662 }
602 663
664 ath10k_dbg(ar, ATH10K_DBG_BOOT,
665 "boot did not find a calibration file, try OTP next: %d\n",
666 ret);
667
603 ret = ath10k_download_and_run_otp(ar); 668 ret = ath10k_download_and_run_otp(ar);
604 if (ret) { 669 if (ret) {
605 ath10k_err(ar, "failed to run otp: %d\n", ret); 670 ath10k_err(ar, "failed to run otp: %d\n", ret);
606 return ret; 671 return ret;
607 } 672 }
608 673
609 ret = ath10k_download_fw(ar, mode); 674 ar->cal_mode = ATH10K_CAL_MODE_OTP;
610 if (ret) {
611 ath10k_err(ar, "failed to download firmware: %d\n", ret);
612 return ret;
613 }
614 675
615 return ret; 676done:
677 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
678 ath10k_cal_mode_str(ar->cal_mode));
679 return 0;
616} 680}
617 681
618static int ath10k_init_uart(struct ath10k *ar) 682static int ath10k_init_uart(struct ath10k *ar)
@@ -685,6 +749,25 @@ static void ath10k_core_restart(struct work_struct *work)
685{ 749{
686 struct ath10k *ar = container_of(work, struct ath10k, restart_work); 750 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
687 751
752 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
753
754 /* Place a barrier to make sure the compiler doesn't reorder
755 * CRASH_FLUSH and calling other functions.
756 */
757 barrier();
758
759 ieee80211_stop_queues(ar->hw);
760 ath10k_drain_tx(ar);
761 complete_all(&ar->scan.started);
762 complete_all(&ar->scan.completed);
763 complete_all(&ar->scan.on_channel);
764 complete_all(&ar->offchan_tx_completed);
765 complete_all(&ar->install_key_done);
766 complete_all(&ar->vdev_setup_done);
767 wake_up(&ar->htt.empty_tx_wq);
768 wake_up(&ar->wmi.tx_credits_wq);
769 wake_up(&ar->peer_mapping_wq);
770
688 mutex_lock(&ar->conf_mutex); 771 mutex_lock(&ar->conf_mutex);
689 772
690 switch (ar->state) { 773 switch (ar->state) {
@@ -722,6 +805,8 @@ int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
722 805
723 lockdep_assert_held(&ar->conf_mutex); 806 lockdep_assert_held(&ar->conf_mutex);
724 807
808 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
809
725 ath10k_bmi_start(ar); 810 ath10k_bmi_start(ar);
726 811
727 if (ath10k_init_configure_target(ar)) { 812 if (ath10k_init_configure_target(ar)) {
@@ -729,7 +814,11 @@ int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
729 goto err; 814 goto err;
730 } 815 }
731 816
732 status = ath10k_init_download_firmware(ar, mode); 817 status = ath10k_download_cal_data(ar);
818 if (status)
819 goto err;
820
821 status = ath10k_download_fw(ar, mode);
733 if (status) 822 if (status)
734 goto err; 823 goto err;
735 824
@@ -846,9 +935,9 @@ int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
846 goto err_hif_stop; 935 goto err_hif_stop;
847 936
848 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) 937 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
849 ar->free_vdev_map = (1 << TARGET_10X_NUM_VDEVS) - 1; 938 ar->free_vdev_map = (1LL << TARGET_10X_NUM_VDEVS) - 1;
850 else 939 else
851 ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1; 940 ar->free_vdev_map = (1LL << TARGET_NUM_VDEVS) - 1;
852 941
853 INIT_LIST_HEAD(&ar->arvifs); 942 INIT_LIST_HEAD(&ar->arvifs);
854 943
@@ -1084,6 +1173,7 @@ void ath10k_core_unregister(struct ath10k *ar)
1084EXPORT_SYMBOL(ath10k_core_unregister); 1173EXPORT_SYMBOL(ath10k_core_unregister);
1085 1174
1086struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev, 1175struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1176 enum ath10k_bus bus,
1087 const struct ath10k_hif_ops *hif_ops) 1177 const struct ath10k_hif_ops *hif_ops)
1088{ 1178{
1089 struct ath10k *ar; 1179 struct ath10k *ar;
@@ -1100,6 +1190,7 @@ struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1100 ar->dev = dev; 1190 ar->dev = dev;
1101 1191
1102 ar->hif.ops = hif_ops; 1192 ar->hif.ops = hif_ops;
1193 ar->hif.bus = bus;
1103 1194
1104 init_completion(&ar->scan.started); 1195 init_completion(&ar->scan.started);
1105 init_completion(&ar->scan.completed); 1196 init_completion(&ar->scan.completed);
@@ -1120,6 +1211,8 @@ struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1120 1211
1121 INIT_LIST_HEAD(&ar->peers); 1212 INIT_LIST_HEAD(&ar->peers);
1122 init_waitqueue_head(&ar->peer_mapping_wq); 1213 init_waitqueue_head(&ar->peer_mapping_wq);
1214 init_waitqueue_head(&ar->htt.empty_tx_wq);
1215 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1123 1216
1124 init_completion(&ar->offchan_tx_completed); 1217 init_completion(&ar->offchan_tx_completed);
1125 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work); 1218 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index fe531ea6926c..8f86bd34e823 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -63,6 +63,20 @@
63 63
64struct ath10k; 64struct ath10k;
65 65
66enum ath10k_bus {
67 ATH10K_BUS_PCI,
68};
69
70static inline const char *ath10k_bus_str(enum ath10k_bus bus)
71{
72 switch (bus) {
73 case ATH10K_BUS_PCI:
74 return "pci";
75 }
76
77 return "unknown";
78}
79
66struct ath10k_skb_cb { 80struct ath10k_skb_cb {
67 dma_addr_t paddr; 81 dma_addr_t paddr;
68 u8 vdev_id; 82 u8 vdev_id;
@@ -96,8 +110,6 @@ struct ath10k_bmi {
96 bool done_sent; 110 bool done_sent;
97}; 111};
98 112
99#define ATH10K_MAX_MEM_REQS 16
100
101struct ath10k_mem_chunk { 113struct ath10k_mem_chunk {
102 void *vaddr; 114 void *vaddr;
103 dma_addr_t paddr; 115 dma_addr_t paddr;
@@ -115,17 +127,21 @@ struct ath10k_wmi {
115 struct wmi_pdev_param_map *pdev_param; 127 struct wmi_pdev_param_map *pdev_param;
116 128
117 u32 num_mem_chunks; 129 u32 num_mem_chunks;
118 struct ath10k_mem_chunk mem_chunks[ATH10K_MAX_MEM_REQS]; 130 struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
119}; 131};
120 132
121struct ath10k_peer_stat { 133struct ath10k_fw_stats_peer {
134 struct list_head list;
135
122 u8 peer_macaddr[ETH_ALEN]; 136 u8 peer_macaddr[ETH_ALEN];
123 u32 peer_rssi; 137 u32 peer_rssi;
124 u32 peer_tx_rate; 138 u32 peer_tx_rate;
125 u32 peer_rx_rate; /* 10x only */ 139 u32 peer_rx_rate; /* 10x only */
126}; 140};
127 141
128struct ath10k_target_stats { 142struct ath10k_fw_stats_pdev {
143 struct list_head list;
144
129 /* PDEV stats */ 145 /* PDEV stats */
130 s32 ch_noise_floor; 146 s32 ch_noise_floor;
131 u32 tx_frame_count; 147 u32 tx_frame_count;
@@ -180,15 +196,11 @@ struct ath10k_target_stats {
180 s32 phy_errs; 196 s32 phy_errs;
181 s32 phy_err_drop; 197 s32 phy_err_drop;
182 s32 mpdu_errs; 198 s32 mpdu_errs;
199};
183 200
184 /* VDEV STATS */ 201struct ath10k_fw_stats {
185 202 struct list_head pdevs;
186 /* PEER STATS */ 203 struct list_head peers;
187 u8 peers;
188 struct ath10k_peer_stat peer_stat[TARGET_NUM_PEERS];
189
190 /* TODO: Beacon filter stats */
191
192}; 204};
193 205
194struct ath10k_dfs_stats { 206struct ath10k_dfs_stats {
@@ -234,6 +246,8 @@ struct ath10k_vif {
234 struct sk_buff *beacon; 246 struct sk_buff *beacon;
235 /* protected by data_lock */ 247 /* protected by data_lock */
236 bool beacon_sent; 248 bool beacon_sent;
249 void *beacon_buf;
250 dma_addr_t beacon_paddr;
237 251
238 struct ath10k *ar; 252 struct ath10k *ar;
239 struct ieee80211_vif *vif; 253 struct ieee80211_vif *vif;
@@ -273,6 +287,7 @@ struct ath10k_vif {
273 u8 force_sgi; 287 u8 force_sgi;
274 bool use_cts_prot; 288 bool use_cts_prot;
275 int num_legacy_stations; 289 int num_legacy_stations;
290 int txpower;
276}; 291};
277 292
278struct ath10k_vif_iter { 293struct ath10k_vif_iter {
@@ -292,17 +307,19 @@ struct ath10k_fw_crash_data {
292struct ath10k_debug { 307struct ath10k_debug {
293 struct dentry *debugfs_phy; 308 struct dentry *debugfs_phy;
294 309
295 struct ath10k_target_stats target_stats; 310 struct ath10k_fw_stats fw_stats;
311 struct completion fw_stats_complete;
312 bool fw_stats_done;
296 DECLARE_BITMAP(wmi_service_bitmap, WMI_SERVICE_MAX); 313 DECLARE_BITMAP(wmi_service_bitmap, WMI_SERVICE_MAX);
297 314
298 struct completion event_stats_compl;
299
300 unsigned long htt_stats_mask; 315 unsigned long htt_stats_mask;
301 struct delayed_work htt_stats_dwork; 316 struct delayed_work htt_stats_dwork;
302 struct ath10k_dfs_stats dfs_stats; 317 struct ath10k_dfs_stats dfs_stats;
303 struct ath_dfs_pool_stats dfs_pool_stats; 318 struct ath_dfs_pool_stats dfs_pool_stats;
304 319
320 /* protected by conf_mutex */
305 u32 fw_dbglog_mask; 321 u32 fw_dbglog_mask;
322 u32 pktlog_filter;
306 323
307 u8 htt_max_amsdu; 324 u8 htt_max_amsdu;
308 u8 htt_max_ampdu; 325 u8 htt_max_ampdu;
@@ -321,7 +338,7 @@ enum ath10k_state {
321 * stopped in ath10k_core_restart() work holding conf_mutex. The state 338 * stopped in ath10k_core_restart() work holding conf_mutex. The state
322 * RESTARTED means that the device is up and mac80211 has started hw 339 * RESTARTED means that the device is up and mac80211 has started hw
323 * reconfiguration. Once mac80211 is done with the reconfiguration we 340 * reconfiguration. Once mac80211 is done with the reconfiguration we
324 * set the state to STATE_ON in restart_complete(). */ 341 * set the state to STATE_ON in reconfig_complete(). */
325 ATH10K_STATE_RESTARTING, 342 ATH10K_STATE_RESTARTING,
326 ATH10K_STATE_RESTARTED, 343 ATH10K_STATE_RESTARTED,
327 344
@@ -369,8 +386,30 @@ enum ath10k_dev_flags {
369 /* Indicates that ath10k device is during CAC phase of DFS */ 386 /* Indicates that ath10k device is during CAC phase of DFS */
370 ATH10K_CAC_RUNNING, 387 ATH10K_CAC_RUNNING,
371 ATH10K_FLAG_CORE_REGISTERED, 388 ATH10K_FLAG_CORE_REGISTERED,
389
390 /* Device has crashed and needs to restart. This indicates any pending
391 * waiters should immediately cancel instead of waiting for a time out.
392 */
393 ATH10K_FLAG_CRASH_FLUSH,
372}; 394};
373 395
396enum ath10k_cal_mode {
397 ATH10K_CAL_MODE_FILE,
398 ATH10K_CAL_MODE_OTP,
399};
400
401static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
402{
403 switch (mode) {
404 case ATH10K_CAL_MODE_FILE:
405 return "file";
406 case ATH10K_CAL_MODE_OTP:
407 return "otp";
408 }
409
410 return "unknown";
411}
412
374enum ath10k_scan_state { 413enum ath10k_scan_state {
375 ATH10K_SCAN_IDLE, 414 ATH10K_SCAN_IDLE,
376 ATH10K_SCAN_STARTING, 415 ATH10K_SCAN_STARTING,
@@ -421,6 +460,7 @@ struct ath10k {
421 bool p2p; 460 bool p2p;
422 461
423 struct { 462 struct {
463 enum ath10k_bus bus;
424 const struct ath10k_hif_ops *ops; 464 const struct ath10k_hif_ops *ops;
425 } hif; 465 } hif;
426 466
@@ -456,7 +496,10 @@ struct ath10k {
456 const void *firmware_data; 496 const void *firmware_data;
457 size_t firmware_len; 497 size_t firmware_len;
458 498
499 const struct firmware *cal_file;
500
459 int fw_api; 501 int fw_api;
502 enum ath10k_cal_mode cal_mode;
460 503
461 struct { 504 struct {
462 struct completion started; 505 struct completion started;
@@ -482,7 +525,7 @@ struct ath10k {
482 /* current operating channel definition */ 525 /* current operating channel definition */
483 struct cfg80211_chan_def chandef; 526 struct cfg80211_chan_def chandef;
484 527
485 int free_vdev_map; 528 unsigned long long free_vdev_map;
486 bool monitor; 529 bool monitor;
487 int monitor_vdev_id; 530 int monitor_vdev_id;
488 bool monitor_started; 531 bool monitor_started;
@@ -563,11 +606,19 @@ struct ath10k {
563 bool utf_monitor; 606 bool utf_monitor;
564 } testmode; 607 } testmode;
565 608
609 struct {
610 /* protected by data_lock */
611 u32 fw_crash_counter;
612 u32 fw_warm_reset_counter;
613 u32 fw_cold_reset_counter;
614 } stats;
615
566 /* must be last */ 616 /* must be last */
567 u8 drv_priv[0] __aligned(sizeof(void *)); 617 u8 drv_priv[0] __aligned(sizeof(void *));
568}; 618};
569 619
570struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev, 620struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
621 enum ath10k_bus bus,
571 const struct ath10k_hif_ops *hif_ops); 622 const struct ath10k_hif_ops *hif_ops);
572void ath10k_core_destroy(struct ath10k *ar); 623void ath10k_core_destroy(struct ath10k *ar);
573 624
diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c
index 3756feba3223..a8f5a72ba259 100644
--- a/drivers/net/wireless/ath/ath10k/debug.c
+++ b/drivers/net/wireless/ath/ath10k/debug.c
@@ -23,6 +23,7 @@
23 23
24#include "core.h" 24#include "core.h"
25#include "debug.h" 25#include "debug.h"
26#include "hif.h"
26 27
27/* ms */ 28/* ms */
28#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000 29#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
@@ -106,34 +107,36 @@ struct ath10k_dump_file_data {
106 u8 data[0]; 107 u8 data[0];
107} __packed; 108} __packed;
108 109
109int ath10k_info(struct ath10k *ar, const char *fmt, ...) 110void ath10k_info(struct ath10k *ar, const char *fmt, ...)
110{ 111{
111 struct va_format vaf = { 112 struct va_format vaf = {
112 .fmt = fmt, 113 .fmt = fmt,
113 }; 114 };
114 va_list args; 115 va_list args;
115 int ret;
116 116
117 va_start(args, fmt); 117 va_start(args, fmt);
118 vaf.va = &args; 118 vaf.va = &args;
119 ret = dev_info(ar->dev, "%pV", &vaf); 119 dev_info(ar->dev, "%pV", &vaf);
120 trace_ath10k_log_info(ar, &vaf); 120 trace_ath10k_log_info(ar, &vaf);
121 va_end(args); 121 va_end(args);
122
123 return ret;
124} 122}
125EXPORT_SYMBOL(ath10k_info); 123EXPORT_SYMBOL(ath10k_info);
126 124
127void ath10k_print_driver_info(struct ath10k *ar) 125void ath10k_print_driver_info(struct ath10k *ar)
128{ 126{
129 ath10k_info(ar, "%s (0x%08x, 0x%08x) fw %s api %d htt %d.%d\n", 127 ath10k_info(ar, "%s (0x%08x, 0x%08x) fw %s api %d htt %d.%d wmi %d.%d.%d.%d cal %s\n",
130 ar->hw_params.name, 128 ar->hw_params.name,
131 ar->target_version, 129 ar->target_version,
132 ar->chip_id, 130 ar->chip_id,
133 ar->hw->wiphy->fw_version, 131 ar->hw->wiphy->fw_version,
134 ar->fw_api, 132 ar->fw_api,
135 ar->htt.target_version_major, 133 ar->htt.target_version_major,
136 ar->htt.target_version_minor); 134 ar->htt.target_version_minor,
135 ar->fw_version_major,
136 ar->fw_version_minor,
137 ar->fw_version_release,
138 ar->fw_version_build,
139 ath10k_cal_mode_str(ar->cal_mode));
137 ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n", 140 ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n",
138 config_enabled(CONFIG_ATH10K_DEBUG), 141 config_enabled(CONFIG_ATH10K_DEBUG),
139 config_enabled(CONFIG_ATH10K_DEBUGFS), 142 config_enabled(CONFIG_ATH10K_DEBUGFS),
@@ -143,25 +146,22 @@ void ath10k_print_driver_info(struct ath10k *ar)
143} 146}
144EXPORT_SYMBOL(ath10k_print_driver_info); 147EXPORT_SYMBOL(ath10k_print_driver_info);
145 148
146int ath10k_err(struct ath10k *ar, const char *fmt, ...) 149void ath10k_err(struct ath10k *ar, const char *fmt, ...)
147{ 150{
148 struct va_format vaf = { 151 struct va_format vaf = {
149 .fmt = fmt, 152 .fmt = fmt,
150 }; 153 };
151 va_list args; 154 va_list args;
152 int ret;
153 155
154 va_start(args, fmt); 156 va_start(args, fmt);
155 vaf.va = &args; 157 vaf.va = &args;
156 ret = dev_err(ar->dev, "%pV", &vaf); 158 dev_err(ar->dev, "%pV", &vaf);
157 trace_ath10k_log_err(ar, &vaf); 159 trace_ath10k_log_err(ar, &vaf);
158 va_end(args); 160 va_end(args);
159
160 return ret;
161} 161}
162EXPORT_SYMBOL(ath10k_err); 162EXPORT_SYMBOL(ath10k_err);
163 163
164int ath10k_warn(struct ath10k *ar, const char *fmt, ...) 164void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
165{ 165{
166 struct va_format vaf = { 166 struct va_format vaf = {
167 .fmt = fmt, 167 .fmt = fmt,
@@ -174,15 +174,13 @@ int ath10k_warn(struct ath10k *ar, const char *fmt, ...)
174 trace_ath10k_log_warn(ar, &vaf); 174 trace_ath10k_log_warn(ar, &vaf);
175 175
176 va_end(args); 176 va_end(args);
177
178 return 0;
179} 177}
180EXPORT_SYMBOL(ath10k_warn); 178EXPORT_SYMBOL(ath10k_warn);
181 179
182#ifdef CONFIG_ATH10K_DEBUGFS 180#ifdef CONFIG_ATH10K_DEBUGFS
183 181
184void ath10k_debug_read_service_map(struct ath10k *ar, 182void ath10k_debug_read_service_map(struct ath10k *ar,
185 void *service_map, 183 const void *service_map,
186 size_t map_size) 184 size_t map_size)
187{ 185{
188 memcpy(ar->debug.wmi_service_bitmap, service_map, map_size); 186 memcpy(ar->debug.wmi_service_bitmap, service_map, map_size);
@@ -242,169 +240,182 @@ static const struct file_operations fops_wmi_services = {
242 .llseek = default_llseek, 240 .llseek = default_llseek,
243}; 241};
244 242
245void ath10k_debug_read_target_stats(struct ath10k *ar, 243static void ath10k_debug_fw_stats_pdevs_free(struct list_head *head)
246 struct wmi_stats_event *ev)
247{ 244{
248 u8 *tmp = ev->data; 245 struct ath10k_fw_stats_pdev *i, *tmp;
249 struct ath10k_target_stats *stats; 246
250 int num_pdev_stats, num_vdev_stats, num_peer_stats; 247 list_for_each_entry_safe(i, tmp, head, list) {
251 struct wmi_pdev_stats_10x *ps; 248 list_del(&i->list);
252 int i; 249 kfree(i);
250 }
251}
252
253static void ath10k_debug_fw_stats_peers_free(struct list_head *head)
254{
255 struct ath10k_fw_stats_peer *i, *tmp;
256
257 list_for_each_entry_safe(i, tmp, head, list) {
258 list_del(&i->list);
259 kfree(i);
260 }
261}
253 262
263static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
264{
254 spin_lock_bh(&ar->data_lock); 265 spin_lock_bh(&ar->data_lock);
266 ar->debug.fw_stats_done = false;
267 ath10k_debug_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
268 ath10k_debug_fw_stats_peers_free(&ar->debug.fw_stats.peers);
269 spin_unlock_bh(&ar->data_lock);
270}
255 271
256 stats = &ar->debug.target_stats; 272static size_t ath10k_debug_fw_stats_num_peers(struct list_head *head)
257 273{
258 num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats); /* 0 or 1 */ 274 struct ath10k_fw_stats_peer *i;
259 num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats); /* 0 or max vdevs */ 275 size_t num = 0;
260 num_peer_stats = __le32_to_cpu(ev->num_peer_stats); /* 0 or max peers */ 276
261 277 list_for_each_entry(i, head, list)
262 if (num_pdev_stats) { 278 ++num;
263 ps = (struct wmi_pdev_stats_10x *)tmp; 279
264 280 return num;
265 stats->ch_noise_floor = __le32_to_cpu(ps->chan_nf); 281}
266 stats->tx_frame_count = __le32_to_cpu(ps->tx_frame_count); 282
267 stats->rx_frame_count = __le32_to_cpu(ps->rx_frame_count); 283void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
268 stats->rx_clear_count = __le32_to_cpu(ps->rx_clear_count); 284{
269 stats->cycle_count = __le32_to_cpu(ps->cycle_count); 285 struct ath10k_fw_stats stats = {};
270 stats->phy_err_count = __le32_to_cpu(ps->phy_err_count); 286 bool is_start, is_started, is_end;
271 stats->chan_tx_power = __le32_to_cpu(ps->chan_tx_pwr); 287 size_t num_peers;
272 288 int ret;
273 stats->comp_queued = __le32_to_cpu(ps->wal.tx.comp_queued); 289
274 stats->comp_delivered = 290 INIT_LIST_HEAD(&stats.pdevs);
275 __le32_to_cpu(ps->wal.tx.comp_delivered); 291 INIT_LIST_HEAD(&stats.peers);
276 stats->msdu_enqued = __le32_to_cpu(ps->wal.tx.msdu_enqued); 292
277 stats->mpdu_enqued = __le32_to_cpu(ps->wal.tx.mpdu_enqued); 293 spin_lock_bh(&ar->data_lock);
278 stats->wmm_drop = __le32_to_cpu(ps->wal.tx.wmm_drop); 294 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
279 stats->local_enqued = __le32_to_cpu(ps->wal.tx.local_enqued); 295 if (ret) {
280 stats->local_freed = __le32_to_cpu(ps->wal.tx.local_freed); 296 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
281 stats->hw_queued = __le32_to_cpu(ps->wal.tx.hw_queued); 297 goto unlock;
282 stats->hw_reaped = __le32_to_cpu(ps->wal.tx.hw_reaped);
283 stats->underrun = __le32_to_cpu(ps->wal.tx.underrun);
284 stats->tx_abort = __le32_to_cpu(ps->wal.tx.tx_abort);
285 stats->mpdus_requed = __le32_to_cpu(ps->wal.tx.mpdus_requed);
286 stats->tx_ko = __le32_to_cpu(ps->wal.tx.tx_ko);
287 stats->data_rc = __le32_to_cpu(ps->wal.tx.data_rc);
288 stats->self_triggers = __le32_to_cpu(ps->wal.tx.self_triggers);
289 stats->sw_retry_failure =
290 __le32_to_cpu(ps->wal.tx.sw_retry_failure);
291 stats->illgl_rate_phy_err =
292 __le32_to_cpu(ps->wal.tx.illgl_rate_phy_err);
293 stats->pdev_cont_xretry =
294 __le32_to_cpu(ps->wal.tx.pdev_cont_xretry);
295 stats->pdev_tx_timeout =
296 __le32_to_cpu(ps->wal.tx.pdev_tx_timeout);
297 stats->pdev_resets = __le32_to_cpu(ps->wal.tx.pdev_resets);
298 stats->phy_underrun = __le32_to_cpu(ps->wal.tx.phy_underrun);
299 stats->txop_ovf = __le32_to_cpu(ps->wal.tx.txop_ovf);
300
301 stats->mid_ppdu_route_change =
302 __le32_to_cpu(ps->wal.rx.mid_ppdu_route_change);
303 stats->status_rcvd = __le32_to_cpu(ps->wal.rx.status_rcvd);
304 stats->r0_frags = __le32_to_cpu(ps->wal.rx.r0_frags);
305 stats->r1_frags = __le32_to_cpu(ps->wal.rx.r1_frags);
306 stats->r2_frags = __le32_to_cpu(ps->wal.rx.r2_frags);
307 stats->r3_frags = __le32_to_cpu(ps->wal.rx.r3_frags);
308 stats->htt_msdus = __le32_to_cpu(ps->wal.rx.htt_msdus);
309 stats->htt_mpdus = __le32_to_cpu(ps->wal.rx.htt_mpdus);
310 stats->loc_msdus = __le32_to_cpu(ps->wal.rx.loc_msdus);
311 stats->loc_mpdus = __le32_to_cpu(ps->wal.rx.loc_mpdus);
312 stats->oversize_amsdu =
313 __le32_to_cpu(ps->wal.rx.oversize_amsdu);
314 stats->phy_errs = __le32_to_cpu(ps->wal.rx.phy_errs);
315 stats->phy_err_drop = __le32_to_cpu(ps->wal.rx.phy_err_drop);
316 stats->mpdu_errs = __le32_to_cpu(ps->wal.rx.mpdu_errs);
317
318 if (test_bit(ATH10K_FW_FEATURE_WMI_10X,
319 ar->fw_features)) {
320 stats->ack_rx_bad = __le32_to_cpu(ps->ack_rx_bad);
321 stats->rts_bad = __le32_to_cpu(ps->rts_bad);
322 stats->rts_good = __le32_to_cpu(ps->rts_good);
323 stats->fcs_bad = __le32_to_cpu(ps->fcs_bad);
324 stats->no_beacons = __le32_to_cpu(ps->no_beacons);
325 stats->mib_int_count = __le32_to_cpu(ps->mib_int_count);
326 tmp += sizeof(struct wmi_pdev_stats_10x);
327 } else {
328 tmp += sizeof(struct wmi_pdev_stats_old);
329 }
330 } 298 }
331 299
332 /* 0 or max vdevs */ 300 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
333 /* Currently firmware does not support VDEV stats */ 301 * splits the stats data and delivers it in a ping-pong fashion of
334 if (num_vdev_stats) { 302 * request cmd-update event.
335 struct wmi_vdev_stats *vdev_stats; 303 *
304 * However there is no explicit end-of-data. Instead start-of-data is
305 * used as an implicit one. This works as follows:
306 * a) discard stat update events until one with pdev stats is
307 * delivered - this skips session started at end of (b)
308 * b) consume stat update events until another one with pdev stats is
309 * delivered which is treated as end-of-data and is itself discarded
310 */
336 311
337 for (i = 0; i < num_vdev_stats; i++) { 312 if (ar->debug.fw_stats_done) {
338 vdev_stats = (struct wmi_vdev_stats *)tmp; 313 ath10k_warn(ar, "received unsolicited stats update event\n");
339 tmp += sizeof(struct wmi_vdev_stats); 314 goto free;
340 }
341 } 315 }
342 316
343 if (num_peer_stats) { 317 num_peers = ath10k_debug_fw_stats_num_peers(&ar->debug.fw_stats.peers);
344 struct wmi_peer_stats_10x *peer_stats; 318 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
345 struct ath10k_peer_stat *s; 319 !list_empty(&stats.pdevs));
346 320 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
347 stats->peers = num_peer_stats; 321 !list_empty(&stats.pdevs));
348 322
349 for (i = 0; i < num_peer_stats; i++) { 323 if (is_start)
350 peer_stats = (struct wmi_peer_stats_10x *)tmp; 324 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
351 s = &stats->peer_stat[i]; 325
352 326 if (is_end)
353 memcpy(s->peer_macaddr, &peer_stats->peer_macaddr.addr, 327 ar->debug.fw_stats_done = true;
354 ETH_ALEN); 328
355 s->peer_rssi = __le32_to_cpu(peer_stats->peer_rssi); 329 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
356 s->peer_tx_rate = 330
357 __le32_to_cpu(peer_stats->peer_tx_rate); 331 if (is_started && !is_end) {
358 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, 332 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
359 ar->fw_features)) { 333 /* Although this is unlikely impose a sane limit to
360 s->peer_rx_rate = 334 * prevent firmware from DoS-ing the host.
361 __le32_to_cpu(peer_stats->peer_rx_rate); 335 */
362 tmp += sizeof(struct wmi_peer_stats_10x); 336 ath10k_warn(ar, "dropping fw peer stats\n");
363 337 goto free;
364 } else {
365 tmp += sizeof(struct wmi_peer_stats_old);
366 }
367 } 338 }
339
340 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
368 } 341 }
369 342
343 complete(&ar->debug.fw_stats_complete);
344
345free:
346 /* In some cases lists have been spliced and cleared. Free up
347 * resources if that is not the case.
348 */
349 ath10k_debug_fw_stats_pdevs_free(&stats.pdevs);
350 ath10k_debug_fw_stats_peers_free(&stats.peers);
351
352unlock:
370 spin_unlock_bh(&ar->data_lock); 353 spin_unlock_bh(&ar->data_lock);
371 complete(&ar->debug.event_stats_compl);
372} 354}
373 355
374static ssize_t ath10k_read_fw_stats(struct file *file, char __user *user_buf, 356static int ath10k_debug_fw_stats_request(struct ath10k *ar)
375 size_t count, loff_t *ppos)
376{ 357{
377 struct ath10k *ar = file->private_data; 358 unsigned long timeout;
378 struct ath10k_target_stats *fw_stats;
379 char *buf = NULL;
380 unsigned int len = 0, buf_len = 8000;
381 ssize_t ret_cnt = 0;
382 long left;
383 int i;
384 int ret; 359 int ret;
385 360
386 fw_stats = &ar->debug.target_stats; 361 lockdep_assert_held(&ar->conf_mutex);
387 362
388 mutex_lock(&ar->conf_mutex); 363 timeout = jiffies + msecs_to_jiffies(1*HZ);
389 364
390 if (ar->state != ATH10K_STATE_ON) 365 ath10k_debug_fw_stats_reset(ar);
391 goto exit;
392 366
393 buf = kzalloc(buf_len, GFP_KERNEL); 367 for (;;) {
394 if (!buf) 368 if (time_after(jiffies, timeout))
395 goto exit; 369 return -ETIMEDOUT;
396 370
397 ret = ath10k_wmi_request_stats(ar, WMI_REQUEST_PEER_STAT); 371 reinit_completion(&ar->debug.fw_stats_complete);
398 if (ret) { 372
399 ath10k_warn(ar, "could not request stats (%d)\n", ret); 373 ret = ath10k_wmi_request_stats(ar, WMI_REQUEST_PEER_STAT);
400 goto exit; 374 if (ret) {
375 ath10k_warn(ar, "could not request stats (%d)\n", ret);
376 return ret;
377 }
378
379 ret = wait_for_completion_timeout(&ar->debug.fw_stats_complete,
380 1*HZ);
381 if (ret <= 0)
382 return -ETIMEDOUT;
383
384 spin_lock_bh(&ar->data_lock);
385 if (ar->debug.fw_stats_done) {
386 spin_unlock_bh(&ar->data_lock);
387 break;
388 }
389 spin_unlock_bh(&ar->data_lock);
401 } 390 }
402 391
403 left = wait_for_completion_timeout(&ar->debug.event_stats_compl, 1*HZ); 392 return 0;
404 if (left <= 0) 393}
405 goto exit; 394
395/* FIXME: How to calculate the buffer size sanely? */
396#define ATH10K_FW_STATS_BUF_SIZE (1024*1024)
397
398static void ath10k_fw_stats_fill(struct ath10k *ar,
399 struct ath10k_fw_stats *fw_stats,
400 char *buf)
401{
402 unsigned int len = 0;
403 unsigned int buf_len = ATH10K_FW_STATS_BUF_SIZE;
404 const struct ath10k_fw_stats_pdev *pdev;
405 const struct ath10k_fw_stats_peer *peer;
406 size_t num_peers;
406 407
407 spin_lock_bh(&ar->data_lock); 408 spin_lock_bh(&ar->data_lock);
409
410 pdev = list_first_entry_or_null(&fw_stats->pdevs,
411 struct ath10k_fw_stats_pdev, list);
412 if (!pdev) {
413 ath10k_warn(ar, "failed to get pdev stats\n");
414 goto unlock;
415 }
416
417 num_peers = ath10k_debug_fw_stats_num_peers(&fw_stats->peers);
418
408 len += scnprintf(buf + len, buf_len - len, "\n"); 419 len += scnprintf(buf + len, buf_len - len, "\n");
409 len += scnprintf(buf + len, buf_len - len, "%30s\n", 420 len += scnprintf(buf + len, buf_len - len, "%30s\n",
410 "ath10k PDEV stats"); 421 "ath10k PDEV stats");
@@ -412,29 +423,29 @@ static ssize_t ath10k_read_fw_stats(struct file *file, char __user *user_buf,
412 "================="); 423 "=================");
413 424
414 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 425 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
415 "Channel noise floor", fw_stats->ch_noise_floor); 426 "Channel noise floor", pdev->ch_noise_floor);
416 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 427 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
417 "Channel TX power", fw_stats->chan_tx_power); 428 "Channel TX power", pdev->chan_tx_power);
418 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 429 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
419 "TX frame count", fw_stats->tx_frame_count); 430 "TX frame count", pdev->tx_frame_count);
420 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 431 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
421 "RX frame count", fw_stats->rx_frame_count); 432 "RX frame count", pdev->rx_frame_count);
422 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 433 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
423 "RX clear count", fw_stats->rx_clear_count); 434 "RX clear count", pdev->rx_clear_count);
424 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 435 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
425 "Cycle count", fw_stats->cycle_count); 436 "Cycle count", pdev->cycle_count);
426 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 437 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
427 "PHY error count", fw_stats->phy_err_count); 438 "PHY error count", pdev->phy_err_count);
428 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 439 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
429 "RTS bad count", fw_stats->rts_bad); 440 "RTS bad count", pdev->rts_bad);
430 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 441 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
431 "RTS good count", fw_stats->rts_good); 442 "RTS good count", pdev->rts_good);
432 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 443 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
433 "FCS bad count", fw_stats->fcs_bad); 444 "FCS bad count", pdev->fcs_bad);
434 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 445 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
435 "No beacon count", fw_stats->no_beacons); 446 "No beacon count", pdev->no_beacons);
436 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 447 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
437 "MIB int count", fw_stats->mib_int_count); 448 "MIB int count", pdev->mib_int_count);
438 449
439 len += scnprintf(buf + len, buf_len - len, "\n"); 450 len += scnprintf(buf + len, buf_len - len, "\n");
440 len += scnprintf(buf + len, buf_len - len, "%30s\n", 451 len += scnprintf(buf + len, buf_len - len, "%30s\n",
@@ -443,51 +454,51 @@ static ssize_t ath10k_read_fw_stats(struct file *file, char __user *user_buf,
443 "================="); 454 "=================");
444 455
445 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 456 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
446 "HTT cookies queued", fw_stats->comp_queued); 457 "HTT cookies queued", pdev->comp_queued);
447 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 458 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
448 "HTT cookies disp.", fw_stats->comp_delivered); 459 "HTT cookies disp.", pdev->comp_delivered);
449 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 460 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
450 "MSDU queued", fw_stats->msdu_enqued); 461 "MSDU queued", pdev->msdu_enqued);
451 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 462 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
452 "MPDU queued", fw_stats->mpdu_enqued); 463 "MPDU queued", pdev->mpdu_enqued);
453 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 464 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
454 "MSDUs dropped", fw_stats->wmm_drop); 465 "MSDUs dropped", pdev->wmm_drop);
455 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 466 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
456 "Local enqued", fw_stats->local_enqued); 467 "Local enqued", pdev->local_enqued);
457 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 468 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
458 "Local freed", fw_stats->local_freed); 469 "Local freed", pdev->local_freed);
459 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 470 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
460 "HW queued", fw_stats->hw_queued); 471 "HW queued", pdev->hw_queued);
461 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 472 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
462 "PPDUs reaped", fw_stats->hw_reaped); 473 "PPDUs reaped", pdev->hw_reaped);
463 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 474 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
464 "Num underruns", fw_stats->underrun); 475 "Num underruns", pdev->underrun);
465 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 476 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
466 "PPDUs cleaned", fw_stats->tx_abort); 477 "PPDUs cleaned", pdev->tx_abort);
467 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 478 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
468 "MPDUs requed", fw_stats->mpdus_requed); 479 "MPDUs requed", pdev->mpdus_requed);
469 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 480 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
470 "Excessive retries", fw_stats->tx_ko); 481 "Excessive retries", pdev->tx_ko);
471 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 482 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
472 "HW rate", fw_stats->data_rc); 483 "HW rate", pdev->data_rc);
473 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 484 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
474 "Sched self tiggers", fw_stats->self_triggers); 485 "Sched self tiggers", pdev->self_triggers);
475 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 486 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
476 "Dropped due to SW retries", 487 "Dropped due to SW retries",
477 fw_stats->sw_retry_failure); 488 pdev->sw_retry_failure);
478 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 489 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
479 "Illegal rate phy errors", 490 "Illegal rate phy errors",
480 fw_stats->illgl_rate_phy_err); 491 pdev->illgl_rate_phy_err);
481 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 492 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
482 "Pdev continous xretry", fw_stats->pdev_cont_xretry); 493 "Pdev continous xretry", pdev->pdev_cont_xretry);
483 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 494 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
484 "TX timeout", fw_stats->pdev_tx_timeout); 495 "TX timeout", pdev->pdev_tx_timeout);
485 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 496 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
486 "PDEV resets", fw_stats->pdev_resets); 497 "PDEV resets", pdev->pdev_resets);
487 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 498 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
488 "PHY underrun", fw_stats->phy_underrun); 499 "PHY underrun", pdev->phy_underrun);
489 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 500 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
490 "MPDU is more than txop limit", fw_stats->txop_ovf); 501 "MPDU is more than txop limit", pdev->txop_ovf);
491 502
492 len += scnprintf(buf + len, buf_len - len, "\n"); 503 len += scnprintf(buf + len, buf_len - len, "\n");
493 len += scnprintf(buf + len, buf_len - len, "%30s\n", 504 len += scnprintf(buf + len, buf_len - len, "%30s\n",
@@ -497,70 +508,161 @@ static ssize_t ath10k_read_fw_stats(struct file *file, char __user *user_buf,
497 508
498 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 509 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
499 "Mid PPDU route change", 510 "Mid PPDU route change",
500 fw_stats->mid_ppdu_route_change); 511 pdev->mid_ppdu_route_change);
501 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 512 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
502 "Tot. number of statuses", fw_stats->status_rcvd); 513 "Tot. number of statuses", pdev->status_rcvd);
503 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 514 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
504 "Extra frags on rings 0", fw_stats->r0_frags); 515 "Extra frags on rings 0", pdev->r0_frags);
505 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 516 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
506 "Extra frags on rings 1", fw_stats->r1_frags); 517 "Extra frags on rings 1", pdev->r1_frags);
507 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 518 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
508 "Extra frags on rings 2", fw_stats->r2_frags); 519 "Extra frags on rings 2", pdev->r2_frags);
509 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 520 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
510 "Extra frags on rings 3", fw_stats->r3_frags); 521 "Extra frags on rings 3", pdev->r3_frags);
511 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 522 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
512 "MSDUs delivered to HTT", fw_stats->htt_msdus); 523 "MSDUs delivered to HTT", pdev->htt_msdus);
513 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 524 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
514 "MPDUs delivered to HTT", fw_stats->htt_mpdus); 525 "MPDUs delivered to HTT", pdev->htt_mpdus);
515 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 526 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
516 "MSDUs delivered to stack", fw_stats->loc_msdus); 527 "MSDUs delivered to stack", pdev->loc_msdus);
517 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 528 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
518 "MPDUs delivered to stack", fw_stats->loc_mpdus); 529 "MPDUs delivered to stack", pdev->loc_mpdus);
519 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 530 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
520 "Oversized AMSUs", fw_stats->oversize_amsdu); 531 "Oversized AMSUs", pdev->oversize_amsdu);
521 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 532 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
522 "PHY errors", fw_stats->phy_errs); 533 "PHY errors", pdev->phy_errs);
523 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 534 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
524 "PHY errors drops", fw_stats->phy_err_drop); 535 "PHY errors drops", pdev->phy_err_drop);
525 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 536 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
526 "MPDU errors (FCS, MIC, ENC)", fw_stats->mpdu_errs); 537 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
527 538
528 len += scnprintf(buf + len, buf_len - len, "\n"); 539 len += scnprintf(buf + len, buf_len - len, "\n");
529 len += scnprintf(buf + len, buf_len - len, "%30s (%d)\n", 540 len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
530 "ath10k PEER stats", fw_stats->peers); 541 "ath10k PEER stats", num_peers);
531 len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 542 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
532 "================="); 543 "=================");
533 544
534 for (i = 0; i < fw_stats->peers; i++) { 545 list_for_each_entry(peer, &fw_stats->peers, list) {
535 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", 546 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
536 "Peer MAC address", 547 "Peer MAC address", peer->peer_macaddr);
537 fw_stats->peer_stat[i].peer_macaddr);
538 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 548 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
539 "Peer RSSI", fw_stats->peer_stat[i].peer_rssi); 549 "Peer RSSI", peer->peer_rssi);
540 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 550 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
541 "Peer TX rate", 551 "Peer TX rate", peer->peer_tx_rate);
542 fw_stats->peer_stat[i].peer_tx_rate);
543 len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 552 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
544 "Peer RX rate", 553 "Peer RX rate", peer->peer_rx_rate);
545 fw_stats->peer_stat[i].peer_rx_rate);
546 len += scnprintf(buf + len, buf_len - len, "\n"); 554 len += scnprintf(buf + len, buf_len - len, "\n");
547 } 555 }
556
557unlock:
548 spin_unlock_bh(&ar->data_lock); 558 spin_unlock_bh(&ar->data_lock);
549 559
550 if (len > buf_len) 560 if (len >= buf_len)
551 len = buf_len; 561 buf[len - 1] = 0;
562 else
563 buf[len] = 0;
564}
552 565
553 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 566static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
567{
568 struct ath10k *ar = inode->i_private;
569 void *buf = NULL;
570 int ret;
571
572 mutex_lock(&ar->conf_mutex);
573
574 if (ar->state != ATH10K_STATE_ON) {
575 ret = -ENETDOWN;
576 goto err_unlock;
577 }
578
579 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
580 if (!buf) {
581 ret = -ENOMEM;
582 goto err_unlock;
583 }
584
585 ret = ath10k_debug_fw_stats_request(ar);
586 if (ret) {
587 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
588 goto err_free;
589 }
590
591 ath10k_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
592 file->private_data = buf;
554 593
555exit:
556 mutex_unlock(&ar->conf_mutex); 594 mutex_unlock(&ar->conf_mutex);
557 kfree(buf); 595 return 0;
558 return ret_cnt; 596
597err_free:
598 vfree(buf);
599
600err_unlock:
601 mutex_unlock(&ar->conf_mutex);
602 return ret;
603}
604
605static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
606{
607 vfree(file->private_data);
608
609 return 0;
610}
611
612static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
613 size_t count, loff_t *ppos)
614{
615 const char *buf = file->private_data;
616 unsigned int len = strlen(buf);
617
618 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
559} 619}
560 620
561static const struct file_operations fops_fw_stats = { 621static const struct file_operations fops_fw_stats = {
562 .read = ath10k_read_fw_stats, 622 .open = ath10k_fw_stats_open,
623 .release = ath10k_fw_stats_release,
624 .read = ath10k_fw_stats_read,
625 .owner = THIS_MODULE,
626 .llseek = default_llseek,
627};
628
629static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
630 char __user *user_buf,
631 size_t count, loff_t *ppos)
632{
633 struct ath10k *ar = file->private_data;
634 int ret, len, buf_len;
635 char *buf;
636
637 buf_len = 500;
638 buf = kmalloc(buf_len, GFP_KERNEL);
639 if (!buf)
640 return -ENOMEM;
641
642 spin_lock_bh(&ar->data_lock);
643
644 len = 0;
645 len += scnprintf(buf + len, buf_len - len,
646 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
647 len += scnprintf(buf + len, buf_len - len,
648 "fw_warm_reset_counter\t\t%d\n",
649 ar->stats.fw_warm_reset_counter);
650 len += scnprintf(buf + len, buf_len - len,
651 "fw_cold_reset_counter\t\t%d\n",
652 ar->stats.fw_cold_reset_counter);
653
654 spin_unlock_bh(&ar->data_lock);
655
656 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
657
658 kfree(buf);
659
660 return ret;
661}
662
663static const struct file_operations fops_fw_reset_stats = {
563 .open = simple_open, 664 .open = simple_open,
665 .read = ath10k_debug_fw_reset_stats_read,
564 .owner = THIS_MODULE, 666 .owner = THIS_MODULE,
565 .llseek = default_llseek, 667 .llseek = default_llseek,
566}; 668};
@@ -593,7 +695,8 @@ static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
593 "To simulate firmware crash write one of the keywords to this file:\n" 695 "To simulate firmware crash write one of the keywords to this file:\n"
594 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n" 696 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
595 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n" 697 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
596 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"; 698 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
699 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
597 700
598 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); 701 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
599} 702}
@@ -646,6 +749,10 @@ static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
646 } else if (!strcmp(buf, "assert")) { 749 } else if (!strcmp(buf, "assert")) {
647 ath10k_info(ar, "simulating firmware assert crash\n"); 750 ath10k_info(ar, "simulating firmware assert crash\n");
648 ret = ath10k_debug_fw_assert(ar); 751 ret = ath10k_debug_fw_assert(ar);
752 } else if (!strcmp(buf, "hw-restart")) {
753 ath10k_info(ar, "user requested hw restart\n");
754 queue_work(ar->workqueue, &ar->restart_work);
755 ret = 0;
649 } else { 756 } else {
650 ret = -EINVAL; 757 ret = -EINVAL;
651 goto exit; 758 goto exit;
@@ -1029,6 +1136,166 @@ exit:
1029 return ret; 1136 return ret;
1030} 1137}
1031 1138
1139/* TODO: Would be nice to always support ethtool stats, would need to
1140 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1141 * struct available..
1142 */
1143
1144/* This generally cooresponds to the debugfs fw_stats file */
1145static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1146 "tx_pkts_nic",
1147 "tx_bytes_nic",
1148 "rx_pkts_nic",
1149 "rx_bytes_nic",
1150 "d_noise_floor",
1151 "d_cycle_count",
1152 "d_phy_error",
1153 "d_rts_bad",
1154 "d_rts_good",
1155 "d_tx_power", /* in .5 dbM I think */
1156 "d_rx_crc_err", /* fcs_bad */
1157 "d_no_beacon",
1158 "d_tx_mpdus_queued",
1159 "d_tx_msdu_queued",
1160 "d_tx_msdu_dropped",
1161 "d_local_enqued",
1162 "d_local_freed",
1163 "d_tx_ppdu_hw_queued",
1164 "d_tx_ppdu_reaped",
1165 "d_tx_fifo_underrun",
1166 "d_tx_ppdu_abort",
1167 "d_tx_mpdu_requed",
1168 "d_tx_excessive_retries",
1169 "d_tx_hw_rate",
1170 "d_tx_dropped_sw_retries",
1171 "d_tx_illegal_rate",
1172 "d_tx_continuous_xretries",
1173 "d_tx_timeout",
1174 "d_tx_mpdu_txop_limit",
1175 "d_pdev_resets",
1176 "d_rx_mid_ppdu_route_change",
1177 "d_rx_status",
1178 "d_rx_extra_frags_ring0",
1179 "d_rx_extra_frags_ring1",
1180 "d_rx_extra_frags_ring2",
1181 "d_rx_extra_frags_ring3",
1182 "d_rx_msdu_htt",
1183 "d_rx_mpdu_htt",
1184 "d_rx_msdu_stack",
1185 "d_rx_mpdu_stack",
1186 "d_rx_phy_err",
1187 "d_rx_phy_err_drops",
1188 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1189 "d_fw_crash_count",
1190 "d_fw_warm_reset_count",
1191 "d_fw_cold_reset_count",
1192};
1193
1194#define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1195
1196void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1197 struct ieee80211_vif *vif,
1198 u32 sset, u8 *data)
1199{
1200 if (sset == ETH_SS_STATS)
1201 memcpy(data, *ath10k_gstrings_stats,
1202 sizeof(ath10k_gstrings_stats));
1203}
1204
1205int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1206 struct ieee80211_vif *vif, int sset)
1207{
1208 if (sset == ETH_SS_STATS)
1209 return ATH10K_SSTATS_LEN;
1210
1211 return 0;
1212}
1213
1214void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1215 struct ieee80211_vif *vif,
1216 struct ethtool_stats *stats, u64 *data)
1217{
1218 struct ath10k *ar = hw->priv;
1219 static const struct ath10k_fw_stats_pdev zero_stats = {};
1220 const struct ath10k_fw_stats_pdev *pdev_stats;
1221 int i = 0, ret;
1222
1223 mutex_lock(&ar->conf_mutex);
1224
1225 if (ar->state == ATH10K_STATE_ON) {
1226 ret = ath10k_debug_fw_stats_request(ar);
1227 if (ret) {
1228 /* just print a warning and try to use older results */
1229 ath10k_warn(ar,
1230 "failed to get fw stats for ethtool: %d\n",
1231 ret);
1232 }
1233 }
1234
1235 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1236 struct ath10k_fw_stats_pdev,
1237 list);
1238 if (!pdev_stats) {
1239 /* no results available so just return zeroes */
1240 pdev_stats = &zero_stats;
1241 }
1242
1243 spin_lock_bh(&ar->data_lock);
1244
1245 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1246 data[i++] = 0; /* tx bytes */
1247 data[i++] = pdev_stats->htt_mpdus;
1248 data[i++] = 0; /* rx bytes */
1249 data[i++] = pdev_stats->ch_noise_floor;
1250 data[i++] = pdev_stats->cycle_count;
1251 data[i++] = pdev_stats->phy_err_count;
1252 data[i++] = pdev_stats->rts_bad;
1253 data[i++] = pdev_stats->rts_good;
1254 data[i++] = pdev_stats->chan_tx_power;
1255 data[i++] = pdev_stats->fcs_bad;
1256 data[i++] = pdev_stats->no_beacons;
1257 data[i++] = pdev_stats->mpdu_enqued;
1258 data[i++] = pdev_stats->msdu_enqued;
1259 data[i++] = pdev_stats->wmm_drop;
1260 data[i++] = pdev_stats->local_enqued;
1261 data[i++] = pdev_stats->local_freed;
1262 data[i++] = pdev_stats->hw_queued;
1263 data[i++] = pdev_stats->hw_reaped;
1264 data[i++] = pdev_stats->underrun;
1265 data[i++] = pdev_stats->tx_abort;
1266 data[i++] = pdev_stats->mpdus_requed;
1267 data[i++] = pdev_stats->tx_ko;
1268 data[i++] = pdev_stats->data_rc;
1269 data[i++] = pdev_stats->sw_retry_failure;
1270 data[i++] = pdev_stats->illgl_rate_phy_err;
1271 data[i++] = pdev_stats->pdev_cont_xretry;
1272 data[i++] = pdev_stats->pdev_tx_timeout;
1273 data[i++] = pdev_stats->txop_ovf;
1274 data[i++] = pdev_stats->pdev_resets;
1275 data[i++] = pdev_stats->mid_ppdu_route_change;
1276 data[i++] = pdev_stats->status_rcvd;
1277 data[i++] = pdev_stats->r0_frags;
1278 data[i++] = pdev_stats->r1_frags;
1279 data[i++] = pdev_stats->r2_frags;
1280 data[i++] = pdev_stats->r3_frags;
1281 data[i++] = pdev_stats->htt_msdus;
1282 data[i++] = pdev_stats->htt_mpdus;
1283 data[i++] = pdev_stats->loc_msdus;
1284 data[i++] = pdev_stats->loc_mpdus;
1285 data[i++] = pdev_stats->phy_errs;
1286 data[i++] = pdev_stats->phy_err_drop;
1287 data[i++] = pdev_stats->mpdu_errs;
1288 data[i++] = ar->stats.fw_crash_counter;
1289 data[i++] = ar->stats.fw_warm_reset_counter;
1290 data[i++] = ar->stats.fw_cold_reset_counter;
1291
1292 spin_unlock_bh(&ar->data_lock);
1293
1294 mutex_unlock(&ar->conf_mutex);
1295
1296 WARN_ON(i != ATH10K_SSTATS_LEN);
1297}
1298
1032static const struct file_operations fops_fw_dbglog = { 1299static const struct file_operations fops_fw_dbglog = {
1033 .read = ath10k_read_fw_dbglog, 1300 .read = ath10k_read_fw_dbglog,
1034 .write = ath10k_write_fw_dbglog, 1301 .write = ath10k_write_fw_dbglog,
@@ -1037,6 +1304,84 @@ static const struct file_operations fops_fw_dbglog = {
1037 .llseek = default_llseek, 1304 .llseek = default_llseek,
1038}; 1305};
1039 1306
1307static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1308{
1309 struct ath10k *ar = inode->i_private;
1310 void *buf;
1311 u32 hi_addr;
1312 __le32 addr;
1313 int ret;
1314
1315 mutex_lock(&ar->conf_mutex);
1316
1317 if (ar->state != ATH10K_STATE_ON &&
1318 ar->state != ATH10K_STATE_UTF) {
1319 ret = -ENETDOWN;
1320 goto err;
1321 }
1322
1323 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1324 if (!buf) {
1325 ret = -ENOMEM;
1326 goto err;
1327 }
1328
1329 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1330
1331 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1332 if (ret) {
1333 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1334 goto err_vfree;
1335 }
1336
1337 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1338 QCA988X_CAL_DATA_LEN);
1339 if (ret) {
1340 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1341 goto err_vfree;
1342 }
1343
1344 file->private_data = buf;
1345
1346 mutex_unlock(&ar->conf_mutex);
1347
1348 return 0;
1349
1350err_vfree:
1351 vfree(buf);
1352
1353err:
1354 mutex_unlock(&ar->conf_mutex);
1355
1356 return ret;
1357}
1358
1359static ssize_t ath10k_debug_cal_data_read(struct file *file,
1360 char __user *user_buf,
1361 size_t count, loff_t *ppos)
1362{
1363 void *buf = file->private_data;
1364
1365 return simple_read_from_buffer(user_buf, count, ppos,
1366 buf, QCA988X_CAL_DATA_LEN);
1367}
1368
1369static int ath10k_debug_cal_data_release(struct inode *inode,
1370 struct file *file)
1371{
1372 vfree(file->private_data);
1373
1374 return 0;
1375}
1376
1377static const struct file_operations fops_cal_data = {
1378 .open = ath10k_debug_cal_data_open,
1379 .read = ath10k_debug_cal_data_read,
1380 .release = ath10k_debug_cal_data_release,
1381 .owner = THIS_MODULE,
1382 .llseek = default_llseek,
1383};
1384
1040int ath10k_debug_start(struct ath10k *ar) 1385int ath10k_debug_start(struct ath10k *ar)
1041{ 1386{
1042 int ret; 1387 int ret;
@@ -1057,7 +1402,22 @@ int ath10k_debug_start(struct ath10k *ar)
1057 ret); 1402 ret);
1058 } 1403 }
1059 1404
1060 return 0; 1405 if (ar->debug.pktlog_filter) {
1406 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1407 ar->debug.pktlog_filter);
1408 if (ret)
1409 /* not serious */
1410 ath10k_warn(ar,
1411 "failed to enable pktlog filter %x: %d\n",
1412 ar->debug.pktlog_filter, ret);
1413 } else {
1414 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1415 if (ret)
1416 /* not serious */
1417 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1418 }
1419
1420 return ret;
1061} 1421}
1062 1422
1063void ath10k_debug_stop(struct ath10k *ar) 1423void ath10k_debug_stop(struct ath10k *ar)
@@ -1072,6 +1432,8 @@ void ath10k_debug_stop(struct ath10k *ar)
1072 1432
1073 ar->debug.htt_max_amsdu = 0; 1433 ar->debug.htt_max_amsdu = 0;
1074 ar->debug.htt_max_ampdu = 0; 1434 ar->debug.htt_max_ampdu = 0;
1435
1436 ath10k_wmi_pdev_pktlog_disable(ar);
1075} 1437}
1076 1438
1077static ssize_t ath10k_write_simulate_radar(struct file *file, 1439static ssize_t ath10k_write_simulate_radar(struct file *file,
@@ -1154,12 +1516,78 @@ static const struct file_operations fops_dfs_stats = {
1154 .llseek = default_llseek, 1516 .llseek = default_llseek,
1155}; 1517};
1156 1518
1519static ssize_t ath10k_write_pktlog_filter(struct file *file,
1520 const char __user *ubuf,
1521 size_t count, loff_t *ppos)
1522{
1523 struct ath10k *ar = file->private_data;
1524 u32 filter;
1525 int ret;
1526
1527 if (kstrtouint_from_user(ubuf, count, 0, &filter))
1528 return -EINVAL;
1529
1530 mutex_lock(&ar->conf_mutex);
1531
1532 if (ar->state != ATH10K_STATE_ON) {
1533 ar->debug.pktlog_filter = filter;
1534 ret = count;
1535 goto out;
1536 }
1537
1538 if (filter && (filter != ar->debug.pktlog_filter)) {
1539 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
1540 if (ret) {
1541 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
1542 ar->debug.pktlog_filter, ret);
1543 goto out;
1544 }
1545 } else {
1546 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1547 if (ret) {
1548 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1549 goto out;
1550 }
1551 }
1552
1553 ar->debug.pktlog_filter = filter;
1554 ret = count;
1555
1556out:
1557 mutex_unlock(&ar->conf_mutex);
1558 return ret;
1559}
1560
1561static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
1562 size_t count, loff_t *ppos)
1563{
1564 char buf[32];
1565 struct ath10k *ar = file->private_data;
1566 int len = 0;
1567
1568 mutex_lock(&ar->conf_mutex);
1569 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
1570 ar->debug.pktlog_filter);
1571 mutex_unlock(&ar->conf_mutex);
1572
1573 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
1574}
1575
1576static const struct file_operations fops_pktlog_filter = {
1577 .read = ath10k_read_pktlog_filter,
1578 .write = ath10k_write_pktlog_filter,
1579 .open = simple_open
1580};
1581
1157int ath10k_debug_create(struct ath10k *ar) 1582int ath10k_debug_create(struct ath10k *ar)
1158{ 1583{
1159 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data)); 1584 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
1160 if (!ar->debug.fw_crash_data) 1585 if (!ar->debug.fw_crash_data)
1161 return -ENOMEM; 1586 return -ENOMEM;
1162 1587
1588 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
1589 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
1590
1163 return 0; 1591 return 0;
1164} 1592}
1165 1593
@@ -1167,6 +1595,8 @@ void ath10k_debug_destroy(struct ath10k *ar)
1167{ 1595{
1168 vfree(ar->debug.fw_crash_data); 1596 vfree(ar->debug.fw_crash_data);
1169 ar->debug.fw_crash_data = NULL; 1597 ar->debug.fw_crash_data = NULL;
1598
1599 ath10k_debug_fw_stats_reset(ar);
1170} 1600}
1171 1601
1172int ath10k_debug_register(struct ath10k *ar) 1602int ath10k_debug_register(struct ath10k *ar)
@@ -1183,11 +1613,14 @@ int ath10k_debug_register(struct ath10k *ar)
1183 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork, 1613 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
1184 ath10k_debug_htt_stats_dwork); 1614 ath10k_debug_htt_stats_dwork);
1185 1615
1186 init_completion(&ar->debug.event_stats_compl); 1616 init_completion(&ar->debug.fw_stats_complete);
1187 1617
1188 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar, 1618 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
1189 &fops_fw_stats); 1619 &fops_fw_stats);
1190 1620
1621 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
1622 ar, &fops_fw_reset_stats);
1623
1191 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar, 1624 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
1192 &fops_wmi_services); 1625 &fops_wmi_services);
1193 1626
@@ -1210,6 +1643,9 @@ int ath10k_debug_register(struct ath10k *ar)
1210 debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy, 1643 debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy,
1211 ar, &fops_fw_dbglog); 1644 ar, &fops_fw_dbglog);
1212 1645
1646 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
1647 ar, &fops_cal_data);
1648
1213 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { 1649 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
1214 debugfs_create_file("dfs_simulate_radar", S_IWUSR, 1650 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
1215 ar->debug.debugfs_phy, ar, 1651 ar->debug.debugfs_phy, ar,
@@ -1224,6 +1660,9 @@ int ath10k_debug_register(struct ath10k *ar)
1224 &fops_dfs_stats); 1660 &fops_dfs_stats);
1225 } 1661 }
1226 1662
1663 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
1664 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
1665
1227 return 0; 1666 return 0;
1228} 1667}
1229 1668
@@ -1260,11 +1699,26 @@ void ath10k_dbg_dump(struct ath10k *ar,
1260 const char *msg, const char *prefix, 1699 const char *msg, const char *prefix,
1261 const void *buf, size_t len) 1700 const void *buf, size_t len)
1262{ 1701{
1702 char linebuf[256];
1703 unsigned int linebuflen;
1704 const void *ptr;
1705
1263 if (ath10k_debug_mask & mask) { 1706 if (ath10k_debug_mask & mask) {
1264 if (msg) 1707 if (msg)
1265 ath10k_dbg(ar, mask, "%s\n", msg); 1708 ath10k_dbg(ar, mask, "%s\n", msg);
1266 1709
1267 print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len); 1710 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
1711 linebuflen = 0;
1712 linebuflen += scnprintf(linebuf + linebuflen,
1713 sizeof(linebuf) - linebuflen,
1714 "%s%08x: ",
1715 (prefix ? prefix : ""),
1716 (unsigned int)(ptr - buf));
1717 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
1718 linebuf + linebuflen,
1719 sizeof(linebuf) - linebuflen, true);
1720 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
1721 }
1268 } 1722 }
1269 1723
1270 /* tracing code doesn't like null strings :/ */ 1724 /* tracing code doesn't like null strings :/ */
diff --git a/drivers/net/wireless/ath/ath10k/debug.h b/drivers/net/wireless/ath/ath10k/debug.h
index b3774f7f492c..0c934a8378db 100644
--- a/drivers/net/wireless/ath/ath10k/debug.h
+++ b/drivers/net/wireless/ath/ath10k/debug.h
@@ -38,11 +38,20 @@ enum ath10k_debug_mask {
38 ATH10K_DBG_ANY = 0xffffffff, 38 ATH10K_DBG_ANY = 0xffffffff,
39}; 39};
40 40
41enum ath10k_pktlog_filter {
42 ATH10K_PKTLOG_RX = 0x000000001,
43 ATH10K_PKTLOG_TX = 0x000000002,
44 ATH10K_PKTLOG_RCFIND = 0x000000004,
45 ATH10K_PKTLOG_RCUPDATE = 0x000000008,
46 ATH10K_PKTLOG_DBG_PRINT = 0x000000010,
47 ATH10K_PKTLOG_ANY = 0x00000001f,
48};
49
41extern unsigned int ath10k_debug_mask; 50extern unsigned int ath10k_debug_mask;
42 51
43__printf(2, 3) int ath10k_info(struct ath10k *ar, const char *fmt, ...); 52__printf(2, 3) void ath10k_info(struct ath10k *ar, const char *fmt, ...);
44__printf(2, 3) int ath10k_err(struct ath10k *ar, const char *fmt, ...); 53__printf(2, 3) void ath10k_err(struct ath10k *ar, const char *fmt, ...);
45__printf(2, 3) int ath10k_warn(struct ath10k *ar, const char *fmt, ...); 54__printf(2, 3) void ath10k_warn(struct ath10k *ar, const char *fmt, ...);
46void ath10k_print_driver_info(struct ath10k *ar); 55void ath10k_print_driver_info(struct ath10k *ar);
47 56
48#ifdef CONFIG_ATH10K_DEBUGFS 57#ifdef CONFIG_ATH10K_DEBUGFS
@@ -53,17 +62,24 @@ void ath10k_debug_destroy(struct ath10k *ar);
53int ath10k_debug_register(struct ath10k *ar); 62int ath10k_debug_register(struct ath10k *ar);
54void ath10k_debug_unregister(struct ath10k *ar); 63void ath10k_debug_unregister(struct ath10k *ar);
55void ath10k_debug_read_service_map(struct ath10k *ar, 64void ath10k_debug_read_service_map(struct ath10k *ar,
56 void *service_map, 65 const void *service_map,
57 size_t map_size); 66 size_t map_size);
58void ath10k_debug_read_target_stats(struct ath10k *ar, 67void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb);
59 struct wmi_stats_event *ev);
60struct ath10k_fw_crash_data * 68struct ath10k_fw_crash_data *
61ath10k_debug_get_new_fw_crash_data(struct ath10k *ar); 69ath10k_debug_get_new_fw_crash_data(struct ath10k *ar);
62 70
63void ath10k_debug_dbglog_add(struct ath10k *ar, u8 *buffer, int len); 71void ath10k_debug_dbglog_add(struct ath10k *ar, u8 *buffer, int len);
64
65#define ATH10K_DFS_STAT_INC(ar, c) (ar->debug.dfs_stats.c++) 72#define ATH10K_DFS_STAT_INC(ar, c) (ar->debug.dfs_stats.c++)
66 73
74void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
75 struct ieee80211_vif *vif,
76 u32 sset, u8 *data);
77int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
78 struct ieee80211_vif *vif, int sset);
79void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
80 struct ieee80211_vif *vif,
81 struct ethtool_stats *stats, u64 *data);
82
67#else 83#else
68static inline int ath10k_debug_start(struct ath10k *ar) 84static inline int ath10k_debug_start(struct ath10k *ar)
69{ 85{
@@ -93,13 +109,13 @@ static inline void ath10k_debug_unregister(struct ath10k *ar)
93} 109}
94 110
95static inline void ath10k_debug_read_service_map(struct ath10k *ar, 111static inline void ath10k_debug_read_service_map(struct ath10k *ar,
96 void *service_map, 112 const void *service_map,
97 size_t map_size) 113 size_t map_size)
98{ 114{
99} 115}
100 116
101static inline void ath10k_debug_read_target_stats(struct ath10k *ar, 117static inline void ath10k_debug_fw_stats_process(struct ath10k *ar,
102 struct wmi_stats_event *ev) 118 struct sk_buff *skb)
103{ 119{
104} 120}
105 121
@@ -116,6 +132,10 @@ ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
116 132
117#define ATH10K_DFS_STAT_INC(ar, c) do { } while (0) 133#define ATH10K_DFS_STAT_INC(ar, c) do { } while (0)
118 134
135#define ath10k_debug_get_et_strings NULL
136#define ath10k_debug_get_et_sset_count NULL
137#define ath10k_debug_get_et_stats NULL
138
119#endif /* CONFIG_ATH10K_DEBUGFS */ 139#endif /* CONFIG_ATH10K_DEBUGFS */
120 140
121#ifdef CONFIG_ATH10K_DEBUG 141#ifdef CONFIG_ATH10K_DEBUG
diff --git a/drivers/net/wireless/ath/ath10k/hif.h b/drivers/net/wireless/ath/ath10k/hif.h
index 62323fea27e1..30301f5b6051 100644
--- a/drivers/net/wireless/ath/ath10k/hif.h
+++ b/drivers/net/wireless/ath/ath10k/hif.h
@@ -43,6 +43,10 @@ struct ath10k_hif_ops {
43 int (*tx_sg)(struct ath10k *ar, u8 pipe_id, 43 int (*tx_sg)(struct ath10k *ar, u8 pipe_id,
44 struct ath10k_hif_sg_item *items, int n_items); 44 struct ath10k_hif_sg_item *items, int n_items);
45 45
46 /* read firmware memory through the diagnose interface */
47 int (*diag_read)(struct ath10k *ar, u32 address, void *buf,
48 size_t buf_len);
49
46 /* 50 /*
47 * API to handle HIF-specific BMI message exchanges, this API is 51 * API to handle HIF-specific BMI message exchanges, this API is
48 * synchronous and only allowed to be called from a context that 52 * synchronous and only allowed to be called from a context that
@@ -98,6 +102,12 @@ static inline int ath10k_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
98 return ar->hif.ops->tx_sg(ar, pipe_id, items, n_items); 102 return ar->hif.ops->tx_sg(ar, pipe_id, items, n_items);
99} 103}
100 104
105static inline int ath10k_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
106 size_t buf_len)
107{
108 return ar->hif.ops->diag_read(ar, address, buf, buf_len);
109}
110
101static inline int ath10k_hif_exchange_bmi_msg(struct ath10k *ar, 111static inline int ath10k_hif_exchange_bmi_msg(struct ath10k *ar,
102 void *request, u32 request_len, 112 void *request, u32 request_len,
103 void *response, u32 *response_len) 113 void *response, u32 *response_len)
diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/ath/ath10k/htt.h
index 3b44217a6c19..15c58e884b6a 100644
--- a/drivers/net/wireless/ath/ath10k/htt.h
+++ b/drivers/net/wireless/ath/ath10k/htt.h
@@ -725,7 +725,7 @@ static inline u8 *htt_rx_test_get_chars(struct htt_rx_test *rx_test)
725 */ 725 */
726struct htt_pktlog_msg { 726struct htt_pktlog_msg {
727 u8 pad[3]; 727 u8 pad[3];
728 __le32 payload[1 /* or more */]; 728 u8 payload[0];
729} __packed; 729} __packed;
730 730
731struct htt_dbg_stats_rx_reorder_stats { 731struct htt_dbg_stats_rx_reorder_stats {
diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index 60d40a04508b..52c630672718 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -291,6 +291,13 @@ static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
291 htt->rx_ring.sw_rd_idx.msdu_payld = idx; 291 htt->rx_ring.sw_rd_idx.msdu_payld = idx;
292 htt->rx_ring.fill_cnt--; 292 htt->rx_ring.fill_cnt--;
293 293
294 dma_unmap_single(htt->ar->dev,
295 ATH10K_SKB_CB(msdu)->paddr,
296 msdu->len + skb_tailroom(msdu),
297 DMA_FROM_DEVICE);
298 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx netbuf pop: ",
299 msdu->data, msdu->len + skb_tailroom(msdu));
300
294 return msdu; 301 return msdu;
295} 302}
296 303
@@ -328,14 +335,6 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
328 while (msdu) { 335 while (msdu) {
329 int last_msdu, msdu_len_invalid, msdu_chained; 336 int last_msdu, msdu_len_invalid, msdu_chained;
330 337
331 dma_unmap_single(htt->ar->dev,
332 ATH10K_SKB_CB(msdu)->paddr,
333 msdu->len + skb_tailroom(msdu),
334 DMA_FROM_DEVICE);
335
336 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt rx pop: ",
337 msdu->data, msdu->len + skb_tailroom(msdu));
338
339 rx_desc = (struct htt_rx_desc *)msdu->data; 338 rx_desc = (struct htt_rx_desc *)msdu->data;
340 339
341 /* FIXME: we must report msdu payload since this is what caller 340 /* FIXME: we must report msdu payload since this is what caller
@@ -426,14 +425,14 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
426 while (msdu_chained--) { 425 while (msdu_chained--) {
427 struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt); 426 struct sk_buff *next = ath10k_htt_rx_netbuf_pop(htt);
428 427
429 dma_unmap_single(htt->ar->dev, 428 if (!next) {
430 ATH10K_SKB_CB(next)->paddr, 429 ath10k_warn(ar, "failed to pop chained msdu\n");
431 next->len + skb_tailroom(next), 430 ath10k_htt_rx_free_msdu_chain(*head_msdu);
432 DMA_FROM_DEVICE); 431 *head_msdu = NULL;
433 432 msdu = NULL;
434 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, 433 htt->rx_confused = true;
435 "htt rx chained: ", next->data, 434 break;
436 next->len + skb_tailroom(next)); 435 }
437 436
438 skb_trim(next, 0); 437 skb_trim(next, 0);
439 skb_put(next, min(msdu_len, HTT_RX_BUF_SIZE)); 438 skb_put(next, min(msdu_len, HTT_RX_BUF_SIZE));
@@ -447,6 +446,8 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
447 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) & 446 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
448 RX_MSDU_END_INFO0_LAST_MSDU; 447 RX_MSDU_END_INFO0_LAST_MSDU;
449 448
449 trace_ath10k_htt_rx_desc(ar, &rx_desc->attention,
450 sizeof(*rx_desc) - sizeof(u32));
450 if (last_msdu) { 451 if (last_msdu) {
451 msdu->next = NULL; 452 msdu->next = NULL;
452 break; 453 break;
@@ -492,6 +493,8 @@ int ath10k_htt_rx_alloc(struct ath10k_htt *htt)
492 size_t size; 493 size_t size;
493 struct timer_list *timer = &htt->rx_ring.refill_retry_timer; 494 struct timer_list *timer = &htt->rx_ring.refill_retry_timer;
494 495
496 htt->rx_confused = false;
497
495 htt->rx_ring.size = ath10k_htt_rx_ring_size(htt); 498 htt->rx_ring.size = ath10k_htt_rx_ring_size(htt);
496 if (!is_power_of_2(htt->rx_ring.size)) { 499 if (!is_power_of_2(htt->rx_ring.size)) {
497 ath10k_warn(ar, "htt rx ring size is not power of 2\n"); 500 ath10k_warn(ar, "htt rx ring size is not power of 2\n");
@@ -581,41 +584,47 @@ static int ath10k_htt_rx_crypto_param_len(struct ath10k *ar,
581 enum htt_rx_mpdu_encrypt_type type) 584 enum htt_rx_mpdu_encrypt_type type)
582{ 585{
583 switch (type) { 586 switch (type) {
587 case HTT_RX_MPDU_ENCRYPT_NONE:
588 return 0;
584 case HTT_RX_MPDU_ENCRYPT_WEP40: 589 case HTT_RX_MPDU_ENCRYPT_WEP40:
585 case HTT_RX_MPDU_ENCRYPT_WEP104: 590 case HTT_RX_MPDU_ENCRYPT_WEP104:
586 return 4; 591 return IEEE80211_WEP_IV_LEN;
587 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC: 592 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
588 case HTT_RX_MPDU_ENCRYPT_WEP128: /* not tested */
589 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA: 593 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
590 case HTT_RX_MPDU_ENCRYPT_WAPI: /* not tested */ 594 return IEEE80211_TKIP_IV_LEN;
591 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2: 595 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
592 return 8; 596 return IEEE80211_CCMP_HDR_LEN;
593 case HTT_RX_MPDU_ENCRYPT_NONE: 597 case HTT_RX_MPDU_ENCRYPT_WEP128:
594 return 0; 598 case HTT_RX_MPDU_ENCRYPT_WAPI:
599 break;
595 } 600 }
596 601
597 ath10k_warn(ar, "unknown encryption type %d\n", type); 602 ath10k_warn(ar, "unsupported encryption type %d\n", type);
598 return 0; 603 return 0;
599} 604}
600 605
606#define MICHAEL_MIC_LEN 8
607
601static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar, 608static int ath10k_htt_rx_crypto_tail_len(struct ath10k *ar,
602 enum htt_rx_mpdu_encrypt_type type) 609 enum htt_rx_mpdu_encrypt_type type)
603{ 610{
604 switch (type) { 611 switch (type) {
605 case HTT_RX_MPDU_ENCRYPT_NONE: 612 case HTT_RX_MPDU_ENCRYPT_NONE:
613 return 0;
606 case HTT_RX_MPDU_ENCRYPT_WEP40: 614 case HTT_RX_MPDU_ENCRYPT_WEP40:
607 case HTT_RX_MPDU_ENCRYPT_WEP104: 615 case HTT_RX_MPDU_ENCRYPT_WEP104:
608 case HTT_RX_MPDU_ENCRYPT_WEP128: 616 return IEEE80211_WEP_ICV_LEN;
609 case HTT_RX_MPDU_ENCRYPT_WAPI:
610 return 0;
611 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC: 617 case HTT_RX_MPDU_ENCRYPT_TKIP_WITHOUT_MIC:
612 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA: 618 case HTT_RX_MPDU_ENCRYPT_TKIP_WPA:
613 return 4; 619 return IEEE80211_TKIP_ICV_LEN;
614 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2: 620 case HTT_RX_MPDU_ENCRYPT_AES_CCM_WPA2:
615 return 8; 621 return IEEE80211_CCMP_MIC_LEN;
622 case HTT_RX_MPDU_ENCRYPT_WEP128:
623 case HTT_RX_MPDU_ENCRYPT_WAPI:
624 break;
616 } 625 }
617 626
618 ath10k_warn(ar, "unknown encryption type %d\n", type); 627 ath10k_warn(ar, "unsupported encryption type %d\n", type);
619 return 0; 628 return 0;
620} 629}
621 630
@@ -892,6 +901,8 @@ static void ath10k_process_rx(struct ath10k *ar,
892 !!(status->flag & RX_FLAG_AMSDU_MORE)); 901 !!(status->flag & RX_FLAG_AMSDU_MORE));
893 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ", 902 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
894 skb->data, skb->len); 903 skb->data, skb->len);
904 trace_ath10k_rx_hdr(ar, skb->data, skb->len);
905 trace_ath10k_rx_payload(ar, skb->data, skb->len);
895 906
896 ieee80211_rx(ar->hw, skb); 907 ieee80211_rx(ar->hw, skb);
897} 908}
@@ -1169,7 +1180,6 @@ static int ath10k_unchain_msdu(struct sk_buff *msdu_head)
1169 1180
1170static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt *htt, 1181static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt *htt,
1171 struct sk_buff *head, 1182 struct sk_buff *head,
1172 enum htt_rx_mpdu_status status,
1173 bool channel_set, 1183 bool channel_set,
1174 u32 attention) 1184 u32 attention)
1175{ 1185{
@@ -1193,22 +1203,11 @@ static bool ath10k_htt_rx_amsdu_allowed(struct ath10k_htt *htt,
1193 } 1203 }
1194 1204
1195 /* Skip mgmt frames while we handle this in WMI */ 1205 /* Skip mgmt frames while we handle this in WMI */
1196 if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL || 1206 if (attention & RX_ATTENTION_FLAGS_MGMT_TYPE) {
1197 attention & RX_ATTENTION_FLAGS_MGMT_TYPE) {
1198 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx mgmt ctrl\n"); 1207 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt rx mgmt ctrl\n");
1199 return false; 1208 return false;
1200 } 1209 }
1201 1210
1202 if (status != HTT_RX_IND_MPDU_STATUS_OK &&
1203 status != HTT_RX_IND_MPDU_STATUS_TKIP_MIC_ERR &&
1204 status != HTT_RX_IND_MPDU_STATUS_ERR_INV_PEER &&
1205 !htt->ar->monitor_started) {
1206 ath10k_dbg(ar, ATH10K_DBG_HTT,
1207 "htt rx ignoring frame w/ status %d\n",
1208 status);
1209 return false;
1210 }
1211
1212 if (test_bit(ATH10K_CAC_RUNNING, &htt->ar->dev_flags)) { 1211 if (test_bit(ATH10K_CAC_RUNNING, &htt->ar->dev_flags)) {
1213 ath10k_dbg(ar, ATH10K_DBG_HTT, 1212 ath10k_dbg(ar, ATH10K_DBG_HTT,
1214 "htt rx CAC running\n"); 1213 "htt rx CAC running\n");
@@ -1224,8 +1223,6 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1224 struct ath10k *ar = htt->ar; 1223 struct ath10k *ar = htt->ar;
1225 struct ieee80211_rx_status *rx_status = &htt->rx_status; 1224 struct ieee80211_rx_status *rx_status = &htt->rx_status;
1226 struct htt_rx_indication_mpdu_range *mpdu_ranges; 1225 struct htt_rx_indication_mpdu_range *mpdu_ranges;
1227 struct htt_rx_desc *rxd;
1228 enum htt_rx_mpdu_status status;
1229 struct ieee80211_hdr *hdr; 1226 struct ieee80211_hdr *hdr;
1230 int num_mpdu_ranges; 1227 int num_mpdu_ranges;
1231 u32 attention; 1228 u32 attention;
@@ -1273,8 +1270,6 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1273 num_mpdu_ranges)); 1270 num_mpdu_ranges));
1274 1271
1275 for (i = 0; i < num_mpdu_ranges; i++) { 1272 for (i = 0; i < num_mpdu_ranges; i++) {
1276 status = mpdu_ranges[i].mpdu_range_status;
1277
1278 for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) { 1273 for (j = 0; j < mpdu_ranges[i].mpdu_count; j++) {
1279 struct sk_buff *msdu_head, *msdu_tail; 1274 struct sk_buff *msdu_head, *msdu_tail;
1280 1275
@@ -1295,12 +1290,7 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
1295 continue; 1290 continue;
1296 } 1291 }
1297 1292
1298 rxd = container_of((void *)msdu_head->data,
1299 struct htt_rx_desc,
1300 msdu_payload);
1301
1302 if (!ath10k_htt_rx_amsdu_allowed(htt, msdu_head, 1293 if (!ath10k_htt_rx_amsdu_allowed(htt, msdu_head,
1303 status,
1304 channel_set, 1294 channel_set,
1305 attention)) { 1295 attention)) {
1306 ath10k_htt_rx_free_msdu_chain(msdu_head); 1296 ath10k_htt_rx_free_msdu_chain(msdu_head);
@@ -1365,6 +1355,8 @@ static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1365 &attention); 1355 &attention);
1366 spin_unlock_bh(&htt->rx_ring.lock); 1356 spin_unlock_bh(&htt->rx_ring.lock);
1367 1357
1358 tasklet_schedule(&htt->rx_replenish_task);
1359
1368 ath10k_dbg(ar, ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n"); 1360 ath10k_dbg(ar, ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
1369 1361
1370 if (ret) { 1362 if (ret) {
@@ -1426,7 +1418,7 @@ static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1426 /* last fragment of TKIP frags has MIC */ 1418 /* last fragment of TKIP frags has MIC */
1427 if (!ieee80211_has_morefrags(hdr->frame_control) && 1419 if (!ieee80211_has_morefrags(hdr->frame_control) &&
1428 enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA) 1420 enctype == HTT_RX_MPDU_ENCRYPT_TKIP_WPA)
1429 trim += 8; 1421 trim += MICHAEL_MIC_LEN;
1430 1422
1431 if (trim > msdu_head->len) { 1423 if (trim > msdu_head->len) {
1432 ath10k_warn(ar, "htt rx fragment: trailer longer than the frame itself? drop\n"); 1424 ath10k_warn(ar, "htt rx fragment: trailer longer than the frame itself? drop\n");
@@ -1674,6 +1666,15 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1674 case HTT_T2H_MSG_TYPE_RX_DELBA: 1666 case HTT_T2H_MSG_TYPE_RX_DELBA:
1675 ath10k_htt_rx_delba(ar, resp); 1667 ath10k_htt_rx_delba(ar, resp);
1676 break; 1668 break;
1669 case HTT_T2H_MSG_TYPE_PKTLOG: {
1670 struct ath10k_pktlog_hdr *hdr =
1671 (struct ath10k_pktlog_hdr *)resp->pktlog_msg.payload;
1672
1673 trace_ath10k_htt_pktlog(ar, resp->pktlog_msg.payload,
1674 sizeof(*hdr) +
1675 __le16_to_cpu(hdr->size));
1676 break;
1677 }
1677 case HTT_T2H_MSG_TYPE_RX_FLUSH: { 1678 case HTT_T2H_MSG_TYPE_RX_FLUSH: {
1678 /* Ignore this event because mac80211 takes care of Rx 1679 /* Ignore this event because mac80211 takes care of Rx
1679 * aggregation reordering. 1680 * aggregation reordering.
@@ -1681,8 +1682,8 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1681 break; 1682 break;
1682 } 1683 }
1683 default: 1684 default:
1684 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt event (%d) not handled\n", 1685 ath10k_warn(ar, "htt event (%d) not handled\n",
1685 resp->hdr.msg_type); 1686 resp->hdr.msg_type);
1686 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ", 1687 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt event: ",
1687 skb->data, skb->len); 1688 skb->data, skb->len);
1688 break; 1689 break;
diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireless/ath/ath10k/htt_tx.c
index bd87a35201d8..5b7e42f7377c 100644
--- a/drivers/net/wireless/ath/ath10k/htt_tx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_tx.c
@@ -92,7 +92,6 @@ int ath10k_htt_tx_alloc(struct ath10k_htt *htt)
92 struct ath10k *ar = htt->ar; 92 struct ath10k *ar = htt->ar;
93 93
94 spin_lock_init(&htt->tx_lock); 94 spin_lock_init(&htt->tx_lock);
95 init_waitqueue_head(&htt->empty_tx_wq);
96 95
97 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, htt->ar->fw_features)) 96 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, htt->ar->fw_features))
98 htt->max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC; 97 htt->max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
@@ -557,12 +556,15 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
557 skb_cb->htt.txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr); 556 skb_cb->htt.txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
558 skb_cb->htt.txbuf->cmd_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID); 557 skb_cb->htt.txbuf->cmd_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID);
559 558
559 trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
560 ath10k_dbg(ar, ATH10K_DBG_HTT, 560 ath10k_dbg(ar, ATH10K_DBG_HTT,
561 "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %08x, msdu_paddr %08x vdev %hhu tid %hhu\n", 561 "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %08x, msdu_paddr %08x vdev %hhu tid %hhu\n",
562 flags0, flags1, msdu->len, msdu_id, frags_paddr, 562 flags0, flags1, msdu->len, msdu_id, frags_paddr,
563 (u32)skb_cb->paddr, vdev_id, tid); 563 (u32)skb_cb->paddr, vdev_id, tid);
564 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ", 564 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
565 msdu->data, msdu->len); 565 msdu->data, msdu->len);
566 trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
567 trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
566 568
567 sg_items[0].transfer_id = 0; 569 sg_items[0].transfer_id = 0;
568 sg_items[0].transfer_context = NULL; 570 sg_items[0].transfer_context = NULL;
diff --git a/drivers/net/wireless/ath/ath10k/hw.h b/drivers/net/wireless/ath/ath10k/hw.h
index 3cf5702c1e7e..392c2501d0a1 100644
--- a/drivers/net/wireless/ath/ath10k/hw.h
+++ b/drivers/net/wireless/ath/ath10k/hw.h
@@ -20,15 +20,16 @@
20 20
21#include "targaddrs.h" 21#include "targaddrs.h"
22 22
23#define ATH10K_FW_DIR "ath10k"
24
23/* QCA988X 1.0 definitions (unsupported) */ 25/* QCA988X 1.0 definitions (unsupported) */
24#define QCA988X_HW_1_0_CHIP_ID_REV 0x0 26#define QCA988X_HW_1_0_CHIP_ID_REV 0x0
25 27
26/* QCA988X 2.0 definitions */ 28/* QCA988X 2.0 definitions */
27#define QCA988X_HW_2_0_VERSION 0x4100016c 29#define QCA988X_HW_2_0_VERSION 0x4100016c
28#define QCA988X_HW_2_0_CHIP_ID_REV 0x2 30#define QCA988X_HW_2_0_CHIP_ID_REV 0x2
29#define QCA988X_HW_2_0_FW_DIR "ath10k/QCA988X/hw2.0" 31#define QCA988X_HW_2_0_FW_DIR ATH10K_FW_DIR "/QCA988X/hw2.0"
30#define QCA988X_HW_2_0_FW_FILE "firmware.bin" 32#define QCA988X_HW_2_0_FW_FILE "firmware.bin"
31#define QCA988X_HW_2_0_FW_3_FILE "firmware-3.bin"
32#define QCA988X_HW_2_0_OTP_FILE "otp.bin" 33#define QCA988X_HW_2_0_OTP_FILE "otp.bin"
33#define QCA988X_HW_2_0_BOARD_DATA_FILE "board.bin" 34#define QCA988X_HW_2_0_BOARD_DATA_FILE "board.bin"
34#define QCA988X_HW_2_0_PATCH_LOAD_ADDR 0x1234 35#define QCA988X_HW_2_0_PATCH_LOAD_ADDR 0x1234
@@ -43,6 +44,8 @@
43 44
44#define REG_DUMP_COUNT_QCA988X 60 45#define REG_DUMP_COUNT_QCA988X 60
45 46
47#define QCA988X_CAL_DATA_LEN 2116
48
46struct ath10k_fw_ie { 49struct ath10k_fw_ie {
47 __le32 id; 50 __le32 id;
48 __le32 len; 51 __le32 len;
@@ -78,6 +81,15 @@ enum ath10k_mcast2ucast_mode {
78 ATH10K_MCAST2UCAST_ENABLED = 1, 81 ATH10K_MCAST2UCAST_ENABLED = 1,
79}; 82};
80 83
84struct ath10k_pktlog_hdr {
85 __le16 flags;
86 __le16 missed_cnt;
87 __le16 log_type;
88 __le16 size;
89 __le32 timestamp;
90 u8 payload[0];
91} __packed;
92
81/* Target specific defines for MAIN firmware */ 93/* Target specific defines for MAIN firmware */
82#define TARGET_NUM_VDEVS 8 94#define TARGET_NUM_VDEVS 8
83#define TARGET_NUM_PEER_AST 2 95#define TARGET_NUM_PEER_AST 2
@@ -279,6 +291,7 @@ enum ath10k_mcast2ucast_mode {
279#define SI_RX_DATA1_OFFSET 0x00000014 291#define SI_RX_DATA1_OFFSET 0x00000014
280 292
281#define CORE_CTRL_CPU_INTR_MASK 0x00002000 293#define CORE_CTRL_CPU_INTR_MASK 0x00002000
294#define CORE_CTRL_PCIE_REG_31_MASK 0x00000800
282#define CORE_CTRL_ADDRESS 0x0000 295#define CORE_CTRL_ADDRESS 0x0000
283#define PCIE_INTR_ENABLE_ADDRESS 0x0008 296#define PCIE_INTR_ENABLE_ADDRESS 0x0008
284#define PCIE_INTR_CAUSE_ADDRESS 0x000c 297#define PCIE_INTR_CAUSE_ADDRESS 0x000c
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 46709301a51e..1245ac8c5c6f 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -479,12 +479,49 @@ static void ath10k_peer_cleanup_all(struct ath10k *ar)
479/* Interface management */ 479/* Interface management */
480/************************/ 480/************************/
481 481
482void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
483{
484 struct ath10k *ar = arvif->ar;
485
486 lockdep_assert_held(&ar->data_lock);
487
488 if (!arvif->beacon)
489 return;
490
491 if (!arvif->beacon_buf)
492 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
493 arvif->beacon->len, DMA_TO_DEVICE);
494
495 dev_kfree_skb_any(arvif->beacon);
496
497 arvif->beacon = NULL;
498 arvif->beacon_sent = false;
499}
500
501static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
502{
503 struct ath10k *ar = arvif->ar;
504
505 lockdep_assert_held(&ar->data_lock);
506
507 ath10k_mac_vif_beacon_free(arvif);
508
509 if (arvif->beacon_buf) {
510 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
511 arvif->beacon_buf, arvif->beacon_paddr);
512 arvif->beacon_buf = NULL;
513 }
514}
515
482static inline int ath10k_vdev_setup_sync(struct ath10k *ar) 516static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
483{ 517{
484 int ret; 518 int ret;
485 519
486 lockdep_assert_held(&ar->conf_mutex); 520 lockdep_assert_held(&ar->conf_mutex);
487 521
522 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
523 return -ESHUTDOWN;
524
488 ret = wait_for_completion_timeout(&ar->vdev_setup_done, 525 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
489 ATH10K_VDEV_SETUP_TIMEOUT_HZ); 526 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
490 if (ret == 0) 527 if (ret == 0)
@@ -517,6 +554,8 @@ static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
517 arg.channel.max_reg_power = channel->max_reg_power * 2; 554 arg.channel.max_reg_power = channel->max_reg_power * 2;
518 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; 555 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
519 556
557 reinit_completion(&ar->vdev_setup_done);
558
520 ret = ath10k_wmi_vdev_start(ar, &arg); 559 ret = ath10k_wmi_vdev_start(ar, &arg);
521 if (ret) { 560 if (ret) {
522 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n", 561 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
@@ -564,6 +603,8 @@ static int ath10k_monitor_vdev_stop(struct ath10k *ar)
564 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n", 603 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
565 ar->monitor_vdev_id, ret); 604 ar->monitor_vdev_id, ret);
566 605
606 reinit_completion(&ar->vdev_setup_done);
607
567 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); 608 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
568 if (ret) 609 if (ret)
569 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n", 610 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
@@ -590,9 +631,9 @@ static int ath10k_monitor_vdev_create(struct ath10k *ar)
590 return -ENOMEM; 631 return -ENOMEM;
591 } 632 }
592 633
593 bit = ffs(ar->free_vdev_map); 634 bit = __ffs64(ar->free_vdev_map);
594 635
595 ar->monitor_vdev_id = bit - 1; 636 ar->monitor_vdev_id = bit;
596 637
597 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, 638 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
598 WMI_VDEV_TYPE_MONITOR, 639 WMI_VDEV_TYPE_MONITOR,
@@ -603,7 +644,7 @@ static int ath10k_monitor_vdev_create(struct ath10k *ar)
603 return ret; 644 return ret;
604 } 645 }
605 646
606 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id); 647 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n", 648 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
608 ar->monitor_vdev_id); 649 ar->monitor_vdev_id);
609 650
@@ -623,7 +664,7 @@ static int ath10k_monitor_vdev_delete(struct ath10k *ar)
623 return ret; 664 return ret;
624 } 665 }
625 666
626 ar->free_vdev_map |= 1 << ar->monitor_vdev_id; 667 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
627 668
628 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", 669 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
629 ar->monitor_vdev_id); 670 ar->monitor_vdev_id);
@@ -909,15 +950,7 @@ static void ath10k_control_beaconing(struct ath10k_vif *arvif,
909 arvif->is_up = false; 950 arvif->is_up = false;
910 951
911 spin_lock_bh(&arvif->ar->data_lock); 952 spin_lock_bh(&arvif->ar->data_lock);
912 if (arvif->beacon) { 953 ath10k_mac_vif_beacon_free(arvif);
913 dma_unmap_single(arvif->ar->dev,
914 ATH10K_SKB_CB(arvif->beacon)->paddr,
915 arvif->beacon->len, DMA_TO_DEVICE);
916 dev_kfree_skb_any(arvif->beacon);
917
918 arvif->beacon = NULL;
919 arvif->beacon_sent = false;
920 }
921 spin_unlock_bh(&arvif->ar->data_lock); 954 spin_unlock_bh(&arvif->ar->data_lock);
922 955
923 return; 956 return;
@@ -966,14 +999,6 @@ static void ath10k_control_ibss(struct ath10k_vif *arvif,
966 if (is_zero_ether_addr(arvif->bssid)) 999 if (is_zero_ether_addr(arvif->bssid))
967 return; 1000 return;
968 1001
969 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
970 arvif->bssid);
971 if (ret) {
972 ath10k_warn(ar, "failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
973 arvif->bssid, arvif->vdev_id, ret);
974 return;
975 }
976
977 memset(arvif->bssid, 0, ETH_ALEN); 1002 memset(arvif->bssid, 0, ETH_ALEN);
978 1003
979 return; 1004 return;
@@ -1042,51 +1067,45 @@ static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1042/* Station management */ 1067/* Station management */
1043/**********************/ 1068/**********************/
1044 1069
1070static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1071 struct ieee80211_vif *vif)
1072{
1073 /* Some firmware revisions have unstable STA powersave when listen
1074 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1075 * generate NullFunc frames properly even if buffered frames have been
1076 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1077 * buffered frames. Often pinging the device from AP would simply fail.
1078 *
1079 * As a workaround set it to 1.
1080 */
1081 if (vif->type == NL80211_IFTYPE_STATION)
1082 return 1;
1083
1084 return ar->hw->conf.listen_interval;
1085}
1086
1045static void ath10k_peer_assoc_h_basic(struct ath10k *ar, 1087static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1046 struct ath10k_vif *arvif, 1088 struct ieee80211_vif *vif,
1047 struct ieee80211_sta *sta, 1089 struct ieee80211_sta *sta,
1048 struct ieee80211_bss_conf *bss_conf,
1049 struct wmi_peer_assoc_complete_arg *arg) 1090 struct wmi_peer_assoc_complete_arg *arg)
1050{ 1091{
1092 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1093
1051 lockdep_assert_held(&ar->conf_mutex); 1094 lockdep_assert_held(&ar->conf_mutex);
1052 1095
1053 ether_addr_copy(arg->addr, sta->addr); 1096 ether_addr_copy(arg->addr, sta->addr);
1054 arg->vdev_id = arvif->vdev_id; 1097 arg->vdev_id = arvif->vdev_id;
1055 arg->peer_aid = sta->aid; 1098 arg->peer_aid = sta->aid;
1056 arg->peer_flags |= WMI_PEER_AUTH; 1099 arg->peer_flags |= WMI_PEER_AUTH;
1057 1100 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1058 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1059 /*
1060 * Seems FW have problems with Power Save in STA
1061 * mode when we setup this parameter to high (eg. 5).
1062 * Often we see that FW don't send NULL (with clean P flags)
1063 * frame even there is info about buffered frames in beacons.
1064 * Sometimes we have to wait more than 10 seconds before FW
1065 * will wakeup. Often sending one ping from AP to our device
1066 * just fail (more than 50%).
1067 *
1068 * Seems setting this FW parameter to 1 couse FW
1069 * will check every beacon and will wakup immediately
1070 * after detection buffered data.
1071 */
1072 arg->peer_listen_intval = 1;
1073 else
1074 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1075
1076 arg->peer_num_spatial_streams = 1; 1101 arg->peer_num_spatial_streams = 1;
1077 1102 arg->peer_caps = vif->bss_conf.assoc_capability;
1078 /*
1079 * The assoc capabilities are available only in managed mode.
1080 */
1081 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1082 arg->peer_caps = bss_conf->assoc_capability;
1083} 1103}
1084 1104
1085static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, 1105static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1086 struct ath10k_vif *arvif, 1106 struct ieee80211_vif *vif,
1087 struct wmi_peer_assoc_complete_arg *arg) 1107 struct wmi_peer_assoc_complete_arg *arg)
1088{ 1108{
1089 struct ieee80211_vif *vif = arvif->vif;
1090 struct ieee80211_bss_conf *info = &vif->bss_conf; 1109 struct ieee80211_bss_conf *info = &vif->bss_conf;
1091 struct cfg80211_bss *bss; 1110 struct cfg80211_bss *bss;
1092 const u8 *rsnie = NULL; 1111 const u8 *rsnie = NULL;
@@ -1343,11 +1362,12 @@ static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1343} 1362}
1344 1363
1345static void ath10k_peer_assoc_h_qos(struct ath10k *ar, 1364static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1346 struct ath10k_vif *arvif, 1365 struct ieee80211_vif *vif,
1347 struct ieee80211_sta *sta, 1366 struct ieee80211_sta *sta,
1348 struct ieee80211_bss_conf *bss_conf,
1349 struct wmi_peer_assoc_complete_arg *arg) 1367 struct wmi_peer_assoc_complete_arg *arg)
1350{ 1368{
1369 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1370
1351 switch (arvif->vdev_type) { 1371 switch (arvif->vdev_type) {
1352 case WMI_VDEV_TYPE_AP: 1372 case WMI_VDEV_TYPE_AP:
1353 if (sta->wme) 1373 if (sta->wme)
@@ -1359,7 +1379,7 @@ static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1359 } 1379 }
1360 break; 1380 break;
1361 case WMI_VDEV_TYPE_STA: 1381 case WMI_VDEV_TYPE_STA:
1362 if (bss_conf->qos) 1382 if (vif->bss_conf.qos)
1363 arg->peer_flags |= WMI_PEER_QOS; 1383 arg->peer_flags |= WMI_PEER_QOS;
1364 break; 1384 break;
1365 default: 1385 default:
@@ -1368,7 +1388,7 @@ static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1368} 1388}
1369 1389
1370static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, 1390static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1371 struct ath10k_vif *arvif, 1391 struct ieee80211_vif *vif,
1372 struct ieee80211_sta *sta, 1392 struct ieee80211_sta *sta,
1373 struct wmi_peer_assoc_complete_arg *arg) 1393 struct wmi_peer_assoc_complete_arg *arg)
1374{ 1394{
@@ -1419,22 +1439,21 @@ static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1419} 1439}
1420 1440
1421static int ath10k_peer_assoc_prepare(struct ath10k *ar, 1441static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1422 struct ath10k_vif *arvif, 1442 struct ieee80211_vif *vif,
1423 struct ieee80211_sta *sta, 1443 struct ieee80211_sta *sta,
1424 struct ieee80211_bss_conf *bss_conf,
1425 struct wmi_peer_assoc_complete_arg *arg) 1444 struct wmi_peer_assoc_complete_arg *arg)
1426{ 1445{
1427 lockdep_assert_held(&ar->conf_mutex); 1446 lockdep_assert_held(&ar->conf_mutex);
1428 1447
1429 memset(arg, 0, sizeof(*arg)); 1448 memset(arg, 0, sizeof(*arg));
1430 1449
1431 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg); 1450 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1432 ath10k_peer_assoc_h_crypto(ar, arvif, arg); 1451 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1433 ath10k_peer_assoc_h_rates(ar, sta, arg); 1452 ath10k_peer_assoc_h_rates(ar, sta, arg);
1434 ath10k_peer_assoc_h_ht(ar, sta, arg); 1453 ath10k_peer_assoc_h_ht(ar, sta, arg);
1435 ath10k_peer_assoc_h_vht(ar, sta, arg); 1454 ath10k_peer_assoc_h_vht(ar, sta, arg);
1436 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg); 1455 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1437 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg); 1456 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1438 1457
1439 return 0; 1458 return 0;
1440} 1459}
@@ -1480,6 +1499,9 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1480 1499
1481 lockdep_assert_held(&ar->conf_mutex); 1500 lockdep_assert_held(&ar->conf_mutex);
1482 1501
1502 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1503 arvif->vdev_id, arvif->bssid, arvif->aid);
1504
1483 rcu_read_lock(); 1505 rcu_read_lock();
1484 1506
1485 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); 1507 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
@@ -1494,8 +1516,7 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1494 * before calling ath10k_setup_peer_smps() which might sleep. */ 1516 * before calling ath10k_setup_peer_smps() which might sleep. */
1495 ht_cap = ap_sta->ht_cap; 1517 ht_cap = ap_sta->ht_cap;
1496 1518
1497 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta, 1519 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1498 bss_conf, &peer_arg);
1499 if (ret) { 1520 if (ret) {
1500 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n", 1521 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1501 bss_conf->bssid, arvif->vdev_id, ret); 1522 bss_conf->bssid, arvif->vdev_id, ret);
@@ -1523,6 +1544,8 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1523 "mac vdev %d up (associated) bssid %pM aid %d\n", 1544 "mac vdev %d up (associated) bssid %pM aid %d\n",
1524 arvif->vdev_id, bss_conf->bssid, bss_conf->aid); 1545 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1525 1546
1547 WARN_ON(arvif->is_up);
1548
1526 arvif->aid = bss_conf->aid; 1549 arvif->aid = bss_conf->aid;
1527 ether_addr_copy(arvif->bssid, bss_conf->bssid); 1550 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1528 1551
@@ -1536,9 +1559,6 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1536 arvif->is_up = true; 1559 arvif->is_up = true;
1537} 1560}
1538 1561
1539/*
1540 * FIXME: flush TIDs
1541 */
1542static void ath10k_bss_disassoc(struct ieee80211_hw *hw, 1562static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1543 struct ieee80211_vif *vif) 1563 struct ieee80211_vif *vif)
1544{ 1564{
@@ -1548,45 +1568,30 @@ static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1548 1568
1549 lockdep_assert_held(&ar->conf_mutex); 1569 lockdep_assert_held(&ar->conf_mutex);
1550 1570
1551 /* 1571 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1552 * For some reason, calling VDEV-DOWN before VDEV-STOP 1572 arvif->vdev_id, arvif->bssid);
1553 * makes the FW to send frames via HTT after disassociation.
1554 * No idea why this happens, even though VDEV-DOWN is supposed
1555 * to be analogous to link down, so just stop the VDEV.
1556 */
1557 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1558 arvif->vdev_id);
1559
1560 /* FIXME: check return value */
1561 ret = ath10k_vdev_stop(arvif);
1562 1573
1563 /*
1564 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1565 * report beacons from previously associated network through HTT.
1566 * This in turn would spam mac80211 WARN_ON if we bring down all
1567 * interfaces as it expects there is no rx when no interface is
1568 * running.
1569 */
1570 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1571
1572 /* FIXME: why don't we print error if wmi call fails? */
1573 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); 1574 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1575 if (ret)
1576 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1577 arvif->vdev_id, ret);
1574 1578
1575 arvif->def_wep_key_idx = 0; 1579 arvif->def_wep_key_idx = 0;
1576
1577 arvif->is_started = false;
1578 arvif->is_up = false; 1580 arvif->is_up = false;
1579} 1581}
1580 1582
1581static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif, 1583static int ath10k_station_assoc(struct ath10k *ar,
1582 struct ieee80211_sta *sta, bool reassoc) 1584 struct ieee80211_vif *vif,
1585 struct ieee80211_sta *sta,
1586 bool reassoc)
1583{ 1587{
1588 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1584 struct wmi_peer_assoc_complete_arg peer_arg; 1589 struct wmi_peer_assoc_complete_arg peer_arg;
1585 int ret = 0; 1590 int ret = 0;
1586 1591
1587 lockdep_assert_held(&ar->conf_mutex); 1592 lockdep_assert_held(&ar->conf_mutex);
1588 1593
1589 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg); 1594 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
1590 if (ret) { 1595 if (ret) {
1591 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n", 1596 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1592 sta->addr, arvif->vdev_id, ret); 1597 sta->addr, arvif->vdev_id, ret);
@@ -1601,43 +1606,51 @@ static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1601 return ret; 1606 return ret;
1602 } 1607 }
1603 1608
1604 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap); 1609 /* Re-assoc is run only to update supported rates for given station. It
1605 if (ret) { 1610 * doesn't make much sense to reconfigure the peer completely.
1606 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n", 1611 */
1607 arvif->vdev_id, ret); 1612 if (!reassoc) {
1608 return ret; 1613 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1609 } 1614 &sta->ht_cap);
1610
1611 if (!sta->wme && !reassoc) {
1612 arvif->num_legacy_stations++;
1613 ret = ath10k_recalc_rtscts_prot(arvif);
1614 if (ret) { 1615 if (ret) {
1615 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", 1616 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1616 arvif->vdev_id, ret); 1617 arvif->vdev_id, ret);
1617 return ret; 1618 return ret;
1618 } 1619 }
1619 }
1620 1620
1621 ret = ath10k_install_peer_wep_keys(arvif, sta->addr); 1621 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1622 if (ret) { 1622 if (ret) {
1623 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", 1623 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1624 arvif->vdev_id, ret); 1624 sta->addr, arvif->vdev_id, ret);
1625 return ret; 1625 return ret;
1626 } 1626 }
1627 1627
1628 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); 1628 if (!sta->wme) {
1629 if (ret) { 1629 arvif->num_legacy_stations++;
1630 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", 1630 ret = ath10k_recalc_rtscts_prot(arvif);
1631 sta->addr, arvif->vdev_id, ret); 1631 if (ret) {
1632 return ret; 1632 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1633 arvif->vdev_id, ret);
1634 return ret;
1635 }
1636 }
1637
1638 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1639 if (ret) {
1640 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1641 arvif->vdev_id, ret);
1642 return ret;
1643 }
1633 } 1644 }
1634 1645
1635 return ret; 1646 return ret;
1636} 1647}
1637 1648
1638static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif, 1649static int ath10k_station_disassoc(struct ath10k *ar,
1650 struct ieee80211_vif *vif,
1639 struct ieee80211_sta *sta) 1651 struct ieee80211_sta *sta)
1640{ 1652{
1653 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1641 int ret = 0; 1654 int ret = 0;
1642 1655
1643 lockdep_assert_held(&ar->conf_mutex); 1656 lockdep_assert_held(&ar->conf_mutex);
@@ -1729,6 +1742,7 @@ static int ath10k_update_channel_list(struct ath10k *ar)
1729 ch->passive = passive; 1742 ch->passive = passive;
1730 1743
1731 ch->freq = channel->center_freq; 1744 ch->freq = channel->center_freq;
1745 ch->band_center_freq1 = channel->center_freq;
1732 ch->min_power = 0; 1746 ch->min_power = 0;
1733 ch->max_power = channel->max_power * 2; 1747 ch->max_power = channel->max_power * 2;
1734 ch->max_reg_power = channel->max_reg_power * 2; 1748 ch->max_reg_power = channel->max_reg_power * 2;
@@ -2343,7 +2357,7 @@ static void ath10k_tx(struct ieee80211_hw *hw,
2343} 2357}
2344 2358
2345/* Must not be called with conf_mutex held as workers can use that also. */ 2359/* Must not be called with conf_mutex held as workers can use that also. */
2346static void ath10k_drain_tx(struct ath10k *ar) 2360void ath10k_drain_tx(struct ath10k *ar)
2347{ 2361{
2348 /* make sure rcu-protected mac80211 tx path itself is drained */ 2362 /* make sure rcu-protected mac80211 tx path itself is drained */
2349 synchronize_net(); 2363 synchronize_net();
@@ -2376,16 +2390,8 @@ void ath10k_halt(struct ath10k *ar)
2376 ath10k_hif_power_down(ar); 2390 ath10k_hif_power_down(ar);
2377 2391
2378 spin_lock_bh(&ar->data_lock); 2392 spin_lock_bh(&ar->data_lock);
2379 list_for_each_entry(arvif, &ar->arvifs, list) { 2393 list_for_each_entry(arvif, &ar->arvifs, list)
2380 if (!arvif->beacon) 2394 ath10k_mac_vif_beacon_cleanup(arvif);
2381 continue;
2382
2383 dma_unmap_single(arvif->ar->dev,
2384 ATH10K_SKB_CB(arvif->beacon)->paddr,
2385 arvif->beacon->len, DMA_TO_DEVICE);
2386 dev_kfree_skb_any(arvif->beacon);
2387 arvif->beacon = NULL;
2388 }
2389 spin_unlock_bh(&ar->data_lock); 2395 spin_unlock_bh(&ar->data_lock);
2390} 2396}
2391 2397
@@ -2677,12 +2683,68 @@ static void ath10k_config_chan(struct ath10k *ar)
2677 ath10k_monitor_recalc(ar); 2683 ath10k_monitor_recalc(ar);
2678} 2684}
2679 2685
2686static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2687{
2688 int ret;
2689 u32 param;
2690
2691 lockdep_assert_held(&ar->conf_mutex);
2692
2693 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2694
2695 param = ar->wmi.pdev_param->txpower_limit2g;
2696 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2697 if (ret) {
2698 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2699 txpower, ret);
2700 return ret;
2701 }
2702
2703 param = ar->wmi.pdev_param->txpower_limit5g;
2704 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2705 if (ret) {
2706 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2707 txpower, ret);
2708 return ret;
2709 }
2710
2711 return 0;
2712}
2713
2714static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2715{
2716 struct ath10k_vif *arvif;
2717 int ret, txpower = -1;
2718
2719 lockdep_assert_held(&ar->conf_mutex);
2720
2721 list_for_each_entry(arvif, &ar->arvifs, list) {
2722 WARN_ON(arvif->txpower < 0);
2723
2724 if (txpower == -1)
2725 txpower = arvif->txpower;
2726 else
2727 txpower = min(txpower, arvif->txpower);
2728 }
2729
2730 if (WARN_ON(txpower == -1))
2731 return -EINVAL;
2732
2733 ret = ath10k_mac_txpower_setup(ar, txpower);
2734 if (ret) {
2735 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2736 txpower, ret);
2737 return ret;
2738 }
2739
2740 return 0;
2741}
2742
2680static int ath10k_config(struct ieee80211_hw *hw, u32 changed) 2743static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2681{ 2744{
2682 struct ath10k *ar = hw->priv; 2745 struct ath10k *ar = hw->priv;
2683 struct ieee80211_conf *conf = &hw->conf; 2746 struct ieee80211_conf *conf = &hw->conf;
2684 int ret = 0; 2747 int ret = 0;
2685 u32 param;
2686 2748
2687 mutex_lock(&ar->conf_mutex); 2749 mutex_lock(&ar->conf_mutex);
2688 2750
@@ -2706,25 +2768,6 @@ static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2706 } 2768 }
2707 } 2769 }
2708 2770
2709 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2710 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
2711 hw->conf.power_level);
2712
2713 param = ar->wmi.pdev_param->txpower_limit2g;
2714 ret = ath10k_wmi_pdev_set_param(ar, param,
2715 hw->conf.power_level * 2);
2716 if (ret)
2717 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2718 hw->conf.power_level, ret);
2719
2720 param = ar->wmi.pdev_param->txpower_limit5g;
2721 ret = ath10k_wmi_pdev_set_param(ar, param,
2722 hw->conf.power_level * 2);
2723 if (ret)
2724 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2725 hw->conf.power_level, ret);
2726 }
2727
2728 if (changed & IEEE80211_CONF_CHANGE_PS) 2771 if (changed & IEEE80211_CONF_CHANGE_PS)
2729 ath10k_config_ps(ar); 2772 ath10k_config_ps(ar);
2730 2773
@@ -2772,9 +2815,12 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2772 ret = -EBUSY; 2815 ret = -EBUSY;
2773 goto err; 2816 goto err;
2774 } 2817 }
2775 bit = ffs(ar->free_vdev_map); 2818 bit = __ffs64(ar->free_vdev_map);
2819
2820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2821 bit, ar->free_vdev_map);
2776 2822
2777 arvif->vdev_id = bit - 1; 2823 arvif->vdev_id = bit;
2778 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; 2824 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2779 2825
2780 if (ar->p2p) 2826 if (ar->p2p)
@@ -2804,8 +2850,39 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2804 break; 2850 break;
2805 } 2851 }
2806 2852
2807 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n", 2853 /* Some firmware revisions don't wait for beacon tx completion before
2808 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype); 2854 * sending another SWBA event. This could lead to hardware using old
2855 * (freed) beacon data in some cases, e.g. tx credit starvation
2856 * combined with missed TBTT. This is very very rare.
2857 *
2858 * On non-IOMMU-enabled hosts this could be a possible security issue
2859 * because hw could beacon some random data on the air. On
2860 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2861 * device would crash.
2862 *
2863 * Since there are no beacon tx completions (implicit nor explicit)
2864 * propagated to host the only workaround for this is to allocate a
2865 * DMA-coherent buffer for a lifetime of a vif and use it for all
2866 * beacon tx commands. Worst case for this approach is some beacons may
2867 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2868 */
2869 if (vif->type == NL80211_IFTYPE_ADHOC ||
2870 vif->type == NL80211_IFTYPE_AP) {
2871 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2872 IEEE80211_MAX_FRAME_LEN,
2873 &arvif->beacon_paddr,
2874 GFP_ATOMIC);
2875 if (!arvif->beacon_buf) {
2876 ret = -ENOMEM;
2877 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2878 ret);
2879 goto err;
2880 }
2881 }
2882
2883 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2884 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2885 arvif->beacon_buf ? "single-buf" : "per-skb");
2809 2886
2810 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, 2887 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2811 arvif->vdev_subtype, vif->addr); 2888 arvif->vdev_subtype, vif->addr);
@@ -2815,7 +2892,7 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2815 goto err; 2892 goto err;
2816 } 2893 }
2817 2894
2818 ar->free_vdev_map &= ~(1 << arvif->vdev_id); 2895 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
2819 list_add(&arvif->list, &ar->arvifs); 2896 list_add(&arvif->list, &ar->arvifs);
2820 2897
2821 vdev_param = ar->wmi.vdev_param->def_keyid; 2898 vdev_param = ar->wmi.vdev_param->def_keyid;
@@ -2899,6 +2976,13 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2899 goto err_peer_delete; 2976 goto err_peer_delete;
2900 } 2977 }
2901 2978
2979 arvif->txpower = vif->bss_conf.txpower;
2980 ret = ath10k_mac_txpower_recalc(ar);
2981 if (ret) {
2982 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
2983 goto err_peer_delete;
2984 }
2985
2902 mutex_unlock(&ar->conf_mutex); 2986 mutex_unlock(&ar->conf_mutex);
2903 return 0; 2987 return 0;
2904 2988
@@ -2908,10 +2992,16 @@ err_peer_delete:
2908 2992
2909err_vdev_delete: 2993err_vdev_delete:
2910 ath10k_wmi_vdev_delete(ar, arvif->vdev_id); 2994 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2911 ar->free_vdev_map |= 1 << arvif->vdev_id; 2995 ar->free_vdev_map |= 1LL << arvif->vdev_id;
2912 list_del(&arvif->list); 2996 list_del(&arvif->list);
2913 2997
2914err: 2998err:
2999 if (arvif->beacon_buf) {
3000 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3001 arvif->beacon_buf, arvif->beacon_paddr);
3002 arvif->beacon_buf = NULL;
3003 }
3004
2915 mutex_unlock(&ar->conf_mutex); 3005 mutex_unlock(&ar->conf_mutex);
2916 3006
2917 return ret; 3007 return ret;
@@ -2929,14 +3019,7 @@ static void ath10k_remove_interface(struct ieee80211_hw *hw,
2929 cancel_work_sync(&arvif->wep_key_work); 3019 cancel_work_sync(&arvif->wep_key_work);
2930 3020
2931 spin_lock_bh(&ar->data_lock); 3021 spin_lock_bh(&ar->data_lock);
2932 if (arvif->beacon) { 3022 ath10k_mac_vif_beacon_cleanup(arvif);
2933 dma_unmap_single(arvif->ar->dev,
2934 ATH10K_SKB_CB(arvif->beacon)->paddr,
2935 arvif->beacon->len, DMA_TO_DEVICE);
2936 dev_kfree_skb_any(arvif->beacon);
2937 arvif->beacon = NULL;
2938 }
2939
2940 spin_unlock_bh(&ar->data_lock); 3023 spin_unlock_bh(&ar->data_lock);
2941 3024
2942 ret = ath10k_spectral_vif_stop(arvif); 3025 ret = ath10k_spectral_vif_stop(arvif);
@@ -2944,7 +3027,7 @@ static void ath10k_remove_interface(struct ieee80211_hw *hw,
2944 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", 3027 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
2945 arvif->vdev_id, ret); 3028 arvif->vdev_id, ret);
2946 3029
2947 ar->free_vdev_map |= 1 << arvif->vdev_id; 3030 ar->free_vdev_map |= 1LL << arvif->vdev_id;
2948 list_del(&arvif->list); 3031 list_del(&arvif->list);
2949 3032
2950 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { 3033 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
@@ -3068,54 +3151,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3068 arvif->u.ap.hidden_ssid = info->hidden_ssid; 3151 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3069 } 3152 }
3070 3153
3071 /* 3154 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3072 * Firmware manages AP self-peer internally so make sure to not create 3155 ether_addr_copy(arvif->bssid, info->bssid);
3073 * it in driver. Otherwise AP self-peer deletion may timeout later.
3074 */
3075 if (changed & BSS_CHANGED_BSSID &&
3076 vif->type != NL80211_IFTYPE_AP) {
3077 if (!is_zero_ether_addr(info->bssid)) {
3078 ath10k_dbg(ar, ATH10K_DBG_MAC,
3079 "mac vdev %d create peer %pM\n",
3080 arvif->vdev_id, info->bssid);
3081
3082 ret = ath10k_peer_create(ar, arvif->vdev_id,
3083 info->bssid);
3084 if (ret)
3085 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
3086 info->bssid, arvif->vdev_id, ret);
3087
3088 if (vif->type == NL80211_IFTYPE_STATION) {
3089 /*
3090 * this is never erased as we it for crypto key
3091 * clearing; this is FW requirement
3092 */
3093 ether_addr_copy(arvif->bssid, info->bssid);
3094
3095 ath10k_dbg(ar, ATH10K_DBG_MAC,
3096 "mac vdev %d start %pM\n",
3097 arvif->vdev_id, info->bssid);
3098
3099 ret = ath10k_vdev_start(arvif);
3100 if (ret) {
3101 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3102 arvif->vdev_id, ret);
3103 goto exit;
3104 }
3105
3106 arvif->is_started = true;
3107 }
3108
3109 /*
3110 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3111 * so driver need to store it. It is needed when leaving
3112 * IBSS in order to remove BSSID peer.
3113 */
3114 if (vif->type == NL80211_IFTYPE_ADHOC)
3115 memcpy(arvif->bssid, info->bssid,
3116 ETH_ALEN);
3117 }
3118 }
3119 3156
3120 if (changed & BSS_CHANGED_BEACON_ENABLED) 3157 if (changed & BSS_CHANGED_BEACON_ENABLED)
3121 ath10k_control_beaconing(arvif, info); 3158 ath10k_control_beaconing(arvif, info);
@@ -3177,10 +3214,21 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3177 ath10k_monitor_stop(ar); 3214 ath10k_monitor_stop(ar);
3178 ath10k_bss_assoc(hw, vif, info); 3215 ath10k_bss_assoc(hw, vif, info);
3179 ath10k_monitor_recalc(ar); 3216 ath10k_monitor_recalc(ar);
3217 } else {
3218 ath10k_bss_disassoc(hw, vif);
3180 } 3219 }
3181 } 3220 }
3182 3221
3183exit: 3222 if (changed & BSS_CHANGED_TXPOWER) {
3223 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3224 arvif->vdev_id, info->txpower);
3225
3226 arvif->txpower = info->txpower;
3227 ret = ath10k_mac_txpower_recalc(ar);
3228 if (ret)
3229 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3230 }
3231
3184 mutex_unlock(&ar->conf_mutex); 3232 mutex_unlock(&ar->conf_mutex);
3185} 3233}
3186 3234
@@ -3266,9 +3314,10 @@ static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3266 struct ath10k *ar = hw->priv; 3314 struct ath10k *ar = hw->priv;
3267 3315
3268 mutex_lock(&ar->conf_mutex); 3316 mutex_lock(&ar->conf_mutex);
3269 cancel_delayed_work_sync(&ar->scan.timeout);
3270 ath10k_scan_abort(ar); 3317 ath10k_scan_abort(ar);
3271 mutex_unlock(&ar->conf_mutex); 3318 mutex_unlock(&ar->conf_mutex);
3319
3320 cancel_delayed_work_sync(&ar->scan.timeout);
3272} 3321}
3273 3322
3274static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, 3323static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
@@ -3453,7 +3502,7 @@ static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3453 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n", 3502 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3454 sta->addr); 3503 sta->addr);
3455 3504
3456 err = ath10k_station_assoc(ar, arvif, sta, true); 3505 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3457 if (err) 3506 if (err)
3458 ath10k_warn(ar, "failed to reassociate station: %pM\n", 3507 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3459 sta->addr); 3508 sta->addr);
@@ -3489,8 +3538,7 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3489 mutex_lock(&ar->conf_mutex); 3538 mutex_lock(&ar->conf_mutex);
3490 3539
3491 if (old_state == IEEE80211_STA_NOTEXIST && 3540 if (old_state == IEEE80211_STA_NOTEXIST &&
3492 new_state == IEEE80211_STA_NONE && 3541 new_state == IEEE80211_STA_NONE) {
3493 vif->type != NL80211_IFTYPE_STATION) {
3494 /* 3542 /*
3495 * New station addition. 3543 * New station addition.
3496 */ 3544 */
@@ -3514,6 +3562,21 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3514 if (ret) 3562 if (ret)
3515 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n", 3563 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3516 sta->addr, arvif->vdev_id, ret); 3564 sta->addr, arvif->vdev_id, ret);
3565
3566 if (vif->type == NL80211_IFTYPE_STATION) {
3567 WARN_ON(arvif->is_started);
3568
3569 ret = ath10k_vdev_start(arvif);
3570 if (ret) {
3571 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3572 arvif->vdev_id, ret);
3573 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3574 sta->addr));
3575 goto exit;
3576 }
3577
3578 arvif->is_started = true;
3579 }
3517 } else if ((old_state == IEEE80211_STA_NONE && 3580 } else if ((old_state == IEEE80211_STA_NONE &&
3518 new_state == IEEE80211_STA_NOTEXIST)) { 3581 new_state == IEEE80211_STA_NOTEXIST)) {
3519 /* 3582 /*
@@ -3522,13 +3585,23 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3522 ath10k_dbg(ar, ATH10K_DBG_MAC, 3585 ath10k_dbg(ar, ATH10K_DBG_MAC,
3523 "mac vdev %d peer delete %pM (sta gone)\n", 3586 "mac vdev %d peer delete %pM (sta gone)\n",
3524 arvif->vdev_id, sta->addr); 3587 arvif->vdev_id, sta->addr);
3588
3589 if (vif->type == NL80211_IFTYPE_STATION) {
3590 WARN_ON(!arvif->is_started);
3591
3592 ret = ath10k_vdev_stop(arvif);
3593 if (ret)
3594 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3595 arvif->vdev_id, ret);
3596
3597 arvif->is_started = false;
3598 }
3599
3525 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); 3600 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3526 if (ret) 3601 if (ret)
3527 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n", 3602 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3528 sta->addr, arvif->vdev_id, ret); 3603 sta->addr, arvif->vdev_id, ret);
3529 3604
3530 if (vif->type == NL80211_IFTYPE_STATION)
3531 ath10k_bss_disassoc(hw, vif);
3532 } else if (old_state == IEEE80211_STA_AUTH && 3605 } else if (old_state == IEEE80211_STA_AUTH &&
3533 new_state == IEEE80211_STA_ASSOC && 3606 new_state == IEEE80211_STA_ASSOC &&
3534 (vif->type == NL80211_IFTYPE_AP || 3607 (vif->type == NL80211_IFTYPE_AP ||
@@ -3539,7 +3612,7 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3539 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", 3612 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3540 sta->addr); 3613 sta->addr);
3541 3614
3542 ret = ath10k_station_assoc(ar, arvif, sta, false); 3615 ret = ath10k_station_assoc(ar, vif, sta, false);
3543 if (ret) 3616 if (ret)
3544 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n", 3617 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3545 sta->addr, arvif->vdev_id, ret); 3618 sta->addr, arvif->vdev_id, ret);
@@ -3553,7 +3626,7 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3553 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", 3626 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3554 sta->addr); 3627 sta->addr);
3555 3628
3556 ret = ath10k_station_disassoc(ar, arvif, sta); 3629 ret = ath10k_station_disassoc(ar, vif, sta);
3557 if (ret) 3630 if (ret)
3558 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", 3631 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3559 sta->addr, arvif->vdev_id, ret); 3632 sta->addr, arvif->vdev_id, ret);
@@ -3761,10 +3834,11 @@ static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3761 struct ath10k *ar = hw->priv; 3834 struct ath10k *ar = hw->priv;
3762 3835
3763 mutex_lock(&ar->conf_mutex); 3836 mutex_lock(&ar->conf_mutex);
3764 cancel_delayed_work_sync(&ar->scan.timeout);
3765 ath10k_scan_abort(ar); 3837 ath10k_scan_abort(ar);
3766 mutex_unlock(&ar->conf_mutex); 3838 mutex_unlock(&ar->conf_mutex);
3767 3839
3840 cancel_delayed_work_sync(&ar->scan.timeout);
3841
3768 return 0; 3842 return 0;
3769} 3843}
3770 3844
@@ -3807,7 +3881,7 @@ static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3807 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n", 3881 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3808 arvif->vdev_id, value); 3882 arvif->vdev_id, value);
3809 3883
3810 ret = ath10k_mac_set_rts(arvif, value); 3884 ret = ath10k_mac_set_frag(arvif, value);
3811 if (ret) { 3885 if (ret) {
3812 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n", 3886 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
3813 arvif->vdev_id, ret); 3887 arvif->vdev_id, ret);
@@ -3843,7 +3917,9 @@ static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3843 empty = (ar->htt.num_pending_tx == 0); 3917 empty = (ar->htt.num_pending_tx == 0);
3844 spin_unlock_bh(&ar->htt.tx_lock); 3918 spin_unlock_bh(&ar->htt.tx_lock);
3845 3919
3846 skip = (ar->state == ATH10K_STATE_WEDGED); 3920 skip = (ar->state == ATH10K_STATE_WEDGED) ||
3921 test_bit(ATH10K_FLAG_CRASH_FLUSH,
3922 &ar->dev_flags);
3847 3923
3848 (empty || skip); 3924 (empty || skip);
3849 }), ATH10K_FLUSH_TIMEOUT_HZ); 3925 }), ATH10K_FLUSH_TIMEOUT_HZ);
@@ -3929,10 +4005,14 @@ exit:
3929} 4005}
3930#endif 4006#endif
3931 4007
3932static void ath10k_restart_complete(struct ieee80211_hw *hw) 4008static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4009 enum ieee80211_reconfig_type reconfig_type)
3933{ 4010{
3934 struct ath10k *ar = hw->priv; 4011 struct ath10k *ar = hw->priv;
3935 4012
4013 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4014 return;
4015
3936 mutex_lock(&ar->conf_mutex); 4016 mutex_lock(&ar->conf_mutex);
3937 4017
3938 /* If device failed to restart it will be in a different state, e.g. 4018 /* If device failed to restart it will be in a different state, e.g.
@@ -3940,6 +4020,7 @@ static void ath10k_restart_complete(struct ieee80211_hw *hw)
3940 if (ar->state == ATH10K_STATE_RESTARTED) { 4020 if (ar->state == ATH10K_STATE_RESTARTED) {
3941 ath10k_info(ar, "device successfully recovered\n"); 4021 ath10k_info(ar, "device successfully recovered\n");
3942 ar->state = ATH10K_STATE_ON; 4022 ar->state = ATH10K_STATE_ON;
4023 ieee80211_wake_queues(ar->hw);
3943 } 4024 }
3944 4025
3945 mutex_unlock(&ar->conf_mutex); 4026 mutex_unlock(&ar->conf_mutex);
@@ -3975,6 +4056,9 @@ static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3975 4056
3976 survey->channel = &sband->channels[idx]; 4057 survey->channel = &sband->channels[idx];
3977 4058
4059 if (ar->rx_channel == survey->channel)
4060 survey->filled |= SURVEY_INFO_IN_USE;
4061
3978exit: 4062exit:
3979 mutex_unlock(&ar->conf_mutex); 4063 mutex_unlock(&ar->conf_mutex);
3980 return ret; 4064 return ret;
@@ -4450,12 +4534,15 @@ static const struct ieee80211_ops ath10k_ops = {
4450 .tx_last_beacon = ath10k_tx_last_beacon, 4534 .tx_last_beacon = ath10k_tx_last_beacon,
4451 .set_antenna = ath10k_set_antenna, 4535 .set_antenna = ath10k_set_antenna,
4452 .get_antenna = ath10k_get_antenna, 4536 .get_antenna = ath10k_get_antenna,
4453 .restart_complete = ath10k_restart_complete, 4537 .reconfig_complete = ath10k_reconfig_complete,
4454 .get_survey = ath10k_get_survey, 4538 .get_survey = ath10k_get_survey,
4455 .set_bitrate_mask = ath10k_set_bitrate_mask, 4539 .set_bitrate_mask = ath10k_set_bitrate_mask,
4456 .sta_rc_update = ath10k_sta_rc_update, 4540 .sta_rc_update = ath10k_sta_rc_update,
4457 .get_tsf = ath10k_get_tsf, 4541 .get_tsf = ath10k_get_tsf,
4458 .ampdu_action = ath10k_ampdu_action, 4542 .ampdu_action = ath10k_ampdu_action,
4543 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4544 .get_et_stats = ath10k_debug_get_et_stats,
4545 .get_et_strings = ath10k_debug_get_et_strings,
4459 4546
4460 CFG80211_TESTMODE_CMD(ath10k_tm_cmd) 4547 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4461 4548
@@ -4800,15 +4887,6 @@ int ath10k_mac_register(struct ath10k *ar)
4800 BIT(NL80211_IFTYPE_STATION) | 4887 BIT(NL80211_IFTYPE_STATION) |
4801 BIT(NL80211_IFTYPE_AP); 4888 BIT(NL80211_IFTYPE_AP);
4802 4889
4803 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4804 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4805 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4806 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4807 } else {
4808 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4809 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4810 }
4811
4812 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask; 4890 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4813 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask; 4891 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4814 4892
@@ -4854,6 +4932,8 @@ int ath10k_mac_register(struct ath10k *ar)
4854 ar->hw->wiphy->max_remain_on_channel_duration = 5000; 4932 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4855 4933
4856 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 4934 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4935 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
4936
4857 /* 4937 /*
4858 * on LL hardware queues are managed entirely by the FW 4938 * on LL hardware queues are managed entirely by the FW
4859 * so we only advertise to mac we can do the queues thing 4939 * so we only advertise to mac we can do the queues thing
diff --git a/drivers/net/wireless/ath/ath10k/mac.h b/drivers/net/wireless/ath/ath10k/mac.h
index 6c80eeada3e2..4e3c989aa841 100644
--- a/drivers/net/wireless/ath/ath10k/mac.h
+++ b/drivers/net/wireless/ath/ath10k/mac.h
@@ -39,6 +39,8 @@ void ath10k_offchan_tx_work(struct work_struct *work);
39void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar); 39void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar);
40void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work); 40void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work);
41void ath10k_halt(struct ath10k *ar); 41void ath10k_halt(struct ath10k *ar);
42void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif);
43void ath10k_drain_tx(struct ath10k *ar);
42 44
43static inline struct ath10k_vif *ath10k_vif_to_arvif(struct ieee80211_vif *vif) 45static inline struct ath10k_vif *ath10k_vif_to_arvif(struct ieee80211_vif *vif)
44{ 46{
diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index 59e0ea83be50..3a6b8a5ca96c 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -485,6 +485,8 @@ static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
485 void *data_buf = NULL; 485 void *data_buf = NULL;
486 int i; 486 int i;
487 487
488 spin_lock_bh(&ar_pci->ce_lock);
489
488 ce_diag = ar_pci->ce_diag; 490 ce_diag = ar_pci->ce_diag;
489 491
490 /* 492 /*
@@ -511,7 +513,7 @@ static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
511 nbytes = min_t(unsigned int, remaining_bytes, 513 nbytes = min_t(unsigned int, remaining_bytes,
512 DIAG_TRANSFER_LIMIT); 514 DIAG_TRANSFER_LIMIT);
513 515
514 ret = ath10k_ce_rx_post_buf(ce_diag, NULL, ce_data); 516 ret = __ath10k_ce_rx_post_buf(ce_diag, NULL, ce_data);
515 if (ret != 0) 517 if (ret != 0)
516 goto done; 518 goto done;
517 519
@@ -527,15 +529,15 @@ static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
527 address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem, 529 address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem,
528 address); 530 address);
529 531
530 ret = ath10k_ce_send(ce_diag, NULL, (u32)address, nbytes, 0, 532 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
531 0); 533 0);
532 if (ret) 534 if (ret)
533 goto done; 535 goto done;
534 536
535 i = 0; 537 i = 0;
536 while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf, 538 while (ath10k_ce_completed_send_next_nolock(ce_diag, NULL, &buf,
537 &completed_nbytes, 539 &completed_nbytes,
538 &id) != 0) { 540 &id) != 0) {
539 mdelay(1); 541 mdelay(1);
540 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { 542 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
541 ret = -EBUSY; 543 ret = -EBUSY;
@@ -554,9 +556,9 @@ static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
554 } 556 }
555 557
556 i = 0; 558 i = 0;
557 while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf, 559 while (ath10k_ce_completed_recv_next_nolock(ce_diag, NULL, &buf,
558 &completed_nbytes, 560 &completed_nbytes,
559 &id, &flags) != 0) { 561 &id, &flags) != 0) {
560 mdelay(1); 562 mdelay(1);
561 563
562 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { 564 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
@@ -591,6 +593,8 @@ done:
591 dma_free_coherent(ar->dev, orig_nbytes, data_buf, 593 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
592 ce_data_base); 594 ce_data_base);
593 595
596 spin_unlock_bh(&ar_pci->ce_lock);
597
594 return ret; 598 return ret;
595} 599}
596 600
@@ -648,6 +652,8 @@ static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
648 dma_addr_t ce_data_base = 0; 652 dma_addr_t ce_data_base = 0;
649 int i; 653 int i;
650 654
655 spin_lock_bh(&ar_pci->ce_lock);
656
651 ce_diag = ar_pci->ce_diag; 657 ce_diag = ar_pci->ce_diag;
652 658
653 /* 659 /*
@@ -688,7 +694,7 @@ static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
688 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT); 694 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
689 695
690 /* Set up to receive directly into Target(!) address */ 696 /* Set up to receive directly into Target(!) address */
691 ret = ath10k_ce_rx_post_buf(ce_diag, NULL, address); 697 ret = __ath10k_ce_rx_post_buf(ce_diag, NULL, address);
692 if (ret != 0) 698 if (ret != 0)
693 goto done; 699 goto done;
694 700
@@ -696,15 +702,15 @@ static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
696 * Request CE to send caller-supplied data that 702 * Request CE to send caller-supplied data that
697 * was copied to bounce buffer to Target(!) address. 703 * was copied to bounce buffer to Target(!) address.
698 */ 704 */
699 ret = ath10k_ce_send(ce_diag, NULL, (u32)ce_data, 705 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
700 nbytes, 0, 0); 706 nbytes, 0, 0);
701 if (ret != 0) 707 if (ret != 0)
702 goto done; 708 goto done;
703 709
704 i = 0; 710 i = 0;
705 while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf, 711 while (ath10k_ce_completed_send_next_nolock(ce_diag, NULL, &buf,
706 &completed_nbytes, 712 &completed_nbytes,
707 &id) != 0) { 713 &id) != 0) {
708 mdelay(1); 714 mdelay(1);
709 715
710 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { 716 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
@@ -724,9 +730,9 @@ static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
724 } 730 }
725 731
726 i = 0; 732 i = 0;
727 while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf, 733 while (ath10k_ce_completed_recv_next_nolock(ce_diag, NULL, &buf,
728 &completed_nbytes, 734 &completed_nbytes,
729 &id, &flags) != 0) { 735 &id, &flags) != 0) {
730 mdelay(1); 736 mdelay(1);
731 737
732 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { 738 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
@@ -760,6 +766,8 @@ done:
760 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n", 766 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
761 address, ret); 767 address, ret);
762 768
769 spin_unlock_bh(&ar_pci->ce_lock);
770
763 return ret; 771 return ret;
764} 772}
765 773
@@ -861,6 +869,12 @@ static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe *ce_state)
861 } 869 }
862 870
863 skb_put(skb, nbytes); 871 skb_put(skb, nbytes);
872
873 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
874 ce_state->id, skb->len);
875 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
876 skb->data, skb->len);
877
864 cb->rx_completion(ar, skb, pipe_info->pipe_num); 878 cb->rx_completion(ar, skb, pipe_info->pipe_num);
865 } 879 }
866 880
@@ -936,6 +950,12 @@ err:
936 return err; 950 return err;
937} 951}
938 952
953static int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
954 size_t buf_len)
955{
956 return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
957}
958
939static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe) 959static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
940{ 960{
941 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 961 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
@@ -986,6 +1006,8 @@ static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
986 1006
987 spin_lock_bh(&ar->data_lock); 1007 spin_lock_bh(&ar->data_lock);
988 1008
1009 ar->stats.fw_crash_counter++;
1010
989 crash_data = ath10k_debug_get_new_fw_crash_data(ar); 1011 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
990 1012
991 if (crash_data) 1013 if (crash_data)
@@ -1121,14 +1143,37 @@ static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1121 &dl_is_polled); 1143 &dl_is_polled);
1122} 1144}
1123 1145
1124static void ath10k_pci_irq_disable(struct ath10k *ar) 1146static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
1125{ 1147{
1126 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1148 u32 val;
1127 int i; 1149
1150 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS);
1151 val &= ~CORE_CTRL_PCIE_REG_31_MASK;
1152
1153 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS, val);
1154}
1155
1156static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
1157{
1158 u32 val;
1128 1159
1160 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS);
1161 val |= CORE_CTRL_PCIE_REG_31_MASK;
1162
1163 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS, val);
1164}
1165
1166static void ath10k_pci_irq_disable(struct ath10k *ar)
1167{
1129 ath10k_ce_disable_interrupts(ar); 1168 ath10k_ce_disable_interrupts(ar);
1130 ath10k_pci_disable_and_clear_legacy_irq(ar); 1169 ath10k_pci_disable_and_clear_legacy_irq(ar);
1131 /* FIXME: How to mask all MSI interrupts? */ 1170 ath10k_pci_irq_msi_fw_mask(ar);
1171}
1172
1173static void ath10k_pci_irq_sync(struct ath10k *ar)
1174{
1175 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1176 int i;
1132 1177
1133 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++) 1178 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1134 synchronize_irq(ar_pci->pdev->irq + i); 1179 synchronize_irq(ar_pci->pdev->irq + i);
@@ -1138,7 +1183,7 @@ static void ath10k_pci_irq_enable(struct ath10k *ar)
1138{ 1183{
1139 ath10k_ce_enable_interrupts(ar); 1184 ath10k_ce_enable_interrupts(ar);
1140 ath10k_pci_enable_legacy_irq(ar); 1185 ath10k_pci_enable_legacy_irq(ar);
1141 /* FIXME: How to unmask all MSI interrupts? */ 1186 ath10k_pci_irq_msi_fw_unmask(ar);
1142} 1187}
1143 1188
1144static int ath10k_pci_hif_start(struct ath10k *ar) 1189static int ath10k_pci_hif_start(struct ath10k *ar)
@@ -1151,64 +1196,74 @@ static int ath10k_pci_hif_start(struct ath10k *ar)
1151 return 0; 1196 return 0;
1152} 1197}
1153 1198
1154static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info) 1199static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
1155{ 1200{
1156 struct ath10k *ar; 1201 struct ath10k *ar;
1157 struct ath10k_pci *ar_pci; 1202 struct ath10k_ce_pipe *ce_pipe;
1158 struct ath10k_ce_pipe *ce_hdl; 1203 struct ath10k_ce_ring *ce_ring;
1159 u32 buf_sz; 1204 struct sk_buff *skb;
1160 struct sk_buff *netbuf; 1205 int i;
1161 u32 ce_data;
1162 1206
1163 buf_sz = pipe_info->buf_sz; 1207 ar = pci_pipe->hif_ce_state;
1208 ce_pipe = pci_pipe->ce_hdl;
1209 ce_ring = ce_pipe->dest_ring;
1164 1210
1165 /* Unused Copy Engine */ 1211 if (!ce_ring)
1166 if (buf_sz == 0)
1167 return; 1212 return;
1168 1213
1169 ar = pipe_info->hif_ce_state; 1214 if (!pci_pipe->buf_sz)
1170 ar_pci = ath10k_pci_priv(ar); 1215 return;
1171 ce_hdl = pipe_info->ce_hdl;
1172 1216
1173 while (ath10k_ce_revoke_recv_next(ce_hdl, (void **)&netbuf, 1217 for (i = 0; i < ce_ring->nentries; i++) {
1174 &ce_data) == 0) { 1218 skb = ce_ring->per_transfer_context[i];
1175 dma_unmap_single(ar->dev, ATH10K_SKB_CB(netbuf)->paddr, 1219 if (!skb)
1176 netbuf->len + skb_tailroom(netbuf), 1220 continue;
1221
1222 ce_ring->per_transfer_context[i] = NULL;
1223
1224 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
1225 skb->len + skb_tailroom(skb),
1177 DMA_FROM_DEVICE); 1226 DMA_FROM_DEVICE);
1178 dev_kfree_skb_any(netbuf); 1227 dev_kfree_skb_any(skb);
1179 } 1228 }
1180} 1229}
1181 1230
1182static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info) 1231static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
1183{ 1232{
1184 struct ath10k *ar; 1233 struct ath10k *ar;
1185 struct ath10k_pci *ar_pci; 1234 struct ath10k_pci *ar_pci;
1186 struct ath10k_ce_pipe *ce_hdl; 1235 struct ath10k_ce_pipe *ce_pipe;
1187 struct sk_buff *netbuf; 1236 struct ath10k_ce_ring *ce_ring;
1188 u32 ce_data; 1237 struct ce_desc *ce_desc;
1189 unsigned int nbytes; 1238 struct sk_buff *skb;
1190 unsigned int id; 1239 unsigned int id;
1191 u32 buf_sz; 1240 int i;
1192 1241
1193 buf_sz = pipe_info->buf_sz; 1242 ar = pci_pipe->hif_ce_state;
1243 ar_pci = ath10k_pci_priv(ar);
1244 ce_pipe = pci_pipe->ce_hdl;
1245 ce_ring = ce_pipe->src_ring;
1194 1246
1195 /* Unused Copy Engine */ 1247 if (!ce_ring)
1196 if (buf_sz == 0)
1197 return; 1248 return;
1198 1249
1199 ar = pipe_info->hif_ce_state; 1250 if (!pci_pipe->buf_sz)
1200 ar_pci = ath10k_pci_priv(ar); 1251 return;
1201 ce_hdl = pipe_info->ce_hdl;
1202 1252
1203 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf, 1253 ce_desc = ce_ring->shadow_base;
1204 &ce_data, &nbytes, &id) == 0) { 1254 if (WARN_ON(!ce_desc))
1205 /* no need to call tx completion for NULL pointers */ 1255 return;
1206 if (!netbuf) 1256
1257 for (i = 0; i < ce_ring->nentries; i++) {
1258 skb = ce_ring->per_transfer_context[i];
1259 if (!skb)
1207 continue; 1260 continue;
1208 1261
1209 ar_pci->msg_callbacks_current.tx_completion(ar, 1262 ce_ring->per_transfer_context[i] = NULL;
1210 netbuf, 1263 id = MS(__le16_to_cpu(ce_desc[i].flags),
1211 id); 1264 CE_DESC_FLAGS_META_DATA);
1265
1266 ar_pci->msg_callbacks_current.tx_completion(ar, skb, id);
1212 } 1267 }
1213} 1268}
1214 1269
@@ -1266,6 +1321,7 @@ static void ath10k_pci_hif_stop(struct ath10k *ar)
1266 ath10k_pci_warm_reset(ar); 1321 ath10k_pci_warm_reset(ar);
1267 1322
1268 ath10k_pci_irq_disable(ar); 1323 ath10k_pci_irq_disable(ar);
1324 ath10k_pci_irq_sync(ar);
1269 ath10k_pci_flush(ar); 1325 ath10k_pci_flush(ar);
1270} 1326}
1271 1327
@@ -1386,6 +1442,9 @@ static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
1386 &nbytes, &transfer_id, &flags)) 1442 &nbytes, &transfer_id, &flags))
1387 return; 1443 return;
1388 1444
1445 if (WARN_ON_ONCE(!xfer))
1446 return;
1447
1389 if (!xfer->wait_for_resp) { 1448 if (!xfer->wait_for_resp) {
1390 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n"); 1449 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
1391 return; 1450 return;
@@ -1569,23 +1628,40 @@ static int ath10k_pci_init_config(struct ath10k *ar)
1569 return 0; 1628 return 0;
1570} 1629}
1571 1630
1572static int ath10k_pci_alloc_ce(struct ath10k *ar) 1631static int ath10k_pci_alloc_pipes(struct ath10k *ar)
1573{ 1632{
1633 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1634 struct ath10k_pci_pipe *pipe;
1574 int i, ret; 1635 int i, ret;
1575 1636
1576 for (i = 0; i < CE_COUNT; i++) { 1637 for (i = 0; i < CE_COUNT; i++) {
1577 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]); 1638 pipe = &ar_pci->pipe_info[i];
1639 pipe->ce_hdl = &ar_pci->ce_states[i];
1640 pipe->pipe_num = i;
1641 pipe->hif_ce_state = ar;
1642
1643 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i],
1644 ath10k_pci_ce_send_done,
1645 ath10k_pci_ce_recv_data);
1578 if (ret) { 1646 if (ret) {
1579 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n", 1647 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
1580 i, ret); 1648 i, ret);
1581 return ret; 1649 return ret;
1582 } 1650 }
1651
1652 /* Last CE is Diagnostic Window */
1653 if (i == CE_COUNT - 1) {
1654 ar_pci->ce_diag = pipe->ce_hdl;
1655 continue;
1656 }
1657
1658 pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
1583 } 1659 }
1584 1660
1585 return 0; 1661 return 0;
1586} 1662}
1587 1663
1588static void ath10k_pci_free_ce(struct ath10k *ar) 1664static void ath10k_pci_free_pipes(struct ath10k *ar)
1589{ 1665{
1590 int i; 1666 int i;
1591 1667
@@ -1593,39 +1669,17 @@ static void ath10k_pci_free_ce(struct ath10k *ar)
1593 ath10k_ce_free_pipe(ar, i); 1669 ath10k_ce_free_pipe(ar, i);
1594} 1670}
1595 1671
1596static int ath10k_pci_ce_init(struct ath10k *ar) 1672static int ath10k_pci_init_pipes(struct ath10k *ar)
1597{ 1673{
1598 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1674 int i, ret;
1599 struct ath10k_pci_pipe *pipe_info;
1600 const struct ce_attr *attr;
1601 int pipe_num, ret;
1602 1675
1603 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) { 1676 for (i = 0; i < CE_COUNT; i++) {
1604 pipe_info = &ar_pci->pipe_info[pipe_num]; 1677 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
1605 pipe_info->ce_hdl = &ar_pci->ce_states[pipe_num];
1606 pipe_info->pipe_num = pipe_num;
1607 pipe_info->hif_ce_state = ar;
1608 attr = &host_ce_config_wlan[pipe_num];
1609
1610 ret = ath10k_ce_init_pipe(ar, pipe_num, attr,
1611 ath10k_pci_ce_send_done,
1612 ath10k_pci_ce_recv_data);
1613 if (ret) { 1678 if (ret) {
1614 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n", 1679 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
1615 pipe_num, ret); 1680 i, ret);
1616 return ret; 1681 return ret;
1617 } 1682 }
1618
1619 if (pipe_num == CE_COUNT - 1) {
1620 /*
1621 * Reserve the ultimate CE for
1622 * diagnostic Window support
1623 */
1624 ar_pci->ce_diag = pipe_info->ce_hdl;
1625 continue;
1626 }
1627
1628 pipe_info->buf_sz = (size_t)(attr->src_sz_max);
1629 } 1683 }
1630 1684
1631 return 0; 1685 return 0;
@@ -1666,93 +1720,167 @@ static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
1666 msleep(10); 1720 msleep(10);
1667} 1721}
1668 1722
1669static int ath10k_pci_warm_reset(struct ath10k *ar) 1723static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
1670{ 1724{
1671 u32 val; 1725 u32 val;
1672 1726
1673 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n"); 1727 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
1674
1675 /* debug */
1676 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1677 PCIE_INTR_CAUSE_ADDRESS);
1678 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot host cpu intr cause: 0x%08x\n",
1679 val);
1680 1728
1681 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + 1729 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1682 CPU_INTR_ADDRESS); 1730 SOC_RESET_CONTROL_ADDRESS);
1683 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target cpu intr cause: 0x%08x\n", 1731 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1684 val); 1732 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
1733}
1685 1734
1686 /* disable pending irqs */ 1735static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
1687 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + 1736{
1688 PCIE_INTR_ENABLE_ADDRESS, 0); 1737 u32 val;
1689 1738
1690 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + 1739 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1691 PCIE_INTR_CLR_ADDRESS, ~0); 1740 SOC_RESET_CONTROL_ADDRESS);
1692 1741
1693 msleep(100); 1742 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1743 val | SOC_RESET_CONTROL_CE_RST_MASK);
1744 msleep(10);
1745 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1746 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
1747}
1694 1748
1695 /* clear fw indicator */ 1749static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
1696 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0); 1750{
1751 u32 val;
1697 1752
1698 /* clear target LF timer interrupts */
1699 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + 1753 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1700 SOC_LF_TIMER_CONTROL0_ADDRESS); 1754 SOC_LF_TIMER_CONTROL0_ADDRESS);
1701 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + 1755 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
1702 SOC_LF_TIMER_CONTROL0_ADDRESS, 1756 SOC_LF_TIMER_CONTROL0_ADDRESS,
1703 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK); 1757 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
1758}
1704 1759
1705 /* reset CE */ 1760static int ath10k_pci_warm_reset(struct ath10k *ar)
1706 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + 1761{
1707 SOC_RESET_CONTROL_ADDRESS); 1762 int ret;
1708 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1709 val | SOC_RESET_CONTROL_CE_RST_MASK);
1710 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1711 SOC_RESET_CONTROL_ADDRESS);
1712 msleep(10);
1713 1763
1714 /* unreset CE */ 1764 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
1715 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS, 1765
1716 val & ~SOC_RESET_CONTROL_CE_RST_MASK); 1766 spin_lock_bh(&ar->data_lock);
1717 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + 1767 ar->stats.fw_warm_reset_counter++;
1718 SOC_RESET_CONTROL_ADDRESS); 1768 spin_unlock_bh(&ar->data_lock);
1719 msleep(10); 1769
1770 ath10k_pci_irq_disable(ar);
1720 1771
1772 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
1773 * were to access copy engine while host performs copy engine reset
1774 * then it is possible for the device to confuse pci-e controller to
1775 * the point of bringing host system to a complete stop (i.e. hang).
1776 */
1721 ath10k_pci_warm_reset_si0(ar); 1777 ath10k_pci_warm_reset_si0(ar);
1778 ath10k_pci_warm_reset_cpu(ar);
1779 ath10k_pci_init_pipes(ar);
1780 ath10k_pci_wait_for_target_init(ar);
1722 1781
1723 /* debug */ 1782 ath10k_pci_warm_reset_clear_lf(ar);
1724 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + 1783 ath10k_pci_warm_reset_ce(ar);
1725 PCIE_INTR_CAUSE_ADDRESS); 1784 ath10k_pci_warm_reset_cpu(ar);
1726 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot host cpu intr cause: 0x%08x\n", 1785 ath10k_pci_init_pipes(ar);
1727 val);
1728 1786
1729 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + 1787 ret = ath10k_pci_wait_for_target_init(ar);
1730 CPU_INTR_ADDRESS); 1788 if (ret) {
1731 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target cpu intr cause: 0x%08x\n", 1789 ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
1732 val); 1790 return ret;
1791 }
1733 1792
1734 /* CPU warm reset */ 1793 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
1735 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1736 SOC_RESET_CONTROL_ADDRESS);
1737 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1738 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
1739 1794
1740 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + 1795 return 0;
1741 SOC_RESET_CONTROL_ADDRESS); 1796}
1742 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target reset state: 0x%08x\n", 1797
1743 val); 1798static int ath10k_pci_chip_reset(struct ath10k *ar)
1799{
1800 int i, ret;
1801 u32 val;
1744 1802
1745 msleep(100); 1803 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset\n");
1746 1804
1747 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n"); 1805 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
1806 * It is thus preferred to use warm reset which is safer but may not be
1807 * able to recover the device from all possible fail scenarios.
1808 *
1809 * Warm reset doesn't always work on first try so attempt it a few
1810 * times before giving up.
1811 */
1812 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
1813 ret = ath10k_pci_warm_reset(ar);
1814 if (ret) {
1815 ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
1816 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
1817 ret);
1818 continue;
1819 }
1820
1821 /* FIXME: Sometimes copy engine doesn't recover after warm
1822 * reset. In most cases this needs cold reset. In some of these
1823 * cases the device is in such a state that a cold reset may
1824 * lock up the host.
1825 *
1826 * Reading any host interest register via copy engine is
1827 * sufficient to verify if device is capable of booting
1828 * firmware blob.
1829 */
1830 ret = ath10k_pci_init_pipes(ar);
1831 if (ret) {
1832 ath10k_warn(ar, "failed to init copy engine: %d\n",
1833 ret);
1834 continue;
1835 }
1836
1837 ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
1838 &val);
1839 if (ret) {
1840 ath10k_warn(ar, "failed to poke copy engine: %d\n",
1841 ret);
1842 continue;
1843 }
1844
1845 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
1846 return 0;
1847 }
1848
1849 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
1850 ath10k_warn(ar, "refusing cold reset as requested\n");
1851 return -EPERM;
1852 }
1853
1854 ret = ath10k_pci_cold_reset(ar);
1855 if (ret) {
1856 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
1857 return ret;
1858 }
1859
1860 ret = ath10k_pci_wait_for_target_init(ar);
1861 if (ret) {
1862 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
1863 ret);
1864 return ret;
1865 }
1866
1867 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (cold)\n");
1748 1868
1749 return 0; 1869 return 0;
1750} 1870}
1751 1871
1752static int __ath10k_pci_hif_power_up(struct ath10k *ar, bool cold_reset) 1872static int ath10k_pci_hif_power_up(struct ath10k *ar)
1753{ 1873{
1754 int ret; 1874 int ret;
1755 1875
1876 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
1877
1878 ret = ath10k_pci_wake(ar);
1879 if (ret) {
1880 ath10k_err(ar, "failed to wake up target: %d\n", ret);
1881 return ret;
1882 }
1883
1756 /* 1884 /*
1757 * Bring the target up cleanly. 1885 * Bring the target up cleanly.
1758 * 1886 *
@@ -1763,26 +1891,16 @@ static int __ath10k_pci_hif_power_up(struct ath10k *ar, bool cold_reset)
1763 * is in an unexpected state. We try to catch that here in order to 1891 * is in an unexpected state. We try to catch that here in order to
1764 * reset the Target and retry the probe. 1892 * reset the Target and retry the probe.
1765 */ 1893 */
1766 if (cold_reset) 1894 ret = ath10k_pci_chip_reset(ar);
1767 ret = ath10k_pci_cold_reset(ar);
1768 else
1769 ret = ath10k_pci_warm_reset(ar);
1770
1771 if (ret) { 1895 if (ret) {
1772 ath10k_err(ar, "failed to reset target: %d\n", ret); 1896 ath10k_err(ar, "failed to reset chip: %d\n", ret);
1773 goto err; 1897 goto err_sleep;
1774 } 1898 }
1775 1899
1776 ret = ath10k_pci_ce_init(ar); 1900 ret = ath10k_pci_init_pipes(ar);
1777 if (ret) { 1901 if (ret) {
1778 ath10k_err(ar, "failed to initialize CE: %d\n", ret); 1902 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
1779 goto err; 1903 goto err_sleep;
1780 }
1781
1782 ret = ath10k_pci_wait_for_target_init(ar);
1783 if (ret) {
1784 ath10k_err(ar, "failed to wait for target to init: %d\n", ret);
1785 goto err_ce;
1786 } 1904 }
1787 1905
1788 ret = ath10k_pci_init_config(ar); 1906 ret = ath10k_pci_init_config(ar);
@@ -1801,73 +1919,21 @@ static int __ath10k_pci_hif_power_up(struct ath10k *ar, bool cold_reset)
1801 1919
1802err_ce: 1920err_ce:
1803 ath10k_pci_ce_deinit(ar); 1921 ath10k_pci_ce_deinit(ar);
1804 ath10k_pci_warm_reset(ar);
1805err:
1806 return ret;
1807}
1808
1809static int ath10k_pci_hif_power_up_warm(struct ath10k *ar)
1810{
1811 int i, ret;
1812
1813 /*
1814 * Sometime warm reset succeeds after retries.
1815 *
1816 * FIXME: It might be possible to tune ath10k_pci_warm_reset() to work
1817 * at first try.
1818 */
1819 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
1820 ret = __ath10k_pci_hif_power_up(ar, false);
1821 if (ret == 0)
1822 break;
1823
1824 ath10k_warn(ar, "failed to warm reset (attempt %d out of %d): %d\n",
1825 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS, ret);
1826 }
1827 1922
1923err_sleep:
1924 ath10k_pci_sleep(ar);
1828 return ret; 1925 return ret;
1829} 1926}
1830 1927
1831static int ath10k_pci_hif_power_up(struct ath10k *ar)
1832{
1833 int ret;
1834
1835 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
1836
1837 /*
1838 * Hardware CUS232 version 2 has some issues with cold reset and the
1839 * preferred (and safer) way to perform a device reset is through a
1840 * warm reset.
1841 *
1842 * Warm reset doesn't always work though so fall back to cold reset may
1843 * be necessary.
1844 */
1845 ret = ath10k_pci_hif_power_up_warm(ar);
1846 if (ret) {
1847 ath10k_warn(ar, "failed to power up target using warm reset: %d\n",
1848 ret);
1849
1850 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY)
1851 return ret;
1852
1853 ath10k_warn(ar, "trying cold reset\n");
1854
1855 ret = __ath10k_pci_hif_power_up(ar, true);
1856 if (ret) {
1857 ath10k_err(ar, "failed to power up target using cold reset too (%d)\n",
1858 ret);
1859 return ret;
1860 }
1861 }
1862
1863 return 0;
1864}
1865
1866static void ath10k_pci_hif_power_down(struct ath10k *ar) 1928static void ath10k_pci_hif_power_down(struct ath10k *ar)
1867{ 1929{
1868 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n"); 1930 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
1869 1931
1870 ath10k_pci_warm_reset(ar); 1932 /* Currently hif_power_up performs effectively a reset and hif_stop
1933 * resets the chip as well so there's no point in resetting here.
1934 */
1935
1936 ath10k_pci_sleep(ar);
1871} 1937}
1872 1938
1873#ifdef CONFIG_PM 1939#ifdef CONFIG_PM
@@ -1921,6 +1987,7 @@ static int ath10k_pci_hif_resume(struct ath10k *ar)
1921 1987
1922static const struct ath10k_hif_ops ath10k_pci_hif_ops = { 1988static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
1923 .tx_sg = ath10k_pci_hif_tx_sg, 1989 .tx_sg = ath10k_pci_hif_tx_sg,
1990 .diag_read = ath10k_pci_hif_diag_read,
1924 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg, 1991 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
1925 .start = ath10k_pci_hif_start, 1992 .start = ath10k_pci_hif_start,
1926 .stop = ath10k_pci_hif_stop, 1993 .stop = ath10k_pci_hif_stop,
@@ -2250,14 +2317,14 @@ static int ath10k_pci_wait_for_target_init(struct ath10k *ar)
2250 2317
2251 if (ar_pci->num_msi_intrs == 0) 2318 if (ar_pci->num_msi_intrs == 0)
2252 /* Fix potential race by repeating CORE_BASE writes */ 2319 /* Fix potential race by repeating CORE_BASE writes */
2253 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + 2320 ath10k_pci_enable_legacy_irq(ar);
2254 PCIE_INTR_ENABLE_ADDRESS,
2255 PCIE_INTR_FIRMWARE_MASK |
2256 PCIE_INTR_CE_MASK_ALL);
2257 2321
2258 mdelay(10); 2322 mdelay(10);
2259 } while (time_before(jiffies, timeout)); 2323 } while (time_before(jiffies, timeout));
2260 2324
2325 ath10k_pci_disable_and_clear_legacy_irq(ar);
2326 ath10k_pci_irq_msi_fw_mask(ar);
2327
2261 if (val == 0xffffffff) { 2328 if (val == 0xffffffff) {
2262 ath10k_err(ar, "failed to read device register, device is gone\n"); 2329 ath10k_err(ar, "failed to read device register, device is gone\n");
2263 return -EIO; 2330 return -EIO;
@@ -2287,6 +2354,12 @@ static int ath10k_pci_cold_reset(struct ath10k *ar)
2287 2354
2288 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n"); 2355 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
2289 2356
2357 spin_lock_bh(&ar->data_lock);
2358
2359 ar->stats.fw_cold_reset_counter++;
2360
2361 spin_unlock_bh(&ar->data_lock);
2362
2290 /* Put Target, including PCIe, into RESET. */ 2363 /* Put Target, including PCIe, into RESET. */
2291 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS); 2364 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
2292 val |= 1; 2365 val |= 1;
@@ -2400,6 +2473,7 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2400 u32 chip_id; 2473 u32 chip_id;
2401 2474
2402 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, 2475 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev,
2476 ATH10K_BUS_PCI,
2403 &ath10k_pci_hif_ops); 2477 &ath10k_pci_hif_ops);
2404 if (!ar) { 2478 if (!ar) {
2405 dev_err(&pdev->dev, "failed to allocate core\n"); 2479 dev_err(&pdev->dev, "failed to allocate core\n");
@@ -2435,7 +2509,7 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2435 goto err_sleep; 2509 goto err_sleep;
2436 } 2510 }
2437 2511
2438 ret = ath10k_pci_alloc_ce(ar); 2512 ret = ath10k_pci_alloc_pipes(ar);
2439 if (ret) { 2513 if (ret) {
2440 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n", 2514 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
2441 ret); 2515 ret);
@@ -2443,25 +2517,12 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2443 } 2517 }
2444 2518
2445 ath10k_pci_ce_deinit(ar); 2519 ath10k_pci_ce_deinit(ar);
2446 2520 ath10k_pci_irq_disable(ar);
2447 ret = ath10k_ce_disable_interrupts(ar);
2448 if (ret) {
2449 ath10k_err(ar, "failed to disable copy engine interrupts: %d\n",
2450 ret);
2451 goto err_free_ce;
2452 }
2453
2454 /* Workaround: There's no known way to mask all possible interrupts via
2455 * device CSR. The only way to make sure device doesn't assert
2456 * interrupts is to reset it. Interrupts are then disabled on host
2457 * after handlers are registered.
2458 */
2459 ath10k_pci_warm_reset(ar);
2460 2521
2461 ret = ath10k_pci_init_irq(ar); 2522 ret = ath10k_pci_init_irq(ar);
2462 if (ret) { 2523 if (ret) {
2463 ath10k_err(ar, "failed to init irqs: %d\n", ret); 2524 ath10k_err(ar, "failed to init irqs: %d\n", ret);
2464 goto err_free_ce; 2525 goto err_free_pipes;
2465 } 2526 }
2466 2527
2467 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n", 2528 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
@@ -2474,8 +2535,7 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2474 goto err_deinit_irq; 2535 goto err_deinit_irq;
2475 } 2536 }
2476 2537
2477 /* This shouldn't race as the device has been reset above. */ 2538 ath10k_pci_sleep(ar);
2478 ath10k_pci_irq_disable(ar);
2479 2539
2480 ret = ath10k_core_register(ar, chip_id); 2540 ret = ath10k_core_register(ar, chip_id);
2481 if (ret) { 2541 if (ret) {
@@ -2492,8 +2552,8 @@ err_free_irq:
2492err_deinit_irq: 2552err_deinit_irq:
2493 ath10k_pci_deinit_irq(ar); 2553 ath10k_pci_deinit_irq(ar);
2494 2554
2495err_free_ce: 2555err_free_pipes:
2496 ath10k_pci_free_ce(ar); 2556 ath10k_pci_free_pipes(ar);
2497 2557
2498err_sleep: 2558err_sleep:
2499 ath10k_pci_sleep(ar); 2559 ath10k_pci_sleep(ar);
@@ -2527,8 +2587,7 @@ static void ath10k_pci_remove(struct pci_dev *pdev)
2527 ath10k_pci_kill_tasklet(ar); 2587 ath10k_pci_kill_tasklet(ar);
2528 ath10k_pci_deinit_irq(ar); 2588 ath10k_pci_deinit_irq(ar);
2529 ath10k_pci_ce_deinit(ar); 2589 ath10k_pci_ce_deinit(ar);
2530 ath10k_pci_free_ce(ar); 2590 ath10k_pci_free_pipes(ar);
2531 ath10k_pci_sleep(ar);
2532 ath10k_pci_release(ar); 2591 ath10k_pci_release(ar);
2533 ath10k_core_destroy(ar); 2592 ath10k_core_destroy(ar);
2534} 2593}
@@ -2565,5 +2624,7 @@ module_exit(ath10k_pci_exit);
2565MODULE_AUTHOR("Qualcomm Atheros"); 2624MODULE_AUTHOR("Qualcomm Atheros");
2566MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices"); 2625MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2567MODULE_LICENSE("Dual BSD/GPL"); 2626MODULE_LICENSE("Dual BSD/GPL");
2568MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_3_FILE); 2627MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
2628MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
2629MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
2569MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE); 2630MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
diff --git a/drivers/net/wireless/ath/ath10k/spectral.c b/drivers/net/wireless/ath/ath10k/spectral.c
index 3e1454b74e00..63ce61fcdac8 100644
--- a/drivers/net/wireless/ath/ath10k/spectral.c
+++ b/drivers/net/wireless/ath/ath10k/spectral.c
@@ -56,14 +56,14 @@ static uint8_t get_max_exp(s8 max_index, u16 max_magnitude, size_t bin_len,
56} 56}
57 57
58int ath10k_spectral_process_fft(struct ath10k *ar, 58int ath10k_spectral_process_fft(struct ath10k *ar,
59 struct wmi_single_phyerr_rx_event *event, 59 const struct wmi_phyerr *phyerr,
60 struct phyerr_fft_report *fftr, 60 const struct phyerr_fft_report *fftr,
61 size_t bin_len, u64 tsf) 61 size_t bin_len, u64 tsf)
62{ 62{
63 struct fft_sample_ath10k *fft_sample; 63 struct fft_sample_ath10k *fft_sample;
64 u8 buf[sizeof(*fft_sample) + SPECTRAL_ATH10K_MAX_NUM_BINS]; 64 u8 buf[sizeof(*fft_sample) + SPECTRAL_ATH10K_MAX_NUM_BINS];
65 u16 freq1, freq2, total_gain_db, base_pwr_db, length, peak_mag; 65 u16 freq1, freq2, total_gain_db, base_pwr_db, length, peak_mag;
66 u32 reg0, reg1, nf_list1, nf_list2; 66 u32 reg0, reg1;
67 u8 chain_idx, *bins; 67 u8 chain_idx, *bins;
68 int dc_pos; 68 int dc_pos;
69 69
@@ -82,7 +82,7 @@ int ath10k_spectral_process_fft(struct ath10k *ar,
82 /* TODO: there might be a reason why the hardware reports 20/40/80 MHz, 82 /* TODO: there might be a reason why the hardware reports 20/40/80 MHz,
83 * but the results/plots suggest that its actually 22/44/88 MHz. 83 * but the results/plots suggest that its actually 22/44/88 MHz.
84 */ 84 */
85 switch (event->hdr.chan_width_mhz) { 85 switch (phyerr->chan_width_mhz) {
86 case 20: 86 case 20:
87 fft_sample->chan_width_mhz = 22; 87 fft_sample->chan_width_mhz = 22;
88 break; 88 break;
@@ -101,7 +101,7 @@ int ath10k_spectral_process_fft(struct ath10k *ar,
101 fft_sample->chan_width_mhz = 88; 101 fft_sample->chan_width_mhz = 88;
102 break; 102 break;
103 default: 103 default:
104 fft_sample->chan_width_mhz = event->hdr.chan_width_mhz; 104 fft_sample->chan_width_mhz = phyerr->chan_width_mhz;
105 } 105 }
106 106
107 fft_sample->relpwr_db = MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB); 107 fft_sample->relpwr_db = MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB);
@@ -110,36 +110,22 @@ int ath10k_spectral_process_fft(struct ath10k *ar,
110 peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG); 110 peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
111 fft_sample->max_magnitude = __cpu_to_be16(peak_mag); 111 fft_sample->max_magnitude = __cpu_to_be16(peak_mag);
112 fft_sample->max_index = MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX); 112 fft_sample->max_index = MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX);
113 fft_sample->rssi = event->hdr.rssi_combined; 113 fft_sample->rssi = phyerr->rssi_combined;
114 114
115 total_gain_db = MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB); 115 total_gain_db = MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB);
116 base_pwr_db = MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB); 116 base_pwr_db = MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB);
117 fft_sample->total_gain_db = __cpu_to_be16(total_gain_db); 117 fft_sample->total_gain_db = __cpu_to_be16(total_gain_db);
118 fft_sample->base_pwr_db = __cpu_to_be16(base_pwr_db); 118 fft_sample->base_pwr_db = __cpu_to_be16(base_pwr_db);
119 119
120 freq1 = __le16_to_cpu(event->hdr.freq1); 120 freq1 = __le16_to_cpu(phyerr->freq1);
121 freq2 = __le16_to_cpu(event->hdr.freq2); 121 freq2 = __le16_to_cpu(phyerr->freq2);
122 fft_sample->freq1 = __cpu_to_be16(freq1); 122 fft_sample->freq1 = __cpu_to_be16(freq1);
123 fft_sample->freq2 = __cpu_to_be16(freq2); 123 fft_sample->freq2 = __cpu_to_be16(freq2);
124 124
125 nf_list1 = __le32_to_cpu(event->hdr.nf_list_1);
126 nf_list2 = __le32_to_cpu(event->hdr.nf_list_2);
127 chain_idx = MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX); 125 chain_idx = MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX);
128 126
129 switch (chain_idx) { 127 fft_sample->noise = __cpu_to_be16(
130 case 0: 128 __le16_to_cpu(phyerr->nf_chains[chain_idx]));
131 fft_sample->noise = __cpu_to_be16(nf_list1 & 0xffffu);
132 break;
133 case 1:
134 fft_sample->noise = __cpu_to_be16((nf_list1 >> 16) & 0xffffu);
135 break;
136 case 2:
137 fft_sample->noise = __cpu_to_be16(nf_list2 & 0xffffu);
138 break;
139 case 3:
140 fft_sample->noise = __cpu_to_be16((nf_list2 >> 16) & 0xffffu);
141 break;
142 }
143 129
144 bins = (u8 *)fftr; 130 bins = (u8 *)fftr;
145 bins += sizeof(*fftr); 131 bins += sizeof(*fftr);
diff --git a/drivers/net/wireless/ath/ath10k/spectral.h b/drivers/net/wireless/ath/ath10k/spectral.h
index ddc57c557272..042f5b302c75 100644
--- a/drivers/net/wireless/ath/ath10k/spectral.h
+++ b/drivers/net/wireless/ath/ath10k/spectral.h
@@ -47,8 +47,8 @@ enum ath10k_spectral_mode {
47#ifdef CONFIG_ATH10K_DEBUGFS 47#ifdef CONFIG_ATH10K_DEBUGFS
48 48
49int ath10k_spectral_process_fft(struct ath10k *ar, 49int ath10k_spectral_process_fft(struct ath10k *ar,
50 struct wmi_single_phyerr_rx_event *event, 50 const struct wmi_phyerr *phyerr,
51 struct phyerr_fft_report *fftr, 51 const struct phyerr_fft_report *fftr,
52 size_t bin_len, u64 tsf); 52 size_t bin_len, u64 tsf);
53int ath10k_spectral_start(struct ath10k *ar); 53int ath10k_spectral_start(struct ath10k *ar);
54int ath10k_spectral_vif_stop(struct ath10k_vif *arvif); 54int ath10k_spectral_vif_stop(struct ath10k_vif *arvif);
@@ -59,8 +59,8 @@ void ath10k_spectral_destroy(struct ath10k *ar);
59 59
60static inline int 60static inline int
61ath10k_spectral_process_fft(struct ath10k *ar, 61ath10k_spectral_process_fft(struct ath10k *ar,
62 struct wmi_single_phyerr_rx_event *event, 62 const struct wmi_phyerr *phyerr,
63 struct phyerr_fft_report *fftr, 63 const struct phyerr_fft_report *fftr,
64 size_t bin_len, u64 tsf) 64 size_t bin_len, u64 tsf)
65{ 65{
66 return 0; 66 return 0;
diff --git a/drivers/net/wireless/ath/ath10k/trace.h b/drivers/net/wireless/ath/ath10k/trace.h
index 574b75ab2609..ceea5668f3f6 100644
--- a/drivers/net/wireless/ath/ath10k/trace.h
+++ b/drivers/net/wireless/ath/ath10k/trace.h
@@ -20,6 +20,13 @@
20#include <linux/tracepoint.h> 20#include <linux/tracepoint.h>
21#include "core.h" 21#include "core.h"
22 22
23#if !defined(_TRACE_H_)
24static inline u32 ath10k_frm_hdr_len(void *buf)
25{
26 return ieee80211_hdrlen(((struct ieee80211_hdr *)buf)->frame_control);
27}
28#endif
29
23#define _TRACE_H_ 30#define _TRACE_H_
24 31
25/* create empty functions when tracing is disabled */ 32/* create empty functions when tracing is disabled */
@@ -254,6 +261,195 @@ TRACE_EVENT(ath10k_wmi_dbglog,
254 ) 261 )
255); 262);
256 263
264TRACE_EVENT(ath10k_htt_pktlog,
265 TP_PROTO(struct ath10k *ar, void *buf, u16 buf_len),
266
267 TP_ARGS(ar, buf, buf_len),
268
269 TP_STRUCT__entry(
270 __string(device, dev_name(ar->dev))
271 __string(driver, dev_driver_string(ar->dev))
272 __field(u16, buf_len)
273 __dynamic_array(u8, pktlog, buf_len)
274 ),
275
276 TP_fast_assign(
277 __assign_str(device, dev_name(ar->dev));
278 __assign_str(driver, dev_driver_string(ar->dev));
279 __entry->buf_len = buf_len;
280 memcpy(__get_dynamic_array(pktlog), buf, buf_len);
281 ),
282
283 TP_printk(
284 "%s %s size %hu",
285 __get_str(driver),
286 __get_str(device),
287 __entry->buf_len
288 )
289);
290
291TRACE_EVENT(ath10k_htt_tx,
292 TP_PROTO(struct ath10k *ar, u16 msdu_id, u16 msdu_len,
293 u8 vdev_id, u8 tid),
294
295 TP_ARGS(ar, msdu_id, msdu_len, vdev_id, tid),
296
297 TP_STRUCT__entry(
298 __string(device, dev_name(ar->dev))
299 __string(driver, dev_driver_string(ar->dev))
300 __field(u16, msdu_id)
301 __field(u16, msdu_len)
302 __field(u8, vdev_id)
303 __field(u8, tid)
304 ),
305
306 TP_fast_assign(
307 __assign_str(device, dev_name(ar->dev));
308 __assign_str(driver, dev_driver_string(ar->dev));
309 __entry->msdu_id = msdu_id;
310 __entry->msdu_len = msdu_len;
311 __entry->vdev_id = vdev_id;
312 __entry->tid = tid;
313 ),
314
315 TP_printk(
316 "%s %s msdu_id %d msdu_len %d vdev_id %d tid %d",
317 __get_str(driver),
318 __get_str(device),
319 __entry->msdu_id,
320 __entry->msdu_len,
321 __entry->vdev_id,
322 __entry->tid
323 )
324);
325
326TRACE_EVENT(ath10k_txrx_tx_unref,
327 TP_PROTO(struct ath10k *ar, u16 msdu_id),
328
329 TP_ARGS(ar, msdu_id),
330
331 TP_STRUCT__entry(
332 __string(device, dev_name(ar->dev))
333 __string(driver, dev_driver_string(ar->dev))
334 __field(u16, msdu_id)
335 ),
336
337 TP_fast_assign(
338 __assign_str(device, dev_name(ar->dev));
339 __assign_str(driver, dev_driver_string(ar->dev));
340 __entry->msdu_id = msdu_id;
341 ),
342
343 TP_printk(
344 "%s %s msdu_id %d",
345 __get_str(driver),
346 __get_str(device),
347 __entry->msdu_id
348 )
349);
350
351DECLARE_EVENT_CLASS(ath10k_hdr_event,
352 TP_PROTO(struct ath10k *ar, void *data, size_t len),
353
354 TP_ARGS(ar, data, len),
355
356 TP_STRUCT__entry(
357 __string(device, dev_name(ar->dev))
358 __string(driver, dev_driver_string(ar->dev))
359 __field(size_t, len)
360 __dynamic_array(u8, data, ath10k_frm_hdr_len(data))
361 ),
362
363 TP_fast_assign(
364 __assign_str(device, dev_name(ar->dev));
365 __assign_str(driver, dev_driver_string(ar->dev));
366 __entry->len = ath10k_frm_hdr_len(data);
367 memcpy(__get_dynamic_array(data), data, __entry->len);
368 ),
369
370 TP_printk(
371 "%s %s len %zu\n",
372 __get_str(driver),
373 __get_str(device),
374 __entry->len
375 )
376);
377
378DECLARE_EVENT_CLASS(ath10k_payload_event,
379 TP_PROTO(struct ath10k *ar, void *data, size_t len),
380
381 TP_ARGS(ar, data, len),
382
383 TP_STRUCT__entry(
384 __string(device, dev_name(ar->dev))
385 __string(driver, dev_driver_string(ar->dev))
386 __field(size_t, len)
387 __dynamic_array(u8, payload, (len - ath10k_frm_hdr_len(data)))
388 ),
389
390 TP_fast_assign(
391 __assign_str(device, dev_name(ar->dev));
392 __assign_str(driver, dev_driver_string(ar->dev));
393 __entry->len = len - ath10k_frm_hdr_len(data);
394 memcpy(__get_dynamic_array(payload),
395 data + ath10k_frm_hdr_len(data), __entry->len);
396 ),
397
398 TP_printk(
399 "%s %s len %zu\n",
400 __get_str(driver),
401 __get_str(device),
402 __entry->len
403 )
404);
405
406DEFINE_EVENT(ath10k_hdr_event, ath10k_tx_hdr,
407 TP_PROTO(struct ath10k *ar, void *data, size_t len),
408 TP_ARGS(ar, data, len)
409);
410
411DEFINE_EVENT(ath10k_payload_event, ath10k_tx_payload,
412 TP_PROTO(struct ath10k *ar, void *data, size_t len),
413 TP_ARGS(ar, data, len)
414);
415
416DEFINE_EVENT(ath10k_hdr_event, ath10k_rx_hdr,
417 TP_PROTO(struct ath10k *ar, void *data, size_t len),
418 TP_ARGS(ar, data, len)
419);
420
421DEFINE_EVENT(ath10k_payload_event, ath10k_rx_payload,
422 TP_PROTO(struct ath10k *ar, void *data, size_t len),
423 TP_ARGS(ar, data, len)
424);
425
426TRACE_EVENT(ath10k_htt_rx_desc,
427 TP_PROTO(struct ath10k *ar, void *data, size_t len),
428
429 TP_ARGS(ar, data, len),
430
431 TP_STRUCT__entry(
432 __string(device, dev_name(ar->dev))
433 __string(driver, dev_driver_string(ar->dev))
434 __field(u16, len)
435 __dynamic_array(u8, rxdesc, len)
436 ),
437
438 TP_fast_assign(
439 __assign_str(device, dev_name(ar->dev));
440 __assign_str(driver, dev_driver_string(ar->dev));
441 __entry->len = len;
442 memcpy(__get_dynamic_array(rxdesc), data, len);
443 ),
444
445 TP_printk(
446 "%s %s rxdesc len %d",
447 __get_str(driver),
448 __get_str(device),
449 __entry->len
450 )
451);
452
257#endif /* _TRACE_H_ || TRACE_HEADER_MULTI_READ*/ 453#endif /* _TRACE_H_ || TRACE_HEADER_MULTI_READ*/
258 454
259/* we don't want to use include/trace/events */ 455/* we don't want to use include/trace/events */
diff --git a/drivers/net/wireless/ath/ath10k/txrx.c b/drivers/net/wireless/ath/ath10k/txrx.c
index a0cbc21d0d4b..7579de8e7a8c 100644
--- a/drivers/net/wireless/ath/ath10k/txrx.c
+++ b/drivers/net/wireless/ath/ath10k/txrx.c
@@ -78,6 +78,7 @@ void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
78 78
79 info = IEEE80211_SKB_CB(msdu); 79 info = IEEE80211_SKB_CB(msdu);
80 memset(&info->status, 0, sizeof(info->status)); 80 memset(&info->status, 0, sizeof(info->status));
81 trace_ath10k_txrx_tx_unref(ar, tx_done->msdu_id);
81 82
82 if (tx_done->discard) { 83 if (tx_done->discard) {
83 ieee80211_free_txskb(htt->ar->hw, msdu); 84 ieee80211_free_txskb(htt->ar->hw, msdu);
@@ -145,7 +146,8 @@ static int ath10k_wait_for_peer_common(struct ath10k *ar, int vdev_id,
145 mapped = !!ath10k_peer_find(ar, vdev_id, addr); 146 mapped = !!ath10k_peer_find(ar, vdev_id, addr);
146 spin_unlock_bh(&ar->data_lock); 147 spin_unlock_bh(&ar->data_lock);
147 148
148 mapped == expect_mapped; 149 (mapped == expect_mapped ||
150 test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags));
149 }), 3*HZ); 151 }), 3*HZ);
150 152
151 if (ret <= 0) 153 if (ret <= 0)
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index 2c42bd504b79..c2bc8282f6cb 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -609,6 +609,40 @@ static struct wmi_cmd_map wmi_10_2_cmd_map = {
609 .gpio_output_cmdid = WMI_10_2_GPIO_OUTPUT_CMDID, 609 .gpio_output_cmdid = WMI_10_2_GPIO_OUTPUT_CMDID,
610}; 610};
611 611
612static void
613ath10k_wmi_put_wmi_channel(struct wmi_channel *ch,
614 const struct wmi_channel_arg *arg)
615{
616 u32 flags = 0;
617
618 memset(ch, 0, sizeof(*ch));
619
620 if (arg->passive)
621 flags |= WMI_CHAN_FLAG_PASSIVE;
622 if (arg->allow_ibss)
623 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
624 if (arg->allow_ht)
625 flags |= WMI_CHAN_FLAG_ALLOW_HT;
626 if (arg->allow_vht)
627 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
628 if (arg->ht40plus)
629 flags |= WMI_CHAN_FLAG_HT40_PLUS;
630 if (arg->chan_radar)
631 flags |= WMI_CHAN_FLAG_DFS;
632
633 ch->mhz = __cpu_to_le32(arg->freq);
634 ch->band_center_freq1 = __cpu_to_le32(arg->band_center_freq1);
635 ch->band_center_freq2 = 0;
636 ch->min_power = arg->min_power;
637 ch->max_power = arg->max_power;
638 ch->reg_power = arg->max_reg_power;
639 ch->antenna_max = arg->max_antenna_gain;
640
641 /* mode & flags share storage */
642 ch->mode = arg->mode;
643 ch->flags |= __cpu_to_le32(flags);
644}
645
612int ath10k_wmi_wait_for_service_ready(struct ath10k *ar) 646int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
613{ 647{
614 int ret; 648 int ret;
@@ -745,6 +779,10 @@ int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id)
745 ath10k_wmi_tx_beacons_nowait(ar); 779 ath10k_wmi_tx_beacons_nowait(ar);
746 780
747 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id); 781 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
782
783 if (ret && test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
784 ret = -ESHUTDOWN;
785
748 (ret != -EAGAIN); 786 (ret != -EAGAIN);
749 }), 3*HZ); 787 }), 3*HZ);
750 788
@@ -800,6 +838,8 @@ int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
800 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n", 838 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n",
801 wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE, 839 wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE,
802 fc & IEEE80211_FCTL_STYPE); 840 fc & IEEE80211_FCTL_STYPE);
841 trace_ath10k_tx_hdr(ar, skb->data, skb->len);
842 trace_ath10k_tx_payload(ar, skb->data, skb->len);
803 843
804 /* Send the management frame buffer to the target */ 844 /* Send the management frame buffer to the target */
805 ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid); 845 ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid);
@@ -1079,7 +1119,6 @@ static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
1079 struct wmi_mgmt_rx_event_v2 *ev_v2; 1119 struct wmi_mgmt_rx_event_v2 *ev_v2;
1080 struct wmi_mgmt_rx_hdr_v1 *ev_hdr; 1120 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
1081 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 1121 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1082 struct ieee80211_channel *ch;
1083 struct ieee80211_hdr *hdr; 1122 struct ieee80211_hdr *hdr;
1084 u32 rx_status; 1123 u32 rx_status;
1085 u32 channel; 1124 u32 channel;
@@ -1132,25 +1171,26 @@ static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
1132 if (rx_status & WMI_RX_STATUS_ERR_MIC) 1171 if (rx_status & WMI_RX_STATUS_ERR_MIC)
1133 status->flag |= RX_FLAG_MMIC_ERROR; 1172 status->flag |= RX_FLAG_MMIC_ERROR;
1134 1173
1135 /* HW can Rx CCK rates on 5GHz. In that case phy_mode is set to 1174 /* Hardware can Rx CCK rates on 5GHz. In that case phy_mode is set to
1136 * MODE_11B. This means phy_mode is not a reliable source for the band 1175 * MODE_11B. This means phy_mode is not a reliable source for the band
1137 * of mgmt rx. */ 1176 * of mgmt rx.
1138 1177 */
1139 ch = ar->scan_channel; 1178 if (channel >= 1 && channel <= 14) {
1140 if (!ch) 1179 status->band = IEEE80211_BAND_2GHZ;
1141 ch = ar->rx_channel; 1180 } else if (channel >= 36 && channel <= 165) {
1142 1181 status->band = IEEE80211_BAND_5GHZ;
1143 if (ch) {
1144 status->band = ch->band;
1145
1146 if (phy_mode == MODE_11B &&
1147 status->band == IEEE80211_BAND_5GHZ)
1148 ath10k_dbg(ar, ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
1149 } else { 1182 } else {
1150 ath10k_warn(ar, "using (unreliable) phy_mode to extract band for mgmt rx\n"); 1183 /* Shouldn't happen unless list of advertised channels to
1151 status->band = phy_mode_to_band(phy_mode); 1184 * mac80211 has been changed.
1185 */
1186 WARN_ON_ONCE(1);
1187 dev_kfree_skb(skb);
1188 return 0;
1152 } 1189 }
1153 1190
1191 if (phy_mode == MODE_11B && status->band == IEEE80211_BAND_5GHZ)
1192 ath10k_dbg(ar, ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
1193
1154 status->freq = ieee80211_channel_to_frequency(channel, status->band); 1194 status->freq = ieee80211_channel_to_frequency(channel, status->band);
1155 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR; 1195 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
1156 status->rate_idx = get_rate_idx(rate, status->band); 1196 status->rate_idx = get_rate_idx(rate, status->band);
@@ -1295,14 +1335,196 @@ static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
1295 return 0; 1335 return 0;
1296} 1336}
1297 1337
1338static void ath10k_wmi_pull_pdev_stats(const struct wmi_pdev_stats *src,
1339 struct ath10k_fw_stats_pdev *dst)
1340{
1341 const struct wal_dbg_tx_stats *tx = &src->wal.tx;
1342 const struct wal_dbg_rx_stats *rx = &src->wal.rx;
1343
1344 dst->ch_noise_floor = __le32_to_cpu(src->chan_nf);
1345 dst->tx_frame_count = __le32_to_cpu(src->tx_frame_count);
1346 dst->rx_frame_count = __le32_to_cpu(src->rx_frame_count);
1347 dst->rx_clear_count = __le32_to_cpu(src->rx_clear_count);
1348 dst->cycle_count = __le32_to_cpu(src->cycle_count);
1349 dst->phy_err_count = __le32_to_cpu(src->phy_err_count);
1350 dst->chan_tx_power = __le32_to_cpu(src->chan_tx_pwr);
1351
1352 dst->comp_queued = __le32_to_cpu(tx->comp_queued);
1353 dst->comp_delivered = __le32_to_cpu(tx->comp_delivered);
1354 dst->msdu_enqued = __le32_to_cpu(tx->msdu_enqued);
1355 dst->mpdu_enqued = __le32_to_cpu(tx->mpdu_enqued);
1356 dst->wmm_drop = __le32_to_cpu(tx->wmm_drop);
1357 dst->local_enqued = __le32_to_cpu(tx->local_enqued);
1358 dst->local_freed = __le32_to_cpu(tx->local_freed);
1359 dst->hw_queued = __le32_to_cpu(tx->hw_queued);
1360 dst->hw_reaped = __le32_to_cpu(tx->hw_reaped);
1361 dst->underrun = __le32_to_cpu(tx->underrun);
1362 dst->tx_abort = __le32_to_cpu(tx->tx_abort);
1363 dst->mpdus_requed = __le32_to_cpu(tx->mpdus_requed);
1364 dst->tx_ko = __le32_to_cpu(tx->tx_ko);
1365 dst->data_rc = __le32_to_cpu(tx->data_rc);
1366 dst->self_triggers = __le32_to_cpu(tx->self_triggers);
1367 dst->sw_retry_failure = __le32_to_cpu(tx->sw_retry_failure);
1368 dst->illgl_rate_phy_err = __le32_to_cpu(tx->illgl_rate_phy_err);
1369 dst->pdev_cont_xretry = __le32_to_cpu(tx->pdev_cont_xretry);
1370 dst->pdev_tx_timeout = __le32_to_cpu(tx->pdev_tx_timeout);
1371 dst->pdev_resets = __le32_to_cpu(tx->pdev_resets);
1372 dst->phy_underrun = __le32_to_cpu(tx->phy_underrun);
1373 dst->txop_ovf = __le32_to_cpu(tx->txop_ovf);
1374
1375 dst->mid_ppdu_route_change = __le32_to_cpu(rx->mid_ppdu_route_change);
1376 dst->status_rcvd = __le32_to_cpu(rx->status_rcvd);
1377 dst->r0_frags = __le32_to_cpu(rx->r0_frags);
1378 dst->r1_frags = __le32_to_cpu(rx->r1_frags);
1379 dst->r2_frags = __le32_to_cpu(rx->r2_frags);
1380 dst->r3_frags = __le32_to_cpu(rx->r3_frags);
1381 dst->htt_msdus = __le32_to_cpu(rx->htt_msdus);
1382 dst->htt_mpdus = __le32_to_cpu(rx->htt_mpdus);
1383 dst->loc_msdus = __le32_to_cpu(rx->loc_msdus);
1384 dst->loc_mpdus = __le32_to_cpu(rx->loc_mpdus);
1385 dst->oversize_amsdu = __le32_to_cpu(rx->oversize_amsdu);
1386 dst->phy_errs = __le32_to_cpu(rx->phy_errs);
1387 dst->phy_err_drop = __le32_to_cpu(rx->phy_err_drop);
1388 dst->mpdu_errs = __le32_to_cpu(rx->mpdu_errs);
1389}
1390
1391static void ath10k_wmi_pull_peer_stats(const struct wmi_peer_stats *src,
1392 struct ath10k_fw_stats_peer *dst)
1393{
1394 ether_addr_copy(dst->peer_macaddr, src->peer_macaddr.addr);
1395 dst->peer_rssi = __le32_to_cpu(src->peer_rssi);
1396 dst->peer_tx_rate = __le32_to_cpu(src->peer_tx_rate);
1397}
1398
1399static int ath10k_wmi_main_pull_fw_stats(struct ath10k *ar,
1400 struct sk_buff *skb,
1401 struct ath10k_fw_stats *stats)
1402{
1403 const struct wmi_stats_event *ev = (void *)skb->data;
1404 u32 num_pdev_stats, num_vdev_stats, num_peer_stats;
1405 int i;
1406
1407 if (!skb_pull(skb, sizeof(*ev)))
1408 return -EPROTO;
1409
1410 num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
1411 num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
1412 num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
1413
1414 for (i = 0; i < num_pdev_stats; i++) {
1415 const struct wmi_pdev_stats *src;
1416 struct ath10k_fw_stats_pdev *dst;
1417
1418 src = (void *)skb->data;
1419 if (!skb_pull(skb, sizeof(*src)))
1420 return -EPROTO;
1421
1422 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1423 if (!dst)
1424 continue;
1425
1426 ath10k_wmi_pull_pdev_stats(src, dst);
1427 list_add_tail(&dst->list, &stats->pdevs);
1428 }
1429
1430 /* fw doesn't implement vdev stats */
1431
1432 for (i = 0; i < num_peer_stats; i++) {
1433 const struct wmi_peer_stats *src;
1434 struct ath10k_fw_stats_peer *dst;
1435
1436 src = (void *)skb->data;
1437 if (!skb_pull(skb, sizeof(*src)))
1438 return -EPROTO;
1439
1440 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1441 if (!dst)
1442 continue;
1443
1444 ath10k_wmi_pull_peer_stats(src, dst);
1445 list_add_tail(&dst->list, &stats->peers);
1446 }
1447
1448 return 0;
1449}
1450
1451static int ath10k_wmi_10x_pull_fw_stats(struct ath10k *ar,
1452 struct sk_buff *skb,
1453 struct ath10k_fw_stats *stats)
1454{
1455 const struct wmi_stats_event *ev = (void *)skb->data;
1456 u32 num_pdev_stats, num_vdev_stats, num_peer_stats;
1457 int i;
1458
1459 if (!skb_pull(skb, sizeof(*ev)))
1460 return -EPROTO;
1461
1462 num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
1463 num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
1464 num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
1465
1466 for (i = 0; i < num_pdev_stats; i++) {
1467 const struct wmi_10x_pdev_stats *src;
1468 struct ath10k_fw_stats_pdev *dst;
1469
1470 src = (void *)skb->data;
1471 if (!skb_pull(skb, sizeof(*src)))
1472 return -EPROTO;
1473
1474 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1475 if (!dst)
1476 continue;
1477
1478 ath10k_wmi_pull_pdev_stats(&src->old, dst);
1479
1480 dst->ack_rx_bad = __le32_to_cpu(src->ack_rx_bad);
1481 dst->rts_bad = __le32_to_cpu(src->rts_bad);
1482 dst->rts_good = __le32_to_cpu(src->rts_good);
1483 dst->fcs_bad = __le32_to_cpu(src->fcs_bad);
1484 dst->no_beacons = __le32_to_cpu(src->no_beacons);
1485 dst->mib_int_count = __le32_to_cpu(src->mib_int_count);
1486
1487 list_add_tail(&dst->list, &stats->pdevs);
1488 }
1489
1490 /* fw doesn't implement vdev stats */
1491
1492 for (i = 0; i < num_peer_stats; i++) {
1493 const struct wmi_10x_peer_stats *src;
1494 struct ath10k_fw_stats_peer *dst;
1495
1496 src = (void *)skb->data;
1497 if (!skb_pull(skb, sizeof(*src)))
1498 return -EPROTO;
1499
1500 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
1501 if (!dst)
1502 continue;
1503
1504 ath10k_wmi_pull_peer_stats(&src->old, dst);
1505
1506 dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
1507
1508 list_add_tail(&dst->list, &stats->peers);
1509 }
1510
1511 return 0;
1512}
1513
1514int ath10k_wmi_pull_fw_stats(struct ath10k *ar, struct sk_buff *skb,
1515 struct ath10k_fw_stats *stats)
1516{
1517 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
1518 return ath10k_wmi_10x_pull_fw_stats(ar, skb, stats);
1519 else
1520 return ath10k_wmi_main_pull_fw_stats(ar, skb, stats);
1521}
1522
1298static void ath10k_wmi_event_update_stats(struct ath10k *ar, 1523static void ath10k_wmi_event_update_stats(struct ath10k *ar,
1299 struct sk_buff *skb) 1524 struct sk_buff *skb)
1300{ 1525{
1301 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
1302
1303 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n"); 1526 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
1304 1527 ath10k_debug_fw_stats_process(ar, skb);
1305 ath10k_debug_read_target_stats(ar, ev);
1306} 1528}
1307 1529
1308static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar, 1530static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
@@ -1579,6 +1801,7 @@ static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1579 struct wmi_bcn_info *bcn_info; 1801 struct wmi_bcn_info *bcn_info;
1580 struct ath10k_vif *arvif; 1802 struct ath10k_vif *arvif;
1581 struct sk_buff *bcn; 1803 struct sk_buff *bcn;
1804 dma_addr_t paddr;
1582 int ret, vdev_id = 0; 1805 int ret, vdev_id = 0;
1583 1806
1584 ev = (struct wmi_host_swba_event *)skb->data; 1807 ev = (struct wmi_host_swba_event *)skb->data;
@@ -1647,27 +1870,37 @@ static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1647 ath10k_warn(ar, "SWBA overrun on vdev %d\n", 1870 ath10k_warn(ar, "SWBA overrun on vdev %d\n",
1648 arvif->vdev_id); 1871 arvif->vdev_id);
1649 1872
1650 dma_unmap_single(arvif->ar->dev, 1873 ath10k_mac_vif_beacon_free(arvif);
1651 ATH10K_SKB_CB(arvif->beacon)->paddr,
1652 arvif->beacon->len, DMA_TO_DEVICE);
1653 dev_kfree_skb_any(arvif->beacon);
1654 arvif->beacon = NULL;
1655 } 1874 }
1656 1875
1657 ATH10K_SKB_CB(bcn)->paddr = dma_map_single(arvif->ar->dev, 1876 if (!arvif->beacon_buf) {
1658 bcn->data, bcn->len, 1877 paddr = dma_map_single(arvif->ar->dev, bcn->data,
1659 DMA_TO_DEVICE); 1878 bcn->len, DMA_TO_DEVICE);
1660 ret = dma_mapping_error(arvif->ar->dev, 1879 ret = dma_mapping_error(arvif->ar->dev, paddr);
1661 ATH10K_SKB_CB(bcn)->paddr); 1880 if (ret) {
1662 if (ret) { 1881 ath10k_warn(ar, "failed to map beacon: %d\n",
1663 ath10k_warn(ar, "failed to map beacon: %d\n", ret); 1882 ret);
1664 dev_kfree_skb_any(bcn); 1883 dev_kfree_skb_any(bcn);
1665 goto skip; 1884 goto skip;
1885 }
1886
1887 ATH10K_SKB_CB(bcn)->paddr = paddr;
1888 } else {
1889 if (bcn->len > IEEE80211_MAX_FRAME_LEN) {
1890 ath10k_warn(ar, "trimming beacon %d -> %d bytes!\n",
1891 bcn->len, IEEE80211_MAX_FRAME_LEN);
1892 skb_trim(bcn, IEEE80211_MAX_FRAME_LEN);
1893 }
1894 memcpy(arvif->beacon_buf, bcn->data, bcn->len);
1895 ATH10K_SKB_CB(bcn)->paddr = arvif->beacon_paddr;
1666 } 1896 }
1667 1897
1668 arvif->beacon = bcn; 1898 arvif->beacon = bcn;
1669 arvif->beacon_sent = false; 1899 arvif->beacon_sent = false;
1670 1900
1901 trace_ath10k_tx_hdr(ar, bcn->data, bcn->len);
1902 trace_ath10k_tx_payload(ar, bcn->data, bcn->len);
1903
1671 ath10k_wmi_tx_beacon_nowait(arvif); 1904 ath10k_wmi_tx_beacon_nowait(arvif);
1672skip: 1905skip:
1673 spin_unlock_bh(&ar->data_lock); 1906 spin_unlock_bh(&ar->data_lock);
@@ -1681,8 +1914,8 @@ static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
1681} 1914}
1682 1915
1683static void ath10k_dfs_radar_report(struct ath10k *ar, 1916static void ath10k_dfs_radar_report(struct ath10k *ar,
1684 struct wmi_single_phyerr_rx_event *event, 1917 const struct wmi_phyerr *phyerr,
1685 struct phyerr_radar_report *rr, 1918 const struct phyerr_radar_report *rr,
1686 u64 tsf) 1919 u64 tsf)
1687{ 1920{
1688 u32 reg0, reg1, tsf32l; 1921 u32 reg0, reg1, tsf32l;
@@ -1715,12 +1948,12 @@ static void ath10k_dfs_radar_report(struct ath10k *ar,
1715 return; 1948 return;
1716 1949
1717 /* report event to DFS pattern detector */ 1950 /* report event to DFS pattern detector */
1718 tsf32l = __le32_to_cpu(event->hdr.tsf_timestamp); 1951 tsf32l = __le32_to_cpu(phyerr->tsf_timestamp);
1719 tsf64 = tsf & (~0xFFFFFFFFULL); 1952 tsf64 = tsf & (~0xFFFFFFFFULL);
1720 tsf64 |= tsf32l; 1953 tsf64 |= tsf32l;
1721 1954
1722 width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR); 1955 width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
1723 rssi = event->hdr.rssi_combined; 1956 rssi = phyerr->rssi_combined;
1724 1957
1725 /* hardware store this as 8 bit signed value, 1958 /* hardware store this as 8 bit signed value,
1726 * set to zero if negative number 1959 * set to zero if negative number
@@ -1759,8 +1992,8 @@ static void ath10k_dfs_radar_report(struct ath10k *ar,
1759} 1992}
1760 1993
1761static int ath10k_dfs_fft_report(struct ath10k *ar, 1994static int ath10k_dfs_fft_report(struct ath10k *ar,
1762 struct wmi_single_phyerr_rx_event *event, 1995 const struct wmi_phyerr *phyerr,
1763 struct phyerr_fft_report *fftr, 1996 const struct phyerr_fft_report *fftr,
1764 u64 tsf) 1997 u64 tsf)
1765{ 1998{
1766 u32 reg0, reg1; 1999 u32 reg0, reg1;
@@ -1768,7 +2001,7 @@ static int ath10k_dfs_fft_report(struct ath10k *ar,
1768 2001
1769 reg0 = __le32_to_cpu(fftr->reg0); 2002 reg0 = __le32_to_cpu(fftr->reg0);
1770 reg1 = __le32_to_cpu(fftr->reg1); 2003 reg1 = __le32_to_cpu(fftr->reg1);
1771 rssi = event->hdr.rssi_combined; 2004 rssi = phyerr->rssi_combined;
1772 2005
1773 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, 2006 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1774 "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n", 2007 "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
@@ -1797,20 +2030,20 @@ static int ath10k_dfs_fft_report(struct ath10k *ar,
1797} 2030}
1798 2031
1799static void ath10k_wmi_event_dfs(struct ath10k *ar, 2032static void ath10k_wmi_event_dfs(struct ath10k *ar,
1800 struct wmi_single_phyerr_rx_event *event, 2033 const struct wmi_phyerr *phyerr,
1801 u64 tsf) 2034 u64 tsf)
1802{ 2035{
1803 int buf_len, tlv_len, res, i = 0; 2036 int buf_len, tlv_len, res, i = 0;
1804 struct phyerr_tlv *tlv; 2037 const struct phyerr_tlv *tlv;
1805 struct phyerr_radar_report *rr; 2038 const struct phyerr_radar_report *rr;
1806 struct phyerr_fft_report *fftr; 2039 const struct phyerr_fft_report *fftr;
1807 u8 *tlv_buf; 2040 const u8 *tlv_buf;
1808 2041
1809 buf_len = __le32_to_cpu(event->hdr.buf_len); 2042 buf_len = __le32_to_cpu(phyerr->buf_len);
1810 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, 2043 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1811 "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n", 2044 "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
1812 event->hdr.phy_err_code, event->hdr.rssi_combined, 2045 phyerr->phy_err_code, phyerr->rssi_combined,
1813 __le32_to_cpu(event->hdr.tsf_timestamp), tsf, buf_len); 2046 __le32_to_cpu(phyerr->tsf_timestamp), tsf, buf_len);
1814 2047
1815 /* Skip event if DFS disabled */ 2048 /* Skip event if DFS disabled */
1816 if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) 2049 if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED))
@@ -1825,9 +2058,9 @@ static void ath10k_wmi_event_dfs(struct ath10k *ar,
1825 return; 2058 return;
1826 } 2059 }
1827 2060
1828 tlv = (struct phyerr_tlv *)&event->bufp[i]; 2061 tlv = (struct phyerr_tlv *)&phyerr->buf[i];
1829 tlv_len = __le16_to_cpu(tlv->len); 2062 tlv_len = __le16_to_cpu(tlv->len);
1830 tlv_buf = &event->bufp[i + sizeof(*tlv)]; 2063 tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
1831 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, 2064 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1832 "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n", 2065 "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
1833 tlv_len, tlv->tag, tlv->sig); 2066 tlv_len, tlv->tag, tlv->sig);
@@ -1841,7 +2074,7 @@ static void ath10k_wmi_event_dfs(struct ath10k *ar,
1841 } 2074 }
1842 2075
1843 rr = (struct phyerr_radar_report *)tlv_buf; 2076 rr = (struct phyerr_radar_report *)tlv_buf;
1844 ath10k_dfs_radar_report(ar, event, rr, tsf); 2077 ath10k_dfs_radar_report(ar, phyerr, rr, tsf);
1845 break; 2078 break;
1846 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT: 2079 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1847 if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) { 2080 if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
@@ -1851,7 +2084,7 @@ static void ath10k_wmi_event_dfs(struct ath10k *ar,
1851 } 2084 }
1852 2085
1853 fftr = (struct phyerr_fft_report *)tlv_buf; 2086 fftr = (struct phyerr_fft_report *)tlv_buf;
1854 res = ath10k_dfs_fft_report(ar, event, fftr, tsf); 2087 res = ath10k_dfs_fft_report(ar, phyerr, fftr, tsf);
1855 if (res) 2088 if (res)
1856 return; 2089 return;
1857 break; 2090 break;
@@ -1863,16 +2096,16 @@ static void ath10k_wmi_event_dfs(struct ath10k *ar,
1863 2096
1864static void 2097static void
1865ath10k_wmi_event_spectral_scan(struct ath10k *ar, 2098ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1866 struct wmi_single_phyerr_rx_event *event, 2099 const struct wmi_phyerr *phyerr,
1867 u64 tsf) 2100 u64 tsf)
1868{ 2101{
1869 int buf_len, tlv_len, res, i = 0; 2102 int buf_len, tlv_len, res, i = 0;
1870 struct phyerr_tlv *tlv; 2103 struct phyerr_tlv *tlv;
1871 u8 *tlv_buf; 2104 const void *tlv_buf;
1872 struct phyerr_fft_report *fftr; 2105 const struct phyerr_fft_report *fftr;
1873 size_t fftr_len; 2106 size_t fftr_len;
1874 2107
1875 buf_len = __le32_to_cpu(event->hdr.buf_len); 2108 buf_len = __le32_to_cpu(phyerr->buf_len);
1876 2109
1877 while (i < buf_len) { 2110 while (i < buf_len) {
1878 if (i + sizeof(*tlv) > buf_len) { 2111 if (i + sizeof(*tlv) > buf_len) {
@@ -1881,9 +2114,9 @@ ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1881 return; 2114 return;
1882 } 2115 }
1883 2116
1884 tlv = (struct phyerr_tlv *)&event->bufp[i]; 2117 tlv = (struct phyerr_tlv *)&phyerr->buf[i];
1885 tlv_len = __le16_to_cpu(tlv->len); 2118 tlv_len = __le16_to_cpu(tlv->len);
1886 tlv_buf = &event->bufp[i + sizeof(*tlv)]; 2119 tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
1887 2120
1888 if (i + sizeof(*tlv) + tlv_len > buf_len) { 2121 if (i + sizeof(*tlv) + tlv_len > buf_len) {
1889 ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n", 2122 ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n",
@@ -1900,8 +2133,8 @@ ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1900 } 2133 }
1901 2134
1902 fftr_len = tlv_len - sizeof(*fftr); 2135 fftr_len = tlv_len - sizeof(*fftr);
1903 fftr = (struct phyerr_fft_report *)tlv_buf; 2136 fftr = tlv_buf;
1904 res = ath10k_spectral_process_fft(ar, event, 2137 res = ath10k_spectral_process_fft(ar, phyerr,
1905 fftr, fftr_len, 2138 fftr, fftr_len,
1906 tsf); 2139 tsf);
1907 if (res < 0) { 2140 if (res < 0) {
@@ -1918,8 +2151,8 @@ ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1918 2151
1919static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb) 2152static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1920{ 2153{
1921 struct wmi_comb_phyerr_rx_event *comb_event; 2154 const struct wmi_phyerr_event *ev;
1922 struct wmi_single_phyerr_rx_event *event; 2155 const struct wmi_phyerr *phyerr;
1923 u32 count, i, buf_len, phy_err_code; 2156 u32 count, i, buf_len, phy_err_code;
1924 u64 tsf; 2157 u64 tsf;
1925 int left_len = skb->len; 2158 int left_len = skb->len;
@@ -1927,38 +2160,38 @@ static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1927 ATH10K_DFS_STAT_INC(ar, phy_errors); 2160 ATH10K_DFS_STAT_INC(ar, phy_errors);
1928 2161
1929 /* Check if combined event available */ 2162 /* Check if combined event available */
1930 if (left_len < sizeof(*comb_event)) { 2163 if (left_len < sizeof(*ev)) {
1931 ath10k_warn(ar, "wmi phyerr combined event wrong len\n"); 2164 ath10k_warn(ar, "wmi phyerr combined event wrong len\n");
1932 return; 2165 return;
1933 } 2166 }
1934 2167
1935 left_len -= sizeof(*comb_event); 2168 left_len -= sizeof(*ev);
1936 2169
1937 /* Check number of included events */ 2170 /* Check number of included events */
1938 comb_event = (struct wmi_comb_phyerr_rx_event *)skb->data; 2171 ev = (const struct wmi_phyerr_event *)skb->data;
1939 count = __le32_to_cpu(comb_event->hdr.num_phyerr_events); 2172 count = __le32_to_cpu(ev->num_phyerrs);
1940 2173
1941 tsf = __le32_to_cpu(comb_event->hdr.tsf_u32); 2174 tsf = __le32_to_cpu(ev->tsf_u32);
1942 tsf <<= 32; 2175 tsf <<= 32;
1943 tsf |= __le32_to_cpu(comb_event->hdr.tsf_l32); 2176 tsf |= __le32_to_cpu(ev->tsf_l32);
1944 2177
1945 ath10k_dbg(ar, ATH10K_DBG_WMI, 2178 ath10k_dbg(ar, ATH10K_DBG_WMI,
1946 "wmi event phyerr count %d tsf64 0x%llX\n", 2179 "wmi event phyerr count %d tsf64 0x%llX\n",
1947 count, tsf); 2180 count, tsf);
1948 2181
1949 event = (struct wmi_single_phyerr_rx_event *)comb_event->bufp; 2182 phyerr = ev->phyerrs;
1950 for (i = 0; i < count; i++) { 2183 for (i = 0; i < count; i++) {
1951 /* Check if we can read event header */ 2184 /* Check if we can read event header */
1952 if (left_len < sizeof(*event)) { 2185 if (left_len < sizeof(*phyerr)) {
1953 ath10k_warn(ar, "single event (%d) wrong head len\n", 2186 ath10k_warn(ar, "single event (%d) wrong head len\n",
1954 i); 2187 i);
1955 return; 2188 return;
1956 } 2189 }
1957 2190
1958 left_len -= sizeof(*event); 2191 left_len -= sizeof(*phyerr);
1959 2192
1960 buf_len = __le32_to_cpu(event->hdr.buf_len); 2193 buf_len = __le32_to_cpu(phyerr->buf_len);
1961 phy_err_code = event->hdr.phy_err_code; 2194 phy_err_code = phyerr->phy_err_code;
1962 2195
1963 if (left_len < buf_len) { 2196 if (left_len < buf_len) {
1964 ath10k_warn(ar, "single event (%d) wrong buf len\n", i); 2197 ath10k_warn(ar, "single event (%d) wrong buf len\n", i);
@@ -1969,20 +2202,20 @@ static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1969 2202
1970 switch (phy_err_code) { 2203 switch (phy_err_code) {
1971 case PHY_ERROR_RADAR: 2204 case PHY_ERROR_RADAR:
1972 ath10k_wmi_event_dfs(ar, event, tsf); 2205 ath10k_wmi_event_dfs(ar, phyerr, tsf);
1973 break; 2206 break;
1974 case PHY_ERROR_SPECTRAL_SCAN: 2207 case PHY_ERROR_SPECTRAL_SCAN:
1975 ath10k_wmi_event_spectral_scan(ar, event, tsf); 2208 ath10k_wmi_event_spectral_scan(ar, phyerr, tsf);
1976 break; 2209 break;
1977 case PHY_ERROR_FALSE_RADAR_EXT: 2210 case PHY_ERROR_FALSE_RADAR_EXT:
1978 ath10k_wmi_event_dfs(ar, event, tsf); 2211 ath10k_wmi_event_dfs(ar, phyerr, tsf);
1979 ath10k_wmi_event_spectral_scan(ar, event, tsf); 2212 ath10k_wmi_event_spectral_scan(ar, phyerr, tsf);
1980 break; 2213 break;
1981 default: 2214 default:
1982 break; 2215 break;
1983 } 2216 }
1984 2217
1985 event += sizeof(*event) + buf_len; 2218 phyerr = (void *)phyerr + sizeof(*phyerr) + buf_len;
1986 } 2219 }
1987} 2220}
1988 2221
@@ -2163,30 +2396,113 @@ static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
2163 return 0; 2396 return 0;
2164} 2397}
2165 2398
2166static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar, 2399static int ath10k_wmi_main_pull_svc_rdy_ev(struct sk_buff *skb,
2167 struct sk_buff *skb) 2400 struct wmi_svc_rdy_ev_arg *arg)
2168{ 2401{
2169 struct wmi_service_ready_event *ev = (void *)skb->data; 2402 struct wmi_service_ready_event *ev;
2403 size_t i, n;
2404
2405 if (skb->len < sizeof(*ev))
2406 return -EPROTO;
2407
2408 ev = (void *)skb->data;
2409 skb_pull(skb, sizeof(*ev));
2410 arg->min_tx_power = ev->hw_min_tx_power;
2411 arg->max_tx_power = ev->hw_max_tx_power;
2412 arg->ht_cap = ev->ht_cap_info;
2413 arg->vht_cap = ev->vht_cap_info;
2414 arg->sw_ver0 = ev->sw_version;
2415 arg->sw_ver1 = ev->sw_version_1;
2416 arg->phy_capab = ev->phy_capability;
2417 arg->num_rf_chains = ev->num_rf_chains;
2418 arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
2419 arg->num_mem_reqs = ev->num_mem_reqs;
2420 arg->service_map = ev->wmi_service_bitmap;
2421
2422 n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
2423 ARRAY_SIZE(arg->mem_reqs));
2424 for (i = 0; i < n; i++)
2425 arg->mem_reqs[i] = &ev->mem_reqs[i];
2426
2427 if (skb->len <
2428 __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
2429 return -EPROTO;
2430
2431 return 0;
2432}
2433
2434static int ath10k_wmi_10x_pull_svc_rdy_ev(struct sk_buff *skb,
2435 struct wmi_svc_rdy_ev_arg *arg)
2436{
2437 struct wmi_10x_service_ready_event *ev;
2438 int i, n;
2439
2440 if (skb->len < sizeof(*ev))
2441 return -EPROTO;
2442
2443 ev = (void *)skb->data;
2444 skb_pull(skb, sizeof(*ev));
2445 arg->min_tx_power = ev->hw_min_tx_power;
2446 arg->max_tx_power = ev->hw_max_tx_power;
2447 arg->ht_cap = ev->ht_cap_info;
2448 arg->vht_cap = ev->vht_cap_info;
2449 arg->sw_ver0 = ev->sw_version;
2450 arg->phy_capab = ev->phy_capability;
2451 arg->num_rf_chains = ev->num_rf_chains;
2452 arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
2453 arg->num_mem_reqs = ev->num_mem_reqs;
2454 arg->service_map = ev->wmi_service_bitmap;
2455
2456 n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
2457 ARRAY_SIZE(arg->mem_reqs));
2458 for (i = 0; i < n; i++)
2459 arg->mem_reqs[i] = &ev->mem_reqs[i];
2460
2461 if (skb->len <
2462 __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
2463 return -EPROTO;
2464
2465 return 0;
2466}
2467
2468static void ath10k_wmi_event_service_ready(struct ath10k *ar,
2469 struct sk_buff *skb)
2470{
2471 struct wmi_svc_rdy_ev_arg arg = {};
2472 u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
2170 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {}; 2473 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {};
2474 int ret;
2475
2476 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2477 ret = ath10k_wmi_10x_pull_svc_rdy_ev(skb, &arg);
2478 wmi_10x_svc_map(arg.service_map, svc_bmap);
2479 } else {
2480 ret = ath10k_wmi_main_pull_svc_rdy_ev(skb, &arg);
2481 wmi_main_svc_map(arg.service_map, svc_bmap);
2482 }
2171 2483
2172 if (skb->len < sizeof(*ev)) { 2484 if (ret) {
2173 ath10k_warn(ar, "Service ready event was %d B but expected %zu B. Wrong firmware version?\n", 2485 ath10k_warn(ar, "failed to parse service ready: %d\n", ret);
2174 skb->len, sizeof(*ev));
2175 return; 2486 return;
2176 } 2487 }
2177 2488
2178 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power); 2489 ar->hw_min_tx_power = __le32_to_cpu(arg.min_tx_power);
2179 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power); 2490 ar->hw_max_tx_power = __le32_to_cpu(arg.max_tx_power);
2180 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info); 2491 ar->ht_cap_info = __le32_to_cpu(arg.ht_cap);
2181 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info); 2492 ar->vht_cap_info = __le32_to_cpu(arg.vht_cap);
2182 ar->fw_version_major = 2493 ar->fw_version_major =
2183 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24; 2494 (__le32_to_cpu(arg.sw_ver0) & 0xff000000) >> 24;
2184 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff); 2495 ar->fw_version_minor = (__le32_to_cpu(arg.sw_ver0) & 0x00ffffff);
2185 ar->fw_version_release = 2496 ar->fw_version_release =
2186 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16; 2497 (__le32_to_cpu(arg.sw_ver1) & 0xffff0000) >> 16;
2187 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff); 2498 ar->fw_version_build = (__le32_to_cpu(arg.sw_ver1) & 0x0000ffff);
2188 ar->phy_capability = __le32_to_cpu(ev->phy_capability); 2499 ar->phy_capability = __le32_to_cpu(arg.phy_capab);
2189 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains); 2500 ar->num_rf_chains = __le32_to_cpu(arg.num_rf_chains);
2501 ar->ath_common.regulatory.current_rd = __le32_to_cpu(arg.eeprom_rd);
2502
2503 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2504 ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
2505 arg.service_map, sizeof(arg.service_map));
2190 2506
2191 /* only manually set fw features when not using FW IE format */ 2507 /* only manually set fw features when not using FW IE format */
2192 if (ar->fw_api == 1 && ar->fw_version_build > 636) 2508 if (ar->fw_api == 1 && ar->fw_version_build > 636)
@@ -2198,13 +2514,8 @@ static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
2198 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM; 2514 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2199 } 2515 }
2200 2516
2201 ar->ath_common.regulatory.current_rd = 2517 ar->supp_tx_chainmask = (1 << ar->num_rf_chains) - 1;
2202 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd); 2518 ar->supp_rx_chainmask = (1 << ar->num_rf_chains) - 1;
2203
2204 wmi_main_svc_map(ev->wmi_service_bitmap, svc_bmap);
2205 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2206 ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
2207 ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
2208 2519
2209 if (strlen(ar->hw->wiphy->fw_version) == 0) { 2520 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2210 snprintf(ar->hw->wiphy->fw_version, 2521 snprintf(ar->hw->wiphy->fw_version,
@@ -2216,93 +2527,18 @@ static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
2216 ar->fw_version_build); 2527 ar->fw_version_build);
2217 } 2528 }
2218 2529
2219 /* FIXME: it probably should be better to support this */ 2530 num_mem_reqs = __le32_to_cpu(arg.num_mem_reqs);
2220 if (__le32_to_cpu(ev->num_mem_reqs) > 0) { 2531 if (num_mem_reqs > WMI_MAX_MEM_REQS) {
2221 ath10k_warn(ar, "target requested %d memory chunks; ignoring\n",
2222 __le32_to_cpu(ev->num_mem_reqs));
2223 }
2224
2225 ath10k_dbg(ar, ATH10K_DBG_WMI,
2226 "wmi event service ready sw_ver 0x%08x sw_ver1 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u num_rf_chains %u\n",
2227 __le32_to_cpu(ev->sw_version),
2228 __le32_to_cpu(ev->sw_version_1),
2229 __le32_to_cpu(ev->abi_version),
2230 __le32_to_cpu(ev->phy_capability),
2231 __le32_to_cpu(ev->ht_cap_info),
2232 __le32_to_cpu(ev->vht_cap_info),
2233 __le32_to_cpu(ev->vht_supp_mcs),
2234 __le32_to_cpu(ev->sys_cap_info),
2235 __le32_to_cpu(ev->num_mem_reqs),
2236 __le32_to_cpu(ev->num_rf_chains));
2237
2238 complete(&ar->wmi.service_ready);
2239}
2240
2241static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2242 struct sk_buff *skb)
2243{
2244 u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
2245 int ret;
2246 struct wmi_service_ready_event_10x *ev = (void *)skb->data;
2247 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {};
2248
2249 if (skb->len < sizeof(*ev)) {
2250 ath10k_warn(ar, "Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2251 skb->len, sizeof(*ev));
2252 return;
2253 }
2254
2255 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2256 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2257 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2258 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2259 ar->fw_version_major =
2260 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2261 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2262 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
2263 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2264
2265 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2266 ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
2267 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2268 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2269 }
2270
2271 ar->ath_common.regulatory.current_rd =
2272 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2273
2274 wmi_10x_svc_map(ev->wmi_service_bitmap, svc_bmap);
2275 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2276 ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
2277 ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
2278
2279 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2280 snprintf(ar->hw->wiphy->fw_version,
2281 sizeof(ar->hw->wiphy->fw_version),
2282 "%u.%u",
2283 ar->fw_version_major,
2284 ar->fw_version_minor);
2285 }
2286
2287 num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
2288
2289 if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
2290 ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n", 2532 ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n",
2291 num_mem_reqs); 2533 num_mem_reqs);
2292 return; 2534 return;
2293 } 2535 }
2294 2536
2295 if (!num_mem_reqs)
2296 goto exit;
2297
2298 ath10k_dbg(ar, ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
2299 num_mem_reqs);
2300
2301 for (i = 0; i < num_mem_reqs; ++i) { 2537 for (i = 0; i < num_mem_reqs; ++i) {
2302 req_id = __le32_to_cpu(ev->mem_reqs[i].req_id); 2538 req_id = __le32_to_cpu(arg.mem_reqs[i]->req_id);
2303 num_units = __le32_to_cpu(ev->mem_reqs[i].num_units); 2539 num_units = __le32_to_cpu(arg.mem_reqs[i]->num_units);
2304 unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size); 2540 unit_size = __le32_to_cpu(arg.mem_reqs[i]->unit_size);
2305 num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info); 2541 num_unit_info = __le32_to_cpu(arg.mem_reqs[i]->num_unit_info);
2306 2542
2307 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) 2543 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
2308 /* number of units to allocate is number of 2544 /* number of units to allocate is number of
@@ -2316,7 +2552,7 @@ static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2316 ath10k_dbg(ar, ATH10K_DBG_WMI, 2552 ath10k_dbg(ar, ATH10K_DBG_WMI,
2317 "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n", 2553 "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
2318 req_id, 2554 req_id,
2319 __le32_to_cpu(ev->mem_reqs[i].num_units), 2555 __le32_to_cpu(arg.mem_reqs[i]->num_units),
2320 num_unit_info, 2556 num_unit_info,
2321 unit_size, 2557 unit_size,
2322 num_units); 2558 num_units);
@@ -2327,23 +2563,23 @@ static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2327 return; 2563 return;
2328 } 2564 }
2329 2565
2330exit:
2331 ath10k_dbg(ar, ATH10K_DBG_WMI, 2566 ath10k_dbg(ar, ATH10K_DBG_WMI,
2332 "wmi event service ready sw_ver 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u num_rf_chains %u\n", 2567 "wmi event service ready min_tx_power 0x%08x max_tx_power 0x%08x ht_cap 0x%08x vht_cap 0x%08x sw_ver0 0x%08x sw_ver1 0x%08x phy_capab 0x%08x num_rf_chains 0x%08x eeprom_rd 0x%08x num_mem_reqs 0x%08x\n",
2333 __le32_to_cpu(ev->sw_version), 2568 __le32_to_cpu(arg.min_tx_power),
2334 __le32_to_cpu(ev->abi_version), 2569 __le32_to_cpu(arg.max_tx_power),
2335 __le32_to_cpu(ev->phy_capability), 2570 __le32_to_cpu(arg.ht_cap),
2336 __le32_to_cpu(ev->ht_cap_info), 2571 __le32_to_cpu(arg.vht_cap),
2337 __le32_to_cpu(ev->vht_cap_info), 2572 __le32_to_cpu(arg.sw_ver0),
2338 __le32_to_cpu(ev->vht_supp_mcs), 2573 __le32_to_cpu(arg.sw_ver1),
2339 __le32_to_cpu(ev->sys_cap_info), 2574 __le32_to_cpu(arg.phy_capab),
2340 __le32_to_cpu(ev->num_mem_reqs), 2575 __le32_to_cpu(arg.num_rf_chains),
2341 __le32_to_cpu(ev->num_rf_chains)); 2576 __le32_to_cpu(arg.eeprom_rd),
2577 __le32_to_cpu(arg.num_mem_reqs));
2342 2578
2343 complete(&ar->wmi.service_ready); 2579 complete(&ar->wmi.service_ready);
2344} 2580}
2345 2581
2346static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb) 2582static int ath10k_wmi_event_ready(struct ath10k *ar, struct sk_buff *skb)
2347{ 2583{
2348 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data; 2584 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
2349 2585
@@ -2466,10 +2702,10 @@ static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
2466 ath10k_wmi_event_vdev_install_key_complete(ar, skb); 2702 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
2467 break; 2703 break;
2468 case WMI_SERVICE_READY_EVENTID: 2704 case WMI_SERVICE_READY_EVENTID:
2469 ath10k_wmi_service_ready_event_rx(ar, skb); 2705 ath10k_wmi_event_service_ready(ar, skb);
2470 break; 2706 break;
2471 case WMI_READY_EVENTID: 2707 case WMI_READY_EVENTID:
2472 ath10k_wmi_ready_event_rx(ar, skb); 2708 ath10k_wmi_event_ready(ar, skb);
2473 break; 2709 break;
2474 default: 2710 default:
2475 ath10k_warn(ar, "Unknown eventid: %d\n", id); 2711 ath10k_warn(ar, "Unknown eventid: %d\n", id);
@@ -2586,10 +2822,10 @@ static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
2586 ath10k_wmi_event_vdev_resume_req(ar, skb); 2822 ath10k_wmi_event_vdev_resume_req(ar, skb);
2587 break; 2823 break;
2588 case WMI_10X_SERVICE_READY_EVENTID: 2824 case WMI_10X_SERVICE_READY_EVENTID:
2589 ath10k_wmi_10x_service_ready_event_rx(ar, skb); 2825 ath10k_wmi_event_service_ready(ar, skb);
2590 break; 2826 break;
2591 case WMI_10X_READY_EVENTID: 2827 case WMI_10X_READY_EVENTID:
2592 ath10k_wmi_ready_event_rx(ar, skb); 2828 ath10k_wmi_event_ready(ar, skb);
2593 break; 2829 break;
2594 case WMI_10X_PDEV_UTF_EVENTID: 2830 case WMI_10X_PDEV_UTF_EVENTID:
2595 /* ignore utf events */ 2831 /* ignore utf events */
@@ -2697,10 +2933,10 @@ static void ath10k_wmi_10_2_process_rx(struct ath10k *ar, struct sk_buff *skb)
2697 ath10k_wmi_event_vdev_resume_req(ar, skb); 2933 ath10k_wmi_event_vdev_resume_req(ar, skb);
2698 break; 2934 break;
2699 case WMI_10_2_SERVICE_READY_EVENTID: 2935 case WMI_10_2_SERVICE_READY_EVENTID:
2700 ath10k_wmi_10x_service_ready_event_rx(ar, skb); 2936 ath10k_wmi_event_service_ready(ar, skb);
2701 break; 2937 break;
2702 case WMI_10_2_READY_EVENTID: 2938 case WMI_10_2_READY_EVENTID:
2703 ath10k_wmi_ready_event_rx(ar, skb); 2939 ath10k_wmi_event_ready(ar, skb);
2704 break; 2940 break;
2705 case WMI_10_2_RTT_KEEPALIVE_EVENTID: 2941 case WMI_10_2_RTT_KEEPALIVE_EVENTID:
2706 case WMI_10_2_GPIO_INPUT_EVENTID: 2942 case WMI_10_2_GPIO_INPUT_EVENTID:
@@ -2732,45 +2968,6 @@ static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
2732 } 2968 }
2733} 2969}
2734 2970
2735/* WMI Initialization functions */
2736int ath10k_wmi_attach(struct ath10k *ar)
2737{
2738 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2739 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2740 ar->wmi.cmd = &wmi_10_2_cmd_map;
2741 else
2742 ar->wmi.cmd = &wmi_10x_cmd_map;
2743
2744 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
2745 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
2746 } else {
2747 ar->wmi.cmd = &wmi_cmd_map;
2748 ar->wmi.vdev_param = &wmi_vdev_param_map;
2749 ar->wmi.pdev_param = &wmi_pdev_param_map;
2750 }
2751
2752 init_completion(&ar->wmi.service_ready);
2753 init_completion(&ar->wmi.unified_ready);
2754 init_waitqueue_head(&ar->wmi.tx_credits_wq);
2755
2756 return 0;
2757}
2758
2759void ath10k_wmi_detach(struct ath10k *ar)
2760{
2761 int i;
2762
2763 /* free the host memory chunks requested by firmware */
2764 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2765 dma_free_coherent(ar->dev,
2766 ar->wmi.mem_chunks[i].len,
2767 ar->wmi.mem_chunks[i].vaddr,
2768 ar->wmi.mem_chunks[i].paddr);
2769 }
2770
2771 ar->wmi.num_mem_chunks = 0;
2772}
2773
2774int ath10k_wmi_connect(struct ath10k *ar) 2971int ath10k_wmi_connect(struct ath10k *ar)
2775{ 2972{
2776 int status; 2973 int status;
@@ -2865,42 +3062,6 @@ int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
2865 ctl2g, ctl5g); 3062 ctl2g, ctl5g);
2866} 3063}
2867 3064
2868int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
2869 const struct wmi_channel_arg *arg)
2870{
2871 struct wmi_set_channel_cmd *cmd;
2872 struct sk_buff *skb;
2873 u32 ch_flags = 0;
2874
2875 if (arg->passive)
2876 return -EINVAL;
2877
2878 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
2879 if (!skb)
2880 return -ENOMEM;
2881
2882 if (arg->chan_radar)
2883 ch_flags |= WMI_CHAN_FLAG_DFS;
2884
2885 cmd = (struct wmi_set_channel_cmd *)skb->data;
2886 cmd->chan.mhz = __cpu_to_le32(arg->freq);
2887 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
2888 cmd->chan.mode = arg->mode;
2889 cmd->chan.flags |= __cpu_to_le32(ch_flags);
2890 cmd->chan.min_power = arg->min_power;
2891 cmd->chan.max_power = arg->max_power;
2892 cmd->chan.reg_power = arg->max_reg_power;
2893 cmd->chan.reg_classid = arg->reg_class_id;
2894 cmd->chan.antenna_max = arg->max_antenna_gain;
2895
2896 ath10k_dbg(ar, ATH10K_DBG_WMI,
2897 "wmi set channel mode %d freq %d\n",
2898 arg->mode, arg->freq);
2899
2900 return ath10k_wmi_cmd_send(ar, skb,
2901 ar->wmi.cmd->pdev_set_channel_cmdid);
2902}
2903
2904int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt) 3065int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt)
2905{ 3066{
2906 struct wmi_pdev_suspend_cmd *cmd; 3067 struct wmi_pdev_suspend_cmd *cmd;
@@ -2951,13 +3112,34 @@ int ath10k_wmi_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
2951 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid); 3112 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
2952} 3113}
2953 3114
3115static void ath10k_wmi_put_host_mem_chunks(struct ath10k *ar,
3116 struct wmi_host_mem_chunks *chunks)
3117{
3118 struct host_memory_chunk *chunk;
3119 int i;
3120
3121 chunks->count = __cpu_to_le32(ar->wmi.num_mem_chunks);
3122
3123 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3124 chunk = &chunks->items[i];
3125 chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3126 chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3127 chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3128
3129 ath10k_dbg(ar, ATH10K_DBG_WMI,
3130 "wmi chunk %d len %d requested, addr 0x%llx\n",
3131 i,
3132 ar->wmi.mem_chunks[i].len,
3133 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3134 }
3135}
3136
2954static int ath10k_wmi_main_cmd_init(struct ath10k *ar) 3137static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
2955{ 3138{
2956 struct wmi_init_cmd *cmd; 3139 struct wmi_init_cmd *cmd;
2957 struct sk_buff *buf; 3140 struct sk_buff *buf;
2958 struct wmi_resource_config config = {}; 3141 struct wmi_resource_config config = {};
2959 u32 len, val; 3142 u32 len, val;
2960 int i;
2961 3143
2962 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS); 3144 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
2963 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS); 3145 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
@@ -3019,32 +3201,8 @@ static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
3019 3201
3020 cmd = (struct wmi_init_cmd *)buf->data; 3202 cmd = (struct wmi_init_cmd *)buf->data;
3021 3203
3022 if (ar->wmi.num_mem_chunks == 0) {
3023 cmd->num_host_mem_chunks = 0;
3024 goto out;
3025 }
3026
3027 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3028 ar->wmi.num_mem_chunks);
3029
3030 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3031
3032 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3033 cmd->host_mem_chunks[i].ptr =
3034 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3035 cmd->host_mem_chunks[i].size =
3036 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3037 cmd->host_mem_chunks[i].req_id =
3038 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3039
3040 ath10k_dbg(ar, ATH10K_DBG_WMI,
3041 "wmi chunk %d len %d requested, addr 0x%llx\n",
3042 i,
3043 ar->wmi.mem_chunks[i].len,
3044 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3045 }
3046out:
3047 memcpy(&cmd->resource_config, &config, sizeof(config)); 3204 memcpy(&cmd->resource_config, &config, sizeof(config));
3205 ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
3048 3206
3049 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n"); 3207 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n");
3050 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid); 3208 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
@@ -3056,7 +3214,6 @@ static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
3056 struct sk_buff *buf; 3214 struct sk_buff *buf;
3057 struct wmi_resource_config_10x config = {}; 3215 struct wmi_resource_config_10x config = {};
3058 u32 len, val; 3216 u32 len, val;
3059 int i;
3060 3217
3061 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS); 3218 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3062 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS); 3219 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
@@ -3110,32 +3267,8 @@ static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
3110 3267
3111 cmd = (struct wmi_init_cmd_10x *)buf->data; 3268 cmd = (struct wmi_init_cmd_10x *)buf->data;
3112 3269
3113 if (ar->wmi.num_mem_chunks == 0) {
3114 cmd->num_host_mem_chunks = 0;
3115 goto out;
3116 }
3117
3118 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3119 ar->wmi.num_mem_chunks);
3120
3121 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3122
3123 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3124 cmd->host_mem_chunks[i].ptr =
3125 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3126 cmd->host_mem_chunks[i].size =
3127 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3128 cmd->host_mem_chunks[i].req_id =
3129 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3130
3131 ath10k_dbg(ar, ATH10K_DBG_WMI,
3132 "wmi chunk %d len %d requested, addr 0x%llx\n",
3133 i,
3134 ar->wmi.mem_chunks[i].len,
3135 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3136 }
3137out:
3138 memcpy(&cmd->resource_config, &config, sizeof(config)); 3270 memcpy(&cmd->resource_config, &config, sizeof(config));
3271 ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
3139 3272
3140 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n"); 3273 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n");
3141 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid); 3274 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
@@ -3147,7 +3280,6 @@ static int ath10k_wmi_10_2_cmd_init(struct ath10k *ar)
3147 struct sk_buff *buf; 3280 struct sk_buff *buf;
3148 struct wmi_resource_config_10x config = {}; 3281 struct wmi_resource_config_10x config = {};
3149 u32 len, val; 3282 u32 len, val;
3150 int i;
3151 3283
3152 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS); 3284 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3153 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS); 3285 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
@@ -3201,32 +3333,8 @@ static int ath10k_wmi_10_2_cmd_init(struct ath10k *ar)
3201 3333
3202 cmd = (struct wmi_init_cmd_10_2 *)buf->data; 3334 cmd = (struct wmi_init_cmd_10_2 *)buf->data;
3203 3335
3204 if (ar->wmi.num_mem_chunks == 0) {
3205 cmd->num_host_mem_chunks = 0;
3206 goto out;
3207 }
3208
3209 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3210 ar->wmi.num_mem_chunks);
3211
3212 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3213
3214 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3215 cmd->host_mem_chunks[i].ptr =
3216 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3217 cmd->host_mem_chunks[i].size =
3218 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3219 cmd->host_mem_chunks[i].req_id =
3220 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3221
3222 ath10k_dbg(ar, ATH10K_DBG_WMI,
3223 "wmi chunk %d len %d requested, addr 0x%llx\n",
3224 i,
3225 ar->wmi.mem_chunks[i].len,
3226 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3227 }
3228out:
3229 memcpy(&cmd->resource_config.common, &config, sizeof(config)); 3336 memcpy(&cmd->resource_config.common, &config, sizeof(config));
3337 ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
3230 3338
3231 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n"); 3339 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n");
3232 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid); 3340 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
@@ -3248,52 +3356,50 @@ int ath10k_wmi_cmd_init(struct ath10k *ar)
3248 return ret; 3356 return ret;
3249} 3357}
3250 3358
3251static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar, 3359static int ath10k_wmi_start_scan_verify(const struct wmi_start_scan_arg *arg)
3252 const struct wmi_start_scan_arg *arg)
3253{ 3360{
3254 int len; 3361 if (arg->ie_len && !arg->ie)
3362 return -EINVAL;
3363 if (arg->n_channels && !arg->channels)
3364 return -EINVAL;
3365 if (arg->n_ssids && !arg->ssids)
3366 return -EINVAL;
3367 if (arg->n_bssids && !arg->bssids)
3368 return -EINVAL;
3255 3369
3256 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) 3370 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
3257 len = sizeof(struct wmi_start_scan_cmd_10x); 3371 return -EINVAL;
3258 else 3372 if (arg->n_channels > ARRAY_SIZE(arg->channels))
3259 len = sizeof(struct wmi_start_scan_cmd); 3373 return -EINVAL;
3374 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
3375 return -EINVAL;
3376 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
3377 return -EINVAL;
3260 3378
3261 if (arg->ie_len) { 3379 return 0;
3262 if (!arg->ie) 3380}
3263 return -EINVAL; 3381
3264 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN) 3382static size_t
3265 return -EINVAL; 3383ath10k_wmi_start_scan_tlvs_len(const struct wmi_start_scan_arg *arg)
3384{
3385 int len = 0;
3266 3386
3387 if (arg->ie_len) {
3267 len += sizeof(struct wmi_ie_data); 3388 len += sizeof(struct wmi_ie_data);
3268 len += roundup(arg->ie_len, 4); 3389 len += roundup(arg->ie_len, 4);
3269 } 3390 }
3270 3391
3271 if (arg->n_channels) { 3392 if (arg->n_channels) {
3272 if (!arg->channels)
3273 return -EINVAL;
3274 if (arg->n_channels > ARRAY_SIZE(arg->channels))
3275 return -EINVAL;
3276
3277 len += sizeof(struct wmi_chan_list); 3393 len += sizeof(struct wmi_chan_list);
3278 len += sizeof(__le32) * arg->n_channels; 3394 len += sizeof(__le32) * arg->n_channels;
3279 } 3395 }
3280 3396
3281 if (arg->n_ssids) { 3397 if (arg->n_ssids) {
3282 if (!arg->ssids)
3283 return -EINVAL;
3284 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
3285 return -EINVAL;
3286
3287 len += sizeof(struct wmi_ssid_list); 3398 len += sizeof(struct wmi_ssid_list);
3288 len += sizeof(struct wmi_ssid) * arg->n_ssids; 3399 len += sizeof(struct wmi_ssid) * arg->n_ssids;
3289 } 3400 }
3290 3401
3291 if (arg->n_bssids) { 3402 if (arg->n_bssids) {
3292 if (!arg->bssids)
3293 return -EINVAL;
3294 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
3295 return -EINVAL;
3296
3297 len += sizeof(struct wmi_bssid_list); 3403 len += sizeof(struct wmi_bssid_list);
3298 len += sizeof(struct wmi_mac_addr) * arg->n_bssids; 3404 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3299 } 3405 }
@@ -3301,28 +3407,12 @@ static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar,
3301 return len; 3407 return len;
3302} 3408}
3303 3409
3304int ath10k_wmi_start_scan(struct ath10k *ar, 3410static void
3305 const struct wmi_start_scan_arg *arg) 3411ath10k_wmi_put_start_scan_common(struct wmi_start_scan_common *cmn,
3412 const struct wmi_start_scan_arg *arg)
3306{ 3413{
3307 struct wmi_start_scan_cmd *cmd;
3308 struct sk_buff *skb;
3309 struct wmi_ie_data *ie;
3310 struct wmi_chan_list *channels;
3311 struct wmi_ssid_list *ssids;
3312 struct wmi_bssid_list *bssids;
3313 u32 scan_id; 3414 u32 scan_id;
3314 u32 scan_req_id; 3415 u32 scan_req_id;
3315 int off;
3316 int len = 0;
3317 int i;
3318
3319 len = ath10k_wmi_start_scan_calc_len(ar, arg);
3320 if (len < 0)
3321 return len; /* len contains error code here */
3322
3323 skb = ath10k_wmi_alloc_skb(ar, len);
3324 if (!skb)
3325 return -ENOMEM;
3326 3416
3327 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX; 3417 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
3328 scan_id |= arg->scan_id; 3418 scan_id |= arg->scan_id;
@@ -3330,35 +3420,36 @@ int ath10k_wmi_start_scan(struct ath10k *ar,
3330 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX; 3420 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3331 scan_req_id |= arg->scan_req_id; 3421 scan_req_id |= arg->scan_req_id;
3332 3422
3333 cmd = (struct wmi_start_scan_cmd *)skb->data; 3423 cmn->scan_id = __cpu_to_le32(scan_id);
3334 cmd->scan_id = __cpu_to_le32(scan_id); 3424 cmn->scan_req_id = __cpu_to_le32(scan_req_id);
3335 cmd->scan_req_id = __cpu_to_le32(scan_req_id); 3425 cmn->vdev_id = __cpu_to_le32(arg->vdev_id);
3336 cmd->vdev_id = __cpu_to_le32(arg->vdev_id); 3426 cmn->scan_priority = __cpu_to_le32(arg->scan_priority);
3337 cmd->scan_priority = __cpu_to_le32(arg->scan_priority); 3427 cmn->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
3338 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events); 3428 cmn->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
3339 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active); 3429 cmn->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
3340 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive); 3430 cmn->min_rest_time = __cpu_to_le32(arg->min_rest_time);
3341 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time); 3431 cmn->max_rest_time = __cpu_to_le32(arg->max_rest_time);
3342 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time); 3432 cmn->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
3343 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time); 3433 cmn->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
3344 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time); 3434 cmn->idle_time = __cpu_to_le32(arg->idle_time);
3345 cmd->idle_time = __cpu_to_le32(arg->idle_time); 3435 cmn->max_scan_time = __cpu_to_le32(arg->max_scan_time);
3346 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time); 3436 cmn->probe_delay = __cpu_to_le32(arg->probe_delay);
3347 cmd->probe_delay = __cpu_to_le32(arg->probe_delay); 3437 cmn->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
3348 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags); 3438}
3349 3439
3350 /* TLV list starts after fields included in the struct */ 3440static void
3351 /* There's just one filed that differes the two start_scan 3441ath10k_wmi_put_start_scan_tlvs(struct wmi_start_scan_tlvs *tlvs,
3352 * structures - burst_duration, which we are not using btw, 3442 const struct wmi_start_scan_arg *arg)
3353 no point to make the split here, just shift the buffer to fit with 3443{
3354 given FW */ 3444 struct wmi_ie_data *ie;
3355 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) 3445 struct wmi_chan_list *channels;
3356 off = sizeof(struct wmi_start_scan_cmd_10x); 3446 struct wmi_ssid_list *ssids;
3357 else 3447 struct wmi_bssid_list *bssids;
3358 off = sizeof(struct wmi_start_scan_cmd); 3448 void *ptr = tlvs->tlvs;
3449 int i;
3359 3450
3360 if (arg->n_channels) { 3451 if (arg->n_channels) {
3361 channels = (void *)skb->data + off; 3452 channels = ptr;
3362 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG); 3453 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
3363 channels->num_chan = __cpu_to_le32(arg->n_channels); 3454 channels->num_chan = __cpu_to_le32(arg->n_channels);
3364 3455
@@ -3366,12 +3457,12 @@ int ath10k_wmi_start_scan(struct ath10k *ar,
3366 channels->channel_list[i].freq = 3457 channels->channel_list[i].freq =
3367 __cpu_to_le16(arg->channels[i]); 3458 __cpu_to_le16(arg->channels[i]);
3368 3459
3369 off += sizeof(*channels); 3460 ptr += sizeof(*channels);
3370 off += sizeof(__le32) * arg->n_channels; 3461 ptr += sizeof(__le32) * arg->n_channels;
3371 } 3462 }
3372 3463
3373 if (arg->n_ssids) { 3464 if (arg->n_ssids) {
3374 ssids = (void *)skb->data + off; 3465 ssids = ptr;
3375 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG); 3466 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
3376 ssids->num_ssids = __cpu_to_le32(arg->n_ssids); 3467 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
3377 3468
@@ -3383,12 +3474,12 @@ int ath10k_wmi_start_scan(struct ath10k *ar,
3383 arg->ssids[i].len); 3474 arg->ssids[i].len);
3384 } 3475 }
3385 3476
3386 off += sizeof(*ssids); 3477 ptr += sizeof(*ssids);
3387 off += sizeof(struct wmi_ssid) * arg->n_ssids; 3478 ptr += sizeof(struct wmi_ssid) * arg->n_ssids;
3388 } 3479 }
3389 3480
3390 if (arg->n_bssids) { 3481 if (arg->n_bssids) {
3391 bssids = (void *)skb->data + off; 3482 bssids = ptr;
3392 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG); 3483 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
3393 bssids->num_bssid = __cpu_to_le32(arg->n_bssids); 3484 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
3394 3485
@@ -3397,23 +3488,57 @@ int ath10k_wmi_start_scan(struct ath10k *ar,
3397 arg->bssids[i].bssid, 3488 arg->bssids[i].bssid,
3398 ETH_ALEN); 3489 ETH_ALEN);
3399 3490
3400 off += sizeof(*bssids); 3491 ptr += sizeof(*bssids);
3401 off += sizeof(struct wmi_mac_addr) * arg->n_bssids; 3492 ptr += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3402 } 3493 }
3403 3494
3404 if (arg->ie_len) { 3495 if (arg->ie_len) {
3405 ie = (void *)skb->data + off; 3496 ie = ptr;
3406 ie->tag = __cpu_to_le32(WMI_IE_TAG); 3497 ie->tag = __cpu_to_le32(WMI_IE_TAG);
3407 ie->ie_len = __cpu_to_le32(arg->ie_len); 3498 ie->ie_len = __cpu_to_le32(arg->ie_len);
3408 memcpy(ie->ie_data, arg->ie, arg->ie_len); 3499 memcpy(ie->ie_data, arg->ie, arg->ie_len);
3409 3500
3410 off += sizeof(*ie); 3501 ptr += sizeof(*ie);
3411 off += roundup(arg->ie_len, 4); 3502 ptr += roundup(arg->ie_len, 4);
3412 } 3503 }
3504}
3413 3505
3414 if (off != skb->len) { 3506int ath10k_wmi_start_scan(struct ath10k *ar,
3415 dev_kfree_skb(skb); 3507 const struct wmi_start_scan_arg *arg)
3416 return -EINVAL; 3508{
3509 struct sk_buff *skb;
3510 size_t len;
3511 int ret;
3512
3513 ret = ath10k_wmi_start_scan_verify(arg);
3514 if (ret)
3515 return ret;
3516
3517 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3518 len = sizeof(struct wmi_10x_start_scan_cmd) +
3519 ath10k_wmi_start_scan_tlvs_len(arg);
3520 else
3521 len = sizeof(struct wmi_start_scan_cmd) +
3522 ath10k_wmi_start_scan_tlvs_len(arg);
3523
3524 skb = ath10k_wmi_alloc_skb(ar, len);
3525 if (!skb)
3526 return -ENOMEM;
3527
3528 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3529 struct wmi_10x_start_scan_cmd *cmd;
3530
3531 cmd = (struct wmi_10x_start_scan_cmd *)skb->data;
3532 ath10k_wmi_put_start_scan_common(&cmd->common, arg);
3533 ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
3534 } else {
3535 struct wmi_start_scan_cmd *cmd;
3536
3537 cmd = (struct wmi_start_scan_cmd *)skb->data;
3538 cmd->burst_duration_ms = __cpu_to_le32(0);
3539
3540 ath10k_wmi_put_start_scan_common(&cmd->common, arg);
3541 ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
3417 } 3542 }
3418 3543
3419 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n"); 3544 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n");
@@ -3532,7 +3657,6 @@ ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3532 struct sk_buff *skb; 3657 struct sk_buff *skb;
3533 const char *cmdname; 3658 const char *cmdname;
3534 u32 flags = 0; 3659 u32 flags = 0;
3535 u32 ch_flags = 0;
3536 3660
3537 if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid && 3661 if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
3538 cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid) 3662 cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
@@ -3559,8 +3683,6 @@ ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3559 flags |= WMI_VDEV_START_HIDDEN_SSID; 3683 flags |= WMI_VDEV_START_HIDDEN_SSID;
3560 if (arg->pmf_enabled) 3684 if (arg->pmf_enabled)
3561 flags |= WMI_VDEV_START_PMF_ENABLED; 3685 flags |= WMI_VDEV_START_PMF_ENABLED;
3562 if (arg->channel.chan_radar)
3563 ch_flags |= WMI_CHAN_FLAG_DFS;
3564 3686
3565 cmd = (struct wmi_vdev_start_request_cmd *)skb->data; 3687 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
3566 cmd->vdev_id = __cpu_to_le32(arg->vdev_id); 3688 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
@@ -3576,18 +3698,7 @@ ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3576 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len); 3698 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
3577 } 3699 }
3578 3700
3579 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq); 3701 ath10k_wmi_put_wmi_channel(&cmd->chan, &arg->channel);
3580
3581 cmd->chan.band_center_freq1 =
3582 __cpu_to_le32(arg->channel.band_center_freq1);
3583
3584 cmd->chan.mode = arg->channel.mode;
3585 cmd->chan.flags |= __cpu_to_le32(ch_flags);
3586 cmd->chan.min_power = arg->channel.min_power;
3587 cmd->chan.max_power = arg->channel.max_power;
3588 cmd->chan.reg_power = arg->channel.max_reg_power;
3589 cmd->chan.reg_classid = arg->channel.reg_class_id;
3590 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
3591 3702
3592 ath10k_dbg(ar, ATH10K_DBG_WMI, 3703 ath10k_dbg(ar, ATH10K_DBG_WMI,
3593 "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n", 3704 "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n",
@@ -3968,35 +4079,10 @@ int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3968 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels); 4079 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3969 4080
3970 for (i = 0; i < arg->n_channels; i++) { 4081 for (i = 0; i < arg->n_channels; i++) {
3971 u32 flags = 0;
3972
3973 ch = &arg->channels[i]; 4082 ch = &arg->channels[i];
3974 ci = &cmd->chan_info[i]; 4083 ci = &cmd->chan_info[i];
3975 4084
3976 if (ch->passive) 4085 ath10k_wmi_put_wmi_channel(ci, ch);
3977 flags |= WMI_CHAN_FLAG_PASSIVE;
3978 if (ch->allow_ibss)
3979 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
3980 if (ch->allow_ht)
3981 flags |= WMI_CHAN_FLAG_ALLOW_HT;
3982 if (ch->allow_vht)
3983 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
3984 if (ch->ht40plus)
3985 flags |= WMI_CHAN_FLAG_HT40_PLUS;
3986 if (ch->chan_radar)
3987 flags |= WMI_CHAN_FLAG_DFS;
3988
3989 ci->mhz = __cpu_to_le32(ch->freq);
3990 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
3991 ci->band_center_freq2 = 0;
3992 ci->min_power = ch->min_power;
3993 ci->max_power = ch->max_power;
3994 ci->reg_power = ch->max_reg_power;
3995 ci->antenna_max = ch->max_antenna_gain;
3996
3997 /* mode & flags share storage */
3998 ci->mode = ch->mode;
3999 ci->flags |= __cpu_to_le32(flags);
4000 } 4086 }
4001 4087
4002 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid); 4088 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
@@ -4108,9 +4194,9 @@ int ath10k_wmi_peer_assoc(struct ath10k *ar,
4108 4194
4109 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) { 4195 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4110 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features)) 4196 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4111 ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
4112 else
4113 ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg); 4197 ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
4198 else
4199 ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
4114 } else { 4200 } else {
4115 ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg); 4201 ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
4116 } 4202 }
@@ -4267,3 +4353,73 @@ int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable)
4267 4353
4268 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid); 4354 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid);
4269} 4355}
4356
4357int ath10k_wmi_pdev_pktlog_enable(struct ath10k *ar, u32 ev_bitmap)
4358{
4359 struct wmi_pdev_pktlog_enable_cmd *cmd;
4360 struct sk_buff *skb;
4361
4362 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
4363 if (!skb)
4364 return -ENOMEM;
4365
4366 ev_bitmap &= ATH10K_PKTLOG_ANY;
4367 ath10k_dbg(ar, ATH10K_DBG_WMI,
4368 "wmi enable pktlog filter:%x\n", ev_bitmap);
4369
4370 cmd = (struct wmi_pdev_pktlog_enable_cmd *)skb->data;
4371 cmd->ev_bitmap = __cpu_to_le32(ev_bitmap);
4372 return ath10k_wmi_cmd_send(ar, skb,
4373 ar->wmi.cmd->pdev_pktlog_enable_cmdid);
4374}
4375
4376int ath10k_wmi_pdev_pktlog_disable(struct ath10k *ar)
4377{
4378 struct sk_buff *skb;
4379
4380 skb = ath10k_wmi_alloc_skb(ar, 0);
4381 if (!skb)
4382 return -ENOMEM;
4383
4384 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi disable pktlog\n");
4385
4386 return ath10k_wmi_cmd_send(ar, skb,
4387 ar->wmi.cmd->pdev_pktlog_disable_cmdid);
4388}
4389
4390int ath10k_wmi_attach(struct ath10k *ar)
4391{
4392 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4393 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4394 ar->wmi.cmd = &wmi_10_2_cmd_map;
4395 else
4396 ar->wmi.cmd = &wmi_10x_cmd_map;
4397
4398 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
4399 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
4400 } else {
4401 ar->wmi.cmd = &wmi_cmd_map;
4402 ar->wmi.vdev_param = &wmi_vdev_param_map;
4403 ar->wmi.pdev_param = &wmi_pdev_param_map;
4404 }
4405
4406 init_completion(&ar->wmi.service_ready);
4407 init_completion(&ar->wmi.unified_ready);
4408
4409 return 0;
4410}
4411
4412void ath10k_wmi_detach(struct ath10k *ar)
4413{
4414 int i;
4415
4416 /* free the host memory chunks requested by firmware */
4417 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
4418 dma_free_coherent(ar->dev,
4419 ar->wmi.mem_chunks[i].len,
4420 ar->wmi.mem_chunks[i].vaddr,
4421 ar->wmi.mem_chunks[i].paddr);
4422 }
4423
4424 ar->wmi.num_mem_chunks = 0;
4425}
diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
index 86f5ebccfe79..a38d788a6101 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.h
+++ b/drivers/net/wireless/ath/ath10k/wmi.h
@@ -1428,11 +1428,11 @@ struct wmi_service_ready_event {
1428 * where FW can access this memory directly (or) by DMA. 1428 * where FW can access this memory directly (or) by DMA.
1429 */ 1429 */
1430 __le32 num_mem_reqs; 1430 __le32 num_mem_reqs;
1431 struct wlan_host_mem_req mem_reqs[1]; 1431 struct wlan_host_mem_req mem_reqs[0];
1432} __packed; 1432} __packed;
1433 1433
1434/* This is the definition from 10.X firmware branch */ 1434/* This is the definition from 10.X firmware branch */
1435struct wmi_service_ready_event_10x { 1435struct wmi_10x_service_ready_event {
1436 __le32 sw_version; 1436 __le32 sw_version;
1437 __le32 abi_version; 1437 __le32 abi_version;
1438 1438
@@ -1467,7 +1467,7 @@ struct wmi_service_ready_event_10x {
1467 */ 1467 */
1468 __le32 num_mem_reqs; 1468 __le32 num_mem_reqs;
1469 1469
1470 struct wlan_host_mem_req mem_reqs[1]; 1470 struct wlan_host_mem_req mem_reqs[0];
1471} __packed; 1471} __packed;
1472 1472
1473#define WMI_SERVICE_READY_TIMEOUT_HZ (5*HZ) 1473#define WMI_SERVICE_READY_TIMEOUT_HZ (5*HZ)
@@ -1883,38 +1883,26 @@ struct host_memory_chunk {
1883 __le32 size; 1883 __le32 size;
1884} __packed; 1884} __packed;
1885 1885
1886struct wmi_host_mem_chunks {
1887 __le32 count;
1888 /* some fw revisions require at least 1 chunk regardless of count */
1889 struct host_memory_chunk items[1];
1890} __packed;
1891
1886struct wmi_init_cmd { 1892struct wmi_init_cmd {
1887 struct wmi_resource_config resource_config; 1893 struct wmi_resource_config resource_config;
1888 __le32 num_host_mem_chunks; 1894 struct wmi_host_mem_chunks mem_chunks;
1889
1890 /*
1891 * variable number of host memory chunks.
1892 * This should be the last element in the structure
1893 */
1894 struct host_memory_chunk host_mem_chunks[1];
1895} __packed; 1895} __packed;
1896 1896
1897/* _10x stucture is from 10.X FW API */ 1897/* _10x stucture is from 10.X FW API */
1898struct wmi_init_cmd_10x { 1898struct wmi_init_cmd_10x {
1899 struct wmi_resource_config_10x resource_config; 1899 struct wmi_resource_config_10x resource_config;
1900 __le32 num_host_mem_chunks; 1900 struct wmi_host_mem_chunks mem_chunks;
1901
1902 /*
1903 * variable number of host memory chunks.
1904 * This should be the last element in the structure
1905 */
1906 struct host_memory_chunk host_mem_chunks[1];
1907} __packed; 1901} __packed;
1908 1902
1909struct wmi_init_cmd_10_2 { 1903struct wmi_init_cmd_10_2 {
1910 struct wmi_resource_config_10_2 resource_config; 1904 struct wmi_resource_config_10_2 resource_config;
1911 __le32 num_host_mem_chunks; 1905 struct wmi_host_mem_chunks mem_chunks;
1912
1913 /*
1914 * variable number of host memory chunks.
1915 * This should be the last element in the structure
1916 */
1917 struct host_memory_chunk host_mem_chunks[1];
1918} __packed; 1906} __packed;
1919 1907
1920struct wmi_chan_list_entry { 1908struct wmi_chan_list_entry {
@@ -1974,7 +1962,7 @@ enum wmi_scan_priority {
1974 WMI_SCAN_PRIORITY_COUNT /* number of priorities supported */ 1962 WMI_SCAN_PRIORITY_COUNT /* number of priorities supported */
1975}; 1963};
1976 1964
1977struct wmi_start_scan_cmd { 1965struct wmi_start_scan_common {
1978 /* Scan ID */ 1966 /* Scan ID */
1979 __le32 scan_id; 1967 __le32 scan_id;
1980 /* Scan requestor ID */ 1968 /* Scan requestor ID */
@@ -2032,95 +2020,25 @@ struct wmi_start_scan_cmd {
2032 __le32 probe_delay; 2020 __le32 probe_delay;
2033 /* Scan control flags */ 2021 /* Scan control flags */
2034 __le32 scan_ctrl_flags; 2022 __le32 scan_ctrl_flags;
2035
2036 /* Burst duration time in msecs */
2037 __le32 burst_duration;
2038 /*
2039 * TLV (tag length value ) paramerters follow the scan_cmd structure.
2040 * TLV can contain channel list, bssid list, ssid list and
2041 * ie. the TLV tags are defined above;
2042 */
2043} __packed; 2023} __packed;
2044 2024
2045/* This is the definition from 10.X firmware branch */ 2025struct wmi_start_scan_tlvs {
2046struct wmi_start_scan_cmd_10x { 2026 /* TLV parameters. These includes channel list, ssid list, bssid list,
2047 /* Scan ID */ 2027 * extra ies.
2048 __le32 scan_id;
2049
2050 /* Scan requestor ID */
2051 __le32 scan_req_id;
2052
2053 /* VDEV id(interface) that is requesting scan */
2054 __le32 vdev_id;
2055
2056 /* Scan Priority, input to scan scheduler */
2057 __le32 scan_priority;
2058
2059 /* Scan events subscription */
2060 __le32 notify_scan_events;
2061
2062 /* dwell time in msec on active channels */
2063 __le32 dwell_time_active;
2064
2065 /* dwell time in msec on passive channels */
2066 __le32 dwell_time_passive;
2067
2068 /*
2069 * min time in msec on the BSS channel,only valid if atleast one
2070 * VDEV is active
2071 */
2072 __le32 min_rest_time;
2073
2074 /*
2075 * max rest time in msec on the BSS channel,only valid if at least
2076 * one VDEV is active
2077 */
2078 /*
2079 * the scanner will rest on the bss channel at least min_rest_time
2080 * after min_rest_time the scanner will start checking for tx/rx
2081 * activity on all VDEVs. if there is no activity the scanner will
2082 * switch to off channel. if there is activity the scanner will let
2083 * the radio on the bss channel until max_rest_time expires.at
2084 * max_rest_time scanner will switch to off channel irrespective of
2085 * activity. activity is determined by the idle_time parameter.
2086 */
2087 __le32 max_rest_time;
2088
2089 /*
2090 * time before sending next set of probe requests.
2091 * The scanner keeps repeating probe requests transmission with
2092 * period specified by repeat_probe_time.
2093 * The number of probe requests specified depends on the ssid_list
2094 * and bssid_list
2095 */
2096 __le32 repeat_probe_time;
2097
2098 /* time in msec between 2 consequetive probe requests with in a set. */
2099 __le32 probe_spacing_time;
2100
2101 /*
2102 * data inactivity time in msec on bss channel that will be used by
2103 * scanner for measuring the inactivity.
2104 */
2105 __le32 idle_time;
2106
2107 /* maximum time in msec allowed for scan */
2108 __le32 max_scan_time;
2109
2110 /*
2111 * delay in msec before sending first probe request after switching
2112 * to a channel
2113 */ 2028 */
2114 __le32 probe_delay; 2029 u8 tlvs[0];
2030} __packed;
2115 2031
2116 /* Scan control flags */ 2032struct wmi_start_scan_cmd {
2117 __le32 scan_ctrl_flags; 2033 struct wmi_start_scan_common common;
2034 __le32 burst_duration_ms;
2035 struct wmi_start_scan_tlvs tlvs;
2036} __packed;
2118 2037
2119 /* 2038/* This is the definition from 10.X firmware branch */
2120 * TLV (tag length value ) paramerters follow the scan_cmd structure. 2039struct wmi_10x_start_scan_cmd {
2121 * TLV can contain channel list, bssid list, ssid list and 2040 struct wmi_start_scan_common common;
2122 * ie. the TLV tags are defined above; 2041 struct wmi_start_scan_tlvs tlvs;
2123 */
2124} __packed; 2042} __packed;
2125 2043
2126struct wmi_ssid_arg { 2044struct wmi_ssid_arg {
@@ -2306,94 +2224,25 @@ struct wmi_mgmt_rx_event_v2 {
2306#define PHY_ERROR_FALSE_RADAR_EXT 0x24 2224#define PHY_ERROR_FALSE_RADAR_EXT 0x24
2307#define PHY_ERROR_RADAR 0x05 2225#define PHY_ERROR_RADAR 0x05
2308 2226
2309struct wmi_single_phyerr_rx_hdr { 2227struct wmi_phyerr {
2310 /* TSF timestamp */
2311 __le32 tsf_timestamp; 2228 __le32 tsf_timestamp;
2312
2313 /*
2314 * Current freq1, freq2
2315 *
2316 * [7:0]: freq1[lo]
2317 * [15:8] : freq1[hi]
2318 * [23:16]: freq2[lo]
2319 * [31:24]: freq2[hi]
2320 */
2321 __le16 freq1; 2229 __le16 freq1;
2322 __le16 freq2; 2230 __le16 freq2;
2323
2324 /*
2325 * Combined RSSI over all chains and channel width for this PHY error
2326 *
2327 * [7:0]: RSSI combined
2328 * [15:8]: Channel width (MHz)
2329 * [23:16]: PHY error code
2330 * [24:16]: reserved (future use)
2331 */
2332 u8 rssi_combined; 2231 u8 rssi_combined;
2333 u8 chan_width_mhz; 2232 u8 chan_width_mhz;
2334 u8 phy_err_code; 2233 u8 phy_err_code;
2335 u8 rsvd0; 2234 u8 rsvd0;
2336 2235 __le32 rssi_chains[4];
2337 /* 2236 __le16 nf_chains[4];
2338 * RSSI on chain 0 through 3
2339 *
2340 * This is formatted the same as the PPDU_START RX descriptor
2341 * field:
2342 *
2343 * [7:0]: pri20
2344 * [15:8]: sec20
2345 * [23:16]: sec40
2346 * [31:24]: sec80
2347 */
2348
2349 __le32 rssi_chain0;
2350 __le32 rssi_chain1;
2351 __le32 rssi_chain2;
2352 __le32 rssi_chain3;
2353
2354 /*
2355 * Last calibrated NF value for chain 0 through 3
2356 *
2357 * nf_list_1:
2358 *
2359 * + [15:0] - chain 0
2360 * + [31:16] - chain 1
2361 *
2362 * nf_list_2:
2363 *
2364 * + [15:0] - chain 2
2365 * + [31:16] - chain 3
2366 */
2367 __le32 nf_list_1;
2368 __le32 nf_list_2;
2369
2370 /* Length of the frame */
2371 __le32 buf_len; 2237 __le32 buf_len;
2238 u8 buf[0];
2372} __packed; 2239} __packed;
2373 2240
2374struct wmi_single_phyerr_rx_event { 2241struct wmi_phyerr_event {
2375 /* Phy error event header */ 2242 __le32 num_phyerrs;
2376 struct wmi_single_phyerr_rx_hdr hdr;
2377 /* frame buffer */
2378 u8 bufp[0];
2379} __packed;
2380
2381struct wmi_comb_phyerr_rx_hdr {
2382 /* Phy error phy error count */
2383 __le32 num_phyerr_events;
2384 __le32 tsf_l32; 2243 __le32 tsf_l32;
2385 __le32 tsf_u32; 2244 __le32 tsf_u32;
2386} __packed; 2245 struct wmi_phyerr phyerrs[0];
2387
2388struct wmi_comb_phyerr_rx_event {
2389 /* Phy error phy error count */
2390 struct wmi_comb_phyerr_rx_hdr hdr;
2391 /*
2392 * frame buffer - contains multiple payloads in the order:
2393 * header - payload, header - payload...
2394 * (The header is of type: wmi_single_phyerr_rx_hdr)
2395 */
2396 u8 bufp[0];
2397} __packed; 2246} __packed;
2398 2247
2399#define PHYERR_TLV_SIG 0xBB 2248#define PHYERR_TLV_SIG 0xBB
@@ -2908,11 +2757,6 @@ enum wmi_tp_scale {
2908 WMI_TP_SCALE_SIZE = 5, /* max num of enum */ 2757 WMI_TP_SCALE_SIZE = 5, /* max num of enum */
2909}; 2758};
2910 2759
2911struct wmi_set_channel_cmd {
2912 /* channel (only frequency and mode info are used) */
2913 struct wmi_channel chan;
2914} __packed;
2915
2916struct wmi_pdev_chanlist_update_event { 2760struct wmi_pdev_chanlist_update_event {
2917 /* number of channels */ 2761 /* number of channels */
2918 __le32 num_chan; 2762 __le32 num_chan;
@@ -2943,6 +2787,10 @@ struct wmi_pdev_set_channel_cmd {
2943 struct wmi_channel chan; 2787 struct wmi_channel chan;
2944} __packed; 2788} __packed;
2945 2789
2790struct wmi_pdev_pktlog_enable_cmd {
2791 __le32 ev_bitmap;
2792} __packed;
2793
2946/* Customize the DSCP (bit) to TID (0-7) mapping for QOS */ 2794/* Customize the DSCP (bit) to TID (0-7) mapping for QOS */
2947#define WMI_DSCP_MAP_MAX (64) 2795#define WMI_DSCP_MAP_MAX (64)
2948struct wmi_pdev_set_dscp_tid_map_cmd { 2796struct wmi_pdev_set_dscp_tid_map_cmd {
@@ -3177,7 +3025,7 @@ struct wmi_stats_event {
3177 * PDEV statistics 3025 * PDEV statistics
3178 * TODO: add all PDEV stats here 3026 * TODO: add all PDEV stats here
3179 */ 3027 */
3180struct wmi_pdev_stats_old { 3028struct wmi_pdev_stats {
3181 __le32 chan_nf; /* Channel noise floor */ 3029 __le32 chan_nf; /* Channel noise floor */
3182 __le32 tx_frame_count; /* TX frame count */ 3030 __le32 tx_frame_count; /* TX frame count */
3183 __le32 rx_frame_count; /* RX frame count */ 3031 __le32 rx_frame_count; /* RX frame count */
@@ -3188,15 +3036,8 @@ struct wmi_pdev_stats_old {
3188 struct wal_dbg_stats wal; /* WAL dbg stats */ 3036 struct wal_dbg_stats wal; /* WAL dbg stats */
3189} __packed; 3037} __packed;
3190 3038
3191struct wmi_pdev_stats_10x { 3039struct wmi_10x_pdev_stats {
3192 __le32 chan_nf; /* Channel noise floor */ 3040 struct wmi_pdev_stats old;
3193 __le32 tx_frame_count; /* TX frame count */
3194 __le32 rx_frame_count; /* RX frame count */
3195 __le32 rx_clear_count; /* rx clear count */
3196 __le32 cycle_count; /* cycle count */
3197 __le32 phy_err_count; /* Phy error count */
3198 __le32 chan_tx_pwr; /* channel tx power */
3199 struct wal_dbg_stats wal; /* WAL dbg stats */
3200 __le32 ack_rx_bad; 3041 __le32 ack_rx_bad;
3201 __le32 rts_bad; 3042 __le32 rts_bad;
3202 __le32 rts_good; 3043 __le32 rts_good;
@@ -3217,16 +3058,14 @@ struct wmi_vdev_stats {
3217 * peer statistics. 3058 * peer statistics.
3218 * TODO: add more stats 3059 * TODO: add more stats
3219 */ 3060 */
3220struct wmi_peer_stats_old { 3061struct wmi_peer_stats {
3221 struct wmi_mac_addr peer_macaddr; 3062 struct wmi_mac_addr peer_macaddr;
3222 __le32 peer_rssi; 3063 __le32 peer_rssi;
3223 __le32 peer_tx_rate; 3064 __le32 peer_tx_rate;
3224} __packed; 3065} __packed;
3225 3066
3226struct wmi_peer_stats_10x { 3067struct wmi_10x_peer_stats {
3227 struct wmi_mac_addr peer_macaddr; 3068 struct wmi_peer_stats old;
3228 __le32 peer_rssi;
3229 __le32 peer_tx_rate;
3230 __le32 peer_rx_rate; 3069 __le32 peer_rx_rate;
3231} __packed; 3070} __packed;
3232 3071
@@ -4719,8 +4558,26 @@ struct wmi_dbglog_cfg_cmd {
4719/* By default disable power save for IBSS */ 4558/* By default disable power save for IBSS */
4720#define ATH10K_DEFAULT_ATIM 0 4559#define ATH10K_DEFAULT_ATIM 0
4721 4560
4561#define WMI_MAX_MEM_REQS 16
4562
4563struct wmi_svc_rdy_ev_arg {
4564 __le32 min_tx_power;
4565 __le32 max_tx_power;
4566 __le32 ht_cap;
4567 __le32 vht_cap;
4568 __le32 sw_ver0;
4569 __le32 sw_ver1;
4570 __le32 phy_capab;
4571 __le32 num_rf_chains;
4572 __le32 eeprom_rd;
4573 __le32 num_mem_reqs;
4574 const __le32 *service_map;
4575 const struct wlan_host_mem_req *mem_reqs[WMI_MAX_MEM_REQS];
4576};
4577
4722struct ath10k; 4578struct ath10k;
4723struct ath10k_vif; 4579struct ath10k_vif;
4580struct ath10k_fw_stats;
4724 4581
4725int ath10k_wmi_attach(struct ath10k *ar); 4582int ath10k_wmi_attach(struct ath10k *ar);
4726void ath10k_wmi_detach(struct ath10k *ar); 4583void ath10k_wmi_detach(struct ath10k *ar);
@@ -4732,8 +4589,6 @@ int ath10k_wmi_connect(struct ath10k *ar);
4732struct sk_buff *ath10k_wmi_alloc_skb(struct ath10k *ar, u32 len); 4589struct sk_buff *ath10k_wmi_alloc_skb(struct ath10k *ar, u32 len);
4733int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id); 4590int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
4734 4591
4735int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
4736 const struct wmi_channel_arg *);
4737int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt); 4592int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt);
4738int ath10k_wmi_pdev_resume_target(struct ath10k *ar); 4593int ath10k_wmi_pdev_resume_target(struct ath10k *ar);
4739int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g, 4594int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
@@ -4794,5 +4649,9 @@ int ath10k_wmi_force_fw_hang(struct ath10k *ar,
4794 enum wmi_force_fw_hang_type type, u32 delay_ms); 4649 enum wmi_force_fw_hang_type type, u32 delay_ms);
4795int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb); 4650int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb);
4796int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable); 4651int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable);
4652int ath10k_wmi_pull_fw_stats(struct ath10k *ar, struct sk_buff *skb,
4653 struct ath10k_fw_stats *stats);
4654int ath10k_wmi_pdev_pktlog_enable(struct ath10k *ar, u32 ev_list);
4655int ath10k_wmi_pdev_pktlog_disable(struct ath10k *ar);
4797 4656
4798#endif /* _WMI_H_ */ 4657#endif /* _WMI_H_ */
diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c
index ba60e37213eb..7a5337877a0c 100644
--- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
+++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
@@ -2976,11 +2976,11 @@ static int ath6kl_stop_ap(struct wiphy *wiphy, struct net_device *dev)
2976static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 2976static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2977 2977
2978static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev, 2978static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev,
2979 const u8 *mac) 2979 struct station_del_parameters *params)
2980{ 2980{
2981 struct ath6kl *ar = ath6kl_priv(dev); 2981 struct ath6kl *ar = ath6kl_priv(dev);
2982 struct ath6kl_vif *vif = netdev_priv(dev); 2982 struct ath6kl_vif *vif = netdev_priv(dev);
2983 const u8 *addr = mac ? mac : bcast_addr; 2983 const u8 *addr = params->mac ? params->mac : bcast_addr;
2984 2984
2985 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH, 2985 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH,
2986 addr, WLAN_REASON_PREV_AUTH_NOT_VALID); 2986 addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
diff --git a/drivers/net/wireless/ath/ath6kl/common.h b/drivers/net/wireless/ath/ath6kl/common.h
index 05debf700a84..4f82e8632d37 100644
--- a/drivers/net/wireless/ath/ath6kl/common.h
+++ b/drivers/net/wireless/ath/ath6kl/common.h
@@ -22,7 +22,7 @@
22 22
23#define ATH6KL_MAX_IE 256 23#define ATH6KL_MAX_IE 256
24 24
25__printf(2, 3) int ath6kl_printk(const char *level, const char *fmt, ...); 25__printf(2, 3) void ath6kl_printk(const char *level, const char *fmt, ...);
26 26
27/* 27/*
28 * Reflects the version of binary interface exposed by ATH6KL target 28 * Reflects the version of binary interface exposed by ATH6KL target
diff --git a/drivers/net/wireless/ath/ath6kl/debug.c b/drivers/net/wireless/ath/ath6kl/debug.c
index 55c4064dd506..81ba48d2938b 100644
--- a/drivers/net/wireless/ath/ath6kl/debug.c
+++ b/drivers/net/wireless/ath/ath6kl/debug.c
@@ -37,76 +37,64 @@ struct ath6kl_fwlog_slot {
37 37
38#define ATH6KL_FWLOG_VALID_MASK 0x1ffff 38#define ATH6KL_FWLOG_VALID_MASK 0x1ffff
39 39
40int ath6kl_printk(const char *level, const char *fmt, ...) 40void ath6kl_printk(const char *level, const char *fmt, ...)
41{ 41{
42 struct va_format vaf; 42 struct va_format vaf;
43 va_list args; 43 va_list args;
44 int rtn;
45 44
46 va_start(args, fmt); 45 va_start(args, fmt);
47 46
48 vaf.fmt = fmt; 47 vaf.fmt = fmt;
49 vaf.va = &args; 48 vaf.va = &args;
50 49
51 rtn = printk("%sath6kl: %pV", level, &vaf); 50 printk("%sath6kl: %pV", level, &vaf);
52 51
53 va_end(args); 52 va_end(args);
54
55 return rtn;
56} 53}
57EXPORT_SYMBOL(ath6kl_printk); 54EXPORT_SYMBOL(ath6kl_printk);
58 55
59int ath6kl_info(const char *fmt, ...) 56void ath6kl_info(const char *fmt, ...)
60{ 57{
61 struct va_format vaf = { 58 struct va_format vaf = {
62 .fmt = fmt, 59 .fmt = fmt,
63 }; 60 };
64 va_list args; 61 va_list args;
65 int ret;
66 62
67 va_start(args, fmt); 63 va_start(args, fmt);
68 vaf.va = &args; 64 vaf.va = &args;
69 ret = ath6kl_printk(KERN_INFO, "%pV", &vaf); 65 ath6kl_printk(KERN_INFO, "%pV", &vaf);
70 trace_ath6kl_log_info(&vaf); 66 trace_ath6kl_log_info(&vaf);
71 va_end(args); 67 va_end(args);
72
73 return ret;
74} 68}
75EXPORT_SYMBOL(ath6kl_info); 69EXPORT_SYMBOL(ath6kl_info);
76 70
77int ath6kl_err(const char *fmt, ...) 71void ath6kl_err(const char *fmt, ...)
78{ 72{
79 struct va_format vaf = { 73 struct va_format vaf = {
80 .fmt = fmt, 74 .fmt = fmt,
81 }; 75 };
82 va_list args; 76 va_list args;
83 int ret;
84 77
85 va_start(args, fmt); 78 va_start(args, fmt);
86 vaf.va = &args; 79 vaf.va = &args;
87 ret = ath6kl_printk(KERN_ERR, "%pV", &vaf); 80 ath6kl_printk(KERN_ERR, "%pV", &vaf);
88 trace_ath6kl_log_err(&vaf); 81 trace_ath6kl_log_err(&vaf);
89 va_end(args); 82 va_end(args);
90
91 return ret;
92} 83}
93EXPORT_SYMBOL(ath6kl_err); 84EXPORT_SYMBOL(ath6kl_err);
94 85
95int ath6kl_warn(const char *fmt, ...) 86void ath6kl_warn(const char *fmt, ...)
96{ 87{
97 struct va_format vaf = { 88 struct va_format vaf = {
98 .fmt = fmt, 89 .fmt = fmt,
99 }; 90 };
100 va_list args; 91 va_list args;
101 int ret;
102 92
103 va_start(args, fmt); 93 va_start(args, fmt);
104 vaf.va = &args; 94 vaf.va = &args;
105 ret = ath6kl_printk(KERN_WARNING, "%pV", &vaf); 95 ath6kl_printk(KERN_WARNING, "%pV", &vaf);
106 trace_ath6kl_log_warn(&vaf); 96 trace_ath6kl_log_warn(&vaf);
107 va_end(args); 97 va_end(args);
108
109 return ret;
110} 98}
111EXPORT_SYMBOL(ath6kl_warn); 99EXPORT_SYMBOL(ath6kl_warn);
112 100
diff --git a/drivers/net/wireless/ath/ath6kl/debug.h b/drivers/net/wireless/ath/ath6kl/debug.h
index e194c10d9f00..19106ed28961 100644
--- a/drivers/net/wireless/ath/ath6kl/debug.h
+++ b/drivers/net/wireless/ath/ath6kl/debug.h
@@ -50,10 +50,10 @@ enum ATH6K_DEBUG_MASK {
50}; 50};
51 51
52extern unsigned int debug_mask; 52extern unsigned int debug_mask;
53__printf(2, 3) int ath6kl_printk(const char *level, const char *fmt, ...); 53__printf(2, 3) void ath6kl_printk(const char *level, const char *fmt, ...);
54__printf(1, 2) int ath6kl_info(const char *fmt, ...); 54__printf(1, 2) void ath6kl_info(const char *fmt, ...);
55__printf(1, 2) int ath6kl_err(const char *fmt, ...); 55__printf(1, 2) void ath6kl_err(const char *fmt, ...);
56__printf(1, 2) int ath6kl_warn(const char *fmt, ...); 56__printf(1, 2) void ath6kl_warn(const char *fmt, ...);
57 57
58enum ath6kl_war { 58enum ath6kl_war {
59 ATH6KL_WAR_INVALID_RATE, 59 ATH6KL_WAR_INVALID_RATE,
@@ -81,10 +81,9 @@ int ath6kl_debug_init_fs(struct ath6kl *ar);
81void ath6kl_debug_cleanup(struct ath6kl *ar); 81void ath6kl_debug_cleanup(struct ath6kl *ar);
82 82
83#else 83#else
84static inline int ath6kl_dbg(enum ATH6K_DEBUG_MASK dbg_mask, 84static inline void ath6kl_dbg(enum ATH6K_DEBUG_MASK dbg_mask,
85 const char *fmt, ...) 85 const char *fmt, ...)
86{ 86{
87 return 0;
88} 87}
89 88
90static inline void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask, 89static inline void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
index a6a5e40b3e98..9da3594fd010 100644
--- a/drivers/net/wireless/ath/ath6kl/usb.c
+++ b/drivers/net/wireless/ath/ath6kl/usb.c
@@ -1193,18 +1193,10 @@ static int ath6kl_usb_pm_resume(struct usb_interface *interface)
1193 return 0; 1193 return 0;
1194} 1194}
1195 1195
1196static int ath6kl_usb_pm_reset_resume(struct usb_interface *intf)
1197{
1198 if (usb_get_intfdata(intf))
1199 ath6kl_usb_remove(intf);
1200 return 0;
1201}
1202
1203#else 1196#else
1204 1197
1205#define ath6kl_usb_pm_suspend NULL 1198#define ath6kl_usb_pm_suspend NULL
1206#define ath6kl_usb_pm_resume NULL 1199#define ath6kl_usb_pm_resume NULL
1207#define ath6kl_usb_pm_reset_resume NULL
1208 1200
1209#endif 1201#endif
1210 1202
@@ -1222,7 +1214,6 @@ static struct usb_driver ath6kl_usb_driver = {
1222 .probe = ath6kl_usb_probe, 1214 .probe = ath6kl_usb_probe,
1223 .suspend = ath6kl_usb_pm_suspend, 1215 .suspend = ath6kl_usb_pm_suspend,
1224 .resume = ath6kl_usb_pm_resume, 1216 .resume = ath6kl_usb_pm_resume,
1225 .reset_resume = ath6kl_usb_pm_reset_resume,
1226 .disconnect = ath6kl_usb_remove, 1217 .disconnect = ath6kl_usb_remove,
1227 .id_table = ath6kl_usb_ids, 1218 .id_table = ath6kl_usb_ids,
1228 .supports_autosuspend = true, 1219 .supports_autosuspend = true,
diff --git a/drivers/net/wireless/ath/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig
index 896e63281b3b..ca101d7cb99f 100644
--- a/drivers/net/wireless/ath/ath9k/Kconfig
+++ b/drivers/net/wireless/ath/ath9k/Kconfig
@@ -148,6 +148,11 @@ config ATH9K_CHANNEL_CONTEXT
148 for multi-channel concurrency. Enable this if P2P PowerSave support 148 for multi-channel concurrency. Enable this if P2P PowerSave support
149 is required. 149 is required.
150 150
151config ATH9K_PCOEM
152 bool "Atheros ath9k support for PC OEM cards" if EXPERT
153 depends on ATH9K
154 default y
155
151config ATH9K_HTC 156config ATH9K_HTC
152 tristate "Atheros HTC based wireless cards support" 157 tristate "Atheros HTC based wireless cards support"
153 depends on USB && MAC80211 158 depends on USB && MAC80211
diff --git a/drivers/net/wireless/ath/ath9k/Makefile b/drivers/net/wireless/ath/ath9k/Makefile
index 73704c1be736..473972288a84 100644
--- a/drivers/net/wireless/ath/ath9k/Makefile
+++ b/drivers/net/wireless/ath/ath9k/Makefile
@@ -16,8 +16,7 @@ ath9k-$(CONFIG_ATH9K_DFS_CERTIFIED) += dfs.o
16ath9k-$(CONFIG_ATH9K_TX99) += tx99.o 16ath9k-$(CONFIG_ATH9K_TX99) += tx99.o
17ath9k-$(CONFIG_ATH9K_WOW) += wow.o 17ath9k-$(CONFIG_ATH9K_WOW) += wow.o
18 18
19ath9k-$(CONFIG_ATH9K_DEBUGFS) += debug.o \ 19ath9k-$(CONFIG_ATH9K_DEBUGFS) += debug.o
20 spectral.o
21 20
22ath9k-$(CONFIG_ATH9K_STATION_STATISTICS) += debug_sta.o 21ath9k-$(CONFIG_ATH9K_STATION_STATISTICS) += debug_sta.o
23 22
@@ -32,7 +31,6 @@ ath9k_hw-y:= \
32 ar5008_phy.o \ 31 ar5008_phy.o \
33 ar9002_calib.o \ 32 ar9002_calib.o \
34 ar9003_calib.o \ 33 ar9003_calib.o \
35 ar9003_rtt.o \
36 calib.o \ 34 calib.o \
37 eeprom.o \ 35 eeprom.o \
38 eeprom_def.o \ 36 eeprom_def.o \
@@ -50,6 +48,8 @@ ath9k_hw-$(CONFIG_ATH9K_WOW) += ar9003_wow.o
50ath9k_hw-$(CONFIG_ATH9K_BTCOEX_SUPPORT) += btcoex.o \ 48ath9k_hw-$(CONFIG_ATH9K_BTCOEX_SUPPORT) += btcoex.o \
51 ar9003_mci.o 49 ar9003_mci.o
52 50
51ath9k_hw-$(CONFIG_ATH9K_PCOEM) += ar9003_rtt.o
52
53ath9k_hw-$(CONFIG_ATH9K_DYNACK) += dynack.o 53ath9k_hw-$(CONFIG_ATH9K_DYNACK) += dynack.o
54 54
55obj-$(CONFIG_ATH9K_HW) += ath9k_hw.o 55obj-$(CONFIG_ATH9K_HW) += ath9k_hw.o
@@ -58,7 +58,8 @@ obj-$(CONFIG_ATH9K_COMMON) += ath9k_common.o
58ath9k_common-y:= common.o \ 58ath9k_common-y:= common.o \
59 common-init.o \ 59 common-init.o \
60 common-beacon.o \ 60 common-beacon.o \
61 common-debug.o 61 common-debug.o \
62 common-spectral.o
62 63
63ath9k_htc-y += htc_hst.o \ 64ath9k_htc-y += htc_hst.o \
64 hif_usb.o \ 65 hif_usb.o \
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index b72d0be716db..5829074208fa 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -1190,7 +1190,7 @@ static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
1190static void ar5008_hw_set_radar_params(struct ath_hw *ah, 1190static void ar5008_hw_set_radar_params(struct ath_hw *ah,
1191 struct ath_hw_radar_conf *conf) 1191 struct ath_hw_radar_conf *conf)
1192{ 1192{
1193 u32 radar_0 = 0, radar_1 = 0; 1193 u32 radar_0 = 0, radar_1;
1194 1194
1195 if (!conf) { 1195 if (!conf) {
1196 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA); 1196 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
@@ -1204,6 +1204,9 @@ static void ar5008_hw_set_radar_params(struct ath_hw *ah,
1204 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI); 1204 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1205 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND); 1205 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1206 1206
1207 radar_1 = REG_READ(ah, AR_PHY_RADAR_1);
1208 radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH |
1209 AR_PHY_RADAR_1_RELPWR_THRESH);
1207 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI; 1210 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1208 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK; 1211 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1209 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN); 1212 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
@@ -1225,7 +1228,7 @@ static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
1225 conf->fir_power = -33; 1228 conf->fir_power = -33;
1226 conf->radar_rssi = 20; 1229 conf->radar_rssi = 20;
1227 conf->pulse_height = 10; 1230 conf->pulse_height = 10;
1228 conf->pulse_rssi = 24; 1231 conf->pulse_rssi = 15;
1229 conf->pulse_inband = 15; 1232 conf->pulse_inband = 15;
1230 conf->pulse_maxlen = 255; 1233 conf->pulse_maxlen = 255;
1231 conf->pulse_inband_step = 12; 1234 conf->pulse_inband_step = 12;
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_calib.c b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
index cdc74005650c..42190b67c671 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
@@ -657,31 +657,29 @@ static void ar9002_hw_olc_temp_compensation(struct ath_hw *ah)
657 ar9280_hw_olc_temp_compensation(ah); 657 ar9280_hw_olc_temp_compensation(ah);
658} 658}
659 659
660static bool ar9002_hw_calibrate(struct ath_hw *ah, 660static int ar9002_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
661 struct ath9k_channel *chan, 661 u8 rxchainmask, bool longcal)
662 u8 rxchainmask,
663 bool longcal)
664{ 662{
665 bool iscaldone = true;
666 struct ath9k_cal_list *currCal = ah->cal_list_curr; 663 struct ath9k_cal_list *currCal = ah->cal_list_curr;
667 bool nfcal, nfcal_pending = false; 664 bool nfcal, nfcal_pending = false, percal_pending;
665 int ret;
668 666
669 nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF); 667 nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
670 if (ah->caldata) 668 if (ah->caldata)
671 nfcal_pending = test_bit(NFCAL_PENDING, &ah->caldata->cal_flags); 669 nfcal_pending = test_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
672 670
673 if (currCal && !nfcal && 671 percal_pending = (currCal &&
674 (currCal->calState == CAL_RUNNING || 672 (currCal->calState == CAL_RUNNING ||
675 currCal->calState == CAL_WAITING)) { 673 currCal->calState == CAL_WAITING));
676 iscaldone = ar9002_hw_per_calibration(ah, chan, 674
677 rxchainmask, currCal); 675 if (percal_pending && !nfcal) {
678 if (iscaldone) { 676 if (!ar9002_hw_per_calibration(ah, chan, rxchainmask, currCal))
679 ah->cal_list_curr = currCal = currCal->calNext; 677 return 0;
680 678
681 if (currCal->calState == CAL_WAITING) { 679 ah->cal_list_curr = currCal = currCal->calNext;
682 iscaldone = false; 680 if (currCal->calState == CAL_WAITING) {
683 ath9k_hw_reset_calibration(ah, currCal); 681 ath9k_hw_reset_calibration(ah, currCal);
684 } 682 return 0;
685 } 683 }
686 } 684 }
687 685
@@ -698,7 +696,9 @@ static bool ar9002_hw_calibrate(struct ath_hw *ah,
698 * NF is slow time-variant, so it is OK to use a 696 * NF is slow time-variant, so it is OK to use a
699 * historical value. 697 * historical value.
700 */ 698 */
701 ath9k_hw_loadnf(ah, ah->curchan); 699 ret = ath9k_hw_loadnf(ah, ah->curchan);
700 if (ret < 0)
701 return ret;
702 } 702 }
703 703
704 if (longcal) { 704 if (longcal) {
@@ -709,7 +709,7 @@ static bool ar9002_hw_calibrate(struct ath_hw *ah,
709 } 709 }
710 } 710 }
711 711
712 return iscaldone; 712 return !percal_pending;
713} 713}
714 714
715/* Carrier leakage Calibration fix */ 715/* Carrier leakage Calibration fix */
@@ -856,6 +856,8 @@ static bool ar9002_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
856 856
857 /* Do PA Calibration */ 857 /* Do PA Calibration */
858 ar9002_hw_pa_cal(ah, true); 858 ar9002_hw_pa_cal(ah, true);
859 ath9k_hw_loadnf(ah, chan);
860 ath9k_hw_start_nfcal(ah, true);
859 861
860 if (ah->caldata) 862 if (ah->caldata)
861 set_bit(NFCAL_PENDING, &ah->caldata->cal_flags); 863 set_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_phy.c b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
index 9a2afa2c690b..fc08162b5820 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
@@ -643,9 +643,12 @@ static void ar9002_hw_spectral_scan_config(struct ath_hw *ah,
643 * and fix otherwise. 643 * and fix otherwise.
644 */ 644 */
645 count = param->count; 645 count = param->count;
646 if (param->endless) 646 if (param->endless) {
647 count = 0x80; 647 if (AR_SREV_9271(ah))
648 else if (count & 0x80) 648 count = 0;
649 else
650 count = 0x80;
651 } else if (count & 0x80)
649 count = 0x7f; 652 count = 0x7f;
650 653
651 REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN, 654 REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index ac8301ef5242..06ab71db6e80 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -121,13 +121,12 @@ static bool ar9003_hw_per_calibration(struct ath_hw *ah,
121 return iscaldone; 121 return iscaldone;
122} 122}
123 123
124static bool ar9003_hw_calibrate(struct ath_hw *ah, 124static int ar9003_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
125 struct ath9k_channel *chan, 125 u8 rxchainmask, bool longcal)
126 u8 rxchainmask,
127 bool longcal)
128{ 126{
129 bool iscaldone = true; 127 bool iscaldone = true;
130 struct ath9k_cal_list *currCal = ah->cal_list_curr; 128 struct ath9k_cal_list *currCal = ah->cal_list_curr;
129 int ret;
131 130
132 /* 131 /*
133 * For given calibration: 132 * For given calibration:
@@ -163,7 +162,9 @@ static bool ar9003_hw_calibrate(struct ath_hw *ah,
163 * NF is slow time-variant, so it is OK to use a historical 162 * NF is slow time-variant, so it is OK to use a historical
164 * value. 163 * value.
165 */ 164 */
166 ath9k_hw_loadnf(ah, ah->curchan); 165 ret = ath9k_hw_loadnf(ah, ah->curchan);
166 if (ret < 0)
167 return ret;
167 168
168 /* start NF calibration, without updating BB NF register */ 169 /* start NF calibration, without updating BB NF register */
169 ath9k_hw_start_nfcal(ah, false); 170 ath9k_hw_start_nfcal(ah, false);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index 80c6eacbda53..e726e405152c 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -4079,27 +4079,28 @@ static int ar9003_hw_get_thermometer(struct ath_hw *ah)
4079 4079
4080static void ar9003_hw_thermometer_apply(struct ath_hw *ah) 4080static void ar9003_hw_thermometer_apply(struct ath_hw *ah)
4081{ 4081{
4082 struct ath9k_hw_capabilities *pCap = &ah->caps;
4082 int thermometer = ar9003_hw_get_thermometer(ah); 4083 int thermometer = ar9003_hw_get_thermometer(ah);
4083 u8 therm_on = (thermometer < 0) ? 0 : 1; 4084 u8 therm_on = (thermometer < 0) ? 0 : 1;
4084 4085
4085 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX4, 4086 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX4,
4086 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on); 4087 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);
4087 if (ah->caps.tx_chainmask & BIT(1)) 4088 if (pCap->chip_chainmask & BIT(1))
4088 REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX4, 4089 REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX4,
4089 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on); 4090 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);
4090 if (ah->caps.tx_chainmask & BIT(2)) 4091 if (pCap->chip_chainmask & BIT(2))
4091 REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4, 4092 REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4092 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on); 4093 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);
4093 4094
4094 therm_on = (thermometer < 0) ? 0 : (thermometer == 0); 4095 therm_on = (thermometer < 0) ? 0 : (thermometer == 0);
4095 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX4, 4096 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX4,
4096 AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on); 4097 AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on);
4097 if (ah->caps.tx_chainmask & BIT(1)) { 4098 if (pCap->chip_chainmask & BIT(1)) {
4098 therm_on = (thermometer < 0) ? 0 : (thermometer == 1); 4099 therm_on = (thermometer < 0) ? 0 : (thermometer == 1);
4099 REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX4, 4100 REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX4,
4100 AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on); 4101 AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on);
4101 } 4102 }
4102 if (ah->caps.tx_chainmask & BIT(2)) { 4103 if (pCap->chip_chainmask & BIT(2)) {
4103 therm_on = (thermometer < 0) ? 0 : (thermometer == 2); 4104 therm_on = (thermometer < 0) ? 0 : (thermometer == 2);
4104 REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4, 4105 REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4105 AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on); 4106 AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_hw.c b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
index ddef9eedbac6..06ad2172030e 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_hw.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
@@ -333,12 +333,29 @@ static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
333 qca953x_1p0_soc_preamble); 333 qca953x_1p0_soc_preamble);
334 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST], 334 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
335 qca953x_1p0_soc_postamble); 335 qca953x_1p0_soc_postamble);
336 INIT_INI_ARRAY(&ah->iniModesRxGain, 336
337 qca953x_1p0_common_wo_xlna_rx_gain_table); 337 if (AR_SREV_9531_20(ah)) {
338 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds, 338 INIT_INI_ARRAY(&ah->iniModesRxGain,
339 qca953x_1p0_common_wo_xlna_rx_gain_bounds); 339 qca953x_2p0_common_wo_xlna_rx_gain_table);
340 INIT_INI_ARRAY(&ah->iniModesTxGain, 340 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
341 qca953x_1p0_modes_no_xpa_tx_gain_table); 341 qca953x_2p0_common_wo_xlna_rx_gain_bounds);
342 } else {
343 INIT_INI_ARRAY(&ah->iniModesRxGain,
344 qca953x_1p0_common_wo_xlna_rx_gain_table);
345 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
346 qca953x_1p0_common_wo_xlna_rx_gain_bounds);
347 }
348
349 if (AR_SREV_9531_20(ah))
350 INIT_INI_ARRAY(&ah->iniModesTxGain,
351 qca953x_2p0_modes_no_xpa_tx_gain_table);
352 else if (AR_SREV_9531_11(ah))
353 INIT_INI_ARRAY(&ah->iniModesTxGain,
354 qca953x_1p1_modes_no_xpa_tx_gain_table);
355 else
356 INIT_INI_ARRAY(&ah->iniModesTxGain,
357 qca953x_1p0_modes_no_xpa_tx_gain_table);
358
342 INIT_INI_ARRAY(&ah->iniModesFastClock, 359 INIT_INI_ARRAY(&ah->iniModesFastClock,
343 qca953x_1p0_modes_fast_clock); 360 qca953x_1p0_modes_fast_clock);
344 } else if (AR_SREV_9580(ah)) { 361 } else if (AR_SREV_9580(ah)) {
@@ -518,9 +535,15 @@ static void ar9003_tx_gain_table_mode0(struct ath_hw *ah)
518 else if (AR_SREV_9550(ah)) 535 else if (AR_SREV_9550(ah))
519 INIT_INI_ARRAY(&ah->iniModesTxGain, 536 INIT_INI_ARRAY(&ah->iniModesTxGain,
520 ar955x_1p0_modes_xpa_tx_gain_table); 537 ar955x_1p0_modes_xpa_tx_gain_table);
521 else if (AR_SREV_9531(ah)) 538 else if (AR_SREV_9531_10(ah))
539 INIT_INI_ARRAY(&ah->iniModesTxGain,
540 qca953x_1p0_modes_xpa_tx_gain_table);
541 else if (AR_SREV_9531_11(ah))
542 INIT_INI_ARRAY(&ah->iniModesTxGain,
543 qca953x_1p1_modes_xpa_tx_gain_table);
544 else if (AR_SREV_9531_20(ah))
522 INIT_INI_ARRAY(&ah->iniModesTxGain, 545 INIT_INI_ARRAY(&ah->iniModesTxGain,
523 qca953x_1p0_modes_xpa_tx_gain_table); 546 qca953x_2p0_modes_xpa_tx_gain_table);
524 else if (AR_SREV_9580(ah)) 547 else if (AR_SREV_9580(ah))
525 INIT_INI_ARRAY(&ah->iniModesTxGain, 548 INIT_INI_ARRAY(&ah->iniModesTxGain,
526 ar9580_1p0_lowest_ob_db_tx_gain_table); 549 ar9580_1p0_lowest_ob_db_tx_gain_table);
@@ -562,7 +585,10 @@ static void ar9003_tx_gain_table_mode1(struct ath_hw *ah)
562 INIT_INI_ARRAY(&ah->iniModesTxGain, 585 INIT_INI_ARRAY(&ah->iniModesTxGain,
563 ar955x_1p0_modes_no_xpa_tx_gain_table); 586 ar955x_1p0_modes_no_xpa_tx_gain_table);
564 else if (AR_SREV_9531(ah)) { 587 else if (AR_SREV_9531(ah)) {
565 if (AR_SREV_9531_11(ah)) 588 if (AR_SREV_9531_20(ah))
589 INIT_INI_ARRAY(&ah->iniModesTxGain,
590 qca953x_2p0_modes_no_xpa_tx_gain_table);
591 else if (AR_SREV_9531_11(ah))
566 INIT_INI_ARRAY(&ah->iniModesTxGain, 592 INIT_INI_ARRAY(&ah->iniModesTxGain,
567 qca953x_1p1_modes_no_xpa_tx_gain_table); 593 qca953x_1p1_modes_no_xpa_tx_gain_table);
568 else 594 else
@@ -670,9 +696,6 @@ static void ar9003_tx_gain_table_mode5(struct ath_hw *ah)
670 if (AR_SREV_9485_11_OR_LATER(ah)) 696 if (AR_SREV_9485_11_OR_LATER(ah))
671 INIT_INI_ARRAY(&ah->iniModesTxGain, 697 INIT_INI_ARRAY(&ah->iniModesTxGain,
672 ar9485Modes_green_ob_db_tx_gain_1_1); 698 ar9485Modes_green_ob_db_tx_gain_1_1);
673 else if (AR_SREV_9340(ah))
674 INIT_INI_ARRAY(&ah->iniModesTxGain,
675 ar9340Modes_ub124_tx_gain_table_1p0);
676 else if (AR_SREV_9580(ah)) 699 else if (AR_SREV_9580(ah))
677 INIT_INI_ARRAY(&ah->iniModesTxGain, 700 INIT_INI_ARRAY(&ah->iniModesTxGain,
678 ar9580_1p0_type5_tx_gain_table); 701 ar9580_1p0_type5_tx_gain_table);
@@ -792,11 +815,16 @@ static void ar9003_rx_gain_table_mode1(struct ath_hw *ah)
792 ar955x_1p0_common_wo_xlna_rx_gain_table); 815 ar955x_1p0_common_wo_xlna_rx_gain_table);
793 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds, 816 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
794 ar955x_1p0_common_wo_xlna_rx_gain_bounds); 817 ar955x_1p0_common_wo_xlna_rx_gain_bounds);
795 } else if (AR_SREV_9531(ah)) { 818 } else if (AR_SREV_9531_10(ah) || AR_SREV_9531_11(ah)) {
796 INIT_INI_ARRAY(&ah->iniModesRxGain, 819 INIT_INI_ARRAY(&ah->iniModesRxGain,
797 qca953x_1p0_common_wo_xlna_rx_gain_table); 820 qca953x_1p0_common_wo_xlna_rx_gain_table);
798 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds, 821 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
799 qca953x_1p0_common_wo_xlna_rx_gain_bounds); 822 qca953x_1p0_common_wo_xlna_rx_gain_bounds);
823 } else if (AR_SREV_9531_20(ah)) {
824 INIT_INI_ARRAY(&ah->iniModesRxGain,
825 qca953x_2p0_common_wo_xlna_rx_gain_table);
826 INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
827 qca953x_2p0_common_wo_xlna_rx_gain_bounds);
800 } else if (AR_SREV_9580(ah)) 828 } else if (AR_SREV_9580(ah))
801 INIT_INI_ARRAY(&ah->iniModesRxGain, 829 INIT_INI_ARRAY(&ah->iniModesRxGain,
802 ar9580_1p0_wo_xlna_rx_gain_table); 830 ar9580_1p0_wo_xlna_rx_gain_table);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index 1e8ea5e4d4ca..2df6d2ee70c2 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -1361,7 +1361,7 @@ static void ar9003_hw_set_radar_params(struct ath_hw *ah,
1361 struct ath_hw_radar_conf *conf) 1361 struct ath_hw_radar_conf *conf)
1362{ 1362{
1363 unsigned int regWrites = 0; 1363 unsigned int regWrites = 0;
1364 u32 radar_0 = 0, radar_1 = 0; 1364 u32 radar_0 = 0, radar_1;
1365 1365
1366 if (!conf) { 1366 if (!conf) {
1367 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA); 1367 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
@@ -1375,6 +1375,9 @@ static void ar9003_hw_set_radar_params(struct ath_hw *ah,
1375 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI); 1375 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1376 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND); 1376 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1377 1377
1378 radar_1 = REG_READ(ah, AR_PHY_RADAR_1);
1379 radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH |
1380 AR_PHY_RADAR_1_RELPWR_THRESH);
1378 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI; 1381 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1379 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK; 1382 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1380 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN); 1383 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
@@ -1401,7 +1404,7 @@ static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
1401 conf->fir_power = -28; 1404 conf->fir_power = -28;
1402 conf->radar_rssi = 0; 1405 conf->radar_rssi = 0;
1403 conf->pulse_height = 10; 1406 conf->pulse_height = 10;
1404 conf->pulse_rssi = 24; 1407 conf->pulse_rssi = 15;
1405 conf->pulse_inband = 8; 1408 conf->pulse_inband = 8;
1406 conf->pulse_maxlen = 255; 1409 conf->pulse_maxlen = 255;
1407 conf->pulse_inband_step = 12; 1410 conf->pulse_inband_step = 12;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_rtt.h b/drivers/net/wireless/ath/ath9k/ar9003_rtt.h
index a43b30d723a4..6290467a75a0 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_rtt.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_rtt.h
@@ -17,6 +17,7 @@
17#ifndef AR9003_RTT_H 17#ifndef AR9003_RTT_H
18#define AR9003_RTT_H 18#define AR9003_RTT_H
19 19
20#ifdef CONFIG_ATH9K_PCOEM
20void ar9003_hw_rtt_enable(struct ath_hw *ah); 21void ar9003_hw_rtt_enable(struct ath_hw *ah);
21void ar9003_hw_rtt_disable(struct ath_hw *ah); 22void ar9003_hw_rtt_disable(struct ath_hw *ah);
22void ar9003_hw_rtt_set_mask(struct ath_hw *ah, u32 rtt_mask); 23void ar9003_hw_rtt_set_mask(struct ath_hw *ah, u32 rtt_mask);
@@ -25,5 +26,40 @@ void ar9003_hw_rtt_load_hist(struct ath_hw *ah);
25void ar9003_hw_rtt_fill_hist(struct ath_hw *ah); 26void ar9003_hw_rtt_fill_hist(struct ath_hw *ah);
26void ar9003_hw_rtt_clear_hist(struct ath_hw *ah); 27void ar9003_hw_rtt_clear_hist(struct ath_hw *ah);
27bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan); 28bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan);
29#else
30static inline void ar9003_hw_rtt_enable(struct ath_hw *ah)
31{
32}
33
34static inline void ar9003_hw_rtt_disable(struct ath_hw *ah)
35{
36}
37
38static inline void ar9003_hw_rtt_set_mask(struct ath_hw *ah, u32 rtt_mask)
39{
40}
41
42static inline bool ar9003_hw_rtt_force_restore(struct ath_hw *ah)
43{
44 return false;
45}
46
47static inline void ar9003_hw_rtt_load_hist(struct ath_hw *ah)
48{
49}
50
51static inline void ar9003_hw_rtt_fill_hist(struct ath_hw *ah)
52{
53}
54
55static inline void ar9003_hw_rtt_clear_hist(struct ath_hw *ah)
56{
57}
58
59static inline bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan)
60{
61 return false;
62}
63#endif
28 64
29#endif 65#endif
diff --git a/drivers/net/wireless/ath/ath9k/ar953x_initvals.h b/drivers/net/wireless/ath/ath9k/ar953x_initvals.h
index 812a9d787bf3..159cc6fd2362 100644
--- a/drivers/net/wireless/ath/ath9k/ar953x_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar953x_initvals.h
@@ -20,6 +20,8 @@
20 20
21#define qca953x_1p0_mac_postamble ar9300_2p2_mac_postamble 21#define qca953x_1p0_mac_postamble ar9300_2p2_mac_postamble
22 22
23#define qca953x_1p0_soc_preamble ar955x_1p0_soc_preamble
24
23#define qca953x_1p0_soc_postamble ar9300_2p2_soc_postamble 25#define qca953x_1p0_soc_postamble ar9300_2p2_soc_postamble
24 26
25#define qca953x_1p0_common_rx_gain_table ar9300Common_rx_gain_table_2p2 27#define qca953x_1p0_common_rx_gain_table ar9300Common_rx_gain_table_2p2
@@ -28,6 +30,10 @@
28 30
29#define qca953x_1p0_modes_fast_clock ar9300Modes_fast_clock_2p2 31#define qca953x_1p0_modes_fast_clock ar9300Modes_fast_clock_2p2
30 32
33#define qca953x_1p0_common_wo_xlna_rx_gain_bounds ar955x_1p0_common_wo_xlna_rx_gain_bounds
34
35#define qca953x_1p0_common_rx_gain_bounds ar955x_1p0_common_rx_gain_bounds
36
31static const u32 qca953x_1p0_mac_core[][2] = { 37static const u32 qca953x_1p0_mac_core[][2] = {
32 /* Addr allmodes */ 38 /* Addr allmodes */
33 {0x00000008, 0x00000000}, 39 {0x00000008, 0x00000000},
@@ -490,35 +496,6 @@ static const u32 qca953x_1p0_radio_postamble[][5] = {
490 {0x00016540, 0x10804008, 0x10804008, 0x50804000, 0x50804000}, 496 {0x00016540, 0x10804008, 0x10804008, 0x50804000, 0x50804000},
491}; 497};
492 498
493static const u32 qca953x_1p0_soc_preamble[][2] = {
494 /* Addr allmodes */
495 {0x00007000, 0x00000000},
496 {0x00007004, 0x00000000},
497 {0x00007008, 0x00000000},
498 {0x0000700c, 0x00000000},
499 {0x0000701c, 0x00000000},
500 {0x00007020, 0x00000000},
501 {0x00007024, 0x00000000},
502 {0x00007028, 0x00000000},
503 {0x0000702c, 0x00000000},
504 {0x00007030, 0x00000000},
505 {0x00007034, 0x00000002},
506 {0x00007038, 0x000004c2},
507 {0x00007048, 0x00000000},
508};
509
510static const u32 qca953x_1p0_common_rx_gain_bounds[][5] = {
511 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
512 {0x00009e44, 0xfe321e27, 0xfe321e27, 0xfe291e27, 0xfe291e27},
513 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302018, 0x50302018},
514};
515
516static const u32 qca953x_1p0_common_wo_xlna_rx_gain_bounds[][5] = {
517 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
518 {0x00009e44, 0xfe321e27, 0xfe321e27, 0xfe291e27, 0xfe291e27},
519 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012},
520};
521
522static const u32 qca953x_1p0_modes_xpa_tx_gain_table[][2] = { 499static const u32 qca953x_1p0_modes_xpa_tx_gain_table[][2] = {
523 /* Addr allmodes */ 500 /* Addr allmodes */
524 {0x0000a2dc, 0xfffd5aaa}, 501 {0x0000a2dc, 0xfffd5aaa},
@@ -715,8 +692,73 @@ static const u32 qca953x_1p1_modes_no_xpa_tx_gain_table[][2] = {
715 {0x00016448, 0x6c927a70}, 692 {0x00016448, 0x6c927a70},
716}; 693};
717 694
695static const u32 qca953x_1p1_modes_xpa_tx_gain_table[][2] = {
696 /* Addr allmodes */
697 {0x0000a2dc, 0xfffb52aa},
698 {0x0000a2e0, 0xfffd64cc},
699 {0x0000a2e4, 0xfffe80f0},
700 {0x0000a2e8, 0xffffff00},
701 {0x0000a410, 0x000050d5},
702 {0x0000a500, 0x00000000},
703 {0x0000a504, 0x04000002},
704 {0x0000a508, 0x08000004},
705 {0x0000a50c, 0x0c000006},
706 {0x0000a510, 0x1000000a},
707 {0x0000a514, 0x1400000c},
708 {0x0000a518, 0x1800000e},
709 {0x0000a51c, 0x1c000048},
710 {0x0000a520, 0x2000004a},
711 {0x0000a524, 0x2400004c},
712 {0x0000a528, 0x2800004e},
713 {0x0000a52c, 0x2b00024a},
714 {0x0000a530, 0x2f00024c},
715 {0x0000a534, 0x3300024e},
716 {0x0000a538, 0x36000668},
717 {0x0000a53c, 0x38000669},
718 {0x0000a540, 0x3a000868},
719 {0x0000a544, 0x3d00086a},
720 {0x0000a548, 0x4000086c},
721 {0x0000a54c, 0x4200086e},
722 {0x0000a550, 0x43000a6e},
723 {0x0000a554, 0x43000a6e},
724 {0x0000a558, 0x43000a6e},
725 {0x0000a55c, 0x43000a6e},
726 {0x0000a560, 0x43000a6e},
727 {0x0000a564, 0x43000a6e},
728 {0x0000a568, 0x43000a6e},
729 {0x0000a56c, 0x43000a6e},
730 {0x0000a570, 0x43000a6e},
731 {0x0000a574, 0x43000a6e},
732 {0x0000a578, 0x43000a6e},
733 {0x0000a57c, 0x43000a6e},
734 {0x0000a600, 0x00000000},
735 {0x0000a604, 0x00000000},
736 {0x0000a608, 0x00000000},
737 {0x0000a60c, 0x03804000},
738 {0x0000a610, 0x03804e01},
739 {0x0000a614, 0x03804e01},
740 {0x0000a618, 0x03804e01},
741 {0x0000a61c, 0x04009002},
742 {0x0000a620, 0x04009002},
743 {0x0000a624, 0x04009002},
744 {0x0000a628, 0x04009002},
745 {0x0000a62c, 0x04009002},
746 {0x0000a630, 0x04009002},
747 {0x0000a634, 0x04009002},
748 {0x0000a638, 0x04009002},
749 {0x0000a63c, 0x04009002},
750 {0x0000b2dc, 0xfffb52aa},
751 {0x0000b2e0, 0xfffd64cc},
752 {0x0000b2e4, 0xfffe80f0},
753 {0x0000b2e8, 0xffffff00},
754 {0x00016044, 0x024922db},
755 {0x00016048, 0x6c927a70},
756 {0x00016444, 0x024922db},
757 {0x00016448, 0x6c927a70},
758};
759
718static const u32 qca953x_2p0_baseband_core[][2] = { 760static const u32 qca953x_2p0_baseband_core[][2] = {
719 /* Addr allmodes */ 761 /* Addr allmodes */
720 {0x00009800, 0xafe68e30}, 762 {0x00009800, 0xafe68e30},
721 {0x00009804, 0xfd14e000}, 763 {0x00009804, 0xfd14e000},
722 {0x00009808, 0x9c0a9f6b}, 764 {0x00009808, 0x9c0a9f6b},
@@ -914,4 +956,400 @@ static const u32 qca953x_2p0_baseband_postamble[][5] = {
914 {0x0000b284, 0x00000000, 0x00000000, 0x00000010, 0x00000010}, 956 {0x0000b284, 0x00000000, 0x00000000, 0x00000010, 0x00000010},
915}; 957};
916 958
959static const u32 qca953x_2p0_common_wo_xlna_rx_gain_table[][2] = {
960 /* Addr allmodes */
961 {0x0000a000, 0x00010000},
962 {0x0000a004, 0x00030002},
963 {0x0000a008, 0x00050004},
964 {0x0000a00c, 0x00810080},
965 {0x0000a010, 0x00830082},
966 {0x0000a014, 0x01810180},
967 {0x0000a018, 0x01830182},
968 {0x0000a01c, 0x01850184},
969 {0x0000a020, 0x01890188},
970 {0x0000a024, 0x018b018a},
971 {0x0000a028, 0x018d018c},
972 {0x0000a02c, 0x03820190},
973 {0x0000a030, 0x03840383},
974 {0x0000a034, 0x03880385},
975 {0x0000a038, 0x038a0389},
976 {0x0000a03c, 0x038c038b},
977 {0x0000a040, 0x0390038d},
978 {0x0000a044, 0x03920391},
979 {0x0000a048, 0x03940393},
980 {0x0000a04c, 0x03960395},
981 {0x0000a050, 0x00000000},
982 {0x0000a054, 0x00000000},
983 {0x0000a058, 0x00000000},
984 {0x0000a05c, 0x00000000},
985 {0x0000a060, 0x00000000},
986 {0x0000a064, 0x00000000},
987 {0x0000a068, 0x00000000},
988 {0x0000a06c, 0x00000000},
989 {0x0000a070, 0x00000000},
990 {0x0000a074, 0x00000000},
991 {0x0000a078, 0x00000000},
992 {0x0000a07c, 0x00000000},
993 {0x0000a080, 0x29292929},
994 {0x0000a084, 0x29292929},
995 {0x0000a088, 0x29292929},
996 {0x0000a08c, 0x29292929},
997 {0x0000a090, 0x22292929},
998 {0x0000a094, 0x1d1d2222},
999 {0x0000a098, 0x0c111117},
1000 {0x0000a09c, 0x00030303},
1001 {0x0000a0a0, 0x00000000},
1002 {0x0000a0a4, 0x00000000},
1003 {0x0000a0a8, 0x00000000},
1004 {0x0000a0ac, 0x00000000},
1005 {0x0000a0b0, 0x00000000},
1006 {0x0000a0b4, 0x00000000},
1007 {0x0000a0b8, 0x00000000},
1008 {0x0000a0bc, 0x00000000},
1009 {0x0000a0c0, 0x001f0000},
1010 {0x0000a0c4, 0x01000101},
1011 {0x0000a0c8, 0x011e011f},
1012 {0x0000a0cc, 0x011c011d},
1013 {0x0000a0d0, 0x02030204},
1014 {0x0000a0d4, 0x02010202},
1015 {0x0000a0d8, 0x021f0200},
1016 {0x0000a0dc, 0x0302021e},
1017 {0x0000a0e0, 0x03000301},
1018 {0x0000a0e4, 0x031e031f},
1019 {0x0000a0e8, 0x0402031d},
1020 {0x0000a0ec, 0x04000401},
1021 {0x0000a0f0, 0x041e041f},
1022 {0x0000a0f4, 0x0502041d},
1023 {0x0000a0f8, 0x05000501},
1024 {0x0000a0fc, 0x051e051f},
1025 {0x0000a100, 0x06010602},
1026 {0x0000a104, 0x061f0600},
1027 {0x0000a108, 0x061d061e},
1028 {0x0000a10c, 0x07020703},
1029 {0x0000a110, 0x07000701},
1030 {0x0000a114, 0x00000000},
1031 {0x0000a118, 0x00000000},
1032 {0x0000a11c, 0x00000000},
1033 {0x0000a120, 0x00000000},
1034 {0x0000a124, 0x00000000},
1035 {0x0000a128, 0x00000000},
1036 {0x0000a12c, 0x00000000},
1037 {0x0000a130, 0x00000000},
1038 {0x0000a134, 0x00000000},
1039 {0x0000a138, 0x00000000},
1040 {0x0000a13c, 0x00000000},
1041 {0x0000a140, 0x001f0000},
1042 {0x0000a144, 0x01000101},
1043 {0x0000a148, 0x011e011f},
1044 {0x0000a14c, 0x011c011d},
1045 {0x0000a150, 0x02030204},
1046 {0x0000a154, 0x02010202},
1047 {0x0000a158, 0x021f0200},
1048 {0x0000a15c, 0x0302021e},
1049 {0x0000a160, 0x03000301},
1050 {0x0000a164, 0x031e031f},
1051 {0x0000a168, 0x0402031d},
1052 {0x0000a16c, 0x04000401},
1053 {0x0000a170, 0x041e041f},
1054 {0x0000a174, 0x0502041d},
1055 {0x0000a178, 0x05000501},
1056 {0x0000a17c, 0x051e051f},
1057 {0x0000a180, 0x06010602},
1058 {0x0000a184, 0x061f0600},
1059 {0x0000a188, 0x061d061e},
1060 {0x0000a18c, 0x07020703},
1061 {0x0000a190, 0x07000701},
1062 {0x0000a194, 0x00000000},
1063 {0x0000a198, 0x00000000},
1064 {0x0000a19c, 0x00000000},
1065 {0x0000a1a0, 0x00000000},
1066 {0x0000a1a4, 0x00000000},
1067 {0x0000a1a8, 0x00000000},
1068 {0x0000a1ac, 0x00000000},
1069 {0x0000a1b0, 0x00000000},
1070 {0x0000a1b4, 0x00000000},
1071 {0x0000a1b8, 0x00000000},
1072 {0x0000a1bc, 0x00000000},
1073 {0x0000a1c0, 0x00000000},
1074 {0x0000a1c4, 0x00000000},
1075 {0x0000a1c8, 0x00000000},
1076 {0x0000a1cc, 0x00000000},
1077 {0x0000a1d0, 0x00000000},
1078 {0x0000a1d4, 0x00000000},
1079 {0x0000a1d8, 0x00000000},
1080 {0x0000a1dc, 0x00000000},
1081 {0x0000a1e0, 0x00000000},
1082 {0x0000a1e4, 0x00000000},
1083 {0x0000a1e8, 0x00000000},
1084 {0x0000a1ec, 0x00000000},
1085 {0x0000a1f0, 0x00000396},
1086 {0x0000a1f4, 0x00000396},
1087 {0x0000a1f8, 0x00000396},
1088 {0x0000a1fc, 0x00000196},
1089 {0x0000b000, 0x00010000},
1090 {0x0000b004, 0x00030002},
1091 {0x0000b008, 0x00050004},
1092 {0x0000b00c, 0x00810080},
1093 {0x0000b010, 0x00830082},
1094 {0x0000b014, 0x01810180},
1095 {0x0000b018, 0x01830182},
1096 {0x0000b01c, 0x01850184},
1097 {0x0000b020, 0x02810280},
1098 {0x0000b024, 0x02830282},
1099 {0x0000b028, 0x02850284},
1100 {0x0000b02c, 0x02890288},
1101 {0x0000b030, 0x028b028a},
1102 {0x0000b034, 0x0388028c},
1103 {0x0000b038, 0x038a0389},
1104 {0x0000b03c, 0x038c038b},
1105 {0x0000b040, 0x0390038d},
1106 {0x0000b044, 0x03920391},
1107 {0x0000b048, 0x03940393},
1108 {0x0000b04c, 0x03960395},
1109 {0x0000b050, 0x00000000},
1110 {0x0000b054, 0x00000000},
1111 {0x0000b058, 0x00000000},
1112 {0x0000b05c, 0x00000000},
1113 {0x0000b060, 0x00000000},
1114 {0x0000b064, 0x00000000},
1115 {0x0000b068, 0x00000000},
1116 {0x0000b06c, 0x00000000},
1117 {0x0000b070, 0x00000000},
1118 {0x0000b074, 0x00000000},
1119 {0x0000b078, 0x00000000},
1120 {0x0000b07c, 0x00000000},
1121 {0x0000b080, 0x32323232},
1122 {0x0000b084, 0x2f2f3232},
1123 {0x0000b088, 0x23282a2d},
1124 {0x0000b08c, 0x1c1e2123},
1125 {0x0000b090, 0x14171919},
1126 {0x0000b094, 0x0e0e1214},
1127 {0x0000b098, 0x03050707},
1128 {0x0000b09c, 0x00030303},
1129 {0x0000b0a0, 0x00000000},
1130 {0x0000b0a4, 0x00000000},
1131 {0x0000b0a8, 0x00000000},
1132 {0x0000b0ac, 0x00000000},
1133 {0x0000b0b0, 0x00000000},
1134 {0x0000b0b4, 0x00000000},
1135 {0x0000b0b8, 0x00000000},
1136 {0x0000b0bc, 0x00000000},
1137 {0x0000b0c0, 0x003f0020},
1138 {0x0000b0c4, 0x00400041},
1139 {0x0000b0c8, 0x0140005f},
1140 {0x0000b0cc, 0x0160015f},
1141 {0x0000b0d0, 0x017e017f},
1142 {0x0000b0d4, 0x02410242},
1143 {0x0000b0d8, 0x025f0240},
1144 {0x0000b0dc, 0x027f0260},
1145 {0x0000b0e0, 0x0341027e},
1146 {0x0000b0e4, 0x035f0340},
1147 {0x0000b0e8, 0x037f0360},
1148 {0x0000b0ec, 0x04400441},
1149 {0x0000b0f0, 0x0460045f},
1150 {0x0000b0f4, 0x0541047f},
1151 {0x0000b0f8, 0x055f0540},
1152 {0x0000b0fc, 0x057f0560},
1153 {0x0000b100, 0x06400641},
1154 {0x0000b104, 0x0660065f},
1155 {0x0000b108, 0x067e067f},
1156 {0x0000b10c, 0x07410742},
1157 {0x0000b110, 0x075f0740},
1158 {0x0000b114, 0x077f0760},
1159 {0x0000b118, 0x07800781},
1160 {0x0000b11c, 0x07a0079f},
1161 {0x0000b120, 0x07c107bf},
1162 {0x0000b124, 0x000007c0},
1163 {0x0000b128, 0x00000000},
1164 {0x0000b12c, 0x00000000},
1165 {0x0000b130, 0x00000000},
1166 {0x0000b134, 0x00000000},
1167 {0x0000b138, 0x00000000},
1168 {0x0000b13c, 0x00000000},
1169 {0x0000b140, 0x003f0020},
1170 {0x0000b144, 0x00400041},
1171 {0x0000b148, 0x0140005f},
1172 {0x0000b14c, 0x0160015f},
1173 {0x0000b150, 0x017e017f},
1174 {0x0000b154, 0x02410242},
1175 {0x0000b158, 0x025f0240},
1176 {0x0000b15c, 0x027f0260},
1177 {0x0000b160, 0x0341027e},
1178 {0x0000b164, 0x035f0340},
1179 {0x0000b168, 0x037f0360},
1180 {0x0000b16c, 0x04400441},
1181 {0x0000b170, 0x0460045f},
1182 {0x0000b174, 0x0541047f},
1183 {0x0000b178, 0x055f0540},
1184 {0x0000b17c, 0x057f0560},
1185 {0x0000b180, 0x06400641},
1186 {0x0000b184, 0x0660065f},
1187 {0x0000b188, 0x067e067f},
1188 {0x0000b18c, 0x07410742},
1189 {0x0000b190, 0x075f0740},
1190 {0x0000b194, 0x077f0760},
1191 {0x0000b198, 0x07800781},
1192 {0x0000b19c, 0x07a0079f},
1193 {0x0000b1a0, 0x07c107bf},
1194 {0x0000b1a4, 0x000007c0},
1195 {0x0000b1a8, 0x00000000},
1196 {0x0000b1ac, 0x00000000},
1197 {0x0000b1b0, 0x00000000},
1198 {0x0000b1b4, 0x00000000},
1199 {0x0000b1b8, 0x00000000},
1200 {0x0000b1bc, 0x00000000},
1201 {0x0000b1c0, 0x00000000},
1202 {0x0000b1c4, 0x00000000},
1203 {0x0000b1c8, 0x00000000},
1204 {0x0000b1cc, 0x00000000},
1205 {0x0000b1d0, 0x00000000},
1206 {0x0000b1d4, 0x00000000},
1207 {0x0000b1d8, 0x00000000},
1208 {0x0000b1dc, 0x00000000},
1209 {0x0000b1e0, 0x00000000},
1210 {0x0000b1e4, 0x00000000},
1211 {0x0000b1e8, 0x00000000},
1212 {0x0000b1ec, 0x00000000},
1213 {0x0000b1f0, 0x00000396},
1214 {0x0000b1f4, 0x00000396},
1215 {0x0000b1f8, 0x00000396},
1216 {0x0000b1fc, 0x00000196},
1217};
1218
1219static const u32 qca953x_2p0_common_wo_xlna_rx_gain_bounds[][5] = {
1220 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
1221 {0x00009e44, 0xfe321e27, 0xfe321e27, 0xfe291e27, 0xfe291e27},
1222 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012},
1223};
1224
1225static const u32 qca953x_2p0_modes_xpa_tx_gain_table[][2] = {
1226 /* Addr allmodes */
1227 {0x0000a2dc, 0xfffb52aa},
1228 {0x0000a2e0, 0xfffd64cc},
1229 {0x0000a2e4, 0xfffe80f0},
1230 {0x0000a2e8, 0xffffff00},
1231 {0x0000a410, 0x000050d5},
1232 {0x0000a500, 0x00000000},
1233 {0x0000a504, 0x04000002},
1234 {0x0000a508, 0x08000004},
1235 {0x0000a50c, 0x0c000006},
1236 {0x0000a510, 0x1000000a},
1237 {0x0000a514, 0x1400000c},
1238 {0x0000a518, 0x1800000e},
1239 {0x0000a51c, 0x1c000048},
1240 {0x0000a520, 0x2000004a},
1241 {0x0000a524, 0x2400004c},
1242 {0x0000a528, 0x2800004e},
1243 {0x0000a52c, 0x2b00024a},
1244 {0x0000a530, 0x2f00024c},
1245 {0x0000a534, 0x3300024e},
1246 {0x0000a538, 0x36000668},
1247 {0x0000a53c, 0x38000669},
1248 {0x0000a540, 0x3a000868},
1249 {0x0000a544, 0x3d00086a},
1250 {0x0000a548, 0x4000086c},
1251 {0x0000a54c, 0x4200086e},
1252 {0x0000a550, 0x43000a6e},
1253 {0x0000a554, 0x43000a6e},
1254 {0x0000a558, 0x43000a6e},
1255 {0x0000a55c, 0x43000a6e},
1256 {0x0000a560, 0x43000a6e},
1257 {0x0000a564, 0x43000a6e},
1258 {0x0000a568, 0x43000a6e},
1259 {0x0000a56c, 0x43000a6e},
1260 {0x0000a570, 0x43000a6e},
1261 {0x0000a574, 0x43000a6e},
1262 {0x0000a578, 0x43000a6e},
1263 {0x0000a57c, 0x43000a6e},
1264 {0x0000a600, 0x00000000},
1265 {0x0000a604, 0x00000000},
1266 {0x0000a608, 0x00000000},
1267 {0x0000a60c, 0x03804000},
1268 {0x0000a610, 0x03804e01},
1269 {0x0000a614, 0x03804e01},
1270 {0x0000a618, 0x03804e01},
1271 {0x0000a61c, 0x04009002},
1272 {0x0000a620, 0x04009002},
1273 {0x0000a624, 0x04009002},
1274 {0x0000a628, 0x04009002},
1275 {0x0000a62c, 0x04009002},
1276 {0x0000a630, 0x04009002},
1277 {0x0000a634, 0x04009002},
1278 {0x0000a638, 0x04009002},
1279 {0x0000a63c, 0x04009002},
1280 {0x0000b2dc, 0xfffb52aa},
1281 {0x0000b2e0, 0xfffd64cc},
1282 {0x0000b2e4, 0xfffe80f0},
1283 {0x0000b2e8, 0xffffff00},
1284 {0x00016044, 0x024922db},
1285 {0x00016048, 0x6c927a70},
1286 {0x00016444, 0x024922db},
1287 {0x00016448, 0x6c927a70},
1288};
1289
1290static const u32 qca953x_2p0_modes_no_xpa_tx_gain_table[][2] = {
1291 /* Addr allmodes */
1292 {0x0000a2dc, 0xffd5f552},
1293 {0x0000a2e0, 0xffe60664},
1294 {0x0000a2e4, 0xfff80780},
1295 {0x0000a2e8, 0xfffff800},
1296 {0x0000a410, 0x000050de},
1297 {0x0000a500, 0x00000061},
1298 {0x0000a504, 0x04000063},
1299 {0x0000a508, 0x08000065},
1300 {0x0000a50c, 0x0c000261},
1301 {0x0000a510, 0x10000263},
1302 {0x0000a514, 0x14000265},
1303 {0x0000a518, 0x18000482},
1304 {0x0000a51c, 0x1b000484},
1305 {0x0000a520, 0x1f000486},
1306 {0x0000a524, 0x240008c2},
1307 {0x0000a528, 0x28000cc1},
1308 {0x0000a52c, 0x2d000ce3},
1309 {0x0000a530, 0x31000ce5},
1310 {0x0000a534, 0x350010e5},
1311 {0x0000a538, 0x360012e5},
1312 {0x0000a53c, 0x380014e5},
1313 {0x0000a540, 0x3b0018e5},
1314 {0x0000a544, 0x3d001d04},
1315 {0x0000a548, 0x3e001d05},
1316 {0x0000a54c, 0x40001d07},
1317 {0x0000a550, 0x42001f27},
1318 {0x0000a554, 0x43001f67},
1319 {0x0000a558, 0x46001fe7},
1320 {0x0000a55c, 0x47001f2b},
1321 {0x0000a560, 0x49001f0d},
1322 {0x0000a564, 0x4b001ed2},
1323 {0x0000a568, 0x4c001ed4},
1324 {0x0000a56c, 0x4e001f15},
1325 {0x0000a570, 0x4f001ff6},
1326 {0x0000a574, 0x4f001ff6},
1327 {0x0000a578, 0x4f001ff6},
1328 {0x0000a57c, 0x4f001ff6},
1329 {0x0000a600, 0x00000000},
1330 {0x0000a604, 0x00000000},
1331 {0x0000a608, 0x00000000},
1332 {0x0000a60c, 0x00804201},
1333 {0x0000a610, 0x01008201},
1334 {0x0000a614, 0x0180c402},
1335 {0x0000a618, 0x0180c603},
1336 {0x0000a61c, 0x0180c603},
1337 {0x0000a620, 0x01c10603},
1338 {0x0000a624, 0x01c10704},
1339 {0x0000a628, 0x02c18b05},
1340 {0x0000a62c, 0x02c14c07},
1341 {0x0000a630, 0x01008704},
1342 {0x0000a634, 0x01c10402},
1343 {0x0000a638, 0x0301cc07},
1344 {0x0000a63c, 0x0301cc07},
1345 {0x0000b2dc, 0xffd5f552},
1346 {0x0000b2e0, 0xffe60664},
1347 {0x0000b2e4, 0xfff80780},
1348 {0x0000b2e8, 0xfffff800},
1349 {0x00016044, 0x049242db},
1350 {0x00016048, 0x6c927a70},
1351 {0x00016444, 0x049242db},
1352 {0x00016448, 0x6c927a70},
1353};
1354
917#endif /* INITVALS_953X_H */ 1355#endif /* INITVALS_953X_H */
diff --git a/drivers/net/wireless/ath/ath9k/ar955x_1p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar955x_1p0_initvals.h
index 74d8bc05b317..fd6a84ccd49e 100644
--- a/drivers/net/wireless/ath/ath9k/ar955x_1p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar955x_1p0_initvals.h
@@ -507,7 +507,7 @@ static const u32 ar955x_1p0_baseband_core[][2] = {
507 {0x00009d04, 0x40206c10}, 507 {0x00009d04, 0x40206c10},
508 {0x00009d08, 0x009c4060}, 508 {0x00009d08, 0x009c4060},
509 {0x00009d0c, 0x9883800a}, 509 {0x00009d0c, 0x9883800a},
510 {0x00009d10, 0x01834061}, 510 {0x00009d10, 0x01884061},
511 {0x00009d14, 0x00c0040b}, 511 {0x00009d14, 0x00c0040b},
512 {0x00009d18, 0x00000000}, 512 {0x00009d18, 0x00000000},
513 {0x00009e08, 0x0038230c}, 513 {0x00009e08, 0x0038230c},
@@ -545,9 +545,9 @@ static const u32 ar955x_1p0_baseband_core[][2] = {
545 {0x0000a370, 0x00000000}, 545 {0x0000a370, 0x00000000},
546 {0x0000a390, 0x00000001}, 546 {0x0000a390, 0x00000001},
547 {0x0000a394, 0x00000444}, 547 {0x0000a394, 0x00000444},
548 {0x0000a398, 0x1f020503}, 548 {0x0000a398, 0x001f0e0f},
549 {0x0000a39c, 0x29180c03}, 549 {0x0000a39c, 0x0075393f},
550 {0x0000a3a0, 0x9a8b6844}, 550 {0x0000a3a0, 0xb79f6427},
551 {0x0000a3a4, 0x00000000}, 551 {0x0000a3a4, 0x00000000},
552 {0x0000a3a8, 0xaaaaaaaa}, 552 {0x0000a3a8, 0xaaaaaaaa},
553 {0x0000a3ac, 0x3c466478}, 553 {0x0000a3ac, 0x3c466478},
diff --git a/drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h
index a5ca65240af3..5d4629f96c15 100644
--- a/drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h
@@ -24,7 +24,149 @@
24 24
25#define ar9580_1p0_soc_postamble ar9300_2p2_soc_postamble 25#define ar9580_1p0_soc_postamble ar9300_2p2_soc_postamble
26 26
27#define ar9580_1p0_radio_core ar9300_2p2_radio_core 27static const u32 ar9580_1p0_radio_core[][2] = {
28 /* Addr allmodes */
29 {0x00016000, 0x36db2db6},
30 {0x00016004, 0x6db6db40},
31 {0x00016008, 0x73f00000},
32 {0x0001600c, 0x00000000},
33 {0x00016040, 0x7f80fff8},
34 {0x0001604c, 0x76d005b5},
35 {0x00016050, 0x556cf031},
36 {0x00016054, 0x13449440},
37 {0x00016058, 0x0c51c92c},
38 {0x0001605c, 0x3db7fffc},
39 {0x00016060, 0xfffffffc},
40 {0x00016064, 0x000f0278},
41 {0x0001606c, 0x6db60000},
42 {0x00016080, 0x00000000},
43 {0x00016084, 0x0e48048c},
44 {0x00016088, 0x54214514},
45 {0x0001608c, 0x119f481e},
46 {0x00016090, 0x24926490},
47 {0x00016098, 0xd2888888},
48 {0x000160a0, 0x0a108ffe},
49 {0x000160a4, 0x812fc370},
50 {0x000160a8, 0x423c8000},
51 {0x000160b4, 0x92480080},
52 {0x000160c0, 0x00adb6d0},
53 {0x000160c4, 0x6db6db60},
54 {0x000160c8, 0x6db6db6c},
55 {0x000160cc, 0x01e6c000},
56 {0x00016100, 0x3fffbe01},
57 {0x00016104, 0xfff80000},
58 {0x00016108, 0x00080010},
59 {0x00016144, 0x02084080},
60 {0x00016148, 0x00000000},
61 {0x00016280, 0x058a0001},
62 {0x00016284, 0x3d840208},
63 {0x00016288, 0x05a20408},
64 {0x0001628c, 0x00038c07},
65 {0x00016290, 0x00000004},
66 {0x00016294, 0x458a214f},
67 {0x00016380, 0x00000000},
68 {0x00016384, 0x00000000},
69 {0x00016388, 0x00800700},
70 {0x0001638c, 0x00800700},
71 {0x00016390, 0x00800700},
72 {0x00016394, 0x00000000},
73 {0x00016398, 0x00000000},
74 {0x0001639c, 0x00000000},
75 {0x000163a0, 0x00000001},
76 {0x000163a4, 0x00000001},
77 {0x000163a8, 0x00000000},
78 {0x000163ac, 0x00000000},
79 {0x000163b0, 0x00000000},
80 {0x000163b4, 0x00000000},
81 {0x000163b8, 0x00000000},
82 {0x000163bc, 0x00000000},
83 {0x000163c0, 0x000000a0},
84 {0x000163c4, 0x000c0000},
85 {0x000163c8, 0x14021402},
86 {0x000163cc, 0x00001402},
87 {0x000163d0, 0x00000000},
88 {0x000163d4, 0x00000000},
89 {0x00016400, 0x36db2db6},
90 {0x00016404, 0x6db6db40},
91 {0x00016408, 0x73f00000},
92 {0x0001640c, 0x00000000},
93 {0x00016440, 0x7f80fff8},
94 {0x0001644c, 0x76d005b5},
95 {0x00016450, 0x556cf031},
96 {0x00016454, 0x13449440},
97 {0x00016458, 0x0c51c92c},
98 {0x0001645c, 0x3db7fffc},
99 {0x00016460, 0xfffffffc},
100 {0x00016464, 0x000f0278},
101 {0x0001646c, 0x6db60000},
102 {0x00016500, 0x3fffbe01},
103 {0x00016504, 0xfff80000},
104 {0x00016508, 0x00080010},
105 {0x00016544, 0x02084080},
106 {0x00016548, 0x00000000},
107 {0x00016780, 0x00000000},
108 {0x00016784, 0x00000000},
109 {0x00016788, 0x00800700},
110 {0x0001678c, 0x00800700},
111 {0x00016790, 0x00800700},
112 {0x00016794, 0x00000000},
113 {0x00016798, 0x00000000},
114 {0x0001679c, 0x00000000},
115 {0x000167a0, 0x00000001},
116 {0x000167a4, 0x00000001},
117 {0x000167a8, 0x00000000},
118 {0x000167ac, 0x00000000},
119 {0x000167b0, 0x00000000},
120 {0x000167b4, 0x00000000},
121 {0x000167b8, 0x00000000},
122 {0x000167bc, 0x00000000},
123 {0x000167c0, 0x000000a0},
124 {0x000167c4, 0x000c0000},
125 {0x000167c8, 0x14021402},
126 {0x000167cc, 0x00001402},
127 {0x000167d0, 0x00000000},
128 {0x000167d4, 0x00000000},
129 {0x00016800, 0x36db2db6},
130 {0x00016804, 0x6db6db40},
131 {0x00016808, 0x73f00000},
132 {0x0001680c, 0x00000000},
133 {0x00016840, 0x7f80fff8},
134 {0x0001684c, 0x76d005b5},
135 {0x00016850, 0x556cf031},
136 {0x00016854, 0x13449440},
137 {0x00016858, 0x0c51c92c},
138 {0x0001685c, 0x3db7fffc},
139 {0x00016860, 0xfffffffc},
140 {0x00016864, 0x000f0278},
141 {0x0001686c, 0x6db60000},
142 {0x00016900, 0x3fffbe01},
143 {0x00016904, 0xfff80000},
144 {0x00016908, 0x00080010},
145 {0x00016944, 0x02084080},
146 {0x00016948, 0x00000000},
147 {0x00016b80, 0x00000000},
148 {0x00016b84, 0x00000000},
149 {0x00016b88, 0x00800700},
150 {0x00016b8c, 0x00800700},
151 {0x00016b90, 0x00800700},
152 {0x00016b94, 0x00000000},
153 {0x00016b98, 0x00000000},
154 {0x00016b9c, 0x00000000},
155 {0x00016ba0, 0x00000001},
156 {0x00016ba4, 0x00000001},
157 {0x00016ba8, 0x00000000},
158 {0x00016bac, 0x00000000},
159 {0x00016bb0, 0x00000000},
160 {0x00016bb4, 0x00000000},
161 {0x00016bb8, 0x00000000},
162 {0x00016bbc, 0x00000000},
163 {0x00016bc0, 0x000000a0},
164 {0x00016bc4, 0x000c0000},
165 {0x00016bc8, 0x14021402},
166 {0x00016bcc, 0x00001402},
167 {0x00016bd0, 0x00000000},
168 {0x00016bd4, 0x00000000},
169};
28 170
29#define ar9580_1p0_mac_postamble ar9300_2p2_mac_postamble 171#define ar9580_1p0_mac_postamble ar9300_2p2_mac_postamble
30 172
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 01a7db061c6a..abe8bd6b972d 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -28,7 +28,6 @@
28#include "debug.h" 28#include "debug.h"
29#include "mci.h" 29#include "mci.h"
30#include "dfs.h" 30#include "dfs.h"
31#include "spectral.h"
32 31
33struct ath_node; 32struct ath_node;
34struct ath_vif; 33struct ath_vif;
@@ -345,7 +344,9 @@ struct ath_chanctx {
345 u64 tsf_val; 344 u64 tsf_val;
346 u32 last_beacon; 345 u32 last_beacon;
347 346
347 int flush_timeout;
348 u16 txpower; 348 u16 txpower;
349 u16 cur_txpower;
349 bool offchannel; 350 bool offchannel;
350 bool stopped; 351 bool stopped;
351 bool active; 352 bool active;
@@ -362,7 +363,7 @@ enum ath_chanctx_event {
362 ATH_CHANCTX_EVENT_BEACON_SENT, 363 ATH_CHANCTX_EVENT_BEACON_SENT,
363 ATH_CHANCTX_EVENT_TSF_TIMER, 364 ATH_CHANCTX_EVENT_TSF_TIMER,
364 ATH_CHANCTX_EVENT_BEACON_RECEIVED, 365 ATH_CHANCTX_EVENT_BEACON_RECEIVED,
365 ATH_CHANCTX_EVENT_ASSOC, 366 ATH_CHANCTX_EVENT_AUTHORIZED,
366 ATH_CHANCTX_EVENT_SWITCH, 367 ATH_CHANCTX_EVENT_SWITCH,
367 ATH_CHANCTX_EVENT_ASSIGN, 368 ATH_CHANCTX_EVENT_ASSIGN,
368 ATH_CHANCTX_EVENT_UNASSIGN, 369 ATH_CHANCTX_EVENT_UNASSIGN,
@@ -380,10 +381,12 @@ enum ath_chanctx_state {
380 381
381struct ath_chanctx_sched { 382struct ath_chanctx_sched {
382 bool beacon_pending; 383 bool beacon_pending;
384 bool beacon_adjust;
383 bool offchannel_pending; 385 bool offchannel_pending;
384 bool wait_switch; 386 bool wait_switch;
385 bool force_noa_update; 387 bool force_noa_update;
386 bool extend_absence; 388 bool extend_absence;
389 bool mgd_prepare_tx;
387 enum ath_chanctx_state state; 390 enum ath_chanctx_state state;
388 u8 beacon_miss; 391 u8 beacon_miss;
389 392
@@ -468,6 +471,7 @@ void ath_chanctx_set_next(struct ath_softc *sc, bool force);
468void ath_offchannel_next(struct ath_softc *sc); 471void ath_offchannel_next(struct ath_softc *sc);
469void ath_scan_complete(struct ath_softc *sc, bool abort); 472void ath_scan_complete(struct ath_softc *sc, bool abort);
470void ath_roc_complete(struct ath_softc *sc, bool abort); 473void ath_roc_complete(struct ath_softc *sc, bool abort);
474struct ath_chanctx* ath_is_go_chanctx_present(struct ath_softc *sc);
471 475
472#else 476#else
473 477
@@ -540,7 +544,6 @@ static inline void ath_chanctx_check_active(struct ath_softc *sc,
540 544
541#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */ 545#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
542 546
543int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan);
544void ath_startrecv(struct ath_softc *sc); 547void ath_startrecv(struct ath_softc *sc);
545bool ath_stoprecv(struct ath_softc *sc); 548bool ath_stoprecv(struct ath_softc *sc);
546u32 ath_calcrxfilter(struct ath_softc *sc); 549u32 ath_calcrxfilter(struct ath_softc *sc);
@@ -595,7 +598,7 @@ struct ath_vif {
595 u16 seq_no; 598 u16 seq_no;
596 599
597 /* BSS info */ 600 /* BSS info */
598 u8 bssid[ETH_ALEN]; 601 u8 bssid[ETH_ALEN] __aligned(2);
599 u16 aid; 602 u16 aid;
600 bool assoc; 603 bool assoc;
601 604
@@ -618,6 +621,7 @@ struct ath_vif {
618 u32 noa_start; 621 u32 noa_start;
619 u32 noa_duration; 622 u32 noa_duration;
620 bool periodic_noa; 623 bool periodic_noa;
624 bool oneshot_noa;
621}; 625};
622 626
623struct ath9k_vif_iter_data { 627struct ath9k_vif_iter_data {
@@ -715,7 +719,8 @@ int ath_update_survey_stats(struct ath_softc *sc);
715void ath_update_survey_nf(struct ath_softc *sc, int channel); 719void ath_update_survey_nf(struct ath_softc *sc, int channel);
716void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type); 720void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
717void ath_ps_full_sleep(unsigned long data); 721void ath_ps_full_sleep(unsigned long data);
718void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop); 722void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop,
723 bool sw_pending, bool timeout_override);
719 724
720/**********/ 725/**********/
721/* BTCOEX */ 726/* BTCOEX */
@@ -927,6 +932,7 @@ void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
927#define ATH9K_PCI_AR9565_2ANT 0x0100 932#define ATH9K_PCI_AR9565_2ANT 0x0100
928#define ATH9K_PCI_NO_PLL_PWRSAVE 0x0200 933#define ATH9K_PCI_NO_PLL_PWRSAVE 0x0200
929#define ATH9K_PCI_KILLER 0x0400 934#define ATH9K_PCI_KILLER 0x0400
935#define ATH9K_PCI_LED_ACT_HI 0x0800
930 936
931/* 937/*
932 * Default cache line size, in bytes. 938 * Default cache line size, in bytes.
@@ -975,6 +981,7 @@ struct ath_softc {
975 struct ath_chanctx_sched sched; 981 struct ath_chanctx_sched sched;
976 struct ath_offchannel offchannel; 982 struct ath_offchannel offchannel;
977 struct ath_chanctx *next_chan; 983 struct ath_chanctx *next_chan;
984 struct completion go_beacon;
978#endif 985#endif
979 986
980 unsigned long driver_data; 987 unsigned long driver_data;
@@ -982,7 +989,6 @@ struct ath_softc {
982 u8 gtt_cnt; 989 u8 gtt_cnt;
983 u32 intrstatus; 990 u32 intrstatus;
984 u16 ps_flags; /* PS_* */ 991 u16 ps_flags; /* PS_* */
985 u16 curtxpow;
986 bool ps_enabled; 992 bool ps_enabled;
987 bool ps_idle; 993 bool ps_idle;
988 short nbcnvifs; 994 short nbcnvifs;
@@ -1023,10 +1029,8 @@ struct ath_softc {
1023 struct dfs_pattern_detector *dfs_detector; 1029 struct dfs_pattern_detector *dfs_detector;
1024 u64 dfs_prev_pulse_ts; 1030 u64 dfs_prev_pulse_ts;
1025 u32 wow_enabled; 1031 u32 wow_enabled;
1026 /* relay(fs) channel for spectral scan */ 1032
1027 struct rchan *rfs_chan_spec_scan; 1033 struct ath_spec_scan_priv spec_priv;
1028 enum spectral_mode spectral_mode;
1029 struct ath_spec_scan spec_config;
1030 1034
1031 struct ieee80211_vif *tx99_vif; 1035 struct ieee80211_vif *tx99_vif;
1032 struct sk_buff *tx99_skb; 1036 struct sk_buff *tx99_skb;
@@ -1069,7 +1073,7 @@ void ath9k_tasklet(unsigned long data);
1069int ath_cabq_update(struct ath_softc *); 1073int ath_cabq_update(struct ath_softc *);
1070u8 ath9k_parse_mpdudensity(u8 mpdudensity); 1074u8 ath9k_parse_mpdudensity(u8 mpdudensity);
1071irqreturn_t ath_isr(int irq, void *dev); 1075irqreturn_t ath_isr(int irq, void *dev);
1072int ath_reset(struct ath_softc *sc); 1076int ath_reset(struct ath_softc *sc, struct ath9k_channel *hchan);
1073void ath_cancel_work(struct ath_softc *sc); 1077void ath_cancel_work(struct ath_softc *sc);
1074void ath_restart_work(struct ath_softc *sc); 1078void ath_restart_work(struct ath_softc *sc);
1075int ath9k_init_device(u16 devid, struct ath_softc *sc, 1079int ath9k_init_device(u16 devid, struct ath_softc *sc,
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 278365b8a895..e200a6e3aca5 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -234,7 +234,7 @@ void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update)
234 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); 234 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
235} 235}
236 236
237void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan) 237int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
238{ 238{
239 struct ath9k_nfcal_hist *h = NULL; 239 struct ath9k_nfcal_hist *h = NULL;
240 unsigned i, j; 240 unsigned i, j;
@@ -301,7 +301,7 @@ void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
301 ath_dbg(common, ANY, 301 ath_dbg(common, ANY,
302 "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n", 302 "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n",
303 REG_READ(ah, AR_PHY_AGC_CONTROL)); 303 REG_READ(ah, AR_PHY_AGC_CONTROL));
304 return; 304 return -ETIMEDOUT;
305 } 305 }
306 306
307 /* 307 /*
@@ -322,6 +322,8 @@ void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
322 } 322 }
323 } 323 }
324 REGWRITE_BUFFER_FLUSH(ah); 324 REGWRITE_BUFFER_FLUSH(ah);
325
326 return 0;
325} 327}
326 328
327 329
diff --git a/drivers/net/wireless/ath/ath9k/calib.h b/drivers/net/wireless/ath/ath9k/calib.h
index b8ed95e9a335..87badf4bb8a4 100644
--- a/drivers/net/wireless/ath/ath9k/calib.h
+++ b/drivers/net/wireless/ath/ath9k/calib.h
@@ -109,7 +109,7 @@ struct ath9k_pacal_info{
109 109
110bool ath9k_hw_reset_calvalid(struct ath_hw *ah); 110bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
111void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update); 111void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
112void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan); 112int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
113bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan); 113bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
114void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah, 114void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
115 struct ath9k_channel *chan); 115 struct ath9k_channel *chan);
diff --git a/drivers/net/wireless/ath/ath9k/channel.c b/drivers/net/wireless/ath/ath9k/channel.c
index 945c89826b14..794d52016437 100644
--- a/drivers/net/wireless/ath/ath9k/channel.c
+++ b/drivers/net/wireless/ath/ath9k/channel.c
@@ -66,7 +66,7 @@ static int ath_set_channel(struct ath_softc *sc)
66 } 66 }
67 67
68 hchan = &sc->sc_ah->channels[pos]; 68 hchan = &sc->sc_ah->channels[pos];
69 r = ath_reset_internal(sc, hchan); 69 r = ath_reset(sc, hchan);
70 if (r) 70 if (r)
71 return r; 71 return r;
72 72
@@ -92,8 +92,8 @@ static int ath_set_channel(struct ath_softc *sc)
92 } else { 92 } else {
93 /* perform spectral scan if requested. */ 93 /* perform spectral scan if requested. */
94 if (test_bit(ATH_OP_SCANNING, &common->op_flags) && 94 if (test_bit(ATH_OP_SCANNING, &common->op_flags) &&
95 sc->spectral_mode == SPECTRAL_CHANSCAN) 95 sc->spec_priv.spectral_mode == SPECTRAL_CHANSCAN)
96 ath9k_spectral_scan_trigger(hw); 96 ath9k_cmn_spectral_scan_trigger(common, &sc->spec_priv);
97 } 97 }
98 98
99 return 0; 99 return 0;
@@ -117,6 +117,7 @@ void ath_chanctx_init(struct ath_softc *sc)
117 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20); 117 cfg80211_chandef_create(&ctx->chandef, chan, NL80211_CHAN_HT20);
118 INIT_LIST_HEAD(&ctx->vifs); 118 INIT_LIST_HEAD(&ctx->vifs);
119 ctx->txpower = ATH_TXPOWER_MAX; 119 ctx->txpower = ATH_TXPOWER_MAX;
120 ctx->flush_timeout = HZ / 5; /* 200ms */
120 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++) 121 for (j = 0; j < ARRAY_SIZE(ctx->acq); j++)
121 INIT_LIST_HEAD(&ctx->acq[j]); 122 INIT_LIST_HEAD(&ctx->acq[j]);
122 } 123 }
@@ -145,6 +146,36 @@ void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
145 146
146#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT 147#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
147 148
149/*************/
150/* Utilities */
151/*************/
152
153struct ath_chanctx* ath_is_go_chanctx_present(struct ath_softc *sc)
154{
155 struct ath_chanctx *ctx;
156 struct ath_vif *avp;
157 struct ieee80211_vif *vif;
158
159 spin_lock_bh(&sc->chan_lock);
160
161 ath_for_each_chanctx(sc, ctx) {
162 if (!ctx->active)
163 continue;
164
165 list_for_each_entry(avp, &ctx->vifs, list) {
166 vif = avp->vif;
167
168 if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_P2P_GO) {
169 spin_unlock_bh(&sc->chan_lock);
170 return ctx;
171 }
172 }
173 }
174
175 spin_unlock_bh(&sc->chan_lock);
176 return NULL;
177}
178
148/**********************************************************/ 179/**********************************************************/
149/* Functions to handle the channel context state machine. */ 180/* Functions to handle the channel context state machine. */
150/**********************************************************/ 181/**********************************************************/
@@ -171,7 +202,7 @@ static const char *chanctx_event_string(enum ath_chanctx_event ev)
171 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_SENT); 202 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_SENT);
172 case_rtn_string(ATH_CHANCTX_EVENT_TSF_TIMER); 203 case_rtn_string(ATH_CHANCTX_EVENT_TSF_TIMER);
173 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_RECEIVED); 204 case_rtn_string(ATH_CHANCTX_EVENT_BEACON_RECEIVED);
174 case_rtn_string(ATH_CHANCTX_EVENT_ASSOC); 205 case_rtn_string(ATH_CHANCTX_EVENT_AUTHORIZED);
175 case_rtn_string(ATH_CHANCTX_EVENT_SWITCH); 206 case_rtn_string(ATH_CHANCTX_EVENT_SWITCH);
176 case_rtn_string(ATH_CHANCTX_EVENT_ASSIGN); 207 case_rtn_string(ATH_CHANCTX_EVENT_ASSIGN);
177 case_rtn_string(ATH_CHANCTX_EVENT_UNASSIGN); 208 case_rtn_string(ATH_CHANCTX_EVENT_UNASSIGN);
@@ -198,6 +229,7 @@ static const char *chanctx_state_string(enum ath_chanctx_state state)
198void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx) 229void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
199{ 230{
200 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 231 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
232 struct ath_chanctx *ictx;
201 struct ath_vif *avp; 233 struct ath_vif *avp;
202 bool active = false; 234 bool active = false;
203 u8 n_active = 0; 235 u8 n_active = 0;
@@ -205,6 +237,28 @@ void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
205 if (!ctx) 237 if (!ctx)
206 return; 238 return;
207 239
240 if (ctx == &sc->offchannel.chan) {
241 spin_lock_bh(&sc->chan_lock);
242
243 if (likely(sc->sched.channel_switch_time))
244 ctx->flush_timeout =
245 usecs_to_jiffies(sc->sched.channel_switch_time);
246 else
247 ctx->flush_timeout =
248 msecs_to_jiffies(10);
249
250 spin_unlock_bh(&sc->chan_lock);
251
252 /*
253 * There is no need to iterate over the
254 * active/assigned channel contexts if
255 * the current context is offchannel.
256 */
257 return;
258 }
259
260 ictx = ctx;
261
208 list_for_each_entry(avp, &ctx->vifs, list) { 262 list_for_each_entry(avp, &ctx->vifs, list) {
209 struct ieee80211_vif *vif = avp->vif; 263 struct ieee80211_vif *vif = avp->vif;
210 264
@@ -227,12 +281,23 @@ void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx)
227 n_active++; 281 n_active++;
228 } 282 }
229 283
284 spin_lock_bh(&sc->chan_lock);
285
230 if (n_active <= 1) { 286 if (n_active <= 1) {
287 ictx->flush_timeout = HZ / 5;
231 clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags); 288 clear_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags);
289 spin_unlock_bh(&sc->chan_lock);
232 return; 290 return;
233 } 291 }
234 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) 292
293 ictx->flush_timeout = usecs_to_jiffies(sc->sched.channel_switch_time);
294
295 if (test_and_set_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) {
296 spin_unlock_bh(&sc->chan_lock);
235 return; 297 return;
298 }
299
300 spin_unlock_bh(&sc->chan_lock);
236 301
237 if (ath9k_is_chanctx_enabled()) { 302 if (ath9k_is_chanctx_enabled()) {
238 ath_chanctx_event(sc, NULL, 303 ath_chanctx_event(sc, NULL,
@@ -301,6 +366,111 @@ static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time)
301 "Setup chanctx timer with timeout: %d ms\n", jiffies_to_msecs(tsf_time)); 366 "Setup chanctx timer with timeout: %d ms\n", jiffies_to_msecs(tsf_time));
302} 367}
303 368
369static void ath_chanctx_handle_bmiss(struct ath_softc *sc,
370 struct ath_chanctx *ctx,
371 struct ath_vif *avp)
372{
373 /*
374 * Clear the extend_absence flag if it had been
375 * set during the previous beacon transmission,
376 * since we need to revert to the normal NoA
377 * schedule.
378 */
379 if (ctx->active && sc->sched.extend_absence) {
380 avp->noa_duration = 0;
381 sc->sched.extend_absence = false;
382 }
383
384 /* If at least two consecutive beacons were missed on the STA
385 * chanctx, stay on the STA channel for one extra beacon period,
386 * to resync the timer properly.
387 */
388 if (ctx->active && sc->sched.beacon_miss >= 2) {
389 avp->noa_duration = 0;
390 sc->sched.extend_absence = true;
391 }
392}
393
394static void ath_chanctx_offchannel_noa(struct ath_softc *sc,
395 struct ath_chanctx *ctx,
396 struct ath_vif *avp,
397 u32 tsf_time)
398{
399 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
400
401 avp->noa_index++;
402 avp->offchannel_start = tsf_time;
403 avp->offchannel_duration = sc->sched.offchannel_duration;
404
405 ath_dbg(common, CHAN_CTX,
406 "offchannel noa_duration: %d, noa_start: %d, noa_index: %d\n",
407 avp->offchannel_duration,
408 avp->offchannel_start,
409 avp->noa_index);
410
411 /*
412 * When multiple contexts are active, the NoA
413 * has to be recalculated and advertised after
414 * an offchannel operation.
415 */
416 if (ctx->active && avp->noa_duration)
417 avp->noa_duration = 0;
418}
419
420static void ath_chanctx_set_periodic_noa(struct ath_softc *sc,
421 struct ath_vif *avp,
422 struct ath_beacon_config *cur_conf,
423 u32 tsf_time,
424 u32 beacon_int)
425{
426 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
427
428 avp->noa_index++;
429 avp->noa_start = tsf_time;
430
431 if (sc->sched.extend_absence)
432 avp->noa_duration = (3 * beacon_int / 2) +
433 sc->sched.channel_switch_time;
434 else
435 avp->noa_duration =
436 TU_TO_USEC(cur_conf->beacon_interval) / 2 +
437 sc->sched.channel_switch_time;
438
439 if (test_bit(ATH_OP_SCANNING, &common->op_flags) ||
440 sc->sched.extend_absence)
441 avp->periodic_noa = false;
442 else
443 avp->periodic_noa = true;
444
445 ath_dbg(common, CHAN_CTX,
446 "noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n",
447 avp->noa_duration,
448 avp->noa_start,
449 avp->noa_index,
450 avp->periodic_noa);
451}
452
453static void ath_chanctx_set_oneshot_noa(struct ath_softc *sc,
454 struct ath_vif *avp,
455 u32 tsf_time,
456 u32 duration)
457{
458 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
459
460 avp->noa_index++;
461 avp->noa_start = tsf_time;
462 avp->periodic_noa = false;
463 avp->oneshot_noa = true;
464 avp->noa_duration = duration + sc->sched.channel_switch_time;
465
466 ath_dbg(common, CHAN_CTX,
467 "oneshot noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n",
468 avp->noa_duration,
469 avp->noa_start,
470 avp->noa_index,
471 avp->periodic_noa);
472}
473
304void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif, 474void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
305 enum ath_chanctx_event ev) 475 enum ath_chanctx_event ev)
306{ 476{
@@ -327,6 +497,14 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
327 if (avp->offchannel_duration) 497 if (avp->offchannel_duration)
328 avp->offchannel_duration = 0; 498 avp->offchannel_duration = 0;
329 499
500 if (avp->oneshot_noa) {
501 avp->noa_duration = 0;
502 avp->oneshot_noa = false;
503
504 ath_dbg(common, CHAN_CTX,
505 "Clearing oneshot NoA\n");
506 }
507
330 if (avp->chanctx != sc->cur_chan) { 508 if (avp->chanctx != sc->cur_chan) {
331 ath_dbg(common, CHAN_CTX, 509 ath_dbg(common, CHAN_CTX,
332 "Contexts differ, not preparing beacon\n"); 510 "Contexts differ, not preparing beacon\n");
@@ -356,6 +534,24 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
356 "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n"); 534 "Move chanctx state from WAIT_FOR_TIMER to WAIT_FOR_BEACON\n");
357 } 535 }
358 536
537 if (sc->sched.mgd_prepare_tx)
538 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON;
539
540 /*
541 * When a context becomes inactive, for example,
542 * disassociation of a station context, the NoA
543 * attribute needs to be removed from subsequent
544 * beacons.
545 */
546 if (!ctx->active && avp->noa_duration &&
547 sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) {
548 avp->noa_duration = 0;
549 avp->periodic_noa = false;
550
551 ath_dbg(common, CHAN_CTX,
552 "Clearing NoA schedule\n");
553 }
554
359 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) 555 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
360 break; 556 break;
361 557
@@ -378,45 +574,22 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
378 * values and increment the index. 574 * values and increment the index.
379 */ 575 */
380 if (sc->next_chan == &sc->offchannel.chan) { 576 if (sc->next_chan == &sc->offchannel.chan) {
381 avp->noa_index++; 577 ath_chanctx_offchannel_noa(sc, ctx, avp, tsf_time);
382 avp->offchannel_start = tsf_time;
383 avp->offchannel_duration = sc->sched.offchannel_duration;
384
385 ath_dbg(common, CHAN_CTX,
386 "offchannel noa_duration: %d, noa_start: %d, noa_index: %d\n",
387 avp->offchannel_duration,
388 avp->offchannel_start,
389 avp->noa_index);
390
391 /*
392 * When multiple contexts are active, the NoA
393 * has to be recalculated and advertised after
394 * an offchannel operation.
395 */
396 if (ctx->active && avp->noa_duration)
397 avp->noa_duration = 0;
398
399 break; 578 break;
400 } 579 }
401 580
402 /* 581 ath_chanctx_handle_bmiss(sc, ctx, avp);
403 * Clear the extend_absence flag if it had been
404 * set during the previous beacon transmission,
405 * since we need to revert to the normal NoA
406 * schedule.
407 */
408 if (ctx->active && sc->sched.extend_absence) {
409 avp->noa_duration = 0;
410 sc->sched.extend_absence = false;
411 }
412 582
413 /* If at least two consecutive beacons were missed on the STA 583 /*
414 * chanctx, stay on the STA channel for one extra beacon period, 584 * If a mgd_prepare_tx() has been called by mac80211,
415 * to resync the timer properly. 585 * a one-shot NoA needs to be sent. This can happen
586 * with one or more active channel contexts - in both
587 * cases, a new NoA schedule has to be advertised.
416 */ 588 */
417 if (ctx->active && sc->sched.beacon_miss >= 2) { 589 if (sc->sched.mgd_prepare_tx) {
418 avp->noa_duration = 0; 590 ath_chanctx_set_oneshot_noa(sc, avp, tsf_time,
419 sc->sched.extend_absence = true; 591 jiffies_to_usecs(HZ / 5));
592 break;
420 } 593 }
421 594
422 /* Prevent wrap-around issues */ 595 /* Prevent wrap-around issues */
@@ -429,31 +602,9 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
429 * announcement. 602 * announcement.
430 */ 603 */
431 if (ctx->active && 604 if (ctx->active &&
432 (!avp->noa_duration || sc->sched.force_noa_update)) { 605 (!avp->noa_duration || sc->sched.force_noa_update))
433 avp->noa_index++; 606 ath_chanctx_set_periodic_noa(sc, avp, cur_conf,
434 avp->noa_start = tsf_time; 607 tsf_time, beacon_int);
435
436 if (sc->sched.extend_absence)
437 avp->noa_duration = (3 * beacon_int / 2) +
438 sc->sched.channel_switch_time;
439 else
440 avp->noa_duration =
441 TU_TO_USEC(cur_conf->beacon_interval) / 2 +
442 sc->sched.channel_switch_time;
443
444 if (test_bit(ATH_OP_SCANNING, &common->op_flags) ||
445 sc->sched.extend_absence)
446 avp->periodic_noa = false;
447 else
448 avp->periodic_noa = true;
449
450 ath_dbg(common, CHAN_CTX,
451 "noa_duration: %d, noa_start: %d, noa_index: %d, periodic: %d\n",
452 avp->noa_duration,
453 avp->noa_start,
454 avp->noa_index,
455 avp->periodic_noa);
456 }
457 608
458 if (ctx->active && sc->sched.force_noa_update) 609 if (ctx->active && sc->sched.force_noa_update)
459 sc->sched.force_noa_update = false; 610 sc->sched.force_noa_update = false;
@@ -467,6 +618,15 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
467 } 618 }
468 619
469 sc->sched.beacon_pending = false; 620 sc->sched.beacon_pending = false;
621
622 if (sc->sched.mgd_prepare_tx) {
623 sc->sched.mgd_prepare_tx = false;
624 complete(&sc->go_beacon);
625 ath_dbg(common, CHAN_CTX,
626 "Beacon sent, complete go_beacon\n");
627 break;
628 }
629
470 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) 630 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON)
471 break; 631 break;
472 632
@@ -495,10 +655,16 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
495 sc->cur_chan == &sc->offchannel.chan) 655 sc->cur_chan == &sc->offchannel.chan)
496 break; 656 break;
497 657
498 ath_chanctx_adjust_tbtt_delta(sc);
499 sc->sched.beacon_pending = false; 658 sc->sched.beacon_pending = false;
500 sc->sched.beacon_miss = 0; 659 sc->sched.beacon_miss = 0;
501 660
661 if (sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE ||
662 !sc->sched.beacon_adjust ||
663 !sc->cur_chan->tsf_val)
664 break;
665
666 ath_chanctx_adjust_tbtt_delta(sc);
667
502 /* TSF time might have been updated by the incoming beacon, 668 /* TSF time might have been updated by the incoming beacon,
503 * need update the channel switch timer to reflect the change. 669 * need update the channel switch timer to reflect the change.
504 */ 670 */
@@ -507,10 +673,10 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
507 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL); 673 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL);
508 tsf_time += ath9k_hw_gettsf32(ah); 674 tsf_time += ath9k_hw_gettsf32(ah);
509 675
510 676 sc->sched.beacon_adjust = false;
511 ath_chanctx_setup_timer(sc, tsf_time); 677 ath_chanctx_setup_timer(sc, tsf_time);
512 break; 678 break;
513 case ATH_CHANCTX_EVENT_ASSOC: 679 case ATH_CHANCTX_EVENT_AUTHORIZED:
514 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE || 680 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE ||
515 avp->chanctx != sc->cur_chan) 681 avp->chanctx != sc->cur_chan)
516 break; 682 break;
@@ -552,6 +718,7 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
552 718
553 ath_chanctx_setup_timer(sc, tsf_time); 719 ath_chanctx_setup_timer(sc, tsf_time);
554 sc->sched.beacon_pending = true; 720 sc->sched.beacon_pending = true;
721 sc->sched.beacon_adjust = true;
555 break; 722 break;
556 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL: 723 case ATH_CHANCTX_EVENT_ENABLE_MULTICHANNEL:
557 if (sc->cur_chan == &sc->offchannel.chan || 724 if (sc->cur_chan == &sc->offchannel.chan ||
@@ -578,22 +745,6 @@ void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif,
578 ieee80211_queue_work(sc->hw, &sc->chanctx_work); 745 ieee80211_queue_work(sc->hw, &sc->chanctx_work);
579 break; 746 break;
580 case ATH_CHANCTX_EVENT_ASSIGN: 747 case ATH_CHANCTX_EVENT_ASSIGN:
581 /*
582 * When adding a new channel context, check if a scan
583 * is in progress and abort it since the addition of
584 * a new channel context is usually followed by VIF
585 * assignment, in which case we have to start multi-channel
586 * operation.
587 */
588 if (test_bit(ATH_OP_SCANNING, &common->op_flags)) {
589 ath_dbg(common, CHAN_CTX,
590 "Aborting HW scan to add new context\n");
591
592 spin_unlock_bh(&sc->chan_lock);
593 del_timer_sync(&sc->offchannel.timer);
594 ath_scan_complete(sc, true);
595 spin_lock_bh(&sc->chan_lock);
596 }
597 break; 748 break;
598 case ATH_CHANCTX_EVENT_CHANGE: 749 case ATH_CHANCTX_EVENT_CHANGE:
599 break; 750 break;
@@ -751,6 +902,11 @@ void ath_offchannel_next(struct ath_softc *sc)
751 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START; 902 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
752 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan); 903 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
753 } else { 904 } else {
905 spin_lock_bh(&sc->chan_lock);
906 sc->sched.offchannel_pending = false;
907 sc->sched.wait_switch = false;
908 spin_unlock_bh(&sc->chan_lock);
909
754 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), 910 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
755 NULL); 911 NULL);
756 sc->offchannel.state = ATH_OFFCHANNEL_IDLE; 912 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
@@ -770,8 +926,7 @@ void ath_roc_complete(struct ath_softc *sc, bool abort)
770 926
771 sc->offchannel.roc_vif = NULL; 927 sc->offchannel.roc_vif = NULL;
772 sc->offchannel.roc_chan = NULL; 928 sc->offchannel.roc_chan = NULL;
773 if (!abort) 929 ieee80211_remain_on_channel_expired(sc->hw);
774 ieee80211_remain_on_channel_expired(sc->hw);
775 ath_offchannel_next(sc); 930 ath_offchannel_next(sc);
776 ath9k_ps_restore(sc); 931 ath9k_ps_restore(sc);
777} 932}
@@ -902,9 +1057,8 @@ static void ath_offchannel_timer(unsigned long data)
902 break; 1057 break;
903 case ATH_OFFCHANNEL_ROC_START: 1058 case ATH_OFFCHANNEL_ROC_START:
904 case ATH_OFFCHANNEL_ROC_WAIT: 1059 case ATH_OFFCHANNEL_ROC_WAIT:
905 ctx = ath_chanctx_get_oper_chan(sc, false);
906 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE; 1060 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
907 ath_chanctx_switch(sc, ctx, NULL); 1061 ath_roc_complete(sc, false);
908 break; 1062 break;
909 default: 1063 default:
910 break; 1064 break;
@@ -1034,7 +1188,6 @@ static void ath_offchannel_channel_change(struct ath_softc *sc)
1034 ieee80211_ready_on_channel(sc->hw); 1188 ieee80211_ready_on_channel(sc->hw);
1035 break; 1189 break;
1036 case ATH_OFFCHANNEL_ROC_DONE: 1190 case ATH_OFFCHANNEL_ROC_DONE:
1037 ath_roc_complete(sc, false);
1038 break; 1191 break;
1039 default: 1192 default:
1040 break; 1193 break;
@@ -1082,10 +1235,11 @@ void ath_chanctx_set_next(struct ath_softc *sc, bool force)
1082 ath9k_chanctx_stop_queues(sc, sc->cur_chan); 1235 ath9k_chanctx_stop_queues(sc, sc->cur_chan);
1083 queues_stopped = true; 1236 queues_stopped = true;
1084 1237
1085 __ath9k_flush(sc->hw, ~0, true); 1238 __ath9k_flush(sc->hw, ~0, true, false, false);
1086 1239
1087 if (ath_chanctx_send_ps_frame(sc, true)) 1240 if (ath_chanctx_send_ps_frame(sc, true))
1088 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), false); 1241 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO),
1242 false, false, false);
1089 1243
1090 send_ps = true; 1244 send_ps = true;
1091 spin_lock_bh(&sc->chan_lock); 1245 spin_lock_bh(&sc->chan_lock);
@@ -1177,6 +1331,8 @@ void ath9k_init_channel_context(struct ath_softc *sc)
1177 (unsigned long)sc); 1331 (unsigned long)sc);
1178 setup_timer(&sc->sched.timer, ath_chanctx_timer, 1332 setup_timer(&sc->sched.timer, ath_chanctx_timer,
1179 (unsigned long)sc); 1333 (unsigned long)sc);
1334
1335 init_completion(&sc->go_beacon);
1180} 1336}
1181 1337
1182void ath9k_deinit_channel_context(struct ath_softc *sc) 1338void ath9k_deinit_channel_context(struct ath_softc *sc)
diff --git a/drivers/net/wireless/ath/ath9k/spectral.c b/drivers/net/wireless/ath/ath9k/common-spectral.c
index 8f68426ca653..ec93ddf0863a 100644
--- a/drivers/net/wireless/ath/ath9k/spectral.c
+++ b/drivers/net/wireless/ath/ath9k/common-spectral.c
@@ -24,23 +24,24 @@ static s8 fix_rssi_inv_only(u8 rssi_val)
24 return (s8) rssi_val; 24 return (s8) rssi_val;
25} 25}
26 26
27static void ath_debug_send_fft_sample(struct ath_softc *sc, 27static void ath_debug_send_fft_sample(struct ath_spec_scan_priv *spec_priv,
28 struct fft_sample_tlv *fft_sample_tlv) 28 struct fft_sample_tlv *fft_sample_tlv)
29{ 29{
30 int length; 30 int length;
31 if (!sc->rfs_chan_spec_scan) 31 if (!spec_priv->rfs_chan_spec_scan)
32 return; 32 return;
33 33
34 length = __be16_to_cpu(fft_sample_tlv->length) + 34 length = __be16_to_cpu(fft_sample_tlv->length) +
35 sizeof(*fft_sample_tlv); 35 sizeof(*fft_sample_tlv);
36 relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length); 36 relay_write(spec_priv->rfs_chan_spec_scan, fft_sample_tlv, length);
37} 37}
38 38
39/* returns 1 if this was a spectral frame, even if not handled. */ 39/* returns 1 if this was a spectral frame, even if not handled. */
40int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr, 40int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
41 struct ath_rx_status *rs, u64 tsf) 41 struct ath_rx_status *rs, u64 tsf)
42{ 42{
43 struct ath_hw *ah = sc->sc_ah; 43 struct ath_hw *ah = spec_priv->ah;
44 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
44 u8 num_bins, *bins, *vdata = (u8 *)hdr; 45 u8 num_bins, *bins, *vdata = (u8 *)hdr;
45 struct fft_sample_ht20 fft_sample_20; 46 struct fft_sample_ht20 fft_sample_20;
46 struct fft_sample_ht20_40 fft_sample_40; 47 struct fft_sample_ht20_40 fft_sample_40;
@@ -67,7 +68,7 @@ int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
67 if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK)) 68 if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK))
68 return 0; 69 return 0;
69 70
70 chan_type = cfg80211_get_chandef_type(&sc->hw->conf.chandef); 71 chan_type = cfg80211_get_chandef_type(&common->hw->conf.chandef);
71 if ((chan_type == NL80211_CHAN_HT40MINUS) || 72 if ((chan_type == NL80211_CHAN_HT40MINUS) ||
72 (chan_type == NL80211_CHAN_HT40PLUS)) { 73 (chan_type == NL80211_CHAN_HT40PLUS)) {
73 fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN; 74 fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN;
@@ -199,10 +200,11 @@ int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
199 tlv = (struct fft_sample_tlv *)&fft_sample_20; 200 tlv = (struct fft_sample_tlv *)&fft_sample_20;
200 } 201 }
201 202
202 ath_debug_send_fft_sample(sc, tlv); 203 ath_debug_send_fft_sample(spec_priv, tlv);
203 204
204 return 1; 205 return 1;
205} 206}
207EXPORT_SYMBOL(ath_cmn_process_fft);
206 208
207/*********************/ 209/*********************/
208/* spectral_scan_ctl */ 210/* spectral_scan_ctl */
@@ -211,11 +213,11 @@ int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
211static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf, 213static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
212 size_t count, loff_t *ppos) 214 size_t count, loff_t *ppos)
213{ 215{
214 struct ath_softc *sc = file->private_data; 216 struct ath_spec_scan_priv *spec_priv = file->private_data;
215 char *mode = ""; 217 char *mode = "";
216 unsigned int len; 218 unsigned int len;
217 219
218 switch (sc->spectral_mode) { 220 switch (spec_priv->spectral_mode) {
219 case SPECTRAL_DISABLED: 221 case SPECTRAL_DISABLED:
220 mode = "disable"; 222 mode = "disable";
221 break; 223 break;
@@ -233,12 +235,84 @@ static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
233 return simple_read_from_buffer(user_buf, count, ppos, mode, len); 235 return simple_read_from_buffer(user_buf, count, ppos, mode, len);
234} 236}
235 237
238void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
239 struct ath_spec_scan_priv *spec_priv)
240{
241 struct ath_hw *ah = spec_priv->ah;
242 u32 rxfilter;
243
244 if (config_enabled(CONFIG_ATH9K_TX99))
245 return;
246
247 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
248 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
249 return;
250 }
251
252 ath_ps_ops(common)->wakeup(common);
253 rxfilter = ath9k_hw_getrxfilter(ah);
254 ath9k_hw_setrxfilter(ah, rxfilter |
255 ATH9K_RX_FILTER_PHYRADAR |
256 ATH9K_RX_FILTER_PHYERR);
257
258 /* TODO: usually this should not be neccesary, but for some reason
259 * (or in some mode?) the trigger must be called after the
260 * configuration, otherwise the register will have its values reset
261 * (on my ar9220 to value 0x01002310)
262 */
263 ath9k_cmn_spectral_scan_config(common, spec_priv, spec_priv->spectral_mode);
264 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
265 ath_ps_ops(common)->restore(common);
266}
267EXPORT_SYMBOL(ath9k_cmn_spectral_scan_trigger);
268
269int ath9k_cmn_spectral_scan_config(struct ath_common *common,
270 struct ath_spec_scan_priv *spec_priv,
271 enum spectral_mode spectral_mode)
272{
273 struct ath_hw *ah = spec_priv->ah;
274
275 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
276 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
277 return -1;
278 }
279
280 switch (spectral_mode) {
281 case SPECTRAL_DISABLED:
282 spec_priv->spec_config.enabled = 0;
283 break;
284 case SPECTRAL_BACKGROUND:
285 /* send endless samples.
286 * TODO: is this really useful for "background"?
287 */
288 spec_priv->spec_config.endless = 1;
289 spec_priv->spec_config.enabled = 1;
290 break;
291 case SPECTRAL_CHANSCAN:
292 case SPECTRAL_MANUAL:
293 spec_priv->spec_config.endless = 0;
294 spec_priv->spec_config.enabled = 1;
295 break;
296 default:
297 return -1;
298 }
299
300 ath_ps_ops(common)->wakeup(common);
301 ath9k_hw_ops(ah)->spectral_scan_config(ah, &spec_priv->spec_config);
302 ath_ps_ops(common)->restore(common);
303
304 spec_priv->spectral_mode = spectral_mode;
305
306 return 0;
307}
308EXPORT_SYMBOL(ath9k_cmn_spectral_scan_config);
309
236static ssize_t write_file_spec_scan_ctl(struct file *file, 310static ssize_t write_file_spec_scan_ctl(struct file *file,
237 const char __user *user_buf, 311 const char __user *user_buf,
238 size_t count, loff_t *ppos) 312 size_t count, loff_t *ppos)
239{ 313{
240 struct ath_softc *sc = file->private_data; 314 struct ath_spec_scan_priv *spec_priv = file->private_data;
241 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 315 struct ath_common *common = ath9k_hw_common(spec_priv->ah);
242 char buf[32]; 316 char buf[32];
243 ssize_t len; 317 ssize_t len;
244 318
@@ -252,18 +326,18 @@ static ssize_t write_file_spec_scan_ctl(struct file *file,
252 buf[len] = '\0'; 326 buf[len] = '\0';
253 327
254 if (strncmp("trigger", buf, 7) == 0) { 328 if (strncmp("trigger", buf, 7) == 0) {
255 ath9k_spectral_scan_trigger(sc->hw); 329 ath9k_cmn_spectral_scan_trigger(common, spec_priv);
256 } else if (strncmp("background", buf, 10) == 0) { 330 } else if (strncmp("background", buf, 10) == 0) {
257 ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND); 331 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_BACKGROUND);
258 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n"); 332 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
259 } else if (strncmp("chanscan", buf, 8) == 0) { 333 } else if (strncmp("chanscan", buf, 8) == 0) {
260 ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN); 334 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_CHANSCAN);
261 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n"); 335 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
262 } else if (strncmp("manual", buf, 6) == 0) { 336 } else if (strncmp("manual", buf, 6) == 0) {
263 ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL); 337 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_MANUAL);
264 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n"); 338 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
265 } else if (strncmp("disable", buf, 7) == 0) { 339 } else if (strncmp("disable", buf, 7) == 0) {
266 ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED); 340 ath9k_cmn_spectral_scan_config(common, spec_priv, SPECTRAL_DISABLED);
267 ath_dbg(common, CONFIG, "spectral scan: disabled\n"); 341 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
268 } else { 342 } else {
269 return -EINVAL; 343 return -EINVAL;
@@ -288,11 +362,11 @@ static ssize_t read_file_spectral_short_repeat(struct file *file,
288 char __user *user_buf, 362 char __user *user_buf,
289 size_t count, loff_t *ppos) 363 size_t count, loff_t *ppos)
290{ 364{
291 struct ath_softc *sc = file->private_data; 365 struct ath_spec_scan_priv *spec_priv = file->private_data;
292 char buf[32]; 366 char buf[32];
293 unsigned int len; 367 unsigned int len;
294 368
295 len = sprintf(buf, "%d\n", sc->spec_config.short_repeat); 369 len = sprintf(buf, "%d\n", spec_priv->spec_config.short_repeat);
296 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 370 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
297} 371}
298 372
@@ -300,7 +374,7 @@ static ssize_t write_file_spectral_short_repeat(struct file *file,
300 const char __user *user_buf, 374 const char __user *user_buf,
301 size_t count, loff_t *ppos) 375 size_t count, loff_t *ppos)
302{ 376{
303 struct ath_softc *sc = file->private_data; 377 struct ath_spec_scan_priv *spec_priv = file->private_data;
304 unsigned long val; 378 unsigned long val;
305 char buf[32]; 379 char buf[32];
306 ssize_t len; 380 ssize_t len;
@@ -316,7 +390,7 @@ static ssize_t write_file_spectral_short_repeat(struct file *file,
316 if (val > 1) 390 if (val > 1)
317 return -EINVAL; 391 return -EINVAL;
318 392
319 sc->spec_config.short_repeat = val; 393 spec_priv->spec_config.short_repeat = val;
320 return count; 394 return count;
321} 395}
322 396
@@ -336,11 +410,11 @@ static ssize_t read_file_spectral_count(struct file *file,
336 char __user *user_buf, 410 char __user *user_buf,
337 size_t count, loff_t *ppos) 411 size_t count, loff_t *ppos)
338{ 412{
339 struct ath_softc *sc = file->private_data; 413 struct ath_spec_scan_priv *spec_priv = file->private_data;
340 char buf[32]; 414 char buf[32];
341 unsigned int len; 415 unsigned int len;
342 416
343 len = sprintf(buf, "%d\n", sc->spec_config.count); 417 len = sprintf(buf, "%d\n", spec_priv->spec_config.count);
344 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 418 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
345} 419}
346 420
@@ -348,7 +422,7 @@ static ssize_t write_file_spectral_count(struct file *file,
348 const char __user *user_buf, 422 const char __user *user_buf,
349 size_t count, loff_t *ppos) 423 size_t count, loff_t *ppos)
350{ 424{
351 struct ath_softc *sc = file->private_data; 425 struct ath_spec_scan_priv *spec_priv = file->private_data;
352 unsigned long val; 426 unsigned long val;
353 char buf[32]; 427 char buf[32];
354 ssize_t len; 428 ssize_t len;
@@ -364,7 +438,7 @@ static ssize_t write_file_spectral_count(struct file *file,
364 if (val > 255) 438 if (val > 255)
365 return -EINVAL; 439 return -EINVAL;
366 440
367 sc->spec_config.count = val; 441 spec_priv->spec_config.count = val;
368 return count; 442 return count;
369} 443}
370 444
@@ -384,11 +458,11 @@ static ssize_t read_file_spectral_period(struct file *file,
384 char __user *user_buf, 458 char __user *user_buf,
385 size_t count, loff_t *ppos) 459 size_t count, loff_t *ppos)
386{ 460{
387 struct ath_softc *sc = file->private_data; 461 struct ath_spec_scan_priv *spec_priv = file->private_data;
388 char buf[32]; 462 char buf[32];
389 unsigned int len; 463 unsigned int len;
390 464
391 len = sprintf(buf, "%d\n", sc->spec_config.period); 465 len = sprintf(buf, "%d\n", spec_priv->spec_config.period);
392 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 466 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
393} 467}
394 468
@@ -396,7 +470,7 @@ static ssize_t write_file_spectral_period(struct file *file,
396 const char __user *user_buf, 470 const char __user *user_buf,
397 size_t count, loff_t *ppos) 471 size_t count, loff_t *ppos)
398{ 472{
399 struct ath_softc *sc = file->private_data; 473 struct ath_spec_scan_priv *spec_priv = file->private_data;
400 unsigned long val; 474 unsigned long val;
401 char buf[32]; 475 char buf[32];
402 ssize_t len; 476 ssize_t len;
@@ -412,7 +486,7 @@ static ssize_t write_file_spectral_period(struct file *file,
412 if (val > 255) 486 if (val > 255)
413 return -EINVAL; 487 return -EINVAL;
414 488
415 sc->spec_config.period = val; 489 spec_priv->spec_config.period = val;
416 return count; 490 return count;
417} 491}
418 492
@@ -432,11 +506,11 @@ static ssize_t read_file_spectral_fft_period(struct file *file,
432 char __user *user_buf, 506 char __user *user_buf,
433 size_t count, loff_t *ppos) 507 size_t count, loff_t *ppos)
434{ 508{
435 struct ath_softc *sc = file->private_data; 509 struct ath_spec_scan_priv *spec_priv = file->private_data;
436 char buf[32]; 510 char buf[32];
437 unsigned int len; 511 unsigned int len;
438 512
439 len = sprintf(buf, "%d\n", sc->spec_config.fft_period); 513 len = sprintf(buf, "%d\n", spec_priv->spec_config.fft_period);
440 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 514 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
441} 515}
442 516
@@ -444,7 +518,7 @@ static ssize_t write_file_spectral_fft_period(struct file *file,
444 const char __user *user_buf, 518 const char __user *user_buf,
445 size_t count, loff_t *ppos) 519 size_t count, loff_t *ppos)
446{ 520{
447 struct ath_softc *sc = file->private_data; 521 struct ath_spec_scan_priv *spec_priv = file->private_data;
448 unsigned long val; 522 unsigned long val;
449 char buf[32]; 523 char buf[32];
450 ssize_t len; 524 ssize_t len;
@@ -460,7 +534,7 @@ static ssize_t write_file_spectral_fft_period(struct file *file,
460 if (val > 15) 534 if (val > 15)
461 return -EINVAL; 535 return -EINVAL;
462 536
463 sc->spec_config.fft_period = val; 537 spec_priv->spec_config.fft_period = val;
464 return count; 538 return count;
465} 539}
466 540
@@ -506,38 +580,41 @@ static struct rchan_callbacks rfs_spec_scan_cb = {
506/* Debug Init/Deinit */ 580/* Debug Init/Deinit */
507/*********************/ 581/*********************/
508 582
509void ath9k_spectral_deinit_debug(struct ath_softc *sc) 583void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
510{ 584{
511 if (config_enabled(CONFIG_ATH9K_DEBUGFS) && sc->rfs_chan_spec_scan) { 585 if (config_enabled(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) {
512 relay_close(sc->rfs_chan_spec_scan); 586 relay_close(spec_priv->rfs_chan_spec_scan);
513 sc->rfs_chan_spec_scan = NULL; 587 spec_priv->rfs_chan_spec_scan = NULL;
514 } 588 }
515} 589}
590EXPORT_SYMBOL(ath9k_cmn_spectral_deinit_debug);
516 591
517void ath9k_spectral_init_debug(struct ath_softc *sc) 592void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv,
593 struct dentry *debugfs_phy)
518{ 594{
519 sc->rfs_chan_spec_scan = relay_open("spectral_scan", 595 spec_priv->rfs_chan_spec_scan = relay_open("spectral_scan",
520 sc->debug.debugfs_phy, 596 debugfs_phy,
521 1024, 256, &rfs_spec_scan_cb, 597 1024, 256, &rfs_spec_scan_cb,
522 NULL); 598 NULL);
523 debugfs_create_file("spectral_scan_ctl", 599 debugfs_create_file("spectral_scan_ctl",
524 S_IRUSR | S_IWUSR, 600 S_IRUSR | S_IWUSR,
525 sc->debug.debugfs_phy, sc, 601 debugfs_phy, spec_priv,
526 &fops_spec_scan_ctl); 602 &fops_spec_scan_ctl);
527 debugfs_create_file("spectral_short_repeat", 603 debugfs_create_file("spectral_short_repeat",
528 S_IRUSR | S_IWUSR, 604 S_IRUSR | S_IWUSR,
529 sc->debug.debugfs_phy, sc, 605 debugfs_phy, spec_priv,
530 &fops_spectral_short_repeat); 606 &fops_spectral_short_repeat);
531 debugfs_create_file("spectral_count", 607 debugfs_create_file("spectral_count",
532 S_IRUSR | S_IWUSR, 608 S_IRUSR | S_IWUSR,
533 sc->debug.debugfs_phy, sc, 609 debugfs_phy, spec_priv,
534 &fops_spectral_count); 610 &fops_spectral_count);
535 debugfs_create_file("spectral_period", 611 debugfs_create_file("spectral_period",
536 S_IRUSR | S_IWUSR, 612 S_IRUSR | S_IWUSR,
537 sc->debug.debugfs_phy, sc, 613 debugfs_phy, spec_priv,
538 &fops_spectral_period); 614 &fops_spectral_period);
539 debugfs_create_file("spectral_fft_period", 615 debugfs_create_file("spectral_fft_period",
540 S_IRUSR | S_IWUSR, 616 S_IRUSR | S_IWUSR,
541 sc->debug.debugfs_phy, sc, 617 debugfs_phy, spec_priv,
542 &fops_spectral_fft_period); 618 &fops_spectral_fft_period);
543} 619}
620EXPORT_SYMBOL(ath9k_cmn_spectral_init_debug);
diff --git a/drivers/net/wireless/ath/ath9k/spectral.h b/drivers/net/wireless/ath/ath9k/common-spectral.h
index 7b410c6858b0..82d9dd29652c 100644
--- a/drivers/net/wireless/ath/ath9k/spectral.h
+++ b/drivers/net/wireless/ath/ath9k/common-spectral.h
@@ -92,6 +92,13 @@ struct ath_ht20_40_fft_packet {
92 struct ath_radar_info radar_info; 92 struct ath_radar_info radar_info;
93} __packed; 93} __packed;
94 94
95struct ath_spec_scan_priv {
96 struct ath_hw *ah;
97 /* relay(fs) channel for spectral scan */
98 struct rchan *rfs_chan_spec_scan;
99 enum spectral_mode spectral_mode;
100 struct ath_spec_scan spec_config;
101};
95 102
96#define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet)) 103#define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet))
97 104
@@ -123,23 +130,15 @@ static inline u8 spectral_bitmap_weight(u8 *bins)
123 return bins[0] & 0x3f; 130 return bins[0] & 0x3f;
124} 131}
125 132
126void ath9k_spectral_init_debug(struct ath_softc *sc); 133void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, struct dentry *debugfs_phy);
127void ath9k_spectral_deinit_debug(struct ath_softc *sc); 134void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv);
128 135
129void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw); 136void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
130int ath9k_spectral_scan_config(struct ieee80211_hw *hw, 137 struct ath_spec_scan_priv *spec_priv);
138int ath9k_cmn_spectral_scan_config(struct ath_common *common,
139 struct ath_spec_scan_priv *spec_priv,
131 enum spectral_mode spectral_mode); 140 enum spectral_mode spectral_mode);
132 141int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
133#ifdef CONFIG_ATH9K_DEBUGFS
134int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
135 struct ath_rx_status *rs, u64 tsf); 142 struct ath_rx_status *rs, u64 tsf);
136#else
137static inline int ath_process_fft(struct ath_softc *sc,
138 struct ieee80211_hdr *hdr,
139 struct ath_rx_status *rs, u64 tsf)
140{
141 return 0;
142}
143#endif /* CONFIG_ATH9K_DEBUGFS */
144 143
145#endif /* SPECTRAL_H */ 144#endif /* SPECTRAL_H */
diff --git a/drivers/net/wireless/ath/ath9k/common.c b/drivers/net/wireless/ath/ath9k/common.c
index 33b0c7aef2ea..e8c699446470 100644
--- a/drivers/net/wireless/ath/ath9k/common.c
+++ b/drivers/net/wireless/ath/ath9k/common.c
@@ -159,7 +159,7 @@ void ath9k_cmn_rx_skb_postprocess(struct ath_common *common,
159 if (test_bit(keyix, common->keymap)) 159 if (test_bit(keyix, common->keymap))
160 rxs->flag |= RX_FLAG_DECRYPTED; 160 rxs->flag |= RX_FLAG_DECRYPTED;
161 } 161 }
162 if (ah->sw_mgmt_crypto && 162 if (ah->sw_mgmt_crypto_rx &&
163 (rxs->flag & RX_FLAG_DECRYPTED) && 163 (rxs->flag & RX_FLAG_DECRYPTED) &&
164 ieee80211_is_mgmt(fc)) 164 ieee80211_is_mgmt(fc))
165 /* Use software decrypt for management frames. */ 165 /* Use software decrypt for management frames. */
diff --git a/drivers/net/wireless/ath/ath9k/common.h b/drivers/net/wireless/ath/ath9k/common.h
index ffc454b18637..2b79a568e803 100644
--- a/drivers/net/wireless/ath/ath9k/common.h
+++ b/drivers/net/wireless/ath/ath9k/common.h
@@ -24,6 +24,7 @@
24#include "common-init.h" 24#include "common-init.h"
25#include "common-beacon.h" 25#include "common-beacon.h"
26#include "common-debug.h" 26#include "common-debug.h"
27#include "common-spectral.h"
27 28
28/* Common header for Atheros 802.11n base driver cores */ 29/* Common header for Atheros 802.11n base driver cores */
29 30
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 5c45e787814e..696e3d5309c6 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -828,13 +828,14 @@ static ssize_t read_file_misc(struct file *file, char __user *user_buf,
828 828
829 i = 0; 829 i = 0;
830 ath_for_each_chanctx(sc, ctx) { 830 ath_for_each_chanctx(sc, ctx) {
831 if (!ctx->assigned || list_empty(&ctx->vifs)) 831 if (list_empty(&ctx->vifs))
832 continue; 832 continue;
833 ath9k_calculate_iter_data(sc, ctx, &iter_data); 833 ath9k_calculate_iter_data(sc, ctx, &iter_data);
834 834
835 len += scnprintf(buf + len, sizeof(buf) - len, 835 len += scnprintf(buf + len, sizeof(buf) - len,
836 "VIF-COUNTS: CTX %i AP: %i STA: %i MESH: %i WDS: %i", 836 "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
837 i++, iter_data.naps, iter_data.nstations, 837 i++, (int)(ctx->assigned), iter_data.naps,
838 iter_data.nstations,
838 iter_data.nmeshes, iter_data.nwds); 839 iter_data.nmeshes, iter_data.nwds);
839 len += scnprintf(buf + len, sizeof(buf) - len, 840 len += scnprintf(buf + len, sizeof(buf) - len,
840 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n", 841 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
@@ -852,36 +853,31 @@ static ssize_t read_file_reset(struct file *file, char __user *user_buf,
852 size_t count, loff_t *ppos) 853 size_t count, loff_t *ppos)
853{ 854{
854 struct ath_softc *sc = file->private_data; 855 struct ath_softc *sc = file->private_data;
856 static const char * const reset_cause[__RESET_TYPE_MAX] = {
857 [RESET_TYPE_BB_HANG] = "Baseband Hang",
858 [RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
859 [RESET_TYPE_FATAL_INT] = "Fatal HW Error",
860 [RESET_TYPE_TX_ERROR] = "TX HW error",
861 [RESET_TYPE_TX_GTT] = "Transmit timeout",
862 [RESET_TYPE_TX_HANG] = "TX Path Hang",
863 [RESET_TYPE_PLL_HANG] = "PLL RX Hang",
864 [RESET_TYPE_MAC_HANG] = "MAC Hang",
865 [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
866 [RESET_TYPE_MCI] = "MCI Reset",
867 [RESET_TYPE_CALIBRATION] = "Calibration error",
868 };
855 char buf[512]; 869 char buf[512];
856 unsigned int len = 0; 870 unsigned int len = 0;
871 int i;
857 872
858 len += scnprintf(buf + len, sizeof(buf) - len, 873 for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
859 "%17s: %2d\n", "Baseband Hang", 874 if (!reset_cause[i])
860 sc->debug.stats.reset[RESET_TYPE_BB_HANG]); 875 continue;
861 len += scnprintf(buf + len, sizeof(buf) - len, 876
862 "%17s: %2d\n", "Baseband Watchdog", 877 len += scnprintf(buf + len, sizeof(buf) - len,
863 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]); 878 "%17s: %2d\n", reset_cause[i],
864 len += scnprintf(buf + len, sizeof(buf) - len, 879 sc->debug.stats.reset[i]);
865 "%17s: %2d\n", "Fatal HW Error", 880 }
866 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
867 len += scnprintf(buf + len, sizeof(buf) - len,
868 "%17s: %2d\n", "TX HW error",
869 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
870 len += scnprintf(buf + len, sizeof(buf) - len,
871 "%17s: %2d\n", "TX Path Hang",
872 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
873 len += scnprintf(buf + len, sizeof(buf) - len,
874 "%17s: %2d\n", "PLL RX Hang",
875 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
876 len += scnprintf(buf + len, sizeof(buf) - len,
877 "%17s: %2d\n", "MAC Hang",
878 sc->debug.stats.reset[RESET_TYPE_MAC_HANG]);
879 len += scnprintf(buf + len, sizeof(buf) - len,
880 "%17s: %2d\n", "Stuck Beacon",
881 sc->debug.stats.reset[RESET_TYPE_BEACON_STUCK]);
882 len += scnprintf(buf + len, sizeof(buf) - len,
883 "%17s: %2d\n", "MCI Reset",
884 sc->debug.stats.reset[RESET_TYPE_MCI]);
885 881
886 if (len > sizeof(buf)) 882 if (len > sizeof(buf))
887 len = sizeof(buf); 883 len = sizeof(buf);
@@ -1315,7 +1311,7 @@ void ath9k_get_et_stats(struct ieee80211_hw *hw,
1315 1311
1316void ath9k_deinit_debug(struct ath_softc *sc) 1312void ath9k_deinit_debug(struct ath_softc *sc)
1317{ 1313{
1318 ath9k_spectral_deinit_debug(sc); 1314 ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
1319} 1315}
1320 1316
1321int ath9k_init_debug(struct ath_hw *ah) 1317int ath9k_init_debug(struct ath_hw *ah)
@@ -1335,7 +1331,7 @@ int ath9k_init_debug(struct ath_hw *ah)
1335 1331
1336 ath9k_dfs_init_debug(sc); 1332 ath9k_dfs_init_debug(sc);
1337 ath9k_tx99_init_debug(sc); 1333 ath9k_tx99_init_debug(sc);
1338 ath9k_spectral_init_debug(sc); 1334 ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
1339 1335
1340 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc, 1336 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1341 &fops_dma); 1337 &fops_dma);
diff --git a/drivers/net/wireless/ath/ath9k/debug.h b/drivers/net/wireless/ath/ath9k/debug.h
index 53ae15bd0c9d..bd75b1f716db 100644
--- a/drivers/net/wireless/ath/ath9k/debug.h
+++ b/drivers/net/wireless/ath/ath9k/debug.h
@@ -49,6 +49,7 @@ enum ath_reset_type {
49 RESET_TYPE_MAC_HANG, 49 RESET_TYPE_MAC_HANG,
50 RESET_TYPE_BEACON_STUCK, 50 RESET_TYPE_BEACON_STUCK,
51 RESET_TYPE_MCI, 51 RESET_TYPE_MCI,
52 RESET_TYPE_CALIBRATION,
52 __RESET_TYPE_MAX 53 __RESET_TYPE_MAX
53}; 54};
54 55
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_def.c b/drivers/net/wireless/ath/ath9k/eeprom_def.c
index 3218ca994746..122b846b8ec0 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
@@ -262,7 +262,7 @@ static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
262{ 262{
263 struct ar5416_eeprom_def *eep = &ah->eeprom.def; 263 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
264 struct ath_common *common = ath9k_hw_common(ah); 264 struct ath_common *common = ath9k_hw_common(ah);
265 u16 *eepdata, temp, magic, magic2; 265 u16 *eepdata, temp, magic;
266 u32 sum = 0, el; 266 u32 sum = 0, el;
267 bool need_swap = false; 267 bool need_swap = false;
268 int i, addr, size; 268 int i, addr, size;
@@ -272,27 +272,16 @@ static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
272 return false; 272 return false;
273 } 273 }
274 274
275 if (!ath9k_hw_use_flash(ah)) { 275 if (swab16(magic) == AR5416_EEPROM_MAGIC &&
276 ath_dbg(common, EEPROM, "Read Magic = 0x%04X\n", magic); 276 !(ah->ah_flags & AH_NO_EEP_SWAP)) {
277 277 size = sizeof(struct ar5416_eeprom_def);
278 if (magic != AR5416_EEPROM_MAGIC) { 278 need_swap = true;
279 magic2 = swab16(magic); 279 eepdata = (u16 *) (&ah->eeprom);
280
281 if (magic2 == AR5416_EEPROM_MAGIC) {
282 size = sizeof(struct ar5416_eeprom_def);
283 need_swap = true;
284 eepdata = (u16 *) (&ah->eeprom);
285 280
286 for (addr = 0; addr < size / sizeof(u16); addr++) { 281 for (addr = 0; addr < size / sizeof(u16); addr++) {
287 temp = swab16(*eepdata); 282 temp = swab16(*eepdata);
288 *eepdata = temp; 283 *eepdata = temp;
289 eepdata++; 284 eepdata++;
290 }
291 } else {
292 ath_err(common,
293 "Invalid EEPROM Magic. Endianness mismatch.\n");
294 return -EINVAL;
295 }
296 } 285 }
297 } 286 }
298 287
diff --git a/drivers/net/wireless/ath/ath9k/gpio.c b/drivers/net/wireless/ath/ath9k/gpio.c
index b1956bf6e01e..2fef7a480fec 100644
--- a/drivers/net/wireless/ath/ath9k/gpio.c
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
@@ -25,7 +25,12 @@ static void ath_led_brightness(struct led_classdev *led_cdev,
25 enum led_brightness brightness) 25 enum led_brightness brightness)
26{ 26{
27 struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev); 27 struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
28 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF)); 28 u32 val = (brightness == LED_OFF);
29
30 if (sc->sc_ah->config.led_active_high)
31 val = !val;
32
33 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
29} 34}
30 35
31void ath_deinit_leds(struct ath_softc *sc) 36void ath_deinit_leds(struct ath_softc *sc)
@@ -82,7 +87,7 @@ void ath_fill_led_pin(struct ath_softc *sc)
82 ath9k_hw_cfg_output(ah, ah->led_pin, AR_GPIO_OUTPUT_MUX_AS_OUTPUT); 87 ath9k_hw_cfg_output(ah, ah->led_pin, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
83 88
84 /* LED off, active low */ 89 /* LED off, active low */
85 ath9k_hw_set_gpio(ah, ah->led_pin, 1); 90 ath9k_hw_set_gpio(ah, ah->led_pin, (ah->config.led_active_high) ? 0 : 1);
86} 91}
87#endif 92#endif
88 93
diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h
index 09a5d72f3ff5..9dde265d3f84 100644
--- a/drivers/net/wireless/ath/ath9k/htc.h
+++ b/drivers/net/wireless/ath/ath9k/htc.h
@@ -481,6 +481,7 @@ struct ath9k_htc_priv {
481 unsigned long op_flags; 481 unsigned long op_flags;
482 482
483 struct ath9k_hw_cal_data caldata; 483 struct ath9k_hw_cal_data caldata;
484 struct ath_spec_scan_priv spec_priv;
484 485
485 spinlock_t beacon_lock; 486 spinlock_t beacon_lock;
486 struct ath_beacon_config cur_beacon_conf; 487 struct ath_beacon_config cur_beacon_conf;
@@ -625,8 +626,12 @@ int ath9k_htc_resume(struct htc_target *htc_handle);
625#endif 626#endif
626#ifdef CONFIG_ATH9K_HTC_DEBUGFS 627#ifdef CONFIG_ATH9K_HTC_DEBUGFS
627int ath9k_htc_init_debug(struct ath_hw *ah); 628int ath9k_htc_init_debug(struct ath_hw *ah);
629void ath9k_htc_deinit_debug(struct ath9k_htc_priv *priv);
628#else 630#else
629static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; }; 631static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; };
632static inline void ath9k_htc_deinit_debug(struct ath9k_htc_priv *priv)
633{
634}
630#endif /* CONFIG_ATH9K_HTC_DEBUGFS */ 635#endif /* CONFIG_ATH9K_HTC_DEBUGFS */
631 636
632#endif /* HTC_H */ 637#endif /* HTC_H */
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
index 8b529e4b8ac4..8cef1edcc621 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
@@ -490,6 +490,10 @@ void ath9k_htc_get_et_stats(struct ieee80211_hw *hw,
490 WARN_ON(i != ATH9K_HTC_SSTATS_LEN); 490 WARN_ON(i != ATH9K_HTC_SSTATS_LEN);
491} 491}
492 492
493void ath9k_htc_deinit_debug(struct ath9k_htc_priv *priv)
494{
495 ath9k_cmn_spectral_deinit_debug(&priv->spec_priv);
496}
493 497
494int ath9k_htc_init_debug(struct ath_hw *ah) 498int ath9k_htc_init_debug(struct ath_hw *ah)
495{ 499{
@@ -501,6 +505,8 @@ int ath9k_htc_init_debug(struct ath_hw *ah)
501 if (!priv->debug.debugfs_phy) 505 if (!priv->debug.debugfs_phy)
502 return -ENOMEM; 506 return -ENOMEM;
503 507
508 ath9k_cmn_spectral_init_debug(&priv->spec_priv, priv->debug.debugfs_phy);
509
504 debugfs_create_file("tgt_int_stats", S_IRUSR, priv->debug.debugfs_phy, 510 debugfs_create_file("tgt_int_stats", S_IRUSR, priv->debug.debugfs_phy,
505 priv, &fops_tgt_int_stats); 511 priv, &fops_tgt_int_stats);
506 debugfs_create_file("tgt_tx_stats", S_IRUSR, priv->debug.debugfs_phy, 512 debugfs_create_file("tgt_tx_stats", S_IRUSR, priv->debug.debugfs_phy,
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index 4014c4be6e79..e8fa9448da24 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -53,6 +53,21 @@ static const struct ieee80211_tpt_blink ath9k_htc_tpt_blink[] = {
53}; 53};
54#endif 54#endif
55 55
56static void ath9k_htc_op_ps_wakeup(struct ath_common *common)
57{
58 ath9k_htc_ps_wakeup((struct ath9k_htc_priv *) common->priv);
59}
60
61static void ath9k_htc_op_ps_restore(struct ath_common *common)
62{
63 ath9k_htc_ps_restore((struct ath9k_htc_priv *) common->priv);
64}
65
66static struct ath_ps_ops ath9k_htc_ps_ops = {
67 .wakeup = ath9k_htc_op_ps_wakeup,
68 .restore = ath9k_htc_op_ps_restore,
69};
70
56static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv) 71static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv)
57{ 72{
58 int time_left; 73 int time_left;
@@ -87,6 +102,7 @@ static void ath9k_deinit_device(struct ath9k_htc_priv *priv)
87 102
88 wiphy_rfkill_stop_polling(hw->wiphy); 103 wiphy_rfkill_stop_polling(hw->wiphy);
89 ath9k_deinit_leds(priv); 104 ath9k_deinit_leds(priv);
105 ath9k_htc_deinit_debug(priv);
90 ieee80211_unregister_hw(hw); 106 ieee80211_unregister_hw(hw);
91 ath9k_rx_cleanup(priv); 107 ath9k_rx_cleanup(priv);
92 ath9k_tx_cleanup(priv); 108 ath9k_tx_cleanup(priv);
@@ -449,6 +465,14 @@ static void ath9k_init_misc(struct ath9k_htc_priv *priv)
449 465
450 common->last_rssi = ATH_RSSI_DUMMY_MARKER; 466 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
451 priv->ah->opmode = NL80211_IFTYPE_STATION; 467 priv->ah->opmode = NL80211_IFTYPE_STATION;
468
469 priv->spec_priv.ah = priv->ah;
470 priv->spec_priv.spec_config.enabled = 0;
471 priv->spec_priv.spec_config.short_repeat = false;
472 priv->spec_priv.spec_config.count = 8;
473 priv->spec_priv.spec_config.endless = false;
474 priv->spec_priv.spec_config.period = 0x12;
475 priv->spec_priv.spec_config.fft_period = 0x02;
452} 476}
453 477
454static int ath9k_init_priv(struct ath9k_htc_priv *priv, 478static int ath9k_init_priv(struct ath9k_htc_priv *priv,
@@ -478,6 +502,7 @@ static int ath9k_init_priv(struct ath9k_htc_priv *priv,
478 502
479 common = ath9k_hw_common(ah); 503 common = ath9k_hw_common(ah);
480 common->ops = &ah->reg_ops; 504 common->ops = &ah->reg_ops;
505 common->ps_ops = &ath9k_htc_ps_ops;
481 common->bus_ops = &ath9k_usb_bus_ops; 506 common->bus_ops = &ath9k_usb_bus_ops;
482 common->ah = ah; 507 common->ah = ah;
483 common->hw = priv->hw; 508 common->hw = priv->hw;
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
index 994fff1ff519..c7d12efaa86a 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
@@ -314,6 +314,10 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
314 mod_timer(&priv->tx.cleanup_timer, 314 mod_timer(&priv->tx.cleanup_timer,
315 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); 315 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
316 316
317 /* perform spectral scan if requested. */
318 if (test_bit(ATH_OP_SCANNING, &common->op_flags) &&
319 priv->spec_priv.spectral_mode == SPECTRAL_CHANSCAN)
320 ath9k_cmn_spectral_scan_trigger(common, &priv->spec_priv);
317err: 321err:
318 ath9k_htc_ps_restore(priv); 322 ath9k_htc_ps_restore(priv);
319 return ret; 323 return ret;
@@ -1443,7 +1447,7 @@ static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1443 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 1447 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1444 if (key->cipher == WLAN_CIPHER_SUITE_TKIP) 1448 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1445 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 1449 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1446 if (priv->ah->sw_mgmt_crypto && 1450 if (priv->ah->sw_mgmt_crypto_tx &&
1447 key->cipher == WLAN_CIPHER_SUITE_CCMP) 1451 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1448 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; 1452 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1449 ret = 0; 1453 ret = 0;
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
index f0484b1b617e..a0f58e2aa553 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
@@ -946,7 +946,7 @@ static inline void convert_htc_flag(struct ath_rx_status *rx_stats,
946static void rx_status_htc_to_ath(struct ath_rx_status *rx_stats, 946static void rx_status_htc_to_ath(struct ath_rx_status *rx_stats,
947 struct ath_htc_rx_status *rxstatus) 947 struct ath_htc_rx_status *rxstatus)
948{ 948{
949 rx_stats->rs_datalen = rxstatus->rs_datalen; 949 rx_stats->rs_datalen = be16_to_cpu(rxstatus->rs_datalen);
950 rx_stats->rs_status = rxstatus->rs_status; 950 rx_stats->rs_status = rxstatus->rs_status;
951 rx_stats->rs_phyerr = rxstatus->rs_phyerr; 951 rx_stats->rs_phyerr = rxstatus->rs_phyerr;
952 rx_stats->rs_rssi = rxstatus->rs_rssi; 952 rx_stats->rs_rssi = rxstatus->rs_rssi;
@@ -1012,6 +1012,20 @@ static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
1012 * separately to avoid doing two lookups for a rate for each frame. 1012 * separately to avoid doing two lookups for a rate for each frame.
1013 */ 1013 */
1014 hdr = (struct ieee80211_hdr *)skb->data; 1014 hdr = (struct ieee80211_hdr *)skb->data;
1015
1016 /*
1017 * Process PHY errors and return so that the packet
1018 * can be dropped.
1019 */
1020 if (rx_stats.rs_status & ATH9K_RXERR_PHY) {
1021 /* TODO: Not using DFS processing now. */
1022 if (ath_cmn_process_fft(&priv->spec_priv, hdr,
1023 &rx_stats, rx_status->mactime)) {
1024 /* TODO: Code to collect spectral scan statistics */
1025 }
1026 goto rx_next;
1027 }
1028
1015 if (!ath9k_cmn_rx_accept(common, hdr, rx_status, &rx_stats, 1029 if (!ath9k_cmn_rx_accept(common, hdr, rx_status, &rx_stats,
1016 &decrypt_error, priv->rxfilter)) 1030 &decrypt_error, priv->rxfilter))
1017 goto rx_next; 1031 goto rx_next;
diff --git a/drivers/net/wireless/ath/ath9k/hw-ops.h b/drivers/net/wireless/ath/ath9k/hw-ops.h
index 8e85efeaeffc..88769b64b20b 100644
--- a/drivers/net/wireless/ath/ath9k/hw-ops.h
+++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
@@ -41,10 +41,9 @@ static inline void ath9k_hw_set_desc_link(struct ath_hw *ah, void *ds,
41 ath9k_hw_ops(ah)->set_desc_link(ds, link); 41 ath9k_hw_ops(ah)->set_desc_link(ds, link);
42} 42}
43 43
44static inline bool ath9k_hw_calibrate(struct ath_hw *ah, 44static inline int ath9k_hw_calibrate(struct ath_hw *ah,
45 struct ath9k_channel *chan, 45 struct ath9k_channel *chan,
46 u8 rxchainmask, 46 u8 rxchainmask, bool longcal)
47 bool longcal)
48{ 47{
49 return ath9k_hw_ops(ah)->calibrate(ah, chan, rxchainmask, longcal); 48 return ath9k_hw_ops(ah)->calibrate(ah, chan, rxchainmask, longcal);
50} 49}
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 2ad605760e21..6d4b273469b1 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/time.h> 20#include <linux/time.h>
21#include <linux/bitops.h> 21#include <linux/bitops.h>
22#include <linux/etherdevice.h>
22#include <asm/unaligned.h> 23#include <asm/unaligned.h>
23 24
24#include "hw.h" 25#include "hw.h"
@@ -446,8 +447,16 @@ static int ath9k_hw_init_macaddr(struct ath_hw *ah)
446 common->macaddr[2 * i] = eeval >> 8; 447 common->macaddr[2 * i] = eeval >> 8;
447 common->macaddr[2 * i + 1] = eeval & 0xff; 448 common->macaddr[2 * i + 1] = eeval & 0xff;
448 } 449 }
449 if (sum == 0 || sum == 0xffff * 3) 450 if (!is_valid_ether_addr(common->macaddr)) {
450 return -EADDRNOTAVAIL; 451 ath_err(common,
452 "eeprom contains invalid mac address: %pM\n",
453 common->macaddr);
454
455 random_ether_addr(common->macaddr);
456 ath_err(common,
457 "random mac address will be used: %pM\n",
458 common->macaddr);
459 }
451 460
452 return 0; 461 return 0;
453} 462}
@@ -1576,16 +1585,22 @@ static void ath9k_hw_init_mfp(struct ath_hw *ah)
1576 * frames when constructing CCMP AAD. */ 1585 * frames when constructing CCMP AAD. */
1577 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT, 1586 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1578 0xc7ff); 1587 0xc7ff);
1579 ah->sw_mgmt_crypto = false; 1588 if (AR_SREV_9271(ah) || AR_DEVID_7010(ah))
1589 ah->sw_mgmt_crypto_tx = true;
1590 else
1591 ah->sw_mgmt_crypto_tx = false;
1592 ah->sw_mgmt_crypto_rx = false;
1580 } else if (AR_SREV_9160_10_OR_LATER(ah)) { 1593 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1581 /* Disable hardware crypto for management frames */ 1594 /* Disable hardware crypto for management frames */
1582 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2, 1595 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1583 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE); 1596 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1584 REG_SET_BIT(ah, AR_PCU_MISC_MODE2, 1597 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1585 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT); 1598 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1586 ah->sw_mgmt_crypto = true; 1599 ah->sw_mgmt_crypto_tx = true;
1600 ah->sw_mgmt_crypto_rx = true;
1587 } else { 1601 } else {
1588 ah->sw_mgmt_crypto = true; 1602 ah->sw_mgmt_crypto_tx = true;
1603 ah->sw_mgmt_crypto_rx = true;
1589 } 1604 }
1590} 1605}
1591 1606
@@ -1932,6 +1947,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1932 1947
1933 REGWRITE_BUFFER_FLUSH(ah); 1948 REGWRITE_BUFFER_FLUSH(ah);
1934 1949
1950 ath9k_hw_gen_timer_start_tsf2(ah);
1951
1935 ath9k_hw_init_desc(ah); 1952 ath9k_hw_init_desc(ah);
1936 1953
1937 if (ath9k_hw_btcoex_is_enabled(ah)) 1954 if (ath9k_hw_btcoex_is_enabled(ah))
@@ -1940,8 +1957,10 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1940 if (ath9k_hw_mci_is_enabled(ah)) 1957 if (ath9k_hw_mci_is_enabled(ah))
1941 ar9003_mci_check_bt(ah); 1958 ar9003_mci_check_bt(ah);
1942 1959
1943 ath9k_hw_loadnf(ah, chan); 1960 if (AR_SREV_9300_20_OR_LATER(ah)) {
1944 ath9k_hw_start_nfcal(ah, true); 1961 ath9k_hw_loadnf(ah, chan);
1962 ath9k_hw_start_nfcal(ah, true);
1963 }
1945 1964
1946 if (AR_SREV_9300_20_OR_LATER(ah)) 1965 if (AR_SREV_9300_20_OR_LATER(ah))
1947 ar9003_hw_bb_watchdog_config(ah); 1966 ar9003_hw_bb_watchdog_config(ah);
@@ -2309,7 +2328,6 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2309 struct ath9k_hw_capabilities *pCap = &ah->caps; 2328 struct ath9k_hw_capabilities *pCap = &ah->caps;
2310 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); 2329 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
2311 struct ath_common *common = ath9k_hw_common(ah); 2330 struct ath_common *common = ath9k_hw_common(ah);
2312 unsigned int chip_chainmask;
2313 2331
2314 u16 eeval; 2332 u16 eeval;
2315 u8 ant_div_ctl1, tx_chainmask, rx_chainmask; 2333 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
@@ -2329,31 +2347,40 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2329 } 2347 }
2330 2348
2331 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE); 2349 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
2332 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) { 2350
2333 ath_err(common, 2351 if (eeval & AR5416_OPFLAGS_11A) {
2334 "no band has been marked as supported in EEPROM\n"); 2352 if (ah->disable_5ghz)
2335 return -EINVAL; 2353 ath_warn(common, "disabling 5GHz band\n");
2354 else
2355 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
2336 } 2356 }
2337 2357
2338 if (eeval & AR5416_OPFLAGS_11A) 2358 if (eeval & AR5416_OPFLAGS_11G) {
2339 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ; 2359 if (ah->disable_2ghz)
2360 ath_warn(common, "disabling 2GHz band\n");
2361 else
2362 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
2363 }
2340 2364
2341 if (eeval & AR5416_OPFLAGS_11G) 2365 if ((pCap->hw_caps & (ATH9K_HW_CAP_2GHZ | ATH9K_HW_CAP_5GHZ)) == 0) {
2342 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ; 2366 ath_err(common, "both bands are disabled\n");
2367 return -EINVAL;
2368 }
2343 2369
2344 if (AR_SREV_9485(ah) || 2370 if (AR_SREV_9485(ah) ||
2345 AR_SREV_9285(ah) || 2371 AR_SREV_9285(ah) ||
2346 AR_SREV_9330(ah) || 2372 AR_SREV_9330(ah) ||
2347 AR_SREV_9565(ah)) 2373 AR_SREV_9565(ah))
2348 chip_chainmask = 1; 2374 pCap->chip_chainmask = 1;
2349 else if (AR_SREV_9462(ah))
2350 chip_chainmask = 3;
2351 else if (!AR_SREV_9280_20_OR_LATER(ah)) 2375 else if (!AR_SREV_9280_20_OR_LATER(ah))
2352 chip_chainmask = 7; 2376 pCap->chip_chainmask = 7;
2353 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah)) 2377 else if (!AR_SREV_9300_20_OR_LATER(ah) ||
2354 chip_chainmask = 3; 2378 AR_SREV_9340(ah) ||
2379 AR_SREV_9462(ah) ||
2380 AR_SREV_9531(ah))
2381 pCap->chip_chainmask = 3;
2355 else 2382 else
2356 chip_chainmask = 7; 2383 pCap->chip_chainmask = 7;
2357 2384
2358 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK); 2385 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
2359 /* 2386 /*
@@ -2371,8 +2398,8 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2371 /* Use rx_chainmask from EEPROM. */ 2398 /* Use rx_chainmask from EEPROM. */
2372 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); 2399 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
2373 2400
2374 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask); 2401 pCap->tx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->tx_chainmask);
2375 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask); 2402 pCap->rx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->rx_chainmask);
2376 ah->txchainmask = pCap->tx_chainmask; 2403 ah->txchainmask = pCap->tx_chainmask;
2377 ah->rxchainmask = pCap->rx_chainmask; 2404 ah->rxchainmask = pCap->rx_chainmask;
2378 2405
@@ -2886,6 +2913,16 @@ u32 ath9k_hw_gettsf32(struct ath_hw *ah)
2886} 2913}
2887EXPORT_SYMBOL(ath9k_hw_gettsf32); 2914EXPORT_SYMBOL(ath9k_hw_gettsf32);
2888 2915
2916void ath9k_hw_gen_timer_start_tsf2(struct ath_hw *ah)
2917{
2918 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2919
2920 if (timer_table->tsf2_enabled) {
2921 REG_SET_BIT(ah, AR_DIRECT_CONNECT, AR_DC_AP_STA_EN);
2922 REG_SET_BIT(ah, AR_RESET_TSF, AR_RESET_TSF2_ONCE);
2923 }
2924}
2925
2889struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, 2926struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2890 void (*trigger)(void *), 2927 void (*trigger)(void *),
2891 void (*overflow)(void *), 2928 void (*overflow)(void *),
@@ -2896,7 +2933,11 @@ struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2896 struct ath_gen_timer *timer; 2933 struct ath_gen_timer *timer;
2897 2934
2898 if ((timer_index < AR_FIRST_NDP_TIMER) || 2935 if ((timer_index < AR_FIRST_NDP_TIMER) ||
2899 (timer_index >= ATH_MAX_GEN_TIMER)) 2936 (timer_index >= ATH_MAX_GEN_TIMER))
2937 return NULL;
2938
2939 if ((timer_index > AR_FIRST_NDP_TIMER) &&
2940 !AR_SREV_9300_20_OR_LATER(ah))
2900 return NULL; 2941 return NULL;
2901 2942
2902 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL); 2943 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
@@ -2910,6 +2951,11 @@ struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2910 timer->overflow = overflow; 2951 timer->overflow = overflow;
2911 timer->arg = arg; 2952 timer->arg = arg;
2912 2953
2954 if ((timer_index > AR_FIRST_NDP_TIMER) && !timer_table->tsf2_enabled) {
2955 timer_table->tsf2_enabled = true;
2956 ath9k_hw_gen_timer_start_tsf2(ah);
2957 }
2958
2913 return timer; 2959 return timer;
2914} 2960}
2915EXPORT_SYMBOL(ath_gen_timer_alloc); 2961EXPORT_SYMBOL(ath_gen_timer_alloc);
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 975074fc11bc..4cf9e0ac0743 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -244,13 +244,20 @@ enum ath9k_hw_caps {
244 ATH9K_HW_CAP_2GHZ = BIT(11), 244 ATH9K_HW_CAP_2GHZ = BIT(11),
245 ATH9K_HW_CAP_5GHZ = BIT(12), 245 ATH9K_HW_CAP_5GHZ = BIT(12),
246 ATH9K_HW_CAP_APM = BIT(13), 246 ATH9K_HW_CAP_APM = BIT(13),
247#ifdef CONFIG_ATH9K_PCOEM
247 ATH9K_HW_CAP_RTT = BIT(14), 248 ATH9K_HW_CAP_RTT = BIT(14),
248 ATH9K_HW_CAP_MCI = BIT(15), 249 ATH9K_HW_CAP_MCI = BIT(15),
249 ATH9K_HW_CAP_DFS = BIT(16), 250 ATH9K_HW_WOW_DEVICE_CAPABLE = BIT(16),
250 ATH9K_HW_WOW_DEVICE_CAPABLE = BIT(17), 251 ATH9K_HW_CAP_BT_ANT_DIV = BIT(17),
251 ATH9K_HW_CAP_PAPRD = BIT(18), 252#else
252 ATH9K_HW_CAP_FCC_BAND_SWITCH = BIT(19), 253 ATH9K_HW_CAP_RTT = 0,
253 ATH9K_HW_CAP_BT_ANT_DIV = BIT(20), 254 ATH9K_HW_CAP_MCI = 0,
255 ATH9K_HW_WOW_DEVICE_CAPABLE = 0,
256 ATH9K_HW_CAP_BT_ANT_DIV = 0,
257#endif
258 ATH9K_HW_CAP_DFS = BIT(18),
259 ATH9K_HW_CAP_PAPRD = BIT(19),
260 ATH9K_HW_CAP_FCC_BAND_SWITCH = BIT(20),
254}; 261};
255 262
256/* 263/*
@@ -269,6 +276,7 @@ struct ath9k_hw_capabilities {
269 u16 rts_aggr_limit; 276 u16 rts_aggr_limit;
270 u8 tx_chainmask; 277 u8 tx_chainmask;
271 u8 rx_chainmask; 278 u8 rx_chainmask;
279 u8 chip_chainmask;
272 u8 max_txchains; 280 u8 max_txchains;
273 u8 max_rxchains; 281 u8 max_rxchains;
274 u8 num_gpio_pins; 282 u8 num_gpio_pins;
@@ -322,6 +330,7 @@ struct ath9k_ops_config {
322 bool alt_mingainidx; 330 bool alt_mingainidx;
323 bool no_pll_pwrsave; 331 bool no_pll_pwrsave;
324 bool tx_gain_buffalo; 332 bool tx_gain_buffalo;
333 bool led_active_high;
325}; 334};
326 335
327enum ath9k_int { 336enum ath9k_int {
@@ -517,6 +526,7 @@ struct ath_gen_timer {
517struct ath_gen_timer_table { 526struct ath_gen_timer_table {
518 struct ath_gen_timer *timers[ATH_MAX_GEN_TIMER]; 527 struct ath_gen_timer *timers[ATH_MAX_GEN_TIMER];
519 u16 timer_mask; 528 u16 timer_mask;
529 bool tsf2_enabled;
520}; 530};
521 531
522struct ath_hw_antcomb_conf { 532struct ath_hw_antcomb_conf {
@@ -681,10 +691,8 @@ struct ath_hw_ops {
681 bool power_off); 691 bool power_off);
682 void (*rx_enable)(struct ath_hw *ah); 692 void (*rx_enable)(struct ath_hw *ah);
683 void (*set_desc_link)(void *ds, u32 link); 693 void (*set_desc_link)(void *ds, u32 link);
684 bool (*calibrate)(struct ath_hw *ah, 694 int (*calibrate)(struct ath_hw *ah, struct ath9k_channel *chan,
685 struct ath9k_channel *chan, 695 u8 rxchainmask, bool longcal);
686 u8 rxchainmask,
687 bool longcal);
688 bool (*get_isr)(struct ath_hw *ah, enum ath9k_int *masked, 696 bool (*get_isr)(struct ath_hw *ah, enum ath9k_int *masked,
689 u32 *sync_cause_p); 697 u32 *sync_cause_p);
690 void (*set_txdesc)(struct ath_hw *ah, void *ds, 698 void (*set_txdesc)(struct ath_hw *ah, void *ds,
@@ -726,6 +734,7 @@ enum ath_cal_list {
726#define AH_USE_EEPROM 0x1 734#define AH_USE_EEPROM 0x1
727#define AH_UNPLUGGED 0x2 /* The card has been physically removed. */ 735#define AH_UNPLUGGED 0x2 /* The card has been physically removed. */
728#define AH_FASTCC 0x4 736#define AH_FASTCC 0x4
737#define AH_NO_EEP_SWAP 0x8 /* Do not swap EEPROM data */
729 738
730struct ath_hw { 739struct ath_hw {
731 struct ath_ops reg_ops; 740 struct ath_ops reg_ops;
@@ -747,7 +756,8 @@ struct ath_hw {
747 } eeprom; 756 } eeprom;
748 const struct eeprom_ops *eep_ops; 757 const struct eeprom_ops *eep_ops;
749 758
750 bool sw_mgmt_crypto; 759 bool sw_mgmt_crypto_tx;
760 bool sw_mgmt_crypto_rx;
751 bool is_pciexpress; 761 bool is_pciexpress;
752 bool aspm_enabled; 762 bool aspm_enabled;
753 bool is_monitoring; 763 bool is_monitoring;
@@ -924,6 +934,8 @@ struct ath_hw {
924 bool is_clk_25mhz; 934 bool is_clk_25mhz;
925 int (*get_mac_revision)(void); 935 int (*get_mac_revision)(void);
926 int (*external_reset)(void); 936 int (*external_reset)(void);
937 bool disable_2ghz;
938 bool disable_5ghz;
927 939
928 const struct firmware *eeprom_blob; 940 const struct firmware *eeprom_blob;
929 941
@@ -1027,6 +1039,7 @@ void ath9k_hw_gen_timer_start(struct ath_hw *ah,
1027 struct ath_gen_timer *timer, 1039 struct ath_gen_timer *timer,
1028 u32 timer_next, 1040 u32 timer_next,
1029 u32 timer_period); 1041 u32 timer_period);
1042void ath9k_hw_gen_timer_start_tsf2(struct ath_hw *ah);
1030void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer); 1043void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer);
1031 1044
1032void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer); 1045void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer);
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 3bd030494986..59d679cebc89 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -88,6 +88,21 @@ static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
88 88
89static void ath9k_deinit_softc(struct ath_softc *sc); 89static void ath9k_deinit_softc(struct ath_softc *sc);
90 90
91static void ath9k_op_ps_wakeup(struct ath_common *common)
92{
93 ath9k_ps_wakeup((struct ath_softc *) common->priv);
94}
95
96static void ath9k_op_ps_restore(struct ath_common *common)
97{
98 ath9k_ps_restore((struct ath_softc *) common->priv);
99}
100
101static struct ath_ps_ops ath9k_ps_ops = {
102 .wakeup = ath9k_op_ps_wakeup,
103 .restore = ath9k_op_ps_restore,
104};
105
91/* 106/*
92 * Read and write, they both share the same lock. We do this to serialize 107 * Read and write, they both share the same lock. We do this to serialize
93 * reads and writes on Atheros 802.11n PCI devices only. This is required 108 * reads and writes on Atheros 802.11n PCI devices only. This is required
@@ -172,17 +187,20 @@ static void ath9k_reg_notifier(struct wiphy *wiphy,
172 ath_reg_notifier_apply(wiphy, request, reg); 187 ath_reg_notifier_apply(wiphy, request, reg);
173 188
174 /* Set tx power */ 189 /* Set tx power */
175 if (ah->curchan) { 190 if (!ah->curchan)
176 sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power; 191 return;
177 ath9k_ps_wakeup(sc); 192
178 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false); 193 sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power;
179 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit; 194 ath9k_ps_wakeup(sc);
180 /* synchronize DFS detector if regulatory domain changed */ 195 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
181 if (sc->dfs_detector != NULL) 196 ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
182 sc->dfs_detector->set_dfs_domain(sc->dfs_detector, 197 sc->cur_chan->txpower,
183 request->dfs_region); 198 &sc->cur_chan->cur_txpower);
184 ath9k_ps_restore(sc); 199 /* synchronize DFS detector if regulatory domain changed */
185 } 200 if (sc->dfs_detector != NULL)
201 sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
202 request->dfs_region);
203 ath9k_ps_restore(sc);
186} 204}
187 205
188/* 206/*
@@ -348,12 +366,13 @@ static void ath9k_init_misc(struct ath_softc *sc)
348 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) 366 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
349 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT; 367 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
350 368
351 sc->spec_config.enabled = 0; 369 sc->spec_priv.ah = sc->sc_ah;
352 sc->spec_config.short_repeat = true; 370 sc->spec_priv.spec_config.enabled = 0;
353 sc->spec_config.count = 8; 371 sc->spec_priv.spec_config.short_repeat = true;
354 sc->spec_config.endless = false; 372 sc->spec_priv.spec_config.count = 8;
355 sc->spec_config.period = 0xFF; 373 sc->spec_priv.spec_config.endless = false;
356 sc->spec_config.fft_period = 0xF; 374 sc->spec_priv.spec_config.period = 0xFF;
375 sc->spec_priv.spec_config.fft_period = 0xF;
357} 376}
358 377
359static void ath9k_init_pcoem_platform(struct ath_softc *sc) 378static void ath9k_init_pcoem_platform(struct ath_softc *sc)
@@ -362,6 +381,9 @@ static void ath9k_init_pcoem_platform(struct ath_softc *sc)
362 struct ath9k_hw_capabilities *pCap = &ah->caps; 381 struct ath9k_hw_capabilities *pCap = &ah->caps;
363 struct ath_common *common = ath9k_hw_common(ah); 382 struct ath_common *common = ath9k_hw_common(ah);
364 383
384 if (!IS_ENABLED(CONFIG_ATH9K_PCOEM))
385 return;
386
365 if (common->bus_ops->ath_bus_type != ATH_PCI) 387 if (common->bus_ops->ath_bus_type != ATH_PCI)
366 return; 388 return;
367 389
@@ -419,6 +441,9 @@ static void ath9k_init_pcoem_platform(struct ath_softc *sc)
419 ah->config.no_pll_pwrsave = true; 441 ah->config.no_pll_pwrsave = true;
420 ath_info(common, "Disable PLL PowerSave\n"); 442 ath_info(common, "Disable PLL PowerSave\n");
421 } 443 }
444
445 if (sc->driver_data & ATH9K_PCI_LED_ACT_HI)
446 ah->config.led_active_high = true;
422} 447}
423 448
424static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob, 449static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
@@ -528,10 +553,15 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
528 ah->is_clk_25mhz = pdata->is_clk_25mhz; 553 ah->is_clk_25mhz = pdata->is_clk_25mhz;
529 ah->get_mac_revision = pdata->get_mac_revision; 554 ah->get_mac_revision = pdata->get_mac_revision;
530 ah->external_reset = pdata->external_reset; 555 ah->external_reset = pdata->external_reset;
556 ah->disable_2ghz = pdata->disable_2ghz;
557 ah->disable_5ghz = pdata->disable_5ghz;
558 if (!pdata->endian_check)
559 ah->ah_flags |= AH_NO_EEP_SWAP;
531 } 560 }
532 561
533 common->ops = &ah->reg_ops; 562 common->ops = &ah->reg_ops;
534 common->bus_ops = bus_ops; 563 common->bus_ops = bus_ops;
564 common->ps_ops = &ath9k_ps_ops;
535 common->ah = ah; 565 common->ah = ah;
536 common->hw = sc->hw; 566 common->hw = sc->hw;
537 common->priv = sc; 567 common->priv = sc;
diff --git a/drivers/net/wireless/ath/ath9k/link.c b/drivers/net/wireless/ath/ath9k/link.c
index 2343f56e6498..b829263e3d0a 100644
--- a/drivers/net/wireless/ath/ath9k/link.c
+++ b/drivers/net/wireless/ath/ath9k/link.c
@@ -371,9 +371,15 @@ void ath_ani_calibrate(unsigned long data)
371 371
372 /* Perform calibration if necessary */ 372 /* Perform calibration if necessary */
373 if (longcal || shortcal) { 373 if (longcal || shortcal) {
374 common->ani.caldone = 374 int ret = ath9k_hw_calibrate(ah, ah->curchan, ah->rxchainmask,
375 ath9k_hw_calibrate(ah, ah->curchan, 375 longcal);
376 ah->rxchainmask, longcal); 376 if (ret < 0) {
377 common->ani.caldone = 0;
378 ath9k_queue_reset(sc, RESET_TYPE_CALIBRATION);
379 return;
380 }
381
382 common->ani.caldone = ret;
377 } 383 }
378 384
379 ath_dbg(common, ANI, 385 ath_dbg(common, ANI,
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 30c66dfcd7a0..f95283f3c350 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -54,7 +54,8 @@ u8 ath9k_parse_mpdudensity(u8 mpdudensity)
54 } 54 }
55} 55}
56 56
57static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq) 57static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq,
58 bool sw_pending)
58{ 59{
59 bool pending = false; 60 bool pending = false;
60 61
@@ -65,6 +66,9 @@ static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
65 goto out; 66 goto out;
66 } 67 }
67 68
69 if (!sw_pending)
70 goto out;
71
68 if (txq->mac80211_qnum >= 0) { 72 if (txq->mac80211_qnum >= 0) {
69 struct list_head *list; 73 struct list_head *list;
70 74
@@ -229,8 +233,9 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
229 233
230 ath9k_calculate_summary_state(sc, sc->cur_chan); 234 ath9k_calculate_summary_state(sc, sc->cur_chan);
231 ath_startrecv(sc); 235 ath_startrecv(sc);
232 ath9k_cmn_update_txpow(ah, sc->curtxpow, 236 ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
233 sc->cur_chan->txpower, &sc->curtxpow); 237 sc->cur_chan->txpower,
238 &sc->cur_chan->cur_txpower);
234 clear_bit(ATH_OP_HW_RESET, &common->op_flags); 239 clear_bit(ATH_OP_HW_RESET, &common->op_flags);
235 240
236 if (!sc->cur_chan->offchannel && start) { 241 if (!sc->cur_chan->offchannel && start) {
@@ -270,7 +275,7 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
270 return true; 275 return true;
271} 276}
272 277
273int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan) 278static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
274{ 279{
275 struct ath_hw *ah = sc->sc_ah; 280 struct ath_hw *ah = sc->sc_ah;
276 struct ath_common *common = ath9k_hw_common(ah); 281 struct ath_common *common = ath9k_hw_common(ah);
@@ -281,6 +286,7 @@ int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
281 __ath_cancel_work(sc); 286 __ath_cancel_work(sc);
282 287
283 tasklet_disable(&sc->intr_tq); 288 tasklet_disable(&sc->intr_tq);
289 tasklet_disable(&sc->bcon_tasklet);
284 spin_lock_bh(&sc->sc_pcu_lock); 290 spin_lock_bh(&sc->sc_pcu_lock);
285 291
286 if (!sc->cur_chan->offchannel) { 292 if (!sc->cur_chan->offchannel) {
@@ -326,6 +332,7 @@ int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
326 332
327out: 333out:
328 spin_unlock_bh(&sc->sc_pcu_lock); 334 spin_unlock_bh(&sc->sc_pcu_lock);
335 tasklet_enable(&sc->bcon_tasklet);
329 tasklet_enable(&sc->intr_tq); 336 tasklet_enable(&sc->intr_tq);
330 337
331 return r; 338 return r;
@@ -539,11 +546,10 @@ irqreturn_t ath_isr(int irq, void *dev)
539 sched = true; 546 sched = true;
540 547
541 /* 548 /*
542 * If a FATAL or RXORN interrupt is received, we have to reset the 549 * If a FATAL interrupt is received, we have to reset the chip
543 * chip immediately. 550 * immediately.
544 */ 551 */
545 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) && 552 if (status & ATH9K_INT_FATAL)
546 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
547 goto chip_reset; 553 goto chip_reset;
548 554
549 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) && 555 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
@@ -598,17 +604,29 @@ chip_reset:
598#undef SCHED_INTR 604#undef SCHED_INTR
599} 605}
600 606
601int ath_reset(struct ath_softc *sc) 607/*
608 * This function is called when a HW reset cannot be deferred
609 * and has to be immediate.
610 */
611int ath_reset(struct ath_softc *sc, struct ath9k_channel *hchan)
602{ 612{
613 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
603 int r; 614 int r;
604 615
616 set_bit(ATH_OP_HW_RESET, &common->op_flags);
617
605 ath9k_ps_wakeup(sc); 618 ath9k_ps_wakeup(sc);
606 r = ath_reset_internal(sc, NULL); 619 r = ath_reset_internal(sc, hchan);
607 ath9k_ps_restore(sc); 620 ath9k_ps_restore(sc);
608 621
609 return r; 622 return r;
610} 623}
611 624
625/*
626 * When a HW reset can be deferred, it is added to the
627 * hw_reset_work workqueue, but we set ATH_OP_HW_RESET before
628 * queueing.
629 */
612void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type) 630void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
613{ 631{
614 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 632 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
@@ -623,7 +641,9 @@ void ath_reset_work(struct work_struct *work)
623{ 641{
624 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work); 642 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
625 643
626 ath_reset(sc); 644 ath9k_ps_wakeup(sc);
645 ath_reset_internal(sc, NULL);
646 ath9k_ps_restore(sc);
627} 647}
628 648
629/**********************/ 649/**********************/
@@ -707,7 +727,8 @@ static int ath9k_start(struct ieee80211_hw *hw)
707 if (ah->led_pin >= 0) { 727 if (ah->led_pin >= 0) {
708 ath9k_hw_cfg_output(ah, ah->led_pin, 728 ath9k_hw_cfg_output(ah, ah->led_pin,
709 AR_GPIO_OUTPUT_MUX_AS_OUTPUT); 729 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
710 ath9k_hw_set_gpio(ah, ah->led_pin, 0); 730 ath9k_hw_set_gpio(ah, ah->led_pin,
731 (ah->config.led_active_high) ? 1 : 0);
711 } 732 }
712 733
713 /* 734 /*
@@ -849,7 +870,8 @@ static void ath9k_stop(struct ieee80211_hw *hw)
849 spin_lock_bh(&sc->sc_pcu_lock); 870 spin_lock_bh(&sc->sc_pcu_lock);
850 871
851 if (ah->led_pin >= 0) { 872 if (ah->led_pin >= 0) {
852 ath9k_hw_set_gpio(ah, ah->led_pin, 1); 873 ath9k_hw_set_gpio(ah, ah->led_pin,
874 (ah->config.led_active_high) ? 0 : 1);
853 ath9k_hw_cfg_gpio_input(ah, ah->led_pin); 875 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
854 } 876 }
855 877
@@ -1037,7 +1059,7 @@ static void ath9k_set_offchannel_state(struct ath_softc *sc)
1037 1059
1038 eth_zero_addr(common->curbssid); 1060 eth_zero_addr(common->curbssid);
1039 eth_broadcast_addr(common->bssidmask); 1061 eth_broadcast_addr(common->bssidmask);
1040 ether_addr_copy(common->macaddr, vif->addr); 1062 memcpy(common->macaddr, vif->addr, ETH_ALEN);
1041 common->curaid = 0; 1063 common->curaid = 0;
1042 ah->opmode = vif->type; 1064 ah->opmode = vif->type;
1043 ah->imask &= ~ATH9K_INT_SWBA; 1065 ah->imask &= ~ATH9K_INT_SWBA;
@@ -1078,7 +1100,7 @@ void ath9k_calculate_summary_state(struct ath_softc *sc,
1078 ath9k_calculate_iter_data(sc, ctx, &iter_data); 1100 ath9k_calculate_iter_data(sc, ctx, &iter_data);
1079 1101
1080 if (iter_data.has_hw_macaddr) 1102 if (iter_data.has_hw_macaddr)
1081 ether_addr_copy(common->macaddr, iter_data.hw_macaddr); 1103 memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
1082 1104
1083 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); 1105 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
1084 ath_hw_setbssidmask(common); 1106 ath_hw_setbssidmask(common);
@@ -1168,7 +1190,8 @@ static void ath9k_assign_hw_queues(struct ieee80211_hw *hw,
1168 for (i = 0; i < IEEE80211_NUM_ACS; i++) 1190 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1169 vif->hw_queue[i] = i; 1191 vif->hw_queue[i] = i;
1170 1192
1171 if (vif->type == NL80211_IFTYPE_AP) 1193 if (vif->type == NL80211_IFTYPE_AP ||
1194 vif->type == NL80211_IFTYPE_MESH_POINT)
1172 vif->cab_queue = hw->queues - 2; 1195 vif->cab_queue = hw->queues - 2;
1173 else 1196 else
1174 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 1197 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
@@ -1320,78 +1343,6 @@ static void ath9k_disable_ps(struct ath_softc *sc)
1320 ath_dbg(common, PS, "PowerSave disabled\n"); 1343 ath_dbg(common, PS, "PowerSave disabled\n");
1321} 1344}
1322 1345
1323void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
1324{
1325 struct ath_softc *sc = hw->priv;
1326 struct ath_hw *ah = sc->sc_ah;
1327 struct ath_common *common = ath9k_hw_common(ah);
1328 u32 rxfilter;
1329
1330 if (config_enabled(CONFIG_ATH9K_TX99))
1331 return;
1332
1333 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1334 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1335 return;
1336 }
1337
1338 ath9k_ps_wakeup(sc);
1339 rxfilter = ath9k_hw_getrxfilter(ah);
1340 ath9k_hw_setrxfilter(ah, rxfilter |
1341 ATH9K_RX_FILTER_PHYRADAR |
1342 ATH9K_RX_FILTER_PHYERR);
1343
1344 /* TODO: usually this should not be neccesary, but for some reason
1345 * (or in some mode?) the trigger must be called after the
1346 * configuration, otherwise the register will have its values reset
1347 * (on my ar9220 to value 0x01002310)
1348 */
1349 ath9k_spectral_scan_config(hw, sc->spectral_mode);
1350 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
1351 ath9k_ps_restore(sc);
1352}
1353
1354int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
1355 enum spectral_mode spectral_mode)
1356{
1357 struct ath_softc *sc = hw->priv;
1358 struct ath_hw *ah = sc->sc_ah;
1359 struct ath_common *common = ath9k_hw_common(ah);
1360
1361 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1362 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1363 return -1;
1364 }
1365
1366 switch (spectral_mode) {
1367 case SPECTRAL_DISABLED:
1368 sc->spec_config.enabled = 0;
1369 break;
1370 case SPECTRAL_BACKGROUND:
1371 /* send endless samples.
1372 * TODO: is this really useful for "background"?
1373 */
1374 sc->spec_config.endless = 1;
1375 sc->spec_config.enabled = 1;
1376 break;
1377 case SPECTRAL_CHANSCAN:
1378 case SPECTRAL_MANUAL:
1379 sc->spec_config.endless = 0;
1380 sc->spec_config.enabled = 1;
1381 break;
1382 default:
1383 return -1;
1384 }
1385
1386 ath9k_ps_wakeup(sc);
1387 ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
1388 ath9k_ps_restore(sc);
1389
1390 sc->spectral_mode = spectral_mode;
1391
1392 return 0;
1393}
1394
1395static int ath9k_config(struct ieee80211_hw *hw, u32 changed) 1346static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1396{ 1347{
1397 struct ath_softc *sc = hw->priv; 1348 struct ath_softc *sc = hw->priv;
@@ -1452,8 +1403,9 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1452 if (changed & IEEE80211_CONF_CHANGE_POWER) { 1403 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1453 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level); 1404 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
1454 sc->cur_chan->txpower = 2 * conf->power_level; 1405 sc->cur_chan->txpower = 2 * conf->power_level;
1455 ath9k_cmn_update_txpow(ah, sc->curtxpow, 1406 ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
1456 sc->cur_chan->txpower, &sc->curtxpow); 1407 sc->cur_chan->txpower,
1408 &sc->cur_chan->cur_txpower);
1457 } 1409 }
1458 1410
1459 mutex_unlock(&sc->mutex); 1411 mutex_unlock(&sc->mutex);
@@ -1550,6 +1502,40 @@ static int ath9k_sta_remove(struct ieee80211_hw *hw,
1550 return 0; 1502 return 0;
1551} 1503}
1552 1504
1505static int ath9k_sta_state(struct ieee80211_hw *hw,
1506 struct ieee80211_vif *vif,
1507 struct ieee80211_sta *sta,
1508 enum ieee80211_sta_state old_state,
1509 enum ieee80211_sta_state new_state)
1510{
1511 struct ath_softc *sc = hw->priv;
1512 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1513 int ret = 0;
1514
1515 if (old_state == IEEE80211_STA_AUTH &&
1516 new_state == IEEE80211_STA_ASSOC) {
1517 ret = ath9k_sta_add(hw, vif, sta);
1518 ath_dbg(common, CONFIG,
1519 "Add station: %pM\n", sta->addr);
1520 } else if (old_state == IEEE80211_STA_ASSOC &&
1521 new_state == IEEE80211_STA_AUTH) {
1522 ret = ath9k_sta_remove(hw, vif, sta);
1523 ath_dbg(common, CONFIG,
1524 "Remove station: %pM\n", sta->addr);
1525 }
1526
1527 if (ath9k_is_chanctx_enabled()) {
1528 if (vif->type == NL80211_IFTYPE_STATION) {
1529 if (old_state == IEEE80211_STA_ASSOC &&
1530 new_state == IEEE80211_STA_AUTHORIZED)
1531 ath_chanctx_event(sc, vif,
1532 ATH_CHANCTX_EVENT_AUTHORIZED);
1533 }
1534 }
1535
1536 return ret;
1537}
1538
1553static void ath9k_sta_set_tx_filter(struct ath_hw *ah, 1539static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
1554 struct ath_node *an, 1540 struct ath_node *an,
1555 bool set) 1541 bool set)
@@ -1674,7 +1660,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,
1674 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 1660 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1675 if (key->cipher == WLAN_CIPHER_SUITE_TKIP) 1661 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1676 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 1662 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1677 if (sc->sc_ah->sw_mgmt_crypto && 1663 if (sc->sc_ah->sw_mgmt_crypto_tx &&
1678 key->cipher == WLAN_CIPHER_SUITE_CCMP) 1664 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1679 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; 1665 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1680 ret = 0; 1666 ret = 0;
@@ -1734,17 +1720,11 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1734 ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n", 1720 ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
1735 bss_conf->bssid, bss_conf->assoc); 1721 bss_conf->bssid, bss_conf->assoc);
1736 1722
1737 ether_addr_copy(avp->bssid, bss_conf->bssid); 1723 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
1738 avp->aid = bss_conf->aid; 1724 avp->aid = bss_conf->aid;
1739 avp->assoc = bss_conf->assoc; 1725 avp->assoc = bss_conf->assoc;
1740 1726
1741 ath9k_calculate_summary_state(sc, avp->chanctx); 1727 ath9k_calculate_summary_state(sc, avp->chanctx);
1742
1743 if (ath9k_is_chanctx_enabled()) {
1744 if (bss_conf->assoc)
1745 ath_chanctx_event(sc, vif,
1746 ATH_CHANCTX_EVENT_ASSOC);
1747 }
1748 } 1728 }
1749 1729
1750 if (changed & BSS_CHANGED_IBSS) { 1730 if (changed & BSS_CHANGED_IBSS) {
@@ -1840,6 +1820,7 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1840 u16 tid, u16 *ssn, u8 buf_size) 1820 u16 tid, u16 *ssn, u8 buf_size)
1841{ 1821{
1842 struct ath_softc *sc = hw->priv; 1822 struct ath_softc *sc = hw->priv;
1823 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1843 bool flush = false; 1824 bool flush = false;
1844 int ret = 0; 1825 int ret = 0;
1845 1826
@@ -1851,6 +1832,12 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1851 case IEEE80211_AMPDU_RX_STOP: 1832 case IEEE80211_AMPDU_RX_STOP:
1852 break; 1833 break;
1853 case IEEE80211_AMPDU_TX_START: 1834 case IEEE80211_AMPDU_TX_START:
1835 if (ath9k_is_chanctx_enabled()) {
1836 if (test_bit(ATH_OP_SCANNING, &common->op_flags)) {
1837 ret = -EBUSY;
1838 break;
1839 }
1840 }
1854 ath9k_ps_wakeup(sc); 1841 ath9k_ps_wakeup(sc);
1855 ret = ath_tx_aggr_start(sc, sta, tid, ssn); 1842 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1856 if (!ret) 1843 if (!ret)
@@ -1964,7 +1951,8 @@ static void ath9k_set_coverage_class(struct ieee80211_hw *hw,
1964 mutex_unlock(&sc->mutex); 1951 mutex_unlock(&sc->mutex);
1965} 1952}
1966 1953
1967static bool ath9k_has_tx_pending(struct ath_softc *sc) 1954static bool ath9k_has_tx_pending(struct ath_softc *sc,
1955 bool sw_pending)
1968{ 1956{
1969 int i, npend = 0; 1957 int i, npend = 0;
1970 1958
@@ -1972,7 +1960,8 @@ static bool ath9k_has_tx_pending(struct ath_softc *sc)
1972 if (!ATH_TXQ_SETUP(sc, i)) 1960 if (!ATH_TXQ_SETUP(sc, i))
1973 continue; 1961 continue;
1974 1962
1975 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]); 1963 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i],
1964 sw_pending);
1976 if (npend) 1965 if (npend)
1977 break; 1966 break;
1978 } 1967 }
@@ -1984,18 +1973,38 @@ static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1984 u32 queues, bool drop) 1973 u32 queues, bool drop)
1985{ 1974{
1986 struct ath_softc *sc = hw->priv; 1975 struct ath_softc *sc = hw->priv;
1976 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1977
1978 if (ath9k_is_chanctx_enabled()) {
1979 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
1980 goto flush;
1987 1981
1982 /*
1983 * If MCC is active, extend the flush timeout
1984 * and wait for the HW/SW queues to become
1985 * empty. This needs to be done outside the
1986 * sc->mutex lock to allow the channel scheduler
1987 * to switch channel contexts.
1988 *
1989 * The vif queues have been stopped in mac80211,
1990 * so there won't be any incoming frames.
1991 */
1992 __ath9k_flush(hw, queues, drop, true, true);
1993 return;
1994 }
1995flush:
1988 mutex_lock(&sc->mutex); 1996 mutex_lock(&sc->mutex);
1989 __ath9k_flush(hw, queues, drop); 1997 __ath9k_flush(hw, queues, drop, true, false);
1990 mutex_unlock(&sc->mutex); 1998 mutex_unlock(&sc->mutex);
1991} 1999}
1992 2000
1993void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop) 2001void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop,
2002 bool sw_pending, bool timeout_override)
1994{ 2003{
1995 struct ath_softc *sc = hw->priv; 2004 struct ath_softc *sc = hw->priv;
1996 struct ath_hw *ah = sc->sc_ah; 2005 struct ath_hw *ah = sc->sc_ah;
1997 struct ath_common *common = ath9k_hw_common(ah); 2006 struct ath_common *common = ath9k_hw_common(ah);
1998 int timeout = HZ / 5; /* 200 ms */ 2007 int timeout;
1999 bool drain_txq; 2008 bool drain_txq;
2000 2009
2001 cancel_delayed_work_sync(&sc->tx_complete_work); 2010 cancel_delayed_work_sync(&sc->tx_complete_work);
@@ -2010,7 +2019,17 @@ void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2010 return; 2019 return;
2011 } 2020 }
2012 2021
2013 if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc), 2022 spin_lock_bh(&sc->chan_lock);
2023 if (timeout_override)
2024 timeout = HZ / 5;
2025 else
2026 timeout = sc->cur_chan->flush_timeout;
2027 spin_unlock_bh(&sc->chan_lock);
2028
2029 ath_dbg(common, CHAN_CTX,
2030 "Flush timeout: %d\n", jiffies_to_msecs(timeout));
2031
2032 if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc, sw_pending),
2014 timeout) > 0) 2033 timeout) > 0)
2015 drop = false; 2034 drop = false;
2016 2035
@@ -2021,7 +2040,7 @@ void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2021 spin_unlock_bh(&sc->sc_pcu_lock); 2040 spin_unlock_bh(&sc->sc_pcu_lock);
2022 2041
2023 if (!drain_txq) 2042 if (!drain_txq)
2024 ath_reset(sc); 2043 ath_reset(sc, NULL);
2025 2044
2026 ath9k_ps_restore(sc); 2045 ath9k_ps_restore(sc);
2027 } 2046 }
@@ -2033,7 +2052,7 @@ static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
2033{ 2052{
2034 struct ath_softc *sc = hw->priv; 2053 struct ath_softc *sc = hw->priv;
2035 2054
2036 return ath9k_has_tx_pending(sc); 2055 return ath9k_has_tx_pending(sc, true);
2037} 2056}
2038 2057
2039static int ath9k_tx_last_beacon(struct ieee80211_hw *hw) 2058static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
@@ -2180,6 +2199,28 @@ static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2180 2199
2181#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT 2200#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
2182 2201
2202static void ath9k_cancel_pending_offchannel(struct ath_softc *sc)
2203{
2204 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2205
2206 if (sc->offchannel.roc_vif) {
2207 ath_dbg(common, CHAN_CTX,
2208 "%s: Aborting RoC\n", __func__);
2209
2210 del_timer_sync(&sc->offchannel.timer);
2211 if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START)
2212 ath_roc_complete(sc, true);
2213 }
2214
2215 if (test_bit(ATH_OP_SCANNING, &common->op_flags)) {
2216 ath_dbg(common, CHAN_CTX,
2217 "%s: Aborting HW scan\n", __func__);
2218
2219 del_timer_sync(&sc->offchannel.timer);
2220 ath_scan_complete(sc, true);
2221 }
2222}
2223
2183static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2224static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2184 struct ieee80211_scan_request *hw_req) 2225 struct ieee80211_scan_request *hw_req)
2185{ 2226{
@@ -2310,7 +2351,6 @@ static int ath9k_add_chanctx(struct ieee80211_hw *hw,
2310 conf->def.chan->center_freq); 2351 conf->def.chan->center_freq);
2311 2352
2312 ath_chanctx_set_channel(sc, ctx, &conf->def); 2353 ath_chanctx_set_channel(sc, ctx, &conf->def);
2313 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_ASSIGN);
2314 2354
2315 mutex_unlock(&sc->mutex); 2355 mutex_unlock(&sc->mutex);
2316 return 0; 2356 return 0;
@@ -2367,6 +2407,8 @@ static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw,
2367 struct ath_chanctx *ctx = ath_chanctx_get(conf); 2407 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2368 int i; 2408 int i;
2369 2409
2410 ath9k_cancel_pending_offchannel(sc);
2411
2370 mutex_lock(&sc->mutex); 2412 mutex_lock(&sc->mutex);
2371 2413
2372 ath_dbg(common, CHAN_CTX, 2414 ath_dbg(common, CHAN_CTX,
@@ -2396,6 +2438,8 @@ static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw,
2396 struct ath_chanctx *ctx = ath_chanctx_get(conf); 2438 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2397 int ac; 2439 int ac;
2398 2440
2441 ath9k_cancel_pending_offchannel(sc);
2442
2399 mutex_lock(&sc->mutex); 2443 mutex_lock(&sc->mutex);
2400 2444
2401 ath_dbg(common, CHAN_CTX, 2445 ath_dbg(common, CHAN_CTX,
@@ -2419,7 +2463,11 @@ static void ath9k_mgd_prepare_tx(struct ieee80211_hw *hw,
2419 struct ath_softc *sc = hw->priv; 2463 struct ath_softc *sc = hw->priv;
2420 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 2464 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2421 struct ath_vif *avp = (struct ath_vif *) vif->drv_priv; 2465 struct ath_vif *avp = (struct ath_vif *) vif->drv_priv;
2466 struct ath_beacon_config *cur_conf;
2467 struct ath_chanctx *go_ctx;
2468 unsigned long timeout;
2422 bool changed = false; 2469 bool changed = false;
2470 u32 beacon_int;
2423 2471
2424 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) 2472 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
2425 return; 2473 return;
@@ -2430,19 +2478,57 @@ static void ath9k_mgd_prepare_tx(struct ieee80211_hw *hw,
2430 mutex_lock(&sc->mutex); 2478 mutex_lock(&sc->mutex);
2431 2479
2432 spin_lock_bh(&sc->chan_lock); 2480 spin_lock_bh(&sc->chan_lock);
2433 if (sc->next_chan || (sc->cur_chan != avp->chanctx)) { 2481 if (sc->next_chan || (sc->cur_chan != avp->chanctx))
2434 sc->next_chan = avp->chanctx;
2435 changed = true; 2482 changed = true;
2483 spin_unlock_bh(&sc->chan_lock);
2484
2485 if (!changed)
2486 goto out;
2487
2488 ath9k_cancel_pending_offchannel(sc);
2489
2490 go_ctx = ath_is_go_chanctx_present(sc);
2491
2492 if (go_ctx) {
2493 /*
2494 * Wait till the GO interface gets a chance
2495 * to send out an NoA.
2496 */
2497 spin_lock_bh(&sc->chan_lock);
2498 sc->sched.mgd_prepare_tx = true;
2499 cur_conf = &go_ctx->beacon;
2500 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
2501 spin_unlock_bh(&sc->chan_lock);
2502
2503 timeout = usecs_to_jiffies(beacon_int * 2);
2504 init_completion(&sc->go_beacon);
2505
2506 mutex_unlock(&sc->mutex);
2507
2508 if (wait_for_completion_timeout(&sc->go_beacon,
2509 timeout) == 0) {
2510 ath_dbg(common, CHAN_CTX,
2511 "Failed to send new NoA\n");
2512
2513 spin_lock_bh(&sc->chan_lock);
2514 sc->sched.mgd_prepare_tx = false;
2515 spin_unlock_bh(&sc->chan_lock);
2516 }
2517
2518 mutex_lock(&sc->mutex);
2436 } 2519 }
2520
2437 ath_dbg(common, CHAN_CTX, 2521 ath_dbg(common, CHAN_CTX,
2438 "%s: Set chanctx state to FORCE_ACTIVE, changed: %d\n", 2522 "%s: Set chanctx state to FORCE_ACTIVE for vif: %pM\n",
2439 __func__, changed); 2523 __func__, vif->addr);
2524
2525 spin_lock_bh(&sc->chan_lock);
2526 sc->next_chan = avp->chanctx;
2440 sc->sched.state = ATH_CHANCTX_STATE_FORCE_ACTIVE; 2527 sc->sched.state = ATH_CHANCTX_STATE_FORCE_ACTIVE;
2441 spin_unlock_bh(&sc->chan_lock); 2528 spin_unlock_bh(&sc->chan_lock);
2442 2529
2443 if (changed) 2530 ath_chanctx_set_next(sc, true);
2444 ath_chanctx_set_next(sc, true); 2531out:
2445
2446 mutex_unlock(&sc->mutex); 2532 mutex_unlock(&sc->mutex);
2447} 2533}
2448 2534
@@ -2465,6 +2551,24 @@ void ath9k_fill_chanctx_ops(void)
2465 2551
2466#endif 2552#endif
2467 2553
2554static int ath9k_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2555 int *dbm)
2556{
2557 struct ath_softc *sc = hw->priv;
2558 struct ath_vif *avp = (void *)vif->drv_priv;
2559
2560 mutex_lock(&sc->mutex);
2561 if (avp->chanctx)
2562 *dbm = avp->chanctx->cur_txpower;
2563 else
2564 *dbm = sc->cur_chan->cur_txpower;
2565 mutex_unlock(&sc->mutex);
2566
2567 *dbm /= 2;
2568
2569 return 0;
2570}
2571
2468struct ieee80211_ops ath9k_ops = { 2572struct ieee80211_ops ath9k_ops = {
2469 .tx = ath9k_tx, 2573 .tx = ath9k_tx,
2470 .start = ath9k_start, 2574 .start = ath9k_start,
@@ -2474,8 +2578,7 @@ struct ieee80211_ops ath9k_ops = {
2474 .remove_interface = ath9k_remove_interface, 2578 .remove_interface = ath9k_remove_interface,
2475 .config = ath9k_config, 2579 .config = ath9k_config,
2476 .configure_filter = ath9k_configure_filter, 2580 .configure_filter = ath9k_configure_filter,
2477 .sta_add = ath9k_sta_add, 2581 .sta_state = ath9k_sta_state,
2478 .sta_remove = ath9k_sta_remove,
2479 .sta_notify = ath9k_sta_notify, 2582 .sta_notify = ath9k_sta_notify,
2480 .conf_tx = ath9k_conf_tx, 2583 .conf_tx = ath9k_conf_tx,
2481 .bss_info_changed = ath9k_bss_info_changed, 2584 .bss_info_changed = ath9k_bss_info_changed,
@@ -2512,4 +2615,5 @@ struct ieee80211_ops ath9k_ops = {
2512#endif 2615#endif
2513 .sw_scan_start = ath9k_sw_scan_start, 2616 .sw_scan_start = ath9k_sw_scan_start,
2514 .sw_scan_complete = ath9k_sw_scan_complete, 2617 .sw_scan_complete = ath9k_sw_scan_complete,
2618 .get_txpower = ath9k_get_txpower,
2515}; 2619};
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index c018dea0b2e8..f009b5b57e5e 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -30,6 +30,7 @@ static const struct pci_device_id ath_pci_id_table[] = {
30 { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */ 30 { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
31 { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */ 31 { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
32 32
33#ifdef CONFIG_ATH9K_PCOEM
33 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS, 34 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
34 0x002A, 35 0x002A,
35 PCI_VENDOR_ID_AZWAVE, 36 PCI_VENDOR_ID_AZWAVE,
@@ -82,6 +83,7 @@ static const struct pci_device_id ath_pci_id_table[] = {
82 PCI_VENDOR_ID_AZWAVE, 83 PCI_VENDOR_ID_AZWAVE,
83 0x2C37), 84 0x2C37),
84 .driver_data = ATH9K_PCI_BT_ANT_DIV }, 85 .driver_data = ATH9K_PCI_BT_ANT_DIV },
86#endif
85 87
86 { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */ 88 { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
87 { PCI_VDEVICE(ATHEROS, 0x002C) }, /* PCI-E 802.11n bonded out */ 89 { PCI_VDEVICE(ATHEROS, 0x002C) }, /* PCI-E 802.11n bonded out */
@@ -102,6 +104,7 @@ static const struct pci_device_id ath_pci_id_table[] = {
102 104
103 { PCI_VDEVICE(ATHEROS, 0x0030) }, /* PCI-E AR9300 */ 105 { PCI_VDEVICE(ATHEROS, 0x0030) }, /* PCI-E AR9300 */
104 106
107#ifdef CONFIG_ATH9K_PCOEM
105 /* PCI-E CUS198 */ 108 /* PCI-E CUS198 */
106 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS, 109 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
107 0x0032, 110 0x0032,
@@ -294,10 +297,12 @@ static const struct pci_device_id ath_pci_id_table[] = {
294 PCI_VENDOR_ID_ASUSTEK, 297 PCI_VENDOR_ID_ASUSTEK,
295 0x850D), 298 0x850D),
296 .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE }, 299 .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
300#endif
297 301
298 { PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E AR9485 */ 302 { PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E AR9485 */
299 { PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E AR9580 */ 303 { PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E AR9580 */
300 304
305#ifdef CONFIG_ATH9K_PCOEM
301 /* PCI-E CUS217 */ 306 /* PCI-E CUS217 */
302 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS, 307 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
303 0x0034, 308 0x0034,
@@ -652,11 +657,14 @@ static const struct pci_device_id ath_pci_id_table[] = {
652 0x0036, 657 0x0036,
653 PCI_VENDOR_ID_DELL, 658 PCI_VENDOR_ID_DELL,
654 0x020E), 659 0x020E),
655 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV }, 660 .driver_data = ATH9K_PCI_AR9565_2ANT |
661 ATH9K_PCI_BT_ANT_DIV |
662 ATH9K_PCI_LED_ACT_HI},
656 663
657 /* PCI-E AR9565 (WB335) */ 664 /* PCI-E AR9565 (WB335) */
658 { PCI_VDEVICE(ATHEROS, 0x0036), 665 { PCI_VDEVICE(ATHEROS, 0x0036),
659 .driver_data = ATH9K_PCI_BT_ANT_DIV }, 666 .driver_data = ATH9K_PCI_BT_ANT_DIV },
667#endif
660 668
661 { 0 } 669 { 0 }
662}; 670};
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index 6914e21816e4..7395afbc5124 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -870,7 +870,7 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
870 */ 870 */
871 if (rx_stats->rs_status & ATH9K_RXERR_PHY) { 871 if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
872 ath9k_dfs_process_phyerr(sc, hdr, rx_stats, rx_status->mactime); 872 ath9k_dfs_process_phyerr(sc, hdr, rx_stats, rx_status->mactime);
873 if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime)) 873 if (ath_cmn_process_fft(&sc->spec_priv, hdr, rx_stats, rx_status->mactime))
874 RX_STAT_INC(rx_spectral); 874 RX_STAT_INC(rx_spectral);
875 875
876 return -EINVAL; 876 return -EINVAL;
diff --git a/drivers/net/wireless/ath/ath9k/reg.h b/drivers/net/wireless/ath/ath9k/reg.h
index 2a938f4feac5..ced36b475acc 100644
--- a/drivers/net/wireless/ath/ath9k/reg.h
+++ b/drivers/net/wireless/ath/ath9k/reg.h
@@ -892,10 +892,21 @@
892 (AR_SREV_9330((_ah)) && \ 892 (AR_SREV_9330((_ah)) && \
893 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9330_12)) 893 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9330_12))
894 894
895#ifdef CONFIG_ATH9K_PCOEM
896#define AR_SREV_9462(_ah) \
897 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9462))
895#define AR_SREV_9485(_ah) \ 898#define AR_SREV_9485(_ah) \
896 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485)) 899 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485))
900#define AR_SREV_9565(_ah) \
901 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9565))
902#else
903#define AR_SREV_9462(_ah) 0
904#define AR_SREV_9485(_ah) 0
905#define AR_SREV_9565(_ah) 0
906#endif
907
897#define AR_SREV_9485_11_OR_LATER(_ah) \ 908#define AR_SREV_9485_11_OR_LATER(_ah) \
898 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485) && \ 909 (AR_SREV_9485(_ah) && \
899 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9485_11)) 910 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9485_11))
900#define AR_SREV_9485_OR_LATER(_ah) \ 911#define AR_SREV_9485_OR_LATER(_ah) \
901 (((_ah)->hw_version.macVersion >= AR_SREV_VERSION_9485)) 912 (((_ah)->hw_version.macVersion >= AR_SREV_VERSION_9485))
@@ -915,34 +926,30 @@
915 (AR_SREV_9285_12_OR_LATER(_ah) && \ 926 (AR_SREV_9285_12_OR_LATER(_ah) && \
916 ((REG_READ(_ah, AR_AN_SYNTH9) & 0x7) == 0x1)) 927 ((REG_READ(_ah, AR_AN_SYNTH9) & 0x7) == 0x1))
917 928
918#define AR_SREV_9462(_ah) \
919 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9462))
920#define AR_SREV_9462_20(_ah) \ 929#define AR_SREV_9462_20(_ah) \
921 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9462) && \ 930 (AR_SREV_9462(_ah) && \
922 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9462_20)) 931 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9462_20))
923#define AR_SREV_9462_21(_ah) \ 932#define AR_SREV_9462_21(_ah) \
924 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9462) && \ 933 (AR_SREV_9462(_ah) && \
925 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9462_21)) 934 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9462_21))
926#define AR_SREV_9462_20_OR_LATER(_ah) \ 935#define AR_SREV_9462_20_OR_LATER(_ah) \
927 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9462) && \ 936 (AR_SREV_9462(_ah) && \
928 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9462_20)) 937 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9462_20))
929#define AR_SREV_9462_21_OR_LATER(_ah) \ 938#define AR_SREV_9462_21_OR_LATER(_ah) \
930 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9462) && \ 939 (AR_SREV_9462(_ah) && \
931 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9462_21)) 940 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9462_21))
932 941
933#define AR_SREV_9565(_ah) \
934 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9565))
935#define AR_SREV_9565_10(_ah) \ 942#define AR_SREV_9565_10(_ah) \
936 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9565) && \ 943 (AR_SREV_9565(_ah) && \
937 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9565_10)) 944 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9565_10))
938#define AR_SREV_9565_101(_ah) \ 945#define AR_SREV_9565_101(_ah) \
939 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9565) && \ 946 (AR_SREV_9565(_ah) && \
940 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9565_101)) 947 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9565_101))
941#define AR_SREV_9565_11(_ah) \ 948#define AR_SREV_9565_11(_ah) \
942 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9565) && \ 949 (AR_SREV_9565(_ah) && \
943 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9565_11)) 950 ((_ah)->hw_version.macRev == AR_SREV_REVISION_9565_11))
944#define AR_SREV_9565_11_OR_LATER(_ah) \ 951#define AR_SREV_9565_11_OR_LATER(_ah) \
945 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9565) && \ 952 (AR_SREV_9565(_ah) && \
946 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9565_11)) 953 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9565_11))
947 954
948#define AR_SREV_9550(_ah) \ 955#define AR_SREV_9550(_ah) \
@@ -1598,6 +1605,7 @@ enum {
1598 1605
1599#define AR_RESET_TSF 0x8020 1606#define AR_RESET_TSF 0x8020
1600#define AR_RESET_TSF_ONCE 0x01000000 1607#define AR_RESET_TSF_ONCE 0x01000000
1608#define AR_RESET_TSF2_ONCE 0x02000000
1601 1609
1602#define AR_MAX_CFP_DUR 0x8038 1610#define AR_MAX_CFP_DUR 0x8038
1603#define AR_CFP_VAL 0x0000FFFF 1611#define AR_CFP_VAL 0x0000FFFF
@@ -1959,6 +1967,8 @@ enum {
1959#define AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET 0x80000000 1967#define AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET 0x80000000
1960#define AR_MAC_PCU_GEN_TIMER_TSF_SEL 0x83d8 1968#define AR_MAC_PCU_GEN_TIMER_TSF_SEL 0x83d8
1961 1969
1970#define AR_DIRECT_CONNECT 0x83a0
1971#define AR_DC_AP_STA_EN 0x00000001
1962 1972
1963#define AR_AES_MUTE_MASK0 0x805c 1973#define AR_AES_MUTE_MASK0 0x805c
1964#define AR_AES_MUTE_MASK0_FC 0x0000FFFF 1974#define AR_AES_MUTE_MASK0_FC 0x0000FFFF
diff --git a/drivers/net/wireless/ath/ath9k/tx99.c b/drivers/net/wireless/ath/ath9k/tx99.c
index 40ab65e6882f..ac4781f37e78 100644
--- a/drivers/net/wireless/ath/ath9k/tx99.c
+++ b/drivers/net/wireless/ath/ath9k/tx99.c
@@ -99,7 +99,7 @@ static struct sk_buff *ath9k_build_tx99_skb(struct ath_softc *sc)
99 99
100static void ath9k_tx99_deinit(struct ath_softc *sc) 100static void ath9k_tx99_deinit(struct ath_softc *sc)
101{ 101{
102 ath_reset(sc); 102 ath_reset(sc, NULL);
103 103
104 ath9k_ps_wakeup(sc); 104 ath9k_ps_wakeup(sc);
105 ath9k_tx99_stop(sc); 105 ath9k_tx99_stop(sc);
@@ -127,7 +127,7 @@ static int ath9k_tx99_init(struct ath_softc *sc)
127 memset(&txctl, 0, sizeof(txctl)); 127 memset(&txctl, 0, sizeof(txctl));
128 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; 128 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
129 129
130 ath_reset(sc); 130 ath_reset(sc, NULL);
131 131
132 ath9k_ps_wakeup(sc); 132 ath9k_ps_wakeup(sc);
133 133
diff --git a/drivers/net/wireless/ath/carl9170/phy.c b/drivers/net/wireless/ath/carl9170/phy.c
index b80b2138ce3c..dca6df13fd5b 100644
--- a/drivers/net/wireless/ath/carl9170/phy.c
+++ b/drivers/net/wireless/ath/carl9170/phy.c
@@ -994,7 +994,7 @@ static int carl9170_init_rf_bank4_pwr(struct ar9170 *ar, bool band5ghz,
994 refsel0 = 0; 994 refsel0 = 0;
995 refsel1 = 1; 995 refsel1 = 1;
996 } 996 }
997 chansel = byte_rev_table[chansel]; 997 chansel = bitrev8(chansel);
998 } else { 998 } else {
999 if (freq == 2484) { 999 if (freq == 2484) {
1000 chansel = 10 + (freq - 2274) / 5; 1000 chansel = 10 + (freq - 2274) / 5;
@@ -1002,7 +1002,7 @@ static int carl9170_init_rf_bank4_pwr(struct ar9170 *ar, bool band5ghz,
1002 } else 1002 } else
1003 chansel = 16 + (freq - 2272) / 5; 1003 chansel = 16 + (freq - 2272) / 5;
1004 chansel *= 4; 1004 chansel *= 4;
1005 chansel = byte_rev_table[chansel]; 1005 chansel = bitrev8(chansel);
1006 } 1006 }
1007 1007
1008 d1 = chansel; 1008 d1 = chansel;
diff --git a/drivers/net/wireless/ath/wil6210/cfg80211.c b/drivers/net/wireless/ath/wil6210/cfg80211.c
index d9f4b30dd343..0fc0b9f8e605 100644
--- a/drivers/net/wireless/ath/wil6210/cfg80211.c
+++ b/drivers/net/wireless/ath/wil6210/cfg80211.c
@@ -792,12 +792,13 @@ static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
792} 792}
793 793
794static int wil_cfg80211_del_station(struct wiphy *wiphy, 794static int wil_cfg80211_del_station(struct wiphy *wiphy,
795 struct net_device *dev, const u8 *mac) 795 struct net_device *dev,
796 struct station_del_parameters *params)
796{ 797{
797 struct wil6210_priv *wil = wiphy_to_wil(wiphy); 798 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
798 799
799 mutex_lock(&wil->mutex); 800 mutex_lock(&wil->mutex);
800 wil6210_disconnect(wil, mac); 801 wil6210_disconnect(wil, params->mac, false);
801 mutex_unlock(&wil->mutex); 802 mutex_unlock(&wil->mutex);
802 803
803 return 0; 804 return 0;
diff --git a/drivers/net/wireless/ath/wil6210/main.c b/drivers/net/wireless/ath/wil6210/main.c
index 6500caf8d609..6212983fede2 100644
--- a/drivers/net/wireless/ath/wil6210/main.c
+++ b/drivers/net/wireless/ath/wil6210/main.c
@@ -38,6 +38,35 @@ static unsigned int itr_trsh = WIL6210_ITR_TRSH_DEFAULT;
38module_param(itr_trsh, uint, S_IRUGO); 38module_param(itr_trsh, uint, S_IRUGO);
39MODULE_PARM_DESC(itr_trsh, " Interrupt moderation threshold, usecs."); 39MODULE_PARM_DESC(itr_trsh, " Interrupt moderation threshold, usecs.");
40 40
41/* We allow allocation of more than 1 page buffers to support large packets.
42 * It is suboptimal behavior performance wise in case MTU above page size.
43 */
44unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - ETH_HLEN;
45static int mtu_max_set(const char *val, const struct kernel_param *kp)
46{
47 int ret;
48
49 /* sets mtu_max directly. no need to restore it in case of
50 * illegal value since we assume this will fail insmod
51 */
52 ret = param_set_uint(val, kp);
53 if (ret)
54 return ret;
55
56 if (mtu_max < 68 || mtu_max > IEEE80211_MAX_DATA_LEN_DMG)
57 ret = -EINVAL;
58
59 return ret;
60}
61
62static struct kernel_param_ops mtu_max_ops = {
63 .set = mtu_max_set,
64 .get = param_get_uint,
65};
66
67module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO);
68MODULE_PARM_DESC(mtu_max, " Max MTU value.");
69
41#define RST_DELAY (20) /* msec, for loop in @wil_target_reset */ 70#define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
42#define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */ 71#define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
43 72
@@ -74,7 +103,8 @@ void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
74 __raw_writel(*s++, d++); 103 __raw_writel(*s++, d++);
75} 104}
76 105
77static void wil_disconnect_cid(struct wil6210_priv *wil, int cid) 106static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
107 bool from_event)
78{ 108{
79 uint i; 109 uint i;
80 struct net_device *ndev = wil_to_ndev(wil); 110 struct net_device *ndev = wil_to_ndev(wil);
@@ -86,7 +116,10 @@ static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
86 116
87 sta->data_port_open = false; 117 sta->data_port_open = false;
88 if (sta->status != wil_sta_unused) { 118 if (sta->status != wil_sta_unused) {
89 wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING); 119 if (!from_event)
120 wmi_disconnect_sta(wil, sta->addr,
121 WLAN_REASON_DEAUTH_LEAVING);
122
90 switch (wdev->iftype) { 123 switch (wdev->iftype) {
91 case NL80211_IFTYPE_AP: 124 case NL80211_IFTYPE_AP:
92 case NL80211_IFTYPE_P2P_GO: 125 case NL80211_IFTYPE_P2P_GO:
@@ -118,7 +151,8 @@ static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
118 memset(&sta->stats, 0, sizeof(sta->stats)); 151 memset(&sta->stats, 0, sizeof(sta->stats));
119} 152}
120 153
121static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid) 154static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
155 bool from_event)
122{ 156{
123 int cid = -ENOENT; 157 int cid = -ENOENT;
124 struct net_device *ndev = wil_to_ndev(wil); 158 struct net_device *ndev = wil_to_ndev(wil);
@@ -133,10 +167,10 @@ static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
133 } 167 }
134 168
135 if (cid >= 0) /* disconnect 1 peer */ 169 if (cid >= 0) /* disconnect 1 peer */
136 wil_disconnect_cid(wil, cid); 170 wil_disconnect_cid(wil, cid, from_event);
137 else /* disconnect all */ 171 else /* disconnect all */
138 for (cid = 0; cid < WIL6210_MAX_CID; cid++) 172 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
139 wil_disconnect_cid(wil, cid); 173 wil_disconnect_cid(wil, cid, from_event);
140 174
141 /* link state */ 175 /* link state */
142 switch (wdev->iftype) { 176 switch (wdev->iftype) {
@@ -166,7 +200,7 @@ static void wil_disconnect_worker(struct work_struct *work)
166 struct wil6210_priv, disconnect_worker); 200 struct wil6210_priv, disconnect_worker);
167 201
168 mutex_lock(&wil->mutex); 202 mutex_lock(&wil->mutex);
169 _wil6210_disconnect(wil, NULL); 203 _wil6210_disconnect(wil, NULL, false);
170 mutex_unlock(&wil->mutex); 204 mutex_unlock(&wil->mutex);
171} 205}
172 206
@@ -223,6 +257,11 @@ static void wil_fw_error_worker(struct work_struct *work)
223 257
224 wil_dbg_misc(wil, "fw error worker\n"); 258 wil_dbg_misc(wil, "fw error worker\n");
225 259
260 if (!netif_running(wil_to_ndev(wil))) {
261 wil_info(wil, "No recovery - interface is down\n");
262 return;
263 }
264
226 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO 265 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
227 * passed since last recovery attempt 266 * passed since last recovery attempt
228 */ 267 */
@@ -257,9 +296,12 @@ static void wil_fw_error_worker(struct work_struct *work)
257 break; 296 break;
258 case NL80211_IFTYPE_AP: 297 case NL80211_IFTYPE_AP:
259 case NL80211_IFTYPE_P2P_GO: 298 case NL80211_IFTYPE_P2P_GO:
299 wil_info(wil, "No recovery for AP-like interface\n");
260 /* recovery in these modes is done by upper layers */ 300 /* recovery in these modes is done by upper layers */
261 break; 301 break;
262 default: 302 default:
303 wil_err(wil, "No recovery - unknown interface type %d\n",
304 wdev->iftype);
263 break; 305 break;
264 } 306 }
265 mutex_unlock(&wil->mutex); 307 mutex_unlock(&wil->mutex);
@@ -346,12 +388,22 @@ int wil_priv_init(struct wil6210_priv *wil)
346 return 0; 388 return 0;
347} 389}
348 390
349void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid) 391/**
392 * wil6210_disconnect - disconnect one connection
393 * @wil: driver context
394 * @bssid: peer to disconnect, NULL to disconnect all
395 * @from_event: whether is invoked from FW event handler
396 *
397 * Disconnect and release associated resources. If invoked not from the
398 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
399 */
400void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
401 bool from_event)
350{ 402{
351 wil_dbg_misc(wil, "%s()\n", __func__); 403 wil_dbg_misc(wil, "%s()\n", __func__);
352 404
353 del_timer_sync(&wil->connect_timer); 405 del_timer_sync(&wil->connect_timer);
354 _wil6210_disconnect(wil, bssid); 406 _wil6210_disconnect(wil, bssid, from_event);
355} 407}
356 408
357void wil_priv_deinit(struct wil6210_priv *wil) 409void wil_priv_deinit(struct wil6210_priv *wil)
@@ -363,7 +415,7 @@ void wil_priv_deinit(struct wil6210_priv *wil)
363 cancel_work_sync(&wil->disconnect_worker); 415 cancel_work_sync(&wil->disconnect_worker);
364 cancel_work_sync(&wil->fw_error_worker); 416 cancel_work_sync(&wil->fw_error_worker);
365 mutex_lock(&wil->mutex); 417 mutex_lock(&wil->mutex);
366 wil6210_disconnect(wil, NULL); 418 wil6210_disconnect(wil, NULL, false);
367 mutex_unlock(&wil->mutex); 419 mutex_unlock(&wil->mutex);
368 wmi_event_flush(wil); 420 wmi_event_flush(wil);
369 destroy_workqueue(wil->wmi_wq_conn); 421 destroy_workqueue(wil->wmi_wq_conn);
@@ -395,7 +447,7 @@ static inline void wil_release_cpu(struct wil6210_priv *wil)
395static int wil_target_reset(struct wil6210_priv *wil) 447static int wil_target_reset(struct wil6210_priv *wil)
396{ 448{
397 int delay = 0; 449 int delay = 0;
398 u32 hw_state; 450 u32 x;
399 u32 rev_id; 451 u32 rev_id;
400 bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW); 452 bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
401 453
@@ -410,9 +462,22 @@ static int wil_target_reset(struct wil6210_priv *wil)
410 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST); 462 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
411 463
412 wil_halt_cpu(wil); 464 wil_halt_cpu(wil);
413 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL); /* 40 MHz */
414 465
415 if (is_sparrow) { 466 if (is_sparrow) {
467 S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
468 /* XTAL stabilization should take about 3ms */
469 usleep_range(5000, 7000);
470 x = R(RGF_CAF_PLL_LOCK_STATUS);
471 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
472 wil_err(wil, "Xtal stabilization timeout\n"
473 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
474 return -ETIME;
475 }
476 /* switch 10k to XTAL*/
477 C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
478 /* 40 MHz */
479 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
480
416 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f); 481 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
417 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf); 482 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
418 } 483 }
@@ -453,13 +518,13 @@ static int wil_target_reset(struct wil6210_priv *wil)
453 /* wait until device ready. typical time is 200..250 msec */ 518 /* wait until device ready. typical time is 200..250 msec */
454 do { 519 do {
455 msleep(RST_DELAY); 520 msleep(RST_DELAY);
456 hw_state = R(RGF_USER_HW_MACHINE_STATE); 521 x = R(RGF_USER_HW_MACHINE_STATE);
457 if (delay++ > RST_COUNT) { 522 if (delay++ > RST_COUNT) {
458 wil_err(wil, "Reset not completed, hw_state 0x%08x\n", 523 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
459 hw_state); 524 x);
460 return -ETIME; 525 return -ETIME;
461 } 526 }
462 } while (hw_state != HW_MACHINE_BOOT_DONE); 527 } while (x != HW_MACHINE_BOOT_DONE);
463 528
464 /* TODO: Erez check rev_id != 1 */ 529 /* TODO: Erez check rev_id != 1 */
465 if (!is_sparrow && (rev_id != 1)) 530 if (!is_sparrow && (rev_id != 1))
@@ -535,7 +600,7 @@ int wil_reset(struct wil6210_priv *wil)
535 WARN_ON(test_bit(wil_status_napi_en, &wil->status)); 600 WARN_ON(test_bit(wil_status_napi_en, &wil->status));
536 601
537 cancel_work_sync(&wil->disconnect_worker); 602 cancel_work_sync(&wil->disconnect_worker);
538 wil6210_disconnect(wil, NULL); 603 wil6210_disconnect(wil, NULL, false);
539 604
540 wil->status = 0; /* prevent NAPI from being scheduled */ 605 wil->status = 0; /* prevent NAPI from being scheduled */
541 606
diff --git a/drivers/net/wireless/ath/wil6210/netdev.c b/drivers/net/wireless/ath/wil6210/netdev.c
index 239965106c05..e81703ca7701 100644
--- a/drivers/net/wireless/ath/wil6210/netdev.c
+++ b/drivers/net/wireless/ath/wil6210/netdev.c
@@ -41,7 +41,7 @@ static int wil_change_mtu(struct net_device *ndev, int new_mtu)
41{ 41{
42 struct wil6210_priv *wil = ndev_to_wil(ndev); 42 struct wil6210_priv *wil = ndev_to_wil(ndev);
43 43
44 if (new_mtu < 68 || new_mtu > (TX_BUF_LEN - ETH_HLEN)) { 44 if (new_mtu < 68 || new_mtu > mtu_max) {
45 wil_err(wil, "invalid MTU %d\n", new_mtu); 45 wil_err(wil, "invalid MTU %d\n", new_mtu);
46 return -EINVAL; 46 return -EINVAL;
47 } 47 }
diff --git a/drivers/net/wireless/ath/wil6210/txrx.c b/drivers/net/wireless/ath/wil6210/txrx.c
index 2936ef0c18cb..c680906bc0dc 100644
--- a/drivers/net/wireless/ath/wil6210/txrx.c
+++ b/drivers/net/wireless/ath/wil6210/txrx.c
@@ -206,7 +206,7 @@ static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct vring *vring,
206 u32 i, int headroom) 206 u32 i, int headroom)
207{ 207{
208 struct device *dev = wil_to_dev(wil); 208 struct device *dev = wil_to_dev(wil);
209 unsigned int sz = RX_BUF_LEN; 209 unsigned int sz = mtu_max + ETH_HLEN;
210 struct vring_rx_desc dd, *d = &dd; 210 struct vring_rx_desc dd, *d = &dd;
211 volatile struct vring_rx_desc *_d = &vring->va[i].rx; 211 volatile struct vring_rx_desc *_d = &vring->va[i].rx;
212 dma_addr_t pa; 212 dma_addr_t pa;
@@ -385,7 +385,7 @@ static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil,
385 struct vring_rx_desc *d; 385 struct vring_rx_desc *d;
386 struct sk_buff *skb; 386 struct sk_buff *skb;
387 dma_addr_t pa; 387 dma_addr_t pa;
388 unsigned int sz = RX_BUF_LEN; 388 unsigned int sz = mtu_max + ETH_HLEN;
389 u16 dmalen; 389 u16 dmalen;
390 u8 ftype; 390 u8 ftype;
391 u8 ds_bits; 391 u8 ds_bits;
@@ -646,7 +646,8 @@ int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
646 .action = cpu_to_le32(WMI_VRING_CMD_ADD), 646 .action = cpu_to_le32(WMI_VRING_CMD_ADD),
647 .vring_cfg = { 647 .vring_cfg = {
648 .tx_sw_ring = { 648 .tx_sw_ring = {
649 .max_mpdu_size = cpu_to_le16(TX_BUF_LEN), 649 .max_mpdu_size =
650 cpu_to_le16(mtu_max + ETH_HLEN),
650 .ring_size = cpu_to_le16(size), 651 .ring_size = cpu_to_le16(size),
651 }, 652 },
652 .ringid = id, 653 .ringid = id,
diff --git a/drivers/net/wireless/ath/wil6210/txrx.h b/drivers/net/wireless/ath/wil6210/txrx.h
index de046716d2b7..630aeb5fa7f4 100644
--- a/drivers/net/wireless/ath/wil6210/txrx.h
+++ b/drivers/net/wireless/ath/wil6210/txrx.h
@@ -21,8 +21,8 @@
21#define BUF_HW_OWNED (0) 21#define BUF_HW_OWNED (0)
22 22
23/* size of max. Tx/Rx buffers, as supported by FW */ 23/* size of max. Tx/Rx buffers, as supported by FW */
24#define RX_BUF_LEN (2242) 24#define TXRX_BUF_LEN_DEFAULT (2242)
25#define TX_BUF_LEN (2242) 25
26/* how many bytes to reserve for rtap header? */ 26/* how many bytes to reserve for rtap header? */
27#define WIL6210_RTAP_SIZE (128) 27#define WIL6210_RTAP_SIZE (128)
28 28
diff --git a/drivers/net/wireless/ath/wil6210/wil6210.h b/drivers/net/wireless/ath/wil6210/wil6210.h
index ce6488e42091..95d3a062d35c 100644
--- a/drivers/net/wireless/ath/wil6210/wil6210.h
+++ b/drivers/net/wireless/ath/wil6210/wil6210.h
@@ -24,6 +24,7 @@
24#include "wil_platform.h" 24#include "wil_platform.h"
25 25
26extern bool no_fw_recovery; 26extern bool no_fw_recovery;
27extern unsigned int mtu_max;
27 28
28#define WIL_NAME "wil6210" 29#define WIL_NAME "wil6210"
29#define WIL_FW_NAME "wil6210.fw" 30#define WIL_FW_NAME "wil6210.fw"
@@ -117,6 +118,8 @@ struct RGF_ICR {
117 #define BIT_USER_USER_ICR_SW_INT_2 BIT(18) 118 #define BIT_USER_USER_ICR_SW_INT_2 BIT(18)
118#define RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0 (0x880c18) 119#define RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0 (0x880c18)
119#define RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1 (0x880c2c) 120#define RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1 (0x880c2c)
121#define RGF_USER_SPARROW_M_4 (0x880c50) /* Sparrow */
122 #define BIT_SPARROW_M_4_SEL_SLEEP_OR_REF BIT(2)
120 123
121#define RGF_DMA_EP_TX_ICR (0x881bb4) /* struct RGF_ICR */ 124#define RGF_DMA_EP_TX_ICR (0x881bb4) /* struct RGF_ICR */
122 #define BIT_DMA_EP_TX_ICR_TX_DONE BIT(0) 125 #define BIT_DMA_EP_TX_ICR_TX_DONE BIT(0)
@@ -152,6 +155,10 @@ struct RGF_ICR {
152#define RGF_MAC_MTRL_COUNTER_0 (0x886aa8) 155#define RGF_MAC_MTRL_COUNTER_0 (0x886aa8)
153 156
154#define RGF_CAF_ICR (0x88946c) /* struct RGF_ICR */ 157#define RGF_CAF_ICR (0x88946c) /* struct RGF_ICR */
158#define RGF_CAF_OSC_CONTROL (0x88afa4)
159 #define BIT_CAF_OSC_XTAL_EN BIT(0)
160#define RGF_CAF_PLL_LOCK_STATUS (0x88afec)
161 #define BIT_CAF_OSC_DIG_XTAL_STABLE BIT(0)
155 162
156/* popular locations */ 163/* popular locations */
157#define HOST_MBOX HOSTADDR(RGF_USER_USER_SCRATCH_PAD) 164#define HOST_MBOX HOSTADDR(RGF_USER_USER_SCRATCH_PAD)
@@ -463,8 +470,11 @@ struct wil6210_priv {
463#define ndev_to_wil(n) (wdev_to_wil(n->ieee80211_ptr)) 470#define ndev_to_wil(n) (wdev_to_wil(n->ieee80211_ptr))
464#define wil_to_pcie_dev(i) (&i->pdev->dev) 471#define wil_to_pcie_dev(i) (&i->pdev->dev)
465 472
473__printf(2, 3)
466void wil_dbg_trace(struct wil6210_priv *wil, const char *fmt, ...); 474void wil_dbg_trace(struct wil6210_priv *wil, const char *fmt, ...);
475__printf(2, 3)
467void wil_err(struct wil6210_priv *wil, const char *fmt, ...); 476void wil_err(struct wil6210_priv *wil, const char *fmt, ...);
477__printf(2, 3)
468void wil_info(struct wil6210_priv *wil, const char *fmt, ...); 478void wil_info(struct wil6210_priv *wil, const char *fmt, ...);
469#define wil_dbg(wil, fmt, arg...) do { \ 479#define wil_dbg(wil, fmt, arg...) do { \
470 netdev_dbg(wil_to_ndev(wil), fmt, ##arg); \ 480 netdev_dbg(wil_to_ndev(wil), fmt, ##arg); \
@@ -575,7 +585,8 @@ void wil_wdev_free(struct wil6210_priv *wil);
575int wmi_set_mac_address(struct wil6210_priv *wil, void *addr); 585int wmi_set_mac_address(struct wil6210_priv *wil, void *addr);
576int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, u8 chan); 586int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, u8 chan);
577int wmi_pcp_stop(struct wil6210_priv *wil); 587int wmi_pcp_stop(struct wil6210_priv *wil);
578void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid); 588void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
589 bool from_event);
579 590
580int wil_rx_init(struct wil6210_priv *wil); 591int wil_rx_init(struct wil6210_priv *wil);
581void wil_rx_fini(struct wil6210_priv *wil); 592void wil_rx_fini(struct wil6210_priv *wil);
diff --git a/drivers/net/wireless/ath/wil6210/wmi.c b/drivers/net/wireless/ath/wil6210/wmi.c
index 4311df982c60..bb1e066f756a 100644
--- a/drivers/net/wireless/ath/wil6210/wmi.c
+++ b/drivers/net/wireless/ath/wil6210/wmi.c
@@ -486,7 +486,7 @@ static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
486 wil->sinfo_gen++; 486 wil->sinfo_gen++;
487 487
488 mutex_lock(&wil->mutex); 488 mutex_lock(&wil->mutex);
489 wil6210_disconnect(wil, evt->bssid); 489 wil6210_disconnect(wil, evt->bssid, true);
490 mutex_unlock(&wil->mutex); 490 mutex_unlock(&wil->mutex);
491} 491}
492 492
@@ -1025,7 +1025,7 @@ int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
1025 struct wmi_cfg_rx_chain_cmd cmd = { 1025 struct wmi_cfg_rx_chain_cmd cmd = {
1026 .action = WMI_RX_CHAIN_ADD, 1026 .action = WMI_RX_CHAIN_ADD,
1027 .rx_sw_ring = { 1027 .rx_sw_ring = {
1028 .max_mpdu_size = cpu_to_le16(RX_BUF_LEN), 1028 .max_mpdu_size = cpu_to_le16(mtu_max + ETH_HLEN),
1029 .ring_mem_base = cpu_to_le64(vring->pa), 1029 .ring_mem_base = cpu_to_le64(vring->pa),
1030 .ring_size = cpu_to_le16(vring->size), 1030 .ring_size = cpu_to_le16(vring->size),
1031 }, 1031 },
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/Makefile b/drivers/net/wireless/brcm80211/brcmfmac/Makefile
index 90a977fe9a64..dc4c75083085 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/Makefile
+++ b/drivers/net/wireless/brcm80211/brcmfmac/Makefile
@@ -23,15 +23,15 @@ ccflags-y += -D__CHECK_ENDIAN__
23 23
24obj-$(CONFIG_BRCMFMAC) += brcmfmac.o 24obj-$(CONFIG_BRCMFMAC) += brcmfmac.o
25brcmfmac-objs += \ 25brcmfmac-objs += \
26 wl_cfg80211.o \ 26 cfg80211.o \
27 chip.o \ 27 chip.o \
28 fwil.o \ 28 fwil.o \
29 fweh.o \ 29 fweh.o \
30 fwsignal.o \ 30 fwsignal.o \
31 p2p.o \ 31 p2p.o \
32 proto.o \ 32 proto.o \
33 dhd_common.o \ 33 common.o \
34 dhd_linux.o \ 34 core.o \
35 firmware.o \ 35 firmware.o \
36 feature.o \ 36 feature.o \
37 btcoex.o \ 37 btcoex.o \
@@ -43,14 +43,14 @@ brcmfmac-$(CONFIG_BRCMFMAC_PROTO_MSGBUF) += \
43 flowring.o \ 43 flowring.o \
44 msgbuf.o 44 msgbuf.o
45brcmfmac-$(CONFIG_BRCMFMAC_SDIO) += \ 45brcmfmac-$(CONFIG_BRCMFMAC_SDIO) += \
46 dhd_sdio.o \ 46 sdio.o \
47 bcmsdh.o 47 bcmsdh.o
48brcmfmac-$(CONFIG_BRCMFMAC_USB) += \ 48brcmfmac-$(CONFIG_BRCMFMAC_USB) += \
49 usb.o 49 usb.o
50brcmfmac-$(CONFIG_BRCMFMAC_PCIE) += \ 50brcmfmac-$(CONFIG_BRCMFMAC_PCIE) += \
51 pcie.o 51 pcie.o
52brcmfmac-$(CONFIG_BRCMDBG) += \ 52brcmfmac-$(CONFIG_BRCMDBG) += \
53 dhd_dbg.o 53 debug.o
54brcmfmac-$(CONFIG_BRCM_TRACING) += \ 54brcmfmac-$(CONFIG_BRCM_TRACING) += \
55 tracepoint.o 55 tracepoint.o
56brcmfmac-$(CONFIG_OF) += \ 56brcmfmac-$(CONFIG_OF) += \
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcdc.c b/drivers/net/wireless/brcm80211/brcmfmac/bcdc.c
index a159ff3427de..8e0e91c4a0b1 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcdc.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcdc.c
@@ -25,10 +25,10 @@
25#include <brcmu_utils.h> 25#include <brcmu_utils.h>
26#include <brcmu_wifi.h> 26#include <brcmu_wifi.h>
27 27
28#include "dhd.h" 28#include "core.h"
29#include "dhd_bus.h" 29#include "bus.h"
30#include "fwsignal.h" 30#include "fwsignal.h"
31#include "dhd_dbg.h" 31#include "debug.h"
32#include "tracepoint.h" 32#include "tracepoint.h"
33#include "proto.h" 33#include "proto.h"
34#include "bcdc.h" 34#include "bcdc.h"
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
index 8dbd5dbb78fd..f754ffcd0308 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
@@ -41,9 +41,9 @@
41#include <chipcommon.h> 41#include <chipcommon.h>
42#include <soc.h> 42#include <soc.h>
43#include "chip.h" 43#include "chip.h"
44#include "dhd_bus.h" 44#include "bus.h"
45#include "dhd_dbg.h" 45#include "debug.h"
46#include "sdio_host.h" 46#include "sdio.h"
47#include "of.h" 47#include "of.h"
48 48
49#define SDIOH_API_ACCESS_RETRY_LIMIT 2 49#define SDIOH_API_ACCESS_RETRY_LIMIT 2
@@ -1064,6 +1064,16 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
1064 if (!sdiodev->pdata) 1064 if (!sdiodev->pdata)
1065 brcmf_of_probe(sdiodev); 1065 brcmf_of_probe(sdiodev);
1066 1066
1067#ifdef CONFIG_PM_SLEEP
1068 /* wowl can be supported when KEEP_POWER is true and (WAKE_SDIO_IRQ
1069 * is true or when platform data OOB irq is true).
1070 */
1071 if ((sdio_get_host_pm_caps(sdiodev->func[1]) & MMC_PM_KEEP_POWER) &&
1072 ((sdio_get_host_pm_caps(sdiodev->func[1]) & MMC_PM_WAKE_SDIO_IRQ) ||
1073 (sdiodev->pdata->oob_irq_supported)))
1074 bus_if->wowl_supported = true;
1075#endif
1076
1067 atomic_set(&sdiodev->suspend, false); 1077 atomic_set(&sdiodev->suspend, false);
1068 init_waitqueue_head(&sdiodev->request_word_wait); 1078 init_waitqueue_head(&sdiodev->request_word_wait);
1069 init_waitqueue_head(&sdiodev->request_buffer_wait); 1079 init_waitqueue_head(&sdiodev->request_buffer_wait);
@@ -1116,34 +1126,39 @@ static void brcmf_ops_sdio_remove(struct sdio_func *func)
1116 brcmf_dbg(SDIO, "Exit\n"); 1126 brcmf_dbg(SDIO, "Exit\n");
1117} 1127}
1118 1128
1129void brcmf_sdio_wowl_config(struct device *dev, bool enabled)
1130{
1131 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
1132 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
1133
1134 brcmf_dbg(SDIO, "Configuring WOWL, enabled=%d\n", enabled);
1135 sdiodev->wowl_enabled = enabled;
1136}
1137
1119#ifdef CONFIG_PM_SLEEP 1138#ifdef CONFIG_PM_SLEEP
1120static int brcmf_ops_sdio_suspend(struct device *dev) 1139static int brcmf_ops_sdio_suspend(struct device *dev)
1121{ 1140{
1122 mmc_pm_flag_t sdio_flags;
1123 struct brcmf_bus *bus_if = dev_get_drvdata(dev); 1141 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
1124 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; 1142 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
1125 int ret = 0; 1143 mmc_pm_flag_t sdio_flags;
1126 1144
1127 brcmf_dbg(SDIO, "Enter\n"); 1145 brcmf_dbg(SDIO, "Enter\n");
1128 1146
1129 sdio_flags = sdio_get_host_pm_caps(sdiodev->func[1]);
1130 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
1131 brcmf_err("Host can't keep power while suspended\n");
1132 return -EINVAL;
1133 }
1134
1135 atomic_set(&sdiodev->suspend, true); 1147 atomic_set(&sdiodev->suspend, true);
1136 1148
1137 ret = sdio_set_host_pm_flags(sdiodev->func[1], MMC_PM_KEEP_POWER); 1149 if (sdiodev->wowl_enabled) {
1138 if (ret) { 1150 sdio_flags = MMC_PM_KEEP_POWER;
1139 brcmf_err("Failed to set pm_flags\n"); 1151 if (sdiodev->pdata->oob_irq_supported)
1140 atomic_set(&sdiodev->suspend, false); 1152 enable_irq_wake(sdiodev->pdata->oob_irq_nr);
1141 return ret; 1153 else
1154 sdio_flags = MMC_PM_WAKE_SDIO_IRQ;
1155 if (sdio_set_host_pm_flags(sdiodev->func[1], sdio_flags))
1156 brcmf_err("Failed to set pm_flags %x\n", sdio_flags);
1142 } 1157 }
1143 1158
1144 brcmf_sdio_wd_timer(sdiodev->bus, 0); 1159 brcmf_sdio_wd_timer(sdiodev->bus, 0);
1145 1160
1146 return ret; 1161 return 0;
1147} 1162}
1148 1163
1149static int brcmf_ops_sdio_resume(struct device *dev) 1164static int brcmf_ops_sdio_resume(struct device *dev)
@@ -1152,6 +1167,8 @@ static int brcmf_ops_sdio_resume(struct device *dev)
1152 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; 1167 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
1153 1168
1154 brcmf_dbg(SDIO, "Enter\n"); 1169 brcmf_dbg(SDIO, "Enter\n");
1170 if (sdiodev->pdata->oob_irq_supported)
1171 disable_irq_wake(sdiodev->pdata->oob_irq_nr);
1155 brcmf_sdio_wd_timer(sdiodev->bus, BRCMF_WD_POLL_MS); 1172 brcmf_sdio_wd_timer(sdiodev->bus, BRCMF_WD_POLL_MS);
1156 atomic_set(&sdiodev->suspend, false); 1173 atomic_set(&sdiodev->suspend, false);
1157 return 0; 1174 return 0;
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/btcoex.c b/drivers/net/wireless/brcm80211/brcmfmac/btcoex.c
index a29ac4977b3a..0445163991b7 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/btcoex.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/btcoex.c
@@ -20,13 +20,13 @@
20#include <brcmu_wifi.h> 20#include <brcmu_wifi.h>
21#include <brcmu_utils.h> 21#include <brcmu_utils.h>
22#include <defs.h> 22#include <defs.h>
23#include <dhd.h> 23#include "core.h"
24#include <dhd_dbg.h> 24#include "debug.h"
25#include "fwil.h" 25#include "fwil.h"
26#include "fwil_types.h" 26#include "fwil_types.h"
27#include "btcoex.h" 27#include "btcoex.h"
28#include "p2p.h" 28#include "p2p.h"
29#include "wl_cfg80211.h" 29#include "cfg80211.h"
30 30
31/* T1 start SCO/eSCO priority suppression */ 31/* T1 start SCO/eSCO priority suppression */
32#define BRCMF_BTCOEX_OPPR_WIN_TIME 2000 32#define BRCMF_BTCOEX_OPPR_WIN_TIME 2000
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h b/drivers/net/wireless/brcm80211/brcmfmac/bus.h
index 80e73a1262be..ef344e47218a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bus.h
@@ -14,10 +14,10 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#ifndef _BRCMF_BUS_H_ 17#ifndef BRCMFMAC_BUS_H
18#define _BRCMF_BUS_H_ 18#define BRCMFMAC_BUS_H
19 19
20#include "dhd_dbg.h" 20#include "debug.h"
21 21
22/* IDs of the 6 default common rings of msgbuf protocol */ 22/* IDs of the 6 default common rings of msgbuf protocol */
23#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 0 23#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 0
@@ -227,8 +227,7 @@ void brcmf_txflowblock(struct device *dev, bool state);
227void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success); 227void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
228 228
229int brcmf_bus_start(struct device *dev); 229int brcmf_bus_start(struct device *dev);
230s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, 230s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
231 u32 len);
232void brcmf_bus_add_txhdrlen(struct device *dev, uint len); 231void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
233 232
234#ifdef CONFIG_BRCMFMAC_SDIO 233#ifdef CONFIG_BRCMFMAC_SDIO
@@ -241,4 +240,4 @@ void brcmf_usb_exit(void);
241void brcmf_usb_register(void); 240void brcmf_usb_register(void);
242#endif 241#endif
243 242
244#endif /* _BRCMF_BUS_H_ */ 243#endif /* BRCMFMAC_BUS_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
index 39b45c038a93..f8a9dfa657ba 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.c
@@ -26,18 +26,18 @@
26#include <brcmu_utils.h> 26#include <brcmu_utils.h>
27#include <defs.h> 27#include <defs.h>
28#include <brcmu_wifi.h> 28#include <brcmu_wifi.h>
29#include "dhd.h" 29#include "core.h"
30#include "dhd_dbg.h" 30#include "debug.h"
31#include "tracepoint.h" 31#include "tracepoint.h"
32#include "fwil_types.h" 32#include "fwil_types.h"
33#include "p2p.h" 33#include "p2p.h"
34#include "btcoex.h" 34#include "btcoex.h"
35#include "wl_cfg80211.h" 35#include "cfg80211.h"
36#include "feature.h" 36#include "feature.h"
37#include "fwil.h" 37#include "fwil.h"
38#include "proto.h" 38#include "proto.h"
39#include "vendor.h" 39#include "vendor.h"
40#include "dhd_bus.h" 40#include "bus.h"
41 41
42#define BRCMF_SCAN_IE_LEN_MAX 2048 42#define BRCMF_SCAN_IE_LEN_MAX 2048
43#define BRCMF_PNO_VERSION 2 43#define BRCMF_PNO_VERSION 2
@@ -2785,6 +2785,44 @@ static __always_inline void brcmf_delay(u32 ms)
2785 } 2785 }
2786} 2786}
2787 2787
2788static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
2789 u8 *pattern, u32 patternsize, u8 *mask,
2790 u32 packet_offset)
2791{
2792 struct brcmf_fil_wowl_pattern_le *filter;
2793 u32 masksize;
2794 u32 patternoffset;
2795 u8 *buf;
2796 u32 bufsize;
2797 s32 ret;
2798
2799 masksize = (patternsize + 7) / 8;
2800 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
2801
2802 bufsize = sizeof(*filter) + patternsize + masksize;
2803 buf = kzalloc(bufsize, GFP_KERNEL);
2804 if (!buf)
2805 return -ENOMEM;
2806 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
2807
2808 memcpy(filter->cmd, cmd, 4);
2809 filter->masksize = cpu_to_le32(masksize);
2810 filter->offset = cpu_to_le32(packet_offset);
2811 filter->patternoffset = cpu_to_le32(patternoffset);
2812 filter->patternsize = cpu_to_le32(patternsize);
2813 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
2814
2815 if ((mask) && (masksize))
2816 memcpy(buf + sizeof(*filter), mask, masksize);
2817 if ((pattern) && (patternsize))
2818 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
2819
2820 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
2821
2822 kfree(buf);
2823 return ret;
2824}
2825
2788static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) 2826static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
2789{ 2827{
2790 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); 2828 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
@@ -2794,10 +2832,11 @@ static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
2794 brcmf_dbg(TRACE, "Enter\n"); 2832 brcmf_dbg(TRACE, "Enter\n");
2795 2833
2796 if (cfg->wowl_enabled) { 2834 if (cfg->wowl_enabled) {
2835 brcmf_configure_arp_offload(ifp, true);
2797 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, 2836 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
2798 cfg->pre_wowl_pmmode); 2837 cfg->pre_wowl_pmmode);
2799 brcmf_fil_iovar_data_set(ifp, "wowl_pattern", "clr", 4);
2800 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); 2838 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
2839 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
2801 cfg->wowl_enabled = false; 2840 cfg->wowl_enabled = false;
2802 } 2841 }
2803 return 0; 2842 return 0;
@@ -2808,21 +2847,29 @@ static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
2808 struct cfg80211_wowlan *wowl) 2847 struct cfg80211_wowlan *wowl)
2809{ 2848{
2810 u32 wowl_config; 2849 u32 wowl_config;
2850 u32 i;
2811 2851
2812 brcmf_dbg(TRACE, "Suspend, wowl config.\n"); 2852 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
2813 2853
2854 brcmf_configure_arp_offload(ifp, false);
2814 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode); 2855 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode);
2815 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); 2856 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
2816 2857
2817 wowl_config = 0; 2858 wowl_config = 0;
2818 if (wowl->disconnect) 2859 if (wowl->disconnect)
2819 wowl_config |= WL_WOWL_DIS | WL_WOWL_BCN | WL_WOWL_RETR; 2860 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
2820 /* Note: if "wowl" target and not "wowlpf" then wowl_bcn_loss
2821 * should be configured. This paramater is not supported by
2822 * wowlpf.
2823 */
2824 if (wowl->magic_pkt) 2861 if (wowl->magic_pkt)
2825 wowl_config |= WL_WOWL_MAGIC; 2862 wowl_config |= BRCMF_WOWL_MAGIC;
2863 if ((wowl->patterns) && (wowl->n_patterns)) {
2864 wowl_config |= BRCMF_WOWL_NET;
2865 for (i = 0; i < wowl->n_patterns; i++) {
2866 brcmf_config_wowl_pattern(ifp, "add",
2867 (u8 *)wowl->patterns[i].pattern,
2868 wowl->patterns[i].pattern_len,
2869 (u8 *)wowl->patterns[i].mask,
2870 wowl->patterns[i].pkt_offset);
2871 }
2872 }
2826 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); 2873 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
2827 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); 2874 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
2828 brcmf_bus_wowl_config(cfg->pub->bus_if, true); 2875 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
@@ -4004,24 +4051,24 @@ brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4004 4051
4005static int 4052static int
4006brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, 4053brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
4007 const u8 *mac) 4054 struct station_del_parameters *params)
4008{ 4055{
4009 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); 4056 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4010 struct brcmf_scb_val_le scbval; 4057 struct brcmf_scb_val_le scbval;
4011 struct brcmf_if *ifp = netdev_priv(ndev); 4058 struct brcmf_if *ifp = netdev_priv(ndev);
4012 s32 err; 4059 s32 err;
4013 4060
4014 if (!mac) 4061 if (!params->mac)
4015 return -EFAULT; 4062 return -EFAULT;
4016 4063
4017 brcmf_dbg(TRACE, "Enter %pM\n", mac); 4064 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
4018 4065
4019 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) 4066 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4020 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; 4067 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
4021 if (!check_vif_up(ifp->vif)) 4068 if (!check_vif_up(ifp->vif))
4022 return -EIO; 4069 return -EIO;
4023 4070
4024 memcpy(&scbval.ea, mac, ETH_ALEN); 4071 memcpy(&scbval.ea, params->mac, ETH_ALEN);
4025 scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING); 4072 scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING);
4026 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON, 4073 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
4027 &scbval, sizeof(scbval)); 4074 &scbval, sizeof(scbval));
@@ -5446,10 +5493,13 @@ static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
5446 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; 5493 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
5447} 5494}
5448 5495
5449
5450#ifdef CONFIG_PM 5496#ifdef CONFIG_PM
5451static const struct wiphy_wowlan_support brcmf_wowlan_support = { 5497static const struct wiphy_wowlan_support brcmf_wowlan_support = {
5452 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, 5498 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
5499 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
5500 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
5501 .pattern_min_len = 1,
5502 .max_pkt_offset = 1500,
5453}; 5503};
5454#endif 5504#endif
5455 5505
@@ -5613,7 +5663,8 @@ enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
5613 return wdev->iftype; 5663 return wdev->iftype;
5614} 5664}
5615 5665
5616bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, unsigned long state) 5666bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
5667 unsigned long state)
5617{ 5668{
5618 struct brcmf_cfg80211_vif *vif; 5669 struct brcmf_cfg80211_vif *vif;
5619 5670
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.h
index 6abf94e41d3d..2a5b22cb3fef 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/cfg80211.h
@@ -14,8 +14,8 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#ifndef _wl_cfg80211_h_ 17#ifndef BRCMFMAC_CFG80211_H
18#define _wl_cfg80211_h_ 18#define BRCMFMAC_CFG80211_H
19 19
20/* for brcmu_d11inf */ 20/* for brcmu_d11inf */
21#include <brcmu_d11.h> 21#include <brcmu_d11.h>
@@ -480,7 +480,8 @@ const struct brcmf_tlv *
480brcmf_parse_tlvs(const void *buf, int buflen, uint key); 480brcmf_parse_tlvs(const void *buf, int buflen, uint key);
481u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, 481u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
482 struct ieee80211_channel *ch); 482 struct ieee80211_channel *ch);
483bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, unsigned long state); 483bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
484 unsigned long state);
484void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, 485void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
485 struct brcmf_cfg80211_vif *vif); 486 struct brcmf_cfg80211_vif *vif);
486bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg); 487bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
@@ -493,4 +494,4 @@ void brcmf_set_mpc(struct brcmf_if *ndev, int mpc);
493void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg); 494void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
494void brcmf_cfg80211_free_netdev(struct net_device *ndev); 495void brcmf_cfg80211_free_netdev(struct net_device *ndev);
495 496
496#endif /* _wl_cfg80211_h_ */ 497#endif /* BRCMFMAC_CFG80211_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/brcm80211/brcmfmac/chip.c
index 95efde868db8..ddae0b5e56ec 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/chip.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/chip.c
@@ -25,7 +25,7 @@
25#include <brcm_hw_ids.h> 25#include <brcm_hw_ids.h>
26#include <brcmu_utils.h> 26#include <brcmu_utils.h>
27#include <chipcommon.h> 27#include <chipcommon.h>
28#include "dhd_dbg.h" 28#include "debug.h"
29#include "chip.h" 29#include "chip.h"
30 30
31/* SOC Interconnect types (aka chip types) */ 31/* SOC Interconnect types (aka chip types) */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/common.c b/drivers/net/wireless/brcm80211/brcmfmac/common.c
new file mode 100644
index 000000000000..1861a13e8d03
--- /dev/null
+++ b/drivers/net/wireless/brcm80211/brcmfmac/common.c
@@ -0,0 +1,168 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/kernel.h>
18#include <linux/string.h>
19#include <linux/netdevice.h>
20#include <brcmu_wifi.h>
21#include <brcmu_utils.h>
22#include "core.h"
23#include "bus.h"
24#include "debug.h"
25#include "fwil.h"
26#include "fwil_types.h"
27#include "tracepoint.h"
28
29#define BRCMF_DEFAULT_BCN_TIMEOUT 3
30#define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
31#define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
32
33/* boost value for RSSI_DELTA in preferred join selection */
34#define BRCMF_JOIN_PREF_RSSI_BOOST 8
35
36int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
37{
38 s8 eventmask[BRCMF_EVENTING_MASK_LEN];
39 u8 buf[BRCMF_DCMD_SMLEN];
40 struct brcmf_join_pref_params join_pref_params[2];
41 char *ptr;
42 s32 err;
43
44 /* retreive mac address */
45 err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
46 sizeof(ifp->mac_addr));
47 if (err < 0) {
48 brcmf_err("Retreiving cur_etheraddr failed, %d\n",
49 err);
50 goto done;
51 }
52 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
53
54 /* query for 'ver' to get version info from firmware */
55 memset(buf, 0, sizeof(buf));
56 strcpy(buf, "ver");
57 err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
58 if (err < 0) {
59 brcmf_err("Retreiving version information failed, %d\n",
60 err);
61 goto done;
62 }
63 ptr = (char *)buf;
64 strsep(&ptr, "\n");
65
66 /* Print fw version info */
67 brcmf_err("Firmware version = %s\n", buf);
68
69 /* locate firmware version number for ethtool */
70 ptr = strrchr(buf, ' ') + 1;
71 strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
72
73 /* set mpc */
74 err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
75 if (err) {
76 brcmf_err("failed setting mpc\n");
77 goto done;
78 }
79
80 /*
81 * Setup timeout if Beacons are lost and roam is off to report
82 * link down
83 */
84 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout",
85 BRCMF_DEFAULT_BCN_TIMEOUT);
86 if (err) {
87 brcmf_err("bcn_timeout error (%d)\n", err);
88 goto done;
89 }
90
91 /* Enable/Disable build-in roaming to allowed ext supplicant to take
92 * of romaing
93 */
94 err = brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
95 if (err) {
96 brcmf_err("roam_off error (%d)\n", err);
97 goto done;
98 }
99
100 /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
101 join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
102 join_pref_params[0].len = 2;
103 join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
104 join_pref_params[0].band = WLC_BAND_5G;
105 join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
106 join_pref_params[1].len = 2;
107 join_pref_params[1].rssi_gain = 0;
108 join_pref_params[1].band = 0;
109 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
110 sizeof(join_pref_params));
111 if (err)
112 brcmf_err("Set join_pref error (%d)\n", err);
113
114 /* Setup event_msgs, enable E_IF */
115 err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
116 BRCMF_EVENTING_MASK_LEN);
117 if (err) {
118 brcmf_err("Get event_msgs error (%d)\n", err);
119 goto done;
120 }
121 setbit(eventmask, BRCMF_E_IF);
122 err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
123 BRCMF_EVENTING_MASK_LEN);
124 if (err) {
125 brcmf_err("Set event_msgs error (%d)\n", err);
126 goto done;
127 }
128
129 /* Setup default scan channel time */
130 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
131 BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
132 if (err) {
133 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
134 err);
135 goto done;
136 }
137
138 /* Setup default scan unassoc time */
139 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
140 BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
141 if (err) {
142 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
143 err);
144 goto done;
145 }
146
147 /* do bus specific preinit here */
148 err = brcmf_bus_preinit(ifp->drvr->bus_if);
149done:
150 return err;
151}
152
153#if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
154void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
155{
156 struct va_format vaf = {
157 .fmt = fmt,
158 };
159 va_list args;
160
161 va_start(args, fmt);
162 vaf.va = &args;
163 if (brcmf_msg_level & level)
164 pr_debug("%s %pV", func, &vaf);
165 trace_brcmf_dbg(level, func, &vaf);
166 va_end(args);
167}
168#endif
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/commonring.c b/drivers/net/wireless/brcm80211/brcmfmac/commonring.c
index c6d65b8e1e15..77656c711bed 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/commonring.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/commonring.c
@@ -19,7 +19,7 @@
19#include <brcmu_utils.h> 19#include <brcmu_utils.h>
20#include <brcmu_wifi.h> 20#include <brcmu_wifi.h>
21 21
22#include "dhd.h" 22#include "core.h"
23#include "commonring.h" 23#include "commonring.h"
24 24
25 25
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c b/drivers/net/wireless/brcm80211/brcmfmac/core.c
index fb1043908a23..f407665cb1ea 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/core.c
@@ -22,12 +22,12 @@
22#include <brcmu_utils.h> 22#include <brcmu_utils.h>
23#include <brcmu_wifi.h> 23#include <brcmu_wifi.h>
24 24
25#include "dhd.h" 25#include "core.h"
26#include "dhd_bus.h" 26#include "bus.h"
27#include "dhd_dbg.h" 27#include "debug.h"
28#include "fwil_types.h" 28#include "fwil_types.h"
29#include "p2p.h" 29#include "p2p.h"
30#include "wl_cfg80211.h" 30#include "cfg80211.h"
31#include "fwil.h" 31#include "fwil.h"
32#include "fwsignal.h" 32#include "fwsignal.h"
33#include "feature.h" 33#include "feature.h"
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd.h b/drivers/net/wireless/brcm80211/brcmfmac/core.h
index 5e4317dbc2b0..98228e922d3a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/core.h
@@ -18,8 +18,8 @@
18 * Common types * 18 * Common types *
19 */ 19 */
20 20
21#ifndef _BRCMF_H_ 21#ifndef BRCMFMAC_CORE_H
22#define _BRCMF_H_ 22#define BRCMFMAC_CORE_H
23 23
24#include "fweh.h" 24#include "fweh.h"
25 25
@@ -83,7 +83,6 @@ struct brcmf_pub {
83 /* Internal brcmf items */ 83 /* Internal brcmf items */
84 uint hdrlen; /* Total BRCMF header length (proto + bus) */ 84 uint hdrlen; /* Total BRCMF header length (proto + bus) */
85 uint rxsz; /* Rx buffer size bus module should use */ 85 uint rxsz; /* Rx buffer size bus module should use */
86 u8 wme_dp; /* wme discard priority */
87 86
88 /* Dongle media info */ 87 /* Dongle media info */
89 char fwver[BRCMF_DRIVER_FIRMWARE_VERSION_LEN]; 88 char fwver[BRCMF_DRIVER_FIRMWARE_VERSION_LEN];
@@ -186,4 +185,4 @@ void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb);
186/* Sets dongle media info (drv_version, mac address). */ 185/* Sets dongle media info (drv_version, mac address). */
187int brcmf_c_preinit_dcmds(struct brcmf_if *ifp); 186int brcmf_c_preinit_dcmds(struct brcmf_if *ifp);
188 187
189#endif /* _BRCMF_H_ */ 188#endif /* BRCMFMAC_CORE_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c b/drivers/net/wireless/brcm80211/brcmfmac/debug.c
index be9f4f829192..9b473d50b005 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/debug.c
@@ -19,9 +19,9 @@
19 19
20#include <brcmu_wifi.h> 20#include <brcmu_wifi.h>
21#include <brcmu_utils.h> 21#include <brcmu_utils.h>
22#include "dhd.h" 22#include "core.h"
23#include "dhd_bus.h" 23#include "bus.h"
24#include "dhd_dbg.h" 24#include "debug.h"
25 25
26static struct dentry *root_folder; 26static struct dentry *root_folder;
27 27
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h b/drivers/net/wireless/brcm80211/brcmfmac/debug.h
index dec40d316c82..eb0b8c47479d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/debug.h
@@ -14,8 +14,8 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#ifndef _BRCMF_DBG_H_ 17#ifndef BRCMFMAC_DEBUG_H
18#define _BRCMF_DBG_H_ 18#define BRCMFMAC_DEBUG_H
19 19
20/* message levels */ 20/* message levels */
21#define BRCMF_TRACE_VAL 0x00000002 21#define BRCMF_TRACE_VAL 0x00000002
@@ -133,4 +133,4 @@ int brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
133} 133}
134#endif 134#endif
135 135
136#endif /* _BRCMF_DBG_H_ */ 136#endif /* BRCMFMAC_DEBUG_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c
deleted file mode 100644
index d991f8e3d9ec..000000000000
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c
+++ /dev/null
@@ -1,400 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/kernel.h>
18#include <linux/string.h>
19#include <linux/netdevice.h>
20#include <brcmu_wifi.h>
21#include <brcmu_utils.h>
22#include "dhd.h"
23#include "dhd_bus.h"
24#include "dhd_dbg.h"
25#include "fwil.h"
26#include "fwil_types.h"
27#include "tracepoint.h"
28
29#define PKTFILTER_BUF_SIZE 128
30#define BRCMF_DEFAULT_BCN_TIMEOUT 3
31#define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
32#define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
33#define BRCMF_DEFAULT_PACKET_FILTER "100 0 0 0 0x01 0x00"
34
35/* boost value for RSSI_DELTA in preferred join selection */
36#define BRCMF_JOIN_PREF_RSSI_BOOST 8
37
38
39bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
40 struct sk_buff *pkt, int prec)
41{
42 struct sk_buff *p;
43 int eprec = -1; /* precedence to evict from */
44 bool discard_oldest;
45 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
46 struct brcmf_pub *drvr = bus_if->drvr;
47
48 /* Fast case, precedence queue is not full and we are also not
49 * exceeding total queue length
50 */
51 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
52 brcmu_pktq_penq(q, prec, pkt);
53 return true;
54 }
55
56 /* Determine precedence from which to evict packet, if any */
57 if (pktq_pfull(q, prec))
58 eprec = prec;
59 else if (pktq_full(q)) {
60 p = brcmu_pktq_peek_tail(q, &eprec);
61 if (eprec > prec)
62 return false;
63 }
64
65 /* Evict if needed */
66 if (eprec >= 0) {
67 /* Detect queueing to unconfigured precedence */
68 discard_oldest = ac_bitmap_tst(drvr->wme_dp, eprec);
69 if (eprec == prec && !discard_oldest)
70 return false; /* refuse newer (incoming) packet */
71 /* Evict packet according to discard policy */
72 p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
73 brcmu_pktq_pdeq_tail(q, eprec);
74 if (p == NULL)
75 brcmf_err("brcmu_pktq_penq() failed, oldest %d\n",
76 discard_oldest);
77
78 brcmu_pkt_buf_free_skb(p);
79 }
80
81 /* Enqueue */
82 p = brcmu_pktq_penq(q, prec, pkt);
83 if (p == NULL)
84 brcmf_err("brcmu_pktq_penq() failed\n");
85
86 return p != NULL;
87}
88
89/* Convert user's input in hex pattern to byte-size mask */
90static int brcmf_c_pattern_atoh(char *src, char *dst)
91{
92 int i;
93 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
94 brcmf_err("Mask invalid format. Needs to start with 0x\n");
95 return -EINVAL;
96 }
97 src = src + 2; /* Skip past 0x */
98 if (strlen(src) % 2 != 0) {
99 brcmf_err("Mask invalid format. Length must be even.\n");
100 return -EINVAL;
101 }
102 for (i = 0; *src != '\0'; i++) {
103 unsigned long res;
104 char num[3];
105 strncpy(num, src, 2);
106 num[2] = '\0';
107 if (kstrtoul(num, 16, &res))
108 return -EINVAL;
109 dst[i] = (u8)res;
110 src += 2;
111 }
112 return i;
113}
114
115static void
116brcmf_c_pktfilter_offload_enable(struct brcmf_if *ifp, char *arg, int enable,
117 int master_mode)
118{
119 unsigned long res;
120 char *argv;
121 char *arg_save = NULL, *arg_org = NULL;
122 s32 err;
123 struct brcmf_pkt_filter_enable_le enable_parm;
124
125 arg_save = kstrdup(arg, GFP_ATOMIC);
126 if (!arg_save)
127 goto fail;
128
129 arg_org = arg_save;
130
131 argv = strsep(&arg_save, " ");
132
133 if (argv == NULL) {
134 brcmf_err("No args provided\n");
135 goto fail;
136 }
137
138 /* Parse packet filter id. */
139 enable_parm.id = 0;
140 if (!kstrtoul(argv, 0, &res))
141 enable_parm.id = cpu_to_le32((u32)res);
142
143 /* Enable/disable the specified filter. */
144 enable_parm.enable = cpu_to_le32(enable);
145
146 err = brcmf_fil_iovar_data_set(ifp, "pkt_filter_enable", &enable_parm,
147 sizeof(enable_parm));
148 if (err)
149 brcmf_err("Set pkt_filter_enable error (%d)\n", err);
150
151 /* Control the master mode */
152 err = brcmf_fil_iovar_int_set(ifp, "pkt_filter_mode", master_mode);
153 if (err)
154 brcmf_err("Set pkt_filter_mode error (%d)\n", err);
155
156fail:
157 kfree(arg_org);
158}
159
160static void brcmf_c_pktfilter_offload_set(struct brcmf_if *ifp, char *arg)
161{
162 struct brcmf_pkt_filter_le *pkt_filter;
163 unsigned long res;
164 int buf_len;
165 s32 err;
166 u32 mask_size;
167 u32 pattern_size;
168 char *argv[8], *buf = NULL;
169 int i = 0;
170 char *arg_save = NULL, *arg_org = NULL;
171
172 arg_save = kstrdup(arg, GFP_ATOMIC);
173 if (!arg_save)
174 goto fail;
175
176 arg_org = arg_save;
177
178 buf = kmalloc(PKTFILTER_BUF_SIZE, GFP_ATOMIC);
179 if (!buf)
180 goto fail;
181
182 argv[i] = strsep(&arg_save, " ");
183 while (argv[i]) {
184 i++;
185 if (i >= 8) {
186 brcmf_err("Too many parameters\n");
187 goto fail;
188 }
189 argv[i] = strsep(&arg_save, " ");
190 }
191
192 if (i != 6) {
193 brcmf_err("Not enough args provided %d\n", i);
194 goto fail;
195 }
196
197 pkt_filter = (struct brcmf_pkt_filter_le *)buf;
198
199 /* Parse packet filter id. */
200 pkt_filter->id = 0;
201 if (!kstrtoul(argv[0], 0, &res))
202 pkt_filter->id = cpu_to_le32((u32)res);
203
204 /* Parse filter polarity. */
205 pkt_filter->negate_match = 0;
206 if (!kstrtoul(argv[1], 0, &res))
207 pkt_filter->negate_match = cpu_to_le32((u32)res);
208
209 /* Parse filter type. */
210 pkt_filter->type = 0;
211 if (!kstrtoul(argv[2], 0, &res))
212 pkt_filter->type = cpu_to_le32((u32)res);
213
214 /* Parse pattern filter offset. */
215 pkt_filter->u.pattern.offset = 0;
216 if (!kstrtoul(argv[3], 0, &res))
217 pkt_filter->u.pattern.offset = cpu_to_le32((u32)res);
218
219 /* Parse pattern filter mask. */
220 mask_size = brcmf_c_pattern_atoh(argv[4],
221 (char *)pkt_filter->u.pattern.mask_and_pattern);
222
223 /* Parse pattern filter pattern. */
224 pattern_size = brcmf_c_pattern_atoh(argv[5],
225 (char *)&pkt_filter->u.pattern.mask_and_pattern[mask_size]);
226
227 if (mask_size != pattern_size) {
228 brcmf_err("Mask and pattern not the same size\n");
229 goto fail;
230 }
231
232 pkt_filter->u.pattern.size_bytes = cpu_to_le32(mask_size);
233 buf_len = offsetof(struct brcmf_pkt_filter_le,
234 u.pattern.mask_and_pattern);
235 buf_len += mask_size + pattern_size;
236
237 err = brcmf_fil_iovar_data_set(ifp, "pkt_filter_add", pkt_filter,
238 buf_len);
239 if (err)
240 brcmf_err("Set pkt_filter_add error (%d)\n", err);
241
242fail:
243 kfree(arg_org);
244
245 kfree(buf);
246}
247
248int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
249{
250 s8 eventmask[BRCMF_EVENTING_MASK_LEN];
251 u8 buf[BRCMF_DCMD_SMLEN];
252 struct brcmf_join_pref_params join_pref_params[2];
253 char *ptr;
254 s32 err;
255
256 /* retreive mac address */
257 err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
258 sizeof(ifp->mac_addr));
259 if (err < 0) {
260 brcmf_err("Retreiving cur_etheraddr failed, %d\n",
261 err);
262 goto done;
263 }
264 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
265
266 /* query for 'ver' to get version info from firmware */
267 memset(buf, 0, sizeof(buf));
268 strcpy(buf, "ver");
269 err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
270 if (err < 0) {
271 brcmf_err("Retreiving version information failed, %d\n",
272 err);
273 goto done;
274 }
275 ptr = (char *)buf;
276 strsep(&ptr, "\n");
277
278 /* Print fw version info */
279 brcmf_err("Firmware version = %s\n", buf);
280
281 /* locate firmware version number for ethtool */
282 ptr = strrchr(buf, ' ') + 1;
283 strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
284
285 /* set mpc */
286 err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
287 if (err) {
288 brcmf_err("failed setting mpc\n");
289 goto done;
290 }
291
292 /*
293 * Setup timeout if Beacons are lost and roam is off to report
294 * link down
295 */
296 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout",
297 BRCMF_DEFAULT_BCN_TIMEOUT);
298 if (err) {
299 brcmf_err("bcn_timeout error (%d)\n", err);
300 goto done;
301 }
302
303 /* Enable/Disable build-in roaming to allowed ext supplicant to take
304 * of romaing
305 */
306 err = brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
307 if (err) {
308 brcmf_err("roam_off error (%d)\n", err);
309 goto done;
310 }
311
312 /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
313 join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
314 join_pref_params[0].len = 2;
315 join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
316 join_pref_params[0].band = WLC_BAND_5G;
317 join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
318 join_pref_params[1].len = 2;
319 join_pref_params[1].rssi_gain = 0;
320 join_pref_params[1].band = 0;
321 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
322 sizeof(join_pref_params));
323 if (err)
324 brcmf_err("Set join_pref error (%d)\n", err);
325
326 /* Setup event_msgs, enable E_IF */
327 err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
328 BRCMF_EVENTING_MASK_LEN);
329 if (err) {
330 brcmf_err("Get event_msgs error (%d)\n", err);
331 goto done;
332 }
333 setbit(eventmask, BRCMF_E_IF);
334 err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
335 BRCMF_EVENTING_MASK_LEN);
336 if (err) {
337 brcmf_err("Set event_msgs error (%d)\n", err);
338 goto done;
339 }
340
341 /* Setup default scan channel time */
342 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
343 BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
344 if (err) {
345 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
346 err);
347 goto done;
348 }
349
350 /* Setup default scan unassoc time */
351 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
352 BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
353 if (err) {
354 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
355 err);
356 goto done;
357 }
358
359 /* Setup packet filter */
360 brcmf_c_pktfilter_offload_set(ifp, BRCMF_DEFAULT_PACKET_FILTER);
361 brcmf_c_pktfilter_offload_enable(ifp, BRCMF_DEFAULT_PACKET_FILTER,
362 0, true);
363
364 /* do bus specific preinit here */
365 err = brcmf_bus_preinit(ifp->drvr->bus_if);
366done:
367 return err;
368}
369
370#ifdef CONFIG_BRCM_TRACING
371void __brcmf_err(const char *func, const char *fmt, ...)
372{
373 struct va_format vaf = {
374 .fmt = fmt,
375 };
376 va_list args;
377
378 va_start(args, fmt);
379 vaf.va = &args;
380 pr_err("%s: %pV", func, &vaf);
381 trace_brcmf_err(func, &vaf);
382 va_end(args);
383}
384#endif
385#if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
386void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
387{
388 struct va_format vaf = {
389 .fmt = fmt,
390 };
391 va_list args;
392
393 va_start(args, fmt);
394 vaf.va = &args;
395 if (brcmf_msg_level & level)
396 pr_debug("%s %pV", func, &vaf);
397 trace_brcmf_dbg(level, func, &vaf);
398 va_end(args);
399}
400#endif
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/brcm80211/brcmfmac/feature.c
index aed53acef456..931f68aefaa4 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/feature.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/feature.c
@@ -17,18 +17,13 @@
17#include <linux/netdevice.h> 17#include <linux/netdevice.h>
18 18
19#include <brcm_hw_ids.h> 19#include <brcm_hw_ids.h>
20#include "dhd.h" 20#include "core.h"
21#include "dhd_bus.h" 21#include "bus.h"
22#include "dhd_dbg.h" 22#include "debug.h"
23#include "fwil.h" 23#include "fwil.h"
24#include "feature.h" 24#include "feature.h"
25 25
26/* 26/*
27 * firmware error code received if iovar is unsupported.
28 */
29#define EBRCMF_FEAT_UNSUPPORTED 23
30
31/*
32 * expand feature list to array of feature strings. 27 * expand feature list to array of feature strings.
33 */ 28 */
34#define BRCMF_FEAT_DEF(_f) \ 29#define BRCMF_FEAT_DEF(_f) \
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
index 8ea9f283d2b8..0f157f151282 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
@@ -20,7 +20,7 @@
20#include <linux/firmware.h> 20#include <linux/firmware.h>
21#include <linux/module.h> 21#include <linux/module.h>
22 22
23#include "dhd_dbg.h" 23#include "debug.h"
24#include "firmware.h" 24#include "firmware.h"
25 25
26char brcmf_firmware_path[BRCMF_FW_PATH_LEN]; 26char brcmf_firmware_path[BRCMF_FW_PATH_LEN];
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/flowring.c b/drivers/net/wireless/brcm80211/brcmfmac/flowring.c
index 1faa929f5fff..44f3a84d1999 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/flowring.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/flowring.c
@@ -19,9 +19,9 @@
19#include <linux/etherdevice.h> 19#include <linux/etherdevice.h>
20#include <brcmu_utils.h> 20#include <brcmu_utils.h>
21 21
22#include "dhd.h" 22#include "core.h"
23#include "dhd_dbg.h" 23#include "debug.h"
24#include "dhd_bus.h" 24#include "bus.h"
25#include "proto.h" 25#include "proto.h"
26#include "flowring.h" 26#include "flowring.h"
27#include "msgbuf.h" 27#include "msgbuf.h"
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/brcm80211/brcmfmac/fweh.c
index 44fc85f68f7a..7338b335e153 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/fweh.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fweh.c
@@ -18,8 +18,8 @@
18#include "brcmu_wifi.h" 18#include "brcmu_wifi.h"
19#include "brcmu_utils.h" 19#include "brcmu_utils.h"
20 20
21#include "dhd.h" 21#include "core.h"
22#include "dhd_dbg.h" 22#include "debug.h"
23#include "tracepoint.h" 23#include "tracepoint.h"
24#include "fwsignal.h" 24#include "fwsignal.h"
25#include "fweh.h" 25#include "fweh.h"
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/fwil.c b/drivers/net/wireless/brcm80211/brcmfmac/fwil.c
index ded328f80cd1..51f88c11e642 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/fwil.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fwil.c
@@ -22,9 +22,9 @@
22#include <linux/netdevice.h> 22#include <linux/netdevice.h>
23#include <brcmu_utils.h> 23#include <brcmu_utils.h>
24#include <brcmu_wifi.h> 24#include <brcmu_wifi.h>
25#include "dhd.h" 25#include "core.h"
26#include "dhd_bus.h" 26#include "bus.h"
27#include "dhd_dbg.h" 27#include "debug.h"
28#include "tracepoint.h" 28#include "tracepoint.h"
29#include "fwil.h" 29#include "fwil.h"
30#include "proto.h" 30#include "proto.h"
@@ -32,6 +32,76 @@
32 32
33#define MAX_HEX_DUMP_LEN 64 33#define MAX_HEX_DUMP_LEN 64
34 34
35#ifdef DEBUG
36static const char * const brcmf_fil_errstr[] = {
37 "BCME_OK",
38 "BCME_ERROR",
39 "BCME_BADARG",
40 "BCME_BADOPTION",
41 "BCME_NOTUP",
42 "BCME_NOTDOWN",
43 "BCME_NOTAP",
44 "BCME_NOTSTA",
45 "BCME_BADKEYIDX",
46 "BCME_RADIOOFF",
47 "BCME_NOTBANDLOCKED",
48 "BCME_NOCLK",
49 "BCME_BADRATESET",
50 "BCME_BADBAND",
51 "BCME_BUFTOOSHORT",
52 "BCME_BUFTOOLONG",
53 "BCME_BUSY",
54 "BCME_NOTASSOCIATED",
55 "BCME_BADSSIDLEN",
56 "BCME_OUTOFRANGECHAN",
57 "BCME_BADCHAN",
58 "BCME_BADADDR",
59 "BCME_NORESOURCE",
60 "BCME_UNSUPPORTED",
61 "BCME_BADLEN",
62 "BCME_NOTREADY",
63 "BCME_EPERM",
64 "BCME_NOMEM",
65 "BCME_ASSOCIATED",
66 "BCME_RANGE",
67 "BCME_NOTFOUND",
68 "BCME_WME_NOT_ENABLED",
69 "BCME_TSPEC_NOTFOUND",
70 "BCME_ACM_NOTSUPPORTED",
71 "BCME_NOT_WME_ASSOCIATION",
72 "BCME_SDIO_ERROR",
73 "BCME_DONGLE_DOWN",
74 "BCME_VERSION",
75 "BCME_TXFAIL",
76 "BCME_RXFAIL",
77 "BCME_NODEVICE",
78 "BCME_NMODE_DISABLED",
79 "BCME_NONRESIDENT",
80 "BCME_SCANREJECT",
81 "BCME_USAGE_ERROR",
82 "BCME_IOCTL_ERROR",
83 "BCME_SERIAL_PORT_ERR",
84 "BCME_DISABLED",
85 "BCME_DECERR",
86 "BCME_ENCERR",
87 "BCME_MICERR",
88 "BCME_REPLAY",
89 "BCME_IE_NOTFOUND",
90};
91
92static const char *brcmf_fil_get_errstr(u32 err)
93{
94 if (err >= ARRAY_SIZE(brcmf_fil_errstr))
95 return "(unknown)";
96
97 return brcmf_fil_errstr[err];
98}
99#else
100static const char *brcmf_fil_get_errstr(u32 err)
101{
102 return "";
103}
104#endif /* DEBUG */
35 105
36static s32 106static s32
37brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set) 107brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set)
@@ -52,11 +122,11 @@ brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set)
52 err = brcmf_proto_query_dcmd(drvr, ifp->ifidx, cmd, data, len); 122 err = brcmf_proto_query_dcmd(drvr, ifp->ifidx, cmd, data, len);
53 123
54 if (err >= 0) 124 if (err >= 0)
55 err = 0; 125 return 0;
56 else
57 brcmf_dbg(FIL, "Failed err=%d\n", err);
58 126
59 return err; 127 brcmf_dbg(FIL, "Failed: %s (%d)\n",
128 brcmf_fil_get_errstr((u32)(-err)), err);
129 return -EBADE;
60} 130}
61 131
62s32 132s32
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/brcm80211/brcmfmac/fwil_types.h
index 5ff5cd0bb032..ba64b292f7a5 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/fwil_types.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fwil_types.h
@@ -55,59 +55,63 @@
55 55
56/* WOWL bits */ 56/* WOWL bits */
57/* Wakeup on Magic packet: */ 57/* Wakeup on Magic packet: */
58#define WL_WOWL_MAGIC (1 << 0) 58#define BRCMF_WOWL_MAGIC (1 << 0)
59/* Wakeup on Netpattern */ 59/* Wakeup on Netpattern */
60#define WL_WOWL_NET (1 << 1) 60#define BRCMF_WOWL_NET (1 << 1)
61/* Wakeup on loss-of-link due to Disassoc/Deauth: */ 61/* Wakeup on loss-of-link due to Disassoc/Deauth: */
62#define WL_WOWL_DIS (1 << 2) 62#define BRCMF_WOWL_DIS (1 << 2)
63/* Wakeup on retrograde TSF: */ 63/* Wakeup on retrograde TSF: */
64#define WL_WOWL_RETR (1 << 3) 64#define BRCMF_WOWL_RETR (1 << 3)
65/* Wakeup on loss of beacon: */ 65/* Wakeup on loss of beacon: */
66#define WL_WOWL_BCN (1 << 4) 66#define BRCMF_WOWL_BCN (1 << 4)
67/* Wakeup after test: */ 67/* Wakeup after test: */
68#define WL_WOWL_TST (1 << 5) 68#define BRCMF_WOWL_TST (1 << 5)
69/* Wakeup after PTK refresh: */ 69/* Wakeup after PTK refresh: */
70#define WL_WOWL_M1 (1 << 6) 70#define BRCMF_WOWL_M1 (1 << 6)
71/* Wakeup after receipt of EAP-Identity Req: */ 71/* Wakeup after receipt of EAP-Identity Req: */
72#define WL_WOWL_EAPID (1 << 7) 72#define BRCMF_WOWL_EAPID (1 << 7)
73/* Wakeind via PME(0) or GPIO(1): */ 73/* Wakeind via PME(0) or GPIO(1): */
74#define WL_WOWL_PME_GPIO (1 << 8) 74#define BRCMF_WOWL_PME_GPIO (1 << 8)
75/* need tkip phase 1 key to be updated by the driver: */ 75/* need tkip phase 1 key to be updated by the driver: */
76#define WL_WOWL_NEEDTKIP1 (1 << 9) 76#define BRCMF_WOWL_NEEDTKIP1 (1 << 9)
77/* enable wakeup if GTK fails: */ 77/* enable wakeup if GTK fails: */
78#define WL_WOWL_GTK_FAILURE (1 << 10) 78#define BRCMF_WOWL_GTK_FAILURE (1 << 10)
79/* support extended magic packets: */ 79/* support extended magic packets: */
80#define WL_WOWL_EXTMAGPAT (1 << 11) 80#define BRCMF_WOWL_EXTMAGPAT (1 << 11)
81/* support ARP/NS/keepalive offloading: */ 81/* support ARP/NS/keepalive offloading: */
82#define WL_WOWL_ARPOFFLOAD (1 << 12) 82#define BRCMF_WOWL_ARPOFFLOAD (1 << 12)
83/* read protocol version for EAPOL frames: */ 83/* read protocol version for EAPOL frames: */
84#define WL_WOWL_WPA2 (1 << 13) 84#define BRCMF_WOWL_WPA2 (1 << 13)
85/* If the bit is set, use key rotaton: */ 85/* If the bit is set, use key rotaton: */
86#define WL_WOWL_KEYROT (1 << 14) 86#define BRCMF_WOWL_KEYROT (1 << 14)
87/* If the bit is set, frm received was bcast frame: */ 87/* If the bit is set, frm received was bcast frame: */
88#define WL_WOWL_BCAST (1 << 15) 88#define BRCMF_WOWL_BCAST (1 << 15)
89/* If the bit is set, scan offload is enabled: */ 89/* If the bit is set, scan offload is enabled: */
90#define WL_WOWL_SCANOL (1 << 16) 90#define BRCMF_WOWL_SCANOL (1 << 16)
91/* Wakeup on tcpkeep alive timeout: */ 91/* Wakeup on tcpkeep alive timeout: */
92#define WL_WOWL_TCPKEEP_TIME (1 << 17) 92#define BRCMF_WOWL_TCPKEEP_TIME (1 << 17)
93/* Wakeup on mDNS Conflict Resolution: */ 93/* Wakeup on mDNS Conflict Resolution: */
94#define WL_WOWL_MDNS_CONFLICT (1 << 18) 94#define BRCMF_WOWL_MDNS_CONFLICT (1 << 18)
95/* Wakeup on mDNS Service Connect: */ 95/* Wakeup on mDNS Service Connect: */
96#define WL_WOWL_MDNS_SERVICE (1 << 19) 96#define BRCMF_WOWL_MDNS_SERVICE (1 << 19)
97/* tcp keepalive got data: */ 97/* tcp keepalive got data: */
98#define WL_WOWL_TCPKEEP_DATA (1 << 20) 98#define BRCMF_WOWL_TCPKEEP_DATA (1 << 20)
99/* Firmware died in wowl mode: */ 99/* Firmware died in wowl mode: */
100#define WL_WOWL_FW_HALT (1 << 21) 100#define BRCMF_WOWL_FW_HALT (1 << 21)
101/* Enable detection of radio button changes: */ 101/* Enable detection of radio button changes: */
102#define WL_WOWL_ENAB_HWRADIO (1 << 22) 102#define BRCMF_WOWL_ENAB_HWRADIO (1 << 22)
103/* Offloads detected MIC failure(s): */ 103/* Offloads detected MIC failure(s): */
104#define WL_WOWL_MIC_FAIL (1 << 23) 104#define BRCMF_WOWL_MIC_FAIL (1 << 23)
105/* Wakeup in Unassociated state (Net/Magic Pattern): */ 105/* Wakeup in Unassociated state (Net/Magic Pattern): */
106#define WL_WOWL_UNASSOC (1 << 24) 106#define BRCMF_WOWL_UNASSOC (1 << 24)
107/* Wakeup if received matched secured pattern: */ 107/* Wakeup if received matched secured pattern: */
108#define WL_WOWL_SECURE (1 << 25) 108#define BRCMF_WOWL_SECURE (1 << 25)
109/* Link Down indication in WoWL mode: */ 109/* Link Down indication in WoWL mode: */
110#define WL_WOWL_LINKDOWN (1 << 31) 110#define BRCMF_WOWL_LINKDOWN (1 << 31)
111
112#define BRCMF_WOWL_MAXPATTERNS 8
113#define BRCMF_WOWL_MAXPATTERNSIZE 128
114
111 115
112/* join preference types for join_pref iovar */ 116/* join preference types for join_pref iovar */
113enum brcmf_join_pref_types { 117enum brcmf_join_pref_types {
@@ -124,6 +128,12 @@ enum brcmf_fil_p2p_if_types {
124 BRCMF_FIL_P2P_IF_DEV, 128 BRCMF_FIL_P2P_IF_DEV,
125}; 129};
126 130
131enum brcmf_wowl_pattern_type {
132 BRCMF_WOWL_PATTERN_TYPE_BITMAP = 0,
133 BRCMF_WOWL_PATTERN_TYPE_ARP,
134 BRCMF_WOWL_PATTERN_TYPE_NA
135};
136
127struct brcmf_fil_p2p_if_le { 137struct brcmf_fil_p2p_if_le {
128 u8 addr[ETH_ALEN]; 138 u8 addr[ETH_ALEN];
129 __le16 type; 139 __le16 type;
@@ -484,4 +494,29 @@ struct brcmf_rx_mgmt_data {
484 __be32 rate; 494 __be32 rate;
485}; 495};
486 496
497/**
498 * struct brcmf_fil_wowl_pattern_le - wowl pattern configuration struct.
499 *
500 * @cmd: "add", "del" or "clr".
501 * @masksize: Size of the mask in #of bytes
502 * @offset: Pattern byte offset in packet
503 * @patternoffset: Offset of start of pattern. Starting from field masksize.
504 * @patternsize: Size of the pattern itself in #of bytes
505 * @id: id
506 * @reasonsize: Size of the wakeup reason code
507 * @type: Type of pattern (enum brcmf_wowl_pattern_type)
508 */
509struct brcmf_fil_wowl_pattern_le {
510 u8 cmd[4];
511 __le32 masksize;
512 __le32 offset;
513 __le32 patternoffset;
514 __le32 patternsize;
515 __le32 id;
516 __le32 reasonsize;
517 __le32 type;
518 /* u8 mask[] - Mask follows the structure above */
519 /* u8 pattern[] - Pattern follows the mask is at 'patternoffset' */
520};
521
487#endif /* FWIL_TYPES_H_ */ 522#endif /* FWIL_TYPES_H_ */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c b/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c
index 183f08d7fc8c..f0dda0ecd23b 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c
@@ -26,15 +26,15 @@
26 26
27#include <brcmu_utils.h> 27#include <brcmu_utils.h>
28#include <brcmu_wifi.h> 28#include <brcmu_wifi.h>
29#include "dhd.h" 29#include "core.h"
30#include "dhd_dbg.h" 30#include "debug.h"
31#include "dhd_bus.h" 31#include "bus.h"
32#include "fwil.h" 32#include "fwil.h"
33#include "fwil_types.h" 33#include "fwil_types.h"
34#include "fweh.h" 34#include "fweh.h"
35#include "fwsignal.h" 35#include "fwsignal.h"
36#include "p2p.h" 36#include "p2p.h"
37#include "wl_cfg80211.h" 37#include "cfg80211.h"
38#include "proto.h" 38#include "proto.h"
39 39
40/** 40/**
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
index 11cc051f97cd..02d39ce8dbca 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
@@ -24,13 +24,13 @@
24#include <brcmu_utils.h> 24#include <brcmu_utils.h>
25#include <brcmu_wifi.h> 25#include <brcmu_wifi.h>
26 26
27#include "dhd.h" 27#include "core.h"
28#include "dhd_dbg.h" 28#include "debug.h"
29#include "proto.h" 29#include "proto.h"
30#include "msgbuf.h" 30#include "msgbuf.h"
31#include "commonring.h" 31#include "commonring.h"
32#include "flowring.h" 32#include "flowring.h"
33#include "dhd_bus.h" 33#include "bus.h"
34#include "tracepoint.h" 34#include "tracepoint.h"
35 35
36 36
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/of.c b/drivers/net/wireless/brcm80211/brcmfmac/of.c
index f05f5270fec1..eb3fce82a223 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/of.c
@@ -21,8 +21,8 @@
21#include <linux/mmc/sdio_func.h> 21#include <linux/mmc/sdio_func.h>
22 22
23#include <defs.h> 23#include <defs.h>
24#include "dhd_dbg.h" 24#include "debug.h"
25#include "sdio_host.h" 25#include "sdio.h"
26 26
27void brcmf_of_probe(struct brcmf_sdio_dev *sdiodev) 27void brcmf_of_probe(struct brcmf_sdio_dev *sdiodev)
28{ 28{
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
index d54c58a32faa..effb48ebd864 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
@@ -21,12 +21,12 @@
21#include <brcmu_wifi.h> 21#include <brcmu_wifi.h>
22#include <brcmu_utils.h> 22#include <brcmu_utils.h>
23#include <defs.h> 23#include <defs.h>
24#include <dhd.h> 24#include "core.h"
25#include <dhd_dbg.h> 25#include "debug.h"
26#include "fwil.h" 26#include "fwil.h"
27#include "fwil_types.h" 27#include "fwil_types.h"
28#include "p2p.h" 28#include "p2p.h"
29#include "wl_cfg80211.h" 29#include "cfg80211.h"
30 30
31/* parameters used for p2p escan */ 31/* parameters used for p2p escan */
32#define P2PAPI_SCAN_NPROBES 1 32#define P2PAPI_SCAN_NPROBES 1
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
index 8c0632ec9f7a..b0ae7993e2e8 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
@@ -30,8 +30,8 @@
30#include <brcmu_wifi.h> 30#include <brcmu_wifi.h>
31#include <brcm_hw_ids.h> 31#include <brcm_hw_ids.h>
32 32
33#include "dhd_dbg.h" 33#include "debug.h"
34#include "dhd_bus.h" 34#include "bus.h"
35#include "commonring.h" 35#include "commonring.h"
36#include "msgbuf.h" 36#include "msgbuf.h"
37#include "pcie.h" 37#include "pcie.h"
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/proto.c b/drivers/net/wireless/brcm80211/brcmfmac/proto.c
index 62b940723339..26b68c367f57 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/proto.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/proto.c
@@ -20,9 +20,9 @@
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21 21
22#include <brcmu_wifi.h> 22#include <brcmu_wifi.h>
23#include "dhd.h" 23#include "core.h"
24#include "dhd_bus.h" 24#include "bus.h"
25#include "dhd_dbg.h" 25#include "debug.h"
26#include "proto.h" 26#include "proto.h"
27#include "bcdc.h" 27#include "bcdc.h"
28#include "msgbuf.h" 28#include "msgbuf.h"
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
index d20d4e6f391a..0b0d51a61060 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
@@ -40,7 +40,7 @@
40#include <brcmu_utils.h> 40#include <brcmu_utils.h>
41#include <brcm_hw_ids.h> 41#include <brcm_hw_ids.h>
42#include <soc.h> 42#include <soc.h>
43#include "sdio_host.h" 43#include "sdio.h"
44#include "chip.h" 44#include "chip.h"
45#include "firmware.h" 45#include "firmware.h"
46 46
@@ -96,8 +96,8 @@ struct rte_console {
96#endif /* DEBUG */ 96#endif /* DEBUG */
97#include <chipcommon.h> 97#include <chipcommon.h>
98 98
99#include "dhd_bus.h" 99#include "bus.h"
100#include "dhd_dbg.h" 100#include "debug.h"
101#include "tracepoint.h" 101#include "tracepoint.h"
102 102
103#define TXQLEN 2048 /* bulk tx queue length */ 103#define TXQLEN 2048 /* bulk tx queue length */
@@ -2762,6 +2762,48 @@ static struct pktq *brcmf_sdio_bus_gettxq(struct device *dev)
2762 return &bus->txq; 2762 return &bus->txq;
2763} 2763}
2764 2764
2765static bool brcmf_sdio_prec_enq(struct pktq *q, struct sk_buff *pkt, int prec)
2766{
2767 struct sk_buff *p;
2768 int eprec = -1; /* precedence to evict from */
2769
2770 /* Fast case, precedence queue is not full and we are also not
2771 * exceeding total queue length
2772 */
2773 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
2774 brcmu_pktq_penq(q, prec, pkt);
2775 return true;
2776 }
2777
2778 /* Determine precedence from which to evict packet, if any */
2779 if (pktq_pfull(q, prec)) {
2780 eprec = prec;
2781 } else if (pktq_full(q)) {
2782 p = brcmu_pktq_peek_tail(q, &eprec);
2783 if (eprec > prec)
2784 return false;
2785 }
2786
2787 /* Evict if needed */
2788 if (eprec >= 0) {
2789 /* Detect queueing to unconfigured precedence */
2790 if (eprec == prec)
2791 return false; /* refuse newer (incoming) packet */
2792 /* Evict packet according to discard policy */
2793 p = brcmu_pktq_pdeq_tail(q, eprec);
2794 if (p == NULL)
2795 brcmf_err("brcmu_pktq_pdeq_tail() failed\n");
2796 brcmu_pkt_buf_free_skb(p);
2797 }
2798
2799 /* Enqueue */
2800 p = brcmu_pktq_penq(q, prec, pkt);
2801 if (p == NULL)
2802 brcmf_err("brcmu_pktq_penq() failed\n");
2803
2804 return p != NULL;
2805}
2806
2765static int brcmf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt) 2807static int brcmf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt)
2766{ 2808{
2767 int ret = -EBADE; 2809 int ret = -EBADE;
@@ -2787,7 +2829,7 @@ static int brcmf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt)
2787 spin_lock_bh(&bus->txq_lock); 2829 spin_lock_bh(&bus->txq_lock);
2788 /* reset bus_flags in packet cb */ 2830 /* reset bus_flags in packet cb */
2789 *(u16 *)(pkt->cb) = 0; 2831 *(u16 *)(pkt->cb) = 0;
2790 if (!brcmf_c_prec_enq(bus->sdiodev->dev, &bus->txq, pkt, prec)) { 2832 if (!brcmf_sdio_prec_enq(&bus->txq, pkt, prec)) {
2791 skb_pull(pkt, bus->tx_hdrlen); 2833 skb_pull(pkt, bus->tx_hdrlen);
2792 brcmf_err("out of bus->txq !!!\n"); 2834 brcmf_err("out of bus->txq !!!\n");
2793 ret = -ENOSR; 2835 ret = -ENOSR;
@@ -2797,7 +2839,7 @@ static int brcmf_sdio_bus_txdata(struct device *dev, struct sk_buff *pkt)
2797 2839
2798 if (pktq_len(&bus->txq) >= TXHI) { 2840 if (pktq_len(&bus->txq) >= TXHI) {
2799 bus->txoff = true; 2841 bus->txoff = true;
2800 brcmf_txflowblock(bus->sdiodev->dev, true); 2842 brcmf_txflowblock(dev, true);
2801 } 2843 }
2802 spin_unlock_bh(&bus->txq_lock); 2844 spin_unlock_bh(&bus->txq_lock);
2803 2845
@@ -3948,6 +3990,7 @@ static struct brcmf_bus_ops brcmf_sdio_bus_ops = {
3948 .txctl = brcmf_sdio_bus_txctl, 3990 .txctl = brcmf_sdio_bus_txctl,
3949 .rxctl = brcmf_sdio_bus_rxctl, 3991 .rxctl = brcmf_sdio_bus_rxctl,
3950 .gettxq = brcmf_sdio_bus_gettxq, 3992 .gettxq = brcmf_sdio_bus_gettxq,
3993 .wowl_config = brcmf_sdio_wowl_config
3951}; 3994};
3952 3995
3953static void brcmf_sdio_firmware_callback(struct device *dev, 3996static void brcmf_sdio_firmware_callback(struct device *dev,
@@ -4074,7 +4117,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
4074 4117
4075 /* platform specific configuration: 4118 /* platform specific configuration:
4076 * alignments must be at least 4 bytes for ADMA 4119 * alignments must be at least 4 bytes for ADMA
4077 */ 4120 */
4078 bus->head_align = ALIGNMENT; 4121 bus->head_align = ALIGNMENT;
4079 bus->sgentry_align = ALIGNMENT; 4122 bus->sgentry_align = ALIGNMENT;
4080 if (sdiodev->pdata) { 4123 if (sdiodev->pdata) {
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/sdio_host.h b/drivers/net/wireless/brcm80211/brcmfmac/sdio.h
index f2d06cae366a..8eb42620129c 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/sdio_host.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.h
@@ -14,8 +14,8 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#ifndef _BRCM_SDH_H_ 17#ifndef BRCMFMAC_SDIO_H
18#define _BRCM_SDH_H_ 18#define BRCMFMAC_SDIO_H
19 19
20#include <linux/skbuff.h> 20#include <linux/skbuff.h>
21#include <linux/firmware.h> 21#include <linux/firmware.h>
@@ -186,6 +186,7 @@ struct brcmf_sdio_dev {
186 struct sg_table sgtable; 186 struct sg_table sgtable;
187 char fw_name[BRCMF_FW_PATH_LEN + BRCMF_FW_NAME_LEN]; 187 char fw_name[BRCMF_FW_PATH_LEN + BRCMF_FW_NAME_LEN];
188 char nvram_name[BRCMF_FW_PATH_LEN + BRCMF_FW_NAME_LEN]; 188 char nvram_name[BRCMF_FW_PATH_LEN + BRCMF_FW_NAME_LEN];
189 bool wowl_enabled;
189}; 190};
190 191
191/* sdio core registers */ 192/* sdio core registers */
@@ -334,5 +335,6 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus);
334void brcmf_sdio_isr(struct brcmf_sdio *bus); 335void brcmf_sdio_isr(struct brcmf_sdio *bus);
335 336
336void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, uint wdtick); 337void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, uint wdtick);
338void brcmf_sdio_wowl_config(struct device *dev, bool enabled);
337 339
338#endif /* _BRCM_SDH_H_ */ 340#endif /* BRCMFMAC_SDIO_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/tracepoint.c b/drivers/net/wireless/brcm80211/brcmfmac/tracepoint.c
index b505db48c60d..a10f35c5eb3d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/tracepoint.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/tracepoint.c
@@ -19,4 +19,19 @@
19#ifndef __CHECKER__ 19#ifndef __CHECKER__
20#define CREATE_TRACE_POINTS 20#define CREATE_TRACE_POINTS
21#include "tracepoint.h" 21#include "tracepoint.h"
22
23void __brcmf_err(const char *func, const char *fmt, ...)
24{
25 struct va_format vaf = {
26 .fmt = fmt,
27 };
28 va_list args;
29
30 va_start(args, fmt);
31 vaf.va = &args;
32 pr_err("%s: %pV", func, &vaf);
33 trace_brcmf_err(func, &vaf);
34 va_end(args);
35}
36
22#endif 37#endif
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index dc135915470d..5265aa70b094 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -23,13 +23,12 @@
23#include <brcmu_utils.h> 23#include <brcmu_utils.h>
24#include <brcm_hw_ids.h> 24#include <brcm_hw_ids.h>
25#include <brcmu_wifi.h> 25#include <brcmu_wifi.h>
26#include <dhd_bus.h> 26#include "bus.h"
27#include <dhd_dbg.h> 27#include "debug.h"
28
29#include "firmware.h" 28#include "firmware.h"
30#include "usb_rdl.h"
31#include "usb.h" 29#include "usb.h"
32 30
31
33#define IOCTL_RESP_TIMEOUT 2000 32#define IOCTL_RESP_TIMEOUT 2000
34 33
35#define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */ 34#define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */
@@ -49,6 +48,71 @@
49#define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin" 48#define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin"
50#define BRCMF_USB_43569_FW_NAME "brcm/brcmfmac43569.bin" 49#define BRCMF_USB_43569_FW_NAME "brcm/brcmfmac43569.bin"
51 50
51#define TRX_MAGIC 0x30524448 /* "HDR0" */
52#define TRX_MAX_OFFSET 3 /* Max number of file offsets */
53#define TRX_UNCOMP_IMAGE 0x20 /* Trx holds uncompressed img */
54#define TRX_RDL_CHUNK 1500 /* size of each dl transfer */
55#define TRX_OFFSETS_DLFWLEN_IDX 0
56
57/* Control messages: bRequest values */
58#define DL_GETSTATE 0 /* returns the rdl_state_t struct */
59#define DL_CHECK_CRC 1 /* currently unused */
60#define DL_GO 2 /* execute downloaded image */
61#define DL_START 3 /* initialize dl state */
62#define DL_REBOOT 4 /* reboot the device in 2 seconds */
63#define DL_GETVER 5 /* returns the bootrom_id_t struct */
64#define DL_GO_PROTECTED 6 /* execute the downloaded code and set reset
65 * event to occur in 2 seconds. It is the
66 * responsibility of the downloaded code to
67 * clear this event
68 */
69#define DL_EXEC 7 /* jump to a supplied address */
70#define DL_RESETCFG 8 /* To support single enum on dongle
71 * - Not used by bootloader
72 */
73#define DL_DEFER_RESP_OK 9 /* Potentially defer the response to setup
74 * if resp unavailable
75 */
76
77/* states */
78#define DL_WAITING 0 /* waiting to rx first pkt */
79#define DL_READY 1 /* hdr was good, waiting for more of the
80 * compressed image
81 */
82#define DL_BAD_HDR 2 /* hdr was corrupted */
83#define DL_BAD_CRC 3 /* compressed image was corrupted */
84#define DL_RUNNABLE 4 /* download was successful,waiting for go cmd */
85#define DL_START_FAIL 5 /* failed to initialize correctly */
86#define DL_NVRAM_TOOBIG 6 /* host specified nvram data exceeds DL_NVRAM
87 * value
88 */
89#define DL_IMAGE_TOOBIG 7 /* firmware image too big */
90
91
92struct trx_header_le {
93 __le32 magic; /* "HDR0" */
94 __le32 len; /* Length of file including header */
95 __le32 crc32; /* CRC from flag_version to end of file */
96 __le32 flag_version; /* 0:15 flags, 16:31 version */
97 __le32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of
98 * header
99 */
100};
101
102struct rdl_state_le {
103 __le32 state;
104 __le32 bytes;
105};
106
107struct bootrom_id_le {
108 __le32 chip; /* Chip id */
109 __le32 chiprev; /* Chip rev */
110 __le32 ramsize; /* Size of RAM */
111 __le32 remapbase; /* Current remap base address */
112 __le32 boardtype; /* Type of board */
113 __le32 boardrev; /* Board revision */
114};
115
52struct brcmf_usb_image { 116struct brcmf_usb_image {
53 struct list_head list; 117 struct list_head list;
54 s8 *fwname; 118 s8 *fwname;
@@ -93,6 +157,8 @@ struct brcmf_usbdev_info {
93 u8 ifnum; 157 u8 ifnum;
94 158
95 struct urb *bulk_urb; /* used for FW download */ 159 struct urb *bulk_urb; /* used for FW download */
160
161 bool wowl_enabled;
96}; 162};
97 163
98static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo, 164static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo,
@@ -600,6 +666,16 @@ static int brcmf_usb_up(struct device *dev)
600 return 0; 666 return 0;
601} 667}
602 668
669static void brcmf_cancel_all_urbs(struct brcmf_usbdev_info *devinfo)
670{
671 if (devinfo->ctl_urb)
672 usb_kill_urb(devinfo->ctl_urb);
673 if (devinfo->bulk_urb)
674 usb_kill_urb(devinfo->bulk_urb);
675 brcmf_usb_free_q(&devinfo->tx_postq, true);
676 brcmf_usb_free_q(&devinfo->rx_postq, true);
677}
678
603static void brcmf_usb_down(struct device *dev) 679static void brcmf_usb_down(struct device *dev)
604{ 680{
605 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 681 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
@@ -613,14 +689,7 @@ static void brcmf_usb_down(struct device *dev)
613 689
614 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_DOWN); 690 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_DOWN);
615 691
616 if (devinfo->ctl_urb) 692 brcmf_cancel_all_urbs(devinfo);
617 usb_kill_urb(devinfo->ctl_urb);
618
619 if (devinfo->bulk_urb)
620 usb_kill_urb(devinfo->bulk_urb);
621 brcmf_usb_free_q(&devinfo->tx_postq, true);
622
623 brcmf_usb_free_q(&devinfo->rx_postq, true);
624} 693}
625 694
626static void 695static void
@@ -783,7 +852,7 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
783 852
784 brcmf_dbg(USB, "Enter, fw %p, len %d\n", fw, fwlen); 853 brcmf_dbg(USB, "Enter, fw %p, len %d\n", fw, fwlen);
785 854
786 bulkchunk = kmalloc(RDL_CHUNK, GFP_ATOMIC); 855 bulkchunk = kmalloc(TRX_RDL_CHUNK, GFP_ATOMIC);
787 if (bulkchunk == NULL) { 856 if (bulkchunk == NULL) {
788 err = -ENOMEM; 857 err = -ENOMEM;
789 goto fail; 858 goto fail;
@@ -810,10 +879,10 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
810 /* Wait until the usb device reports it received all 879 /* Wait until the usb device reports it received all
811 * the bytes we sent */ 880 * the bytes we sent */
812 if ((rdlbytes == sent) && (rdlbytes != dllen)) { 881 if ((rdlbytes == sent) && (rdlbytes != dllen)) {
813 if ((dllen-sent) < RDL_CHUNK) 882 if ((dllen-sent) < TRX_RDL_CHUNK)
814 sendlen = dllen-sent; 883 sendlen = dllen-sent;
815 else 884 else
816 sendlen = RDL_CHUNK; 885 sendlen = TRX_RDL_CHUNK;
817 886
818 /* simply avoid having to send a ZLP by ensuring we 887 /* simply avoid having to send a ZLP by ensuring we
819 * never have an even 888 * never have an even
@@ -978,21 +1047,6 @@ static void brcmf_usb_detach(struct brcmf_usbdev_info *devinfo)
978 kfree(devinfo->rx_reqs); 1047 kfree(devinfo->rx_reqs);
979} 1048}
980 1049
981#define TRX_MAGIC 0x30524448 /* "HDR0" */
982#define TRX_VERSION 1 /* Version 1 */
983#define TRX_MAX_LEN 0x3B0000 /* Max length */
984#define TRX_NO_HEADER 1 /* Do not write TRX header */
985#define TRX_MAX_OFFSET 3 /* Max number of individual files */
986#define TRX_UNCOMP_IMAGE 0x20 /* Trx contains uncompressed image */
987
988struct trx_header_le {
989 __le32 magic; /* "HDR0" */
990 __le32 len; /* Length of file including header */
991 __le32 crc32; /* CRC from flag_version to end of file */
992 __le32 flag_version; /* 0:15 flags, 16:31 version */
993 __le32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of
994 * header */
995};
996 1050
997static int check_file(const u8 *headers) 1051static int check_file(const u8 *headers)
998{ 1052{
@@ -1094,11 +1148,24 @@ error:
1094 return NULL; 1148 return NULL;
1095} 1149}
1096 1150
1151static void brcmf_usb_wowl_config(struct device *dev, bool enabled)
1152{
1153 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
1154
1155 brcmf_dbg(USB, "Configuring WOWL, enabled=%d\n", enabled);
1156 devinfo->wowl_enabled = enabled;
1157 if (enabled)
1158 device_set_wakeup_enable(devinfo->dev, true);
1159 else
1160 device_set_wakeup_enable(devinfo->dev, false);
1161}
1162
1097static struct brcmf_bus_ops brcmf_usb_bus_ops = { 1163static struct brcmf_bus_ops brcmf_usb_bus_ops = {
1098 .txdata = brcmf_usb_tx, 1164 .txdata = brcmf_usb_tx,
1099 .stop = brcmf_usb_down, 1165 .stop = brcmf_usb_down,
1100 .txctl = brcmf_usb_tx_ctlpkt, 1166 .txctl = brcmf_usb_tx_ctlpkt,
1101 .rxctl = brcmf_usb_rx_ctlpkt, 1167 .rxctl = brcmf_usb_rx_ctlpkt,
1168 .wowl_config = brcmf_usb_wowl_config,
1102}; 1169};
1103 1170
1104static int brcmf_usb_bus_setup(struct brcmf_usbdev_info *devinfo) 1171static int brcmf_usb_bus_setup(struct brcmf_usbdev_info *devinfo)
@@ -1186,6 +1253,9 @@ static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
1186 bus->ops = &brcmf_usb_bus_ops; 1253 bus->ops = &brcmf_usb_bus_ops;
1187 bus->proto_type = BRCMF_PROTO_BCDC; 1254 bus->proto_type = BRCMF_PROTO_BCDC;
1188 bus->always_use_fws_queue = true; 1255 bus->always_use_fws_queue = true;
1256#ifdef CONFIG_PM
1257 bus->wowl_supported = true;
1258#endif
1189 1259
1190 if (!brcmf_usb_dlneeded(devinfo)) { 1260 if (!brcmf_usb_dlneeded(devinfo)) {
1191 ret = brcmf_usb_bus_setup(devinfo); 1261 ret = brcmf_usb_bus_setup(devinfo);
@@ -1339,7 +1409,10 @@ static int brcmf_usb_suspend(struct usb_interface *intf, pm_message_t state)
1339 1409
1340 brcmf_dbg(USB, "Enter\n"); 1410 brcmf_dbg(USB, "Enter\n");
1341 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_SLEEP; 1411 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_SLEEP;
1342 brcmf_detach(&usb->dev); 1412 if (devinfo->wowl_enabled)
1413 brcmf_cancel_all_urbs(devinfo);
1414 else
1415 brcmf_detach(&usb->dev);
1343 return 0; 1416 return 0;
1344} 1417}
1345 1418
@@ -1352,7 +1425,12 @@ static int brcmf_usb_resume(struct usb_interface *intf)
1352 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); 1425 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1353 1426
1354 brcmf_dbg(USB, "Enter\n"); 1427 brcmf_dbg(USB, "Enter\n");
1355 return brcmf_usb_bus_setup(devinfo); 1428 if (!devinfo->wowl_enabled)
1429 return brcmf_usb_bus_setup(devinfo);
1430
1431 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_UP;
1432 brcmf_usb_rx_fill_all(devinfo);
1433 return 0;
1356} 1434}
1357 1435
1358static int brcmf_usb_reset_resume(struct usb_interface *intf) 1436static int brcmf_usb_reset_resume(struct usb_interface *intf)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb_rdl.h b/drivers/net/wireless/brcm80211/brcmfmac/usb_rdl.h
deleted file mode 100644
index 0a35c51c3da2..000000000000
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb_rdl.h
+++ /dev/null
@@ -1,75 +0,0 @@
1/*
2 * Copyright (c) 2011 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _USB_RDL_H
18#define _USB_RDL_H
19
20/* Control messages: bRequest values */
21#define DL_GETSTATE 0 /* returns the rdl_state_t struct */
22#define DL_CHECK_CRC 1 /* currently unused */
23#define DL_GO 2 /* execute downloaded image */
24#define DL_START 3 /* initialize dl state */
25#define DL_REBOOT 4 /* reboot the device in 2 seconds */
26#define DL_GETVER 5 /* returns the bootrom_id_t struct */
27#define DL_GO_PROTECTED 6 /* execute the downloaded code and set reset
28 * event to occur in 2 seconds. It is the
29 * responsibility of the downloaded code to
30 * clear this event
31 */
32#define DL_EXEC 7 /* jump to a supplied address */
33#define DL_RESETCFG 8 /* To support single enum on dongle
34 * - Not used by bootloader
35 */
36#define DL_DEFER_RESP_OK 9 /* Potentially defer the response to setup
37 * if resp unavailable
38 */
39
40/* states */
41#define DL_WAITING 0 /* waiting to rx first pkt */
42#define DL_READY 1 /* hdr was good, waiting for more of the
43 * compressed image */
44#define DL_BAD_HDR 2 /* hdr was corrupted */
45#define DL_BAD_CRC 3 /* compressed image was corrupted */
46#define DL_RUNNABLE 4 /* download was successful,waiting for go cmd */
47#define DL_START_FAIL 5 /* failed to initialize correctly */
48#define DL_NVRAM_TOOBIG 6 /* host specified nvram data exceeds DL_NVRAM
49 * value */
50#define DL_IMAGE_TOOBIG 7 /* download image too big (exceeds DATA_START
51 * for rdl) */
52
53struct rdl_state_le {
54 __le32 state;
55 __le32 bytes;
56};
57
58struct bootrom_id_le {
59 __le32 chip; /* Chip id */
60 __le32 chiprev; /* Chip rev */
61 __le32 ramsize; /* Size of RAM */
62 __le32 remapbase; /* Current remap base address */
63 __le32 boardtype; /* Type of board */
64 __le32 boardrev; /* Board revision */
65};
66
67#define RDL_CHUNK 1500 /* size of each dl transfer */
68
69#define TRX_OFFSETS_DLFWLEN_IDX 0
70#define TRX_OFFSETS_JUMPTO_IDX 1
71#define TRX_OFFSETS_NVM_LEN_IDX 2
72
73#define TRX_OFFSETS_DLBASE_IDX 0
74
75#endif /* _USB_RDL_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/vendor.c b/drivers/net/wireless/brcm80211/brcmfmac/vendor.c
index 5960d827508c..222f26a39642 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/vendor.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/vendor.c
@@ -20,10 +20,10 @@
20 20
21#include <brcmu_wifi.h> 21#include <brcmu_wifi.h>
22#include "fwil_types.h" 22#include "fwil_types.h"
23#include "dhd.h" 23#include "core.h"
24#include "p2p.h" 24#include "p2p.h"
25#include "dhd_dbg.h" 25#include "debug.h"
26#include "wl_cfg80211.h" 26#include "cfg80211.h"
27#include "vendor.h" 27#include "vendor.h"
28#include "fwil.h" 28#include "fwil.h"
29 29
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/debug.c b/drivers/net/wireless/brcm80211/brcmsmac/debug.c
index a5d4add26f41..19740c1b1566 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/debug.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/debug.c
@@ -71,48 +71,148 @@ struct dentry *brcms_debugfs_get_devdir(struct brcms_pub *drvr)
71} 71}
72 72
73static 73static
74ssize_t brcms_debugfs_hardware_read(struct file *f, char __user *data, 74int brcms_debugfs_hardware_read(struct seq_file *s, void *data)
75 size_t count, loff_t *ppos)
76{ 75{
77 char buf[128]; 76 struct brcms_pub *drvr = s->private;
78 int res; 77
79 struct brcms_pub *drvr = f->private_data; 78 seq_printf(s, "board vendor: %x\n"
80 79 "board type: %x\n"
81 /* only allow read from start */ 80 "board revision: %x\n"
82 if (*ppos > 0) 81 "board flags: %x\n"
83 return 0; 82 "board flags2: %x\n"
84 83 "firmware revision: %x\n",
85 res = scnprintf(buf, sizeof(buf), 84 drvr->wlc->hw->d11core->bus->boardinfo.vendor,
86 "board vendor: %x\n" 85 drvr->wlc->hw->d11core->bus->boardinfo.type,
87 "board type: %x\n" 86 drvr->wlc->hw->boardrev,
88 "board revision: %x\n" 87 drvr->wlc->hw->boardflags,
89 "board flags: %x\n" 88 drvr->wlc->hw->boardflags2,
90 "board flags2: %x\n" 89 drvr->wlc->ucode_rev);
91 "firmware revision: %x\n", 90
92 drvr->wlc->hw->d11core->bus->boardinfo.vendor, 91 return 0;
93 drvr->wlc->hw->d11core->bus->boardinfo.type, 92}
94 drvr->wlc->hw->boardrev, 93
95 drvr->wlc->hw->boardflags, 94static int brcms_debugfs_macstat_read(struct seq_file *s, void *data)
96 drvr->wlc->hw->boardflags2, 95{
97 drvr->wlc->ucode_rev 96 struct brcms_pub *drvr = s->private;
98 ); 97 struct brcms_info *wl = drvr->ieee_hw->priv;
99 98 struct macstat stats;
100 return simple_read_from_buffer(data, count, ppos, buf, res); 99 int i;
100
101 spin_lock_bh(&wl->lock);
102 stats = *(drvr->wlc->core->macstat_snapshot);
103 spin_unlock_bh(&wl->lock);
104
105 seq_printf(s, "txallfrm: %d\n", stats.txallfrm);
106 seq_printf(s, "txrtsfrm: %d\n", stats.txrtsfrm);
107 seq_printf(s, "txctsfrm: %d\n", stats.txctsfrm);
108 seq_printf(s, "txackfrm: %d\n", stats.txackfrm);
109 seq_printf(s, "txdnlfrm: %d\n", stats.txdnlfrm);
110 seq_printf(s, "txbcnfrm: %d\n", stats.txbcnfrm);
111 seq_printf(s, "txfunfl[8]:");
112 for (i = 0; i < ARRAY_SIZE(stats.txfunfl); i++)
113 seq_printf(s, " %d", stats.txfunfl[i]);
114 seq_printf(s, "\ntxtplunfl: %d\n", stats.txtplunfl);
115 seq_printf(s, "txphyerr: %d\n", stats.txphyerr);
116 seq_printf(s, "pktengrxducast: %d\n", stats.pktengrxducast);
117 seq_printf(s, "pktengrxdmcast: %d\n", stats.pktengrxdmcast);
118 seq_printf(s, "rxfrmtoolong: %d\n", stats.rxfrmtoolong);
119 seq_printf(s, "rxfrmtooshrt: %d\n", stats.rxfrmtooshrt);
120 seq_printf(s, "rxinvmachdr: %d\n", stats.rxinvmachdr);
121 seq_printf(s, "rxbadfcs: %d\n", stats.rxbadfcs);
122 seq_printf(s, "rxbadplcp: %d\n", stats.rxbadplcp);
123 seq_printf(s, "rxcrsglitch: %d\n", stats.rxcrsglitch);
124 seq_printf(s, "rxstrt: %d\n", stats.rxstrt);
125 seq_printf(s, "rxdfrmucastmbss: %d\n", stats.rxdfrmucastmbss);
126 seq_printf(s, "rxmfrmucastmbss: %d\n", stats.rxmfrmucastmbss);
127 seq_printf(s, "rxcfrmucast: %d\n", stats.rxcfrmucast);
128 seq_printf(s, "rxrtsucast: %d\n", stats.rxrtsucast);
129 seq_printf(s, "rxctsucast: %d\n", stats.rxctsucast);
130 seq_printf(s, "rxackucast: %d\n", stats.rxackucast);
131 seq_printf(s, "rxdfrmocast: %d\n", stats.rxdfrmocast);
132 seq_printf(s, "rxmfrmocast: %d\n", stats.rxmfrmocast);
133 seq_printf(s, "rxcfrmocast: %d\n", stats.rxcfrmocast);
134 seq_printf(s, "rxrtsocast: %d\n", stats.rxrtsocast);
135 seq_printf(s, "rxctsocast: %d\n", stats.rxctsocast);
136 seq_printf(s, "rxdfrmmcast: %d\n", stats.rxdfrmmcast);
137 seq_printf(s, "rxmfrmmcast: %d\n", stats.rxmfrmmcast);
138 seq_printf(s, "rxcfrmmcast: %d\n", stats.rxcfrmmcast);
139 seq_printf(s, "rxbeaconmbss: %d\n", stats.rxbeaconmbss);
140 seq_printf(s, "rxdfrmucastobss: %d\n", stats.rxdfrmucastobss);
141 seq_printf(s, "rxbeaconobss: %d\n", stats.rxbeaconobss);
142 seq_printf(s, "rxrsptmout: %d\n", stats.rxrsptmout);
143 seq_printf(s, "bcntxcancl: %d\n", stats.bcntxcancl);
144 seq_printf(s, "rxf0ovfl: %d\n", stats.rxf0ovfl);
145 seq_printf(s, "rxf1ovfl: %d\n", stats.rxf1ovfl);
146 seq_printf(s, "rxf2ovfl: %d\n", stats.rxf2ovfl);
147 seq_printf(s, "txsfovfl: %d\n", stats.txsfovfl);
148 seq_printf(s, "pmqovfl: %d\n", stats.pmqovfl);
149 seq_printf(s, "rxcgprqfrm: %d\n", stats.rxcgprqfrm);
150 seq_printf(s, "rxcgprsqovfl: %d\n", stats.rxcgprsqovfl);
151 seq_printf(s, "txcgprsfail: %d\n", stats.txcgprsfail);
152 seq_printf(s, "txcgprssuc: %d\n", stats.txcgprssuc);
153 seq_printf(s, "prs_timeout: %d\n", stats.prs_timeout);
154 seq_printf(s, "rxnack: %d\n", stats.rxnack);
155 seq_printf(s, "frmscons: %d\n", stats.frmscons);
156 seq_printf(s, "txnack: %d\n", stats.txnack);
157 seq_printf(s, "txglitch_nack: %d\n", stats.txglitch_nack);
158 seq_printf(s, "txburst: %d\n", stats.txburst);
159 seq_printf(s, "bphy_rxcrsglitch: %d\n", stats.bphy_rxcrsglitch);
160 seq_printf(s, "phywatchdog: %d\n", stats.phywatchdog);
161 seq_printf(s, "bphy_badplcp: %d\n", stats.bphy_badplcp);
162 return 0;
163}
164
165struct brcms_debugfs_entry {
166 int (*read)(struct seq_file *seq, void *data);
167 struct brcms_pub *drvr;
168};
169
170static int brcms_debugfs_entry_open(struct inode *inode, struct file *f)
171{
172 struct brcms_debugfs_entry *entry = inode->i_private;
173
174 return single_open(f, entry->read, entry->drvr);
101} 175}
102 176
103static const struct file_operations brcms_debugfs_hardware_ops = { 177static const struct file_operations brcms_debugfs_def_ops = {
104 .owner = THIS_MODULE, 178 .owner = THIS_MODULE,
105 .open = simple_open, 179 .open = brcms_debugfs_entry_open,
106 .read = brcms_debugfs_hardware_read 180 .release = single_release,
181 .read = seq_read,
182 .llseek = seq_lseek
107}; 183};
108 184
185static int
186brcms_debugfs_add_entry(struct brcms_pub *drvr, const char *fn,
187 int (*read_fn)(struct seq_file *seq, void *data))
188{
189 struct device *dev = &drvr->wlc->hw->d11core->dev;
190 struct dentry *dentry = drvr->dbgfs_dir;
191 struct brcms_debugfs_entry *entry;
192
193 if (IS_ERR_OR_NULL(dentry))
194 return -ENOENT;
195
196 entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
197 if (!entry)
198 return -ENOMEM;
199
200 entry->read = read_fn;
201 entry->drvr = drvr;
202
203 dentry = debugfs_create_file(fn, S_IRUGO, dentry, entry,
204 &brcms_debugfs_def_ops);
205
206 return PTR_ERR_OR_ZERO(dentry);
207}
208
109void brcms_debugfs_create_files(struct brcms_pub *drvr) 209void brcms_debugfs_create_files(struct brcms_pub *drvr)
110{ 210{
111 struct dentry *dentry = drvr->dbgfs_dir; 211 if (IS_ERR_OR_NULL(drvr->dbgfs_dir))
212 return;
112 213
113 if (!IS_ERR_OR_NULL(dentry)) 214 brcms_debugfs_add_entry(drvr, "hardware", brcms_debugfs_hardware_read);
114 debugfs_create_file("hardware", S_IRUGO, dentry, 215 brcms_debugfs_add_entry(drvr, "macstat", brcms_debugfs_macstat_read);
115 drvr, &brcms_debugfs_hardware_ops);
116} 216}
117 217
118#define __brcms_fn(fn) \ 218#define __brcms_fn(fn) \
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/main.c b/drivers/net/wireless/brcm80211/brcmsmac/main.c
index 1b474828d5b8..bc9be78faafa 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/main.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/main.c
@@ -3081,7 +3081,7 @@ static bool brcms_c_ps_allowed(struct brcms_c_info *wlc)
3081static void brcms_c_statsupd(struct brcms_c_info *wlc) 3081static void brcms_c_statsupd(struct brcms_c_info *wlc)
3082{ 3082{
3083 int i; 3083 int i;
3084 struct macstat macstats; 3084 struct macstat *macstats;
3085#ifdef DEBUG 3085#ifdef DEBUG
3086 u16 delta; 3086 u16 delta;
3087 u16 rxf0ovfl; 3087 u16 rxf0ovfl;
@@ -3092,31 +3092,31 @@ static void brcms_c_statsupd(struct brcms_c_info *wlc)
3092 if (!wlc->pub->up) 3092 if (!wlc->pub->up)
3093 return; 3093 return;
3094 3094
3095 macstats = wlc->core->macstat_snapshot;
3096
3095#ifdef DEBUG 3097#ifdef DEBUG
3096 /* save last rx fifo 0 overflow count */ 3098 /* save last rx fifo 0 overflow count */
3097 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl; 3099 rxf0ovfl = macstats->rxf0ovfl;
3098 3100
3099 /* save last tx fifo underflow count */ 3101 /* save last tx fifo underflow count */
3100 for (i = 0; i < NFIFO; i++) 3102 for (i = 0; i < NFIFO; i++)
3101 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i]; 3103 txfunfl[i] = macstats->txfunfl[i];
3102#endif /* DEBUG */ 3104#endif /* DEBUG */
3103 3105
3104 /* Read mac stats from contiguous shared memory */ 3106 /* Read mac stats from contiguous shared memory */
3105 brcms_b_copyfrom_objmem(wlc->hw, M_UCODE_MACSTAT, &macstats, 3107 brcms_b_copyfrom_objmem(wlc->hw, M_UCODE_MACSTAT, macstats,
3106 sizeof(struct macstat), OBJADDR_SHM_SEL); 3108 sizeof(*macstats), OBJADDR_SHM_SEL);
3107 3109
3108#ifdef DEBUG 3110#ifdef DEBUG
3109 /* check for rx fifo 0 overflow */ 3111 /* check for rx fifo 0 overflow */
3110 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl); 3112 delta = (u16)(macstats->rxf0ovfl - rxf0ovfl);
3111 if (delta) 3113 if (delta)
3112 brcms_err(wlc->hw->d11core, "wl%d: %u rx fifo 0 overflows!\n", 3114 brcms_err(wlc->hw->d11core, "wl%d: %u rx fifo 0 overflows!\n",
3113 wlc->pub->unit, delta); 3115 wlc->pub->unit, delta);
3114 3116
3115 /* check for tx fifo underflows */ 3117 /* check for tx fifo underflows */
3116 for (i = 0; i < NFIFO; i++) { 3118 for (i = 0; i < NFIFO; i++) {
3117 delta = 3119 delta = macstats->txfunfl[i] - txfunfl[i];
3118 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
3119 txfunfl[i]);
3120 if (delta) 3120 if (delta)
3121 brcms_err(wlc->hw->d11core, 3121 brcms_err(wlc->hw->d11core,
3122 "wl%d: %u tx fifo %d underflows!\n", 3122 "wl%d: %u tx fifo %d underflows!\n",
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index edc344334a75..67cad9b05ad8 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -1363,7 +1363,7 @@ static ssize_t show_cmd_log(struct device *d,
1363 if (!priv->cmdlog) 1363 if (!priv->cmdlog)
1364 return 0; 1364 return 0;
1365 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; 1365 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1366 (i != priv->cmdlog_pos) && (PAGE_SIZE - len); 1366 (i != priv->cmdlog_pos) && (len < PAGE_SIZE);
1367 i = (i + 1) % priv->cmdlog_len) { 1367 i = (i + 1) % priv->cmdlog_len) {
1368 len += 1368 len +=
1369 snprintf(buf + len, PAGE_SIZE - len, 1369 snprintf(buf + len, PAGE_SIZE - len,
diff --git a/drivers/net/wireless/ipw2x00/libipw.h b/drivers/net/wireless/ipw2x00/libipw.h
index 5ce2f59d3378..b0571618c2ed 100644
--- a/drivers/net/wireless/ipw2x00/libipw.h
+++ b/drivers/net/wireless/ipw2x00/libipw.h
@@ -654,10 +654,6 @@ struct libipw_network {
654 /* TPC Report - mandatory if spctrm mgmt required */ 654 /* TPC Report - mandatory if spctrm mgmt required */
655 struct libipw_tpc_report tpc_report; 655 struct libipw_tpc_report tpc_report;
656 656
657 /* IBSS DFS - mandatory if spctrm mgmt required and IBSS
658 * NOTE: This is variable length and so must be allocated dynamically */
659 struct libipw_ibss_dfs *ibss_dfs;
660
661 /* Channel Switch Announcement - optional if spctrm mgmt required */ 657 /* Channel Switch Announcement - optional if spctrm mgmt required */
662 struct libipw_csa csa; 658 struct libipw_csa csa;
663 659
@@ -970,7 +966,6 @@ int libipw_rx(struct libipw_device *ieee, struct sk_buff *skb,
970/* make sure to set stats->len */ 966/* make sure to set stats->len */
971void libipw_rx_mgt(struct libipw_device *ieee, struct libipw_hdr_4addr *header, 967void libipw_rx_mgt(struct libipw_device *ieee, struct libipw_hdr_4addr *header,
972 struct libipw_rx_stats *stats); 968 struct libipw_rx_stats *stats);
973void libipw_network_reset(struct libipw_network *network);
974 969
975/* libipw_geo.c */ 970/* libipw_geo.c */
976const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee); 971const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee);
diff --git a/drivers/net/wireless/ipw2x00/libipw_module.c b/drivers/net/wireless/ipw2x00/libipw_module.c
index 5f31b72a4921..60f28740f6af 100644
--- a/drivers/net/wireless/ipw2x00/libipw_module.c
+++ b/drivers/net/wireless/ipw2x00/libipw_module.c
@@ -84,25 +84,12 @@ static int libipw_networks_allocate(struct libipw_device *ieee)
84 return 0; 84 return 0;
85} 85}
86 86
87void libipw_network_reset(struct libipw_network *network)
88{
89 if (!network)
90 return;
91
92 if (network->ibss_dfs) {
93 kfree(network->ibss_dfs);
94 network->ibss_dfs = NULL;
95 }
96}
97
98static inline void libipw_networks_free(struct libipw_device *ieee) 87static inline void libipw_networks_free(struct libipw_device *ieee)
99{ 88{
100 int i; 89 int i;
101 90
102 for (i = 0; i < MAX_NETWORK_COUNT; i++) { 91 for (i = 0; i < MAX_NETWORK_COUNT; i++)
103 kfree(ieee->networks[i]->ibss_dfs);
104 kfree(ieee->networks[i]); 92 kfree(ieee->networks[i]);
105 }
106} 93}
107 94
108void libipw_networks_age(struct libipw_device *ieee, 95void libipw_networks_age(struct libipw_device *ieee,
diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
index 2d66984079bb..a6877dd6ba73 100644
--- a/drivers/net/wireless/ipw2x00/libipw_rx.c
+++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
@@ -1298,13 +1298,6 @@ static int libipw_parse_info_param(struct libipw_info_element
1298 break; 1298 break;
1299 1299
1300 case WLAN_EID_IBSS_DFS: 1300 case WLAN_EID_IBSS_DFS:
1301 if (network->ibss_dfs)
1302 break;
1303 network->ibss_dfs = kmemdup(info_element->data,
1304 info_element->len,
1305 GFP_ATOMIC);
1306 if (!network->ibss_dfs)
1307 return 1;
1308 network->flags |= NETWORK_HAS_IBSS_DFS; 1301 network->flags |= NETWORK_HAS_IBSS_DFS;
1309 break; 1302 break;
1310 1303
@@ -1335,9 +1328,7 @@ static int libipw_parse_info_param(struct libipw_info_element
1335static int libipw_handle_assoc_resp(struct libipw_device *ieee, struct libipw_assoc_response 1328static int libipw_handle_assoc_resp(struct libipw_device *ieee, struct libipw_assoc_response
1336 *frame, struct libipw_rx_stats *stats) 1329 *frame, struct libipw_rx_stats *stats)
1337{ 1330{
1338 struct libipw_network network_resp = { 1331 struct libipw_network network_resp = { };
1339 .ibss_dfs = NULL,
1340 };
1341 struct libipw_network *network = &network_resp; 1332 struct libipw_network *network = &network_resp;
1342 struct net_device *dev = ieee->dev; 1333 struct net_device *dev = ieee->dev;
1343 1334
@@ -1472,9 +1463,6 @@ static void update_network(struct libipw_network *dst,
1472 int qos_active; 1463 int qos_active;
1473 u8 old_param; 1464 u8 old_param;
1474 1465
1475 libipw_network_reset(dst);
1476 dst->ibss_dfs = src->ibss_dfs;
1477
1478 /* We only update the statistics if they were created by receiving 1466 /* We only update the statistics if they were created by receiving
1479 * the network information on the actual channel the network is on. 1467 * the network information on the actual channel the network is on.
1480 * 1468 *
@@ -1548,9 +1536,7 @@ static void libipw_process_probe_response(struct libipw_device
1548 *stats) 1536 *stats)
1549{ 1537{
1550 struct net_device *dev = ieee->dev; 1538 struct net_device *dev = ieee->dev;
1551 struct libipw_network network = { 1539 struct libipw_network network = { };
1552 .ibss_dfs = NULL,
1553 };
1554 struct libipw_network *target; 1540 struct libipw_network *target;
1555 struct libipw_network *oldest = NULL; 1541 struct libipw_network *oldest = NULL;
1556#ifdef CONFIG_LIBIPW_DEBUG 1542#ifdef CONFIG_LIBIPW_DEBUG
@@ -1618,7 +1604,6 @@ static void libipw_process_probe_response(struct libipw_device
1618 LIBIPW_DEBUG_SCAN("Expired '%*pE' (%pM) from network list.\n", 1604 LIBIPW_DEBUG_SCAN("Expired '%*pE' (%pM) from network list.\n",
1619 target->ssid_len, target->ssid, 1605 target->ssid_len, target->ssid,
1620 target->bssid); 1606 target->bssid);
1621 libipw_network_reset(target);
1622 } else { 1607 } else {
1623 /* Otherwise just pull from the free list */ 1608 /* Otherwise just pull from the free list */
1624 target = list_entry(ieee->network_free_list.next, 1609 target = list_entry(ieee->network_free_list.next,
@@ -1634,7 +1619,6 @@ static void libipw_process_probe_response(struct libipw_device
1634 "BEACON" : "PROBE RESPONSE"); 1619 "BEACON" : "PROBE RESPONSE");
1635#endif 1620#endif
1636 memcpy(target, &network, sizeof(*target)); 1621 memcpy(target, &network, sizeof(*target));
1637 network.ibss_dfs = NULL;
1638 list_add_tail(&target->list, &ieee->network_list); 1622 list_add_tail(&target->list, &ieee->network_list);
1639 } else { 1623 } else {
1640 LIBIPW_DEBUG_SCAN("Updating '%*pE' (%pM) via %s.\n", 1624 LIBIPW_DEBUG_SCAN("Updating '%*pE' (%pM) via %s.\n",
@@ -1643,7 +1627,6 @@ static void libipw_process_probe_response(struct libipw_device
1643 is_beacon(beacon->header.frame_ctl) ? 1627 is_beacon(beacon->header.frame_ctl) ?
1644 "BEACON" : "PROBE RESPONSE"); 1628 "BEACON" : "PROBE RESPONSE");
1645 update_network(target, &network); 1629 update_network(target, &network);
1646 network.ibss_dfs = NULL;
1647 } 1630 }
1648 1631
1649 spin_unlock_irqrestore(&ieee->lock, flags); 1632 spin_unlock_irqrestore(&ieee->lock, flags);
diff --git a/drivers/net/wireless/iwlegacy/4965-mac.c b/drivers/net/wireless/iwlegacy/4965-mac.c
index 26fec54dcd03..2748fde4b90c 100644
--- a/drivers/net/wireless/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/iwlegacy/4965-mac.c
@@ -6063,7 +6063,7 @@ il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6063} 6063}
6064 6064
6065void 6065void
6066il4965_mac_channel_switch(struct ieee80211_hw *hw, 6066il4965_mac_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6067 struct ieee80211_channel_switch *ch_switch) 6067 struct ieee80211_channel_switch *ch_switch)
6068{ 6068{
6069 struct il_priv *il = hw->priv; 6069 struct il_priv *il = hw->priv;
diff --git a/drivers/net/wireless/iwlegacy/4965.h b/drivers/net/wireless/iwlegacy/4965.h
index 337dfcf3bbde..3a57f71b8ed5 100644
--- a/drivers/net/wireless/iwlegacy/4965.h
+++ b/drivers/net/wireless/iwlegacy/4965.h
@@ -187,8 +187,9 @@ int il4965_mac_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
187 u8 buf_size); 187 u8 buf_size);
188int il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 188int il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
189 struct ieee80211_sta *sta); 189 struct ieee80211_sta *sta);
190void il4965_mac_channel_switch(struct ieee80211_hw *hw, 190void
191 struct ieee80211_channel_switch *ch_switch); 191il4965_mac_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
192 struct ieee80211_channel_switch *ch_switch);
192 193
193void il4965_led_enable(struct il_priv *il); 194void il4965_led_enable(struct il_priv *il);
194 195
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index 267e48a2915e..139de90c2aaf 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -59,6 +59,7 @@ config IWLDVM
59 59
60config IWLMVM 60config IWLMVM
61 tristate "Intel Wireless WiFi MVM Firmware support" 61 tristate "Intel Wireless WiFi MVM Firmware support"
62 select BACKPORT_WANT_DEV_COREDUMP
62 help 63 help
63 This is the driver that supports the MVM firmware which is 64 This is the driver that supports the MVM firmware which is
64 currently only available for 7260 and 3160 devices. 65 currently only available for 7260 and 3160 devices.
diff --git a/drivers/net/wireless/iwlwifi/dvm/lib.c b/drivers/net/wireless/iwlwifi/dvm/lib.c
index 2191621d69c1..02e4ede2b042 100644
--- a/drivers/net/wireless/iwlwifi/dvm/lib.c
+++ b/drivers/net/wireless/iwlwifi/dvm/lib.c
@@ -418,8 +418,8 @@ void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
418 418
419static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg) 419static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
420{ 420{
421 return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >> 421 return (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
422 BT_UART_MSG_FRAME3SCOESCO_POS; 422 BT_UART_MSG_FRAME3SCOESCO_POS;
423} 423}
424 424
425static void iwlagn_bt_traffic_change_work(struct work_struct *work) 425static void iwlagn_bt_traffic_change_work(struct work_struct *work)
diff --git a/drivers/net/wireless/iwlwifi/dvm/mac80211.c b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
index cae692ff1013..47e64e8b9517 100644
--- a/drivers/net/wireless/iwlwifi/dvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
@@ -941,6 +941,7 @@ static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
941} 941}
942 942
943static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw, 943static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
944 struct ieee80211_vif *vif,
944 struct ieee80211_channel_switch *ch_switch) 945 struct ieee80211_channel_switch *ch_switch)
945{ 946{
946 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 947 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
diff --git a/drivers/net/wireless/iwlwifi/iwl-8000.c b/drivers/net/wireless/iwlwifi/iwl-8000.c
index d2b7234b1c73..896ea906549c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-8000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-8000.c
@@ -104,6 +104,7 @@ static const struct iwl_base_params iwl8000_base_params = {
104}; 104};
105 105
106static const struct iwl_ht_params iwl8000_ht_params = { 106static const struct iwl_ht_params iwl8000_ht_params = {
107 .stbc = true,
107 .ldpc = true, 108 .ldpc = true,
108 .ht40_bands = BIT(IEEE80211_BAND_2GHZ) | BIT(IEEE80211_BAND_5GHZ), 109 .ht40_bands = BIT(IEEE80211_BAND_2GHZ) | BIT(IEEE80211_BAND_5GHZ),
109}; 110};
diff --git a/drivers/net/wireless/iwlwifi/iwl-config.h b/drivers/net/wireless/iwlwifi/iwl-config.h
index 2ef83a39ff10..f8aa9cf08279 100644
--- a/drivers/net/wireless/iwlwifi/iwl-config.h
+++ b/drivers/net/wireless/iwlwifi/iwl-config.h
@@ -87,6 +87,16 @@ enum iwl_device_family {
87 IWL_DEVICE_FAMILY_8000, 87 IWL_DEVICE_FAMILY_8000,
88}; 88};
89 89
90static inline bool iwl_has_secure_boot(u32 hw_rev,
91 enum iwl_device_family family)
92{
93 /* return 1 only for family 8000 B0 */
94 if ((family == IWL_DEVICE_FAMILY_8000) && (hw_rev & 0xC))
95 return 1;
96
97 return 0;
98}
99
90/* 100/*
91 * LED mode 101 * LED mode
92 * IWL_LED_DEFAULT: use device default 102 * IWL_LED_DEFAULT: use device default
@@ -246,6 +256,7 @@ struct iwl_pwr_tx_backoff {
246 * @nvm_hw_section_num: the ID of the HW NVM section 256 * @nvm_hw_section_num: the ID of the HW NVM section
247 * @pwr_tx_backoffs: translation table between power limits and backoffs 257 * @pwr_tx_backoffs: translation table between power limits and backoffs
248 * @max_rx_agg_size: max RX aggregation size of the ADDBA request/response 258 * @max_rx_agg_size: max RX aggregation size of the ADDBA request/response
259 * @max_tx_agg_size: max TX aggregation size of the ADDBA request/response
249 * 260 *
250 * We enable the driver to be backward compatible wrt. hardware features. 261 * We enable the driver to be backward compatible wrt. hardware features.
251 * API differences in uCode shouldn't be handled here but through TLVs 262 * API differences in uCode shouldn't be handled here but through TLVs
@@ -285,6 +296,7 @@ struct iwl_cfg {
285 const char *default_nvm_file; 296 const char *default_nvm_file;
286 unsigned int max_rx_agg_size; 297 unsigned int max_rx_agg_size;
287 bool disable_dummy_notification; 298 bool disable_dummy_notification;
299 unsigned int max_tx_agg_size;
288}; 300};
289 301
290/* 302/*
diff --git a/drivers/net/wireless/iwlwifi/iwl-drv.c b/drivers/net/wireless/iwlwifi/iwl-drv.c
index 0f1084f09caa..d9fa8e034da2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-drv.c
+++ b/drivers/net/wireless/iwlwifi/iwl-drv.c
@@ -807,19 +807,16 @@ static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
807 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR, 807 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
808 tlv_len); 808 tlv_len);
809 drv->fw.mvm_fw = true; 809 drv->fw.mvm_fw = true;
810 drv->fw.img[IWL_UCODE_REGULAR].is_secure = true;
811 break; 810 break;
812 case IWL_UCODE_TLV_SECURE_SEC_INIT: 811 case IWL_UCODE_TLV_SECURE_SEC_INIT:
813 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT, 812 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
814 tlv_len); 813 tlv_len);
815 drv->fw.mvm_fw = true; 814 drv->fw.mvm_fw = true;
816 drv->fw.img[IWL_UCODE_INIT].is_secure = true;
817 break; 815 break;
818 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN: 816 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
819 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN, 817 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
820 tlv_len); 818 tlv_len);
821 drv->fw.mvm_fw = true; 819 drv->fw.mvm_fw = true;
822 drv->fw.img[IWL_UCODE_WOWLAN].is_secure = true;
823 break; 820 break;
824 case IWL_UCODE_TLV_NUM_OF_CPU: 821 case IWL_UCODE_TLV_NUM_OF_CPU:
825 if (tlv_len != sizeof(u32)) 822 if (tlv_len != sizeof(u32))
diff --git a/drivers/net/wireless/iwlwifi/iwl-fw.h b/drivers/net/wireless/iwlwifi/iwl-fw.h
index 4f6e66892acc..6f7ae5f7bdae 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fw.h
@@ -227,7 +227,6 @@ struct fw_desc {
227 227
228struct fw_img { 228struct fw_img {
229 struct fw_desc sec[IWL_UCODE_SECTION_MAX]; 229 struct fw_desc sec[IWL_UCODE_SECTION_MAX];
230 bool is_secure;
231 bool is_dual_cpus; 230 bool is_dual_cpus;
232}; 231};
233 232
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans.h b/drivers/net/wireless/iwlwifi/iwl-trans.h
index d8fc548c0d6c..0768f83e709d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans.h
+++ b/drivers/net/wireless/iwlwifi/iwl-trans.h
@@ -535,9 +535,7 @@ struct iwl_trans_ops {
535 void (*ref)(struct iwl_trans *trans); 535 void (*ref)(struct iwl_trans *trans);
536 void (*unref)(struct iwl_trans *trans); 536 void (*unref)(struct iwl_trans *trans);
537 537
538#ifdef CONFIG_IWLWIFI_DEBUGFS
539 struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans); 538 struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans);
540#endif
541}; 539};
542 540
543/** 541/**
@@ -704,7 +702,6 @@ static inline void iwl_trans_unref(struct iwl_trans *trans)
704 trans->ops->unref(trans); 702 trans->ops->unref(trans);
705} 703}
706 704
707#ifdef CONFIG_IWLWIFI_DEBUGFS
708static inline struct iwl_trans_dump_data * 705static inline struct iwl_trans_dump_data *
709iwl_trans_dump_data(struct iwl_trans *trans) 706iwl_trans_dump_data(struct iwl_trans *trans)
710{ 707{
@@ -712,7 +709,6 @@ iwl_trans_dump_data(struct iwl_trans *trans)
712 return NULL; 709 return NULL;
713 return trans->ops->dump_data(trans); 710 return trans->ops->dump_data(trans);
714} 711}
715#endif
716 712
717static inline int iwl_trans_send_cmd(struct iwl_trans *trans, 713static inline int iwl_trans_send_cmd(struct iwl_trans *trans,
718 struct iwl_host_cmd *cmd) 714 struct iwl_host_cmd *cmd)
diff --git a/drivers/net/wireless/iwlwifi/mvm/coex.c b/drivers/net/wireless/iwlwifi/mvm/coex.c
index da2ffb785194..508c81359e41 100644
--- a/drivers/net/wireless/iwlwifi/mvm/coex.c
+++ b/drivers/net/wireless/iwlwifi/mvm/coex.c
@@ -72,8 +72,6 @@
72#include "mvm.h" 72#include "mvm.h"
73#include "iwl-debug.h" 73#include "iwl-debug.h"
74 74
75#define BT_ANTENNA_COUPLING_THRESHOLD (30)
76
77const u32 iwl_bt_ctl_kill_msk[BT_KILL_MSK_MAX] = { 75const u32 iwl_bt_ctl_kill_msk[BT_KILL_MSK_MAX] = {
78 [BT_KILL_MSK_DEFAULT] = 0xfffffc00, 76 [BT_KILL_MSK_DEFAULT] = 0xfffffc00,
79 [BT_KILL_MSK_NEVER] = 0xffffffff, 77 [BT_KILL_MSK_NEVER] = 0xffffffff,
@@ -302,11 +300,6 @@ static const __le64 iwl_ci_mask[][3] = {
302 }, 300 },
303}; 301};
304 302
305static const __le32 iwl_bt_mprio_lut[BT_COEX_MULTI_PRIO_LUT_SIZE] = {
306 cpu_to_le32(0x2e402280),
307 cpu_to_le32(0x7711a751),
308};
309
310struct corunning_block_luts { 303struct corunning_block_luts {
311 u8 range; 304 u8 range;
312 __le32 lut20[BT_COEX_CORUN_LUT_SIZE]; 305 __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
@@ -605,7 +598,7 @@ int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
605 598
606 bt_cmd->max_kill = cpu_to_le32(5); 599 bt_cmd->max_kill = cpu_to_le32(5);
607 bt_cmd->bt4_antenna_isolation_thr = 600 bt_cmd->bt4_antenna_isolation_thr =
608 cpu_to_le32(BT_ANTENNA_COUPLING_THRESHOLD); 601 cpu_to_le32(IWL_MVM_BT_COEX_ANTENNA_COUPLING_THRS);
609 bt_cmd->bt4_tx_tx_delta_freq_thr = cpu_to_le32(15); 602 bt_cmd->bt4_tx_tx_delta_freq_thr = cpu_to_le32(15);
610 bt_cmd->bt4_tx_rx_max_freq0 = cpu_to_le32(15); 603 bt_cmd->bt4_tx_rx_max_freq0 = cpu_to_le32(15);
611 bt_cmd->override_primary_lut = cpu_to_le32(BT_COEX_INVALID_LUT); 604 bt_cmd->override_primary_lut = cpu_to_le32(BT_COEX_INVALID_LUT);
@@ -638,8 +631,8 @@ int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
638 631
639 memcpy(&bt_cmd->mplut_prio_boost, iwl_bt_prio_boost, 632 memcpy(&bt_cmd->mplut_prio_boost, iwl_bt_prio_boost,
640 sizeof(iwl_bt_prio_boost)); 633 sizeof(iwl_bt_prio_boost));
641 memcpy(&bt_cmd->multiprio_lut, iwl_bt_mprio_lut, 634 bt_cmd->multiprio_lut[0] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG0);
642 sizeof(iwl_bt_mprio_lut)); 635 bt_cmd->multiprio_lut[1] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG1);
643 636
644send_cmd: 637send_cmd:
645 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 638 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
diff --git a/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c b/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c
index 8a1d2f33d5b7..b571e1b0550c 100644
--- a/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c
+++ b/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c
@@ -102,8 +102,6 @@ static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
102 102
103#undef EVENT_PRIO_ANT 103#undef EVENT_PRIO_ANT
104 104
105#define BT_ANTENNA_COUPLING_THRESHOLD (30)
106
107static int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm) 105static int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm)
108{ 106{
109 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) 107 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
@@ -290,11 +288,6 @@ static const __le64 iwl_ci_mask[][3] = {
290 }, 288 },
291}; 289};
292 290
293static const __le32 iwl_bt_mprio_lut[BT_COEX_MULTI_PRIO_LUT_SIZE] = {
294 cpu_to_le32(0x2e402280),
295 cpu_to_le32(0x7711a751),
296};
297
298struct corunning_block_luts { 291struct corunning_block_luts {
299 u8 range; 292 u8 range;
300 __le32 lut20[BT_COEX_CORUN_LUT_SIZE]; 293 __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
@@ -593,7 +586,8 @@ int iwl_send_bt_init_conf_old(struct iwl_mvm *mvm)
593 } 586 }
594 587
595 bt_cmd->max_kill = 5; 588 bt_cmd->max_kill = 5;
596 bt_cmd->bt4_antenna_isolation_thr = BT_ANTENNA_COUPLING_THRESHOLD; 589 bt_cmd->bt4_antenna_isolation_thr =
590 IWL_MVM_BT_COEX_ANTENNA_COUPLING_THRS;
597 bt_cmd->bt4_antenna_isolation = iwlwifi_mod_params.ant_coupling; 591 bt_cmd->bt4_antenna_isolation = iwlwifi_mod_params.ant_coupling;
598 bt_cmd->bt4_tx_tx_delta_freq_thr = 15; 592 bt_cmd->bt4_tx_tx_delta_freq_thr = 15;
599 bt_cmd->bt4_tx_rx_max_freq0 = 15; 593 bt_cmd->bt4_tx_rx_max_freq0 = 15;
@@ -649,8 +643,8 @@ int iwl_send_bt_init_conf_old(struct iwl_mvm *mvm)
649 643
650 memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost, 644 memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost,
651 sizeof(iwl_bt_prio_boost)); 645 sizeof(iwl_bt_prio_boost));
652 memcpy(&bt_cmd->bt4_multiprio_lut, iwl_bt_mprio_lut, 646 bt_cmd->bt4_multiprio_lut[0] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG0);
653 sizeof(iwl_bt_mprio_lut)); 647 bt_cmd->bt4_multiprio_lut[1] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG1);
654 648
655send_cmd: 649send_cmd:
656 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old)); 650 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
diff --git a/drivers/net/wireless/iwlwifi/mvm/constants.h b/drivers/net/wireless/iwlwifi/mvm/constants.h
index d4dfbe4cb66d..5c1ea80d5e3b 100644
--- a/drivers/net/wireless/iwlwifi/mvm/constants.h
+++ b/drivers/net/wireless/iwlwifi/mvm/constants.h
@@ -92,8 +92,13 @@
92#define IWL_MVM_BT_COEX_SYNC2SCO 1 92#define IWL_MVM_BT_COEX_SYNC2SCO 1
93#define IWL_MVM_BT_COEX_CORUNNING 0 93#define IWL_MVM_BT_COEX_CORUNNING 0
94#define IWL_MVM_BT_COEX_MPLUT 1 94#define IWL_MVM_BT_COEX_MPLUT 1
95#define IWL_MVM_BT_COEX_MPLUT_REG0 0x2e402280
96#define IWL_MVM_BT_COEX_MPLUT_REG1 0x7711a751
97#define IWL_MVM_BT_COEX_ANTENNA_COUPLING_THRS 30
95#define IWL_MVM_FW_MCAST_FILTER_PASS_ALL 0 98#define IWL_MVM_FW_MCAST_FILTER_PASS_ALL 0
99#define IWL_MVM_FW_BCAST_FILTER_PASS_ALL 0
96#define IWL_MVM_QUOTA_THRESHOLD 8 100#define IWL_MVM_QUOTA_THRESHOLD 8
97#define IWL_MVM_RS_RSSI_BASED_INIT_RATE 0 101#define IWL_MVM_RS_RSSI_BASED_INIT_RATE 0
102#define IWL_MVM_RS_DISABLE_MIMO 0
98 103
99#endif /* __MVM_CONSTANTS_H */ 104#endif /* __MVM_CONSTANTS_H */
diff --git a/drivers/net/wireless/iwlwifi/mvm/d3.c b/drivers/net/wireless/iwlwifi/mvm/d3.c
index c17be0fb7283..3bbb511b0b38 100644
--- a/drivers/net/wireless/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/iwlwifi/mvm/d3.c
@@ -601,33 +601,6 @@ static int iwl_mvm_send_remote_wake_cfg(struct iwl_mvm *mvm,
601 return ret; 601 return ret;
602} 602}
603 603
604struct iwl_d3_iter_data {
605 struct iwl_mvm *mvm;
606 struct ieee80211_vif *vif;
607 bool error;
608};
609
610static void iwl_mvm_d3_iface_iterator(void *_data, u8 *mac,
611 struct ieee80211_vif *vif)
612{
613 struct iwl_d3_iter_data *data = _data;
614 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
615
616 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
617 return;
618
619 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
620 return;
621
622 if (data->vif) {
623 IWL_ERR(data->mvm, "More than one managed interface active!\n");
624 data->error = true;
625 return;
626 }
627
628 data->vif = vif;
629}
630
631static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 604static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
632 struct ieee80211_sta *ap_sta) 605 struct ieee80211_sta *ap_sta)
633{ 606{
@@ -783,6 +756,35 @@ void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
783 IWL_ERR(mvm, "failed to set non-QoS seqno\n"); 756 IWL_ERR(mvm, "failed to set non-QoS seqno\n");
784} 757}
785 758
759static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm)
760{
761 iwl_mvm_cancel_scan(mvm);
762
763 iwl_trans_stop_device(mvm->trans);
764
765 /*
766 * Set the HW restart bit -- this is mostly true as we're
767 * going to load new firmware and reprogram that, though
768 * the reprogramming is going to be manual to avoid adding
769 * all the MACs that aren't support.
770 * We don't have to clear up everything though because the
771 * reprogramming is manual. When we resume, we'll actually
772 * go through a proper restart sequence again to switch
773 * back to the runtime firmware image.
774 */
775 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
776
777 /* We reprogram keys and shouldn't allocate new key indices */
778 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
779
780 mvm->ptk_ivlen = 0;
781 mvm->ptk_icvlen = 0;
782 mvm->ptk_ivlen = 0;
783 mvm->ptk_icvlen = 0;
784
785 return iwl_mvm_load_d3_fw(mvm);
786}
787
786static int 788static int
787iwl_mvm_send_wowlan_config_cmd(struct iwl_mvm *mvm, 789iwl_mvm_send_wowlan_config_cmd(struct iwl_mvm *mvm,
788 const struct iwl_wowlan_config_cmd_v3 *cmd) 790 const struct iwl_wowlan_config_cmd_v3 *cmd)
@@ -797,116 +799,52 @@ iwl_mvm_send_wowlan_config_cmd(struct iwl_mvm *mvm,
797 cmd_len, cmd); 799 cmd_len, cmd);
798} 800}
799 801
800static int __iwl_mvm_suspend(struct ieee80211_hw *hw, 802static int
801 struct cfg80211_wowlan *wowlan, 803iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm,
802 bool test) 804 struct cfg80211_wowlan *wowlan,
805 struct iwl_wowlan_config_cmd_v3 *wowlan_config_cmd,
806 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
807 struct ieee80211_sta *ap_sta)
803{ 808{
804 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
805 struct iwl_d3_iter_data suspend_iter_data = {
806 .mvm = mvm,
807 };
808 struct ieee80211_vif *vif;
809 struct iwl_mvm_vif *mvmvif;
810 struct ieee80211_sta *ap_sta;
811 struct iwl_mvm_sta *mvm_ap_sta;
812 struct iwl_wowlan_config_cmd_v3 wowlan_config_cmd = {};
813 struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {};
814 struct iwl_wowlan_tkip_params_cmd tkip_cmd = {};
815 struct iwl_d3_manager_config d3_cfg_cmd_data = {
816 /*
817 * Program the minimum sleep time to 10 seconds, as many
818 * platforms have issues processing a wakeup signal while
819 * still being in the process of suspending.
820 */
821 .min_sleep_time = cpu_to_le32(10 * 1000 * 1000),
822 };
823 struct iwl_host_cmd d3_cfg_cmd = {
824 .id = D3_CONFIG_CMD,
825 .flags = CMD_WANT_SKB,
826 .data[0] = &d3_cfg_cmd_data,
827 .len[0] = sizeof(d3_cfg_cmd_data),
828 };
829 struct wowlan_key_data key_data = {
830 .use_rsc_tsc = false,
831 .tkip = &tkip_cmd,
832 .use_tkip = false,
833 };
834 int ret; 809 int ret;
835 int len __maybe_unused; 810 struct iwl_mvm_sta *mvm_ap_sta = (struct iwl_mvm_sta *)ap_sta->drv_priv;
836
837 if (!wowlan) {
838 /*
839 * mac80211 shouldn't get here, but for D3 test
840 * it doesn't warrant a warning
841 */
842 WARN_ON(!test);
843 return -EINVAL;
844 }
845
846 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
847 if (!key_data.rsc_tsc)
848 return -ENOMEM;
849
850 mutex_lock(&mvm->mutex);
851
852 /* see if there's only a single BSS vif and it's associated */
853 ieee80211_iterate_active_interfaces_atomic(
854 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
855 iwl_mvm_d3_iface_iterator, &suspend_iter_data);
856
857 if (suspend_iter_data.error || !suspend_iter_data.vif) {
858 ret = 1;
859 goto out_noreset;
860 }
861
862 vif = suspend_iter_data.vif;
863 mvmvif = iwl_mvm_vif_from_mac80211(vif);
864
865 ap_sta = rcu_dereference_protected(
866 mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
867 lockdep_is_held(&mvm->mutex));
868 if (IS_ERR_OR_NULL(ap_sta)) {
869 ret = -EINVAL;
870 goto out_noreset;
871 }
872
873 mvm_ap_sta = (struct iwl_mvm_sta *)ap_sta->drv_priv;
874 811
875 /* TODO: wowlan_config_cmd.common.wowlan_ba_teardown_tids */ 812 /* TODO: wowlan_config_cmd->common.wowlan_ba_teardown_tids */
876 813
877 wowlan_config_cmd.common.is_11n_connection = 814 wowlan_config_cmd->common.is_11n_connection =
878 ap_sta->ht_cap.ht_supported; 815 ap_sta->ht_cap.ht_supported;
879 816
880 /* Query the last used seqno and set it */ 817 /* Query the last used seqno and set it */
881 ret = iwl_mvm_get_last_nonqos_seq(mvm, vif); 818 ret = iwl_mvm_get_last_nonqos_seq(mvm, vif);
882 if (ret < 0) 819 if (ret < 0)
883 goto out_noreset; 820 return ret;
884 wowlan_config_cmd.common.non_qos_seq = cpu_to_le16(ret);
885 821
886 iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, &wowlan_config_cmd.common); 822 wowlan_config_cmd->common.non_qos_seq = cpu_to_le16(ret);
823
824 iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, &wowlan_config_cmd->common);
887 825
888 if (wowlan->disconnect) 826 if (wowlan->disconnect)
889 wowlan_config_cmd.common.wakeup_filter |= 827 wowlan_config_cmd->common.wakeup_filter |=
890 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | 828 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
891 IWL_WOWLAN_WAKEUP_LINK_CHANGE); 829 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
892 if (wowlan->magic_pkt) 830 if (wowlan->magic_pkt)
893 wowlan_config_cmd.common.wakeup_filter |= 831 wowlan_config_cmd->common.wakeup_filter |=
894 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET); 832 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET);
895 if (wowlan->gtk_rekey_failure) 833 if (wowlan->gtk_rekey_failure)
896 wowlan_config_cmd.common.wakeup_filter |= 834 wowlan_config_cmd->common.wakeup_filter |=
897 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL); 835 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
898 if (wowlan->eap_identity_req) 836 if (wowlan->eap_identity_req)
899 wowlan_config_cmd.common.wakeup_filter |= 837 wowlan_config_cmd->common.wakeup_filter |=
900 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ); 838 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ);
901 if (wowlan->four_way_handshake) 839 if (wowlan->four_way_handshake)
902 wowlan_config_cmd.common.wakeup_filter |= 840 wowlan_config_cmd->common.wakeup_filter |=
903 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE); 841 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
904 if (wowlan->n_patterns) 842 if (wowlan->n_patterns)
905 wowlan_config_cmd.common.wakeup_filter |= 843 wowlan_config_cmd->common.wakeup_filter |=
906 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH); 844 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH);
907 845
908 if (wowlan->rfkill_release) 846 if (wowlan->rfkill_release)
909 wowlan_config_cmd.common.wakeup_filter |= 847 wowlan_config_cmd->common.wakeup_filter |=
910 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); 848 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
911 849
912 if (wowlan->tcp) { 850 if (wowlan->tcp) {
@@ -914,44 +852,39 @@ static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
914 * Set the "link change" (really "link lost") flag as well 852 * Set the "link change" (really "link lost") flag as well
915 * since that implies losing the TCP connection. 853 * since that implies losing the TCP connection.
916 */ 854 */
917 wowlan_config_cmd.common.wakeup_filter |= 855 wowlan_config_cmd->common.wakeup_filter |=
918 cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS | 856 cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS |
919 IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE | 857 IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE |
920 IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET | 858 IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET |
921 IWL_WOWLAN_WAKEUP_LINK_CHANGE); 859 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
922 } 860 }
923 861
924 iwl_mvm_cancel_scan(mvm); 862 return 0;
925 863}
926 iwl_trans_stop_device(mvm->trans);
927
928 /*
929 * Set the HW restart bit -- this is mostly true as we're
930 * going to load new firmware and reprogram that, though
931 * the reprogramming is going to be manual to avoid adding
932 * all the MACs that aren't support.
933 * We don't have to clear up everything though because the
934 * reprogramming is manual. When we resume, we'll actually
935 * go through a proper restart sequence again to switch
936 * back to the runtime firmware image.
937 */
938 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
939
940 /* We reprogram keys and shouldn't allocate new key indices */
941 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
942
943 mvm->ptk_ivlen = 0;
944 mvm->ptk_icvlen = 0;
945 mvm->ptk_ivlen = 0;
946 mvm->ptk_icvlen = 0;
947 864
948 ret = iwl_mvm_load_d3_fw(mvm); 865static int
949 if (ret) 866iwl_mvm_wowlan_config(struct iwl_mvm *mvm,
950 goto out; 867 struct cfg80211_wowlan *wowlan,
868 struct iwl_wowlan_config_cmd_v3 *wowlan_config_cmd,
869 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
870 struct ieee80211_sta *ap_sta)
871{
872 struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {};
873 struct iwl_wowlan_tkip_params_cmd tkip_cmd = {};
874 struct wowlan_key_data key_data = {
875 .use_rsc_tsc = false,
876 .tkip = &tkip_cmd,
877 .use_tkip = false,
878 };
879 int ret;
951 880
952 ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta); 881 ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta);
953 if (ret) 882 if (ret)
954 goto out; 883 return ret;
884
885 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
886 if (!key_data.rsc_tsc)
887 return -ENOMEM;
955 888
956 if (!iwlwifi_mod_params.sw_crypto) { 889 if (!iwlwifi_mod_params.sw_crypto) {
957 /* 890 /*
@@ -1010,7 +943,7 @@ static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
1010 } 943 }
1011 } 944 }
1012 945
1013 ret = iwl_mvm_send_wowlan_config_cmd(mvm, &wowlan_config_cmd); 946 ret = iwl_mvm_send_wowlan_config_cmd(mvm, wowlan_config_cmd);
1014 if (ret) 947 if (ret)
1015 goto out; 948 goto out;
1016 949
@@ -1023,8 +956,93 @@ static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
1023 goto out; 956 goto out;
1024 957
1025 ret = iwl_mvm_send_remote_wake_cfg(mvm, vif, wowlan->tcp); 958 ret = iwl_mvm_send_remote_wake_cfg(mvm, vif, wowlan->tcp);
1026 if (ret) 959
1027 goto out; 960out:
961 kfree(key_data.rsc_tsc);
962 return ret;
963}
964
965static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
966 struct cfg80211_wowlan *wowlan,
967 bool test)
968{
969 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
970 struct ieee80211_vif *vif = NULL;
971 struct iwl_mvm_vif *mvmvif = NULL;
972 struct ieee80211_sta *ap_sta = NULL;
973 struct iwl_wowlan_config_cmd_v3 wowlan_config_cmd = {};
974 struct iwl_d3_manager_config d3_cfg_cmd_data = {
975 /*
976 * Program the minimum sleep time to 10 seconds, as many
977 * platforms have issues processing a wakeup signal while
978 * still being in the process of suspending.
979 */
980 .min_sleep_time = cpu_to_le32(10 * 1000 * 1000),
981 };
982 struct iwl_host_cmd d3_cfg_cmd = {
983 .id = D3_CONFIG_CMD,
984 .flags = CMD_WANT_SKB,
985 .data[0] = &d3_cfg_cmd_data,
986 .len[0] = sizeof(d3_cfg_cmd_data),
987 };
988 int ret;
989 int len __maybe_unused;
990
991 if (!wowlan) {
992 /*
993 * mac80211 shouldn't get here, but for D3 test
994 * it doesn't warrant a warning
995 */
996 WARN_ON(!test);
997 return -EINVAL;
998 }
999
1000 mutex_lock(&mvm->mutex);
1001
1002 vif = iwl_mvm_get_bss_vif(mvm);
1003 if (IS_ERR_OR_NULL(vif)) {
1004 ret = 1;
1005 goto out_noreset;
1006 }
1007
1008 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1009
1010 /* if we're associated, this is wowlan */
1011 if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1012 ap_sta = rcu_dereference_protected(
1013 mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
1014 lockdep_is_held(&mvm->mutex));
1015 if (IS_ERR_OR_NULL(ap_sta)) {
1016 ret = -EINVAL;
1017 goto out_noreset;
1018 }
1019
1020 ret = iwl_mvm_get_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1021 vif, mvmvif, ap_sta);
1022 if (ret)
1023 goto out_noreset;
1024
1025 ret = iwl_mvm_switch_to_d3(mvm);
1026 if (ret)
1027 goto out;
1028
1029 ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1030 vif, mvmvif, ap_sta);
1031 if (ret)
1032 goto out;
1033 } else if (mvm->nd_config) {
1034 ret = iwl_mvm_switch_to_d3(mvm);
1035 if (ret)
1036 goto out;
1037
1038 ret = iwl_mvm_scan_offload_start(mvm, vif, mvm->nd_config,
1039 mvm->nd_ies);
1040 if (ret)
1041 goto out;
1042 } else {
1043 ret = 1;
1044 goto out_noreset;
1045 }
1028 1046
1029 ret = iwl_mvm_power_update_device(mvm); 1047 ret = iwl_mvm_power_update_device(mvm);
1030 if (ret) 1048 if (ret)
@@ -1060,8 +1078,6 @@ static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
1060 if (ret < 0) 1078 if (ret < 0)
1061 ieee80211_restart_hw(mvm->hw); 1079 ieee80211_restart_hw(mvm->hw);
1062 out_noreset: 1080 out_noreset:
1063 kfree(key_data.rsc_tsc);
1064
1065 mutex_unlock(&mvm->mutex); 1081 mutex_unlock(&mvm->mutex);
1066 1082
1067 return ret; 1083 return ret;
@@ -1592,9 +1608,6 @@ static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac,
1592 1608
1593static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test) 1609static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
1594{ 1610{
1595 struct iwl_d3_iter_data resume_iter_data = {
1596 .mvm = mvm,
1597 };
1598 struct ieee80211_vif *vif = NULL; 1611 struct ieee80211_vif *vif = NULL;
1599 int ret; 1612 int ret;
1600 enum iwl_d3_status d3_status; 1613 enum iwl_d3_status d3_status;
@@ -1603,15 +1616,10 @@ static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
1603 mutex_lock(&mvm->mutex); 1616 mutex_lock(&mvm->mutex);
1604 1617
1605 /* get the BSS vif pointer again */ 1618 /* get the BSS vif pointer again */
1606 ieee80211_iterate_active_interfaces_atomic( 1619 vif = iwl_mvm_get_bss_vif(mvm);
1607 mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1620 if (IS_ERR_OR_NULL(vif))
1608 iwl_mvm_d3_iface_iterator, &resume_iter_data);
1609
1610 if (WARN_ON(resume_iter_data.error || !resume_iter_data.vif))
1611 goto out_unlock; 1621 goto out_unlock;
1612 1622
1613 vif = resume_iter_data.vif;
1614
1615 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test); 1623 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test);
1616 if (ret) 1624 if (ret)
1617 goto out_unlock; 1625 goto out_unlock;
@@ -1741,7 +1749,9 @@ static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
1741 int remaining_time = 10; 1749 int remaining_time = 10;
1742 1750
1743 mvm->d3_test_active = false; 1751 mvm->d3_test_active = false;
1752 rtnl_lock();
1744 __iwl_mvm_resume(mvm, true); 1753 __iwl_mvm_resume(mvm, true);
1754 rtnl_unlock();
1745 iwl_abort_notification_waits(&mvm->notif_wait); 1755 iwl_abort_notification_waits(&mvm->notif_wait);
1746 ieee80211_restart_hw(mvm->hw); 1756 ieee80211_restart_hw(mvm->hw);
1747 1757
diff --git a/drivers/net/wireless/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/iwlwifi/mvm/debugfs.c
index 50527a9bb267..51b7116965ed 100644
--- a/drivers/net/wireless/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/iwlwifi/mvm/debugfs.c
@@ -121,78 +121,6 @@ static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
121 return ret; 121 return ret;
122} 122}
123 123
124static int iwl_dbgfs_fw_error_dump_open(struct inode *inode, struct file *file)
125{
126 struct iwl_mvm *mvm = inode->i_private;
127 int ret;
128
129 if (!mvm)
130 return -EINVAL;
131
132 mutex_lock(&mvm->mutex);
133 if (!mvm->fw_error_dump) {
134 ret = -ENODATA;
135 goto out;
136 }
137
138 file->private_data = mvm->fw_error_dump;
139 mvm->fw_error_dump = NULL;
140 ret = 0;
141
142out:
143 mutex_unlock(&mvm->mutex);
144 return ret;
145}
146
147static ssize_t iwl_dbgfs_fw_error_dump_read(struct file *file,
148 char __user *user_buf,
149 size_t count, loff_t *ppos)
150{
151 struct iwl_mvm_dump_ptrs *dump_ptrs = (void *)file->private_data;
152 ssize_t bytes_read = 0;
153 ssize_t bytes_read_trans = 0;
154
155 if (*ppos < dump_ptrs->op_mode_len)
156 bytes_read +=
157 simple_read_from_buffer(user_buf, count, ppos,
158 dump_ptrs->op_mode_ptr,
159 dump_ptrs->op_mode_len);
160
161 if (bytes_read < 0 || *ppos < dump_ptrs->op_mode_len)
162 return bytes_read;
163
164 if (dump_ptrs->trans_ptr) {
165 *ppos -= dump_ptrs->op_mode_len;
166 bytes_read_trans =
167 simple_read_from_buffer(user_buf + bytes_read,
168 count - bytes_read, ppos,
169 dump_ptrs->trans_ptr->data,
170 dump_ptrs->trans_ptr->len);
171 *ppos += dump_ptrs->op_mode_len;
172
173 if (bytes_read_trans >= 0)
174 bytes_read += bytes_read_trans;
175 else if (!bytes_read)
176 /* propagate the failure */
177 return bytes_read_trans;
178 }
179
180 return bytes_read;
181
182}
183
184static int iwl_dbgfs_fw_error_dump_release(struct inode *inode,
185 struct file *file)
186{
187 struct iwl_mvm_dump_ptrs *dump_ptrs = (void *)file->private_data;
188
189 vfree(dump_ptrs->op_mode_ptr);
190 vfree(dump_ptrs->trans_ptr);
191 kfree(dump_ptrs);
192
193 return 0;
194}
195
196static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, 124static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
197 size_t count, loff_t *ppos) 125 size_t count, loff_t *ppos)
198{ 126{
@@ -1250,6 +1178,126 @@ static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1250 1178
1251 return ret; 1179 return ret;
1252} 1180}
1181
1182#define MAX_NUM_ND_MATCHSETS 10
1183
1184static ssize_t iwl_dbgfs_netdetect_write(struct iwl_mvm *mvm, char *buf,
1185 size_t count, loff_t *ppos)
1186{
1187 const char *seps = ",\n";
1188 char *buf_ptr = buf;
1189 char *value_str = NULL;
1190 int ret, i;
1191
1192 /* TODO: don't free if write is being called several times in one go */
1193 if (mvm->nd_config) {
1194 kfree(mvm->nd_config->match_sets);
1195 kfree(mvm->nd_config);
1196 mvm->nd_config = NULL;
1197 kfree(mvm->nd_ies);
1198 mvm->nd_ies = NULL;
1199 }
1200
1201 mvm->nd_ies = kzalloc(sizeof(*mvm->nd_ies), GFP_KERNEL);
1202 if (!mvm->nd_ies)
1203 return -ENOMEM;
1204
1205 mvm->nd_config = kzalloc(sizeof(*mvm->nd_config) +
1206 (11 * sizeof(struct ieee80211_channel *)),
1207 GFP_KERNEL);
1208 if (!mvm->nd_config) {
1209 ret = -ENOMEM;
1210 goto out_free;
1211 }
1212
1213 mvm->nd_config->n_channels = 11;
1214 mvm->nd_config->scan_width = NL80211_BSS_CHAN_WIDTH_20;
1215 mvm->nd_config->interval = 5;
1216 mvm->nd_config->min_rssi_thold = -80;
1217 for (i = 0; i < mvm->nd_config->n_channels; i++)
1218 mvm->nd_config->channels[i] = &mvm->nvm_data->channels[i];
1219
1220 mvm->nd_config->match_sets =
1221 kcalloc(MAX_NUM_ND_MATCHSETS,
1222 sizeof(*mvm->nd_config->match_sets),
1223 GFP_KERNEL);
1224 if (!mvm->nd_config->match_sets) {
1225 ret = -ENOMEM;
1226 goto out_free;
1227 }
1228
1229 while ((value_str = strsep(&buf_ptr, seps)) &&
1230 strlen(value_str)) {
1231 struct cfg80211_match_set *set;
1232
1233 if (mvm->nd_config->n_match_sets >= MAX_NUM_ND_MATCHSETS) {
1234 ret = -EINVAL;
1235 goto out_free;
1236 }
1237
1238 set = &mvm->nd_config->match_sets[mvm->nd_config->n_match_sets];
1239 set->ssid.ssid_len = strlen(value_str);
1240
1241 if (set->ssid.ssid_len > IEEE80211_MAX_SSID_LEN) {
1242 ret = -EINVAL;
1243 goto out_free;
1244 }
1245
1246 memcpy(set->ssid.ssid, value_str, set->ssid.ssid_len);
1247
1248 mvm->nd_config->n_match_sets++;
1249 }
1250
1251 ret = count;
1252
1253 if (mvm->nd_config->n_match_sets)
1254 goto out;
1255
1256out_free:
1257 if (mvm->nd_config)
1258 kfree(mvm->nd_config->match_sets);
1259 kfree(mvm->nd_config);
1260 mvm->nd_config = NULL;
1261 kfree(mvm->nd_ies);
1262 mvm->nd_ies = NULL;
1263out:
1264 return ret;
1265}
1266
1267static ssize_t
1268iwl_dbgfs_netdetect_read(struct file *file, char __user *user_buf,
1269 size_t count, loff_t *ppos)
1270{
1271 struct iwl_mvm *mvm = file->private_data;
1272 size_t bufsz, ret;
1273 char *buf;
1274 int i, n_match_sets, pos = 0;
1275
1276 n_match_sets = mvm->nd_config ? mvm->nd_config->n_match_sets : 0;
1277
1278 bufsz = n_match_sets * (IEEE80211_MAX_SSID_LEN + 1) + 1;
1279 buf = kzalloc(bufsz, GFP_KERNEL);
1280 if (!buf)
1281 return -ENOMEM;
1282
1283 for (i = 0; i < n_match_sets; i++) {
1284 if (pos +
1285 mvm->nd_config->match_sets[i].ssid.ssid_len + 2 > bufsz) {
1286 ret = -EIO;
1287 goto out;
1288 }
1289
1290 memcpy(buf + pos, mvm->nd_config->match_sets[i].ssid.ssid,
1291 mvm->nd_config->match_sets[i].ssid.ssid_len);
1292 pos += mvm->nd_config->match_sets[i].ssid.ssid_len;
1293 buf[pos++] = '\n';
1294 }
1295
1296 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1297out:
1298 kfree(buf);
1299 return ret;
1300}
1253#endif 1301#endif
1254 1302
1255#define PRINT_MVM_REF(ref) do { \ 1303#define PRINT_MVM_REF(ref) do { \
@@ -1415,12 +1463,6 @@ MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1415MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8); 1463MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1416MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8); 1464MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
1417 1465
1418static const struct file_operations iwl_dbgfs_fw_error_dump_ops = {
1419 .open = iwl_dbgfs_fw_error_dump_open,
1420 .read = iwl_dbgfs_fw_error_dump_read,
1421 .release = iwl_dbgfs_fw_error_dump_release,
1422};
1423
1424#ifdef CONFIG_IWLWIFI_BCAST_FILTERING 1466#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1425MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256); 1467MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1426MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256); 1468MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
@@ -1428,6 +1470,7 @@ MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1428 1470
1429#ifdef CONFIG_PM_SLEEP 1471#ifdef CONFIG_PM_SLEEP
1430MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8); 1472MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
1473MVM_DEBUGFS_READ_WRITE_FILE_OPS(netdetect, 384);
1431#endif 1474#endif
1432 1475
1433int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir) 1476int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
@@ -1446,7 +1489,6 @@ int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1446 S_IWUSR | S_IRUSR); 1489 S_IWUSR | S_IRUSR);
1447 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR); 1490 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
1448 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR); 1491 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1449 MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR);
1450 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR); 1492 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1451 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR); 1493 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
1452 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, 1494 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
@@ -1487,6 +1529,7 @@ int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1487 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR, 1529 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1488 mvm->debugfs_dir, &mvm->d3_wake_sysassert)) 1530 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1489 goto err; 1531 goto err;
1532 MVM_DEBUGFS_ADD_FILE(netdetect, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1490#endif 1533#endif
1491 1534
1492 if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR | S_IWUSR, 1535 if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR | S_IWUSR,
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
index 0c5c0b0e23f5..b8ab4a108720 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
@@ -197,8 +197,7 @@ static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
197/* 197/*
198 * Get the mask of the queues used by the vif 198 * Get the mask of the queues used by the vif
199 */ 199 */
200u32 iwl_mvm_mac_get_queues_mask(struct iwl_mvm *mvm, 200u32 iwl_mvm_mac_get_queues_mask(struct ieee80211_vif *vif)
201 struct ieee80211_vif *vif)
202{ 201{
203 u32 qmask = 0, ac; 202 u32 qmask = 0, ac;
204 203
@@ -227,7 +226,7 @@ static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
227 } 226 }
228 227
229 /* Mark the queues used by the vif */ 228 /* Mark the queues used by the vif */
230 data->used_hw_queues |= iwl_mvm_mac_get_queues_mask(data->mvm, vif); 229 data->used_hw_queues |= iwl_mvm_mac_get_queues_mask(vif);
231 230
232 /* Mark MAC IDs as used by clearing the available bit, and 231 /* Mark MAC IDs as used by clearing the available bit, and
233 * (below) mark TSFs as used if their existing use is not 232 * (below) mark TSFs as used if their existing use is not
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index b62405865b25..57325589ee5b 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -69,6 +69,7 @@
69#include <linux/etherdevice.h> 69#include <linux/etherdevice.h>
70#include <linux/ip.h> 70#include <linux/ip.h>
71#include <linux/if_arp.h> 71#include <linux/if_arp.h>
72#include <linux/devcoredump.h>
72#include <net/mac80211.h> 73#include <net/mac80211.h>
73#include <net/ieee80211_radiotap.h> 74#include <net/ieee80211_radiotap.h>
74#include <net/tcp.h> 75#include <net/tcp.h>
@@ -679,10 +680,51 @@ static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
679 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); 680 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
680} 681}
681 682
682#ifdef CONFIG_IWLWIFI_DEBUGFS 683static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
684 const void *data, size_t datalen)
685{
686 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
687 ssize_t bytes_read;
688 ssize_t bytes_read_trans;
689
690 if (offset < dump_ptrs->op_mode_len) {
691 bytes_read = min_t(ssize_t, count,
692 dump_ptrs->op_mode_len - offset);
693 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
694 bytes_read);
695 offset += bytes_read;
696 count -= bytes_read;
697
698 if (count == 0)
699 return bytes_read;
700 } else {
701 bytes_read = 0;
702 }
703
704 if (!dump_ptrs->trans_ptr)
705 return bytes_read;
706
707 offset -= dump_ptrs->op_mode_len;
708 bytes_read_trans = min_t(ssize_t, count,
709 dump_ptrs->trans_ptr->len - offset);
710 memcpy(buffer + bytes_read,
711 (u8 *)dump_ptrs->trans_ptr->data + offset,
712 bytes_read_trans);
713
714 return bytes_read + bytes_read_trans;
715}
716
717static void iwl_mvm_free_coredump(const void *data)
718{
719 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
720
721 vfree(fw_error_dump->op_mode_ptr);
722 vfree(fw_error_dump->trans_ptr);
723 kfree(fw_error_dump);
724}
725
683void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm) 726void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
684{ 727{
685 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
686 struct iwl_fw_error_dump_file *dump_file; 728 struct iwl_fw_error_dump_file *dump_file;
687 struct iwl_fw_error_dump_data *dump_data; 729 struct iwl_fw_error_dump_data *dump_data;
688 struct iwl_fw_error_dump_info *dump_info; 730 struct iwl_fw_error_dump_info *dump_info;
@@ -695,10 +737,7 @@ void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
695 737
696 lockdep_assert_held(&mvm->mutex); 738 lockdep_assert_held(&mvm->mutex);
697 739
698 if (mvm->fw_error_dump) 740 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
699 return;
700
701 fw_error_dump = kzalloc(sizeof(*mvm->fw_error_dump), GFP_KERNEL);
702 if (!fw_error_dump) 741 if (!fw_error_dump)
703 return; 742 return;
704 743
@@ -773,12 +812,10 @@ void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
773 if (fw_error_dump->trans_ptr) 812 if (fw_error_dump->trans_ptr)
774 file_len += fw_error_dump->trans_ptr->len; 813 file_len += fw_error_dump->trans_ptr->len;
775 dump_file->file_len = cpu_to_le32(file_len); 814 dump_file->file_len = cpu_to_le32(file_len);
776 mvm->fw_error_dump = fw_error_dump;
777 815
778 /* notify the userspace about the error we had */ 816 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
779 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env); 817 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
780} 818}
781#endif
782 819
783static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 820static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
784{ 821{
@@ -859,9 +896,8 @@ static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
859 return ret; 896 return ret;
860} 897}
861 898
862static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) 899static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
863{ 900{
864 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
865 int ret; 901 int ret;
866 902
867 mutex_lock(&mvm->mutex); 903 mutex_lock(&mvm->mutex);
@@ -879,6 +915,21 @@ static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
879 mutex_unlock(&mvm->mutex); 915 mutex_unlock(&mvm->mutex);
880} 916}
881 917
918static void
919iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
920 enum ieee80211_reconfig_type reconfig_type)
921{
922 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
923
924 switch (reconfig_type) {
925 case IEEE80211_RECONFIG_TYPE_RESTART:
926 iwl_mvm_restart_complete(mvm);
927 break;
928 case IEEE80211_RECONFIG_TYPE_SUSPEND:
929 break;
930 }
931}
932
882void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 933void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
883{ 934{
884 lockdep_assert_held(&mvm->mutex); 935 lockdep_assert_held(&mvm->mutex);
@@ -1087,7 +1138,7 @@ static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1087static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1138static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1088 struct ieee80211_vif *vif) 1139 struct ieee80211_vif *vif)
1089{ 1140{
1090 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(mvm, vif); 1141 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
1091 1142
1092 if (tfd_msk) { 1143 if (tfd_msk) {
1093 mutex_lock(&mvm->mutex); 1144 mutex_lock(&mvm->mutex);
@@ -1383,6 +1434,9 @@ bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1383 .cmd = cmd, 1434 .cmd = cmd,
1384 }; 1435 };
1385 1436
1437 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1438 return false;
1439
1386 memset(cmd, 0, sizeof(*cmd)); 1440 memset(cmd, 0, sizeof(*cmd));
1387 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); 1441 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1388 cmd->max_macs = ARRAY_SIZE(cmd->macs); 1442 cmd->max_macs = ARRAY_SIZE(cmd->macs);
@@ -2171,25 +2225,9 @@ static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2171 2225
2172 mvm->scan_status = IWL_MVM_SCAN_SCHED; 2226 mvm->scan_status = IWL_MVM_SCAN_SCHED;
2173 2227
2174 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) { 2228 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
2175 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
2176 if (ret)
2177 goto err;
2178 }
2179
2180 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
2181 if (ret) 2229 if (ret)
2182 goto err; 2230 mvm->scan_status = IWL_MVM_SCAN_NONE;
2183
2184 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
2185 ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies);
2186 else
2187 ret = iwl_mvm_sched_scan_start(mvm, req);
2188
2189 if (!ret)
2190 goto out;
2191err:
2192 mvm->scan_status = IWL_MVM_SCAN_NONE;
2193out: 2231out:
2194 mutex_unlock(&mvm->mutex); 2232 mutex_unlock(&mvm->mutex);
2195 return ret; 2233 return ret;
@@ -3011,25 +3049,31 @@ static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3011 mvmvif = iwl_mvm_vif_from_mac80211(vif); 3049 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3012 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id); 3050 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
3013 3051
3014 if (WARN_ON_ONCE(!mvmsta)) 3052 if (WARN_ON_ONCE(!mvmsta)) {
3015 goto done; 3053 mutex_unlock(&mvm->mutex);
3054 return;
3055 }
3016 3056
3017 if (drop) { 3057 if (drop) {
3018 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true)) 3058 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
3019 IWL_ERR(mvm, "flush request fail\n"); 3059 IWL_ERR(mvm, "flush request fail\n");
3060 mutex_unlock(&mvm->mutex);
3020 } else { 3061 } else {
3021 iwl_trans_wait_tx_queue_empty(mvm->trans, 3062 u32 tfd_queue_msk = mvmsta->tfd_queue_msk;
3022 mvmsta->tfd_queue_msk); 3063 mutex_unlock(&mvm->mutex);
3064
3065 /* this can take a while, and we may need/want other operations
3066 * to succeed while doing this, so do it without the mutex held
3067 */
3068 iwl_trans_wait_tx_queue_empty(mvm->trans, tfd_queue_msk);
3023 } 3069 }
3024done:
3025 mutex_unlock(&mvm->mutex);
3026} 3070}
3027 3071
3028const struct ieee80211_ops iwl_mvm_hw_ops = { 3072const struct ieee80211_ops iwl_mvm_hw_ops = {
3029 .tx = iwl_mvm_mac_tx, 3073 .tx = iwl_mvm_mac_tx,
3030 .ampdu_action = iwl_mvm_mac_ampdu_action, 3074 .ampdu_action = iwl_mvm_mac_ampdu_action,
3031 .start = iwl_mvm_mac_start, 3075 .start = iwl_mvm_mac_start,
3032 .restart_complete = iwl_mvm_mac_restart_complete, 3076 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
3033 .stop = iwl_mvm_mac_stop, 3077 .stop = iwl_mvm_mac_stop,
3034 .add_interface = iwl_mvm_mac_add_interface, 3078 .add_interface = iwl_mvm_mac_add_interface,
3035 .remove_interface = iwl_mvm_mac_remove_interface, 3079 .remove_interface = iwl_mvm_mac_remove_interface,
diff --git a/drivers/net/wireless/iwlwifi/mvm/mvm.h b/drivers/net/wireless/iwlwifi/mvm/mvm.h
index 845429c88cf4..d015fac06a62 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/iwlwifi/mvm/mvm.h
@@ -649,7 +649,6 @@ struct iwl_mvm {
649 /* -1 for always, 0 for never, >0 for that many times */ 649 /* -1 for always, 0 for never, >0 for that many times */
650 s8 restart_fw; 650 s8 restart_fw;
651 struct work_struct fw_error_dump_wk; 651 struct work_struct fw_error_dump_wk;
652 struct iwl_mvm_dump_ptrs *fw_error_dump;
653 652
654#ifdef CONFIG_IWLWIFI_LEDS 653#ifdef CONFIG_IWLWIFI_LEDS
655 struct led_classdev led; 654 struct led_classdev led;
@@ -660,6 +659,10 @@ struct iwl_mvm {
660#ifdef CONFIG_PM_SLEEP 659#ifdef CONFIG_PM_SLEEP
661 struct wiphy_wowlan_support wowlan; 660 struct wiphy_wowlan_support wowlan;
662 int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen; 661 int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen;
662
663 /* sched scan settings for net detect */
664 struct cfg80211_sched_scan_request *nd_config;
665 struct ieee80211_scan_ies *nd_ies;
663#ifdef CONFIG_IWLWIFI_DEBUGFS 666#ifdef CONFIG_IWLWIFI_DEBUGFS
664 u32 d3_wake_sysassert; /* must be u32 for debugfs_create_bool */ 667 u32 d3_wake_sysassert; /* must be u32 for debugfs_create_bool */
665 bool d3_test_active; 668 bool d3_test_active;
@@ -906,8 +909,7 @@ int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
906int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 909int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
907 bool force_assoc_off, const u8 *bssid_override); 910 bool force_assoc_off, const u8 *bssid_override);
908int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif); 911int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
909u32 iwl_mvm_mac_get_queues_mask(struct iwl_mvm *mvm, 912u32 iwl_mvm_mac_get_queues_mask(struct ieee80211_vif *vif);
910 struct ieee80211_vif *vif);
911int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm, 913int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
912 struct ieee80211_vif *vif); 914 struct ieee80211_vif *vif);
913int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm, 915int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
@@ -950,6 +952,10 @@ int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
950 struct cfg80211_sched_scan_request *req); 952 struct cfg80211_sched_scan_request *req);
951int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm, 953int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
952 struct cfg80211_sched_scan_request *req); 954 struct cfg80211_sched_scan_request *req);
955int iwl_mvm_scan_offload_start(struct iwl_mvm *mvm,
956 struct ieee80211_vif *vif,
957 struct cfg80211_sched_scan_request *req,
958 struct ieee80211_scan_ies *ies);
953int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify); 959int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify);
954int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm, 960int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm,
955 struct iwl_rx_cmd_buffer *rxb, 961 struct iwl_rx_cmd_buffer *rxb,
@@ -1207,11 +1213,9 @@ void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1207void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw, 1213void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
1208 struct ieee80211_vif *vif); 1214 struct ieee80211_vif *vif);
1209 1215
1216struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm);
1217
1210void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error); 1218void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error);
1211#ifdef CONFIG_IWLWIFI_DEBUGFS
1212void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm); 1219void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm);
1213#else
1214static inline void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm) {}
1215#endif
1216 1220
1217#endif /* __IWL_MVM_H__ */ 1221#endif /* __IWL_MVM_H__ */
diff --git a/drivers/net/wireless/iwlwifi/mvm/ops.c b/drivers/net/wireless/iwlwifi/mvm/ops.c
index 5b719ee8e789..7a9578567f4f 100644
--- a/drivers/net/wireless/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/iwlwifi/mvm/ops.c
@@ -403,6 +403,9 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
403 if (cfg->max_rx_agg_size) 403 if (cfg->max_rx_agg_size)
404 hw->max_rx_aggregation_subframes = cfg->max_rx_agg_size; 404 hw->max_rx_aggregation_subframes = cfg->max_rx_agg_size;
405 405
406 if (cfg->max_tx_agg_size)
407 hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
408
406 op_mode = hw->priv; 409 op_mode = hw->priv;
407 op_mode->ops = &iwl_mvm_ops; 410 op_mode->ops = &iwl_mvm_ops;
408 411
@@ -585,16 +588,18 @@ static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
585 ieee80211_unregister_hw(mvm->hw); 588 ieee80211_unregister_hw(mvm->hw);
586 589
587 kfree(mvm->scan_cmd); 590 kfree(mvm->scan_cmd);
588 if (mvm->fw_error_dump) {
589 vfree(mvm->fw_error_dump->op_mode_ptr);
590 vfree(mvm->fw_error_dump->trans_ptr);
591 kfree(mvm->fw_error_dump);
592 }
593 kfree(mvm->mcast_filter_cmd); 591 kfree(mvm->mcast_filter_cmd);
594 mvm->mcast_filter_cmd = NULL; 592 mvm->mcast_filter_cmd = NULL;
595 593
596#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS) 594#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS)
597 kfree(mvm->d3_resume_sram); 595 kfree(mvm->d3_resume_sram);
596 if (mvm->nd_config) {
597 kfree(mvm->nd_config->match_sets);
598 kfree(mvm->nd_config);
599 mvm->nd_config = NULL;
600 kfree(mvm->nd_ies);
601 mvm->nd_ies = NULL;
602 }
598#endif 603#endif
599 604
600 iwl_trans_op_mode_leave(mvm->trans); 605 iwl_trans_op_mode_leave(mvm->trans);
diff --git a/drivers/net/wireless/iwlwifi/mvm/rs.c b/drivers/net/wireless/iwlwifi/mvm/rs.c
index 18a539999580..ce884847cc8a 100644
--- a/drivers/net/wireless/iwlwifi/mvm/rs.c
+++ b/drivers/net/wireless/iwlwifi/mvm/rs.c
@@ -505,10 +505,11 @@ static const char *rs_pretty_lq_type(enum iwl_table_type type)
505static inline void rs_dump_rate(struct iwl_mvm *mvm, const struct rs_rate *rate, 505static inline void rs_dump_rate(struct iwl_mvm *mvm, const struct rs_rate *rate,
506 const char *prefix) 506 const char *prefix)
507{ 507{
508 IWL_DEBUG_RATE(mvm, "%s: (%s: %d) ANT: %s BW: %d SGI: %d LDPC: %d\n", 508 IWL_DEBUG_RATE(mvm,
509 "%s: (%s: %d) ANT: %s BW: %d SGI: %d LDPC: %d STBC %d\n",
509 prefix, rs_pretty_lq_type(rate->type), 510 prefix, rs_pretty_lq_type(rate->type),
510 rate->index, rs_pretty_ant(rate->ant), 511 rate->index, rs_pretty_ant(rate->ant),
511 rate->bw, rate->sgi, rate->ldpc); 512 rate->bw, rate->sgi, rate->ldpc, rate->stbc);
512} 513}
513 514
514static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) 515static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
@@ -741,6 +742,12 @@ static u32 ucode_rate_from_rs_rate(struct iwl_mvm *mvm,
741 IWL_ERR(mvm, "Invalid rate->type %d\n", rate->type); 742 IWL_ERR(mvm, "Invalid rate->type %d\n", rate->type);
742 } 743 }
743 744
745 if (is_siso(rate) && rate->stbc) {
746 /* To enable STBC we need to set both a flag and ANT_AB */
747 ucode_rate |= RATE_MCS_ANT_AB_MSK;
748 ucode_rate |= RATE_MCS_VHT_STBC_MSK;
749 }
750
744 ucode_rate |= rate->bw; 751 ucode_rate |= rate->bw;
745 if (rate->sgi) 752 if (rate->sgi)
746 ucode_rate |= RATE_MCS_SGI_MSK; 753 ucode_rate |= RATE_MCS_SGI_MSK;
@@ -785,6 +792,8 @@ static int rs_rate_from_ucode_rate(const u32 ucode_rate,
785 rate->sgi = true; 792 rate->sgi = true;
786 if (ucode_rate & RATE_MCS_LDPC_MSK) 793 if (ucode_rate & RATE_MCS_LDPC_MSK)
787 rate->ldpc = true; 794 rate->ldpc = true;
795 if (ucode_rate & RATE_MCS_VHT_STBC_MSK)
796 rate->stbc = true;
788 797
789 rate->bw = ucode_rate & RATE_MCS_CHAN_WIDTH_MSK; 798 rate->bw = ucode_rate & RATE_MCS_CHAN_WIDTH_MSK;
790 799
@@ -794,7 +803,7 @@ static int rs_rate_from_ucode_rate(const u32 ucode_rate,
794 803
795 if (nss == 1) { 804 if (nss == 1) {
796 rate->type = LQ_HT_SISO; 805 rate->type = LQ_HT_SISO;
797 WARN_ON_ONCE(num_of_ant != 1); 806 WARN_ON_ONCE(!rate->stbc && num_of_ant != 1);
798 } else if (nss == 2) { 807 } else if (nss == 2) {
799 rate->type = LQ_HT_MIMO2; 808 rate->type = LQ_HT_MIMO2;
800 WARN_ON_ONCE(num_of_ant != 2); 809 WARN_ON_ONCE(num_of_ant != 2);
@@ -992,7 +1001,15 @@ static void rs_get_lower_rate_down_column(struct iwl_lq_sta *lq_sta,
992static inline bool rs_rate_match(struct rs_rate *a, 1001static inline bool rs_rate_match(struct rs_rate *a,
993 struct rs_rate *b) 1002 struct rs_rate *b)
994{ 1003{
995 return (a->type == b->type) && (a->ant == b->ant) && (a->sgi == b->sgi); 1004 bool ant_match;
1005
1006 if (a->stbc)
1007 ant_match = (b->ant == ANT_A || b->ant == ANT_B);
1008 else
1009 ant_match = (a->ant == b->ant);
1010
1011 return (a->type == b->type) && (a->bw == b->bw) && (a->sgi == b->sgi)
1012 && ant_match;
996} 1013}
997 1014
998static u32 rs_ch_width_from_mac_flags(enum mac80211_rate_control_flags flags) 1015static u32 rs_ch_width_from_mac_flags(enum mac80211_rate_control_flags flags)
@@ -1225,7 +1242,7 @@ void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
1225 IWL_DEBUG_RATE(mvm, "reduced txpower: %d\n", reduced_txp); 1242 IWL_DEBUG_RATE(mvm, "reduced txpower: %d\n", reduced_txp);
1226done: 1243done:
1227 /* See if there's a better rate or modulation mode to try. */ 1244 /* See if there's a better rate or modulation mode to try. */
1228 if (sta && sta->supp_rates[info->band]) 1245 if (sta->supp_rates[info->band])
1229 rs_rate_scale_perform(mvm, sta, lq_sta, tid); 1246 rs_rate_scale_perform(mvm, sta, lq_sta, tid);
1230} 1247}
1231 1248
@@ -1623,6 +1640,8 @@ static int rs_switch_to_column(struct iwl_mvm *mvm,
1623 else 1640 else
1624 rate->type = LQ_LEGACY_G; 1641 rate->type = LQ_LEGACY_G;
1625 1642
1643 rate->bw = RATE_MCS_CHAN_WIDTH_20;
1644 rate->ldpc = false;
1626 rate_mask = lq_sta->active_legacy_rate; 1645 rate_mask = lq_sta->active_legacy_rate;
1627 } else if (column->mode == RS_SISO) { 1646 } else if (column->mode == RS_SISO) {
1628 rate->type = lq_sta->is_vht ? LQ_VHT_SISO : LQ_HT_SISO; 1647 rate->type = lq_sta->is_vht ? LQ_VHT_SISO : LQ_HT_SISO;
@@ -1634,8 +1653,11 @@ static int rs_switch_to_column(struct iwl_mvm *mvm,
1634 WARN_ON_ONCE("Bad column mode"); 1653 WARN_ON_ONCE("Bad column mode");
1635 } 1654 }
1636 1655
1637 rate->bw = rs_bw_from_sta_bw(sta); 1656 if (column->mode != RS_LEGACY) {
1638 rate->ldpc = lq_sta->ldpc; 1657 rate->bw = rs_bw_from_sta_bw(sta);
1658 rate->ldpc = lq_sta->ldpc;
1659 }
1660
1639 search_tbl->column = col_id; 1661 search_tbl->column = col_id;
1640 rs_set_expected_tpt_table(lq_sta, search_tbl); 1662 rs_set_expected_tpt_table(lq_sta, search_tbl);
1641 1663
@@ -1754,6 +1776,29 @@ out:
1754 return action; 1776 return action;
1755} 1777}
1756 1778
1779static bool rs_stbc_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
1780 struct iwl_lq_sta *lq_sta)
1781{
1782 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1783 struct ieee80211_vif *vif = mvmsta->vif;
1784 bool sta_ps_disabled = (vif->type == NL80211_IFTYPE_STATION &&
1785 !vif->bss_conf.ps);
1786
1787 /* Our chip supports Tx STBC and the peer is an HT/VHT STA which
1788 * supports STBC of at least 1*SS
1789 */
1790 if (!lq_sta->stbc)
1791 return false;
1792
1793 if (!mvm->ps_disabled && !sta_ps_disabled)
1794 return false;
1795
1796 if (!iwl_mvm_bt_coex_is_mimo_allowed(mvm, sta))
1797 return false;
1798
1799 return true;
1800}
1801
1757static void rs_get_adjacent_txp(struct iwl_mvm *mvm, int index, 1802static void rs_get_adjacent_txp(struct iwl_mvm *mvm, int index,
1758 int *weaker, int *stronger) 1803 int *weaker, int *stronger)
1759{ 1804{
@@ -2675,6 +2720,11 @@ void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2675 if (mvm->cfg->ht_params->ldpc && 2720 if (mvm->cfg->ht_params->ldpc &&
2676 (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)) 2721 (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING))
2677 lq_sta->ldpc = true; 2722 lq_sta->ldpc = true;
2723
2724 if (mvm->cfg->ht_params->stbc &&
2725 (num_of_ant(mvm->fw->valid_tx_ant) > 1) &&
2726 (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC))
2727 lq_sta->stbc = true;
2678 } else { 2728 } else {
2679 rs_vht_set_enabled_rates(sta, vht_cap, lq_sta); 2729 rs_vht_set_enabled_rates(sta, vht_cap, lq_sta);
2680 lq_sta->is_vht = true; 2730 lq_sta->is_vht = true;
@@ -2682,8 +2732,16 @@ void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2682 if (mvm->cfg->ht_params->ldpc && 2732 if (mvm->cfg->ht_params->ldpc &&
2683 (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC)) 2733 (vht_cap->cap & IEEE80211_VHT_CAP_RXLDPC))
2684 lq_sta->ldpc = true; 2734 lq_sta->ldpc = true;
2735
2736 if (mvm->cfg->ht_params->stbc &&
2737 (num_of_ant(mvm->fw->valid_tx_ant) > 1) &&
2738 (vht_cap->cap & IEEE80211_VHT_CAP_RXSTBC_MASK))
2739 lq_sta->stbc = true;
2685 } 2740 }
2686 2741
2742 if (IWL_MVM_RS_DISABLE_MIMO)
2743 lq_sta->active_mimo2_rate = 0;
2744
2687 lq_sta->max_legacy_rate_idx = find_last_bit(&lq_sta->active_legacy_rate, 2745 lq_sta->max_legacy_rate_idx = find_last_bit(&lq_sta->active_legacy_rate,
2688 BITS_PER_LONG); 2746 BITS_PER_LONG);
2689 lq_sta->max_siso_rate_idx = find_last_bit(&lq_sta->active_siso_rate, 2747 lq_sta->max_siso_rate_idx = find_last_bit(&lq_sta->active_siso_rate,
@@ -2692,11 +2750,11 @@ void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2692 BITS_PER_LONG); 2750 BITS_PER_LONG);
2693 2751
2694 IWL_DEBUG_RATE(mvm, 2752 IWL_DEBUG_RATE(mvm,
2695 "RATE MASK: LEGACY=%lX SISO=%lX MIMO2=%lX VHT=%d LDPC=%d\n", 2753 "RATE MASK: LEGACY=%lX SISO=%lX MIMO2=%lX VHT=%d LDPC=%d STBC%d\n",
2696 lq_sta->active_legacy_rate, 2754 lq_sta->active_legacy_rate,
2697 lq_sta->active_siso_rate, 2755 lq_sta->active_siso_rate,
2698 lq_sta->active_mimo2_rate, 2756 lq_sta->active_mimo2_rate,
2699 lq_sta->is_vht, lq_sta->ldpc); 2757 lq_sta->is_vht, lq_sta->ldpc, lq_sta->stbc);
2700 IWL_DEBUG_RATE(mvm, "MAX RATE: LEGACY=%d SISO=%d MIMO2=%d\n", 2758 IWL_DEBUG_RATE(mvm, "MAX RATE: LEGACY=%d SISO=%d MIMO2=%d\n",
2701 lq_sta->max_legacy_rate_idx, 2759 lq_sta->max_legacy_rate_idx,
2702 lq_sta->max_siso_rate_idx, 2760 lq_sta->max_siso_rate_idx,
@@ -2820,6 +2878,7 @@ static void rs_fill_rates_for_column(struct iwl_mvm *mvm,
2820 * rate[15] 0x800D Legacy | ANT: B Rate: 6 Mbps 2878 * rate[15] 0x800D Legacy | ANT: B Rate: 6 Mbps
2821 */ 2879 */
2822static void rs_build_rates_table(struct iwl_mvm *mvm, 2880static void rs_build_rates_table(struct iwl_mvm *mvm,
2881 struct ieee80211_sta *sta,
2823 struct iwl_lq_sta *lq_sta, 2882 struct iwl_lq_sta *lq_sta,
2824 const struct rs_rate *initial_rate) 2883 const struct rs_rate *initial_rate)
2825{ 2884{
@@ -2832,6 +2891,7 @@ static void rs_build_rates_table(struct iwl_mvm *mvm,
2832 memcpy(&rate, initial_rate, sizeof(rate)); 2891 memcpy(&rate, initial_rate, sizeof(rate));
2833 2892
2834 valid_tx_ant = mvm->fw->valid_tx_ant; 2893 valid_tx_ant = mvm->fw->valid_tx_ant;
2894 rate.stbc = rs_stbc_allow(mvm, sta, lq_sta);
2835 2895
2836 if (is_siso(&rate)) { 2896 if (is_siso(&rate)) {
2837 num_rates = RS_INITIAL_SISO_NUM_RATES; 2897 num_rates = RS_INITIAL_SISO_NUM_RATES;
@@ -2903,7 +2963,7 @@ static void rs_fill_lq_cmd(struct iwl_mvm *mvm,
2903 if (WARN_ON_ONCE(!sta || !initial_rate)) 2963 if (WARN_ON_ONCE(!sta || !initial_rate))
2904 return; 2964 return;
2905 2965
2906 rs_build_rates_table(mvm, lq_sta, initial_rate); 2966 rs_build_rates_table(mvm, sta, lq_sta, initial_rate);
2907 2967
2908 if (num_of_ant(initial_rate->ant) == 1) 2968 if (num_of_ant(initial_rate->ant) == 1)
2909 lq_cmd->single_stream_ant_msk = initial_rate->ant; 2969 lq_cmd->single_stream_ant_msk = initial_rate->ant;
diff --git a/drivers/net/wireless/iwlwifi/mvm/rs.h b/drivers/net/wireless/iwlwifi/mvm/rs.h
index eb34c1209acc..defd70a6d9e6 100644
--- a/drivers/net/wireless/iwlwifi/mvm/rs.h
+++ b/drivers/net/wireless/iwlwifi/mvm/rs.h
@@ -208,6 +208,7 @@ struct rs_rate {
208 u32 bw; 208 u32 bw;
209 bool sgi; 209 bool sgi;
210 bool ldpc; 210 bool ldpc;
211 bool stbc;
211}; 212};
212 213
213 214
@@ -331,6 +332,7 @@ struct iwl_lq_sta {
331 u64 last_tx; 332 u64 last_tx;
332 bool is_vht; 333 bool is_vht;
333 bool ldpc; /* LDPC Rx is supported by the STA */ 334 bool ldpc; /* LDPC Rx is supported by the STA */
335 bool stbc; /* Tx STBC is supported by chip and Rx by STA */
334 enum ieee80211_band band; 336 enum ieee80211_band band;
335 337
336 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ 338 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index 7554f7053830..fb2a8628b8fc 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -270,7 +270,8 @@ static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
270 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 270 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
271 bool *global_bound = data; 271 bool *global_bound = data;
272 272
273 if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < MAX_PHYS) 273 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
274 mvmvif->phy_ctxt->id < MAX_PHYS)
274 *global_bound = true; 275 *global_bound = true;
275} 276}
276 277
@@ -662,6 +663,7 @@ int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm,
662 mvm->scan_status = IWL_MVM_SCAN_NONE; 663 mvm->scan_status = IWL_MVM_SCAN_NONE;
663 ieee80211_scan_completed(mvm->hw, 664 ieee80211_scan_completed(mvm->hw,
664 status == IWL_SCAN_OFFLOAD_ABORTED); 665 status == IWL_SCAN_OFFLOAD_ABORTED);
666 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
665 } 667 }
666 668
667 mvm->last_ebs_successful = !ebs_status; 669 mvm->last_ebs_successful = !ebs_status;
@@ -997,6 +999,31 @@ int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
997 sizeof(scan_req), &scan_req); 999 sizeof(scan_req), &scan_req);
998} 1000}
999 1001
1002int iwl_mvm_scan_offload_start(struct iwl_mvm *mvm,
1003 struct ieee80211_vif *vif,
1004 struct cfg80211_sched_scan_request *req,
1005 struct ieee80211_scan_ies *ies)
1006{
1007 int ret;
1008
1009 if ((mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) {
1010 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1011 if (ret)
1012 return ret;
1013 ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies);
1014 } else {
1015 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1016 if (ret)
1017 return ret;
1018 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1019 if (ret)
1020 return ret;
1021 ret = iwl_mvm_sched_scan_start(mvm, req);
1022 }
1023
1024 return ret;
1025}
1026
1000static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm) 1027static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm)
1001{ 1028{
1002 int ret; 1029 int ret;
@@ -1071,8 +1098,12 @@ int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify)
1071 /* 1098 /*
1072 * Clear the scan status so the next scan requests will succeed. This 1099 * Clear the scan status so the next scan requests will succeed. This
1073 * also ensures the Rx handler doesn't do anything, as the scan was 1100 * also ensures the Rx handler doesn't do anything, as the scan was
1074 * stopped from above. 1101 * stopped from above. Since the rx handler won't do anything now,
1102 * we have to release the scan reference here.
1075 */ 1103 */
1104 if (mvm->scan_status == IWL_MVM_SCAN_OS)
1105 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1106
1076 mvm->scan_status = IWL_MVM_SCAN_NONE; 1107 mvm->scan_status = IWL_MVM_SCAN_NONE;
1077 1108
1078 if (notify) { 1109 if (notify) {
diff --git a/drivers/net/wireless/iwlwifi/mvm/sta.c b/drivers/net/wireless/iwlwifi/mvm/sta.c
index 1731c205c81d..dd0dc5bf8583 100644
--- a/drivers/net/wireless/iwlwifi/mvm/sta.c
+++ b/drivers/net/wireless/iwlwifi/mvm/sta.c
@@ -609,7 +609,7 @@ int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
609 609
610 lockdep_assert_held(&mvm->mutex); 610 lockdep_assert_held(&mvm->mutex);
611 611
612 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); 612 qmask = iwl_mvm_mac_get_queues_mask(vif);
613 613
614 /* 614 /*
615 * The firmware defines the TFD queue mask to only be relevant 615 * The firmware defines the TFD queue mask to only be relevant
diff --git a/drivers/net/wireless/iwlwifi/mvm/tt.c b/drivers/net/wireless/iwlwifi/mvm/tt.c
index acca44a45086..d4f2c29025c7 100644
--- a/drivers/net/wireless/iwlwifi/mvm/tt.c
+++ b/drivers/net/wireless/iwlwifi/mvm/tt.c
@@ -64,10 +64,6 @@
64 *****************************************************************************/ 64 *****************************************************************************/
65 65
66#include "mvm.h" 66#include "mvm.h"
67#include "iwl-config.h"
68#include "iwl-io.h"
69#include "iwl-csr.h"
70#include "iwl-prph.h"
71 67
72#define IWL_MVM_TEMP_NOTIF_WAIT_TIMEOUT HZ 68#define IWL_MVM_TEMP_NOTIF_WAIT_TIMEOUT HZ
73 69
diff --git a/drivers/net/wireless/iwlwifi/mvm/tx.c b/drivers/net/wireless/iwlwifi/mvm/tx.c
index c6a517c771df..8d848735cdb8 100644
--- a/drivers/net/wireless/iwlwifi/mvm/tx.c
+++ b/drivers/net/wireless/iwlwifi/mvm/tx.c
@@ -189,8 +189,10 @@ static void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm,
189 189
190 /* HT rate doesn't make sense for a non data frame */ 190 /* HT rate doesn't make sense for a non data frame */
191 WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS, 191 WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS,
192 "Got an HT rate for a non data frame 0x%x\n", 192 "Got an HT rate (flags:0x%x/mcs:%d) for a non data frame (fc:0x%x)\n",
193 info->control.rates[0].flags); 193 info->control.rates[0].flags,
194 info->control.rates[0].idx,
195 le16_to_cpu(fc));
194 196
195 rate_idx = info->control.rates[0].idx; 197 rate_idx = info->control.rates[0].idx;
196 /* if the rate isn't a well known legacy rate, take the lowest one */ 198 /* if the rate isn't a well known legacy rate, take the lowest one */
diff --git a/drivers/net/wireless/iwlwifi/mvm/utils.c b/drivers/net/wireless/iwlwifi/mvm/utils.c
index 8021f6eec27f..e56e77ef5d2e 100644
--- a/drivers/net/wireless/iwlwifi/mvm/utils.c
+++ b/drivers/net/wireless/iwlwifi/mvm/utils.c
@@ -734,3 +734,40 @@ bool iwl_mvm_is_idle(struct iwl_mvm *mvm)
734 734
735 return idle; 735 return idle;
736} 736}
737
738struct iwl_bss_iter_data {
739 struct ieee80211_vif *vif;
740 bool error;
741};
742
743static void iwl_mvm_bss_iface_iterator(void *_data, u8 *mac,
744 struct ieee80211_vif *vif)
745{
746 struct iwl_bss_iter_data *data = _data;
747
748 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
749 return;
750
751 if (data->vif) {
752 data->error = true;
753 return;
754 }
755
756 data->vif = vif;
757}
758
759struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm)
760{
761 struct iwl_bss_iter_data bss_iter_data = {};
762
763 ieee80211_iterate_active_interfaces_atomic(
764 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
765 iwl_mvm_bss_iface_iterator, &bss_iter_data);
766
767 if (bss_iter_data.error) {
768 IWL_ERR(mvm, "More than one managed interface active!\n");
769 return ERR_PTR(-EINVAL);
770 }
771
772 return bss_iter_data.vif;
773}
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index dd2f3f8baa9d..ea8efed25c6a 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -133,7 +133,7 @@ static void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans)
133 break; 133 break;
134 } 134 }
135 135
136 if (!page) 136 if (WARN_ON_ONCE(!page))
137 return; 137 return;
138 138
139 trans_pcie->fw_mon_page = page; 139 trans_pcie->fw_mon_page = page;
@@ -747,14 +747,11 @@ static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
747 int first_ucode_section; 747 int first_ucode_section;
748 748
749 IWL_DEBUG_FW(trans, 749 IWL_DEBUG_FW(trans,
750 "working with %s image\n",
751 image->is_secure ? "Secured" : "Non Secured");
752 IWL_DEBUG_FW(trans,
753 "working with %s CPU\n", 750 "working with %s CPU\n",
754 image->is_dual_cpus ? "Dual" : "Single"); 751 image->is_dual_cpus ? "Dual" : "Single");
755 752
756 /* configure the ucode to be ready to get the secured image */ 753 /* configure the ucode to be ready to get the secured image */
757 if (image->is_secure) { 754 if (iwl_has_secure_boot(trans->hw_rev, trans->cfg->device_family)) {
758 /* set secure boot inspector addresses */ 755 /* set secure boot inspector addresses */
759 iwl_write_prph(trans, 756 iwl_write_prph(trans,
760 LMPM_SECURE_INSPECTOR_CODE_ADDR, 757 LMPM_SECURE_INSPECTOR_CODE_ADDR,
@@ -790,7 +787,8 @@ static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
790 LMPM_SECURE_CPU2_HDR_MEM_SPACE); 787 LMPM_SECURE_CPU2_HDR_MEM_SPACE);
791 788
792 /* load to FW the binary sections of CPU2 */ 789 /* load to FW the binary sections of CPU2 */
793 if (image->is_secure) 790 if (iwl_has_secure_boot(trans->hw_rev,
791 trans->cfg->device_family))
794 ret = iwl_pcie_load_cpu_secured_sections( 792 ret = iwl_pcie_load_cpu_secured_sections(
795 trans, image, 2, 793 trans, image, 2,
796 &first_ucode_section); 794 &first_ucode_section);
@@ -821,7 +819,7 @@ static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
821 else 819 else
822 iwl_write32(trans, CSR_RESET, 0); 820 iwl_write32(trans, CSR_RESET, 0);
823 821
824 if (image->is_secure) { 822 if (iwl_has_secure_boot(trans->hw_rev, trans->cfg->device_family)) {
825 /* wait for image verification to complete */ 823 /* wait for image verification to complete */
826 ret = iwl_poll_prph_bit(trans, 824 ret = iwl_poll_prph_bit(trans,
827 LMPM_SECURE_BOOT_CPU1_STATUS_ADDR, 825 LMPM_SECURE_BOOT_CPU1_STATUS_ADDR,
@@ -1023,14 +1021,6 @@ static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
1023 return 0; 1021 return 0;
1024 } 1022 }
1025 1023
1026 iwl_pcie_set_pwr(trans, false);
1027
1028 val = iwl_read32(trans, CSR_RESET);
1029 if (val & CSR_RESET_REG_FLAG_NEVO_RESET) {
1030 *status = IWL_D3_STATUS_RESET;
1031 return 0;
1032 }
1033
1034 /* 1024 /*
1035 * Also enables interrupts - none will happen as the device doesn't 1025 * Also enables interrupts - none will happen as the device doesn't
1036 * know we're waking it up, only when the opmode actually tells it 1026 * know we're waking it up, only when the opmode actually tells it
@@ -1050,6 +1040,8 @@ static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
1050 return ret; 1040 return ret;
1051 } 1041 }
1052 1042
1043 iwl_pcie_set_pwr(trans, false);
1044
1053 iwl_trans_pcie_tx_reset(trans); 1045 iwl_trans_pcie_tx_reset(trans);
1054 1046
1055 ret = iwl_pcie_rx_init(trans); 1047 ret = iwl_pcie_rx_init(trans);
@@ -1058,7 +1050,12 @@ static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
1058 return ret; 1050 return ret;
1059 } 1051 }
1060 1052
1061 *status = IWL_D3_STATUS_ALIVE; 1053 val = iwl_read32(trans, CSR_RESET);
1054 if (val & CSR_RESET_REG_FLAG_NEVO_RESET)
1055 *status = IWL_D3_STATUS_RESET;
1056 else
1057 *status = IWL_D3_STATUS_ALIVE;
1058
1062 return 0; 1059 return 0;
1063} 1060}
1064 1061
@@ -1767,6 +1764,13 @@ err:
1767 IWL_ERR(trans, "failed to create the trans debugfs entry\n"); 1764 IWL_ERR(trans, "failed to create the trans debugfs entry\n");
1768 return -ENOMEM; 1765 return -ENOMEM;
1769} 1766}
1767#else
1768static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
1769 struct dentry *dir)
1770{
1771 return 0;
1772}
1773#endif /*CONFIG_IWLWIFI_DEBUGFS */
1770 1774
1771static u32 iwl_trans_pcie_get_cmdlen(struct iwl_tfd *tfd) 1775static u32 iwl_trans_pcie_get_cmdlen(struct iwl_tfd *tfd)
1772{ 1776{
@@ -2044,13 +2048,6 @@ struct iwl_trans_dump_data *iwl_trans_pcie_dump_data(struct iwl_trans *trans)
2044 2048
2045 return dump_data; 2049 return dump_data;
2046} 2050}
2047#else
2048static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
2049 struct dentry *dir)
2050{
2051 return 0;
2052}
2053#endif /*CONFIG_IWLWIFI_DEBUGFS */
2054 2051
2055static const struct iwl_trans_ops trans_ops_pcie = { 2052static const struct iwl_trans_ops trans_ops_pcie = {
2056 .start_hw = iwl_trans_pcie_start_hw, 2053 .start_hw = iwl_trans_pcie_start_hw,
@@ -2087,9 +2084,7 @@ static const struct iwl_trans_ops trans_ops_pcie = {
2087 .release_nic_access = iwl_trans_pcie_release_nic_access, 2084 .release_nic_access = iwl_trans_pcie_release_nic_access,
2088 .set_bits_mask = iwl_trans_pcie_set_bits_mask, 2085 .set_bits_mask = iwl_trans_pcie_set_bits_mask,
2089 2086
2090#ifdef CONFIG_IWLWIFI_DEBUGFS
2091 .dump_data = iwl_trans_pcie_dump_data, 2087 .dump_data = iwl_trans_pcie_dump_data,
2092#endif
2093}; 2088};
2094 2089
2095struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev, 2090struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index c9ad4cf1adfb..77fbf3035038 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -412,6 +412,9 @@ struct mac80211_hwsim_data {
412 struct mac_address addresses[2]; 412 struct mac_address addresses[2];
413 int channels, idx; 413 int channels, idx;
414 bool use_chanctx; 414 bool use_chanctx;
415 bool destroy_on_close;
416 struct work_struct destroy_work;
417 u32 portid;
415 418
416 struct ieee80211_channel *tmp_chan; 419 struct ieee80211_channel *tmp_chan;
417 struct delayed_work roc_done; 420 struct delayed_work roc_done;
@@ -436,7 +439,7 @@ struct mac80211_hwsim_data {
436 /* 439 /*
437 * Only radios in the same group can communicate together (the 440 * Only radios in the same group can communicate together (the
438 * channel has to match too). Each bit represents a group. A 441 * channel has to match too). Each bit represents a group. A
439 * radio can be in more then one group. 442 * radio can be in more than one group.
440 */ 443 */
441 u64 group; 444 u64 group;
442 445
@@ -447,6 +450,14 @@ struct mac80211_hwsim_data {
447 s64 bcn_delta; 450 s64 bcn_delta;
448 /* absolute beacon transmission time. Used to cover up "tx" delay. */ 451 /* absolute beacon transmission time. Used to cover up "tx" delay. */
449 u64 abs_bcn_ts; 452 u64 abs_bcn_ts;
453
454 /* Stats */
455 u64 tx_pkts;
456 u64 rx_pkts;
457 u64 tx_bytes;
458 u64 rx_bytes;
459 u64 tx_dropped;
460 u64 tx_failed;
450}; 461};
451 462
452 463
@@ -476,6 +487,14 @@ static struct genl_family hwsim_genl_family = {
476 .maxattr = HWSIM_ATTR_MAX, 487 .maxattr = HWSIM_ATTR_MAX,
477}; 488};
478 489
490enum hwsim_multicast_groups {
491 HWSIM_MCGRP_CONFIG,
492};
493
494static const struct genl_multicast_group hwsim_mcgrps[] = {
495 [HWSIM_MCGRP_CONFIG] = { .name = "config", },
496};
497
479/* MAC80211_HWSIM netlink policy */ 498/* MAC80211_HWSIM netlink policy */
480 499
481static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { 500static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = {
@@ -496,6 +515,10 @@ static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = {
496 [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 }, 515 [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 },
497 [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG }, 516 [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG },
498 [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG }, 517 [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG },
518 [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE] = { .type = NLA_FLAG },
519 [HWSIM_ATTR_RADIO_NAME] = { .type = NLA_STRING },
520 [HWSIM_ATTR_NO_VIF] = { .type = NLA_FLAG },
521 [HWSIM_ATTR_FREQ] = { .type = NLA_U32 },
499}; 522};
500 523
501static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, 524static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
@@ -861,8 +884,10 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
861 /* If the queue contains MAX_QUEUE skb's drop some */ 884 /* If the queue contains MAX_QUEUE skb's drop some */
862 if (skb_queue_len(&data->pending) >= MAX_QUEUE) { 885 if (skb_queue_len(&data->pending) >= MAX_QUEUE) {
863 /* Droping until WARN_QUEUE level */ 886 /* Droping until WARN_QUEUE level */
864 while (skb_queue_len(&data->pending) >= WARN_QUEUE) 887 while (skb_queue_len(&data->pending) >= WARN_QUEUE) {
865 skb_dequeue(&data->pending); 888 ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
889 data->tx_dropped++;
890 }
866 } 891 }
867 892
868 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC); 893 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
@@ -896,6 +921,9 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
896 if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags)) 921 if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags))
897 goto nla_put_failure; 922 goto nla_put_failure;
898 923
924 if (nla_put_u32(skb, HWSIM_ATTR_FREQ, data->channel->center_freq))
925 goto nla_put_failure;
926
899 /* We get the tx control (rate and retries) info*/ 927 /* We get the tx control (rate and retries) info*/
900 928
901 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 929 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
@@ -917,10 +945,14 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
917 945
918 /* Enqueue the packet */ 946 /* Enqueue the packet */
919 skb_queue_tail(&data->pending, my_skb); 947 skb_queue_tail(&data->pending, my_skb);
948 data->tx_pkts++;
949 data->tx_bytes += my_skb->len;
920 return; 950 return;
921 951
922nla_put_failure: 952nla_put_failure:
923 printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__); 953 printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__);
954 ieee80211_free_txskb(hw, my_skb);
955 data->tx_failed++;
924} 956}
925 957
926static bool hwsim_chans_compat(struct ieee80211_channel *c1, 958static bool hwsim_chans_compat(struct ieee80211_channel *c1,
@@ -1066,6 +1098,8 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
1066 rx_status.mactime = now + data2->tsf_offset; 1098 rx_status.mactime = now + data2->tsf_offset;
1067 1099
1068 memcpy(IEEE80211_SKB_RXCB(nskb), &rx_status, sizeof(rx_status)); 1100 memcpy(IEEE80211_SKB_RXCB(nskb), &rx_status, sizeof(rx_status));
1101 data2->rx_pkts++;
1102 data2->rx_bytes += nskb->len;
1069 ieee80211_rx_irqsafe(data2->hw, nskb); 1103 ieee80211_rx_irqsafe(data2->hw, nskb);
1070 } 1104 }
1071 spin_unlock(&hwsim_radio_lock); 1105 spin_unlock(&hwsim_radio_lock);
@@ -1133,6 +1167,8 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
1133 return mac80211_hwsim_tx_frame_nl(hw, skb, _portid); 1167 return mac80211_hwsim_tx_frame_nl(hw, skb, _portid);
1134 1168
1135 /* NO wmediumd detected, perfect medium simulation */ 1169 /* NO wmediumd detected, perfect medium simulation */
1170 data->tx_pkts++;
1171 data->tx_bytes += skb->len;
1136 ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel); 1172 ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel);
1137 1173
1138 if (ack && skb->len >= 16) { 1174 if (ack && skb->len >= 16) {
@@ -1916,6 +1952,57 @@ static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw,
1916 hwsim_check_chanctx_magic(ctx); 1952 hwsim_check_chanctx_magic(ctx);
1917} 1953}
1918 1954
1955static const char mac80211_hwsim_gstrings_stats[][ETH_GSTRING_LEN] = {
1956 "tx_pkts_nic",
1957 "tx_bytes_nic",
1958 "rx_pkts_nic",
1959 "rx_bytes_nic",
1960 "d_tx_dropped",
1961 "d_tx_failed",
1962 "d_ps_mode",
1963 "d_group",
1964 "d_tx_power",
1965};
1966
1967#define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats)
1968
1969static void mac80211_hwsim_get_et_strings(struct ieee80211_hw *hw,
1970 struct ieee80211_vif *vif,
1971 u32 sset, u8 *data)
1972{
1973 if (sset == ETH_SS_STATS)
1974 memcpy(data, *mac80211_hwsim_gstrings_stats,
1975 sizeof(mac80211_hwsim_gstrings_stats));
1976}
1977
1978static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw *hw,
1979 struct ieee80211_vif *vif, int sset)
1980{
1981 if (sset == ETH_SS_STATS)
1982 return MAC80211_HWSIM_SSTATS_LEN;
1983 return 0;
1984}
1985
1986static void mac80211_hwsim_get_et_stats(struct ieee80211_hw *hw,
1987 struct ieee80211_vif *vif,
1988 struct ethtool_stats *stats, u64 *data)
1989{
1990 struct mac80211_hwsim_data *ar = hw->priv;
1991 int i = 0;
1992
1993 data[i++] = ar->tx_pkts;
1994 data[i++] = ar->tx_bytes;
1995 data[i++] = ar->rx_pkts;
1996 data[i++] = ar->rx_bytes;
1997 data[i++] = ar->tx_dropped;
1998 data[i++] = ar->tx_failed;
1999 data[i++] = ar->ps;
2000 data[i++] = ar->group;
2001 data[i++] = ar->power_level;
2002
2003 WARN_ON(i != MAC80211_HWSIM_SSTATS_LEN);
2004}
2005
1919static const struct ieee80211_ops mac80211_hwsim_ops = { 2006static const struct ieee80211_ops mac80211_hwsim_ops = {
1920 .tx = mac80211_hwsim_tx, 2007 .tx = mac80211_hwsim_tx,
1921 .start = mac80211_hwsim_start, 2008 .start = mac80211_hwsim_start,
@@ -1939,14 +2026,131 @@ static const struct ieee80211_ops mac80211_hwsim_ops = {
1939 .flush = mac80211_hwsim_flush, 2026 .flush = mac80211_hwsim_flush,
1940 .get_tsf = mac80211_hwsim_get_tsf, 2027 .get_tsf = mac80211_hwsim_get_tsf,
1941 .set_tsf = mac80211_hwsim_set_tsf, 2028 .set_tsf = mac80211_hwsim_set_tsf,
2029 .get_et_sset_count = mac80211_hwsim_get_et_sset_count,
2030 .get_et_stats = mac80211_hwsim_get_et_stats,
2031 .get_et_strings = mac80211_hwsim_get_et_strings,
1942}; 2032};
1943 2033
1944static struct ieee80211_ops mac80211_hwsim_mchan_ops; 2034static struct ieee80211_ops mac80211_hwsim_mchan_ops;
1945 2035
1946static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2, 2036struct hwsim_new_radio_params {
1947 const struct ieee80211_regdomain *regd, 2037 unsigned int channels;
1948 bool reg_strict, bool p2p_device, 2038 const char *reg_alpha2;
1949 bool use_chanctx) 2039 const struct ieee80211_regdomain *regd;
2040 bool reg_strict;
2041 bool p2p_device;
2042 bool use_chanctx;
2043 bool destroy_on_close;
2044 const char *hwname;
2045 bool no_vif;
2046};
2047
2048static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
2049 struct genl_info *info)
2050{
2051 if (info)
2052 genl_notify(&hwsim_genl_family, mcast_skb,
2053 genl_info_net(info), info->snd_portid,
2054 HWSIM_MCGRP_CONFIG, info->nlhdr, GFP_KERNEL);
2055 else
2056 genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0,
2057 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
2058}
2059
2060static struct sk_buff *build_radio_msg(int cmd, int id,
2061 struct hwsim_new_radio_params *param)
2062{
2063 struct sk_buff *skb;
2064 void *data;
2065 int ret;
2066
2067 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
2068 if (!skb)
2069 return NULL;
2070
2071 data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, cmd);
2072 if (!data)
2073 goto error;
2074
2075 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
2076 if (ret < 0)
2077 goto error;
2078
2079 if (param->channels) {
2080 ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
2081 if (ret < 0)
2082 goto error;
2083 }
2084
2085 if (param->reg_alpha2) {
2086 ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
2087 param->reg_alpha2);
2088 if (ret < 0)
2089 goto error;
2090 }
2091
2092 if (param->regd) {
2093 int i;
2094
2095 for (i = 0; hwsim_world_regdom_custom[i] != param->regd &&
2096 i < ARRAY_SIZE(hwsim_world_regdom_custom); i++)
2097 ;
2098
2099 if (i < ARRAY_SIZE(hwsim_world_regdom_custom)) {
2100 ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
2101 if (ret < 0)
2102 goto error;
2103 }
2104 }
2105
2106 if (param->reg_strict) {
2107 ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
2108 if (ret < 0)
2109 goto error;
2110 }
2111
2112 if (param->p2p_device) {
2113 ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
2114 if (ret < 0)
2115 goto error;
2116 }
2117
2118 if (param->use_chanctx) {
2119 ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
2120 if (ret < 0)
2121 goto error;
2122 }
2123
2124 if (param->hwname) {
2125 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
2126 strlen(param->hwname), param->hwname);
2127 if (ret < 0)
2128 goto error;
2129 }
2130
2131 genlmsg_end(skb, data);
2132
2133 return skb;
2134
2135error:
2136 nlmsg_free(skb);
2137 return NULL;
2138}
2139
2140static void hswim_mcast_new_radio(int id, struct genl_info *info,
2141 struct hwsim_new_radio_params *param)
2142{
2143 struct sk_buff *mcast_skb;
2144
2145 mcast_skb = build_radio_msg(HWSIM_CMD_NEW_RADIO, id, param);
2146 if (!mcast_skb)
2147 return;
2148
2149 hwsim_mcast_config_msg(mcast_skb, info);
2150}
2151
2152static int mac80211_hwsim_new_radio(struct genl_info *info,
2153 struct hwsim_new_radio_params *param)
1950{ 2154{
1951 int err; 2155 int err;
1952 u8 addr[ETH_ALEN]; 2156 u8 addr[ETH_ALEN];
@@ -1956,16 +2160,16 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
1956 const struct ieee80211_ops *ops = &mac80211_hwsim_ops; 2160 const struct ieee80211_ops *ops = &mac80211_hwsim_ops;
1957 int idx; 2161 int idx;
1958 2162
1959 if (WARN_ON(channels > 1 && !use_chanctx)) 2163 if (WARN_ON(param->channels > 1 && !param->use_chanctx))
1960 return -EINVAL; 2164 return -EINVAL;
1961 2165
1962 spin_lock_bh(&hwsim_radio_lock); 2166 spin_lock_bh(&hwsim_radio_lock);
1963 idx = hwsim_radio_idx++; 2167 idx = hwsim_radio_idx++;
1964 spin_unlock_bh(&hwsim_radio_lock); 2168 spin_unlock_bh(&hwsim_radio_lock);
1965 2169
1966 if (use_chanctx) 2170 if (param->use_chanctx)
1967 ops = &mac80211_hwsim_mchan_ops; 2171 ops = &mac80211_hwsim_mchan_ops;
1968 hw = ieee80211_alloc_hw(sizeof(*data), ops); 2172 hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname);
1969 if (!hw) { 2173 if (!hw) {
1970 printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw failed\n"); 2174 printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw failed\n");
1971 err = -ENOMEM; 2175 err = -ENOMEM;
@@ -2003,9 +2207,12 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2003 hw->wiphy->n_addresses = 2; 2207 hw->wiphy->n_addresses = 2;
2004 hw->wiphy->addresses = data->addresses; 2208 hw->wiphy->addresses = data->addresses;
2005 2209
2006 data->channels = channels; 2210 data->channels = param->channels;
2007 data->use_chanctx = use_chanctx; 2211 data->use_chanctx = param->use_chanctx;
2008 data->idx = idx; 2212 data->idx = idx;
2213 data->destroy_on_close = param->destroy_on_close;
2214 if (info)
2215 data->portid = info->snd_portid;
2009 2216
2010 if (data->use_chanctx) { 2217 if (data->use_chanctx) {
2011 hw->wiphy->max_scan_ssids = 255; 2218 hw->wiphy->max_scan_ssids = 255;
@@ -2014,12 +2221,12 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2014 /* For channels > 1 DFS is not allowed */ 2221 /* For channels > 1 DFS is not allowed */
2015 hw->wiphy->n_iface_combinations = 1; 2222 hw->wiphy->n_iface_combinations = 1;
2016 hw->wiphy->iface_combinations = &data->if_combination; 2223 hw->wiphy->iface_combinations = &data->if_combination;
2017 if (p2p_device) 2224 if (param->p2p_device)
2018 data->if_combination = hwsim_if_comb_p2p_dev[0]; 2225 data->if_combination = hwsim_if_comb_p2p_dev[0];
2019 else 2226 else
2020 data->if_combination = hwsim_if_comb[0]; 2227 data->if_combination = hwsim_if_comb[0];
2021 data->if_combination.num_different_channels = data->channels; 2228 data->if_combination.num_different_channels = data->channels;
2022 } else if (p2p_device) { 2229 } else if (param->p2p_device) {
2023 hw->wiphy->iface_combinations = hwsim_if_comb_p2p_dev; 2230 hw->wiphy->iface_combinations = hwsim_if_comb_p2p_dev;
2024 hw->wiphy->n_iface_combinations = 2231 hw->wiphy->n_iface_combinations =
2025 ARRAY_SIZE(hwsim_if_comb_p2p_dev); 2232 ARRAY_SIZE(hwsim_if_comb_p2p_dev);
@@ -2040,7 +2247,7 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2040 BIT(NL80211_IFTYPE_ADHOC) | 2247 BIT(NL80211_IFTYPE_ADHOC) |
2041 BIT(NL80211_IFTYPE_MESH_POINT); 2248 BIT(NL80211_IFTYPE_MESH_POINT);
2042 2249
2043 if (p2p_device) 2250 if (param->p2p_device)
2044 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_DEVICE); 2251 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
2045 2252
2046 hw->flags = IEEE80211_HW_MFP_CAPABLE | 2253 hw->flags = IEEE80211_HW_MFP_CAPABLE |
@@ -2095,6 +2302,7 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2095 sband->ht_cap.ht_supported = true; 2302 sband->ht_cap.ht_supported = true;
2096 sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 2303 sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
2097 IEEE80211_HT_CAP_GRN_FLD | 2304 IEEE80211_HT_CAP_GRN_FLD |
2305 IEEE80211_HT_CAP_SGI_20 |
2098 IEEE80211_HT_CAP_SGI_40 | 2306 IEEE80211_HT_CAP_SGI_40 |
2099 IEEE80211_HT_CAP_DSSSCCK40; 2307 IEEE80211_HT_CAP_DSSSCCK40;
2100 sband->ht_cap.ampdu_factor = 0x3; 2308 sband->ht_cap.ampdu_factor = 0x3;
@@ -2142,15 +2350,18 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2142 hw->max_rates = 4; 2350 hw->max_rates = 4;
2143 hw->max_rate_tries = 11; 2351 hw->max_rate_tries = 11;
2144 2352
2145 if (reg_strict) 2353 if (param->reg_strict)
2146 hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG; 2354 hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
2147 if (regd) { 2355 if (param->regd) {
2148 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; 2356 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
2149 wiphy_apply_custom_regulatory(hw->wiphy, regd); 2357 wiphy_apply_custom_regulatory(hw->wiphy, param->regd);
2150 /* give the regulatory workqueue a chance to run */ 2358 /* give the regulatory workqueue a chance to run */
2151 schedule_timeout_interruptible(1); 2359 schedule_timeout_interruptible(1);
2152 } 2360 }
2153 2361
2362 if (param->no_vif)
2363 hw->flags |= IEEE80211_HW_NO_AUTO_VIF;
2364
2154 err = ieee80211_register_hw(hw); 2365 err = ieee80211_register_hw(hw);
2155 if (err < 0) { 2366 if (err < 0) {
2156 printk(KERN_DEBUG "mac80211_hwsim: ieee80211_register_hw failed (%d)\n", 2367 printk(KERN_DEBUG "mac80211_hwsim: ieee80211_register_hw failed (%d)\n",
@@ -2160,8 +2371,8 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2160 2371
2161 wiphy_debug(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr); 2372 wiphy_debug(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr);
2162 2373
2163 if (reg_alpha2) 2374 if (param->reg_alpha2)
2164 regulatory_hint(hw->wiphy, reg_alpha2); 2375 regulatory_hint(hw->wiphy, param->reg_alpha2);
2165 2376
2166 data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir); 2377 data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir);
2167 debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps); 2378 debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps);
@@ -2180,6 +2391,9 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2180 list_add_tail(&data->list, &hwsim_radios); 2391 list_add_tail(&data->list, &hwsim_radios);
2181 spin_unlock_bh(&hwsim_radio_lock); 2392 spin_unlock_bh(&hwsim_radio_lock);
2182 2393
2394 if (idx > 0)
2395 hswim_mcast_new_radio(idx, info, param);
2396
2183 return idx; 2397 return idx;
2184 2398
2185failed_hw: 2399failed_hw:
@@ -2192,8 +2406,48 @@ failed:
2192 return err; 2406 return err;
2193} 2407}
2194 2408
2195static void mac80211_hwsim_destroy_radio(struct mac80211_hwsim_data *data) 2409static void hwsim_mcast_del_radio(int id, const char *hwname,
2410 struct genl_info *info)
2411{
2412 struct sk_buff *skb;
2413 void *data;
2414 int ret;
2415
2416 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
2417 if (!skb)
2418 return;
2419
2420 data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
2421 HWSIM_CMD_DEL_RADIO);
2422 if (!data)
2423 goto error;
2424
2425 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
2426 if (ret < 0)
2427 goto error;
2428
2429 if (hwname) {
2430 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname),
2431 hwname);
2432 if (ret < 0)
2433 goto error;
2434 }
2435
2436 genlmsg_end(skb, data);
2437
2438 hwsim_mcast_config_msg(skb, info);
2439
2440 return;
2441
2442error:
2443 nlmsg_free(skb);
2444}
2445
2446static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
2447 const char *hwname,
2448 struct genl_info *info)
2196{ 2449{
2450 hwsim_mcast_del_radio(data->idx, hwname, info);
2197 debugfs_remove_recursive(data->debugfs); 2451 debugfs_remove_recursive(data->debugfs);
2198 ieee80211_unregister_hw(data->hw); 2452 ieee80211_unregister_hw(data->hw);
2199 device_release_driver(data->dev); 2453 device_release_driver(data->dev);
@@ -2211,7 +2465,7 @@ static void mac80211_hwsim_free(void)
2211 list))) { 2465 list))) {
2212 list_del(&data->list); 2466 list_del(&data->list);
2213 spin_unlock_bh(&hwsim_radio_lock); 2467 spin_unlock_bh(&hwsim_radio_lock);
2214 mac80211_hwsim_destroy_radio(data); 2468 mac80211_hwsim_del_radio(data, NULL, NULL);
2215 spin_lock_bh(&hwsim_radio_lock); 2469 spin_lock_bh(&hwsim_radio_lock);
2216 } 2470 }
2217 spin_unlock_bh(&hwsim_radio_lock); 2471 spin_unlock_bh(&hwsim_radio_lock);
@@ -2339,7 +2593,6 @@ out:
2339static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, 2593static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
2340 struct genl_info *info) 2594 struct genl_info *info)
2341{ 2595{
2342
2343 struct mac80211_hwsim_data *data2; 2596 struct mac80211_hwsim_data *data2;
2344 struct ieee80211_rx_status rx_status; 2597 struct ieee80211_rx_status rx_status;
2345 const u8 *dst; 2598 const u8 *dst;
@@ -2382,18 +2635,22 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
2382 2635
2383 /* A frame is received from user space */ 2636 /* A frame is received from user space */
2384 memset(&rx_status, 0, sizeof(rx_status)); 2637 memset(&rx_status, 0, sizeof(rx_status));
2638 /* TODO: Check ATTR_FREQ if it exists, and maybe throw away off-channel
2639 * packets?
2640 */
2385 rx_status.freq = data2->channel->center_freq; 2641 rx_status.freq = data2->channel->center_freq;
2386 rx_status.band = data2->channel->band; 2642 rx_status.band = data2->channel->band;
2387 rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]); 2643 rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]);
2388 rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); 2644 rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
2389 2645
2390 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); 2646 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
2647 data2->rx_pkts++;
2648 data2->rx_bytes += skb->len;
2391 ieee80211_rx_irqsafe(data2->hw, skb); 2649 ieee80211_rx_irqsafe(data2->hw, skb);
2392 2650
2393 return 0; 2651 return 0;
2394err: 2652err:
2395 printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__); 2653 printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__);
2396 goto out;
2397out: 2654out:
2398 dev_kfree_skb(skb); 2655 dev_kfree_skb(skb);
2399 return -EINVAL; 2656 return -EINVAL;
@@ -2429,54 +2686,72 @@ static int hwsim_register_received_nl(struct sk_buff *skb_2,
2429 return 0; 2686 return 0;
2430} 2687}
2431 2688
2432static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info) 2689static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
2433{ 2690{
2434 unsigned int chans = channels; 2691 struct hwsim_new_radio_params param = { 0 };
2435 const char *alpha2 = NULL; 2692
2436 const struct ieee80211_regdomain *regd = NULL; 2693 param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
2437 bool reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG]; 2694 param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
2438 bool p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE]; 2695 param.channels = channels;
2439 bool use_chanctx; 2696 param.destroy_on_close =
2697 info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE];
2440 2698
2441 if (info->attrs[HWSIM_ATTR_CHANNELS]) 2699 if (info->attrs[HWSIM_ATTR_CHANNELS])
2442 chans = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]); 2700 param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]);
2701
2702 if (info->attrs[HWSIM_ATTR_NO_VIF])
2703 param.no_vif = true;
2704
2705 if (info->attrs[HWSIM_ATTR_RADIO_NAME])
2706 param.hwname = nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
2443 2707
2444 if (info->attrs[HWSIM_ATTR_USE_CHANCTX]) 2708 if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
2445 use_chanctx = true; 2709 param.use_chanctx = true;
2446 else 2710 else
2447 use_chanctx = (chans > 1); 2711 param.use_chanctx = (param.channels > 1);
2448 2712
2449 if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]) 2713 if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2])
2450 alpha2 = nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]); 2714 param.reg_alpha2 =
2715 nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]);
2451 2716
2452 if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) { 2717 if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) {
2453 u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]); 2718 u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]);
2454 2719
2455 if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom)) 2720 if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom))
2456 return -EINVAL; 2721 return -EINVAL;
2457 regd = hwsim_world_regdom_custom[idx]; 2722 param.regd = hwsim_world_regdom_custom[idx];
2458 } 2723 }
2459 2724
2460 return mac80211_hwsim_create_radio(chans, alpha2, regd, reg_strict, 2725 return mac80211_hwsim_new_radio(info, &param);
2461 p2p_device, use_chanctx);
2462} 2726}
2463 2727
2464static int hwsim_destroy_radio_nl(struct sk_buff *msg, struct genl_info *info) 2728static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
2465{ 2729{
2466 struct mac80211_hwsim_data *data; 2730 struct mac80211_hwsim_data *data;
2467 int idx; 2731 s64 idx = -1;
2732 const char *hwname = NULL;
2468 2733
2469 if (!info->attrs[HWSIM_ATTR_RADIO_ID]) 2734 if (info->attrs[HWSIM_ATTR_RADIO_ID])
2735 idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
2736 else if (info->attrs[HWSIM_ATTR_RADIO_NAME])
2737 hwname = (void *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
2738 else
2470 return -EINVAL; 2739 return -EINVAL;
2471 idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
2472 2740
2473 spin_lock_bh(&hwsim_radio_lock); 2741 spin_lock_bh(&hwsim_radio_lock);
2474 list_for_each_entry(data, &hwsim_radios, list) { 2742 list_for_each_entry(data, &hwsim_radios, list) {
2475 if (data->idx != idx) 2743 if (idx >= 0) {
2476 continue; 2744 if (data->idx != idx)
2745 continue;
2746 } else {
2747 if (hwname &&
2748 strcmp(hwname, wiphy_name(data->hw->wiphy)))
2749 continue;
2750 }
2751
2477 list_del(&data->list); 2752 list_del(&data->list);
2478 spin_unlock_bh(&hwsim_radio_lock); 2753 spin_unlock_bh(&hwsim_radio_lock);
2479 mac80211_hwsim_destroy_radio(data); 2754 mac80211_hwsim_del_radio(data, hwname, info);
2480 return 0; 2755 return 0;
2481 } 2756 }
2482 spin_unlock_bh(&hwsim_radio_lock); 2757 spin_unlock_bh(&hwsim_radio_lock);
@@ -2503,19 +2778,42 @@ static const struct genl_ops hwsim_ops[] = {
2503 .doit = hwsim_tx_info_frame_received_nl, 2778 .doit = hwsim_tx_info_frame_received_nl,
2504 }, 2779 },
2505 { 2780 {
2506 .cmd = HWSIM_CMD_CREATE_RADIO, 2781 .cmd = HWSIM_CMD_NEW_RADIO,
2507 .policy = hwsim_genl_policy, 2782 .policy = hwsim_genl_policy,
2508 .doit = hwsim_create_radio_nl, 2783 .doit = hwsim_new_radio_nl,
2509 .flags = GENL_ADMIN_PERM, 2784 .flags = GENL_ADMIN_PERM,
2510 }, 2785 },
2511 { 2786 {
2512 .cmd = HWSIM_CMD_DESTROY_RADIO, 2787 .cmd = HWSIM_CMD_DEL_RADIO,
2513 .policy = hwsim_genl_policy, 2788 .policy = hwsim_genl_policy,
2514 .doit = hwsim_destroy_radio_nl, 2789 .doit = hwsim_del_radio_nl,
2515 .flags = GENL_ADMIN_PERM, 2790 .flags = GENL_ADMIN_PERM,
2516 }, 2791 },
2517}; 2792};
2518 2793
2794static void destroy_radio(struct work_struct *work)
2795{
2796 struct mac80211_hwsim_data *data =
2797 container_of(work, struct mac80211_hwsim_data, destroy_work);
2798
2799 mac80211_hwsim_del_radio(data, NULL, NULL);
2800}
2801
2802static void remove_user_radios(u32 portid)
2803{
2804 struct mac80211_hwsim_data *entry, *tmp;
2805
2806 spin_lock_bh(&hwsim_radio_lock);
2807 list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) {
2808 if (entry->destroy_on_close && entry->portid == portid) {
2809 list_del(&entry->list);
2810 INIT_WORK(&entry->destroy_work, destroy_radio);
2811 schedule_work(&entry->destroy_work);
2812 }
2813 }
2814 spin_unlock_bh(&hwsim_radio_lock);
2815}
2816
2519static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, 2817static int mac80211_hwsim_netlink_notify(struct notifier_block *nb,
2520 unsigned long state, 2818 unsigned long state,
2521 void *_notify) 2819 void *_notify)
@@ -2525,6 +2823,8 @@ static int mac80211_hwsim_netlink_notify(struct notifier_block *nb,
2525 if (state != NETLINK_URELEASE) 2823 if (state != NETLINK_URELEASE)
2526 return NOTIFY_DONE; 2824 return NOTIFY_DONE;
2527 2825
2826 remove_user_radios(notify->portid);
2827
2528 if (notify->portid == wmediumd_portid) { 2828 if (notify->portid == wmediumd_portid) {
2529 printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink" 2829 printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink"
2530 " socket, switching to perfect channel medium\n"); 2830 " socket, switching to perfect channel medium\n");
@@ -2544,7 +2844,9 @@ static int hwsim_init_netlink(void)
2544 2844
2545 printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); 2845 printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");
2546 2846
2547 rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops); 2847 rc = genl_register_family_with_ops_groups(&hwsim_genl_family,
2848 hwsim_ops,
2849 hwsim_mcgrps);
2548 if (rc) 2850 if (rc)
2549 goto failure; 2851 goto failure;
2550 2852
@@ -2605,69 +2907,73 @@ static int __init init_mac80211_hwsim(void)
2605 goto out_unregister_driver; 2907 goto out_unregister_driver;
2606 } 2908 }
2607 2909
2910 err = hwsim_init_netlink();
2911 if (err < 0)
2912 goto out_unregister_driver;
2913
2608 for (i = 0; i < radios; i++) { 2914 for (i = 0; i < radios; i++) {
2609 const char *reg_alpha2 = NULL; 2915 struct hwsim_new_radio_params param = { 0 };
2610 const struct ieee80211_regdomain *regd = NULL; 2916
2611 bool reg_strict = false; 2917 param.channels = channels;
2612 2918
2613 switch (regtest) { 2919 switch (regtest) {
2614 case HWSIM_REGTEST_DIFF_COUNTRY: 2920 case HWSIM_REGTEST_DIFF_COUNTRY:
2615 if (i < ARRAY_SIZE(hwsim_alpha2s)) 2921 if (i < ARRAY_SIZE(hwsim_alpha2s))
2616 reg_alpha2 = hwsim_alpha2s[i]; 2922 param.reg_alpha2 = hwsim_alpha2s[i];
2617 break; 2923 break;
2618 case HWSIM_REGTEST_DRIVER_REG_FOLLOW: 2924 case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
2619 if (!i) 2925 if (!i)
2620 reg_alpha2 = hwsim_alpha2s[0]; 2926 param.reg_alpha2 = hwsim_alpha2s[0];
2621 break; 2927 break;
2622 case HWSIM_REGTEST_STRICT_ALL: 2928 case HWSIM_REGTEST_STRICT_ALL:
2623 reg_strict = true; 2929 param.reg_strict = true;
2624 case HWSIM_REGTEST_DRIVER_REG_ALL: 2930 case HWSIM_REGTEST_DRIVER_REG_ALL:
2625 reg_alpha2 = hwsim_alpha2s[0]; 2931 param.reg_alpha2 = hwsim_alpha2s[0];
2626 break; 2932 break;
2627 case HWSIM_REGTEST_WORLD_ROAM: 2933 case HWSIM_REGTEST_WORLD_ROAM:
2628 if (i == 0) 2934 if (i == 0)
2629 regd = &hwsim_world_regdom_custom_01; 2935 param.regd = &hwsim_world_regdom_custom_01;
2630 break; 2936 break;
2631 case HWSIM_REGTEST_CUSTOM_WORLD: 2937 case HWSIM_REGTEST_CUSTOM_WORLD:
2632 regd = &hwsim_world_regdom_custom_01; 2938 param.regd = &hwsim_world_regdom_custom_01;
2633 break; 2939 break;
2634 case HWSIM_REGTEST_CUSTOM_WORLD_2: 2940 case HWSIM_REGTEST_CUSTOM_WORLD_2:
2635 if (i == 0) 2941 if (i == 0)
2636 regd = &hwsim_world_regdom_custom_01; 2942 param.regd = &hwsim_world_regdom_custom_01;
2637 else if (i == 1) 2943 else if (i == 1)
2638 regd = &hwsim_world_regdom_custom_02; 2944 param.regd = &hwsim_world_regdom_custom_02;
2639 break; 2945 break;
2640 case HWSIM_REGTEST_STRICT_FOLLOW: 2946 case HWSIM_REGTEST_STRICT_FOLLOW:
2641 if (i == 0) { 2947 if (i == 0) {
2642 reg_strict = true; 2948 param.reg_strict = true;
2643 reg_alpha2 = hwsim_alpha2s[0]; 2949 param.reg_alpha2 = hwsim_alpha2s[0];
2644 } 2950 }
2645 break; 2951 break;
2646 case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: 2952 case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
2647 if (i == 0) { 2953 if (i == 0) {
2648 reg_strict = true; 2954 param.reg_strict = true;
2649 reg_alpha2 = hwsim_alpha2s[0]; 2955 param.reg_alpha2 = hwsim_alpha2s[0];
2650 } else if (i == 1) { 2956 } else if (i == 1) {
2651 reg_alpha2 = hwsim_alpha2s[1]; 2957 param.reg_alpha2 = hwsim_alpha2s[1];
2652 } 2958 }
2653 break; 2959 break;
2654 case HWSIM_REGTEST_ALL: 2960 case HWSIM_REGTEST_ALL:
2655 switch (i) { 2961 switch (i) {
2656 case 0: 2962 case 0:
2657 regd = &hwsim_world_regdom_custom_01; 2963 param.regd = &hwsim_world_regdom_custom_01;
2658 break; 2964 break;
2659 case 1: 2965 case 1:
2660 regd = &hwsim_world_regdom_custom_02; 2966 param.regd = &hwsim_world_regdom_custom_02;
2661 break; 2967 break;
2662 case 2: 2968 case 2:
2663 reg_alpha2 = hwsim_alpha2s[0]; 2969 param.reg_alpha2 = hwsim_alpha2s[0];
2664 break; 2970 break;
2665 case 3: 2971 case 3:
2666 reg_alpha2 = hwsim_alpha2s[1]; 2972 param.reg_alpha2 = hwsim_alpha2s[1];
2667 break; 2973 break;
2668 case 4: 2974 case 4:
2669 reg_strict = true; 2975 param.reg_strict = true;
2670 reg_alpha2 = hwsim_alpha2s[2]; 2976 param.reg_alpha2 = hwsim_alpha2s[2];
2671 break; 2977 break;
2672 } 2978 }
2673 break; 2979 break;
@@ -2675,10 +2981,10 @@ static int __init init_mac80211_hwsim(void)
2675 break; 2981 break;
2676 } 2982 }
2677 2983
2678 err = mac80211_hwsim_create_radio(channels, reg_alpha2, 2984 param.p2p_device = support_p2p_device;
2679 regd, reg_strict, 2985 param.use_chanctx = channels > 1;
2680 support_p2p_device, 2986
2681 channels > 1); 2987 err = mac80211_hwsim_new_radio(NULL, &param);
2682 if (err < 0) 2988 if (err < 0)
2683 goto out_free_radios; 2989 goto out_free_radios;
2684 } 2990 }
@@ -2704,10 +3010,6 @@ static int __init init_mac80211_hwsim(void)
2704 } 3010 }
2705 rtnl_unlock(); 3011 rtnl_unlock();
2706 3012
2707 err = hwsim_init_netlink();
2708 if (err < 0)
2709 goto out_free_mon;
2710
2711 return 0; 3013 return 0;
2712 3014
2713out_free_mon: 3015out_free_mon:
diff --git a/drivers/net/wireless/mac80211_hwsim.h b/drivers/net/wireless/mac80211_hwsim.h
index c9d0315575ba..f08debdd639b 100644
--- a/drivers/net/wireless/mac80211_hwsim.h
+++ b/drivers/net/wireless/mac80211_hwsim.h
@@ -60,14 +60,15 @@ enum hwsim_tx_control_flags {
60 * space, uses: 60 * space, uses:
61 * %HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_ADDR_RECEIVER, 61 * %HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_ADDR_RECEIVER,
62 * %HWSIM_ATTR_FRAME, %HWSIM_ATTR_FLAGS, %HWSIM_ATTR_RX_RATE, 62 * %HWSIM_ATTR_FRAME, %HWSIM_ATTR_FLAGS, %HWSIM_ATTR_RX_RATE,
63 * %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE 63 * %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE, %HWSIM_ATTR_FREQ (optional)
64 * @HWSIM_CMD_TX_INFO_FRAME: Transmission info report from user space to 64 * @HWSIM_CMD_TX_INFO_FRAME: Transmission info report from user space to
65 * kernel, uses: 65 * kernel, uses:
66 * %HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_FLAGS, 66 * %HWSIM_ATTR_ADDR_TRANSMITTER, %HWSIM_ATTR_FLAGS,
67 * %HWSIM_ATTR_TX_INFO, %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE 67 * %HWSIM_ATTR_TX_INFO, %HWSIM_ATTR_SIGNAL, %HWSIM_ATTR_COOKIE
68 * @HWSIM_CMD_CREATE_RADIO: create a new radio with the given parameters, 68 * @HWSIM_CMD_NEW_RADIO: create a new radio with the given parameters,
69 * returns the radio ID (>= 0) or negative on errors 69 * returns the radio ID (>= 0) or negative on errors, if successful
70 * @HWSIM_CMD_DESTROY_RADIO: destroy a radio 70 * then multicast the result
71 * @HWSIM_CMD_DEL_RADIO: destroy a radio, reply is multicasted
71 * @__HWSIM_CMD_MAX: enum limit 72 * @__HWSIM_CMD_MAX: enum limit
72 */ 73 */
73enum { 74enum {
@@ -75,12 +76,15 @@ enum {
75 HWSIM_CMD_REGISTER, 76 HWSIM_CMD_REGISTER,
76 HWSIM_CMD_FRAME, 77 HWSIM_CMD_FRAME,
77 HWSIM_CMD_TX_INFO_FRAME, 78 HWSIM_CMD_TX_INFO_FRAME,
78 HWSIM_CMD_CREATE_RADIO, 79 HWSIM_CMD_NEW_RADIO,
79 HWSIM_CMD_DESTROY_RADIO, 80 HWSIM_CMD_DEL_RADIO,
80 __HWSIM_CMD_MAX, 81 __HWSIM_CMD_MAX,
81}; 82};
82#define HWSIM_CMD_MAX (_HWSIM_CMD_MAX - 1) 83#define HWSIM_CMD_MAX (_HWSIM_CMD_MAX - 1)
83 84
85#define HWSIM_CMD_CREATE_RADIO HWSIM_CMD_NEW_RADIO
86#define HWSIM_CMD_DESTROY_RADIO HWSIM_CMD_DEL_RADIO
87
84/** 88/**
85 * enum hwsim_attrs - hwsim netlink attributes 89 * enum hwsim_attrs - hwsim netlink attributes
86 * 90 *
@@ -111,6 +115,11 @@ enum {
111 * @HWSIM_ATTR_USE_CHANCTX: used with the %HWSIM_CMD_CREATE_RADIO 115 * @HWSIM_ATTR_USE_CHANCTX: used with the %HWSIM_CMD_CREATE_RADIO
112 * command to force use of channel contexts even when only a 116 * command to force use of channel contexts even when only a
113 * single channel is supported 117 * single channel is supported
118 * @HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE: used with the %HWSIM_CMD_CREATE_RADIO
119 * command to force radio removal when process that created the radio dies
120 * @HWSIM_ATTR_RADIO_NAME: Name of radio, e.g. phy666
121 * @HWSIM_ATTR_NO_VIF: Do not create vif (wlanX) when creating radio.
122 * @HWSIM_ATTR_FREQ: Frequency at which packet is transmitted or received.
114 * @__HWSIM_ATTR_MAX: enum limit 123 * @__HWSIM_ATTR_MAX: enum limit
115 */ 124 */
116 125
@@ -132,6 +141,10 @@ enum {
132 HWSIM_ATTR_REG_STRICT_REG, 141 HWSIM_ATTR_REG_STRICT_REG,
133 HWSIM_ATTR_SUPPORT_P2P_DEVICE, 142 HWSIM_ATTR_SUPPORT_P2P_DEVICE,
134 HWSIM_ATTR_USE_CHANCTX, 143 HWSIM_ATTR_USE_CHANCTX,
144 HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE,
145 HWSIM_ATTR_RADIO_NAME,
146 HWSIM_ATTR_NO_VIF,
147 HWSIM_ATTR_FREQ,
135 __HWSIM_ATTR_MAX, 148 __HWSIM_ATTR_MAX,
136}; 149};
137#define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1) 150#define HWSIM_ATTR_MAX (__HWSIM_ATTR_MAX - 1)
diff --git a/drivers/net/wireless/mwifiex/11n.h b/drivers/net/wireless/mwifiex/11n.h
index 2ee268b632be..f275675cdbd3 100644
--- a/drivers/net/wireless/mwifiex/11n.h
+++ b/drivers/net/wireless/mwifiex/11n.h
@@ -84,6 +84,8 @@ mwifiex_is_amsdu_in_ampdu_allowed(struct mwifiex_private *priv,
84{ 84{
85 struct mwifiex_tx_ba_stream_tbl *tx_tbl; 85 struct mwifiex_tx_ba_stream_tbl *tx_tbl;
86 86
87 if (is_broadcast_ether_addr(ptr->ra))
88 return false;
87 tx_tbl = mwifiex_get_ba_tbl(priv, tid, ptr->ra); 89 tx_tbl = mwifiex_get_ba_tbl(priv, tid, ptr->ra);
88 if (tx_tbl) 90 if (tx_tbl)
89 return tx_tbl->amsdu; 91 return tx_tbl->amsdu;
@@ -96,6 +98,8 @@ static inline u8
96mwifiex_is_ampdu_allowed(struct mwifiex_private *priv, 98mwifiex_is_ampdu_allowed(struct mwifiex_private *priv,
97 struct mwifiex_ra_list_tbl *ptr, int tid) 99 struct mwifiex_ra_list_tbl *ptr, int tid)
98{ 100{
101 if (is_broadcast_ether_addr(ptr->ra))
102 return false;
99 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { 103 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
100 return mwifiex_is_station_ampdu_allowed(priv, ptr, tid); 104 return mwifiex_is_station_ampdu_allowed(priv, ptr, tid);
101 } else { 105 } else {
diff --git a/drivers/net/wireless/mwifiex/cfg80211.c b/drivers/net/wireless/mwifiex/cfg80211.c
index 0dd672954ad1..17f0ee02d6e7 100644
--- a/drivers/net/wireless/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/mwifiex/cfg80211.c
@@ -992,6 +992,52 @@ mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
992 return mwifiex_dump_station_info(priv, sinfo); 992 return mwifiex_dump_station_info(priv, sinfo);
993} 993}
994 994
995static int
996mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
997 int idx, struct survey_info *survey)
998{
999 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1000 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1001 enum ieee80211_band band;
1002
1003 dev_dbg(priv->adapter->dev, "dump_survey idx=%d\n", idx);
1004
1005 memset(survey, 0, sizeof(struct survey_info));
1006
1007 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1008 priv->media_connected && idx == 0) {
1009 u8 curr_bss_band = priv->curr_bss_params.band;
1010 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1011
1012 band = mwifiex_band_to_radio_type(curr_bss_band);
1013 survey->channel = ieee80211_get_channel(wiphy,
1014 ieee80211_channel_to_frequency(chan, band));
1015
1016 if (priv->bcn_nf_last) {
1017 survey->filled = SURVEY_INFO_NOISE_DBM;
1018 survey->noise = priv->bcn_nf_last;
1019 }
1020 return 0;
1021 }
1022
1023 if (idx >= priv->adapter->num_in_chan_stats)
1024 return -ENOENT;
1025
1026 if (!pchan_stats[idx].cca_scan_dur)
1027 return 0;
1028
1029 band = pchan_stats[idx].bandcfg;
1030 survey->channel = ieee80211_get_channel(wiphy,
1031 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1032 survey->filled = SURVEY_INFO_NOISE_DBM |
1033 SURVEY_INFO_CHANNEL_TIME | SURVEY_INFO_CHANNEL_TIME_BUSY;
1034 survey->noise = pchan_stats[idx].noise;
1035 survey->channel_time = pchan_stats[idx].cca_scan_dur;
1036 survey->channel_time_busy = pchan_stats[idx].cca_busy_dur;
1037
1038 return 0;
1039}
1040
995/* Supported rates to be advertised to the cfg80211 */ 1041/* Supported rates to be advertised to the cfg80211 */
996static struct ieee80211_rate mwifiex_rates[] = { 1042static struct ieee80211_rate mwifiex_rates[] = {
997 {.bitrate = 10, .hw_value = 2, }, 1043 {.bitrate = 10, .hw_value = 2, },
@@ -1239,7 +1285,7 @@ static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1239 */ 1285 */
1240static int 1286static int
1241mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev, 1287mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1242 const u8 *mac) 1288 struct station_del_parameters *params)
1243{ 1289{
1244 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1290 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1245 struct mwifiex_sta_node *sta_node; 1291 struct mwifiex_sta_node *sta_node;
@@ -1248,7 +1294,7 @@ mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1248 if (list_empty(&priv->sta_list) || !priv->bss_started) 1294 if (list_empty(&priv->sta_list) || !priv->bss_started)
1249 return 0; 1295 return 0;
1250 1296
1251 if (!mac || is_broadcast_ether_addr(mac)) { 1297 if (!params->mac || is_broadcast_ether_addr(params->mac)) {
1252 wiphy_dbg(wiphy, "%s: NULL/broadcast mac address\n", __func__); 1298 wiphy_dbg(wiphy, "%s: NULL/broadcast mac address\n", __func__);
1253 list_for_each_entry(sta_node, &priv->sta_list, list) { 1299 list_for_each_entry(sta_node, &priv->sta_list, list) {
1254 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH, 1300 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
@@ -1258,9 +1304,10 @@ mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1258 mwifiex_uap_del_sta_data(priv, sta_node); 1304 mwifiex_uap_del_sta_data(priv, sta_node);
1259 } 1305 }
1260 } else { 1306 } else {
1261 wiphy_dbg(wiphy, "%s: mac address %pM\n", __func__, mac); 1307 wiphy_dbg(wiphy, "%s: mac address %pM\n", __func__,
1308 params->mac);
1262 spin_lock_irqsave(&priv->sta_list_spinlock, flags); 1309 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1263 sta_node = mwifiex_get_sta_entry(priv, mac); 1310 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1264 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 1311 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1265 if (sta_node) { 1312 if (sta_node) {
1266 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH, 1313 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
@@ -1759,6 +1806,10 @@ mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1759 dev_dbg(priv->adapter->dev, 1806 dev_dbg(priv->adapter->dev,
1760 "info: associated to bssid %pM successfully\n", 1807 "info: associated to bssid %pM successfully\n",
1761 priv->cfg_bssid); 1808 priv->cfg_bssid);
1809 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
1810 priv->adapter->auto_tdls &&
1811 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
1812 mwifiex_setup_auto_tdls_timer(priv);
1762 } else { 1813 } else {
1763 dev_dbg(priv->adapter->dev, 1814 dev_dbg(priv->adapter->dev,
1764 "info: association to bssid %pM failed\n", 1815 "info: association to bssid %pM failed\n",
@@ -2630,11 +2681,13 @@ mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2630 dev_dbg(priv->adapter->dev, 2681 dev_dbg(priv->adapter->dev,
2631 "Send TDLS Setup Request to %pM status_code=%d\n", peer, 2682 "Send TDLS Setup Request to %pM status_code=%d\n", peer,
2632 status_code); 2683 status_code);
2684 mwifiex_add_auto_tdls_peer(priv, peer);
2633 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 2685 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
2634 dialog_token, status_code, 2686 dialog_token, status_code,
2635 extra_ies, extra_ies_len); 2687 extra_ies, extra_ies_len);
2636 break; 2688 break;
2637 case WLAN_TDLS_SETUP_RESPONSE: 2689 case WLAN_TDLS_SETUP_RESPONSE:
2690 mwifiex_add_auto_tdls_peer(priv, peer);
2638 dev_dbg(priv->adapter->dev, 2691 dev_dbg(priv->adapter->dev,
2639 "Send TDLS Setup Response to %pM status_code=%d\n", 2692 "Send TDLS Setup Response to %pM status_code=%d\n",
2640 peer, status_code); 2693 peer, status_code);
@@ -2779,6 +2832,7 @@ static struct cfg80211_ops mwifiex_cfg80211_ops = {
2779 .disconnect = mwifiex_cfg80211_disconnect, 2832 .disconnect = mwifiex_cfg80211_disconnect,
2780 .get_station = mwifiex_cfg80211_get_station, 2833 .get_station = mwifiex_cfg80211_get_station,
2781 .dump_station = mwifiex_cfg80211_dump_station, 2834 .dump_station = mwifiex_cfg80211_dump_station,
2835 .dump_survey = mwifiex_cfg80211_dump_survey,
2782 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params, 2836 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
2783 .join_ibss = mwifiex_cfg80211_join_ibss, 2837 .join_ibss = mwifiex_cfg80211_join_ibss,
2784 .leave_ibss = mwifiex_cfg80211_leave_ibss, 2838 .leave_ibss = mwifiex_cfg80211_leave_ibss,
@@ -2840,6 +2894,25 @@ static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
2840 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 2894 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
2841}; 2895};
2842 2896
2897int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
2898{
2899 u32 n_channels_bg, n_channels_a = 0;
2900
2901 n_channels_bg = mwifiex_band_2ghz.n_channels;
2902
2903 if (adapter->config_bands & BAND_A)
2904 n_channels_a = mwifiex_band_5ghz.n_channels;
2905
2906 adapter->num_in_chan_stats = max_t(u32, n_channels_bg, n_channels_a);
2907 adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
2908 adapter->num_in_chan_stats);
2909
2910 if (!adapter->chan_stats)
2911 return -ENOMEM;
2912
2913 return 0;
2914}
2915
2843/* 2916/*
2844 * This function registers the device with CFG802.11 subsystem. 2917 * This function registers the device with CFG802.11 subsystem.
2845 * 2918 *
diff --git a/drivers/net/wireless/mwifiex/decl.h b/drivers/net/wireless/mwifiex/decl.h
index e0d00a7f0ec3..fc0b1ed80a6a 100644
--- a/drivers/net/wireless/mwifiex/decl.h
+++ b/drivers/net/wireless/mwifiex/decl.h
@@ -85,6 +85,11 @@
85#define MWIFIEX_TDLS_CREATE_LINK 0x02 85#define MWIFIEX_TDLS_CREATE_LINK 0x02
86#define MWIFIEX_TDLS_CONFIG_LINK 0x03 86#define MWIFIEX_TDLS_CONFIG_LINK 0x03
87 87
88#define MWIFIEX_TDLS_RSSI_HIGH 50
89#define MWIFIEX_TDLS_RSSI_LOW 55
90#define MWIFIEX_TDLS_MAX_FAIL_COUNT 4
91#define MWIFIEX_AUTO_TDLS_IDLE_TIME 10
92
88enum mwifiex_bss_type { 93enum mwifiex_bss_type {
89 MWIFIEX_BSS_TYPE_STA = 0, 94 MWIFIEX_BSS_TYPE_STA = 0,
90 MWIFIEX_BSS_TYPE_UAP = 1, 95 MWIFIEX_BSS_TYPE_UAP = 1,
@@ -185,4 +190,14 @@ struct mwifiex_arp_eth_header {
185 u8 ar_tha[ETH_ALEN]; 190 u8 ar_tha[ETH_ALEN];
186 u8 ar_tip[4]; 191 u8 ar_tip[4];
187} __packed; 192} __packed;
193
194struct mwifiex_chan_stats {
195 u8 chan_num;
196 u8 bandcfg;
197 u8 flags;
198 s8 noise;
199 u16 total_bss;
200 u16 cca_scan_dur;
201 u16 cca_busy_dur;
202} __packed;
188#endif /* !_MWIFIEX_DECL_H_ */ 203#endif /* !_MWIFIEX_DECL_H_ */
diff --git a/drivers/net/wireless/mwifiex/fw.h b/drivers/net/wireless/mwifiex/fw.h
index 1eb61739071f..e095f371545a 100644
--- a/drivers/net/wireless/mwifiex/fw.h
+++ b/drivers/net/wireless/mwifiex/fw.h
@@ -172,6 +172,7 @@ enum MWIFIEX_802_11_PRIVACY_FILTER {
172#define TLV_TYPE_TDLS_IDLE_TIMEOUT (PROPRIETARY_TLV_BASE_ID + 194) 172#define TLV_TYPE_TDLS_IDLE_TIMEOUT (PROPRIETARY_TLV_BASE_ID + 194)
173#define TLV_TYPE_SCAN_CHANNEL_GAP (PROPRIETARY_TLV_BASE_ID + 197) 173#define TLV_TYPE_SCAN_CHANNEL_GAP (PROPRIETARY_TLV_BASE_ID + 197)
174#define TLV_TYPE_API_REV (PROPRIETARY_TLV_BASE_ID + 199) 174#define TLV_TYPE_API_REV (PROPRIETARY_TLV_BASE_ID + 199)
175#define TLV_TYPE_CHANNEL_STATS (PROPRIETARY_TLV_BASE_ID + 198)
175 176
176#define MWIFIEX_TX_DATA_BUF_SIZE_2K 2048 177#define MWIFIEX_TX_DATA_BUF_SIZE_2K 2048
177 178
@@ -583,6 +584,7 @@ struct rxpd {
583 * [Bit 7] Reserved 584 * [Bit 7] Reserved
584 */ 585 */
585 u8 ht_info; 586 u8 ht_info;
587 u8 reserved[3];
586 u8 flags; 588 u8 flags;
587} __packed; 589} __packed;
588 590
@@ -611,6 +613,16 @@ struct uap_rxpd {
611 u8 reserved1; 613 u8 reserved1;
612}; 614};
613 615
616struct mwifiex_fw_chan_stats {
617 u8 chan_num;
618 u8 bandcfg;
619 u8 flags;
620 s8 noise;
621 __le16 total_bss;
622 __le16 cca_scan_dur;
623 __le16 cca_busy_dur;
624} __packed;
625
614enum mwifiex_chan_scan_mode_bitmasks { 626enum mwifiex_chan_scan_mode_bitmasks {
615 MWIFIEX_PASSIVE_SCAN = BIT(0), 627 MWIFIEX_PASSIVE_SCAN = BIT(0),
616 MWIFIEX_DISABLE_CHAN_FILT = BIT(1), 628 MWIFIEX_DISABLE_CHAN_FILT = BIT(1),
@@ -660,6 +672,11 @@ struct mwifiex_ie_types_scan_chan_gap {
660 __le16 chan_gap; 672 __le16 chan_gap;
661} __packed; 673} __packed;
662 674
675struct mwifiex_ietypes_chanstats {
676 struct mwifiex_ie_types_header header;
677 struct mwifiex_fw_chan_stats chanstats[0];
678} __packed;
679
663struct mwifiex_ie_types_wildcard_ssid_params { 680struct mwifiex_ie_types_wildcard_ssid_params {
664 struct mwifiex_ie_types_header header; 681 struct mwifiex_ie_types_header header;
665 u8 max_ssid_length; 682 u8 max_ssid_length;
diff --git a/drivers/net/wireless/mwifiex/init.c b/drivers/net/wireless/mwifiex/init.c
index 580aa45ec4bc..cc15ab81aa66 100644
--- a/drivers/net/wireless/mwifiex/init.c
+++ b/drivers/net/wireless/mwifiex/init.c
@@ -137,6 +137,7 @@ int mwifiex_init_priv(struct mwifiex_private *priv)
137 priv->csa_expire_time = 0; 137 priv->csa_expire_time = 0;
138 priv->del_list_idx = 0; 138 priv->del_list_idx = 0;
139 priv->hs2_enabled = false; 139 priv->hs2_enabled = false;
140 priv->check_tdls_tx = false;
140 memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID); 141 memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
141 142
142 return mwifiex_add_bss_prio_tbl(priv); 143 return mwifiex_add_bss_prio_tbl(priv);
@@ -366,6 +367,7 @@ static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
366 list_del(&priv->tx_ba_stream_tbl_ptr); 367 list_del(&priv->tx_ba_stream_tbl_ptr);
367 list_del(&priv->rx_reorder_tbl_ptr); 368 list_del(&priv->rx_reorder_tbl_ptr);
368 list_del(&priv->sta_list); 369 list_del(&priv->sta_list);
370 list_del(&priv->auto_tdls_list);
369 } 371 }
370 } 372 }
371} 373}
@@ -434,6 +436,7 @@ int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
434 spin_lock_init(&priv->wmm.ra_list_spinlock); 436 spin_lock_init(&priv->wmm.ra_list_spinlock);
435 spin_lock_init(&priv->curr_bcn_buf_lock); 437 spin_lock_init(&priv->curr_bcn_buf_lock);
436 spin_lock_init(&priv->sta_list_spinlock); 438 spin_lock_init(&priv->sta_list_spinlock);
439 spin_lock_init(&priv->auto_tdls_lock);
437 } 440 }
438 } 441 }
439 442
@@ -449,7 +452,6 @@ int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
449 spin_lock_init(&adapter->scan_pending_q_lock); 452 spin_lock_init(&adapter->scan_pending_q_lock);
450 spin_lock_init(&adapter->rx_proc_lock); 453 spin_lock_init(&adapter->rx_proc_lock);
451 454
452 skb_queue_head_init(&adapter->usb_rx_data_q);
453 skb_queue_head_init(&adapter->rx_data_q); 455 skb_queue_head_init(&adapter->rx_data_q);
454 456
455 for (i = 0; i < adapter->priv_num; ++i) { 457 for (i = 0; i < adapter->priv_num; ++i) {
@@ -466,6 +468,7 @@ int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
466 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr); 468 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
467 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); 469 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
468 INIT_LIST_HEAD(&priv->sta_list); 470 INIT_LIST_HEAD(&priv->sta_list);
471 INIT_LIST_HEAD(&priv->auto_tdls_list);
469 skb_queue_head_init(&priv->tdls_txq); 472 skb_queue_head_init(&priv->tdls_txq);
470 473
471 spin_lock_init(&priv->tx_ba_stream_tbl_lock); 474 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
@@ -646,6 +649,7 @@ mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
646 if (adapter->priv[i]) { 649 if (adapter->priv[i]) {
647 priv = adapter->priv[i]; 650 priv = adapter->priv[i];
648 651
652 mwifiex_clean_auto_tdls(priv);
649 mwifiex_clean_txrx(priv); 653 mwifiex_clean_txrx(priv);
650 mwifiex_delete_bss_prio_tbl(priv); 654 mwifiex_delete_bss_prio_tbl(priv);
651 } 655 }
@@ -668,19 +672,6 @@ mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
668 672
669 spin_lock(&adapter->mwifiex_lock); 673 spin_lock(&adapter->mwifiex_lock);
670 674
671 if (adapter->if_ops.data_complete) {
672 while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) {
673 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
674
675 priv = adapter->priv[rx_info->bss_num];
676 if (priv)
677 priv->stats.rx_dropped++;
678
679 dev_kfree_skb_any(skb);
680 adapter->if_ops.data_complete(adapter);
681 }
682 }
683
684 mwifiex_adapter_cleanup(adapter); 675 mwifiex_adapter_cleanup(adapter);
685 676
686 spin_unlock(&adapter->mwifiex_lock); 677 spin_unlock(&adapter->mwifiex_lock);
diff --git a/drivers/net/wireless/mwifiex/join.c b/drivers/net/wireless/mwifiex/join.c
index 8d6c25908b6d..411a6c2f4aca 100644
--- a/drivers/net/wireless/mwifiex/join.c
+++ b/drivers/net/wireless/mwifiex/join.c
@@ -880,9 +880,7 @@ mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
880 880
881 /* Set Capability info */ 881 /* Set Capability info */
882 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS; 882 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
883 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap); 883 tmp_cap = WLAN_CAPABILITY_IBSS;
884 tmp_cap &= ~WLAN_CAPABILITY_ESS;
885 tmp_cap |= WLAN_CAPABILITY_IBSS;
886 884
887 /* Set up privacy in bss_desc */ 885 /* Set up privacy in bss_desc */
888 if (priv->sec_info.encryption_mode) { 886 if (priv->sec_info.encryption_mode) {
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index d5070c444fe1..0e50120eb807 100644
--- a/drivers/net/wireless/mwifiex/main.c
+++ b/drivers/net/wireless/mwifiex/main.c
@@ -28,6 +28,11 @@ const char driver_version[] = "mwifiex " VERSION " (%s) ";
28static char *cal_data_cfg; 28static char *cal_data_cfg;
29module_param(cal_data_cfg, charp, 0); 29module_param(cal_data_cfg, charp, 0);
30 30
31static unsigned short driver_mode;
32module_param(driver_mode, ushort, 0);
33MODULE_PARM_DESC(driver_mode,
34 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
35
31/* 36/*
32 * This function registers the device and performs all the necessary 37 * This function registers the device and performs all the necessary
33 * initializations. 38 * initializations.
@@ -122,6 +127,7 @@ static int mwifiex_unregister(struct mwifiex_adapter *adapter)
122 } 127 }
123 } 128 }
124 129
130 vfree(adapter->chan_stats);
125 kfree(adapter); 131 kfree(adapter);
126 return 0; 132 return 0;
127} 133}
@@ -145,6 +151,8 @@ static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
145 atomic_dec(&adapter->rx_pending); 151 atomic_dec(&adapter->rx_pending);
146 if (adapter->delay_main_work && 152 if (adapter->delay_main_work &&
147 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) { 153 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
154 if (adapter->if_ops.submit_rem_rx_urbs)
155 adapter->if_ops.submit_rem_rx_urbs(adapter);
148 adapter->delay_main_work = false; 156 adapter->delay_main_work = false;
149 queue_work(adapter->workqueue, &adapter->main_work); 157 queue_work(adapter->workqueue, &adapter->main_work);
150 } 158 }
@@ -177,7 +185,6 @@ int mwifiex_main_process(struct mwifiex_adapter *adapter)
177{ 185{
178 int ret = 0; 186 int ret = 0;
179 unsigned long flags; 187 unsigned long flags;
180 struct sk_buff *skb;
181 188
182 spin_lock_irqsave(&adapter->main_proc_lock, flags); 189 spin_lock_irqsave(&adapter->main_proc_lock, flags);
183 190
@@ -252,11 +259,6 @@ process_start:
252 } 259 }
253 } 260 }
254 261
255 /* Check Rx data for USB */
256 if (adapter->iface_type == MWIFIEX_USB)
257 while ((skb = skb_dequeue(&adapter->usb_rx_data_q)))
258 mwifiex_handle_rx_packet(adapter, skb);
259
260 /* Check for event */ 262 /* Check for event */
261 if (adapter->event_received) { 263 if (adapter->event_received) {
262 adapter->event_received = false; 264 adapter->event_received = false;
@@ -447,6 +449,16 @@ static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
447 goto err_init_fw; 449 goto err_init_fw;
448 } 450 }
449 451
452 if (mwifiex_init_channel_scan_gap(adapter)) {
453 dev_err(adapter->dev, "could not init channel stats table\n");
454 goto err_init_fw;
455 }
456
457 if (driver_mode) {
458 driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
459 driver_mode |= MWIFIEX_DRIVER_MODE_STA;
460 }
461
450 rtnl_lock(); 462 rtnl_lock();
451 /* Create station interface by default */ 463 /* Create station interface by default */
452 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", 464 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
@@ -456,6 +468,28 @@ static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
456 rtnl_unlock(); 468 rtnl_unlock();
457 goto err_add_intf; 469 goto err_add_intf;
458 } 470 }
471
472 if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
473 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d",
474 NL80211_IFTYPE_AP, NULL, NULL);
475 if (IS_ERR(wdev)) {
476 dev_err(adapter->dev, "cannot create AP interface\n");
477 rtnl_unlock();
478 goto err_add_intf;
479 }
480 }
481
482 if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
483 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d",
484 NL80211_IFTYPE_P2P_CLIENT, NULL,
485 NULL);
486 if (IS_ERR(wdev)) {
487 dev_err(adapter->dev,
488 "cannot create p2p client interface\n");
489 rtnl_unlock();
490 goto err_add_intf;
491 }
492 }
459 rtnl_unlock(); 493 rtnl_unlock();
460 494
461 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1); 495 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
@@ -628,6 +662,13 @@ mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
628 */ 662 */
629 __net_timestamp(skb); 663 __net_timestamp(skb);
630 664
665 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
666 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
667 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
668 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
669 mwifiex_tdls_check_tx(priv, skb);
670 }
671
631 mwifiex_queue_tx_pkt(priv, skb); 672 mwifiex_queue_tx_pkt(priv, skb);
632 673
633 return 0; 674 return 0;
@@ -858,7 +899,7 @@ mwifiex_add_card(void *card, struct semaphore *sem,
858 adapter->cmd_wait_q.status = 0; 899 adapter->cmd_wait_q.status = 0;
859 adapter->scan_wait_q_woken = false; 900 adapter->scan_wait_q_woken = false;
860 901
861 if (num_possible_cpus() > 1) { 902 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
862 adapter->rx_work_enabled = true; 903 adapter->rx_work_enabled = true;
863 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus()); 904 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
864 } 905 }
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index f55658d15c60..5a690d5210f0 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -48,6 +48,11 @@ enum {
48 MWIFIEX_SYNC_CMD 48 MWIFIEX_SYNC_CMD
49}; 49};
50 50
51#define MWIFIEX_DRIVER_MODE_STA BIT(0)
52#define MWIFIEX_DRIVER_MODE_UAP BIT(1)
53#define MWIFIEX_DRIVER_MODE_P2P BIT(2)
54#define MWIFIEX_DRIVER_MODE_BITMASK (BIT(0) | BIT(1) | BIT(2))
55
51#define MWIFIEX_MAX_AP 64 56#define MWIFIEX_MAX_AP 64
52 57
53#define MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT (5 * HZ) 58#define MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT (5 * HZ)
@@ -106,10 +111,7 @@ enum {
106 */ 111 */
107#define IS_CARD_RX_RCVD(adapter) (adapter->cmd_resp_received || \ 112#define IS_CARD_RX_RCVD(adapter) (adapter->cmd_resp_received || \
108 adapter->event_received || \ 113 adapter->event_received || \
109 ((adapter->iface_type != MWIFIEX_USB) && \ 114 adapter->data_received)
110 adapter->data_received) || \
111 ((adapter->iface_type == MWIFIEX_USB) && \
112 !skb_queue_empty(&adapter->usb_rx_data_q)))
113 115
114#define MWIFIEX_TYPE_CMD 1 116#define MWIFIEX_TYPE_CMD 1
115#define MWIFIEX_TYPE_DATA 0 117#define MWIFIEX_TYPE_DATA 0
@@ -504,8 +506,11 @@ struct mwifiex_private {
504 struct mwifiex_wmm_desc wmm; 506 struct mwifiex_wmm_desc wmm;
505 atomic_t wmm_tx_pending[IEEE80211_NUM_ACS]; 507 atomic_t wmm_tx_pending[IEEE80211_NUM_ACS];
506 struct list_head sta_list; 508 struct list_head sta_list;
507 /* spin lock for associated station list */ 509 /* spin lock for associated station/TDLS peers list */
508 spinlock_t sta_list_spinlock; 510 spinlock_t sta_list_spinlock;
511 struct list_head auto_tdls_list;
512 /* spin lock for auto TDLS peer list */
513 spinlock_t auto_tdls_lock;
509 struct list_head tx_ba_stream_tbl_ptr; 514 struct list_head tx_ba_stream_tbl_ptr;
510 /* spin lock for tx_ba_stream_tbl_ptr queue */ 515 /* spin lock for tx_ba_stream_tbl_ptr queue */
511 spinlock_t tx_ba_stream_tbl_lock; 516 spinlock_t tx_ba_stream_tbl_lock;
@@ -570,6 +575,9 @@ struct mwifiex_private {
570 bool hs2_enabled; 575 bool hs2_enabled;
571 struct station_parameters *sta_params; 576 struct station_parameters *sta_params;
572 struct sk_buff_head tdls_txq; 577 struct sk_buff_head tdls_txq;
578 u8 check_tdls_tx;
579 struct timer_list auto_tdls_timer;
580 bool auto_tdls_timer_active;
573}; 581};
574 582
575enum mwifiex_ba_status { 583enum mwifiex_ba_status {
@@ -670,6 +678,17 @@ struct mwifiex_sta_node {
670 struct mwifiex_tdls_capab tdls_cap; 678 struct mwifiex_tdls_capab tdls_cap;
671}; 679};
672 680
681struct mwifiex_auto_tdls_peer {
682 struct list_head list;
683 u8 mac_addr[ETH_ALEN];
684 u8 tdls_status;
685 int rssi;
686 long rssi_jiffies;
687 u8 failure_count;
688 u8 do_discover;
689 u8 do_setup;
690};
691
673struct mwifiex_if_ops { 692struct mwifiex_if_ops {
674 int (*init_if) (struct mwifiex_adapter *); 693 int (*init_if) (struct mwifiex_adapter *);
675 void (*cleanup_if) (struct mwifiex_adapter *); 694 void (*cleanup_if) (struct mwifiex_adapter *);
@@ -690,13 +709,13 @@ struct mwifiex_if_ops {
690 void (*cleanup_mpa_buf) (struct mwifiex_adapter *); 709 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
691 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *); 710 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
692 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *); 711 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
693 int (*data_complete) (struct mwifiex_adapter *);
694 int (*init_fw_port) (struct mwifiex_adapter *); 712 int (*init_fw_port) (struct mwifiex_adapter *);
695 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *); 713 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
696 void (*card_reset) (struct mwifiex_adapter *); 714 void (*card_reset) (struct mwifiex_adapter *);
697 void (*fw_dump)(struct mwifiex_adapter *); 715 void (*fw_dump)(struct mwifiex_adapter *);
698 int (*clean_pcie_ring) (struct mwifiex_adapter *adapter); 716 int (*clean_pcie_ring) (struct mwifiex_adapter *adapter);
699 void (*iface_work)(struct work_struct *work); 717 void (*iface_work)(struct work_struct *work);
718 void (*submit_rem_rx_urbs)(struct mwifiex_adapter *adapter);
700}; 719};
701 720
702struct mwifiex_adapter { 721struct mwifiex_adapter {
@@ -767,7 +786,6 @@ struct mwifiex_adapter {
767 spinlock_t scan_pending_q_lock; 786 spinlock_t scan_pending_q_lock;
768 /* spin lock for RX processing routine */ 787 /* spin lock for RX processing routine */
769 spinlock_t rx_proc_lock; 788 spinlock_t rx_proc_lock;
770 struct sk_buff_head usb_rx_data_q;
771 u32 scan_processing; 789 u32 scan_processing;
772 u16 region_code; 790 u16 region_code;
773 struct mwifiex_802_11d_domain_reg domain_reg; 791 struct mwifiex_802_11d_domain_reg domain_reg;
@@ -845,6 +863,10 @@ struct mwifiex_adapter {
845 u8 curr_mem_idx; 863 u8 curr_mem_idx;
846 bool scan_chan_gap_enabled; 864 bool scan_chan_gap_enabled;
847 struct sk_buff_head rx_data_q; 865 struct sk_buff_head rx_data_q;
866 struct mwifiex_chan_stats *chan_stats;
867 u32 num_in_chan_stats;
868 int survey_idx;
869 bool auto_tdls;
848}; 870};
849 871
850int mwifiex_init_lock_list(struct mwifiex_adapter *adapter); 872int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
@@ -1031,7 +1053,8 @@ void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv);
1031int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv, 1053int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
1032 struct host_cmd_ds_command *cmd, 1054 struct host_cmd_ds_command *cmd,
1033 void *data_buf); 1055 void *data_buf);
1034int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv); 1056int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
1057 struct host_cmd_ds_command *resp);
1035int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv, 1058int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
1036 void *buf); 1059 void *buf);
1037 1060
@@ -1301,6 +1324,17 @@ u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
1301 u32 pri_chan, u8 chan_bw); 1324 u32 pri_chan, u8 chan_bw);
1302int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter); 1325int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter);
1303 1326
1327int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb);
1328void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv);
1329void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
1330 const u8 *mac, u8 link_status);
1331void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
1332 u8 *mac, s8 snr, s8 nflr);
1333void mwifiex_check_auto_tdls(unsigned long context);
1334void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac);
1335void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv);
1336void mwifiex_clean_auto_tdls(struct mwifiex_private *priv);
1337
1304#ifdef CONFIG_DEBUG_FS 1338#ifdef CONFIG_DEBUG_FS
1305void mwifiex_debugfs_init(void); 1339void mwifiex_debugfs_init(void);
1306void mwifiex_debugfs_remove(void); 1340void mwifiex_debugfs_remove(void);
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index ca64d4c94112..3a17821157d7 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -1755,6 +1755,7 @@ static void mwifiex_complete_scan(struct mwifiex_private *priv)
1755{ 1755{
1756 struct mwifiex_adapter *adapter = priv->adapter; 1756 struct mwifiex_adapter *adapter = priv->adapter;
1757 1757
1758 adapter->survey_idx = 0;
1758 if (adapter->curr_cmd->wait_q_enabled) { 1759 if (adapter->curr_cmd->wait_q_enabled) {
1759 adapter->cmd_wait_q.status = 0; 1760 adapter->cmd_wait_q.status = 0;
1760 if (!priv->scan_request) { 1761 if (!priv->scan_request) {
@@ -1976,10 +1977,53 @@ int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
1976 return 0; 1977 return 0;
1977} 1978}
1978 1979
1980static void
1981mwifiex_update_chan_statistics(struct mwifiex_private *priv,
1982 struct mwifiex_ietypes_chanstats *tlv_stat)
1983{
1984 struct mwifiex_adapter *adapter = priv->adapter;
1985 u8 i, num_chan;
1986 struct mwifiex_fw_chan_stats *fw_chan_stats;
1987 struct mwifiex_chan_stats chan_stats;
1988
1989 fw_chan_stats = (void *)((u8 *)tlv_stat +
1990 sizeof(struct mwifiex_ie_types_header));
1991 num_chan = le16_to_cpu(tlv_stat->header.len) /
1992 sizeof(struct mwifiex_chan_stats);
1993
1994 for (i = 0 ; i < num_chan; i++) {
1995 chan_stats.chan_num = fw_chan_stats->chan_num;
1996 chan_stats.bandcfg = fw_chan_stats->bandcfg;
1997 chan_stats.flags = fw_chan_stats->flags;
1998 chan_stats.noise = fw_chan_stats->noise;
1999 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2000 chan_stats.cca_scan_dur =
2001 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2002 chan_stats.cca_busy_dur =
2003 le16_to_cpu(fw_chan_stats->cca_busy_dur);
2004 dev_dbg(adapter->dev,
2005 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2006 chan_stats.chan_num,
2007 chan_stats.noise,
2008 chan_stats.total_bss,
2009 chan_stats.cca_scan_dur,
2010 chan_stats.cca_busy_dur);
2011 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2012 sizeof(struct mwifiex_chan_stats));
2013 fw_chan_stats++;
2014 }
2015}
2016
1979/* This function handles the command response of extended scan */ 2017/* This function handles the command response of extended scan */
1980int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv) 2018int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2019 struct host_cmd_ds_command *resp)
1981{ 2020{
1982 struct mwifiex_adapter *adapter = priv->adapter; 2021 struct mwifiex_adapter *adapter = priv->adapter;
2022 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2023 struct mwifiex_ie_types_header *tlv;
2024 struct mwifiex_ietypes_chanstats *tlv_stat;
2025 u16 buf_left, type, len;
2026
1983 struct host_cmd_ds_command *cmd_ptr; 2027 struct host_cmd_ds_command *cmd_ptr;
1984 struct cmd_ctrl_node *cmd_node; 2028 struct cmd_ctrl_node *cmd_node;
1985 unsigned long cmd_flags, scan_flags; 2029 unsigned long cmd_flags, scan_flags;
@@ -1987,6 +2031,36 @@ int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv)
1987 2031
1988 dev_dbg(priv->adapter->dev, "info: EXT scan returns successfully\n"); 2032 dev_dbg(priv->adapter->dev, "info: EXT scan returns successfully\n");
1989 2033
2034 ext_scan_resp = &resp->params.ext_scan;
2035
2036 tlv = (void *)ext_scan_resp->tlv_buffer;
2037 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2038 - 1);
2039
2040 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2041 type = le16_to_cpu(tlv->type);
2042 len = le16_to_cpu(tlv->len);
2043
2044 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
2045 dev_err(adapter->dev,
2046 "error processing scan response TLVs");
2047 break;
2048 }
2049
2050 switch (type) {
2051 case TLV_TYPE_CHANNEL_STATS:
2052 tlv_stat = (void *)tlv;
2053 mwifiex_update_chan_statistics(priv, tlv_stat);
2054 break;
2055 default:
2056 break;
2057 }
2058
2059 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2060 tlv = (void *)((u8 *)tlv + len +
2061 sizeof(struct mwifiex_ie_types_header));
2062 }
2063
1990 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags); 2064 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
1991 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags); 2065 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
1992 if (list_empty(&adapter->scan_pending_q)) { 2066 if (list_empty(&adapter->scan_pending_q)) {
diff --git a/drivers/net/wireless/mwifiex/sdio.c b/drivers/net/wireless/mwifiex/sdio.c
index b25766b43b9f..933dae137850 100644
--- a/drivers/net/wireless/mwifiex/sdio.c
+++ b/drivers/net/wireless/mwifiex/sdio.c
@@ -106,6 +106,7 @@ mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
106 card->mp_tx_agg_buf_size = data->mp_tx_agg_buf_size; 106 card->mp_tx_agg_buf_size = data->mp_tx_agg_buf_size;
107 card->mp_rx_agg_buf_size = data->mp_rx_agg_buf_size; 107 card->mp_rx_agg_buf_size = data->mp_rx_agg_buf_size;
108 card->supports_fw_dump = data->supports_fw_dump; 108 card->supports_fw_dump = data->supports_fw_dump;
109 card->auto_tdls = data->auto_tdls;
109 } 110 }
110 111
111 sdio_claim_host(func); 112 sdio_claim_host(func);
@@ -1880,6 +1881,7 @@ static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
1880 return -1; 1881 return -1;
1881 } 1882 }
1882 1883
1884 adapter->auto_tdls = card->auto_tdls;
1883 return ret; 1885 return ret;
1884} 1886}
1885 1887
diff --git a/drivers/net/wireless/mwifiex/sdio.h b/drivers/net/wireless/mwifiex/sdio.h
index 20cd9adc98d3..54c07156dd78 100644
--- a/drivers/net/wireless/mwifiex/sdio.h
+++ b/drivers/net/wireless/mwifiex/sdio.h
@@ -246,6 +246,7 @@ struct sdio_mmc_card {
246 u8 curr_wr_port; 246 u8 curr_wr_port;
247 247
248 u8 *mp_regs; 248 u8 *mp_regs;
249 u8 auto_tdls;
249 250
250 struct mwifiex_sdio_mpa_tx mpa_tx; 251 struct mwifiex_sdio_mpa_tx mpa_tx;
251 struct mwifiex_sdio_mpa_rx mpa_rx; 252 struct mwifiex_sdio_mpa_rx mpa_rx;
@@ -262,6 +263,7 @@ struct mwifiex_sdio_device {
262 u16 tx_buf_size; 263 u16 tx_buf_size;
263 u32 mp_tx_agg_buf_size; 264 u32 mp_tx_agg_buf_size;
264 u32 mp_rx_agg_buf_size; 265 u32 mp_rx_agg_buf_size;
266 u8 auto_tdls;
265}; 267};
266 268
267static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx = { 269static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx = {
@@ -387,6 +389,7 @@ static const struct mwifiex_sdio_device mwifiex_sdio_sd8786 = {
387 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K, 389 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
388 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K, 390 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
389 .supports_fw_dump = false, 391 .supports_fw_dump = false,
392 .auto_tdls = false,
390}; 393};
391 394
392static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = { 395static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = {
@@ -400,6 +403,7 @@ static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = {
400 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K, 403 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
401 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K, 404 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
402 .supports_fw_dump = false, 405 .supports_fw_dump = false,
406 .auto_tdls = false,
403}; 407};
404 408
405static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = { 409static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = {
@@ -413,6 +417,7 @@ static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = {
413 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K, 417 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
414 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K, 418 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
415 .supports_fw_dump = false, 419 .supports_fw_dump = false,
420 .auto_tdls = false,
416}; 421};
417 422
418static const struct mwifiex_sdio_device mwifiex_sdio_sd8897 = { 423static const struct mwifiex_sdio_device mwifiex_sdio_sd8897 = {
@@ -426,6 +431,7 @@ static const struct mwifiex_sdio_device mwifiex_sdio_sd8897 = {
426 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K, 431 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K,
427 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K, 432 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K,
428 .supports_fw_dump = true, 433 .supports_fw_dump = true,
434 .auto_tdls = false,
429}; 435};
430 436
431static const struct mwifiex_sdio_device mwifiex_sdio_sd8887 = { 437static const struct mwifiex_sdio_device mwifiex_sdio_sd8887 = {
@@ -439,6 +445,7 @@ static const struct mwifiex_sdio_device mwifiex_sdio_sd8887 = {
439 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K, 445 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K,
440 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K, 446 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K,
441 .supports_fw_dump = false, 447 .supports_fw_dump = false,
448 .auto_tdls = true,
442}; 449};
443 450
444/* 451/*
diff --git a/drivers/net/wireless/mwifiex/sta_cmdresp.c b/drivers/net/wireless/mwifiex/sta_cmdresp.c
index 4aad44685f8d..b65e1014b0fc 100644
--- a/drivers/net/wireless/mwifiex/sta_cmdresp.c
+++ b/drivers/net/wireless/mwifiex/sta_cmdresp.c
@@ -983,7 +983,7 @@ int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
983 adapter->curr_cmd->wait_q_enabled = false; 983 adapter->curr_cmd->wait_q_enabled = false;
984 break; 984 break;
985 case HostCmd_CMD_802_11_SCAN_EXT: 985 case HostCmd_CMD_802_11_SCAN_EXT:
986 ret = mwifiex_ret_802_11_scan_ext(priv); 986 ret = mwifiex_ret_802_11_scan_ext(priv, resp);
987 adapter->curr_cmd->wait_q_enabled = false; 987 adapter->curr_cmd->wait_q_enabled = false;
988 break; 988 break;
989 case HostCmd_CMD_802_11_BG_SCAN_QUERY: 989 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
diff --git a/drivers/net/wireless/mwifiex/sta_event.c b/drivers/net/wireless/mwifiex/sta_event.c
index f1c240eca0cd..204ecc8faa5b 100644
--- a/drivers/net/wireless/mwifiex/sta_event.c
+++ b/drivers/net/wireless/mwifiex/sta_event.c
@@ -55,9 +55,13 @@ mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason_code)
55 priv->scan_block = false; 55 priv->scan_block = false;
56 56
57 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && 57 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
58 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) 58 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) {
59 mwifiex_disable_all_tdls_links(priv); 59 mwifiex_disable_all_tdls_links(priv);
60 60
61 if (priv->adapter->auto_tdls)
62 mwifiex_clean_auto_tdls(priv);
63 }
64
61 /* Free Tx and Rx packets, report disconnect to upper layer */ 65 /* Free Tx and Rx packets, report disconnect to upper layer */
62 mwifiex_clean_txrx(priv); 66 mwifiex_clean_txrx(priv);
63 67
@@ -163,9 +167,6 @@ static int mwifiex_parse_tdls_event(struct mwifiex_private *priv,
163 NL80211_TDLS_TEARDOWN, 167 NL80211_TDLS_TEARDOWN,
164 le16_to_cpu(tdls_evt->u.reason_code), 168 le16_to_cpu(tdls_evt->u.reason_code),
165 GFP_KERNEL); 169 GFP_KERNEL);
166 ret = mwifiex_tdls_oper(priv, tdls_evt->peer_mac,
167 MWIFIEX_TDLS_DISABLE_LINK);
168 queue_work(adapter->workqueue, &adapter->main_work);
169 break; 170 break;
170 default: 171 default:
171 break; 172 break;
diff --git a/drivers/net/wireless/mwifiex/sta_ioctl.c b/drivers/net/wireless/mwifiex/sta_ioctl.c
index 92f3eb839866..1626868a4b5c 100644
--- a/drivers/net/wireless/mwifiex/sta_ioctl.c
+++ b/drivers/net/wireless/mwifiex/sta_ioctl.c
@@ -1026,12 +1026,12 @@ mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1026 int max_len) 1026 int max_len)
1027{ 1027{
1028 union { 1028 union {
1029 u32 l; 1029 __le32 l;
1030 u8 c[4]; 1030 u8 c[4];
1031 } ver; 1031 } ver;
1032 char fw_ver[32]; 1032 char fw_ver[32];
1033 1033
1034 ver.l = adapter->fw_release_number; 1034 ver.l = cpu_to_le32(adapter->fw_release_number);
1035 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]); 1035 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1036 1036
1037 snprintf(version, max_len, driver_version, fw_ver); 1037 snprintf(version, max_len, driver_version, fw_ver);
diff --git a/drivers/net/wireless/mwifiex/sta_rx.c b/drivers/net/wireless/mwifiex/sta_rx.c
index 9ceb1dbe34c5..c2ad3b63ae70 100644
--- a/drivers/net/wireless/mwifiex/sta_rx.c
+++ b/drivers/net/wireless/mwifiex/sta_rx.c
@@ -232,6 +232,9 @@ int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv,
232 if (sta_ptr) 232 if (sta_ptr)
233 sta_ptr->rx_seq[local_rx_pd->priority] = 233 sta_ptr->rx_seq[local_rx_pd->priority] =
234 le16_to_cpu(local_rx_pd->seq_num); 234 le16_to_cpu(local_rx_pd->seq_num);
235 mwifiex_auto_tdls_update_peer_signal(priv, ta,
236 local_rx_pd->snr,
237 local_rx_pd->nf);
235 } 238 }
236 } else { 239 } else {
237 if (rx_pkt_type != PKT_TYPE_BAR) 240 if (rx_pkt_type != PKT_TYPE_BAR)
diff --git a/drivers/net/wireless/mwifiex/tdls.c b/drivers/net/wireless/mwifiex/tdls.c
index e2949077f5b5..22884b429be7 100644
--- a/drivers/net/wireless/mwifiex/tdls.c
+++ b/drivers/net/wireless/mwifiex/tdls.c
@@ -24,6 +24,7 @@
24#define TDLS_REQ_FIX_LEN 6 24#define TDLS_REQ_FIX_LEN 6
25#define TDLS_RESP_FIX_LEN 8 25#define TDLS_RESP_FIX_LEN 8
26#define TDLS_CONFIRM_FIX_LEN 6 26#define TDLS_CONFIRM_FIX_LEN 6
27#define MWIFIEX_TDLS_WMM_INFO_SIZE 7
27 28
28static void mwifiex_restore_tdls_packets(struct mwifiex_private *priv, 29static void mwifiex_restore_tdls_packets(struct mwifiex_private *priv,
29 const u8 *mac, u8 status) 30 const u8 *mac, u8 status)
@@ -367,6 +368,55 @@ static void mwifiex_tdls_add_qos_capab(struct sk_buff *skb)
367 *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB; 368 *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB;
368} 369}
369 370
371static void
372mwifiex_tdls_add_wmm_param_ie(struct mwifiex_private *priv, struct sk_buff *skb)
373{
374 struct ieee80211_wmm_param_ie *wmm;
375 u8 ac_vi[] = {0x42, 0x43, 0x5e, 0x00};
376 u8 ac_vo[] = {0x62, 0x32, 0x2f, 0x00};
377 u8 ac_be[] = {0x03, 0xa4, 0x00, 0x00};
378 u8 ac_bk[] = {0x27, 0xa4, 0x00, 0x00};
379
380 wmm = (void *)skb_put(skb, sizeof(*wmm));
381 memset(wmm, 0, sizeof(*wmm));
382
383 wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
384 wmm->len = sizeof(*wmm) - 2;
385 wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
386 wmm->oui[1] = 0x50;
387 wmm->oui[2] = 0xf2;
388 wmm->oui_type = 2; /* WME */
389 wmm->oui_subtype = 1; /* WME param */
390 wmm->version = 1; /* WME ver */
391 wmm->qos_info = 0; /* U-APSD not in use */
392
393 /* use default WMM AC parameters for TDLS link*/
394 memcpy(&wmm->ac[0], ac_be, sizeof(ac_be));
395 memcpy(&wmm->ac[1], ac_bk, sizeof(ac_bk));
396 memcpy(&wmm->ac[2], ac_vi, sizeof(ac_vi));
397 memcpy(&wmm->ac[3], ac_vo, sizeof(ac_vo));
398}
399
400static void
401mwifiex_add_wmm_info_ie(struct mwifiex_private *priv, struct sk_buff *skb,
402 u8 qosinfo)
403{
404 u8 *buf;
405
406 buf = (void *)skb_put(skb, MWIFIEX_TDLS_WMM_INFO_SIZE +
407 sizeof(struct ieee_types_header));
408
409 *buf++ = WLAN_EID_VENDOR_SPECIFIC;
410 *buf++ = 7; /* len */
411 *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
412 *buf++ = 0x50;
413 *buf++ = 0xf2;
414 *buf++ = 2; /* WME */
415 *buf++ = 0; /* WME info */
416 *buf++ = 1; /* WME ver */
417 *buf++ = qosinfo; /* U-APSD no in use */
418}
419
370static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv, 420static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
371 const u8 *peer, u8 action_code, 421 const u8 *peer, u8 action_code,
372 u8 dialog_token, 422 u8 dialog_token,
@@ -421,6 +471,7 @@ static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
421 471
422 mwifiex_tdls_add_ext_capab(priv, skb); 472 mwifiex_tdls_add_ext_capab(priv, skb);
423 mwifiex_tdls_add_qos_capab(skb); 473 mwifiex_tdls_add_qos_capab(skb);
474 mwifiex_add_wmm_info_ie(priv, skb, 0);
424 break; 475 break;
425 476
426 case WLAN_TDLS_SETUP_RESPONSE: 477 case WLAN_TDLS_SETUP_RESPONSE:
@@ -458,6 +509,7 @@ static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
458 509
459 mwifiex_tdls_add_ext_capab(priv, skb); 510 mwifiex_tdls_add_ext_capab(priv, skb);
460 mwifiex_tdls_add_qos_capab(skb); 511 mwifiex_tdls_add_qos_capab(skb);
512 mwifiex_add_wmm_info_ie(priv, skb, 0);
461 break; 513 break;
462 514
463 case WLAN_TDLS_SETUP_CONFIRM: 515 case WLAN_TDLS_SETUP_CONFIRM:
@@ -466,6 +518,8 @@ static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
466 skb_put(skb, sizeof(tf->u.setup_cfm)); 518 skb_put(skb, sizeof(tf->u.setup_cfm));
467 tf->u.setup_cfm.status_code = cpu_to_le16(status_code); 519 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
468 tf->u.setup_cfm.dialog_token = dialog_token; 520 tf->u.setup_cfm.dialog_token = dialog_token;
521
522 mwifiex_tdls_add_wmm_param_ie(priv, skb);
469 if (priv->adapter->is_hw_11ac_capable) { 523 if (priv->adapter->is_hw_11ac_capable) {
470 ret = mwifiex_tdls_add_vht_oper(priv, peer, skb); 524 ret = mwifiex_tdls_add_vht_oper(priv, peer, skb);
471 if (ret) { 525 if (ret) {
@@ -544,6 +598,7 @@ int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
544 sizeof(struct ieee_types_bss_co_2040) + 598 sizeof(struct ieee_types_bss_co_2040) +
545 sizeof(struct ieee80211_ht_operation) + 599 sizeof(struct ieee80211_ht_operation) +
546 sizeof(struct ieee80211_tdls_lnkie) + 600 sizeof(struct ieee80211_tdls_lnkie) +
601 sizeof(struct ieee80211_wmm_param_ie) +
547 extra_ies_len; 602 extra_ies_len;
548 603
549 if (priv->adapter->is_hw_11ac_capable) 604 if (priv->adapter->is_hw_11ac_capable)
@@ -973,6 +1028,7 @@ mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
973 } 1028 }
974 1029
975 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN); 1030 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1031 mwifiex_auto_tdls_update_peer_status(priv, peer, TDLS_NOT_SETUP);
976 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN); 1032 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
977 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK; 1033 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
978 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER, 1034 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
@@ -1017,6 +1073,8 @@ mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
1017 1073
1018 memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq)); 1074 memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
1019 mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE); 1075 mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
1076 mwifiex_auto_tdls_update_peer_status(priv, peer,
1077 TDLS_SETUP_COMPLETE);
1020 } else { 1078 } else {
1021 dev_dbg(priv->adapter->dev, 1079 dev_dbg(priv->adapter->dev,
1022 "tdls: enable link %pM failed\n", peer); 1080 "tdls: enable link %pM failed\n", peer);
@@ -1030,6 +1088,8 @@ mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
1030 mwifiex_del_sta_entry(priv, peer); 1088 mwifiex_del_sta_entry(priv, peer);
1031 } 1089 }
1032 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN); 1090 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1091 mwifiex_auto_tdls_update_peer_status(priv, peer,
1092 TDLS_NOT_SETUP);
1033 1093
1034 return -1; 1094 return -1;
1035 } 1095 }
@@ -1097,3 +1157,231 @@ void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
1097 1157
1098 mwifiex_del_all_sta_list(priv); 1158 mwifiex_del_all_sta_list(priv);
1099} 1159}
1160
1161int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb)
1162{
1163 struct mwifiex_auto_tdls_peer *peer;
1164 unsigned long flags;
1165 u8 mac[ETH_ALEN];
1166
1167 ether_addr_copy(mac, skb->data);
1168
1169 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1170 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1171 if (!memcmp(mac, peer->mac_addr, ETH_ALEN)) {
1172 if (peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
1173 peer->tdls_status == TDLS_NOT_SETUP &&
1174 (peer->failure_count <
1175 MWIFIEX_TDLS_MAX_FAIL_COUNT)) {
1176 peer->tdls_status = TDLS_SETUP_INPROGRESS;
1177 dev_dbg(priv->adapter->dev,
1178 "setup TDLS link, peer=%pM rssi=%d\n",
1179 peer->mac_addr, peer->rssi);
1180
1181 cfg80211_tdls_oper_request(priv->netdev,
1182 peer->mac_addr,
1183 NL80211_TDLS_SETUP,
1184 0, GFP_ATOMIC);
1185 peer->do_setup = false;
1186 priv->check_tdls_tx = false;
1187 } else if (peer->failure_count <
1188 MWIFIEX_TDLS_MAX_FAIL_COUNT &&
1189 peer->do_discover) {
1190 mwifiex_send_tdls_data_frame(priv,
1191 peer->mac_addr,
1192 WLAN_TDLS_DISCOVERY_REQUEST,
1193 1, 0, NULL, 0);
1194 peer->do_discover = false;
1195 }
1196 }
1197 }
1198 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1199
1200 return 0;
1201}
1202
1203void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv)
1204{
1205 struct mwifiex_auto_tdls_peer *peer, *tmp_node;
1206 unsigned long flags;
1207
1208 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1209 list_for_each_entry_safe(peer, tmp_node, &priv->auto_tdls_list, list) {
1210 list_del(&peer->list);
1211 kfree(peer);
1212 }
1213
1214 INIT_LIST_HEAD(&priv->auto_tdls_list);
1215 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1216 priv->check_tdls_tx = false;
1217}
1218
1219void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac)
1220{
1221 struct mwifiex_auto_tdls_peer *tdls_peer;
1222 unsigned long flags;
1223
1224 if (!priv->adapter->auto_tdls)
1225 return;
1226
1227 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1228 list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
1229 if (!memcmp(tdls_peer->mac_addr, mac, ETH_ALEN)) {
1230 tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
1231 tdls_peer->rssi_jiffies = jiffies;
1232 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1233 return;
1234 }
1235 }
1236
1237 /* create new TDLS peer */
1238 tdls_peer = kzalloc(sizeof(*tdls_peer), GFP_ATOMIC);
1239 if (tdls_peer) {
1240 ether_addr_copy(tdls_peer->mac_addr, mac);
1241 tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
1242 tdls_peer->rssi_jiffies = jiffies;
1243 INIT_LIST_HEAD(&tdls_peer->list);
1244 list_add_tail(&tdls_peer->list, &priv->auto_tdls_list);
1245 dev_dbg(priv->adapter->dev, "Add auto TDLS peer= %pM to list\n",
1246 mac);
1247 }
1248
1249 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1250}
1251
1252void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
1253 const u8 *mac, u8 link_status)
1254{
1255 struct mwifiex_auto_tdls_peer *peer;
1256 unsigned long flags;
1257
1258 if (!priv->adapter->auto_tdls)
1259 return;
1260
1261 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1262 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1263 if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
1264 if ((link_status == TDLS_NOT_SETUP) &&
1265 (peer->tdls_status == TDLS_SETUP_INPROGRESS))
1266 peer->failure_count++;
1267 else if (link_status == TDLS_SETUP_COMPLETE)
1268 peer->failure_count = 0;
1269
1270 peer->tdls_status = link_status;
1271 break;
1272 }
1273 }
1274 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1275}
1276
1277void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
1278 u8 *mac, s8 snr, s8 nflr)
1279{
1280 struct mwifiex_auto_tdls_peer *peer;
1281 unsigned long flags;
1282
1283 if (!priv->adapter->auto_tdls)
1284 return;
1285
1286 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1287 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1288 if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
1289 peer->rssi = nflr - snr;
1290 peer->rssi_jiffies = jiffies;
1291 break;
1292 }
1293 }
1294 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1295}
1296
1297void mwifiex_check_auto_tdls(unsigned long context)
1298{
1299 struct mwifiex_private *priv = (struct mwifiex_private *)context;
1300 struct mwifiex_auto_tdls_peer *tdls_peer;
1301 unsigned long flags;
1302 u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
1303
1304 if (WARN_ON_ONCE(!priv || !priv->adapter)) {
1305 pr_err("mwifiex: %s: adapter or private structure is NULL\n",
1306 __func__);
1307 return;
1308 }
1309
1310 if (unlikely(!priv->adapter->auto_tdls))
1311 return;
1312
1313 if (!priv->auto_tdls_timer_active) {
1314 dev_dbg(priv->adapter->dev,
1315 "auto TDLS timer inactive; return");
1316 return;
1317 }
1318
1319 priv->check_tdls_tx = false;
1320
1321 if (list_empty(&priv->auto_tdls_list)) {
1322 mod_timer(&priv->auto_tdls_timer,
1323 jiffies +
1324 msecs_to_jiffies(MWIFIEX_TIMER_10S));
1325 return;
1326 }
1327
1328 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1329 list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
1330 if ((jiffies - tdls_peer->rssi_jiffies) >
1331 (MWIFIEX_AUTO_TDLS_IDLE_TIME * HZ)) {
1332 tdls_peer->rssi = 0;
1333 tdls_peer->do_discover = true;
1334 priv->check_tdls_tx = true;
1335 }
1336
1337 if (((tdls_peer->rssi >= MWIFIEX_TDLS_RSSI_LOW) ||
1338 !tdls_peer->rssi) &&
1339 tdls_peer->tdls_status == TDLS_SETUP_COMPLETE) {
1340 tdls_peer->tdls_status = TDLS_LINK_TEARDOWN;
1341 dev_dbg(priv->adapter->dev,
1342 "teardown TDLS link,peer=%pM rssi=%d\n",
1343 tdls_peer->mac_addr, -tdls_peer->rssi);
1344 tdls_peer->do_discover = true;
1345 priv->check_tdls_tx = true;
1346 cfg80211_tdls_oper_request(priv->netdev,
1347 tdls_peer->mac_addr,
1348 NL80211_TDLS_TEARDOWN,
1349 reason, GFP_ATOMIC);
1350 } else if (tdls_peer->rssi &&
1351 tdls_peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
1352 tdls_peer->tdls_status == TDLS_NOT_SETUP &&
1353 tdls_peer->failure_count <
1354 MWIFIEX_TDLS_MAX_FAIL_COUNT) {
1355 priv->check_tdls_tx = true;
1356 tdls_peer->do_setup = true;
1357 dev_dbg(priv->adapter->dev,
1358 "check TDLS with peer=%pM rssi=%d\n",
1359 tdls_peer->mac_addr, -tdls_peer->rssi);
1360 }
1361 }
1362 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1363
1364 mod_timer(&priv->auto_tdls_timer,
1365 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
1366}
1367
1368void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv)
1369{
1370 init_timer(&priv->auto_tdls_timer);
1371 priv->auto_tdls_timer.function = mwifiex_check_auto_tdls;
1372 priv->auto_tdls_timer.data = (unsigned long)priv;
1373 priv->auto_tdls_timer_active = true;
1374 mod_timer(&priv->auto_tdls_timer,
1375 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
1376}
1377
1378void mwifiex_clean_auto_tdls(struct mwifiex_private *priv)
1379{
1380 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
1381 priv->adapter->auto_tdls &&
1382 priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1383 priv->auto_tdls_timer_active = false;
1384 del_timer(&priv->auto_tdls_timer);
1385 mwifiex_flush_auto_tdls_list(priv);
1386 }
1387}
diff --git a/drivers/net/wireless/mwifiex/txrx.c b/drivers/net/wireless/mwifiex/txrx.c
index 96a2126cc44b..a5983fc4e83a 100644
--- a/drivers/net/wireless/mwifiex/txrx.c
+++ b/drivers/net/wireless/mwifiex/txrx.c
@@ -64,10 +64,6 @@ int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
64 else 64 else
65 ret = mwifiex_process_sta_rx_packet(priv, skb); 65 ret = mwifiex_process_sta_rx_packet(priv, skb);
66 66
67 /* Decrement RX pending counter for each packet */
68 if (adapter->if_ops.data_complete)
69 adapter->if_ops.data_complete(adapter);
70
71 return ret; 67 return ret;
72} 68}
73EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet); 69EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
diff --git a/drivers/net/wireless/mwifiex/uap_cmd.c b/drivers/net/wireless/mwifiex/uap_cmd.c
index 300bab438011..0f347fdefa0a 100644
--- a/drivers/net/wireless/mwifiex/uap_cmd.c
+++ b/drivers/net/wireless/mwifiex/uap_cmd.c
@@ -167,7 +167,7 @@ mwifiex_set_ht_params(struct mwifiex_private *priv,
167 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail, 167 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
168 params->beacon.tail_len); 168 params->beacon.tail_len);
169 if (ht_ie) { 169 if (ht_ie) {
170 memcpy(&bss_cfg->ht_cap, ht_ie + 2, 170 memcpy(&bss_cfg->ht_cap, ht_ie,
171 sizeof(struct ieee80211_ht_cap)); 171 sizeof(struct ieee80211_ht_cap));
172 cap_info = le16_to_cpu(bss_cfg->ht_cap.cap_info); 172 cap_info = le16_to_cpu(bss_cfg->ht_cap.cap_info);
173 memset(&bss_cfg->ht_cap.mcs, 0, 173 memset(&bss_cfg->ht_cap.mcs, 0,
diff --git a/drivers/net/wireless/mwifiex/usb.c b/drivers/net/wireless/mwifiex/usb.c
index 4371e12b36f3..6cc8519c0f40 100644
--- a/drivers/net/wireless/mwifiex/usb.c
+++ b/drivers/net/wireless/mwifiex/usb.c
@@ -125,8 +125,10 @@ static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
125 dev_err(dev, "DATA: skb->len too large\n"); 125 dev_err(dev, "DATA: skb->len too large\n");
126 return -1; 126 return -1;
127 } 127 }
128 skb_queue_tail(&adapter->usb_rx_data_q, skb); 128
129 skb_queue_tail(&adapter->rx_data_q, skb);
129 adapter->data_received = true; 130 adapter->data_received = true;
131 atomic_inc(&adapter->rx_pending);
130 break; 132 break;
131 default: 133 default:
132 dev_err(dev, "%s: unknown endport %#x\n", __func__, ep); 134 dev_err(dev, "%s: unknown endport %#x\n", __func__, ep);
@@ -176,7 +178,6 @@ static void mwifiex_usb_rx_complete(struct urb *urb)
176 else 178 else
177 skb_put(skb, recv_length - skb->len); 179 skb_put(skb, recv_length - skb->len);
178 180
179 atomic_inc(&adapter->rx_pending);
180 status = mwifiex_usb_recv(adapter, skb, context->ep); 181 status = mwifiex_usb_recv(adapter, skb, context->ep);
181 182
182 dev_dbg(adapter->dev, "info: recv_length=%d, status=%d\n", 183 dev_dbg(adapter->dev, "info: recv_length=%d, status=%d\n",
@@ -191,7 +192,6 @@ static void mwifiex_usb_rx_complete(struct urb *urb)
191 if (card->rx_cmd_ep == context->ep) 192 if (card->rx_cmd_ep == context->ep)
192 return; 193 return;
193 } else { 194 } else {
194 atomic_dec(&adapter->rx_pending);
195 if (status == -1) 195 if (status == -1)
196 dev_err(adapter->dev, 196 dev_err(adapter->dev,
197 "received data processing failed!\n"); 197 "received data processing failed!\n");
@@ -222,7 +222,13 @@ setup_for_next:
222 else 222 else
223 size = MWIFIEX_RX_DATA_BUF_SIZE; 223 size = MWIFIEX_RX_DATA_BUF_SIZE;
224 224
225 mwifiex_usb_submit_rx_urb(context, size); 225 if (card->rx_cmd_ep == context->ep) {
226 mwifiex_usb_submit_rx_urb(context, size);
227 } else {
228 context->skb = NULL;
229 if (atomic_read(&adapter->rx_pending) <= HIGH_RX_PENDING)
230 mwifiex_usb_submit_rx_urb(context, size);
231 }
226 232
227 return; 233 return;
228} 234}
@@ -962,19 +968,11 @@ static void mwifiex_submit_rx_urb(struct mwifiex_adapter *adapter, u8 ep)
962static int mwifiex_usb_cmd_event_complete(struct mwifiex_adapter *adapter, 968static int mwifiex_usb_cmd_event_complete(struct mwifiex_adapter *adapter,
963 struct sk_buff *skb) 969 struct sk_buff *skb)
964{ 970{
965 atomic_dec(&adapter->rx_pending);
966 mwifiex_submit_rx_urb(adapter, MWIFIEX_USB_EP_CMD_EVENT); 971 mwifiex_submit_rx_urb(adapter, MWIFIEX_USB_EP_CMD_EVENT);
967 972
968 return 0; 973 return 0;
969} 974}
970 975
971static int mwifiex_usb_data_complete(struct mwifiex_adapter *adapter)
972{
973 atomic_dec(&adapter->rx_pending);
974
975 return 0;
976}
977
978/* This function wakes up the card. */ 976/* This function wakes up the card. */
979static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter) 977static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
980{ 978{
@@ -986,6 +984,20 @@ static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
986 return 0; 984 return 0;
987} 985}
988 986
987static void mwifiex_usb_submit_rem_rx_urbs(struct mwifiex_adapter *adapter)
988{
989 struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
990 int i;
991 struct urb_context *ctx;
992
993 for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
994 if (card->rx_data_list[i].skb)
995 continue;
996 ctx = &card->rx_data_list[i];
997 mwifiex_usb_submit_rx_urb(ctx, MWIFIEX_RX_DATA_BUF_SIZE);
998 }
999}
1000
989static struct mwifiex_if_ops usb_ops = { 1001static struct mwifiex_if_ops usb_ops = {
990 .register_dev = mwifiex_register_dev, 1002 .register_dev = mwifiex_register_dev,
991 .unregister_dev = mwifiex_unregister_dev, 1003 .unregister_dev = mwifiex_unregister_dev,
@@ -996,8 +1008,8 @@ static struct mwifiex_if_ops usb_ops = {
996 .dnld_fw = mwifiex_usb_dnld_fw, 1008 .dnld_fw = mwifiex_usb_dnld_fw,
997 .cmdrsp_complete = mwifiex_usb_cmd_event_complete, 1009 .cmdrsp_complete = mwifiex_usb_cmd_event_complete,
998 .event_complete = mwifiex_usb_cmd_event_complete, 1010 .event_complete = mwifiex_usb_cmd_event_complete,
999 .data_complete = mwifiex_usb_data_complete,
1000 .host_to_card = mwifiex_usb_host_to_card, 1011 .host_to_card = mwifiex_usb_host_to_card,
1012 .submit_rem_rx_urbs = mwifiex_usb_submit_rem_rx_urbs,
1001}; 1013};
1002 1014
1003/* This function initializes the USB driver module. 1015/* This function initializes the USB driver module.
diff --git a/drivers/net/wireless/mwifiex/util.c b/drivers/net/wireless/mwifiex/util.c
index ec79c49de097..a113ef8f0b8b 100644
--- a/drivers/net/wireless/mwifiex/util.c
+++ b/drivers/net/wireless/mwifiex/util.c
@@ -141,6 +141,38 @@ int mwifiex_get_debug_info(struct mwifiex_private *priv,
141 return 0; 141 return 0;
142} 142}
143 143
144static int
145mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,
146 struct rxpd *rx_pd)
147{
148 u16 stype;
149 u8 category, action_code;
150 struct ieee80211_hdr *ieee_hdr = (void *)payload;
151
152 stype = (cpu_to_le16(ieee_hdr->frame_control) & IEEE80211_FCTL_STYPE);
153
154 switch (stype) {
155 case IEEE80211_STYPE_ACTION:
156 category = *(payload + sizeof(struct ieee80211_hdr));
157 action_code = *(payload + sizeof(struct ieee80211_hdr) + 1);
158 if (category == WLAN_CATEGORY_PUBLIC &&
159 action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) {
160 dev_dbg(priv->adapter->dev,
161 "TDLS discovery response %pM nf=%d, snr=%d\n",
162 ieee_hdr->addr2, rx_pd->nf, rx_pd->snr);
163 mwifiex_auto_tdls_update_peer_signal(priv,
164 ieee_hdr->addr2,
165 rx_pd->snr,
166 rx_pd->nf);
167 }
168 break;
169 default:
170 dev_dbg(priv->adapter->dev,
171 "unknown mgmt frame subytpe %#x\n", stype);
172 }
173
174 return 0;
175}
144/* 176/*
145 * This function processes the received management packet and send it 177 * This function processes the received management packet and send it
146 * to the kernel. 178 * to the kernel.
@@ -151,6 +183,7 @@ mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
151{ 183{
152 struct rxpd *rx_pd; 184 struct rxpd *rx_pd;
153 u16 pkt_len; 185 u16 pkt_len;
186 struct ieee80211_hdr *ieee_hdr;
154 187
155 if (!skb) 188 if (!skb)
156 return -1; 189 return -1;
@@ -162,6 +195,11 @@ mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
162 195
163 pkt_len = le16_to_cpu(rx_pd->rx_pkt_length); 196 pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
164 197
198 ieee_hdr = (void *)skb->data;
199 if (ieee80211_is_mgmt(ieee_hdr->frame_control)) {
200 mwifiex_parse_mgmt_packet(priv, (u8 *)ieee_hdr,
201 pkt_len, rx_pd);
202 }
165 /* Remove address4 */ 203 /* Remove address4 */
166 memmove(skb->data + sizeof(struct ieee80211_hdr_3addr), 204 memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
167 skb->data + sizeof(struct ieee80211_hdr), 205 skb->data + sizeof(struct ieee80211_hdr),
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index d849d590de25..c878e3f3993c 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -62,7 +62,7 @@ static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
62 __le16 reg; 62 __le16 reg;
63 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, 63 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
64 USB_VENDOR_REQUEST_IN, offset, 64 USB_VENDOR_REQUEST_IN, offset,
65 &reg, sizeof(reg), REGISTER_TIMEOUT); 65 &reg, sizeof(reg));
66 *value = le16_to_cpu(reg); 66 *value = le16_to_cpu(reg);
67} 67}
68 68
@@ -83,8 +83,7 @@ static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
83{ 83{
84 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, 84 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
85 USB_VENDOR_REQUEST_IN, offset, 85 USB_VENDOR_REQUEST_IN, offset,
86 value, length, 86 value, length);
87 REGISTER_TIMEOUT16(length));
88} 87}
89 88
90static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev, 89static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
@@ -94,7 +93,7 @@ static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
94 __le16 reg = cpu_to_le16(value); 93 __le16 reg = cpu_to_le16(value);
95 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 94 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
96 USB_VENDOR_REQUEST_OUT, offset, 95 USB_VENDOR_REQUEST_OUT, offset,
97 &reg, sizeof(reg), REGISTER_TIMEOUT); 96 &reg, sizeof(reg));
98} 97}
99 98
100static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev, 99static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
@@ -113,8 +112,7 @@ static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
113{ 112{
114 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 113 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
115 USB_VENDOR_REQUEST_OUT, offset, 114 USB_VENDOR_REQUEST_OUT, offset,
116 value, length, 115 value, length);
117 REGISTER_TIMEOUT16(length));
118} 116}
119 117
120static int rt2500usb_regbusy_read(struct rt2x00_dev *rt2x00dev, 118static int rt2500usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 86c43d112a4b..dc85d3e0ffe5 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -116,7 +116,7 @@ EXPORT_SYMBOL_GPL(rt2x00usb_vendor_req_buff_lock);
116int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev, 116int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
117 const u8 request, const u8 requesttype, 117 const u8 request, const u8 requesttype,
118 const u16 offset, void *buffer, 118 const u16 offset, void *buffer,
119 const u16 buffer_length, const int timeout) 119 const u16 buffer_length)
120{ 120{
121 int status = 0; 121 int status = 0;
122 unsigned char *tb; 122 unsigned char *tb;
@@ -131,7 +131,7 @@ int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
131 bsize = min_t(u16, CSR_CACHE_SIZE, len); 131 bsize = min_t(u16, CSR_CACHE_SIZE, len);
132 status = rt2x00usb_vendor_req_buff_lock(rt2x00dev, request, 132 status = rt2x00usb_vendor_req_buff_lock(rt2x00dev, request,
133 requesttype, off, tb, 133 requesttype, off, tb,
134 bsize, timeout); 134 bsize, REGISTER_TIMEOUT);
135 135
136 tb += bsize; 136 tb += bsize;
137 len -= bsize; 137 len -= bsize;
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.h b/drivers/net/wireless/rt2x00/rt2x00usb.h
index 831b65f93feb..819690e978c0 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.h
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.h
@@ -33,27 +33,14 @@
33}) 33})
34 34
35/* 35/*
36 * For USB vendor requests we need to pass a timeout 36 * For USB vendor requests we need to pass a timeout time in ms, for this we
37 * time in ms, for this we use the REGISTER_TIMEOUT, 37 * use the REGISTER_TIMEOUT, however when loading firmware or read EEPROM
38 * however when loading firmware a higher value is 38 * a higher value is required. In that case we use the REGISTER_TIMEOUT_FIRMWARE
39 * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE. 39 * and EEPROM_TIMEOUT.
40 */ 40 */
41#define REGISTER_TIMEOUT 500 41#define REGISTER_TIMEOUT 500
42#define REGISTER_TIMEOUT_FIRMWARE 1000 42#define REGISTER_TIMEOUT_FIRMWARE 1000
43 43#define EEPROM_TIMEOUT 2000
44/**
45 * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access
46 * @__datalen: Data length
47 */
48#define REGISTER_TIMEOUT16(__datalen) \
49 ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) )
50
51/**
52 * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access
53 * @__datalen: Data length
54 */
55#define REGISTER_TIMEOUT32(__datalen) \
56 ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) )
57 44
58/* 45/*
59 * Cache size 46 * Cache size
@@ -126,7 +113,6 @@ int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
126 * @offset: Register offset to perform action on 113 * @offset: Register offset to perform action on
127 * @buffer: Buffer where information will be read/written to by device 114 * @buffer: Buffer where information will be read/written to by device
128 * @buffer_length: Size of &buffer 115 * @buffer_length: Size of &buffer
129 * @timeout: Operation timeout
130 * 116 *
131 * This function will use a previously with kmalloc allocated cache 117 * This function will use a previously with kmalloc allocated cache
132 * to communicate with the device. The contents of the buffer pointer 118 * to communicate with the device. The contents of the buffer pointer
@@ -139,7 +125,7 @@ int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
139int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev, 125int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
140 const u8 request, const u8 requesttype, 126 const u8 request, const u8 requesttype,
141 const u16 offset, void *buffer, 127 const u16 offset, void *buffer,
142 const u16 buffer_length, const int timeout); 128 const u16 buffer_length);
143 129
144/** 130/**
145 * rt2x00usb_vendor_request_buff - Send register command to device (buffered) 131 * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
@@ -197,8 +183,7 @@ static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
197{ 183{
198 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ, 184 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
199 USB_VENDOR_REQUEST_IN, 0, 0, 185 USB_VENDOR_REQUEST_IN, 0, 0,
200 eeprom, length, 186 eeprom, length, EEPROM_TIMEOUT);
201 REGISTER_TIMEOUT16(length));
202} 187}
203 188
204/** 189/**
@@ -217,7 +202,7 @@ static inline void rt2x00usb_register_read(struct rt2x00_dev *rt2x00dev,
217 __le32 reg; 202 __le32 reg;
218 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, 203 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
219 USB_VENDOR_REQUEST_IN, offset, 204 USB_VENDOR_REQUEST_IN, offset,
220 &reg, sizeof(reg), REGISTER_TIMEOUT); 205 &reg, sizeof(reg));
221 *value = le32_to_cpu(reg); 206 *value = le32_to_cpu(reg);
222} 207}
223 208
@@ -257,8 +242,7 @@ static inline void rt2x00usb_register_multiread(struct rt2x00_dev *rt2x00dev,
257{ 242{
258 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, 243 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
259 USB_VENDOR_REQUEST_IN, offset, 244 USB_VENDOR_REQUEST_IN, offset,
260 value, length, 245 value, length);
261 REGISTER_TIMEOUT32(length));
262} 246}
263 247
264/** 248/**
@@ -277,7 +261,7 @@ static inline void rt2x00usb_register_write(struct rt2x00_dev *rt2x00dev,
277 __le32 reg = cpu_to_le32(value); 261 __le32 reg = cpu_to_le32(value);
278 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 262 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
279 USB_VENDOR_REQUEST_OUT, offset, 263 USB_VENDOR_REQUEST_OUT, offset,
280 &reg, sizeof(reg), REGISTER_TIMEOUT); 264 &reg, sizeof(reg));
281} 265}
282 266
283/** 267/**
@@ -316,8 +300,7 @@ static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
316{ 300{
317 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 301 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
318 USB_VENDOR_REQUEST_OUT, offset, 302 USB_VENDOR_REQUEST_OUT, offset,
319 (void *)value, length, 303 (void *)value, length);
320 REGISTER_TIMEOUT32(length));
321} 304}
322 305
323/** 306/**
diff --git a/drivers/net/wireless/rtlwifi/rtl8821ae/phy.c b/drivers/net/wireless/rtlwifi/rtl8821ae/phy.c
index 1e9570fa874f..9b4d8a637915 100644
--- a/drivers/net/wireless/rtlwifi/rtl8821ae/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8821ae/phy.c
@@ -800,7 +800,7 @@ static void _rtl8821ae_phy_set_txpower_by_rate_base(struct ieee80211_hw *hw,
800 "Invalid RateSection %d in Band 2.4G,Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n", 800 "Invalid RateSection %d in Band 2.4G,Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n",
801 rate_section, path, txnum); 801 rate_section, path, txnum);
802 break; 802 break;
803 }; 803 }
804 } else if (band == BAND_ON_5G) { 804 } else if (band == BAND_ON_5G) {
805 switch (rate_section) { 805 switch (rate_section) {
806 case OFDM: 806 case OFDM:
@@ -823,7 +823,7 @@ static void _rtl8821ae_phy_set_txpower_by_rate_base(struct ieee80211_hw *hw,
823 "Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n", 823 "Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n",
824 rate_section, path, txnum); 824 rate_section, path, txnum);
825 break; 825 break;
826 }; 826 }
827 } else { 827 } else {
828 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, 828 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
829 "Invalid Band %d in PHY_SetTxPowerByRateBase()\n", band); 829 "Invalid Band %d in PHY_SetTxPowerByRateBase()\n", band);
@@ -870,7 +870,7 @@ static u8 _rtl8821ae_phy_get_txpower_by_rate_base(struct ieee80211_hw *hw,
870 "Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n", 870 "Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
871 rate_section, path, txnum); 871 rate_section, path, txnum);
872 break; 872 break;
873 }; 873 }
874 } else if (band == BAND_ON_5G) { 874 } else if (band == BAND_ON_5G) {
875 switch (rate_section) { 875 switch (rate_section) {
876 case OFDM: 876 case OFDM:
@@ -893,7 +893,7 @@ static u8 _rtl8821ae_phy_get_txpower_by_rate_base(struct ieee80211_hw *hw,
893 "Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n", 893 "Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
894 rate_section, path, txnum); 894 rate_section, path, txnum);
895 break; 895 break;
896 }; 896 }
897 } else { 897 } else {
898 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, 898 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
899 "Invalid Band %d in PHY_GetTxPowerByRateBase()\n", band); 899 "Invalid Band %d in PHY_GetTxPowerByRateBase()\n", band);
@@ -3746,7 +3746,7 @@ static void _rtl8821ae_iqk_tx_fill_iqc(struct ieee80211_hw *hw,
3746 break; 3746 break;
3747 default: 3747 default:
3748 break; 3748 break;
3749 }; 3749 }
3750} 3750}
3751 3751
3752static void _rtl8821ae_iqk_rx_fill_iqc(struct ieee80211_hw *hw, 3752static void _rtl8821ae_iqk_rx_fill_iqc(struct ieee80211_hw *hw,
@@ -3767,7 +3767,7 @@ static void _rtl8821ae_iqk_rx_fill_iqc(struct ieee80211_hw *hw,
3767 break; 3767 break;
3768 default: 3768 default:
3769 break; 3769 break;
3770 }; 3770 }
3771} 3771}
3772 3772
3773#define cal_num 10 3773#define cal_num 10
diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c
index 05604ee31224..dd2e448c3e2b 100644
--- a/drivers/net/wireless/ti/wlcore/cmd.c
+++ b/drivers/net/wireless/ti/wlcore/cmd.c
@@ -64,6 +64,9 @@ static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf,
64 id != CMD_STOP_FWLOGGER)) 64 id != CMD_STOP_FWLOGGER))
65 return -EIO; 65 return -EIO;
66 66
67 if (WARN_ON_ONCE(len < sizeof(*cmd)))
68 return -EIO;
69
67 cmd = buf; 70 cmd = buf;
68 cmd->id = cpu_to_le16(id); 71 cmd->id = cpu_to_le16(id);
69 cmd->status = 0; 72 cmd->status = 0;
@@ -128,8 +131,9 @@ static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf,
128 * send command to fw and return cmd status on success 131 * send command to fw and return cmd status on success
129 * valid_rets contains a bitmap of allowed error codes 132 * valid_rets contains a bitmap of allowed error codes
130 */ 133 */
131int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf, size_t len, 134static int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf,
132 size_t res_len, unsigned long valid_rets) 135 size_t len, size_t res_len,
136 unsigned long valid_rets)
133{ 137{
134 int ret = __wlcore_cmd_send(wl, id, buf, len, res_len); 138 int ret = __wlcore_cmd_send(wl, id, buf, len, res_len);
135 139
@@ -150,7 +154,6 @@ fail:
150 wl12xx_queue_recovery_work(wl); 154 wl12xx_queue_recovery_work(wl);
151 return ret; 155 return ret;
152} 156}
153EXPORT_SYMBOL_GPL(wl1271_cmd_send);
154 157
155/* 158/*
156 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS 159 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
@@ -165,6 +168,7 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
165 return ret; 168 return ret;
166 return 0; 169 return 0;
167} 170}
171EXPORT_SYMBOL_GPL(wl1271_cmd_send);
168 172
169/* 173/*
170 * Poll the mailbox event field until any of the bits in the mask is set or a 174 * Poll the mailbox event field until any of the bits in the mask is set or a
@@ -891,6 +895,9 @@ int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf,
891 895
892 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id); 896 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
893 897
898 if (WARN_ON_ONCE(len < sizeof(*acx)))
899 return -EIO;
900
894 acx->id = cpu_to_le16(id); 901 acx->id = cpu_to_le16(id);
895 902
896 /* payload length, does not include any headers */ 903 /* payload length, does not include any headers */
diff --git a/drivers/net/wireless/ti/wlcore/cmd.h b/drivers/net/wireless/ti/wlcore/cmd.h
index ca6a28b03f8f..453684a71d30 100644
--- a/drivers/net/wireless/ti/wlcore/cmd.h
+++ b/drivers/net/wireless/ti/wlcore/cmd.h
@@ -31,8 +31,6 @@ struct acx_header;
31 31
32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, 32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
33 size_t res_len); 33 size_t res_len);
34int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf, size_t len,
35 size_t res_len, unsigned long valid_rets);
36int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type, 34int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
37 u8 *role_id); 35 u8 *role_id);
38int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id); 36int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id);
diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 575c8f6d4009..6ad3fcedab9b 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -5177,10 +5177,11 @@ out:
5177} 5177}
5178 5178
5179static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, 5179static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
5180 struct ieee80211_vif *vif,
5180 struct ieee80211_channel_switch *ch_switch) 5181 struct ieee80211_channel_switch *ch_switch)
5181{ 5182{
5182 struct wl1271 *wl = hw->priv; 5183 struct wl1271 *wl = hw->priv;
5183 struct wl12xx_vif *wlvif; 5184 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
5184 int ret; 5185 int ret;
5185 5186
5186 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); 5187 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
@@ -5190,14 +5191,8 @@ static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
5190 mutex_lock(&wl->mutex); 5191 mutex_lock(&wl->mutex);
5191 5192
5192 if (unlikely(wl->state == WLCORE_STATE_OFF)) { 5193 if (unlikely(wl->state == WLCORE_STATE_OFF)) {
5193 wl12xx_for_each_wlvif_sta(wl, wlvif) { 5194 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
5194 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
5195
5196 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
5197 continue;
5198
5199 ieee80211_chswitch_done(vif, false); 5195 ieee80211_chswitch_done(vif, false);
5200 }
5201 goto out; 5196 goto out;
5202 } else if (unlikely(wl->state != WLCORE_STATE_ON)) { 5197 } else if (unlikely(wl->state != WLCORE_STATE_ON)) {
5203 goto out; 5198 goto out;
@@ -5208,11 +5203,9 @@ static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
5208 goto out; 5203 goto out;
5209 5204
5210 /* TODO: change mac80211 to pass vif as param */ 5205 /* TODO: change mac80211 to pass vif as param */
5211 wl12xx_for_each_wlvif_sta(wl, wlvif) {
5212 unsigned long delay_usec;
5213 5206
5214 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) 5207 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
5215 continue; 5208 unsigned long delay_usec;
5216 5209
5217 ret = wl->ops->channel_switch(wl, wlvif, ch_switch); 5210 ret = wl->ops->channel_switch(wl, wlvif, ch_switch);
5218 if (ret) 5211 if (ret)
@@ -5222,10 +5215,10 @@ static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
5222 5215
5223 /* indicate failure 5 seconds after channel switch time */ 5216 /* indicate failure 5 seconds after channel switch time */
5224 delay_usec = ieee80211_tu_to_usec(wlvif->beacon_int) * 5217 delay_usec = ieee80211_tu_to_usec(wlvif->beacon_int) *
5225 ch_switch->count; 5218 ch_switch->count;
5226 ieee80211_queue_delayed_work(hw, &wlvif->channel_switch_work, 5219 ieee80211_queue_delayed_work(hw, &wlvif->channel_switch_work,
5227 usecs_to_jiffies(delay_usec) + 5220 usecs_to_jiffies(delay_usec) +
5228 msecs_to_jiffies(5000)); 5221 msecs_to_jiffies(5000));
5229 } 5222 }
5230 5223
5231out_sleep: 5224out_sleep:
diff --git a/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
index bd6953af0a03..3d26955da724 100644
--- a/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
@@ -2856,8 +2856,10 @@ static int cfg80211_rtw_add_station(struct wiphy *wiphy,
2856} 2856}
2857 2857
2858static int cfg80211_rtw_del_station(struct wiphy *wiphy, 2858static int cfg80211_rtw_del_station(struct wiphy *wiphy,
2859 struct net_device *ndev, const u8 *mac) 2859 struct net_device *ndev,
2860 struct station_del_parameters *params)
2860{ 2861{
2862 const u8 *mac = params->mac;
2861 int ret = 0; 2863 int ret = 0;
2862 struct list_head *phead, *plist, *ptmp; 2864 struct list_head *phead, *plist, *ptmp;
2863 u8 updated = 0; 2865 u8 updated = 0;
diff --git a/include/linux/ath9k_platform.h b/include/linux/ath9k_platform.h
index a495a959e8a7..33eb274cd0e6 100644
--- a/include/linux/ath9k_platform.h
+++ b/include/linux/ath9k_platform.h
@@ -31,8 +31,11 @@ struct ath9k_platform_data {
31 u32 gpio_mask; 31 u32 gpio_mask;
32 u32 gpio_val; 32 u32 gpio_val;
33 33
34 bool endian_check;
34 bool is_clk_25mhz; 35 bool is_clk_25mhz;
35 bool tx_gain_buffalo; 36 bool tx_gain_buffalo;
37 bool disable_2ghz;
38 bool disable_5ghz;
36 39
37 int (*get_mac_revision)(void); 40 int (*get_mac_revision)(void);
38 int (*external_reset)(void); 41 int (*external_reset)(void);
diff --git a/include/linux/bcma/bcma.h b/include/linux/bcma/bcma.h
index 729f48e6b20b..eb1c6a47b67f 100644
--- a/include/linux/bcma/bcma.h
+++ b/include/linux/bcma/bcma.h
@@ -447,4 +447,6 @@ extern u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset);
447#define BCMA_DMA_TRANSLATION_DMA64_CMT 0x80000000 /* Client Mode Translation for 64-bit DMA */ 447#define BCMA_DMA_TRANSLATION_DMA64_CMT 0x80000000 /* Client Mode Translation for 64-bit DMA */
448extern u32 bcma_core_dma_translation(struct bcma_device *core); 448extern u32 bcma_core_dma_translation(struct bcma_device *core);
449 449
450extern unsigned int bcma_core_irq(struct bcma_device *core, int num);
451
450#endif /* LINUX_BCMA_H_ */ 452#endif /* LINUX_BCMA_H_ */
diff --git a/include/linux/bcma/bcma_driver_mips.h b/include/linux/bcma/bcma_driver_mips.h
index fb61f3fb4ddb..0b3b32aeeb8a 100644
--- a/include/linux/bcma/bcma_driver_mips.h
+++ b/include/linux/bcma/bcma_driver_mips.h
@@ -43,12 +43,12 @@ struct bcma_drv_mips {
43extern void bcma_core_mips_init(struct bcma_drv_mips *mcore); 43extern void bcma_core_mips_init(struct bcma_drv_mips *mcore);
44extern void bcma_core_mips_early_init(struct bcma_drv_mips *mcore); 44extern void bcma_core_mips_early_init(struct bcma_drv_mips *mcore);
45 45
46extern unsigned int bcma_core_irq(struct bcma_device *core); 46extern unsigned int bcma_core_mips_irq(struct bcma_device *dev);
47#else 47#else
48static inline void bcma_core_mips_init(struct bcma_drv_mips *mcore) { } 48static inline void bcma_core_mips_init(struct bcma_drv_mips *mcore) { }
49static inline void bcma_core_mips_early_init(struct bcma_drv_mips *mcore) { } 49static inline void bcma_core_mips_early_init(struct bcma_drv_mips *mcore) { }
50 50
51static inline unsigned int bcma_core_irq(struct bcma_device *core) 51static inline unsigned int bcma_core_mips_irq(struct bcma_device *dev)
52{ 52{
53 return 0; 53 return 0;
54} 54}
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index b1be39c76931..f65b5446d983 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -1274,7 +1274,7 @@ struct ieee80211_ht_cap {
1274#define IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2 1274#define IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2
1275 1275
1276/* 1276/*
1277 * Maximum length of AMPDU that the STA can receive. 1277 * Maximum length of AMPDU that the STA can receive in high-throughput (HT).
1278 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) 1278 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
1279 */ 1279 */
1280enum ieee80211_max_ampdu_length_exp { 1280enum ieee80211_max_ampdu_length_exp {
@@ -1284,6 +1284,21 @@ enum ieee80211_max_ampdu_length_exp {
1284 IEEE80211_HT_MAX_AMPDU_64K = 3 1284 IEEE80211_HT_MAX_AMPDU_64K = 3
1285}; 1285};
1286 1286
1287/*
1288 * Maximum length of AMPDU that the STA can receive in VHT.
1289 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
1290 */
1291enum ieee80211_vht_max_ampdu_length_exp {
1292 IEEE80211_VHT_MAX_AMPDU_8K = 0,
1293 IEEE80211_VHT_MAX_AMPDU_16K = 1,
1294 IEEE80211_VHT_MAX_AMPDU_32K = 2,
1295 IEEE80211_VHT_MAX_AMPDU_64K = 3,
1296 IEEE80211_VHT_MAX_AMPDU_128K = 4,
1297 IEEE80211_VHT_MAX_AMPDU_256K = 5,
1298 IEEE80211_VHT_MAX_AMPDU_512K = 6,
1299 IEEE80211_VHT_MAX_AMPDU_1024K = 7
1300};
1301
1287#define IEEE80211_HT_MAX_AMPDU_FACTOR 13 1302#define IEEE80211_HT_MAX_AMPDU_FACTOR 13
1288 1303
1289/* Minimum MPDU start spacing */ 1304/* Minimum MPDU start spacing */
@@ -1998,6 +2013,11 @@ enum ieee80211_tdls_actioncode {
1998 WLAN_TDLS_DISCOVERY_REQUEST = 10, 2013 WLAN_TDLS_DISCOVERY_REQUEST = 10,
1999}; 2014};
2000 2015
2016/* Extended Channel Switching capability to be set in the 1st byte of
2017 * the @WLAN_EID_EXT_CAPABILITY information element
2018 */
2019#define WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING BIT(2)
2020
2001/* Interworking capabilities are set in 7th bit of 4th byte of the 2021/* Interworking capabilities are set in 7th bit of 4th byte of the
2002 * @WLAN_EID_EXT_CAPABILITY information element 2022 * @WLAN_EID_EXT_CAPABILITY information element
2003 */ 2023 */
diff --git a/include/net/ieee802154.h b/include/linux/ieee802154.h
index 0aa7122e8f15..6e82d888287c 100644
--- a/include/net/ieee802154.h
+++ b/include/linux/ieee802154.h
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 16 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
21 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 17 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
@@ -24,10 +20,27 @@
24 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 20 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
25 */ 21 */
26 22
27#ifndef NET_IEEE802154_H 23#ifndef LINUX_IEEE802154_H
28#define NET_IEEE802154_H 24#define LINUX_IEEE802154_H
25
26#include <linux/types.h>
27#include <linux/random.h>
28#include <asm/byteorder.h>
29 29
30#define IEEE802154_MTU 127 30#define IEEE802154_MTU 127
31#define IEEE802154_MIN_PSDU_LEN 5
32
33#define IEEE802154_PAN_ID_BROADCAST 0xffff
34#define IEEE802154_ADDR_SHORT_BROADCAST 0xffff
35#define IEEE802154_ADDR_SHORT_UNSPEC 0xfffe
36
37#define IEEE802154_EXTENDED_ADDR_LEN 8
38
39#define IEEE802154_LIFS_PERIOD 40
40#define IEEE802154_SIFS_PERIOD 12
41
42#define IEEE802154_MAX_CHANNEL 26
43#define IEEE802154_MAX_PAGE 31
31 44
32#define IEEE802154_FC_TYPE_BEACON 0x0 /* Frame is beacon */ 45#define IEEE802154_FC_TYPE_BEACON 0x0 /* Frame is beacon */
33#define IEEE802154_FC_TYPE_DATA 0x1 /* Frame is data */ 46#define IEEE802154_FC_TYPE_DATA 0x1 /* Frame is data */
@@ -189,7 +202,41 @@ enum {
189 IEEE802154_SCAN_IN_PROGRESS = 0xfc, 202 IEEE802154_SCAN_IN_PROGRESS = 0xfc,
190}; 203};
191 204
205/**
206 * ieee802154_is_valid_psdu_len - check if psdu len is valid
207 * @len: psdu len with (MHR + payload + MFR)
208 */
209static inline bool ieee802154_is_valid_psdu_len(const u8 len)
210{
211 return (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU);
212}
213
214/**
215 * ieee802154_is_valid_psdu_len - check if extended addr is valid
216 * @addr: extended addr to check
217 */
218static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
219{
220 /* These EUI-64 addresses are reserved by IEEE. 0xffffffffffffffff
221 * is used internally as extended to short address broadcast mapping.
222 * This is currently a workaround because neighbor discovery can't
223 * deal with short addresses types right now.
224 */
225 return ((addr != cpu_to_le64(0x0000000000000000ULL)) &&
226 (addr != cpu_to_le64(0xffffffffffffffffULL)));
227}
192 228
193#endif 229/**
230 * ieee802154_random_extended_addr - generates a random extended address
231 * @addr: extended addr pointer to place the random address
232 */
233static inline void ieee802154_random_extended_addr(__le64 *addr)
234{
235 get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
194 236
237 /* toggle some bit if we hit an invalid extended addr */
238 if (!ieee802154_is_valid_extended_addr(*addr))
239 ((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;
240}
195 241
242#endif /* LINUX_IEEE802154_H */
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 74fd5d37f15a..c9bcf33efb47 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -57,6 +57,8 @@ struct device;
57struct phy_device; 57struct phy_device;
58/* 802.11 specific */ 58/* 802.11 specific */
59struct wireless_dev; 59struct wireless_dev;
60/* 802.15.4 specific */
61struct wpan_dev;
60 62
61void netdev_set_default_ethtool_ops(struct net_device *dev, 63void netdev_set_default_ethtool_ops(struct net_device *dev,
62 const struct ethtool_ops *ops); 64 const struct ethtool_ops *ops);
@@ -1572,6 +1574,7 @@ struct net_device {
1572 struct inet6_dev __rcu *ip6_ptr; 1574 struct inet6_dev __rcu *ip6_ptr;
1573 void *ax25_ptr; 1575 void *ax25_ptr;
1574 struct wireless_dev *ieee80211_ptr; 1576 struct wireless_dev *ieee80211_ptr;
1577 struct wpan_dev *ieee802154_ptr;
1575 1578
1576/* 1579/*
1577 * Cache lines mostly used on receive path (including eth_type_trans()) 1580 * Cache lines mostly used on receive path (including eth_type_trans())
diff --git a/include/linux/nl802154.h b/include/linux/nl802154.h
index 20163b9a0eae..167342c2ce6b 100644
--- a/include/linux/nl802154.h
+++ b/include/linux/nl802154.h
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */ 15 */
20 16
21#ifndef NL802154_H 17#ifndef NL802154_H
diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h
index d184df1d0d41..dc03d77ad23b 100644
--- a/include/net/6lowpan.h
+++ b/include/net/6lowpan.h
@@ -372,12 +372,12 @@ lowpan_uncompress_size(const struct sk_buff *skb, u16 *dgram_offset)
372 return skb->len + uncomp_header - ret; 372 return skb->len + uncomp_header - ret;
373} 373}
374 374
375typedef int (*skb_delivery_cb)(struct sk_buff *skb, struct net_device *dev); 375int
376 376lowpan_header_decompress(struct sk_buff *skb, struct net_device *dev,
377int lowpan_process_data(struct sk_buff *skb, struct net_device *dev, 377 const u8 *saddr, const u8 saddr_type,
378 const u8 *saddr, const u8 saddr_type, const u8 saddr_len, 378 const u8 saddr_len, const u8 *daddr,
379 const u8 *daddr, const u8 daddr_type, const u8 daddr_len, 379 const u8 daddr_type, const u8 daddr_len,
380 u8 iphc0, u8 iphc1, skb_delivery_cb skb_deliver); 380 u8 iphc0, u8 iphc1);
381int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, 381int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
382 unsigned short type, const void *_daddr, 382 unsigned short type, const void *_daddr,
383 const void *_saddr, unsigned int len); 383 const void *_saddr, unsigned int len);
diff --git a/include/net/af_ieee802154.h b/include/net/af_ieee802154.h
index 085940f7eeec..7d38e2ffd256 100644
--- a/include/net/af_ieee802154.h
+++ b/include/net/af_ieee802154.h
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 6e8f24967308..e56f9099f8e3 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -129,6 +129,15 @@ enum {
129 * during the hdev->setup vendor callback. 129 * during the hdev->setup vendor callback.
130 */ 130 */
131 HCI_QUIRK_INVALID_BDADDR, 131 HCI_QUIRK_INVALID_BDADDR,
132
133 /* When this quirk is set, the duplicate filtering during
134 * scanning is based on Bluetooth devices addresses. To allow
135 * RSSI based updates, restart scanning if needed.
136 *
137 * This quirk can be set before hci_register_dev is called or
138 * during the hdev->setup vendor callback.
139 */
140 HCI_QUIRK_STRICT_DUPLICATE_FILTER,
132}; 141};
133 142
134/* HCI device flags */ 143/* HCI device flags */
@@ -265,6 +274,7 @@ enum {
265/* Low Energy links do not have defined link type. Use invented one */ 274/* Low Energy links do not have defined link type. Use invented one */
266#define LE_LINK 0x80 275#define LE_LINK 0x80
267#define AMP_LINK 0x81 276#define AMP_LINK 0x81
277#define INVALID_LINK 0xff
268 278
269/* LMP features */ 279/* LMP features */
270#define LMP_3SLOT 0x01 280#define LMP_3SLOT 0x01
@@ -629,7 +639,7 @@ struct hci_cp_user_passkey_reply {
629struct hci_cp_remote_oob_data_reply { 639struct hci_cp_remote_oob_data_reply {
630 bdaddr_t bdaddr; 640 bdaddr_t bdaddr;
631 __u8 hash[16]; 641 __u8 hash[16];
632 __u8 randomizer[16]; 642 __u8 rand[16];
633} __packed; 643} __packed;
634 644
635#define HCI_OP_REMOTE_OOB_DATA_NEG_REPLY 0x0433 645#define HCI_OP_REMOTE_OOB_DATA_NEG_REPLY 0x0433
@@ -721,9 +731,9 @@ struct hci_rp_set_csb {
721struct hci_cp_remote_oob_ext_data_reply { 731struct hci_cp_remote_oob_ext_data_reply {
722 bdaddr_t bdaddr; 732 bdaddr_t bdaddr;
723 __u8 hash192[16]; 733 __u8 hash192[16];
724 __u8 randomizer192[16]; 734 __u8 rand192[16];
725 __u8 hash256[16]; 735 __u8 hash256[16];
726 __u8 randomizer256[16]; 736 __u8 rand256[16];
727} __packed; 737} __packed;
728 738
729#define HCI_OP_SNIFF_MODE 0x0803 739#define HCI_OP_SNIFF_MODE 0x0803
@@ -930,7 +940,7 @@ struct hci_cp_write_ssp_mode {
930struct hci_rp_read_local_oob_data { 940struct hci_rp_read_local_oob_data {
931 __u8 status; 941 __u8 status;
932 __u8 hash[16]; 942 __u8 hash[16];
933 __u8 randomizer[16]; 943 __u8 rand[16];
934} __packed; 944} __packed;
935 945
936#define HCI_OP_READ_INQ_RSP_TX_POWER 0x0c58 946#define HCI_OP_READ_INQ_RSP_TX_POWER 0x0c58
@@ -1014,9 +1024,9 @@ struct hci_cp_write_sc_support {
1014struct hci_rp_read_local_oob_ext_data { 1024struct hci_rp_read_local_oob_ext_data {
1015 __u8 status; 1025 __u8 status;
1016 __u8 hash192[16]; 1026 __u8 hash192[16];
1017 __u8 randomizer192[16]; 1027 __u8 rand192[16];
1018 __u8 hash256[16]; 1028 __u8 hash256[16];
1019 __u8 randomizer256[16]; 1029 __u8 rand256[16];
1020} __packed; 1030} __packed;
1021 1031
1022#define HCI_OP_READ_LOCAL_VERSION 0x1001 1032#define HCI_OP_READ_LOCAL_VERSION 0x1001
@@ -1463,6 +1473,11 @@ struct hci_ev_cmd_status {
1463 __le16 opcode; 1473 __le16 opcode;
1464} __packed; 1474} __packed;
1465 1475
1476#define HCI_EV_HARDWARE_ERROR 0x10
1477struct hci_ev_hardware_error {
1478 __u8 code;
1479} __packed;
1480
1466#define HCI_EV_ROLE_CHANGE 0x12 1481#define HCI_EV_ROLE_CHANGE 0x12
1467struct hci_ev_role_change { 1482struct hci_ev_role_change {
1468 __u8 status; 1483 __u8 status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 37ff1aef0845..a805b3d97c0b 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -108,6 +108,7 @@ struct smp_csrk {
108 108
109struct smp_ltk { 109struct smp_ltk {
110 struct list_head list; 110 struct list_head list;
111 struct rcu_head rcu;
111 bdaddr_t bdaddr; 112 bdaddr_t bdaddr;
112 u8 bdaddr_type; 113 u8 bdaddr_type;
113 u8 authenticated; 114 u8 authenticated;
@@ -120,6 +121,7 @@ struct smp_ltk {
120 121
121struct smp_irk { 122struct smp_irk {
122 struct list_head list; 123 struct list_head list;
124 struct rcu_head rcu;
123 bdaddr_t rpa; 125 bdaddr_t rpa;
124 bdaddr_t bdaddr; 126 bdaddr_t bdaddr;
125 u8 addr_type; 127 u8 addr_type;
@@ -138,9 +140,9 @@ struct oob_data {
138 struct list_head list; 140 struct list_head list;
139 bdaddr_t bdaddr; 141 bdaddr_t bdaddr;
140 u8 hash192[16]; 142 u8 hash192[16];
141 u8 randomizer192[16]; 143 u8 rand192[16];
142 u8 hash256[16]; 144 u8 hash256[16];
143 u8 randomizer256[16]; 145 u8 rand256[16];
144}; 146};
145 147
146#define HCI_MAX_SHORT_NAME_LENGTH 10 148#define HCI_MAX_SHORT_NAME_LENGTH 10
@@ -398,6 +400,8 @@ struct hci_conn {
398 __u16 le_conn_interval; 400 __u16 le_conn_interval;
399 __u16 le_conn_latency; 401 __u16 le_conn_latency;
400 __u16 le_supv_timeout; 402 __u16 le_supv_timeout;
403 __u8 le_adv_data[HCI_MAX_AD_LENGTH];
404 __u8 le_adv_data_len;
401 __s8 rssi; 405 __s8 rssi;
402 __s8 tx_power; 406 __s8 tx_power;
403 __s8 max_tx_power; 407 __s8 max_tx_power;
@@ -553,6 +557,7 @@ enum {
553 HCI_CONN_STK_ENCRYPT, 557 HCI_CONN_STK_ENCRYPT,
554 HCI_CONN_AUTH_INITIATOR, 558 HCI_CONN_AUTH_INITIATOR,
555 HCI_CONN_DROP, 559 HCI_CONN_DROP,
560 HCI_CONN_PARAM_REMOVAL_PEND,
556}; 561};
557 562
558static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 563static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
@@ -643,6 +648,26 @@ static inline unsigned int hci_conn_count(struct hci_dev *hdev)
643 return c->acl_num + c->amp_num + c->sco_num + c->le_num; 648 return c->acl_num + c->amp_num + c->sco_num + c->le_num;
644} 649}
645 650
651static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle)
652{
653 struct hci_conn_hash *h = &hdev->conn_hash;
654 struct hci_conn *c;
655 __u8 type = INVALID_LINK;
656
657 rcu_read_lock();
658
659 list_for_each_entry_rcu(c, &h->list, list) {
660 if (c->handle == handle) {
661 type = c->type;
662 break;
663 }
664 }
665
666 rcu_read_unlock();
667
668 return type;
669}
670
646static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 671static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
647 __u16 handle) 672 __u16 handle)
648{ 673{
@@ -853,6 +878,7 @@ int hci_register_dev(struct hci_dev *hdev);
853void hci_unregister_dev(struct hci_dev *hdev); 878void hci_unregister_dev(struct hci_dev *hdev);
854int hci_suspend_dev(struct hci_dev *hdev); 879int hci_suspend_dev(struct hci_dev *hdev);
855int hci_resume_dev(struct hci_dev *hdev); 880int hci_resume_dev(struct hci_dev *hdev);
881int hci_reset_dev(struct hci_dev *hdev);
856int hci_dev_open(__u16 dev); 882int hci_dev_open(__u16 dev);
857int hci_dev_close(__u16 dev); 883int hci_dev_close(__u16 dev);
858int hci_dev_reset(__u16 dev); 884int hci_dev_reset(__u16 dev);
@@ -917,10 +943,10 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev);
917struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 943struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
918 bdaddr_t *bdaddr); 944 bdaddr_t *bdaddr);
919int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 945int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
920 u8 *hash, u8 *randomizer); 946 u8 *hash, u8 *rand);
921int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 947int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
922 u8 *hash192, u8 *randomizer192, 948 u8 *hash192, u8 *rand192,
923 u8 *hash256, u8 *randomizer256); 949 u8 *hash256, u8 *rand256);
924int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); 950int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
925 951
926void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); 952void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
@@ -1310,9 +1336,8 @@ int mgmt_update_adv_data(struct hci_dev *hdev);
1310void mgmt_discoverable_timeout(struct hci_dev *hdev); 1336void mgmt_discoverable_timeout(struct hci_dev *hdev);
1311void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 1337void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
1312 bool persistent); 1338 bool persistent);
1313void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1339void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
1314 u8 addr_type, u32 flags, u8 *name, u8 name_len, 1340 u32 flags, u8 *name, u8 name_len);
1315 u8 *dev_class);
1316void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 1341void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
1317 u8 link_type, u8 addr_type, u8 reason, 1342 u8 link_type, u8 addr_type, u8 reason,
1318 bool mgmt_connected); 1343 bool mgmt_connected);
@@ -1349,8 +1374,8 @@ void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1349 u8 status); 1374 u8 status);
1350void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1375void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
1351void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192, 1376void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
1352 u8 *randomizer192, u8 *hash256, 1377 u8 *rand192, u8 *hash256, u8 *rand256,
1353 u8 *randomizer256, u8 status); 1378 u8 status);
1354void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1379void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1355 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, 1380 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
1356 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len); 1381 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len);
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index ead99f032f7a..061e648052c8 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -28,6 +28,7 @@
28#define __L2CAP_H 28#define __L2CAP_H
29 29
30#include <asm/unaligned.h> 30#include <asm/unaligned.h>
31#include <linux/atomic.h>
31 32
32/* L2CAP defaults */ 33/* L2CAP defaults */
33#define L2CAP_DEFAULT_MTU 672 34#define L2CAP_DEFAULT_MTU 672
@@ -481,6 +482,7 @@ struct l2cap_chan {
481 struct hci_conn *hs_hcon; 482 struct hci_conn *hs_hcon;
482 struct hci_chan *hs_hchan; 483 struct hci_chan *hs_hchan;
483 struct kref kref; 484 struct kref kref;
485 atomic_t nesting;
484 486
485 __u8 state; 487 __u8 state;
486 488
@@ -713,6 +715,17 @@ enum {
713 FLAG_HOLD_HCI_CONN, 715 FLAG_HOLD_HCI_CONN,
714}; 716};
715 717
718/* Lock nesting levels for L2CAP channels. We need these because lockdep
719 * otherwise considers all channels equal and will e.g. complain about a
720 * connection oriented channel triggering SMP procedures or a listening
721 * channel creating and locking a child channel.
722 */
723enum {
724 L2CAP_NESTING_SMP,
725 L2CAP_NESTING_NORMAL,
726 L2CAP_NESTING_PARENT,
727};
728
716enum { 729enum {
717 L2CAP_TX_STATE_XMIT, 730 L2CAP_TX_STATE_XMIT,
718 L2CAP_TX_STATE_WAIT_F, 731 L2CAP_TX_STATE_WAIT_F,
@@ -778,7 +791,7 @@ void l2cap_chan_put(struct l2cap_chan *c);
778 791
779static inline void l2cap_chan_lock(struct l2cap_chan *chan) 792static inline void l2cap_chan_lock(struct l2cap_chan *chan)
780{ 793{
781 mutex_lock(&chan->lock); 794 mutex_lock_nested(&chan->lock, atomic_read(&chan->nesting));
782} 795}
783 796
784static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 797static inline void l2cap_chan_unlock(struct l2cap_chan *chan)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 414cd2f9a437..b391fd663468 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -299,28 +299,28 @@ struct mgmt_cp_user_passkey_neg_reply {
299#define MGMT_READ_LOCAL_OOB_DATA_SIZE 0 299#define MGMT_READ_LOCAL_OOB_DATA_SIZE 0
300struct mgmt_rp_read_local_oob_data { 300struct mgmt_rp_read_local_oob_data {
301 __u8 hash[16]; 301 __u8 hash[16];
302 __u8 randomizer[16]; 302 __u8 rand[16];
303} __packed; 303} __packed;
304struct mgmt_rp_read_local_oob_ext_data { 304struct mgmt_rp_read_local_oob_ext_data {
305 __u8 hash192[16]; 305 __u8 hash192[16];
306 __u8 randomizer192[16]; 306 __u8 rand192[16];
307 __u8 hash256[16]; 307 __u8 hash256[16];
308 __u8 randomizer256[16]; 308 __u8 rand256[16];
309} __packed; 309} __packed;
310 310
311#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021 311#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021
312struct mgmt_cp_add_remote_oob_data { 312struct mgmt_cp_add_remote_oob_data {
313 struct mgmt_addr_info addr; 313 struct mgmt_addr_info addr;
314 __u8 hash[16]; 314 __u8 hash[16];
315 __u8 randomizer[16]; 315 __u8 rand[16];
316} __packed; 316} __packed;
317#define MGMT_ADD_REMOTE_OOB_DATA_SIZE (MGMT_ADDR_INFO_SIZE + 32) 317#define MGMT_ADD_REMOTE_OOB_DATA_SIZE (MGMT_ADDR_INFO_SIZE + 32)
318struct mgmt_cp_add_remote_oob_ext_data { 318struct mgmt_cp_add_remote_oob_ext_data {
319 struct mgmt_addr_info addr; 319 struct mgmt_addr_info addr;
320 __u8 hash192[16]; 320 __u8 hash192[16];
321 __u8 randomizer192[16]; 321 __u8 rand192[16];
322 __u8 hash256[16]; 322 __u8 hash256[16];
323 __u8 randomizer256[16]; 323 __u8 rand256[16];
324} __packed; 324} __packed;
325#define MGMT_ADD_REMOTE_OOB_EXT_DATA_SIZE (MGMT_ADDR_INFO_SIZE + 64) 325#define MGMT_ADD_REMOTE_OOB_EXT_DATA_SIZE (MGMT_ADDR_INFO_SIZE + 64)
326 326
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index a2ddcf2398fd..5c3acd07acd9 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -319,9 +319,12 @@ struct ieee80211_supported_band {
319/** 319/**
320 * struct vif_params - describes virtual interface parameters 320 * struct vif_params - describes virtual interface parameters
321 * @use_4addr: use 4-address frames 321 * @use_4addr: use 4-address frames
322 * @macaddr: address to use for this virtual interface. This will only 322 * @macaddr: address to use for this virtual interface.
323 * be used for non-netdevice interfaces. If this parameter is set 323 * If this parameter is set to zero address the driver may
324 * to zero address the driver may determine the address as needed. 324 * determine the address as needed.
325 * This feature is only fully supported by drivers that enable the
326 * %NL80211_FEATURE_MAC_ON_CREATE flag. Others may support creating
327 ** only p2p devices with specified MAC.
325 */ 328 */
326struct vif_params { 329struct vif_params {
327 int use_4addr; 330 int use_4addr;
@@ -799,6 +802,22 @@ struct station_parameters {
799}; 802};
800 803
801/** 804/**
805 * struct station_del_parameters - station deletion parameters
806 *
807 * Used to delete a station entry (or all stations).
808 *
809 * @mac: MAC address of the station to remove or NULL to remove all stations
810 * @subtype: Management frame subtype to use for indicating removal
811 * (10 = Disassociation, 12 = Deauthentication)
812 * @reason_code: Reason code for the Disassociation/Deauthentication frame
813 */
814struct station_del_parameters {
815 const u8 *mac;
816 u8 subtype;
817 u16 reason_code;
818};
819
820/**
802 * enum cfg80211_station_type - the type of station being modified 821 * enum cfg80211_station_type - the type of station being modified
803 * @CFG80211_STA_AP_CLIENT: client of an AP interface 822 * @CFG80211_STA_AP_CLIENT: client of an AP interface
804 * @CFG80211_STA_AP_MLME_CLIENT: client of an AP interface that has 823 * @CFG80211_STA_AP_MLME_CLIENT: client of an AP interface that has
@@ -1340,6 +1359,16 @@ struct mesh_setup {
1340}; 1359};
1341 1360
1342/** 1361/**
1362 * struct ocb_setup - 802.11p OCB mode setup configuration
1363 * @chandef: defines the channel to use
1364 *
1365 * These parameters are fixed when connecting to the network
1366 */
1367struct ocb_setup {
1368 struct cfg80211_chan_def chandef;
1369};
1370
1371/**
1343 * struct ieee80211_txq_params - TX queue parameters 1372 * struct ieee80211_txq_params - TX queue parameters
1344 * @ac: AC identifier 1373 * @ac: AC identifier
1345 * @txop: Maximum burst time in units of 32 usecs, 0 meaning disabled 1374 * @txop: Maximum burst time in units of 32 usecs, 0 meaning disabled
@@ -2132,7 +2161,7 @@ struct cfg80211_qos_map {
2132 * @stop_ap: Stop being an AP, including stopping beaconing. 2161 * @stop_ap: Stop being an AP, including stopping beaconing.
2133 * 2162 *
2134 * @add_station: Add a new station. 2163 * @add_station: Add a new station.
2135 * @del_station: Remove a station; @mac may be NULL to remove all stations. 2164 * @del_station: Remove a station
2136 * @change_station: Modify a given station. Note that flags changes are not much 2165 * @change_station: Modify a given station. Note that flags changes are not much
2137 * validated in cfg80211, in particular the auth/assoc/authorized flags 2166 * validated in cfg80211, in particular the auth/assoc/authorized flags
2138 * might come to the driver in invalid combinations -- make sure to check 2167 * might come to the driver in invalid combinations -- make sure to check
@@ -2146,6 +2175,8 @@ struct cfg80211_qos_map {
2146 * @change_mpath: change a given mesh path 2175 * @change_mpath: change a given mesh path
2147 * @get_mpath: get a mesh path for the given parameters 2176 * @get_mpath: get a mesh path for the given parameters
2148 * @dump_mpath: dump mesh path callback -- resume dump at index @idx 2177 * @dump_mpath: dump mesh path callback -- resume dump at index @idx
2178 * @get_mpp: get a mesh proxy path for the given parameters
2179 * @dump_mpp: dump mesh proxy path callback -- resume dump at index @idx
2149 * @join_mesh: join the mesh network with the specified parameters 2180 * @join_mesh: join the mesh network with the specified parameters
2150 * (invoked with the wireless_dev mutex held) 2181 * (invoked with the wireless_dev mutex held)
2151 * @leave_mesh: leave the current mesh network 2182 * @leave_mesh: leave the current mesh network
@@ -2331,6 +2362,11 @@ struct cfg80211_qos_map {
2331 * with the peer followed by immediate teardown when the addition is later 2362 * with the peer followed by immediate teardown when the addition is later
2332 * rejected) 2363 * rejected)
2333 * @del_tx_ts: remove an existing TX TS 2364 * @del_tx_ts: remove an existing TX TS
2365 *
2366 * @join_ocb: join the OCB network with the specified parameters
2367 * (invoked with the wireless_dev mutex held)
2368 * @leave_ocb: leave the current OCB network
2369 * (invoked with the wireless_dev mutex held)
2334 */ 2370 */
2335struct cfg80211_ops { 2371struct cfg80211_ops {
2336 int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow); 2372 int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2376,7 +2412,7 @@ struct cfg80211_ops {
2376 const u8 *mac, 2412 const u8 *mac,
2377 struct station_parameters *params); 2413 struct station_parameters *params);
2378 int (*del_station)(struct wiphy *wiphy, struct net_device *dev, 2414 int (*del_station)(struct wiphy *wiphy, struct net_device *dev,
2379 const u8 *mac); 2415 struct station_del_parameters *params);
2380 int (*change_station)(struct wiphy *wiphy, struct net_device *dev, 2416 int (*change_station)(struct wiphy *wiphy, struct net_device *dev,
2381 const u8 *mac, 2417 const u8 *mac,
2382 struct station_parameters *params); 2418 struct station_parameters *params);
@@ -2396,6 +2432,11 @@ struct cfg80211_ops {
2396 int (*dump_mpath)(struct wiphy *wiphy, struct net_device *dev, 2432 int (*dump_mpath)(struct wiphy *wiphy, struct net_device *dev,
2397 int idx, u8 *dst, u8 *next_hop, 2433 int idx, u8 *dst, u8 *next_hop,
2398 struct mpath_info *pinfo); 2434 struct mpath_info *pinfo);
2435 int (*get_mpp)(struct wiphy *wiphy, struct net_device *dev,
2436 u8 *dst, u8 *mpp, struct mpath_info *pinfo);
2437 int (*dump_mpp)(struct wiphy *wiphy, struct net_device *dev,
2438 int idx, u8 *dst, u8 *mpp,
2439 struct mpath_info *pinfo);
2399 int (*get_mesh_config)(struct wiphy *wiphy, 2440 int (*get_mesh_config)(struct wiphy *wiphy,
2400 struct net_device *dev, 2441 struct net_device *dev,
2401 struct mesh_config *conf); 2442 struct mesh_config *conf);
@@ -2407,6 +2448,10 @@ struct cfg80211_ops {
2407 const struct mesh_setup *setup); 2448 const struct mesh_setup *setup);
2408 int (*leave_mesh)(struct wiphy *wiphy, struct net_device *dev); 2449 int (*leave_mesh)(struct wiphy *wiphy, struct net_device *dev);
2409 2450
2451 int (*join_ocb)(struct wiphy *wiphy, struct net_device *dev,
2452 struct ocb_setup *setup);
2453 int (*leave_ocb)(struct wiphy *wiphy, struct net_device *dev);
2454
2410 int (*change_bss)(struct wiphy *wiphy, struct net_device *dev, 2455 int (*change_bss)(struct wiphy *wiphy, struct net_device *dev,
2411 struct bss_parameters *params); 2456 struct bss_parameters *params);
2412 2457
@@ -2623,13 +2668,9 @@ struct cfg80211_ops {
2623 * @WIPHY_FLAG_SUPPORTS_5_10_MHZ: Device supports 5 MHz and 10 MHz channels. 2668 * @WIPHY_FLAG_SUPPORTS_5_10_MHZ: Device supports 5 MHz and 10 MHz channels.
2624 * @WIPHY_FLAG_HAS_CHANNEL_SWITCH: Device supports channel switch in 2669 * @WIPHY_FLAG_HAS_CHANNEL_SWITCH: Device supports channel switch in
2625 * beaconing mode (AP, IBSS, Mesh, ...). 2670 * beaconing mode (AP, IBSS, Mesh, ...).
2626 * @WIPHY_FLAG_SUPPORTS_WMM_ADMISSION: the device supports setting up WMM
2627 * TSPEC sessions (TID aka TSID 0-7) with the NL80211_CMD_ADD_TX_TS
2628 * command. Standard IEEE 802.11 TSPEC setup is not yet supported, it
2629 * needs to be able to handle Block-Ack agreements and other things.
2630 */ 2671 */
2631enum wiphy_flags { 2672enum wiphy_flags {
2632 WIPHY_FLAG_SUPPORTS_WMM_ADMISSION = BIT(0), 2673 /* use hole at 0 */
2633 /* use hole at 1 */ 2674 /* use hole at 1 */
2634 /* use hole at 2 */ 2675 /* use hole at 2 */
2635 WIPHY_FLAG_NETNS_OK = BIT(3), 2676 WIPHY_FLAG_NETNS_OK = BIT(3),
@@ -3166,6 +3207,23 @@ static inline const char *wiphy_name(const struct wiphy *wiphy)
3166} 3207}
3167 3208
3168/** 3209/**
3210 * wiphy_new_nm - create a new wiphy for use with cfg80211
3211 *
3212 * @ops: The configuration operations for this device
3213 * @sizeof_priv: The size of the private area to allocate
3214 * @requested_name: Request a particular name.
3215 * NULL is valid value, and means use the default phy%d naming.
3216 *
3217 * Create a new wiphy and associate the given operations with it.
3218 * @sizeof_priv bytes are allocated for private use.
3219 *
3220 * Return: A pointer to the new wiphy. This pointer must be
3221 * assigned to each netdev's ieee80211_ptr for proper operation.
3222 */
3223struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv,
3224 const char *requested_name);
3225
3226/**
3169 * wiphy_new - create a new wiphy for use with cfg80211 3227 * wiphy_new - create a new wiphy for use with cfg80211
3170 * 3228 *
3171 * @ops: The configuration operations for this device 3229 * @ops: The configuration operations for this device
@@ -3177,7 +3235,11 @@ static inline const char *wiphy_name(const struct wiphy *wiphy)
3177 * Return: A pointer to the new wiphy. This pointer must be 3235 * Return: A pointer to the new wiphy. This pointer must be
3178 * assigned to each netdev's ieee80211_ptr for proper operation. 3236 * assigned to each netdev's ieee80211_ptr for proper operation.
3179 */ 3237 */
3180struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv); 3238static inline struct wiphy *wiphy_new(const struct cfg80211_ops *ops,
3239 int sizeof_priv)
3240{
3241 return wiphy_new_nm(ops, sizeof_priv, NULL);
3242}
3181 3243
3182/** 3244/**
3183 * wiphy_register - register a wiphy with cfg80211 3245 * wiphy_register - register a wiphy with cfg80211
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
new file mode 100644
index 000000000000..7f713acfa106
--- /dev/null
+++ b/include/net/cfg802154.h
@@ -0,0 +1,161 @@
1/*
2 * Copyright (C) 2007, 2008, 2009 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * Written by:
14 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
15 */
16
17#ifndef __NET_CFG802154_H
18#define __NET_CFG802154_H
19
20#include <linux/ieee802154.h>
21#include <linux/netdevice.h>
22#include <linux/mutex.h>
23#include <linux/bug.h>
24
25#include <net/nl802154.h>
26
27struct wpan_phy;
28
29struct cfg802154_ops {
30 struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
31 const char *name,
32 int type);
33 void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
34 struct net_device *dev);
35 int (*add_virtual_intf)(struct wpan_phy *wpan_phy,
36 const char *name,
37 enum nl802154_iftype type,
38 __le64 extended_addr);
39 int (*del_virtual_intf)(struct wpan_phy *wpan_phy,
40 struct wpan_dev *wpan_dev);
41 int (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
42 int (*set_pan_id)(struct wpan_phy *wpan_phy,
43 struct wpan_dev *wpan_dev, __le16 pan_id);
44 int (*set_short_addr)(struct wpan_phy *wpan_phy,
45 struct wpan_dev *wpan_dev, __le16 short_addr);
46 int (*set_backoff_exponent)(struct wpan_phy *wpan_phy,
47 struct wpan_dev *wpan_dev, u8 min_be,
48 u8 max_be);
49 int (*set_max_csma_backoffs)(struct wpan_phy *wpan_phy,
50 struct wpan_dev *wpan_dev,
51 u8 max_csma_backoffs);
52 int (*set_max_frame_retries)(struct wpan_phy *wpan_phy,
53 struct wpan_dev *wpan_dev,
54 s8 max_frame_retries);
55 int (*set_lbt_mode)(struct wpan_phy *wpan_phy,
56 struct wpan_dev *wpan_dev, bool mode);
57};
58
59struct wpan_phy {
60 struct mutex pib_lock;
61
62 /* If multiple wpan_phys are registered and you're handed e.g.
63 * a regular netdev with assigned ieee802154_ptr, you won't
64 * know whether it points to a wpan_phy your driver has registered
65 * or not. Assign this to something global to your driver to
66 * help determine whether you own this wpan_phy or not.
67 */
68 const void *privid;
69
70 /*
71 * This is a PIB according to 802.15.4-2011.
72 * We do not provide timing-related variables, as they
73 * aren't used outside of driver
74 */
75 u8 current_channel;
76 u8 current_page;
77 u32 channels_supported[IEEE802154_MAX_PAGE + 1];
78 s8 transmit_power;
79 u8 cca_mode;
80
81 __le64 perm_extended_addr;
82
83 s32 cca_ed_level;
84
85 /* PHY depended MAC PIB values */
86
87 /* 802.15.4 acronym: Tdsym in usec */
88 u8 symbol_duration;
89 /* lifs and sifs periods timing */
90 u16 lifs_period;
91 u16 sifs_period;
92
93 struct device dev;
94
95 char priv[0] __aligned(NETDEV_ALIGN);
96};
97
98struct wpan_dev {
99 struct wpan_phy *wpan_phy;
100 int iftype;
101
102 /* the remainder of this struct should be private to cfg802154 */
103 struct list_head list;
104 struct net_device *netdev;
105
106 u32 identifier;
107
108 /* MAC PIB */
109 __le16 pan_id;
110 __le16 short_addr;
111 __le64 extended_addr;
112
113 /* MAC BSN field */
114 u8 bsn;
115 /* MAC DSN field */
116 u8 dsn;
117
118 u8 min_be;
119 u8 max_be;
120 u8 csma_retries;
121 s8 frame_retries;
122
123 bool lbt;
124
125 bool promiscuous_mode;
126};
127
128#define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
129
130struct wpan_phy *
131wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
132static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
133{
134 phy->dev.parent = dev;
135}
136
137int wpan_phy_register(struct wpan_phy *phy);
138void wpan_phy_unregister(struct wpan_phy *phy);
139void wpan_phy_free(struct wpan_phy *phy);
140/* Same semantics as for class_for_each_device */
141int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
142
143static inline void *wpan_phy_priv(struct wpan_phy *phy)
144{
145 BUG_ON(!phy);
146 return &phy->priv;
147}
148
149struct wpan_phy *wpan_phy_find(const char *str);
150
151static inline void wpan_phy_put(struct wpan_phy *phy)
152{
153 put_device(&phy->dev);
154}
155
156static inline const char *wpan_phy_name(struct wpan_phy *phy)
157{
158 return dev_name(&phy->dev);
159}
160
161#endif /* __NET_CFG802154_H */
diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h
index 3b53c8e405e4..83bb8a73d23c 100644
--- a/include/net/ieee802154_netdev.h
+++ b/include/net/ieee802154_netdev.h
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 16 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
21 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 17 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
@@ -27,10 +23,10 @@
27#ifndef IEEE802154_NETDEVICE_H 23#ifndef IEEE802154_NETDEVICE_H
28#define IEEE802154_NETDEVICE_H 24#define IEEE802154_NETDEVICE_H
29 25
30#include <net/ieee802154.h>
31#include <net/af_ieee802154.h> 26#include <net/af_ieee802154.h>
32#include <linux/netdevice.h> 27#include <linux/netdevice.h>
33#include <linux/skbuff.h> 28#include <linux/skbuff.h>
29#include <linux/ieee802154.h>
34 30
35struct ieee802154_sechdr { 31struct ieee802154_sechdr {
36#if defined(__LITTLE_ENDIAN_BITFIELD) 32#if defined(__LITTLE_ENDIAN_BITFIELD)
@@ -427,8 +423,6 @@ struct ieee802154_mlme_ops {
427 423
428 /* The fields below are required. */ 424 /* The fields below are required. */
429 425
430 struct wpan_phy *(*get_phy)(const struct net_device *dev);
431
432 /* 426 /*
433 * FIXME: these should become the part of PIB/MIB interface. 427 * FIXME: these should become the part of PIB/MIB interface.
434 * However we still don't have IB interface of any kind 428 * However we still don't have IB interface of any kind
@@ -438,16 +432,6 @@ struct ieee802154_mlme_ops {
438 u8 (*get_dsn)(const struct net_device *dev); 432 u8 (*get_dsn)(const struct net_device *dev);
439}; 433};
440 434
441/* The IEEE 802.15.4 standard defines 2 type of the devices:
442 * - FFD - full functionality device
443 * - RFD - reduce functionality device
444 *
445 * So 2 sets of mlme operations are needed
446 */
447struct ieee802154_reduced_mlme_ops {
448 struct wpan_phy *(*get_phy)(const struct net_device *dev);
449};
450
451static inline struct ieee802154_mlme_ops * 435static inline struct ieee802154_mlme_ops *
452ieee802154_mlme_ops(const struct net_device *dev) 436ieee802154_mlme_ops(const struct net_device *dev)
453{ 437{
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 0ad1f47d2dc7..5f203a6a5e7e 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -263,6 +263,7 @@ struct ieee80211_vif_chanctx_switch {
263 * @BSS_CHANGED_BANDWIDTH: The bandwidth used by this interface changed, 263 * @BSS_CHANGED_BANDWIDTH: The bandwidth used by this interface changed,
264 * note that this is only called when it changes after the channel 264 * note that this is only called when it changes after the channel
265 * context had been assigned. 265 * context had been assigned.
266 * @BSS_CHANGED_OCB: OCB join status changed
266 */ 267 */
267enum ieee80211_bss_change { 268enum ieee80211_bss_change {
268 BSS_CHANGED_ASSOC = 1<<0, 269 BSS_CHANGED_ASSOC = 1<<0,
@@ -287,6 +288,7 @@ enum ieee80211_bss_change {
287 BSS_CHANGED_P2P_PS = 1<<19, 288 BSS_CHANGED_P2P_PS = 1<<19,
288 BSS_CHANGED_BEACON_INFO = 1<<20, 289 BSS_CHANGED_BEACON_INFO = 1<<20,
289 BSS_CHANGED_BANDWIDTH = 1<<21, 290 BSS_CHANGED_BANDWIDTH = 1<<21,
291 BSS_CHANGED_OCB = 1<<22,
290 292
291 /* when adding here, make sure to change ieee80211_reconfig */ 293 /* when adding here, make sure to change ieee80211_reconfig */
292}; 294};
@@ -739,7 +741,8 @@ struct ieee80211_tx_info {
739 u8 ampdu_ack_len; 741 u8 ampdu_ack_len;
740 u8 ampdu_len; 742 u8 ampdu_len;
741 u8 antenna; 743 u8 antenna;
742 void *status_driver_data[21 / sizeof(void *)]; 744 u16 tx_time;
745 void *status_driver_data[19 / sizeof(void *)];
743 } status; 746 } status;
744 struct { 747 struct {
745 struct ieee80211_tx_rate driver_rates[ 748 struct ieee80211_tx_rate driver_rates[
@@ -1117,6 +1120,8 @@ struct ieee80211_conf {
1117 * Function (TSF) timer when the frame containing the channel switch 1120 * Function (TSF) timer when the frame containing the channel switch
1118 * announcement was received. This is simply the rx.mactime parameter 1121 * announcement was received. This is simply the rx.mactime parameter
1119 * the driver passed into mac80211. 1122 * the driver passed into mac80211.
1123 * @device_timestamp: arbitrary timestamp for the device, this is the
1124 * rx.device_timestamp parameter the driver passed to mac80211.
1120 * @block_tx: Indicates whether transmission must be blocked before the 1125 * @block_tx: Indicates whether transmission must be blocked before the
1121 * scheduled channel switch, as indicated by the AP. 1126 * scheduled channel switch, as indicated by the AP.
1122 * @chandef: the new channel to switch to 1127 * @chandef: the new channel to switch to
@@ -1124,6 +1129,7 @@ struct ieee80211_conf {
1124 */ 1129 */
1125struct ieee80211_channel_switch { 1130struct ieee80211_channel_switch {
1126 u64 timestamp; 1131 u64 timestamp;
1132 u32 device_timestamp;
1127 bool block_tx; 1133 bool block_tx;
1128 struct cfg80211_chan_def chandef; 1134 struct cfg80211_chan_def chandef;
1129 u8 count; 1135 u8 count;
@@ -1423,6 +1429,8 @@ struct ieee80211_sta_rates {
1423 * @smps_mode: current SMPS mode (off, static or dynamic) 1429 * @smps_mode: current SMPS mode (off, static or dynamic)
1424 * @rates: rate control selection table 1430 * @rates: rate control selection table
1425 * @tdls: indicates whether the STA is a TDLS peer 1431 * @tdls: indicates whether the STA is a TDLS peer
1432 * @tdls_initiator: indicates the STA is an initiator of the TDLS link. Only
1433 * valid if the STA is a TDLS peer in the first place.
1426 */ 1434 */
1427struct ieee80211_sta { 1435struct ieee80211_sta {
1428 u32 supp_rates[IEEE80211_NUM_BANDS]; 1436 u32 supp_rates[IEEE80211_NUM_BANDS];
@@ -1438,6 +1446,7 @@ struct ieee80211_sta {
1438 enum ieee80211_smps_mode smps_mode; 1446 enum ieee80211_smps_mode smps_mode;
1439 struct ieee80211_sta_rates __rcu *rates; 1447 struct ieee80211_sta_rates __rcu *rates;
1440 bool tdls; 1448 bool tdls;
1449 bool tdls_initiator;
1441 1450
1442 /* must be last */ 1451 /* must be last */
1443 u8 drv_priv[0] __aligned(sizeof(void *)); 1452 u8 drv_priv[0] __aligned(sizeof(void *));
@@ -1576,6 +1585,10 @@ struct ieee80211_tx_control {
1576 * a virtual monitor interface when monitor interfaces are the only 1585 * a virtual monitor interface when monitor interfaces are the only
1577 * active interfaces. 1586 * active interfaces.
1578 * 1587 *
1588 * @IEEE80211_HW_NO_AUTO_VIF: The driver would like for no wlanX to
1589 * be created. It is expected user-space will create vifs as
1590 * desired (and thus have them named as desired).
1591 *
1579 * @IEEE80211_HW_QUEUE_CONTROL: The driver wants to control per-interface 1592 * @IEEE80211_HW_QUEUE_CONTROL: The driver wants to control per-interface
1580 * queue mapping in order to use different queues (not just one per AC) 1593 * queue mapping in order to use different queues (not just one per AC)
1581 * for different virtual interfaces. See the doc section on HW queue 1594 * for different virtual interfaces. See the doc section on HW queue
@@ -1622,7 +1635,8 @@ enum ieee80211_hw_flags {
1622 IEEE80211_HW_SUPPORTS_DYNAMIC_PS = 1<<12, 1635 IEEE80211_HW_SUPPORTS_DYNAMIC_PS = 1<<12,
1623 IEEE80211_HW_MFP_CAPABLE = 1<<13, 1636 IEEE80211_HW_MFP_CAPABLE = 1<<13,
1624 IEEE80211_HW_WANT_MONITOR_VIF = 1<<14, 1637 IEEE80211_HW_WANT_MONITOR_VIF = 1<<14,
1625 /* free slots */ 1638 IEEE80211_HW_NO_AUTO_VIF = 1<<15,
1639 /* free slot */
1626 IEEE80211_HW_SUPPORTS_UAPSD = 1<<17, 1640 IEEE80211_HW_SUPPORTS_UAPSD = 1<<17,
1627 IEEE80211_HW_REPORTS_TX_ACK_STATUS = 1<<18, 1641 IEEE80211_HW_REPORTS_TX_ACK_STATUS = 1<<18,
1628 IEEE80211_HW_CONNECTION_MONITOR = 1<<19, 1642 IEEE80211_HW_CONNECTION_MONITOR = 1<<19,
@@ -2375,6 +2389,22 @@ enum ieee80211_roc_type {
2375}; 2389};
2376 2390
2377/** 2391/**
2392 * enum ieee80211_reconfig_complete_type - reconfig type
2393 *
2394 * This enum is used by the reconfig_complete() callback to indicate what
2395 * reconfiguration type was completed.
2396 *
2397 * @IEEE80211_RECONFIG_TYPE_RESTART: hw restart type
2398 * (also due to resume() callback returning 1)
2399 * @IEEE80211_RECONFIG_TYPE_SUSPEND: suspend type (regardless
2400 * of wowlan configuration)
2401 */
2402enum ieee80211_reconfig_type {
2403 IEEE80211_RECONFIG_TYPE_RESTART,
2404 IEEE80211_RECONFIG_TYPE_SUSPEND,
2405};
2406
2407/**
2378 * struct ieee80211_ops - callbacks from mac80211 to the driver 2408 * struct ieee80211_ops - callbacks from mac80211 to the driver
2379 * 2409 *
2380 * This structure contains various callbacks that the driver may 2410 * This structure contains various callbacks that the driver may
@@ -2809,11 +2839,11 @@ enum ieee80211_roc_type {
2809 * disabled/enabled via @bss_info_changed. 2839 * disabled/enabled via @bss_info_changed.
2810 * @stop_ap: Stop operation on the AP interface. 2840 * @stop_ap: Stop operation on the AP interface.
2811 * 2841 *
2812 * @restart_complete: Called after a call to ieee80211_restart_hw(), when the 2842 * @reconfig_complete: Called after a call to ieee80211_restart_hw() and
2813 * reconfiguration has completed. This can help the driver implement the 2843 * during resume, when the reconfiguration has completed.
2814 * reconfiguration step. Also called when reconfiguring because the 2844 * This can help the driver implement the reconfiguration step (and
2815 * driver's resume function returned 1, as this is just like an "inline" 2845 * indicate mac80211 is ready to receive frames).
2816 * hardware restart. This callback may sleep. 2846 * This callback may sleep.
2817 * 2847 *
2818 * @ipv6_addr_change: IPv6 address assignment on the given interface changed. 2848 * @ipv6_addr_change: IPv6 address assignment on the given interface changed.
2819 * Currently, this is only called for managed or P2P client interfaces. 2849 * Currently, this is only called for managed or P2P client interfaces.
@@ -2829,6 +2859,13 @@ enum ieee80211_roc_type {
2829 * transmitted and then call ieee80211_csa_finish(). 2859 * transmitted and then call ieee80211_csa_finish().
2830 * If the CSA count starts as zero or 1, this function will not be called, 2860 * If the CSA count starts as zero or 1, this function will not be called,
2831 * since there won't be any time to beacon before the switch anyway. 2861 * since there won't be any time to beacon before the switch anyway.
2862 * @pre_channel_switch: This is an optional callback that is called
2863 * before a channel switch procedure is started (ie. when a STA
2864 * gets a CSA or an userspace initiated channel-switch), allowing
2865 * the driver to prepare for the channel switch.
2866 * @post_channel_switch: This is an optional callback that is called
2867 * after a channel switch procedure is completed, allowing the
2868 * driver to go back to a normal configuration.
2832 * 2869 *
2833 * @join_ibss: Join an IBSS (on an IBSS interface); this is called after all 2870 * @join_ibss: Join an IBSS (on an IBSS interface); this is called after all
2834 * information in bss_conf is set up and the beacon can be retrieved. A 2871 * information in bss_conf is set up and the beacon can be retrieved. A
@@ -2838,6 +2875,9 @@ enum ieee80211_roc_type {
2838 * @get_expected_throughput: extract the expected throughput towards the 2875 * @get_expected_throughput: extract the expected throughput towards the
2839 * specified station. The returned value is expressed in Kbps. It returns 0 2876 * specified station. The returned value is expressed in Kbps. It returns 0
2840 * if the RC algorithm does not have proper data to provide. 2877 * if the RC algorithm does not have proper data to provide.
2878 *
2879 * @get_txpower: get current maximum tx power (in dBm) based on configuration
2880 * and hardware limits.
2841 */ 2881 */
2842struct ieee80211_ops { 2882struct ieee80211_ops {
2843 void (*tx)(struct ieee80211_hw *hw, 2883 void (*tx)(struct ieee80211_hw *hw,
@@ -2959,6 +2999,7 @@ struct ieee80211_ops {
2959 void (*flush)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2999 void (*flush)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2960 u32 queues, bool drop); 3000 u32 queues, bool drop);
2961 void (*channel_switch)(struct ieee80211_hw *hw, 3001 void (*channel_switch)(struct ieee80211_hw *hw,
3002 struct ieee80211_vif *vif,
2962 struct ieee80211_channel_switch *ch_switch); 3003 struct ieee80211_channel_switch *ch_switch);
2963 int (*set_antenna)(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant); 3004 int (*set_antenna)(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant);
2964 int (*get_antenna)(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant); 3005 int (*get_antenna)(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
@@ -3025,7 +3066,8 @@ struct ieee80211_ops {
3025 int n_vifs, 3066 int n_vifs,
3026 enum ieee80211_chanctx_switch_mode mode); 3067 enum ieee80211_chanctx_switch_mode mode);
3027 3068
3028 void (*restart_complete)(struct ieee80211_hw *hw); 3069 void (*reconfig_complete)(struct ieee80211_hw *hw,
3070 enum ieee80211_reconfig_type reconfig_type);
3029 3071
3030#if IS_ENABLED(CONFIG_IPV6) 3072#if IS_ENABLED(CONFIG_IPV6)
3031 void (*ipv6_addr_change)(struct ieee80211_hw *hw, 3073 void (*ipv6_addr_change)(struct ieee80211_hw *hw,
@@ -3035,14 +3077,42 @@ struct ieee80211_ops {
3035 void (*channel_switch_beacon)(struct ieee80211_hw *hw, 3077 void (*channel_switch_beacon)(struct ieee80211_hw *hw,
3036 struct ieee80211_vif *vif, 3078 struct ieee80211_vif *vif,
3037 struct cfg80211_chan_def *chandef); 3079 struct cfg80211_chan_def *chandef);
3080 int (*pre_channel_switch)(struct ieee80211_hw *hw,
3081 struct ieee80211_vif *vif,
3082 struct ieee80211_channel_switch *ch_switch);
3083
3084 int (*post_channel_switch)(struct ieee80211_hw *hw,
3085 struct ieee80211_vif *vif);
3038 3086
3039 int (*join_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 3087 int (*join_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
3040 void (*leave_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 3088 void (*leave_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
3041 u32 (*get_expected_throughput)(struct ieee80211_sta *sta); 3089 u32 (*get_expected_throughput)(struct ieee80211_sta *sta);
3090 int (*get_txpower)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3091 int *dbm);
3042}; 3092};
3043 3093
3044/** 3094/**
3045 * ieee80211_alloc_hw - Allocate a new hardware device 3095 * ieee80211_alloc_hw_nm - Allocate a new hardware device
3096 *
3097 * This must be called once for each hardware device. The returned pointer
3098 * must be used to refer to this device when calling other functions.
3099 * mac80211 allocates a private data area for the driver pointed to by
3100 * @priv in &struct ieee80211_hw, the size of this area is given as
3101 * @priv_data_len.
3102 *
3103 * @priv_data_len: length of private data
3104 * @ops: callbacks for this device
3105 * @requested_name: Requested name for this device.
3106 * NULL is valid value, and means use the default naming (phy%d)
3107 *
3108 * Return: A pointer to the new hardware device, or %NULL on error.
3109 */
3110struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
3111 const struct ieee80211_ops *ops,
3112 const char *requested_name);
3113
3114/**
3115 * ieee80211_alloc_hw - Allocate a new hardware device
3046 * 3116 *
3047 * This must be called once for each hardware device. The returned pointer 3117 * This must be called once for each hardware device. The returned pointer
3048 * must be used to refer to this device when calling other functions. 3118 * must be used to refer to this device when calling other functions.
@@ -3055,8 +3125,12 @@ struct ieee80211_ops {
3055 * 3125 *
3056 * Return: A pointer to the new hardware device, or %NULL on error. 3126 * Return: A pointer to the new hardware device, or %NULL on error.
3057 */ 3127 */
3128static inline
3058struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 3129struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
3059 const struct ieee80211_ops *ops); 3130 const struct ieee80211_ops *ops)
3131{
3132 return ieee80211_alloc_hw_nm(priv_data_len, ops, NULL);
3133}
3060 3134
3061/** 3135/**
3062 * ieee80211_register_hw - Register hardware device 3136 * ieee80211_register_hw - Register hardware device
@@ -4172,6 +4246,22 @@ void ieee80211_iterate_active_interfaces_rtnl(struct ieee80211_hw *hw,
4172 void *data); 4246 void *data);
4173 4247
4174/** 4248/**
4249 * ieee80211_iterate_stations_atomic - iterate stations
4250 *
4251 * This function iterates over all stations associated with a given
4252 * hardware that are currently uploaded to the driver and calls the callback
4253 * function for them.
4254 * This function requires the iterator callback function to be atomic,
4255 *
4256 * @hw: the hardware struct of which the interfaces should be iterated over
4257 * @iterator: the iterator function to call, cannot sleep
4258 * @data: first argument of the iterator function
4259 */
4260void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
4261 void (*iterator)(void *data,
4262 struct ieee80211_sta *sta),
4263 void *data);
4264/**
4175 * ieee80211_queue_work - add work onto the mac80211 workqueue 4265 * ieee80211_queue_work - add work onto the mac80211 workqueue
4176 * 4266 *
4177 * Drivers and mac80211 use this to add work onto the mac80211 workqueue. 4267 * Drivers and mac80211 use this to add work onto the mac80211 workqueue.
@@ -4888,4 +4978,32 @@ void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf);
4888void ieee80211_tdls_oper_request(struct ieee80211_vif *vif, const u8 *peer, 4978void ieee80211_tdls_oper_request(struct ieee80211_vif *vif, const u8 *peer,
4889 enum nl80211_tdls_operation oper, 4979 enum nl80211_tdls_operation oper,
4890 u16 reason_code, gfp_t gfp); 4980 u16 reason_code, gfp_t gfp);
4981
4982/**
4983 * ieee80211_ie_split - split an IE buffer according to ordering
4984 *
4985 * @ies: the IE buffer
4986 * @ielen: the length of the IE buffer
4987 * @ids: an array with element IDs that are allowed before
4988 * the split
4989 * @n_ids: the size of the element ID array
4990 * @offset: offset where to start splitting in the buffer
4991 *
4992 * This function splits an IE buffer by updating the @offset
4993 * variable to point to the location where the buffer should be
4994 * split.
4995 *
4996 * It assumes that the given IE buffer is well-formed, this
4997 * has to be guaranteed by the caller!
4998 *
4999 * It also assumes that the IEs in the buffer are ordered
5000 * correctly, if not the result of using this function will not
5001 * be ordered correctly either, i.e. it does no reordering.
5002 *
5003 * The function returns the offset where the next part of the
5004 * buffer starts, which may be @ielen if the entire (remainder)
5005 * of the buffer should be used.
5006 */
5007size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
5008 const u8 *ids, int n_ids, size_t offset);
4891#endif /* MAC80211_H */ 5009#endif /* MAC80211_H */
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 2e67cdd19cdc..c823d910b46c 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -12,14 +12,12 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */ 15 */
19#ifndef NET_MAC802154_H 16#ifndef NET_MAC802154_H
20#define NET_MAC802154_H 17#define NET_MAC802154_H
21 18
22#include <net/af_ieee802154.h> 19#include <net/af_ieee802154.h>
20#include <linux/ieee802154.h>
23#include <linux/skbuff.h> 21#include <linux/skbuff.h>
24 22
25/* General MAC frame format: 23/* General MAC frame format:
@@ -35,13 +33,13 @@
35 */ 33 */
36 34
37/* indicates that the Short Address changed */ 35/* indicates that the Short Address changed */
38#define IEEE802515_AFILT_SADDR_CHANGED 0x00000001 36#define IEEE802154_AFILT_SADDR_CHANGED 0x00000001
39/* indicates that the IEEE Address changed */ 37/* indicates that the IEEE Address changed */
40#define IEEE802515_AFILT_IEEEADDR_CHANGED 0x00000002 38#define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002
41/* indicates that the PAN ID changed */ 39/* indicates that the PAN ID changed */
42#define IEEE802515_AFILT_PANID_CHANGED 0x00000004 40#define IEEE802154_AFILT_PANID_CHANGED 0x00000004
43/* indicates that PAN Coordinator status changed */ 41/* indicates that PAN Coordinator status changed */
44#define IEEE802515_AFILT_PANC_CHANGED 0x00000008 42#define IEEE802154_AFILT_PANC_CHANGED 0x00000008
45 43
46struct ieee802154_hw_addr_filt { 44struct ieee802154_hw_addr_filt {
47 __le16 pan_id; /* Each independent PAN selects a unique 45 __le16 pan_id; /* Each independent PAN selects a unique
@@ -55,7 +53,14 @@ struct ieee802154_hw_addr_filt {
55 u8 pan_coord; 53 u8 pan_coord;
56}; 54};
57 55
58struct ieee802154_dev { 56struct ieee802154_vif {
57 int type;
58
59 /* must be last */
60 u8 drv_priv[0] __aligned(sizeof(void *));
61};
62
63struct ieee802154_hw {
59 /* filled by the driver */ 64 /* filled by the driver */
60 int extra_tx_headroom; 65 int extra_tx_headroom;
61 u32 flags; 66 u32 flags;
@@ -65,6 +70,7 @@ struct ieee802154_dev {
65 struct ieee802154_hw_addr_filt hw_filt; 70 struct ieee802154_hw_addr_filt hw_filt;
66 void *priv; 71 void *priv;
67 struct wpan_phy *phy; 72 struct wpan_phy *phy;
73 size_t vif_data_size;
68}; 74};
69 75
70/* Checksum is in hardware and is omitted from a packet 76/* Checksum is in hardware and is omitted from a packet
@@ -76,28 +82,43 @@ struct ieee802154_dev {
76 * however, so you are advised to review these flags carefully. 82 * however, so you are advised to review these flags carefully.
77 */ 83 */
78 84
79/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */ 85/* Indicates that xmitter will add FCS on it's own. */
80#define IEEE802154_HW_OMIT_CKSUM 0x00000001 86#define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001
81/* Indicates that receiver will autorespond with ACK frames. */ 87/* Indicates that receiver will autorespond with ACK frames. */
82#define IEEE802154_HW_AACK 0x00000002 88#define IEEE802154_HW_AACK 0x00000002
83/* Indicates that transceiver will support transmit power setting. */ 89/* Indicates that transceiver will support transmit power setting. */
84#define IEEE802154_HW_TXPOWER 0x00000004 90#define IEEE802154_HW_TXPOWER 0x00000004
85/* Indicates that transceiver will support listen before transmit. */ 91/* Indicates that transceiver will support listen before transmit. */
86#define IEEE802154_HW_LBT 0x00000008 92#define IEEE802154_HW_LBT 0x00000008
87/* Indicates that transceiver will support cca mode setting. */ 93/* Indicates that transceiver will support cca mode setting. */
88#define IEEE802154_HW_CCA_MODE 0x00000010 94#define IEEE802154_HW_CCA_MODE 0x00000010
89/* Indicates that transceiver will support cca ed level setting. */ 95/* Indicates that transceiver will support cca ed level setting. */
90#define IEEE802154_HW_CCA_ED_LEVEL 0x00000020 96#define IEEE802154_HW_CCA_ED_LEVEL 0x00000020
91/* Indicates that transceiver will support csma (max_be, min_be, csma retries) 97/* Indicates that transceiver will support csma (max_be, min_be, csma retries)
92 * settings. */ 98 * settings. */
93#define IEEE802154_HW_CSMA_PARAMS 0x00000040 99#define IEEE802154_HW_CSMA_PARAMS 0x00000040
94/* Indicates that transceiver will support ARET frame retries setting. */ 100/* Indicates that transceiver will support ARET frame retries setting. */
95#define IEEE802154_HW_FRAME_RETRIES 0x00000080 101#define IEEE802154_HW_FRAME_RETRIES 0x00000080
102/* Indicates that transceiver will support hardware address filter setting. */
103#define IEEE802154_HW_AFILT 0x00000100
104/* Indicates that transceiver will support promiscuous mode setting. */
105#define IEEE802154_HW_PROMISCUOUS 0x00000200
106/* Indicates that receiver omits FCS. */
107#define IEEE802154_HW_RX_OMIT_CKSUM 0x00000400
108/* Indicates that receiver will not filter frames with bad checksum. */
109#define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000800
110
111/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
112#define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \
113 IEEE802154_HW_RX_OMIT_CKSUM)
96 114
97/* This groups the most common CSMA support fields into one. */ 115/* This groups the most common CSMA support fields into one. */
98#define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \ 116#define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \
99 IEEE802154_HW_CCA_ED_LEVEL | \ 117 IEEE802154_HW_CCA_ED_LEVEL | \
100 IEEE802154_HW_CSMA_PARAMS | \ 118 IEEE802154_HW_CSMA_PARAMS)
119
120/* This groups the most common ARET support fields into one. */
121#define IEEE802154_HW_ARET (IEEE802154_HW_CSMA | \
101 IEEE802154_HW_FRAME_RETRIES) 122 IEEE802154_HW_FRAME_RETRIES)
102 123
103/* struct ieee802154_ops - callbacks from mac802154 to the driver 124/* struct ieee802154_ops - callbacks from mac802154 to the driver
@@ -112,12 +133,24 @@ struct ieee802154_dev {
112 * stop: Handler that 802.15.4 module calls for device cleanup. 133 * stop: Handler that 802.15.4 module calls for device cleanup.
113 * This function is called after the last interface is removed. 134 * This function is called after the last interface is removed.
114 * 135 *
115 * xmit: Handler that 802.15.4 module calls for each transmitted frame. 136 * xmit_sync:
137 * Handler that 802.15.4 module calls for each transmitted frame.
138 * skb cntains the buffer starting from the IEEE 802.15.4 header.
139 * The low-level driver should send the frame based on available
140 * configuration. This is called by a workqueue and useful for
141 * synchronous 802.15.4 drivers.
142 * This function should return zero or negative errno.
143 *
144 * WARNING:
145 * This will be deprecated soon. We don't accept synced xmit callbacks
146 * drivers anymore.
147 *
148 * xmit_async:
149 * Handler that 802.15.4 module calls for each transmitted frame.
116 * skb cntains the buffer starting from the IEEE 802.15.4 header. 150 * skb cntains the buffer starting from the IEEE 802.15.4 header.
117 * The low-level driver should send the frame based on available 151 * The low-level driver should send the frame based on available
118 * configuration. 152 * configuration.
119 * This function should return zero or negative errno. Called with 153 * This function should return zero or negative errno.
120 * pib_lock held.
121 * 154 *
122 * ed: Handler that 802.15.4 module calls for Energy Detection. 155 * ed: Handler that 802.15.4 module calls for Energy Detection.
123 * This function should place the value for detected energy 156 * This function should place the value for detected energy
@@ -159,40 +192,75 @@ struct ieee802154_dev {
159 * set_frame_retries 192 * set_frame_retries
160 * Sets the retransmission attempt limit. Called with pib_lock held. 193 * Sets the retransmission attempt limit. Called with pib_lock held.
161 * Returns either zero, or negative errno. 194 * Returns either zero, or negative errno.
195 *
196 * set_promiscuous_mode
197 * Enables or disable promiscuous mode.
162 */ 198 */
163struct ieee802154_ops { 199struct ieee802154_ops {
164 struct module *owner; 200 struct module *owner;
165 int (*start)(struct ieee802154_dev *dev); 201 int (*start)(struct ieee802154_hw *hw);
166 void (*stop)(struct ieee802154_dev *dev); 202 void (*stop)(struct ieee802154_hw *hw);
167 int (*xmit)(struct ieee802154_dev *dev, 203 int (*xmit_sync)(struct ieee802154_hw *hw,
168 struct sk_buff *skb); 204 struct sk_buff *skb);
169 int (*ed)(struct ieee802154_dev *dev, u8 *level); 205 int (*xmit_async)(struct ieee802154_hw *hw,
170 int (*set_channel)(struct ieee802154_dev *dev, 206 struct sk_buff *skb);
171 int page, 207 int (*ed)(struct ieee802154_hw *hw, u8 *level);
172 int channel); 208 int (*set_channel)(struct ieee802154_hw *hw, u8 page,
173 int (*set_hw_addr_filt)(struct ieee802154_dev *dev, 209 u8 channel);
174 struct ieee802154_hw_addr_filt *filt, 210 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
211 struct ieee802154_hw_addr_filt *filt,
175 unsigned long changed); 212 unsigned long changed);
176 int (*ieee_addr)(struct ieee802154_dev *dev, __le64 addr); 213 int (*set_txpower)(struct ieee802154_hw *hw, int db);
177 int (*set_txpower)(struct ieee802154_dev *dev, int db); 214 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
178 int (*set_lbt)(struct ieee802154_dev *dev, bool on); 215 int (*set_cca_mode)(struct ieee802154_hw *hw, u8 mode);
179 int (*set_cca_mode)(struct ieee802154_dev *dev, u8 mode); 216 int (*set_cca_ed_level)(struct ieee802154_hw *hw,
180 int (*set_cca_ed_level)(struct ieee802154_dev *dev,
181 s32 level); 217 s32 level);
182 int (*set_csma_params)(struct ieee802154_dev *dev, 218 int (*set_csma_params)(struct ieee802154_hw *hw,
183 u8 min_be, u8 max_be, u8 retries); 219 u8 min_be, u8 max_be, u8 retries);
184 int (*set_frame_retries)(struct ieee802154_dev *dev, 220 int (*set_frame_retries)(struct ieee802154_hw *hw,
185 s8 retries); 221 s8 retries);
222 int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
223 const bool on);
186}; 224};
187 225
188/* Basic interface to register ieee802154 device */ 226/**
189struct ieee802154_dev * 227 * ieee802154_be64_to_le64 - copies and convert be64 to le64
190ieee802154_alloc_device(size_t priv_data_len, struct ieee802154_ops *ops); 228 * @le64_dst: le64 destination pointer
191void ieee802154_free_device(struct ieee802154_dev *dev); 229 * @be64_src: be64 source pointer
192int ieee802154_register_device(struct ieee802154_dev *dev); 230 */
193void ieee802154_unregister_device(struct ieee802154_dev *dev); 231static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
232{
233 __le64 tmp = (__force __le64)swab64p(be64_src);
234
235 memcpy(le64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
236}
194 237
195void ieee802154_rx_irqsafe(struct ieee802154_dev *dev, struct sk_buff *skb, 238/**
239 * ieee802154_le64_to_be64 - copies and convert le64 to be64
240 * @be64_dst: be64 destination pointer
241 * @le64_src: le64 source pointer
242 */
243static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
244{
245 __be64 tmp = (__force __be64)swab64p(le64_src);
246
247 memcpy(be64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
248}
249
250/* Basic interface to register ieee802154 hwice */
251struct ieee802154_hw *
252ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
253void ieee802154_free_hw(struct ieee802154_hw *hw);
254int ieee802154_register_hw(struct ieee802154_hw *hw);
255void ieee802154_unregister_hw(struct ieee802154_hw *hw);
256
257void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
258void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
196 u8 lqi); 259 u8 lqi);
197 260
261void ieee802154_wake_queue(struct ieee802154_hw *hw);
262void ieee802154_stop_queue(struct ieee802154_hw *hw);
263void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
264 bool ifs_handling);
265
198#endif /* NET_MAC802154_H */ 266#endif /* NET_MAC802154_H */
diff --git a/include/net/nl802154.h b/include/net/nl802154.h
index b23548e04098..6dbd406ca41b 100644
--- a/include/net/nl802154.h
+++ b/include/net/nl802154.h
@@ -1,126 +1,122 @@
1#ifndef __NL802154_H
2#define __NL802154_H
1/* 3/*
2 * nl802154.h 4 * 802.15.4 netlink interface public header
3 * 5 *
4 * Copyright (C) 2007, 2008, 2009 Siemens AG 6 * Copyright 2014 Alexander Aring <aar@pengutronix.de>
5 * 7 *
6 * This program is free software; you can redistribute it and/or modify 8 * Permission to use, copy, modify, and/or distribute this software for any
7 * it under the terms of the GNU General Public License version 2 9 * purpose with or without fee is hereby granted, provided that the above
8 * as published by the Free Software Foundation. 10 * copyright notice and this permission notice appear in all copies.
9 * 11 *
10 * This program is distributed in the hope that it will be useful, 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * GNU General Public License for more details. 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * You should have received a copy of the GNU General Public License along 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * with this program; if not, write to the Free Software Foundation, Inc., 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 19 *
19 */ 20 */
20 21
21#ifndef IEEE802154_NL_H 22#define NL802154_GENL_NAME "nl802154"
22#define IEEE802154_NL_H
23 23
24struct net_device; 24enum nl802154_commands {
25struct ieee802154_addr; 25/* don't change the order or add anything between, this is ABI! */
26/* currently we don't shipping this file via uapi, ignore the above one */
27 NL802154_CMD_UNSPEC,
26 28
27/** 29 NL802154_CMD_GET_WPAN_PHY, /* can dump */
28 * ieee802154_nl_assoc_indic - Notify userland of an association request. 30 NL802154_CMD_SET_WPAN_PHY,
29 * @dev: The network device on which this association request was 31 NL802154_CMD_NEW_WPAN_PHY,
30 * received. 32 NL802154_CMD_DEL_WPAN_PHY,
31 * @addr: The address of the device requesting association.
32 * @cap: The capability information field from the device.
33 *
34 * This informs a userland coordinator of a device requesting to
35 * associate with the PAN controlled by the coordinator.
36 *
37 * Note: This is in section 7.3.1 of the IEEE 802.15.4-2006 document.
38 */
39int ieee802154_nl_assoc_indic(struct net_device *dev,
40 struct ieee802154_addr *addr, u8 cap);
41
42/**
43 * ieee802154_nl_assoc_confirm - Notify userland of association.
44 * @dev: The device which has completed association.
45 * @short_addr: The short address assigned to the device.
46 * @status: The status of the association.
47 *
48 * Inform userland of the result of an association request. If the
49 * association request included asking the coordinator to allocate
50 * a short address then it is returned in @short_addr.
51 *
52 * Note: This is in section 7.3.2 of the IEEE 802.15.4 document.
53 */
54int ieee802154_nl_assoc_confirm(struct net_device *dev,
55 __le16 short_addr, u8 status);
56
57/**
58 * ieee802154_nl_disassoc_indic - Notify userland of disassociation.
59 * @dev: The device on which disassociation was indicated.
60 * @addr: The device which is disassociating.
61 * @reason: The reason for the disassociation.
62 *
63 * Inform userland that a device has disassociated from the network.
64 *
65 * Note: This is in section 7.3.3 of the IEEE 802.15.4 document.
66 */
67int ieee802154_nl_disassoc_indic(struct net_device *dev,
68 struct ieee802154_addr *addr, u8 reason);
69
70/**
71 * ieee802154_nl_disassoc_confirm - Notify userland of disassociation
72 * completion.
73 * @dev: The device on which disassociation was ordered.
74 * @status: The result of the disassociation.
75 *
76 * Inform userland of the result of requesting that a device
77 * disassociate, or the result of requesting that we disassociate from
78 * a PAN managed by another coordinator.
79 *
80 * Note: This is in section 7.1.4.3 of the IEEE 802.15.4 document.
81 */
82int ieee802154_nl_disassoc_confirm(struct net_device *dev,
83 u8 status);
84
85/**
86 * ieee802154_nl_scan_confirm - Notify userland of completion of scan.
87 * @dev: The device which was instructed to scan.
88 * @status: The status of the scan operation.
89 * @scan_type: What type of scan was performed.
90 * @unscanned: Any channels that the device was unable to scan.
91 * @edl: The energy levels (if a passive scan).
92 *
93 *
94 * Note: This is in section 7.1.11 of the IEEE 802.15.4 document.
95 * Note: This API does not permit the return of an active scan result.
96 */
97int ieee802154_nl_scan_confirm(struct net_device *dev,
98 u8 status, u8 scan_type, u32 unscanned, u8 page,
99 u8 *edl/*, struct list_head *pan_desc_list */);
100
101/**
102 * ieee802154_nl_beacon_indic - Notify userland of a received beacon.
103 * @dev: The device on which a beacon was received.
104 * @panid: The PAN of the coordinator.
105 * @coord_addr: The short address of the coordinator on that PAN.
106 *
107 * Note: This is in section 7.1.5 of the IEEE 802.15.4 document.
108 * Note: This API does not provide extended information such as what
109 * channel the PAN is on or what the LQI of the beacon frame was on
110 * receipt.
111 * Note: This API cannot indicate a beacon frame for a coordinator
112 * operating in long addressing mode.
113 */
114int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
115 __le16 coord_addr);
116 33
117/** 34 NL802154_CMD_GET_INTERFACE, /* can dump */
118 * ieee802154_nl_start_confirm - Notify userland of completion of start. 35 NL802154_CMD_SET_INTERFACE,
119 * @dev: The device which was instructed to scan. 36 NL802154_CMD_NEW_INTERFACE,
120 * @status: The status of the scan operation. 37 NL802154_CMD_DEL_INTERFACE,
121 * 38
122 * Note: This is in section 7.1.14 of the IEEE 802.15.4 document. 39 NL802154_CMD_SET_CHANNEL,
123 */ 40
124int ieee802154_nl_start_confirm(struct net_device *dev, u8 status); 41 NL802154_CMD_SET_PAN_ID,
42 NL802154_CMD_SET_SHORT_ADDR,
43
44 NL802154_CMD_SET_TX_POWER,
45 NL802154_CMD_SET_CCA_MODE,
46 NL802154_CMD_SET_CCA_ED_LEVEL,
47
48 NL802154_CMD_SET_MAX_FRAME_RETRIES,
49
50 NL802154_CMD_SET_BACKOFF_EXPONENT,
51 NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
52
53 NL802154_CMD_SET_LBT_MODE,
54
55 /* add new commands above here */
56
57 /* used to define NL802154_CMD_MAX below */
58 __NL802154_CMD_AFTER_LAST,
59 NL802154_CMD_MAX = __NL802154_CMD_AFTER_LAST - 1
60};
61
62enum nl802154_attrs {
63/* don't change the order or add anything between, this is ABI! */
64/* currently we don't shipping this file via uapi, ignore the above one */
65 NL802154_ATTR_UNSPEC,
66
67 NL802154_ATTR_WPAN_PHY,
68 NL802154_ATTR_WPAN_PHY_NAME,
69
70 NL802154_ATTR_IFINDEX,
71 NL802154_ATTR_IFNAME,
72 NL802154_ATTR_IFTYPE,
73
74 NL802154_ATTR_WPAN_DEV,
75
76 NL802154_ATTR_PAGE,
77 NL802154_ATTR_CHANNEL,
78
79 NL802154_ATTR_PAN_ID,
80 NL802154_ATTR_SHORT_ADDR,
81
82 NL802154_ATTR_TX_POWER,
83
84 NL802154_ATTR_CCA_MODE,
85 NL802154_ATTR_CCA_MODE3_AND,
86 NL802154_ATTR_CCA_ED_LEVEL,
87
88 NL802154_ATTR_MAX_FRAME_RETRIES,
89
90 NL802154_ATTR_MAX_BE,
91 NL802154_ATTR_MIN_BE,
92 NL802154_ATTR_MAX_CSMA_BACKOFFS,
93
94 NL802154_ATTR_LBT_MODE,
95
96 NL802154_ATTR_GENERATION,
97
98 NL802154_ATTR_CHANNELS_SUPPORTED,
99 NL802154_ATTR_SUPPORTED_CHANNEL,
100
101 NL802154_ATTR_EXTENDED_ADDR,
102
103 /* add attributes here, update the policy in nl802154.c */
104
105 __NL802154_ATTR_AFTER_LAST,
106 NL802154_ATTR_MAX = __NL802154_ATTR_AFTER_LAST - 1
107};
108
109enum nl802154_iftype {
110 /* for backwards compatibility TODO */
111 NL802154_IFTYPE_UNSPEC = -1,
112
113 NL802154_IFTYPE_NODE,
114 NL802154_IFTYPE_MONITOR,
115 NL802154_IFTYPE_COORD,
116
117 /* keep last */
118 NUM_NL802154_IFTYPES,
119 NL802154_IFTYPE_MAX = NUM_NL802154_IFTYPES - 1
120};
125 121
126#endif 122#endif /* __NL802154_H */
diff --git a/include/net/wpan-phy.h b/include/net/wpan-phy.h
deleted file mode 100644
index 10ab0fc6d4f7..000000000000
--- a/include/net/wpan-phy.h
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * Copyright (C) 2007, 2008, 2009 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by:
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 */
20
21#ifndef WPAN_PHY_H
22#define WPAN_PHY_H
23
24#include <linux/netdevice.h>
25#include <linux/mutex.h>
26#include <linux/bug.h>
27
28/* According to the IEEE 802.15.4 stadard the upper most significant bits of
29 * the 32-bit channel bitmaps shall be used as an integer value to specify 32
30 * possible channel pages. The lower 27 bits of the channel bit map shall be
31 * used as a bit mask to specify channel numbers within a channel page.
32 */
33#define WPAN_NUM_CHANNELS 27
34#define WPAN_NUM_PAGES 32
35
36struct wpan_phy {
37 struct mutex pib_lock;
38
39 /*
40 * This is a PIB according to 802.15.4-2011.
41 * We do not provide timing-related variables, as they
42 * aren't used outside of driver
43 */
44 u8 current_channel;
45 u8 current_page;
46 u32 channels_supported[32];
47 s8 transmit_power;
48 u8 cca_mode;
49 u8 min_be;
50 u8 max_be;
51 u8 csma_retries;
52 s8 frame_retries;
53
54 bool lbt;
55 s32 cca_ed_level;
56
57 struct device dev;
58 int idx;
59
60 struct net_device *(*add_iface)(struct wpan_phy *phy,
61 const char *name, int type);
62 void (*del_iface)(struct wpan_phy *phy, struct net_device *dev);
63
64 int (*set_txpower)(struct wpan_phy *phy, int db);
65 int (*set_lbt)(struct wpan_phy *phy, bool on);
66 int (*set_cca_mode)(struct wpan_phy *phy, u8 cca_mode);
67 int (*set_cca_ed_level)(struct wpan_phy *phy, int level);
68 int (*set_csma_params)(struct wpan_phy *phy, u8 min_be, u8 max_be,
69 u8 retries);
70 int (*set_frame_retries)(struct wpan_phy *phy, s8 retries);
71
72 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
73};
74
75#define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
76
77struct wpan_phy *wpan_phy_alloc(size_t priv_size);
78static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
79{
80 phy->dev.parent = dev;
81}
82int wpan_phy_register(struct wpan_phy *phy);
83void wpan_phy_unregister(struct wpan_phy *phy);
84void wpan_phy_free(struct wpan_phy *phy);
85/* Same semantics as for class_for_each_device */
86int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
87
88static inline void *wpan_phy_priv(struct wpan_phy *phy)
89{
90 BUG_ON(!phy);
91 return &phy->priv;
92}
93
94struct wpan_phy *wpan_phy_find(const char *str);
95
96static inline void wpan_phy_put(struct wpan_phy *phy)
97{
98 put_device(&phy->dev);
99}
100
101static inline const char *wpan_phy_name(struct wpan_phy *phy)
102{
103 return dev_name(&phy->dev);
104}
105#endif
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 4b28dc07bcb1..9b3025e4377a 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -227,7 +227,11 @@
227 * the interface identified by %NL80211_ATTR_IFINDEX. 227 * the interface identified by %NL80211_ATTR_IFINDEX.
228 * @NL80211_CMD_DEL_STATION: Remove a station identified by %NL80211_ATTR_MAC 228 * @NL80211_CMD_DEL_STATION: Remove a station identified by %NL80211_ATTR_MAC
229 * or, if no MAC address given, all stations, on the interface identified 229 * or, if no MAC address given, all stations, on the interface identified
230 * by %NL80211_ATTR_IFINDEX. 230 * by %NL80211_ATTR_IFINDEX. %NL80211_ATTR_MGMT_SUBTYPE and
231 * %NL80211_ATTR_REASON_CODE can optionally be used to specify which type
232 * of disconnection indication should be sent to the station
233 * (Deauthentication or Disassociation frame and reason code for that
234 * frame).
231 * 235 *
232 * @NL80211_CMD_GET_MPATH: Get mesh path attributes for mesh path to 236 * @NL80211_CMD_GET_MPATH: Get mesh path attributes for mesh path to
233 * destination %NL80211_ATTR_MAC on the interface identified by 237 * destination %NL80211_ATTR_MAC on the interface identified by
@@ -738,6 +742,15 @@
738 * before removing a station entry entirely, or before disassociating 742 * before removing a station entry entirely, or before disassociating
739 * or similar, cleanup will happen in the driver/device in this case. 743 * or similar, cleanup will happen in the driver/device in this case.
740 * 744 *
745 * @NL80211_CMD_GET_MPP: Get mesh path attributes for mesh proxy path to
746 * destination %NL80211_ATTR_MAC on the interface identified by
747 * %NL80211_ATTR_IFINDEX.
748 *
749 * @NL80211_CMD_JOIN_OCB: Join the OCB network. The center frequency and
750 * bandwidth of a channel must be given.
751 * @NL80211_CMD_LEAVE_OCB: Leave the OCB network -- no special arguments, the
752 * network is determined by the network interface.
753 *
741 * @NL80211_CMD_MAX: highest used command number 754 * @NL80211_CMD_MAX: highest used command number
742 * @__NL80211_CMD_AFTER_LAST: internal use 755 * @__NL80211_CMD_AFTER_LAST: internal use
743 */ 756 */
@@ -912,6 +925,11 @@ enum nl80211_commands {
912 NL80211_CMD_ADD_TX_TS, 925 NL80211_CMD_ADD_TX_TS,
913 NL80211_CMD_DEL_TX_TS, 926 NL80211_CMD_DEL_TX_TS,
914 927
928 NL80211_CMD_GET_MPP,
929
930 NL80211_CMD_JOIN_OCB,
931 NL80211_CMD_LEAVE_OCB,
932
915 /* add new commands above here */ 933 /* add new commands above here */
916 934
917 /* used to define NL80211_CMD_MAX below */ 935 /* used to define NL80211_CMD_MAX below */
@@ -2064,6 +2082,8 @@ enum nl80211_attrs {
2064 * and therefore can't be created in the normal ways, use the 2082 * and therefore can't be created in the normal ways, use the
2065 * %NL80211_CMD_START_P2P_DEVICE and %NL80211_CMD_STOP_P2P_DEVICE 2083 * %NL80211_CMD_START_P2P_DEVICE and %NL80211_CMD_STOP_P2P_DEVICE
2066 * commands to create and destroy one 2084 * commands to create and destroy one
2085 * @NL80211_IF_TYPE_OCB: Outside Context of a BSS
2086 * This mode corresponds to the MIB variable dot11OCBActivated=true
2067 * @NL80211_IFTYPE_MAX: highest interface type number currently defined 2087 * @NL80211_IFTYPE_MAX: highest interface type number currently defined
2068 * @NUM_NL80211_IFTYPES: number of defined interface types 2088 * @NUM_NL80211_IFTYPES: number of defined interface types
2069 * 2089 *
@@ -2083,6 +2103,7 @@ enum nl80211_iftype {
2083 NL80211_IFTYPE_P2P_CLIENT, 2103 NL80211_IFTYPE_P2P_CLIENT,
2084 NL80211_IFTYPE_P2P_GO, 2104 NL80211_IFTYPE_P2P_GO,
2085 NL80211_IFTYPE_P2P_DEVICE, 2105 NL80211_IFTYPE_P2P_DEVICE,
2106 NL80211_IFTYPE_OCB,
2086 2107
2087 /* keep last */ 2108 /* keep last */
2088 NUM_NL80211_IFTYPES, 2109 NUM_NL80211_IFTYPES,
@@ -4042,6 +4063,13 @@ enum nl80211_ap_sme_features {
4042 * multiplexing powersave, ie. can turn off all but one chain 4063 * multiplexing powersave, ie. can turn off all but one chain
4043 * and then wake the rest up as required after, for example, 4064 * and then wake the rest up as required after, for example,
4044 * rts/cts handshake. 4065 * rts/cts handshake.
4066 * @NL80211_FEATURE_SUPPORTS_WMM_ADMISSION: the device supports setting up WMM
4067 * TSPEC sessions (TID aka TSID 0-7) with the %NL80211_CMD_ADD_TX_TS
4068 * command. Standard IEEE 802.11 TSPEC setup is not yet supported, it
4069 * needs to be able to handle Block-Ack agreements and other things.
4070 * @NL80211_FEATURE_MAC_ON_CREATE: Device supports configuring
4071 * the vif's MAC address upon creation.
4072 * See 'macaddr' field in the vif_params (cfg80211.h).
4045 */ 4073 */
4046enum nl80211_feature_flags { 4074enum nl80211_feature_flags {
4047 NL80211_FEATURE_SK_TX_STATUS = 1 << 0, 4075 NL80211_FEATURE_SK_TX_STATUS = 1 << 0,
@@ -4070,6 +4098,8 @@ enum nl80211_feature_flags {
4070 NL80211_FEATURE_ACKTO_ESTIMATION = 1 << 23, 4098 NL80211_FEATURE_ACKTO_ESTIMATION = 1 << 23,
4071 NL80211_FEATURE_STATIC_SMPS = 1 << 24, 4099 NL80211_FEATURE_STATIC_SMPS = 1 << 24,
4072 NL80211_FEATURE_DYNAMIC_SMPS = 1 << 25, 4100 NL80211_FEATURE_DYNAMIC_SMPS = 1 << 25,
4101 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION = 1 << 26,
4102 NL80211_FEATURE_MAC_ON_CREATE = 1 << 27,
4073}; 4103};
4074 4104
4075/** 4105/**
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
index 142eef55c9e2..aced97db62f0 100644
--- a/net/6lowpan/iphc.c
+++ b/net/6lowpan/iphc.c
@@ -171,37 +171,6 @@ static int uncompress_context_based_src_addr(struct sk_buff *skb,
171 return 0; 171 return 0;
172} 172}
173 173
174static int skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr,
175 struct net_device *dev, skb_delivery_cb deliver_skb)
176{
177 struct sk_buff *new;
178 int stat;
179
180 new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
181 GFP_ATOMIC);
182 kfree_skb(skb);
183
184 if (!new)
185 return -ENOMEM;
186
187 skb_push(new, sizeof(struct ipv6hdr));
188 skb_reset_network_header(new);
189 skb_copy_to_linear_data(new, hdr, sizeof(struct ipv6hdr));
190
191 new->protocol = htons(ETH_P_IPV6);
192 new->pkt_type = PACKET_HOST;
193 new->dev = dev;
194
195 raw_dump_table(__func__, "raw skb data dump before receiving",
196 new->data, new->len);
197
198 stat = deliver_skb(new, dev);
199
200 kfree_skb(new);
201
202 return stat;
203}
204
205/* Uncompress function for multicast destination address, 174/* Uncompress function for multicast destination address,
206 * when M bit is set. 175 * when M bit is set.
207 */ 176 */
@@ -332,10 +301,12 @@ err:
332/* TTL uncompression values */ 301/* TTL uncompression values */
333static const u8 lowpan_ttl_values[] = { 0, 1, 64, 255 }; 302static const u8 lowpan_ttl_values[] = { 0, 1, 64, 255 };
334 303
335int lowpan_process_data(struct sk_buff *skb, struct net_device *dev, 304int
336 const u8 *saddr, const u8 saddr_type, const u8 saddr_len, 305lowpan_header_decompress(struct sk_buff *skb, struct net_device *dev,
337 const u8 *daddr, const u8 daddr_type, const u8 daddr_len, 306 const u8 *saddr, const u8 saddr_type,
338 u8 iphc0, u8 iphc1, skb_delivery_cb deliver_skb) 307 const u8 saddr_len, const u8 *daddr,
308 const u8 daddr_type, const u8 daddr_len,
309 u8 iphc0, u8 iphc1)
339{ 310{
340 struct ipv6hdr hdr = {}; 311 struct ipv6hdr hdr = {};
341 u8 tmp, num_context = 0; 312 u8 tmp, num_context = 0;
@@ -348,7 +319,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
348 if (iphc1 & LOWPAN_IPHC_CID) { 319 if (iphc1 & LOWPAN_IPHC_CID) {
349 pr_debug("CID flag is set, increase header with one\n"); 320 pr_debug("CID flag is set, increase header with one\n");
350 if (lowpan_fetch_skb(skb, &num_context, sizeof(num_context))) 321 if (lowpan_fetch_skb(skb, &num_context, sizeof(num_context)))
351 goto drop; 322 return -EINVAL;
352 } 323 }
353 324
354 hdr.version = 6; 325 hdr.version = 6;
@@ -360,7 +331,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
360 */ 331 */
361 case 0: /* 00b */ 332 case 0: /* 00b */
362 if (lowpan_fetch_skb(skb, &tmp, sizeof(tmp))) 333 if (lowpan_fetch_skb(skb, &tmp, sizeof(tmp)))
363 goto drop; 334 return -EINVAL;
364 335
365 memcpy(&hdr.flow_lbl, &skb->data[0], 3); 336 memcpy(&hdr.flow_lbl, &skb->data[0], 3);
366 skb_pull(skb, 3); 337 skb_pull(skb, 3);
@@ -373,7 +344,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
373 */ 344 */
374 case 2: /* 10b */ 345 case 2: /* 10b */
375 if (lowpan_fetch_skb(skb, &tmp, sizeof(tmp))) 346 if (lowpan_fetch_skb(skb, &tmp, sizeof(tmp)))
376 goto drop; 347 return -EINVAL;
377 348
378 hdr.priority = ((tmp >> 2) & 0x0f); 349 hdr.priority = ((tmp >> 2) & 0x0f);
379 hdr.flow_lbl[0] = ((tmp << 6) & 0xC0) | ((tmp >> 2) & 0x30); 350 hdr.flow_lbl[0] = ((tmp << 6) & 0xC0) | ((tmp >> 2) & 0x30);
@@ -383,7 +354,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
383 */ 354 */
384 case 1: /* 01b */ 355 case 1: /* 01b */
385 if (lowpan_fetch_skb(skb, &tmp, sizeof(tmp))) 356 if (lowpan_fetch_skb(skb, &tmp, sizeof(tmp)))
386 goto drop; 357 return -EINVAL;
387 358
388 hdr.flow_lbl[0] = (skb->data[0] & 0x0F) | ((tmp >> 2) & 0x30); 359 hdr.flow_lbl[0] = (skb->data[0] & 0x0F) | ((tmp >> 2) & 0x30);
389 memcpy(&hdr.flow_lbl[1], &skb->data[0], 2); 360 memcpy(&hdr.flow_lbl[1], &skb->data[0], 2);
@@ -400,7 +371,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
400 if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) { 371 if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) {
401 /* Next header is carried inline */ 372 /* Next header is carried inline */
402 if (lowpan_fetch_skb(skb, &hdr.nexthdr, sizeof(hdr.nexthdr))) 373 if (lowpan_fetch_skb(skb, &hdr.nexthdr, sizeof(hdr.nexthdr)))
403 goto drop; 374 return -EINVAL;
404 375
405 pr_debug("NH flag is set, next header carried inline: %02x\n", 376 pr_debug("NH flag is set, next header carried inline: %02x\n",
406 hdr.nexthdr); 377 hdr.nexthdr);
@@ -412,7 +383,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
412 } else { 383 } else {
413 if (lowpan_fetch_skb(skb, &hdr.hop_limit, 384 if (lowpan_fetch_skb(skb, &hdr.hop_limit,
414 sizeof(hdr.hop_limit))) 385 sizeof(hdr.hop_limit)))
415 goto drop; 386 return -EINVAL;
416 } 387 }
417 388
418 /* Extract SAM to the tmp variable */ 389 /* Extract SAM to the tmp variable */
@@ -431,7 +402,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
431 402
432 /* Check on error of previous branch */ 403 /* Check on error of previous branch */
433 if (err) 404 if (err)
434 goto drop; 405 return -EINVAL;
435 406
436 /* Extract DAM to the tmp variable */ 407 /* Extract DAM to the tmp variable */
437 tmp = ((iphc1 & LOWPAN_IPHC_DAM_11) >> LOWPAN_IPHC_DAM_BIT) & 0x03; 408 tmp = ((iphc1 & LOWPAN_IPHC_DAM_11) >> LOWPAN_IPHC_DAM_BIT) & 0x03;
@@ -446,7 +417,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
446 tmp); 417 tmp);
447 418
448 if (err) 419 if (err)
449 goto drop; 420 return -EINVAL;
450 } 421 }
451 } else { 422 } else {
452 err = uncompress_addr(skb, &hdr.daddr, tmp, daddr, 423 err = uncompress_addr(skb, &hdr.daddr, tmp, daddr,
@@ -454,28 +425,23 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
454 pr_debug("dest: stateless compression mode %d dest %pI6c\n", 425 pr_debug("dest: stateless compression mode %d dest %pI6c\n",
455 tmp, &hdr.daddr); 426 tmp, &hdr.daddr);
456 if (err) 427 if (err)
457 goto drop; 428 return -EINVAL;
458 } 429 }
459 430
460 /* UDP data uncompression */ 431 /* UDP data uncompression */
461 if (iphc0 & LOWPAN_IPHC_NH_C) { 432 if (iphc0 & LOWPAN_IPHC_NH_C) {
462 struct udphdr uh; 433 struct udphdr uh;
463 struct sk_buff *new; 434 const int needed = sizeof(struct udphdr) + sizeof(hdr);
464 435
465 if (uncompress_udp_header(skb, &uh)) 436 if (uncompress_udp_header(skb, &uh))
466 goto drop; 437 return -EINVAL;
467 438
468 /* replace the compressed UDP head by the uncompressed UDP 439 /* replace the compressed UDP head by the uncompressed UDP
469 * header 440 * header
470 */ 441 */
471 new = skb_copy_expand(skb, sizeof(struct udphdr), 442 err = skb_cow(skb, needed);
472 skb_tailroom(skb), GFP_ATOMIC); 443 if (unlikely(err))
473 kfree_skb(skb); 444 return err;
474
475 if (!new)
476 return -ENOMEM;
477
478 skb = new;
479 445
480 skb_push(skb, sizeof(struct udphdr)); 446 skb_push(skb, sizeof(struct udphdr));
481 skb_reset_transport_header(skb); 447 skb_reset_transport_header(skb);
@@ -485,6 +451,10 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
485 (u8 *)&uh, sizeof(uh)); 451 (u8 *)&uh, sizeof(uh));
486 452
487 hdr.nexthdr = UIP_PROTO_UDP; 453 hdr.nexthdr = UIP_PROTO_UDP;
454 } else {
455 err = skb_cow(skb, sizeof(hdr));
456 if (unlikely(err))
457 return err;
488 } 458 }
489 459
490 hdr.payload_len = htons(skb->len); 460 hdr.payload_len = htons(skb->len);
@@ -497,15 +467,15 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
497 hdr.version, ntohs(hdr.payload_len), hdr.nexthdr, 467 hdr.version, ntohs(hdr.payload_len), hdr.nexthdr,
498 hdr.hop_limit, &hdr.daddr); 468 hdr.hop_limit, &hdr.daddr);
499 469
500 raw_dump_table(__func__, "raw header dump", (u8 *)&hdr, sizeof(hdr)); 470 skb_push(skb, sizeof(hdr));
471 skb_reset_network_header(skb);
472 skb_copy_to_linear_data(skb, &hdr, sizeof(hdr));
501 473
502 return skb_deliver(skb, &hdr, dev, deliver_skb); 474 raw_dump_table(__func__, "raw header dump", (u8 *)&hdr, sizeof(hdr));
503 475
504drop: 476 return 0;
505 kfree_skb(skb);
506 return -EINVAL;
507} 477}
508EXPORT_SYMBOL_GPL(lowpan_process_data); 478EXPORT_SYMBOL_GPL(lowpan_header_decompress);
509 479
510static u8 lowpan_compress_addr_64(u8 **hc_ptr, u8 shift, 480static u8 lowpan_compress_addr_64(u8 **hc_ptr, u8 shift,
511 const struct in6_addr *ipaddr, 481 const struct in6_addr *ipaddr,
@@ -535,9 +505,17 @@ static u8 lowpan_compress_addr_64(u8 **hc_ptr, u8 shift,
535 505
536static void compress_udp_header(u8 **hc_ptr, struct sk_buff *skb) 506static void compress_udp_header(u8 **hc_ptr, struct sk_buff *skb)
537{ 507{
538 struct udphdr *uh = udp_hdr(skb); 508 struct udphdr *uh;
539 u8 tmp; 509 u8 tmp;
540 510
511 /* In the case of RAW sockets the transport header is not set by
512 * the ip6 stack so we must set it ourselves
513 */
514 if (skb->transport_header == skb->network_header)
515 skb_set_transport_header(skb, sizeof(struct ipv6hdr));
516
517 uh = udp_hdr(skb);
518
541 if (((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_MASK) == 519 if (((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_MASK) ==
542 LOWPAN_NHC_UDP_4BIT_PORT) && 520 LOWPAN_NHC_UDP_4BIT_PORT) &&
543 ((ntohs(uh->dest) & LOWPAN_NHC_UDP_4BIT_MASK) == 521 ((ntohs(uh->dest) & LOWPAN_NHC_UDP_4BIT_MASK) ==
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index c2e0d14433df..bdcaefd2db12 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -53,7 +53,7 @@ struct skb_cb {
53 * The list contains struct lowpan_dev elements. 53 * The list contains struct lowpan_dev elements.
54 */ 54 */
55static LIST_HEAD(bt_6lowpan_devices); 55static LIST_HEAD(bt_6lowpan_devices);
56static DEFINE_RWLOCK(devices_lock); 56static DEFINE_SPINLOCK(devices_lock);
57 57
58/* If psm is set to 0 (default value), then 6lowpan is disabled. 58/* If psm is set to 0 (default value), then 6lowpan is disabled.
59 * Other values are used to indicate a Protocol Service Multiplexer 59 * Other values are used to indicate a Protocol Service Multiplexer
@@ -67,6 +67,7 @@ static struct l2cap_chan *listen_chan;
67 67
68struct lowpan_peer { 68struct lowpan_peer {
69 struct list_head list; 69 struct list_head list;
70 struct rcu_head rcu;
70 struct l2cap_chan *chan; 71 struct l2cap_chan *chan;
71 72
72 /* peer addresses in various formats */ 73 /* peer addresses in various formats */
@@ -93,13 +94,14 @@ static inline struct lowpan_dev *lowpan_dev(const struct net_device *netdev)
93 94
94static inline void peer_add(struct lowpan_dev *dev, struct lowpan_peer *peer) 95static inline void peer_add(struct lowpan_dev *dev, struct lowpan_peer *peer)
95{ 96{
96 list_add(&peer->list, &dev->peers); 97 list_add_rcu(&peer->list, &dev->peers);
97 atomic_inc(&dev->peer_count); 98 atomic_inc(&dev->peer_count);
98} 99}
99 100
100static inline bool peer_del(struct lowpan_dev *dev, struct lowpan_peer *peer) 101static inline bool peer_del(struct lowpan_dev *dev, struct lowpan_peer *peer)
101{ 102{
102 list_del(&peer->list); 103 list_del_rcu(&peer->list);
104 kfree_rcu(peer, rcu);
103 105
104 module_put(THIS_MODULE); 106 module_put(THIS_MODULE);
105 107
@@ -114,31 +116,37 @@ static inline bool peer_del(struct lowpan_dev *dev, struct lowpan_peer *peer)
114static inline struct lowpan_peer *peer_lookup_ba(struct lowpan_dev *dev, 116static inline struct lowpan_peer *peer_lookup_ba(struct lowpan_dev *dev,
115 bdaddr_t *ba, __u8 type) 117 bdaddr_t *ba, __u8 type)
116{ 118{
117 struct lowpan_peer *peer, *tmp; 119 struct lowpan_peer *peer;
118 120
119 BT_DBG("peers %d addr %pMR type %d", atomic_read(&dev->peer_count), 121 BT_DBG("peers %d addr %pMR type %d", atomic_read(&dev->peer_count),
120 ba, type); 122 ba, type);
121 123
122 list_for_each_entry_safe(peer, tmp, &dev->peers, list) { 124 rcu_read_lock();
125
126 list_for_each_entry_rcu(peer, &dev->peers, list) {
123 BT_DBG("dst addr %pMR dst type %d", 127 BT_DBG("dst addr %pMR dst type %d",
124 &peer->chan->dst, peer->chan->dst_type); 128 &peer->chan->dst, peer->chan->dst_type);
125 129
126 if (bacmp(&peer->chan->dst, ba)) 130 if (bacmp(&peer->chan->dst, ba))
127 continue; 131 continue;
128 132
129 if (type == peer->chan->dst_type) 133 if (type == peer->chan->dst_type) {
134 rcu_read_unlock();
130 return peer; 135 return peer;
136 }
131 } 137 }
132 138
139 rcu_read_unlock();
140
133 return NULL; 141 return NULL;
134} 142}
135 143
136static inline struct lowpan_peer *peer_lookup_chan(struct lowpan_dev *dev, 144static inline struct lowpan_peer *__peer_lookup_chan(struct lowpan_dev *dev,
137 struct l2cap_chan *chan) 145 struct l2cap_chan *chan)
138{ 146{
139 struct lowpan_peer *peer, *tmp; 147 struct lowpan_peer *peer;
140 148
141 list_for_each_entry_safe(peer, tmp, &dev->peers, list) { 149 list_for_each_entry_rcu(peer, &dev->peers, list) {
142 if (peer->chan == chan) 150 if (peer->chan == chan)
143 return peer; 151 return peer;
144 } 152 }
@@ -146,12 +154,12 @@ static inline struct lowpan_peer *peer_lookup_chan(struct lowpan_dev *dev,
146 return NULL; 154 return NULL;
147} 155}
148 156
149static inline struct lowpan_peer *peer_lookup_conn(struct lowpan_dev *dev, 157static inline struct lowpan_peer *__peer_lookup_conn(struct lowpan_dev *dev,
150 struct l2cap_conn *conn) 158 struct l2cap_conn *conn)
151{ 159{
152 struct lowpan_peer *peer, *tmp; 160 struct lowpan_peer *peer;
153 161
154 list_for_each_entry_safe(peer, tmp, &dev->peers, list) { 162 list_for_each_entry_rcu(peer, &dev->peers, list) {
155 if (peer->chan->conn == conn) 163 if (peer->chan->conn == conn)
156 return peer; 164 return peer;
157 } 165 }
@@ -163,7 +171,7 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
163 struct in6_addr *daddr, 171 struct in6_addr *daddr,
164 struct sk_buff *skb) 172 struct sk_buff *skb)
165{ 173{
166 struct lowpan_peer *peer, *tmp; 174 struct lowpan_peer *peer;
167 struct in6_addr *nexthop; 175 struct in6_addr *nexthop;
168 struct rt6_info *rt = (struct rt6_info *)skb_dst(skb); 176 struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
169 int count = atomic_read(&dev->peer_count); 177 int count = atomic_read(&dev->peer_count);
@@ -174,9 +182,13 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
174 * send the packet. If only one peer exists, then we can send the 182 * send the packet. If only one peer exists, then we can send the
175 * packet right away. 183 * packet right away.
176 */ 184 */
177 if (count == 1) 185 if (count == 1) {
178 return list_first_entry(&dev->peers, struct lowpan_peer, 186 rcu_read_lock();
179 list); 187 peer = list_first_or_null_rcu(&dev->peers, struct lowpan_peer,
188 list);
189 rcu_read_unlock();
190 return peer;
191 }
180 192
181 if (!rt) { 193 if (!rt) {
182 nexthop = &lowpan_cb(skb)->gw; 194 nexthop = &lowpan_cb(skb)->gw;
@@ -195,53 +207,57 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
195 207
196 BT_DBG("gw %pI6c", nexthop); 208 BT_DBG("gw %pI6c", nexthop);
197 209
198 list_for_each_entry_safe(peer, tmp, &dev->peers, list) { 210 rcu_read_lock();
211
212 list_for_each_entry_rcu(peer, &dev->peers, list) {
199 BT_DBG("dst addr %pMR dst type %d ip %pI6c", 213 BT_DBG("dst addr %pMR dst type %d ip %pI6c",
200 &peer->chan->dst, peer->chan->dst_type, 214 &peer->chan->dst, peer->chan->dst_type,
201 &peer->peer_addr); 215 &peer->peer_addr);
202 216
203 if (!ipv6_addr_cmp(&peer->peer_addr, nexthop)) 217 if (!ipv6_addr_cmp(&peer->peer_addr, nexthop)) {
218 rcu_read_unlock();
204 return peer; 219 return peer;
220 }
205 } 221 }
206 222
223 rcu_read_unlock();
224
207 return NULL; 225 return NULL;
208} 226}
209 227
210static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn) 228static struct lowpan_peer *lookup_peer(struct l2cap_conn *conn)
211{ 229{
212 struct lowpan_dev *entry, *tmp; 230 struct lowpan_dev *entry;
213 struct lowpan_peer *peer = NULL; 231 struct lowpan_peer *peer = NULL;
214 unsigned long flags;
215 232
216 read_lock_irqsave(&devices_lock, flags); 233 rcu_read_lock();
217 234
218 list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) { 235 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
219 peer = peer_lookup_conn(entry, conn); 236 peer = __peer_lookup_conn(entry, conn);
220 if (peer) 237 if (peer)
221 break; 238 break;
222 } 239 }
223 240
224 read_unlock_irqrestore(&devices_lock, flags); 241 rcu_read_unlock();
225 242
226 return peer; 243 return peer;
227} 244}
228 245
229static struct lowpan_dev *lookup_dev(struct l2cap_conn *conn) 246static struct lowpan_dev *lookup_dev(struct l2cap_conn *conn)
230{ 247{
231 struct lowpan_dev *entry, *tmp; 248 struct lowpan_dev *entry;
232 struct lowpan_dev *dev = NULL; 249 struct lowpan_dev *dev = NULL;
233 unsigned long flags;
234 250
235 read_lock_irqsave(&devices_lock, flags); 251 rcu_read_lock();
236 252
237 list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) { 253 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
238 if (conn->hcon->hdev == entry->hdev) { 254 if (conn->hcon->hdev == entry->hdev) {
239 dev = entry; 255 dev = entry;
240 break; 256 break;
241 } 257 }
242 } 258 }
243 259
244 read_unlock_irqrestore(&devices_lock, flags); 260 rcu_read_unlock();
245 261
246 return dev; 262 return dev;
247} 263}
@@ -249,59 +265,49 @@ static struct lowpan_dev *lookup_dev(struct l2cap_conn *conn)
249static int give_skb_to_upper(struct sk_buff *skb, struct net_device *dev) 265static int give_skb_to_upper(struct sk_buff *skb, struct net_device *dev)
250{ 266{
251 struct sk_buff *skb_cp; 267 struct sk_buff *skb_cp;
252 int ret;
253 268
254 skb_cp = skb_copy(skb, GFP_ATOMIC); 269 skb_cp = skb_copy(skb, GFP_ATOMIC);
255 if (!skb_cp) 270 if (!skb_cp)
256 return -ENOMEM;
257
258 ret = netif_rx(skb_cp);
259 if (ret < 0) {
260 BT_DBG("receive skb %d", ret);
261 return NET_RX_DROP; 271 return NET_RX_DROP;
262 }
263 272
264 return ret; 273 return netif_rx(skb_cp);
265} 274}
266 275
267static int process_data(struct sk_buff *skb, struct net_device *netdev, 276static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
268 struct l2cap_chan *chan) 277 struct l2cap_chan *chan)
269{ 278{
270 const u8 *saddr, *daddr; 279 const u8 *saddr, *daddr;
271 u8 iphc0, iphc1; 280 u8 iphc0, iphc1;
272 struct lowpan_dev *dev; 281 struct lowpan_dev *dev;
273 struct lowpan_peer *peer; 282 struct lowpan_peer *peer;
274 unsigned long flags;
275 283
276 dev = lowpan_dev(netdev); 284 dev = lowpan_dev(netdev);
277 285
278 read_lock_irqsave(&devices_lock, flags); 286 rcu_read_lock();
279 peer = peer_lookup_chan(dev, chan); 287 peer = __peer_lookup_chan(dev, chan);
280 read_unlock_irqrestore(&devices_lock, flags); 288 rcu_read_unlock();
281 if (!peer) 289 if (!peer)
282 goto drop; 290 return -EINVAL;
283 291
284 saddr = peer->eui64_addr; 292 saddr = peer->eui64_addr;
285 daddr = dev->netdev->dev_addr; 293 daddr = dev->netdev->dev_addr;
286 294
287 /* at least two bytes will be used for the encoding */ 295 /* at least two bytes will be used for the encoding */
288 if (skb->len < 2) 296 if (skb->len < 2)
289 goto drop; 297 return -EINVAL;
290 298
291 if (lowpan_fetch_skb_u8(skb, &iphc0)) 299 if (lowpan_fetch_skb_u8(skb, &iphc0))
292 goto drop; 300 return -EINVAL;
293 301
294 if (lowpan_fetch_skb_u8(skb, &iphc1)) 302 if (lowpan_fetch_skb_u8(skb, &iphc1))
295 goto drop; 303 return -EINVAL;
296 304
297 return lowpan_process_data(skb, netdev, 305 return lowpan_header_decompress(skb, netdev,
298 saddr, IEEE802154_ADDR_LONG, EUI64_ADDR_LEN, 306 saddr, IEEE802154_ADDR_LONG,
299 daddr, IEEE802154_ADDR_LONG, EUI64_ADDR_LEN, 307 EUI64_ADDR_LEN, daddr,
300 iphc0, iphc1, give_skb_to_upper); 308 IEEE802154_ADDR_LONG, EUI64_ADDR_LEN,
309 iphc0, iphc1);
301 310
302drop:
303 kfree_skb(skb);
304 return -EINVAL;
305} 311}
306 312
307static int recv_pkt(struct sk_buff *skb, struct net_device *dev, 313static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
@@ -316,6 +322,10 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
316 if (dev->type != ARPHRD_6LOWPAN) 322 if (dev->type != ARPHRD_6LOWPAN)
317 goto drop; 323 goto drop;
318 324
325 skb = skb_share_check(skb, GFP_ATOMIC);
326 if (!skb)
327 goto drop;
328
319 /* check that it's our buffer */ 329 /* check that it's our buffer */
320 if (skb->data[0] == LOWPAN_DISPATCH_IPV6) { 330 if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
321 /* Copy the packet so that the IPv6 header is 331 /* Copy the packet so that the IPv6 header is
@@ -340,8 +350,8 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
340 dev->stats.rx_bytes += skb->len; 350 dev->stats.rx_bytes += skb->len;
341 dev->stats.rx_packets++; 351 dev->stats.rx_packets++;
342 352
343 kfree_skb(local_skb); 353 consume_skb(local_skb);
344 kfree_skb(skb); 354 consume_skb(skb);
345 } else { 355 } else {
346 switch (skb->data[0] & 0xe0) { 356 switch (skb->data[0] & 0xe0) {
347 case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */ 357 case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */
@@ -349,14 +359,27 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
349 if (!local_skb) 359 if (!local_skb)
350 goto drop; 360 goto drop;
351 361
352 ret = process_data(local_skb, dev, chan); 362 ret = iphc_decompress(local_skb, dev, chan);
353 if (ret != NET_RX_SUCCESS) 363 if (ret < 0) {
364 kfree_skb(local_skb);
354 goto drop; 365 goto drop;
366 }
367
368 local_skb->protocol = htons(ETH_P_IPV6);
369 local_skb->pkt_type = PACKET_HOST;
370 local_skb->dev = dev;
371
372 if (give_skb_to_upper(local_skb, dev)
373 != NET_RX_SUCCESS) {
374 kfree_skb(local_skb);
375 goto drop;
376 }
355 377
356 dev->stats.rx_bytes += skb->len; 378 dev->stats.rx_bytes += skb->len;
357 dev->stats.rx_packets++; 379 dev->stats.rx_packets++;
358 380
359 kfree_skb(skb); 381 consume_skb(local_skb);
382 consume_skb(skb);
360 break; 383 break;
361 default: 384 default:
362 break; 385 break;
@@ -443,7 +466,6 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev,
443 if (ipv6_addr_is_multicast(&ipv6_daddr)) { 466 if (ipv6_addr_is_multicast(&ipv6_daddr)) {
444 lowpan_cb(skb)->chan = NULL; 467 lowpan_cb(skb)->chan = NULL;
445 } else { 468 } else {
446 unsigned long flags;
447 u8 addr_type; 469 u8 addr_type;
448 470
449 /* Get destination BT device from skb. 471 /* Get destination BT device from skb.
@@ -454,19 +476,14 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev,
454 BT_DBG("dest addr %pMR type %d IP %pI6c", &addr, 476 BT_DBG("dest addr %pMR type %d IP %pI6c", &addr,
455 addr_type, &ipv6_daddr); 477 addr_type, &ipv6_daddr);
456 478
457 read_lock_irqsave(&devices_lock, flags);
458 peer = peer_lookup_ba(dev, &addr, addr_type); 479 peer = peer_lookup_ba(dev, &addr, addr_type);
459 read_unlock_irqrestore(&devices_lock, flags);
460
461 if (!peer) { 480 if (!peer) {
462 /* The packet might be sent to 6lowpan interface 481 /* The packet might be sent to 6lowpan interface
463 * because of routing (either via default route 482 * because of routing (either via default route
464 * or user set route) so get peer according to 483 * or user set route) so get peer according to
465 * the destination address. 484 * the destination address.
466 */ 485 */
467 read_lock_irqsave(&devices_lock, flags);
468 peer = peer_lookup_dst(dev, &ipv6_daddr, skb); 486 peer = peer_lookup_dst(dev, &ipv6_daddr, skb);
469 read_unlock_irqrestore(&devices_lock, flags);
470 if (!peer) { 487 if (!peer) {
471 BT_DBG("no such peer %pMR found", &addr); 488 BT_DBG("no such peer %pMR found", &addr);
472 return -ENOENT; 489 return -ENOENT;
@@ -549,14 +566,13 @@ static int send_pkt(struct l2cap_chan *chan, struct sk_buff *skb,
549static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev) 566static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)
550{ 567{
551 struct sk_buff *local_skb; 568 struct sk_buff *local_skb;
552 struct lowpan_dev *entry, *tmp; 569 struct lowpan_dev *entry;
553 unsigned long flags;
554 int err = 0; 570 int err = 0;
555 571
556 read_lock_irqsave(&devices_lock, flags); 572 rcu_read_lock();
557 573
558 list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) { 574 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
559 struct lowpan_peer *pentry, *ptmp; 575 struct lowpan_peer *pentry;
560 struct lowpan_dev *dev; 576 struct lowpan_dev *dev;
561 577
562 if (entry->netdev != netdev) 578 if (entry->netdev != netdev)
@@ -564,7 +580,7 @@ static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)
564 580
565 dev = lowpan_dev(entry->netdev); 581 dev = lowpan_dev(entry->netdev);
566 582
567 list_for_each_entry_safe(pentry, ptmp, &dev->peers, list) { 583 list_for_each_entry_rcu(pentry, &dev->peers, list) {
568 int ret; 584 int ret;
569 585
570 local_skb = skb_clone(skb, GFP_ATOMIC); 586 local_skb = skb_clone(skb, GFP_ATOMIC);
@@ -581,7 +597,7 @@ static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)
581 } 597 }
582 } 598 }
583 599
584 read_unlock_irqrestore(&devices_lock, flags); 600 rcu_read_unlock();
585 601
586 return err; 602 return err;
587} 603}
@@ -591,17 +607,13 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
591 int err = 0; 607 int err = 0;
592 bdaddr_t addr; 608 bdaddr_t addr;
593 u8 addr_type; 609 u8 addr_type;
594 struct sk_buff *tmpskb;
595 610
596 /* We must take a copy of the skb before we modify/replace the ipv6 611 /* We must take a copy of the skb before we modify/replace the ipv6
597 * header as the header could be used elsewhere 612 * header as the header could be used elsewhere
598 */ 613 */
599 tmpskb = skb_unshare(skb, GFP_ATOMIC); 614 skb = skb_unshare(skb, GFP_ATOMIC);
600 if (!tmpskb) { 615 if (!skb)
601 kfree_skb(skb);
602 return NET_XMIT_DROP; 616 return NET_XMIT_DROP;
603 }
604 skb = tmpskb;
605 617
606 /* Return values from setup_header() 618 /* Return values from setup_header()
607 * <0 - error, packet is dropped 619 * <0 - error, packet is dropped
@@ -638,7 +650,26 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
638 return err < 0 ? NET_XMIT_DROP : err; 650 return err < 0 ? NET_XMIT_DROP : err;
639} 651}
640 652
653static struct lock_class_key bt_tx_busylock;
654static struct lock_class_key bt_netdev_xmit_lock_key;
655
656static void bt_set_lockdep_class_one(struct net_device *dev,
657 struct netdev_queue *txq,
658 void *_unused)
659{
660 lockdep_set_class(&txq->_xmit_lock, &bt_netdev_xmit_lock_key);
661}
662
663static int bt_dev_init(struct net_device *dev)
664{
665 netdev_for_each_tx_queue(dev, bt_set_lockdep_class_one, NULL);
666 dev->qdisc_tx_busylock = &bt_tx_busylock;
667
668 return 0;
669}
670
641static const struct net_device_ops netdev_ops = { 671static const struct net_device_ops netdev_ops = {
672 .ndo_init = bt_dev_init,
642 .ndo_start_xmit = bt_xmit, 673 .ndo_start_xmit = bt_xmit,
643}; 674};
644 675
@@ -783,7 +814,6 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
783 struct lowpan_dev *dev) 814 struct lowpan_dev *dev)
784{ 815{
785 struct lowpan_peer *peer; 816 struct lowpan_peer *peer;
786 unsigned long flags;
787 817
788 peer = kzalloc(sizeof(*peer), GFP_ATOMIC); 818 peer = kzalloc(sizeof(*peer), GFP_ATOMIC);
789 if (!peer) 819 if (!peer)
@@ -806,10 +836,10 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
806 */ 836 */
807 set_ip_addr_bits(chan->dst_type, (u8 *)&peer->peer_addr.s6_addr + 8); 837 set_ip_addr_bits(chan->dst_type, (u8 *)&peer->peer_addr.s6_addr + 8);
808 838
809 write_lock_irqsave(&devices_lock, flags); 839 spin_lock(&devices_lock);
810 INIT_LIST_HEAD(&peer->list); 840 INIT_LIST_HEAD(&peer->list);
811 peer_add(dev, peer); 841 peer_add(dev, peer);
812 write_unlock_irqrestore(&devices_lock, flags); 842 spin_unlock(&devices_lock);
813 843
814 /* Notifying peers about us needs to be done without locks held */ 844 /* Notifying peers about us needs to be done without locks held */
815 INIT_DELAYED_WORK(&dev->notify_peers, do_notify_peers); 845 INIT_DELAYED_WORK(&dev->notify_peers, do_notify_peers);
@@ -822,7 +852,6 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
822{ 852{
823 struct net_device *netdev; 853 struct net_device *netdev;
824 int err = 0; 854 int err = 0;
825 unsigned long flags;
826 855
827 netdev = alloc_netdev(sizeof(struct lowpan_dev), IFACE_NAME_TEMPLATE, 856 netdev = alloc_netdev(sizeof(struct lowpan_dev), IFACE_NAME_TEMPLATE,
828 NET_NAME_UNKNOWN, netdev_setup); 857 NET_NAME_UNKNOWN, netdev_setup);
@@ -852,10 +881,10 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
852 (*dev)->hdev = chan->conn->hcon->hdev; 881 (*dev)->hdev = chan->conn->hcon->hdev;
853 INIT_LIST_HEAD(&(*dev)->peers); 882 INIT_LIST_HEAD(&(*dev)->peers);
854 883
855 write_lock_irqsave(&devices_lock, flags); 884 spin_lock(&devices_lock);
856 INIT_LIST_HEAD(&(*dev)->list); 885 INIT_LIST_HEAD(&(*dev)->list);
857 list_add(&(*dev)->list, &bt_6lowpan_devices); 886 list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
858 write_unlock_irqrestore(&devices_lock, flags); 887 spin_unlock(&devices_lock);
859 888
860 return 0; 889 return 0;
861 890
@@ -909,11 +938,10 @@ static void delete_netdev(struct work_struct *work)
909 938
910static void chan_close_cb(struct l2cap_chan *chan) 939static void chan_close_cb(struct l2cap_chan *chan)
911{ 940{
912 struct lowpan_dev *entry, *tmp; 941 struct lowpan_dev *entry;
913 struct lowpan_dev *dev = NULL; 942 struct lowpan_dev *dev = NULL;
914 struct lowpan_peer *peer; 943 struct lowpan_peer *peer;
915 int err = -ENOENT; 944 int err = -ENOENT;
916 unsigned long flags;
917 bool last = false, removed = true; 945 bool last = false, removed = true;
918 946
919 BT_DBG("chan %p conn %p", chan, chan->conn); 947 BT_DBG("chan %p conn %p", chan, chan->conn);
@@ -928,11 +956,11 @@ static void chan_close_cb(struct l2cap_chan *chan)
928 removed = false; 956 removed = false;
929 } 957 }
930 958
931 write_lock_irqsave(&devices_lock, flags); 959 spin_lock(&devices_lock);
932 960
933 list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) { 961 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
934 dev = lowpan_dev(entry->netdev); 962 dev = lowpan_dev(entry->netdev);
935 peer = peer_lookup_chan(dev, chan); 963 peer = __peer_lookup_chan(dev, chan);
936 if (peer) { 964 if (peer) {
937 last = peer_del(dev, peer); 965 last = peer_del(dev, peer);
938 err = 0; 966 err = 0;
@@ -943,13 +971,12 @@ static void chan_close_cb(struct l2cap_chan *chan)
943 atomic_read(&chan->kref.refcount)); 971 atomic_read(&chan->kref.refcount));
944 972
945 l2cap_chan_put(chan); 973 l2cap_chan_put(chan);
946 kfree(peer);
947 break; 974 break;
948 } 975 }
949 } 976 }
950 977
951 if (!err && last && dev && !atomic_read(&dev->peer_count)) { 978 if (!err && last && dev && !atomic_read(&dev->peer_count)) {
952 write_unlock_irqrestore(&devices_lock, flags); 979 spin_unlock(&devices_lock);
953 980
954 cancel_delayed_work_sync(&dev->notify_peers); 981 cancel_delayed_work_sync(&dev->notify_peers);
955 982
@@ -960,7 +987,7 @@ static void chan_close_cb(struct l2cap_chan *chan)
960 schedule_work(&entry->delete_netdev); 987 schedule_work(&entry->delete_netdev);
961 } 988 }
962 } else { 989 } else {
963 write_unlock_irqrestore(&devices_lock, flags); 990 spin_unlock(&devices_lock);
964 } 991 }
965 992
966 return; 993 return;
@@ -1103,6 +1130,8 @@ static struct l2cap_chan *bt_6lowpan_listen(void)
1103 pchan->state = BT_LISTEN; 1130 pchan->state = BT_LISTEN;
1104 pchan->src_type = BDADDR_LE_PUBLIC; 1131 pchan->src_type = BDADDR_LE_PUBLIC;
1105 1132
1133 atomic_set(&pchan->nesting, L2CAP_NESTING_PARENT);
1134
1106 BT_DBG("psm 0x%04x chan %p src type %d", psm_6lowpan, pchan, 1135 BT_DBG("psm 0x%04x chan %p src type %d", psm_6lowpan, pchan,
1107 pchan->src_type); 1136 pchan->src_type);
1108 1137
@@ -1152,10 +1181,9 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
1152 1181
1153static void disconnect_all_peers(void) 1182static void disconnect_all_peers(void)
1154{ 1183{
1155 struct lowpan_dev *entry, *tmp_dev; 1184 struct lowpan_dev *entry;
1156 struct lowpan_peer *peer, *tmp_peer, *new_peer; 1185 struct lowpan_peer *peer, *tmp_peer, *new_peer;
1157 struct list_head peers; 1186 struct list_head peers;
1158 unsigned long flags;
1159 1187
1160 INIT_LIST_HEAD(&peers); 1188 INIT_LIST_HEAD(&peers);
1161 1189
@@ -1164,10 +1192,10 @@ static void disconnect_all_peers(void)
1164 * with the same list at the same time. 1192 * with the same list at the same time.
1165 */ 1193 */
1166 1194
1167 read_lock_irqsave(&devices_lock, flags); 1195 rcu_read_lock();
1168 1196
1169 list_for_each_entry_safe(entry, tmp_dev, &bt_6lowpan_devices, list) { 1197 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
1170 list_for_each_entry_safe(peer, tmp_peer, &entry->peers, list) { 1198 list_for_each_entry_rcu(peer, &entry->peers, list) {
1171 new_peer = kmalloc(sizeof(*new_peer), GFP_ATOMIC); 1199 new_peer = kmalloc(sizeof(*new_peer), GFP_ATOMIC);
1172 if (!new_peer) 1200 if (!new_peer)
1173 break; 1201 break;
@@ -1179,26 +1207,36 @@ static void disconnect_all_peers(void)
1179 } 1207 }
1180 } 1208 }
1181 1209
1182 read_unlock_irqrestore(&devices_lock, flags); 1210 rcu_read_unlock();
1183 1211
1212 spin_lock(&devices_lock);
1184 list_for_each_entry_safe(peer, tmp_peer, &peers, list) { 1213 list_for_each_entry_safe(peer, tmp_peer, &peers, list) {
1185 l2cap_chan_close(peer->chan, ENOENT); 1214 l2cap_chan_close(peer->chan, ENOENT);
1186 kfree(peer); 1215
1216 list_del_rcu(&peer->list);
1217 kfree_rcu(peer, rcu);
1218
1219 module_put(THIS_MODULE);
1187 } 1220 }
1221 spin_unlock(&devices_lock);
1188} 1222}
1189 1223
1190static int lowpan_psm_set(void *data, u64 val) 1224struct set_psm {
1191{ 1225 struct work_struct work;
1192 u16 psm; 1226 u16 psm;
1227};
1193 1228
1194 psm = val; 1229static void do_psm_set(struct work_struct *work)
1195 if (psm == 0 || psm_6lowpan != psm) 1230{
1231 struct set_psm *set_psm = container_of(work, struct set_psm, work);
1232
1233 if (set_psm->psm == 0 || psm_6lowpan != set_psm->psm)
1196 /* Disconnect existing connections if 6lowpan is 1234 /* Disconnect existing connections if 6lowpan is
1197 * disabled (psm = 0), or if psm changes. 1235 * disabled (psm = 0), or if psm changes.
1198 */ 1236 */
1199 disconnect_all_peers(); 1237 disconnect_all_peers();
1200 1238
1201 psm_6lowpan = psm; 1239 psm_6lowpan = set_psm->psm;
1202 1240
1203 if (listen_chan) { 1241 if (listen_chan) {
1204 l2cap_chan_close(listen_chan, 0); 1242 l2cap_chan_close(listen_chan, 0);
@@ -1207,6 +1245,22 @@ static int lowpan_psm_set(void *data, u64 val)
1207 1245
1208 listen_chan = bt_6lowpan_listen(); 1246 listen_chan = bt_6lowpan_listen();
1209 1247
1248 kfree(set_psm);
1249}
1250
1251static int lowpan_psm_set(void *data, u64 val)
1252{
1253 struct set_psm *set_psm;
1254
1255 set_psm = kzalloc(sizeof(*set_psm), GFP_KERNEL);
1256 if (!set_psm)
1257 return -ENOMEM;
1258
1259 set_psm->psm = val;
1260 INIT_WORK(&set_psm->work, do_psm_set);
1261
1262 schedule_work(&set_psm->work);
1263
1210 return 0; 1264 return 0;
1211} 1265}
1212 1266
@@ -1288,19 +1342,18 @@ static ssize_t lowpan_control_write(struct file *fp,
1288 1342
1289static int lowpan_control_show(struct seq_file *f, void *ptr) 1343static int lowpan_control_show(struct seq_file *f, void *ptr)
1290{ 1344{
1291 struct lowpan_dev *entry, *tmp_dev; 1345 struct lowpan_dev *entry;
1292 struct lowpan_peer *peer, *tmp_peer; 1346 struct lowpan_peer *peer;
1293 unsigned long flags;
1294 1347
1295 read_lock_irqsave(&devices_lock, flags); 1348 spin_lock(&devices_lock);
1296 1349
1297 list_for_each_entry_safe(entry, tmp_dev, &bt_6lowpan_devices, list) { 1350 list_for_each_entry(entry, &bt_6lowpan_devices, list) {
1298 list_for_each_entry_safe(peer, tmp_peer, &entry->peers, list) 1351 list_for_each_entry(peer, &entry->peers, list)
1299 seq_printf(f, "%pMR (type %u)\n", 1352 seq_printf(f, "%pMR (type %u)\n",
1300 &peer->chan->dst, peer->chan->dst_type); 1353 &peer->chan->dst, peer->chan->dst_type);
1301 } 1354 }
1302 1355
1303 read_unlock_irqrestore(&devices_lock, flags); 1356 spin_unlock(&devices_lock);
1304 1357
1305 return 0; 1358 return 0;
1306} 1359}
@@ -1322,7 +1375,6 @@ static void disconnect_devices(void)
1322{ 1375{
1323 struct lowpan_dev *entry, *tmp, *new_dev; 1376 struct lowpan_dev *entry, *tmp, *new_dev;
1324 struct list_head devices; 1377 struct list_head devices;
1325 unsigned long flags;
1326 1378
1327 INIT_LIST_HEAD(&devices); 1379 INIT_LIST_HEAD(&devices);
1328 1380
@@ -1331,9 +1383,9 @@ static void disconnect_devices(void)
1331 * devices list. 1383 * devices list.
1332 */ 1384 */
1333 1385
1334 read_lock_irqsave(&devices_lock, flags); 1386 rcu_read_lock();
1335 1387
1336 list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, list) { 1388 list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
1337 new_dev = kmalloc(sizeof(*new_dev), GFP_ATOMIC); 1389 new_dev = kmalloc(sizeof(*new_dev), GFP_ATOMIC);
1338 if (!new_dev) 1390 if (!new_dev)
1339 break; 1391 break;
@@ -1341,10 +1393,10 @@ static void disconnect_devices(void)
1341 new_dev->netdev = entry->netdev; 1393 new_dev->netdev = entry->netdev;
1342 INIT_LIST_HEAD(&new_dev->list); 1394 INIT_LIST_HEAD(&new_dev->list);
1343 1395
1344 list_add(&new_dev->list, &devices); 1396 list_add_rcu(&new_dev->list, &devices);
1345 } 1397 }
1346 1398
1347 read_unlock_irqrestore(&devices_lock, flags); 1399 rcu_read_unlock();
1348 1400
1349 list_for_each_entry_safe(entry, tmp, &devices, list) { 1401 list_for_each_entry_safe(entry, tmp, &devices, list) {
1350 ifdown(entry->netdev); 1402 ifdown(entry->netdev);
@@ -1359,17 +1411,15 @@ static int device_event(struct notifier_block *unused,
1359 unsigned long event, void *ptr) 1411 unsigned long event, void *ptr)
1360{ 1412{
1361 struct net_device *netdev = netdev_notifier_info_to_dev(ptr); 1413 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
1362 struct lowpan_dev *entry, *tmp; 1414 struct lowpan_dev *entry;
1363 unsigned long flags;
1364 1415
1365 if (netdev->type != ARPHRD_6LOWPAN) 1416 if (netdev->type != ARPHRD_6LOWPAN)
1366 return NOTIFY_DONE; 1417 return NOTIFY_DONE;
1367 1418
1368 switch (event) { 1419 switch (event) {
1369 case NETDEV_UNREGISTER: 1420 case NETDEV_UNREGISTER:
1370 write_lock_irqsave(&devices_lock, flags); 1421 spin_lock(&devices_lock);
1371 list_for_each_entry_safe(entry, tmp, &bt_6lowpan_devices, 1422 list_for_each_entry(entry, &bt_6lowpan_devices, list) {
1372 list) {
1373 if (entry->netdev == netdev) { 1423 if (entry->netdev == netdev) {
1374 BT_DBG("Unregistered netdev %s %p", 1424 BT_DBG("Unregistered netdev %s %p",
1375 netdev->name, netdev); 1425 netdev->name, netdev);
@@ -1378,7 +1428,7 @@ static int device_event(struct notifier_block *unused,
1378 break; 1428 break;
1379 } 1429 }
1380 } 1430 }
1381 write_unlock_irqrestore(&devices_lock, flags); 1431 spin_unlock(&devices_lock);
1382 break; 1432 break;
1383 } 1433 }
1384 1434
diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index 600fb29288f4..5e97a8ff850b 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -39,11 +39,10 @@ menuconfig BT
39 to Bluetooth kernel modules are provided in the BlueZ packages. For 39 to Bluetooth kernel modules are provided in the BlueZ packages. For
40 more information, see <http://www.bluez.org/>. 40 more information, see <http://www.bluez.org/>.
41 41
42config BT_6LOWPAN 42config BT_BREDR
43 tristate "Bluetooth 6LoWPAN support" 43 bool "Bluetooth Classic (BR/EDR) features"
44 depends on BT && 6LOWPAN 44 depends on BT
45 help 45 default y
46 IPv6 compression over Bluetooth Low Energy.
47 46
48source "net/bluetooth/rfcomm/Kconfig" 47source "net/bluetooth/rfcomm/Kconfig"
49 48
@@ -53,4 +52,15 @@ source "net/bluetooth/cmtp/Kconfig"
53 52
54source "net/bluetooth/hidp/Kconfig" 53source "net/bluetooth/hidp/Kconfig"
55 54
55config BT_LE
56 bool "Bluetooth Low Energy (LE) features"
57 depends on BT
58 default y
59
60config BT_6LOWPAN
61 tristate "Bluetooth 6LoWPAN support"
62 depends on BT_LE && 6LOWPAN
63 help
64 IPv6 compression over Bluetooth Low Energy.
65
56source "drivers/bluetooth/Kconfig" 66source "drivers/bluetooth/Kconfig"
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index 2640d78f30b8..ee016f039100 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -134,6 +134,7 @@ struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr,
134static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output) 134static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
135{ 135{
136 struct crypto_shash *tfm; 136 struct crypto_shash *tfm;
137 struct shash_desc *shash;
137 int ret; 138 int ret;
138 139
139 if (!ksize) 140 if (!ksize)
@@ -148,18 +149,24 @@ static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
148 ret = crypto_shash_setkey(tfm, key, ksize); 149 ret = crypto_shash_setkey(tfm, key, ksize);
149 if (ret) { 150 if (ret) {
150 BT_DBG("crypto_ahash_setkey failed: err %d", ret); 151 BT_DBG("crypto_ahash_setkey failed: err %d", ret);
151 } else { 152 goto failed;
152 char desc[sizeof(struct shash_desc) + 153 }
153 crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR;
154 struct shash_desc *shash = (struct shash_desc *)desc;
155
156 shash->tfm = tfm;
157 shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
158 154
159 ret = crypto_shash_digest(shash, plaintext, psize, 155 shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(tfm),
160 output); 156 GFP_KERNEL);
157 if (!shash) {
158 ret = -ENOMEM;
159 goto failed;
161 } 160 }
162 161
162 shash->tfm = tfm;
163 shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
164
165 ret = crypto_shash_digest(shash, plaintext, psize, output);
166
167 kfree(shash);
168
169failed:
163 crypto_free_shash(tfm); 170 crypto_free_shash(tfm);
164 return ret; 171 return ret;
165} 172}
diff --git a/net/bluetooth/bnep/Kconfig b/net/bluetooth/bnep/Kconfig
index 71791fc9f6b1..9b70317c49dc 100644
--- a/net/bluetooth/bnep/Kconfig
+++ b/net/bluetooth/bnep/Kconfig
@@ -1,6 +1,6 @@
1config BT_BNEP 1config BT_BNEP
2 tristate "BNEP protocol support" 2 tristate "BNEP protocol support"
3 depends on BT 3 depends on BT_BREDR
4 select CRC32 4 select CRC32
5 help 5 help
6 BNEP (Bluetooth Network Encapsulation Protocol) is Ethernet 6 BNEP (Bluetooth Network Encapsulation Protocol) is Ethernet
diff --git a/net/bluetooth/cmtp/Kconfig b/net/bluetooth/cmtp/Kconfig
index 94cbf42ce155..939da0fbdd88 100644
--- a/net/bluetooth/cmtp/Kconfig
+++ b/net/bluetooth/cmtp/Kconfig
@@ -1,6 +1,6 @@
1config BT_CMTP 1config BT_CMTP
2 tristate "CMTP protocol support" 2 tristate "CMTP protocol support"
3 depends on BT && ISDN_CAPI 3 depends on BT_BREDR && ISDN_CAPI
4 help 4 help
5 CMTP (CAPI Message Transport Protocol) is a transport layer 5 CMTP (CAPI Message Transport Protocol) is a transport layer
6 for CAPI messages. CMTP is required for the Bluetooth Common 6 for CAPI messages. CMTP is required for the Bluetooth Common
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index b9517bd17190..96887ae8375b 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -141,10 +141,11 @@ int hci_disconnect(struct hci_conn *conn, __u8 reason)
141 */ 141 */
142 if (conn->type == ACL_LINK && conn->role == HCI_ROLE_MASTER) { 142 if (conn->type == ACL_LINK && conn->role == HCI_ROLE_MASTER) {
143 struct hci_dev *hdev = conn->hdev; 143 struct hci_dev *hdev = conn->hdev;
144 struct hci_cp_read_clock_offset cp; 144 struct hci_cp_read_clock_offset clkoff_cp;
145 145
146 cp.handle = cpu_to_le16(conn->handle); 146 clkoff_cp.handle = cpu_to_le16(conn->handle);
147 hci_send_cmd(hdev, HCI_OP_READ_CLOCK_OFFSET, sizeof(cp), &cp); 147 hci_send_cmd(hdev, HCI_OP_READ_CLOCK_OFFSET, sizeof(clkoff_cp),
148 &clkoff_cp);
148 } 149 }
149 150
150 conn->state = BT_DISCONN; 151 conn->state = BT_DISCONN;
@@ -415,7 +416,7 @@ static void le_conn_timeout(struct work_struct *work)
415 * happen with broken hardware or if low duty cycle was used 416 * happen with broken hardware or if low duty cycle was used
416 * (which doesn't have a timeout of its own). 417 * (which doesn't have a timeout of its own).
417 */ 418 */
418 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags)) { 419 if (conn->role == HCI_ROLE_SLAVE) {
419 u8 enable = 0x00; 420 u8 enable = 0x00;
420 hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable), 421 hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
421 &enable); 422 &enable);
@@ -517,7 +518,7 @@ int hci_conn_del(struct hci_conn *conn)
517 /* Unacked frames */ 518 /* Unacked frames */
518 hdev->acl_cnt += conn->sent; 519 hdev->acl_cnt += conn->sent;
519 } else if (conn->type == LE_LINK) { 520 } else if (conn->type == LE_LINK) {
520 cancel_delayed_work_sync(&conn->le_conn_timeout); 521 cancel_delayed_work(&conn->le_conn_timeout);
521 522
522 if (hdev->le_pkts) 523 if (hdev->le_pkts)
523 hdev->le_cnt += conn->sent; 524 hdev->le_cnt += conn->sent;
@@ -544,6 +545,9 @@ int hci_conn_del(struct hci_conn *conn)
544 545
545 hci_conn_del_sysfs(conn); 546 hci_conn_del_sysfs(conn);
546 547
548 if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags))
549 hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
550
547 hci_dev_put(hdev); 551 hci_dev_put(hdev);
548 552
549 hci_conn_put(conn); 553 hci_conn_put(conn);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index cb05d7f16a34..d786958a1dec 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -200,31 +200,6 @@ static const struct file_operations blacklist_fops = {
200 .release = single_release, 200 .release = single_release,
201}; 201};
202 202
203static int whitelist_show(struct seq_file *f, void *p)
204{
205 struct hci_dev *hdev = f->private;
206 struct bdaddr_list *b;
207
208 hci_dev_lock(hdev);
209 list_for_each_entry(b, &hdev->whitelist, list)
210 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
211 hci_dev_unlock(hdev);
212
213 return 0;
214}
215
216static int whitelist_open(struct inode *inode, struct file *file)
217{
218 return single_open(file, whitelist_show, inode->i_private);
219}
220
221static const struct file_operations whitelist_fops = {
222 .open = whitelist_open,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
226};
227
228static int uuids_show(struct seq_file *f, void *p) 203static int uuids_show(struct seq_file *f, void *p)
229{ 204{
230 struct hci_dev *hdev = f->private; 205 struct hci_dev *hdev = f->private;
@@ -773,16 +748,15 @@ static const struct file_operations white_list_fops = {
773static int identity_resolving_keys_show(struct seq_file *f, void *ptr) 748static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
774{ 749{
775 struct hci_dev *hdev = f->private; 750 struct hci_dev *hdev = f->private;
776 struct list_head *p, *n; 751 struct smp_irk *irk;
777 752
778 hci_dev_lock(hdev); 753 rcu_read_lock();
779 list_for_each_safe(p, n, &hdev->identity_resolving_keys) { 754 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
780 struct smp_irk *irk = list_entry(p, struct smp_irk, list);
781 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", 755 seq_printf(f, "%pMR (type %u) %*phN %pMR\n",
782 &irk->bdaddr, irk->addr_type, 756 &irk->bdaddr, irk->addr_type,
783 16, irk->val, &irk->rpa); 757 16, irk->val, &irk->rpa);
784 } 758 }
785 hci_dev_unlock(hdev); 759 rcu_read_unlock();
786 760
787 return 0; 761 return 0;
788} 762}
@@ -803,17 +777,15 @@ static const struct file_operations identity_resolving_keys_fops = {
803static int long_term_keys_show(struct seq_file *f, void *ptr) 777static int long_term_keys_show(struct seq_file *f, void *ptr)
804{ 778{
805 struct hci_dev *hdev = f->private; 779 struct hci_dev *hdev = f->private;
806 struct list_head *p, *n; 780 struct smp_ltk *ltk;
807 781
808 hci_dev_lock(hdev); 782 rcu_read_lock();
809 list_for_each_safe(p, n, &hdev->long_term_keys) { 783 list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list)
810 struct smp_ltk *ltk = list_entry(p, struct smp_ltk, list);
811 seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n", 784 seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n",
812 &ltk->bdaddr, ltk->bdaddr_type, ltk->authenticated, 785 &ltk->bdaddr, ltk->bdaddr_type, ltk->authenticated,
813 ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv), 786 ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv),
814 __le64_to_cpu(ltk->rand), 16, ltk->val); 787 __le64_to_cpu(ltk->rand), 16, ltk->val);
815 } 788 rcu_read_unlock();
816 hci_dev_unlock(hdev);
817 789
818 return 0; 790 return 0;
819} 791}
@@ -1030,10 +1002,13 @@ static int device_list_show(struct seq_file *f, void *ptr)
1030{ 1002{
1031 struct hci_dev *hdev = f->private; 1003 struct hci_dev *hdev = f->private;
1032 struct hci_conn_params *p; 1004 struct hci_conn_params *p;
1005 struct bdaddr_list *b;
1033 1006
1034 hci_dev_lock(hdev); 1007 hci_dev_lock(hdev);
1008 list_for_each_entry(b, &hdev->whitelist, list)
1009 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
1035 list_for_each_entry(p, &hdev->le_conn_params, list) { 1010 list_for_each_entry(p, &hdev->le_conn_params, list) {
1036 seq_printf(f, "%pMR %u %u\n", &p->addr, p->addr_type, 1011 seq_printf(f, "%pMR (type %u) %u\n", &p->addr, p->addr_type,
1037 p->auto_connect); 1012 p->auto_connect);
1038 } 1013 }
1039 hci_dev_unlock(hdev); 1014 hci_dev_unlock(hdev);
@@ -1147,13 +1122,15 @@ struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
1147 1122
1148 hdev->req_status = HCI_REQ_PEND; 1123 hdev->req_status = HCI_REQ_PEND;
1149 1124
1150 err = hci_req_run(&req, hci_req_sync_complete);
1151 if (err < 0)
1152 return ERR_PTR(err);
1153
1154 add_wait_queue(&hdev->req_wait_q, &wait); 1125 add_wait_queue(&hdev->req_wait_q, &wait);
1155 set_current_state(TASK_INTERRUPTIBLE); 1126 set_current_state(TASK_INTERRUPTIBLE);
1156 1127
1128 err = hci_req_run(&req, hci_req_sync_complete);
1129 if (err < 0) {
1130 remove_wait_queue(&hdev->req_wait_q, &wait);
1131 return ERR_PTR(err);
1132 }
1133
1157 schedule_timeout(timeout); 1134 schedule_timeout(timeout);
1158 1135
1159 remove_wait_queue(&hdev->req_wait_q, &wait); 1136 remove_wait_queue(&hdev->req_wait_q, &wait);
@@ -1211,10 +1188,15 @@ static int __hci_req_sync(struct hci_dev *hdev,
1211 1188
1212 func(&req, opt); 1189 func(&req, opt);
1213 1190
1191 add_wait_queue(&hdev->req_wait_q, &wait);
1192 set_current_state(TASK_INTERRUPTIBLE);
1193
1214 err = hci_req_run(&req, hci_req_sync_complete); 1194 err = hci_req_run(&req, hci_req_sync_complete);
1215 if (err < 0) { 1195 if (err < 0) {
1216 hdev->req_status = 0; 1196 hdev->req_status = 0;
1217 1197
1198 remove_wait_queue(&hdev->req_wait_q, &wait);
1199
1218 /* ENODATA means the HCI request command queue is empty. 1200 /* ENODATA means the HCI request command queue is empty.
1219 * This can happen when a request with conditionals doesn't 1201 * This can happen when a request with conditionals doesn't
1220 * trigger any commands to be sent. This is normal behavior 1202 * trigger any commands to be sent. This is normal behavior
@@ -1226,9 +1208,6 @@ static int __hci_req_sync(struct hci_dev *hdev,
1226 return err; 1208 return err;
1227 } 1209 }
1228 1210
1229 add_wait_queue(&hdev->req_wait_q, &wait);
1230 set_current_state(TASK_INTERRUPTIBLE);
1231
1232 schedule_timeout(timeout); 1211 schedule_timeout(timeout);
1233 1212
1234 remove_wait_queue(&hdev->req_wait_q, &wait); 1213 remove_wait_queue(&hdev->req_wait_q, &wait);
@@ -1811,10 +1790,10 @@ static int __hci_init(struct hci_dev *hdev)
1811 &hdev->manufacturer); 1790 &hdev->manufacturer);
1812 debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver); 1791 debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver);
1813 debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev); 1792 debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev);
1793 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
1794 &device_list_fops);
1814 debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev, 1795 debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev,
1815 &blacklist_fops); 1796 &blacklist_fops);
1816 debugfs_create_file("whitelist", 0444, hdev->debugfs, hdev,
1817 &whitelist_fops);
1818 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops); 1797 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
1819 1798
1820 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev, 1799 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
@@ -1893,8 +1872,6 @@ static int __hci_init(struct hci_dev *hdev)
1893 hdev, &adv_min_interval_fops); 1872 hdev, &adv_min_interval_fops);
1894 debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, 1873 debugfs_create_file("adv_max_interval", 0644, hdev->debugfs,
1895 hdev, &adv_max_interval_fops); 1874 hdev, &adv_max_interval_fops);
1896 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
1897 &device_list_fops);
1898 debugfs_create_u16("discov_interleaved_timeout", 0644, 1875 debugfs_create_u16("discov_interleaved_timeout", 0644,
1899 hdev->debugfs, 1876 hdev->debugfs,
1900 &hdev->discov_interleaved_timeout); 1877 &hdev->discov_interleaved_timeout);
@@ -2584,6 +2561,11 @@ static int hci_dev_do_close(struct hci_dev *hdev)
2584 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 2561 if (test_bit(HCI_MGMT, &hdev->dev_flags))
2585 cancel_delayed_work_sync(&hdev->rpa_expired); 2562 cancel_delayed_work_sync(&hdev->rpa_expired);
2586 2563
2564 /* Avoid potential lockdep warnings from the *_flush() calls by
2565 * ensuring the workqueue is empty up front.
2566 */
2567 drain_workqueue(hdev->workqueue);
2568
2587 hci_dev_lock(hdev); 2569 hci_dev_lock(hdev);
2588 hci_inquiry_cache_flush(hdev); 2570 hci_inquiry_cache_flush(hdev);
2589 hci_pend_le_actions_clear(hdev); 2571 hci_pend_le_actions_clear(hdev);
@@ -2707,6 +2689,11 @@ int hci_dev_reset(__u16 dev)
2707 skb_queue_purge(&hdev->rx_q); 2689 skb_queue_purge(&hdev->rx_q);
2708 skb_queue_purge(&hdev->cmd_q); 2690 skb_queue_purge(&hdev->cmd_q);
2709 2691
2692 /* Avoid potential lockdep warnings from the *_flush() calls by
2693 * ensuring the workqueue is empty up front.
2694 */
2695 drain_workqueue(hdev->workqueue);
2696
2710 hci_dev_lock(hdev); 2697 hci_dev_lock(hdev);
2711 hci_inquiry_cache_flush(hdev); 2698 hci_inquiry_cache_flush(hdev);
2712 hci_conn_hash_flush(hdev); 2699 hci_conn_hash_flush(hdev);
@@ -3126,21 +3113,21 @@ void hci_link_keys_clear(struct hci_dev *hdev)
3126 3113
3127void hci_smp_ltks_clear(struct hci_dev *hdev) 3114void hci_smp_ltks_clear(struct hci_dev *hdev)
3128{ 3115{
3129 struct smp_ltk *k, *tmp; 3116 struct smp_ltk *k;
3130 3117
3131 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { 3118 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
3132 list_del(&k->list); 3119 list_del_rcu(&k->list);
3133 kfree(k); 3120 kfree_rcu(k, rcu);
3134 } 3121 }
3135} 3122}
3136 3123
3137void hci_smp_irks_clear(struct hci_dev *hdev) 3124void hci_smp_irks_clear(struct hci_dev *hdev)
3138{ 3125{
3139 struct smp_irk *k, *tmp; 3126 struct smp_irk *k;
3140 3127
3141 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { 3128 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) {
3142 list_del(&k->list); 3129 list_del_rcu(&k->list);
3143 kfree(k); 3130 kfree_rcu(k, rcu);
3144 } 3131 }
3145} 3132}
3146 3133
@@ -3204,15 +3191,18 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
3204{ 3191{
3205 struct smp_ltk *k; 3192 struct smp_ltk *k;
3206 3193
3207 list_for_each_entry(k, &hdev->long_term_keys, list) { 3194 rcu_read_lock();
3195 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
3208 if (k->ediv != ediv || k->rand != rand) 3196 if (k->ediv != ediv || k->rand != rand)
3209 continue; 3197 continue;
3210 3198
3211 if (ltk_role(k->type) != role) 3199 if (ltk_role(k->type) != role)
3212 continue; 3200 continue;
3213 3201
3202 rcu_read_unlock();
3214 return k; 3203 return k;
3215 } 3204 }
3205 rcu_read_unlock();
3216 3206
3217 return NULL; 3207 return NULL;
3218} 3208}
@@ -3222,11 +3212,16 @@ struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
3222{ 3212{
3223 struct smp_ltk *k; 3213 struct smp_ltk *k;
3224 3214
3225 list_for_each_entry(k, &hdev->long_term_keys, list) 3215 rcu_read_lock();
3216 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
3226 if (addr_type == k->bdaddr_type && 3217 if (addr_type == k->bdaddr_type &&
3227 bacmp(bdaddr, &k->bdaddr) == 0 && 3218 bacmp(bdaddr, &k->bdaddr) == 0 &&
3228 ltk_role(k->type) == role) 3219 ltk_role(k->type) == role) {
3220 rcu_read_unlock();
3229 return k; 3221 return k;
3222 }
3223 }
3224 rcu_read_unlock();
3230 3225
3231 return NULL; 3226 return NULL;
3232} 3227}
@@ -3235,17 +3230,22 @@ struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa)
3235{ 3230{
3236 struct smp_irk *irk; 3231 struct smp_irk *irk;
3237 3232
3238 list_for_each_entry(irk, &hdev->identity_resolving_keys, list) { 3233 rcu_read_lock();
3239 if (!bacmp(&irk->rpa, rpa)) 3234 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
3235 if (!bacmp(&irk->rpa, rpa)) {
3236 rcu_read_unlock();
3240 return irk; 3237 return irk;
3238 }
3241 } 3239 }
3242 3240
3243 list_for_each_entry(irk, &hdev->identity_resolving_keys, list) { 3241 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
3244 if (smp_irk_matches(hdev, irk->val, rpa)) { 3242 if (smp_irk_matches(hdev, irk->val, rpa)) {
3245 bacpy(&irk->rpa, rpa); 3243 bacpy(&irk->rpa, rpa);
3244 rcu_read_unlock();
3246 return irk; 3245 return irk;
3247 } 3246 }
3248 } 3247 }
3248 rcu_read_unlock();
3249 3249
3250 return NULL; 3250 return NULL;
3251} 3251}
@@ -3259,11 +3259,15 @@ struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
3259 if (addr_type == ADDR_LE_DEV_RANDOM && (bdaddr->b[5] & 0xc0) != 0xc0) 3259 if (addr_type == ADDR_LE_DEV_RANDOM && (bdaddr->b[5] & 0xc0) != 0xc0)
3260 return NULL; 3260 return NULL;
3261 3261
3262 list_for_each_entry(irk, &hdev->identity_resolving_keys, list) { 3262 rcu_read_lock();
3263 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
3263 if (addr_type == irk->addr_type && 3264 if (addr_type == irk->addr_type &&
3264 bacmp(bdaddr, &irk->bdaddr) == 0) 3265 bacmp(bdaddr, &irk->bdaddr) == 0) {
3266 rcu_read_unlock();
3265 return irk; 3267 return irk;
3268 }
3266 } 3269 }
3270 rcu_read_unlock();
3267 3271
3268 return NULL; 3272 return NULL;
3269} 3273}
@@ -3329,7 +3333,7 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
3329 key = kzalloc(sizeof(*key), GFP_KERNEL); 3333 key = kzalloc(sizeof(*key), GFP_KERNEL);
3330 if (!key) 3334 if (!key)
3331 return NULL; 3335 return NULL;
3332 list_add(&key->list, &hdev->long_term_keys); 3336 list_add_rcu(&key->list, &hdev->long_term_keys);
3333 } 3337 }
3334 3338
3335 bacpy(&key->bdaddr, bdaddr); 3339 bacpy(&key->bdaddr, bdaddr);
@@ -3358,7 +3362,7 @@ struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
3358 bacpy(&irk->bdaddr, bdaddr); 3362 bacpy(&irk->bdaddr, bdaddr);
3359 irk->addr_type = addr_type; 3363 irk->addr_type = addr_type;
3360 3364
3361 list_add(&irk->list, &hdev->identity_resolving_keys); 3365 list_add_rcu(&irk->list, &hdev->identity_resolving_keys);
3362 } 3366 }
3363 3367
3364 memcpy(irk->val, val, 16); 3368 memcpy(irk->val, val, 16);
@@ -3385,17 +3389,17 @@ int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
3385 3389
3386int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) 3390int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type)
3387{ 3391{
3388 struct smp_ltk *k, *tmp; 3392 struct smp_ltk *k;
3389 int removed = 0; 3393 int removed = 0;
3390 3394
3391 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { 3395 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
3392 if (bacmp(bdaddr, &k->bdaddr) || k->bdaddr_type != bdaddr_type) 3396 if (bacmp(bdaddr, &k->bdaddr) || k->bdaddr_type != bdaddr_type)
3393 continue; 3397 continue;
3394 3398
3395 BT_DBG("%s removing %pMR", hdev->name, bdaddr); 3399 BT_DBG("%s removing %pMR", hdev->name, bdaddr);
3396 3400
3397 list_del(&k->list); 3401 list_del_rcu(&k->list);
3398 kfree(k); 3402 kfree_rcu(k, rcu);
3399 removed++; 3403 removed++;
3400 } 3404 }
3401 3405
@@ -3404,16 +3408,16 @@ int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type)
3404 3408
3405void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) 3409void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type)
3406{ 3410{
3407 struct smp_irk *k, *tmp; 3411 struct smp_irk *k;
3408 3412
3409 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { 3413 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) {
3410 if (bacmp(bdaddr, &k->bdaddr) || k->addr_type != addr_type) 3414 if (bacmp(bdaddr, &k->bdaddr) || k->addr_type != addr_type)
3411 continue; 3415 continue;
3412 3416
3413 BT_DBG("%s removing %pMR", hdev->name, bdaddr); 3417 BT_DBG("%s removing %pMR", hdev->name, bdaddr);
3414 3418
3415 list_del(&k->list); 3419 list_del_rcu(&k->list);
3416 kfree(k); 3420 kfree_rcu(k, rcu);
3417 } 3421 }
3418} 3422}
3419 3423
@@ -3475,7 +3479,7 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev)
3475} 3479}
3476 3480
3477int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 3481int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3478 u8 *hash, u8 *randomizer) 3482 u8 *hash, u8 *rand)
3479{ 3483{
3480 struct oob_data *data; 3484 struct oob_data *data;
3481 3485
@@ -3490,10 +3494,10 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3490 } 3494 }
3491 3495
3492 memcpy(data->hash192, hash, sizeof(data->hash192)); 3496 memcpy(data->hash192, hash, sizeof(data->hash192));
3493 memcpy(data->randomizer192, randomizer, sizeof(data->randomizer192)); 3497 memcpy(data->rand192, rand, sizeof(data->rand192));
3494 3498
3495 memset(data->hash256, 0, sizeof(data->hash256)); 3499 memset(data->hash256, 0, sizeof(data->hash256));
3496 memset(data->randomizer256, 0, sizeof(data->randomizer256)); 3500 memset(data->rand256, 0, sizeof(data->rand256));
3497 3501
3498 BT_DBG("%s for %pMR", hdev->name, bdaddr); 3502 BT_DBG("%s for %pMR", hdev->name, bdaddr);
3499 3503
@@ -3501,8 +3505,8 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3501} 3505}
3502 3506
3503int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 3507int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3504 u8 *hash192, u8 *randomizer192, 3508 u8 *hash192, u8 *rand192,
3505 u8 *hash256, u8 *randomizer256) 3509 u8 *hash256, u8 *rand256)
3506{ 3510{
3507 struct oob_data *data; 3511 struct oob_data *data;
3508 3512
@@ -3517,10 +3521,10 @@ int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
3517 } 3521 }
3518 3522
3519 memcpy(data->hash192, hash192, sizeof(data->hash192)); 3523 memcpy(data->hash192, hash192, sizeof(data->hash192));
3520 memcpy(data->randomizer192, randomizer192, sizeof(data->randomizer192)); 3524 memcpy(data->rand192, rand192, sizeof(data->rand192));
3521 3525
3522 memcpy(data->hash256, hash256, sizeof(data->hash256)); 3526 memcpy(data->hash256, hash256, sizeof(data->hash256));
3523 memcpy(data->randomizer256, randomizer256, sizeof(data->randomizer256)); 3527 memcpy(data->rand256, rand256, sizeof(data->rand256));
3524 3528
3525 BT_DBG("%s for %pMR", hdev->name, bdaddr); 3529 BT_DBG("%s for %pMR", hdev->name, bdaddr);
3526 3530
@@ -4244,6 +4248,24 @@ int hci_resume_dev(struct hci_dev *hdev)
4244} 4248}
4245EXPORT_SYMBOL(hci_resume_dev); 4249EXPORT_SYMBOL(hci_resume_dev);
4246 4250
4251/* Reset HCI device */
4252int hci_reset_dev(struct hci_dev *hdev)
4253{
4254 const u8 hw_err[] = { HCI_EV_HARDWARE_ERROR, 0x01, 0x00 };
4255 struct sk_buff *skb;
4256
4257 skb = bt_skb_alloc(3, GFP_ATOMIC);
4258 if (!skb)
4259 return -ENOMEM;
4260
4261 bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
4262 memcpy(skb_put(skb, 3), hw_err, 3);
4263
4264 /* Send Hardware Error to upper stack */
4265 return hci_recv_frame(hdev, skb);
4266}
4267EXPORT_SYMBOL(hci_reset_dev);
4268
4247/* Receive frame from HCI drivers */ 4269/* Receive frame from HCI drivers */
4248int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) 4270int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
4249{ 4271{
@@ -4477,7 +4499,7 @@ int hci_req_run(struct hci_request *req, hci_req_complete_t complete)
4477 4499
4478 BT_DBG("length %u", skb_queue_len(&req->cmd_q)); 4500 BT_DBG("length %u", skb_queue_len(&req->cmd_q));
4479 4501
4480 /* If an error occured during request building, remove all HCI 4502 /* If an error occurred during request building, remove all HCI
4481 * commands queued on the HCI request queue. 4503 * commands queued on the HCI request queue.
4482 */ 4504 */
4483 if (req->err) { 4505 if (req->err) {
@@ -4546,7 +4568,7 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
4546 return -ENOMEM; 4568 return -ENOMEM;
4547 } 4569 }
4548 4570
4549 /* Stand-alone HCI commands must be flaged as 4571 /* Stand-alone HCI commands must be flagged as
4550 * single-command requests. 4572 * single-command requests.
4551 */ 4573 */
4552 bt_cb(skb)->req.start = true; 4574 bt_cb(skb)->req.start = true;
@@ -4566,7 +4588,7 @@ void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
4566 4588
4567 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); 4589 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen);
4568 4590
4569 /* If an error occured during request building, there is no point in 4591 /* If an error occurred during request building, there is no point in
4570 * queueing the HCI command. We can simply return. 4592 * queueing the HCI command. We can simply return.
4571 */ 4593 */
4572 if (req->err) 4594 if (req->err)
@@ -4661,8 +4683,12 @@ static void hci_queue_acl(struct hci_chan *chan, struct sk_buff_head *queue,
4661 4683
4662 skb_shinfo(skb)->frag_list = NULL; 4684 skb_shinfo(skb)->frag_list = NULL;
4663 4685
4664 /* Queue all fragments atomically */ 4686 /* Queue all fragments atomically. We need to use spin_lock_bh
4665 spin_lock(&queue->lock); 4687 * here because of 6LoWPAN links, as there this function is
4688 * called from softirq and using normal spin lock could cause
4689 * deadlocks.
4690 */
4691 spin_lock_bh(&queue->lock);
4666 4692
4667 __skb_queue_tail(queue, skb); 4693 __skb_queue_tail(queue, skb);
4668 4694
@@ -4679,7 +4705,7 @@ static void hci_queue_acl(struct hci_chan *chan, struct sk_buff_head *queue,
4679 __skb_queue_tail(queue, skb); 4705 __skb_queue_tail(queue, skb);
4680 } while (list); 4706 } while (list);
4681 4707
4682 spin_unlock(&queue->lock); 4708 spin_unlock_bh(&queue->lock);
4683 } 4709 }
4684} 4710}
4685 4711
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8b0a2a6de419..844f7d1ff1cd 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -189,6 +189,9 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
189 189
190 clear_bit(HCI_RESET, &hdev->flags); 190 clear_bit(HCI_RESET, &hdev->flags);
191 191
192 if (status)
193 return;
194
192 /* Reset all non-persistent flags */ 195 /* Reset all non-persistent flags */
193 hdev->dev_flags &= ~HCI_PERSISTENT_MASK; 196 hdev->dev_flags &= ~HCI_PERSISTENT_MASK;
194 197
@@ -205,6 +208,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
205 hdev->le_scan_type = LE_SCAN_PASSIVE; 208 hdev->le_scan_type = LE_SCAN_PASSIVE;
206 209
207 hdev->ssp_debug_mode = 0; 210 hdev->ssp_debug_mode = 0;
211
212 hci_bdaddr_list_clear(&hdev->le_white_list);
208} 213}
209 214
210static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) 215static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -989,8 +994,8 @@ static void hci_cc_read_local_oob_data(struct hci_dev *hdev,
989 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); 994 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
990 995
991 hci_dev_lock(hdev); 996 hci_dev_lock(hdev);
992 mgmt_read_local_oob_data_complete(hdev, rp->hash, rp->randomizer, 997 mgmt_read_local_oob_data_complete(hdev, rp->hash, rp->rand, NULL, NULL,
993 NULL, NULL, rp->status); 998 rp->status);
994 hci_dev_unlock(hdev); 999 hci_dev_unlock(hdev);
995} 1000}
996 1001
@@ -1002,8 +1007,8 @@ static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev,
1002 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); 1007 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1003 1008
1004 hci_dev_lock(hdev); 1009 hci_dev_lock(hdev);
1005 mgmt_read_local_oob_data_complete(hdev, rp->hash192, rp->randomizer192, 1010 mgmt_read_local_oob_data_complete(hdev, rp->hash192, rp->rand192,
1006 rp->hash256, rp->randomizer256, 1011 rp->hash256, rp->rand256,
1007 rp->status); 1012 rp->status);
1008 hci_dev_unlock(hdev); 1013 hci_dev_unlock(hdev);
1009} 1014}
@@ -1045,7 +1050,7 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
1045 1050
1046 hci_dev_lock(hdev); 1051 hci_dev_lock(hdev);
1047 1052
1048 /* If we're doing connection initation as peripheral. Set a 1053 /* If we're doing connection initiation as peripheral. Set a
1049 * timeout in case something goes wrong. 1054 * timeout in case something goes wrong.
1050 */ 1055 */
1051 if (*sent) { 1056 if (*sent) {
@@ -1576,9 +1581,15 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
1576 struct discovery_state *discov = &hdev->discovery; 1581 struct discovery_state *discov = &hdev->discovery;
1577 struct inquiry_entry *e; 1582 struct inquiry_entry *e;
1578 1583
1579 if (conn && !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 1584 /* Update the mgmt connected state if necessary. Be careful with
1580 mgmt_device_connected(hdev, bdaddr, ACL_LINK, 0x00, 0, name, 1585 * conn objects that exist but are not (yet) connected however.
1581 name_len, conn->dev_class); 1586 * Only those in BT_CONFIG or BT_CONNECTED states can be
1587 * considered connected.
1588 */
1589 if (conn &&
1590 (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) &&
1591 !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
1592 mgmt_device_connected(hdev, conn, 0, name, name_len);
1582 1593
1583 if (discov->state == DISCOVERY_STOPPED) 1594 if (discov->state == DISCOVERY_STOPPED)
1584 return; 1595 return;
@@ -1943,6 +1954,29 @@ unlock:
1943 hci_dev_unlock(hdev); 1954 hci_dev_unlock(hdev);
1944} 1955}
1945 1956
1957static void hci_cs_switch_role(struct hci_dev *hdev, u8 status)
1958{
1959 struct hci_cp_switch_role *cp;
1960 struct hci_conn *conn;
1961
1962 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1963
1964 if (!status)
1965 return;
1966
1967 cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE);
1968 if (!cp)
1969 return;
1970
1971 hci_dev_lock(hdev);
1972
1973 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1974 if (conn)
1975 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
1976
1977 hci_dev_unlock(hdev);
1978}
1979
1946static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1980static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1947{ 1981{
1948 __u8 status = *((__u8 *) skb->data); 1982 __u8 status = *((__u8 *) skb->data);
@@ -2536,9 +2570,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev,
2536 cp.pscan_rep_mode = 0x02; 2570 cp.pscan_rep_mode = 0x02;
2537 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); 2571 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2538 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 2572 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2539 mgmt_device_connected(hdev, &conn->dst, conn->type, 2573 mgmt_device_connected(hdev, conn, 0, NULL, 0);
2540 conn->dst_type, 0, NULL, 0,
2541 conn->dev_class);
2542 2574
2543 if (!hci_outgoing_auth_needed(hdev, conn)) { 2575 if (!hci_outgoing_auth_needed(hdev, conn)) {
2544 conn->state = BT_CONNECTED; 2576 conn->state = BT_CONNECTED;
@@ -2848,6 +2880,10 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2848 hci_cs_create_conn(hdev, ev->status); 2880 hci_cs_create_conn(hdev, ev->status);
2849 break; 2881 break;
2850 2882
2883 case HCI_OP_DISCONNECT:
2884 hci_cs_disconnect(hdev, ev->status);
2885 break;
2886
2851 case HCI_OP_ADD_SCO: 2887 case HCI_OP_ADD_SCO:
2852 hci_cs_add_sco(hdev, ev->status); 2888 hci_cs_add_sco(hdev, ev->status);
2853 break; 2889 break;
@@ -2876,24 +2912,24 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2876 hci_cs_setup_sync_conn(hdev, ev->status); 2912 hci_cs_setup_sync_conn(hdev, ev->status);
2877 break; 2913 break;
2878 2914
2879 case HCI_OP_SNIFF_MODE: 2915 case HCI_OP_CREATE_PHY_LINK:
2880 hci_cs_sniff_mode(hdev, ev->status); 2916 hci_cs_create_phylink(hdev, ev->status);
2881 break; 2917 break;
2882 2918
2883 case HCI_OP_EXIT_SNIFF_MODE: 2919 case HCI_OP_ACCEPT_PHY_LINK:
2884 hci_cs_exit_sniff_mode(hdev, ev->status); 2920 hci_cs_accept_phylink(hdev, ev->status);
2885 break; 2921 break;
2886 2922
2887 case HCI_OP_DISCONNECT: 2923 case HCI_OP_SNIFF_MODE:
2888 hci_cs_disconnect(hdev, ev->status); 2924 hci_cs_sniff_mode(hdev, ev->status);
2889 break; 2925 break;
2890 2926
2891 case HCI_OP_CREATE_PHY_LINK: 2927 case HCI_OP_EXIT_SNIFF_MODE:
2892 hci_cs_create_phylink(hdev, ev->status); 2928 hci_cs_exit_sniff_mode(hdev, ev->status);
2893 break; 2929 break;
2894 2930
2895 case HCI_OP_ACCEPT_PHY_LINK: 2931 case HCI_OP_SWITCH_ROLE:
2896 hci_cs_accept_phylink(hdev, ev->status); 2932 hci_cs_switch_role(hdev, ev->status);
2897 break; 2933 break;
2898 2934
2899 case HCI_OP_LE_CREATE_CONN: 2935 case HCI_OP_LE_CREATE_CONN:
@@ -2923,6 +2959,13 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2923 } 2959 }
2924} 2960}
2925 2961
2962static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb)
2963{
2964 struct hci_ev_hardware_error *ev = (void *) skb->data;
2965
2966 BT_ERR("%s hardware error 0x%2.2x", hdev->name, ev->code);
2967}
2968
2926static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 2969static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2927{ 2970{
2928 struct hci_ev_role_change *ev = (void *) skb->data; 2971 struct hci_ev_role_change *ev = (void *) skb->data;
@@ -3434,9 +3477,7 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev,
3434 cp.pscan_rep_mode = 0x02; 3477 cp.pscan_rep_mode = 0x02;
3435 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); 3478 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
3436 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 3479 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3437 mgmt_device_connected(hdev, &conn->dst, conn->type, 3480 mgmt_device_connected(hdev, conn, 0, NULL, 0);
3438 conn->dst_type, 0, NULL, 0,
3439 conn->dev_class);
3440 3481
3441 if (!hci_outgoing_auth_needed(hdev, conn)) { 3482 if (!hci_outgoing_auth_needed(hdev, conn)) {
3442 conn->state = BT_CONNECTED; 3483 conn->state = BT_CONNECTED;
@@ -3955,11 +3996,9 @@ static void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3955 3996
3956 bacpy(&cp.bdaddr, &ev->bdaddr); 3997 bacpy(&cp.bdaddr, &ev->bdaddr);
3957 memcpy(cp.hash192, data->hash192, sizeof(cp.hash192)); 3998 memcpy(cp.hash192, data->hash192, sizeof(cp.hash192));
3958 memcpy(cp.randomizer192, data->randomizer192, 3999 memcpy(cp.rand192, data->rand192, sizeof(cp.rand192));
3959 sizeof(cp.randomizer192));
3960 memcpy(cp.hash256, data->hash256, sizeof(cp.hash256)); 4000 memcpy(cp.hash256, data->hash256, sizeof(cp.hash256));
3961 memcpy(cp.randomizer256, data->randomizer256, 4001 memcpy(cp.rand256, data->rand256, sizeof(cp.rand256));
3962 sizeof(cp.randomizer256));
3963 4002
3964 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_EXT_DATA_REPLY, 4003 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_EXT_DATA_REPLY,
3965 sizeof(cp), &cp); 4004 sizeof(cp), &cp);
@@ -3968,8 +4007,7 @@ static void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3968 4007
3969 bacpy(&cp.bdaddr, &ev->bdaddr); 4008 bacpy(&cp.bdaddr, &ev->bdaddr);
3970 memcpy(cp.hash, data->hash192, sizeof(cp.hash)); 4009 memcpy(cp.hash, data->hash192, sizeof(cp.hash));
3971 memcpy(cp.randomizer, data->randomizer192, 4010 memcpy(cp.rand, data->rand192, sizeof(cp.rand));
3972 sizeof(cp.randomizer));
3973 4011
3974 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, 4012 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY,
3975 sizeof(cp), &cp); 4013 sizeof(cp), &cp);
@@ -4214,8 +4252,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4214 } 4252 }
4215 4253
4216 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 4254 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
4217 mgmt_device_connected(hdev, &conn->dst, conn->type, 4255 mgmt_device_connected(hdev, conn, 0, NULL, 0);
4218 conn->dst_type, 0, NULL, 0, NULL);
4219 4256
4220 conn->sec_level = BT_SECURITY_LOW; 4257 conn->sec_level = BT_SECURITY_LOW;
4221 conn->handle = __le16_to_cpu(ev->handle); 4258 conn->handle = __le16_to_cpu(ev->handle);
@@ -4269,25 +4306,26 @@ static void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
4269} 4306}
4270 4307
4271/* This function requires the caller holds hdev->lock */ 4308/* This function requires the caller holds hdev->lock */
4272static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr, 4309static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
4273 u8 addr_type, u8 adv_type) 4310 bdaddr_t *addr,
4311 u8 addr_type, u8 adv_type)
4274{ 4312{
4275 struct hci_conn *conn; 4313 struct hci_conn *conn;
4276 struct hci_conn_params *params; 4314 struct hci_conn_params *params;
4277 4315
4278 /* If the event is not connectable don't proceed further */ 4316 /* If the event is not connectable don't proceed further */
4279 if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) 4317 if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND)
4280 return; 4318 return NULL;
4281 4319
4282 /* Ignore if the device is blocked */ 4320 /* Ignore if the device is blocked */
4283 if (hci_bdaddr_list_lookup(&hdev->blacklist, addr, addr_type)) 4321 if (hci_bdaddr_list_lookup(&hdev->blacklist, addr, addr_type))
4284 return; 4322 return NULL;
4285 4323
4286 /* Most controller will fail if we try to create new connections 4324 /* Most controller will fail if we try to create new connections
4287 * while we have an existing one in slave role. 4325 * while we have an existing one in slave role.
4288 */ 4326 */
4289 if (hdev->conn_hash.le_num_slave > 0) 4327 if (hdev->conn_hash.le_num_slave > 0)
4290 return; 4328 return NULL;
4291 4329
4292 /* If we're not connectable only connect devices that we have in 4330 /* If we're not connectable only connect devices that we have in
4293 * our pend_le_conns list. 4331 * our pend_le_conns list.
@@ -4295,7 +4333,7 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
4295 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, 4333 params = hci_pend_le_action_lookup(&hdev->pend_le_conns,
4296 addr, addr_type); 4334 addr, addr_type);
4297 if (!params) 4335 if (!params)
4298 return; 4336 return NULL;
4299 4337
4300 switch (params->auto_connect) { 4338 switch (params->auto_connect) {
4301 case HCI_AUTO_CONN_DIRECT: 4339 case HCI_AUTO_CONN_DIRECT:
@@ -4304,7 +4342,7 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
4304 * incoming connections from slave devices. 4342 * incoming connections from slave devices.
4305 */ 4343 */
4306 if (adv_type != LE_ADV_DIRECT_IND) 4344 if (adv_type != LE_ADV_DIRECT_IND)
4307 return; 4345 return NULL;
4308 break; 4346 break;
4309 case HCI_AUTO_CONN_ALWAYS: 4347 case HCI_AUTO_CONN_ALWAYS:
4310 /* Devices advertising with ADV_IND or ADV_DIRECT_IND 4348 /* Devices advertising with ADV_IND or ADV_DIRECT_IND
@@ -4315,7 +4353,7 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
4315 */ 4353 */
4316 break; 4354 break;
4317 default: 4355 default:
4318 return; 4356 return NULL;
4319 } 4357 }
4320 4358
4321 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW, 4359 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
@@ -4328,7 +4366,7 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
4328 * count consistent once the connection is established. 4366 * count consistent once the connection is established.
4329 */ 4367 */
4330 params->conn = hci_conn_get(conn); 4368 params->conn = hci_conn_get(conn);
4331 return; 4369 return conn;
4332 } 4370 }
4333 4371
4334 switch (PTR_ERR(conn)) { 4372 switch (PTR_ERR(conn)) {
@@ -4341,7 +4379,10 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
4341 break; 4379 break;
4342 default: 4380 default:
4343 BT_DBG("Failed to connect: err %ld", PTR_ERR(conn)); 4381 BT_DBG("Failed to connect: err %ld", PTR_ERR(conn));
4382 return NULL;
4344 } 4383 }
4384
4385 return NULL;
4345} 4386}
4346 4387
4347static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, 4388static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
@@ -4349,6 +4390,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
4349{ 4390{
4350 struct discovery_state *d = &hdev->discovery; 4391 struct discovery_state *d = &hdev->discovery;
4351 struct smp_irk *irk; 4392 struct smp_irk *irk;
4393 struct hci_conn *conn;
4352 bool match; 4394 bool match;
4353 u32 flags; 4395 u32 flags;
4354 4396
@@ -4360,7 +4402,14 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
4360 } 4402 }
4361 4403
4362 /* Check if we have been requested to connect to this device */ 4404 /* Check if we have been requested to connect to this device */
4363 check_pending_le_conn(hdev, bdaddr, bdaddr_type, type); 4405 conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, type);
4406 if (conn && type == LE_ADV_IND) {
4407 /* Store report for later inclusion by
4408 * mgmt_device_connected
4409 */
4410 memcpy(conn->le_adv_data, data, len);
4411 conn->le_adv_data_len = len;
4412 }
4364 4413
4365 /* Passive scanning shouldn't trigger any device found events, 4414 /* Passive scanning shouldn't trigger any device found events,
4366 * except for devices marked as CONN_REPORT for which we do send 4415 * except for devices marked as CONN_REPORT for which we do send
@@ -4526,8 +4575,8 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
4526 */ 4575 */
4527 if (ltk->type == SMP_STK) { 4576 if (ltk->type == SMP_STK) {
4528 set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); 4577 set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags);
4529 list_del(&ltk->list); 4578 list_del_rcu(&ltk->list);
4530 kfree(ltk); 4579 kfree_rcu(ltk, rcu);
4531 } else { 4580 } else {
4532 clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); 4581 clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags);
4533 } 4582 }
@@ -4735,6 +4784,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
4735 hci_cmd_status_evt(hdev, skb); 4784 hci_cmd_status_evt(hdev, skb);
4736 break; 4785 break;
4737 4786
4787 case HCI_EV_HARDWARE_ERROR:
4788 hci_hardware_error_evt(hdev, skb);
4789 break;
4790
4738 case HCI_EV_ROLE_CHANGE: 4791 case HCI_EV_ROLE_CHANGE:
4739 hci_role_change_evt(hdev, skb); 4792 hci_role_change_evt(hdev, skb);
4740 break; 4793 break;
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 115f149362ba..bbc4ac748263 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -987,7 +987,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
987 skb_queue_tail(&hdev->raw_q, skb); 987 skb_queue_tail(&hdev->raw_q, skb);
988 queue_work(hdev->workqueue, &hdev->tx_work); 988 queue_work(hdev->workqueue, &hdev->tx_work);
989 } else { 989 } else {
990 /* Stand-alone HCI commands must be flaged as 990 /* Stand-alone HCI commands must be flagged as
991 * single-command requests. 991 * single-command requests.
992 */ 992 */
993 bt_cb(skb)->req.start = true; 993 bt_cb(skb)->req.start = true;
diff --git a/net/bluetooth/hidp/Kconfig b/net/bluetooth/hidp/Kconfig
index 9332bc7aa851..bc8610b24077 100644
--- a/net/bluetooth/hidp/Kconfig
+++ b/net/bluetooth/hidp/Kconfig
@@ -1,6 +1,6 @@
1config BT_HIDP 1config BT_HIDP
2 tristate "HIDP protocol support" 2 tristate "HIDP protocol support"
3 depends on BT && INPUT 3 depends on BT_BREDR && INPUT
4 select HID 4 select HID
5 help 5 help
6 HIDP (Human Interface Device Protocol) is a transport layer 6 HIDP (Human Interface Device Protocol) is a transport layer
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 1b7d605706aa..cc25d0b74b36 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -736,14 +736,10 @@ static int hidp_setup_hid(struct hidp_session *session,
736 struct hid_device *hid; 736 struct hid_device *hid;
737 int err; 737 int err;
738 738
739 session->rd_data = kzalloc(req->rd_size, GFP_KERNEL); 739 session->rd_data = memdup_user(req->rd_data, req->rd_size);
740 if (!session->rd_data) 740 if (IS_ERR(session->rd_data))
741 return -ENOMEM; 741 return PTR_ERR(session->rd_data);
742 742
743 if (copy_from_user(session->rd_data, req->rd_data, req->rd_size)) {
744 err = -EFAULT;
745 goto fault;
746 }
747 session->rd_size = req->rd_size; 743 session->rd_size = req->rd_size;
748 744
749 hid = hid_allocate_device(); 745 hid = hid_allocate_device();
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b6f9777e057d..8e1273173020 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -424,6 +424,9 @@ struct l2cap_chan *l2cap_chan_create(void)
424 424
425 mutex_init(&chan->lock); 425 mutex_init(&chan->lock);
426 426
427 /* Set default lock nesting level */
428 atomic_set(&chan->nesting, L2CAP_NESTING_NORMAL);
429
427 write_lock(&chan_list_lock); 430 write_lock(&chan_list_lock);
428 list_add(&chan->global_l, &chan_list); 431 list_add(&chan->global_l, &chan_list);
429 write_unlock(&chan_list_lock); 432 write_unlock(&chan_list_lock);
@@ -567,7 +570,8 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
567 570
568 __clear_chan_timer(chan); 571 __clear_chan_timer(chan);
569 572
570 BT_DBG("chan %p, conn %p, err %d", chan, conn, err); 573 BT_DBG("chan %p, conn %p, err %d, state %s", chan, conn, err,
574 state_to_string(chan->state));
571 575
572 chan->ops->teardown(chan, err); 576 chan->ops->teardown(chan, err);
573 577
@@ -3873,9 +3877,7 @@ static int l2cap_connect_req(struct l2cap_conn *conn,
3873 hci_dev_lock(hdev); 3877 hci_dev_lock(hdev);
3874 if (test_bit(HCI_MGMT, &hdev->dev_flags) && 3878 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
3875 !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags)) 3879 !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags))
3876 mgmt_device_connected(hdev, &hcon->dst, hcon->type, 3880 mgmt_device_connected(hdev, hcon, 0, NULL, 0);
3877 hcon->dst_type, 0, NULL, 0,
3878 hcon->dev_class);
3879 hci_dev_unlock(hdev); 3881 hci_dev_unlock(hdev);
3880 3882
3881 l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP, 0); 3883 l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP, 0);
@@ -4084,7 +4086,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
4084 chan->num_conf_req++; 4086 chan->num_conf_req++;
4085 } 4087 }
4086 4088
4087 /* Got Conf Rsp PENDING from remote side and asume we sent 4089 /* Got Conf Rsp PENDING from remote side and assume we sent
4088 Conf Rsp PENDING in the code above */ 4090 Conf Rsp PENDING in the code above */
4089 if (test_bit(CONF_REM_CONF_PEND, &chan->conf_state) && 4091 if (test_bit(CONF_REM_CONF_PEND, &chan->conf_state) &&
4090 test_bit(CONF_LOC_CONF_PEND, &chan->conf_state)) { 4092 test_bit(CONF_LOC_CONF_PEND, &chan->conf_state)) {
@@ -5217,9 +5219,10 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn,
5217 u8 *data) 5219 u8 *data)
5218{ 5220{
5219 struct l2cap_le_conn_rsp *rsp = (struct l2cap_le_conn_rsp *) data; 5221 struct l2cap_le_conn_rsp *rsp = (struct l2cap_le_conn_rsp *) data;
5222 struct hci_conn *hcon = conn->hcon;
5220 u16 dcid, mtu, mps, credits, result; 5223 u16 dcid, mtu, mps, credits, result;
5221 struct l2cap_chan *chan; 5224 struct l2cap_chan *chan;
5222 int err; 5225 int err, sec_level;
5223 5226
5224 if (cmd_len < sizeof(*rsp)) 5227 if (cmd_len < sizeof(*rsp))
5225 return -EPROTO; 5228 return -EPROTO;
@@ -5258,6 +5261,26 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn,
5258 l2cap_chan_ready(chan); 5261 l2cap_chan_ready(chan);
5259 break; 5262 break;
5260 5263
5264 case L2CAP_CR_AUTHENTICATION:
5265 case L2CAP_CR_ENCRYPTION:
5266 /* If we already have MITM protection we can't do
5267 * anything.
5268 */
5269 if (hcon->sec_level > BT_SECURITY_MEDIUM) {
5270 l2cap_chan_del(chan, ECONNREFUSED);
5271 break;
5272 }
5273
5274 sec_level = hcon->sec_level + 1;
5275 if (chan->sec_level < sec_level)
5276 chan->sec_level = sec_level;
5277
5278 /* We'll need to send a new Connect Request */
5279 clear_bit(FLAG_LE_CONN_REQ_SENT, &chan->flags);
5280
5281 smp_conn_security(hcon, chan->sec_level);
5282 break;
5283
5261 default: 5284 default:
5262 l2cap_chan_del(chan, ECONNREFUSED); 5285 l2cap_chan_del(chan, ECONNREFUSED);
5263 break; 5286 break;
@@ -5390,7 +5413,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
5390 mutex_lock(&conn->chan_lock); 5413 mutex_lock(&conn->chan_lock);
5391 l2cap_chan_lock(pchan); 5414 l2cap_chan_lock(pchan);
5392 5415
5393 if (!smp_sufficient_security(conn->hcon, pchan->sec_level)) { 5416 if (!smp_sufficient_security(conn->hcon, pchan->sec_level,
5417 SMP_ALLOW_STK)) {
5394 result = L2CAP_CR_AUTHENTICATION; 5418 result = L2CAP_CR_AUTHENTICATION;
5395 chan = NULL; 5419 chan = NULL;
5396 goto response_unlock; 5420 goto response_unlock;
@@ -5494,6 +5518,7 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
5494 if (credits > max_credits) { 5518 if (credits > max_credits) {
5495 BT_ERR("LE credits overflow"); 5519 BT_ERR("LE credits overflow");
5496 l2cap_send_disconn_req(chan, ECONNRESET); 5520 l2cap_send_disconn_req(chan, ECONNRESET);
5521 l2cap_chan_unlock(chan);
5497 5522
5498 /* Return 0 so that we don't trigger an unnecessary 5523 /* Return 0 so that we don't trigger an unnecessary
5499 * command reject packet. 5524 * command reject packet.
@@ -7330,7 +7355,8 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
7330 l2cap_start_connection(chan); 7355 l2cap_start_connection(chan);
7331 else 7356 else
7332 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT); 7357 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
7333 } else if (chan->state == BT_CONNECT2) { 7358 } else if (chan->state == BT_CONNECT2 &&
7359 chan->mode != L2CAP_MODE_LE_FLOWCTL) {
7334 struct l2cap_conn_rsp rsp; 7360 struct l2cap_conn_rsp rsp;
7335 __u16 res, stat; 7361 __u16 res, stat;
7336 7362
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 31f106e61ca2..b0efb7202957 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -285,6 +285,12 @@ static int l2cap_sock_listen(struct socket *sock, int backlog)
285 sk->sk_max_ack_backlog = backlog; 285 sk->sk_max_ack_backlog = backlog;
286 sk->sk_ack_backlog = 0; 286 sk->sk_ack_backlog = 0;
287 287
288 /* Listening channels need to use nested locking in order not to
289 * cause lockdep warnings when the created child channels end up
290 * being locked in the same thread as the parent channel.
291 */
292 atomic_set(&chan->nesting, L2CAP_NESTING_PARENT);
293
288 chan->state = BT_LISTEN; 294 chan->state = BT_LISTEN;
289 sk->sk_state = BT_LISTEN; 295 sk->sk_state = BT_LISTEN;
290 296
@@ -301,7 +307,7 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
301 long timeo; 307 long timeo;
302 int err = 0; 308 int err = 0;
303 309
304 lock_sock_nested(sk, SINGLE_DEPTH_NESTING); 310 lock_sock_nested(sk, L2CAP_NESTING_PARENT);
305 311
306 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); 312 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
307 313
@@ -333,7 +339,7 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
333 339
334 release_sock(sk); 340 release_sock(sk);
335 timeo = schedule_timeout(timeo); 341 timeo = schedule_timeout(timeo);
336 lock_sock_nested(sk, SINGLE_DEPTH_NESTING); 342 lock_sock_nested(sk, L2CAP_NESTING_PARENT);
337 } 343 }
338 __set_current_state(TASK_RUNNING); 344 __set_current_state(TASK_RUNNING);
339 remove_wait_queue(sk_sleep(sk), &wait); 345 remove_wait_queue(sk_sleep(sk), &wait);
@@ -1096,6 +1102,8 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
1096 chan = l2cap_pi(sk)->chan; 1102 chan = l2cap_pi(sk)->chan;
1097 conn = chan->conn; 1103 conn = chan->conn;
1098 1104
1105 BT_DBG("chan %p state %s", chan, state_to_string(chan->state));
1106
1099 if (conn) 1107 if (conn)
1100 mutex_lock(&conn->chan_lock); 1108 mutex_lock(&conn->chan_lock);
1101 1109
@@ -1153,12 +1161,16 @@ static void l2cap_sock_cleanup_listen(struct sock *parent)
1153{ 1161{
1154 struct sock *sk; 1162 struct sock *sk;
1155 1163
1156 BT_DBG("parent %p", parent); 1164 BT_DBG("parent %p state %s", parent,
1165 state_to_string(parent->sk_state));
1157 1166
1158 /* Close not yet accepted channels */ 1167 /* Close not yet accepted channels */
1159 while ((sk = bt_accept_dequeue(parent, NULL))) { 1168 while ((sk = bt_accept_dequeue(parent, NULL))) {
1160 struct l2cap_chan *chan = l2cap_pi(sk)->chan; 1169 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
1161 1170
1171 BT_DBG("child chan %p state %s", chan,
1172 state_to_string(chan->state));
1173
1162 l2cap_chan_lock(chan); 1174 l2cap_chan_lock(chan);
1163 __clear_chan_timer(chan); 1175 __clear_chan_timer(chan);
1164 l2cap_chan_close(chan, ECONNRESET); 1176 l2cap_chan_close(chan, ECONNRESET);
@@ -1246,7 +1258,16 @@ static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err)
1246 struct sock *sk = chan->data; 1258 struct sock *sk = chan->data;
1247 struct sock *parent; 1259 struct sock *parent;
1248 1260
1249 lock_sock(sk); 1261 BT_DBG("chan %p state %s", chan, state_to_string(chan->state));
1262
1263 /* This callback can be called both for server (BT_LISTEN)
1264 * sockets as well as "normal" ones. To avoid lockdep warnings
1265 * with child socket locking (through l2cap_sock_cleanup_listen)
1266 * we need separation into separate nesting levels. The simplest
1267 * way to accomplish this is to inherit the nesting level used
1268 * for the channel.
1269 */
1270 lock_sock_nested(sk, atomic_read(&chan->nesting));
1250 1271
1251 parent = bt_sk(sk)->parent; 1272 parent = bt_sk(sk)->parent;
1252 1273
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index efb71b022ab6..cbeef5f62f3b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2725,10 +2725,40 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
2725 } 2725 }
2726 2726
2727 if (cp->addr.type == BDADDR_BREDR) { 2727 if (cp->addr.type == BDADDR_BREDR) {
2728 /* If disconnection is requested, then look up the
2729 * connection. If the remote device is connected, it
2730 * will be later used to terminate the link.
2731 *
2732 * Setting it to NULL explicitly will cause no
2733 * termination of the link.
2734 */
2735 if (cp->disconnect)
2736 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
2737 &cp->addr.bdaddr);
2738 else
2739 conn = NULL;
2740
2728 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); 2741 err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
2729 } else { 2742 } else {
2730 u8 addr_type; 2743 u8 addr_type;
2731 2744
2745 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
2746 &cp->addr.bdaddr);
2747 if (conn) {
2748 /* Defer clearing up the connection parameters
2749 * until closing to give a chance of keeping
2750 * them if a repairing happens.
2751 */
2752 set_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags);
2753
2754 /* If disconnection is not requested, then
2755 * clear the connection variable so that the
2756 * link is not terminated.
2757 */
2758 if (!cp->disconnect)
2759 conn = NULL;
2760 }
2761
2732 if (cp->addr.type == BDADDR_LE_PUBLIC) 2762 if (cp->addr.type == BDADDR_LE_PUBLIC)
2733 addr_type = ADDR_LE_DEV_PUBLIC; 2763 addr_type = ADDR_LE_DEV_PUBLIC;
2734 else 2764 else
@@ -2736,8 +2766,6 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
2736 2766
2737 hci_remove_irk(hdev, &cp->addr.bdaddr, addr_type); 2767 hci_remove_irk(hdev, &cp->addr.bdaddr, addr_type);
2738 2768
2739 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type);
2740
2741 err = hci_remove_ltk(hdev, &cp->addr.bdaddr, addr_type); 2769 err = hci_remove_ltk(hdev, &cp->addr.bdaddr, addr_type);
2742 } 2770 }
2743 2771
@@ -2747,17 +2775,9 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
2747 goto unlock; 2775 goto unlock;
2748 } 2776 }
2749 2777
2750 if (cp->disconnect) { 2778 /* If the connection variable is set, then termination of the
2751 if (cp->addr.type == BDADDR_BREDR) 2779 * link is requested.
2752 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, 2780 */
2753 &cp->addr.bdaddr);
2754 else
2755 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
2756 &cp->addr.bdaddr);
2757 } else {
2758 conn = NULL;
2759 }
2760
2761 if (!conn) { 2781 if (!conn) {
2762 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, 2782 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0,
2763 &rp, sizeof(rp)); 2783 &rp, sizeof(rp));
@@ -3062,6 +3082,11 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
3062 hci_conn_put(conn); 3082 hci_conn_put(conn);
3063 3083
3064 mgmt_pending_remove(cmd); 3084 mgmt_pending_remove(cmd);
3085
3086 /* The device is paired so there is no need to remove
3087 * its connection parameters anymore.
3088 */
3089 clear_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags);
3065} 3090}
3066 3091
3067void mgmt_smp_complete(struct hci_conn *conn, bool complete) 3092void mgmt_smp_complete(struct hci_conn *conn, bool complete)
@@ -3564,8 +3589,16 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
3564 struct mgmt_cp_add_remote_oob_data *cp = data; 3589 struct mgmt_cp_add_remote_oob_data *cp = data;
3565 u8 status; 3590 u8 status;
3566 3591
3592 if (cp->addr.type != BDADDR_BREDR) {
3593 err = cmd_complete(sk, hdev->id,
3594 MGMT_OP_ADD_REMOTE_OOB_DATA,
3595 MGMT_STATUS_INVALID_PARAMS,
3596 &cp->addr, sizeof(cp->addr));
3597 goto unlock;
3598 }
3599
3567 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, 3600 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr,
3568 cp->hash, cp->randomizer); 3601 cp->hash, cp->rand);
3569 if (err < 0) 3602 if (err < 0)
3570 status = MGMT_STATUS_FAILED; 3603 status = MGMT_STATUS_FAILED;
3571 else 3604 else
@@ -3577,11 +3610,17 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
3577 struct mgmt_cp_add_remote_oob_ext_data *cp = data; 3610 struct mgmt_cp_add_remote_oob_ext_data *cp = data;
3578 u8 status; 3611 u8 status;
3579 3612
3613 if (cp->addr.type != BDADDR_BREDR) {
3614 err = cmd_complete(sk, hdev->id,
3615 MGMT_OP_ADD_REMOTE_OOB_DATA,
3616 MGMT_STATUS_INVALID_PARAMS,
3617 &cp->addr, sizeof(cp->addr));
3618 goto unlock;
3619 }
3620
3580 err = hci_add_remote_oob_ext_data(hdev, &cp->addr.bdaddr, 3621 err = hci_add_remote_oob_ext_data(hdev, &cp->addr.bdaddr,
3581 cp->hash192, 3622 cp->hash192, cp->rand192,
3582 cp->randomizer192, 3623 cp->hash256, cp->rand256);
3583 cp->hash256,
3584 cp->randomizer256);
3585 if (err < 0) 3624 if (err < 0)
3586 status = MGMT_STATUS_FAILED; 3625 status = MGMT_STATUS_FAILED;
3587 else 3626 else
@@ -3595,6 +3634,7 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
3595 MGMT_STATUS_INVALID_PARAMS); 3634 MGMT_STATUS_INVALID_PARAMS);
3596 } 3635 }
3597 3636
3637unlock:
3598 hci_dev_unlock(hdev); 3638 hci_dev_unlock(hdev);
3599 return err; 3639 return err;
3600} 3640}
@@ -3608,14 +3648,26 @@ static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
3608 3648
3609 BT_DBG("%s", hdev->name); 3649 BT_DBG("%s", hdev->name);
3610 3650
3651 if (cp->addr.type != BDADDR_BREDR)
3652 return cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
3653 MGMT_STATUS_INVALID_PARAMS,
3654 &cp->addr, sizeof(cp->addr));
3655
3611 hci_dev_lock(hdev); 3656 hci_dev_lock(hdev);
3612 3657
3658 if (!bacmp(&cp->addr.bdaddr, BDADDR_ANY)) {
3659 hci_remote_oob_data_clear(hdev);
3660 status = MGMT_STATUS_SUCCESS;
3661 goto done;
3662 }
3663
3613 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr); 3664 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr);
3614 if (err < 0) 3665 if (err < 0)
3615 status = MGMT_STATUS_INVALID_PARAMS; 3666 status = MGMT_STATUS_INVALID_PARAMS;
3616 else 3667 else
3617 status = MGMT_STATUS_SUCCESS; 3668 status = MGMT_STATUS_SUCCESS;
3618 3669
3670done:
3619 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, 3671 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
3620 status, &cp->addr, sizeof(cp->addr)); 3672 status, &cp->addr, sizeof(cp->addr));
3621 3673
@@ -3702,20 +3754,23 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
3702 hci_dev_lock(hdev); 3754 hci_dev_lock(hdev);
3703 3755
3704 if (!hdev_is_powered(hdev)) { 3756 if (!hdev_is_powered(hdev)) {
3705 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3757 err = cmd_complete(sk, hdev->id, MGMT_OP_START_DISCOVERY,
3706 MGMT_STATUS_NOT_POWERED); 3758 MGMT_STATUS_NOT_POWERED,
3759 &cp->type, sizeof(cp->type));
3707 goto failed; 3760 goto failed;
3708 } 3761 }
3709 3762
3710 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) { 3763 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) {
3711 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3764 err = cmd_complete(sk, hdev->id, MGMT_OP_START_DISCOVERY,
3712 MGMT_STATUS_BUSY); 3765 MGMT_STATUS_BUSY, &cp->type,
3766 sizeof(cp->type));
3713 goto failed; 3767 goto failed;
3714 } 3768 }
3715 3769
3716 if (hdev->discovery.state != DISCOVERY_STOPPED) { 3770 if (hdev->discovery.state != DISCOVERY_STOPPED) {
3717 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3771 err = cmd_complete(sk, hdev->id, MGMT_OP_START_DISCOVERY,
3718 MGMT_STATUS_BUSY); 3772 MGMT_STATUS_BUSY, &cp->type,
3773 sizeof(cp->type));
3719 goto failed; 3774 goto failed;
3720 } 3775 }
3721 3776
@@ -3733,15 +3788,18 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
3733 case DISCOV_TYPE_BREDR: 3788 case DISCOV_TYPE_BREDR:
3734 status = mgmt_bredr_support(hdev); 3789 status = mgmt_bredr_support(hdev);
3735 if (status) { 3790 if (status) {
3736 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3791 err = cmd_complete(sk, hdev->id,
3737 status); 3792 MGMT_OP_START_DISCOVERY, status,
3793 &cp->type, sizeof(cp->type));
3738 mgmt_pending_remove(cmd); 3794 mgmt_pending_remove(cmd);
3739 goto failed; 3795 goto failed;
3740 } 3796 }
3741 3797
3742 if (test_bit(HCI_INQUIRY, &hdev->flags)) { 3798 if (test_bit(HCI_INQUIRY, &hdev->flags)) {
3743 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3799 err = cmd_complete(sk, hdev->id,
3744 MGMT_STATUS_BUSY); 3800 MGMT_OP_START_DISCOVERY,
3801 MGMT_STATUS_BUSY, &cp->type,
3802 sizeof(cp->type));
3745 mgmt_pending_remove(cmd); 3803 mgmt_pending_remove(cmd);
3746 goto failed; 3804 goto failed;
3747 } 3805 }
@@ -3758,16 +3816,19 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
3758 case DISCOV_TYPE_INTERLEAVED: 3816 case DISCOV_TYPE_INTERLEAVED:
3759 status = mgmt_le_support(hdev); 3817 status = mgmt_le_support(hdev);
3760 if (status) { 3818 if (status) {
3761 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3819 err = cmd_complete(sk, hdev->id,
3762 status); 3820 MGMT_OP_START_DISCOVERY, status,
3821 &cp->type, sizeof(cp->type));
3763 mgmt_pending_remove(cmd); 3822 mgmt_pending_remove(cmd);
3764 goto failed; 3823 goto failed;
3765 } 3824 }
3766 3825
3767 if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED && 3826 if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED &&
3768 !test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) { 3827 !test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
3769 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3828 err = cmd_complete(sk, hdev->id,
3770 MGMT_STATUS_NOT_SUPPORTED); 3829 MGMT_OP_START_DISCOVERY,
3830 MGMT_STATUS_NOT_SUPPORTED,
3831 &cp->type, sizeof(cp->type));
3771 mgmt_pending_remove(cmd); 3832 mgmt_pending_remove(cmd);
3772 goto failed; 3833 goto failed;
3773 } 3834 }
@@ -3779,9 +3840,11 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
3779 */ 3840 */
3780 if (hci_conn_hash_lookup_state(hdev, LE_LINK, 3841 if (hci_conn_hash_lookup_state(hdev, LE_LINK,
3781 BT_CONNECT)) { 3842 BT_CONNECT)) {
3782 err = cmd_status(sk, hdev->id, 3843 err = cmd_complete(sk, hdev->id,
3783 MGMT_OP_START_DISCOVERY, 3844 MGMT_OP_START_DISCOVERY,
3784 MGMT_STATUS_REJECTED); 3845 MGMT_STATUS_REJECTED,
3846 &cp->type,
3847 sizeof(cp->type));
3785 mgmt_pending_remove(cmd); 3848 mgmt_pending_remove(cmd);
3786 goto failed; 3849 goto failed;
3787 } 3850 }
@@ -3804,8 +3867,10 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
3804 */ 3867 */
3805 err = hci_update_random_address(&req, true, &own_addr_type); 3868 err = hci_update_random_address(&req, true, &own_addr_type);
3806 if (err < 0) { 3869 if (err < 0) {
3807 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3870 err = cmd_complete(sk, hdev->id,
3808 MGMT_STATUS_FAILED); 3871 MGMT_OP_START_DISCOVERY,
3872 MGMT_STATUS_FAILED,
3873 &cp->type, sizeof(cp->type));
3809 mgmt_pending_remove(cmd); 3874 mgmt_pending_remove(cmd);
3810 goto failed; 3875 goto failed;
3811 } 3876 }
@@ -3825,8 +3890,9 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
3825 break; 3890 break;
3826 3891
3827 default: 3892 default:
3828 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 3893 err = cmd_complete(sk, hdev->id, MGMT_OP_START_DISCOVERY,
3829 MGMT_STATUS_INVALID_PARAMS); 3894 MGMT_STATUS_INVALID_PARAMS,
3895 &cp->type, sizeof(cp->type));
3830 mgmt_pending_remove(cmd); 3896 mgmt_pending_remove(cmd);
3831 goto failed; 3897 goto failed;
3832 } 3898 }
@@ -6171,26 +6237,36 @@ static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
6171 return eir_len; 6237 return eir_len;
6172} 6238}
6173 6239
6174void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 6240void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
6175 u8 addr_type, u32 flags, u8 *name, u8 name_len, 6241 u32 flags, u8 *name, u8 name_len)
6176 u8 *dev_class)
6177{ 6242{
6178 char buf[512]; 6243 char buf[512];
6179 struct mgmt_ev_device_connected *ev = (void *) buf; 6244 struct mgmt_ev_device_connected *ev = (void *) buf;
6180 u16 eir_len = 0; 6245 u16 eir_len = 0;
6181 6246
6182 bacpy(&ev->addr.bdaddr, bdaddr); 6247 bacpy(&ev->addr.bdaddr, &conn->dst);
6183 ev->addr.type = link_to_bdaddr(link_type, addr_type); 6248 ev->addr.type = link_to_bdaddr(conn->type, conn->dst_type);
6184 6249
6185 ev->flags = __cpu_to_le32(flags); 6250 ev->flags = __cpu_to_le32(flags);
6186 6251
6187 if (name_len > 0) 6252 /* We must ensure that the EIR Data fields are ordered and
6188 eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, 6253 * unique. Keep it simple for now and avoid the problem by not
6189 name, name_len); 6254 * adding any BR/EDR data to the LE adv.
6255 */
6256 if (conn->le_adv_data_len > 0) {
6257 memcpy(&ev->eir[eir_len],
6258 conn->le_adv_data, conn->le_adv_data_len);
6259 eir_len = conn->le_adv_data_len;
6260 } else {
6261 if (name_len > 0)
6262 eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE,
6263 name, name_len);
6190 6264
6191 if (dev_class && memcmp(dev_class, "\0\0\0", 3) != 0) 6265 if (memcmp(conn->dev_class, "\0\0\0", 3) != 0)
6192 eir_len = eir_append_data(ev->eir, eir_len, 6266 eir_len = eir_append_data(ev->eir, eir_len,
6193 EIR_CLASS_OF_DEV, dev_class, 3); 6267 EIR_CLASS_OF_DEV,
6268 conn->dev_class, 3);
6269 }
6194 6270
6195 ev->eir_len = cpu_to_le16(eir_len); 6271 ev->eir_len = cpu_to_le16(eir_len);
6196 6272
@@ -6693,8 +6769,8 @@ void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status)
6693} 6769}
6694 6770
6695void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192, 6771void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
6696 u8 *randomizer192, u8 *hash256, 6772 u8 *rand192, u8 *hash256, u8 *rand256,
6697 u8 *randomizer256, u8 status) 6773 u8 status)
6698{ 6774{
6699 struct pending_cmd *cmd; 6775 struct pending_cmd *cmd;
6700 6776
@@ -6709,16 +6785,14 @@ void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
6709 mgmt_status(status)); 6785 mgmt_status(status));
6710 } else { 6786 } else {
6711 if (test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && 6787 if (test_bit(HCI_SC_ENABLED, &hdev->dev_flags) &&
6712 hash256 && randomizer256) { 6788 hash256 && rand256) {
6713 struct mgmt_rp_read_local_oob_ext_data rp; 6789 struct mgmt_rp_read_local_oob_ext_data rp;
6714 6790
6715 memcpy(rp.hash192, hash192, sizeof(rp.hash192)); 6791 memcpy(rp.hash192, hash192, sizeof(rp.hash192));
6716 memcpy(rp.randomizer192, randomizer192, 6792 memcpy(rp.rand192, rand192, sizeof(rp.rand192));
6717 sizeof(rp.randomizer192));
6718 6793
6719 memcpy(rp.hash256, hash256, sizeof(rp.hash256)); 6794 memcpy(rp.hash256, hash256, sizeof(rp.hash256));
6720 memcpy(rp.randomizer256, randomizer256, 6795 memcpy(rp.rand256, rand256, sizeof(rp.rand256));
6721 sizeof(rp.randomizer256));
6722 6796
6723 cmd_complete(cmd->sk, hdev->id, 6797 cmd_complete(cmd->sk, hdev->id,
6724 MGMT_OP_READ_LOCAL_OOB_DATA, 0, 6798 MGMT_OP_READ_LOCAL_OOB_DATA, 0,
@@ -6727,8 +6801,7 @@ void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
6727 struct mgmt_rp_read_local_oob_data rp; 6801 struct mgmt_rp_read_local_oob_data rp;
6728 6802
6729 memcpy(rp.hash, hash192, sizeof(rp.hash)); 6803 memcpy(rp.hash, hash192, sizeof(rp.hash));
6730 memcpy(rp.randomizer, randomizer192, 6804 memcpy(rp.rand, rand192, sizeof(rp.rand));
6731 sizeof(rp.randomizer));
6732 6805
6733 cmd_complete(cmd->sk, hdev->id, 6806 cmd_complete(cmd->sk, hdev->id,
6734 MGMT_OP_READ_LOCAL_OOB_DATA, 0, 6807 MGMT_OP_READ_LOCAL_OOB_DATA, 0,
diff --git a/net/bluetooth/rfcomm/Kconfig b/net/bluetooth/rfcomm/Kconfig
index 18d352ea2bc7..335df7515220 100644
--- a/net/bluetooth/rfcomm/Kconfig
+++ b/net/bluetooth/rfcomm/Kconfig
@@ -1,6 +1,6 @@
1config BT_RFCOMM 1config BT_RFCOMM
2 tristate "RFCOMM protocol support" 2 tristate "RFCOMM protocol support"
3 depends on BT 3 depends on BT_BREDR
4 help 4 help
5 RFCOMM provides connection oriented stream transport. RFCOMM 5 RFCOMM provides connection oriented stream transport. RFCOMM
6 support is required for Dialup Networking, OBEX and other Bluetooth 6 support is required for Dialup Networking, OBEX and other Bluetooth
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index af73bc3acb40..64e20dde4837 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -78,8 +78,10 @@ static struct rfcomm_session *rfcomm_session_del(struct rfcomm_session *s);
78#define __get_type(b) ((b & 0xef)) 78#define __get_type(b) ((b & 0xef))
79 79
80#define __test_ea(b) ((b & 0x01)) 80#define __test_ea(b) ((b & 0x01))
81#define __test_cr(b) ((b & 0x02)) 81#define __test_cr(b) (!!(b & 0x02))
82#define __test_pf(b) ((b & 0x10)) 82#define __test_pf(b) (!!(b & 0x10))
83
84#define __session_dir(s) ((s)->initiator ? 0x00 : 0x01)
83 85
84#define __addr(cr, dlci) (((dlci & 0x3f) << 2) | (cr << 1) | 0x01) 86#define __addr(cr, dlci) (((dlci & 0x3f) << 2) | (cr << 1) | 0x01)
85#define __ctrl(type, pf) (((type & 0xef) | (pf << 4))) 87#define __ctrl(type, pf) (((type & 0xef) | (pf << 4)))
@@ -388,7 +390,7 @@ static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst,
388 return err; 390 return err;
389 } 391 }
390 392
391 dlci = __dlci(!s->initiator, channel); 393 dlci = __dlci(__session_dir(s), channel);
392 394
393 /* Check if DLCI already exists */ 395 /* Check if DLCI already exists */
394 if (rfcomm_dlc_get(s, dlci)) 396 if (rfcomm_dlc_get(s, dlci))
@@ -543,7 +545,7 @@ struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel)
543 rfcomm_lock(); 545 rfcomm_lock();
544 s = rfcomm_session_get(src, dst); 546 s = rfcomm_session_get(src, dst);
545 if (s) { 547 if (s) {
546 dlci = __dlci(!s->initiator, channel); 548 dlci = __dlci(__session_dir(s), channel);
547 dlc = rfcomm_dlc_get(s, dlci); 549 dlc = rfcomm_dlc_get(s, dlci);
548 } 550 }
549 rfcomm_unlock(); 551 rfcomm_unlock();
@@ -904,7 +906,7 @@ static int rfcomm_send_nsc(struct rfcomm_session *s, int cr, u8 type)
904 hdr->len = __len8(sizeof(*mcc) + 1); 906 hdr->len = __len8(sizeof(*mcc) + 1);
905 907
906 mcc = (void *) ptr; ptr += sizeof(*mcc); 908 mcc = (void *) ptr; ptr += sizeof(*mcc);
907 mcc->type = __mcc_type(cr, RFCOMM_NSC); 909 mcc->type = __mcc_type(0, RFCOMM_NSC);
908 mcc->len = __len8(1); 910 mcc->len = __len8(1);
909 911
910 /* Type that we didn't like */ 912 /* Type that we didn't like */
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index f09b6b65cf6b..069b76e03b57 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -191,16 +191,13 @@ int smp_generate_rpa(struct hci_dev *hdev, u8 irk[16], bdaddr_t *rpa)
191 return 0; 191 return 0;
192} 192}
193 193
194static int smp_c1(struct smp_chan *smp, u8 k[16], u8 r[16], u8 preq[7], 194static int smp_c1(struct crypto_blkcipher *tfm_aes, u8 k[16], u8 r[16],
195 u8 pres[7], u8 _iat, bdaddr_t *ia, u8 _rat, bdaddr_t *ra, 195 u8 preq[7], u8 pres[7], u8 _iat, bdaddr_t *ia, u8 _rat,
196 u8 res[16]) 196 bdaddr_t *ra, u8 res[16])
197{ 197{
198 struct hci_dev *hdev = smp->conn->hcon->hdev;
199 u8 p1[16], p2[16]; 198 u8 p1[16], p2[16];
200 int err; 199 int err;
201 200
202 BT_DBG("%s", hdev->name);
203
204 memset(p1, 0, 16); 201 memset(p1, 0, 16);
205 202
206 /* p1 = pres || preq || _rat || _iat */ 203 /* p1 = pres || preq || _rat || _iat */
@@ -218,7 +215,7 @@ static int smp_c1(struct smp_chan *smp, u8 k[16], u8 r[16], u8 preq[7],
218 u128_xor((u128 *) res, (u128 *) r, (u128 *) p1); 215 u128_xor((u128 *) res, (u128 *) r, (u128 *) p1);
219 216
220 /* res = e(k, res) */ 217 /* res = e(k, res) */
221 err = smp_e(smp->tfm_aes, k, res); 218 err = smp_e(tfm_aes, k, res);
222 if (err) { 219 if (err) {
223 BT_ERR("Encrypt data error"); 220 BT_ERR("Encrypt data error");
224 return err; 221 return err;
@@ -228,26 +225,23 @@ static int smp_c1(struct smp_chan *smp, u8 k[16], u8 r[16], u8 preq[7],
228 u128_xor((u128 *) res, (u128 *) res, (u128 *) p2); 225 u128_xor((u128 *) res, (u128 *) res, (u128 *) p2);
229 226
230 /* res = e(k, res) */ 227 /* res = e(k, res) */
231 err = smp_e(smp->tfm_aes, k, res); 228 err = smp_e(tfm_aes, k, res);
232 if (err) 229 if (err)
233 BT_ERR("Encrypt data error"); 230 BT_ERR("Encrypt data error");
234 231
235 return err; 232 return err;
236} 233}
237 234
238static int smp_s1(struct smp_chan *smp, u8 k[16], u8 r1[16], u8 r2[16], 235static int smp_s1(struct crypto_blkcipher *tfm_aes, u8 k[16], u8 r1[16],
239 u8 _r[16]) 236 u8 r2[16], u8 _r[16])
240{ 237{
241 struct hci_dev *hdev = smp->conn->hcon->hdev;
242 int err; 238 int err;
243 239
244 BT_DBG("%s", hdev->name);
245
246 /* Just least significant octets from r1 and r2 are considered */ 240 /* Just least significant octets from r1 and r2 are considered */
247 memcpy(_r, r2, 8); 241 memcpy(_r, r2, 8);
248 memcpy(_r + 8, r1, 8); 242 memcpy(_r + 8, r1, 8);
249 243
250 err = smp_e(smp->tfm_aes, k, _r); 244 err = smp_e(tfm_aes, k, _r);
251 if (err) 245 if (err)
252 BT_ERR("Encrypt data error"); 246 BT_ERR("Encrypt data error");
253 247
@@ -389,18 +383,18 @@ static void smp_chan_destroy(struct l2cap_conn *conn)
389 /* If pairing failed clean up any keys we might have */ 383 /* If pairing failed clean up any keys we might have */
390 if (!complete) { 384 if (!complete) {
391 if (smp->ltk) { 385 if (smp->ltk) {
392 list_del(&smp->ltk->list); 386 list_del_rcu(&smp->ltk->list);
393 kfree(smp->ltk); 387 kfree_rcu(smp->ltk, rcu);
394 } 388 }
395 389
396 if (smp->slave_ltk) { 390 if (smp->slave_ltk) {
397 list_del(&smp->slave_ltk->list); 391 list_del_rcu(&smp->slave_ltk->list);
398 kfree(smp->slave_ltk); 392 kfree_rcu(smp->slave_ltk, rcu);
399 } 393 }
400 394
401 if (smp->remote_irk) { 395 if (smp->remote_irk) {
402 list_del(&smp->remote_irk->list); 396 list_del_rcu(&smp->remote_irk->list);
403 kfree(smp->remote_irk); 397 kfree_rcu(smp->remote_irk, rcu);
404 } 398 }
405 } 399 }
406 400
@@ -520,8 +514,6 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
520 set_bit(SMP_FLAG_TK_VALID, &smp->flags); 514 set_bit(SMP_FLAG_TK_VALID, &smp->flags);
521 } 515 }
522 516
523 hci_dev_lock(hcon->hdev);
524
525 if (method == REQ_PASSKEY) 517 if (method == REQ_PASSKEY)
526 ret = mgmt_user_passkey_request(hcon->hdev, &hcon->dst, 518 ret = mgmt_user_passkey_request(hcon->hdev, &hcon->dst,
527 hcon->type, hcon->dst_type); 519 hcon->type, hcon->dst_type);
@@ -534,8 +526,6 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
534 hcon->type, hcon->dst_type, 526 hcon->type, hcon->dst_type,
535 passkey, 0); 527 passkey, 0);
536 528
537 hci_dev_unlock(hcon->hdev);
538
539 return ret; 529 return ret;
540} 530}
541 531
@@ -547,7 +537,7 @@ static u8 smp_confirm(struct smp_chan *smp)
547 537
548 BT_DBG("conn %p", conn); 538 BT_DBG("conn %p", conn);
549 539
550 ret = smp_c1(smp, smp->tk, smp->prnd, smp->preq, smp->prsp, 540 ret = smp_c1(smp->tfm_aes, smp->tk, smp->prnd, smp->preq, smp->prsp,
551 conn->hcon->init_addr_type, &conn->hcon->init_addr, 541 conn->hcon->init_addr_type, &conn->hcon->init_addr,
552 conn->hcon->resp_addr_type, &conn->hcon->resp_addr, 542 conn->hcon->resp_addr_type, &conn->hcon->resp_addr,
553 cp.confirm_val); 543 cp.confirm_val);
@@ -578,7 +568,7 @@ static u8 smp_random(struct smp_chan *smp)
578 568
579 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); 569 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave");
580 570
581 ret = smp_c1(smp, smp->tk, smp->rrnd, smp->preq, smp->prsp, 571 ret = smp_c1(smp->tfm_aes, smp->tk, smp->rrnd, smp->preq, smp->prsp,
582 hcon->init_addr_type, &hcon->init_addr, 572 hcon->init_addr_type, &hcon->init_addr,
583 hcon->resp_addr_type, &hcon->resp_addr, confirm); 573 hcon->resp_addr_type, &hcon->resp_addr, confirm);
584 if (ret) 574 if (ret)
@@ -594,7 +584,7 @@ static u8 smp_random(struct smp_chan *smp)
594 __le64 rand = 0; 584 __le64 rand = 0;
595 __le16 ediv = 0; 585 __le16 ediv = 0;
596 586
597 smp_s1(smp, smp->tk, smp->rrnd, smp->prnd, stk); 587 smp_s1(smp->tfm_aes, smp->tk, smp->rrnd, smp->prnd, stk);
598 588
599 memset(stk + smp->enc_key_size, 0, 589 memset(stk + smp->enc_key_size, 0,
600 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 590 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);
@@ -613,7 +603,7 @@ static u8 smp_random(struct smp_chan *smp)
613 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), 603 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
614 smp->prnd); 604 smp->prnd);
615 605
616 smp_s1(smp, smp->tk, smp->prnd, smp->rrnd, stk); 606 smp_s1(smp->tfm_aes, smp->tk, smp->prnd, smp->rrnd, stk);
617 607
618 memset(stk + smp->enc_key_size, 0, 608 memset(stk + smp->enc_key_size, 0,
619 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 609 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);
@@ -665,8 +655,8 @@ static void smp_notify_keys(struct l2cap_conn *conn)
665 * just remove it. 655 * just remove it.
666 */ 656 */
667 if (!bacmp(&smp->remote_irk->rpa, BDADDR_ANY)) { 657 if (!bacmp(&smp->remote_irk->rpa, BDADDR_ANY)) {
668 list_del(&smp->remote_irk->list); 658 list_del_rcu(&smp->remote_irk->list);
669 kfree(smp->remote_irk); 659 kfree_rcu(smp->remote_irk, rcu);
670 smp->remote_irk = NULL; 660 smp->remote_irk = NULL;
671 } 661 }
672 } 662 }
@@ -970,7 +960,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
970 if (sec_level > conn->hcon->pending_sec_level) 960 if (sec_level > conn->hcon->pending_sec_level)
971 conn->hcon->pending_sec_level = sec_level; 961 conn->hcon->pending_sec_level = sec_level;
972 962
973 /* If we need MITM check that it can be acheived */ 963 /* If we need MITM check that it can be achieved */
974 if (conn->hcon->pending_sec_level >= BT_SECURITY_HIGH) { 964 if (conn->hcon->pending_sec_level >= BT_SECURITY_HIGH) {
975 u8 method; 965 u8 method;
976 966
@@ -1028,7 +1018,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
1028 1018
1029 auth = rsp->auth_req & AUTH_REQ_MASK; 1019 auth = rsp->auth_req & AUTH_REQ_MASK;
1030 1020
1031 /* If we need MITM check that it can be acheived */ 1021 /* If we need MITM check that it can be achieved */
1032 if (conn->hcon->pending_sec_level >= BT_SECURITY_HIGH) { 1022 if (conn->hcon->pending_sec_level >= BT_SECURITY_HIGH) {
1033 u8 method; 1023 u8 method;
1034 1024
@@ -1132,18 +1122,20 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
1132 return true; 1122 return true;
1133} 1123}
1134 1124
1135bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level) 1125bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level,
1126 enum smp_key_pref key_pref)
1136{ 1127{
1137 if (sec_level == BT_SECURITY_LOW) 1128 if (sec_level == BT_SECURITY_LOW)
1138 return true; 1129 return true;
1139 1130
1140 /* If we're encrypted with an STK always claim insufficient 1131 /* If we're encrypted with an STK but the caller prefers using
1141 * security. This way we allow the connection to be re-encrypted 1132 * LTK claim insufficient security. This way we allow the
1142 * with an LTK, even if the LTK provides the same level of 1133 * connection to be re-encrypted with an LTK, even if the LTK
1143 * security. Only exception is if we don't have an LTK (e.g. 1134 * provides the same level of security. Only exception is if we
1144 * because of key distribution bits). 1135 * don't have an LTK (e.g. because of key distribution bits).
1145 */ 1136 */
1146 if (test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags) && 1137 if (key_pref == SMP_USE_LTK &&
1138 test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags) &&
1147 hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type, 1139 hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type,
1148 hcon->role)) 1140 hcon->role))
1149 return false; 1141 return false;
@@ -1177,7 +1169,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
1177 else 1169 else
1178 sec_level = authreq_to_seclevel(auth); 1170 sec_level = authreq_to_seclevel(auth);
1179 1171
1180 if (smp_sufficient_security(hcon, sec_level)) 1172 if (smp_sufficient_security(hcon, sec_level, SMP_USE_LTK))
1181 return 0; 1173 return 0;
1182 1174
1183 if (sec_level > hcon->pending_sec_level) 1175 if (sec_level > hcon->pending_sec_level)
@@ -1227,7 +1219,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
1227 if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags)) 1219 if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags))
1228 return 1; 1220 return 1;
1229 1221
1230 if (smp_sufficient_security(hcon, sec_level)) 1222 if (smp_sufficient_security(hcon, sec_level, SMP_USE_LTK))
1231 return 1; 1223 return 1;
1232 1224
1233 if (sec_level > hcon->pending_sec_level) 1225 if (sec_level > hcon->pending_sec_level)
@@ -1329,7 +1321,6 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
1329 1321
1330 skb_pull(skb, sizeof(*rp)); 1322 skb_pull(skb, sizeof(*rp));
1331 1323
1332 hci_dev_lock(hdev);
1333 authenticated = (hcon->sec_level == BT_SECURITY_HIGH); 1324 authenticated = (hcon->sec_level == BT_SECURITY_HIGH);
1334 ltk = hci_add_ltk(hdev, &hcon->dst, hcon->dst_type, SMP_LTK, 1325 ltk = hci_add_ltk(hdev, &hcon->dst, hcon->dst_type, SMP_LTK,
1335 authenticated, smp->tk, smp->enc_key_size, 1326 authenticated, smp->tk, smp->enc_key_size,
@@ -1337,7 +1328,6 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
1337 smp->ltk = ltk; 1328 smp->ltk = ltk;
1338 if (!(smp->remote_key_dist & KEY_DIST_MASK)) 1329 if (!(smp->remote_key_dist & KEY_DIST_MASK))
1339 smp_distribute_keys(smp); 1330 smp_distribute_keys(smp);
1340 hci_dev_unlock(hdev);
1341 1331
1342 return 0; 1332 return 0;
1343} 1333}
@@ -1384,8 +1374,6 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn,
1384 1374
1385 skb_pull(skb, sizeof(*info)); 1375 skb_pull(skb, sizeof(*info));
1386 1376
1387 hci_dev_lock(hcon->hdev);
1388
1389 /* Strictly speaking the Core Specification (4.1) allows sending 1377 /* Strictly speaking the Core Specification (4.1) allows sending
1390 * an empty address which would force us to rely on just the IRK 1378 * an empty address which would force us to rely on just the IRK
1391 * as "identity information". However, since such 1379 * as "identity information". However, since such
@@ -1413,8 +1401,6 @@ distribute:
1413 if (!(smp->remote_key_dist & KEY_DIST_MASK)) 1401 if (!(smp->remote_key_dist & KEY_DIST_MASK))
1414 smp_distribute_keys(smp); 1402 smp_distribute_keys(smp);
1415 1403
1416 hci_dev_unlock(hcon->hdev);
1417
1418 return 0; 1404 return 0;
1419} 1405}
1420 1406
@@ -1423,7 +1409,6 @@ static int smp_cmd_sign_info(struct l2cap_conn *conn, struct sk_buff *skb)
1423 struct smp_cmd_sign_info *rp = (void *) skb->data; 1409 struct smp_cmd_sign_info *rp = (void *) skb->data;
1424 struct l2cap_chan *chan = conn->smp; 1410 struct l2cap_chan *chan = conn->smp;
1425 struct smp_chan *smp = chan->data; 1411 struct smp_chan *smp = chan->data;
1426 struct hci_dev *hdev = conn->hcon->hdev;
1427 struct smp_csrk *csrk; 1412 struct smp_csrk *csrk;
1428 1413
1429 BT_DBG("conn %p", conn); 1414 BT_DBG("conn %p", conn);
@@ -1436,7 +1421,6 @@ static int smp_cmd_sign_info(struct l2cap_conn *conn, struct sk_buff *skb)
1436 1421
1437 skb_pull(skb, sizeof(*rp)); 1422 skb_pull(skb, sizeof(*rp));
1438 1423
1439 hci_dev_lock(hdev);
1440 csrk = kzalloc(sizeof(*csrk), GFP_KERNEL); 1424 csrk = kzalloc(sizeof(*csrk), GFP_KERNEL);
1441 if (csrk) { 1425 if (csrk) {
1442 csrk->master = 0x01; 1426 csrk->master = 0x01;
@@ -1444,7 +1428,6 @@ static int smp_cmd_sign_info(struct l2cap_conn *conn, struct sk_buff *skb)
1444 } 1428 }
1445 smp->csrk = csrk; 1429 smp->csrk = csrk;
1446 smp_distribute_keys(smp); 1430 smp_distribute_keys(smp);
1447 hci_dev_unlock(hdev);
1448 1431
1449 return 0; 1432 return 0;
1450} 1433}
@@ -1668,6 +1651,13 @@ static inline struct l2cap_chan *smp_new_conn_cb(struct l2cap_chan *pchan)
1668 chan->omtu = pchan->omtu; 1651 chan->omtu = pchan->omtu;
1669 chan->mode = pchan->mode; 1652 chan->mode = pchan->mode;
1670 1653
1654 /* Other L2CAP channels may request SMP routines in order to
1655 * change the security level. This means that the SMP channel
1656 * lock must be considered in its own category to avoid lockdep
1657 * warnings.
1658 */
1659 atomic_set(&chan->nesting, L2CAP_NESTING_SMP);
1660
1671 BT_DBG("created chan %p", chan); 1661 BT_DBG("created chan %p", chan);
1672 1662
1673 return chan; 1663 return chan;
@@ -1699,7 +1689,7 @@ int smp_register(struct hci_dev *hdev)
1699 1689
1700 BT_DBG("%s", hdev->name); 1690 BT_DBG("%s", hdev->name);
1701 1691
1702 tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); 1692 tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0, 0);
1703 if (IS_ERR(tfm_aes)) { 1693 if (IS_ERR(tfm_aes)) {
1704 int err = PTR_ERR(tfm_aes); 1694 int err = PTR_ERR(tfm_aes);
1705 BT_ERR("Unable to create crypto context"); 1695 BT_ERR("Unable to create crypto context");
@@ -1725,6 +1715,9 @@ int smp_register(struct hci_dev *hdev)
1725 chan->imtu = L2CAP_DEFAULT_MTU; 1715 chan->imtu = L2CAP_DEFAULT_MTU;
1726 chan->ops = &smp_root_chan_ops; 1716 chan->ops = &smp_root_chan_ops;
1727 1717
1718 /* Set correct nesting level for a parent/listening channel */
1719 atomic_set(&chan->nesting, L2CAP_NESTING_PARENT);
1720
1728 hdev->smp_data = chan; 1721 hdev->smp_data = chan;
1729 1722
1730 return 0; 1723 return 0;
diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h
index 86a683a8b491..f76083b85005 100644
--- a/net/bluetooth/smp.h
+++ b/net/bluetooth/smp.h
@@ -133,8 +133,15 @@ static inline u8 smp_ltk_sec_level(struct smp_ltk *key)
133 return BT_SECURITY_MEDIUM; 133 return BT_SECURITY_MEDIUM;
134} 134}
135 135
136/* Key preferences for smp_sufficient security */
137enum smp_key_pref {
138 SMP_ALLOW_STK,
139 SMP_USE_LTK,
140};
141
136/* SMP Commands */ 142/* SMP Commands */
137bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level); 143bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level,
144 enum smp_key_pref key_pref);
138int smp_conn_security(struct hci_conn *hcon, __u8 sec_level); 145int smp_conn_security(struct hci_conn *hcon, __u8 sec_level);
139int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey); 146int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey);
140 147
diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
index 44136297b673..290e14f2e92e 100644
--- a/net/ieee802154/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan_rtnl.c
@@ -49,8 +49,8 @@
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/moduleparam.h> 50#include <linux/moduleparam.h>
51#include <linux/netdevice.h> 51#include <linux/netdevice.h>
52#include <linux/ieee802154.h>
52#include <net/af_ieee802154.h> 53#include <net/af_ieee802154.h>
53#include <net/ieee802154.h>
54#include <net/ieee802154_netdev.h> 54#include <net/ieee802154_netdev.h>
55#include <net/6lowpan.h> 55#include <net/6lowpan.h>
56#include <net/ipv6.h> 56#include <net/ipv6.h>
@@ -58,12 +58,13 @@
58#include "reassembly.h" 58#include "reassembly.h"
59 59
60static LIST_HEAD(lowpan_devices); 60static LIST_HEAD(lowpan_devices);
61static int lowpan_open_count;
61 62
62/* private device info */ 63/* private device info */
63struct lowpan_dev_info { 64struct lowpan_dev_info {
64 struct net_device *real_dev; /* real WPAN device ptr */ 65 struct net_device *real_dev; /* real WPAN device ptr */
65 struct mutex dev_list_mtx; /* mutex for list ops */ 66 struct mutex dev_list_mtx; /* mutex for list ops */
66 __be16 fragment_tag; 67 u16 fragment_tag;
67}; 68};
68 69
69struct lowpan_dev_record { 70struct lowpan_dev_record {
@@ -140,24 +141,33 @@ static int lowpan_give_skb_to_devices(struct sk_buff *skb,
140 struct sk_buff *skb_cp; 141 struct sk_buff *skb_cp;
141 int stat = NET_RX_SUCCESS; 142 int stat = NET_RX_SUCCESS;
142 143
144 skb->protocol = htons(ETH_P_IPV6);
145 skb->pkt_type = PACKET_HOST;
146
143 rcu_read_lock(); 147 rcu_read_lock();
144 list_for_each_entry_rcu(entry, &lowpan_devices, list) 148 list_for_each_entry_rcu(entry, &lowpan_devices, list)
145 if (lowpan_dev_info(entry->ldev)->real_dev == skb->dev) { 149 if (lowpan_dev_info(entry->ldev)->real_dev == skb->dev) {
146 skb_cp = skb_copy(skb, GFP_ATOMIC); 150 skb_cp = skb_copy(skb, GFP_ATOMIC);
147 if (!skb_cp) { 151 if (!skb_cp) {
148 stat = -ENOMEM; 152 kfree_skb(skb);
149 break; 153 rcu_read_unlock();
154 return NET_RX_DROP;
150 } 155 }
151 156
152 skb_cp->dev = entry->ldev; 157 skb_cp->dev = entry->ldev;
153 stat = netif_rx(skb_cp); 158 stat = netif_rx(skb_cp);
159 if (stat == NET_RX_DROP)
160 break;
154 } 161 }
155 rcu_read_unlock(); 162 rcu_read_unlock();
156 163
164 consume_skb(skb);
165
157 return stat; 166 return stat;
158} 167}
159 168
160static int process_data(struct sk_buff *skb, const struct ieee802154_hdr *hdr) 169static int
170iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
161{ 171{
162 u8 iphc0, iphc1; 172 u8 iphc0, iphc1;
163 struct ieee802154_addr_sa sa, da; 173 struct ieee802154_addr_sa sa, da;
@@ -166,13 +176,13 @@ static int process_data(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
166 raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len); 176 raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
167 /* at least two bytes will be used for the encoding */ 177 /* at least two bytes will be used for the encoding */
168 if (skb->len < 2) 178 if (skb->len < 2)
169 goto drop; 179 return -EINVAL;
170 180
171 if (lowpan_fetch_skb_u8(skb, &iphc0)) 181 if (lowpan_fetch_skb_u8(skb, &iphc0))
172 goto drop; 182 return -EINVAL;
173 183
174 if (lowpan_fetch_skb_u8(skb, &iphc1)) 184 if (lowpan_fetch_skb_u8(skb, &iphc1))
175 goto drop; 185 return -EINVAL;
176 186
177 ieee802154_addr_to_sa(&sa, &hdr->source); 187 ieee802154_addr_to_sa(&sa, &hdr->source);
178 ieee802154_addr_to_sa(&da, &hdr->dest); 188 ieee802154_addr_to_sa(&da, &hdr->dest);
@@ -187,27 +197,9 @@ static int process_data(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
187 else 197 else
188 dap = &da.hwaddr; 198 dap = &da.hwaddr;
189 199
190 return lowpan_process_data(skb, skb->dev, sap, sa.addr_type, 200 return lowpan_header_decompress(skb, skb->dev, sap, sa.addr_type,
191 IEEE802154_ADDR_LEN, dap, da.addr_type, 201 IEEE802154_ADDR_LEN, dap, da.addr_type,
192 IEEE802154_ADDR_LEN, iphc0, iphc1, 202 IEEE802154_ADDR_LEN, iphc0, iphc1);
193 lowpan_give_skb_to_devices);
194
195drop:
196 kfree_skb(skb);
197 return -EINVAL;
198}
199
200static int lowpan_set_address(struct net_device *dev, void *p)
201{
202 struct sockaddr *sa = p;
203
204 if (netif_running(dev))
205 return -EBUSY;
206
207 /* TODO: validate addr */
208 memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
209
210 return 0;
211} 203}
212 204
213static struct sk_buff* 205static struct sk_buff*
@@ -233,7 +225,7 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
233 &master_hdr->source, size); 225 &master_hdr->source, size);
234 if (rc < 0) { 226 if (rc < 0) {
235 kfree_skb(frag); 227 kfree_skb(frag);
236 return ERR_PTR(-rc); 228 return ERR_PTR(rc);
237 } 229 }
238 } else { 230 } else {
239 frag = ERR_PTR(-ENOMEM); 231 frag = ERR_PTR(-ENOMEM);
@@ -275,7 +267,8 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
275 267
276 dgram_size = lowpan_uncompress_size(skb, &dgram_offset) - 268 dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
277 skb->mac_len; 269 skb->mac_len;
278 frag_tag = lowpan_dev_info(dev)->fragment_tag++; 270 frag_tag = htons(lowpan_dev_info(dev)->fragment_tag);
271 lowpan_dev_info(dev)->fragment_tag++;
279 272
280 frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07); 273 frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
281 frag_hdr[1] = dgram_size & 0xff; 274 frag_hdr[1] = dgram_size & 0xff;
@@ -294,7 +287,7 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
294 frag_len + skb_network_header_len(skb)); 287 frag_len + skb_network_header_len(skb));
295 if (rc) { 288 if (rc) {
296 pr_debug("%s unable to send FRAG1 packet (tag: %d)", 289 pr_debug("%s unable to send FRAG1 packet (tag: %d)",
297 __func__, frag_tag); 290 __func__, ntohs(frag_tag));
298 goto err; 291 goto err;
299 } 292 }
300 293
@@ -315,7 +308,7 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
315 frag_len); 308 frag_len);
316 if (rc) { 309 if (rc) {
317 pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n", 310 pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
318 __func__, frag_tag, skb_offset); 311 __func__, ntohs(frag_tag), skb_offset);
319 goto err; 312 goto err;
320 } 313 }
321 } while (skb_unprocessed > frag_cap); 314 } while (skb_unprocessed > frag_cap);
@@ -410,13 +403,6 @@ static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
410 } 403 }
411} 404}
412 405
413static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
414{
415 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
416
417 return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
418}
419
420static __le16 lowpan_get_pan_id(const struct net_device *dev) 406static __le16 lowpan_get_pan_id(const struct net_device *dev)
421{ 407{
422 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; 408 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
@@ -464,12 +450,10 @@ static int lowpan_dev_init(struct net_device *dev)
464static const struct net_device_ops lowpan_netdev_ops = { 450static const struct net_device_ops lowpan_netdev_ops = {
465 .ndo_init = lowpan_dev_init, 451 .ndo_init = lowpan_dev_init,
466 .ndo_start_xmit = lowpan_xmit, 452 .ndo_start_xmit = lowpan_xmit,
467 .ndo_set_mac_address = lowpan_set_address,
468}; 453};
469 454
470static struct ieee802154_mlme_ops lowpan_mlme = { 455static struct ieee802154_mlme_ops lowpan_mlme = {
471 .get_pan_id = lowpan_get_pan_id, 456 .get_pan_id = lowpan_get_pan_id,
472 .get_phy = lowpan_get_phy,
473 .get_short_addr = lowpan_get_short_addr, 457 .get_short_addr = lowpan_get_short_addr,
474 .get_dsn = lowpan_get_dsn, 458 .get_dsn = lowpan_get_dsn,
475}; 459};
@@ -515,6 +499,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
515 if (!netif_running(dev)) 499 if (!netif_running(dev))
516 goto drop_skb; 500 goto drop_skb;
517 501
502 if (skb->pkt_type == PACKET_OTHERHOST)
503 goto drop_skb;
504
518 if (dev->type != ARPHRD_IEEE802154) 505 if (dev->type != ARPHRD_IEEE802154)
519 goto drop_skb; 506 goto drop_skb;
520 507
@@ -523,55 +510,67 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
523 510
524 /* check that it's our buffer */ 511 /* check that it's our buffer */
525 if (skb->data[0] == LOWPAN_DISPATCH_IPV6) { 512 if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
526 skb->protocol = htons(ETH_P_IPV6);
527 skb->pkt_type = PACKET_HOST;
528
529 /* Pull off the 1-byte of 6lowpan header. */ 513 /* Pull off the 1-byte of 6lowpan header. */
530 skb_pull(skb, 1); 514 skb_pull(skb, 1);
531 515 return lowpan_give_skb_to_devices(skb, NULL);
532 ret = lowpan_give_skb_to_devices(skb, NULL);
533 if (ret == NET_RX_DROP)
534 goto drop;
535 } else { 516 } else {
536 switch (skb->data[0] & 0xe0) { 517 switch (skb->data[0] & 0xe0) {
537 case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */ 518 case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */
538 ret = process_data(skb, &hdr); 519 ret = iphc_decompress(skb, &hdr);
539 if (ret == NET_RX_DROP) 520 if (ret < 0)
540 goto drop; 521 goto drop_skb;
541 break; 522
523 return lowpan_give_skb_to_devices(skb, NULL);
542 case LOWPAN_DISPATCH_FRAG1: /* first fragment header */ 524 case LOWPAN_DISPATCH_FRAG1: /* first fragment header */
543 ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1); 525 ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
544 if (ret == 1) { 526 if (ret == 1) {
545 ret = process_data(skb, &hdr); 527 ret = iphc_decompress(skb, &hdr);
546 if (ret == NET_RX_DROP) 528 if (ret < 0)
547 goto drop; 529 goto drop_skb;
530
531 return lowpan_give_skb_to_devices(skb, NULL);
532 } else if (ret == -1) {
533 return NET_RX_DROP;
534 } else {
535 return NET_RX_SUCCESS;
548 } 536 }
549 break;
550 case LOWPAN_DISPATCH_FRAGN: /* next fragments headers */ 537 case LOWPAN_DISPATCH_FRAGN: /* next fragments headers */
551 ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN); 538 ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
552 if (ret == 1) { 539 if (ret == 1) {
553 ret = process_data(skb, &hdr); 540 ret = iphc_decompress(skb, &hdr);
554 if (ret == NET_RX_DROP) 541 if (ret < 0)
555 goto drop; 542 goto drop_skb;
543
544 return lowpan_give_skb_to_devices(skb, NULL);
545 } else if (ret == -1) {
546 return NET_RX_DROP;
547 } else {
548 return NET_RX_SUCCESS;
556 } 549 }
557 break;
558 default: 550 default:
559 break; 551 break;
560 } 552 }
561 } 553 }
562 554
563 return NET_RX_SUCCESS;
564drop_skb: 555drop_skb:
565 kfree_skb(skb); 556 kfree_skb(skb);
566drop: 557drop:
567 return NET_RX_DROP; 558 return NET_RX_DROP;
568} 559}
569 560
561static struct packet_type lowpan_packet_type = {
562 .type = htons(ETH_P_IEEE802154),
563 .func = lowpan_rcv,
564};
565
570static int lowpan_newlink(struct net *src_net, struct net_device *dev, 566static int lowpan_newlink(struct net *src_net, struct net_device *dev,
571 struct nlattr *tb[], struct nlattr *data[]) 567 struct nlattr *tb[], struct nlattr *data[])
572{ 568{
573 struct net_device *real_dev; 569 struct net_device *real_dev;
574 struct lowpan_dev_record *entry; 570 struct lowpan_dev_record *entry;
571 int ret;
572
573 ASSERT_RTNL();
575 574
576 pr_debug("adding new link\n"); 575 pr_debug("adding new link\n");
577 576
@@ -606,9 +605,14 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
606 list_add_tail(&entry->list, &lowpan_devices); 605 list_add_tail(&entry->list, &lowpan_devices);
607 mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx); 606 mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
608 607
609 register_netdevice(dev); 608 ret = register_netdevice(dev);
609 if (ret >= 0) {
610 if (!lowpan_open_count)
611 dev_add_pack(&lowpan_packet_type);
612 lowpan_open_count++;
613 }
610 614
611 return 0; 615 return ret;
612} 616}
613 617
614static void lowpan_dellink(struct net_device *dev, struct list_head *head) 618static void lowpan_dellink(struct net_device *dev, struct list_head *head)
@@ -619,6 +623,10 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
619 623
620 ASSERT_RTNL(); 624 ASSERT_RTNL();
621 625
626 lowpan_open_count--;
627 if (!lowpan_open_count)
628 dev_remove_pack(&lowpan_packet_type);
629
622 mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx); 630 mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
623 list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) { 631 list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
624 if (entry->ldev == dev) { 632 if (entry->ldev == dev) {
@@ -681,11 +689,6 @@ static struct notifier_block lowpan_dev_notifier = {
681 .notifier_call = lowpan_device_event, 689 .notifier_call = lowpan_device_event,
682}; 690};
683 691
684static struct packet_type lowpan_packet_type = {
685 .type = htons(ETH_P_IEEE802154),
686 .func = lowpan_rcv,
687};
688
689static int __init lowpan_init_module(void) 692static int __init lowpan_init_module(void)
690{ 693{
691 int err = 0; 694 int err = 0;
@@ -698,8 +701,6 @@ static int __init lowpan_init_module(void)
698 if (err < 0) 701 if (err < 0)
699 goto out_frag; 702 goto out_frag;
700 703
701 dev_add_pack(&lowpan_packet_type);
702
703 err = register_netdevice_notifier(&lowpan_dev_notifier); 704 err = register_netdevice_notifier(&lowpan_dev_notifier);
704 if (err < 0) 705 if (err < 0)
705 goto out_pack; 706 goto out_pack;
@@ -707,7 +708,6 @@ static int __init lowpan_init_module(void)
707 return 0; 708 return 0;
708 709
709out_pack: 710out_pack:
710 dev_remove_pack(&lowpan_packet_type);
711 lowpan_netlink_fini(); 711 lowpan_netlink_fini();
712out_frag: 712out_frag:
713 lowpan_net_frag_exit(); 713 lowpan_net_frag_exit();
@@ -719,8 +719,6 @@ static void __exit lowpan_cleanup_module(void)
719{ 719{
720 lowpan_netlink_fini(); 720 lowpan_netlink_fini();
721 721
722 dev_remove_pack(&lowpan_packet_type);
723
724 lowpan_net_frag_exit(); 722 lowpan_net_frag_exit();
725 723
726 unregister_netdevice_notifier(&lowpan_dev_notifier); 724 unregister_netdevice_notifier(&lowpan_dev_notifier);
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index 3914b1ed4274..9f6970f2a28b 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -2,8 +2,8 @@ obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o
2obj-$(CONFIG_IEEE802154_6LOWPAN) += ieee802154_6lowpan.o 2obj-$(CONFIG_IEEE802154_6LOWPAN) += ieee802154_6lowpan.o
3 3
4ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o 4ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o
5ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o \ 5ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \
6 header_ops.o 6 header_ops.o sysfs.o nl802154.o
7af_802154-y := af_ieee802154.o raw.o dgram.o 7af_802154-y := af_ieee802154.o raw.o dgram.o
8 8
9ccflags-y += -D__CHECK_ENDIAN__ 9ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/ieee802154/af802154.h b/net/ieee802154/af802154.h
index 8330a09bfc95..343b63e6f953 100644
--- a/net/ieee802154/af802154.h
+++ b/net/ieee802154/af802154.h
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
diff --git a/net/ieee802154/af_ieee802154.c b/net/ieee802154/af_ieee802154.c
index 29e0de63001b..26da1e179737 100644
--- a/net/ieee802154/af_ieee802154.c
+++ b/net/ieee802154/af_ieee802154.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 17 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
new file mode 100644
index 000000000000..18bc7e738507
--- /dev/null
+++ b/net/ieee802154/core.c
@@ -0,0 +1,321 @@
1/*
2 * Copyright (C) 2007, 2008, 2009 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#include <linux/slab.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/device.h>
19
20#include <net/cfg802154.h>
21#include <net/rtnetlink.h>
22
23#include "ieee802154.h"
24#include "nl802154.h"
25#include "sysfs.h"
26#include "core.h"
27
28/* RCU-protected (and RTNL for writers) */
29LIST_HEAD(cfg802154_rdev_list);
30int cfg802154_rdev_list_generation;
31
32static int wpan_phy_match(struct device *dev, const void *data)
33{
34 return !strcmp(dev_name(dev), (const char *)data);
35}
36
37struct wpan_phy *wpan_phy_find(const char *str)
38{
39 struct device *dev;
40
41 if (WARN_ON(!str))
42 return NULL;
43
44 dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
45 if (!dev)
46 return NULL;
47
48 return container_of(dev, struct wpan_phy, dev);
49}
50EXPORT_SYMBOL(wpan_phy_find);
51
52struct wpan_phy_iter_data {
53 int (*fn)(struct wpan_phy *phy, void *data);
54 void *data;
55};
56
57static int wpan_phy_iter(struct device *dev, void *_data)
58{
59 struct wpan_phy_iter_data *wpid = _data;
60 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
61
62 return wpid->fn(phy, wpid->data);
63}
64
65int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),
66 void *data)
67{
68 struct wpan_phy_iter_data wpid = {
69 .fn = fn,
70 .data = data,
71 };
72
73 return class_for_each_device(&wpan_phy_class, NULL,
74 &wpid, wpan_phy_iter);
75}
76EXPORT_SYMBOL(wpan_phy_for_each);
77
78struct cfg802154_registered_device *
79cfg802154_rdev_by_wpan_phy_idx(int wpan_phy_idx)
80{
81 struct cfg802154_registered_device *result = NULL, *rdev;
82
83 ASSERT_RTNL();
84
85 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
86 if (rdev->wpan_phy_idx == wpan_phy_idx) {
87 result = rdev;
88 break;
89 }
90 }
91
92 return result;
93}
94
95struct wpan_phy *
96wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size)
97{
98 static atomic_t wpan_phy_counter = ATOMIC_INIT(0);
99 struct cfg802154_registered_device *rdev;
100 size_t alloc_size;
101
102 alloc_size = sizeof(*rdev) + priv_size;
103 rdev = kzalloc(alloc_size, GFP_KERNEL);
104 if (!rdev)
105 return NULL;
106
107 rdev->ops = ops;
108
109 rdev->wpan_phy_idx = atomic_inc_return(&wpan_phy_counter);
110
111 if (unlikely(rdev->wpan_phy_idx < 0)) {
112 /* ugh, wrapped! */
113 atomic_dec(&wpan_phy_counter);
114 kfree(rdev);
115 return NULL;
116 }
117
118 /* atomic_inc_return makes it start at 1, make it start at 0 */
119 rdev->wpan_phy_idx--;
120
121 mutex_init(&rdev->wpan_phy.pib_lock);
122
123 INIT_LIST_HEAD(&rdev->wpan_dev_list);
124 device_initialize(&rdev->wpan_phy.dev);
125 dev_set_name(&rdev->wpan_phy.dev, "wpan-phy%d", rdev->wpan_phy_idx);
126
127 rdev->wpan_phy.dev.class = &wpan_phy_class;
128 rdev->wpan_phy.dev.platform_data = rdev;
129
130 init_waitqueue_head(&rdev->dev_wait);
131
132 return &rdev->wpan_phy;
133}
134EXPORT_SYMBOL(wpan_phy_new);
135
136int wpan_phy_register(struct wpan_phy *phy)
137{
138 struct cfg802154_registered_device *rdev = wpan_phy_to_rdev(phy);
139 int ret;
140
141 rtnl_lock();
142 ret = device_add(&phy->dev);
143 if (ret) {
144 rtnl_unlock();
145 return ret;
146 }
147
148 list_add_rcu(&rdev->list, &cfg802154_rdev_list);
149 cfg802154_rdev_list_generation++;
150
151 /* TODO phy registered lock */
152 rtnl_unlock();
153
154 /* TODO nl802154 phy notify */
155
156 return 0;
157}
158EXPORT_SYMBOL(wpan_phy_register);
159
160void wpan_phy_unregister(struct wpan_phy *phy)
161{
162 struct cfg802154_registered_device *rdev = wpan_phy_to_rdev(phy);
163
164 wait_event(rdev->dev_wait, ({
165 int __count;
166 rtnl_lock();
167 __count = rdev->opencount;
168 rtnl_unlock();
169 __count == 0; }));
170
171 rtnl_lock();
172 /* TODO nl802154 phy notify */
173 /* TODO phy registered lock */
174
175 WARN_ON(!list_empty(&rdev->wpan_dev_list));
176
177 /* First remove the hardware from everywhere, this makes
178 * it impossible to find from userspace.
179 */
180 list_del_rcu(&rdev->list);
181 synchronize_rcu();
182
183 cfg802154_rdev_list_generation++;
184
185 device_del(&phy->dev);
186
187 rtnl_unlock();
188}
189EXPORT_SYMBOL(wpan_phy_unregister);
190
191void wpan_phy_free(struct wpan_phy *phy)
192{
193 put_device(&phy->dev);
194}
195EXPORT_SYMBOL(wpan_phy_free);
196
197void cfg802154_dev_free(struct cfg802154_registered_device *rdev)
198{
199 kfree(rdev);
200}
201
202static void
203cfg802154_update_iface_num(struct cfg802154_registered_device *rdev,
204 int iftype, int num)
205{
206 ASSERT_RTNL();
207
208 rdev->num_running_ifaces += num;
209}
210
211static int cfg802154_netdev_notifier_call(struct notifier_block *nb,
212 unsigned long state, void *ptr)
213{
214 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
215 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
216 struct cfg802154_registered_device *rdev;
217
218 if (!wpan_dev)
219 return NOTIFY_DONE;
220
221 rdev = wpan_phy_to_rdev(wpan_dev->wpan_phy);
222
223 /* TODO WARN_ON unspec type */
224
225 switch (state) {
226 /* TODO NETDEV_DEVTYPE */
227 case NETDEV_REGISTER:
228 wpan_dev->identifier = ++rdev->wpan_dev_id;
229 list_add_rcu(&wpan_dev->list, &rdev->wpan_dev_list);
230 rdev->devlist_generation++;
231
232 wpan_dev->netdev = dev;
233 break;
234 case NETDEV_DOWN:
235 cfg802154_update_iface_num(rdev, wpan_dev->iftype, -1);
236
237 rdev->opencount--;
238 wake_up(&rdev->dev_wait);
239 break;
240 case NETDEV_UP:
241 cfg802154_update_iface_num(rdev, wpan_dev->iftype, 1);
242
243 rdev->opencount++;
244 break;
245 case NETDEV_UNREGISTER:
246 /* It is possible to get NETDEV_UNREGISTER
247 * multiple times. To detect that, check
248 * that the interface is still on the list
249 * of registered interfaces, and only then
250 * remove and clean it up.
251 */
252 if (!list_empty(&wpan_dev->list)) {
253 list_del_rcu(&wpan_dev->list);
254 rdev->devlist_generation++;
255 }
256 /* synchronize (so that we won't find this netdev
257 * from other code any more) and then clear the list
258 * head so that the above code can safely check for
259 * !list_empty() to avoid double-cleanup.
260 */
261 synchronize_rcu();
262 INIT_LIST_HEAD(&wpan_dev->list);
263 break;
264 default:
265 return NOTIFY_DONE;
266 }
267
268 return NOTIFY_OK;
269}
270
271static struct notifier_block cfg802154_netdev_notifier = {
272 .notifier_call = cfg802154_netdev_notifier_call,
273};
274
275static int __init wpan_phy_class_init(void)
276{
277 int rc;
278
279 rc = wpan_phy_sysfs_init();
280 if (rc)
281 goto err;
282
283 rc = register_netdevice_notifier(&cfg802154_netdev_notifier);
284 if (rc)
285 goto err_nl;
286
287 rc = ieee802154_nl_init();
288 if (rc)
289 goto err_notifier;
290
291 rc = nl802154_init();
292 if (rc)
293 goto err_ieee802154_nl;
294
295 return 0;
296
297err_ieee802154_nl:
298 ieee802154_nl_exit();
299
300err_notifier:
301 unregister_netdevice_notifier(&cfg802154_netdev_notifier);
302err_nl:
303 wpan_phy_sysfs_exit();
304err:
305 return rc;
306}
307subsys_initcall(wpan_phy_class_init);
308
309static void __exit wpan_phy_class_exit(void)
310{
311 nl802154_exit();
312 ieee802154_nl_exit();
313 unregister_netdevice_notifier(&cfg802154_netdev_notifier);
314 wpan_phy_sysfs_exit();
315}
316module_exit(wpan_phy_class_exit);
317
318MODULE_LICENSE("GPL v2");
319MODULE_DESCRIPTION("IEEE 802.15.4 configuration interface");
320MODULE_AUTHOR("Dmitry Eremin-Solenikov");
321
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
new file mode 100644
index 000000000000..f3e95580caee
--- /dev/null
+++ b/net/ieee802154/core.h
@@ -0,0 +1,46 @@
1#ifndef __IEEE802154_CORE_H
2#define __IEEE802154_CORE_H
3
4#include <net/cfg802154.h>
5
6struct cfg802154_registered_device {
7 const struct cfg802154_ops *ops;
8 struct list_head list;
9
10 /* wpan_phy index, internal only */
11 int wpan_phy_idx;
12
13 /* also protected by devlist_mtx */
14 int opencount;
15 wait_queue_head_t dev_wait;
16
17 /* protected by RTNL only */
18 int num_running_ifaces;
19
20 /* associated wpan interfaces, protected by rtnl or RCU */
21 struct list_head wpan_dev_list;
22 int devlist_generation, wpan_dev_id;
23
24 /* must be last because of the way we do wpan_phy_priv(),
25 * and it should at least be aligned to NETDEV_ALIGN
26 */
27 struct wpan_phy wpan_phy __aligned(NETDEV_ALIGN);
28};
29
30static inline struct cfg802154_registered_device *
31wpan_phy_to_rdev(struct wpan_phy *wpan_phy)
32{
33 BUG_ON(!wpan_phy);
34 return container_of(wpan_phy, struct cfg802154_registered_device,
35 wpan_phy);
36}
37
38extern struct list_head cfg802154_rdev_list;
39extern int cfg802154_rdev_list_generation;
40
41/* free object */
42void cfg802154_dev_free(struct cfg802154_registered_device *rdev);
43struct cfg802154_registered_device *
44cfg802154_rdev_by_wpan_phy_idx(int wpan_phy_idx);
45
46#endif /* __IEEE802154_CORE_H */
diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
index ef2ad8aaef13..3d58befef467 100644
--- a/net/ieee802154/dgram.c
+++ b/net/ieee802154/dgram.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
@@ -27,9 +23,9 @@
27#include <linux/if_arp.h> 23#include <linux/if_arp.h>
28#include <linux/list.h> 24#include <linux/list.h>
29#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/ieee802154.h>
30#include <net/sock.h> 27#include <net/sock.h>
31#include <net/af_ieee802154.h> 28#include <net/af_ieee802154.h>
32#include <net/ieee802154.h>
33#include <net/ieee802154_netdev.h> 29#include <net/ieee802154_netdev.h>
34 30
35#include <asm/ioctls.h> 31#include <asm/ioctls.h>
diff --git a/net/ieee802154/header_ops.c b/net/ieee802154/header_ops.c
index c09294e39ca6..a051b6993177 100644
--- a/net/ieee802154/header_ops.c
+++ b/net/ieee802154/header_ops.c
@@ -14,8 +14,9 @@
14 * Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> 14 * Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
15 */ 15 */
16 16
17#include <linux/ieee802154.h>
18
17#include <net/mac802154.h> 19#include <net/mac802154.h>
18#include <net/ieee802154.h>
19#include <net/ieee802154_netdev.h> 20#include <net/ieee802154_netdev.h>
20 21
21static int 22static int
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h
index 5d352f86979e..a5d7515b7f62 100644
--- a/net/ieee802154/ieee802154.h
+++ b/net/ieee802154/ieee802154.h
@@ -10,16 +10,12 @@
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 */ 13 */
18#ifndef IEEE_802154_LOCAL_H 14#ifndef IEEE_802154_LOCAL_H
19#define IEEE_802154_LOCAL_H 15#define IEEE_802154_LOCAL_H
20 16
21int __init ieee802154_nl_init(void); 17int __init ieee802154_nl_init(void);
22void __exit ieee802154_nl_exit(void); 18void ieee802154_nl_exit(void);
23 19
24#define IEEE802154_OP(_cmd, _func) \ 20#define IEEE802154_OP(_cmd, _func) \
25 { \ 21 { \
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index 9222966f5e6d..63ee7d66950e 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
@@ -159,7 +155,7 @@ int __init ieee802154_nl_init(void)
159 ieee802154_mcgrps); 155 ieee802154_mcgrps);
160} 156}
161 157
162void __exit ieee802154_nl_exit(void) 158void ieee802154_nl_exit(void)
163{ 159{
164 genl_unregister_family(&nl802154_family); 160 genl_unregister_family(&nl802154_family);
165} 161}
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index c6bfe22bfa5e..fe77f0c770b8 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
@@ -26,16 +22,15 @@
26#include <linux/kernel.h> 22#include <linux/kernel.h>
27#include <linux/if_arp.h> 23#include <linux/if_arp.h>
28#include <linux/netdevice.h> 24#include <linux/netdevice.h>
25#include <linux/ieee802154.h>
29#include <net/netlink.h> 26#include <net/netlink.h>
30#include <net/genetlink.h> 27#include <net/genetlink.h>
31#include <net/sock.h> 28#include <net/sock.h>
32#include <linux/nl802154.h> 29#include <linux/nl802154.h>
33#include <linux/export.h> 30#include <linux/export.h>
34#include <net/af_ieee802154.h> 31#include <net/af_ieee802154.h>
35#include <net/nl802154.h>
36#include <net/ieee802154.h>
37#include <net/ieee802154_netdev.h> 32#include <net/ieee802154_netdev.h>
38#include <net/wpan-phy.h> 33#include <net/cfg802154.h>
39 34
40#include "ieee802154.h" 35#include "ieee802154.h"
41 36
@@ -59,186 +54,7 @@ static __le16 nla_get_shortaddr(const struct nlattr *nla)
59 return cpu_to_le16(nla_get_u16(nla)); 54 return cpu_to_le16(nla_get_u16(nla));
60} 55}
61 56
62int ieee802154_nl_assoc_indic(struct net_device *dev, 57static int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
63 struct ieee802154_addr *addr,
64 u8 cap)
65{
66 struct sk_buff *msg;
67
68 pr_debug("%s\n", __func__);
69
70 if (addr->mode != IEEE802154_ADDR_LONG) {
71 pr_err("%s: received non-long source address!\n", __func__);
72 return -EINVAL;
73 }
74
75 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
76 if (!msg)
77 return -ENOBUFS;
78
79 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
80 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
81 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
82 dev->dev_addr) ||
83 nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
84 addr->extended_addr) ||
85 nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap))
86 goto nla_put_failure;
87
88 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
89
90nla_put_failure:
91 nlmsg_free(msg);
92 return -ENOBUFS;
93}
94EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
95
96int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr,
97 u8 status)
98{
99 struct sk_buff *msg;
100
101 pr_debug("%s\n", __func__);
102
103 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
104 if (!msg)
105 return -ENOBUFS;
106
107 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
108 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
109 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
110 dev->dev_addr) ||
111 nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
112 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
113 goto nla_put_failure;
114 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
115
116nla_put_failure:
117 nlmsg_free(msg);
118 return -ENOBUFS;
119}
120EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
121
122int ieee802154_nl_disassoc_indic(struct net_device *dev,
123 struct ieee802154_addr *addr,
124 u8 reason)
125{
126 struct sk_buff *msg;
127
128 pr_debug("%s\n", __func__);
129
130 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
131 if (!msg)
132 return -ENOBUFS;
133
134 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
135 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
136 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
137 dev->dev_addr))
138 goto nla_put_failure;
139 if (addr->mode == IEEE802154_ADDR_LONG) {
140 if (nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
141 addr->extended_addr))
142 goto nla_put_failure;
143 } else {
144 if (nla_put_shortaddr(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
145 addr->short_addr))
146 goto nla_put_failure;
147 }
148 if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
149 goto nla_put_failure;
150 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
151
152nla_put_failure:
153 nlmsg_free(msg);
154 return -ENOBUFS;
155}
156EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
157
158int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
159{
160 struct sk_buff *msg;
161
162 pr_debug("%s\n", __func__);
163
164 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
165 if (!msg)
166 return -ENOBUFS;
167
168 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
169 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
170 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
171 dev->dev_addr) ||
172 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
173 goto nla_put_failure;
174 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
175
176nla_put_failure:
177 nlmsg_free(msg);
178 return -ENOBUFS;
179}
180EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
181
182int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
183 __le16 coord_addr)
184{
185 struct sk_buff *msg;
186
187 pr_debug("%s\n", __func__);
188
189 msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
190 if (!msg)
191 return -ENOBUFS;
192
193 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
194 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
195 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
196 dev->dev_addr) ||
197 nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_SHORT_ADDR,
198 coord_addr) ||
199 nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
200 goto nla_put_failure;
201 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
202
203nla_put_failure:
204 nlmsg_free(msg);
205 return -ENOBUFS;
206}
207EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
208
209int ieee802154_nl_scan_confirm(struct net_device *dev,
210 u8 status, u8 scan_type,
211 u32 unscanned, u8 page,
212 u8 *edl/* , struct list_head *pan_desc_list */)
213{
214 struct sk_buff *msg;
215
216 pr_debug("%s\n", __func__);
217
218 msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
219 if (!msg)
220 return -ENOBUFS;
221
222 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
223 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
224 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
225 dev->dev_addr) ||
226 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status) ||
227 nla_put_u8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type) ||
228 nla_put_u32(msg, IEEE802154_ATTR_CHANNELS, unscanned) ||
229 nla_put_u8(msg, IEEE802154_ATTR_PAGE, page) ||
230 (edl &&
231 nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl)))
232 goto nla_put_failure;
233 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
234
235nla_put_failure:
236 nlmsg_free(msg);
237 return -ENOBUFS;
238}
239EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
240
241int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
242{ 58{
243 struct sk_buff *msg; 59 struct sk_buff *msg;
244 60
@@ -278,8 +94,9 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
278 goto out; 94 goto out;
279 95
280 ops = ieee802154_mlme_ops(dev); 96 ops = ieee802154_mlme_ops(dev);
281 phy = ops->get_phy(dev); 97 phy = dev->ieee802154_ptr->wpan_phy;
282 BUG_ON(!phy); 98 BUG_ON(!phy);
99 get_device(&phy->dev);
283 100
284 short_addr = ops->get_short_addr(dev); 101 short_addr = ops->get_short_addr(dev);
285 pan_id = ops->get_pan_id(dev); 102 pan_id = ops->get_pan_id(dev);
@@ -296,7 +113,9 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
296 if (ops->get_mac_params) { 113 if (ops->get_mac_params) {
297 struct ieee802154_mac_params params; 114 struct ieee802154_mac_params params;
298 115
116 rtnl_lock();
299 ops->get_mac_params(dev, &params); 117 ops->get_mac_params(dev, &params);
118 rtnl_unlock();
300 119
301 if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER, 120 if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER,
302 params.transmit_power) || 121 params.transmit_power) ||
@@ -347,7 +166,10 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
347 if (!dev) 166 if (!dev)
348 return NULL; 167 return NULL;
349 168
350 if (dev->type != ARPHRD_IEEE802154) { 169 /* Check on mtu is currently a hacked solution because lowpan
170 * and wpan have the same ARPHRD type.
171 */
172 if (dev->type != ARPHRD_IEEE802154 || dev->mtu != IEEE802154_MTU) {
351 dev_put(dev); 173 dev_put(dev);
352 return NULL; 174 return NULL;
353 } 175 }
@@ -481,7 +303,7 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
481 u8 channel, bcn_ord, sf_ord; 303 u8 channel, bcn_ord, sf_ord;
482 u8 page; 304 u8 page;
483 int pan_coord, blx, coord_realign; 305 int pan_coord, blx, coord_realign;
484 int ret = -EOPNOTSUPP; 306 int ret = -EBUSY;
485 307
486 if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] || 308 if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
487 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] || 309 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] ||
@@ -497,8 +319,14 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
497 dev = ieee802154_nl_get_dev(info); 319 dev = ieee802154_nl_get_dev(info);
498 if (!dev) 320 if (!dev)
499 return -ENODEV; 321 return -ENODEV;
500 if (!ieee802154_mlme_ops(dev)->start_req) 322
323 if (netif_running(dev))
324 goto out;
325
326 if (!ieee802154_mlme_ops(dev)->start_req) {
327 ret = -EOPNOTSUPP;
501 goto out; 328 goto out;
329 }
502 330
503 addr.mode = IEEE802154_ADDR_SHORT; 331 addr.mode = IEEE802154_ADDR_SHORT;
504 addr.short_addr = nla_get_shortaddr( 332 addr.short_addr = nla_get_shortaddr(
@@ -525,8 +353,15 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
525 return -EINVAL; 353 return -EINVAL;
526 } 354 }
527 355
356 rtnl_lock();
528 ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page, 357 ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
529 bcn_ord, sf_ord, pan_coord, blx, coord_realign); 358 bcn_ord, sf_ord, pan_coord, blx, coord_realign);
359 rtnl_unlock();
360
361 /* FIXME: add validation for unused parameters to be sane
362 * for SoftMAC
363 */
364 ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
530 365
531out: 366out:
532 dev_put(dev); 367 dev_put(dev);
@@ -616,7 +451,11 @@ int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
616 451
617 idx = 0; 452 idx = 0;
618 for_each_netdev(net, dev) { 453 for_each_netdev(net, dev) {
619 if (idx < s_idx || (dev->type != ARPHRD_IEEE802154)) 454 /* Check on mtu is currently a hacked solution because lowpan
455 * and wpan have the same ARPHRD type.
456 */
457 if (idx < s_idx || dev->type != ARPHRD_IEEE802154 ||
458 dev->mtu != IEEE802154_MTU)
620 goto cont; 459 goto cont;
621 460
622 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid, 461 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
@@ -666,22 +505,10 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
666 !info->attrs[IEEE802154_ATTR_FRAME_RETRIES]) 505 !info->attrs[IEEE802154_ATTR_FRAME_RETRIES])
667 goto out; 506 goto out;
668 507
669 phy = ops->get_phy(dev); 508 phy = dev->ieee802154_ptr->wpan_phy;
670 509 get_device(&phy->dev);
671 if ((!phy->set_lbt && info->attrs[IEEE802154_ATTR_LBT_ENABLED]) ||
672 (!phy->set_cca_mode && info->attrs[IEEE802154_ATTR_CCA_MODE]) ||
673 (!phy->set_cca_ed_level &&
674 info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]) ||
675 (!phy->set_csma_params &&
676 (info->attrs[IEEE802154_ATTR_CSMA_RETRIES] ||
677 info->attrs[IEEE802154_ATTR_CSMA_MIN_BE] ||
678 info->attrs[IEEE802154_ATTR_CSMA_MAX_BE])) ||
679 (!phy->set_frame_retries &&
680 info->attrs[IEEE802154_ATTR_FRAME_RETRIES])) {
681 rc = -EOPNOTSUPP;
682 goto out_phy;
683 }
684 510
511 rtnl_lock();
685 ops->get_mac_params(dev, &params); 512 ops->get_mac_params(dev, &params);
686 513
687 if (info->attrs[IEEE802154_ATTR_TXPOWER]) 514 if (info->attrs[IEEE802154_ATTR_TXPOWER])
@@ -709,13 +536,13 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
709 params.frame_retries = nla_get_s8(info->attrs[IEEE802154_ATTR_FRAME_RETRIES]); 536 params.frame_retries = nla_get_s8(info->attrs[IEEE802154_ATTR_FRAME_RETRIES]);
710 537
711 rc = ops->set_mac_params(dev, &params); 538 rc = ops->set_mac_params(dev, &params);
539 rtnl_unlock();
712 540
713 wpan_phy_put(phy); 541 wpan_phy_put(phy);
714 dev_put(dev); 542 dev_put(dev);
715 return rc;
716 543
717out_phy: 544 return 0;
718 wpan_phy_put(phy); 545
719out: 546out:
720 dev_put(dev); 547 dev_put(dev);
721 return rc; 548 return rc;
@@ -962,7 +789,11 @@ ieee802154_llsec_dump_table(struct sk_buff *skb, struct netlink_callback *cb,
962 int rc; 789 int rc;
963 790
964 for_each_netdev(net, dev) { 791 for_each_netdev(net, dev) {
965 if (idx < first_dev || dev->type != ARPHRD_IEEE802154) 792 /* Check on mtu is currently a hacked solution because lowpan
793 * and wpan have the same ARPHRD type.
794 */
795 if (idx < first_dev || dev->type != ARPHRD_IEEE802154 ||
796 dev->mtu != IEEE802154_MTU)
966 goto skip; 797 goto skip;
967 798
968 data.ops = ieee802154_mlme_ops(dev); 799 data.ops = ieee802154_mlme_ops(dev);
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 972baf83411a..80a946dddd90 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
@@ -27,13 +23,15 @@
27#include <linux/if_arp.h> 23#include <linux/if_arp.h>
28#include <net/netlink.h> 24#include <net/netlink.h>
29#include <net/genetlink.h> 25#include <net/genetlink.h>
30#include <net/wpan-phy.h> 26#include <net/cfg802154.h>
31#include <net/af_ieee802154.h> 27#include <net/af_ieee802154.h>
32#include <net/ieee802154_netdev.h> 28#include <net/ieee802154_netdev.h>
33#include <net/rtnetlink.h> /* for rtnl_{un,}lock */ 29#include <net/rtnetlink.h> /* for rtnl_{un,}lock */
34#include <linux/nl802154.h> 30#include <linux/nl802154.h>
35 31
36#include "ieee802154.h" 32#include "ieee802154.h"
33#include "rdev-ops.h"
34#include "core.h"
37 35
38static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid, 36static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid,
39 u32 seq, int flags, struct wpan_phy *phy) 37 u32 seq, int flags, struct wpan_phy *phy)
@@ -207,11 +205,6 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
207 if (!msg) 205 if (!msg)
208 goto out_dev; 206 goto out_dev;
209 207
210 if (!phy->add_iface) {
211 rc = -EINVAL;
212 goto nla_put_failure;
213 }
214
215 if (info->attrs[IEEE802154_ATTR_HW_ADDR] && 208 if (info->attrs[IEEE802154_ATTR_HW_ADDR] &&
216 nla_len(info->attrs[IEEE802154_ATTR_HW_ADDR]) != 209 nla_len(info->attrs[IEEE802154_ATTR_HW_ADDR]) !=
217 IEEE802154_ADDR_LEN) { 210 IEEE802154_ADDR_LEN) {
@@ -227,11 +220,13 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
227 } 220 }
228 } 221 }
229 222
230 dev = phy->add_iface(phy, devname, type); 223 dev = rdev_add_virtual_intf_deprecated(wpan_phy_to_rdev(phy), devname,
224 type);
231 if (IS_ERR(dev)) { 225 if (IS_ERR(dev)) {
232 rc = PTR_ERR(dev); 226 rc = PTR_ERR(dev);
233 goto nla_put_failure; 227 goto nla_put_failure;
234 } 228 }
229 dev_hold(dev);
235 230
236 if (info->attrs[IEEE802154_ATTR_HW_ADDR]) { 231 if (info->attrs[IEEE802154_ATTR_HW_ADDR]) {
237 struct sockaddr addr; 232 struct sockaddr addr;
@@ -261,7 +256,7 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
261 256
262dev_unregister: 257dev_unregister:
263 rtnl_lock(); /* del_iface must be called with RTNL lock */ 258 rtnl_lock(); /* del_iface must be called with RTNL lock */
264 phy->del_iface(phy, dev); 259 rdev_del_virtual_intf_deprecated(wpan_phy_to_rdev(phy), dev);
265 dev_put(dev); 260 dev_put(dev);
266 rtnl_unlock(); 261 rtnl_unlock();
267nla_put_failure: 262nla_put_failure:
@@ -292,8 +287,9 @@ int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
292 if (!dev) 287 if (!dev)
293 return -ENODEV; 288 return -ENODEV;
294 289
295 phy = ieee802154_mlme_ops(dev)->get_phy(dev); 290 phy = dev->ieee802154_ptr->wpan_phy;
296 BUG_ON(!phy); 291 BUG_ON(!phy);
292 get_device(&phy->dev);
297 293
298 rc = -EINVAL; 294 rc = -EINVAL;
299 /* phy name is optional, but should be checked if it's given */ 295 /* phy name is optional, but should be checked if it's given */
@@ -323,13 +319,8 @@ int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
323 if (!msg) 319 if (!msg)
324 goto out_dev; 320 goto out_dev;
325 321
326 if (!phy->del_iface) {
327 rc = -EINVAL;
328 goto nla_put_failure;
329 }
330
331 rtnl_lock(); 322 rtnl_lock();
332 phy->del_iface(phy, dev); 323 rdev_del_virtual_intf_deprecated(wpan_phy_to_rdev(phy), dev);
333 324
334 /* We don't have device anymore */ 325 /* We don't have device anymore */
335 dev_put(dev); 326 dev_put(dev);
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
new file mode 100644
index 000000000000..889647744697
--- /dev/null
+++ b/net/ieee802154/nl802154.c
@@ -0,0 +1,957 @@
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
12 *
13 * Based on: net/wireless/nl80211.c
14 */
15
16#include <linux/rtnetlink.h>
17
18#include <net/cfg802154.h>
19#include <net/genetlink.h>
20#include <net/mac802154.h>
21#include <net/netlink.h>
22#include <net/nl802154.h>
23#include <net/sock.h>
24
25#include "nl802154.h"
26#include "rdev-ops.h"
27#include "core.h"
28
29static int nl802154_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
30 struct genl_info *info);
31
32static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34
35/* the netlink family */
36static struct genl_family nl802154_fam = {
37 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
38 .name = NL802154_GENL_NAME, /* have users key off the name instead */
39 .hdrsize = 0, /* no private header */
40 .version = 1, /* no particular meaning now */
41 .maxattr = NL802154_ATTR_MAX,
42 .netnsok = true,
43 .pre_doit = nl802154_pre_doit,
44 .post_doit = nl802154_post_doit,
45};
46
47/* multicast groups */
48enum nl802154_multicast_groups {
49 NL802154_MCGRP_CONFIG,
50};
51
52static const struct genl_multicast_group nl802154_mcgrps[] = {
53 [NL802154_MCGRP_CONFIG] = { .name = "config", },
54};
55
56/* returns ERR_PTR values */
57static struct wpan_dev *
58__cfg802154_wpan_dev_from_attrs(struct net *netns, struct nlattr **attrs)
59{
60 struct cfg802154_registered_device *rdev;
61 struct wpan_dev *result = NULL;
62 bool have_ifidx = attrs[NL802154_ATTR_IFINDEX];
63 bool have_wpan_dev_id = attrs[NL802154_ATTR_WPAN_DEV];
64 u64 wpan_dev_id;
65 int wpan_phy_idx = -1;
66 int ifidx = -1;
67
68 ASSERT_RTNL();
69
70 if (!have_ifidx && !have_wpan_dev_id)
71 return ERR_PTR(-EINVAL);
72
73 if (have_ifidx)
74 ifidx = nla_get_u32(attrs[NL802154_ATTR_IFINDEX]);
75 if (have_wpan_dev_id) {
76 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
77 wpan_phy_idx = wpan_dev_id >> 32;
78 }
79
80 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
81 struct wpan_dev *wpan_dev;
82
83 /* TODO netns compare */
84
85 if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
86 continue;
87
88 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
89 if (have_ifidx && wpan_dev->netdev &&
90 wpan_dev->netdev->ifindex == ifidx) {
91 result = wpan_dev;
92 break;
93 }
94 if (have_wpan_dev_id &&
95 wpan_dev->identifier == (u32)wpan_dev_id) {
96 result = wpan_dev;
97 break;
98 }
99 }
100
101 if (result)
102 break;
103 }
104
105 if (result)
106 return result;
107
108 return ERR_PTR(-ENODEV);
109}
110
111static struct cfg802154_registered_device *
112__cfg802154_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
113{
114 struct cfg802154_registered_device *rdev = NULL, *tmp;
115 struct net_device *netdev;
116
117 ASSERT_RTNL();
118
119 if (!attrs[NL802154_ATTR_WPAN_PHY] &&
120 !attrs[NL802154_ATTR_IFINDEX] &&
121 !attrs[NL802154_ATTR_WPAN_DEV])
122 return ERR_PTR(-EINVAL);
123
124 if (attrs[NL802154_ATTR_WPAN_PHY])
125 rdev = cfg802154_rdev_by_wpan_phy_idx(
126 nla_get_u32(attrs[NL802154_ATTR_WPAN_PHY]));
127
128 if (attrs[NL802154_ATTR_WPAN_DEV]) {
129 u64 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
130 struct wpan_dev *wpan_dev;
131 bool found = false;
132
133 tmp = cfg802154_rdev_by_wpan_phy_idx(wpan_dev_id >> 32);
134 if (tmp) {
135 /* make sure wpan_dev exists */
136 list_for_each_entry(wpan_dev, &tmp->wpan_dev_list, list) {
137 if (wpan_dev->identifier != (u32)wpan_dev_id)
138 continue;
139 found = true;
140 break;
141 }
142
143 if (!found)
144 tmp = NULL;
145
146 if (rdev && tmp != rdev)
147 return ERR_PTR(-EINVAL);
148 rdev = tmp;
149 }
150 }
151
152 if (attrs[NL802154_ATTR_IFINDEX]) {
153 int ifindex = nla_get_u32(attrs[NL802154_ATTR_IFINDEX]);
154
155 netdev = __dev_get_by_index(netns, ifindex);
156 if (netdev) {
157 if (netdev->ieee802154_ptr)
158 tmp = wpan_phy_to_rdev(
159 netdev->ieee802154_ptr->wpan_phy);
160 else
161 tmp = NULL;
162
163 /* not wireless device -- return error */
164 if (!tmp)
165 return ERR_PTR(-EINVAL);
166
167 /* mismatch -- return error */
168 if (rdev && tmp != rdev)
169 return ERR_PTR(-EINVAL);
170
171 rdev = tmp;
172 }
173 }
174
175 if (!rdev)
176 return ERR_PTR(-ENODEV);
177
178 /* TODO netns compare */
179
180 return rdev;
181}
182
183/* This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 *
186 * The result of this can be a PTR_ERR and hence must
187 * be checked with IS_ERR() for errors.
188 */
189static struct cfg802154_registered_device *
190cfg802154_get_dev_from_info(struct net *netns, struct genl_info *info)
191{
192 return __cfg802154_rdev_from_attrs(netns, info->attrs);
193}
194
195/* policy for the attributes */
196static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
197 [NL802154_ATTR_WPAN_PHY] = { .type = NLA_U32 },
198 [NL802154_ATTR_WPAN_PHY_NAME] = { .type = NLA_NUL_STRING,
199 .len = 20-1 },
200
201 [NL802154_ATTR_IFINDEX] = { .type = NLA_U32 },
202 [NL802154_ATTR_IFTYPE] = { .type = NLA_U32 },
203 [NL802154_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
204
205 [NL802154_ATTR_WPAN_DEV] = { .type = NLA_U64 },
206
207 [NL802154_ATTR_PAGE] = { .type = NLA_U8, },
208 [NL802154_ATTR_CHANNEL] = { .type = NLA_U8, },
209
210 [NL802154_ATTR_TX_POWER] = { .type = NLA_S8, },
211
212 [NL802154_ATTR_CCA_MODE] = { .type = NLA_U8, },
213
214 [NL802154_ATTR_SUPPORTED_CHANNEL] = { .type = NLA_U32, },
215
216 [NL802154_ATTR_PAN_ID] = { .type = NLA_U16, },
217 [NL802154_ATTR_EXTENDED_ADDR] = { .type = NLA_U64 },
218 [NL802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, },
219
220 [NL802154_ATTR_MIN_BE] = { .type = NLA_U8, },
221 [NL802154_ATTR_MAX_BE] = { .type = NLA_U8, },
222 [NL802154_ATTR_MAX_CSMA_BACKOFFS] = { .type = NLA_U8, },
223
224 [NL802154_ATTR_MAX_FRAME_RETRIES] = { .type = NLA_S8, },
225
226 [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, },
227};
228
229/* message building helper */
230static inline void *nl802154hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
231 int flags, u8 cmd)
232{
233 /* since there is no private header just add the generic one */
234 return genlmsg_put(skb, portid, seq, &nl802154_fam, flags, cmd);
235}
236
237static int
238nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
239 struct sk_buff *msg)
240{
241 struct nlattr *nl_page;
242 unsigned long page;
243
244 nl_page = nla_nest_start(msg, NL802154_ATTR_CHANNELS_SUPPORTED);
245 if (!nl_page)
246 return -ENOBUFS;
247
248 for (page = 0; page <= IEEE802154_MAX_PAGE; page++) {
249 if (nla_put_u32(msg, NL802154_ATTR_SUPPORTED_CHANNEL,
250 rdev->wpan_phy.channels_supported[page]))
251 return -ENOBUFS;
252 }
253 nla_nest_end(msg, nl_page);
254
255 return 0;
256}
257
258static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
259 enum nl802154_commands cmd,
260 struct sk_buff *msg, u32 portid, u32 seq,
261 int flags)
262{
263 void *hdr;
264
265 hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
266 if (!hdr)
267 return -ENOBUFS;
268
269 if (nla_put_u32(msg, NL802154_ATTR_WPAN_PHY, rdev->wpan_phy_idx) ||
270 nla_put_string(msg, NL802154_ATTR_WPAN_PHY_NAME,
271 wpan_phy_name(&rdev->wpan_phy)) ||
272 nla_put_u32(msg, NL802154_ATTR_GENERATION,
273 cfg802154_rdev_list_generation))
274 goto nla_put_failure;
275
276 if (cmd != NL802154_CMD_NEW_WPAN_PHY)
277 goto finish;
278
279 /* DUMP PHY PIB */
280
281 /* current channel settings */
282 if (nla_put_u8(msg, NL802154_ATTR_PAGE,
283 rdev->wpan_phy.current_page) ||
284 nla_put_u8(msg, NL802154_ATTR_CHANNEL,
285 rdev->wpan_phy.current_channel))
286 goto nla_put_failure;
287
288 /* supported channels array */
289 if (nl802154_send_wpan_phy_channels(rdev, msg))
290 goto nla_put_failure;
291
292 /* cca mode */
293 if (nla_put_u8(msg, NL802154_ATTR_CCA_MODE,
294 rdev->wpan_phy.cca_mode))
295 goto nla_put_failure;
296
297 if (nla_put_s8(msg, NL802154_ATTR_TX_POWER,
298 rdev->wpan_phy.transmit_power))
299 goto nla_put_failure;
300
301finish:
302 return genlmsg_end(msg, hdr);
303
304nla_put_failure:
305 genlmsg_cancel(msg, hdr);
306 return -EMSGSIZE;
307}
308
309struct nl802154_dump_wpan_phy_state {
310 s64 filter_wpan_phy;
311 long start;
312
313};
314
315static int nl802154_dump_wpan_phy_parse(struct sk_buff *skb,
316 struct netlink_callback *cb,
317 struct nl802154_dump_wpan_phy_state *state)
318{
319 struct nlattr **tb = nl802154_fam.attrbuf;
320 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl802154_fam.hdrsize,
321 tb, nl802154_fam.maxattr, nl802154_policy);
322
323 /* TODO check if we can handle error here,
324 * we have no backward compatibility
325 */
326 if (ret)
327 return 0;
328
329 if (tb[NL802154_ATTR_WPAN_PHY])
330 state->filter_wpan_phy = nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]);
331 if (tb[NL802154_ATTR_WPAN_DEV])
332 state->filter_wpan_phy = nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]) >> 32;
333 if (tb[NL802154_ATTR_IFINDEX]) {
334 struct net_device *netdev;
335 struct cfg802154_registered_device *rdev;
336 int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
337
338 /* TODO netns */
339 netdev = __dev_get_by_index(&init_net, ifidx);
340 if (!netdev)
341 return -ENODEV;
342 if (netdev->ieee802154_ptr) {
343 rdev = wpan_phy_to_rdev(
344 netdev->ieee802154_ptr->wpan_phy);
345 state->filter_wpan_phy = rdev->wpan_phy_idx;
346 }
347 }
348
349 return 0;
350}
351
352static int
353nl802154_dump_wpan_phy(struct sk_buff *skb, struct netlink_callback *cb)
354{
355 int idx = 0, ret;
356 struct nl802154_dump_wpan_phy_state *state = (void *)cb->args[0];
357 struct cfg802154_registered_device *rdev;
358
359 rtnl_lock();
360 if (!state) {
361 state = kzalloc(sizeof(*state), GFP_KERNEL);
362 if (!state) {
363 rtnl_unlock();
364 return -ENOMEM;
365 }
366 state->filter_wpan_phy = -1;
367 ret = nl802154_dump_wpan_phy_parse(skb, cb, state);
368 if (ret) {
369 kfree(state);
370 rtnl_unlock();
371 return ret;
372 }
373 cb->args[0] = (long)state;
374 }
375
376 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
377 /* TODO net ns compare */
378 if (++idx <= state->start)
379 continue;
380 if (state->filter_wpan_phy != -1 &&
381 state->filter_wpan_phy != rdev->wpan_phy_idx)
382 continue;
383 /* attempt to fit multiple wpan_phy data chunks into the skb */
384 ret = nl802154_send_wpan_phy(rdev,
385 NL802154_CMD_NEW_WPAN_PHY,
386 skb,
387 NETLINK_CB(cb->skb).portid,
388 cb->nlh->nlmsg_seq, NLM_F_MULTI);
389 if (ret < 0) {
390 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
391 !skb->len && cb->min_dump_alloc < 4096) {
392 cb->min_dump_alloc = 4096;
393 rtnl_unlock();
394 return 1;
395 }
396 idx--;
397 break;
398 }
399 break;
400 }
401 rtnl_unlock();
402
403 state->start = idx;
404
405 return skb->len;
406}
407
408static int nl802154_dump_wpan_phy_done(struct netlink_callback *cb)
409{
410 kfree((void *)cb->args[0]);
411 return 0;
412}
413
414static int nl802154_get_wpan_phy(struct sk_buff *skb, struct genl_info *info)
415{
416 struct sk_buff *msg;
417 struct cfg802154_registered_device *rdev = info->user_ptr[0];
418
419 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
420 if (!msg)
421 return -ENOMEM;
422
423 if (nl802154_send_wpan_phy(rdev, NL802154_CMD_NEW_WPAN_PHY, msg,
424 info->snd_portid, info->snd_seq, 0) < 0) {
425 nlmsg_free(msg);
426 return -ENOBUFS;
427 }
428
429 return genlmsg_reply(msg, info);
430}
431
432static inline u64 wpan_dev_id(struct wpan_dev *wpan_dev)
433{
434 return (u64)wpan_dev->identifier |
435 ((u64)wpan_phy_to_rdev(wpan_dev->wpan_phy)->wpan_phy_idx << 32);
436}
437
438static int
439nl802154_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
440 struct cfg802154_registered_device *rdev,
441 struct wpan_dev *wpan_dev)
442{
443 struct net_device *dev = wpan_dev->netdev;
444 void *hdr;
445
446 hdr = nl802154hdr_put(msg, portid, seq, flags,
447 NL802154_CMD_NEW_INTERFACE);
448 if (!hdr)
449 return -1;
450
451 if (dev &&
452 (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex) ||
453 nla_put_string(msg, NL802154_ATTR_IFNAME, dev->name)))
454 goto nla_put_failure;
455
456 if (nla_put_u32(msg, NL802154_ATTR_WPAN_PHY, rdev->wpan_phy_idx) ||
457 nla_put_u32(msg, NL802154_ATTR_IFTYPE, wpan_dev->iftype) ||
458 nla_put_u64(msg, NL802154_ATTR_WPAN_DEV, wpan_dev_id(wpan_dev)) ||
459 nla_put_u32(msg, NL802154_ATTR_GENERATION,
460 rdev->devlist_generation ^
461 (cfg802154_rdev_list_generation << 2)))
462 goto nla_put_failure;
463
464 /* address settings */
465 if (nla_put_le64(msg, NL802154_ATTR_EXTENDED_ADDR,
466 wpan_dev->extended_addr) ||
467 nla_put_le16(msg, NL802154_ATTR_SHORT_ADDR,
468 wpan_dev->short_addr) ||
469 nla_put_le16(msg, NL802154_ATTR_PAN_ID, wpan_dev->pan_id))
470 goto nla_put_failure;
471
472 /* ARET handling */
473 if (nla_put_s8(msg, NL802154_ATTR_MAX_FRAME_RETRIES,
474 wpan_dev->frame_retries) ||
475 nla_put_u8(msg, NL802154_ATTR_MAX_BE, wpan_dev->max_be) ||
476 nla_put_u8(msg, NL802154_ATTR_MAX_CSMA_BACKOFFS,
477 wpan_dev->csma_retries) ||
478 nla_put_u8(msg, NL802154_ATTR_MIN_BE, wpan_dev->min_be))
479 goto nla_put_failure;
480
481 /* listen before transmit */
482 if (nla_put_u8(msg, NL802154_ATTR_LBT_MODE, wpan_dev->lbt))
483 goto nla_put_failure;
484
485 return genlmsg_end(msg, hdr);
486
487nla_put_failure:
488 genlmsg_cancel(msg, hdr);
489 return -EMSGSIZE;
490}
491
492static int
493nl802154_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
494{
495 int wp_idx = 0;
496 int if_idx = 0;
497 int wp_start = cb->args[0];
498 int if_start = cb->args[1];
499 struct cfg802154_registered_device *rdev;
500 struct wpan_dev *wpan_dev;
501
502 rtnl_lock();
503 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
504 /* TODO netns compare */
505 if (wp_idx < wp_start) {
506 wp_idx++;
507 continue;
508 }
509 if_idx = 0;
510
511 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
512 if (if_idx < if_start) {
513 if_idx++;
514 continue;
515 }
516 if (nl802154_send_iface(skb, NETLINK_CB(cb->skb).portid,
517 cb->nlh->nlmsg_seq, NLM_F_MULTI,
518 rdev, wpan_dev) < 0) {
519 goto out;
520 }
521 if_idx++;
522 }
523
524 wp_idx++;
525 }
526out:
527 rtnl_unlock();
528
529 cb->args[0] = wp_idx;
530 cb->args[1] = if_idx;
531
532 return skb->len;
533}
534
535static int nl802154_get_interface(struct sk_buff *skb, struct genl_info *info)
536{
537 struct sk_buff *msg;
538 struct cfg802154_registered_device *rdev = info->user_ptr[0];
539 struct wpan_dev *wdev = info->user_ptr[1];
540
541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
542 if (!msg)
543 return -ENOMEM;
544
545 if (nl802154_send_iface(msg, info->snd_portid, info->snd_seq, 0,
546 rdev, wdev) < 0) {
547 nlmsg_free(msg);
548 return -ENOBUFS;
549 }
550
551 return genlmsg_reply(msg, info);
552}
553
554static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
555{
556 struct cfg802154_registered_device *rdev = info->user_ptr[0];
557 enum nl802154_iftype type = NL802154_IFTYPE_UNSPEC;
558 __le64 extended_addr = cpu_to_le64(0x0000000000000000ULL);
559
560 /* TODO avoid failing a new interface
561 * creation due to pending removal?
562 */
563
564 if (!info->attrs[NL802154_ATTR_IFNAME])
565 return -EINVAL;
566
567 if (info->attrs[NL802154_ATTR_IFTYPE]) {
568 type = nla_get_u32(info->attrs[NL802154_ATTR_IFTYPE]);
569 if (type > NL802154_IFTYPE_MAX)
570 return -EINVAL;
571 }
572
573 /* TODO add nla_get_le64 to netlink */
574 if (info->attrs[NL802154_ATTR_EXTENDED_ADDR])
575 extended_addr = (__force __le64)nla_get_u64(
576 info->attrs[NL802154_ATTR_EXTENDED_ADDR]);
577
578 if (!rdev->ops->add_virtual_intf)
579 return -EOPNOTSUPP;
580
581 return rdev_add_virtual_intf(rdev,
582 nla_data(info->attrs[NL802154_ATTR_IFNAME]),
583 type, extended_addr);
584}
585
586static int nl802154_del_interface(struct sk_buff *skb, struct genl_info *info)
587{
588 struct cfg802154_registered_device *rdev = info->user_ptr[0];
589 struct wpan_dev *wpan_dev = info->user_ptr[1];
590
591 if (!rdev->ops->del_virtual_intf)
592 return -EOPNOTSUPP;
593
594 /* If we remove a wpan device without a netdev then clear
595 * user_ptr[1] so that nl802154_post_doit won't dereference it
596 * to check if it needs to do dev_put(). Otherwise it crashes
597 * since the wpan_dev has been freed, unlike with a netdev where
598 * we need the dev_put() for the netdev to really be freed.
599 */
600 if (!wpan_dev->netdev)
601 info->user_ptr[1] = NULL;
602
603 return rdev_del_virtual_intf(rdev, wpan_dev);
604}
605
606static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
607{
608 struct cfg802154_registered_device *rdev = info->user_ptr[0];
609 u8 channel, page;
610
611 if (!info->attrs[NL802154_ATTR_PAGE] ||
612 !info->attrs[NL802154_ATTR_CHANNEL])
613 return -EINVAL;
614
615 page = nla_get_u8(info->attrs[NL802154_ATTR_PAGE]);
616 channel = nla_get_u8(info->attrs[NL802154_ATTR_CHANNEL]);
617
618 /* check 802.15.4 constraints */
619 if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL)
620 return -EINVAL;
621
622 return rdev_set_channel(rdev, page, channel);
623}
624
625static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)
626{
627 struct cfg802154_registered_device *rdev = info->user_ptr[0];
628 struct net_device *dev = info->user_ptr[1];
629 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
630 __le16 pan_id;
631
632 /* conflict here while tx/rx calls */
633 if (netif_running(dev))
634 return -EBUSY;
635
636 /* don't change address fields on monitor */
637 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR)
638 return -EINVAL;
639
640 if (!info->attrs[NL802154_ATTR_PAN_ID])
641 return -EINVAL;
642
643 pan_id = nla_get_le16(info->attrs[NL802154_ATTR_PAN_ID]);
644
645 return rdev_set_pan_id(rdev, wpan_dev, pan_id);
646}
647
648static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)
649{
650 struct cfg802154_registered_device *rdev = info->user_ptr[0];
651 struct net_device *dev = info->user_ptr[1];
652 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
653 __le16 short_addr;
654
655 /* conflict here while tx/rx calls */
656 if (netif_running(dev))
657 return -EBUSY;
658
659 /* don't change address fields on monitor */
660 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR)
661 return -EINVAL;
662
663 if (!info->attrs[NL802154_ATTR_SHORT_ADDR])
664 return -EINVAL;
665
666 short_addr = nla_get_le16(info->attrs[NL802154_ATTR_SHORT_ADDR]);
667
668 return rdev_set_short_addr(rdev, wpan_dev, short_addr);
669}
670
671static int
672nl802154_set_backoff_exponent(struct sk_buff *skb, struct genl_info *info)
673{
674 struct cfg802154_registered_device *rdev = info->user_ptr[0];
675 struct net_device *dev = info->user_ptr[1];
676 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
677 u8 min_be, max_be;
678
679 /* should be set on netif open inside phy settings */
680 if (netif_running(dev))
681 return -EBUSY;
682
683 if (!info->attrs[NL802154_ATTR_MIN_BE] ||
684 !info->attrs[NL802154_ATTR_MAX_BE])
685 return -EINVAL;
686
687 min_be = nla_get_u8(info->attrs[NL802154_ATTR_MIN_BE]);
688 max_be = nla_get_u8(info->attrs[NL802154_ATTR_MAX_BE]);
689
690 /* check 802.15.4 constraints */
691 if (max_be < 3 || max_be > 8 || min_be > max_be)
692 return -EINVAL;
693
694 return rdev_set_backoff_exponent(rdev, wpan_dev, min_be, max_be);
695}
696
697static int
698nl802154_set_max_csma_backoffs(struct sk_buff *skb, struct genl_info *info)
699{
700 struct cfg802154_registered_device *rdev = info->user_ptr[0];
701 struct net_device *dev = info->user_ptr[1];
702 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
703 u8 max_csma_backoffs;
704
705 /* conflict here while other running iface settings */
706 if (netif_running(dev))
707 return -EBUSY;
708
709 if (!info->attrs[NL802154_ATTR_MAX_CSMA_BACKOFFS])
710 return -EINVAL;
711
712 max_csma_backoffs = nla_get_u8(
713 info->attrs[NL802154_ATTR_MAX_CSMA_BACKOFFS]);
714
715 /* check 802.15.4 constraints */
716 if (max_csma_backoffs > 5)
717 return -EINVAL;
718
719 return rdev_set_max_csma_backoffs(rdev, wpan_dev, max_csma_backoffs);
720}
721
722static int
723nl802154_set_max_frame_retries(struct sk_buff *skb, struct genl_info *info)
724{
725 struct cfg802154_registered_device *rdev = info->user_ptr[0];
726 struct net_device *dev = info->user_ptr[1];
727 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
728 s8 max_frame_retries;
729
730 if (netif_running(dev))
731 return -EBUSY;
732
733 if (!info->attrs[NL802154_ATTR_MAX_FRAME_RETRIES])
734 return -EINVAL;
735
736 max_frame_retries = nla_get_s8(
737 info->attrs[NL802154_ATTR_MAX_FRAME_RETRIES]);
738
739 /* check 802.15.4 constraints */
740 if (max_frame_retries < -1 || max_frame_retries > 7)
741 return -EINVAL;
742
743 return rdev_set_max_frame_retries(rdev, wpan_dev, max_frame_retries);
744}
745
746static int nl802154_set_lbt_mode(struct sk_buff *skb, struct genl_info *info)
747{
748 struct cfg802154_registered_device *rdev = info->user_ptr[0];
749 struct net_device *dev = info->user_ptr[1];
750 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
751 bool mode;
752
753 if (netif_running(dev))
754 return -EBUSY;
755
756 if (!info->attrs[NL802154_ATTR_LBT_MODE])
757 return -EINVAL;
758
759 mode = !!nla_get_u8(info->attrs[NL802154_ATTR_LBT_MODE]);
760 return rdev_set_lbt_mode(rdev, wpan_dev, mode);
761}
762
763#define NL802154_FLAG_NEED_WPAN_PHY 0x01
764#define NL802154_FLAG_NEED_NETDEV 0x02
765#define NL802154_FLAG_NEED_RTNL 0x04
766#define NL802154_FLAG_CHECK_NETDEV_UP 0x08
767#define NL802154_FLAG_NEED_NETDEV_UP (NL802154_FLAG_NEED_NETDEV |\
768 NL802154_FLAG_CHECK_NETDEV_UP)
769#define NL802154_FLAG_NEED_WPAN_DEV 0x10
770#define NL802154_FLAG_NEED_WPAN_DEV_UP (NL802154_FLAG_NEED_WPAN_DEV |\
771 NL802154_FLAG_CHECK_NETDEV_UP)
772
773static int nl802154_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
774 struct genl_info *info)
775{
776 struct cfg802154_registered_device *rdev;
777 struct wpan_dev *wpan_dev;
778 struct net_device *dev;
779 bool rtnl = ops->internal_flags & NL802154_FLAG_NEED_RTNL;
780
781 if (rtnl)
782 rtnl_lock();
783
784 if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_PHY) {
785 rdev = cfg802154_get_dev_from_info(genl_info_net(info), info);
786 if (IS_ERR(rdev)) {
787 if (rtnl)
788 rtnl_unlock();
789 return PTR_ERR(rdev);
790 }
791 info->user_ptr[0] = rdev;
792 } else if (ops->internal_flags & NL802154_FLAG_NEED_NETDEV ||
793 ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
794 ASSERT_RTNL();
795 wpan_dev = __cfg802154_wpan_dev_from_attrs(genl_info_net(info),
796 info->attrs);
797 if (IS_ERR(wpan_dev)) {
798 if (rtnl)
799 rtnl_unlock();
800 return PTR_ERR(wpan_dev);
801 }
802
803 dev = wpan_dev->netdev;
804 rdev = wpan_phy_to_rdev(wpan_dev->wpan_phy);
805
806 if (ops->internal_flags & NL802154_FLAG_NEED_NETDEV) {
807 if (!dev) {
808 if (rtnl)
809 rtnl_unlock();
810 return -EINVAL;
811 }
812
813 info->user_ptr[1] = dev;
814 } else {
815 info->user_ptr[1] = wpan_dev;
816 }
817
818 if (dev) {
819 if (ops->internal_flags & NL802154_FLAG_CHECK_NETDEV_UP &&
820 !netif_running(dev)) {
821 if (rtnl)
822 rtnl_unlock();
823 return -ENETDOWN;
824 }
825
826 dev_hold(dev);
827 }
828
829 info->user_ptr[0] = rdev;
830 }
831
832 return 0;
833}
834
835static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
836 struct genl_info *info)
837{
838 if (info->user_ptr[1]) {
839 if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
840 struct wpan_dev *wpan_dev = info->user_ptr[1];
841
842 if (wpan_dev->netdev)
843 dev_put(wpan_dev->netdev);
844 } else {
845 dev_put(info->user_ptr[1]);
846 }
847 }
848
849 if (ops->internal_flags & NL802154_FLAG_NEED_RTNL)
850 rtnl_unlock();
851}
852
853static const struct genl_ops nl802154_ops[] = {
854 {
855 .cmd = NL802154_CMD_GET_WPAN_PHY,
856 .doit = nl802154_get_wpan_phy,
857 .dumpit = nl802154_dump_wpan_phy,
858 .done = nl802154_dump_wpan_phy_done,
859 .policy = nl802154_policy,
860 /* can be retrieved by unprivileged users */
861 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
862 NL802154_FLAG_NEED_RTNL,
863 },
864 {
865 .cmd = NL802154_CMD_GET_INTERFACE,
866 .doit = nl802154_get_interface,
867 .dumpit = nl802154_dump_interface,
868 .policy = nl802154_policy,
869 /* can be retrieved by unprivileged users */
870 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
871 NL802154_FLAG_NEED_RTNL,
872 },
873 {
874 .cmd = NL802154_CMD_NEW_INTERFACE,
875 .doit = nl802154_new_interface,
876 .policy = nl802154_policy,
877 .flags = GENL_ADMIN_PERM,
878 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
879 NL802154_FLAG_NEED_RTNL,
880 },
881 {
882 .cmd = NL802154_CMD_DEL_INTERFACE,
883 .doit = nl802154_del_interface,
884 .policy = nl802154_policy,
885 .flags = GENL_ADMIN_PERM,
886 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
887 NL802154_FLAG_NEED_RTNL,
888 },
889 {
890 .cmd = NL802154_CMD_SET_CHANNEL,
891 .doit = nl802154_set_channel,
892 .policy = nl802154_policy,
893 .flags = GENL_ADMIN_PERM,
894 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
895 NL802154_FLAG_NEED_RTNL,
896 },
897 {
898 .cmd = NL802154_CMD_SET_PAN_ID,
899 .doit = nl802154_set_pan_id,
900 .policy = nl802154_policy,
901 .flags = GENL_ADMIN_PERM,
902 .internal_flags = NL802154_FLAG_NEED_NETDEV |
903 NL802154_FLAG_NEED_RTNL,
904 },
905 {
906 .cmd = NL802154_CMD_SET_SHORT_ADDR,
907 .doit = nl802154_set_short_addr,
908 .policy = nl802154_policy,
909 .flags = GENL_ADMIN_PERM,
910 .internal_flags = NL802154_FLAG_NEED_NETDEV |
911 NL802154_FLAG_NEED_RTNL,
912 },
913 {
914 .cmd = NL802154_CMD_SET_BACKOFF_EXPONENT,
915 .doit = nl802154_set_backoff_exponent,
916 .policy = nl802154_policy,
917 .flags = GENL_ADMIN_PERM,
918 .internal_flags = NL802154_FLAG_NEED_NETDEV |
919 NL802154_FLAG_NEED_RTNL,
920 },
921 {
922 .cmd = NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
923 .doit = nl802154_set_max_csma_backoffs,
924 .policy = nl802154_policy,
925 .flags = GENL_ADMIN_PERM,
926 .internal_flags = NL802154_FLAG_NEED_NETDEV |
927 NL802154_FLAG_NEED_RTNL,
928 },
929 {
930 .cmd = NL802154_CMD_SET_MAX_FRAME_RETRIES,
931 .doit = nl802154_set_max_frame_retries,
932 .policy = nl802154_policy,
933 .flags = GENL_ADMIN_PERM,
934 .internal_flags = NL802154_FLAG_NEED_NETDEV |
935 NL802154_FLAG_NEED_RTNL,
936 },
937 {
938 .cmd = NL802154_CMD_SET_LBT_MODE,
939 .doit = nl802154_set_lbt_mode,
940 .policy = nl802154_policy,
941 .flags = GENL_ADMIN_PERM,
942 .internal_flags = NL802154_FLAG_NEED_NETDEV |
943 NL802154_FLAG_NEED_RTNL,
944 },
945};
946
947/* initialisation/exit functions */
948int nl802154_init(void)
949{
950 return genl_register_family_with_ops_groups(&nl802154_fam, nl802154_ops,
951 nl802154_mcgrps);
952}
953
954void nl802154_exit(void)
955{
956 genl_unregister_family(&nl802154_fam);
957}
diff --git a/net/ieee802154/nl802154.h b/net/ieee802154/nl802154.h
new file mode 100644
index 000000000000..3846a89d0958
--- /dev/null
+++ b/net/ieee802154/nl802154.h
@@ -0,0 +1,7 @@
1#ifndef __IEEE802154_NL802154_H
2#define __IEEE802154_NL802154_H
3
4int nl802154_init(void);
5void nl802154_exit(void);
6
7#endif /* __IEEE802154_NL802154_H */
diff --git a/net/ieee802154/nl_policy.c b/net/ieee802154/nl_policy.c
index 3a703ab88348..35c432668454 100644
--- a/net/ieee802154/nl_policy.c
+++ b/net/ieee802154/nl_policy.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */ 15 */
20 16
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
index 9d1f64806f02..3ffcf4a9de01 100644
--- a/net/ieee802154/raw.c
+++ b/net/ieee802154/raw.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
diff --git a/net/ieee802154/rdev-ops.h b/net/ieee802154/rdev-ops.h
new file mode 100644
index 000000000000..aff54fbd9264
--- /dev/null
+++ b/net/ieee802154/rdev-ops.h
@@ -0,0 +1,89 @@
1#ifndef __CFG802154_RDEV_OPS
2#define __CFG802154_RDEV_OPS
3
4#include <net/cfg802154.h>
5
6#include "core.h"
7
8static inline struct net_device *
9rdev_add_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
10 const char *name, int type)
11{
12 return rdev->ops->add_virtual_intf_deprecated(&rdev->wpan_phy, name,
13 type);
14}
15
16static inline void
17rdev_del_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
18 struct net_device *dev)
19{
20 rdev->ops->del_virtual_intf_deprecated(&rdev->wpan_phy, dev);
21}
22
23static inline int
24rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name,
25 enum nl802154_iftype type, __le64 extended_addr)
26{
27 return rdev->ops->add_virtual_intf(&rdev->wpan_phy, name, type,
28 extended_addr);
29}
30
31static inline int
32rdev_del_virtual_intf(struct cfg802154_registered_device *rdev,
33 struct wpan_dev *wpan_dev)
34{
35 return rdev->ops->del_virtual_intf(&rdev->wpan_phy, wpan_dev);
36}
37
38static inline int
39rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel)
40{
41 return rdev->ops->set_channel(&rdev->wpan_phy, page, channel);
42}
43
44static inline int
45rdev_set_pan_id(struct cfg802154_registered_device *rdev,
46 struct wpan_dev *wpan_dev, __le16 pan_id)
47{
48 return rdev->ops->set_pan_id(&rdev->wpan_phy, wpan_dev, pan_id);
49}
50
51static inline int
52rdev_set_short_addr(struct cfg802154_registered_device *rdev,
53 struct wpan_dev *wpan_dev, __le16 short_addr)
54{
55 return rdev->ops->set_short_addr(&rdev->wpan_phy, wpan_dev, short_addr);
56}
57
58static inline int
59rdev_set_backoff_exponent(struct cfg802154_registered_device *rdev,
60 struct wpan_dev *wpan_dev, u8 min_be, u8 max_be)
61{
62 return rdev->ops->set_backoff_exponent(&rdev->wpan_phy, wpan_dev,
63 min_be, max_be);
64}
65
66static inline int
67rdev_set_max_csma_backoffs(struct cfg802154_registered_device *rdev,
68 struct wpan_dev *wpan_dev, u8 max_csma_backoffs)
69{
70 return rdev->ops->set_max_csma_backoffs(&rdev->wpan_phy, wpan_dev,
71 max_csma_backoffs);
72}
73
74static inline int
75rdev_set_max_frame_retries(struct cfg802154_registered_device *rdev,
76 struct wpan_dev *wpan_dev, s8 max_frame_retries)
77{
78 return rdev->ops->set_max_frame_retries(&rdev->wpan_phy, wpan_dev,
79 max_frame_retries);
80}
81
82static inline int
83rdev_set_lbt_mode(struct cfg802154_registered_device *rdev,
84 struct wpan_dev *wpan_dev, bool mode)
85{
86 return rdev->ops->set_lbt_mode(&rdev->wpan_phy, wpan_dev, mode);
87}
88
89#endif /* __CFG802154_RDEV_OPS */
diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
index 7cfcd6885225..9d980ed3ffe2 100644
--- a/net/ieee802154/reassembly.c
+++ b/net/ieee802154/reassembly.c
@@ -33,7 +33,7 @@
33static const char lowpan_frags_cache_name[] = "lowpan-frags"; 33static const char lowpan_frags_cache_name[] = "lowpan-frags";
34 34
35struct lowpan_frag_info { 35struct lowpan_frag_info {
36 __be16 d_tag; 36 u16 d_tag;
37 u16 d_size; 37 u16 d_size;
38 u8 d_offset; 38 u8 d_offset;
39}; 39};
@@ -48,7 +48,7 @@ static struct inet_frags lowpan_frags;
48static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, 48static int lowpan_frag_reasm(struct lowpan_frag_queue *fq,
49 struct sk_buff *prev, struct net_device *dev); 49 struct sk_buff *prev, struct net_device *dev);
50 50
51static unsigned int lowpan_hash_frag(__be16 tag, u16 d_size, 51static unsigned int lowpan_hash_frag(u16 tag, u16 d_size,
52 const struct ieee802154_addr *saddr, 52 const struct ieee802154_addr *saddr,
53 const struct ieee802154_addr *daddr) 53 const struct ieee802154_addr *daddr)
54{ 54{
@@ -330,11 +330,13 @@ static int lowpan_get_frag_info(struct sk_buff *skb, const u8 frag_type,
330{ 330{
331 bool fail; 331 bool fail;
332 u8 pattern = 0, low = 0; 332 u8 pattern = 0, low = 0;
333 __be16 d_tag = 0;
333 334
334 fail = lowpan_fetch_skb(skb, &pattern, 1); 335 fail = lowpan_fetch_skb(skb, &pattern, 1);
335 fail |= lowpan_fetch_skb(skb, &low, 1); 336 fail |= lowpan_fetch_skb(skb, &low, 1);
336 frag_info->d_size = (pattern & 7) << 8 | low; 337 frag_info->d_size = (pattern & 7) << 8 | low;
337 fail |= lowpan_fetch_skb(skb, &frag_info->d_tag, 2); 338 fail |= lowpan_fetch_skb(skb, &d_tag, 2);
339 frag_info->d_tag = ntohs(d_tag);
338 340
339 if (frag_type == LOWPAN_DISPATCH_FRAGN) { 341 if (frag_type == LOWPAN_DISPATCH_FRAGN) {
340 fail |= lowpan_fetch_skb(skb, &frag_info->d_offset, 1); 342 fail |= lowpan_fetch_skb(skb, &frag_info->d_offset, 1);
diff --git a/net/ieee802154/reassembly.h b/net/ieee802154/reassembly.h
index 74e4a7c98191..836b16fa001f 100644
--- a/net/ieee802154/reassembly.h
+++ b/net/ieee802154/reassembly.h
@@ -4,7 +4,7 @@
4#include <net/inet_frag.h> 4#include <net/inet_frag.h>
5 5
6struct lowpan_create_arg { 6struct lowpan_create_arg {
7 __be16 tag; 7 u16 tag;
8 u16 d_size; 8 u16 d_size;
9 const struct ieee802154_addr *src; 9 const struct ieee802154_addr *src;
10 const struct ieee802154_addr *dst; 10 const struct ieee802154_addr *dst;
@@ -15,7 +15,7 @@ struct lowpan_create_arg {
15struct lowpan_frag_queue { 15struct lowpan_frag_queue {
16 struct inet_frag_queue q; 16 struct inet_frag_queue q;
17 17
18 __be16 tag; 18 u16 tag;
19 u16 d_size; 19 u16 d_size;
20 struct ieee802154_addr saddr; 20 struct ieee802154_addr saddr;
21 struct ieee802154_addr daddr; 21 struct ieee802154_addr daddr;
diff --git a/net/ieee802154/sysfs.c b/net/ieee802154/sysfs.c
new file mode 100644
index 000000000000..1613b9c65dfa
--- /dev/null
+++ b/net/ieee802154/sysfs.c
@@ -0,0 +1,128 @@
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
12 *
13 * Based on: net/wireless/sysfs.c
14 */
15
16#include <linux/device.h>
17
18#include <net/cfg802154.h>
19
20#include "core.h"
21#include "sysfs.h"
22
23static inline struct cfg802154_registered_device *
24dev_to_rdev(struct device *dev)
25{
26 return container_of(dev, struct cfg802154_registered_device,
27 wpan_phy.dev);
28}
29
30#define SHOW_FMT(name, fmt, member) \
31static ssize_t name ## _show(struct device *dev, \
32 struct device_attribute *attr, \
33 char *buf) \
34{ \
35 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
36} \
37static DEVICE_ATTR_RO(name)
38
39SHOW_FMT(index, "%d", wpan_phy_idx);
40
41static ssize_t name_show(struct device *dev,
42 struct device_attribute *attr,
43 char *buf)
44{
45 struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
46
47 return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
48}
49static DEVICE_ATTR_RO(name);
50
51#define MASTER_SHOW_COMPLEX(name, format_string, args...) \
52static ssize_t name ## _show(struct device *dev, \
53 struct device_attribute *attr, char *buf) \
54{ \
55 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); \
56 int ret; \
57 \
58 mutex_lock(&phy->pib_lock); \
59 ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \
60 mutex_unlock(&phy->pib_lock); \
61 return ret; \
62} \
63static DEVICE_ATTR_RO(name)
64
65#define MASTER_SHOW(field, format_string) \
66 MASTER_SHOW_COMPLEX(field, format_string, phy->field)
67
68MASTER_SHOW(current_channel, "%d");
69MASTER_SHOW(current_page, "%d");
70MASTER_SHOW(transmit_power, "%d +- 1 dB");
71MASTER_SHOW(cca_mode, "%d");
72
73static ssize_t channels_supported_show(struct device *dev,
74 struct device_attribute *attr,
75 char *buf)
76{
77 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
78 int ret;
79 int i, len = 0;
80
81 mutex_lock(&phy->pib_lock);
82 for (i = 0; i < 32; i++) {
83 ret = snprintf(buf + len, PAGE_SIZE - len,
84 "%#09x\n", phy->channels_supported[i]);
85 if (ret < 0)
86 break;
87 len += ret;
88 }
89 mutex_unlock(&phy->pib_lock);
90 return len;
91}
92static DEVICE_ATTR_RO(channels_supported);
93
94static void wpan_phy_release(struct device *dev)
95{
96 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
97
98 cfg802154_dev_free(rdev);
99}
100
101static struct attribute *pmib_attrs[] = {
102 &dev_attr_index.attr,
103 &dev_attr_name.attr,
104 /* below will be removed soon */
105 &dev_attr_current_channel.attr,
106 &dev_attr_current_page.attr,
107 &dev_attr_channels_supported.attr,
108 &dev_attr_transmit_power.attr,
109 &dev_attr_cca_mode.attr,
110 NULL,
111};
112ATTRIBUTE_GROUPS(pmib);
113
114struct class wpan_phy_class = {
115 .name = "ieee802154",
116 .dev_release = wpan_phy_release,
117 .dev_groups = pmib_groups,
118};
119
120int wpan_phy_sysfs_init(void)
121{
122 return class_register(&wpan_phy_class);
123}
124
125void wpan_phy_sysfs_exit(void)
126{
127 class_unregister(&wpan_phy_class);
128}
diff --git a/net/ieee802154/sysfs.h b/net/ieee802154/sysfs.h
new file mode 100644
index 000000000000..aa42e39ecbec
--- /dev/null
+++ b/net/ieee802154/sysfs.h
@@ -0,0 +1,9 @@
1#ifndef __IEEE802154_SYSFS_H
2#define __IEEE802154_SYSFS_H
3
4int wpan_phy_sysfs_init(void);
5void wpan_phy_sysfs_exit(void);
6
7extern struct class wpan_phy_class;
8
9#endif /* __IEEE802154_SYSFS_H */
diff --git a/net/ieee802154/wpan-class.c b/net/ieee802154/wpan-class.c
deleted file mode 100644
index 4955e0fe5883..000000000000
--- a/net/ieee802154/wpan-class.c
+++ /dev/null
@@ -1,230 +0,0 @@
1/*
2 * Copyright (C) 2007, 2008, 2009 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 */
18
19#include <linux/slab.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/device.h>
23
24#include <net/wpan-phy.h>
25
26#include "ieee802154.h"
27
28#define MASTER_SHOW_COMPLEX(name, format_string, args...) \
29static ssize_t name ## _show(struct device *dev, \
30 struct device_attribute *attr, char *buf) \
31{ \
32 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); \
33 int ret; \
34 \
35 mutex_lock(&phy->pib_lock); \
36 ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \
37 mutex_unlock(&phy->pib_lock); \
38 return ret; \
39} \
40static DEVICE_ATTR_RO(name);
41
42#define MASTER_SHOW(field, format_string) \
43 MASTER_SHOW_COMPLEX(field, format_string, phy->field)
44
45MASTER_SHOW(current_channel, "%d");
46MASTER_SHOW(current_page, "%d");
47MASTER_SHOW(transmit_power, "%d +- 1 dB");
48MASTER_SHOW(cca_mode, "%d");
49
50static ssize_t channels_supported_show(struct device *dev,
51 struct device_attribute *attr,
52 char *buf)
53{
54 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
55 int ret;
56 int i, len = 0;
57
58 mutex_lock(&phy->pib_lock);
59 for (i = 0; i < 32; i++) {
60 ret = snprintf(buf + len, PAGE_SIZE - len,
61 "%#09x\n", phy->channels_supported[i]);
62 if (ret < 0)
63 break;
64 len += ret;
65 }
66 mutex_unlock(&phy->pib_lock);
67 return len;
68}
69static DEVICE_ATTR_RO(channels_supported);
70
71static struct attribute *pmib_attrs[] = {
72 &dev_attr_current_channel.attr,
73 &dev_attr_current_page.attr,
74 &dev_attr_channels_supported.attr,
75 &dev_attr_transmit_power.attr,
76 &dev_attr_cca_mode.attr,
77 NULL,
78};
79ATTRIBUTE_GROUPS(pmib);
80
81static void wpan_phy_release(struct device *d)
82{
83 struct wpan_phy *phy = container_of(d, struct wpan_phy, dev);
84
85 kfree(phy);
86}
87
88static struct class wpan_phy_class = {
89 .name = "ieee802154",
90 .dev_release = wpan_phy_release,
91 .dev_groups = pmib_groups,
92};
93
94static DEFINE_MUTEX(wpan_phy_mutex);
95static int wpan_phy_idx;
96
97static int wpan_phy_match(struct device *dev, const void *data)
98{
99 return !strcmp(dev_name(dev), (const char *)data);
100}
101
102struct wpan_phy *wpan_phy_find(const char *str)
103{
104 struct device *dev;
105
106 if (WARN_ON(!str))
107 return NULL;
108
109 dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
110 if (!dev)
111 return NULL;
112
113 return container_of(dev, struct wpan_phy, dev);
114}
115EXPORT_SYMBOL(wpan_phy_find);
116
117struct wpan_phy_iter_data {
118 int (*fn)(struct wpan_phy *phy, void *data);
119 void *data;
120};
121
122static int wpan_phy_iter(struct device *dev, void *_data)
123{
124 struct wpan_phy_iter_data *wpid = _data;
125 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
126
127 return wpid->fn(phy, wpid->data);
128}
129
130int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),
131 void *data)
132{
133 struct wpan_phy_iter_data wpid = {
134 .fn = fn,
135 .data = data,
136 };
137
138 return class_for_each_device(&wpan_phy_class, NULL,
139 &wpid, wpan_phy_iter);
140}
141EXPORT_SYMBOL(wpan_phy_for_each);
142
143static int wpan_phy_idx_valid(int idx)
144{
145 return idx >= 0;
146}
147
148struct wpan_phy *wpan_phy_alloc(size_t priv_size)
149{
150 struct wpan_phy *phy = kzalloc(sizeof(*phy) + priv_size,
151 GFP_KERNEL);
152
153 if (!phy)
154 goto out;
155 mutex_lock(&wpan_phy_mutex);
156 phy->idx = wpan_phy_idx++;
157 if (unlikely(!wpan_phy_idx_valid(phy->idx))) {
158 wpan_phy_idx--;
159 mutex_unlock(&wpan_phy_mutex);
160 kfree(phy);
161 goto out;
162 }
163 mutex_unlock(&wpan_phy_mutex);
164
165 mutex_init(&phy->pib_lock);
166
167 device_initialize(&phy->dev);
168 dev_set_name(&phy->dev, "wpan-phy%d", phy->idx);
169
170 phy->dev.class = &wpan_phy_class;
171
172 phy->current_channel = -1; /* not initialised */
173 phy->current_page = 0; /* for compatibility */
174
175 return phy;
176
177out:
178 return NULL;
179}
180EXPORT_SYMBOL(wpan_phy_alloc);
181
182int wpan_phy_register(struct wpan_phy *phy)
183{
184 return device_add(&phy->dev);
185}
186EXPORT_SYMBOL(wpan_phy_register);
187
188void wpan_phy_unregister(struct wpan_phy *phy)
189{
190 device_del(&phy->dev);
191}
192EXPORT_SYMBOL(wpan_phy_unregister);
193
194void wpan_phy_free(struct wpan_phy *phy)
195{
196 put_device(&phy->dev);
197}
198EXPORT_SYMBOL(wpan_phy_free);
199
200static int __init wpan_phy_class_init(void)
201{
202 int rc;
203
204 rc = class_register(&wpan_phy_class);
205 if (rc)
206 goto err;
207
208 rc = ieee802154_nl_init();
209 if (rc)
210 goto err_nl;
211
212 return 0;
213err_nl:
214 class_unregister(&wpan_phy_class);
215err:
216 return rc;
217}
218subsys_initcall(wpan_phy_class_init);
219
220static void __exit wpan_phy_class_exit(void)
221{
222 ieee802154_nl_exit();
223 class_unregister(&wpan_phy_class);
224}
225module_exit(wpan_phy_class_exit);
226
227MODULE_LICENSE("GPL v2");
228MODULE_DESCRIPTION("IEEE 802.15.4 configuration interface");
229MODULE_AUTHOR("Dmitry Eremin-Solenikov");
230
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index aeb6a483b3bc..75cc6801a431 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -33,6 +33,13 @@ config MAC80211_RC_MINSTREL_HT
33 ---help--- 33 ---help---
34 This option enables the 'minstrel_ht' TX rate control algorithm 34 This option enables the 'minstrel_ht' TX rate control algorithm
35 35
36config MAC80211_RC_MINSTREL_VHT
37 bool "Minstrel 802.11ac support" if EXPERT
38 depends on MAC80211_RC_MINSTREL_HT
39 default n
40 ---help---
41 This option enables VHT in the 'minstrel_ht' TX rate control algorithm
42
36choice 43choice
37 prompt "Default rate control algorithm" 44 prompt "Default rate control algorithm"
38 depends on MAC80211_HAS_RC 45 depends on MAC80211_HAS_RC
@@ -169,6 +176,17 @@ config MAC80211_HT_DEBUG
169 176
170 Do not select this option. 177 Do not select this option.
171 178
179config MAC80211_OCB_DEBUG
180 bool "Verbose OCB debugging"
181 depends on MAC80211_DEBUG_MENU
182 ---help---
183 Selecting this option causes mac80211 to print out
184 very verbose OCB debugging messages. It should not
185 be selected on production systems as those messages
186 are remotely triggerable.
187
188 Do not select this option.
189
172config MAC80211_IBSS_DEBUG 190config MAC80211_IBSS_DEBUG
173 bool "Verbose IBSS debugging" 191 bool "Verbose IBSS debugging"
174 depends on MAC80211_DEBUG_MENU 192 depends on MAC80211_DEBUG_MENU
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 7273d2796dd1..e53671b1105e 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -27,7 +27,8 @@ mac80211-y := \
27 event.o \ 27 event.o \
28 chan.o \ 28 chan.o \
29 trace.o mlme.o \ 29 trace.o mlme.o \
30 tdls.o 30 tdls.o \
31 ocb.o
31 32
32mac80211-$(CONFIG_MAC80211_LEDS) += led.o 33mac80211-$(CONFIG_MAC80211_LEDS) += led.o
33mac80211-$(CONFIG_MAC80211_DEBUGFS) += \ 34mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index d6986f3aa5c4..9242c60048cf 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -149,11 +149,6 @@ void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
149 rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx); 149 rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
150} 150}
151 151
152static inline int ieee80211_ac_from_tid(int tid)
153{
154 return ieee802_1d_to_ac[tid & 7];
155}
156
157/* 152/*
158 * When multiple aggregation sessions on multiple stations 153 * When multiple aggregation sessions on multiple stations
159 * are being created/destroyed simultaneously, we need to 154 * are being created/destroyed simultaneously, we need to
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 343da1e35025..06185940cbb6 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -20,6 +20,7 @@
20#include "cfg.h" 20#include "cfg.h"
21#include "rate.h" 21#include "rate.h"
22#include "mesh.h" 22#include "mesh.h"
23#include "wme.h"
23 24
24static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, 25static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
25 const char *name, 26 const char *name,
@@ -190,7 +191,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
190 * receive the key. When wpa_supplicant has roamed 191 * receive the key. When wpa_supplicant has roamed
191 * using FT, it attempts to set the key before 192 * using FT, it attempts to set the key before
192 * association has completed, this rejects that attempt 193 * association has completed, this rejects that attempt
193 * so it will set the key again after assocation. 194 * so it will set the key again after association.
194 * 195 *
195 * TODO: accept the key if we have a station entry and 196 * TODO: accept the key if we have a station entry and
196 * add it to the device after the station. 197 * add it to the device after the station.
@@ -229,6 +230,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
229 case NUM_NL80211_IFTYPES: 230 case NUM_NL80211_IFTYPES:
230 case NL80211_IFTYPE_P2P_CLIENT: 231 case NL80211_IFTYPE_P2P_CLIENT:
231 case NL80211_IFTYPE_P2P_GO: 232 case NL80211_IFTYPE_P2P_GO:
233 case NL80211_IFTYPE_OCB:
232 /* shouldn't happen */ 234 /* shouldn't happen */
233 WARN_ON_ONCE(1); 235 WARN_ON_ONCE(1);
234 break; 236 break;
@@ -1225,14 +1227,14 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1225} 1227}
1226 1228
1227static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, 1229static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1228 const u8 *mac) 1230 struct station_del_parameters *params)
1229{ 1231{
1230 struct ieee80211_sub_if_data *sdata; 1232 struct ieee80211_sub_if_data *sdata;
1231 1233
1232 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1234 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1233 1235
1234 if (mac) 1236 if (params->mac)
1235 return sta_info_destroy_addr_bss(sdata, mac); 1237 return sta_info_destroy_addr_bss(sdata, params->mac);
1236 1238
1237 sta_info_flush(sdata); 1239 sta_info_flush(sdata);
1238 return 0; 1240 return 0;
@@ -1516,6 +1518,57 @@ static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1516 return 0; 1518 return 0;
1517} 1519}
1518 1520
1521static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1522 struct mpath_info *pinfo)
1523{
1524 memset(pinfo, 0, sizeof(*pinfo));
1525 memcpy(mpp, mpath->mpp, ETH_ALEN);
1526
1527 pinfo->generation = mpp_paths_generation;
1528}
1529
1530static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1531 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1532
1533{
1534 struct ieee80211_sub_if_data *sdata;
1535 struct mesh_path *mpath;
1536
1537 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1538
1539 rcu_read_lock();
1540 mpath = mpp_path_lookup(sdata, dst);
1541 if (!mpath) {
1542 rcu_read_unlock();
1543 return -ENOENT;
1544 }
1545 memcpy(dst, mpath->dst, ETH_ALEN);
1546 mpp_set_pinfo(mpath, mpp, pinfo);
1547 rcu_read_unlock();
1548 return 0;
1549}
1550
1551static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1552 int idx, u8 *dst, u8 *mpp,
1553 struct mpath_info *pinfo)
1554{
1555 struct ieee80211_sub_if_data *sdata;
1556 struct mesh_path *mpath;
1557
1558 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1559
1560 rcu_read_lock();
1561 mpath = mpp_path_lookup_by_idx(sdata, idx);
1562 if (!mpath) {
1563 rcu_read_unlock();
1564 return -ENOENT;
1565 }
1566 memcpy(dst, mpath->dst, ETH_ALEN);
1567 mpp_set_pinfo(mpath, mpp, pinfo);
1568 rcu_read_unlock();
1569 return 0;
1570}
1571
1519static int ieee80211_get_mesh_config(struct wiphy *wiphy, 1572static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1520 struct net_device *dev, 1573 struct net_device *dev,
1521 struct mesh_config *conf) 1574 struct mesh_config *conf)
@@ -1966,6 +2019,17 @@ static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1966 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); 2019 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
1967} 2020}
1968 2021
2022static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2023 struct ocb_setup *setup)
2024{
2025 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2026}
2027
2028static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2029{
2030 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2031}
2032
1969static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, 2033static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
1970 int rate[IEEE80211_NUM_BANDS]) 2034 int rate[IEEE80211_NUM_BANDS])
1971{ 2035{
@@ -2081,6 +2145,9 @@ static int ieee80211_get_tx_power(struct wiphy *wiphy,
2081 struct ieee80211_local *local = wiphy_priv(wiphy); 2145 struct ieee80211_local *local = wiphy_priv(wiphy);
2082 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 2146 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2083 2147
2148 if (local->ops->get_txpower)
2149 return drv_get_txpower(local, sdata, dbm);
2150
2084 if (!local->use_chanctx) 2151 if (!local->use_chanctx)
2085 *dbm = local->hw.conf.power_level; 2152 *dbm = local->hw.conf.power_level;
2086 else 2153 else
@@ -2850,11 +2917,7 @@ static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2850 if (sdata->reserved_ready) 2917 if (sdata->reserved_ready)
2851 return 0; 2918 return 0;
2852 2919
2853 err = ieee80211_vif_use_reserved_context(sdata); 2920 return ieee80211_vif_use_reserved_context(sdata);
2854 if (err)
2855 return err;
2856
2857 return 0;
2858 } 2921 }
2859 2922
2860 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, 2923 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
@@ -2868,7 +2931,6 @@ static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2868 return err; 2931 return err;
2869 2932
2870 ieee80211_bss_info_change_notify(sdata, changed); 2933 ieee80211_bss_info_change_notify(sdata, changed);
2871 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2872 2934
2873 if (sdata->csa_block_tx) { 2935 if (sdata->csa_block_tx) {
2874 ieee80211_wake_vif_queues(local, sdata, 2936 ieee80211_wake_vif_queues(local, sdata,
@@ -2876,6 +2938,12 @@ static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2876 sdata->csa_block_tx = false; 2938 sdata->csa_block_tx = false;
2877 } 2939 }
2878 2940
2941 err = drv_post_channel_switch(sdata);
2942 if (err)
2943 return err;
2944
2945 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2946
2879 return 0; 2947 return 0;
2880} 2948}
2881 2949
@@ -3053,9 +3121,11 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3053{ 3121{
3054 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3055 struct ieee80211_local *local = sdata->local; 3123 struct ieee80211_local *local = sdata->local;
3124 struct ieee80211_channel_switch ch_switch;
3056 struct ieee80211_chanctx_conf *conf; 3125 struct ieee80211_chanctx_conf *conf;
3057 struct ieee80211_chanctx *chanctx; 3126 struct ieee80211_chanctx *chanctx;
3058 int err, changed = 0; 3127 u32 changed = 0;
3128 int err;
3059 3129
3060 sdata_assert_lock(sdata); 3130 sdata_assert_lock(sdata);
3061 lockdep_assert_held(&local->mtx); 3131 lockdep_assert_held(&local->mtx);
@@ -3088,6 +3158,10 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3088 goto out; 3158 goto out;
3089 } 3159 }
3090 3160
3161 err = drv_pre_channel_switch(sdata, &ch_switch);
3162 if (err)
3163 goto out;
3164
3091 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef, 3165 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3092 chanctx->mode, 3166 chanctx->mode,
3093 params->radar_required); 3167 params->radar_required);
@@ -3101,6 +3175,12 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3101 goto out; 3175 goto out;
3102 } 3176 }
3103 3177
3178 ch_switch.timestamp = 0;
3179 ch_switch.device_timestamp = 0;
3180 ch_switch.block_tx = params->block_tx;
3181 ch_switch.chandef = params->chandef;
3182 ch_switch.count = params->count;
3183
3104 err = ieee80211_set_csa_beacon(sdata, params, &changed); 3184 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3105 if (err) { 3185 if (err) {
3106 ieee80211_vif_unreserve_chanctx(sdata); 3186 ieee80211_vif_unreserve_chanctx(sdata);
@@ -3521,6 +3601,76 @@ static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3521 return ret; 3601 return ret;
3522} 3602}
3523 3603
3604static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3605 u8 tsid, const u8 *peer, u8 up,
3606 u16 admitted_time)
3607{
3608 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3609 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3610 int ac = ieee802_1d_to_ac[up];
3611
3612 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3613 return -EOPNOTSUPP;
3614
3615 if (!(sdata->wmm_acm & BIT(up)))
3616 return -EINVAL;
3617
3618 if (ifmgd->tx_tspec[ac].admitted_time)
3619 return -EBUSY;
3620
3621 if (admitted_time) {
3622 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3623 ifmgd->tx_tspec[ac].tsid = tsid;
3624 ifmgd->tx_tspec[ac].up = up;
3625 }
3626
3627 return 0;
3628}
3629
3630static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3631 u8 tsid, const u8 *peer)
3632{
3633 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3634 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3635 struct ieee80211_local *local = wiphy_priv(wiphy);
3636 int ac;
3637
3638 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3639 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3640
3641 /* skip unused entries */
3642 if (!tx_tspec->admitted_time)
3643 continue;
3644
3645 if (tx_tspec->tsid != tsid)
3646 continue;
3647
3648 /* due to this new packets will be reassigned to non-ACM ACs */
3649 tx_tspec->up = -1;
3650
3651 /* Make sure that all packets have been sent to avoid to
3652 * restore the QoS params on packets that are still on the
3653 * queues.
3654 */
3655 synchronize_net();
3656 ieee80211_flush_queues(local, sdata);
3657
3658 /* restore the normal QoS parameters
3659 * (unconditionally to avoid races)
3660 */
3661 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3662 tx_tspec->downgraded = false;
3663 ieee80211_sta_handle_tspec_ac_params(sdata);
3664
3665 /* finally clear all the data */
3666 memset(tx_tspec, 0, sizeof(*tx_tspec));
3667
3668 return 0;
3669 }
3670
3671 return -ENOENT;
3672}
3673
3524const struct cfg80211_ops mac80211_config_ops = { 3674const struct cfg80211_ops mac80211_config_ops = {
3525 .add_virtual_intf = ieee80211_add_iface, 3675 .add_virtual_intf = ieee80211_add_iface,
3526 .del_virtual_intf = ieee80211_del_iface, 3676 .del_virtual_intf = ieee80211_del_iface,
@@ -3547,11 +3697,15 @@ const struct cfg80211_ops mac80211_config_ops = {
3547 .change_mpath = ieee80211_change_mpath, 3697 .change_mpath = ieee80211_change_mpath,
3548 .get_mpath = ieee80211_get_mpath, 3698 .get_mpath = ieee80211_get_mpath,
3549 .dump_mpath = ieee80211_dump_mpath, 3699 .dump_mpath = ieee80211_dump_mpath,
3700 .get_mpp = ieee80211_get_mpp,
3701 .dump_mpp = ieee80211_dump_mpp,
3550 .update_mesh_config = ieee80211_update_mesh_config, 3702 .update_mesh_config = ieee80211_update_mesh_config,
3551 .get_mesh_config = ieee80211_get_mesh_config, 3703 .get_mesh_config = ieee80211_get_mesh_config,
3552 .join_mesh = ieee80211_join_mesh, 3704 .join_mesh = ieee80211_join_mesh,
3553 .leave_mesh = ieee80211_leave_mesh, 3705 .leave_mesh = ieee80211_leave_mesh,
3554#endif 3706#endif
3707 .join_ocb = ieee80211_join_ocb,
3708 .leave_ocb = ieee80211_leave_ocb,
3555 .change_bss = ieee80211_change_bss, 3709 .change_bss = ieee80211_change_bss,
3556 .set_txq_params = ieee80211_set_txq_params, 3710 .set_txq_params = ieee80211_set_txq_params,
3557 .set_monitor_channel = ieee80211_set_monitor_channel, 3711 .set_monitor_channel = ieee80211_set_monitor_channel,
@@ -3597,4 +3751,6 @@ const struct cfg80211_ops mac80211_config_ops = {
3597 .channel_switch = ieee80211_channel_switch, 3751 .channel_switch = ieee80211_channel_switch,
3598 .set_qos_map = ieee80211_set_qos_map, 3752 .set_qos_map = ieee80211_set_qos_map,
3599 .set_ap_chanwidth = ieee80211_set_ap_chanwidth, 3753 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
3754 .add_tx_ts = ieee80211_add_tx_ts,
3755 .del_tx_ts = ieee80211_del_tx_ts,
3600}; 3756};
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 4c74e8da64b9..c7c514220298 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -270,6 +270,7 @@ ieee80211_get_chanctx_max_required_bw(struct ieee80211_local *local,
270 case NL80211_IFTYPE_ADHOC: 270 case NL80211_IFTYPE_ADHOC:
271 case NL80211_IFTYPE_WDS: 271 case NL80211_IFTYPE_WDS:
272 case NL80211_IFTYPE_MESH_POINT: 272 case NL80211_IFTYPE_MESH_POINT:
273 case NL80211_IFTYPE_OCB:
273 width = vif->bss_conf.chandef.width; 274 width = vif->bss_conf.chandef.width;
274 break; 275 break;
275 case NL80211_IFTYPE_UNSPECIFIED: 276 case NL80211_IFTYPE_UNSPECIFIED:
@@ -674,6 +675,7 @@ void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
674 case NL80211_IFTYPE_ADHOC: 675 case NL80211_IFTYPE_ADHOC:
675 case NL80211_IFTYPE_WDS: 676 case NL80211_IFTYPE_WDS:
676 case NL80211_IFTYPE_MESH_POINT: 677 case NL80211_IFTYPE_MESH_POINT:
678 case NL80211_IFTYPE_OCB:
677 break; 679 break;
678 default: 680 default:
679 WARN_ON_ONCE(1); 681 WARN_ON_ONCE(1);
@@ -909,6 +911,7 @@ ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata)
909 case NL80211_IFTYPE_ADHOC: 911 case NL80211_IFTYPE_ADHOC:
910 case NL80211_IFTYPE_AP: 912 case NL80211_IFTYPE_AP:
911 case NL80211_IFTYPE_MESH_POINT: 913 case NL80211_IFTYPE_MESH_POINT:
914 case NL80211_IFTYPE_OCB:
912 ieee80211_queue_work(&sdata->local->hw, 915 ieee80211_queue_work(&sdata->local->hw,
913 &sdata->csa_finalize_work); 916 &sdata->csa_finalize_work);
914 break; 917 break;
@@ -1634,7 +1637,7 @@ int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
1634 } 1637 }
1635 break; 1638 break;
1636 case IEEE80211_CHANCTX_WILL_BE_REPLACED: 1639 case IEEE80211_CHANCTX_WILL_BE_REPLACED:
1637 /* TODO: Perhaps the bandwith change could be treated as a 1640 /* TODO: Perhaps the bandwidth change could be treated as a
1638 * reservation itself? */ 1641 * reservation itself? */
1639 ret = -EBUSY; 1642 ret = -EBUSY;
1640 goto out; 1643 goto out;
diff --git a/net/mac80211/debug.h b/net/mac80211/debug.h
index 493d68061f0c..1956b3115dd5 100644
--- a/net/mac80211/debug.h
+++ b/net/mac80211/debug.h
@@ -2,6 +2,12 @@
2#define __MAC80211_DEBUG_H 2#define __MAC80211_DEBUG_H
3#include <net/cfg80211.h> 3#include <net/cfg80211.h>
4 4
5#ifdef CONFIG_MAC80211_OCB_DEBUG
6#define MAC80211_OCB_DEBUG 1
7#else
8#define MAC80211_OCB_DEBUG 0
9#endif
10
5#ifdef CONFIG_MAC80211_IBSS_DEBUG 11#ifdef CONFIG_MAC80211_IBSS_DEBUG
6#define MAC80211_IBSS_DEBUG 1 12#define MAC80211_IBSS_DEBUG 1
7#else 13#else
@@ -131,6 +137,10 @@ do { \
131 _sdata_dbg(MAC80211_HT_DEBUG && net_ratelimit(), \ 137 _sdata_dbg(MAC80211_HT_DEBUG && net_ratelimit(), \
132 sdata, fmt, ##__VA_ARGS__) 138 sdata, fmt, ##__VA_ARGS__)
133 139
140#define ocb_dbg(sdata, fmt, ...) \
141 _sdata_dbg(MAC80211_OCB_DEBUG, \
142 sdata, fmt, ##__VA_ARGS__)
143
134#define ibss_dbg(sdata, fmt, ...) \ 144#define ibss_dbg(sdata, fmt, ...) \
135 _sdata_dbg(MAC80211_IBSS_DEBUG, \ 145 _sdata_dbg(MAC80211_IBSS_DEBUG, \
136 sdata, fmt, ##__VA_ARGS__) 146 sdata, fmt, ##__VA_ARGS__)
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index 1521cabad3d6..5523b94c7c90 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -300,10 +300,8 @@ void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
300 300
301 lockdep_assert_held(&sdata->local->key_mtx); 301 lockdep_assert_held(&sdata->local->key_mtx);
302 302
303 if (sdata->debugfs.default_unicast_key) { 303 debugfs_remove(sdata->debugfs.default_unicast_key);
304 debugfs_remove(sdata->debugfs.default_unicast_key); 304 sdata->debugfs.default_unicast_key = NULL;
305 sdata->debugfs.default_unicast_key = NULL;
306 }
307 305
308 if (sdata->default_unicast_key) { 306 if (sdata->default_unicast_key) {
309 key = key_mtx_dereference(sdata->local, 307 key = key_mtx_dereference(sdata->local,
@@ -314,10 +312,8 @@ void ieee80211_debugfs_key_update_default(struct ieee80211_sub_if_data *sdata)
314 sdata->vif.debugfs_dir, buf); 312 sdata->vif.debugfs_dir, buf);
315 } 313 }
316 314
317 if (sdata->debugfs.default_multicast_key) { 315 debugfs_remove(sdata->debugfs.default_multicast_key);
318 debugfs_remove(sdata->debugfs.default_multicast_key); 316 sdata->debugfs.default_multicast_key = NULL;
319 sdata->debugfs.default_multicast_key = NULL;
320 }
321 317
322 if (sdata->default_multicast_key) { 318 if (sdata->default_multicast_key) {
323 key = key_mtx_dereference(sdata->local, 319 key = key_mtx_dereference(sdata->local,
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 196d48c68134..9759dd1f0734 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -214,7 +214,8 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
214 BSS_CHANGED_BEACON_ENABLED) && 214 BSS_CHANGED_BEACON_ENABLED) &&
215 sdata->vif.type != NL80211_IFTYPE_AP && 215 sdata->vif.type != NL80211_IFTYPE_AP &&
216 sdata->vif.type != NL80211_IFTYPE_ADHOC && 216 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
217 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)) 217 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
218 sdata->vif.type != NL80211_IFTYPE_OCB))
218 return; 219 return;
219 220
220 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE || 221 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
@@ -631,6 +632,12 @@ static inline int drv_conf_tx(struct ieee80211_local *local,
631 if (!check_sdata_in_driver(sdata)) 632 if (!check_sdata_in_driver(sdata))
632 return -EIO; 633 return -EIO;
633 634
635 if (WARN_ONCE(params->cw_min == 0 ||
636 params->cw_min > params->cw_max,
637 "%s: invalid CW_min/CW_max: %d/%d\n",
638 sdata->name, params->cw_min, params->cw_max))
639 return -EINVAL;
640
634 trace_drv_conf_tx(local, sdata, ac, params); 641 trace_drv_conf_tx(local, sdata, ac, params);
635 if (local->ops->conf_tx) 642 if (local->ops->conf_tx)
636 ret = local->ops->conf_tx(&local->hw, &sdata->vif, 643 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
@@ -764,12 +771,13 @@ static inline void drv_flush(struct ieee80211_local *local,
764} 771}
765 772
766static inline void drv_channel_switch(struct ieee80211_local *local, 773static inline void drv_channel_switch(struct ieee80211_local *local,
767 struct ieee80211_channel_switch *ch_switch) 774 struct ieee80211_sub_if_data *sdata,
775 struct ieee80211_channel_switch *ch_switch)
768{ 776{
769 might_sleep(); 777 might_sleep();
770 778
771 trace_drv_channel_switch(local, ch_switch); 779 trace_drv_channel_switch(local, sdata, ch_switch);
772 local->ops->channel_switch(&local->hw, ch_switch); 780 local->ops->channel_switch(&local->hw, &sdata->vif, ch_switch);
773 trace_drv_return_void(local); 781 trace_drv_return_void(local);
774} 782}
775 783
@@ -1144,13 +1152,15 @@ static inline void drv_stop_ap(struct ieee80211_local *local,
1144 trace_drv_return_void(local); 1152 trace_drv_return_void(local);
1145} 1153}
1146 1154
1147static inline void drv_restart_complete(struct ieee80211_local *local) 1155static inline void
1156drv_reconfig_complete(struct ieee80211_local *local,
1157 enum ieee80211_reconfig_type reconfig_type)
1148{ 1158{
1149 might_sleep(); 1159 might_sleep();
1150 1160
1151 trace_drv_restart_complete(local); 1161 trace_drv_reconfig_complete(local, reconfig_type);
1152 if (local->ops->restart_complete) 1162 if (local->ops->reconfig_complete)
1153 local->ops->restart_complete(&local->hw); 1163 local->ops->reconfig_complete(&local->hw, reconfig_type);
1154 trace_drv_return_void(local); 1164 trace_drv_return_void(local);
1155} 1165}
1156 1166
@@ -1196,6 +1206,40 @@ drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
1196 } 1206 }
1197} 1207}
1198 1208
1209static inline int
1210drv_pre_channel_switch(struct ieee80211_sub_if_data *sdata,
1211 struct ieee80211_channel_switch *ch_switch)
1212{
1213 struct ieee80211_local *local = sdata->local;
1214 int ret = 0;
1215
1216 if (!check_sdata_in_driver(sdata))
1217 return -EIO;
1218
1219 trace_drv_pre_channel_switch(local, sdata, ch_switch);
1220 if (local->ops->pre_channel_switch)
1221 ret = local->ops->pre_channel_switch(&local->hw, &sdata->vif,
1222 ch_switch);
1223 trace_drv_return_int(local, ret);
1224 return ret;
1225}
1226
1227static inline int
1228drv_post_channel_switch(struct ieee80211_sub_if_data *sdata)
1229{
1230 struct ieee80211_local *local = sdata->local;
1231 int ret = 0;
1232
1233 if (!check_sdata_in_driver(sdata))
1234 return -EIO;
1235
1236 trace_drv_post_channel_switch(local, sdata);
1237 if (local->ops->post_channel_switch)
1238 ret = local->ops->post_channel_switch(&local->hw, &sdata->vif);
1239 trace_drv_return_int(local, ret);
1240 return ret;
1241}
1242
1199static inline int drv_join_ibss(struct ieee80211_local *local, 1243static inline int drv_join_ibss(struct ieee80211_local *local,
1200 struct ieee80211_sub_if_data *sdata) 1244 struct ieee80211_sub_if_data *sdata)
1201{ 1245{
@@ -1238,4 +1282,18 @@ static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1238 return ret; 1282 return ret;
1239} 1283}
1240 1284
1285static inline int drv_get_txpower(struct ieee80211_local *local,
1286 struct ieee80211_sub_if_data *sdata, int *dbm)
1287{
1288 int ret;
1289
1290 if (!local->ops->get_txpower)
1291 return -EOPNOTSUPP;
1292
1293 ret = local->ops->get_txpower(&local->hw, &sdata->vif, dbm);
1294 trace_drv_get_txpower(local, sdata, *dbm, ret);
1295
1296 return ret;
1297}
1298
1241#endif /* __MAC80211_DRIVER_OPS */ 1299#endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 8c68da30595d..842e0661fb57 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -131,7 +131,7 @@ enum ieee80211_bss_corrupt_data_flags {
131 * 131 *
132 * These are bss flags that are attached to a bss in the 132 * These are bss flags that are attached to a bss in the
133 * @valid_data field of &struct ieee80211_bss. They show which parts 133 * @valid_data field of &struct ieee80211_bss. They show which parts
134 * of the data structure were recieved as a result of an un-corrupted 134 * of the data structure were received as a result of an un-corrupted
135 * beacon/probe response. 135 * beacon/probe response.
136 */ 136 */
137enum ieee80211_bss_valid_data_flags { 137enum ieee80211_bss_valid_data_flags {
@@ -399,6 +399,24 @@ struct ieee80211_mgd_assoc_data {
399 u8 ie[]; 399 u8 ie[];
400}; 400};
401 401
402struct ieee80211_sta_tx_tspec {
403 /* timestamp of the first packet in the time slice */
404 unsigned long time_slice_start;
405
406 u32 admitted_time; /* in usecs, unlike over the air */
407 u8 tsid;
408 s8 up; /* signed to be able to invalidate with -1 during teardown */
409
410 /* consumed TX time in microseconds in the time slice */
411 u32 consumed_tx_time;
412 enum {
413 TX_TSPEC_ACTION_NONE = 0,
414 TX_TSPEC_ACTION_DOWNGRADE,
415 TX_TSPEC_ACTION_STOP_DOWNGRADE,
416 } action;
417 bool downgraded;
418};
419
402struct ieee80211_if_managed { 420struct ieee80211_if_managed {
403 struct timer_list timer; 421 struct timer_list timer;
404 struct timer_list conn_mon_timer; 422 struct timer_list conn_mon_timer;
@@ -434,6 +452,8 @@ struct ieee80211_if_managed {
434 452
435 unsigned int flags; 453 unsigned int flags;
436 454
455 bool csa_waiting_bcn;
456
437 bool beacon_crc_valid; 457 bool beacon_crc_valid;
438 u32 beacon_crc; 458 u32 beacon_crc;
439 459
@@ -507,6 +527,16 @@ struct ieee80211_if_managed {
507 527
508 u8 tdls_peer[ETH_ALEN] __aligned(2); 528 u8 tdls_peer[ETH_ALEN] __aligned(2);
509 struct delayed_work tdls_peer_del_work; 529 struct delayed_work tdls_peer_del_work;
530
531 /* WMM-AC TSPEC support */
532 struct ieee80211_sta_tx_tspec tx_tspec[IEEE80211_NUM_ACS];
533 /* Use a separate work struct so that we can do something here
534 * while the sdata->work is flushing the queues, for example.
535 * otherwise, in scenarios where we hardly get any traffic out
536 * on the BE queue, but there's a lot of VO traffic, we might
537 * get stuck in a downgraded situation and flush takes forever.
538 */
539 struct delayed_work tx_tspec_wk;
510}; 540};
511 541
512struct ieee80211_if_ibss { 542struct ieee80211_if_ibss {
@@ -547,6 +577,25 @@ struct ieee80211_if_ibss {
547}; 577};
548 578
549/** 579/**
580 * struct ieee80211_if_ocb - OCB mode state
581 *
582 * @housekeeping_timer: timer for periodic invocation of a housekeeping task
583 * @wrkq_flags: OCB deferred task action
584 * @incomplete_lock: delayed STA insertion lock
585 * @incomplete_stations: list of STAs waiting for delayed insertion
586 * @joined: indication if the interface is connected to an OCB network
587 */
588struct ieee80211_if_ocb {
589 struct timer_list housekeeping_timer;
590 unsigned long wrkq_flags;
591
592 spinlock_t incomplete_lock;
593 struct list_head incomplete_stations;
594
595 bool joined;
596};
597
598/**
550 * struct ieee80211_mesh_sync_ops - Extensible synchronization framework interface 599 * struct ieee80211_mesh_sync_ops - Extensible synchronization framework interface
551 * 600 *
552 * these declarations define the interface, which enables 601 * these declarations define the interface, which enables
@@ -839,6 +888,7 @@ struct ieee80211_sub_if_data {
839 struct ieee80211_if_managed mgd; 888 struct ieee80211_if_managed mgd;
840 struct ieee80211_if_ibss ibss; 889 struct ieee80211_if_ibss ibss;
841 struct ieee80211_if_mesh mesh; 890 struct ieee80211_if_mesh mesh;
891 struct ieee80211_if_ocb ocb;
842 u32 mntr_flags; 892 u32 mntr_flags;
843 } u; 893 } u;
844 894
@@ -1307,6 +1357,9 @@ struct ieee80211_local {
1307 /* virtual monitor interface */ 1357 /* virtual monitor interface */
1308 struct ieee80211_sub_if_data __rcu *monitor_sdata; 1358 struct ieee80211_sub_if_data __rcu *monitor_sdata;
1309 struct cfg80211_chan_def monitor_chandef; 1359 struct cfg80211_chan_def monitor_chandef;
1360
1361 /* extended capabilities provided by mac80211 */
1362 u8 ext_capa[8];
1310}; 1363};
1311 1364
1312static inline struct ieee80211_sub_if_data * 1365static inline struct ieee80211_sub_if_data *
@@ -1454,6 +1507,7 @@ void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
1454 __le16 fc, bool acked); 1507 __le16 fc, bool acked);
1455void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata); 1508void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata);
1456void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata); 1509void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata);
1510void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata);
1457 1511
1458/* IBSS code */ 1512/* IBSS code */
1459void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local); 1513void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
@@ -1471,6 +1525,15 @@ int ieee80211_ibss_csa_beacon(struct ieee80211_sub_if_data *sdata,
1471int ieee80211_ibss_finish_csa(struct ieee80211_sub_if_data *sdata); 1525int ieee80211_ibss_finish_csa(struct ieee80211_sub_if_data *sdata);
1472void ieee80211_ibss_stop(struct ieee80211_sub_if_data *sdata); 1526void ieee80211_ibss_stop(struct ieee80211_sub_if_data *sdata);
1473 1527
1528/* OCB code */
1529void ieee80211_ocb_work(struct ieee80211_sub_if_data *sdata);
1530void ieee80211_ocb_rx_no_sta(struct ieee80211_sub_if_data *sdata,
1531 const u8 *bssid, const u8 *addr, u32 supp_rates);
1532void ieee80211_ocb_setup_sdata(struct ieee80211_sub_if_data *sdata);
1533int ieee80211_ocb_join(struct ieee80211_sub_if_data *sdata,
1534 struct ocb_setup *setup);
1535int ieee80211_ocb_leave(struct ieee80211_sub_if_data *sdata);
1536
1474/* mesh code */ 1537/* mesh code */
1475void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata); 1538void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata);
1476void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 1539void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
@@ -1757,6 +1820,13 @@ static inline bool ieee80211_rx_reorder_ready(struct sk_buff_head *frames)
1757 return true; 1820 return true;
1758} 1821}
1759 1822
1823extern const int ieee802_1d_to_ac[8];
1824
1825static inline int ieee80211_ac_from_tid(int tid)
1826{
1827 return ieee802_1d_to_ac[tid & 7];
1828}
1829
1760void ieee80211_dynamic_ps_enable_work(struct work_struct *work); 1830void ieee80211_dynamic_ps_enable_work(struct work_struct *work);
1761void ieee80211_dynamic_ps_disable_work(struct work_struct *work); 1831void ieee80211_dynamic_ps_disable_work(struct work_struct *work);
1762void ieee80211_dynamic_ps_timer(unsigned long data); 1832void ieee80211_dynamic_ps_timer(unsigned long data);
@@ -1766,7 +1836,7 @@ void ieee80211_send_nullfunc(struct ieee80211_local *local,
1766void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, 1836void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1767 struct ieee80211_hdr *hdr); 1837 struct ieee80211_hdr *hdr);
1768void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, 1838void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
1769 struct ieee80211_hdr *hdr, bool ack); 1839 struct ieee80211_hdr *hdr, bool ack, u16 tx_time);
1770 1840
1771void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, 1841void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
1772 unsigned long queues, 1842 unsigned long queues,
@@ -1832,8 +1902,10 @@ int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
1832void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata); 1902void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata);
1833void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata); 1903void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata);
1834 1904
1835size_t ieee80211_ie_split(const u8 *ies, size_t ielen, 1905size_t ieee80211_ie_split_ric(const u8 *ies, size_t ielen,
1836 const u8 *ids, int n_ids, size_t offset); 1906 const u8 *ids, int n_ids,
1907 const u8 *after_ric, int n_after_ric,
1908 size_t offset);
1837size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset); 1909size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset);
1838u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap, 1910u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
1839 u16 cap); 1911 u16 cap);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 653f5eb07a27..9df26adb864a 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -259,6 +259,15 @@ static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
259 list_for_each_entry(nsdata, &local->interfaces, list) { 259 list_for_each_entry(nsdata, &local->interfaces, list) {
260 if (nsdata != sdata && ieee80211_sdata_running(nsdata)) { 260 if (nsdata != sdata && ieee80211_sdata_running(nsdata)) {
261 /* 261 /*
262 * Only OCB and monitor mode may coexist
263 */
264 if ((sdata->vif.type == NL80211_IFTYPE_OCB &&
265 nsdata->vif.type != NL80211_IFTYPE_MONITOR) ||
266 (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
267 nsdata->vif.type == NL80211_IFTYPE_OCB))
268 return -EBUSY;
269
270 /*
262 * Allow only a single IBSS interface to be up at any 271 * Allow only a single IBSS interface to be up at any
263 * time. This is restricted because beacon distribution 272 * time. This is restricted because beacon distribution
264 * cannot work properly if both are in the same IBSS. 273 * cannot work properly if both are in the same IBSS.
@@ -521,6 +530,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
521 case NL80211_IFTYPE_MONITOR: 530 case NL80211_IFTYPE_MONITOR:
522 case NL80211_IFTYPE_ADHOC: 531 case NL80211_IFTYPE_ADHOC:
523 case NL80211_IFTYPE_P2P_DEVICE: 532 case NL80211_IFTYPE_P2P_DEVICE:
533 case NL80211_IFTYPE_OCB:
524 /* no special treatment */ 534 /* no special treatment */
525 break; 535 break;
526 case NL80211_IFTYPE_UNSPECIFIED: 536 case NL80211_IFTYPE_UNSPECIFIED:
@@ -631,6 +641,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
631 case NL80211_IFTYPE_ADHOC: 641 case NL80211_IFTYPE_ADHOC:
632 case NL80211_IFTYPE_AP: 642 case NL80211_IFTYPE_AP:
633 case NL80211_IFTYPE_MESH_POINT: 643 case NL80211_IFTYPE_MESH_POINT:
644 case NL80211_IFTYPE_OCB:
634 netif_carrier_off(dev); 645 netif_carrier_off(dev);
635 break; 646 break;
636 case NL80211_IFTYPE_WDS: 647 case NL80211_IFTYPE_WDS:
@@ -844,6 +855,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
844 sdata_lock(sdata); 855 sdata_lock(sdata);
845 mutex_lock(&local->mtx); 856 mutex_lock(&local->mtx);
846 sdata->vif.csa_active = false; 857 sdata->vif.csa_active = false;
858 if (sdata->vif.type == NL80211_IFTYPE_STATION)
859 sdata->u.mgd.csa_waiting_bcn = false;
847 if (sdata->csa_block_tx) { 860 if (sdata->csa_block_tx) {
848 ieee80211_wake_vif_queues(local, sdata, 861 ieee80211_wake_vif_queues(local, sdata,
849 IEEE80211_QUEUE_STOP_REASON_CSA); 862 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -1285,6 +1298,9 @@ static void ieee80211_iface_work(struct work_struct *work)
1285 break; 1298 break;
1286 ieee80211_mesh_work(sdata); 1299 ieee80211_mesh_work(sdata);
1287 break; 1300 break;
1301 case NL80211_IFTYPE_OCB:
1302 ieee80211_ocb_work(sdata);
1303 break;
1288 default: 1304 default:
1289 break; 1305 break;
1290 } 1306 }
@@ -1304,6 +1320,9 @@ static void ieee80211_recalc_smps_work(struct work_struct *work)
1304static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, 1320static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1305 enum nl80211_iftype type) 1321 enum nl80211_iftype type)
1306{ 1322{
1323 static const u8 bssid_wildcard[ETH_ALEN] = {0xff, 0xff, 0xff,
1324 0xff, 0xff, 0xff};
1325
1307 /* clear type-dependent union */ 1326 /* clear type-dependent union */
1308 memset(&sdata->u, 0, sizeof(sdata->u)); 1327 memset(&sdata->u, 0, sizeof(sdata->u));
1309 1328
@@ -1355,6 +1374,10 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1355 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid; 1374 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
1356 ieee80211_sta_setup_sdata(sdata); 1375 ieee80211_sta_setup_sdata(sdata);
1357 break; 1376 break;
1377 case NL80211_IFTYPE_OCB:
1378 sdata->vif.bss_conf.bssid = bssid_wildcard;
1379 ieee80211_ocb_setup_sdata(sdata);
1380 break;
1358 case NL80211_IFTYPE_ADHOC: 1381 case NL80211_IFTYPE_ADHOC:
1359 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid; 1382 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
1360 ieee80211_ibss_setup_sdata(sdata); 1383 ieee80211_ibss_setup_sdata(sdata);
@@ -1402,6 +1425,7 @@ static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
1402 case NL80211_IFTYPE_AP: 1425 case NL80211_IFTYPE_AP:
1403 case NL80211_IFTYPE_STATION: 1426 case NL80211_IFTYPE_STATION:
1404 case NL80211_IFTYPE_ADHOC: 1427 case NL80211_IFTYPE_ADHOC:
1428 case NL80211_IFTYPE_OCB:
1405 /* 1429 /*
1406 * Could maybe also all others here? 1430 * Could maybe also all others here?
1407 * Just not sure how that interacts 1431 * Just not sure how that interacts
@@ -1417,6 +1441,7 @@ static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
1417 case NL80211_IFTYPE_AP: 1441 case NL80211_IFTYPE_AP:
1418 case NL80211_IFTYPE_STATION: 1442 case NL80211_IFTYPE_STATION:
1419 case NL80211_IFTYPE_ADHOC: 1443 case NL80211_IFTYPE_ADHOC:
1444 case NL80211_IFTYPE_OCB:
1420 /* 1445 /*
1421 * Could probably support everything 1446 * Could probably support everything
1422 * but WDS here (WDS do_open can fail 1447 * but WDS here (WDS do_open can fail
@@ -1675,7 +1700,10 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1675 } 1700 }
1676 1701
1677 ieee80211_assign_perm_addr(local, ndev->perm_addr, type); 1702 ieee80211_assign_perm_addr(local, ndev->perm_addr, type);
1678 memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN); 1703 if (params && is_valid_ether_addr(params->macaddr))
1704 memcpy(ndev->dev_addr, params->macaddr, ETH_ALEN);
1705 else
1706 memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN);
1679 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); 1707 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
1680 1708
1681 /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */ 1709 /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 4712150dc210..434a91ad12c8 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -94,8 +94,17 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
94 94
95 might_sleep(); 95 might_sleep();
96 96
97 if (key->flags & KEY_FLAG_TAINTED) 97 if (key->flags & KEY_FLAG_TAINTED) {
98 /* If we get here, it's during resume and the key is
99 * tainted so shouldn't be used/programmed any more.
100 * However, its flags may still indicate that it was
101 * programmed into the device (since we're in resume)
102 * so clear that flag now to avoid trying to remove
103 * it again later.
104 */
105 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
98 return -EINVAL; 106 return -EINVAL;
107 }
99 108
100 if (!key->local->ops->set_key) 109 if (!key->local->ops->set_key)
101 goto out_unsupported; 110 goto out_unsupported;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 0de7c93bf62b..282a4f36eb92 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -478,13 +478,9 @@ static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
478 }, 478 },
479}; 479};
480 480
481static const u8 extended_capabilities[] = { 481struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
482 0, 0, 0, 0, 0, 0, 0, 482 const struct ieee80211_ops *ops,
483 WLAN_EXT_CAPA8_OPMODE_NOTIF, 483 const char *requested_name)
484};
485
486struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
487 const struct ieee80211_ops *ops)
488{ 484{
489 struct ieee80211_local *local; 485 struct ieee80211_local *local;
490 int priv_size, i; 486 int priv_size, i;
@@ -524,7 +520,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
524 */ 520 */
525 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len; 521 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
526 522
527 wiphy = wiphy_new(&mac80211_config_ops, priv_size); 523 wiphy = wiphy_new_nm(&mac80211_config_ops, priv_size, requested_name);
528 524
529 if (!wiphy) 525 if (!wiphy)
530 return NULL; 526 return NULL;
@@ -539,10 +535,6 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
539 WIPHY_FLAG_REPORTS_OBSS | 535 WIPHY_FLAG_REPORTS_OBSS |
540 WIPHY_FLAG_OFFCHAN_TX; 536 WIPHY_FLAG_OFFCHAN_TX;
541 537
542 wiphy->extended_capabilities = extended_capabilities;
543 wiphy->extended_capabilities_mask = extended_capabilities;
544 wiphy->extended_capabilities_len = ARRAY_SIZE(extended_capabilities);
545
546 if (ops->remain_on_channel) 538 if (ops->remain_on_channel)
547 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 539 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
548 540
@@ -550,6 +542,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
550 NL80211_FEATURE_SAE | 542 NL80211_FEATURE_SAE |
551 NL80211_FEATURE_HT_IBSS | 543 NL80211_FEATURE_HT_IBSS |
552 NL80211_FEATURE_VIF_TXPOWER | 544 NL80211_FEATURE_VIF_TXPOWER |
545 NL80211_FEATURE_MAC_ON_CREATE |
553 NL80211_FEATURE_USERSPACE_MPM; 546 NL80211_FEATURE_USERSPACE_MPM;
554 547
555 if (!ops->hw_scan) 548 if (!ops->hw_scan)
@@ -591,6 +584,13 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
591 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask; 584 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
592 wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask; 585 wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
593 586
587 local->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
588
589 wiphy->extended_capabilities = local->ext_capa;
590 wiphy->extended_capabilities_mask = local->ext_capa;
591 wiphy->extended_capabilities_len =
592 ARRAY_SIZE(local->ext_capa);
593
594 INIT_LIST_HEAD(&local->interfaces); 594 INIT_LIST_HEAD(&local->interfaces);
595 595
596 __hw_addr_init(&local->mc_list); 596 __hw_addr_init(&local->mc_list);
@@ -651,7 +651,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
651 651
652 return &local->hw; 652 return &local->hw;
653} 653}
654EXPORT_SYMBOL(ieee80211_alloc_hw); 654EXPORT_SYMBOL(ieee80211_alloc_hw_nm);
655 655
656static int ieee80211_init_cipher_suites(struct ieee80211_local *local) 656static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
657{ 657{
@@ -787,13 +787,14 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
787 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS)) 787 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
788 return -EINVAL; 788 return -EINVAL;
789 789
790 /* DFS currently not supported with channel context drivers */ 790 /* DFS is not supported with multi-channel combinations yet */
791 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) { 791 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
792 const struct ieee80211_iface_combination *comb; 792 const struct ieee80211_iface_combination *comb;
793 793
794 comb = &local->hw.wiphy->iface_combinations[i]; 794 comb = &local->hw.wiphy->iface_combinations[i];
795 795
796 if (comb->radar_detect_widths) 796 if (comb->radar_detect_widths &&
797 comb->num_different_channels > 1)
797 return -EINVAL; 798 return -EINVAL;
798 } 799 }
799 } 800 }
@@ -958,6 +959,10 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
958 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) 959 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
959 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP; 960 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
960 961
962 /* mac80211 supports eCSA, if the driver supports STA CSA at all */
963 if (local->hw.flags & IEEE80211_HW_CHANCTX_STA_CSA)
964 local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
965
961 local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM; 966 local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
962 967
963 result = wiphy_register(local->hw.wiphy); 968 result = wiphy_register(local->hw.wiphy);
@@ -1019,7 +1024,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1019 } 1024 }
1020 1025
1021 /* add one default STA interface if supported */ 1026 /* add one default STA interface if supported */
1022 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) { 1027 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
1028 !(hw->flags & IEEE80211_HW_NO_AUTO_VIF)) {
1023 result = ieee80211_if_add(local, "wlan%d", NULL, 1029 result = ieee80211_if_add(local, "wlan%d", NULL,
1024 NL80211_IFTYPE_STATION, NULL); 1030 NL80211_IFTYPE_STATION, NULL);
1025 if (result) 1031 if (result)
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index f39a19f9090f..50c8473cf9dc 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -270,6 +270,8 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
270 const u8 *dst, const u8 *mpp); 270 const u8 *dst, const u8 *mpp);
271struct mesh_path * 271struct mesh_path *
272mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx); 272mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
273struct mesh_path *
274mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx);
273void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop); 275void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
274void mesh_path_expire(struct ieee80211_sub_if_data *sdata); 276void mesh_path_expire(struct ieee80211_sub_if_data *sdata);
275void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata, 277void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
@@ -317,6 +319,7 @@ void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
317 319
318bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt); 320bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
319extern int mesh_paths_generation; 321extern int mesh_paths_generation;
322extern int mpp_paths_generation;
320 323
321#ifdef CONFIG_MAC80211_MESH 324#ifdef CONFIG_MAC80211_MESH
322static inline 325static inline
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index a6699dceae7c..b890e225a8f1 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -44,6 +44,7 @@ static struct mesh_table __rcu *mesh_paths;
44static struct mesh_table __rcu *mpp_paths; /* Store paths for MPP&MAP */ 44static struct mesh_table __rcu *mpp_paths; /* Store paths for MPP&MAP */
45 45
46int mesh_paths_generation; 46int mesh_paths_generation;
47int mpp_paths_generation;
47 48
48/* This lock will have the grow table function as writer and add / delete nodes 49/* This lock will have the grow table function as writer and add / delete nodes
49 * as readers. RCU provides sufficient protection only when reading the table 50 * as readers. RCU provides sufficient protection only when reading the table
@@ -410,6 +411,33 @@ mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
410} 411}
411 412
412/** 413/**
414 * mpp_path_lookup_by_idx - look up a path in the proxy path table by its index
415 * @idx: index
416 * @sdata: local subif, or NULL for all entries
417 *
418 * Returns: pointer to the proxy path structure, or NULL if not found.
419 *
420 * Locking: must be called within a read rcu section.
421 */
422struct mesh_path *
423mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
424{
425 struct mesh_table *tbl = rcu_dereference(mpp_paths);
426 struct mpath_node *node;
427 int i;
428 int j = 0;
429
430 for_each_mesh_entry(tbl, node, i) {
431 if (sdata && node->mpath->sdata != sdata)
432 continue;
433 if (j++ == idx)
434 return node->mpath;
435 }
436
437 return NULL;
438}
439
440/**
413 * mesh_path_add_gate - add the given mpath to a mesh gate to our path table 441 * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
414 * @mpath: gate path to add to table 442 * @mpath: gate path to add to table
415 */ 443 */
@@ -691,6 +719,9 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
691 719
692 spin_unlock(&tbl->hashwlock[hash_idx]); 720 spin_unlock(&tbl->hashwlock[hash_idx]);
693 read_unlock_bh(&pathtbl_resize_lock); 721 read_unlock_bh(&pathtbl_resize_lock);
722
723 mpp_paths_generation++;
724
694 if (grow) { 725 if (grow) {
695 set_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags); 726 set_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags);
696 ieee80211_queue_work(&local->hw, &sdata->work); 727 ieee80211_queue_work(&local->hw, &sdata->work);
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 93af0f1c9d99..0d166e766dad 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -775,11 +775,30 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
775 WLAN_EID_QOS_CAPA, 775 WLAN_EID_QOS_CAPA,
776 WLAN_EID_RRM_ENABLED_CAPABILITIES, 776 WLAN_EID_RRM_ENABLED_CAPABILITIES,
777 WLAN_EID_MOBILITY_DOMAIN, 777 WLAN_EID_MOBILITY_DOMAIN,
778 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
779 WLAN_EID_RIC_DATA, /* reassoc only */
778 WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 780 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
779 }; 781 };
780 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, 782 static const u8 after_ric[] = {
781 before_ht, ARRAY_SIZE(before_ht), 783 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
782 offset); 784 WLAN_EID_HT_CAPABILITY,
785 WLAN_EID_BSS_COEX_2040,
786 WLAN_EID_EXT_CAPABILITY,
787 WLAN_EID_QOS_TRAFFIC_CAPA,
788 WLAN_EID_TIM_BCAST_REQ,
789 WLAN_EID_INTERWORKING,
790 /* 60GHz doesn't happen right now */
791 WLAN_EID_VHT_CAPABILITY,
792 WLAN_EID_OPMODE_NOTIF,
793 };
794
795 noffset = ieee80211_ie_split_ric(assoc_data->ie,
796 assoc_data->ie_len,
797 before_ht,
798 ARRAY_SIZE(before_ht),
799 after_ric,
800 ARRAY_SIZE(after_ric),
801 offset);
783 pos = skb_put(skb, noffset - offset); 802 pos = skb_put(skb, noffset - offset);
784 memcpy(pos, assoc_data->ie + offset, noffset - offset); 803 memcpy(pos, assoc_data->ie + offset, noffset - offset);
785 offset = noffset; 804 offset = noffset;
@@ -813,6 +832,8 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
813 WLAN_EID_TIM_BCAST_REQ, 832 WLAN_EID_TIM_BCAST_REQ,
814 WLAN_EID_INTERWORKING, 833 WLAN_EID_INTERWORKING,
815 }; 834 };
835
836 /* RIC already taken above, so no need to handle here anymore */
816 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, 837 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
817 before_vht, ARRAY_SIZE(before_vht), 838 before_vht, ARRAY_SIZE(before_vht),
818 offset); 839 offset);
@@ -1001,14 +1022,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
1001 /* XXX: shouldn't really modify cfg80211-owned data! */ 1022 /* XXX: shouldn't really modify cfg80211-owned data! */
1002 ifmgd->associated->channel = sdata->csa_chandef.chan; 1023 ifmgd->associated->channel = sdata->csa_chandef.chan;
1003 1024
1004 sdata->vif.csa_active = false; 1025 ifmgd->csa_waiting_bcn = true;
1005
1006 /* XXX: wait for a beacon first? */
1007 if (sdata->csa_block_tx) {
1008 ieee80211_wake_vif_queues(local, sdata,
1009 IEEE80211_QUEUE_STOP_REASON_CSA);
1010 sdata->csa_block_tx = false;
1011 }
1012 1026
1013 ieee80211_sta_reset_beacon_monitor(sdata); 1027 ieee80211_sta_reset_beacon_monitor(sdata);
1014 ieee80211_sta_reset_conn_monitor(sdata); 1028 ieee80211_sta_reset_conn_monitor(sdata);
@@ -1019,6 +1033,35 @@ out:
1019 sdata_unlock(sdata); 1033 sdata_unlock(sdata);
1020} 1034}
1021 1035
1036static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1037{
1038 struct ieee80211_local *local = sdata->local;
1039 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1040 int ret;
1041
1042 sdata_assert_lock(sdata);
1043
1044 WARN_ON(!sdata->vif.csa_active);
1045
1046 if (sdata->csa_block_tx) {
1047 ieee80211_wake_vif_queues(local, sdata,
1048 IEEE80211_QUEUE_STOP_REASON_CSA);
1049 sdata->csa_block_tx = false;
1050 }
1051
1052 sdata->vif.csa_active = false;
1053 ifmgd->csa_waiting_bcn = false;
1054
1055 ret = drv_post_channel_switch(sdata);
1056 if (ret) {
1057 sdata_info(sdata,
1058 "driver post channel switch failed, disconnecting\n");
1059 ieee80211_queue_work(&local->hw,
1060 &ifmgd->csa_connection_drop_work);
1061 return;
1062 }
1063}
1064
1022void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) 1065void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1023{ 1066{
1024 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 1067 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
@@ -1046,7 +1089,8 @@ static void ieee80211_chswitch_timer(unsigned long data)
1046 1089
1047static void 1090static void
1048ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, 1091ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1049 u64 timestamp, struct ieee802_11_elems *elems, 1092 u64 timestamp, u32 device_timestamp,
1093 struct ieee802_11_elems *elems,
1050 bool beacon) 1094 bool beacon)
1051{ 1095{
1052 struct ieee80211_local *local = sdata->local; 1096 struct ieee80211_local *local = sdata->local;
@@ -1056,6 +1100,7 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1056 struct ieee80211_chanctx *chanctx; 1100 struct ieee80211_chanctx *chanctx;
1057 enum ieee80211_band current_band; 1101 enum ieee80211_band current_band;
1058 struct ieee80211_csa_ie csa_ie; 1102 struct ieee80211_csa_ie csa_ie;
1103 struct ieee80211_channel_switch ch_switch;
1059 int res; 1104 int res;
1060 1105
1061 sdata_assert_lock(sdata); 1106 sdata_assert_lock(sdata);
@@ -1110,21 +1155,31 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1110 1155
1111 chanctx = container_of(conf, struct ieee80211_chanctx, conf); 1156 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1112 1157
1113 if (local->use_chanctx) { 1158 if (local->use_chanctx &&
1114 u32 num_chanctx = 0; 1159 !(local->hw.flags & IEEE80211_HW_CHANCTX_STA_CSA)) {
1115 list_for_each_entry(chanctx, &local->chanctx_list, list) 1160 sdata_info(sdata,
1116 num_chanctx++; 1161 "driver doesn't support chan-switch with channel contexts\n");
1162 ieee80211_queue_work(&local->hw,
1163 &ifmgd->csa_connection_drop_work);
1164 mutex_unlock(&local->chanctx_mtx);
1165 mutex_unlock(&local->mtx);
1166 return;
1167 }
1117 1168
1118 if (num_chanctx > 1 || 1169 ch_switch.timestamp = timestamp;
1119 !(local->hw.flags & IEEE80211_HW_CHANCTX_STA_CSA)) { 1170 ch_switch.device_timestamp = device_timestamp;
1120 sdata_info(sdata, 1171 ch_switch.block_tx = csa_ie.mode;
1121 "not handling chan-switch with channel contexts\n"); 1172 ch_switch.chandef = csa_ie.chandef;
1122 ieee80211_queue_work(&local->hw, 1173 ch_switch.count = csa_ie.count;
1123 &ifmgd->csa_connection_drop_work); 1174
1124 mutex_unlock(&local->chanctx_mtx); 1175 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1125 mutex_unlock(&local->mtx); 1176 sdata_info(sdata,
1126 return; 1177 "preparing for channel switch failed, disconnecting\n");
1127 } 1178 ieee80211_queue_work(&local->hw,
1179 &ifmgd->csa_connection_drop_work);
1180 mutex_unlock(&local->chanctx_mtx);
1181 mutex_unlock(&local->mtx);
1182 return;
1128 } 1183 }
1129 1184
1130 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef, 1185 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
@@ -1152,14 +1207,7 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1152 1207
1153 if (local->ops->channel_switch) { 1208 if (local->ops->channel_switch) {
1154 /* use driver's channel switch callback */ 1209 /* use driver's channel switch callback */
1155 struct ieee80211_channel_switch ch_switch = { 1210 drv_channel_switch(local, sdata, &ch_switch);
1156 .timestamp = timestamp,
1157 .block_tx = csa_ie.mode,
1158 .chandef = csa_ie.chandef,
1159 .count = csa_ie.count,
1160 };
1161
1162 drv_channel_switch(local, &ch_switch);
1163 return; 1211 return;
1164 } 1212 }
1165 1213
@@ -1580,6 +1628,95 @@ void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1580 mutex_unlock(&sdata->local->mtx); 1628 mutex_unlock(&sdata->local->mtx);
1581} 1629}
1582 1630
1631static bool
1632__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1633{
1634 struct ieee80211_local *local = sdata->local;
1635 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1636 bool ret;
1637 int ac;
1638
1639 if (local->hw.queues < IEEE80211_NUM_ACS)
1640 return false;
1641
1642 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1643 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1644 int non_acm_ac;
1645 unsigned long now = jiffies;
1646
1647 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1648 tx_tspec->admitted_time &&
1649 time_after(now, tx_tspec->time_slice_start + HZ)) {
1650 tx_tspec->consumed_tx_time = 0;
1651 tx_tspec->time_slice_start = now;
1652
1653 if (tx_tspec->downgraded)
1654 tx_tspec->action =
1655 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1656 }
1657
1658 switch (tx_tspec->action) {
1659 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1660 /* take the original parameters */
1661 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1662 sdata_err(sdata,
1663 "failed to set TX queue parameters for queue %d\n",
1664 ac);
1665 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1666 tx_tspec->downgraded = false;
1667 ret = true;
1668 break;
1669 case TX_TSPEC_ACTION_DOWNGRADE:
1670 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1671 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1672 ret = true;
1673 break;
1674 }
1675 /* downgrade next lower non-ACM AC */
1676 for (non_acm_ac = ac + 1;
1677 non_acm_ac < IEEE80211_NUM_ACS;
1678 non_acm_ac++)
1679 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1680 break;
1681 /* The loop will result in using BK even if it requires
1682 * admission control, such configuration makes no sense
1683 * and we have to transmit somehow - the AC selection
1684 * does the same thing.
1685 */
1686 if (drv_conf_tx(local, sdata, ac,
1687 &sdata->tx_conf[non_acm_ac]))
1688 sdata_err(sdata,
1689 "failed to set TX queue parameters for queue %d\n",
1690 ac);
1691 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1692 ret = true;
1693 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1694 tx_tspec->time_slice_start + HZ - now + 1);
1695 break;
1696 case TX_TSPEC_ACTION_NONE:
1697 /* nothing now */
1698 break;
1699 }
1700 }
1701
1702 return ret;
1703}
1704
1705void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1706{
1707 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1708 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1709}
1710
1711static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1712{
1713 struct ieee80211_sub_if_data *sdata;
1714
1715 sdata = container_of(work, struct ieee80211_sub_if_data,
1716 u.mgd.tx_tspec_wk.work);
1717 ieee80211_sta_handle_tspec_ac_params(sdata);
1718}
1719
1583/* MLME */ 1720/* MLME */
1584static bool ieee80211_sta_wmm_params(struct ieee80211_local *local, 1721static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
1585 struct ieee80211_sub_if_data *sdata, 1722 struct ieee80211_sub_if_data *sdata,
@@ -1664,12 +1801,14 @@ static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
1664 params.uapsd = uapsd; 1801 params.uapsd = uapsd;
1665 1802
1666 mlme_dbg(sdata, 1803 mlme_dbg(sdata,
1667 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n", 1804 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1668 queue, aci, acm, 1805 queue, aci, acm,
1669 params.aifs, params.cw_min, params.cw_max, 1806 params.aifs, params.cw_min, params.cw_max,
1670 params.txop, params.uapsd); 1807 params.txop, params.uapsd,
1808 ifmgd->tx_tspec[queue].downgraded);
1671 sdata->tx_conf[queue] = params; 1809 sdata->tx_conf[queue] = params;
1672 if (drv_conf_tx(local, sdata, queue, &params)) 1810 if (!ifmgd->tx_tspec[queue].downgraded &&
1811 drv_conf_tx(local, sdata, queue, &params))
1673 sdata_err(sdata, 1812 sdata_err(sdata,
1674 "failed to set TX queue parameters for queue %d\n", 1813 "failed to set TX queue parameters for queue %d\n",
1675 queue); 1814 queue);
@@ -1924,6 +2063,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1924 ieee80211_vif_release_channel(sdata); 2063 ieee80211_vif_release_channel(sdata);
1925 2064
1926 sdata->vif.csa_active = false; 2065 sdata->vif.csa_active = false;
2066 ifmgd->csa_waiting_bcn = false;
1927 if (sdata->csa_block_tx) { 2067 if (sdata->csa_block_tx) {
1928 ieee80211_wake_vif_queues(local, sdata, 2068 ieee80211_wake_vif_queues(local, sdata,
1929 IEEE80211_QUEUE_STOP_REASON_CSA); 2069 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -1931,6 +2071,10 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1931 } 2071 }
1932 mutex_unlock(&local->mtx); 2072 mutex_unlock(&local->mtx);
1933 2073
2074 /* existing TX TSPEC sessions no longer exist */
2075 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2076 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2077
1934 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; 2078 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
1935} 2079}
1936 2080
@@ -1983,9 +2127,46 @@ out:
1983 mutex_unlock(&local->mtx); 2127 mutex_unlock(&local->mtx);
1984} 2128}
1985 2129
2130static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2131 struct ieee80211_hdr *hdr,
2132 u16 tx_time)
2133{
2134 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2135 u16 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
2136 int ac = ieee80211_ac_from_tid(tid);
2137 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2138 unsigned long now = jiffies;
2139
2140 if (likely(!tx_tspec->admitted_time))
2141 return;
2142
2143 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2144 tx_tspec->consumed_tx_time = 0;
2145 tx_tspec->time_slice_start = now;
2146
2147 if (tx_tspec->downgraded) {
2148 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2149 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2150 }
2151 }
2152
2153 if (tx_tspec->downgraded)
2154 return;
2155
2156 tx_tspec->consumed_tx_time += tx_time;
2157
2158 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2159 tx_tspec->downgraded = true;
2160 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2161 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2162 }
2163}
2164
1986void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, 2165void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
1987 struct ieee80211_hdr *hdr, bool ack) 2166 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
1988{ 2167{
2168 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2169
1989 if (!ieee80211_is_data(hdr->frame_control)) 2170 if (!ieee80211_is_data(hdr->frame_control))
1990 return; 2171 return;
1991 2172
@@ -2048,8 +2229,6 @@ static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2048 2229
2049 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); 2230 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2050 run_again(sdata, ifmgd->probe_timeout); 2231 run_again(sdata, ifmgd->probe_timeout);
2051 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2052 ieee80211_flush_queues(sdata->local, sdata);
2053} 2232}
2054 2233
2055static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, 2234static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
@@ -2172,6 +2351,7 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2172 true, frame_buf); 2351 true, frame_buf);
2173 mutex_lock(&local->mtx); 2352 mutex_lock(&local->mtx);
2174 sdata->vif.csa_active = false; 2353 sdata->vif.csa_active = false;
2354 ifmgd->csa_waiting_bcn = false;
2175 if (sdata->csa_block_tx) { 2355 if (sdata->csa_block_tx) {
2176 ieee80211_wake_vif_queues(local, sdata, 2356 ieee80211_wake_vif_queues(local, sdata,
2177 IEEE80211_QUEUE_STOP_REASON_CSA); 2357 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -3196,6 +3376,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3196 } 3376 }
3197 } 3377 }
3198 3378
3379 if (ifmgd->csa_waiting_bcn)
3380 ieee80211_chswitch_post_beacon(sdata);
3381
3199 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) 3382 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
3200 return; 3383 return;
3201 ifmgd->beacon_crc = ncrc; 3384 ifmgd->beacon_crc = ncrc;
@@ -3204,6 +3387,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3204 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); 3387 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3205 3388
3206 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime, 3389 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
3390 rx_status->device_timestamp,
3207 &elems, true); 3391 &elems, true);
3208 3392
3209 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) && 3393 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
@@ -3335,8 +3519,9 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3335 break; 3519 break;
3336 3520
3337 ieee80211_sta_process_chanswitch(sdata, 3521 ieee80211_sta_process_chanswitch(sdata,
3338 rx_status->mactime, 3522 rx_status->mactime,
3339 &elems, false); 3523 rx_status->device_timestamp,
3524 &elems, false);
3340 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) { 3525 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3341 ies_len = skb->len - 3526 ies_len = skb->len -
3342 offsetof(struct ieee80211_mgmt, 3527 offsetof(struct ieee80211_mgmt,
@@ -3357,8 +3542,9 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3357 &mgmt->u.action.u.ext_chan_switch.data; 3542 &mgmt->u.action.u.ext_chan_switch.data;
3358 3543
3359 ieee80211_sta_process_chanswitch(sdata, 3544 ieee80211_sta_process_chanswitch(sdata,
3360 rx_status->mactime, 3545 rx_status->mactime,
3361 &elems, false); 3546 rx_status->device_timestamp,
3547 &elems, false);
3362 } 3548 }
3363 break; 3549 break;
3364 } 3550 }
@@ -3665,11 +3851,12 @@ static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3665 struct ieee80211_sub_if_data *sdata = 3851 struct ieee80211_sub_if_data *sdata =
3666 (struct ieee80211_sub_if_data *) data; 3852 (struct ieee80211_sub_if_data *) data;
3667 struct ieee80211_local *local = sdata->local; 3853 struct ieee80211_local *local = sdata->local;
3854 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3668 3855
3669 if (local->quiescing) 3856 if (local->quiescing)
3670 return; 3857 return;
3671 3858
3672 if (sdata->vif.csa_active) 3859 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
3673 return; 3860 return;
3674 3861
3675 sdata->u.mgd.connection_loss = false; 3862 sdata->u.mgd.connection_loss = false;
@@ -3687,7 +3874,7 @@ static void ieee80211_sta_conn_mon_timer(unsigned long data)
3687 if (local->quiescing) 3874 if (local->quiescing)
3688 return; 3875 return;
3689 3876
3690 if (sdata->vif.csa_active) 3877 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
3691 return; 3878 return;
3692 3879
3693 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); 3880 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
@@ -3799,6 +3986,8 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3799 (unsigned long) sdata); 3986 (unsigned long) sdata);
3800 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 3987 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
3801 (unsigned long) sdata); 3988 (unsigned long) sdata);
3989 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
3990 ieee80211_sta_handle_tspec_ac_params_wk);
3802 3991
3803 ifmgd->flags = 0; 3992 ifmgd->flags = 0;
3804 ifmgd->powersave = sdata->wdev.ps; 3993 ifmgd->powersave = sdata->wdev.ps;
diff --git a/net/mac80211/ocb.c b/net/mac80211/ocb.c
new file mode 100644
index 000000000000..358d5f9d8207
--- /dev/null
+++ b/net/mac80211/ocb.c
@@ -0,0 +1,250 @@
1/*
2 * OCB mode implementation
3 *
4 * Copyright: (c) 2014 Czech Technical University in Prague
5 * (c) 2014 Volkswagen Group Research
6 * Author: Rostislav Lisovy <rostislav.lisovy@fel.cvut.cz>
7 * Funded by: Volkswagen Group Research
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/delay.h>
15#include <linux/if_ether.h>
16#include <linux/skbuff.h>
17#include <linux/if_arp.h>
18#include <linux/etherdevice.h>
19#include <linux/rtnetlink.h>
20#include <net/mac80211.h>
21#include <asm/unaligned.h>
22
23#include "ieee80211_i.h"
24#include "driver-ops.h"
25#include "rate.h"
26
27#define IEEE80211_OCB_HOUSEKEEPING_INTERVAL (60 * HZ)
28#define IEEE80211_OCB_PEER_INACTIVITY_LIMIT (240 * HZ)
29#define IEEE80211_OCB_MAX_STA_ENTRIES 128
30
31/**
32 * enum ocb_deferred_task_flags - mac80211 OCB deferred tasks
33 * @OCB_WORK_HOUSEKEEPING: run the periodic OCB housekeeping tasks
34 *
35 * These flags are used in @wrkq_flags field of &struct ieee80211_if_ocb
36 */
37enum ocb_deferred_task_flags {
38 OCB_WORK_HOUSEKEEPING,
39};
40
41void ieee80211_ocb_rx_no_sta(struct ieee80211_sub_if_data *sdata,
42 const u8 *bssid, const u8 *addr,
43 u32 supp_rates)
44{
45 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
46 struct ieee80211_local *local = sdata->local;
47 struct ieee80211_chanctx_conf *chanctx_conf;
48 struct ieee80211_supported_band *sband;
49 enum nl80211_bss_scan_width scan_width;
50 struct sta_info *sta;
51 int band;
52
53 /* XXX: Consider removing the least recently used entry and
54 * allow new one to be added.
55 */
56 if (local->num_sta >= IEEE80211_OCB_MAX_STA_ENTRIES) {
57 net_info_ratelimited("%s: No room for a new OCB STA entry %pM\n",
58 sdata->name, addr);
59 return;
60 }
61
62 ocb_dbg(sdata, "Adding new OCB station %pM\n", addr);
63
64 rcu_read_lock();
65 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
66 if (WARN_ON_ONCE(!chanctx_conf)) {
67 rcu_read_unlock();
68 return;
69 }
70 band = chanctx_conf->def.chan->band;
71 scan_width = cfg80211_chandef_to_scan_width(&chanctx_conf->def);
72 rcu_read_unlock();
73
74 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
75 if (!sta)
76 return;
77
78 sta->last_rx = jiffies;
79
80 /* Add only mandatory rates for now */
81 sband = local->hw.wiphy->bands[band];
82 sta->sta.supp_rates[band] =
83 ieee80211_mandatory_rates(sband, scan_width);
84
85 spin_lock(&ifocb->incomplete_lock);
86 list_add(&sta->list, &ifocb->incomplete_stations);
87 spin_unlock(&ifocb->incomplete_lock);
88 ieee80211_queue_work(&local->hw, &sdata->work);
89}
90
91static struct sta_info *ieee80211_ocb_finish_sta(struct sta_info *sta)
92 __acquires(RCU)
93{
94 struct ieee80211_sub_if_data *sdata = sta->sdata;
95 u8 addr[ETH_ALEN];
96
97 memcpy(addr, sta->sta.addr, ETH_ALEN);
98
99 ocb_dbg(sdata, "Adding new IBSS station %pM (dev=%s)\n",
100 addr, sdata->name);
101
102 sta_info_move_state(sta, IEEE80211_STA_AUTH);
103 sta_info_move_state(sta, IEEE80211_STA_ASSOC);
104 sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
105
106 rate_control_rate_init(sta);
107
108 /* If it fails, maybe we raced another insertion? */
109 if (sta_info_insert_rcu(sta))
110 return sta_info_get(sdata, addr);
111 return sta;
112}
113
114static void ieee80211_ocb_housekeeping(struct ieee80211_sub_if_data *sdata)
115{
116 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
117
118 ocb_dbg(sdata, "Running ocb housekeeping\n");
119
120 ieee80211_sta_expire(sdata, IEEE80211_OCB_PEER_INACTIVITY_LIMIT);
121
122 mod_timer(&ifocb->housekeeping_timer,
123 round_jiffies(jiffies + IEEE80211_OCB_HOUSEKEEPING_INTERVAL));
124}
125
126void ieee80211_ocb_work(struct ieee80211_sub_if_data *sdata)
127{
128 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
129 struct sta_info *sta;
130
131 if (ifocb->joined != true)
132 return;
133
134 sdata_lock(sdata);
135
136 spin_lock_bh(&ifocb->incomplete_lock);
137 while (!list_empty(&ifocb->incomplete_stations)) {
138 sta = list_first_entry(&ifocb->incomplete_stations,
139 struct sta_info, list);
140 list_del(&sta->list);
141 spin_unlock_bh(&ifocb->incomplete_lock);
142
143 ieee80211_ocb_finish_sta(sta);
144 rcu_read_unlock();
145 spin_lock_bh(&ifocb->incomplete_lock);
146 }
147 spin_unlock_bh(&ifocb->incomplete_lock);
148
149 if (test_and_clear_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags))
150 ieee80211_ocb_housekeeping(sdata);
151
152 sdata_unlock(sdata);
153}
154
155static void ieee80211_ocb_housekeeping_timer(unsigned long data)
156{
157 struct ieee80211_sub_if_data *sdata = (void *)data;
158 struct ieee80211_local *local = sdata->local;
159 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
160
161 set_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags);
162
163 ieee80211_queue_work(&local->hw, &sdata->work);
164}
165
166void ieee80211_ocb_setup_sdata(struct ieee80211_sub_if_data *sdata)
167{
168 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
169
170 setup_timer(&ifocb->housekeeping_timer,
171 ieee80211_ocb_housekeeping_timer,
172 (unsigned long)sdata);
173 INIT_LIST_HEAD(&ifocb->incomplete_stations);
174 spin_lock_init(&ifocb->incomplete_lock);
175}
176
177int ieee80211_ocb_join(struct ieee80211_sub_if_data *sdata,
178 struct ocb_setup *setup)
179{
180 struct ieee80211_local *local = sdata->local;
181 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
182 u32 changed = BSS_CHANGED_OCB;
183 int err;
184
185 if (ifocb->joined == true)
186 return -EINVAL;
187
188 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
189 sdata->smps_mode = IEEE80211_SMPS_OFF;
190 sdata->needed_rx_chains = sdata->local->rx_chains;
191
192 mutex_lock(&sdata->local->mtx);
193 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
194 IEEE80211_CHANCTX_SHARED);
195 mutex_unlock(&sdata->local->mtx);
196 if (err)
197 return err;
198
199 ieee80211_bss_info_change_notify(sdata, changed);
200
201 ifocb->joined = true;
202
203 set_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags);
204 ieee80211_queue_work(&local->hw, &sdata->work);
205
206 netif_carrier_on(sdata->dev);
207 return 0;
208}
209
210int ieee80211_ocb_leave(struct ieee80211_sub_if_data *sdata)
211{
212 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
213 struct ieee80211_local *local = sdata->local;
214 struct sta_info *sta;
215
216 ifocb->joined = false;
217 sta_info_flush(sdata);
218
219 spin_lock_bh(&ifocb->incomplete_lock);
220 while (!list_empty(&ifocb->incomplete_stations)) {
221 sta = list_first_entry(&ifocb->incomplete_stations,
222 struct sta_info, list);
223 list_del(&sta->list);
224 spin_unlock_bh(&ifocb->incomplete_lock);
225
226 sta_info_free(local, sta);
227 spin_lock_bh(&ifocb->incomplete_lock);
228 }
229 spin_unlock_bh(&ifocb->incomplete_lock);
230
231 netif_carrier_off(sdata->dev);
232 clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
233 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_OCB);
234
235 mutex_lock(&sdata->local->mtx);
236 ieee80211_vif_release_channel(sdata);
237 mutex_unlock(&sdata->local->mtx);
238
239 skb_queue_purge(&sdata->skb_queue);
240
241 del_timer_sync(&sdata->u.ocb.housekeeping_timer);
242 /* If the timer fired while we waited for it, it will have
243 * requeued the work. Now the work will be running again
244 * but will not rearm the timer again because it checks
245 * whether we are connected to the network or not -- at this
246 * point we shouldn't be anymore.
247 */
248
249 return 0;
250}
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index 2baa7ed8789d..c2b91bf47f6d 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -191,7 +191,7 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
191 * (1) if any success probabilitiy >= 95%, out of those rates 191 * (1) if any success probabilitiy >= 95%, out of those rates
192 * choose the maximum throughput rate as max_prob_rate 192 * choose the maximum throughput rate as max_prob_rate
193 * (2) if all success probabilities < 95%, the rate with 193 * (2) if all success probabilities < 95%, the rate with
194 * highest success probability is choosen as max_prob_rate */ 194 * highest success probability is chosen as max_prob_rate */
195 if (mrs->probability >= MINSTREL_FRAC(95, 100)) { 195 if (mrs->probability >= MINSTREL_FRAC(95, 100)) {
196 if (mrs->cur_tp >= mi->r[tmp_prob_rate].stats.cur_tp) 196 if (mrs->cur_tp >= mi->r[tmp_prob_rate].stats.cur_tp)
197 tmp_prob_rate = i; 197 tmp_prob_rate = i;
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index df90ce2db00c..c50fd94d2aef 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -10,6 +10,7 @@
10#include <linux/skbuff.h> 10#include <linux/skbuff.h>
11#include <linux/debugfs.h> 11#include <linux/debugfs.h>
12#include <linux/random.h> 12#include <linux/random.h>
13#include <linux/moduleparam.h>
13#include <linux/ieee80211.h> 14#include <linux/ieee80211.h>
14#include <net/mac80211.h> 15#include <net/mac80211.h>
15#include "rate.h" 16#include "rate.h"
@@ -34,12 +35,17 @@
34/* Transmit duration for the raw data part of an average sized packet */ 35/* Transmit duration for the raw data part of an average sized packet */
35#define MCS_DURATION(streams, sgi, bps) MCS_SYMBOL_TIME(sgi, MCS_NSYMS((streams) * (bps))) 36#define MCS_DURATION(streams, sgi, bps) MCS_SYMBOL_TIME(sgi, MCS_NSYMS((streams) * (bps)))
36 37
38#define BW_20 0
39#define BW_40 1
40#define BW_80 2
41
37/* 42/*
38 * Define group sort order: HT40 -> SGI -> #streams 43 * Define group sort order: HT40 -> SGI -> #streams
39 */ 44 */
40#define GROUP_IDX(_streams, _sgi, _ht40) \ 45#define GROUP_IDX(_streams, _sgi, _ht40) \
46 MINSTREL_HT_GROUP_0 + \
41 MINSTREL_MAX_STREAMS * 2 * _ht40 + \ 47 MINSTREL_MAX_STREAMS * 2 * _ht40 + \
42 MINSTREL_MAX_STREAMS * _sgi + \ 48 MINSTREL_MAX_STREAMS * _sgi + \
43 _streams - 1 49 _streams - 1
44 50
45/* MCS rate information for an MCS group */ 51/* MCS rate information for an MCS group */
@@ -47,6 +53,7 @@
47 [GROUP_IDX(_streams, _sgi, _ht40)] = { \ 53 [GROUP_IDX(_streams, _sgi, _ht40)] = { \
48 .streams = _streams, \ 54 .streams = _streams, \
49 .flags = \ 55 .flags = \
56 IEEE80211_TX_RC_MCS | \
50 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \ 57 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \
51 (_ht40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \ 58 (_ht40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \
52 .duration = { \ 59 .duration = { \
@@ -61,6 +68,47 @@
61 } \ 68 } \
62} 69}
63 70
71#define VHT_GROUP_IDX(_streams, _sgi, _bw) \
72 (MINSTREL_VHT_GROUP_0 + \
73 MINSTREL_MAX_STREAMS * 2 * (_bw) + \
74 MINSTREL_MAX_STREAMS * (_sgi) + \
75 (_streams) - 1)
76
77#define BW2VBPS(_bw, r3, r2, r1) \
78 (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
79
80#define VHT_GROUP(_streams, _sgi, _bw) \
81 [VHT_GROUP_IDX(_streams, _sgi, _bw)] = { \
82 .streams = _streams, \
83 .flags = \
84 IEEE80211_TX_RC_VHT_MCS | \
85 (_sgi ? IEEE80211_TX_RC_SHORT_GI : 0) | \
86 (_bw == BW_80 ? IEEE80211_TX_RC_80_MHZ_WIDTH : \
87 _bw == BW_40 ? IEEE80211_TX_RC_40_MHZ_WIDTH : 0), \
88 .duration = { \
89 MCS_DURATION(_streams, _sgi, \
90 BW2VBPS(_bw, 117, 54, 26)), \
91 MCS_DURATION(_streams, _sgi, \
92 BW2VBPS(_bw, 234, 108, 52)), \
93 MCS_DURATION(_streams, _sgi, \
94 BW2VBPS(_bw, 351, 162, 78)), \
95 MCS_DURATION(_streams, _sgi, \
96 BW2VBPS(_bw, 468, 216, 104)), \
97 MCS_DURATION(_streams, _sgi, \
98 BW2VBPS(_bw, 702, 324, 156)), \
99 MCS_DURATION(_streams, _sgi, \
100 BW2VBPS(_bw, 936, 432, 208)), \
101 MCS_DURATION(_streams, _sgi, \
102 BW2VBPS(_bw, 1053, 486, 234)), \
103 MCS_DURATION(_streams, _sgi, \
104 BW2VBPS(_bw, 1170, 540, 260)), \
105 MCS_DURATION(_streams, _sgi, \
106 BW2VBPS(_bw, 1404, 648, 312)), \
107 MCS_DURATION(_streams, _sgi, \
108 BW2VBPS(_bw, 1560, 720, 346)) \
109 } \
110}
111
64#define CCK_DURATION(_bitrate, _short, _len) \ 112#define CCK_DURATION(_bitrate, _short, _len) \
65 (1000 * (10 /* SIFS */ + \ 113 (1000 * (10 /* SIFS */ + \
66 (_short ? 72 + 24 : 144 + 48) + \ 114 (_short ? 72 + 24 : 144 + 48) + \
@@ -76,53 +124,96 @@
76 CCK_ACK_DURATION(55, _short), \ 124 CCK_ACK_DURATION(55, _short), \
77 CCK_ACK_DURATION(110, _short) 125 CCK_ACK_DURATION(110, _short)
78 126
79#define CCK_GROUP \ 127#define CCK_GROUP \
80 [MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS] = { \ 128 [MINSTREL_CCK_GROUP] = { \
81 .streams = 0, \ 129 .streams = 0, \
82 .duration = { \ 130 .flags = 0, \
83 CCK_DURATION_LIST(false), \ 131 .duration = { \
84 CCK_DURATION_LIST(true) \ 132 CCK_DURATION_LIST(false), \
85 } \ 133 CCK_DURATION_LIST(true) \
134 } \
86 } 135 }
87 136
137#ifdef CONFIG_MAC80211_RC_MINSTREL_VHT
138static bool minstrel_vht_only = true;
139module_param(minstrel_vht_only, bool, 0644);
140MODULE_PARM_DESC(minstrel_vht_only,
141 "Use only VHT rates when VHT is supported by sta.");
142#endif
143
88/* 144/*
89 * To enable sufficiently targeted rate sampling, MCS rates are divided into 145 * To enable sufficiently targeted rate sampling, MCS rates are divided into
90 * groups, based on the number of streams and flags (HT40, SGI) that they 146 * groups, based on the number of streams and flags (HT40, SGI) that they
91 * use. 147 * use.
92 * 148 *
93 * Sortorder has to be fixed for GROUP_IDX macro to be applicable: 149 * Sortorder has to be fixed for GROUP_IDX macro to be applicable:
94 * HT40 -> SGI -> #streams 150 * BW -> SGI -> #streams
95 */ 151 */
96const struct mcs_group minstrel_mcs_groups[] = { 152const struct mcs_group minstrel_mcs_groups[] = {
97 MCS_GROUP(1, 0, 0), 153 MCS_GROUP(1, 0, BW_20),
98 MCS_GROUP(2, 0, 0), 154 MCS_GROUP(2, 0, BW_20),
99#if MINSTREL_MAX_STREAMS >= 3 155#if MINSTREL_MAX_STREAMS >= 3
100 MCS_GROUP(3, 0, 0), 156 MCS_GROUP(3, 0, BW_20),
101#endif 157#endif
102 158
103 MCS_GROUP(1, 1, 0), 159 MCS_GROUP(1, 1, BW_20),
104 MCS_GROUP(2, 1, 0), 160 MCS_GROUP(2, 1, BW_20),
105#if MINSTREL_MAX_STREAMS >= 3 161#if MINSTREL_MAX_STREAMS >= 3
106 MCS_GROUP(3, 1, 0), 162 MCS_GROUP(3, 1, BW_20),
107#endif 163#endif
108 164
109 MCS_GROUP(1, 0, 1), 165 MCS_GROUP(1, 0, BW_40),
110 MCS_GROUP(2, 0, 1), 166 MCS_GROUP(2, 0, BW_40),
111#if MINSTREL_MAX_STREAMS >= 3 167#if MINSTREL_MAX_STREAMS >= 3
112 MCS_GROUP(3, 0, 1), 168 MCS_GROUP(3, 0, BW_40),
113#endif 169#endif
114 170
115 MCS_GROUP(1, 1, 1), 171 MCS_GROUP(1, 1, BW_40),
116 MCS_GROUP(2, 1, 1), 172 MCS_GROUP(2, 1, BW_40),
117#if MINSTREL_MAX_STREAMS >= 3 173#if MINSTREL_MAX_STREAMS >= 3
118 MCS_GROUP(3, 1, 1), 174 MCS_GROUP(3, 1, BW_40),
119#endif 175#endif
120 176
121 /* must be last */ 177 CCK_GROUP,
122 CCK_GROUP
123};
124 178
125#define MINSTREL_CCK_GROUP (ARRAY_SIZE(minstrel_mcs_groups) - 1) 179#ifdef CONFIG_MAC80211_RC_MINSTREL_VHT
180 VHT_GROUP(1, 0, BW_20),
181 VHT_GROUP(2, 0, BW_20),
182#if MINSTREL_MAX_STREAMS >= 3
183 VHT_GROUP(3, 0, BW_20),
184#endif
185
186 VHT_GROUP(1, 1, BW_20),
187 VHT_GROUP(2, 1, BW_20),
188#if MINSTREL_MAX_STREAMS >= 3
189 VHT_GROUP(3, 1, BW_20),
190#endif
191
192 VHT_GROUP(1, 0, BW_40),
193 VHT_GROUP(2, 0, BW_40),
194#if MINSTREL_MAX_STREAMS >= 3
195 VHT_GROUP(3, 0, BW_40),
196#endif
197
198 VHT_GROUP(1, 1, BW_40),
199 VHT_GROUP(2, 1, BW_40),
200#if MINSTREL_MAX_STREAMS >= 3
201 VHT_GROUP(3, 1, BW_40),
202#endif
203
204 VHT_GROUP(1, 0, BW_80),
205 VHT_GROUP(2, 0, BW_80),
206#if MINSTREL_MAX_STREAMS >= 3
207 VHT_GROUP(3, 0, BW_80),
208#endif
209
210 VHT_GROUP(1, 1, BW_80),
211 VHT_GROUP(2, 1, BW_80),
212#if MINSTREL_MAX_STREAMS >= 3
213 VHT_GROUP(3, 1, BW_80),
214#endif
215#endif
216};
126 217
127static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly; 218static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
128 219
@@ -130,16 +221,64 @@ static void
130minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi); 221minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
131 222
132/* 223/*
224 * Some VHT MCSes are invalid (when Ndbps / Nes is not an integer)
225 * e.g for MCS9@20MHzx1Nss: Ndbps=8x52*(5/6) Nes=1
226 *
227 * Returns the valid mcs map for struct minstrel_mcs_group_data.supported
228 */
229static u16
230minstrel_get_valid_vht_rates(int bw, int nss, __le16 mcs_map)
231{
232 u16 mask = 0;
233
234 if (bw == BW_20) {
235 if (nss != 3 && nss != 6)
236 mask = BIT(9);
237 } else if (bw == BW_80) {
238 if (nss == 3 || nss == 7)
239 mask = BIT(6);
240 else if (nss == 6)
241 mask = BIT(9);
242 } else {
243 WARN_ON(bw != BW_40);
244 }
245
246 switch ((le16_to_cpu(mcs_map) >> (2 * (nss - 1))) & 3) {
247 case IEEE80211_VHT_MCS_SUPPORT_0_7:
248 mask |= 0x300;
249 break;
250 case IEEE80211_VHT_MCS_SUPPORT_0_8:
251 mask |= 0x200;
252 break;
253 case IEEE80211_VHT_MCS_SUPPORT_0_9:
254 break;
255 default:
256 mask = 0x3ff;
257 }
258
259 return 0x3ff & ~mask;
260}
261
262/*
133 * Look up an MCS group index based on mac80211 rate information 263 * Look up an MCS group index based on mac80211 rate information
134 */ 264 */
135static int 265static int
136minstrel_ht_get_group_idx(struct ieee80211_tx_rate *rate) 266minstrel_ht_get_group_idx(struct ieee80211_tx_rate *rate)
137{ 267{
138 return GROUP_IDX((rate->idx / MCS_GROUP_RATES) + 1, 268 return GROUP_IDX((rate->idx / 8) + 1,
139 !!(rate->flags & IEEE80211_TX_RC_SHORT_GI), 269 !!(rate->flags & IEEE80211_TX_RC_SHORT_GI),
140 !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)); 270 !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH));
141} 271}
142 272
273static int
274minstrel_vht_get_group_idx(struct ieee80211_tx_rate *rate)
275{
276 return VHT_GROUP_IDX(ieee80211_rate_get_vht_nss(rate),
277 !!(rate->flags & IEEE80211_TX_RC_SHORT_GI),
278 !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) +
279 2*!!(rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH));
280}
281
143static struct minstrel_rate_stats * 282static struct minstrel_rate_stats *
144minstrel_ht_get_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi, 283minstrel_ht_get_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
145 struct ieee80211_tx_rate *rate) 284 struct ieee80211_tx_rate *rate)
@@ -149,6 +288,9 @@ minstrel_ht_get_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
149 if (rate->flags & IEEE80211_TX_RC_MCS) { 288 if (rate->flags & IEEE80211_TX_RC_MCS) {
150 group = minstrel_ht_get_group_idx(rate); 289 group = minstrel_ht_get_group_idx(rate);
151 idx = rate->idx % 8; 290 idx = rate->idx % 8;
291 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
292 group = minstrel_vht_get_group_idx(rate);
293 idx = ieee80211_rate_get_vht_mcs(rate);
152 } else { 294 } else {
153 group = MINSTREL_CCK_GROUP; 295 group = MINSTREL_CCK_GROUP;
154 296
@@ -240,8 +382,8 @@ minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate)
240 * MCS groups, CCK rates do not provide aggregation and are therefore at last. 382 * MCS groups, CCK rates do not provide aggregation and are therefore at last.
241 */ 383 */
242static void 384static void
243minstrel_ht_sort_best_tp_rates(struct minstrel_ht_sta *mi, u8 index, 385minstrel_ht_sort_best_tp_rates(struct minstrel_ht_sta *mi, u16 index,
244 u8 *tp_list) 386 u16 *tp_list)
245{ 387{
246 int cur_group, cur_idx, cur_thr, cur_prob; 388 int cur_group, cur_idx, cur_thr, cur_prob;
247 int tmp_group, tmp_idx, tmp_thr, tmp_prob; 389 int tmp_group, tmp_idx, tmp_thr, tmp_prob;
@@ -278,7 +420,7 @@ minstrel_ht_sort_best_tp_rates(struct minstrel_ht_sta *mi, u8 index,
278 * Find and set the topmost probability rate per sta and per group 420 * Find and set the topmost probability rate per sta and per group
279 */ 421 */
280static void 422static void
281minstrel_ht_set_best_prob_rate(struct minstrel_ht_sta *mi, u8 index) 423minstrel_ht_set_best_prob_rate(struct minstrel_ht_sta *mi, u16 index)
282{ 424{
283 struct minstrel_mcs_group_data *mg; 425 struct minstrel_mcs_group_data *mg;
284 struct minstrel_rate_stats *mr; 426 struct minstrel_rate_stats *mr;
@@ -321,8 +463,8 @@ minstrel_ht_set_best_prob_rate(struct minstrel_ht_sta *mi, u8 index)
321 */ 463 */
322static void 464static void
323minstrel_ht_assign_best_tp_rates(struct minstrel_ht_sta *mi, 465minstrel_ht_assign_best_tp_rates(struct minstrel_ht_sta *mi,
324 u8 tmp_mcs_tp_rate[MAX_THR_RATES], 466 u16 tmp_mcs_tp_rate[MAX_THR_RATES],
325 u8 tmp_cck_tp_rate[MAX_THR_RATES]) 467 u16 tmp_cck_tp_rate[MAX_THR_RATES])
326{ 468{
327 unsigned int tmp_group, tmp_idx, tmp_cck_tp, tmp_mcs_tp; 469 unsigned int tmp_group, tmp_idx, tmp_cck_tp, tmp_mcs_tp;
328 int i; 470 int i;
@@ -386,8 +528,8 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
386 struct minstrel_mcs_group_data *mg; 528 struct minstrel_mcs_group_data *mg;
387 struct minstrel_rate_stats *mr; 529 struct minstrel_rate_stats *mr;
388 int group, i, j; 530 int group, i, j;
389 u8 tmp_mcs_tp_rate[MAX_THR_RATES], tmp_group_tp_rate[MAX_THR_RATES]; 531 u16 tmp_mcs_tp_rate[MAX_THR_RATES], tmp_group_tp_rate[MAX_THR_RATES];
390 u8 tmp_cck_tp_rate[MAX_THR_RATES], index; 532 u16 tmp_cck_tp_rate[MAX_THR_RATES], index;
391 533
392 if (mi->ampdu_packets > 0) { 534 if (mi->ampdu_packets > 0) {
393 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len, 535 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
@@ -485,7 +627,8 @@ minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct ieee80211_tx_rate *rat
485 if (!rate->count) 627 if (!rate->count)
486 return false; 628 return false;
487 629
488 if (rate->flags & IEEE80211_TX_RC_MCS) 630 if (rate->flags & IEEE80211_TX_RC_MCS ||
631 rate->flags & IEEE80211_TX_RC_VHT_MCS)
489 return true; 632 return true;
490 633
491 return rate->idx == mp->cck_rates[0] || 634 return rate->idx == mp->cck_rates[0] ||
@@ -517,7 +660,7 @@ minstrel_next_sample_idx(struct minstrel_ht_sta *mi)
517} 660}
518 661
519static void 662static void
520minstrel_downgrade_rate(struct minstrel_ht_sta *mi, u8 *idx, bool primary) 663minstrel_downgrade_rate(struct minstrel_ht_sta *mi, u16 *idx, bool primary)
521{ 664{
522 int group, orig_group; 665 int group, orig_group;
523 666
@@ -714,7 +857,7 @@ minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
714 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES]; 857 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
715 struct minstrel_rate_stats *mr; 858 struct minstrel_rate_stats *mr;
716 u8 idx; 859 u8 idx;
717 u16 flags; 860 u16 flags = group->flags;
718 861
719 mr = minstrel_get_ratestats(mi, index); 862 mr = minstrel_get_ratestats(mi, index);
720 if (!mr->retry_updated) 863 if (!mr->retry_updated)
@@ -730,13 +873,13 @@ minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
730 ratetbl->rate[offset].count_rts = mr->retry_count_rtscts; 873 ratetbl->rate[offset].count_rts = mr->retry_count_rtscts;
731 } 874 }
732 875
733 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) { 876 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP)
734 idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)]; 877 idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
735 flags = 0; 878 else if (flags & IEEE80211_TX_RC_VHT_MCS)
736 } else { 879 idx = ((group->streams - 1) << 4) |
880 ((index % MCS_GROUP_RATES) & 0xF);
881 else
737 idx = index % MCS_GROUP_RATES + (group->streams - 1) * 8; 882 idx = index % MCS_GROUP_RATES + (group->streams - 1) * 8;
738 flags = IEEE80211_TX_RC_MCS | group->flags;
739 }
740 883
741 if (offset > 0) { 884 if (offset > 0) {
742 ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts; 885 ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
@@ -916,13 +1059,15 @@ minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
916 if (sample_idx / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) { 1059 if (sample_idx / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
917 int idx = sample_idx % ARRAY_SIZE(mp->cck_rates); 1060 int idx = sample_idx % ARRAY_SIZE(mp->cck_rates);
918 rate->idx = mp->cck_rates[idx]; 1061 rate->idx = mp->cck_rates[idx];
919 rate->flags = 0; 1062 } else if (sample_group->flags & IEEE80211_TX_RC_VHT_MCS) {
920 return; 1063 ieee80211_rate_set_vht(rate, sample_idx % MCS_GROUP_RATES,
1064 sample_group->streams);
1065 } else {
1066 rate->idx = sample_idx % MCS_GROUP_RATES +
1067 (sample_group->streams - 1) * 8;
921 } 1068 }
922 1069
923 rate->idx = sample_idx % MCS_GROUP_RATES + 1070 rate->flags = sample_group->flags;
924 (sample_group->streams - 1) * 8;
925 rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
926} 1071}
927 1072
928static void 1073static void
@@ -962,6 +1107,8 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
962 struct minstrel_ht_sta *mi = &msp->ht; 1107 struct minstrel_ht_sta *mi = &msp->ht;
963 struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs; 1108 struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs;
964 u16 sta_cap = sta->ht_cap.cap; 1109 u16 sta_cap = sta->ht_cap.cap;
1110 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1111 int use_vht;
965 int n_supported = 0; 1112 int n_supported = 0;
966 int ack_dur; 1113 int ack_dur;
967 int stbc; 1114 int stbc;
@@ -971,8 +1118,14 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
971 if (!sta->ht_cap.ht_supported) 1118 if (!sta->ht_cap.ht_supported)
972 goto use_legacy; 1119 goto use_legacy;
973 1120
974 BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != 1121 BUILD_BUG_ON(ARRAY_SIZE(minstrel_mcs_groups) != MINSTREL_GROUPS_NB);
975 MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS + 1); 1122
1123#ifdef CONFIG_MAC80211_RC_MINSTREL_VHT
1124 if (vht_cap->vht_supported)
1125 use_vht = vht_cap->vht_mcs.tx_mcs_map != cpu_to_le16(~0);
1126 else
1127#endif
1128 use_vht = 0;
976 1129
977 msp->is_ht = true; 1130 msp->is_ht = true;
978 memset(mi, 0, sizeof(*mi)); 1131 memset(mi, 0, sizeof(*mi));
@@ -997,22 +1150,28 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
997 } 1150 }
998 mi->sample_tries = 4; 1151 mi->sample_tries = 4;
999 1152
1000 stbc = (sta_cap & IEEE80211_HT_CAP_RX_STBC) >> 1153 /* TODO tx_flags for vht - ATM the RC API is not fine-grained enough */
1001 IEEE80211_HT_CAP_RX_STBC_SHIFT; 1154 if (!use_vht) {
1002 mi->tx_flags |= stbc << IEEE80211_TX_CTL_STBC_SHIFT; 1155 stbc = (sta_cap & IEEE80211_HT_CAP_RX_STBC) >>
1156 IEEE80211_HT_CAP_RX_STBC_SHIFT;
1157 mi->tx_flags |= stbc << IEEE80211_TX_CTL_STBC_SHIFT;
1003 1158
1004 if (sta_cap & IEEE80211_HT_CAP_LDPC_CODING) 1159 if (sta_cap & IEEE80211_HT_CAP_LDPC_CODING)
1005 mi->tx_flags |= IEEE80211_TX_CTL_LDPC; 1160 mi->tx_flags |= IEEE80211_TX_CTL_LDPC;
1161 }
1006 1162
1007 for (i = 0; i < ARRAY_SIZE(mi->groups); i++) { 1163 for (i = 0; i < ARRAY_SIZE(mi->groups); i++) {
1164 u32 gflags = minstrel_mcs_groups[i].flags;
1165 int bw, nss;
1166
1008 mi->groups[i].supported = 0; 1167 mi->groups[i].supported = 0;
1009 if (i == MINSTREL_CCK_GROUP) { 1168 if (i == MINSTREL_CCK_GROUP) {
1010 minstrel_ht_update_cck(mp, mi, sband, sta); 1169 minstrel_ht_update_cck(mp, mi, sband, sta);
1011 continue; 1170 continue;
1012 } 1171 }
1013 1172
1014 if (minstrel_mcs_groups[i].flags & IEEE80211_TX_RC_SHORT_GI) { 1173 if (gflags & IEEE80211_TX_RC_SHORT_GI) {
1015 if (minstrel_mcs_groups[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) { 1174 if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH) {
1016 if (!(sta_cap & IEEE80211_HT_CAP_SGI_40)) 1175 if (!(sta_cap & IEEE80211_HT_CAP_SGI_40))
1017 continue; 1176 continue;
1018 } else { 1177 } else {
@@ -1021,17 +1180,51 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
1021 } 1180 }
1022 } 1181 }
1023 1182
1024 if (minstrel_mcs_groups[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH && 1183 if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH &&
1025 sta->bandwidth < IEEE80211_STA_RX_BW_40) 1184 sta->bandwidth < IEEE80211_STA_RX_BW_40)
1026 continue; 1185 continue;
1027 1186
1187 nss = minstrel_mcs_groups[i].streams;
1188
1028 /* Mark MCS > 7 as unsupported if STA is in static SMPS mode */ 1189 /* Mark MCS > 7 as unsupported if STA is in static SMPS mode */
1029 if (sta->smps_mode == IEEE80211_SMPS_STATIC && 1190 if (sta->smps_mode == IEEE80211_SMPS_STATIC && nss > 1)
1030 minstrel_mcs_groups[i].streams > 1) 1191 continue;
1192
1193 /* HT rate */
1194 if (gflags & IEEE80211_TX_RC_MCS) {
1195#ifdef CONFIG_MAC80211_RC_MINSTREL_VHT
1196 if (use_vht && minstrel_vht_only)
1197 continue;
1198#endif
1199 mi->groups[i].supported = mcs->rx_mask[nss - 1];
1200 if (mi->groups[i].supported)
1201 n_supported++;
1031 continue; 1202 continue;
1203 }
1204
1205 /* VHT rate */
1206 if (!vht_cap->vht_supported ||
1207 WARN_ON(!(gflags & IEEE80211_TX_RC_VHT_MCS)) ||
1208 WARN_ON(gflags & IEEE80211_TX_RC_160_MHZ_WIDTH))
1209 continue;
1210
1211 if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH) {
1212 if (sta->bandwidth < IEEE80211_STA_RX_BW_80 ||
1213 ((gflags & IEEE80211_TX_RC_SHORT_GI) &&
1214 !(vht_cap->cap & IEEE80211_VHT_CAP_SHORT_GI_80))) {
1215 continue;
1216 }
1217 }
1218
1219 if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1220 bw = BW_40;
1221 else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1222 bw = BW_80;
1223 else
1224 bw = BW_20;
1032 1225
1033 mi->groups[i].supported = 1226 mi->groups[i].supported = minstrel_get_valid_vht_rates(bw, nss,
1034 mcs->rx_mask[minstrel_mcs_groups[i].streams - 1]; 1227 vht_cap->vht_mcs.tx_mcs_map);
1035 1228
1036 if (mi->groups[i].supported) 1229 if (mi->groups[i].supported)
1037 n_supported++; 1230 n_supported++;
diff --git a/net/mac80211/rc80211_minstrel_ht.h b/net/mac80211/rc80211_minstrel_ht.h
index 01570e0e014b..f2217d6aa0c2 100644
--- a/net/mac80211/rc80211_minstrel_ht.h
+++ b/net/mac80211/rc80211_minstrel_ht.h
@@ -13,10 +13,32 @@
13 * The number of streams can be changed to 2 to reduce code 13 * The number of streams can be changed to 2 to reduce code
14 * size and memory footprint. 14 * size and memory footprint.
15 */ 15 */
16#define MINSTREL_MAX_STREAMS 3 16#define MINSTREL_MAX_STREAMS 3
17#define MINSTREL_STREAM_GROUPS 4 17#define MINSTREL_HT_STREAM_GROUPS 4 /* BW(=2) * SGI(=2) */
18#ifdef CONFIG_MAC80211_RC_MINSTREL_VHT
19#define MINSTREL_VHT_STREAM_GROUPS 6 /* BW(=3) * SGI(=2) */
20#else
21#define MINSTREL_VHT_STREAM_GROUPS 0
22#endif
18 23
19#define MCS_GROUP_RATES 8 24#define MINSTREL_HT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
25 MINSTREL_HT_STREAM_GROUPS)
26#define MINSTREL_VHT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
27 MINSTREL_VHT_STREAM_GROUPS)
28#define MINSTREL_CCK_GROUPS_NB 1
29#define MINSTREL_GROUPS_NB (MINSTREL_HT_GROUPS_NB + \
30 MINSTREL_VHT_GROUPS_NB + \
31 MINSTREL_CCK_GROUPS_NB)
32
33#define MINSTREL_HT_GROUP_0 0
34#define MINSTREL_CCK_GROUP (MINSTREL_HT_GROUP_0 + MINSTREL_HT_GROUPS_NB)
35#define MINSTREL_VHT_GROUP_0 (MINSTREL_CCK_GROUP + 1)
36
37#ifdef CONFIG_MAC80211_RC_MINSTREL_VHT
38#define MCS_GROUP_RATES 10
39#else
40#define MCS_GROUP_RATES 8
41#endif
20 42
21struct mcs_group { 43struct mcs_group {
22 u32 flags; 44 u32 flags;
@@ -31,11 +53,11 @@ struct minstrel_mcs_group_data {
31 u8 column; 53 u8 column;
32 54
33 /* bitfield of supported MCS rates of this group */ 55 /* bitfield of supported MCS rates of this group */
34 u8 supported; 56 u16 supported;
35 57
36 /* sorted rate set within a MCS group*/ 58 /* sorted rate set within a MCS group*/
37 u8 max_group_tp_rate[MAX_THR_RATES]; 59 u16 max_group_tp_rate[MAX_THR_RATES];
38 u8 max_group_prob_rate; 60 u16 max_group_prob_rate;
39 61
40 /* MCS rate statistics */ 62 /* MCS rate statistics */
41 struct minstrel_rate_stats rates[MCS_GROUP_RATES]; 63 struct minstrel_rate_stats rates[MCS_GROUP_RATES];
@@ -52,8 +74,8 @@ struct minstrel_ht_sta {
52 unsigned int avg_ampdu_len; 74 unsigned int avg_ampdu_len;
53 75
54 /* overall sorted rate set */ 76 /* overall sorted rate set */
55 u8 max_tp_rate[MAX_THR_RATES]; 77 u16 max_tp_rate[MAX_THR_RATES];
56 u8 max_prob_rate; 78 u16 max_prob_rate;
57 79
58 /* time of last status update */ 80 /* time of last status update */
59 unsigned long stats_update; 81 unsigned long stats_update;
@@ -80,7 +102,7 @@ struct minstrel_ht_sta {
80 u8 cck_supported_short; 102 u8 cck_supported_short;
81 103
82 /* MCS rate group info and statistics */ 104 /* MCS rate group info and statistics */
83 struct minstrel_mcs_group_data groups[MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS + 1]; 105 struct minstrel_mcs_group_data groups[MINSTREL_GROUPS_NB];
84}; 106};
85 107
86struct minstrel_ht_sta_priv { 108struct minstrel_ht_sta_priv {
diff --git a/net/mac80211/rc80211_minstrel_ht_debugfs.c b/net/mac80211/rc80211_minstrel_ht_debugfs.c
index d537bec93754..20c676b8e5b6 100644
--- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
+++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
@@ -18,19 +18,23 @@
18static char * 18static char *
19minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p) 19minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
20{ 20{
21 unsigned int max_mcs = MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS;
22 const struct mcs_group *mg; 21 const struct mcs_group *mg;
23 unsigned int j, tp, prob, eprob; 22 unsigned int j, tp, prob, eprob;
24 char htmode = '2'; 23 char htmode = '2';
25 char gimode = 'L'; 24 char gimode = 'L';
25 u32 gflags;
26 26
27 if (!mi->groups[i].supported) 27 if (!mi->groups[i].supported)
28 return p; 28 return p;
29 29
30 mg = &minstrel_mcs_groups[i]; 30 mg = &minstrel_mcs_groups[i];
31 if (mg->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) 31 gflags = mg->flags;
32
33 if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
32 htmode = '4'; 34 htmode = '4';
33 if (mg->flags & IEEE80211_TX_RC_SHORT_GI) 35 else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
36 htmode = '8';
37 if (gflags & IEEE80211_TX_RC_SHORT_GI)
34 gimode = 'S'; 38 gimode = 'S';
35 39
36 for (j = 0; j < MCS_GROUP_RATES; j++) { 40 for (j = 0; j < MCS_GROUP_RATES; j++) {
@@ -41,10 +45,12 @@ minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
41 if (!(mi->groups[i].supported & BIT(j))) 45 if (!(mi->groups[i].supported & BIT(j)))
42 continue; 46 continue;
43 47
44 if (i == max_mcs) 48 if (gflags & IEEE80211_TX_RC_MCS)
45 p += sprintf(p, "CCK/%cP ", j < 4 ? 'L' : 'S'); 49 p += sprintf(p, " HT%c0/%cGI ", htmode, gimode);
50 else if (gflags & IEEE80211_TX_RC_VHT_MCS)
51 p += sprintf(p, "VHT%c0/%cGI ", htmode, gimode);
46 else 52 else
47 p += sprintf(p, "HT%c0/%cGI ", htmode, gimode); 53 p += sprintf(p, " CCK/%cP ", j < 4 ? 'L' : 'S');
48 54
49 *(p++) = (idx == mi->max_tp_rate[0]) ? 'A' : ' '; 55 *(p++) = (idx == mi->max_tp_rate[0]) ? 'A' : ' ';
50 *(p++) = (idx == mi->max_tp_rate[1]) ? 'B' : ' '; 56 *(p++) = (idx == mi->max_tp_rate[1]) ? 'B' : ' ';
@@ -52,11 +58,14 @@ minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
52 *(p++) = (idx == mi->max_tp_rate[3]) ? 'D' : ' '; 58 *(p++) = (idx == mi->max_tp_rate[3]) ? 'D' : ' ';
53 *(p++) = (idx == mi->max_prob_rate) ? 'P' : ' '; 59 *(p++) = (idx == mi->max_prob_rate) ? 'P' : ' ';
54 60
55 if (i == max_mcs) { 61 if (gflags & IEEE80211_TX_RC_MCS) {
56 int r = bitrates[j % 4]; 62 p += sprintf(p, " MCS%-2u ", (mg->streams - 1) * 8 + j);
57 p += sprintf(p, " %2u.%1uM", r / 10, r % 10); 63 } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
64 p += sprintf(p, " MCS%-1u/%1u", j, mg->streams);
58 } else { 65 } else {
59 p += sprintf(p, " MCS%-2u", (mg->streams - 1) * 8 + j); 66 int r = bitrates[j % 4];
67
68 p += sprintf(p, " %2u.%1uM ", r / 10, r % 10);
60 } 69 }
61 70
62 tp = mr->cur_tp / 10; 71 tp = mr->cur_tp / 10;
@@ -85,7 +94,6 @@ minstrel_ht_stats_open(struct inode *inode, struct file *file)
85 struct minstrel_ht_sta *mi = &msp->ht; 94 struct minstrel_ht_sta *mi = &msp->ht;
86 struct minstrel_debugfs_info *ms; 95 struct minstrel_debugfs_info *ms;
87 unsigned int i; 96 unsigned int i;
88 unsigned int max_mcs = MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS;
89 char *p; 97 char *p;
90 int ret; 98 int ret;
91 99
@@ -96,18 +104,19 @@ minstrel_ht_stats_open(struct inode *inode, struct file *file)
96 return ret; 104 return ret;
97 } 105 }
98 106
99 ms = kmalloc(8192, GFP_KERNEL); 107 ms = kmalloc(32768, GFP_KERNEL);
100 if (!ms) 108 if (!ms)
101 return -ENOMEM; 109 return -ENOMEM;
102 110
103 file->private_data = ms; 111 file->private_data = ms;
104 p = ms->buf; 112 p = ms->buf;
105 p += sprintf(p, "type rate tpt eprob *prob " 113 p += sprintf(p, " type rate tpt eprob *prob "
106 "ret *ok(*cum) ok( cum)\n"); 114 "ret *ok(*cum) ok( cum)\n");
107 115
108 116 p = minstrel_ht_stats_dump(mi, MINSTREL_CCK_GROUP, p);
109 p = minstrel_ht_stats_dump(mi, max_mcs, p); 117 for (i = 0; i < MINSTREL_CCK_GROUP; i++)
110 for (i = 0; i < max_mcs; i++) 118 p = minstrel_ht_stats_dump(mi, i, p);
119 for (i++; i < ARRAY_SIZE(mi->groups); i++)
111 p = minstrel_ht_stats_dump(mi, i, p); 120 p = minstrel_ht_stats_dump(mi, i, p);
112 121
113 p += sprintf(p, "\nTotal packet count:: ideal %d " 122 p += sprintf(p, "\nTotal packet count:: ideal %d "
@@ -119,7 +128,7 @@ minstrel_ht_stats_open(struct inode *inode, struct file *file)
119 MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10); 128 MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
120 ms->len = p - ms->buf; 129 ms->len = p - ms->buf;
121 130
122 WARN_ON(ms->len + sizeof(*ms) > 8192); 131 WARN_ON(ms->len + sizeof(*ms) > 32768);
123 132
124 return nonseekable_open(inode, file); 133 return nonseekable_open(inode, file);
125} 134}
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index a37f9af634cb..a726bb169302 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1032,6 +1032,7 @@ ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1032 ieee80211_is_pspoll(hdr->frame_control)) && 1032 ieee80211_is_pspoll(hdr->frame_control)) &&
1033 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC && 1033 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1034 rx->sdata->vif.type != NL80211_IFTYPE_WDS && 1034 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1035 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1035 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) { 1036 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1036 /* 1037 /*
1037 * accept port control frames from the AP even when it's not 1038 * accept port control frames from the AP even when it's not
@@ -1272,6 +1273,12 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1272 sta->last_rx_rate_vht_nss = status->vht_nss; 1273 sta->last_rx_rate_vht_nss = status->vht_nss;
1273 } 1274 }
1274 } 1275 }
1276 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1277 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1278 NL80211_IFTYPE_OCB);
1279 /* OCB uses wild-card BSSID */
1280 if (is_broadcast_ether_addr(bssid))
1281 sta->last_rx = jiffies;
1275 } else if (!is_multicast_ether_addr(hdr->addr1)) { 1282 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1276 /* 1283 /*
1277 * Mesh beacons will update last_rx when if they are found to 1284 * Mesh beacons will update last_rx when if they are found to
@@ -2820,6 +2827,7 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2820 2827
2821 if (!ieee80211_vif_is_mesh(&sdata->vif) && 2828 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2822 sdata->vif.type != NL80211_IFTYPE_ADHOC && 2829 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2830 sdata->vif.type != NL80211_IFTYPE_OCB &&
2823 sdata->vif.type != NL80211_IFTYPE_STATION) 2831 sdata->vif.type != NL80211_IFTYPE_STATION)
2824 return RX_DROP_MONITOR; 2832 return RX_DROP_MONITOR;
2825 2833
@@ -3130,6 +3138,33 @@ static bool prepare_for_handlers(struct ieee80211_rx_data *rx,
3130 BIT(rate_idx)); 3138 BIT(rate_idx));
3131 } 3139 }
3132 break; 3140 break;
3141 case NL80211_IFTYPE_OCB:
3142 if (!bssid)
3143 return false;
3144 if (ieee80211_is_beacon(hdr->frame_control)) {
3145 return false;
3146 } else if (!is_broadcast_ether_addr(bssid)) {
3147 ocb_dbg(sdata, "BSSID mismatch in OCB mode!\n");
3148 return false;
3149 } else if (!multicast &&
3150 !ether_addr_equal(sdata->dev->dev_addr,
3151 hdr->addr1)) {
3152 /* if we are in promisc mode we also accept
3153 * packets not destined for us
3154 */
3155 if (!(sdata->dev->flags & IFF_PROMISC))
3156 return false;
3157 rx->flags &= ~IEEE80211_RX_RA_MATCH;
3158 } else if (!rx->sta) {
3159 int rate_idx;
3160 if (status->flag & RX_FLAG_HT)
3161 rate_idx = 0; /* TODO: HT rates */
3162 else
3163 rate_idx = status->rate_idx;
3164 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3165 BIT(rate_idx));
3166 }
3167 break;
3133 case NL80211_IFTYPE_MESH_POINT: 3168 case NL80211_IFTYPE_MESH_POINT:
3134 if (!multicast && 3169 if (!multicast &&
3135 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) { 3170 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index de494df3bab8..adc25371b171 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -501,7 +501,7 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
501 /* make the station visible */ 501 /* make the station visible */
502 sta_info_hash_add(local, sta); 502 sta_info_hash_add(local, sta);
503 503
504 list_add_rcu(&sta->list, &local->sta_list); 504 list_add_tail_rcu(&sta->list, &local->sta_list);
505 505
506 /* notify driver */ 506 /* notify driver */
507 err = sta_info_insert_drv_state(local, sdata, sta); 507 err = sta_info_insert_drv_state(local, sdata, sta);
@@ -1531,7 +1531,7 @@ void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
1531 break; 1531 break;
1532 case 0: 1532 case 0:
1533 /* XXX: what is a good value? */ 1533 /* XXX: what is a good value? */
1534 n_frames = 8; 1534 n_frames = 128;
1535 break; 1535 break;
1536 } 1536 }
1537 1537
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 89290e33dafe..9612d89fad56 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -704,7 +704,8 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
704 704
705 if ((sta->sdata->vif.type == NL80211_IFTYPE_STATION) && 705 if ((sta->sdata->vif.type == NL80211_IFTYPE_STATION) &&
706 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) 706 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
707 ieee80211_sta_tx_notify(sta->sdata, (void *) skb->data, acked); 707 ieee80211_sta_tx_notify(sta->sdata, (void *) skb->data,
708 acked, info->status.tx_time);
708 709
709 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { 710 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
710 if (info->flags & IEEE80211_TX_STAT_ACK) { 711 if (info->flags & IEEE80211_TX_STAT_ACK) {
diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
index 4ea25dec0698..b4f368e2cb3b 100644
--- a/net/mac80211/tdls.c
+++ b/net/mac80211/tdls.c
@@ -562,8 +562,10 @@ ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev,
562 /* infer the initiator if we can, to support old userspace */ 562 /* infer the initiator if we can, to support old userspace */
563 switch (action_code) { 563 switch (action_code) {
564 case WLAN_TDLS_SETUP_REQUEST: 564 case WLAN_TDLS_SETUP_REQUEST:
565 if (sta) 565 if (sta) {
566 set_sta_flag(sta, WLAN_STA_TDLS_INITIATOR); 566 set_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
567 sta->sta.tdls_initiator = false;
568 }
567 /* fall-through */ 569 /* fall-through */
568 case WLAN_TDLS_SETUP_CONFIRM: 570 case WLAN_TDLS_SETUP_CONFIRM:
569 case WLAN_TDLS_DISCOVERY_REQUEST: 571 case WLAN_TDLS_DISCOVERY_REQUEST:
@@ -575,8 +577,10 @@ ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev,
575 * Make the last packet sent take effect for the initiator 577 * Make the last packet sent take effect for the initiator
576 * value. 578 * value.
577 */ 579 */
578 if (sta) 580 if (sta) {
579 clear_sta_flag(sta, WLAN_STA_TDLS_INITIATOR); 581 clear_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
582 sta->sta.tdls_initiator = true;
583 }
580 /* fall-through */ 584 /* fall-through */
581 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: 585 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
582 initiator = false; 586 initiator = false;
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index 38fae7ebe984..809a4983eb4a 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -987,29 +987,34 @@ TRACE_EVENT(drv_flush,
987 987
988TRACE_EVENT(drv_channel_switch, 988TRACE_EVENT(drv_channel_switch,
989 TP_PROTO(struct ieee80211_local *local, 989 TP_PROTO(struct ieee80211_local *local,
990 struct ieee80211_sub_if_data *sdata,
990 struct ieee80211_channel_switch *ch_switch), 991 struct ieee80211_channel_switch *ch_switch),
991 992
992 TP_ARGS(local, ch_switch), 993 TP_ARGS(local, sdata, ch_switch),
993 994
994 TP_STRUCT__entry( 995 TP_STRUCT__entry(
995 LOCAL_ENTRY 996 LOCAL_ENTRY
997 VIF_ENTRY
996 CHANDEF_ENTRY 998 CHANDEF_ENTRY
997 __field(u64, timestamp) 999 __field(u64, timestamp)
1000 __field(u32, device_timestamp)
998 __field(bool, block_tx) 1001 __field(bool, block_tx)
999 __field(u8, count) 1002 __field(u8, count)
1000 ), 1003 ),
1001 1004
1002 TP_fast_assign( 1005 TP_fast_assign(
1003 LOCAL_ASSIGN; 1006 LOCAL_ASSIGN;
1007 VIF_ASSIGN;
1004 CHANDEF_ASSIGN(&ch_switch->chandef) 1008 CHANDEF_ASSIGN(&ch_switch->chandef)
1005 __entry->timestamp = ch_switch->timestamp; 1009 __entry->timestamp = ch_switch->timestamp;
1010 __entry->device_timestamp = ch_switch->device_timestamp;
1006 __entry->block_tx = ch_switch->block_tx; 1011 __entry->block_tx = ch_switch->block_tx;
1007 __entry->count = ch_switch->count; 1012 __entry->count = ch_switch->count;
1008 ), 1013 ),
1009 1014
1010 TP_printk( 1015 TP_printk(
1011 LOCAL_PR_FMT " new " CHANDEF_PR_FMT " count:%d", 1016 LOCAL_PR_FMT VIF_PR_FMT " new " CHANDEF_PR_FMT " count:%d",
1012 LOCAL_PR_ARG, CHANDEF_PR_ARG, __entry->count 1017 LOCAL_PR_ARG, VIF_PR_ARG, CHANDEF_PR_ARG, __entry->count
1013 ) 1018 )
1014); 1019);
1015 1020
@@ -1557,9 +1562,26 @@ DEFINE_EVENT(local_sdata_evt, drv_stop_ap,
1557 TP_ARGS(local, sdata) 1562 TP_ARGS(local, sdata)
1558); 1563);
1559 1564
1560DEFINE_EVENT(local_only_evt, drv_restart_complete, 1565TRACE_EVENT(drv_reconfig_complete,
1561 TP_PROTO(struct ieee80211_local *local), 1566 TP_PROTO(struct ieee80211_local *local,
1562 TP_ARGS(local) 1567 enum ieee80211_reconfig_type reconfig_type),
1568 TP_ARGS(local, reconfig_type),
1569
1570 TP_STRUCT__entry(
1571 LOCAL_ENTRY
1572 __field(u8, reconfig_type)
1573 ),
1574
1575 TP_fast_assign(
1576 LOCAL_ASSIGN;
1577 __entry->reconfig_type = reconfig_type;
1578 ),
1579
1580 TP_printk(
1581 LOCAL_PR_FMT " reconfig_type:%d",
1582 LOCAL_PR_ARG, __entry->reconfig_type
1583 )
1584
1563); 1585);
1564 1586
1565#if IS_ENABLED(CONFIG_IPV6) 1587#if IS_ENABLED(CONFIG_IPV6)
@@ -2106,6 +2128,72 @@ TRACE_EVENT(drv_channel_switch_beacon,
2106 ) 2128 )
2107); 2129);
2108 2130
2131TRACE_EVENT(drv_pre_channel_switch,
2132 TP_PROTO(struct ieee80211_local *local,
2133 struct ieee80211_sub_if_data *sdata,
2134 struct ieee80211_channel_switch *ch_switch),
2135
2136 TP_ARGS(local, sdata, ch_switch),
2137
2138 TP_STRUCT__entry(
2139 LOCAL_ENTRY
2140 VIF_ENTRY
2141 CHANDEF_ENTRY
2142 __field(u64, timestamp)
2143 __field(bool, block_tx)
2144 __field(u8, count)
2145 ),
2146
2147 TP_fast_assign(
2148 LOCAL_ASSIGN;
2149 VIF_ASSIGN;
2150 CHANDEF_ASSIGN(&ch_switch->chandef)
2151 __entry->timestamp = ch_switch->timestamp;
2152 __entry->block_tx = ch_switch->block_tx;
2153 __entry->count = ch_switch->count;
2154 ),
2155
2156 TP_printk(
2157 LOCAL_PR_FMT VIF_PR_FMT " prepare channel switch to "
2158 CHANDEF_PR_FMT " count:%d block_tx:%d timestamp:%llu",
2159 LOCAL_PR_ARG, VIF_PR_ARG, CHANDEF_PR_ARG, __entry->count,
2160 __entry->block_tx, __entry->timestamp
2161 )
2162);
2163
2164DEFINE_EVENT(local_sdata_evt, drv_post_channel_switch,
2165 TP_PROTO(struct ieee80211_local *local,
2166 struct ieee80211_sub_if_data *sdata),
2167 TP_ARGS(local, sdata)
2168);
2169
2170TRACE_EVENT(drv_get_txpower,
2171 TP_PROTO(struct ieee80211_local *local,
2172 struct ieee80211_sub_if_data *sdata,
2173 int dbm, int ret),
2174
2175 TP_ARGS(local, sdata, dbm, ret),
2176
2177 TP_STRUCT__entry(
2178 LOCAL_ENTRY
2179 VIF_ENTRY
2180 __field(int, dbm)
2181 __field(int, ret)
2182 ),
2183
2184 TP_fast_assign(
2185 LOCAL_ASSIGN;
2186 VIF_ASSIGN;
2187 __entry->dbm = dbm;
2188 __entry->ret = ret;
2189 ),
2190
2191 TP_printk(
2192 LOCAL_PR_FMT VIF_PR_FMT " dbm:%d ret:%d",
2193 LOCAL_PR_ARG, VIF_PR_ARG, __entry->dbm, __entry->ret
2194 )
2195);
2196
2109 2197
2110#ifdef CONFIG_MAC80211_MESSAGE_TRACING 2198#ifdef CONFIG_MAC80211_MESSAGE_TRACING
2111#undef TRACE_SYSTEM 2199#undef TRACE_SYSTEM
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 900632a250ec..3ffd91f295a6 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -296,6 +296,9 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
296 */ 296 */
297 return TX_DROP; 297 return TX_DROP;
298 298
299 if (tx->sdata->vif.type == NL80211_IFTYPE_OCB)
300 return TX_CONTINUE;
301
299 if (tx->sdata->vif.type == NL80211_IFTYPE_WDS) 302 if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
300 return TX_CONTINUE; 303 return TX_CONTINUE;
301 304
@@ -2013,6 +2016,17 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2013 goto fail_rcu; 2016 goto fail_rcu;
2014 band = chanctx_conf->def.chan->band; 2017 band = chanctx_conf->def.chan->band;
2015 break; 2018 break;
2019 case NL80211_IFTYPE_OCB:
2020 /* DA SA BSSID */
2021 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2022 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2023 eth_broadcast_addr(hdr.addr3);
2024 hdrlen = 24;
2025 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2026 if (!chanctx_conf)
2027 goto fail_rcu;
2028 band = chanctx_conf->def.chan->band;
2029 break;
2016 case NL80211_IFTYPE_ADHOC: 2030 case NL80211_IFTYPE_ADHOC:
2017 /* DA SA BSSID */ 2031 /* DA SA BSSID */
2018 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2032 memcpy(hdr.addr1, skb->data, ETH_ALEN);
@@ -2057,6 +2071,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2057 * EAPOL frames from the local station. 2071 * EAPOL frames from the local station.
2058 */ 2072 */
2059 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) && 2073 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
2074 (sdata->vif.type != NL80211_IFTYPE_OCB) &&
2060 !multicast && !authorized && 2075 !multicast && !authorized &&
2061 (cpu_to_be16(ethertype) != sdata->control_port_protocol || 2076 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
2062 !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) { 2077 !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) {
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 3c61060a4d2b..f9319a5dca64 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -693,6 +693,34 @@ void ieee80211_iterate_active_interfaces_rtnl(
693} 693}
694EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl); 694EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl);
695 695
696static void __iterate_stations(struct ieee80211_local *local,
697 void (*iterator)(void *data,
698 struct ieee80211_sta *sta),
699 void *data)
700{
701 struct sta_info *sta;
702
703 list_for_each_entry_rcu(sta, &local->sta_list, list) {
704 if (!sta->uploaded)
705 continue;
706
707 iterator(data, &sta->sta);
708 }
709}
710
711void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
712 void (*iterator)(void *data,
713 struct ieee80211_sta *sta),
714 void *data)
715{
716 struct ieee80211_local *local = hw_to_local(hw);
717
718 rcu_read_lock();
719 __iterate_stations(local, iterator, data);
720 rcu_read_unlock();
721}
722EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_atomic);
723
696struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev) 724struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev)
697{ 725{
698 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 726 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
@@ -1073,6 +1101,7 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1073 struct ieee80211_chanctx_conf *chanctx_conf; 1101 struct ieee80211_chanctx_conf *chanctx_conf;
1074 int ac; 1102 int ac;
1075 bool use_11b, enable_qos; 1103 bool use_11b, enable_qos;
1104 bool is_ocb; /* Use another EDCA parameters if dot11OCBActivated=true */
1076 int aCWmin, aCWmax; 1105 int aCWmin, aCWmax;
1077 1106
1078 if (!local->ops->conf_tx) 1107 if (!local->ops->conf_tx)
@@ -1097,6 +1126,8 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1097 */ 1126 */
1098 enable_qos = (sdata->vif.type != NL80211_IFTYPE_STATION); 1127 enable_qos = (sdata->vif.type != NL80211_IFTYPE_STATION);
1099 1128
1129 is_ocb = (sdata->vif.type == NL80211_IFTYPE_OCB);
1130
1100 /* Set defaults according to 802.11-2007 Table 7-37 */ 1131 /* Set defaults according to 802.11-2007 Table 7-37 */
1101 aCWmax = 1023; 1132 aCWmax = 1023;
1102 if (use_11b) 1133 if (use_11b)
@@ -1118,7 +1149,10 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1118 qparam.cw_max = aCWmax; 1149 qparam.cw_max = aCWmax;
1119 qparam.cw_min = aCWmin; 1150 qparam.cw_min = aCWmin;
1120 qparam.txop = 0; 1151 qparam.txop = 0;
1121 qparam.aifs = 7; 1152 if (is_ocb)
1153 qparam.aifs = 9;
1154 else
1155 qparam.aifs = 7;
1122 break; 1156 break;
1123 /* never happens but let's not leave undefined */ 1157 /* never happens but let's not leave undefined */
1124 default: 1158 default:
@@ -1126,21 +1160,32 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1126 qparam.cw_max = aCWmax; 1160 qparam.cw_max = aCWmax;
1127 qparam.cw_min = aCWmin; 1161 qparam.cw_min = aCWmin;
1128 qparam.txop = 0; 1162 qparam.txop = 0;
1129 qparam.aifs = 3; 1163 if (is_ocb)
1164 qparam.aifs = 6;
1165 else
1166 qparam.aifs = 3;
1130 break; 1167 break;
1131 case IEEE80211_AC_VI: 1168 case IEEE80211_AC_VI:
1132 qparam.cw_max = aCWmin; 1169 qparam.cw_max = aCWmin;
1133 qparam.cw_min = (aCWmin + 1) / 2 - 1; 1170 qparam.cw_min = (aCWmin + 1) / 2 - 1;
1134 if (use_11b) 1171 if (is_ocb)
1172 qparam.txop = 0;
1173 else if (use_11b)
1135 qparam.txop = 6016/32; 1174 qparam.txop = 6016/32;
1136 else 1175 else
1137 qparam.txop = 3008/32; 1176 qparam.txop = 3008/32;
1138 qparam.aifs = 2; 1177
1178 if (is_ocb)
1179 qparam.aifs = 3;
1180 else
1181 qparam.aifs = 2;
1139 break; 1182 break;
1140 case IEEE80211_AC_VO: 1183 case IEEE80211_AC_VO:
1141 qparam.cw_max = (aCWmin + 1) / 2 - 1; 1184 qparam.cw_max = (aCWmin + 1) / 2 - 1;
1142 qparam.cw_min = (aCWmin + 1) / 4 - 1; 1185 qparam.cw_min = (aCWmin + 1) / 4 - 1;
1143 if (use_11b) 1186 if (is_ocb)
1187 qparam.txop = 0;
1188 else if (use_11b)
1144 qparam.txop = 3264/32; 1189 qparam.txop = 3264/32;
1145 else 1190 else
1146 qparam.txop = 1504/32; 1191 qparam.txop = 1504/32;
@@ -1813,6 +1858,10 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1813 ieee80211_bss_info_change_notify(sdata, changed); 1858 ieee80211_bss_info_change_notify(sdata, changed);
1814 sdata_unlock(sdata); 1859 sdata_unlock(sdata);
1815 break; 1860 break;
1861 case NL80211_IFTYPE_OCB:
1862 changed |= BSS_CHANGED_OCB;
1863 ieee80211_bss_info_change_notify(sdata, changed);
1864 break;
1816 case NL80211_IFTYPE_ADHOC: 1865 case NL80211_IFTYPE_ADHOC:
1817 changed |= BSS_CHANGED_IBSS; 1866 changed |= BSS_CHANGED_IBSS;
1818 /* fall through */ 1867 /* fall through */
@@ -1949,7 +1998,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1949 * We may want to change that later, however. 1998 * We may want to change that later, however.
1950 */ 1999 */
1951 if (!local->suspended || reconfig_due_to_wowlan) 2000 if (!local->suspended || reconfig_due_to_wowlan)
1952 drv_restart_complete(local); 2001 drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_RESTART);
1953 2002
1954 if (!local->suspended) 2003 if (!local->suspended)
1955 return 0; 2004 return 0;
@@ -1960,6 +2009,9 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1960 mb(); 2009 mb();
1961 local->resuming = false; 2010 local->resuming = false;
1962 2011
2012 if (!reconfig_due_to_wowlan)
2013 drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_SUSPEND);
2014
1963 list_for_each_entry(sdata, &local->interfaces, list) { 2015 list_for_each_entry(sdata, &local->interfaces, list) {
1964 if (!ieee80211_sdata_running(sdata)) 2016 if (!ieee80211_sdata_running(sdata))
1965 continue; 2017 continue;
@@ -2052,42 +2104,36 @@ static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
2052 return false; 2104 return false;
2053} 2105}
2054 2106
2055/** 2107size_t ieee80211_ie_split_ric(const u8 *ies, size_t ielen,
2056 * ieee80211_ie_split - split an IE buffer according to ordering 2108 const u8 *ids, int n_ids,
2057 * 2109 const u8 *after_ric, int n_after_ric,
2058 * @ies: the IE buffer 2110 size_t offset)
2059 * @ielen: the length of the IE buffer
2060 * @ids: an array with element IDs that are allowed before
2061 * the split
2062 * @n_ids: the size of the element ID array
2063 * @offset: offset where to start splitting in the buffer
2064 *
2065 * This function splits an IE buffer by updating the @offset
2066 * variable to point to the location where the buffer should be
2067 * split.
2068 *
2069 * It assumes that the given IE buffer is well-formed, this
2070 * has to be guaranteed by the caller!
2071 *
2072 * It also assumes that the IEs in the buffer are ordered
2073 * correctly, if not the result of using this function will not
2074 * be ordered correctly either, i.e. it does no reordering.
2075 *
2076 * The function returns the offset where the next part of the
2077 * buffer starts, which may be @ielen if the entire (remainder)
2078 * of the buffer should be used.
2079 */
2080size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
2081 const u8 *ids, int n_ids, size_t offset)
2082{ 2111{
2083 size_t pos = offset; 2112 size_t pos = offset;
2084 2113
2085 while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos])) 2114 while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos])) {
2086 pos += 2 + ies[pos + 1]; 2115 if (ies[pos] == WLAN_EID_RIC_DATA && n_after_ric) {
2116 pos += 2 + ies[pos + 1];
2117
2118 while (pos < ielen &&
2119 !ieee80211_id_in_list(after_ric, n_after_ric,
2120 ies[pos]))
2121 pos += 2 + ies[pos + 1];
2122 } else {
2123 pos += 2 + ies[pos + 1];
2124 }
2125 }
2087 2126
2088 return pos; 2127 return pos;
2089} 2128}
2090 2129
2130size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
2131 const u8 *ids, int n_ids, size_t offset)
2132{
2133 return ieee80211_ie_split_ric(ies, ielen, ids, n_ids, NULL, 0, offset);
2134}
2135EXPORT_SYMBOL(ieee80211_ie_split);
2136
2091size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset) 2137size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
2092{ 2138{
2093 size_t pos = offset; 2139 size_t pos = offset;
@@ -2526,11 +2572,23 @@ void ieee80211_dfs_radar_detected_work(struct work_struct *work)
2526 struct ieee80211_local *local = 2572 struct ieee80211_local *local =
2527 container_of(work, struct ieee80211_local, radar_detected_work); 2573 container_of(work, struct ieee80211_local, radar_detected_work);
2528 struct cfg80211_chan_def chandef = local->hw.conf.chandef; 2574 struct cfg80211_chan_def chandef = local->hw.conf.chandef;
2575 struct ieee80211_chanctx *ctx;
2576 int num_chanctx = 0;
2577
2578 mutex_lock(&local->chanctx_mtx);
2579 list_for_each_entry(ctx, &local->chanctx_list, list) {
2580 if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER)
2581 continue;
2582
2583 num_chanctx++;
2584 chandef = ctx->conf.def;
2585 }
2586 mutex_unlock(&local->chanctx_mtx);
2529 2587
2530 ieee80211_dfs_cac_cancel(local); 2588 ieee80211_dfs_cac_cancel(local);
2531 2589
2532 if (local->use_chanctx) 2590 if (num_chanctx > 1)
2533 /* currently not handled */ 2591 /* XXX: multi-channel is not supported yet */
2534 WARN_ON(1); 2592 WARN_ON(1);
2535 else 2593 else
2536 cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL); 2594 cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL);
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index 9181fb6d6437..a4220e92f0cc 100644
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -111,8 +111,6 @@ static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
111 (info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) 111 (info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE))
112 return newhdr + hdrlen; 112 return newhdr + hdrlen;
113 113
114 skb_set_network_header(skb, skb_network_offset(skb) +
115 IEEE80211_WEP_IV_LEN);
116 ieee80211_wep_get_iv(local, keylen, keyidx, newhdr + hdrlen); 114 ieee80211_wep_get_iv(local, keylen, keyidx, newhdr + hdrlen);
117 return newhdr + hdrlen; 115 return newhdr + hdrlen;
118} 116}
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 3b873989992c..fdf52db95b33 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -54,10 +54,18 @@ static int wme_downgrade_ac(struct sk_buff *skb)
54} 54}
55 55
56static u16 ieee80211_downgrade_queue(struct ieee80211_sub_if_data *sdata, 56static u16 ieee80211_downgrade_queue(struct ieee80211_sub_if_data *sdata,
57 struct sk_buff *skb) 57 struct sta_info *sta, struct sk_buff *skb)
58{ 58{
59 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
60
59 /* in case we are a client verify acm is not set for this ac */ 61 /* in case we are a client verify acm is not set for this ac */
60 while (unlikely(sdata->wmm_acm & BIT(skb->priority))) { 62 while (sdata->wmm_acm & BIT(skb->priority)) {
63 int ac = ieee802_1d_to_ac[skb->priority];
64
65 if (ifmgd->tx_tspec[ac].admitted_time &&
66 skb->priority == ifmgd->tx_tspec[ac].up)
67 return ac;
68
61 if (wme_downgrade_ac(skb)) { 69 if (wme_downgrade_ac(skb)) {
62 /* 70 /*
63 * This should not really happen. The AP has marked all 71 * This should not really happen. The AP has marked all
@@ -96,7 +104,7 @@ u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
96 p = ieee80211_get_qos_ctl(hdr); 104 p = ieee80211_get_qos_ctl(hdr);
97 skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK; 105 skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
98 106
99 return ieee80211_downgrade_queue(sdata, skb); 107 return ieee80211_downgrade_queue(sdata, NULL, skb);
100} 108}
101 109
102/* Indicate which queue to use. */ 110/* Indicate which queue to use. */
@@ -108,6 +116,7 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
108 const u8 *ra = NULL; 116 const u8 *ra = NULL;
109 bool qos = false; 117 bool qos = false;
110 struct mac80211_qos_map *qos_map; 118 struct mac80211_qos_map *qos_map;
119 u16 ret;
111 120
112 if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) { 121 if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) {
113 skb->priority = 0; /* required for correct WPA/11i MIC */ 122 skb->priority = 0; /* required for correct WPA/11i MIC */
@@ -139,6 +148,10 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
139 case NL80211_IFTYPE_ADHOC: 148 case NL80211_IFTYPE_ADHOC:
140 ra = skb->data; 149 ra = skb->data;
141 break; 150 break;
151 case NL80211_IFTYPE_OCB:
152 /* all stations are required to support WME */
153 qos = true;
154 break;
142 default: 155 default:
143 break; 156 break;
144 } 157 }
@@ -148,27 +161,29 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
148 if (sta) 161 if (sta)
149 qos = sta->sta.wme; 162 qos = sta->sta.wme;
150 } 163 }
151 rcu_read_unlock();
152 164
153 if (!qos) { 165 if (!qos) {
154 skb->priority = 0; /* required for correct WPA/11i MIC */ 166 skb->priority = 0; /* required for correct WPA/11i MIC */
155 return IEEE80211_AC_BE; 167 ret = IEEE80211_AC_BE;
168 goto out;
156 } 169 }
157 170
158 if (skb->protocol == sdata->control_port_protocol) { 171 if (skb->protocol == sdata->control_port_protocol) {
159 skb->priority = 7; 172 skb->priority = 7;
160 return ieee80211_downgrade_queue(sdata, skb); 173 goto downgrade;
161 } 174 }
162 175
163 /* use the data classifier to determine what 802.1d tag the 176 /* use the data classifier to determine what 802.1d tag the
164 * data frame has */ 177 * data frame has */
165 rcu_read_lock();
166 qos_map = rcu_dereference(sdata->qos_map); 178 qos_map = rcu_dereference(sdata->qos_map);
167 skb->priority = cfg80211_classify8021d(skb, qos_map ? 179 skb->priority = cfg80211_classify8021d(skb, qos_map ?
168 &qos_map->qos_map : NULL); 180 &qos_map->qos_map : NULL);
169 rcu_read_unlock();
170 181
171 return ieee80211_downgrade_queue(sdata, skb); 182 downgrade:
183 ret = ieee80211_downgrade_queue(sdata, sta, skb);
184 out:
185 rcu_read_unlock();
186 return ret;
172} 187}
173 188
174/** 189/**
diff --git a/net/mac80211/wme.h b/net/mac80211/wme.h
index 7fea4bb8acbc..80151edc5195 100644
--- a/net/mac80211/wme.h
+++ b/net/mac80211/wme.h
@@ -13,8 +13,6 @@
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include "ieee80211_i.h" 14#include "ieee80211_i.h"
15 15
16extern const int ieee802_1d_to_ac[8];
17
18u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata, 16u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
19 struct sk_buff *skb, 17 struct sk_buff *skb,
20 struct ieee80211_hdr *hdr); 18 struct ieee80211_hdr *hdr);
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 983527a4c1ab..12398fde02e8 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -209,8 +209,6 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
209 209
210 pos = skb_push(skb, IEEE80211_TKIP_IV_LEN); 210 pos = skb_push(skb, IEEE80211_TKIP_IV_LEN);
211 memmove(pos, pos + IEEE80211_TKIP_IV_LEN, hdrlen); 211 memmove(pos, pos + IEEE80211_TKIP_IV_LEN, hdrlen);
212 skb_set_network_header(skb, skb_network_offset(skb) +
213 IEEE80211_TKIP_IV_LEN);
214 pos += hdrlen; 212 pos += hdrlen;
215 213
216 /* the HW only needs room for the IV, but not the actual IV */ 214 /* the HW only needs room for the IV, but not the actual IV */
@@ -434,8 +432,6 @@ static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
434 432
435 pos = skb_push(skb, IEEE80211_CCMP_HDR_LEN); 433 pos = skb_push(skb, IEEE80211_CCMP_HDR_LEN);
436 memmove(pos, pos + IEEE80211_CCMP_HDR_LEN, hdrlen); 434 memmove(pos, pos + IEEE80211_CCMP_HDR_LEN, hdrlen);
437 skb_set_network_header(skb, skb_network_offset(skb) +
438 IEEE80211_CCMP_HDR_LEN);
439 435
440 /* the HW only needs room for the IV, but not the actual IV */ 436 /* the HW only needs room for the IV, but not the actual IV */
441 if (info->control.hw_key && 437 if (info->control.hw_key &&
@@ -575,7 +571,6 @@ ieee80211_crypto_cs_encrypt(struct ieee80211_tx_data *tx,
575 571
576 pos = skb_push(skb, cs->hdr_len); 572 pos = skb_push(skb, cs->hdr_len);
577 memmove(pos, pos + cs->hdr_len, hdrlen); 573 memmove(pos, pos + cs->hdr_len, hdrlen);
578 skb_set_network_header(skb, skb_network_offset(skb) + cs->hdr_len);
579 574
580 return TX_CONTINUE; 575 return TX_CONTINUE;
581} 576}
diff --git a/net/mac802154/Kconfig b/net/mac802154/Kconfig
index 1818a99b3081..aa462b480a39 100644
--- a/net/mac802154/Kconfig
+++ b/net/mac802154/Kconfig
@@ -16,5 +16,5 @@ config MAC802154
16 been tested yet! 16 been tested yet!
17 17
18 If you plan to use HardMAC IEEE 802.15.4 devices, you can 18 If you plan to use HardMAC IEEE 802.15.4 devices, you can
19 say N here. Alternatievly you can say M to compile it as 19 say N here. Alternatively you can say M to compile it as
20 module. 20 module.
diff --git a/net/mac802154/Makefile b/net/mac802154/Makefile
index 9723d6f3f3e5..702d8b466317 100644
--- a/net/mac802154/Makefile
+++ b/net/mac802154/Makefile
@@ -1,5 +1,5 @@
1obj-$(CONFIG_MAC802154) += mac802154.o 1obj-$(CONFIG_MAC802154) += mac802154.o
2mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o \ 2mac802154-objs := main.o rx.o tx.o mac_cmd.o mib.o \
3 monitor.o wpan.o llsec.o 3 iface.o llsec.o util.o cfg.o
4 4
5ccflags-y += -D__CHECK_ENDIAN__ 5ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
new file mode 100644
index 000000000000..c035708ada16
--- /dev/null
+++ b/net/mac802154/cfg.c
@@ -0,0 +1,210 @@
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
12 *
13 * Based on: net/mac80211/cfg.c
14 */
15
16#include <net/rtnetlink.h>
17#include <net/cfg802154.h>
18
19#include "ieee802154_i.h"
20#include "driver-ops.h"
21#include "cfg.h"
22
23static struct net_device *
24ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
25 const char *name, int type)
26{
27 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
28 struct net_device *dev;
29
30 rtnl_lock();
31 dev = ieee802154_if_add(local, name, type,
32 cpu_to_le64(0x0000000000000000ULL));
33 rtnl_unlock();
34
35 return dev;
36}
37
38static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
39 struct net_device *dev)
40{
41 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
42
43 ieee802154_if_remove(sdata);
44}
45
46static int
47ieee802154_add_iface(struct wpan_phy *phy, const char *name,
48 enum nl802154_iftype type, __le64 extended_addr)
49{
50 struct ieee802154_local *local = wpan_phy_priv(phy);
51 struct net_device *err;
52
53 err = ieee802154_if_add(local, name, type, extended_addr);
54 if (IS_ERR(err))
55 return PTR_ERR(err);
56
57 return 0;
58}
59
60static int
61ieee802154_del_iface(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev)
62{
63 ieee802154_if_remove(IEEE802154_WPAN_DEV_TO_SUB_IF(wpan_dev));
64
65 return 0;
66}
67
68static int
69ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
70{
71 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
72 int ret;
73
74 ASSERT_RTNL();
75
76 /* check if phy support this setting */
77 if (!(wpan_phy->channels_supported[page] & BIT(channel)))
78 return -EINVAL;
79
80 ret = drv_set_channel(local, page, channel);
81 if (!ret) {
82 wpan_phy->current_page = page;
83 wpan_phy->current_channel = channel;
84 }
85
86 return ret;
87}
88
89static int
90ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
91 __le16 pan_id)
92{
93 ASSERT_RTNL();
94
95 /* TODO
96 * I am not sure about to check here on broadcast pan_id.
97 * Broadcast is a valid setting, comment from 802.15.4:
98 * If this value is 0xffff, the device is not associated.
99 *
100 * This could useful to simple deassociate an device.
101 */
102 if (pan_id == cpu_to_le16(IEEE802154_PAN_ID_BROADCAST))
103 return -EINVAL;
104
105 wpan_dev->pan_id = pan_id;
106 return 0;
107}
108
109static int
110ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy,
111 struct wpan_dev *wpan_dev,
112 u8 min_be, u8 max_be)
113{
114 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
115
116 ASSERT_RTNL();
117
118 if (!(local->hw.flags & IEEE802154_HW_CSMA_PARAMS))
119 return -EOPNOTSUPP;
120
121 wpan_dev->min_be = min_be;
122 wpan_dev->max_be = max_be;
123 return 0;
124}
125
126static int
127ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
128 __le16 short_addr)
129{
130 ASSERT_RTNL();
131
132 /* TODO
133 * I am not sure about to check here on broadcast short_addr.
134 * Broadcast is a valid setting, comment from 802.15.4:
135 * A value of 0xfffe indicates that the device has
136 * associated but has not been allocated an address. A
137 * value of 0xffff indicates that the device does not
138 * have a short address.
139 *
140 * I think we should allow to set these settings but
141 * don't allow to allow socket communication with it.
142 */
143 if (short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC) ||
144 short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST))
145 return -EINVAL;
146
147 wpan_dev->short_addr = short_addr;
148 return 0;
149}
150
151static int
152ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy,
153 struct wpan_dev *wpan_dev,
154 u8 max_csma_backoffs)
155{
156 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
157
158 ASSERT_RTNL();
159
160 if (!(local->hw.flags & IEEE802154_HW_CSMA_PARAMS))
161 return -EOPNOTSUPP;
162
163 wpan_dev->csma_retries = max_csma_backoffs;
164 return 0;
165}
166
167static int
168ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy,
169 struct wpan_dev *wpan_dev,
170 s8 max_frame_retries)
171{
172 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
173
174 ASSERT_RTNL();
175
176 if (!(local->hw.flags & IEEE802154_HW_FRAME_RETRIES))
177 return -EOPNOTSUPP;
178
179 wpan_dev->frame_retries = max_frame_retries;
180 return 0;
181}
182
183static int
184ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
185 bool mode)
186{
187 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
188
189 ASSERT_RTNL();
190
191 if (!(local->hw.flags & IEEE802154_HW_LBT))
192 return -EOPNOTSUPP;
193
194 wpan_dev->lbt = mode;
195 return 0;
196}
197
198const struct cfg802154_ops mac802154_config_ops = {
199 .add_virtual_intf_deprecated = ieee802154_add_iface_deprecated,
200 .del_virtual_intf_deprecated = ieee802154_del_iface_deprecated,
201 .add_virtual_intf = ieee802154_add_iface,
202 .del_virtual_intf = ieee802154_del_iface,
203 .set_channel = ieee802154_set_channel,
204 .set_pan_id = ieee802154_set_pan_id,
205 .set_short_addr = ieee802154_set_short_addr,
206 .set_backoff_exponent = ieee802154_set_backoff_exponent,
207 .set_max_csma_backoffs = ieee802154_set_max_csma_backoffs,
208 .set_max_frame_retries = ieee802154_set_max_frame_retries,
209 .set_lbt_mode = ieee802154_set_lbt_mode,
210};
diff --git a/net/mac802154/cfg.h b/net/mac802154/cfg.h
new file mode 100644
index 000000000000..e2718f981e82
--- /dev/null
+++ b/net/mac802154/cfg.h
@@ -0,0 +1,9 @@
1/* mac802154 configuration hooks for cfg802154
2 */
3
4#ifndef __CFG_H
5#define __CFG_H
6
7extern const struct cfg802154_ops mac802154_config_ops;
8
9#endif /* __CFG_H */
diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h
new file mode 100644
index 000000000000..f21e864613d0
--- /dev/null
+++ b/net/mac802154/driver-ops.h
@@ -0,0 +1,222 @@
1#ifndef __MAC802154_DRVIER_OPS
2#define __MAC802154_DRIVER_OPS
3
4#include <linux/types.h>
5#include <linux/rtnetlink.h>
6
7#include <net/mac802154.h>
8
9#include "ieee802154_i.h"
10
11static inline int
12drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
13{
14 return local->ops->xmit_async(&local->hw, skb);
15}
16
17static inline int
18drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
19{
20 /* don't allow other operations while sync xmit */
21 ASSERT_RTNL();
22
23 might_sleep();
24
25 return local->ops->xmit_sync(&local->hw, skb);
26}
27
28static inline int drv_start(struct ieee802154_local *local)
29{
30 might_sleep();
31
32 local->started = true;
33 smp_mb();
34
35 return local->ops->start(&local->hw);
36}
37
38static inline void drv_stop(struct ieee802154_local *local)
39{
40 might_sleep();
41
42 local->ops->stop(&local->hw);
43
44 /* sync away all work on the tasklet before clearing started */
45 tasklet_disable(&local->tasklet);
46 tasklet_enable(&local->tasklet);
47
48 barrier();
49
50 local->started = false;
51}
52
53static inline int
54drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
55{
56 might_sleep();
57
58 return local->ops->set_channel(&local->hw, page, channel);
59}
60
61static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm)
62{
63 might_sleep();
64
65 if (!local->ops->set_txpower) {
66 WARN_ON(1);
67 return -EOPNOTSUPP;
68 }
69
70 return local->ops->set_txpower(&local->hw, dbm);
71}
72
73static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode)
74{
75 might_sleep();
76
77 if (!local->ops->set_cca_mode) {
78 WARN_ON(1);
79 return -EOPNOTSUPP;
80 }
81
82 return local->ops->set_cca_mode(&local->hw, cca_mode);
83}
84
85static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
86{
87 might_sleep();
88
89 if (!local->ops->set_lbt) {
90 WARN_ON(1);
91 return -EOPNOTSUPP;
92 }
93
94 return local->ops->set_lbt(&local->hw, mode);
95}
96
97static inline int
98drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level)
99{
100 might_sleep();
101
102 if (!local->ops->set_cca_ed_level) {
103 WARN_ON(1);
104 return -EOPNOTSUPP;
105 }
106
107 return local->ops->set_cca_ed_level(&local->hw, ed_level);
108}
109
110static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
111{
112 struct ieee802154_hw_addr_filt filt;
113
114 might_sleep();
115
116 if (!local->ops->set_hw_addr_filt) {
117 WARN_ON(1);
118 return -EOPNOTSUPP;
119 }
120
121 filt.pan_id = pan_id;
122
123 return local->ops->set_hw_addr_filt(&local->hw, &filt,
124 IEEE802154_AFILT_PANID_CHANGED);
125}
126
127static inline int
128drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
129{
130 struct ieee802154_hw_addr_filt filt;
131
132 might_sleep();
133
134 if (!local->ops->set_hw_addr_filt) {
135 WARN_ON(1);
136 return -EOPNOTSUPP;
137 }
138
139 filt.ieee_addr = extended_addr;
140
141 return local->ops->set_hw_addr_filt(&local->hw, &filt,
142 IEEE802154_AFILT_IEEEADDR_CHANGED);
143}
144
145static inline int
146drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
147{
148 struct ieee802154_hw_addr_filt filt;
149
150 might_sleep();
151
152 if (!local->ops->set_hw_addr_filt) {
153 WARN_ON(1);
154 return -EOPNOTSUPP;
155 }
156
157 filt.short_addr = short_addr;
158
159 return local->ops->set_hw_addr_filt(&local->hw, &filt,
160 IEEE802154_AFILT_SADDR_CHANGED);
161}
162
163static inline int
164drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
165{
166 struct ieee802154_hw_addr_filt filt;
167
168 might_sleep();
169
170 if (!local->ops->set_hw_addr_filt) {
171 WARN_ON(1);
172 return -EOPNOTSUPP;
173 }
174
175 filt.pan_coord = is_coord;
176
177 return local->ops->set_hw_addr_filt(&local->hw, &filt,
178 IEEE802154_AFILT_PANC_CHANGED);
179}
180
181static inline int
182drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
183 u8 max_csma_backoffs)
184{
185 might_sleep();
186
187 if (!local->ops->set_csma_params) {
188 WARN_ON(1);
189 return -EOPNOTSUPP;
190 }
191
192 return local->ops->set_csma_params(&local->hw, min_be, max_be,
193 max_csma_backoffs);
194}
195
196static inline int
197drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
198{
199 might_sleep();
200
201 if (!local->ops->set_frame_retries) {
202 WARN_ON(1);
203 return -EOPNOTSUPP;
204 }
205
206 return local->ops->set_frame_retries(&local->hw, max_frame_retries);
207}
208
209static inline int
210drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
211{
212 might_sleep();
213
214 if (!local->ops->set_promiscuous_mode) {
215 WARN_ON(1);
216 return -EOPNOTSUPP;
217 }
218
219 return local->ops->set_promiscuous_mode(&local->hw, on);
220}
221
222#endif /* __MAC802154_DRVIER_OPS */
diff --git a/net/mac802154/ieee802154_dev.c b/net/mac802154/ieee802154_dev.c
deleted file mode 100644
index b36b2b996578..000000000000
--- a/net/mac802154/ieee802154_dev.c
+++ /dev/null
@@ -1,415 +0,0 @@
1/*
2 * Copyright (C) 2007-2012 Siemens AG
3 *
4 * Written by:
5 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
6 *
7 * Based on the code from 'linux-zigbee.sourceforge.net' project.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/netdevice.h>
26
27#include <net/netlink.h>
28#include <linux/nl802154.h>
29#include <net/mac802154.h>
30#include <net/ieee802154_netdev.h>
31#include <net/route.h>
32#include <net/wpan-phy.h>
33
34#include "mac802154.h"
35
36int mac802154_slave_open(struct net_device *dev)
37{
38 struct mac802154_sub_if_data *priv = netdev_priv(dev);
39 struct mac802154_sub_if_data *subif;
40 struct mac802154_priv *ipriv = priv->hw;
41 int res = 0;
42
43 ASSERT_RTNL();
44
45 if (priv->type == IEEE802154_DEV_WPAN) {
46 mutex_lock(&priv->hw->slaves_mtx);
47 list_for_each_entry(subif, &priv->hw->slaves, list) {
48 if (subif != priv && subif->type == priv->type &&
49 subif->running) {
50 mutex_unlock(&priv->hw->slaves_mtx);
51 return -EBUSY;
52 }
53 }
54 mutex_unlock(&priv->hw->slaves_mtx);
55 }
56
57 mutex_lock(&priv->hw->slaves_mtx);
58 priv->running = true;
59 mutex_unlock(&priv->hw->slaves_mtx);
60
61 if (ipriv->open_count++ == 0) {
62 res = ipriv->ops->start(&ipriv->hw);
63 WARN_ON(res);
64 if (res)
65 goto err;
66 }
67
68 if (ipriv->ops->ieee_addr) {
69 __le64 addr = ieee802154_devaddr_from_raw(dev->dev_addr);
70
71 res = ipriv->ops->ieee_addr(&ipriv->hw, addr);
72 WARN_ON(res);
73 if (res)
74 goto err;
75 mac802154_dev_set_ieee_addr(dev);
76 }
77
78 netif_start_queue(dev);
79 return 0;
80err:
81 priv->hw->open_count--;
82
83 return res;
84}
85
86int mac802154_slave_close(struct net_device *dev)
87{
88 struct mac802154_sub_if_data *priv = netdev_priv(dev);
89 struct mac802154_priv *ipriv = priv->hw;
90
91 ASSERT_RTNL();
92
93 netif_stop_queue(dev);
94
95 mutex_lock(&priv->hw->slaves_mtx);
96 priv->running = false;
97 mutex_unlock(&priv->hw->slaves_mtx);
98
99 if (!--ipriv->open_count)
100 ipriv->ops->stop(&ipriv->hw);
101
102 return 0;
103}
104
105static int
106mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
107{
108 struct mac802154_sub_if_data *priv;
109 struct mac802154_priv *ipriv;
110 int err;
111
112 ipriv = wpan_phy_priv(phy);
113
114 priv = netdev_priv(dev);
115 priv->dev = dev;
116 priv->hw = ipriv;
117
118 dev->needed_headroom = ipriv->hw.extra_tx_headroom;
119
120 SET_NETDEV_DEV(dev, &ipriv->phy->dev);
121
122 mutex_lock(&ipriv->slaves_mtx);
123 if (!ipriv->running) {
124 mutex_unlock(&ipriv->slaves_mtx);
125 return -ENODEV;
126 }
127 mutex_unlock(&ipriv->slaves_mtx);
128
129 err = register_netdev(dev);
130 if (err < 0)
131 return err;
132
133 rtnl_lock();
134 mutex_lock(&ipriv->slaves_mtx);
135 list_add_tail_rcu(&priv->list, &ipriv->slaves);
136 mutex_unlock(&ipriv->slaves_mtx);
137 rtnl_unlock();
138
139 return 0;
140}
141
142static void
143mac802154_del_iface(struct wpan_phy *phy, struct net_device *dev)
144{
145 struct mac802154_sub_if_data *sdata;
146
147 ASSERT_RTNL();
148
149 sdata = netdev_priv(dev);
150
151 BUG_ON(sdata->hw->phy != phy);
152
153 mutex_lock(&sdata->hw->slaves_mtx);
154 list_del_rcu(&sdata->list);
155 mutex_unlock(&sdata->hw->slaves_mtx);
156
157 synchronize_rcu();
158 unregister_netdevice(sdata->dev);
159}
160
161static struct net_device *
162mac802154_add_iface(struct wpan_phy *phy, const char *name, int type)
163{
164 struct net_device *dev;
165 int err = -ENOMEM;
166
167 switch (type) {
168 case IEEE802154_DEV_MONITOR:
169 dev = alloc_netdev(sizeof(struct mac802154_sub_if_data),
170 name, NET_NAME_UNKNOWN,
171 mac802154_monitor_setup);
172 break;
173 case IEEE802154_DEV_WPAN:
174 dev = alloc_netdev(sizeof(struct mac802154_sub_if_data),
175 name, NET_NAME_UNKNOWN,
176 mac802154_wpan_setup);
177 break;
178 default:
179 dev = NULL;
180 err = -EINVAL;
181 break;
182 }
183 if (!dev)
184 goto err;
185
186 err = mac802154_netdev_register(phy, dev);
187 if (err)
188 goto err_free;
189
190 dev_hold(dev); /* we return an incremented device refcount */
191 return dev;
192
193err_free:
194 free_netdev(dev);
195err:
196 return ERR_PTR(err);
197}
198
199static int mac802154_set_txpower(struct wpan_phy *phy, int db)
200{
201 struct mac802154_priv *priv = wpan_phy_priv(phy);
202
203 return priv->ops->set_txpower(&priv->hw, db);
204}
205
206static int mac802154_set_lbt(struct wpan_phy *phy, bool on)
207{
208 struct mac802154_priv *priv = wpan_phy_priv(phy);
209
210 return priv->ops->set_lbt(&priv->hw, on);
211}
212
213static int mac802154_set_cca_mode(struct wpan_phy *phy, u8 mode)
214{
215 struct mac802154_priv *priv = wpan_phy_priv(phy);
216
217 return priv->ops->set_cca_mode(&priv->hw, mode);
218}
219
220static int mac802154_set_cca_ed_level(struct wpan_phy *phy, s32 level)
221{
222 struct mac802154_priv *priv = wpan_phy_priv(phy);
223
224 return priv->ops->set_cca_ed_level(&priv->hw, level);
225}
226
227static int mac802154_set_csma_params(struct wpan_phy *phy, u8 min_be,
228 u8 max_be, u8 retries)
229{
230 struct mac802154_priv *priv = wpan_phy_priv(phy);
231
232 return priv->ops->set_csma_params(&priv->hw, min_be, max_be, retries);
233}
234
235static int mac802154_set_frame_retries(struct wpan_phy *phy, s8 retries)
236{
237 struct mac802154_priv *priv = wpan_phy_priv(phy);
238
239 return priv->ops->set_frame_retries(&priv->hw, retries);
240}
241
242struct ieee802154_dev *
243ieee802154_alloc_device(size_t priv_data_len, struct ieee802154_ops *ops)
244{
245 struct wpan_phy *phy;
246 struct mac802154_priv *priv;
247 size_t priv_size;
248
249 if (!ops || !ops->xmit || !ops->ed || !ops->start ||
250 !ops->stop || !ops->set_channel) {
251 pr_err("undefined IEEE802.15.4 device operations\n");
252 return NULL;
253 }
254
255 /* Ensure 32-byte alignment of our private data and hw private data.
256 * We use the wpan_phy priv data for both our mac802154_priv and for
257 * the driver's private data
258 *
259 * in memory it'll be like this:
260 *
261 * +-----------------------+
262 * | struct wpan_phy |
263 * +-----------------------+
264 * | struct mac802154_priv |
265 * +-----------------------+
266 * | driver's private data |
267 * +-----------------------+
268 *
269 * Due to ieee802154 layer isn't aware of driver and MAC structures,
270 * so lets allign them here.
271 */
272
273 priv_size = ALIGN(sizeof(*priv), NETDEV_ALIGN) + priv_data_len;
274
275 phy = wpan_phy_alloc(priv_size);
276 if (!phy) {
277 pr_err("failure to allocate master IEEE802.15.4 device\n");
278 return NULL;
279 }
280
281 priv = wpan_phy_priv(phy);
282 priv->phy = phy;
283 priv->hw.phy = priv->phy;
284 priv->hw.priv = (char *)priv + ALIGN(sizeof(*priv), NETDEV_ALIGN);
285 priv->ops = ops;
286
287 INIT_LIST_HEAD(&priv->slaves);
288 mutex_init(&priv->slaves_mtx);
289
290 return &priv->hw;
291}
292EXPORT_SYMBOL(ieee802154_alloc_device);
293
294void ieee802154_free_device(struct ieee802154_dev *hw)
295{
296 struct mac802154_priv *priv = mac802154_to_priv(hw);
297
298 BUG_ON(!list_empty(&priv->slaves));
299
300 mutex_destroy(&priv->slaves_mtx);
301
302 wpan_phy_free(priv->phy);
303}
304EXPORT_SYMBOL(ieee802154_free_device);
305
306int ieee802154_register_device(struct ieee802154_dev *dev)
307{
308 struct mac802154_priv *priv = mac802154_to_priv(dev);
309 int rc = -ENOSYS;
310
311 if (dev->flags & IEEE802154_HW_TXPOWER) {
312 if (!priv->ops->set_txpower)
313 goto out;
314
315 priv->phy->set_txpower = mac802154_set_txpower;
316 }
317
318 if (dev->flags & IEEE802154_HW_LBT) {
319 if (!priv->ops->set_lbt)
320 goto out;
321
322 priv->phy->set_lbt = mac802154_set_lbt;
323 }
324
325 if (dev->flags & IEEE802154_HW_CCA_MODE) {
326 if (!priv->ops->set_cca_mode)
327 goto out;
328
329 priv->phy->set_cca_mode = mac802154_set_cca_mode;
330 }
331
332 if (dev->flags & IEEE802154_HW_CCA_ED_LEVEL) {
333 if (!priv->ops->set_cca_ed_level)
334 goto out;
335
336 priv->phy->set_cca_ed_level = mac802154_set_cca_ed_level;
337 }
338
339 if (dev->flags & IEEE802154_HW_CSMA_PARAMS) {
340 if (!priv->ops->set_csma_params)
341 goto out;
342
343 priv->phy->set_csma_params = mac802154_set_csma_params;
344 }
345
346 if (dev->flags & IEEE802154_HW_FRAME_RETRIES) {
347 if (!priv->ops->set_frame_retries)
348 goto out;
349
350 priv->phy->set_frame_retries = mac802154_set_frame_retries;
351 }
352
353 priv->dev_workqueue =
354 create_singlethread_workqueue(wpan_phy_name(priv->phy));
355 if (!priv->dev_workqueue) {
356 rc = -ENOMEM;
357 goto out;
358 }
359
360 wpan_phy_set_dev(priv->phy, priv->hw.parent);
361
362 priv->phy->add_iface = mac802154_add_iface;
363 priv->phy->del_iface = mac802154_del_iface;
364
365 rc = wpan_phy_register(priv->phy);
366 if (rc < 0)
367 goto out_wq;
368
369 rtnl_lock();
370
371 mutex_lock(&priv->slaves_mtx);
372 priv->running = MAC802154_DEVICE_RUN;
373 mutex_unlock(&priv->slaves_mtx);
374
375 rtnl_unlock();
376
377 return 0;
378
379out_wq:
380 destroy_workqueue(priv->dev_workqueue);
381out:
382 return rc;
383}
384EXPORT_SYMBOL(ieee802154_register_device);
385
386void ieee802154_unregister_device(struct ieee802154_dev *dev)
387{
388 struct mac802154_priv *priv = mac802154_to_priv(dev);
389 struct mac802154_sub_if_data *sdata, *next;
390
391 flush_workqueue(priv->dev_workqueue);
392 destroy_workqueue(priv->dev_workqueue);
393
394 rtnl_lock();
395
396 mutex_lock(&priv->slaves_mtx);
397 priv->running = MAC802154_DEVICE_STOPPED;
398 mutex_unlock(&priv->slaves_mtx);
399
400 list_for_each_entry_safe(sdata, next, &priv->slaves, list) {
401 mutex_lock(&sdata->hw->slaves_mtx);
402 list_del(&sdata->list);
403 mutex_unlock(&sdata->hw->slaves_mtx);
404
405 unregister_netdevice(sdata->dev);
406 }
407
408 rtnl_unlock();
409
410 wpan_phy_unregister(priv->phy);
411}
412EXPORT_SYMBOL(ieee802154_unregister_device);
413
414MODULE_DESCRIPTION("IEEE 802.15.4 implementation");
415MODULE_LICENSE("GPL v2");
diff --git a/net/mac802154/mac802154.h b/net/mac802154/ieee802154_i.h
index 762a6f849c6b..bebd70ffc7a3 100644
--- a/net/mac802154/mac802154.h
+++ b/net/mac802154/ieee802154_i.h
@@ -10,29 +10,28 @@
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by: 13 * Written by:
18 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 14 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
19 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 15 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
20 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 16 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 17 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
22 */ 18 */
23#ifndef MAC802154_H 19#ifndef __IEEE802154_I_H
24#define MAC802154_H 20#define __IEEE802154_I_H
25 21
26#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/hrtimer.h>
24#include <net/cfg802154.h>
27#include <net/mac802154.h> 25#include <net/mac802154.h>
26#include <net/nl802154.h>
28#include <net/ieee802154_netdev.h> 27#include <net/ieee802154_netdev.h>
29 28
30#include "llsec.h" 29#include "llsec.h"
31 30
32/* mac802154 device private data */ 31/* mac802154 device private data */
33struct mac802154_priv { 32struct ieee802154_local {
34 struct ieee802154_dev hw; 33 struct ieee802154_hw hw;
35 struct ieee802154_ops *ops; 34 const struct ieee802154_ops *ops;
36 35
37 /* ieee802154 phy */ 36 /* ieee802154 phy */
38 struct wpan_phy *phy; 37 struct wpan_phy *phy;
@@ -46,23 +45,29 @@ struct mac802154_priv {
46 * 45 *
47 * So atomic readers can use any of this protection methods. 46 * So atomic readers can use any of this protection methods.
48 */ 47 */
49 struct list_head slaves; 48 struct list_head interfaces;
50 struct mutex slaves_mtx; 49 struct mutex iflist_mtx;
51 50
52 /* This one is used for scanning and other jobs not to be interfered 51 /* This one is used for scanning and other jobs not to be interfered
53 * with serial driver. 52 * with serial driver.
54 */ 53 */
55 struct workqueue_struct *dev_workqueue; 54 struct workqueue_struct *workqueue;
56 55
57 /* SoftMAC device is registered and running. One can add subinterfaces. 56 struct hrtimer ifs_timer;
58 * This flag should be modified under slaves_mtx and RTNL, so you can 57
59 * read them using any of protection methods. 58 bool started;
60 */ 59
61 bool running; 60 struct tasklet_struct tasklet;
61 struct sk_buff_head skb_queue;
62};
63
64enum {
65 IEEE802154_RX_MSG = 1,
62}; 66};
63 67
64#define MAC802154_DEVICE_STOPPED 0x00 68enum ieee802154_sdata_state_bits {
65#define MAC802154_DEVICE_RUN 0x01 69 SDATA_STATE_RUNNING,
70};
66 71
67/* Slave interface definition. 72/* Slave interface definition.
68 * 73 *
@@ -70,72 +75,74 @@ struct mac802154_priv {
70 * Each ieee802154 device/transceiver may have several slaves and able 75 * Each ieee802154 device/transceiver may have several slaves and able
71 * to be associated with several networks at the same time. 76 * to be associated with several networks at the same time.
72 */ 77 */
73struct mac802154_sub_if_data { 78struct ieee802154_sub_if_data {
74 struct list_head list; /* the ieee802154_priv->slaves list */ 79 struct list_head list; /* the ieee802154_priv->slaves list */
75 80
76 struct mac802154_priv *hw; 81 struct wpan_dev wpan_dev;
82
83 struct ieee802154_local *local;
77 struct net_device *dev; 84 struct net_device *dev;
78 85
79 int type; 86 unsigned long state;
80 bool running; 87 char name[IFNAMSIZ];
81 88
82 spinlock_t mib_lock; 89 spinlock_t mib_lock;
83 90
84 __le16 pan_id;
85 __le16 short_addr;
86 __le64 extended_addr;
87
88 u8 chan;
89 u8 page;
90
91 struct ieee802154_mac_params mac_params;
92
93 /* MAC BSN field */
94 u8 bsn;
95 /* MAC DSN field */
96 u8 dsn;
97
98 /* protects sec from concurrent access by netlink. access by 91 /* protects sec from concurrent access by netlink. access by
99 * encrypt/decrypt/header_create safe without additional protection. 92 * encrypt/decrypt/header_create safe without additional protection.
100 */ 93 */
101 struct mutex sec_mtx; 94 struct mutex sec_mtx;
102 95
103 struct mac802154_llsec sec; 96 struct mac802154_llsec sec;
97 /* must be last, dynamically sized area in this! */
98 struct ieee802154_vif vif;
104}; 99};
105 100
106#define mac802154_to_priv(_hw) container_of(_hw, struct mac802154_priv, hw)
107
108#define MAC802154_CHAN_NONE 0xff /* No channel is assigned */ 101#define MAC802154_CHAN_NONE 0xff /* No channel is assigned */
109 102
110extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced; 103/* utility functions/constants */
111extern struct ieee802154_mlme_ops mac802154_mlme_wpan; 104extern const void *const mac802154_wpan_phy_privid; /* for wpan_phy privid */
112 105
113int mac802154_slave_open(struct net_device *dev); 106static inline struct ieee802154_local *
114int mac802154_slave_close(struct net_device *dev); 107hw_to_local(struct ieee802154_hw *hw)
108{
109 return container_of(hw, struct ieee802154_local, hw);
110}
111
112static inline struct ieee802154_sub_if_data *
113IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
114{
115 return netdev_priv(dev);
116}
117
118static inline struct ieee802154_sub_if_data *
119IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
120{
121 return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
122}
123
124static inline bool
125ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
126{
127 return test_bit(SDATA_STATE_RUNNING, &sdata->state);
128}
115 129
116void mac802154_monitors_rx(struct mac802154_priv *priv, struct sk_buff *skb); 130extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
117void mac802154_monitor_setup(struct net_device *dev);
118
119void mac802154_wpans_rx(struct mac802154_priv *priv, struct sk_buff *skb);
120void mac802154_wpan_setup(struct net_device *dev);
121 131
122netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb, 132netdev_tx_t
123 u8 page, u8 chan); 133ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
134netdev_tx_t
135ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
136enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
124 137
125/* MIB callbacks */ 138/* MIB callbacks */
126void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val); 139void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val);
127__le16 mac802154_dev_get_short_addr(const struct net_device *dev); 140__le16 mac802154_dev_get_short_addr(const struct net_device *dev);
128void mac802154_dev_set_ieee_addr(struct net_device *dev);
129__le16 mac802154_dev_get_pan_id(const struct net_device *dev); 141__le16 mac802154_dev_get_pan_id(const struct net_device *dev);
130void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val); 142void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val);
131void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); 143void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
132u8 mac802154_dev_get_dsn(const struct net_device *dev); 144u8 mac802154_dev_get_dsn(const struct net_device *dev);
133 145
134int mac802154_set_mac_params(struct net_device *dev,
135 const struct ieee802154_mac_params *params);
136void mac802154_get_mac_params(struct net_device *dev,
137 struct ieee802154_mac_params *params);
138
139int mac802154_get_params(struct net_device *dev, 146int mac802154_get_params(struct net_device *dev,
140 struct ieee802154_llsec_params *params); 147 struct ieee802154_llsec_params *params);
141int mac802154_set_params(struct net_device *dev, 148int mac802154_set_params(struct net_device *dev,
@@ -169,4 +176,13 @@ void mac802154_get_table(struct net_device *dev,
169 struct ieee802154_llsec_table **t); 176 struct ieee802154_llsec_table **t);
170void mac802154_unlock_table(struct net_device *dev); 177void mac802154_unlock_table(struct net_device *dev);
171 178
172#endif /* MAC802154_H */ 179/* interface handling */
180int ieee802154_iface_init(void);
181void ieee802154_iface_exit(void);
182void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
183struct net_device *
184ieee802154_if_add(struct ieee802154_local *local, const char *name,
185 enum nl802154_iftype type, __le64 extended_addr);
186void ieee802154_remove_interfaces(struct ieee802154_local *local);
187
188#endif /* __IEEE802154_I_H */
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
new file mode 100644
index 000000000000..38dfc72d24b6
--- /dev/null
+++ b/net/mac802154/iface.c
@@ -0,0 +1,588 @@
1/*
2 * Copyright 2007-2012 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * Written by:
14 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
15 * Sergey Lapin <slapin@ossfans.org>
16 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
17 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
18 */
19
20#include <linux/netdevice.h>
21#include <linux/module.h>
22#include <linux/if_arp.h>
23#include <linux/ieee802154.h>
24
25#include <net/nl802154.h>
26#include <net/mac802154.h>
27#include <net/ieee802154_netdev.h>
28#include <net/cfg802154.h>
29
30#include "ieee802154_i.h"
31#include "driver-ops.h"
32
33static int mac802154_wpan_update_llsec(struct net_device *dev)
34{
35 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
36 struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
37 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
38 int rc = 0;
39
40 if (ops->llsec) {
41 struct ieee802154_llsec_params params;
42 int changed = 0;
43
44 params.pan_id = wpan_dev->pan_id;
45 changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
46
47 params.hwaddr = wpan_dev->extended_addr;
48 changed |= IEEE802154_LLSEC_PARAM_HWADDR;
49
50 rc = ops->llsec->set_params(dev, &params, changed);
51 }
52
53 return rc;
54}
55
56static int
57mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
58{
59 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
60 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
61 struct sockaddr_ieee802154 *sa =
62 (struct sockaddr_ieee802154 *)&ifr->ifr_addr;
63 int err = -ENOIOCTLCMD;
64
65 ASSERT_RTNL();
66
67 spin_lock_bh(&sdata->mib_lock);
68
69 switch (cmd) {
70 case SIOCGIFADDR:
71 {
72 u16 pan_id, short_addr;
73
74 pan_id = le16_to_cpu(wpan_dev->pan_id);
75 short_addr = le16_to_cpu(wpan_dev->short_addr);
76 if (pan_id == IEEE802154_PANID_BROADCAST ||
77 short_addr == IEEE802154_ADDR_BROADCAST) {
78 err = -EADDRNOTAVAIL;
79 break;
80 }
81
82 sa->family = AF_IEEE802154;
83 sa->addr.addr_type = IEEE802154_ADDR_SHORT;
84 sa->addr.pan_id = pan_id;
85 sa->addr.short_addr = short_addr;
86
87 err = 0;
88 break;
89 }
90 case SIOCSIFADDR:
91 if (netif_running(dev)) {
92 spin_unlock_bh(&sdata->mib_lock);
93 return -EBUSY;
94 }
95
96 dev_warn(&dev->dev,
97 "Using DEBUGing ioctl SIOCSIFADDR isn't recommended!\n");
98 if (sa->family != AF_IEEE802154 ||
99 sa->addr.addr_type != IEEE802154_ADDR_SHORT ||
100 sa->addr.pan_id == IEEE802154_PANID_BROADCAST ||
101 sa->addr.short_addr == IEEE802154_ADDR_BROADCAST ||
102 sa->addr.short_addr == IEEE802154_ADDR_UNDEF) {
103 err = -EINVAL;
104 break;
105 }
106
107 wpan_dev->pan_id = cpu_to_le16(sa->addr.pan_id);
108 wpan_dev->short_addr = cpu_to_le16(sa->addr.short_addr);
109
110 err = mac802154_wpan_update_llsec(dev);
111 break;
112 }
113
114 spin_unlock_bh(&sdata->mib_lock);
115 return err;
116}
117
118static int mac802154_wpan_mac_addr(struct net_device *dev, void *p)
119{
120 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
121 struct sockaddr *addr = p;
122 __le64 extended_addr;
123
124 if (netif_running(dev))
125 return -EBUSY;
126
127 ieee802154_be64_to_le64(&extended_addr, addr->sa_data);
128 if (!ieee802154_is_valid_extended_addr(extended_addr))
129 return -EINVAL;
130
131 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
132 sdata->wpan_dev.extended_addr = extended_addr;
133
134 return mac802154_wpan_update_llsec(dev);
135}
136
137static int mac802154_slave_open(struct net_device *dev)
138{
139 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
140 struct ieee802154_sub_if_data *subif;
141 struct ieee802154_local *local = sdata->local;
142 int res = 0;
143
144 ASSERT_RTNL();
145
146 if (sdata->vif.type == NL802154_IFTYPE_NODE) {
147 mutex_lock(&sdata->local->iflist_mtx);
148 list_for_each_entry(subif, &sdata->local->interfaces, list) {
149 if (subif != sdata &&
150 subif->vif.type == sdata->vif.type &&
151 ieee802154_sdata_running(subif)) {
152 mutex_unlock(&sdata->local->iflist_mtx);
153 return -EBUSY;
154 }
155 }
156 mutex_unlock(&sdata->local->iflist_mtx);
157 }
158
159 set_bit(SDATA_STATE_RUNNING, &sdata->state);
160
161 if (!local->open_count) {
162 res = drv_start(local);
163 WARN_ON(res);
164 if (res)
165 goto err;
166 }
167
168 local->open_count++;
169 netif_start_queue(dev);
170 return 0;
171err:
172 /* might already be clear but that doesn't matter */
173 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
174
175 return res;
176}
177
178static int mac802154_wpan_open(struct net_device *dev)
179{
180 int rc;
181 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
182 struct ieee802154_local *local = sdata->local;
183 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
184 struct wpan_phy *phy = sdata->local->phy;
185
186 rc = mac802154_slave_open(dev);
187 if (rc < 0)
188 return rc;
189
190 mutex_lock(&phy->pib_lock);
191
192 if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
193 rc = drv_set_promiscuous_mode(local,
194 wpan_dev->promiscuous_mode);
195 if (rc < 0)
196 goto out;
197 }
198
199 if (local->hw.flags & IEEE802154_HW_AFILT) {
200 rc = drv_set_pan_id(local, wpan_dev->pan_id);
201 if (rc < 0)
202 goto out;
203
204 rc = drv_set_extended_addr(local, wpan_dev->extended_addr);
205 if (rc < 0)
206 goto out;
207
208 rc = drv_set_short_addr(local, wpan_dev->short_addr);
209 if (rc < 0)
210 goto out;
211 }
212
213 if (local->hw.flags & IEEE802154_HW_LBT) {
214 rc = drv_set_lbt_mode(local, wpan_dev->lbt);
215 if (rc < 0)
216 goto out;
217 }
218
219 if (local->hw.flags & IEEE802154_HW_CSMA_PARAMS) {
220 rc = drv_set_csma_params(local, wpan_dev->min_be,
221 wpan_dev->max_be,
222 wpan_dev->csma_retries);
223 if (rc < 0)
224 goto out;
225 }
226
227 if (local->hw.flags & IEEE802154_HW_FRAME_RETRIES) {
228 rc = drv_set_max_frame_retries(local, wpan_dev->frame_retries);
229 if (rc < 0)
230 goto out;
231 }
232
233 mutex_unlock(&phy->pib_lock);
234 return 0;
235
236out:
237 mutex_unlock(&phy->pib_lock);
238 return rc;
239}
240
241static int mac802154_slave_close(struct net_device *dev)
242{
243 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
244 struct ieee802154_local *local = sdata->local;
245
246 ASSERT_RTNL();
247
248 hrtimer_cancel(&local->ifs_timer);
249
250 netif_stop_queue(dev);
251 local->open_count--;
252
253 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
254
255 if (!local->open_count)
256 drv_stop(local);
257
258 return 0;
259}
260
261static int mac802154_set_header_security(struct ieee802154_sub_if_data *sdata,
262 struct ieee802154_hdr *hdr,
263 const struct ieee802154_mac_cb *cb)
264{
265 struct ieee802154_llsec_params params;
266 u8 level;
267
268 mac802154_llsec_get_params(&sdata->sec, &params);
269
270 if (!params.enabled && cb->secen_override && cb->secen)
271 return -EINVAL;
272 if (!params.enabled ||
273 (cb->secen_override && !cb->secen) ||
274 !params.out_level)
275 return 0;
276 if (cb->seclevel_override && !cb->seclevel)
277 return -EINVAL;
278
279 level = cb->seclevel_override ? cb->seclevel : params.out_level;
280
281 hdr->fc.security_enabled = 1;
282 hdr->sec.level = level;
283 hdr->sec.key_id_mode = params.out_key.mode;
284 if (params.out_key.mode == IEEE802154_SCF_KEY_SHORT_INDEX)
285 hdr->sec.short_src = params.out_key.short_source;
286 else if (params.out_key.mode == IEEE802154_SCF_KEY_HW_INDEX)
287 hdr->sec.extended_src = params.out_key.extended_source;
288 hdr->sec.key_id = params.out_key.id;
289
290 return 0;
291}
292
293static int mac802154_header_create(struct sk_buff *skb,
294 struct net_device *dev,
295 unsigned short type,
296 const void *daddr,
297 const void *saddr,
298 unsigned len)
299{
300 struct ieee802154_hdr hdr;
301 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
302 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
303 struct ieee802154_mac_cb *cb = mac_cb(skb);
304 int hlen;
305
306 if (!daddr)
307 return -EINVAL;
308
309 memset(&hdr.fc, 0, sizeof(hdr.fc));
310 hdr.fc.type = cb->type;
311 hdr.fc.security_enabled = cb->secen;
312 hdr.fc.ack_request = cb->ackreq;
313 hdr.seq = ieee802154_mlme_ops(dev)->get_dsn(dev);
314
315 if (mac802154_set_header_security(sdata, &hdr, cb) < 0)
316 return -EINVAL;
317
318 if (!saddr) {
319 spin_lock_bh(&sdata->mib_lock);
320
321 if (wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
322 wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
323 wpan_dev->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
324 hdr.source.mode = IEEE802154_ADDR_LONG;
325 hdr.source.extended_addr = wpan_dev->extended_addr;
326 } else {
327 hdr.source.mode = IEEE802154_ADDR_SHORT;
328 hdr.source.short_addr = wpan_dev->short_addr;
329 }
330
331 hdr.source.pan_id = wpan_dev->pan_id;
332
333 spin_unlock_bh(&sdata->mib_lock);
334 } else {
335 hdr.source = *(const struct ieee802154_addr *)saddr;
336 }
337
338 hdr.dest = *(const struct ieee802154_addr *)daddr;
339
340 hlen = ieee802154_hdr_push(skb, &hdr);
341 if (hlen < 0)
342 return -EINVAL;
343
344 skb_reset_mac_header(skb);
345 skb->mac_len = hlen;
346
347 if (len > ieee802154_max_payload(&hdr))
348 return -EMSGSIZE;
349
350 return hlen;
351}
352
353static int
354mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)
355{
356 struct ieee802154_hdr hdr;
357 struct ieee802154_addr *addr = (struct ieee802154_addr *)haddr;
358
359 if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0) {
360 pr_debug("malformed packet\n");
361 return 0;
362 }
363
364 *addr = hdr.source;
365 return sizeof(*addr);
366}
367
368static struct header_ops mac802154_header_ops = {
369 .create = mac802154_header_create,
370 .parse = mac802154_header_parse,
371};
372
373static const struct net_device_ops mac802154_wpan_ops = {
374 .ndo_open = mac802154_wpan_open,
375 .ndo_stop = mac802154_slave_close,
376 .ndo_start_xmit = ieee802154_subif_start_xmit,
377 .ndo_do_ioctl = mac802154_wpan_ioctl,
378 .ndo_set_mac_address = mac802154_wpan_mac_addr,
379};
380
381static const struct net_device_ops mac802154_monitor_ops = {
382 .ndo_open = mac802154_wpan_open,
383 .ndo_stop = mac802154_slave_close,
384 .ndo_start_xmit = ieee802154_monitor_start_xmit,
385};
386
387static void mac802154_wpan_free(struct net_device *dev)
388{
389 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
390
391 mac802154_llsec_destroy(&sdata->sec);
392
393 free_netdev(dev);
394}
395
396static void ieee802154_if_setup(struct net_device *dev)
397{
398 dev->addr_len = IEEE802154_EXTENDED_ADDR_LEN;
399 memset(dev->broadcast, 0xff, IEEE802154_EXTENDED_ADDR_LEN);
400
401 dev->hard_header_len = MAC802154_FRAME_HARD_HEADER_LEN;
402 dev->needed_tailroom = 2 + 16; /* FCS + MIC */
403 dev->mtu = IEEE802154_MTU;
404 dev->tx_queue_len = 300;
405 dev->flags = IFF_NOARP | IFF_BROADCAST;
406}
407
408static int
409ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
410 enum nl802154_iftype type)
411{
412 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
413
414 /* set some type-dependent values */
415 sdata->vif.type = type;
416 sdata->wpan_dev.iftype = type;
417
418 get_random_bytes(&wpan_dev->bsn, 1);
419 get_random_bytes(&wpan_dev->dsn, 1);
420
421 /* defaults per 802.15.4-2011 */
422 wpan_dev->min_be = 3;
423 wpan_dev->max_be = 5;
424 wpan_dev->csma_retries = 4;
425 /* for compatibility, actual default is 3 */
426 wpan_dev->frame_retries = -1;
427
428 wpan_dev->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
429 wpan_dev->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
430
431 switch (type) {
432 case NL802154_IFTYPE_NODE:
433 ieee802154_be64_to_le64(&wpan_dev->extended_addr,
434 sdata->dev->dev_addr);
435
436 sdata->dev->header_ops = &mac802154_header_ops;
437 sdata->dev->destructor = mac802154_wpan_free;
438 sdata->dev->netdev_ops = &mac802154_wpan_ops;
439 sdata->dev->ml_priv = &mac802154_mlme_wpan;
440 wpan_dev->promiscuous_mode = false;
441
442 spin_lock_init(&sdata->mib_lock);
443 mutex_init(&sdata->sec_mtx);
444
445 mac802154_llsec_init(&sdata->sec);
446 break;
447 case NL802154_IFTYPE_MONITOR:
448 sdata->dev->destructor = free_netdev;
449 sdata->dev->netdev_ops = &mac802154_monitor_ops;
450 wpan_dev->promiscuous_mode = true;
451 break;
452 default:
453 BUG();
454 }
455
456 return 0;
457}
458
459struct net_device *
460ieee802154_if_add(struct ieee802154_local *local, const char *name,
461 enum nl802154_iftype type, __le64 extended_addr)
462{
463 struct net_device *ndev = NULL;
464 struct ieee802154_sub_if_data *sdata = NULL;
465 int ret = -ENOMEM;
466
467 ASSERT_RTNL();
468
469 ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, name,
470 NET_NAME_UNKNOWN, ieee802154_if_setup);
471 if (!ndev)
472 return ERR_PTR(-ENOMEM);
473
474 ndev->needed_headroom = local->hw.extra_tx_headroom;
475
476 ret = dev_alloc_name(ndev, ndev->name);
477 if (ret < 0)
478 goto err;
479
480 ieee802154_le64_to_be64(ndev->perm_addr,
481 &local->hw.phy->perm_extended_addr);
482 switch (type) {
483 case NL802154_IFTYPE_NODE:
484 ndev->type = ARPHRD_IEEE802154;
485 if (ieee802154_is_valid_extended_addr(extended_addr))
486 ieee802154_le64_to_be64(ndev->dev_addr, &extended_addr);
487 else
488 memcpy(ndev->dev_addr, ndev->perm_addr,
489 IEEE802154_EXTENDED_ADDR_LEN);
490 break;
491 case NL802154_IFTYPE_MONITOR:
492 ndev->type = ARPHRD_IEEE802154_MONITOR;
493 break;
494 default:
495 ret = -EINVAL;
496 goto err;
497 }
498
499 /* TODO check this */
500 SET_NETDEV_DEV(ndev, &local->phy->dev);
501 sdata = netdev_priv(ndev);
502 ndev->ieee802154_ptr = &sdata->wpan_dev;
503 memcpy(sdata->name, ndev->name, IFNAMSIZ);
504 sdata->dev = ndev;
505 sdata->wpan_dev.wpan_phy = local->hw.phy;
506 sdata->local = local;
507
508 /* setup type-dependent data */
509 ret = ieee802154_setup_sdata(sdata, type);
510 if (ret)
511 goto err;
512
513 if (ndev) {
514 ret = register_netdevice(ndev);
515 if (ret < 0)
516 goto err;
517 }
518
519 mutex_lock(&local->iflist_mtx);
520 list_add_tail_rcu(&sdata->list, &local->interfaces);
521 mutex_unlock(&local->iflist_mtx);
522
523 return ndev;
524
525err:
526 free_netdev(ndev);
527 return ERR_PTR(ret);
528}
529
530void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
531{
532 ASSERT_RTNL();
533
534 mutex_lock(&sdata->local->iflist_mtx);
535 list_del_rcu(&sdata->list);
536 mutex_unlock(&sdata->local->iflist_mtx);
537
538 synchronize_rcu();
539 unregister_netdevice(sdata->dev);
540}
541
542void ieee802154_remove_interfaces(struct ieee802154_local *local)
543{
544 struct ieee802154_sub_if_data *sdata, *tmp;
545
546 mutex_lock(&local->iflist_mtx);
547 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
548 list_del(&sdata->list);
549
550 unregister_netdevice(sdata->dev);
551 }
552 mutex_unlock(&local->iflist_mtx);
553}
554
555static int netdev_notify(struct notifier_block *nb,
556 unsigned long state, void *ptr)
557{
558 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
559 struct ieee802154_sub_if_data *sdata;
560
561 if (state != NETDEV_CHANGENAME)
562 return NOTIFY_DONE;
563
564 if (!dev->ieee802154_ptr || !dev->ieee802154_ptr->wpan_phy)
565 return NOTIFY_DONE;
566
567 if (dev->ieee802154_ptr->wpan_phy->privid != mac802154_wpan_phy_privid)
568 return NOTIFY_DONE;
569
570 sdata = IEEE802154_DEV_TO_SUB_IF(dev);
571 memcpy(sdata->name, dev->name, IFNAMSIZ);
572
573 return NOTIFY_OK;
574}
575
576static struct notifier_block mac802154_netdev_notifier = {
577 .notifier_call = netdev_notify,
578};
579
580int ieee802154_iface_init(void)
581{
582 return register_netdevice_notifier(&mac802154_netdev_notifier);
583}
584
585void ieee802154_iface_exit(void)
586{
587 unregister_netdevice_notifier(&mac802154_netdev_notifier);
588}
diff --git a/net/mac802154/llsec.c b/net/mac802154/llsec.c
index 457058142098..fa0d5237c2e0 100644
--- a/net/mac802154/llsec.c
+++ b/net/mac802154/llsec.c
@@ -17,10 +17,10 @@
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/bug.h> 18#include <linux/bug.h>
19#include <linux/completion.h> 19#include <linux/completion.h>
20#include <net/ieee802154.h> 20#include <linux/ieee802154.h>
21#include <crypto/algapi.h> 21#include <crypto/algapi.h>
22 22
23#include "mac802154.h" 23#include "ieee802154_i.h"
24#include "llsec.h" 24#include "llsec.h"
25 25
26static void llsec_key_put(struct mac802154_llsec_key *key); 26static void llsec_key_put(struct mac802154_llsec_key *key);
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index bf809131eef7..6aacb1816889 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by: 15 * Written by:
20 * Sergey Lapin <slapin@ossfans.org> 16 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
@@ -24,14 +20,14 @@
24 20
25#include <linux/skbuff.h> 21#include <linux/skbuff.h>
26#include <linux/if_arp.h> 22#include <linux/if_arp.h>
23#include <linux/ieee802154.h>
27 24
28#include <net/ieee802154.h>
29#include <net/ieee802154_netdev.h> 25#include <net/ieee802154_netdev.h>
30#include <net/wpan-phy.h> 26#include <net/cfg802154.h>
31#include <net/mac802154.h> 27#include <net/mac802154.h>
32#include <net/nl802154.h>
33 28
34#include "mac802154.h" 29#include "ieee802154_i.h"
30#include "driver-ops.h"
35 31
36static int mac802154_mlme_start_req(struct net_device *dev, 32static int mac802154_mlme_start_req(struct net_device *dev,
37 struct ieee802154_addr *addr, 33 struct ieee802154_addr *addr,
@@ -43,11 +39,12 @@ static int mac802154_mlme_start_req(struct net_device *dev,
43 struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev); 39 struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
44 int rc = 0; 40 int rc = 0;
45 41
42 ASSERT_RTNL();
43
46 BUG_ON(addr->mode != IEEE802154_ADDR_SHORT); 44 BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
47 45
48 mac802154_dev_set_pan_id(dev, addr->pan_id); 46 mac802154_dev_set_pan_id(dev, addr->pan_id);
49 mac802154_dev_set_short_addr(dev, addr->short_addr); 47 mac802154_dev_set_short_addr(dev, addr->short_addr);
50 mac802154_dev_set_ieee_addr(dev);
51 mac802154_dev_set_page_channel(dev, page, channel); 48 mac802154_dev_set_page_channel(dev, page, channel);
52 49
53 if (ops->llsec) { 50 if (ops->llsec) {
@@ -69,21 +66,71 @@ static int mac802154_mlme_start_req(struct net_device *dev,
69 rc = ops->llsec->set_params(dev, &params, changed); 66 rc = ops->llsec->set_params(dev, &params, changed);
70 } 67 }
71 68
72 /* FIXME: add validation for unused parameters to be sane
73 * for SoftMAC
74 */
75 ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
76
77 return rc; 69 return rc;
78} 70}
79 71
80static struct wpan_phy *mac802154_get_phy(const struct net_device *dev) 72static int mac802154_set_mac_params(struct net_device *dev,
73 const struct ieee802154_mac_params *params)
81{ 74{
82 struct mac802154_sub_if_data *priv = netdev_priv(dev); 75 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
76 struct ieee802154_local *local = sdata->local;
77 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
78 int ret;
79
80 ASSERT_RTNL();
81
82 /* PHY */
83 wpan_dev->wpan_phy->transmit_power = params->transmit_power;
84 wpan_dev->wpan_phy->cca_mode = params->cca_mode;
85 wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level;
86
87 /* MAC */
88 wpan_dev->min_be = params->min_be;
89 wpan_dev->max_be = params->max_be;
90 wpan_dev->csma_retries = params->csma_retries;
91 wpan_dev->frame_retries = params->frame_retries;
92 wpan_dev->lbt = params->lbt;
93
94 if (local->hw.flags & IEEE802154_HW_TXPOWER) {
95 ret = drv_set_tx_power(local, params->transmit_power);
96 if (ret < 0)
97 return ret;
98 }
99
100 if (local->hw.flags & IEEE802154_HW_CCA_MODE) {
101 ret = drv_set_cca_mode(local, params->cca_mode);
102 if (ret < 0)
103 return ret;
104 }
83 105
84 BUG_ON(dev->type != ARPHRD_IEEE802154); 106 if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) {
107 ret = drv_set_cca_ed_level(local, params->cca_ed_level);
108 if (ret < 0)
109 return ret;
110 }
111
112 return 0;
113}
85 114
86 return to_phy(get_device(&priv->hw->phy->dev)); 115static void mac802154_get_mac_params(struct net_device *dev,
116 struct ieee802154_mac_params *params)
117{
118 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
119 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
120
121 ASSERT_RTNL();
122
123 /* PHY */
124 params->transmit_power = wpan_dev->wpan_phy->transmit_power;
125 params->cca_mode = wpan_dev->wpan_phy->cca_mode;
126 params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level;
127
128 /* MAC */
129 params->min_be = wpan_dev->min_be;
130 params->max_be = wpan_dev->max_be;
131 params->csma_retries = wpan_dev->csma_retries;
132 params->frame_retries = wpan_dev->frame_retries;
133 params->lbt = wpan_dev->lbt;
87} 134}
88 135
89static struct ieee802154_llsec_ops mac802154_llsec_ops = { 136static struct ieee802154_llsec_ops mac802154_llsec_ops = {
@@ -102,12 +149,7 @@ static struct ieee802154_llsec_ops mac802154_llsec_ops = {
102 .unlock_table = mac802154_unlock_table, 149 .unlock_table = mac802154_unlock_table,
103}; 150};
104 151
105struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced = {
106 .get_phy = mac802154_get_phy,
107};
108
109struct ieee802154_mlme_ops mac802154_mlme_wpan = { 152struct ieee802154_mlme_ops mac802154_mlme_wpan = {
110 .get_phy = mac802154_get_phy,
111 .start_req = mac802154_mlme_start_req, 153 .start_req = mac802154_mlme_start_req,
112 .get_pan_id = mac802154_dev_get_pan_id, 154 .get_pan_id = mac802154_dev_get_pan_id,
113 .get_short_addr = mac802154_dev_get_short_addr, 155 .get_short_addr = mac802154_dev_get_short_addr,
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
new file mode 100644
index 000000000000..8500378c8318
--- /dev/null
+++ b/net/mac802154/main.c
@@ -0,0 +1,217 @@
1/*
2 * Copyright (C) 2007-2012 Siemens AG
3 *
4 * Written by:
5 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/netdevice.h>
20
21#include <net/netlink.h>
22#include <net/nl802154.h>
23#include <net/mac802154.h>
24#include <net/ieee802154_netdev.h>
25#include <net/route.h>
26#include <net/cfg802154.h>
27
28#include "ieee802154_i.h"
29#include "cfg.h"
30
31static void ieee802154_tasklet_handler(unsigned long data)
32{
33 struct ieee802154_local *local = (struct ieee802154_local *)data;
34 struct sk_buff *skb;
35
36 while ((skb = skb_dequeue(&local->skb_queue))) {
37 switch (skb->pkt_type) {
38 case IEEE802154_RX_MSG:
39 /* Clear skb->pkt_type in order to not confuse kernel
40 * netstack.
41 */
42 skb->pkt_type = 0;
43 ieee802154_rx(&local->hw, skb);
44 break;
45 default:
46 WARN(1, "mac802154: Packet is of unknown type %d\n",
47 skb->pkt_type);
48 kfree_skb(skb);
49 break;
50 }
51 }
52}
53
54struct ieee802154_hw *
55ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
56{
57 struct wpan_phy *phy;
58 struct ieee802154_local *local;
59 size_t priv_size;
60
61 if (!ops || !(ops->xmit_async || ops->xmit_sync) || !ops->ed ||
62 !ops->start || !ops->stop || !ops->set_channel) {
63 pr_err("undefined IEEE802.15.4 device operations\n");
64 return NULL;
65 }
66
67 /* Ensure 32-byte alignment of our private data and hw private data.
68 * We use the wpan_phy priv data for both our ieee802154_local and for
69 * the driver's private data
70 *
71 * in memory it'll be like this:
72 *
73 * +-------------------------+
74 * | struct wpan_phy |
75 * +-------------------------+
76 * | struct ieee802154_local |
77 * +-------------------------+
78 * | driver's private data |
79 * +-------------------------+
80 *
81 * Due to ieee802154 layer isn't aware of driver and MAC structures,
82 * so lets align them here.
83 */
84
85 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
86
87 phy = wpan_phy_new(&mac802154_config_ops, priv_size);
88 if (!phy) {
89 pr_err("failure to allocate master IEEE802.15.4 device\n");
90 return NULL;
91 }
92
93 phy->privid = mac802154_wpan_phy_privid;
94
95 local = wpan_phy_priv(phy);
96 local->phy = phy;
97 local->hw.phy = local->phy;
98 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
99 local->ops = ops;
100
101 INIT_LIST_HEAD(&local->interfaces);
102 mutex_init(&local->iflist_mtx);
103
104 tasklet_init(&local->tasklet,
105 ieee802154_tasklet_handler,
106 (unsigned long)local);
107
108 skb_queue_head_init(&local->skb_queue);
109
110 return &local->hw;
111}
112EXPORT_SYMBOL(ieee802154_alloc_hw);
113
114void ieee802154_free_hw(struct ieee802154_hw *hw)
115{
116 struct ieee802154_local *local = hw_to_local(hw);
117
118 BUG_ON(!list_empty(&local->interfaces));
119
120 mutex_destroy(&local->iflist_mtx);
121
122 wpan_phy_free(local->phy);
123}
124EXPORT_SYMBOL(ieee802154_free_hw);
125
126static void ieee802154_setup_wpan_phy_pib(struct wpan_phy *wpan_phy)
127{
128 /* TODO warn on empty symbol_duration
129 * Should be done when all drivers sets this value.
130 */
131
132 wpan_phy->lifs_period = IEEE802154_LIFS_PERIOD *
133 wpan_phy->symbol_duration;
134 wpan_phy->sifs_period = IEEE802154_SIFS_PERIOD *
135 wpan_phy->symbol_duration;
136}
137
138int ieee802154_register_hw(struct ieee802154_hw *hw)
139{
140 struct ieee802154_local *local = hw_to_local(hw);
141 struct net_device *dev;
142 int rc = -ENOSYS;
143
144 local->workqueue =
145 create_singlethread_workqueue(wpan_phy_name(local->phy));
146 if (!local->workqueue) {
147 rc = -ENOMEM;
148 goto out;
149 }
150
151 hrtimer_init(&local->ifs_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
152 local->ifs_timer.function = ieee802154_xmit_ifs_timer;
153
154 wpan_phy_set_dev(local->phy, local->hw.parent);
155
156 ieee802154_setup_wpan_phy_pib(local->phy);
157
158 rc = wpan_phy_register(local->phy);
159 if (rc < 0)
160 goto out_wq;
161
162 rtnl_lock();
163
164 dev = ieee802154_if_add(local, "wpan%d", NL802154_IFTYPE_NODE,
165 cpu_to_le64(0x0000000000000000ULL));
166 if (IS_ERR(dev)) {
167 rtnl_unlock();
168 rc = PTR_ERR(dev);
169 goto out_wq;
170 }
171
172 rtnl_unlock();
173
174 return 0;
175
176out_wq:
177 destroy_workqueue(local->workqueue);
178out:
179 return rc;
180}
181EXPORT_SYMBOL(ieee802154_register_hw);
182
183void ieee802154_unregister_hw(struct ieee802154_hw *hw)
184{
185 struct ieee802154_local *local = hw_to_local(hw);
186
187 tasklet_kill(&local->tasklet);
188 flush_workqueue(local->workqueue);
189 destroy_workqueue(local->workqueue);
190
191 rtnl_lock();
192
193 ieee802154_remove_interfaces(local);
194
195 rtnl_unlock();
196
197 wpan_phy_unregister(local->phy);
198}
199EXPORT_SYMBOL(ieee802154_unregister_hw);
200
201static int __init ieee802154_init(void)
202{
203 return ieee802154_iface_init();
204}
205
206static void __exit ieee802154_exit(void)
207{
208 ieee802154_iface_exit();
209
210 rcu_barrier();
211}
212
213subsys_initcall(ieee802154_init);
214module_exit(ieee802154_exit);
215
216MODULE_DESCRIPTION("IEEE 802.15.4 subsystem");
217MODULE_LICENSE("GPL v2");
diff --git a/net/mac802154/mib.c b/net/mac802154/mib.c
index 868a040fd422..3596b29ead6b 100644
--- a/net/mac802154/mib.c
+++ b/net/mac802154/mib.c
@@ -10,10 +10,6 @@
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by: 13 * Written by:
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 14 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Sergey Lapin <slapin@ossfans.org> 15 * Sergey Lapin <slapin@ossfans.org>
@@ -25,193 +21,86 @@
25 21
26#include <net/mac802154.h> 22#include <net/mac802154.h>
27#include <net/ieee802154_netdev.h> 23#include <net/ieee802154_netdev.h>
28#include <net/wpan-phy.h> 24#include <net/cfg802154.h>
29
30#include "mac802154.h"
31
32struct phy_chan_notify_work {
33 struct work_struct work;
34 struct net_device *dev;
35};
36
37struct hw_addr_filt_notify_work {
38 struct work_struct work;
39 struct net_device *dev;
40 unsigned long changed;
41};
42
43static struct mac802154_priv *mac802154_slave_get_priv(struct net_device *dev)
44{
45 struct mac802154_sub_if_data *priv = netdev_priv(dev);
46 25
47 BUG_ON(dev->type != ARPHRD_IEEE802154); 26#include "ieee802154_i.h"
48 27#include "driver-ops.h"
49 return priv->hw;
50}
51
52static void hw_addr_notify(struct work_struct *work)
53{
54 struct hw_addr_filt_notify_work *nw = container_of(work,
55 struct hw_addr_filt_notify_work, work);
56 struct mac802154_priv *hw = mac802154_slave_get_priv(nw->dev);
57 int res;
58
59 res = hw->ops->set_hw_addr_filt(&hw->hw,
60 &hw->hw.hw_filt,
61 nw->changed);
62 if (res)
63 pr_debug("failed changed mask %lx\n", nw->changed);
64
65 kfree(nw);
66}
67
68static void set_hw_addr_filt(struct net_device *dev, unsigned long changed)
69{
70 struct mac802154_sub_if_data *priv = netdev_priv(dev);
71 struct hw_addr_filt_notify_work *work;
72
73 work = kzalloc(sizeof(*work), GFP_ATOMIC);
74 if (!work)
75 return;
76
77 INIT_WORK(&work->work, hw_addr_notify);
78 work->dev = dev;
79 work->changed = changed;
80 queue_work(priv->hw->dev_workqueue, &work->work);
81}
82 28
83void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val) 29void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val)
84{ 30{
85 struct mac802154_sub_if_data *priv = netdev_priv(dev); 31 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
86 32
87 BUG_ON(dev->type != ARPHRD_IEEE802154); 33 BUG_ON(dev->type != ARPHRD_IEEE802154);
88 34
89 spin_lock_bh(&priv->mib_lock); 35 spin_lock_bh(&sdata->mib_lock);
90 priv->short_addr = val; 36 sdata->wpan_dev.short_addr = val;
91 spin_unlock_bh(&priv->mib_lock); 37 spin_unlock_bh(&sdata->mib_lock);
92
93 if ((priv->hw->ops->set_hw_addr_filt) &&
94 (priv->hw->hw.hw_filt.short_addr != priv->short_addr)) {
95 priv->hw->hw.hw_filt.short_addr = priv->short_addr;
96 set_hw_addr_filt(dev, IEEE802515_AFILT_SADDR_CHANGED);
97 }
98} 38}
99 39
100__le16 mac802154_dev_get_short_addr(const struct net_device *dev) 40__le16 mac802154_dev_get_short_addr(const struct net_device *dev)
101{ 41{
102 struct mac802154_sub_if_data *priv = netdev_priv(dev); 42 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
103 __le16 ret; 43 __le16 ret;
104 44
105 BUG_ON(dev->type != ARPHRD_IEEE802154); 45 BUG_ON(dev->type != ARPHRD_IEEE802154);
106 46
107 spin_lock_bh(&priv->mib_lock); 47 spin_lock_bh(&sdata->mib_lock);
108 ret = priv->short_addr; 48 ret = sdata->wpan_dev.short_addr;
109 spin_unlock_bh(&priv->mib_lock); 49 spin_unlock_bh(&sdata->mib_lock);
110 50
111 return ret; 51 return ret;
112} 52}
113 53
114void mac802154_dev_set_ieee_addr(struct net_device *dev)
115{
116 struct mac802154_sub_if_data *priv = netdev_priv(dev);
117 struct mac802154_priv *mac = priv->hw;
118
119 priv->extended_addr = ieee802154_devaddr_from_raw(dev->dev_addr);
120
121 if (mac->ops->set_hw_addr_filt &&
122 mac->hw.hw_filt.ieee_addr != priv->extended_addr) {
123 mac->hw.hw_filt.ieee_addr = priv->extended_addr;
124 set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED);
125 }
126}
127
128__le16 mac802154_dev_get_pan_id(const struct net_device *dev) 54__le16 mac802154_dev_get_pan_id(const struct net_device *dev)
129{ 55{
130 struct mac802154_sub_if_data *priv = netdev_priv(dev); 56 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
131 __le16 ret; 57 __le16 ret;
132 58
133 BUG_ON(dev->type != ARPHRD_IEEE802154); 59 BUG_ON(dev->type != ARPHRD_IEEE802154);
134 60
135 spin_lock_bh(&priv->mib_lock); 61 spin_lock_bh(&sdata->mib_lock);
136 ret = priv->pan_id; 62 ret = sdata->wpan_dev.pan_id;
137 spin_unlock_bh(&priv->mib_lock); 63 spin_unlock_bh(&sdata->mib_lock);
138 64
139 return ret; 65 return ret;
140} 66}
141 67
142void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val) 68void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)
143{ 69{
144 struct mac802154_sub_if_data *priv = netdev_priv(dev); 70 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
145 71
146 BUG_ON(dev->type != ARPHRD_IEEE802154); 72 BUG_ON(dev->type != ARPHRD_IEEE802154);
147 73
148 spin_lock_bh(&priv->mib_lock); 74 spin_lock_bh(&sdata->mib_lock);
149 priv->pan_id = val; 75 sdata->wpan_dev.pan_id = val;
150 spin_unlock_bh(&priv->mib_lock); 76 spin_unlock_bh(&sdata->mib_lock);
151
152 if ((priv->hw->ops->set_hw_addr_filt) &&
153 (priv->hw->hw.hw_filt.pan_id != priv->pan_id)) {
154 priv->hw->hw.hw_filt.pan_id = priv->pan_id;
155 set_hw_addr_filt(dev, IEEE802515_AFILT_PANID_CHANGED);
156 }
157} 77}
158 78
159u8 mac802154_dev_get_dsn(const struct net_device *dev) 79u8 mac802154_dev_get_dsn(const struct net_device *dev)
160{ 80{
161 struct mac802154_sub_if_data *priv = netdev_priv(dev); 81 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
162 82
163 BUG_ON(dev->type != ARPHRD_IEEE802154); 83 BUG_ON(dev->type != ARPHRD_IEEE802154);
164 84
165 return priv->dsn++; 85 return sdata->wpan_dev.dsn++;
166}
167
168static void phy_chan_notify(struct work_struct *work)
169{
170 struct phy_chan_notify_work *nw = container_of(work,
171 struct phy_chan_notify_work, work);
172 struct mac802154_priv *hw = mac802154_slave_get_priv(nw->dev);
173 struct mac802154_sub_if_data *priv = netdev_priv(nw->dev);
174 int res;
175
176 mutex_lock(&priv->hw->phy->pib_lock);
177 res = hw->ops->set_channel(&hw->hw, priv->page, priv->chan);
178 if (res) {
179 pr_debug("set_channel failed\n");
180 } else {
181 priv->hw->phy->current_channel = priv->chan;
182 priv->hw->phy->current_page = priv->page;
183 }
184 mutex_unlock(&priv->hw->phy->pib_lock);
185
186 kfree(nw);
187} 86}
188 87
189void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan) 88void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
190{ 89{
191 struct mac802154_sub_if_data *priv = netdev_priv(dev); 90 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
192 struct phy_chan_notify_work *work; 91 struct ieee802154_local *local = sdata->local;
92 int res;
193 93
194 BUG_ON(dev->type != ARPHRD_IEEE802154); 94 BUG_ON(dev->type != ARPHRD_IEEE802154);
195 95
196 spin_lock_bh(&priv->mib_lock); 96 res = drv_set_channel(local, page, chan);
197 priv->page = page; 97 if (res) {
198 priv->chan = chan; 98 pr_debug("set_channel failed\n");
199 spin_unlock_bh(&priv->mib_lock);
200
201 mutex_lock(&priv->hw->phy->pib_lock);
202 if (priv->hw->phy->current_channel != priv->chan ||
203 priv->hw->phy->current_page != priv->page) {
204 mutex_unlock(&priv->hw->phy->pib_lock);
205
206 work = kzalloc(sizeof(*work), GFP_ATOMIC);
207 if (!work)
208 return;
209
210 INIT_WORK(&work->work, phy_chan_notify);
211 work->dev = dev;
212 queue_work(priv->hw->dev_workqueue, &work->work);
213 } else { 99 } else {
214 mutex_unlock(&priv->hw->phy->pib_lock); 100 mutex_lock(&local->phy->pib_lock);
101 local->phy->current_channel = chan;
102 local->phy->current_page = page;
103 mutex_unlock(&local->phy->pib_lock);
215 } 104 }
216} 105}
217 106
@@ -219,14 +108,14 @@ void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
219int mac802154_get_params(struct net_device *dev, 108int mac802154_get_params(struct net_device *dev,
220 struct ieee802154_llsec_params *params) 109 struct ieee802154_llsec_params *params)
221{ 110{
222 struct mac802154_sub_if_data *priv = netdev_priv(dev); 111 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
223 int res; 112 int res;
224 113
225 BUG_ON(dev->type != ARPHRD_IEEE802154); 114 BUG_ON(dev->type != ARPHRD_IEEE802154);
226 115
227 mutex_lock(&priv->sec_mtx); 116 mutex_lock(&sdata->sec_mtx);
228 res = mac802154_llsec_get_params(&priv->sec, params); 117 res = mac802154_llsec_get_params(&sdata->sec, params);
229 mutex_unlock(&priv->sec_mtx); 118 mutex_unlock(&sdata->sec_mtx);
230 119
231 return res; 120 return res;
232} 121}
@@ -235,14 +124,14 @@ int mac802154_set_params(struct net_device *dev,
235 const struct ieee802154_llsec_params *params, 124 const struct ieee802154_llsec_params *params,
236 int changed) 125 int changed)
237{ 126{
238 struct mac802154_sub_if_data *priv = netdev_priv(dev); 127 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
239 int res; 128 int res;
240 129
241 BUG_ON(dev->type != ARPHRD_IEEE802154); 130 BUG_ON(dev->type != ARPHRD_IEEE802154);
242 131
243 mutex_lock(&priv->sec_mtx); 132 mutex_lock(&sdata->sec_mtx);
244 res = mac802154_llsec_set_params(&priv->sec, params, changed); 133 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
245 mutex_unlock(&priv->sec_mtx); 134 mutex_unlock(&sdata->sec_mtx);
246 135
247 return res; 136 return res;
248} 137}
@@ -252,14 +141,14 @@ int mac802154_add_key(struct net_device *dev,
252 const struct ieee802154_llsec_key_id *id, 141 const struct ieee802154_llsec_key_id *id,
253 const struct ieee802154_llsec_key *key) 142 const struct ieee802154_llsec_key *key)
254{ 143{
255 struct mac802154_sub_if_data *priv = netdev_priv(dev); 144 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
256 int res; 145 int res;
257 146
258 BUG_ON(dev->type != ARPHRD_IEEE802154); 147 BUG_ON(dev->type != ARPHRD_IEEE802154);
259 148
260 mutex_lock(&priv->sec_mtx); 149 mutex_lock(&sdata->sec_mtx);
261 res = mac802154_llsec_key_add(&priv->sec, id, key); 150 res = mac802154_llsec_key_add(&sdata->sec, id, key);
262 mutex_unlock(&priv->sec_mtx); 151 mutex_unlock(&sdata->sec_mtx);
263 152
264 return res; 153 return res;
265} 154}
@@ -267,14 +156,14 @@ int mac802154_add_key(struct net_device *dev,
267int mac802154_del_key(struct net_device *dev, 156int mac802154_del_key(struct net_device *dev,
268 const struct ieee802154_llsec_key_id *id) 157 const struct ieee802154_llsec_key_id *id)
269{ 158{
270 struct mac802154_sub_if_data *priv = netdev_priv(dev); 159 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
271 int res; 160 int res;
272 161
273 BUG_ON(dev->type != ARPHRD_IEEE802154); 162 BUG_ON(dev->type != ARPHRD_IEEE802154);
274 163
275 mutex_lock(&priv->sec_mtx); 164 mutex_lock(&sdata->sec_mtx);
276 res = mac802154_llsec_key_del(&priv->sec, id); 165 res = mac802154_llsec_key_del(&sdata->sec, id);
277 mutex_unlock(&priv->sec_mtx); 166 mutex_unlock(&sdata->sec_mtx);
278 167
279 return res; 168 return res;
280} 169}
@@ -283,28 +172,28 @@ int mac802154_del_key(struct net_device *dev,
283int mac802154_add_dev(struct net_device *dev, 172int mac802154_add_dev(struct net_device *dev,
284 const struct ieee802154_llsec_device *llsec_dev) 173 const struct ieee802154_llsec_device *llsec_dev)
285{ 174{
286 struct mac802154_sub_if_data *priv = netdev_priv(dev); 175 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
287 int res; 176 int res;
288 177
289 BUG_ON(dev->type != ARPHRD_IEEE802154); 178 BUG_ON(dev->type != ARPHRD_IEEE802154);
290 179
291 mutex_lock(&priv->sec_mtx); 180 mutex_lock(&sdata->sec_mtx);
292 res = mac802154_llsec_dev_add(&priv->sec, llsec_dev); 181 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
293 mutex_unlock(&priv->sec_mtx); 182 mutex_unlock(&sdata->sec_mtx);
294 183
295 return res; 184 return res;
296} 185}
297 186
298int mac802154_del_dev(struct net_device *dev, __le64 dev_addr) 187int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
299{ 188{
300 struct mac802154_sub_if_data *priv = netdev_priv(dev); 189 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
301 int res; 190 int res;
302 191
303 BUG_ON(dev->type != ARPHRD_IEEE802154); 192 BUG_ON(dev->type != ARPHRD_IEEE802154);
304 193
305 mutex_lock(&priv->sec_mtx); 194 mutex_lock(&sdata->sec_mtx);
306 res = mac802154_llsec_dev_del(&priv->sec, dev_addr); 195 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
307 mutex_unlock(&priv->sec_mtx); 196 mutex_unlock(&sdata->sec_mtx);
308 197
309 return res; 198 return res;
310} 199}
@@ -314,14 +203,14 @@ int mac802154_add_devkey(struct net_device *dev,
314 __le64 device_addr, 203 __le64 device_addr,
315 const struct ieee802154_llsec_device_key *key) 204 const struct ieee802154_llsec_device_key *key)
316{ 205{
317 struct mac802154_sub_if_data *priv = netdev_priv(dev); 206 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
318 int res; 207 int res;
319 208
320 BUG_ON(dev->type != ARPHRD_IEEE802154); 209 BUG_ON(dev->type != ARPHRD_IEEE802154);
321 210
322 mutex_lock(&priv->sec_mtx); 211 mutex_lock(&sdata->sec_mtx);
323 res = mac802154_llsec_devkey_add(&priv->sec, device_addr, key); 212 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
324 mutex_unlock(&priv->sec_mtx); 213 mutex_unlock(&sdata->sec_mtx);
325 214
326 return res; 215 return res;
327} 216}
@@ -330,14 +219,14 @@ int mac802154_del_devkey(struct net_device *dev,
330 __le64 device_addr, 219 __le64 device_addr,
331 const struct ieee802154_llsec_device_key *key) 220 const struct ieee802154_llsec_device_key *key)
332{ 221{
333 struct mac802154_sub_if_data *priv = netdev_priv(dev); 222 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
334 int res; 223 int res;
335 224
336 BUG_ON(dev->type != ARPHRD_IEEE802154); 225 BUG_ON(dev->type != ARPHRD_IEEE802154);
337 226
338 mutex_lock(&priv->sec_mtx); 227 mutex_lock(&sdata->sec_mtx);
339 res = mac802154_llsec_devkey_del(&priv->sec, device_addr, key); 228 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
340 mutex_unlock(&priv->sec_mtx); 229 mutex_unlock(&sdata->sec_mtx);
341 230
342 return res; 231 return res;
343} 232}
@@ -346,14 +235,14 @@ int mac802154_del_devkey(struct net_device *dev,
346int mac802154_add_seclevel(struct net_device *dev, 235int mac802154_add_seclevel(struct net_device *dev,
347 const struct ieee802154_llsec_seclevel *sl) 236 const struct ieee802154_llsec_seclevel *sl)
348{ 237{
349 struct mac802154_sub_if_data *priv = netdev_priv(dev); 238 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
350 int res; 239 int res;
351 240
352 BUG_ON(dev->type != ARPHRD_IEEE802154); 241 BUG_ON(dev->type != ARPHRD_IEEE802154);
353 242
354 mutex_lock(&priv->sec_mtx); 243 mutex_lock(&sdata->sec_mtx);
355 res = mac802154_llsec_seclevel_add(&priv->sec, sl); 244 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
356 mutex_unlock(&priv->sec_mtx); 245 mutex_unlock(&sdata->sec_mtx);
357 246
358 return res; 247 return res;
359} 248}
@@ -361,14 +250,14 @@ int mac802154_add_seclevel(struct net_device *dev,
361int mac802154_del_seclevel(struct net_device *dev, 250int mac802154_del_seclevel(struct net_device *dev,
362 const struct ieee802154_llsec_seclevel *sl) 251 const struct ieee802154_llsec_seclevel *sl)
363{ 252{
364 struct mac802154_sub_if_data *priv = netdev_priv(dev); 253 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
365 int res; 254 int res;
366 255
367 BUG_ON(dev->type != ARPHRD_IEEE802154); 256 BUG_ON(dev->type != ARPHRD_IEEE802154);
368 257
369 mutex_lock(&priv->sec_mtx); 258 mutex_lock(&sdata->sec_mtx);
370 res = mac802154_llsec_seclevel_del(&priv->sec, sl); 259 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
371 mutex_unlock(&priv->sec_mtx); 260 mutex_unlock(&sdata->sec_mtx);
372 261
373 return res; 262 return res;
374} 263}
@@ -376,28 +265,28 @@ int mac802154_del_seclevel(struct net_device *dev,
376 265
377void mac802154_lock_table(struct net_device *dev) 266void mac802154_lock_table(struct net_device *dev)
378{ 267{
379 struct mac802154_sub_if_data *priv = netdev_priv(dev); 268 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
380 269
381 BUG_ON(dev->type != ARPHRD_IEEE802154); 270 BUG_ON(dev->type != ARPHRD_IEEE802154);
382 271
383 mutex_lock(&priv->sec_mtx); 272 mutex_lock(&sdata->sec_mtx);
384} 273}
385 274
386void mac802154_get_table(struct net_device *dev, 275void mac802154_get_table(struct net_device *dev,
387 struct ieee802154_llsec_table **t) 276 struct ieee802154_llsec_table **t)
388{ 277{
389 struct mac802154_sub_if_data *priv = netdev_priv(dev); 278 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
390 279
391 BUG_ON(dev->type != ARPHRD_IEEE802154); 280 BUG_ON(dev->type != ARPHRD_IEEE802154);
392 281
393 *t = &priv->sec.table; 282 *t = &sdata->sec.table;
394} 283}
395 284
396void mac802154_unlock_table(struct net_device *dev) 285void mac802154_unlock_table(struct net_device *dev)
397{ 286{
398 struct mac802154_sub_if_data *priv = netdev_priv(dev); 287 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
399 288
400 BUG_ON(dev->type != ARPHRD_IEEE802154); 289 BUG_ON(dev->type != ARPHRD_IEEE802154);
401 290
402 mutex_unlock(&priv->sec_mtx); 291 mutex_unlock(&sdata->sec_mtx);
403} 292}
diff --git a/net/mac802154/monitor.c b/net/mac802154/monitor.c
deleted file mode 100644
index a68230e2b25f..000000000000
--- a/net/mac802154/monitor.c
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 * Copyright 2007, 2008, 2009 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by:
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Sergey Lapin <slapin@ossfans.org>
20 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
22 */
23
24#include <linux/netdevice.h>
25#include <linux/skbuff.h>
26#include <linux/if_arp.h>
27#include <linux/crc-ccitt.h>
28
29#include <net/ieee802154.h>
30#include <net/mac802154.h>
31#include <net/netlink.h>
32#include <net/wpan-phy.h>
33#include <linux/nl802154.h>
34
35#include "mac802154.h"
36
37static netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb,
38 struct net_device *dev)
39{
40 struct mac802154_sub_if_data *priv;
41 u8 chan, page;
42
43 priv = netdev_priv(dev);
44
45 /* FIXME: locking */
46 chan = priv->hw->phy->current_channel;
47 page = priv->hw->phy->current_page;
48
49 if (chan == MAC802154_CHAN_NONE) /* not initialized */
50 return NETDEV_TX_OK;
51
52 if (WARN_ON(page >= WPAN_NUM_PAGES) ||
53 WARN_ON(chan >= WPAN_NUM_CHANNELS))
54 return NETDEV_TX_OK;
55
56 skb->skb_iif = dev->ifindex;
57 dev->stats.tx_packets++;
58 dev->stats.tx_bytes += skb->len;
59
60 return mac802154_tx(priv->hw, skb, page, chan);
61}
62
63
64void mac802154_monitors_rx(struct mac802154_priv *priv, struct sk_buff *skb)
65{
66 struct sk_buff *skb2;
67 struct mac802154_sub_if_data *sdata;
68 u16 crc = crc_ccitt(0, skb->data, skb->len);
69 u8 *data;
70
71 rcu_read_lock();
72 list_for_each_entry_rcu(sdata, &priv->slaves, list) {
73 if (sdata->type != IEEE802154_DEV_MONITOR ||
74 !netif_running(sdata->dev))
75 continue;
76
77 skb2 = skb_clone(skb, GFP_ATOMIC);
78 skb2->dev = sdata->dev;
79 skb2->pkt_type = PACKET_HOST;
80 data = skb_put(skb2, 2);
81 data[0] = crc & 0xff;
82 data[1] = crc >> 8;
83
84 netif_rx_ni(skb2);
85 }
86 rcu_read_unlock();
87}
88
89static const struct net_device_ops mac802154_monitor_ops = {
90 .ndo_open = mac802154_slave_open,
91 .ndo_stop = mac802154_slave_close,
92 .ndo_start_xmit = mac802154_monitor_xmit,
93};
94
95void mac802154_monitor_setup(struct net_device *dev)
96{
97 struct mac802154_sub_if_data *priv;
98
99 dev->addr_len = 0;
100 dev->hard_header_len = 0;
101 dev->needed_tailroom = 2; /* room for FCS */
102 dev->mtu = IEEE802154_MTU;
103 dev->tx_queue_len = 10;
104 dev->type = ARPHRD_IEEE802154_MONITOR;
105 dev->flags = IFF_NOARP | IFF_BROADCAST;
106 dev->watchdog_timeo = 0;
107
108 dev->destructor = free_netdev;
109 dev->netdev_ops = &mac802154_monitor_ops;
110 dev->ml_priv = &mac802154_mlme_reduced;
111
112 priv = netdev_priv(dev);
113 priv->type = IEEE802154_DEV_MONITOR;
114
115 priv->chan = MAC802154_CHAN_NONE; /* not initialized */
116 priv->page = 0;
117}
diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c
index a14cf9ede171..041dbd5958d4 100644
--- a/net/mac802154/rx.c
+++ b/net/mac802154/rx.c
@@ -10,10 +10,6 @@
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by: 13 * Written by:
18 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 14 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
19 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 15 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
@@ -23,92 +19,285 @@
23 19
24#include <linux/kernel.h> 20#include <linux/kernel.h>
25#include <linux/module.h> 21#include <linux/module.h>
26#include <linux/workqueue.h>
27#include <linux/netdevice.h> 22#include <linux/netdevice.h>
28#include <linux/crc-ccitt.h> 23#include <linux/crc-ccitt.h>
24#include <asm/unaligned.h>
29 25
30#include <net/mac802154.h> 26#include <net/mac802154.h>
31#include <net/ieee802154_netdev.h> 27#include <net/ieee802154_netdev.h>
28#include <net/nl802154.h>
32 29
33#include "mac802154.h" 30#include "ieee802154_i.h"
34 31
35/* The IEEE 802.15.4 standard defines 4 MAC packet types: 32static int ieee802154_deliver_skb(struct sk_buff *skb)
36 * - beacon frame 33{
37 * - MAC command frame 34 skb->ip_summed = CHECKSUM_UNNECESSARY;
38 * - acknowledgement frame 35 skb->protocol = htons(ETH_P_IEEE802154);
39 * - data frame
40 *
41 * and only the data frame should be pushed to the upper layers, other types
42 * are just internal MAC layer management information. So only data packets
43 * are going to be sent to the networking queue, all other will be processed
44 * right here by using the device workqueue.
45 */
46struct rx_work {
47 struct sk_buff *skb;
48 struct work_struct work;
49 struct ieee802154_dev *dev;
50 u8 lqi;
51};
52 36
53static void 37 return netif_receive_skb(skb);
54mac802154_subif_rx(struct ieee802154_dev *hw, struct sk_buff *skb, u8 lqi) 38}
39
40static int
41ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
42 struct sk_buff *skb, const struct ieee802154_hdr *hdr)
55{ 43{
56 struct mac802154_priv *priv = mac802154_to_priv(hw); 44 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
45 __le16 span, sshort;
46 int rc;
57 47
58 mac_cb(skb)->lqi = lqi; 48 pr_debug("getting packet via slave interface %s\n", sdata->dev->name);
59 skb->protocol = htons(ETH_P_IEEE802154);
60 skb_reset_mac_header(skb);
61 49
62 if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { 50 spin_lock_bh(&sdata->mib_lock);
63 u16 crc;
64 51
65 if (skb->len < 2) { 52 span = wpan_dev->pan_id;
66 pr_debug("got invalid frame\n"); 53 sshort = wpan_dev->short_addr;
67 goto fail; 54
68 } 55 switch (mac_cb(skb)->dest.mode) {
69 crc = crc_ccitt(0, skb->data, skb->len); 56 case IEEE802154_ADDR_NONE:
70 if (crc) { 57 if (mac_cb(skb)->dest.mode != IEEE802154_ADDR_NONE)
71 pr_debug("CRC mismatch\n"); 58 /* FIXME: check if we are PAN coordinator */
72 goto fail; 59 skb->pkt_type = PACKET_OTHERHOST;
73 } 60 else
74 skb_trim(skb, skb->len - 2); /* CRC */ 61 /* ACK comes with both addresses empty */
62 skb->pkt_type = PACKET_HOST;
63 break;
64 case IEEE802154_ADDR_LONG:
65 if (mac_cb(skb)->dest.pan_id != span &&
66 mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST))
67 skb->pkt_type = PACKET_OTHERHOST;
68 else if (mac_cb(skb)->dest.extended_addr == wpan_dev->extended_addr)
69 skb->pkt_type = PACKET_HOST;
70 else
71 skb->pkt_type = PACKET_OTHERHOST;
72 break;
73 case IEEE802154_ADDR_SHORT:
74 if (mac_cb(skb)->dest.pan_id != span &&
75 mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST))
76 skb->pkt_type = PACKET_OTHERHOST;
77 else if (mac_cb(skb)->dest.short_addr == sshort)
78 skb->pkt_type = PACKET_HOST;
79 else if (mac_cb(skb)->dest.short_addr ==
80 cpu_to_le16(IEEE802154_ADDR_BROADCAST))
81 skb->pkt_type = PACKET_BROADCAST;
82 else
83 skb->pkt_type = PACKET_OTHERHOST;
84 break;
85 default:
86 spin_unlock_bh(&sdata->mib_lock);
87 pr_debug("invalid dest mode\n");
88 kfree_skb(skb);
89 return NET_RX_DROP;
75 } 90 }
76 91
77 mac802154_monitors_rx(priv, skb); 92 spin_unlock_bh(&sdata->mib_lock);
78 mac802154_wpans_rx(priv, skb);
79 93
80 return; 94 skb->dev = sdata->dev;
95
96 rc = mac802154_llsec_decrypt(&sdata->sec, skb);
97 if (rc) {
98 pr_debug("decryption failed: %i\n", rc);
99 goto fail;
100 }
101
102 sdata->dev->stats.rx_packets++;
103 sdata->dev->stats.rx_bytes += skb->len;
104
105 switch (mac_cb(skb)->type) {
106 case IEEE802154_FC_TYPE_DATA:
107 return ieee802154_deliver_skb(skb);
108 default:
109 pr_warn("ieee802154: bad frame received (type = %d)\n",
110 mac_cb(skb)->type);
111 goto fail;
112 }
81 113
82fail: 114fail:
83 kfree_skb(skb); 115 kfree_skb(skb);
116 return NET_RX_DROP;
84} 117}
85 118
86static void mac802154_rx_worker(struct work_struct *work) 119static void
120ieee802154_print_addr(const char *name, const struct ieee802154_addr *addr)
87{ 121{
88 struct rx_work *rw = container_of(work, struct rx_work, work); 122 if (addr->mode == IEEE802154_ADDR_NONE)
123 pr_debug("%s not present\n", name);
124
125 pr_debug("%s PAN ID: %04x\n", name, le16_to_cpu(addr->pan_id));
126 if (addr->mode == IEEE802154_ADDR_SHORT) {
127 pr_debug("%s is short: %04x\n", name,
128 le16_to_cpu(addr->short_addr));
129 } else {
130 u64 hw = swab64((__force u64)addr->extended_addr);
89 131
90 mac802154_subif_rx(rw->dev, rw->skb, rw->lqi); 132 pr_debug("%s is hardware: %8phC\n", name, &hw);
91 kfree(rw); 133 }
92} 134}
93 135
94void 136static int
95ieee802154_rx_irqsafe(struct ieee802154_dev *dev, struct sk_buff *skb, u8 lqi) 137ieee802154_parse_frame_start(struct sk_buff *skb, struct ieee802154_hdr *hdr)
96{ 138{
97 struct mac802154_priv *priv = mac802154_to_priv(dev); 139 int hlen;
98 struct rx_work *work; 140 struct ieee802154_mac_cb *cb = mac_cb_init(skb);
99 141
100 if (!skb) 142 skb_reset_mac_header(skb);
101 return; 143
144 hlen = ieee802154_hdr_pull(skb, hdr);
145 if (hlen < 0)
146 return -EINVAL;
147
148 skb->mac_len = hlen;
149
150 pr_debug("fc: %04x dsn: %02x\n", le16_to_cpup((__le16 *)&hdr->fc),
151 hdr->seq);
152
153 cb->type = hdr->fc.type;
154 cb->ackreq = hdr->fc.ack_request;
155 cb->secen = hdr->fc.security_enabled;
156
157 ieee802154_print_addr("destination", &hdr->dest);
158 ieee802154_print_addr("source", &hdr->source);
159
160 cb->source = hdr->source;
161 cb->dest = hdr->dest;
162
163 if (hdr->fc.security_enabled) {
164 u64 key;
165
166 pr_debug("seclevel %i\n", hdr->sec.level);
167
168 switch (hdr->sec.key_id_mode) {
169 case IEEE802154_SCF_KEY_IMPLICIT:
170 pr_debug("implicit key\n");
171 break;
172
173 case IEEE802154_SCF_KEY_INDEX:
174 pr_debug("key %02x\n", hdr->sec.key_id);
175 break;
176
177 case IEEE802154_SCF_KEY_SHORT_INDEX:
178 pr_debug("key %04x:%04x %02x\n",
179 le32_to_cpu(hdr->sec.short_src) >> 16,
180 le32_to_cpu(hdr->sec.short_src) & 0xffff,
181 hdr->sec.key_id);
182 break;
183
184 case IEEE802154_SCF_KEY_HW_INDEX:
185 key = swab64((__force u64)hdr->sec.extended_src);
186 pr_debug("key source %8phC %02x\n", &key,
187 hdr->sec.key_id);
188 break;
189 }
190 }
191
192 return 0;
193}
194
195static void
196__ieee802154_rx_handle_packet(struct ieee802154_local *local,
197 struct sk_buff *skb)
198{
199 int ret;
200 struct ieee802154_sub_if_data *sdata;
201 struct ieee802154_hdr hdr;
102 202
103 work = kzalloc(sizeof(*work), GFP_ATOMIC); 203 ret = ieee802154_parse_frame_start(skb, &hdr);
104 if (!work) 204 if (ret) {
205 pr_debug("got invalid frame\n");
206 kfree_skb(skb);
105 return; 207 return;
208 }
209
210 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
211 if (sdata->vif.type != NL802154_IFTYPE_NODE ||
212 !netif_running(sdata->dev))
213 continue;
214
215 ieee802154_subif_frame(sdata, skb, &hdr);
216 skb = NULL;
217 break;
218 }
219
220 if (skb)
221 kfree_skb(skb);
222}
223
224static void
225ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
226{
227 struct sk_buff *skb2;
228 struct ieee802154_sub_if_data *sdata;
229
230 skb_reset_mac_header(skb);
231 skb->ip_summed = CHECKSUM_UNNECESSARY;
232 skb->pkt_type = PACKET_OTHERHOST;
233 skb->protocol = htons(ETH_P_IEEE802154);
234
235 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
236 if (sdata->vif.type != NL802154_IFTYPE_MONITOR)
237 continue;
238
239 if (!ieee802154_sdata_running(sdata))
240 continue;
241
242 skb2 = skb_clone(skb, GFP_ATOMIC);
243 if (skb2) {
244 skb2->dev = sdata->dev;
245 ieee802154_deliver_skb(skb2);
246
247 sdata->dev->stats.rx_packets++;
248 sdata->dev->stats.rx_bytes += skb->len;
249 }
250 }
251}
252
253void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
254{
255 struct ieee802154_local *local = hw_to_local(hw);
256 u16 crc;
106 257
107 INIT_WORK(&work->work, mac802154_rx_worker); 258 WARN_ON_ONCE(softirq_count() == 0);
108 work->skb = skb;
109 work->dev = dev;
110 work->lqi = lqi;
111 259
112 queue_work(priv->dev_workqueue, &work->work); 260 /* TODO: When a transceiver omits the checksum here, we
261 * add an own calculated one. This is currently an ugly
262 * solution because the monitor needs a crc here.
263 */
264 if (local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM) {
265 crc = crc_ccitt(0, skb->data, skb->len);
266 put_unaligned_le16(crc, skb_put(skb, 2));
267 }
268
269 rcu_read_lock();
270
271 ieee802154_monitors_rx(local, skb);
272
273 /* Check if transceiver doesn't validate the checksum.
274 * If not we validate the checksum here.
275 */
276 if (local->hw.flags & IEEE802154_HW_RX_DROP_BAD_CKSUM) {
277 crc = crc_ccitt(0, skb->data, skb->len);
278 if (crc) {
279 rcu_read_unlock();
280 kfree_skb(skb);
281 return;
282 }
283 }
284 /* remove crc */
285 skb_trim(skb, skb->len - 2);
286
287 __ieee802154_rx_handle_packet(local, skb);
288
289 rcu_read_unlock();
290}
291EXPORT_SYMBOL(ieee802154_rx);
292
293void
294ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi)
295{
296 struct ieee802154_local *local = hw_to_local(hw);
297
298 mac_cb(skb)->lqi = lqi;
299 skb->pkt_type = IEEE802154_RX_MSG;
300 skb_queue_tail(&local->skb_queue, skb);
301 tasklet_schedule(&local->tasklet);
113} 302}
114EXPORT_SYMBOL(ieee802154_rx_irqsafe); 303EXPORT_SYMBOL(ieee802154_rx_irqsafe);
diff --git a/net/mac802154/tx.c b/net/mac802154/tx.c
index fdf4c0e67259..c62e95695c78 100644
--- a/net/mac802154/tx.c
+++ b/net/mac802154/tx.c
@@ -10,10 +10,6 @@
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by: 13 * Written by:
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 14 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Sergey Lapin <slapin@ossfans.org> 15 * Sergey Lapin <slapin@ossfans.org>
@@ -24,106 +20,98 @@
24#include <linux/netdevice.h> 20#include <linux/netdevice.h>
25#include <linux/if_arp.h> 21#include <linux/if_arp.h>
26#include <linux/crc-ccitt.h> 22#include <linux/crc-ccitt.h>
23#include <asm/unaligned.h>
27 24
25#include <net/rtnetlink.h>
28#include <net/ieee802154_netdev.h> 26#include <net/ieee802154_netdev.h>
29#include <net/mac802154.h> 27#include <net/mac802154.h>
30#include <net/wpan-phy.h> 28#include <net/cfg802154.h>
31 29
32#include "mac802154.h" 30#include "ieee802154_i.h"
31#include "driver-ops.h"
33 32
34/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process 33/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
35 * packets through the workqueue. 34 * packets through the workqueue.
36 */ 35 */
37struct xmit_work { 36struct ieee802154_xmit_cb {
38 struct sk_buff *skb; 37 struct sk_buff *skb;
39 struct work_struct work; 38 struct work_struct work;
40 struct mac802154_priv *priv; 39 struct ieee802154_local *local;
41 u8 chan;
42 u8 page;
43}; 40};
44 41
45static void mac802154_xmit_worker(struct work_struct *work) 42static struct ieee802154_xmit_cb ieee802154_xmit_cb;
43
44static void ieee802154_xmit_worker(struct work_struct *work)
46{ 45{
47 struct xmit_work *xw = container_of(work, struct xmit_work, work); 46 struct ieee802154_xmit_cb *cb =
48 struct mac802154_sub_if_data *sdata; 47 container_of(work, struct ieee802154_xmit_cb, work);
48 struct ieee802154_local *local = cb->local;
49 struct sk_buff *skb = cb->skb;
50 struct net_device *dev = skb->dev;
49 int res; 51 int res;
50 52
51 mutex_lock(&xw->priv->phy->pib_lock); 53 rtnl_lock();
52 if (xw->priv->phy->current_channel != xw->chan ||
53 xw->priv->phy->current_page != xw->page) {
54 res = xw->priv->ops->set_channel(&xw->priv->hw,
55 xw->page,
56 xw->chan);
57 if (res) {
58 pr_debug("set_channel failed\n");
59 goto out;
60 }
61 54
62 xw->priv->phy->current_channel = xw->chan; 55 /* check if ifdown occurred while schedule */
63 xw->priv->phy->current_page = xw->page; 56 if (!netif_running(dev))
64 } 57 goto err_tx;
65 58
66 res = xw->priv->ops->xmit(&xw->priv->hw, xw->skb); 59 res = drv_xmit_sync(local, skb);
67 if (res) 60 if (res)
68 pr_debug("transmission failed\n"); 61 goto err_tx;
69 62
70out: 63 ieee802154_xmit_complete(&local->hw, skb, false);
71 mutex_unlock(&xw->priv->phy->pib_lock);
72 64
73 /* Restart the netif queue on each sub_if_data object. */ 65 dev->stats.tx_packets++;
74 rcu_read_lock(); 66 dev->stats.tx_bytes += skb->len;
75 list_for_each_entry_rcu(sdata, &xw->priv->slaves, list)
76 netif_wake_queue(sdata->dev);
77 rcu_read_unlock();
78 67
79 dev_kfree_skb(xw->skb); 68 rtnl_unlock();
80 69
81 kfree(xw); 70 return;
71
72err_tx:
73 /* Restart the netif queue on each sub_if_data object. */
74 ieee802154_wake_queue(&local->hw);
75 rtnl_unlock();
76 kfree_skb(skb);
77 netdev_dbg(dev, "transmission failed\n");
82} 78}
83 79
84netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb, 80static netdev_tx_t
85 u8 page, u8 chan) 81ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
86{ 82{
87 struct xmit_work *work; 83 struct net_device *dev = skb->dev;
88 struct mac802154_sub_if_data *sdata; 84 int ret;
89
90 if (!(priv->phy->channels_supported[page] & (1 << chan))) {
91 WARN_ON(1);
92 goto err_tx;
93 }
94
95 mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
96 85
97 if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { 86 if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
98 u16 crc = crc_ccitt(0, skb->data, skb->len); 87 u16 crc = crc_ccitt(0, skb->data, skb->len);
99 u8 *data = skb_put(skb, 2);
100 88
101 data[0] = crc & 0xff; 89 put_unaligned_le16(crc, skb_put(skb, 2));
102 data[1] = crc >> 8;
103 } 90 }
104 91
105 if (skb_cow_head(skb, priv->hw.extra_tx_headroom)) 92 if (skb_cow_head(skb, local->hw.extra_tx_headroom))
106 goto err_tx; 93 goto err_tx;
107 94
108 work = kzalloc(sizeof(*work), GFP_ATOMIC);
109 if (!work) {
110 kfree_skb(skb);
111 return NETDEV_TX_BUSY;
112 }
113
114 /* Stop the netif queue on each sub_if_data object. */ 95 /* Stop the netif queue on each sub_if_data object. */
115 rcu_read_lock(); 96 ieee802154_stop_queue(&local->hw);
116 list_for_each_entry_rcu(sdata, &priv->slaves, list) 97
117 netif_stop_queue(sdata->dev); 98 /* async is priority, otherwise sync is fallback */
118 rcu_read_unlock(); 99 if (local->ops->xmit_async) {
100 ret = drv_xmit_async(local, skb);
101 if (ret) {
102 ieee802154_wake_queue(&local->hw);
103 goto err_tx;
104 }
119 105
120 INIT_WORK(&work->work, mac802154_xmit_worker); 106 dev->stats.tx_packets++;
121 work->skb = skb; 107 dev->stats.tx_bytes += skb->len;
122 work->priv = priv; 108 } else {
123 work->page = page; 109 INIT_WORK(&ieee802154_xmit_cb.work, ieee802154_xmit_worker);
124 work->chan = chan; 110 ieee802154_xmit_cb.skb = skb;
111 ieee802154_xmit_cb.local = local;
125 112
126 queue_work(priv->dev_workqueue, &work->work); 113 queue_work(local->workqueue, &ieee802154_xmit_cb.work);
114 }
127 115
128 return NETDEV_TX_OK; 116 return NETDEV_TX_OK;
129 117
@@ -131,3 +119,31 @@ err_tx:
131 kfree_skb(skb); 119 kfree_skb(skb);
132 return NETDEV_TX_OK; 120 return NETDEV_TX_OK;
133} 121}
122
123netdev_tx_t
124ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
125{
126 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
127
128 skb->skb_iif = dev->ifindex;
129
130 return ieee802154_tx(sdata->local, skb);
131}
132
133netdev_tx_t
134ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)
135{
136 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
137 int rc;
138
139 rc = mac802154_llsec_encrypt(&sdata->sec, skb);
140 if (rc) {
141 netdev_warn(dev, "encryption failed: %i\n", rc);
142 kfree_skb(skb);
143 return NETDEV_TX_OK;
144 }
145
146 skb->skb_iif = dev->ifindex;
147
148 return ieee802154_tx(sdata->local, skb);
149}
diff --git a/net/mac802154/util.c b/net/mac802154/util.c
new file mode 100644
index 000000000000..5fc979027919
--- /dev/null
+++ b/net/mac802154/util.c
@@ -0,0 +1,84 @@
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
12 *
13 * Based on: net/mac80211/util.c
14 */
15
16#include "ieee802154_i.h"
17
18/* privid for wpan_phys to determine whether they belong to us or not */
19const void *const mac802154_wpan_phy_privid = &mac802154_wpan_phy_privid;
20
21void ieee802154_wake_queue(struct ieee802154_hw *hw)
22{
23 struct ieee802154_local *local = hw_to_local(hw);
24 struct ieee802154_sub_if_data *sdata;
25
26 rcu_read_lock();
27 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
28 if (!sdata->dev)
29 continue;
30
31 netif_wake_queue(sdata->dev);
32 }
33 rcu_read_unlock();
34}
35EXPORT_SYMBOL(ieee802154_wake_queue);
36
37void ieee802154_stop_queue(struct ieee802154_hw *hw)
38{
39 struct ieee802154_local *local = hw_to_local(hw);
40 struct ieee802154_sub_if_data *sdata;
41
42 rcu_read_lock();
43 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
44 if (!sdata->dev)
45 continue;
46
47 netif_stop_queue(sdata->dev);
48 }
49 rcu_read_unlock();
50}
51EXPORT_SYMBOL(ieee802154_stop_queue);
52
53enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer)
54{
55 struct ieee802154_local *local =
56 container_of(timer, struct ieee802154_local, ifs_timer);
57
58 ieee802154_wake_queue(&local->hw);
59
60 return HRTIMER_NORESTART;
61}
62
63void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
64 bool ifs_handling)
65{
66 if (ifs_handling) {
67 struct ieee802154_local *local = hw_to_local(hw);
68
69 if (skb->len > 18)
70 hrtimer_start(&local->ifs_timer,
71 ktime_set(0, hw->phy->lifs_period * NSEC_PER_USEC),
72 HRTIMER_MODE_REL);
73 else
74 hrtimer_start(&local->ifs_timer,
75 ktime_set(0, hw->phy->sifs_period * NSEC_PER_USEC),
76 HRTIMER_MODE_REL);
77
78 consume_skb(skb);
79 } else {
80 ieee802154_wake_queue(hw);
81 consume_skb(skb);
82 }
83}
84EXPORT_SYMBOL(ieee802154_xmit_complete);
diff --git a/net/mac802154/wpan.c b/net/mac802154/wpan.c
deleted file mode 100644
index 4ab86a57dca5..000000000000
--- a/net/mac802154/wpan.c
+++ /dev/null
@@ -1,599 +0,0 @@
1/*
2 * Copyright 2007-2012 Siemens AG
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by:
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Sergey Lapin <slapin@ossfans.org>
20 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
22 */
23
24#include <linux/netdevice.h>
25#include <linux/module.h>
26#include <linux/if_arp.h>
27
28#include <net/rtnetlink.h>
29#include <linux/nl802154.h>
30#include <net/af_ieee802154.h>
31#include <net/mac802154.h>
32#include <net/ieee802154_netdev.h>
33#include <net/ieee802154.h>
34#include <net/wpan-phy.h>
35
36#include "mac802154.h"
37
38static int mac802154_wpan_update_llsec(struct net_device *dev)
39{
40 struct mac802154_sub_if_data *priv = netdev_priv(dev);
41 struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
42 int rc = 0;
43
44 if (ops->llsec) {
45 struct ieee802154_llsec_params params;
46 int changed = 0;
47
48 params.pan_id = priv->pan_id;
49 changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
50
51 params.hwaddr = priv->extended_addr;
52 changed |= IEEE802154_LLSEC_PARAM_HWADDR;
53
54 rc = ops->llsec->set_params(dev, &params, changed);
55 }
56
57 return rc;
58}
59
60static int
61mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
62{
63 struct mac802154_sub_if_data *priv = netdev_priv(dev);
64 struct sockaddr_ieee802154 *sa =
65 (struct sockaddr_ieee802154 *)&ifr->ifr_addr;
66 int err = -ENOIOCTLCMD;
67
68 spin_lock_bh(&priv->mib_lock);
69
70 switch (cmd) {
71 case SIOCGIFADDR:
72 {
73 u16 pan_id, short_addr;
74
75 pan_id = le16_to_cpu(priv->pan_id);
76 short_addr = le16_to_cpu(priv->short_addr);
77 if (pan_id == IEEE802154_PANID_BROADCAST ||
78 short_addr == IEEE802154_ADDR_BROADCAST) {
79 err = -EADDRNOTAVAIL;
80 break;
81 }
82
83 sa->family = AF_IEEE802154;
84 sa->addr.addr_type = IEEE802154_ADDR_SHORT;
85 sa->addr.pan_id = pan_id;
86 sa->addr.short_addr = short_addr;
87
88 err = 0;
89 break;
90 }
91 case SIOCSIFADDR:
92 dev_warn(&dev->dev,
93 "Using DEBUGing ioctl SIOCSIFADDR isn't recommended!\n");
94 if (sa->family != AF_IEEE802154 ||
95 sa->addr.addr_type != IEEE802154_ADDR_SHORT ||
96 sa->addr.pan_id == IEEE802154_PANID_BROADCAST ||
97 sa->addr.short_addr == IEEE802154_ADDR_BROADCAST ||
98 sa->addr.short_addr == IEEE802154_ADDR_UNDEF) {
99 err = -EINVAL;
100 break;
101 }
102
103 priv->pan_id = cpu_to_le16(sa->addr.pan_id);
104 priv->short_addr = cpu_to_le16(sa->addr.short_addr);
105
106 err = mac802154_wpan_update_llsec(dev);
107 break;
108 }
109
110 spin_unlock_bh(&priv->mib_lock);
111 return err;
112}
113
114static int mac802154_wpan_mac_addr(struct net_device *dev, void *p)
115{
116 struct sockaddr *addr = p;
117
118 if (netif_running(dev))
119 return -EBUSY;
120
121 /* FIXME: validate addr */
122 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
123 mac802154_dev_set_ieee_addr(dev);
124 return mac802154_wpan_update_llsec(dev);
125}
126
127int mac802154_set_mac_params(struct net_device *dev,
128 const struct ieee802154_mac_params *params)
129{
130 struct mac802154_sub_if_data *priv = netdev_priv(dev);
131
132 mutex_lock(&priv->hw->slaves_mtx);
133 priv->mac_params = *params;
134 mutex_unlock(&priv->hw->slaves_mtx);
135
136 return 0;
137}
138
139void mac802154_get_mac_params(struct net_device *dev,
140 struct ieee802154_mac_params *params)
141{
142 struct mac802154_sub_if_data *priv = netdev_priv(dev);
143
144 mutex_lock(&priv->hw->slaves_mtx);
145 *params = priv->mac_params;
146 mutex_unlock(&priv->hw->slaves_mtx);
147}
148
149static int mac802154_wpan_open(struct net_device *dev)
150{
151 int rc;
152 struct mac802154_sub_if_data *priv = netdev_priv(dev);
153 struct wpan_phy *phy = priv->hw->phy;
154
155 rc = mac802154_slave_open(dev);
156 if (rc < 0)
157 return rc;
158
159 mutex_lock(&phy->pib_lock);
160
161 if (phy->set_txpower) {
162 rc = phy->set_txpower(phy, priv->mac_params.transmit_power);
163 if (rc < 0)
164 goto out;
165 }
166
167 if (phy->set_lbt) {
168 rc = phy->set_lbt(phy, priv->mac_params.lbt);
169 if (rc < 0)
170 goto out;
171 }
172
173 if (phy->set_cca_mode) {
174 rc = phy->set_cca_mode(phy, priv->mac_params.cca_mode);
175 if (rc < 0)
176 goto out;
177 }
178
179 if (phy->set_cca_ed_level) {
180 rc = phy->set_cca_ed_level(phy, priv->mac_params.cca_ed_level);
181 if (rc < 0)
182 goto out;
183 }
184
185 if (phy->set_csma_params) {
186 rc = phy->set_csma_params(phy, priv->mac_params.min_be,
187 priv->mac_params.max_be,
188 priv->mac_params.csma_retries);
189 if (rc < 0)
190 goto out;
191 }
192
193 if (phy->set_frame_retries) {
194 rc = phy->set_frame_retries(phy,
195 priv->mac_params.frame_retries);
196 if (rc < 0)
197 goto out;
198 }
199
200 mutex_unlock(&phy->pib_lock);
201 return 0;
202
203out:
204 mutex_unlock(&phy->pib_lock);
205 return rc;
206}
207
208static int mac802154_set_header_security(struct mac802154_sub_if_data *priv,
209 struct ieee802154_hdr *hdr,
210 const struct ieee802154_mac_cb *cb)
211{
212 struct ieee802154_llsec_params params;
213 u8 level;
214
215 mac802154_llsec_get_params(&priv->sec, &params);
216
217 if (!params.enabled && cb->secen_override && cb->secen)
218 return -EINVAL;
219 if (!params.enabled ||
220 (cb->secen_override && !cb->secen) ||
221 !params.out_level)
222 return 0;
223 if (cb->seclevel_override && !cb->seclevel)
224 return -EINVAL;
225
226 level = cb->seclevel_override ? cb->seclevel : params.out_level;
227
228 hdr->fc.security_enabled = 1;
229 hdr->sec.level = level;
230 hdr->sec.key_id_mode = params.out_key.mode;
231 if (params.out_key.mode == IEEE802154_SCF_KEY_SHORT_INDEX)
232 hdr->sec.short_src = params.out_key.short_source;
233 else if (params.out_key.mode == IEEE802154_SCF_KEY_HW_INDEX)
234 hdr->sec.extended_src = params.out_key.extended_source;
235 hdr->sec.key_id = params.out_key.id;
236
237 return 0;
238}
239
240static int mac802154_header_create(struct sk_buff *skb,
241 struct net_device *dev,
242 unsigned short type,
243 const void *daddr,
244 const void *saddr,
245 unsigned len)
246{
247 struct ieee802154_hdr hdr;
248 struct mac802154_sub_if_data *priv = netdev_priv(dev);
249 struct ieee802154_mac_cb *cb = mac_cb(skb);
250 int hlen;
251
252 if (!daddr)
253 return -EINVAL;
254
255 memset(&hdr.fc, 0, sizeof(hdr.fc));
256 hdr.fc.type = cb->type;
257 hdr.fc.security_enabled = cb->secen;
258 hdr.fc.ack_request = cb->ackreq;
259 hdr.seq = ieee802154_mlme_ops(dev)->get_dsn(dev);
260
261 if (mac802154_set_header_security(priv, &hdr, cb) < 0)
262 return -EINVAL;
263
264 if (!saddr) {
265 spin_lock_bh(&priv->mib_lock);
266
267 if (priv->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
268 priv->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
269 priv->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
270 hdr.source.mode = IEEE802154_ADDR_LONG;
271 hdr.source.extended_addr = priv->extended_addr;
272 } else {
273 hdr.source.mode = IEEE802154_ADDR_SHORT;
274 hdr.source.short_addr = priv->short_addr;
275 }
276
277 hdr.source.pan_id = priv->pan_id;
278
279 spin_unlock_bh(&priv->mib_lock);
280 } else {
281 hdr.source = *(const struct ieee802154_addr *)saddr;
282 }
283
284 hdr.dest = *(const struct ieee802154_addr *)daddr;
285
286 hlen = ieee802154_hdr_push(skb, &hdr);
287 if (hlen < 0)
288 return -EINVAL;
289
290 skb_reset_mac_header(skb);
291 skb->mac_len = hlen;
292
293 if (len > ieee802154_max_payload(&hdr))
294 return -EMSGSIZE;
295
296 return hlen;
297}
298
299static int
300mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)
301{
302 struct ieee802154_hdr hdr;
303 struct ieee802154_addr *addr = (struct ieee802154_addr *)haddr;
304
305 if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0) {
306 pr_debug("malformed packet\n");
307 return 0;
308 }
309
310 *addr = hdr.source;
311 return sizeof(*addr);
312}
313
314static netdev_tx_t
315mac802154_wpan_xmit(struct sk_buff *skb, struct net_device *dev)
316{
317 struct mac802154_sub_if_data *priv;
318 u8 chan, page;
319 int rc;
320
321 priv = netdev_priv(dev);
322
323 spin_lock_bh(&priv->mib_lock);
324 chan = priv->chan;
325 page = priv->page;
326 spin_unlock_bh(&priv->mib_lock);
327
328 if (chan == MAC802154_CHAN_NONE ||
329 page >= WPAN_NUM_PAGES ||
330 chan >= WPAN_NUM_CHANNELS) {
331 kfree_skb(skb);
332 return NETDEV_TX_OK;
333 }
334
335 rc = mac802154_llsec_encrypt(&priv->sec, skb);
336 if (rc) {
337 pr_warn("encryption failed: %i\n", rc);
338 kfree_skb(skb);
339 return NETDEV_TX_OK;
340 }
341
342 skb->skb_iif = dev->ifindex;
343 dev->stats.tx_packets++;
344 dev->stats.tx_bytes += skb->len;
345
346 return mac802154_tx(priv->hw, skb, page, chan);
347}
348
349static struct header_ops mac802154_header_ops = {
350 .create = mac802154_header_create,
351 .parse = mac802154_header_parse,
352};
353
354static const struct net_device_ops mac802154_wpan_ops = {
355 .ndo_open = mac802154_wpan_open,
356 .ndo_stop = mac802154_slave_close,
357 .ndo_start_xmit = mac802154_wpan_xmit,
358 .ndo_do_ioctl = mac802154_wpan_ioctl,
359 .ndo_set_mac_address = mac802154_wpan_mac_addr,
360};
361
362static void mac802154_wpan_free(struct net_device *dev)
363{
364 struct mac802154_sub_if_data *priv = netdev_priv(dev);
365
366 mac802154_llsec_destroy(&priv->sec);
367
368 free_netdev(dev);
369}
370
371void mac802154_wpan_setup(struct net_device *dev)
372{
373 struct mac802154_sub_if_data *priv;
374
375 dev->addr_len = IEEE802154_ADDR_LEN;
376 memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
377
378 dev->hard_header_len = MAC802154_FRAME_HARD_HEADER_LEN;
379 dev->header_ops = &mac802154_header_ops;
380 dev->needed_tailroom = 2 + 16; /* FCS + MIC */
381 dev->mtu = IEEE802154_MTU;
382 dev->tx_queue_len = 300;
383 dev->type = ARPHRD_IEEE802154;
384 dev->flags = IFF_NOARP | IFF_BROADCAST;
385 dev->watchdog_timeo = 0;
386
387 dev->destructor = mac802154_wpan_free;
388 dev->netdev_ops = &mac802154_wpan_ops;
389 dev->ml_priv = &mac802154_mlme_wpan;
390
391 priv = netdev_priv(dev);
392 priv->type = IEEE802154_DEV_WPAN;
393
394 priv->chan = MAC802154_CHAN_NONE;
395 priv->page = 0;
396
397 spin_lock_init(&priv->mib_lock);
398 mutex_init(&priv->sec_mtx);
399
400 get_random_bytes(&priv->bsn, 1);
401 get_random_bytes(&priv->dsn, 1);
402
403 /* defaults per 802.15.4-2011 */
404 priv->mac_params.min_be = 3;
405 priv->mac_params.max_be = 5;
406 priv->mac_params.csma_retries = 4;
407 priv->mac_params.frame_retries = -1; /* for compatibility, actual default is 3 */
408
409 priv->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
410 priv->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
411
412 mac802154_llsec_init(&priv->sec);
413}
414
415static int mac802154_process_data(struct net_device *dev, struct sk_buff *skb)
416{
417 return netif_rx_ni(skb);
418}
419
420static int
421mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb,
422 const struct ieee802154_hdr *hdr)
423{
424 __le16 span, sshort;
425 int rc;
426
427 pr_debug("getting packet via slave interface %s\n", sdata->dev->name);
428
429 spin_lock_bh(&sdata->mib_lock);
430
431 span = sdata->pan_id;
432 sshort = sdata->short_addr;
433
434 switch (mac_cb(skb)->dest.mode) {
435 case IEEE802154_ADDR_NONE:
436 if (mac_cb(skb)->dest.mode != IEEE802154_ADDR_NONE)
437 /* FIXME: check if we are PAN coordinator */
438 skb->pkt_type = PACKET_OTHERHOST;
439 else
440 /* ACK comes with both addresses empty */
441 skb->pkt_type = PACKET_HOST;
442 break;
443 case IEEE802154_ADDR_LONG:
444 if (mac_cb(skb)->dest.pan_id != span &&
445 mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST))
446 skb->pkt_type = PACKET_OTHERHOST;
447 else if (mac_cb(skb)->dest.extended_addr == sdata->extended_addr)
448 skb->pkt_type = PACKET_HOST;
449 else
450 skb->pkt_type = PACKET_OTHERHOST;
451 break;
452 case IEEE802154_ADDR_SHORT:
453 if (mac_cb(skb)->dest.pan_id != span &&
454 mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST))
455 skb->pkt_type = PACKET_OTHERHOST;
456 else if (mac_cb(skb)->dest.short_addr == sshort)
457 skb->pkt_type = PACKET_HOST;
458 else if (mac_cb(skb)->dest.short_addr ==
459 cpu_to_le16(IEEE802154_ADDR_BROADCAST))
460 skb->pkt_type = PACKET_BROADCAST;
461 else
462 skb->pkt_type = PACKET_OTHERHOST;
463 break;
464 default:
465 spin_unlock_bh(&sdata->mib_lock);
466 pr_debug("invalid dest mode\n");
467 kfree_skb(skb);
468 return NET_RX_DROP;
469 }
470
471 spin_unlock_bh(&sdata->mib_lock);
472
473 skb->dev = sdata->dev;
474
475 rc = mac802154_llsec_decrypt(&sdata->sec, skb);
476 if (rc) {
477 pr_debug("decryption failed: %i\n", rc);
478 goto fail;
479 }
480
481 sdata->dev->stats.rx_packets++;
482 sdata->dev->stats.rx_bytes += skb->len;
483
484 switch (mac_cb(skb)->type) {
485 case IEEE802154_FC_TYPE_DATA:
486 return mac802154_process_data(sdata->dev, skb);
487 default:
488 pr_warn("ieee802154: bad frame received (type = %d)\n",
489 mac_cb(skb)->type);
490 goto fail;
491 }
492
493fail:
494 kfree_skb(skb);
495 return NET_RX_DROP;
496}
497
498static void mac802154_print_addr(const char *name,
499 const struct ieee802154_addr *addr)
500{
501 if (addr->mode == IEEE802154_ADDR_NONE)
502 pr_debug("%s not present\n", name);
503
504 pr_debug("%s PAN ID: %04x\n", name, le16_to_cpu(addr->pan_id));
505 if (addr->mode == IEEE802154_ADDR_SHORT) {
506 pr_debug("%s is short: %04x\n", name,
507 le16_to_cpu(addr->short_addr));
508 } else {
509 u64 hw = swab64((__force u64) addr->extended_addr);
510
511 pr_debug("%s is hardware: %8phC\n", name, &hw);
512 }
513}
514
515static int mac802154_parse_frame_start(struct sk_buff *skb,
516 struct ieee802154_hdr *hdr)
517{
518 int hlen;
519 struct ieee802154_mac_cb *cb = mac_cb_init(skb);
520
521 hlen = ieee802154_hdr_pull(skb, hdr);
522 if (hlen < 0)
523 return -EINVAL;
524
525 skb->mac_len = hlen;
526
527 pr_debug("fc: %04x dsn: %02x\n", le16_to_cpup((__le16 *)&hdr->fc),
528 hdr->seq);
529
530 cb->type = hdr->fc.type;
531 cb->ackreq = hdr->fc.ack_request;
532 cb->secen = hdr->fc.security_enabled;
533
534 mac802154_print_addr("destination", &hdr->dest);
535 mac802154_print_addr("source", &hdr->source);
536
537 cb->source = hdr->source;
538 cb->dest = hdr->dest;
539
540 if (hdr->fc.security_enabled) {
541 u64 key;
542
543 pr_debug("seclevel %i\n", hdr->sec.level);
544
545 switch (hdr->sec.key_id_mode) {
546 case IEEE802154_SCF_KEY_IMPLICIT:
547 pr_debug("implicit key\n");
548 break;
549
550 case IEEE802154_SCF_KEY_INDEX:
551 pr_debug("key %02x\n", hdr->sec.key_id);
552 break;
553
554 case IEEE802154_SCF_KEY_SHORT_INDEX:
555 pr_debug("key %04x:%04x %02x\n",
556 le32_to_cpu(hdr->sec.short_src) >> 16,
557 le32_to_cpu(hdr->sec.short_src) & 0xffff,
558 hdr->sec.key_id);
559 break;
560
561 case IEEE802154_SCF_KEY_HW_INDEX:
562 key = swab64((__force u64) hdr->sec.extended_src);
563 pr_debug("key source %8phC %02x\n", &key,
564 hdr->sec.key_id);
565 break;
566 }
567 }
568
569 return 0;
570}
571
572void mac802154_wpans_rx(struct mac802154_priv *priv, struct sk_buff *skb)
573{
574 int ret;
575 struct mac802154_sub_if_data *sdata;
576 struct ieee802154_hdr hdr;
577
578 ret = mac802154_parse_frame_start(skb, &hdr);
579 if (ret) {
580 pr_debug("got invalid frame\n");
581 kfree_skb(skb);
582 return;
583 }
584
585 rcu_read_lock();
586 list_for_each_entry_rcu(sdata, &priv->slaves, list) {
587 if (sdata->type != IEEE802154_DEV_WPAN ||
588 !netif_running(sdata->dev))
589 continue;
590
591 mac802154_subif_frame(sdata, skb, &hdr);
592 skb = NULL;
593 break;
594 }
595 rcu_read_unlock();
596
597 if (skb)
598 kfree_skb(skb);
599}
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index a761670af31d..4c9e39f04ef8 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_WEXT_SPY) += wext-spy.o
10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o 10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o
11 11
12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o 12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o ap.o trace.o 13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o ap.o trace.o ocb.o
14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o 14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o 15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o
16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o 16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index 72d81e2154d5..85506f1d0789 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -115,7 +115,7 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
115EXPORT_SYMBOL(cfg80211_chandef_valid); 115EXPORT_SYMBOL(cfg80211_chandef_valid);
116 116
117static void chandef_primary_freqs(const struct cfg80211_chan_def *c, 117static void chandef_primary_freqs(const struct cfg80211_chan_def *c,
118 int *pri40, int *pri80) 118 u32 *pri40, u32 *pri80)
119{ 119{
120 int tmp; 120 int tmp;
121 121
@@ -366,6 +366,7 @@ int cfg80211_chandef_dfs_required(struct wiphy *wiphy,
366 366
367 break; 367 break;
368 case NL80211_IFTYPE_STATION: 368 case NL80211_IFTYPE_STATION:
369 case NL80211_IFTYPE_OCB:
369 case NL80211_IFTYPE_P2P_CLIENT: 370 case NL80211_IFTYPE_P2P_CLIENT:
370 case NL80211_IFTYPE_MONITOR: 371 case NL80211_IFTYPE_MONITOR:
371 case NL80211_IFTYPE_AP_VLAN: 372 case NL80211_IFTYPE_AP_VLAN:
@@ -892,6 +893,13 @@ cfg80211_get_chan_state(struct wireless_dev *wdev,
892 *radar_detect |= BIT(wdev->chandef.width); 893 *radar_detect |= BIT(wdev->chandef.width);
893 } 894 }
894 return; 895 return;
896 case NL80211_IFTYPE_OCB:
897 if (wdev->chandef.chan) {
898 *chan = wdev->chandef.chan;
899 *chanmode = CHAN_MODE_SHARED;
900 return;
901 }
902 break;
895 case NL80211_IFTYPE_MONITOR: 903 case NL80211_IFTYPE_MONITOR:
896 case NL80211_IFTYPE_AP_VLAN: 904 case NL80211_IFTYPE_AP_VLAN:
897 case NL80211_IFTYPE_WDS: 905 case NL80211_IFTYPE_WDS:
diff --git a/net/wireless/core.c b/net/wireless/core.c
index f52a4cd7017c..a4d27927aba2 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -86,11 +86,11 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
86 return &rdev->wiphy; 86 return &rdev->wiphy;
87} 87}
88 88
89int cfg80211_dev_rename(struct cfg80211_registered_device *rdev, 89static int cfg80211_dev_check_name(struct cfg80211_registered_device *rdev,
90 char *newname) 90 const char *newname)
91{ 91{
92 struct cfg80211_registered_device *rdev2; 92 struct cfg80211_registered_device *rdev2;
93 int wiphy_idx, taken = -1, result, digits; 93 int wiphy_idx, taken = -1, digits;
94 94
95 ASSERT_RTNL(); 95 ASSERT_RTNL();
96 96
@@ -109,15 +109,28 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
109 return -EINVAL; 109 return -EINVAL;
110 } 110 }
111 111
112 /* Ensure another device does not already have this name. */
113 list_for_each_entry(rdev2, &cfg80211_rdev_list, list)
114 if (strcmp(newname, wiphy_name(&rdev2->wiphy)) == 0)
115 return -EINVAL;
116
117 return 0;
118}
119
120int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
121 char *newname)
122{
123 int result;
124
125 ASSERT_RTNL();
112 126
113 /* Ignore nop renames */ 127 /* Ignore nop renames */
114 if (strcmp(newname, dev_name(&rdev->wiphy.dev)) == 0) 128 if (strcmp(newname, wiphy_name(&rdev->wiphy)) == 0)
115 return 0; 129 return 0;
116 130
117 /* Ensure another device does not already have this name. */ 131 result = cfg80211_dev_check_name(rdev, newname);
118 list_for_each_entry(rdev2, &cfg80211_rdev_list, list) 132 if (result < 0)
119 if (strcmp(newname, dev_name(&rdev2->wiphy.dev)) == 0) 133 return result;
120 return -EINVAL;
121 134
122 result = device_rename(&rdev->wiphy.dev, newname); 135 result = device_rename(&rdev->wiphy.dev, newname);
123 if (result) 136 if (result)
@@ -309,7 +322,8 @@ static void cfg80211_destroy_iface_wk(struct work_struct *work)
309 322
310/* exported functions */ 323/* exported functions */
311 324
312struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv) 325struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv,
326 const char *requested_name)
313{ 327{
314 static atomic_t wiphy_counter = ATOMIC_INIT(0); 328 static atomic_t wiphy_counter = ATOMIC_INIT(0);
315 329
@@ -346,7 +360,31 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
346 rdev->wiphy_idx--; 360 rdev->wiphy_idx--;
347 361
348 /* give it a proper name */ 362 /* give it a proper name */
349 dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx); 363 if (requested_name && requested_name[0]) {
364 int rv;
365
366 rtnl_lock();
367 rv = cfg80211_dev_check_name(rdev, requested_name);
368
369 if (rv < 0) {
370 rtnl_unlock();
371 goto use_default_name;
372 }
373
374 rv = dev_set_name(&rdev->wiphy.dev, "%s", requested_name);
375 rtnl_unlock();
376 if (rv)
377 goto use_default_name;
378 } else {
379use_default_name:
380 /* NOTE: This is *probably* safe w/out holding rtnl because of
381 * the restrictions on phy names. Probably this call could
382 * fail if some other part of the kernel (re)named a device
383 * phyX. But, might should add some locking and check return
384 * value, and use a different name if this one exists?
385 */
386 dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
387 }
350 388
351 INIT_LIST_HEAD(&rdev->wdev_list); 389 INIT_LIST_HEAD(&rdev->wdev_list);
352 INIT_LIST_HEAD(&rdev->beacon_registrations); 390 INIT_LIST_HEAD(&rdev->beacon_registrations);
@@ -406,7 +444,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
406 444
407 return &rdev->wiphy; 445 return &rdev->wiphy;
408} 446}
409EXPORT_SYMBOL(wiphy_new); 447EXPORT_SYMBOL(wiphy_new_nm);
410 448
411static int wiphy_verify_combinations(struct wiphy *wiphy) 449static int wiphy_verify_combinations(struct wiphy *wiphy)
412{ 450{
@@ -831,7 +869,22 @@ void __cfg80211_leave(struct cfg80211_registered_device *rdev,
831 case NL80211_IFTYPE_P2P_GO: 869 case NL80211_IFTYPE_P2P_GO:
832 __cfg80211_stop_ap(rdev, dev, true); 870 __cfg80211_stop_ap(rdev, dev, true);
833 break; 871 break;
834 default: 872 case NL80211_IFTYPE_OCB:
873 __cfg80211_leave_ocb(rdev, dev);
874 break;
875 case NL80211_IFTYPE_WDS:
876 /* must be handled by mac80211/driver, has no APIs */
877 break;
878 case NL80211_IFTYPE_P2P_DEVICE:
879 /* cannot happen, has no netdev */
880 break;
881 case NL80211_IFTYPE_AP_VLAN:
882 case NL80211_IFTYPE_MONITOR:
883 /* nothing to do */
884 break;
885 case NL80211_IFTYPE_UNSPECIFIED:
886 case NUM_NL80211_IFTYPES:
887 /* invalid */
835 break; 888 break;
836 } 889 }
837} 890}
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 7e3a3cef7df9..61ee664cf2bd 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -290,6 +290,18 @@ int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev,
290 struct wireless_dev *wdev, 290 struct wireless_dev *wdev,
291 struct cfg80211_chan_def *chandef); 291 struct cfg80211_chan_def *chandef);
292 292
293/* OCB */
294int __cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
295 struct net_device *dev,
296 struct ocb_setup *setup);
297int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
298 struct net_device *dev,
299 struct ocb_setup *setup);
300int __cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
301 struct net_device *dev);
302int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
303 struct net_device *dev);
304
293/* AP */ 305/* AP */
294int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev, 306int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
295 struct net_device *dev, bool notify); 307 struct net_device *dev, bool notify);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 5839c85075f1..1a31736914e5 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -884,7 +884,12 @@ static int nl80211_key_allowed(struct wireless_dev *wdev)
884 if (!wdev->current_bss) 884 if (!wdev->current_bss)
885 return -ENOLINK; 885 return -ENOLINK;
886 break; 886 break;
887 default: 887 case NL80211_IFTYPE_UNSPECIFIED:
888 case NL80211_IFTYPE_OCB:
889 case NL80211_IFTYPE_MONITOR:
890 case NL80211_IFTYPE_P2P_DEVICE:
891 case NL80211_IFTYPE_WDS:
892 case NUM_NL80211_IFTYPES:
888 return -EINVAL; 893 return -EINVAL;
889 } 894 }
890 895
@@ -1514,8 +1519,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1514 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 1519 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1515 CMD(channel_switch, CHANNEL_SWITCH); 1520 CMD(channel_switch, CHANNEL_SWITCH);
1516 CMD(set_qos_map, SET_QOS_MAP); 1521 CMD(set_qos_map, SET_QOS_MAP);
1517 if (rdev->wiphy.flags & 1522 if (rdev->wiphy.features &
1518 WIPHY_FLAG_SUPPORTS_WMM_ADMISSION) 1523 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
1519 CMD(add_tx_ts, ADD_TX_TS); 1524 CMD(add_tx_ts, ADD_TX_TS);
1520 } 1525 }
1521 /* add into the if now */ 1526 /* add into the if now */
@@ -2605,7 +2610,9 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2605 !(rdev->wiphy.interface_modes & (1 << type))) 2610 !(rdev->wiphy.interface_modes & (1 << type)))
2606 return -EOPNOTSUPP; 2611 return -EOPNOTSUPP;
2607 2612
2608 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { 2613 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2614 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2615 info->attrs[NL80211_ATTR_MAC]) {
2609 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 2616 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2610 ETH_ALEN); 2617 ETH_ALEN);
2611 if (!is_valid_ether_addr(params.macaddr)) 2618 if (!is_valid_ether_addr(params.macaddr))
@@ -4398,10 +4405,12 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4398{ 4405{
4399 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4400 struct net_device *dev = info->user_ptr[1]; 4407 struct net_device *dev = info->user_ptr[1];
4401 u8 *mac_addr = NULL; 4408 struct station_del_parameters params;
4409
4410 memset(&params, 0, sizeof(params));
4402 4411
4403 if (info->attrs[NL80211_ATTR_MAC]) 4412 if (info->attrs[NL80211_ATTR_MAC])
4404 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4413 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
4405 4414
4406 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4415 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4407 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 4416 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
@@ -4412,7 +4421,28 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4412 if (!rdev->ops->del_station) 4421 if (!rdev->ops->del_station)
4413 return -EOPNOTSUPP; 4422 return -EOPNOTSUPP;
4414 4423
4415 return rdev_del_station(rdev, dev, mac_addr); 4424 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4425 params.subtype =
4426 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4427 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4428 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4429 return -EINVAL;
4430 } else {
4431 /* Default to Deauthentication frame */
4432 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4433 }
4434
4435 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4436 params.reason_code =
4437 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4438 if (params.reason_code == 0)
4439 return -EINVAL; /* 0 is reserved */
4440 } else {
4441 /* Default to reason code 2 */
4442 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4443 }
4444
4445 return rdev_del_station(rdev, dev, &params);
4416} 4446}
4417 4447
4418static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 4448static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
@@ -4624,6 +4654,96 @@ static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4624 return rdev_del_mpath(rdev, dev, dst); 4654 return rdev_del_mpath(rdev, dev, dst);
4625} 4655}
4626 4656
4657static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4658{
4659 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4660 int err;
4661 struct net_device *dev = info->user_ptr[1];
4662 struct mpath_info pinfo;
4663 struct sk_buff *msg;
4664 u8 *dst = NULL;
4665 u8 mpp[ETH_ALEN];
4666
4667 memset(&pinfo, 0, sizeof(pinfo));
4668
4669 if (!info->attrs[NL80211_ATTR_MAC])
4670 return -EINVAL;
4671
4672 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4673
4674 if (!rdev->ops->get_mpp)
4675 return -EOPNOTSUPP;
4676
4677 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4678 return -EOPNOTSUPP;
4679
4680 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4681 if (err)
4682 return err;
4683
4684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4685 if (!msg)
4686 return -ENOMEM;
4687
4688 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4689 dev, dst, mpp, &pinfo) < 0) {
4690 nlmsg_free(msg);
4691 return -ENOBUFS;
4692 }
4693
4694 return genlmsg_reply(msg, info);
4695}
4696
4697static int nl80211_dump_mpp(struct sk_buff *skb,
4698 struct netlink_callback *cb)
4699{
4700 struct mpath_info pinfo;
4701 struct cfg80211_registered_device *rdev;
4702 struct wireless_dev *wdev;
4703 u8 dst[ETH_ALEN];
4704 u8 mpp[ETH_ALEN];
4705 int path_idx = cb->args[2];
4706 int err;
4707
4708 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4709 if (err)
4710 return err;
4711
4712 if (!rdev->ops->dump_mpp) {
4713 err = -EOPNOTSUPP;
4714 goto out_err;
4715 }
4716
4717 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4718 err = -EOPNOTSUPP;
4719 goto out_err;
4720 }
4721
4722 while (1) {
4723 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4724 mpp, &pinfo);
4725 if (err == -ENOENT)
4726 break;
4727 if (err)
4728 goto out_err;
4729
4730 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4731 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4732 wdev->netdev, dst, mpp,
4733 &pinfo) < 0)
4734 goto out;
4735
4736 path_idx++;
4737 }
4738
4739 out:
4740 cb->args[2] = path_idx;
4741 err = skb->len;
4742 out_err:
4743 nl80211_finish_wdev_dump(rdev);
4744 return err;
4745}
4746
4627static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 4747static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4628{ 4748{
4629 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -5923,7 +6043,6 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5923 * function is called under RTNL lock, so this should not be a problem. 6043 * function is called under RTNL lock, so this should not be a problem.
5924 */ 6044 */
5925 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; 6045 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5926 u8 radar_detect_width = 0;
5927 int err; 6046 int err;
5928 bool need_new_beacon = false; 6047 bool need_new_beacon = false;
5929 int len, i; 6048 int len, i;
@@ -6059,10 +6178,8 @@ skip_beacons:
6059 if (err < 0) 6178 if (err < 0)
6060 return err; 6179 return err;
6061 6180
6062 if (err > 0) { 6181 if (err > 0)
6063 radar_detect_width = BIT(params.chandef.width);
6064 params.radar_required = true; 6182 params.radar_required = true;
6065 }
6066 6183
6067 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 6184 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6068 params.block_tx = true; 6185 params.block_tx = true;
@@ -8159,6 +8276,28 @@ static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8159 return -EINVAL; 8276 return -EINVAL;
8160} 8277}
8161 8278
8279static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8280{
8281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8282 struct net_device *dev = info->user_ptr[1];
8283 struct ocb_setup setup = {};
8284 int err;
8285
8286 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8287 if (err)
8288 return err;
8289
8290 return cfg80211_join_ocb(rdev, dev, &setup);
8291}
8292
8293static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8294{
8295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8296 struct net_device *dev = info->user_ptr[1];
8297
8298 return cfg80211_leave_ocb(rdev, dev);
8299}
8300
8162static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 8301static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8163{ 8302{
8164 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -9444,7 +9583,7 @@ static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9444 u16 admitted_time = 0; 9583 u16 admitted_time = 0;
9445 int err; 9584 int err;
9446 9585
9447 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_WMM_ADMISSION)) 9586 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
9448 return -EOPNOTSUPP; 9587 return -EOPNOTSUPP;
9449 9588
9450 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 9589 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
@@ -9460,12 +9599,10 @@ static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9460 return -EINVAL; 9599 return -EINVAL;
9461 9600
9462 /* WMM uses TIDs 0-7 even for TSPEC */ 9601 /* WMM uses TIDs 0-7 even for TSPEC */
9463 if (tsid < IEEE80211_FIRST_TSPEC_TSID) { 9602 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
9464 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_WMM_ADMISSION))
9465 return -EINVAL;
9466 } else {
9467 /* TODO: handle 802.11 TSPEC/admission control 9603 /* TODO: handle 802.11 TSPEC/admission control
9468 * need more attributes for that (e.g. BA session requirement) 9604 * need more attributes for that (e.g. BA session requirement);
9605 * change the WMM adminssion test above to allow both then
9469 */ 9606 */
9470 return -EINVAL; 9607 return -EINVAL;
9471 } 9608 }
@@ -9782,6 +9919,15 @@ static const struct genl_ops nl80211_ops[] = {
9782 NL80211_FLAG_NEED_RTNL, 9919 NL80211_FLAG_NEED_RTNL,
9783 }, 9920 },
9784 { 9921 {
9922 .cmd = NL80211_CMD_GET_MPP,
9923 .doit = nl80211_get_mpp,
9924 .dumpit = nl80211_dump_mpp,
9925 .policy = nl80211_policy,
9926 .flags = GENL_ADMIN_PERM,
9927 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9928 NL80211_FLAG_NEED_RTNL,
9929 },
9930 {
9785 .cmd = NL80211_CMD_SET_MPATH, 9931 .cmd = NL80211_CMD_SET_MPATH,
9786 .doit = nl80211_set_mpath, 9932 .doit = nl80211_set_mpath,
9787 .policy = nl80211_policy, 9933 .policy = nl80211_policy,
@@ -10095,6 +10241,22 @@ static const struct genl_ops nl80211_ops[] = {
10095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 10241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10096 NL80211_FLAG_NEED_RTNL, 10242 NL80211_FLAG_NEED_RTNL,
10097 }, 10243 },
10244 {
10245 .cmd = NL80211_CMD_JOIN_OCB,
10246 .doit = nl80211_join_ocb,
10247 .policy = nl80211_policy,
10248 .flags = GENL_ADMIN_PERM,
10249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10250 NL80211_FLAG_NEED_RTNL,
10251 },
10252 {
10253 .cmd = NL80211_CMD_LEAVE_OCB,
10254 .doit = nl80211_leave_ocb,
10255 .policy = nl80211_policy,
10256 .flags = GENL_ADMIN_PERM,
10257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10258 NL80211_FLAG_NEED_RTNL,
10259 },
10098#ifdef CONFIG_PM 10260#ifdef CONFIG_PM
10099 { 10261 {
10100 .cmd = NL80211_CMD_GET_WOWLAN, 10262 .cmd = NL80211_CMD_GET_WOWLAN,
diff --git a/net/wireless/ocb.c b/net/wireless/ocb.c
new file mode 100644
index 000000000000..c00d4a792319
--- /dev/null
+++ b/net/wireless/ocb.c
@@ -0,0 +1,88 @@
1/*
2 * OCB mode implementation
3 *
4 * Copyright: (c) 2014 Czech Technical University in Prague
5 * (c) 2014 Volkswagen Group Research
6 * Author: Rostislav Lisovy <rostislav.lisovy@fel.cvut.cz>
7 * Funded by: Volkswagen Group Research
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/ieee80211.h>
15#include <net/cfg80211.h>
16#include "nl80211.h"
17#include "core.h"
18#include "rdev-ops.h"
19
20int __cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
21 struct net_device *dev,
22 struct ocb_setup *setup)
23{
24 struct wireless_dev *wdev = dev->ieee80211_ptr;
25 int err;
26
27 ASSERT_WDEV_LOCK(wdev);
28
29 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
30 return -EOPNOTSUPP;
31
32 if (WARN_ON(!setup->chandef.chan))
33 return -EINVAL;
34
35 err = rdev_join_ocb(rdev, dev, setup);
36 if (!err)
37 wdev->chandef = setup->chandef;
38
39 return err;
40}
41
42int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
43 struct net_device *dev,
44 struct ocb_setup *setup)
45{
46 struct wireless_dev *wdev = dev->ieee80211_ptr;
47 int err;
48
49 wdev_lock(wdev);
50 err = __cfg80211_join_ocb(rdev, dev, setup);
51 wdev_unlock(wdev);
52
53 return err;
54}
55
56int __cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
57 struct net_device *dev)
58{
59 struct wireless_dev *wdev = dev->ieee80211_ptr;
60 int err;
61
62 ASSERT_WDEV_LOCK(wdev);
63
64 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
65 return -EOPNOTSUPP;
66
67 if (!rdev->ops->leave_ocb)
68 return -EOPNOTSUPP;
69
70 err = rdev_leave_ocb(rdev, dev);
71 if (!err)
72 memset(&wdev->chandef, 0, sizeof(wdev->chandef));
73
74 return err;
75}
76
77int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
78 struct net_device *dev)
79{
80 struct wireless_dev *wdev = dev->ieee80211_ptr;
81 int err;
82
83 wdev_lock(wdev);
84 err = __cfg80211_leave_ocb(rdev, dev);
85 wdev_unlock(wdev);
86
87 return err;
88}
diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h
index f6d457d6a558..1b3864cd50ca 100644
--- a/net/wireless/rdev-ops.h
+++ b/net/wireless/rdev-ops.h
@@ -178,11 +178,12 @@ static inline int rdev_add_station(struct cfg80211_registered_device *rdev,
178} 178}
179 179
180static inline int rdev_del_station(struct cfg80211_registered_device *rdev, 180static inline int rdev_del_station(struct cfg80211_registered_device *rdev,
181 struct net_device *dev, u8 *mac) 181 struct net_device *dev,
182 struct station_del_parameters *params)
182{ 183{
183 int ret; 184 int ret;
184 trace_rdev_del_station(&rdev->wiphy, dev, mac); 185 trace_rdev_del_station(&rdev->wiphy, dev, params);
185 ret = rdev->ops->del_station(&rdev->wiphy, dev, mac); 186 ret = rdev->ops->del_station(&rdev->wiphy, dev, params);
186 trace_rdev_return_int(&rdev->wiphy, ret); 187 trace_rdev_return_int(&rdev->wiphy, ret);
187 return ret; 188 return ret;
188} 189}
@@ -263,6 +264,18 @@ static inline int rdev_get_mpath(struct cfg80211_registered_device *rdev,
263 264
264} 265}
265 266
267static inline int rdev_get_mpp(struct cfg80211_registered_device *rdev,
268 struct net_device *dev, u8 *dst, u8 *mpp,
269 struct mpath_info *pinfo)
270{
271 int ret;
272
273 trace_rdev_get_mpp(&rdev->wiphy, dev, dst, mpp);
274 ret = rdev->ops->get_mpp(&rdev->wiphy, dev, dst, mpp, pinfo);
275 trace_rdev_return_int_mpath_info(&rdev->wiphy, ret, pinfo);
276 return ret;
277}
278
266static inline int rdev_dump_mpath(struct cfg80211_registered_device *rdev, 279static inline int rdev_dump_mpath(struct cfg80211_registered_device *rdev,
267 struct net_device *dev, int idx, u8 *dst, 280 struct net_device *dev, int idx, u8 *dst,
268 u8 *next_hop, struct mpath_info *pinfo) 281 u8 *next_hop, struct mpath_info *pinfo)
@@ -271,7 +284,20 @@ static inline int rdev_dump_mpath(struct cfg80211_registered_device *rdev,
271 int ret; 284 int ret;
272 trace_rdev_dump_mpath(&rdev->wiphy, dev, idx, dst, next_hop); 285 trace_rdev_dump_mpath(&rdev->wiphy, dev, idx, dst, next_hop);
273 ret = rdev->ops->dump_mpath(&rdev->wiphy, dev, idx, dst, next_hop, 286 ret = rdev->ops->dump_mpath(&rdev->wiphy, dev, idx, dst, next_hop,
274 pinfo); 287 pinfo);
288 trace_rdev_return_int_mpath_info(&rdev->wiphy, ret, pinfo);
289 return ret;
290}
291
292static inline int rdev_dump_mpp(struct cfg80211_registered_device *rdev,
293 struct net_device *dev, int idx, u8 *dst,
294 u8 *mpp, struct mpath_info *pinfo)
295
296{
297 int ret;
298
299 trace_rdev_dump_mpp(&rdev->wiphy, dev, idx, dst, mpp);
300 ret = rdev->ops->dump_mpp(&rdev->wiphy, dev, idx, dst, mpp, pinfo);
275 trace_rdev_return_int_mpath_info(&rdev->wiphy, ret, pinfo); 301 trace_rdev_return_int_mpath_info(&rdev->wiphy, ret, pinfo);
276 return ret; 302 return ret;
277} 303}
@@ -322,6 +348,27 @@ static inline int rdev_leave_mesh(struct cfg80211_registered_device *rdev,
322 return ret; 348 return ret;
323} 349}
324 350
351static inline int rdev_join_ocb(struct cfg80211_registered_device *rdev,
352 struct net_device *dev,
353 struct ocb_setup *setup)
354{
355 int ret;
356 trace_rdev_join_ocb(&rdev->wiphy, dev, setup);
357 ret = rdev->ops->join_ocb(&rdev->wiphy, dev, setup);
358 trace_rdev_return_int(&rdev->wiphy, ret);
359 return ret;
360}
361
362static inline int rdev_leave_ocb(struct cfg80211_registered_device *rdev,
363 struct net_device *dev)
364{
365 int ret;
366 trace_rdev_leave_ocb(&rdev->wiphy, dev);
367 ret = rdev->ops->leave_ocb(&rdev->wiphy, dev);
368 trace_rdev_return_int(&rdev->wiphy, ret);
369 return ret;
370}
371
325static inline int rdev_change_bss(struct cfg80211_registered_device *rdev, 372static inline int rdev_change_bss(struct cfg80211_registered_device *rdev,
326 struct net_device *dev, 373 struct net_device *dev,
327 struct bss_parameters *params) 374 struct bss_parameters *params)
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index dc1668ff543b..0ab3711c79a0 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -80,9 +80,18 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev)
80 if (!request) 80 if (!request)
81 return -ENOMEM; 81 return -ENOMEM;
82 82
83 if (wdev->conn->params.channel) 83 if (wdev->conn->params.channel) {
84 enum ieee80211_band band = wdev->conn->params.channel->band;
85 struct ieee80211_supported_band *sband =
86 wdev->wiphy->bands[band];
87
88 if (!sband) {
89 kfree(request);
90 return -EINVAL;
91 }
84 request->channels[0] = wdev->conn->params.channel; 92 request->channels[0] = wdev->conn->params.channel;
85 else { 93 request->rates[band] = (1 << sband->n_bitrates) - 1;
94 } else {
86 int i = 0, j; 95 int i = 0, j;
87 enum ieee80211_band band; 96 enum ieee80211_band band;
88 struct ieee80211_supported_band *bands; 97 struct ieee80211_supported_band *bands;
diff --git a/net/wireless/trace.h b/net/wireless/trace.h
index 625a6e6d1168..277a85df910e 100644
--- a/net/wireless/trace.h
+++ b/net/wireless/trace.h
@@ -600,6 +600,11 @@ DEFINE_EVENT(wiphy_netdev_evt, rdev_leave_ibss,
600 TP_ARGS(wiphy, netdev) 600 TP_ARGS(wiphy, netdev)
601); 601);
602 602
603DEFINE_EVENT(wiphy_netdev_evt, rdev_leave_ocb,
604 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev),
605 TP_ARGS(wiphy, netdev)
606);
607
603DEFINE_EVENT(wiphy_netdev_evt, rdev_flush_pmksa, 608DEFINE_EVENT(wiphy_netdev_evt, rdev_flush_pmksa,
604 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev), 609 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev),
605 TP_ARGS(wiphy, netdev) 610 TP_ARGS(wiphy, netdev)
@@ -680,9 +685,34 @@ DECLARE_EVENT_CLASS(wiphy_netdev_mac_evt,
680 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(sta_mac)) 685 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(sta_mac))
681); 686);
682 687
683DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_del_station, 688DECLARE_EVENT_CLASS(station_del,
684 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, const u8 *mac), 689 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
685 TP_ARGS(wiphy, netdev, mac) 690 struct station_del_parameters *params),
691 TP_ARGS(wiphy, netdev, params),
692 TP_STRUCT__entry(
693 WIPHY_ENTRY
694 NETDEV_ENTRY
695 MAC_ENTRY(sta_mac)
696 __field(u8, subtype)
697 __field(u16, reason_code)
698 ),
699 TP_fast_assign(
700 WIPHY_ASSIGN;
701 NETDEV_ASSIGN;
702 MAC_ASSIGN(sta_mac, params->mac);
703 __entry->subtype = params->subtype;
704 __entry->reason_code = params->reason_code;
705 ),
706 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", station mac: " MAC_PR_FMT
707 ", subtype: %u, reason_code: %u",
708 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(sta_mac),
709 __entry->subtype, __entry->reason_code)
710);
711
712DEFINE_EVENT(station_del, rdev_del_station,
713 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
714 struct station_del_parameters *params),
715 TP_ARGS(wiphy, netdev, params)
686); 716);
687 717
688DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_get_station, 718DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_get_station,
@@ -801,6 +831,51 @@ TRACE_EVENT(rdev_dump_mpath,
801 MAC_PR_ARG(next_hop)) 831 MAC_PR_ARG(next_hop))
802); 832);
803 833
834TRACE_EVENT(rdev_get_mpp,
835 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
836 u8 *dst, u8 *mpp),
837 TP_ARGS(wiphy, netdev, dst, mpp),
838 TP_STRUCT__entry(
839 WIPHY_ENTRY
840 NETDEV_ENTRY
841 MAC_ENTRY(dst)
842 MAC_ENTRY(mpp)
843 ),
844 TP_fast_assign(
845 WIPHY_ASSIGN;
846 NETDEV_ASSIGN;
847 MAC_ASSIGN(dst, dst);
848 MAC_ASSIGN(mpp, mpp);
849 ),
850 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", destination: " MAC_PR_FMT
851 ", mpp: " MAC_PR_FMT, WIPHY_PR_ARG, NETDEV_PR_ARG,
852 MAC_PR_ARG(dst), MAC_PR_ARG(mpp))
853);
854
855TRACE_EVENT(rdev_dump_mpp,
856 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, int idx,
857 u8 *dst, u8 *mpp),
858 TP_ARGS(wiphy, netdev, idx, mpp, dst),
859 TP_STRUCT__entry(
860 WIPHY_ENTRY
861 NETDEV_ENTRY
862 MAC_ENTRY(dst)
863 MAC_ENTRY(mpp)
864 __field(int, idx)
865 ),
866 TP_fast_assign(
867 WIPHY_ASSIGN;
868 NETDEV_ASSIGN;
869 MAC_ASSIGN(dst, dst);
870 MAC_ASSIGN(mpp, mpp);
871 __entry->idx = idx;
872 ),
873 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", index: %d, destination: "
874 MAC_PR_FMT ", mpp: " MAC_PR_FMT,
875 WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->idx, MAC_PR_ARG(dst),
876 MAC_PR_ARG(mpp))
877);
878
804TRACE_EVENT(rdev_return_int_mpath_info, 879TRACE_EVENT(rdev_return_int_mpath_info,
805 TP_PROTO(struct wiphy *wiphy, int ret, struct mpath_info *pinfo), 880 TP_PROTO(struct wiphy *wiphy, int ret, struct mpath_info *pinfo),
806 TP_ARGS(wiphy, ret, pinfo), 881 TP_ARGS(wiphy, ret, pinfo),
@@ -1246,6 +1321,22 @@ TRACE_EVENT(rdev_join_ibss,
1246 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(bssid), __entry->ssid) 1321 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(bssid), __entry->ssid)
1247); 1322);
1248 1323
1324TRACE_EVENT(rdev_join_ocb,
1325 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
1326 const struct ocb_setup *setup),
1327 TP_ARGS(wiphy, netdev, setup),
1328 TP_STRUCT__entry(
1329 WIPHY_ENTRY
1330 NETDEV_ENTRY
1331 ),
1332 TP_fast_assign(
1333 WIPHY_ASSIGN;
1334 NETDEV_ASSIGN;
1335 ),
1336 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT,
1337 WIPHY_PR_ARG, NETDEV_PR_ARG)
1338);
1339
1249TRACE_EVENT(rdev_set_wiphy_params, 1340TRACE_EVENT(rdev_set_wiphy_params,
1250 TP_PROTO(struct wiphy *wiphy, u32 changed), 1341 TP_PROTO(struct wiphy *wiphy, u32 changed),
1251 TP_ARGS(wiphy, changed), 1342 TP_ARGS(wiphy, changed),
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 5e233a577d0f..d0ac795445b7 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -442,7 +442,8 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
442 break; 442 break;
443 case cpu_to_le16(0): 443 case cpu_to_le16(0):
444 if (iftype != NL80211_IFTYPE_ADHOC && 444 if (iftype != NL80211_IFTYPE_ADHOC &&
445 iftype != NL80211_IFTYPE_STATION) 445 iftype != NL80211_IFTYPE_STATION &&
446 iftype != NL80211_IFTYPE_OCB)
446 return -1; 447 return -1;
447 break; 448 break;
448 } 449 }
@@ -519,6 +520,7 @@ int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
519 memcpy(hdr.addr3, skb->data, ETH_ALEN); 520 memcpy(hdr.addr3, skb->data, ETH_ALEN);
520 hdrlen = 24; 521 hdrlen = 24;
521 break; 522 break;
523 case NL80211_IFTYPE_OCB:
522 case NL80211_IFTYPE_ADHOC: 524 case NL80211_IFTYPE_ADHOC:
523 /* DA SA BSSID */ 525 /* DA SA BSSID */
524 memcpy(hdr.addr1, skb->data, ETH_ALEN); 526 memcpy(hdr.addr1, skb->data, ETH_ALEN);
@@ -937,6 +939,7 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
937 if (dev->ieee80211_ptr->use_4addr) 939 if (dev->ieee80211_ptr->use_4addr)
938 break; 940 break;
939 /* fall through */ 941 /* fall through */
942 case NL80211_IFTYPE_OCB:
940 case NL80211_IFTYPE_P2P_CLIENT: 943 case NL80211_IFTYPE_P2P_CLIENT:
941 case NL80211_IFTYPE_ADHOC: 944 case NL80211_IFTYPE_ADHOC:
942 dev->priv_flags |= IFF_DONT_BRIDGE; 945 dev->priv_flags |= IFF_DONT_BRIDGE;