aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2013-10-07 15:40:44 -0400
committerDavid S. Miller <davem@davemloft.net>2013-10-07 15:40:44 -0400
commit7009deab19d7be03e05f67ceac56cfdfc73aa71c (patch)
tree106f789a079e606753809fad4290644a9310d62d
parent5cde282938915f36a2e6769b51c24c4159654859 (diff)
parent274dede8c52036a1849ea970fab8d185fb0dce2b (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next
Conflicts: drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h drivers/net/wireless/rtlwifi/rtl8188ee/phy.h drivers/net/wireless/rtlwifi/rtl8192ce/phy.h drivers/net/wireless/rtlwifi/rtl8192de/phy.h drivers/net/wireless/rtlwifi/rtl8723ae/phy.h Just some minor conflicts between the wireless-next changes and Joe Perches's "extern" removal from function prototypes in header files. John W. Linville says: ==================== Regarding the Bluetooth bits, Gustavo says: "The big work here is from Marcel and Johan. They did a lot of work in the L2CAP, HCI and MGMT layers. The most important ones are the addition of a new MGMT command to enable/disable LE advertisement and the introduction of the HCI user channel to allow applications to get directly and exclusive access to Bluetooth devices." As to the ath10k bits, Kalle says: "Bartosz dropped support for qca98xx hw1.0 hardware from ath10k, it's just too much to support it. Michal added support for the new firmware interface. Marek fixed WEP in AP and IBSS mode. Rest of the changes are minor fixes or cleanups." And also: "Major changes are: * throughput improvements including aligning the RX frames correctly and optimising HTT layer (Michal) * remove qca98xx hw1.0 support (Bartosz) * add support for firmware version 999.999.0.636 (Michal) * firmware htt statistics support (Kalle) * fix WEP in AP and IBSS mode (Marek) * fix a mutex unlock balance in debugfs file (Shafi) And of course there's a lot of smaller fixes and cleanup." For the wl12xx bits, Luca says: "Here are some patches intended for 3.13. Eliad is upstreaming a bunch of patches that have been pending in the internal tree. Mostly bugfixes and other small improvements." Along with that... Arend and friends bring us a batch of brcmfmac updates, Larry Finger offers some rtlwifi refactoring, and Sujith sends the usual batch of ath9k updates. As usual, there are a number of other small updates from a variety of players as well. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/bluetooth/Makefile2
-rw-r--r--drivers/bluetooth/btmrvl_drv.h12
-rw-r--r--drivers/bluetooth/btmrvl_main.c269
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c15
-rw-r--r--drivers/bluetooth/btmrvl_sdio.h2
-rw-r--r--drivers/bluetooth/hci_vhci.c170
-rw-r--r--drivers/net/wireless/adm8211.c1
-rw-r--r--drivers/net/wireless/airo.c1
-rw-r--r--drivers/net/wireless/ath/ar5523/ar5523.c1
-rw-r--r--drivers/net/wireless/ath/ath10k/bmi.c42
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.c382
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.h120
-rw-r--r--drivers/net/wireless/ath/ath10k/core.c70
-rw-r--r--drivers/net/wireless/ath/ath10k/core.h35
-rw-r--r--drivers/net/wireless/ath/ath10k/debug.c144
-rw-r--r--drivers/net/wireless/ath/ath10k/debug.h14
-rw-r--r--drivers/net/wireless/ath/ath10k/htc.c241
-rw-r--r--drivers/net/wireless/ath/ath10k/htc.h5
-rw-r--r--drivers/net/wireless/ath/ath10k/htt.c19
-rw-r--r--drivers/net/wireless/ath/ath10k/htt.h13
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_rx.c314
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_tx.c285
-rw-r--r--drivers/net/wireless/ath/ath10k/hw.h25
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.c244
-rw-r--r--drivers/net/wireless/ath/ath10k/pci.c446
-rw-r--r--drivers/net/wireless/ath/ath10k/pci.h73
-rw-r--r--drivers/net/wireless/ath/ath10k/rx_desc.h24
-rw-r--r--drivers/net/wireless/ath/ath10k/trace.h32
-rw-r--r--drivers/net/wireless/ath/ath10k/txrx.c67
-rw-r--r--drivers/net/wireless/ath/ath10k/txrx.h5
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.c232
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.h71
-rw-r--r--drivers/net/wireless/ath/ath5k/ahb.c15
-rw-r--r--drivers/net/wireless/ath/ath9k/ahb.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/antenna.c36
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c5
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_calib.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_phy.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c92
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c34
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.h2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_hw.c5
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_mci.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c32
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_rtt.c58
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9485_initvals.h218
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9565_1p0_initvals.h24
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h20
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c14
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c446
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.h12
-rw-r--r--drivers/net/wireless/ath/ath9k/dfs_debug.c25
-rw-r--r--drivers/net/wireless/ath/ath9k/dfs_pri_detector.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_4k.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_9287.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_def.c12
-rw-r--r--drivers/net/wireless/ath/ath9k/gpio.c22
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_debug.c456
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c59
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h26
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c20
-rw-r--r--drivers/net/wireless/ath/ath9k/link.c12
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c195
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c32
-rw-r--r--drivers/net/wireless/ath/ath9k/wmi.h2
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c2
-rw-r--r--drivers/net/wireless/ath/wil6210/pcie_bus.c1
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c13
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd.h2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c38
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c234
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/fweh.h5
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.c28
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.h8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c5
-rw-r--r--drivers/net/wireless/brcm80211/include/brcm_hw_ids.h1
-rw-r--r--drivers/net/wireless/cw1200/cw1200_spi.c4
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c2
-rw-r--r--drivers/net/wireless/iwlegacy/3945-mac.c2
-rw-r--r--drivers/net/wireless/iwlegacy/4965-mac.c2
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c8
-rw-r--r--drivers/net/wireless/libertas/if_spi.c2
-rw-r--r--drivers/net/wireless/mwifiex/pcie.c6
-rw-r--r--drivers/net/wireless/mwl8k.c2
-rw-r--r--drivers/net/wireless/orinoco/orinoco_nortel.c2
-rw-r--r--drivers/net/wireless/orinoco/orinoco_pci.c2
-rw-r--r--drivers/net/wireless/orinoco/orinoco_plx.c2
-rw-r--r--drivers/net/wireless/orinoco/orinoco_tmd.c2
-rw-r--r--drivers/net/wireless/p54/p54pci.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2800.h2
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c49
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c17
-rw-r--r--drivers/net/wireless/rtl818x/rtl8180/dev.c1
-rw-r--r--drivers/net/wireless/rtlwifi/base.c29
-rw-r--r--drivers/net/wireless/rtlwifi/base.h2
-rw-r--r--drivers/net/wireless/rtlwifi/efuse.c18
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8188ee/hw.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8188ee/phy.c28
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8188ee/phy.h17
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8188ee/sw.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8188ee/trx.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c25
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c30
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/def.h2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/phy.h10
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/reg.h20
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/sw.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/trx.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/mac.c187
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/sw.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/trx.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/dm.c8
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/hw.c18
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/phy.c28
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/phy.h17
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/sw.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/trx.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/reg.h5
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/trx.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8723ae/phy.c29
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8723ae/phy.h19
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8723ae/sw.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8723ae/trx.c1
-rw-r--r--drivers/net/wireless/rtlwifi/usb.c6
-rw-r--r--drivers/net/wireless/rtlwifi/wifi.h2
-rw-r--r--drivers/net/wireless/ti/wl1251/spi.c2
-rw-r--r--drivers/net/wireless/ti/wl12xx/main.c2
-rw-r--r--drivers/net/wireless/ti/wl18xx/main.c95
-rw-r--r--drivers/net/wireless/ti/wl18xx/reg.h33
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.c58
-rw-r--r--drivers/net/wireless/ti/wlcore/main.c158
-rw-r--r--drivers/net/wireless/ti/wlcore/ps.c4
-rw-r--r--drivers/net/wireless/ti/wlcore/scan.c27
-rw-r--r--drivers/net/wireless/ti/wlcore/spi.c2
-rw-r--r--drivers/net/wireless/ti/wlcore/testmode.c13
-rw-r--r--drivers/net/wireless/ti/wlcore/tx.c27
-rw-r--r--drivers/net/wireless/ti/wlcore/tx.h3
-rw-r--r--drivers/net/wireless/ti/wlcore/wlcore.h2
-rw-r--r--drivers/net/wireless/ti/wlcore/wlcore_i.h11
-rw-r--r--include/net/bluetooth/bluetooth.h5
-rw-r--r--include/net/bluetooth/hci.h81
-rw-r--r--include/net/bluetooth/hci_core.h2
-rw-r--r--include/net/bluetooth/l2cap.h1
-rw-r--r--include/net/bluetooth/mgmt.h11
-rw-r--r--net/bluetooth/Makefile2
-rw-r--r--net/bluetooth/af_bluetooth.c41
-rw-r--r--net/bluetooth/hci_conn.c4
-rw-r--r--net/bluetooth/hci_core.c189
-rw-r--r--net/bluetooth/hci_event.c17
-rw-r--r--net/bluetooth/hci_sock.c204
-rw-r--r--net/bluetooth/l2cap_core.c162
-rw-r--r--net/bluetooth/l2cap_sock.c20
-rw-r--r--net/bluetooth/mgmt.c562
-rw-r--r--net/bluetooth/rfcomm/sock.c7
-rw-r--r--net/bluetooth/smp.c15
162 files changed, 4834 insertions, 3207 deletions
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 4afae20df512..9fe8a875a827 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -30,3 +30,5 @@ hci_uart-$(CONFIG_BT_HCIUART_LL) += hci_ll.o
30hci_uart-$(CONFIG_BT_HCIUART_ATH3K) += hci_ath.o 30hci_uart-$(CONFIG_BT_HCIUART_ATH3K) += hci_ath.o
31hci_uart-$(CONFIG_BT_HCIUART_3WIRE) += hci_h5.o 31hci_uart-$(CONFIG_BT_HCIUART_3WIRE) += hci_h5.o
32hci_uart-objs := $(hci_uart-y) 32hci_uart-objs := $(hci_uart-y)
33
34ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/bluetooth/btmrvl_drv.h b/drivers/bluetooth/btmrvl_drv.h
index 27068d149380..f9d183387f45 100644
--- a/drivers/bluetooth/btmrvl_drv.h
+++ b/drivers/bluetooth/btmrvl_drv.h
@@ -23,6 +23,8 @@
23#include <linux/bitops.h> 23#include <linux/bitops.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <net/bluetooth/bluetooth.h> 25#include <net/bluetooth/bluetooth.h>
26#include <linux/ctype.h>
27#include <linux/firmware.h>
26 28
27#define BTM_HEADER_LEN 4 29#define BTM_HEADER_LEN 4
28#define BTM_UPLD_SIZE 2312 30#define BTM_UPLD_SIZE 2312
@@ -41,6 +43,8 @@ struct btmrvl_thread {
41struct btmrvl_device { 43struct btmrvl_device {
42 void *card; 44 void *card;
43 struct hci_dev *hcidev; 45 struct hci_dev *hcidev;
46 struct device *dev;
47 const char *cal_data;
44 48
45 u8 dev_type; 49 u8 dev_type;
46 50
@@ -91,6 +95,7 @@ struct btmrvl_private {
91#define BT_CMD_HOST_SLEEP_CONFIG 0x59 95#define BT_CMD_HOST_SLEEP_CONFIG 0x59
92#define BT_CMD_HOST_SLEEP_ENABLE 0x5A 96#define BT_CMD_HOST_SLEEP_ENABLE 0x5A
93#define BT_CMD_MODULE_CFG_REQ 0x5B 97#define BT_CMD_MODULE_CFG_REQ 0x5B
98#define BT_CMD_LOAD_CONFIG_DATA 0x61
94 99
95/* Sub-commands: Module Bringup/Shutdown Request/Response */ 100/* Sub-commands: Module Bringup/Shutdown Request/Response */
96#define MODULE_BRINGUP_REQ 0xF1 101#define MODULE_BRINGUP_REQ 0xF1
@@ -116,11 +121,8 @@ struct btmrvl_private {
116#define PS_SLEEP 0x01 121#define PS_SLEEP 0x01
117#define PS_AWAKE 0x00 122#define PS_AWAKE 0x00
118 123
119struct btmrvl_cmd { 124#define BT_CMD_DATA_SIZE 32
120 __le16 ocf_ogf; 125#define BT_CAL_DATA_SIZE 28
121 u8 length;
122 u8 data[4];
123} __packed;
124 126
125struct btmrvl_event { 127struct btmrvl_event {
126 u8 ec; /* event counter */ 128 u8 ec; /* event counter */
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 9a9f51875df5..6e7bd4e4adbb 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -57,8 +57,7 @@ bool btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb)
57 ocf = hci_opcode_ocf(opcode); 57 ocf = hci_opcode_ocf(opcode);
58 ogf = hci_opcode_ogf(opcode); 58 ogf = hci_opcode_ogf(opcode);
59 59
60 if (ocf == BT_CMD_MODULE_CFG_REQ && 60 if (priv->btmrvl_dev.sendcmdflag) {
61 priv->btmrvl_dev.sendcmdflag) {
62 priv->btmrvl_dev.sendcmdflag = false; 61 priv->btmrvl_dev.sendcmdflag = false;
63 priv->adapter->cmd_complete = true; 62 priv->adapter->cmd_complete = true;
64 wake_up_interruptible(&priv->adapter->cmd_wait_q); 63 wake_up_interruptible(&priv->adapter->cmd_wait_q);
@@ -116,7 +115,6 @@ int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb)
116 adapter->hs_state = HS_ACTIVATED; 115 adapter->hs_state = HS_ACTIVATED;
117 if (adapter->psmode) 116 if (adapter->psmode)
118 adapter->ps_state = PS_SLEEP; 117 adapter->ps_state = PS_SLEEP;
119 wake_up_interruptible(&adapter->cmd_wait_q);
120 BT_DBG("HS ACTIVATED!"); 118 BT_DBG("HS ACTIVATED!");
121 } else { 119 } else {
122 BT_DBG("HS Enable failed"); 120 BT_DBG("HS Enable failed");
@@ -168,22 +166,24 @@ exit:
168} 166}
169EXPORT_SYMBOL_GPL(btmrvl_process_event); 167EXPORT_SYMBOL_GPL(btmrvl_process_event);
170 168
171int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd) 169static int btmrvl_send_sync_cmd(struct btmrvl_private *priv, u16 cmd_no,
170 const void *param, u8 len)
172{ 171{
173 struct sk_buff *skb; 172 struct sk_buff *skb;
174 struct btmrvl_cmd *cmd; 173 struct hci_command_hdr *hdr;
175 int ret = 0;
176 174
177 skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC); 175 skb = bt_skb_alloc(HCI_COMMAND_HDR_SIZE + len, GFP_ATOMIC);
178 if (skb == NULL) { 176 if (skb == NULL) {
179 BT_ERR("No free skb"); 177 BT_ERR("No free skb");
180 return -ENOMEM; 178 return -ENOMEM;
181 } 179 }
182 180
183 cmd = (struct btmrvl_cmd *) skb_put(skb, sizeof(*cmd)); 181 hdr = (struct hci_command_hdr *)skb_put(skb, HCI_COMMAND_HDR_SIZE);
184 cmd->ocf_ogf = cpu_to_le16(hci_opcode_pack(OGF, BT_CMD_MODULE_CFG_REQ)); 182 hdr->opcode = cpu_to_le16(hci_opcode_pack(OGF, cmd_no));
185 cmd->length = 1; 183 hdr->plen = len;
186 cmd->data[0] = subcmd; 184
185 if (len)
186 memcpy(skb_put(skb, len), param, len);
187 187
188 bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT; 188 bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
189 189
@@ -194,19 +194,23 @@ int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd)
194 194
195 priv->adapter->cmd_complete = false; 195 priv->adapter->cmd_complete = false;
196 196
197 BT_DBG("Queue module cfg Command");
198
199 wake_up_interruptible(&priv->main_thread.wait_q); 197 wake_up_interruptible(&priv->main_thread.wait_q);
200 198
201 if (!wait_event_interruptible_timeout(priv->adapter->cmd_wait_q, 199 if (!wait_event_interruptible_timeout(priv->adapter->cmd_wait_q,
202 priv->adapter->cmd_complete, 200 priv->adapter->cmd_complete,
203 msecs_to_jiffies(WAIT_UNTIL_CMD_RESP))) { 201 msecs_to_jiffies(WAIT_UNTIL_CMD_RESP)))
204 ret = -ETIMEDOUT; 202 return -ETIMEDOUT;
205 BT_ERR("module_cfg_cmd(%x): timeout: %d",
206 subcmd, priv->btmrvl_dev.sendcmdflag);
207 }
208 203
209 BT_DBG("module cfg Command done"); 204 return 0;
205}
206
207int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd)
208{
209 int ret;
210
211 ret = btmrvl_send_sync_cmd(priv, BT_CMD_MODULE_CFG_REQ, &subcmd, 1);
212 if (ret)
213 BT_ERR("module_cfg_cmd(%x) failed\n", subcmd);
210 214
211 return ret; 215 return ret;
212} 216}
@@ -214,61 +218,36 @@ EXPORT_SYMBOL_GPL(btmrvl_send_module_cfg_cmd);
214 218
215int btmrvl_send_hscfg_cmd(struct btmrvl_private *priv) 219int btmrvl_send_hscfg_cmd(struct btmrvl_private *priv)
216{ 220{
217 struct sk_buff *skb; 221 int ret;
218 struct btmrvl_cmd *cmd; 222 u8 param[2];
219
220 skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
221 if (!skb) {
222 BT_ERR("No free skb");
223 return -ENOMEM;
224 }
225
226 cmd = (struct btmrvl_cmd *) skb_put(skb, sizeof(*cmd));
227 cmd->ocf_ogf = cpu_to_le16(hci_opcode_pack(OGF,
228 BT_CMD_HOST_SLEEP_CONFIG));
229 cmd->length = 2;
230 cmd->data[0] = (priv->btmrvl_dev.gpio_gap & 0xff00) >> 8;
231 cmd->data[1] = (u8) (priv->btmrvl_dev.gpio_gap & 0x00ff);
232 223
233 bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT; 224 param[0] = (priv->btmrvl_dev.gpio_gap & 0xff00) >> 8;
225 param[1] = (u8) (priv->btmrvl_dev.gpio_gap & 0x00ff);
234 226
235 skb->dev = (void *) priv->btmrvl_dev.hcidev; 227 BT_DBG("Sending HSCFG Command, gpio=0x%x, gap=0x%x",
236 skb_queue_head(&priv->adapter->tx_queue, skb); 228 param[0], param[1]);
237 229
238 BT_DBG("Queue HSCFG Command, gpio=0x%x, gap=0x%x", cmd->data[0], 230 ret = btmrvl_send_sync_cmd(priv, BT_CMD_HOST_SLEEP_CONFIG, param, 2);
239 cmd->data[1]); 231 if (ret)
232 BT_ERR("HSCFG command failed\n");
240 233
241 return 0; 234 return ret;
242} 235}
243EXPORT_SYMBOL_GPL(btmrvl_send_hscfg_cmd); 236EXPORT_SYMBOL_GPL(btmrvl_send_hscfg_cmd);
244 237
245int btmrvl_enable_ps(struct btmrvl_private *priv) 238int btmrvl_enable_ps(struct btmrvl_private *priv)
246{ 239{
247 struct sk_buff *skb; 240 int ret;
248 struct btmrvl_cmd *cmd; 241 u8 param;
249
250 skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
251 if (skb == NULL) {
252 BT_ERR("No free skb");
253 return -ENOMEM;
254 }
255
256 cmd = (struct btmrvl_cmd *) skb_put(skb, sizeof(*cmd));
257 cmd->ocf_ogf = cpu_to_le16(hci_opcode_pack(OGF,
258 BT_CMD_AUTO_SLEEP_MODE));
259 cmd->length = 1;
260 242
261 if (priv->btmrvl_dev.psmode) 243 if (priv->btmrvl_dev.psmode)
262 cmd->data[0] = BT_PS_ENABLE; 244 param = BT_PS_ENABLE;
263 else 245 else
264 cmd->data[0] = BT_PS_DISABLE; 246 param = BT_PS_DISABLE;
265
266 bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
267 247
268 skb->dev = (void *) priv->btmrvl_dev.hcidev; 248 ret = btmrvl_send_sync_cmd(priv, BT_CMD_AUTO_SLEEP_MODE, &param, 1);
269 skb_queue_head(&priv->adapter->tx_queue, skb); 249 if (ret)
270 250 BT_ERR("PSMODE command failed\n");
271 BT_DBG("Queue PSMODE Command:%d", cmd->data[0]);
272 251
273 return 0; 252 return 0;
274} 253}
@@ -276,37 +255,11 @@ EXPORT_SYMBOL_GPL(btmrvl_enable_ps);
276 255
277int btmrvl_enable_hs(struct btmrvl_private *priv) 256int btmrvl_enable_hs(struct btmrvl_private *priv)
278{ 257{
279 struct sk_buff *skb; 258 int ret;
280 struct btmrvl_cmd *cmd;
281 int ret = 0;
282
283 skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
284 if (skb == NULL) {
285 BT_ERR("No free skb");
286 return -ENOMEM;
287 }
288
289 cmd = (struct btmrvl_cmd *) skb_put(skb, sizeof(*cmd));
290 cmd->ocf_ogf = cpu_to_le16(hci_opcode_pack(OGF, BT_CMD_HOST_SLEEP_ENABLE));
291 cmd->length = 0;
292
293 bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
294
295 skb->dev = (void *) priv->btmrvl_dev.hcidev;
296 skb_queue_head(&priv->adapter->tx_queue, skb);
297
298 BT_DBG("Queue hs enable Command");
299
300 wake_up_interruptible(&priv->main_thread.wait_q);
301 259
302 if (!wait_event_interruptible_timeout(priv->adapter->cmd_wait_q, 260 ret = btmrvl_send_sync_cmd(priv, BT_CMD_HOST_SLEEP_ENABLE, NULL, 0);
303 priv->adapter->hs_state, 261 if (ret)
304 msecs_to_jiffies(WAIT_UNTIL_HS_STATE_CHANGED))) { 262 BT_ERR("Host sleep enable command failed\n");
305 ret = -ETIMEDOUT;
306 BT_ERR("timeout: %d, %d,%d", priv->adapter->hs_state,
307 priv->adapter->ps_state,
308 priv->adapter->wakeup_tries);
309 }
310 263
311 return ret; 264 return ret;
312} 265}
@@ -480,6 +433,137 @@ static int btmrvl_open(struct hci_dev *hdev)
480} 433}
481 434
482/* 435/*
436 * This function parses provided calibration data input. It should contain
437 * hex bytes separated by space or new line character. Here is an example.
438 * 00 1C 01 37 FF FF FF FF 02 04 7F 01
439 * CE BA 00 00 00 2D C6 C0 00 00 00 00
440 * 00 F0 00 00
441 */
442static int btmrvl_parse_cal_cfg(const u8 *src, u32 len, u8 *dst, u32 dst_size)
443{
444 const u8 *s = src;
445 u8 *d = dst;
446 int ret;
447 u8 tmp[3];
448
449 tmp[2] = '\0';
450 while ((s - src) <= len - 2) {
451 if (isspace(*s)) {
452 s++;
453 continue;
454 }
455
456 if (isxdigit(*s)) {
457 if ((d - dst) >= dst_size) {
458 BT_ERR("calibration data file too big!!!");
459 return -EINVAL;
460 }
461
462 memcpy(tmp, s, 2);
463
464 ret = kstrtou8(tmp, 16, d++);
465 if (ret < 0)
466 return ret;
467
468 s += 2;
469 } else {
470 return -EINVAL;
471 }
472 }
473 if (d == dst)
474 return -EINVAL;
475
476 return 0;
477}
478
479static int btmrvl_load_cal_data(struct btmrvl_private *priv,
480 u8 *config_data)
481{
482 int i, ret;
483 u8 data[BT_CMD_DATA_SIZE];
484
485 data[0] = 0x00;
486 data[1] = 0x00;
487 data[2] = 0x00;
488 data[3] = BT_CMD_DATA_SIZE - 4;
489
490 /* Swap cal-data bytes. Each four bytes are swapped. Considering 4
491 * byte SDIO header offset, mapping of input and output bytes will be
492 * {3, 2, 1, 0} -> {0+4, 1+4, 2+4, 3+4},
493 * {7, 6, 5, 4} -> {4+4, 5+4, 6+4, 7+4} */
494 for (i = 4; i < BT_CMD_DATA_SIZE; i++)
495 data[i] = config_data[(i / 4) * 8 - 1 - i];
496
497 print_hex_dump_bytes("Calibration data: ",
498 DUMP_PREFIX_OFFSET, data, BT_CMD_DATA_SIZE);
499
500 ret = btmrvl_send_sync_cmd(priv, BT_CMD_LOAD_CONFIG_DATA, data,
501 BT_CMD_DATA_SIZE);
502 if (ret)
503 BT_ERR("Failed to download caibration data\n");
504
505 return 0;
506}
507
508static int
509btmrvl_process_cal_cfg(struct btmrvl_private *priv, u8 *data, u32 size)
510{
511 u8 cal_data[BT_CAL_DATA_SIZE];
512 int ret;
513
514 ret = btmrvl_parse_cal_cfg(data, size, cal_data, sizeof(cal_data));
515 if (ret)
516 return ret;
517
518 ret = btmrvl_load_cal_data(priv, cal_data);
519 if (ret) {
520 BT_ERR("Fail to load calibrate data");
521 return ret;
522 }
523
524 return 0;
525}
526
527static int btmrvl_cal_data_config(struct btmrvl_private *priv)
528{
529 const struct firmware *cfg;
530 int ret;
531 const char *cal_data = priv->btmrvl_dev.cal_data;
532
533 if (!cal_data)
534 return 0;
535
536 ret = request_firmware(&cfg, cal_data, priv->btmrvl_dev.dev);
537 if (ret < 0) {
538 BT_DBG("Failed to get %s file, skipping cal data download",
539 cal_data);
540 return 0;
541 }
542
543 ret = btmrvl_process_cal_cfg(priv, (u8 *)cfg->data, cfg->size);
544 release_firmware(cfg);
545 return ret;
546}
547
548static int btmrvl_setup(struct hci_dev *hdev)
549{
550 struct btmrvl_private *priv = hci_get_drvdata(hdev);
551
552 btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
553
554 if (btmrvl_cal_data_config(priv))
555 BT_ERR("Set cal data failed");
556
557 priv->btmrvl_dev.psmode = 1;
558 btmrvl_enable_ps(priv);
559
560 priv->btmrvl_dev.gpio_gap = 0xffff;
561 btmrvl_send_hscfg_cmd(priv);
562
563 return 0;
564}
565
566/*
483 * This function handles the event generated by firmware, rx data 567 * This function handles the event generated by firmware, rx data
484 * received from firmware, and tx data sent from kernel. 568 * received from firmware, and tx data sent from kernel.
485 */ 569 */
@@ -572,8 +656,7 @@ int btmrvl_register_hdev(struct btmrvl_private *priv)
572 hdev->flush = btmrvl_flush; 656 hdev->flush = btmrvl_flush;
573 hdev->send = btmrvl_send_frame; 657 hdev->send = btmrvl_send_frame;
574 hdev->ioctl = btmrvl_ioctl; 658 hdev->ioctl = btmrvl_ioctl;
575 659 hdev->setup = btmrvl_setup;
576 btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
577 660
578 hdev->dev_type = priv->btmrvl_dev.dev_type; 661 hdev->dev_type = priv->btmrvl_dev.dev_type;
579 662
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 00da6df9f71e..332475e400cf 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -18,7 +18,6 @@
18 * this warranty disclaimer. 18 * this warranty disclaimer.
19 **/ 19 **/
20 20
21#include <linux/firmware.h>
22#include <linux/slab.h> 21#include <linux/slab.h>
23 22
24#include <linux/mmc/sdio_ids.h> 23#include <linux/mmc/sdio_ids.h>
@@ -102,6 +101,7 @@ static const struct btmrvl_sdio_card_reg btmrvl_reg_88xx = {
102static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = { 101static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = {
103 .helper = "mrvl/sd8688_helper.bin", 102 .helper = "mrvl/sd8688_helper.bin",
104 .firmware = "mrvl/sd8688.bin", 103 .firmware = "mrvl/sd8688.bin",
104 .cal_data = NULL,
105 .reg = &btmrvl_reg_8688, 105 .reg = &btmrvl_reg_8688,
106 .sd_blksz_fw_dl = 64, 106 .sd_blksz_fw_dl = 64,
107}; 107};
@@ -109,6 +109,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = {
109static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = { 109static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = {
110 .helper = NULL, 110 .helper = NULL,
111 .firmware = "mrvl/sd8787_uapsta.bin", 111 .firmware = "mrvl/sd8787_uapsta.bin",
112 .cal_data = NULL,
112 .reg = &btmrvl_reg_87xx, 113 .reg = &btmrvl_reg_87xx,
113 .sd_blksz_fw_dl = 256, 114 .sd_blksz_fw_dl = 256,
114}; 115};
@@ -116,6 +117,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = {
116static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = { 117static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = {
117 .helper = NULL, 118 .helper = NULL,
118 .firmware = "mrvl/sd8797_uapsta.bin", 119 .firmware = "mrvl/sd8797_uapsta.bin",
120 .cal_data = "mrvl/sd8797_caldata.conf",
119 .reg = &btmrvl_reg_87xx, 121 .reg = &btmrvl_reg_87xx,
120 .sd_blksz_fw_dl = 256, 122 .sd_blksz_fw_dl = 256,
121}; 123};
@@ -123,6 +125,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = {
123static const struct btmrvl_sdio_device btmrvl_sdio_sd8897 = { 125static const struct btmrvl_sdio_device btmrvl_sdio_sd8897 = {
124 .helper = NULL, 126 .helper = NULL,
125 .firmware = "mrvl/sd8897_uapsta.bin", 127 .firmware = "mrvl/sd8897_uapsta.bin",
128 .cal_data = NULL,
126 .reg = &btmrvl_reg_88xx, 129 .reg = &btmrvl_reg_88xx,
127 .sd_blksz_fw_dl = 256, 130 .sd_blksz_fw_dl = 256,
128}; 131};
@@ -1006,6 +1009,7 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
1006 struct btmrvl_sdio_device *data = (void *) id->driver_data; 1009 struct btmrvl_sdio_device *data = (void *) id->driver_data;
1007 card->helper = data->helper; 1010 card->helper = data->helper;
1008 card->firmware = data->firmware; 1011 card->firmware = data->firmware;
1012 card->cal_data = data->cal_data;
1009 card->reg = data->reg; 1013 card->reg = data->reg;
1010 card->sd_blksz_fw_dl = data->sd_blksz_fw_dl; 1014 card->sd_blksz_fw_dl = data->sd_blksz_fw_dl;
1011 } 1015 }
@@ -1034,6 +1038,8 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
1034 } 1038 }
1035 1039
1036 card->priv = priv; 1040 card->priv = priv;
1041 priv->btmrvl_dev.dev = &card->func->dev;
1042 priv->btmrvl_dev.cal_data = card->cal_data;
1037 1043
1038 /* Initialize the interface specific function pointers */ 1044 /* Initialize the interface specific function pointers */
1039 priv->hw_host_to_card = btmrvl_sdio_host_to_card; 1045 priv->hw_host_to_card = btmrvl_sdio_host_to_card;
@@ -1046,12 +1052,6 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
1046 goto disable_host_int; 1052 goto disable_host_int;
1047 } 1053 }
1048 1054
1049 priv->btmrvl_dev.psmode = 1;
1050 btmrvl_enable_ps(priv);
1051
1052 priv->btmrvl_dev.gpio_gap = 0xffff;
1053 btmrvl_send_hscfg_cmd(priv);
1054
1055 return 0; 1055 return 0;
1056 1056
1057disable_host_int: 1057disable_host_int:
@@ -1222,4 +1222,5 @@ MODULE_FIRMWARE("mrvl/sd8688_helper.bin");
1222MODULE_FIRMWARE("mrvl/sd8688.bin"); 1222MODULE_FIRMWARE("mrvl/sd8688.bin");
1223MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin"); 1223MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");
1224MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin"); 1224MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin");
1225MODULE_FIRMWARE("mrvl/sd8797_caldata.conf");
1225MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin"); 1226MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin");
diff --git a/drivers/bluetooth/btmrvl_sdio.h b/drivers/bluetooth/btmrvl_sdio.h
index 43d35a609ca9..6872d9ecac07 100644
--- a/drivers/bluetooth/btmrvl_sdio.h
+++ b/drivers/bluetooth/btmrvl_sdio.h
@@ -85,6 +85,7 @@ struct btmrvl_sdio_card {
85 u32 ioport; 85 u32 ioport;
86 const char *helper; 86 const char *helper;
87 const char *firmware; 87 const char *firmware;
88 const char *cal_data;
88 const struct btmrvl_sdio_card_reg *reg; 89 const struct btmrvl_sdio_card_reg *reg;
89 u16 sd_blksz_fw_dl; 90 u16 sd_blksz_fw_dl;
90 u8 rx_unit; 91 u8 rx_unit;
@@ -94,6 +95,7 @@ struct btmrvl_sdio_card {
94struct btmrvl_sdio_device { 95struct btmrvl_sdio_device {
95 const char *helper; 96 const char *helper;
96 const char *firmware; 97 const char *firmware;
98 const char *cal_data;
97 const struct btmrvl_sdio_card_reg *reg; 99 const struct btmrvl_sdio_card_reg *reg;
98 u16 sd_blksz_fw_dl; 100 u16 sd_blksz_fw_dl;
99}; 101};
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index d8b7aed6e4a9..c04a3e6fb37c 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -24,6 +24,7 @@
24 */ 24 */
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <asm/unaligned.h>
27 28
28#include <linux/kernel.h> 29#include <linux/kernel.h>
29#include <linux/init.h> 30#include <linux/init.h>
@@ -39,17 +40,17 @@
39#include <net/bluetooth/bluetooth.h> 40#include <net/bluetooth/bluetooth.h>
40#include <net/bluetooth/hci_core.h> 41#include <net/bluetooth/hci_core.h>
41 42
42#define VERSION "1.3" 43#define VERSION "1.4"
43 44
44static bool amp; 45static bool amp;
45 46
46struct vhci_data { 47struct vhci_data {
47 struct hci_dev *hdev; 48 struct hci_dev *hdev;
48 49
49 unsigned long flags;
50
51 wait_queue_head_t read_wait; 50 wait_queue_head_t read_wait;
52 struct sk_buff_head readq; 51 struct sk_buff_head readq;
52
53 struct delayed_work open_timeout;
53}; 54};
54 55
55static int vhci_open_dev(struct hci_dev *hdev) 56static int vhci_open_dev(struct hci_dev *hdev)
@@ -99,16 +100,62 @@ static int vhci_send_frame(struct sk_buff *skb)
99 skb_queue_tail(&data->readq, skb); 100 skb_queue_tail(&data->readq, skb);
100 101
101 wake_up_interruptible(&data->read_wait); 102 wake_up_interruptible(&data->read_wait);
103 return 0;
104}
105
106static int vhci_create_device(struct vhci_data *data, __u8 dev_type)
107{
108 struct hci_dev *hdev;
109 struct sk_buff *skb;
110
111 skb = bt_skb_alloc(4, GFP_KERNEL);
112 if (!skb)
113 return -ENOMEM;
114
115 hdev = hci_alloc_dev();
116 if (!hdev) {
117 kfree_skb(skb);
118 return -ENOMEM;
119 }
120
121 data->hdev = hdev;
122
123 hdev->bus = HCI_VIRTUAL;
124 hdev->dev_type = dev_type;
125 hci_set_drvdata(hdev, data);
126
127 hdev->open = vhci_open_dev;
128 hdev->close = vhci_close_dev;
129 hdev->flush = vhci_flush;
130 hdev->send = vhci_send_frame;
102 131
132 if (hci_register_dev(hdev) < 0) {
133 BT_ERR("Can't register HCI device");
134 hci_free_dev(hdev);
135 data->hdev = NULL;
136 kfree_skb(skb);
137 return -EBUSY;
138 }
139
140 bt_cb(skb)->pkt_type = HCI_VENDOR_PKT;
141
142 *skb_put(skb, 1) = 0xff;
143 *skb_put(skb, 1) = dev_type;
144 put_unaligned_le16(hdev->id, skb_put(skb, 2));
145 skb_queue_tail(&data->readq, skb);
146
147 wake_up_interruptible(&data->read_wait);
103 return 0; 148 return 0;
104} 149}
105 150
106static inline ssize_t vhci_get_user(struct vhci_data *data, 151static inline ssize_t vhci_get_user(struct vhci_data *data,
107 const char __user *buf, size_t count) 152 const char __user *buf, size_t count)
108{ 153{
109 struct sk_buff *skb; 154 struct sk_buff *skb;
155 __u8 pkt_type, dev_type;
156 int ret;
110 157
111 if (count > HCI_MAX_FRAME_SIZE) 158 if (count < 2 || count > HCI_MAX_FRAME_SIZE)
112 return -EINVAL; 159 return -EINVAL;
113 160
114 skb = bt_skb_alloc(count, GFP_KERNEL); 161 skb = bt_skb_alloc(count, GFP_KERNEL);
@@ -120,27 +167,70 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,
120 return -EFAULT; 167 return -EFAULT;
121 } 168 }
122 169
123 skb->dev = (void *) data->hdev; 170 pkt_type = *((__u8 *) skb->data);
124 bt_cb(skb)->pkt_type = *((__u8 *) skb->data);
125 skb_pull(skb, 1); 171 skb_pull(skb, 1);
126 172
127 hci_recv_frame(skb); 173 switch (pkt_type) {
174 case HCI_EVENT_PKT:
175 case HCI_ACLDATA_PKT:
176 case HCI_SCODATA_PKT:
177 if (!data->hdev) {
178 kfree_skb(skb);
179 return -ENODEV;
180 }
181
182 skb->dev = (void *) data->hdev;
183 bt_cb(skb)->pkt_type = pkt_type;
184
185 ret = hci_recv_frame(skb);
186 break;
187
188 case HCI_VENDOR_PKT:
189 if (data->hdev) {
190 kfree_skb(skb);
191 return -EBADFD;
192 }
128 193
129 return count; 194 cancel_delayed_work_sync(&data->open_timeout);
195
196 dev_type = *((__u8 *) skb->data);
197 skb_pull(skb, 1);
198
199 if (skb->len > 0) {
200 kfree_skb(skb);
201 return -EINVAL;
202 }
203
204 kfree_skb(skb);
205
206 if (dev_type != HCI_BREDR && dev_type != HCI_AMP)
207 return -EINVAL;
208
209 ret = vhci_create_device(data, dev_type);
210 break;
211
212 default:
213 kfree_skb(skb);
214 return -EINVAL;
215 }
216
217 return (ret < 0) ? ret : count;
130} 218}
131 219
132static inline ssize_t vhci_put_user(struct vhci_data *data, 220static inline ssize_t vhci_put_user(struct vhci_data *data,
133 struct sk_buff *skb, char __user *buf, int count) 221 struct sk_buff *skb,
222 char __user *buf, int count)
134{ 223{
135 char __user *ptr = buf; 224 char __user *ptr = buf;
136 int len, total = 0; 225 int len;
137 226
138 len = min_t(unsigned int, skb->len, count); 227 len = min_t(unsigned int, skb->len, count);
139 228
140 if (copy_to_user(ptr, skb->data, len)) 229 if (copy_to_user(ptr, skb->data, len))
141 return -EFAULT; 230 return -EFAULT;
142 231
143 total += len; 232 if (!data->hdev)
233 return len;
144 234
145 data->hdev->stat.byte_tx += len; 235 data->hdev->stat.byte_tx += len;
146 236
@@ -148,21 +238,19 @@ static inline ssize_t vhci_put_user(struct vhci_data *data,
148 case HCI_COMMAND_PKT: 238 case HCI_COMMAND_PKT:
149 data->hdev->stat.cmd_tx++; 239 data->hdev->stat.cmd_tx++;
150 break; 240 break;
151
152 case HCI_ACLDATA_PKT: 241 case HCI_ACLDATA_PKT:
153 data->hdev->stat.acl_tx++; 242 data->hdev->stat.acl_tx++;
154 break; 243 break;
155
156 case HCI_SCODATA_PKT: 244 case HCI_SCODATA_PKT:
157 data->hdev->stat.sco_tx++; 245 data->hdev->stat.sco_tx++;
158 break; 246 break;
159 } 247 }
160 248
161 return total; 249 return len;
162} 250}
163 251
164static ssize_t vhci_read(struct file *file, 252static ssize_t vhci_read(struct file *file,
165 char __user *buf, size_t count, loff_t *pos) 253 char __user *buf, size_t count, loff_t *pos)
166{ 254{
167 struct vhci_data *data = file->private_data; 255 struct vhci_data *data = file->private_data;
168 struct sk_buff *skb; 256 struct sk_buff *skb;
@@ -185,7 +273,7 @@ static ssize_t vhci_read(struct file *file,
185 } 273 }
186 274
187 ret = wait_event_interruptible(data->read_wait, 275 ret = wait_event_interruptible(data->read_wait,
188 !skb_queue_empty(&data->readq)); 276 !skb_queue_empty(&data->readq));
189 if (ret < 0) 277 if (ret < 0)
190 break; 278 break;
191 } 279 }
@@ -194,7 +282,7 @@ static ssize_t vhci_read(struct file *file,
194} 282}
195 283
196static ssize_t vhci_write(struct file *file, 284static ssize_t vhci_write(struct file *file,
197 const char __user *buf, size_t count, loff_t *pos) 285 const char __user *buf, size_t count, loff_t *pos)
198{ 286{
199 struct vhci_data *data = file->private_data; 287 struct vhci_data *data = file->private_data;
200 288
@@ -213,10 +301,17 @@ static unsigned int vhci_poll(struct file *file, poll_table *wait)
213 return POLLOUT | POLLWRNORM; 301 return POLLOUT | POLLWRNORM;
214} 302}
215 303
304static void vhci_open_timeout(struct work_struct *work)
305{
306 struct vhci_data *data = container_of(work, struct vhci_data,
307 open_timeout.work);
308
309 vhci_create_device(data, amp ? HCI_AMP : HCI_BREDR);
310}
311
216static int vhci_open(struct inode *inode, struct file *file) 312static int vhci_open(struct inode *inode, struct file *file)
217{ 313{
218 struct vhci_data *data; 314 struct vhci_data *data;
219 struct hci_dev *hdev;
220 315
221 data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL); 316 data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
222 if (!data) 317 if (!data)
@@ -225,35 +320,13 @@ static int vhci_open(struct inode *inode, struct file *file)
225 skb_queue_head_init(&data->readq); 320 skb_queue_head_init(&data->readq);
226 init_waitqueue_head(&data->read_wait); 321 init_waitqueue_head(&data->read_wait);
227 322
228 hdev = hci_alloc_dev(); 323 INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);
229 if (!hdev) {
230 kfree(data);
231 return -ENOMEM;
232 }
233
234 data->hdev = hdev;
235
236 hdev->bus = HCI_VIRTUAL;
237 hci_set_drvdata(hdev, data);
238
239 if (amp)
240 hdev->dev_type = HCI_AMP;
241
242 hdev->open = vhci_open_dev;
243 hdev->close = vhci_close_dev;
244 hdev->flush = vhci_flush;
245 hdev->send = vhci_send_frame;
246
247 if (hci_register_dev(hdev) < 0) {
248 BT_ERR("Can't register HCI device");
249 kfree(data);
250 hci_free_dev(hdev);
251 return -EBUSY;
252 }
253 324
254 file->private_data = data; 325 file->private_data = data;
255 nonseekable_open(inode, file); 326 nonseekable_open(inode, file);
256 327
328 schedule_delayed_work(&data->open_timeout, msecs_to_jiffies(1000));
329
257 return 0; 330 return 0;
258} 331}
259 332
@@ -262,8 +335,12 @@ static int vhci_release(struct inode *inode, struct file *file)
262 struct vhci_data *data = file->private_data; 335 struct vhci_data *data = file->private_data;
263 struct hci_dev *hdev = data->hdev; 336 struct hci_dev *hdev = data->hdev;
264 337
265 hci_unregister_dev(hdev); 338 cancel_delayed_work_sync(&data->open_timeout);
266 hci_free_dev(hdev); 339
340 if (hdev) {
341 hci_unregister_dev(hdev);
342 hci_free_dev(hdev);
343 }
267 344
268 file->private_data = NULL; 345 file->private_data = NULL;
269 kfree(data); 346 kfree(data);
@@ -309,3 +386,4 @@ MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
309MODULE_DESCRIPTION("Bluetooth virtual HCI driver ver " VERSION); 386MODULE_DESCRIPTION("Bluetooth virtual HCI driver ver " VERSION);
310MODULE_VERSION(VERSION); 387MODULE_VERSION(VERSION);
311MODULE_LICENSE("GPL"); 388MODULE_LICENSE("GPL");
389MODULE_ALIAS("devname:vhci");
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index f9a24e599dee..cfce83e1f273 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -1924,7 +1924,6 @@ static int adm8211_probe(struct pci_dev *pdev,
1924 pci_iounmap(pdev, priv->map); 1924 pci_iounmap(pdev, priv->map);
1925 1925
1926 err_free_dev: 1926 err_free_dev:
1927 pci_set_drvdata(pdev, NULL);
1928 ieee80211_free_hw(dev); 1927 ieee80211_free_hw(dev);
1929 1928
1930 err_free_reg: 1929 err_free_reg:
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 7fe19648f10e..edf4b57c4aaa 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -5570,7 +5570,6 @@ static void airo_pci_remove(struct pci_dev *pdev)
5570 airo_print_info(dev->name, "Unregistering..."); 5570 airo_print_info(dev->name, "Unregistering...");
5571 stop_airo_card(dev, 1); 5571 stop_airo_card(dev, 1);
5572 pci_disable_device(pdev); 5572 pci_disable_device(pdev);
5573 pci_set_drvdata(pdev, NULL);
5574} 5573}
5575 5574
5576static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state) 5575static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
index 17d7fece35d2..280fc3d53a36 100644
--- a/drivers/net/wireless/ath/ar5523/ar5523.c
+++ b/drivers/net/wireless/ath/ar5523/ar5523.c
@@ -1762,6 +1762,7 @@ static struct usb_device_id ar5523_id_table[] = {
1762 AR5523_DEVICE_UX(0x2001, 0x3a00), /* Dlink / DWLAG132 */ 1762 AR5523_DEVICE_UX(0x2001, 0x3a00), /* Dlink / DWLAG132 */
1763 AR5523_DEVICE_UG(0x2001, 0x3a02), /* Dlink / DWLG132 */ 1763 AR5523_DEVICE_UG(0x2001, 0x3a02), /* Dlink / DWLG132 */
1764 AR5523_DEVICE_UX(0x2001, 0x3a04), /* Dlink / DWLAG122 */ 1764 AR5523_DEVICE_UX(0x2001, 0x3a04), /* Dlink / DWLAG122 */
1765 AR5523_DEVICE_UG(0x07d1, 0x3a07), /* D-Link / WUA-2340 rev A1 */
1765 AR5523_DEVICE_UG(0x1690, 0x0712), /* Gigaset / AR5523 */ 1766 AR5523_DEVICE_UG(0x1690, 0x0712), /* Gigaset / AR5523 */
1766 AR5523_DEVICE_UG(0x1690, 0x0710), /* Gigaset / SMCWUSBTG */ 1767 AR5523_DEVICE_UG(0x1690, 0x0710), /* Gigaset / SMCWUSBTG */
1767 AR5523_DEVICE_UG(0x129b, 0x160c), /* Gigaset / USB stick 108 1768 AR5523_DEVICE_UG(0x129b, 0x160c), /* Gigaset / USB stick 108
diff --git a/drivers/net/wireless/ath/ath10k/bmi.c b/drivers/net/wireless/ath/ath10k/bmi.c
index 744da6d1c405..a1f099628850 100644
--- a/drivers/net/wireless/ath/ath10k/bmi.c
+++ b/drivers/net/wireless/ath/ath10k/bmi.c
@@ -22,7 +22,8 @@
22 22
23void ath10k_bmi_start(struct ath10k *ar) 23void ath10k_bmi_start(struct ath10k *ar)
24{ 24{
25 ath10k_dbg(ATH10K_DBG_CORE, "BMI started\n"); 25 ath10k_dbg(ATH10K_DBG_BMI, "bmi start\n");
26
26 ar->bmi.done_sent = false; 27 ar->bmi.done_sent = false;
27} 28}
28 29
@@ -32,8 +33,10 @@ int ath10k_bmi_done(struct ath10k *ar)
32 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.done); 33 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.done);
33 int ret; 34 int ret;
34 35
36 ath10k_dbg(ATH10K_DBG_BMI, "bmi done\n");
37
35 if (ar->bmi.done_sent) { 38 if (ar->bmi.done_sent) {
36 ath10k_dbg(ATH10K_DBG_CORE, "%s skipped\n", __func__); 39 ath10k_dbg(ATH10K_DBG_BMI, "bmi skipped\n");
37 return 0; 40 return 0;
38 } 41 }
39 42
@@ -46,7 +49,6 @@ int ath10k_bmi_done(struct ath10k *ar)
46 return ret; 49 return ret;
47 } 50 }
48 51
49 ath10k_dbg(ATH10K_DBG_CORE, "BMI done\n");
50 return 0; 52 return 0;
51} 53}
52 54
@@ -59,6 +61,8 @@ int ath10k_bmi_get_target_info(struct ath10k *ar,
59 u32 resplen = sizeof(resp.get_target_info); 61 u32 resplen = sizeof(resp.get_target_info);
60 int ret; 62 int ret;
61 63
64 ath10k_dbg(ATH10K_DBG_BMI, "bmi get target info\n");
65
62 if (ar->bmi.done_sent) { 66 if (ar->bmi.done_sent) {
63 ath10k_warn("BMI Get Target Info Command disallowed\n"); 67 ath10k_warn("BMI Get Target Info Command disallowed\n");
64 return -EBUSY; 68 return -EBUSY;
@@ -80,6 +84,7 @@ int ath10k_bmi_get_target_info(struct ath10k *ar,
80 84
81 target_info->version = __le32_to_cpu(resp.get_target_info.version); 85 target_info->version = __le32_to_cpu(resp.get_target_info.version);
82 target_info->type = __le32_to_cpu(resp.get_target_info.type); 86 target_info->type = __le32_to_cpu(resp.get_target_info.type);
87
83 return 0; 88 return 0;
84} 89}
85 90
@@ -92,15 +97,14 @@ int ath10k_bmi_read_memory(struct ath10k *ar,
92 u32 rxlen; 97 u32 rxlen;
93 int ret; 98 int ret;
94 99
100 ath10k_dbg(ATH10K_DBG_BMI, "bmi read address 0x%x length %d\n",
101 address, length);
102
95 if (ar->bmi.done_sent) { 103 if (ar->bmi.done_sent) {
96 ath10k_warn("command disallowed\n"); 104 ath10k_warn("command disallowed\n");
97 return -EBUSY; 105 return -EBUSY;
98 } 106 }
99 107
100 ath10k_dbg(ATH10K_DBG_CORE,
101 "%s: (device: 0x%p, address: 0x%x, length: %d)\n",
102 __func__, ar, address, length);
103
104 while (length) { 108 while (length) {
105 rxlen = min_t(u32, length, BMI_MAX_DATA_SIZE); 109 rxlen = min_t(u32, length, BMI_MAX_DATA_SIZE);
106 110
@@ -133,15 +137,14 @@ int ath10k_bmi_write_memory(struct ath10k *ar,
133 u32 txlen; 137 u32 txlen;
134 int ret; 138 int ret;
135 139
140 ath10k_dbg(ATH10K_DBG_BMI, "bmi write address 0x%x length %d\n",
141 address, length);
142
136 if (ar->bmi.done_sent) { 143 if (ar->bmi.done_sent) {
137 ath10k_warn("command disallowed\n"); 144 ath10k_warn("command disallowed\n");
138 return -EBUSY; 145 return -EBUSY;
139 } 146 }
140 147
141 ath10k_dbg(ATH10K_DBG_CORE,
142 "%s: (device: 0x%p, address: 0x%x, length: %d)\n",
143 __func__, ar, address, length);
144
145 while (length) { 148 while (length) {
146 txlen = min(length, BMI_MAX_DATA_SIZE - hdrlen); 149 txlen = min(length, BMI_MAX_DATA_SIZE - hdrlen);
147 150
@@ -180,15 +183,14 @@ int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 *param)
180 u32 resplen = sizeof(resp.execute); 183 u32 resplen = sizeof(resp.execute);
181 int ret; 184 int ret;
182 185
186 ath10k_dbg(ATH10K_DBG_BMI, "bmi execute address 0x%x param 0x%x\n",
187 address, *param);
188
183 if (ar->bmi.done_sent) { 189 if (ar->bmi.done_sent) {
184 ath10k_warn("command disallowed\n"); 190 ath10k_warn("command disallowed\n");
185 return -EBUSY; 191 return -EBUSY;
186 } 192 }
187 193
188 ath10k_dbg(ATH10K_DBG_CORE,
189 "%s: (device: 0x%p, address: 0x%x, param: %d)\n",
190 __func__, ar, address, *param);
191
192 cmd.id = __cpu_to_le32(BMI_EXECUTE); 194 cmd.id = __cpu_to_le32(BMI_EXECUTE);
193 cmd.execute.addr = __cpu_to_le32(address); 195 cmd.execute.addr = __cpu_to_le32(address);
194 cmd.execute.param = __cpu_to_le32(*param); 196 cmd.execute.param = __cpu_to_le32(*param);
@@ -216,6 +218,9 @@ int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length)
216 u32 txlen; 218 u32 txlen;
217 int ret; 219 int ret;
218 220
221 ath10k_dbg(ATH10K_DBG_BMI, "bmi lz data buffer 0x%p length %d\n",
222 buffer, length);
223
219 if (ar->bmi.done_sent) { 224 if (ar->bmi.done_sent) {
220 ath10k_warn("command disallowed\n"); 225 ath10k_warn("command disallowed\n");
221 return -EBUSY; 226 return -EBUSY;
@@ -250,6 +255,9 @@ int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address)
250 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.lz_start); 255 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.lz_start);
251 int ret; 256 int ret;
252 257
258 ath10k_dbg(ATH10K_DBG_BMI, "bmi lz stream start address 0x%x\n",
259 address);
260
253 if (ar->bmi.done_sent) { 261 if (ar->bmi.done_sent) {
254 ath10k_warn("command disallowed\n"); 262 ath10k_warn("command disallowed\n");
255 return -EBUSY; 263 return -EBUSY;
@@ -275,6 +283,10 @@ int ath10k_bmi_fast_download(struct ath10k *ar,
275 u32 trailer_len = length - head_len; 283 u32 trailer_len = length - head_len;
276 int ret; 284 int ret;
277 285
286 ath10k_dbg(ATH10K_DBG_BMI,
287 "bmi fast download address 0x%x buffer 0x%p length %d\n",
288 address, buffer, length);
289
278 ret = ath10k_bmi_lz_stream_start(ar, address); 290 ret = ath10k_bmi_lz_stream_start(ar, address);
279 if (ret) 291 if (ret)
280 return ret; 292 return ret;
diff --git a/drivers/net/wireless/ath/ath10k/ce.c b/drivers/net/wireless/ath/ath10k/ce.c
index f8b969f518f8..834e29ea236c 100644
--- a/drivers/net/wireless/ath/ath10k/ce.c
+++ b/drivers/net/wireless/ath/ath10k/ce.c
@@ -76,36 +76,7 @@ static inline void ath10k_ce_src_ring_write_index_set(struct ath10k *ar,
76 u32 ce_ctrl_addr, 76 u32 ce_ctrl_addr,
77 unsigned int n) 77 unsigned int n)
78{ 78{
79 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 79 ath10k_pci_write32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS, n);
80 void __iomem *indicator_addr;
81
82 if (!test_bit(ATH10K_PCI_FEATURE_HW_1_0_WORKAROUND, ar_pci->features)) {
83 ath10k_pci_write32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS, n);
84 return;
85 }
86
87 /* workaround for QCA988x_1.0 HW CE */
88 indicator_addr = ar_pci->mem + ce_ctrl_addr + DST_WATERMARK_ADDRESS;
89
90 if (ce_ctrl_addr == ath10k_ce_base_address(CDC_WAR_DATA_CE)) {
91 iowrite32((CDC_WAR_MAGIC_STR | n), indicator_addr);
92 } else {
93 unsigned long irq_flags;
94 local_irq_save(irq_flags);
95 iowrite32(1, indicator_addr);
96
97 /*
98 * PCIE write waits for ACK in IPQ8K, there is no
99 * need to read back value.
100 */
101 (void)ioread32(indicator_addr);
102 (void)ioread32(indicator_addr); /* conservative */
103
104 ath10k_pci_write32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS, n);
105
106 iowrite32(0, indicator_addr);
107 local_irq_restore(irq_flags);
108 }
109} 80}
110 81
111static inline u32 ath10k_ce_src_ring_write_index_get(struct ath10k *ar, 82static inline u32 ath10k_ce_src_ring_write_index_get(struct ath10k *ar,
@@ -285,7 +256,7 @@ static inline void ath10k_ce_engine_int_status_clear(struct ath10k *ar,
285 * ath10k_ce_sendlist_send. 256 * ath10k_ce_sendlist_send.
286 * The caller takes responsibility for any needed locking. 257 * The caller takes responsibility for any needed locking.
287 */ 258 */
288static int ath10k_ce_send_nolock(struct ce_state *ce_state, 259static int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
289 void *per_transfer_context, 260 void *per_transfer_context,
290 u32 buffer, 261 u32 buffer,
291 unsigned int nbytes, 262 unsigned int nbytes,
@@ -293,7 +264,7 @@ static int ath10k_ce_send_nolock(struct ce_state *ce_state,
293 unsigned int flags) 264 unsigned int flags)
294{ 265{
295 struct ath10k *ar = ce_state->ar; 266 struct ath10k *ar = ce_state->ar;
296 struct ce_ring_state *src_ring = ce_state->src_ring; 267 struct ath10k_ce_ring *src_ring = ce_state->src_ring;
297 struct ce_desc *desc, *sdesc; 268 struct ce_desc *desc, *sdesc;
298 unsigned int nentries_mask = src_ring->nentries_mask; 269 unsigned int nentries_mask = src_ring->nentries_mask;
299 unsigned int sw_index = src_ring->sw_index; 270 unsigned int sw_index = src_ring->sw_index;
@@ -306,7 +277,9 @@ static int ath10k_ce_send_nolock(struct ce_state *ce_state,
306 ath10k_warn("%s: send more we can (nbytes: %d, max: %d)\n", 277 ath10k_warn("%s: send more we can (nbytes: %d, max: %d)\n",
307 __func__, nbytes, ce_state->src_sz_max); 278 __func__, nbytes, ce_state->src_sz_max);
308 279
309 ath10k_pci_wake(ar); 280 ret = ath10k_pci_wake(ar);
281 if (ret)
282 return ret;
310 283
311 if (unlikely(CE_RING_DELTA(nentries_mask, 284 if (unlikely(CE_RING_DELTA(nentries_mask,
312 write_index, sw_index - 1) <= 0)) { 285 write_index, sw_index - 1) <= 0)) {
@@ -346,7 +319,7 @@ exit:
346 return ret; 319 return ret;
347} 320}
348 321
349int ath10k_ce_send(struct ce_state *ce_state, 322int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
350 void *per_transfer_context, 323 void *per_transfer_context,
351 u32 buffer, 324 u32 buffer,
352 unsigned int nbytes, 325 unsigned int nbytes,
@@ -365,33 +338,19 @@ int ath10k_ce_send(struct ce_state *ce_state,
365 return ret; 338 return ret;
366} 339}
367 340
368void ath10k_ce_sendlist_buf_add(struct ce_sendlist *sendlist, u32 buffer, 341int ath10k_ce_sendlist_send(struct ath10k_ce_pipe *ce_state,
369 unsigned int nbytes, u32 flags)
370{
371 unsigned int num_items = sendlist->num_items;
372 struct ce_sendlist_item *item;
373
374 item = &sendlist->item[num_items];
375 item->data = buffer;
376 item->u.nbytes = nbytes;
377 item->flags = flags;
378 sendlist->num_items++;
379}
380
381int ath10k_ce_sendlist_send(struct ce_state *ce_state,
382 void *per_transfer_context, 342 void *per_transfer_context,
383 struct ce_sendlist *sendlist, 343 unsigned int transfer_id,
384 unsigned int transfer_id) 344 u32 paddr, unsigned int nbytes,
345 u32 flags)
385{ 346{
386 struct ce_ring_state *src_ring = ce_state->src_ring; 347 struct ath10k_ce_ring *src_ring = ce_state->src_ring;
387 struct ce_sendlist_item *item;
388 struct ath10k *ar = ce_state->ar; 348 struct ath10k *ar = ce_state->ar;
389 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 349 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
390 unsigned int nentries_mask = src_ring->nentries_mask; 350 unsigned int nentries_mask = src_ring->nentries_mask;
391 unsigned int num_items = sendlist->num_items;
392 unsigned int sw_index; 351 unsigned int sw_index;
393 unsigned int write_index; 352 unsigned int write_index;
394 int i, delta, ret = -ENOMEM; 353 int delta, ret = -ENOMEM;
395 354
396 spin_lock_bh(&ar_pci->ce_lock); 355 spin_lock_bh(&ar_pci->ce_lock);
397 356
@@ -400,30 +359,12 @@ int ath10k_ce_sendlist_send(struct ce_state *ce_state,
400 359
401 delta = CE_RING_DELTA(nentries_mask, write_index, sw_index - 1); 360 delta = CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
402 361
403 if (delta >= num_items) { 362 if (delta >= 1) {
404 /*
405 * Handle all but the last item uniformly.
406 */
407 for (i = 0; i < num_items - 1; i++) {
408 item = &sendlist->item[i];
409 ret = ath10k_ce_send_nolock(ce_state,
410 CE_SENDLIST_ITEM_CTXT,
411 (u32) item->data,
412 item->u.nbytes, transfer_id,
413 item->flags |
414 CE_SEND_FLAG_GATHER);
415 if (ret)
416 ath10k_warn("CE send failed for item: %d\n", i);
417 }
418 /*
419 * Provide valid context pointer for final item.
420 */
421 item = &sendlist->item[i];
422 ret = ath10k_ce_send_nolock(ce_state, per_transfer_context, 363 ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
423 (u32) item->data, item->u.nbytes, 364 paddr, nbytes,
424 transfer_id, item->flags); 365 transfer_id, flags);
425 if (ret) 366 if (ret)
426 ath10k_warn("CE send failed for last item: %d\n", i); 367 ath10k_warn("CE send failed: %d\n", ret);
427 } 368 }
428 369
429 spin_unlock_bh(&ar_pci->ce_lock); 370 spin_unlock_bh(&ar_pci->ce_lock);
@@ -431,11 +372,11 @@ int ath10k_ce_sendlist_send(struct ce_state *ce_state,
431 return ret; 372 return ret;
432} 373}
433 374
434int ath10k_ce_recv_buf_enqueue(struct ce_state *ce_state, 375int ath10k_ce_recv_buf_enqueue(struct ath10k_ce_pipe *ce_state,
435 void *per_recv_context, 376 void *per_recv_context,
436 u32 buffer) 377 u32 buffer)
437{ 378{
438 struct ce_ring_state *dest_ring = ce_state->dest_ring; 379 struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
439 u32 ctrl_addr = ce_state->ctrl_addr; 380 u32 ctrl_addr = ce_state->ctrl_addr;
440 struct ath10k *ar = ce_state->ar; 381 struct ath10k *ar = ce_state->ar;
441 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 382 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
@@ -448,7 +389,9 @@ int ath10k_ce_recv_buf_enqueue(struct ce_state *ce_state,
448 write_index = dest_ring->write_index; 389 write_index = dest_ring->write_index;
449 sw_index = dest_ring->sw_index; 390 sw_index = dest_ring->sw_index;
450 391
451 ath10k_pci_wake(ar); 392 ret = ath10k_pci_wake(ar);
393 if (ret)
394 goto out;
452 395
453 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) { 396 if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) {
454 struct ce_desc *base = dest_ring->base_addr_owner_space; 397 struct ce_desc *base = dest_ring->base_addr_owner_space;
@@ -470,6 +413,8 @@ int ath10k_ce_recv_buf_enqueue(struct ce_state *ce_state,
470 ret = -EIO; 413 ret = -EIO;
471 } 414 }
472 ath10k_pci_sleep(ar); 415 ath10k_pci_sleep(ar);
416
417out:
473 spin_unlock_bh(&ar_pci->ce_lock); 418 spin_unlock_bh(&ar_pci->ce_lock);
474 419
475 return ret; 420 return ret;
@@ -479,14 +424,14 @@ int ath10k_ce_recv_buf_enqueue(struct ce_state *ce_state,
479 * Guts of ath10k_ce_completed_recv_next. 424 * Guts of ath10k_ce_completed_recv_next.
480 * The caller takes responsibility for any necessary locking. 425 * The caller takes responsibility for any necessary locking.
481 */ 426 */
482static int ath10k_ce_completed_recv_next_nolock(struct ce_state *ce_state, 427static int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
483 void **per_transfer_contextp, 428 void **per_transfer_contextp,
484 u32 *bufferp, 429 u32 *bufferp,
485 unsigned int *nbytesp, 430 unsigned int *nbytesp,
486 unsigned int *transfer_idp, 431 unsigned int *transfer_idp,
487 unsigned int *flagsp) 432 unsigned int *flagsp)
488{ 433{
489 struct ce_ring_state *dest_ring = ce_state->dest_ring; 434 struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
490 unsigned int nentries_mask = dest_ring->nentries_mask; 435 unsigned int nentries_mask = dest_ring->nentries_mask;
491 unsigned int sw_index = dest_ring->sw_index; 436 unsigned int sw_index = dest_ring->sw_index;
492 437
@@ -535,7 +480,7 @@ static int ath10k_ce_completed_recv_next_nolock(struct ce_state *ce_state,
535 return 0; 480 return 0;
536} 481}
537 482
538int ath10k_ce_completed_recv_next(struct ce_state *ce_state, 483int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
539 void **per_transfer_contextp, 484 void **per_transfer_contextp,
540 u32 *bufferp, 485 u32 *bufferp,
541 unsigned int *nbytesp, 486 unsigned int *nbytesp,
@@ -556,11 +501,11 @@ int ath10k_ce_completed_recv_next(struct ce_state *ce_state,
556 return ret; 501 return ret;
557} 502}
558 503
559int ath10k_ce_revoke_recv_next(struct ce_state *ce_state, 504int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
560 void **per_transfer_contextp, 505 void **per_transfer_contextp,
561 u32 *bufferp) 506 u32 *bufferp)
562{ 507{
563 struct ce_ring_state *dest_ring; 508 struct ath10k_ce_ring *dest_ring;
564 unsigned int nentries_mask; 509 unsigned int nentries_mask;
565 unsigned int sw_index; 510 unsigned int sw_index;
566 unsigned int write_index; 511 unsigned int write_index;
@@ -612,19 +557,20 @@ int ath10k_ce_revoke_recv_next(struct ce_state *ce_state,
612 * Guts of ath10k_ce_completed_send_next. 557 * Guts of ath10k_ce_completed_send_next.
613 * The caller takes responsibility for any necessary locking. 558 * The caller takes responsibility for any necessary locking.
614 */ 559 */
615static int ath10k_ce_completed_send_next_nolock(struct ce_state *ce_state, 560static int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
616 void **per_transfer_contextp, 561 void **per_transfer_contextp,
617 u32 *bufferp, 562 u32 *bufferp,
618 unsigned int *nbytesp, 563 unsigned int *nbytesp,
619 unsigned int *transfer_idp) 564 unsigned int *transfer_idp)
620{ 565{
621 struct ce_ring_state *src_ring = ce_state->src_ring; 566 struct ath10k_ce_ring *src_ring = ce_state->src_ring;
622 u32 ctrl_addr = ce_state->ctrl_addr; 567 u32 ctrl_addr = ce_state->ctrl_addr;
623 struct ath10k *ar = ce_state->ar; 568 struct ath10k *ar = ce_state->ar;
624 unsigned int nentries_mask = src_ring->nentries_mask; 569 unsigned int nentries_mask = src_ring->nentries_mask;
625 unsigned int sw_index = src_ring->sw_index; 570 unsigned int sw_index = src_ring->sw_index;
571 struct ce_desc *sdesc, *sbase;
626 unsigned int read_index; 572 unsigned int read_index;
627 int ret = -EIO; 573 int ret;
628 574
629 if (src_ring->hw_index == sw_index) { 575 if (src_ring->hw_index == sw_index) {
630 /* 576 /*
@@ -634,48 +580,54 @@ static int ath10k_ce_completed_send_next_nolock(struct ce_state *ce_state,
634 * the SW has really caught up to the HW, or if the cached 580 * the SW has really caught up to the HW, or if the cached
635 * value of the HW index has become stale. 581 * value of the HW index has become stale.
636 */ 582 */
637 ath10k_pci_wake(ar); 583
584 ret = ath10k_pci_wake(ar);
585 if (ret)
586 return ret;
587
638 src_ring->hw_index = 588 src_ring->hw_index =
639 ath10k_ce_src_ring_read_index_get(ar, ctrl_addr); 589 ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
640 src_ring->hw_index &= nentries_mask; 590 src_ring->hw_index &= nentries_mask;
591
641 ath10k_pci_sleep(ar); 592 ath10k_pci_sleep(ar);
642 } 593 }
594
643 read_index = src_ring->hw_index; 595 read_index = src_ring->hw_index;
644 596
645 if ((read_index != sw_index) && (read_index != 0xffffffff)) { 597 if ((read_index == sw_index) || (read_index == 0xffffffff))
646 struct ce_desc *sbase = src_ring->shadow_base; 598 return -EIO;
647 struct ce_desc *sdesc = CE_SRC_RING_TO_DESC(sbase, sw_index);
648 599
649 /* Return data from completed source descriptor */ 600 sbase = src_ring->shadow_base;
650 *bufferp = __le32_to_cpu(sdesc->addr); 601 sdesc = CE_SRC_RING_TO_DESC(sbase, sw_index);
651 *nbytesp = __le16_to_cpu(sdesc->nbytes);
652 *transfer_idp = MS(__le16_to_cpu(sdesc->flags),
653 CE_DESC_FLAGS_META_DATA);
654 602
655 if (per_transfer_contextp) 603 /* Return data from completed source descriptor */
656 *per_transfer_contextp = 604 *bufferp = __le32_to_cpu(sdesc->addr);
657 src_ring->per_transfer_context[sw_index]; 605 *nbytesp = __le16_to_cpu(sdesc->nbytes);
606 *transfer_idp = MS(__le16_to_cpu(sdesc->flags),
607 CE_DESC_FLAGS_META_DATA);
658 608
659 /* sanity */ 609 if (per_transfer_contextp)
660 src_ring->per_transfer_context[sw_index] = NULL; 610 *per_transfer_contextp =
611 src_ring->per_transfer_context[sw_index];
661 612
662 /* Update sw_index */ 613 /* sanity */
663 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index); 614 src_ring->per_transfer_context[sw_index] = NULL;
664 src_ring->sw_index = sw_index;
665 ret = 0;
666 }
667 615
668 return ret; 616 /* Update sw_index */
617 sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
618 src_ring->sw_index = sw_index;
619
620 return 0;
669} 621}
670 622
671/* NB: Modeled after ath10k_ce_completed_send_next */ 623/* NB: Modeled after ath10k_ce_completed_send_next */
672int ath10k_ce_cancel_send_next(struct ce_state *ce_state, 624int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
673 void **per_transfer_contextp, 625 void **per_transfer_contextp,
674 u32 *bufferp, 626 u32 *bufferp,
675 unsigned int *nbytesp, 627 unsigned int *nbytesp,
676 unsigned int *transfer_idp) 628 unsigned int *transfer_idp)
677{ 629{
678 struct ce_ring_state *src_ring; 630 struct ath10k_ce_ring *src_ring;
679 unsigned int nentries_mask; 631 unsigned int nentries_mask;
680 unsigned int sw_index; 632 unsigned int sw_index;
681 unsigned int write_index; 633 unsigned int write_index;
@@ -727,7 +679,7 @@ int ath10k_ce_cancel_send_next(struct ce_state *ce_state,
727 return ret; 679 return ret;
728} 680}
729 681
730int ath10k_ce_completed_send_next(struct ce_state *ce_state, 682int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
731 void **per_transfer_contextp, 683 void **per_transfer_contextp,
732 u32 *bufferp, 684 u32 *bufferp,
733 unsigned int *nbytesp, 685 unsigned int *nbytesp,
@@ -756,53 +708,29 @@ int ath10k_ce_completed_send_next(struct ce_state *ce_state,
756void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id) 708void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
757{ 709{
758 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 710 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
759 struct ce_state *ce_state = ar_pci->ce_id_to_state[ce_id]; 711 struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
760 u32 ctrl_addr = ce_state->ctrl_addr; 712 u32 ctrl_addr = ce_state->ctrl_addr;
761 void *transfer_context; 713 int ret;
762 u32 buf; 714
763 unsigned int nbytes; 715 ret = ath10k_pci_wake(ar);
764 unsigned int id; 716 if (ret)
765 unsigned int flags; 717 return;
766 718
767 ath10k_pci_wake(ar);
768 spin_lock_bh(&ar_pci->ce_lock); 719 spin_lock_bh(&ar_pci->ce_lock);
769 720
770 /* Clear the copy-complete interrupts that will be handled here. */ 721 /* Clear the copy-complete interrupts that will be handled here. */
771 ath10k_ce_engine_int_status_clear(ar, ctrl_addr, 722 ath10k_ce_engine_int_status_clear(ar, ctrl_addr,
772 HOST_IS_COPY_COMPLETE_MASK); 723 HOST_IS_COPY_COMPLETE_MASK);
773 724
774 if (ce_state->recv_cb) { 725 spin_unlock_bh(&ar_pci->ce_lock);
775 /*
776 * Pop completed recv buffers and call the registered
777 * recv callback for each
778 */
779 while (ath10k_ce_completed_recv_next_nolock(ce_state,
780 &transfer_context,
781 &buf, &nbytes,
782 &id, &flags) == 0) {
783 spin_unlock_bh(&ar_pci->ce_lock);
784 ce_state->recv_cb(ce_state, transfer_context, buf,
785 nbytes, id, flags);
786 spin_lock_bh(&ar_pci->ce_lock);
787 }
788 }
789 726
790 if (ce_state->send_cb) { 727 if (ce_state->recv_cb)
791 /* 728 ce_state->recv_cb(ce_state);
792 * Pop completed send buffers and call the registered 729
793 * send callback for each 730 if (ce_state->send_cb)
794 */ 731 ce_state->send_cb(ce_state);
795 while (ath10k_ce_completed_send_next_nolock(ce_state, 732
796 &transfer_context, 733 spin_lock_bh(&ar_pci->ce_lock);
797 &buf,
798 &nbytes,
799 &id) == 0) {
800 spin_unlock_bh(&ar_pci->ce_lock);
801 ce_state->send_cb(ce_state, transfer_context,
802 buf, nbytes, id);
803 spin_lock_bh(&ar_pci->ce_lock);
804 }
805 }
806 734
807 /* 735 /*
808 * Misc CE interrupts are not being handled, but still need 736 * Misc CE interrupts are not being handled, but still need
@@ -823,10 +751,13 @@ void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
823void ath10k_ce_per_engine_service_any(struct ath10k *ar) 751void ath10k_ce_per_engine_service_any(struct ath10k *ar)
824{ 752{
825 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 753 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
826 int ce_id; 754 int ce_id, ret;
827 u32 intr_summary; 755 u32 intr_summary;
828 756
829 ath10k_pci_wake(ar); 757 ret = ath10k_pci_wake(ar);
758 if (ret)
759 return;
760
830 intr_summary = CE_INTERRUPT_SUMMARY(ar); 761 intr_summary = CE_INTERRUPT_SUMMARY(ar);
831 762
832 for (ce_id = 0; intr_summary && (ce_id < ar_pci->ce_count); ce_id++) { 763 for (ce_id = 0; intr_summary && (ce_id < ar_pci->ce_count); ce_id++) {
@@ -849,13 +780,16 @@ void ath10k_ce_per_engine_service_any(struct ath10k *ar)
849 * 780 *
850 * Called with ce_lock held. 781 * Called with ce_lock held.
851 */ 782 */
852static void ath10k_ce_per_engine_handler_adjust(struct ce_state *ce_state, 783static void ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe *ce_state,
853 int disable_copy_compl_intr) 784 int disable_copy_compl_intr)
854{ 785{
855 u32 ctrl_addr = ce_state->ctrl_addr; 786 u32 ctrl_addr = ce_state->ctrl_addr;
856 struct ath10k *ar = ce_state->ar; 787 struct ath10k *ar = ce_state->ar;
788 int ret;
857 789
858 ath10k_pci_wake(ar); 790 ret = ath10k_pci_wake(ar);
791 if (ret)
792 return;
859 793
860 if ((!disable_copy_compl_intr) && 794 if ((!disable_copy_compl_intr) &&
861 (ce_state->send_cb || ce_state->recv_cb)) 795 (ce_state->send_cb || ce_state->recv_cb))
@@ -871,11 +805,14 @@ static void ath10k_ce_per_engine_handler_adjust(struct ce_state *ce_state,
871void ath10k_ce_disable_interrupts(struct ath10k *ar) 805void ath10k_ce_disable_interrupts(struct ath10k *ar)
872{ 806{
873 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 807 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
874 int ce_id; 808 int ce_id, ret;
809
810 ret = ath10k_pci_wake(ar);
811 if (ret)
812 return;
875 813
876 ath10k_pci_wake(ar);
877 for (ce_id = 0; ce_id < ar_pci->ce_count; ce_id++) { 814 for (ce_id = 0; ce_id < ar_pci->ce_count; ce_id++) {
878 struct ce_state *ce_state = ar_pci->ce_id_to_state[ce_id]; 815 struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
879 u32 ctrl_addr = ce_state->ctrl_addr; 816 u32 ctrl_addr = ce_state->ctrl_addr;
880 817
881 ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr); 818 ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
@@ -883,12 +820,8 @@ void ath10k_ce_disable_interrupts(struct ath10k *ar)
883 ath10k_pci_sleep(ar); 820 ath10k_pci_sleep(ar);
884} 821}
885 822
886void ath10k_ce_send_cb_register(struct ce_state *ce_state, 823void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
887 void (*send_cb) (struct ce_state *ce_state, 824 void (*send_cb)(struct ath10k_ce_pipe *),
888 void *transfer_context,
889 u32 buffer,
890 unsigned int nbytes,
891 unsigned int transfer_id),
892 int disable_interrupts) 825 int disable_interrupts)
893{ 826{
894 struct ath10k *ar = ce_state->ar; 827 struct ath10k *ar = ce_state->ar;
@@ -900,13 +833,8 @@ void ath10k_ce_send_cb_register(struct ce_state *ce_state,
900 spin_unlock_bh(&ar_pci->ce_lock); 833 spin_unlock_bh(&ar_pci->ce_lock);
901} 834}
902 835
903void ath10k_ce_recv_cb_register(struct ce_state *ce_state, 836void ath10k_ce_recv_cb_register(struct ath10k_ce_pipe *ce_state,
904 void (*recv_cb) (struct ce_state *ce_state, 837 void (*recv_cb)(struct ath10k_ce_pipe *))
905 void *transfer_context,
906 u32 buffer,
907 unsigned int nbytes,
908 unsigned int transfer_id,
909 unsigned int flags))
910{ 838{
911 struct ath10k *ar = ce_state->ar; 839 struct ath10k *ar = ce_state->ar;
912 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 840 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
@@ -919,11 +847,11 @@ void ath10k_ce_recv_cb_register(struct ce_state *ce_state,
919 847
920static int ath10k_ce_init_src_ring(struct ath10k *ar, 848static int ath10k_ce_init_src_ring(struct ath10k *ar,
921 unsigned int ce_id, 849 unsigned int ce_id,
922 struct ce_state *ce_state, 850 struct ath10k_ce_pipe *ce_state,
923 const struct ce_attr *attr) 851 const struct ce_attr *attr)
924{ 852{
925 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 853 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
926 struct ce_ring_state *src_ring; 854 struct ath10k_ce_ring *src_ring;
927 unsigned int nentries = attr->src_nentries; 855 unsigned int nentries = attr->src_nentries;
928 unsigned int ce_nbytes; 856 unsigned int ce_nbytes;
929 u32 ctrl_addr = ath10k_ce_base_address(ce_id); 857 u32 ctrl_addr = ath10k_ce_base_address(ce_id);
@@ -937,19 +865,18 @@ static int ath10k_ce_init_src_ring(struct ath10k *ar,
937 return 0; 865 return 0;
938 } 866 }
939 867
940 ce_nbytes = sizeof(struct ce_ring_state) + (nentries * sizeof(void *)); 868 ce_nbytes = sizeof(struct ath10k_ce_ring) + (nentries * sizeof(void *));
941 ptr = kzalloc(ce_nbytes, GFP_KERNEL); 869 ptr = kzalloc(ce_nbytes, GFP_KERNEL);
942 if (ptr == NULL) 870 if (ptr == NULL)
943 return -ENOMEM; 871 return -ENOMEM;
944 872
945 ce_state->src_ring = (struct ce_ring_state *)ptr; 873 ce_state->src_ring = (struct ath10k_ce_ring *)ptr;
946 src_ring = ce_state->src_ring; 874 src_ring = ce_state->src_ring;
947 875
948 ptr += sizeof(struct ce_ring_state); 876 ptr += sizeof(struct ath10k_ce_ring);
949 src_ring->nentries = nentries; 877 src_ring->nentries = nentries;
950 src_ring->nentries_mask = nentries - 1; 878 src_ring->nentries_mask = nentries - 1;
951 879
952 ath10k_pci_wake(ar);
953 src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr); 880 src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
954 src_ring->sw_index &= src_ring->nentries_mask; 881 src_ring->sw_index &= src_ring->nentries_mask;
955 src_ring->hw_index = src_ring->sw_index; 882 src_ring->hw_index = src_ring->sw_index;
@@ -957,7 +884,6 @@ static int ath10k_ce_init_src_ring(struct ath10k *ar,
957 src_ring->write_index = 884 src_ring->write_index =
958 ath10k_ce_src_ring_write_index_get(ar, ctrl_addr); 885 ath10k_ce_src_ring_write_index_get(ar, ctrl_addr);
959 src_ring->write_index &= src_ring->nentries_mask; 886 src_ring->write_index &= src_ring->nentries_mask;
960 ath10k_pci_sleep(ar);
961 887
962 src_ring->per_transfer_context = (void **)ptr; 888 src_ring->per_transfer_context = (void **)ptr;
963 889
@@ -970,6 +896,12 @@ static int ath10k_ce_init_src_ring(struct ath10k *ar,
970 (nentries * sizeof(struct ce_desc) + 896 (nentries * sizeof(struct ce_desc) +
971 CE_DESC_RING_ALIGN), 897 CE_DESC_RING_ALIGN),
972 &base_addr); 898 &base_addr);
899 if (!src_ring->base_addr_owner_space_unaligned) {
900 kfree(ce_state->src_ring);
901 ce_state->src_ring = NULL;
902 return -ENOMEM;
903 }
904
973 src_ring->base_addr_ce_space_unaligned = base_addr; 905 src_ring->base_addr_ce_space_unaligned = base_addr;
974 906
975 src_ring->base_addr_owner_space = PTR_ALIGN( 907 src_ring->base_addr_owner_space = PTR_ALIGN(
@@ -986,12 +918,21 @@ static int ath10k_ce_init_src_ring(struct ath10k *ar,
986 src_ring->shadow_base_unaligned = 918 src_ring->shadow_base_unaligned =
987 kmalloc((nentries * sizeof(struct ce_desc) + 919 kmalloc((nentries * sizeof(struct ce_desc) +
988 CE_DESC_RING_ALIGN), GFP_KERNEL); 920 CE_DESC_RING_ALIGN), GFP_KERNEL);
921 if (!src_ring->shadow_base_unaligned) {
922 pci_free_consistent(ar_pci->pdev,
923 (nentries * sizeof(struct ce_desc) +
924 CE_DESC_RING_ALIGN),
925 src_ring->base_addr_owner_space,
926 src_ring->base_addr_ce_space);
927 kfree(ce_state->src_ring);
928 ce_state->src_ring = NULL;
929 return -ENOMEM;
930 }
989 931
990 src_ring->shadow_base = PTR_ALIGN( 932 src_ring->shadow_base = PTR_ALIGN(
991 src_ring->shadow_base_unaligned, 933 src_ring->shadow_base_unaligned,
992 CE_DESC_RING_ALIGN); 934 CE_DESC_RING_ALIGN);
993 935
994 ath10k_pci_wake(ar);
995 ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr, 936 ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr,
996 src_ring->base_addr_ce_space); 937 src_ring->base_addr_ce_space);
997 ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries); 938 ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries);
@@ -999,18 +940,21 @@ static int ath10k_ce_init_src_ring(struct ath10k *ar,
999 ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0); 940 ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0);
1000 ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0); 941 ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0);
1001 ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries); 942 ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries);
1002 ath10k_pci_sleep(ar); 943
944 ath10k_dbg(ATH10K_DBG_BOOT,
945 "boot ce src ring id %d entries %d base_addr %p\n",
946 ce_id, nentries, src_ring->base_addr_owner_space);
1003 947
1004 return 0; 948 return 0;
1005} 949}
1006 950
1007static int ath10k_ce_init_dest_ring(struct ath10k *ar, 951static int ath10k_ce_init_dest_ring(struct ath10k *ar,
1008 unsigned int ce_id, 952 unsigned int ce_id,
1009 struct ce_state *ce_state, 953 struct ath10k_ce_pipe *ce_state,
1010 const struct ce_attr *attr) 954 const struct ce_attr *attr)
1011{ 955{
1012 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 956 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1013 struct ce_ring_state *dest_ring; 957 struct ath10k_ce_ring *dest_ring;
1014 unsigned int nentries = attr->dest_nentries; 958 unsigned int nentries = attr->dest_nentries;
1015 unsigned int ce_nbytes; 959 unsigned int ce_nbytes;
1016 u32 ctrl_addr = ath10k_ce_base_address(ce_id); 960 u32 ctrl_addr = ath10k_ce_base_address(ce_id);
@@ -1024,25 +968,23 @@ static int ath10k_ce_init_dest_ring(struct ath10k *ar,
1024 return 0; 968 return 0;
1025 } 969 }
1026 970
1027 ce_nbytes = sizeof(struct ce_ring_state) + (nentries * sizeof(void *)); 971 ce_nbytes = sizeof(struct ath10k_ce_ring) + (nentries * sizeof(void *));
1028 ptr = kzalloc(ce_nbytes, GFP_KERNEL); 972 ptr = kzalloc(ce_nbytes, GFP_KERNEL);
1029 if (ptr == NULL) 973 if (ptr == NULL)
1030 return -ENOMEM; 974 return -ENOMEM;
1031 975
1032 ce_state->dest_ring = (struct ce_ring_state *)ptr; 976 ce_state->dest_ring = (struct ath10k_ce_ring *)ptr;
1033 dest_ring = ce_state->dest_ring; 977 dest_ring = ce_state->dest_ring;
1034 978
1035 ptr += sizeof(struct ce_ring_state); 979 ptr += sizeof(struct ath10k_ce_ring);
1036 dest_ring->nentries = nentries; 980 dest_ring->nentries = nentries;
1037 dest_ring->nentries_mask = nentries - 1; 981 dest_ring->nentries_mask = nentries - 1;
1038 982
1039 ath10k_pci_wake(ar);
1040 dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr); 983 dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
1041 dest_ring->sw_index &= dest_ring->nentries_mask; 984 dest_ring->sw_index &= dest_ring->nentries_mask;
1042 dest_ring->write_index = 985 dest_ring->write_index =
1043 ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr); 986 ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
1044 dest_ring->write_index &= dest_ring->nentries_mask; 987 dest_ring->write_index &= dest_ring->nentries_mask;
1045 ath10k_pci_sleep(ar);
1046 988
1047 dest_ring->per_transfer_context = (void **)ptr; 989 dest_ring->per_transfer_context = (void **)ptr;
1048 990
@@ -1055,6 +997,12 @@ static int ath10k_ce_init_dest_ring(struct ath10k *ar,
1055 (nentries * sizeof(struct ce_desc) + 997 (nentries * sizeof(struct ce_desc) +
1056 CE_DESC_RING_ALIGN), 998 CE_DESC_RING_ALIGN),
1057 &base_addr); 999 &base_addr);
1000 if (!dest_ring->base_addr_owner_space_unaligned) {
1001 kfree(ce_state->dest_ring);
1002 ce_state->dest_ring = NULL;
1003 return -ENOMEM;
1004 }
1005
1058 dest_ring->base_addr_ce_space_unaligned = base_addr; 1006 dest_ring->base_addr_ce_space_unaligned = base_addr;
1059 1007
1060 /* 1008 /*
@@ -1071,44 +1019,35 @@ static int ath10k_ce_init_dest_ring(struct ath10k *ar,
1071 dest_ring->base_addr_ce_space_unaligned, 1019 dest_ring->base_addr_ce_space_unaligned,
1072 CE_DESC_RING_ALIGN); 1020 CE_DESC_RING_ALIGN);
1073 1021
1074 ath10k_pci_wake(ar);
1075 ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr, 1022 ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr,
1076 dest_ring->base_addr_ce_space); 1023 dest_ring->base_addr_ce_space);
1077 ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries); 1024 ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries);
1078 ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0); 1025 ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0);
1079 ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0); 1026 ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0);
1080 ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries); 1027 ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries);
1081 ath10k_pci_sleep(ar); 1028
1029 ath10k_dbg(ATH10K_DBG_BOOT,
1030 "boot ce dest ring id %d entries %d base_addr %p\n",
1031 ce_id, nentries, dest_ring->base_addr_owner_space);
1082 1032
1083 return 0; 1033 return 0;
1084} 1034}
1085 1035
1086static struct ce_state *ath10k_ce_init_state(struct ath10k *ar, 1036static struct ath10k_ce_pipe *ath10k_ce_init_state(struct ath10k *ar,
1087 unsigned int ce_id, 1037 unsigned int ce_id,
1088 const struct ce_attr *attr) 1038 const struct ce_attr *attr)
1089{ 1039{
1090 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1040 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1091 struct ce_state *ce_state = NULL; 1041 struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
1092 u32 ctrl_addr = ath10k_ce_base_address(ce_id); 1042 u32 ctrl_addr = ath10k_ce_base_address(ce_id);
1093 1043
1094 spin_lock_bh(&ar_pci->ce_lock); 1044 spin_lock_bh(&ar_pci->ce_lock);
1095 1045
1096 if (!ar_pci->ce_id_to_state[ce_id]) { 1046 ce_state->ar = ar;
1097 ce_state = kzalloc(sizeof(*ce_state), GFP_ATOMIC); 1047 ce_state->id = ce_id;
1098 if (ce_state == NULL) { 1048 ce_state->ctrl_addr = ctrl_addr;
1099 spin_unlock_bh(&ar_pci->ce_lock); 1049 ce_state->attr_flags = attr->flags;
1100 return NULL; 1050 ce_state->src_sz_max = attr->src_sz_max;
1101 }
1102
1103 ar_pci->ce_id_to_state[ce_id] = ce_state;
1104 ce_state->ar = ar;
1105 ce_state->id = ce_id;
1106 ce_state->ctrl_addr = ctrl_addr;
1107 ce_state->state = CE_RUNNING;
1108 /* Save attribute flags */
1109 ce_state->attr_flags = attr->flags;
1110 ce_state->src_sz_max = attr->src_sz_max;
1111 }
1112 1051
1113 spin_unlock_bh(&ar_pci->ce_lock); 1052 spin_unlock_bh(&ar_pci->ce_lock);
1114 1053
@@ -1122,12 +1061,17 @@ static struct ce_state *ath10k_ce_init_state(struct ath10k *ar,
1122 * initialization. It may be that only one side or the other is 1061 * initialization. It may be that only one side or the other is
1123 * initialized by software/firmware. 1062 * initialized by software/firmware.
1124 */ 1063 */
1125struct ce_state *ath10k_ce_init(struct ath10k *ar, 1064struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
1126 unsigned int ce_id, 1065 unsigned int ce_id,
1127 const struct ce_attr *attr) 1066 const struct ce_attr *attr)
1128{ 1067{
1129 struct ce_state *ce_state; 1068 struct ath10k_ce_pipe *ce_state;
1130 u32 ctrl_addr = ath10k_ce_base_address(ce_id); 1069 u32 ctrl_addr = ath10k_ce_base_address(ce_id);
1070 int ret;
1071
1072 ret = ath10k_pci_wake(ar);
1073 if (ret)
1074 return NULL;
1131 1075
1132 ce_state = ath10k_ce_init_state(ar, ce_id, attr); 1076 ce_state = ath10k_ce_init_state(ar, ce_id, attr);
1133 if (!ce_state) { 1077 if (!ce_state) {
@@ -1136,40 +1080,38 @@ struct ce_state *ath10k_ce_init(struct ath10k *ar,
1136 } 1080 }
1137 1081
1138 if (attr->src_nentries) { 1082 if (attr->src_nentries) {
1139 if (ath10k_ce_init_src_ring(ar, ce_id, ce_state, attr)) { 1083 ret = ath10k_ce_init_src_ring(ar, ce_id, ce_state, attr);
1140 ath10k_err("Failed to initialize CE src ring for ID: %d\n", 1084 if (ret) {
1141 ce_id); 1085 ath10k_err("Failed to initialize CE src ring for ID: %d (%d)\n",
1086 ce_id, ret);
1142 ath10k_ce_deinit(ce_state); 1087 ath10k_ce_deinit(ce_state);
1143 return NULL; 1088 return NULL;
1144 } 1089 }
1145 } 1090 }
1146 1091
1147 if (attr->dest_nentries) { 1092 if (attr->dest_nentries) {
1148 if (ath10k_ce_init_dest_ring(ar, ce_id, ce_state, attr)) { 1093 ret = ath10k_ce_init_dest_ring(ar, ce_id, ce_state, attr);
1149 ath10k_err("Failed to initialize CE dest ring for ID: %d\n", 1094 if (ret) {
1150 ce_id); 1095 ath10k_err("Failed to initialize CE dest ring for ID: %d (%d)\n",
1096 ce_id, ret);
1151 ath10k_ce_deinit(ce_state); 1097 ath10k_ce_deinit(ce_state);
1152 return NULL; 1098 return NULL;
1153 } 1099 }
1154 } 1100 }
1155 1101
1156 /* Enable CE error interrupts */ 1102 /* Enable CE error interrupts */
1157 ath10k_pci_wake(ar);
1158 ath10k_ce_error_intr_enable(ar, ctrl_addr); 1103 ath10k_ce_error_intr_enable(ar, ctrl_addr);
1104
1159 ath10k_pci_sleep(ar); 1105 ath10k_pci_sleep(ar);
1160 1106
1161 return ce_state; 1107 return ce_state;
1162} 1108}
1163 1109
1164void ath10k_ce_deinit(struct ce_state *ce_state) 1110void ath10k_ce_deinit(struct ath10k_ce_pipe *ce_state)
1165{ 1111{
1166 unsigned int ce_id = ce_state->id;
1167 struct ath10k *ar = ce_state->ar; 1112 struct ath10k *ar = ce_state->ar;
1168 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1113 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1169 1114
1170 ce_state->state = CE_UNUSED;
1171 ar_pci->ce_id_to_state[ce_id] = NULL;
1172
1173 if (ce_state->src_ring) { 1115 if (ce_state->src_ring) {
1174 kfree(ce_state->src_ring->shadow_base_unaligned); 1116 kfree(ce_state->src_ring->shadow_base_unaligned);
1175 pci_free_consistent(ar_pci->pdev, 1117 pci_free_consistent(ar_pci->pdev,
@@ -1190,5 +1132,7 @@ void ath10k_ce_deinit(struct ce_state *ce_state)
1190 ce_state->dest_ring->base_addr_ce_space); 1132 ce_state->dest_ring->base_addr_ce_space);
1191 kfree(ce_state->dest_ring); 1133 kfree(ce_state->dest_ring);
1192 } 1134 }
1193 kfree(ce_state); 1135
1136 ce_state->src_ring = NULL;
1137 ce_state->dest_ring = NULL;
1194} 1138}
diff --git a/drivers/net/wireless/ath/ath10k/ce.h b/drivers/net/wireless/ath/ath10k/ce.h
index c17f07c026f4..aec802868341 100644
--- a/drivers/net/wireless/ath/ath10k/ce.h
+++ b/drivers/net/wireless/ath/ath10k/ce.h
@@ -27,7 +27,6 @@
27 27
28/* Descriptor rings must be aligned to this boundary */ 28/* Descriptor rings must be aligned to this boundary */
29#define CE_DESC_RING_ALIGN 8 29#define CE_DESC_RING_ALIGN 8
30#define CE_SENDLIST_ITEMS_MAX 12
31#define CE_SEND_FLAG_GATHER 0x00010000 30#define CE_SEND_FLAG_GATHER 0x00010000
32 31
33/* 32/*
@@ -36,16 +35,9 @@
36 * how to use copy engines. 35 * how to use copy engines.
37 */ 36 */
38 37
39struct ce_state; 38struct ath10k_ce_pipe;
40 39
41 40
42/* Copy Engine operational state */
43enum ce_op_state {
44 CE_UNUSED,
45 CE_PAUSED,
46 CE_RUNNING,
47};
48
49#define CE_DESC_FLAGS_GATHER (1 << 0) 41#define CE_DESC_FLAGS_GATHER (1 << 0)
50#define CE_DESC_FLAGS_BYTE_SWAP (1 << 1) 42#define CE_DESC_FLAGS_BYTE_SWAP (1 << 1)
51#define CE_DESC_FLAGS_META_DATA_MASK 0xFFFC 43#define CE_DESC_FLAGS_META_DATA_MASK 0xFFFC
@@ -57,8 +49,7 @@ struct ce_desc {
57 __le16 flags; /* %CE_DESC_FLAGS_ */ 49 __le16 flags; /* %CE_DESC_FLAGS_ */
58}; 50};
59 51
60/* Copy Engine Ring internal state */ 52struct ath10k_ce_ring {
61struct ce_ring_state {
62 /* Number of entries in this ring; must be power of 2 */ 53 /* Number of entries in this ring; must be power of 2 */
63 unsigned int nentries; 54 unsigned int nentries;
64 unsigned int nentries_mask; 55 unsigned int nentries_mask;
@@ -116,49 +107,20 @@ struct ce_ring_state {
116 void **per_transfer_context; 107 void **per_transfer_context;
117}; 108};
118 109
119/* Copy Engine internal state */ 110struct ath10k_ce_pipe {
120struct ce_state {
121 struct ath10k *ar; 111 struct ath10k *ar;
122 unsigned int id; 112 unsigned int id;
123 113
124 unsigned int attr_flags; 114 unsigned int attr_flags;
125 115
126 u32 ctrl_addr; 116 u32 ctrl_addr;
127 enum ce_op_state state;
128
129 void (*send_cb) (struct ce_state *ce_state,
130 void *per_transfer_send_context,
131 u32 buffer,
132 unsigned int nbytes,
133 unsigned int transfer_id);
134 void (*recv_cb) (struct ce_state *ce_state,
135 void *per_transfer_recv_context,
136 u32 buffer,
137 unsigned int nbytes,
138 unsigned int transfer_id,
139 unsigned int flags);
140 117
141 unsigned int src_sz_max; 118 void (*send_cb)(struct ath10k_ce_pipe *);
142 struct ce_ring_state *src_ring; 119 void (*recv_cb)(struct ath10k_ce_pipe *);
143 struct ce_ring_state *dest_ring;
144};
145 120
146struct ce_sendlist_item { 121 unsigned int src_sz_max;
147 /* e.g. buffer or desc list */ 122 struct ath10k_ce_ring *src_ring;
148 dma_addr_t data; 123 struct ath10k_ce_ring *dest_ring;
149 union {
150 /* simple buffer */
151 unsigned int nbytes;
152 /* Rx descriptor list */
153 unsigned int ndesc;
154 } u;
155 /* externally-specified flags; OR-ed with internal flags */
156 u32 flags;
157};
158
159struct ce_sendlist {
160 unsigned int num_items;
161 struct ce_sendlist_item item[CE_SENDLIST_ITEMS_MAX];
162}; 124};
163 125
164/* Copy Engine settable attributes */ 126/* Copy Engine settable attributes */
@@ -182,7 +144,7 @@ struct ce_attr;
182 * 144 *
183 * Implementation note: pushes 1 buffer to Source ring 145 * Implementation note: pushes 1 buffer to Source ring
184 */ 146 */
185int ath10k_ce_send(struct ce_state *ce_state, 147int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
186 void *per_transfer_send_context, 148 void *per_transfer_send_context,
187 u32 buffer, 149 u32 buffer,
188 unsigned int nbytes, 150 unsigned int nbytes,
@@ -190,21 +152,10 @@ int ath10k_ce_send(struct ce_state *ce_state,
190 unsigned int transfer_id, 152 unsigned int transfer_id,
191 unsigned int flags); 153 unsigned int flags);
192 154
193void ath10k_ce_send_cb_register(struct ce_state *ce_state, 155void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
194 void (*send_cb) (struct ce_state *ce_state, 156 void (*send_cb)(struct ath10k_ce_pipe *),
195 void *transfer_context,
196 u32 buffer,
197 unsigned int nbytes,
198 unsigned int transfer_id),
199 int disable_interrupts); 157 int disable_interrupts);
200 158
201/* Append a simple buffer (address/length) to a sendlist. */
202void ath10k_ce_sendlist_buf_add(struct ce_sendlist *sendlist,
203 u32 buffer,
204 unsigned int nbytes,
205 /* OR-ed with internal flags */
206 u32 flags);
207
208/* 159/*
209 * Queue a "sendlist" of buffers to be sent using gather to a single 160 * Queue a "sendlist" of buffers to be sent using gather to a single
210 * anonymous destination buffer 161 * anonymous destination buffer
@@ -215,11 +166,11 @@ void ath10k_ce_sendlist_buf_add(struct ce_sendlist *sendlist,
215 * 166 *
216 * Implemenation note: Pushes multiple buffers with Gather to Source ring. 167 * Implemenation note: Pushes multiple buffers with Gather to Source ring.
217 */ 168 */
218int ath10k_ce_sendlist_send(struct ce_state *ce_state, 169int ath10k_ce_sendlist_send(struct ath10k_ce_pipe *ce_state,
219 void *per_transfer_send_context, 170 void *per_transfer_context,
220 struct ce_sendlist *sendlist, 171 unsigned int transfer_id,
221 /* 14 bits */ 172 u32 paddr, unsigned int nbytes,
222 unsigned int transfer_id); 173 u32 flags);
223 174
224/*==================Recv=======================*/ 175/*==================Recv=======================*/
225 176
@@ -233,17 +184,12 @@ int ath10k_ce_sendlist_send(struct ce_state *ce_state,
233 * 184 *
234 * Implemenation note: Pushes a buffer to Dest ring. 185 * Implemenation note: Pushes a buffer to Dest ring.
235 */ 186 */
236int ath10k_ce_recv_buf_enqueue(struct ce_state *ce_state, 187int ath10k_ce_recv_buf_enqueue(struct ath10k_ce_pipe *ce_state,
237 void *per_transfer_recv_context, 188 void *per_transfer_recv_context,
238 u32 buffer); 189 u32 buffer);
239 190
240void ath10k_ce_recv_cb_register(struct ce_state *ce_state, 191void ath10k_ce_recv_cb_register(struct ath10k_ce_pipe *ce_state,
241 void (*recv_cb) (struct ce_state *ce_state, 192 void (*recv_cb)(struct ath10k_ce_pipe *));
242 void *transfer_context,
243 u32 buffer,
244 unsigned int nbytes,
245 unsigned int transfer_id,
246 unsigned int flags));
247 193
248/* recv flags */ 194/* recv flags */
249/* Data is byte-swapped */ 195/* Data is byte-swapped */
@@ -253,7 +199,7 @@ void ath10k_ce_recv_cb_register(struct ce_state *ce_state,
253 * Supply data for the next completed unprocessed receive descriptor. 199 * Supply data for the next completed unprocessed receive descriptor.
254 * Pops buffer from Dest ring. 200 * Pops buffer from Dest ring.
255 */ 201 */
256int ath10k_ce_completed_recv_next(struct ce_state *ce_state, 202int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
257 void **per_transfer_contextp, 203 void **per_transfer_contextp,
258 u32 *bufferp, 204 u32 *bufferp,
259 unsigned int *nbytesp, 205 unsigned int *nbytesp,
@@ -263,7 +209,7 @@ int ath10k_ce_completed_recv_next(struct ce_state *ce_state,
263 * Supply data for the next completed unprocessed send descriptor. 209 * Supply data for the next completed unprocessed send descriptor.
264 * Pops 1 completed send buffer from Source ring. 210 * Pops 1 completed send buffer from Source ring.
265 */ 211 */
266int ath10k_ce_completed_send_next(struct ce_state *ce_state, 212int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
267 void **per_transfer_contextp, 213 void **per_transfer_contextp,
268 u32 *bufferp, 214 u32 *bufferp,
269 unsigned int *nbytesp, 215 unsigned int *nbytesp,
@@ -272,7 +218,7 @@ int ath10k_ce_completed_send_next(struct ce_state *ce_state,
272/*==================CE Engine Initialization=======================*/ 218/*==================CE Engine Initialization=======================*/
273 219
274/* Initialize an instance of a CE */ 220/* Initialize an instance of a CE */
275struct ce_state *ath10k_ce_init(struct ath10k *ar, 221struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
276 unsigned int ce_id, 222 unsigned int ce_id,
277 const struct ce_attr *attr); 223 const struct ce_attr *attr);
278 224
@@ -282,7 +228,7 @@ struct ce_state *ath10k_ce_init(struct ath10k *ar,
282 * receive buffers. Target DMA must be stopped before using 228 * receive buffers. Target DMA must be stopped before using
283 * this API. 229 * this API.
284 */ 230 */
285int ath10k_ce_revoke_recv_next(struct ce_state *ce_state, 231int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
286 void **per_transfer_contextp, 232 void **per_transfer_contextp,
287 u32 *bufferp); 233 u32 *bufferp);
288 234
@@ -291,13 +237,13 @@ int ath10k_ce_revoke_recv_next(struct ce_state *ce_state,
291 * pending sends. Target DMA must be stopped before using 237 * pending sends. Target DMA must be stopped before using
292 * this API. 238 * this API.
293 */ 239 */
294int ath10k_ce_cancel_send_next(struct ce_state *ce_state, 240int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
295 void **per_transfer_contextp, 241 void **per_transfer_contextp,
296 u32 *bufferp, 242 u32 *bufferp,
297 unsigned int *nbytesp, 243 unsigned int *nbytesp,
298 unsigned int *transfer_idp); 244 unsigned int *transfer_idp);
299 245
300void ath10k_ce_deinit(struct ce_state *ce_state); 246void ath10k_ce_deinit(struct ath10k_ce_pipe *ce_state);
301 247
302/*==================CE Interrupt Handlers====================*/ 248/*==================CE Interrupt Handlers====================*/
303void ath10k_ce_per_engine_service_any(struct ath10k *ar); 249void ath10k_ce_per_engine_service_any(struct ath10k *ar);
@@ -322,9 +268,6 @@ struct ce_attr {
322 /* CE_ATTR_* values */ 268 /* CE_ATTR_* values */
323 unsigned int flags; 269 unsigned int flags;
324 270
325 /* currently not in use */
326 unsigned int priority;
327
328 /* #entries in source ring - Must be a power of 2 */ 271 /* #entries in source ring - Must be a power of 2 */
329 unsigned int src_nentries; 272 unsigned int src_nentries;
330 273
@@ -336,21 +279,8 @@ struct ce_attr {
336 279
337 /* #entries in destination ring - Must be a power of 2 */ 280 /* #entries in destination ring - Must be a power of 2 */
338 unsigned int dest_nentries; 281 unsigned int dest_nentries;
339
340 /* Future use */
341 void *reserved;
342}; 282};
343 283
344/*
345 * When using sendlist_send to transfer multiple buffer fragments, the
346 * transfer context of each fragment, except last one, will be filled
347 * with CE_SENDLIST_ITEM_CTXT. ce_completed_send will return success for
348 * each fragment done with send and the transfer context would be
349 * CE_SENDLIST_ITEM_CTXT. Upper layer could use this to identify the
350 * status of a send completion.
351 */
352#define CE_SENDLIST_ITEM_CTXT ((void *)0xcecebeef)
353
354#define SR_BA_ADDRESS 0x0000 284#define SR_BA_ADDRESS 0x0000
355#define SR_SIZE_ADDRESS 0x0004 285#define SR_SIZE_ADDRESS 0x0004
356#define DR_BA_ADDRESS 0x0008 286#define DR_BA_ADDRESS 0x0008
diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index 7226c23b9569..76906d5a082e 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -39,17 +39,6 @@ MODULE_PARM_DESC(p2p, "Enable ath10k P2P support");
39 39
40static const struct ath10k_hw_params ath10k_hw_params_list[] = { 40static const struct ath10k_hw_params ath10k_hw_params_list[] = {
41 { 41 {
42 .id = QCA988X_HW_1_0_VERSION,
43 .name = "qca988x hw1.0",
44 .patch_load_addr = QCA988X_HW_1_0_PATCH_LOAD_ADDR,
45 .fw = {
46 .dir = QCA988X_HW_1_0_FW_DIR,
47 .fw = QCA988X_HW_1_0_FW_FILE,
48 .otp = QCA988X_HW_1_0_OTP_FILE,
49 .board = QCA988X_HW_1_0_BOARD_DATA_FILE,
50 },
51 },
52 {
53 .id = QCA988X_HW_2_0_VERSION, 42 .id = QCA988X_HW_2_0_VERSION,
54 .name = "qca988x hw2.0", 43 .name = "qca988x hw2.0",
55 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR, 44 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
@@ -64,7 +53,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
64 53
65static void ath10k_send_suspend_complete(struct ath10k *ar) 54static void ath10k_send_suspend_complete(struct ath10k *ar)
66{ 55{
67 ath10k_dbg(ATH10K_DBG_CORE, "%s\n", __func__); 56 ath10k_dbg(ATH10K_DBG_BOOT, "boot suspend complete\n");
68 57
69 ar->is_target_paused = true; 58 ar->is_target_paused = true;
70 wake_up(&ar->event_queue); 59 wake_up(&ar->event_queue);
@@ -112,7 +101,7 @@ static int ath10k_init_connect_htc(struct ath10k *ar)
112 goto timeout; 101 goto timeout;
113 } 102 }
114 103
115 ath10k_dbg(ATH10K_DBG_CORE, "core wmi ready\n"); 104 ath10k_dbg(ATH10K_DBG_BOOT, "boot wmi ready\n");
116 return 0; 105 return 0;
117 106
118timeout: 107timeout:
@@ -214,8 +203,8 @@ static int ath10k_push_board_ext_data(struct ath10k *ar,
214 return ret; 203 return ret;
215 } 204 }
216 205
217 ath10k_dbg(ATH10K_DBG_CORE, 206 ath10k_dbg(ATH10K_DBG_BOOT,
218 "ath10k: Board extended Data download addr: 0x%x\n", 207 "boot push board extended data addr 0x%x\n",
219 board_ext_data_addr); 208 board_ext_data_addr);
220 209
221 if (board_ext_data_addr == 0) 210 if (board_ext_data_addr == 0)
@@ -446,6 +435,13 @@ static int ath10k_init_uart(struct ath10k *ar)
446 return ret; 435 return ret;
447 } 436 }
448 437
438 /* Set the UART baud rate to 19200. */
439 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
440 if (ret) {
441 ath10k_warn("could not set the baud rate (%d)\n", ret);
442 return ret;
443 }
444
449 ath10k_info("UART prints enabled\n"); 445 ath10k_info("UART prints enabled\n");
450 return 0; 446 return 0;
451} 447}
@@ -641,6 +637,10 @@ int ath10k_core_start(struct ath10k *ar)
641 if (status) 637 if (status)
642 goto err_disconnect_htc; 638 goto err_disconnect_htc;
643 639
640 status = ath10k_debug_start(ar);
641 if (status)
642 goto err_disconnect_htc;
643
644 ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1; 644 ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
645 645
646 return 0; 646 return 0;
@@ -658,6 +658,7 @@ EXPORT_SYMBOL(ath10k_core_start);
658 658
659void ath10k_core_stop(struct ath10k *ar) 659void ath10k_core_stop(struct ath10k *ar)
660{ 660{
661 ath10k_debug_stop(ar);
661 ath10k_htc_stop(&ar->htc); 662 ath10k_htc_stop(&ar->htc);
662 ath10k_htt_detach(&ar->htt); 663 ath10k_htt_detach(&ar->htt);
663 ath10k_wmi_detach(ar); 664 ath10k_wmi_detach(ar);
@@ -717,10 +718,46 @@ static int ath10k_core_probe_fw(struct ath10k *ar)
717 return 0; 718 return 0;
718} 719}
719 720
720int ath10k_core_register(struct ath10k *ar) 721static int ath10k_core_check_chip_id(struct ath10k *ar)
722{
723 u32 hw_revision = MS(ar->chip_id, SOC_CHIP_ID_REV);
724
725 ath10k_dbg(ATH10K_DBG_BOOT, "boot chip_id 0x%08x hw_revision 0x%x\n",
726 ar->chip_id, hw_revision);
727
728 /* Check that we are not using hw1.0 (some of them have same pci id
729 * as hw2.0) before doing anything else as ath10k crashes horribly
730 * due to missing hw1.0 workarounds. */
731 switch (hw_revision) {
732 case QCA988X_HW_1_0_CHIP_ID_REV:
733 ath10k_err("ERROR: qca988x hw1.0 is not supported\n");
734 return -EOPNOTSUPP;
735
736 case QCA988X_HW_2_0_CHIP_ID_REV:
737 /* known hardware revision, continue normally */
738 return 0;
739
740 default:
741 ath10k_warn("Warning: hardware revision unknown (0x%x), expect problems\n",
742 ar->chip_id);
743 return 0;
744 }
745
746 return 0;
747}
748
749int ath10k_core_register(struct ath10k *ar, u32 chip_id)
721{ 750{
722 int status; 751 int status;
723 752
753 ar->chip_id = chip_id;
754
755 status = ath10k_core_check_chip_id(ar);
756 if (status) {
757 ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id);
758 return status;
759 }
760
724 status = ath10k_core_probe_fw(ar); 761 status = ath10k_core_probe_fw(ar);
725 if (status) { 762 if (status) {
726 ath10k_err("could not probe fw (%d)\n", status); 763 ath10k_err("could not probe fw (%d)\n", status);
@@ -755,6 +792,7 @@ void ath10k_core_unregister(struct ath10k *ar)
755 * Otherwise we will fail to submit commands to FW and mac80211 will be 792 * Otherwise we will fail to submit commands to FW and mac80211 will be
756 * unhappy about callback failures. */ 793 * unhappy about callback failures. */
757 ath10k_mac_unregister(ar); 794 ath10k_mac_unregister(ar);
795
758 ath10k_core_free_firmware_files(ar); 796 ath10k_core_free_firmware_files(ar);
759} 797}
760EXPORT_SYMBOL(ath10k_core_unregister); 798EXPORT_SYMBOL(ath10k_core_unregister);
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index e4bba563ed42..292ad4577c98 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -52,18 +52,12 @@ struct ath10k_skb_cb {
52 52
53 struct { 53 struct {
54 u8 vdev_id; 54 u8 vdev_id;
55 u16 msdu_id;
56 u8 tid; 55 u8 tid;
57 bool is_offchan; 56 bool is_offchan;
58 bool is_conf;
59 bool discard;
60 bool no_ack;
61 u8 refcount;
62 struct sk_buff *txfrag;
63 struct sk_buff *msdu;
64 } __packed htt;
65 57
66 /* 4 bytes left on 64bit arch */ 58 u8 frag_len;
59 u8 pad_len;
60 } __packed htt;
67} __packed; 61} __packed;
68 62
69static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb) 63static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
@@ -112,11 +106,7 @@ struct ath10k_wmi {
112 enum ath10k_htc_ep_id eid; 106 enum ath10k_htc_ep_id eid;
113 struct completion service_ready; 107 struct completion service_ready;
114 struct completion unified_ready; 108 struct completion unified_ready;
115 atomic_t pending_tx_count; 109 wait_queue_head_t tx_credits_wq;
116 wait_queue_head_t wq;
117
118 struct sk_buff_head wmi_event_list;
119 struct work_struct wmi_event_work;
120}; 110};
121 111
122struct ath10k_peer_stat { 112struct ath10k_peer_stat {
@@ -203,6 +193,7 @@ struct ath10k_vif {
203 enum wmi_vdev_subtype vdev_subtype; 193 enum wmi_vdev_subtype vdev_subtype;
204 u32 beacon_interval; 194 u32 beacon_interval;
205 u32 dtim_period; 195 u32 dtim_period;
196 struct sk_buff *beacon;
206 197
207 struct ath10k *ar; 198 struct ath10k *ar;
208 struct ieee80211_vif *vif; 199 struct ieee80211_vif *vif;
@@ -246,6 +237,9 @@ struct ath10k_debug {
246 u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE]; 237 u32 wmi_service_bitmap[WMI_SERVICE_BM_SIZE];
247 238
248 struct completion event_stats_compl; 239 struct completion event_stats_compl;
240
241 unsigned long htt_stats_mask;
242 struct delayed_work htt_stats_dwork;
249}; 243};
250 244
251enum ath10k_state { 245enum ath10k_state {
@@ -270,12 +264,21 @@ enum ath10k_state {
270 ATH10K_STATE_WEDGED, 264 ATH10K_STATE_WEDGED,
271}; 265};
272 266
267enum ath10k_fw_features {
268 /* wmi_mgmt_rx_hdr contains extra RSSI information */
269 ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
270
271 /* keep last */
272 ATH10K_FW_FEATURE_COUNT,
273};
274
273struct ath10k { 275struct ath10k {
274 struct ath_common ath_common; 276 struct ath_common ath_common;
275 struct ieee80211_hw *hw; 277 struct ieee80211_hw *hw;
276 struct device *dev; 278 struct device *dev;
277 u8 mac_addr[ETH_ALEN]; 279 u8 mac_addr[ETH_ALEN];
278 280
281 u32 chip_id;
279 u32 target_version; 282 u32 target_version;
280 u8 fw_version_major; 283 u8 fw_version_major;
281 u32 fw_version_minor; 284 u32 fw_version_minor;
@@ -288,6 +291,8 @@ struct ath10k {
288 u32 vht_cap_info; 291 u32 vht_cap_info;
289 u32 num_rf_chains; 292 u32 num_rf_chains;
290 293
294 DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
295
291 struct targetdef *targetdef; 296 struct targetdef *targetdef;
292 struct hostdef *hostdef; 297 struct hostdef *hostdef;
293 298
@@ -393,7 +398,7 @@ void ath10k_core_destroy(struct ath10k *ar);
393 398
394int ath10k_core_start(struct ath10k *ar); 399int ath10k_core_start(struct ath10k *ar);
395void ath10k_core_stop(struct ath10k *ar); 400void ath10k_core_stop(struct ath10k *ar);
396int ath10k_core_register(struct ath10k *ar); 401int ath10k_core_register(struct ath10k *ar, u32 chip_id);
397void ath10k_core_unregister(struct ath10k *ar); 402void ath10k_core_unregister(struct ath10k *ar);
398 403
399#endif /* _CORE_H_ */ 404#endif /* _CORE_H_ */
diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c
index 3d65594fa098..59615c7f217e 100644
--- a/drivers/net/wireless/ath/ath10k/debug.c
+++ b/drivers/net/wireless/ath/ath10k/debug.c
@@ -21,6 +21,9 @@
21#include "core.h" 21#include "core.h"
22#include "debug.h" 22#include "debug.h"
23 23
24/* ms */
25#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
26
24static int ath10k_printk(const char *level, const char *fmt, ...) 27static int ath10k_printk(const char *level, const char *fmt, ...)
25{ 28{
26 struct va_format vaf; 29 struct va_format vaf;
@@ -260,7 +263,6 @@ void ath10k_debug_read_target_stats(struct ath10k *ar,
260 } 263 }
261 264
262 spin_unlock_bh(&ar->data_lock); 265 spin_unlock_bh(&ar->data_lock);
263 mutex_unlock(&ar->conf_mutex);
264 complete(&ar->debug.event_stats_compl); 266 complete(&ar->debug.event_stats_compl);
265} 267}
266 268
@@ -499,6 +501,136 @@ static const struct file_operations fops_simulate_fw_crash = {
499 .llseek = default_llseek, 501 .llseek = default_llseek,
500}; 502};
501 503
504static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
505 size_t count, loff_t *ppos)
506{
507 struct ath10k *ar = file->private_data;
508 unsigned int len;
509 char buf[50];
510
511 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
512
513 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
514}
515
516static const struct file_operations fops_chip_id = {
517 .read = ath10k_read_chip_id,
518 .open = simple_open,
519 .owner = THIS_MODULE,
520 .llseek = default_llseek,
521};
522
523static int ath10k_debug_htt_stats_req(struct ath10k *ar)
524{
525 u64 cookie;
526 int ret;
527
528 lockdep_assert_held(&ar->conf_mutex);
529
530 if (ar->debug.htt_stats_mask == 0)
531 /* htt stats are disabled */
532 return 0;
533
534 if (ar->state != ATH10K_STATE_ON)
535 return 0;
536
537 cookie = get_jiffies_64();
538
539 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
540 cookie);
541 if (ret) {
542 ath10k_warn("failed to send htt stats request: %d\n", ret);
543 return ret;
544 }
545
546 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
547 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
548
549 return 0;
550}
551
552static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
553{
554 struct ath10k *ar = container_of(work, struct ath10k,
555 debug.htt_stats_dwork.work);
556
557 mutex_lock(&ar->conf_mutex);
558
559 ath10k_debug_htt_stats_req(ar);
560
561 mutex_unlock(&ar->conf_mutex);
562}
563
564static ssize_t ath10k_read_htt_stats_mask(struct file *file,
565 char __user *user_buf,
566 size_t count, loff_t *ppos)
567{
568 struct ath10k *ar = file->private_data;
569 char buf[32];
570 unsigned int len;
571
572 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
573
574 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
575}
576
577static ssize_t ath10k_write_htt_stats_mask(struct file *file,
578 const char __user *user_buf,
579 size_t count, loff_t *ppos)
580{
581 struct ath10k *ar = file->private_data;
582 unsigned long mask;
583 int ret;
584
585 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
586 if (ret)
587 return ret;
588
589 /* max 8 bit masks (for now) */
590 if (mask > 0xff)
591 return -E2BIG;
592
593 mutex_lock(&ar->conf_mutex);
594
595 ar->debug.htt_stats_mask = mask;
596
597 ret = ath10k_debug_htt_stats_req(ar);
598 if (ret)
599 goto out;
600
601 ret = count;
602
603out:
604 mutex_unlock(&ar->conf_mutex);
605
606 return ret;
607}
608
609static const struct file_operations fops_htt_stats_mask = {
610 .read = ath10k_read_htt_stats_mask,
611 .write = ath10k_write_htt_stats_mask,
612 .open = simple_open,
613 .owner = THIS_MODULE,
614 .llseek = default_llseek,
615};
616
617int ath10k_debug_start(struct ath10k *ar)
618{
619 int ret;
620
621 ret = ath10k_debug_htt_stats_req(ar);
622 if (ret)
623 /* continue normally anyway, this isn't serious */
624 ath10k_warn("failed to start htt stats workqueue: %d\n", ret);
625
626 return 0;
627}
628
629void ath10k_debug_stop(struct ath10k *ar)
630{
631 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
632}
633
502int ath10k_debug_create(struct ath10k *ar) 634int ath10k_debug_create(struct ath10k *ar)
503{ 635{
504 ar->debug.debugfs_phy = debugfs_create_dir("ath10k", 636 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
@@ -507,6 +639,9 @@ int ath10k_debug_create(struct ath10k *ar)
507 if (!ar->debug.debugfs_phy) 639 if (!ar->debug.debugfs_phy)
508 return -ENOMEM; 640 return -ENOMEM;
509 641
642 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
643 ath10k_debug_htt_stats_dwork);
644
510 init_completion(&ar->debug.event_stats_compl); 645 init_completion(&ar->debug.event_stats_compl);
511 646
512 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar, 647 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
@@ -518,8 +653,15 @@ int ath10k_debug_create(struct ath10k *ar)
518 debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy, 653 debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy,
519 ar, &fops_simulate_fw_crash); 654 ar, &fops_simulate_fw_crash);
520 655
656 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
657 ar, &fops_chip_id);
658
659 debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy,
660 ar, &fops_htt_stats_mask);
661
521 return 0; 662 return 0;
522} 663}
664
523#endif /* CONFIG_ATH10K_DEBUGFS */ 665#endif /* CONFIG_ATH10K_DEBUGFS */
524 666
525#ifdef CONFIG_ATH10K_DEBUG 667#ifdef CONFIG_ATH10K_DEBUG
diff --git a/drivers/net/wireless/ath/ath10k/debug.h b/drivers/net/wireless/ath/ath10k/debug.h
index bb0063320397..6576b82a8d86 100644
--- a/drivers/net/wireless/ath/ath10k/debug.h
+++ b/drivers/net/wireless/ath/ath10k/debug.h
@@ -27,11 +27,12 @@ enum ath10k_debug_mask {
27 ATH10K_DBG_HTC = 0x00000004, 27 ATH10K_DBG_HTC = 0x00000004,
28 ATH10K_DBG_HTT = 0x00000008, 28 ATH10K_DBG_HTT = 0x00000008,
29 ATH10K_DBG_MAC = 0x00000010, 29 ATH10K_DBG_MAC = 0x00000010,
30 ATH10K_DBG_CORE = 0x00000020, 30 ATH10K_DBG_BOOT = 0x00000020,
31 ATH10K_DBG_PCI_DUMP = 0x00000040, 31 ATH10K_DBG_PCI_DUMP = 0x00000040,
32 ATH10K_DBG_HTT_DUMP = 0x00000080, 32 ATH10K_DBG_HTT_DUMP = 0x00000080,
33 ATH10K_DBG_MGMT = 0x00000100, 33 ATH10K_DBG_MGMT = 0x00000100,
34 ATH10K_DBG_DATA = 0x00000200, 34 ATH10K_DBG_DATA = 0x00000200,
35 ATH10K_DBG_BMI = 0x00000400,
35 ATH10K_DBG_ANY = 0xffffffff, 36 ATH10K_DBG_ANY = 0xffffffff,
36}; 37};
37 38
@@ -42,6 +43,8 @@ __printf(1, 2) int ath10k_err(const char *fmt, ...);
42__printf(1, 2) int ath10k_warn(const char *fmt, ...); 43__printf(1, 2) int ath10k_warn(const char *fmt, ...);
43 44
44#ifdef CONFIG_ATH10K_DEBUGFS 45#ifdef CONFIG_ATH10K_DEBUGFS
46int ath10k_debug_start(struct ath10k *ar);
47void ath10k_debug_stop(struct ath10k *ar);
45int ath10k_debug_create(struct ath10k *ar); 48int ath10k_debug_create(struct ath10k *ar);
46void ath10k_debug_read_service_map(struct ath10k *ar, 49void ath10k_debug_read_service_map(struct ath10k *ar,
47 void *service_map, 50 void *service_map,
@@ -50,6 +53,15 @@ void ath10k_debug_read_target_stats(struct ath10k *ar,
50 struct wmi_stats_event *ev); 53 struct wmi_stats_event *ev);
51 54
52#else 55#else
56static inline int ath10k_debug_start(struct ath10k *ar)
57{
58 return 0;
59}
60
61static inline void ath10k_debug_stop(struct ath10k *ar)
62{
63}
64
53static inline int ath10k_debug_create(struct ath10k *ar) 65static inline int ath10k_debug_create(struct ath10k *ar)
54{ 66{
55 return 0; 67 return 0;
diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
index ef3329ef52f3..3118d7506734 100644
--- a/drivers/net/wireless/ath/ath10k/htc.c
+++ b/drivers/net/wireless/ath/ath10k/htc.c
@@ -103,10 +103,10 @@ static void ath10k_htc_prepare_tx_skb(struct ath10k_htc_ep *ep,
103 struct ath10k_htc_hdr *hdr; 103 struct ath10k_htc_hdr *hdr;
104 104
105 hdr = (struct ath10k_htc_hdr *)skb->data; 105 hdr = (struct ath10k_htc_hdr *)skb->data;
106 memset(hdr, 0, sizeof(*hdr));
107 106
108 hdr->eid = ep->eid; 107 hdr->eid = ep->eid;
109 hdr->len = __cpu_to_le16(skb->len - sizeof(*hdr)); 108 hdr->len = __cpu_to_le16(skb->len - sizeof(*hdr));
109 hdr->flags = 0;
110 110
111 spin_lock_bh(&ep->htc->tx_lock); 111 spin_lock_bh(&ep->htc->tx_lock);
112 hdr->seq_no = ep->seq_no++; 112 hdr->seq_no = ep->seq_no++;
@@ -117,134 +117,13 @@ static void ath10k_htc_prepare_tx_skb(struct ath10k_htc_ep *ep,
117 spin_unlock_bh(&ep->htc->tx_lock); 117 spin_unlock_bh(&ep->htc->tx_lock);
118} 118}
119 119
120static int ath10k_htc_issue_skb(struct ath10k_htc *htc,
121 struct ath10k_htc_ep *ep,
122 struct sk_buff *skb,
123 u8 credits)
124{
125 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
126 int ret;
127
128 ath10k_dbg(ATH10K_DBG_HTC, "%s: ep %d skb %p\n", __func__,
129 ep->eid, skb);
130
131 ath10k_htc_prepare_tx_skb(ep, skb);
132
133 ret = ath10k_skb_map(htc->ar->dev, skb);
134 if (ret)
135 goto err;
136
137 ret = ath10k_hif_send_head(htc->ar,
138 ep->ul_pipe_id,
139 ep->eid,
140 skb->len,
141 skb);
142 if (unlikely(ret))
143 goto err;
144
145 return 0;
146err:
147 ath10k_warn("HTC issue failed: %d\n", ret);
148
149 spin_lock_bh(&htc->tx_lock);
150 ep->tx_credits += credits;
151 spin_unlock_bh(&htc->tx_lock);
152
153 /* this is the simplest way to handle out-of-resources for non-credit
154 * based endpoints. credit based endpoints can still get -ENOSR, but
155 * this is highly unlikely as credit reservation should prevent that */
156 if (ret == -ENOSR) {
157 spin_lock_bh(&htc->tx_lock);
158 __skb_queue_head(&ep->tx_queue, skb);
159 spin_unlock_bh(&htc->tx_lock);
160
161 return ret;
162 }
163
164 skb_cb->is_aborted = true;
165 ath10k_htc_notify_tx_completion(ep, skb);
166
167 return ret;
168}
169
170static struct sk_buff *ath10k_htc_get_skb_credit_based(struct ath10k_htc *htc,
171 struct ath10k_htc_ep *ep,
172 u8 *credits)
173{
174 struct sk_buff *skb;
175 struct ath10k_skb_cb *skb_cb;
176 int credits_required;
177 int remainder;
178 unsigned int transfer_len;
179
180 lockdep_assert_held(&htc->tx_lock);
181
182 skb = __skb_dequeue(&ep->tx_queue);
183 if (!skb)
184 return NULL;
185
186 skb_cb = ATH10K_SKB_CB(skb);
187 transfer_len = skb->len;
188
189 if (likely(transfer_len <= htc->target_credit_size)) {
190 credits_required = 1;
191 } else {
192 /* figure out how many credits this message requires */
193 credits_required = transfer_len / htc->target_credit_size;
194 remainder = transfer_len % htc->target_credit_size;
195
196 if (remainder)
197 credits_required++;
198 }
199
200 ath10k_dbg(ATH10K_DBG_HTC, "Credits required %d got %d\n",
201 credits_required, ep->tx_credits);
202
203 if (ep->tx_credits < credits_required) {
204 __skb_queue_head(&ep->tx_queue, skb);
205 return NULL;
206 }
207
208 ep->tx_credits -= credits_required;
209 *credits = credits_required;
210 return skb;
211}
212
213static void ath10k_htc_send_work(struct work_struct *work)
214{
215 struct ath10k_htc_ep *ep = container_of(work,
216 struct ath10k_htc_ep, send_work);
217 struct ath10k_htc *htc = ep->htc;
218 struct sk_buff *skb;
219 u8 credits = 0;
220 int ret;
221
222 while (true) {
223 if (ep->ul_is_polled)
224 ath10k_htc_send_complete_check(ep, 0);
225
226 spin_lock_bh(&htc->tx_lock);
227 if (ep->tx_credit_flow_enabled)
228 skb = ath10k_htc_get_skb_credit_based(htc, ep,
229 &credits);
230 else
231 skb = __skb_dequeue(&ep->tx_queue);
232 spin_unlock_bh(&htc->tx_lock);
233
234 if (!skb)
235 break;
236
237 ret = ath10k_htc_issue_skb(htc, ep, skb, credits);
238 if (ret == -ENOSR)
239 break;
240 }
241}
242
243int ath10k_htc_send(struct ath10k_htc *htc, 120int ath10k_htc_send(struct ath10k_htc *htc,
244 enum ath10k_htc_ep_id eid, 121 enum ath10k_htc_ep_id eid,
245 struct sk_buff *skb) 122 struct sk_buff *skb)
246{ 123{
247 struct ath10k_htc_ep *ep = &htc->endpoint[eid]; 124 struct ath10k_htc_ep *ep = &htc->endpoint[eid];
125 int credits = 0;
126 int ret;
248 127
249 if (htc->ar->state == ATH10K_STATE_WEDGED) 128 if (htc->ar->state == ATH10K_STATE_WEDGED)
250 return -ECOMM; 129 return -ECOMM;
@@ -254,18 +133,55 @@ int ath10k_htc_send(struct ath10k_htc *htc,
254 return -ENOENT; 133 return -ENOENT;
255 } 134 }
256 135
136 /* FIXME: This looks ugly, can we fix it? */
257 spin_lock_bh(&htc->tx_lock); 137 spin_lock_bh(&htc->tx_lock);
258 if (htc->stopped) { 138 if (htc->stopped) {
259 spin_unlock_bh(&htc->tx_lock); 139 spin_unlock_bh(&htc->tx_lock);
260 return -ESHUTDOWN; 140 return -ESHUTDOWN;
261 } 141 }
142 spin_unlock_bh(&htc->tx_lock);
262 143
263 __skb_queue_tail(&ep->tx_queue, skb);
264 skb_push(skb, sizeof(struct ath10k_htc_hdr)); 144 skb_push(skb, sizeof(struct ath10k_htc_hdr));
265 spin_unlock_bh(&htc->tx_lock);
266 145
267 queue_work(htc->ar->workqueue, &ep->send_work); 146 if (ep->tx_credit_flow_enabled) {
147 credits = DIV_ROUND_UP(skb->len, htc->target_credit_size);
148 spin_lock_bh(&htc->tx_lock);
149 if (ep->tx_credits < credits) {
150 spin_unlock_bh(&htc->tx_lock);
151 ret = -EAGAIN;
152 goto err_pull;
153 }
154 ep->tx_credits -= credits;
155 spin_unlock_bh(&htc->tx_lock);
156 }
157
158 ath10k_htc_prepare_tx_skb(ep, skb);
159
160 ret = ath10k_skb_map(htc->ar->dev, skb);
161 if (ret)
162 goto err_credits;
163
164 ret = ath10k_hif_send_head(htc->ar, ep->ul_pipe_id, ep->eid,
165 skb->len, skb);
166 if (ret)
167 goto err_unmap;
168
268 return 0; 169 return 0;
170
171err_unmap:
172 ath10k_skb_unmap(htc->ar->dev, skb);
173err_credits:
174 if (ep->tx_credit_flow_enabled) {
175 spin_lock_bh(&htc->tx_lock);
176 ep->tx_credits += credits;
177 spin_unlock_bh(&htc->tx_lock);
178
179 if (ep->ep_ops.ep_tx_credits)
180 ep->ep_ops.ep_tx_credits(htc->ar);
181 }
182err_pull:
183 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
184 return ret;
269} 185}
270 186
271static int ath10k_htc_tx_completion_handler(struct ath10k *ar, 187static int ath10k_htc_tx_completion_handler(struct ath10k *ar,
@@ -278,39 +194,9 @@ static int ath10k_htc_tx_completion_handler(struct ath10k *ar,
278 ath10k_htc_notify_tx_completion(ep, skb); 194 ath10k_htc_notify_tx_completion(ep, skb);
279 /* the skb now belongs to the completion handler */ 195 /* the skb now belongs to the completion handler */
280 196
281 /* note: when using TX credit flow, the re-checking of queues happens
282 * when credits flow back from the target. in the non-TX credit case,
283 * we recheck after the packet completes */
284 spin_lock_bh(&htc->tx_lock);
285 if (!ep->tx_credit_flow_enabled && !htc->stopped)
286 queue_work(ar->workqueue, &ep->send_work);
287 spin_unlock_bh(&htc->tx_lock);
288
289 return 0; 197 return 0;
290} 198}
291 199
292/* flush endpoint TX queue */
293static void ath10k_htc_flush_endpoint_tx(struct ath10k_htc *htc,
294 struct ath10k_htc_ep *ep)
295{
296 struct sk_buff *skb;
297 struct ath10k_skb_cb *skb_cb;
298
299 spin_lock_bh(&htc->tx_lock);
300 for (;;) {
301 skb = __skb_dequeue(&ep->tx_queue);
302 if (!skb)
303 break;
304
305 skb_cb = ATH10K_SKB_CB(skb);
306 skb_cb->is_aborted = true;
307 ath10k_htc_notify_tx_completion(ep, skb);
308 }
309 spin_unlock_bh(&htc->tx_lock);
310
311 cancel_work_sync(&ep->send_work);
312}
313
314/***********/ 200/***********/
315/* Receive */ 201/* Receive */
316/***********/ 202/***********/
@@ -340,8 +226,11 @@ ath10k_htc_process_credit_report(struct ath10k_htc *htc,
340 ep = &htc->endpoint[report->eid]; 226 ep = &htc->endpoint[report->eid];
341 ep->tx_credits += report->credits; 227 ep->tx_credits += report->credits;
342 228
343 if (ep->tx_credits && !skb_queue_empty(&ep->tx_queue)) 229 if (ep->ep_ops.ep_tx_credits) {
344 queue_work(htc->ar->workqueue, &ep->send_work); 230 spin_unlock_bh(&htc->tx_lock);
231 ep->ep_ops.ep_tx_credits(htc->ar);
232 spin_lock_bh(&htc->tx_lock);
233 }
345 } 234 }
346 spin_unlock_bh(&htc->tx_lock); 235 spin_unlock_bh(&htc->tx_lock);
347} 236}
@@ -599,10 +488,8 @@ static void ath10k_htc_reset_endpoint_states(struct ath10k_htc *htc)
599 ep->max_ep_message_len = 0; 488 ep->max_ep_message_len = 0;
600 ep->max_tx_queue_depth = 0; 489 ep->max_tx_queue_depth = 0;
601 ep->eid = i; 490 ep->eid = i;
602 skb_queue_head_init(&ep->tx_queue);
603 ep->htc = htc; 491 ep->htc = htc;
604 ep->tx_credit_flow_enabled = true; 492 ep->tx_credit_flow_enabled = true;
605 INIT_WORK(&ep->send_work, ath10k_htc_send_work);
606 } 493 }
607} 494}
608 495
@@ -752,8 +639,8 @@ int ath10k_htc_connect_service(struct ath10k_htc *htc,
752 tx_alloc = ath10k_htc_get_credit_allocation(htc, 639 tx_alloc = ath10k_htc_get_credit_allocation(htc,
753 conn_req->service_id); 640 conn_req->service_id);
754 if (!tx_alloc) 641 if (!tx_alloc)
755 ath10k_dbg(ATH10K_DBG_HTC, 642 ath10k_dbg(ATH10K_DBG_BOOT,
756 "HTC Service %s does not allocate target credits\n", 643 "boot htc service %s does not allocate target credits\n",
757 htc_service_name(conn_req->service_id)); 644 htc_service_name(conn_req->service_id));
758 645
759 skb = ath10k_htc_build_tx_ctrl_skb(htc->ar); 646 skb = ath10k_htc_build_tx_ctrl_skb(htc->ar);
@@ -772,16 +659,16 @@ int ath10k_htc_connect_service(struct ath10k_htc *htc,
772 659
773 flags |= SM(tx_alloc, ATH10K_HTC_CONN_FLAGS_RECV_ALLOC); 660 flags |= SM(tx_alloc, ATH10K_HTC_CONN_FLAGS_RECV_ALLOC);
774 661
775 req_msg = &msg->connect_service;
776 req_msg->flags = __cpu_to_le16(flags);
777 req_msg->service_id = __cpu_to_le16(conn_req->service_id);
778
779 /* Only enable credit flow control for WMI ctrl service */ 662 /* Only enable credit flow control for WMI ctrl service */
780 if (conn_req->service_id != ATH10K_HTC_SVC_ID_WMI_CONTROL) { 663 if (conn_req->service_id != ATH10K_HTC_SVC_ID_WMI_CONTROL) {
781 flags |= ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL; 664 flags |= ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
782 disable_credit_flow_ctrl = true; 665 disable_credit_flow_ctrl = true;
783 } 666 }
784 667
668 req_msg = &msg->connect_service;
669 req_msg->flags = __cpu_to_le16(flags);
670 req_msg->service_id = __cpu_to_le16(conn_req->service_id);
671
785 INIT_COMPLETION(htc->ctl_resp); 672 INIT_COMPLETION(htc->ctl_resp);
786 673
787 status = ath10k_htc_send(htc, ATH10K_HTC_EP_0, skb); 674 status = ath10k_htc_send(htc, ATH10K_HTC_EP_0, skb);
@@ -873,19 +760,19 @@ setup:
873 if (status) 760 if (status)
874 return status; 761 return status;
875 762
876 ath10k_dbg(ATH10K_DBG_HTC, 763 ath10k_dbg(ATH10K_DBG_BOOT,
877 "HTC service: %s UL pipe: %d DL pipe: %d eid: %d ready\n", 764 "boot htc service '%s' ul pipe %d dl pipe %d eid %d ready\n",
878 htc_service_name(ep->service_id), ep->ul_pipe_id, 765 htc_service_name(ep->service_id), ep->ul_pipe_id,
879 ep->dl_pipe_id, ep->eid); 766 ep->dl_pipe_id, ep->eid);
880 767
881 ath10k_dbg(ATH10K_DBG_HTC, 768 ath10k_dbg(ATH10K_DBG_BOOT,
882 "EP %d UL polled: %d, DL polled: %d\n", 769 "boot htc ep %d ul polled %d dl polled %d\n",
883 ep->eid, ep->ul_is_polled, ep->dl_is_polled); 770 ep->eid, ep->ul_is_polled, ep->dl_is_polled);
884 771
885 if (disable_credit_flow_ctrl && ep->tx_credit_flow_enabled) { 772 if (disable_credit_flow_ctrl && ep->tx_credit_flow_enabled) {
886 ep->tx_credit_flow_enabled = false; 773 ep->tx_credit_flow_enabled = false;
887 ath10k_dbg(ATH10K_DBG_HTC, 774 ath10k_dbg(ATH10K_DBG_BOOT,
888 "HTC service: %s eid: %d TX flow control disabled\n", 775 "boot htc service '%s' eid %d TX flow control disabled\n",
889 htc_service_name(ep->service_id), assigned_eid); 776 htc_service_name(ep->service_id), assigned_eid);
890 } 777 }
891 778
@@ -945,18 +832,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
945 */ 832 */
946void ath10k_htc_stop(struct ath10k_htc *htc) 833void ath10k_htc_stop(struct ath10k_htc *htc)
947{ 834{
948 int i;
949 struct ath10k_htc_ep *ep;
950
951 spin_lock_bh(&htc->tx_lock); 835 spin_lock_bh(&htc->tx_lock);
952 htc->stopped = true; 836 htc->stopped = true;
953 spin_unlock_bh(&htc->tx_lock); 837 spin_unlock_bh(&htc->tx_lock);
954 838
955 for (i = ATH10K_HTC_EP_0; i < ATH10K_HTC_EP_COUNT; i++) {
956 ep = &htc->endpoint[i];
957 ath10k_htc_flush_endpoint_tx(htc, ep);
958 }
959
960 ath10k_hif_stop(htc->ar); 839 ath10k_hif_stop(htc->ar);
961} 840}
962 841
diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
index e1dd8c761853..4716d331e6b6 100644
--- a/drivers/net/wireless/ath/ath10k/htc.h
+++ b/drivers/net/wireless/ath/ath10k/htc.h
@@ -276,6 +276,7 @@ struct ath10k_htc_ops {
276struct ath10k_htc_ep_ops { 276struct ath10k_htc_ep_ops {
277 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *); 277 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
278 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *); 278 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
279 void (*ep_tx_credits)(struct ath10k *);
279}; 280};
280 281
281/* service connection information */ 282/* service connection information */
@@ -315,15 +316,11 @@ struct ath10k_htc_ep {
315 int ul_is_polled; /* call HIF to get tx completions */ 316 int ul_is_polled; /* call HIF to get tx completions */
316 int dl_is_polled; /* call HIF to fetch rx (not implemented) */ 317 int dl_is_polled; /* call HIF to fetch rx (not implemented) */
317 318
318 struct sk_buff_head tx_queue;
319
320 u8 seq_no; /* for debugging */ 319 u8 seq_no; /* for debugging */
321 int tx_credits; 320 int tx_credits;
322 int tx_credit_size; 321 int tx_credit_size;
323 int tx_credits_per_max_message; 322 int tx_credits_per_max_message;
324 bool tx_credit_flow_enabled; 323 bool tx_credit_flow_enabled;
325
326 struct work_struct send_work;
327}; 324};
328 325
329struct ath10k_htc_svc_tx_credits { 326struct ath10k_htc_svc_tx_credits {
diff --git a/drivers/net/wireless/ath/ath10k/htt.c b/drivers/net/wireless/ath/ath10k/htt.c
index 39342c5cfcb2..5f7eeebc5432 100644
--- a/drivers/net/wireless/ath/ath10k/htt.c
+++ b/drivers/net/wireless/ath/ath10k/htt.c
@@ -104,21 +104,16 @@ err_htc_attach:
104 104
105static int ath10k_htt_verify_version(struct ath10k_htt *htt) 105static int ath10k_htt_verify_version(struct ath10k_htt *htt)
106{ 106{
107 ath10k_dbg(ATH10K_DBG_HTT, 107 ath10k_info("htt target version %d.%d\n",
108 "htt target version %d.%d; host version %d.%d\n", 108 htt->target_version_major, htt->target_version_minor);
109 htt->target_version_major, 109
110 htt->target_version_minor, 110 if (htt->target_version_major != 2 &&
111 HTT_CURRENT_VERSION_MAJOR, 111 htt->target_version_major != 3) {
112 HTT_CURRENT_VERSION_MINOR); 112 ath10k_err("unsupported htt major version %d. supported versions are 2 and 3\n",
113 113 htt->target_version_major);
114 if (htt->target_version_major != HTT_CURRENT_VERSION_MAJOR) {
115 ath10k_err("htt major versions are incompatible!\n");
116 return -ENOTSUPP; 114 return -ENOTSUPP;
117 } 115 }
118 116
119 if (htt->target_version_minor != HTT_CURRENT_VERSION_MINOR)
120 ath10k_warn("htt minor version differ but still compatible\n");
121
122 return 0; 117 return 0;
123} 118}
124 119
diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/ath/ath10k/htt.h
index 318be4629cde..1a337e93b7e9 100644
--- a/drivers/net/wireless/ath/ath10k/htt.h
+++ b/drivers/net/wireless/ath/ath10k/htt.h
@@ -19,13 +19,11 @@
19#define _HTT_H_ 19#define _HTT_H_
20 20
21#include <linux/bug.h> 21#include <linux/bug.h>
22#include <linux/interrupt.h>
22 23
23#include "htc.h" 24#include "htc.h"
24#include "rx_desc.h" 25#include "rx_desc.h"
25 26
26#define HTT_CURRENT_VERSION_MAJOR 2
27#define HTT_CURRENT_VERSION_MINOR 1
28
29enum htt_dbg_stats_type { 27enum htt_dbg_stats_type {
30 HTT_DBG_STATS_WAL_PDEV_TXRX = 1 << 0, 28 HTT_DBG_STATS_WAL_PDEV_TXRX = 1 << 0,
31 HTT_DBG_STATS_RX_REORDER = 1 << 1, 29 HTT_DBG_STATS_RX_REORDER = 1 << 1,
@@ -45,6 +43,9 @@ enum htt_h2t_msg_type { /* host-to-target */
45 HTT_H2T_MSG_TYPE_SYNC = 4, 43 HTT_H2T_MSG_TYPE_SYNC = 4,
46 HTT_H2T_MSG_TYPE_AGGR_CFG = 5, 44 HTT_H2T_MSG_TYPE_AGGR_CFG = 5,
47 HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG = 6, 45 HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG = 6,
46
47 /* This command is used for sending management frames in HTT < 3.0.
48 * HTT >= 3.0 uses TX_FRM for everything. */
48 HTT_H2T_MSG_TYPE_MGMT_TX = 7, 49 HTT_H2T_MSG_TYPE_MGMT_TX = 7,
49 50
50 HTT_H2T_NUM_MSGS /* keep this last */ 51 HTT_H2T_NUM_MSGS /* keep this last */
@@ -1268,6 +1269,7 @@ struct ath10k_htt {
1268 /* set if host-fw communication goes haywire 1269 /* set if host-fw communication goes haywire
1269 * used to avoid further failures */ 1270 * used to avoid further failures */
1270 bool rx_confused; 1271 bool rx_confused;
1272 struct tasklet_struct rx_replenish_task;
1271}; 1273};
1272 1274
1273#define RX_HTT_HDR_STATUS_LEN 64 1275#define RX_HTT_HDR_STATUS_LEN 64
@@ -1308,6 +1310,10 @@ struct htt_rx_desc {
1308#define HTT_RX_BUF_SIZE 1920 1310#define HTT_RX_BUF_SIZE 1920
1309#define HTT_RX_MSDU_SIZE (HTT_RX_BUF_SIZE - (int)sizeof(struct htt_rx_desc)) 1311#define HTT_RX_MSDU_SIZE (HTT_RX_BUF_SIZE - (int)sizeof(struct htt_rx_desc))
1310 1312
1313/* Refill a bunch of RX buffers for each refill round so that FW/HW can handle
1314 * aggregated traffic more nicely. */
1315#define ATH10K_HTT_MAX_NUM_REFILL 16
1316
1311/* 1317/*
1312 * DMA_MAP expects the buffer to be an integral number of cache lines. 1318 * DMA_MAP expects the buffer to be an integral number of cache lines.
1313 * Rather than checking the actual cache line size, this code makes a 1319 * Rather than checking the actual cache line size, this code makes a
@@ -1327,6 +1333,7 @@ void ath10k_htt_rx_detach(struct ath10k_htt *htt);
1327void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb); 1333void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb);
1328void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb); 1334void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb);
1329int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt); 1335int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt);
1336int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u8 mask, u64 cookie);
1330int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt); 1337int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt);
1331 1338
1332void __ath10k_htt_tx_dec_pending(struct ath10k_htt *htt); 1339void __ath10k_htt_tx_dec_pending(struct ath10k_htt *htt);
diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index e784c40b904b..90d4f74c28d7 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -20,6 +20,7 @@
20#include "htt.h" 20#include "htt.h"
21#include "txrx.h" 21#include "txrx.h"
22#include "debug.h" 22#include "debug.h"
23#include "trace.h"
23 24
24#include <linux/log2.h> 25#include <linux/log2.h>
25 26
@@ -40,6 +41,10 @@
40/* when under memory pressure rx ring refill may fail and needs a retry */ 41/* when under memory pressure rx ring refill may fail and needs a retry */
41#define HTT_RX_RING_REFILL_RETRY_MS 50 42#define HTT_RX_RING_REFILL_RETRY_MS 50
42 43
44
45static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb);
46
47
43static int ath10k_htt_rx_ring_size(struct ath10k_htt *htt) 48static int ath10k_htt_rx_ring_size(struct ath10k_htt *htt)
44{ 49{
45 int size; 50 int size;
@@ -177,10 +182,27 @@ static int ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num)
177 182
178static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt) 183static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt)
179{ 184{
180 int ret, num_to_fill; 185 int ret, num_deficit, num_to_fill;
181 186
187 /* Refilling the whole RX ring buffer proves to be a bad idea. The
188 * reason is RX may take up significant amount of CPU cycles and starve
189 * other tasks, e.g. TX on an ethernet device while acting as a bridge
190 * with ath10k wlan interface. This ended up with very poor performance
191 * once CPU the host system was overwhelmed with RX on ath10k.
192 *
193 * By limiting the number of refills the replenishing occurs
194 * progressively. This in turns makes use of the fact tasklets are
195 * processed in FIFO order. This means actual RX processing can starve
196 * out refilling. If there's not enough buffers on RX ring FW will not
197 * report RX until it is refilled with enough buffers. This
198 * automatically balances load wrt to CPU power.
199 *
200 * This probably comes at a cost of lower maximum throughput but
201 * improves the avarage and stability. */
182 spin_lock_bh(&htt->rx_ring.lock); 202 spin_lock_bh(&htt->rx_ring.lock);
183 num_to_fill = htt->rx_ring.fill_level - htt->rx_ring.fill_cnt; 203 num_deficit = htt->rx_ring.fill_level - htt->rx_ring.fill_cnt;
204 num_to_fill = min(ATH10K_HTT_MAX_NUM_REFILL, num_deficit);
205 num_deficit -= num_to_fill;
184 ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill); 206 ret = ath10k_htt_rx_ring_fill_n(htt, num_to_fill);
185 if (ret == -ENOMEM) { 207 if (ret == -ENOMEM) {
186 /* 208 /*
@@ -191,6 +213,8 @@ static void ath10k_htt_rx_msdu_buff_replenish(struct ath10k_htt *htt)
191 */ 213 */
192 mod_timer(&htt->rx_ring.refill_retry_timer, jiffies + 214 mod_timer(&htt->rx_ring.refill_retry_timer, jiffies +
193 msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS)); 215 msecs_to_jiffies(HTT_RX_RING_REFILL_RETRY_MS));
216 } else if (num_deficit > 0) {
217 tasklet_schedule(&htt->rx_replenish_task);
194 } 218 }
195 spin_unlock_bh(&htt->rx_ring.lock); 219 spin_unlock_bh(&htt->rx_ring.lock);
196} 220}
@@ -212,6 +236,7 @@ void ath10k_htt_rx_detach(struct ath10k_htt *htt)
212 int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld; 236 int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld;
213 237
214 del_timer_sync(&htt->rx_ring.refill_retry_timer); 238 del_timer_sync(&htt->rx_ring.refill_retry_timer);
239 tasklet_kill(&htt->rx_replenish_task);
215 240
216 while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) { 241 while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) {
217 struct sk_buff *skb = 242 struct sk_buff *skb =
@@ -441,6 +466,12 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
441 return msdu_chaining; 466 return msdu_chaining;
442} 467}
443 468
469static void ath10k_htt_rx_replenish_task(unsigned long ptr)
470{
471 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
472 ath10k_htt_rx_msdu_buff_replenish(htt);
473}
474
444int ath10k_htt_rx_attach(struct ath10k_htt *htt) 475int ath10k_htt_rx_attach(struct ath10k_htt *htt)
445{ 476{
446 dma_addr_t paddr; 477 dma_addr_t paddr;
@@ -501,7 +532,10 @@ int ath10k_htt_rx_attach(struct ath10k_htt *htt)
501 if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level)) 532 if (__ath10k_htt_rx_ring_fill_n(htt, htt->rx_ring.fill_level))
502 goto err_fill_ring; 533 goto err_fill_ring;
503 534
504 ath10k_dbg(ATH10K_DBG_HTT, "HTT RX ring size: %d, fill_level: %d\n", 535 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
536 (unsigned long)htt);
537
538 ath10k_dbg(ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
505 htt->rx_ring.size, htt->rx_ring.fill_level); 539 htt->rx_ring.size, htt->rx_ring.fill_level);
506 return 0; 540 return 0;
507 541
@@ -590,134 +624,144 @@ static bool ath10k_htt_rx_hdr_is_amsdu(struct ieee80211_hdr *hdr)
590 return false; 624 return false;
591} 625}
592 626
593static int ath10k_htt_rx_amsdu(struct ath10k_htt *htt, 627struct rfc1042_hdr {
594 struct htt_rx_info *info) 628 u8 llc_dsap;
629 u8 llc_ssap;
630 u8 llc_ctrl;
631 u8 snap_oui[3];
632 __be16 snap_type;
633} __packed;
634
635struct amsdu_subframe_hdr {
636 u8 dst[ETH_ALEN];
637 u8 src[ETH_ALEN];
638 __be16 len;
639} __packed;
640
641static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
642 struct htt_rx_info *info)
595{ 643{
596 struct htt_rx_desc *rxd; 644 struct htt_rx_desc *rxd;
597 struct sk_buff *amsdu;
598 struct sk_buff *first; 645 struct sk_buff *first;
599 struct ieee80211_hdr *hdr;
600 struct sk_buff *skb = info->skb; 646 struct sk_buff *skb = info->skb;
601 enum rx_msdu_decap_format fmt; 647 enum rx_msdu_decap_format fmt;
602 enum htt_rx_mpdu_encrypt_type enctype; 648 enum htt_rx_mpdu_encrypt_type enctype;
649 struct ieee80211_hdr *hdr;
650 u8 hdr_buf[64], addr[ETH_ALEN], *qos;
603 unsigned int hdr_len; 651 unsigned int hdr_len;
604 int crypto_len;
605 652
606 rxd = (void *)skb->data - sizeof(*rxd); 653 rxd = (void *)skb->data - sizeof(*rxd);
607 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
608 RX_MSDU_START_INFO1_DECAP_FORMAT);
609 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), 654 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
610 RX_MPDU_START_INFO0_ENCRYPT_TYPE); 655 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
611 656
612 /* FIXME: No idea what assumptions are safe here. Need logs */ 657 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
613 if ((fmt == RX_MSDU_DECAP_RAW && skb->next) || 658 hdr_len = ieee80211_hdrlen(hdr->frame_control);
614 (fmt == RX_MSDU_DECAP_8023_SNAP_LLC)) { 659 memcpy(hdr_buf, hdr, hdr_len);
615 ath10k_htt_rx_free_msdu_chain(skb->next); 660 hdr = (struct ieee80211_hdr *)hdr_buf;
616 skb->next = NULL;
617 return -ENOTSUPP;
618 }
619 661
620 /* A-MSDU max is a little less than 8K */ 662 /* FIXME: Hopefully this is a temporary measure.
621 amsdu = dev_alloc_skb(8*1024); 663 *
622 if (!amsdu) { 664 * Reporting individual A-MSDU subframes means each reported frame
623 ath10k_warn("A-MSDU allocation failed\n"); 665 * shares the same sequence number.
624 ath10k_htt_rx_free_msdu_chain(skb->next); 666 *
625 skb->next = NULL; 667 * mac80211 drops frames it recognizes as duplicates, i.e.
626 return -ENOMEM; 668 * retransmission flag is set and sequence number matches sequence
627 } 669 * number from a previous frame (as per IEEE 802.11-2012: 9.3.2.10
628 670 * "Duplicate detection and recovery")
629 if (fmt >= RX_MSDU_DECAP_NATIVE_WIFI) { 671 *
630 int hdrlen; 672 * To avoid frames being dropped clear retransmission flag for all
631 673 * received A-MSDUs.
632 hdr = (void *)rxd->rx_hdr_status; 674 *
633 hdrlen = ieee80211_hdrlen(hdr->frame_control); 675 * Worst case: actual duplicate frames will be reported but this should
634 memcpy(skb_put(amsdu, hdrlen), hdr, hdrlen); 676 * still be handled gracefully by other OSI/ISO layers. */
635 } 677 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_RETRY);
636 678
637 first = skb; 679 first = skb;
638 while (skb) { 680 while (skb) {
639 void *decap_hdr; 681 void *decap_hdr;
640 int decap_len = 0; 682 int len;
641 683
642 rxd = (void *)skb->data - sizeof(*rxd); 684 rxd = (void *)skb->data - sizeof(*rxd);
643 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1), 685 fmt = MS(__le32_to_cpu(rxd->msdu_start.info1),
644 RX_MSDU_START_INFO1_DECAP_FORMAT); 686 RX_MSDU_START_INFO1_DECAP_FORMAT);
645 decap_hdr = (void *)rxd->rx_hdr_status; 687 decap_hdr = (void *)rxd->rx_hdr_status;
646 688
647 if (skb == first) { 689 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
648 /* We receive linked A-MSDU subframe skbuffs. The
649 * first one contains the original 802.11 header (and
650 * possible crypto param) in the RX descriptor. The
651 * A-MSDU subframe header follows that. Each part is
652 * aligned to 4 byte boundary. */
653
654 hdr = (void *)amsdu->data;
655 hdr_len = ieee80211_hdrlen(hdr->frame_control);
656 crypto_len = ath10k_htt_rx_crypto_param_len(enctype);
657
658 decap_hdr += roundup(hdr_len, 4);
659 decap_hdr += roundup(crypto_len, 4);
660 }
661 690
662 if (fmt == RX_MSDU_DECAP_ETHERNET2_DIX) { 691 /* First frame in an A-MSDU chain has more decapped data. */
663 /* Ethernet2 decap inserts ethernet header in place of 692 if (skb == first) {
664 * A-MSDU subframe header. */ 693 len = round_up(ieee80211_hdrlen(hdr->frame_control), 4);
665 skb_pull(skb, 6 + 6 + 2); 694 len += round_up(ath10k_htt_rx_crypto_param_len(enctype),
666 695 4);
667 /* A-MSDU subframe header length */ 696 decap_hdr += len;
668 decap_len += 6 + 6 + 2;
669
670 /* Ethernet2 decap also strips the LLC/SNAP so we need
671 * to re-insert it. The LLC/SNAP follows A-MSDU
672 * subframe header. */
673 /* FIXME: Not all LLCs are 8 bytes long */
674 decap_len += 8;
675
676 memcpy(skb_put(amsdu, decap_len), decap_hdr, decap_len);
677 } 697 }
678 698
679 if (fmt == RX_MSDU_DECAP_NATIVE_WIFI) { 699 switch (fmt) {
680 /* Native Wifi decap inserts regular 802.11 header 700 case RX_MSDU_DECAP_RAW:
681 * in place of A-MSDU subframe header. */ 701 /* remove trailing FCS */
702 skb_trim(skb, skb->len - FCS_LEN);
703 break;
704 case RX_MSDU_DECAP_NATIVE_WIFI:
705 /* pull decapped header and copy DA */
682 hdr = (struct ieee80211_hdr *)skb->data; 706 hdr = (struct ieee80211_hdr *)skb->data;
683 skb_pull(skb, ieee80211_hdrlen(hdr->frame_control)); 707 hdr_len = ieee80211_hdrlen(hdr->frame_control);
708 memcpy(addr, ieee80211_get_DA(hdr), ETH_ALEN);
709 skb_pull(skb, hdr_len);
684 710
685 /* A-MSDU subframe header length */ 711 /* push original 802.11 header */
686 decap_len += 6 + 6 + 2; 712 hdr = (struct ieee80211_hdr *)hdr_buf;
713 hdr_len = ieee80211_hdrlen(hdr->frame_control);
714 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
687 715
688 memcpy(skb_put(amsdu, decap_len), decap_hdr, decap_len); 716 /* original A-MSDU header has the bit set but we're
689 } 717 * not including A-MSDU subframe header */
718 hdr = (struct ieee80211_hdr *)skb->data;
719 qos = ieee80211_get_qos_ctl(hdr);
720 qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
690 721
691 if (fmt == RX_MSDU_DECAP_RAW) 722 /* original 802.11 header has a different DA */
692 skb_trim(skb, skb->len - 4); /* remove FCS */ 723 memcpy(ieee80211_get_DA(hdr), addr, ETH_ALEN);
724 break;
725 case RX_MSDU_DECAP_ETHERNET2_DIX:
726 /* strip ethernet header and insert decapped 802.11
727 * header, amsdu subframe header and rfc1042 header */
693 728
694 memcpy(skb_put(amsdu, skb->len), skb->data, skb->len); 729 len = 0;
730 len += sizeof(struct rfc1042_hdr);
731 len += sizeof(struct amsdu_subframe_hdr);
695 732
696 /* A-MSDU subframes are padded to 4bytes 733 skb_pull(skb, sizeof(struct ethhdr));
697 * but relative to first subframe, not the whole MPDU */ 734 memcpy(skb_push(skb, len), decap_hdr, len);
698 if (skb->next && ((decap_len + skb->len) & 3)) { 735 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
699 int padlen = 4 - ((decap_len + skb->len) & 3); 736 break;
700 memset(skb_put(amsdu, padlen), 0, padlen); 737 case RX_MSDU_DECAP_8023_SNAP_LLC:
738 /* insert decapped 802.11 header making a singly
739 * A-MSDU */
740 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
741 break;
701 } 742 }
702 743
744 info->skb = skb;
745 info->encrypt_type = enctype;
703 skb = skb->next; 746 skb = skb->next;
704 } 747 info->skb->next = NULL;
705 748
706 info->skb = amsdu; 749 ath10k_process_rx(htt->ar, info);
707 info->encrypt_type = enctype; 750 }
708
709 ath10k_htt_rx_free_msdu_chain(first);
710 751
711 return 0; 752 /* FIXME: It might be nice to re-assemble the A-MSDU when there's a
753 * monitor interface active for sniffing purposes. */
712} 754}
713 755
714static int ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info) 756static void ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info)
715{ 757{
716 struct sk_buff *skb = info->skb; 758 struct sk_buff *skb = info->skb;
717 struct htt_rx_desc *rxd; 759 struct htt_rx_desc *rxd;
718 struct ieee80211_hdr *hdr; 760 struct ieee80211_hdr *hdr;
719 enum rx_msdu_decap_format fmt; 761 enum rx_msdu_decap_format fmt;
720 enum htt_rx_mpdu_encrypt_type enctype; 762 enum htt_rx_mpdu_encrypt_type enctype;
763 int hdr_len;
764 void *rfc1042;
721 765
722 /* This shouldn't happen. If it does than it may be a FW bug. */ 766 /* This shouldn't happen. If it does than it may be a FW bug. */
723 if (skb->next) { 767 if (skb->next) {
@@ -731,49 +775,53 @@ static int ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info)
731 RX_MSDU_START_INFO1_DECAP_FORMAT); 775 RX_MSDU_START_INFO1_DECAP_FORMAT);
732 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), 776 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
733 RX_MPDU_START_INFO0_ENCRYPT_TYPE); 777 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
734 hdr = (void *)skb->data - RX_HTT_HDR_STATUS_LEN; 778 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
779 hdr_len = ieee80211_hdrlen(hdr->frame_control);
780
781 skb->ip_summed = ath10k_htt_rx_get_csum_state(skb);
735 782
736 switch (fmt) { 783 switch (fmt) {
737 case RX_MSDU_DECAP_RAW: 784 case RX_MSDU_DECAP_RAW:
738 /* remove trailing FCS */ 785 /* remove trailing FCS */
739 skb_trim(skb, skb->len - 4); 786 skb_trim(skb, skb->len - FCS_LEN);
740 break; 787 break;
741 case RX_MSDU_DECAP_NATIVE_WIFI: 788 case RX_MSDU_DECAP_NATIVE_WIFI:
742 /* nothing to do here */ 789 /* Pull decapped header */
790 hdr = (struct ieee80211_hdr *)skb->data;
791 hdr_len = ieee80211_hdrlen(hdr->frame_control);
792 skb_pull(skb, hdr_len);
793
794 /* Push original header */
795 hdr = (struct ieee80211_hdr *)rxd->rx_hdr_status;
796 hdr_len = ieee80211_hdrlen(hdr->frame_control);
797 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
743 break; 798 break;
744 case RX_MSDU_DECAP_ETHERNET2_DIX: 799 case RX_MSDU_DECAP_ETHERNET2_DIX:
745 /* macaddr[6] + macaddr[6] + ethertype[2] */ 800 /* strip ethernet header and insert decapped 802.11 header and
746 skb_pull(skb, 6 + 6 + 2); 801 * rfc1042 header */
747 break;
748 case RX_MSDU_DECAP_8023_SNAP_LLC:
749 /* macaddr[6] + macaddr[6] + len[2] */
750 /* we don't need this for non-A-MSDU */
751 skb_pull(skb, 6 + 6 + 2);
752 break;
753 }
754 802
755 if (fmt == RX_MSDU_DECAP_ETHERNET2_DIX) { 803 rfc1042 = hdr;
756 void *llc; 804 rfc1042 += roundup(hdr_len, 4);
757 int llclen; 805 rfc1042 += roundup(ath10k_htt_rx_crypto_param_len(enctype), 4);
758 806
759 llclen = 8; 807 skb_pull(skb, sizeof(struct ethhdr));
760 llc = hdr; 808 memcpy(skb_push(skb, sizeof(struct rfc1042_hdr)),
761 llc += roundup(ieee80211_hdrlen(hdr->frame_control), 4); 809 rfc1042, sizeof(struct rfc1042_hdr));
762 llc += roundup(ath10k_htt_rx_crypto_param_len(enctype), 4); 810 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
763 811 break;
764 skb_push(skb, llclen); 812 case RX_MSDU_DECAP_8023_SNAP_LLC:
765 memcpy(skb->data, llc, llclen); 813 /* remove A-MSDU subframe header and insert
766 } 814 * decapped 802.11 header. rfc1042 header is already there */
767 815
768 if (fmt >= RX_MSDU_DECAP_ETHERNET2_DIX) { 816 skb_pull(skb, sizeof(struct amsdu_subframe_hdr));
769 int len = ieee80211_hdrlen(hdr->frame_control); 817 memcpy(skb_push(skb, hdr_len), hdr, hdr_len);
770 skb_push(skb, len); 818 break;
771 memcpy(skb->data, hdr, len);
772 } 819 }
773 820
774 info->skb = skb; 821 info->skb = skb;
775 info->encrypt_type = enctype; 822 info->encrypt_type = enctype;
776 return 0; 823
824 ath10k_process_rx(htt->ar, info);
777} 825}
778 826
779static bool ath10k_htt_rx_has_decrypt_err(struct sk_buff *skb) 827static bool ath10k_htt_rx_has_decrypt_err(struct sk_buff *skb)
@@ -845,8 +893,6 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
845 int fw_desc_len; 893 int fw_desc_len;
846 u8 *fw_desc; 894 u8 *fw_desc;
847 int i, j; 895 int i, j;
848 int ret;
849 int ip_summed;
850 896
851 memset(&info, 0, sizeof(info)); 897 memset(&info, 0, sizeof(info));
852 898
@@ -921,11 +967,6 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
921 continue; 967 continue;
922 } 968 }
923 969
924 /* The skb is not yet processed and it may be
925 * reallocated. Since the offload is in the original
926 * skb extract the checksum now and assign it later */
927 ip_summed = ath10k_htt_rx_get_csum_state(msdu_head);
928
929 info.skb = msdu_head; 970 info.skb = msdu_head;
930 info.fcs_err = ath10k_htt_rx_has_fcs_err(msdu_head); 971 info.fcs_err = ath10k_htt_rx_has_fcs_err(msdu_head);
931 info.signal = ATH10K_DEFAULT_NOISE_FLOOR; 972 info.signal = ATH10K_DEFAULT_NOISE_FLOOR;
@@ -938,28 +979,13 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
938 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head); 979 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head);
939 980
940 if (ath10k_htt_rx_hdr_is_amsdu(hdr)) 981 if (ath10k_htt_rx_hdr_is_amsdu(hdr))
941 ret = ath10k_htt_rx_amsdu(htt, &info); 982 ath10k_htt_rx_amsdu(htt, &info);
942 else 983 else
943 ret = ath10k_htt_rx_msdu(htt, &info); 984 ath10k_htt_rx_msdu(htt, &info);
944
945 if (ret && !info.fcs_err) {
946 ath10k_warn("error processing msdus %d\n", ret);
947 dev_kfree_skb_any(info.skb);
948 continue;
949 }
950
951 if (ath10k_htt_rx_hdr_is_amsdu((void *)info.skb->data))
952 ath10k_dbg(ATH10K_DBG_HTT, "htt mpdu is amsdu\n");
953
954 info.skb->ip_summed = ip_summed;
955
956 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt mpdu: ",
957 info.skb->data, info.skb->len);
958 ath10k_process_rx(htt->ar, &info);
959 } 985 }
960 } 986 }
961 987
962 ath10k_htt_rx_msdu_buff_replenish(htt); 988 tasklet_schedule(&htt->rx_replenish_task);
963} 989}
964 990
965static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt, 991static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
@@ -1131,7 +1157,7 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1131 break; 1157 break;
1132 } 1158 }
1133 1159
1134 ath10k_txrx_tx_completed(htt, &tx_done); 1160 ath10k_txrx_tx_unref(htt, &tx_done);
1135 break; 1161 break;
1136 } 1162 }
1137 case HTT_T2H_MSG_TYPE_TX_COMPL_IND: { 1163 case HTT_T2H_MSG_TYPE_TX_COMPL_IND: {
@@ -1165,7 +1191,7 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1165 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) { 1191 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1166 msdu_id = resp->data_tx_completion.msdus[i]; 1192 msdu_id = resp->data_tx_completion.msdus[i];
1167 tx_done.msdu_id = __le16_to_cpu(msdu_id); 1193 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1168 ath10k_txrx_tx_completed(htt, &tx_done); 1194 ath10k_txrx_tx_unref(htt, &tx_done);
1169 } 1195 }
1170 break; 1196 break;
1171 } 1197 }
@@ -1190,8 +1216,10 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1190 case HTT_T2H_MSG_TYPE_TEST: 1216 case HTT_T2H_MSG_TYPE_TEST:
1191 /* FIX THIS */ 1217 /* FIX THIS */
1192 break; 1218 break;
1193 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
1194 case HTT_T2H_MSG_TYPE_STATS_CONF: 1219 case HTT_T2H_MSG_TYPE_STATS_CONF:
1220 trace_ath10k_htt_stats(skb->data, skb->len);
1221 break;
1222 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
1195 case HTT_T2H_MSG_TYPE_RX_ADDBA: 1223 case HTT_T2H_MSG_TYPE_RX_ADDBA:
1196 case HTT_T2H_MSG_TYPE_RX_DELBA: 1224 case HTT_T2H_MSG_TYPE_RX_DELBA:
1197 case HTT_T2H_MSG_TYPE_RX_FLUSH: 1225 case HTT_T2H_MSG_TYPE_RX_FLUSH:
diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireless/ath/ath10k/htt_tx.c
index 656c2546b294..3b93c6a01c6c 100644
--- a/drivers/net/wireless/ath/ath10k/htt_tx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_tx.c
@@ -96,7 +96,7 @@ int ath10k_htt_tx_attach(struct ath10k_htt *htt)
96 htt->max_num_pending_tx = ath10k_hif_get_free_queue_number(htt->ar, 96 htt->max_num_pending_tx = ath10k_hif_get_free_queue_number(htt->ar,
97 pipe); 97 pipe);
98 98
99 ath10k_dbg(ATH10K_DBG_HTT, "htt tx max num pending tx %d\n", 99 ath10k_dbg(ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
100 htt->max_num_pending_tx); 100 htt->max_num_pending_tx);
101 101
102 htt->pending_tx = kzalloc(sizeof(*htt->pending_tx) * 102 htt->pending_tx = kzalloc(sizeof(*htt->pending_tx) *
@@ -117,7 +117,7 @@ int ath10k_htt_tx_attach(struct ath10k_htt *htt)
117 117
118static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt) 118static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt)
119{ 119{
120 struct sk_buff *txdesc; 120 struct htt_tx_done tx_done = {0};
121 int msdu_id; 121 int msdu_id;
122 122
123 /* No locks needed. Called after communication with the device has 123 /* No locks needed. Called after communication with the device has
@@ -127,18 +127,13 @@ static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt)
127 if (!test_bit(msdu_id, htt->used_msdu_ids)) 127 if (!test_bit(msdu_id, htt->used_msdu_ids))
128 continue; 128 continue;
129 129
130 txdesc = htt->pending_tx[msdu_id];
131 if (!txdesc)
132 continue;
133
134 ath10k_dbg(ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n", 130 ath10k_dbg(ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n",
135 msdu_id); 131 msdu_id);
136 132
137 if (ATH10K_SKB_CB(txdesc)->htt.refcount > 0) 133 tx_done.discard = 1;
138 ATH10K_SKB_CB(txdesc)->htt.refcount = 1; 134 tx_done.msdu_id = msdu_id;
139 135
140 ATH10K_SKB_CB(txdesc)->htt.discard = true; 136 ath10k_txrx_tx_unref(htt, &tx_done);
141 ath10k_txrx_tx_unref(htt, txdesc);
142 } 137 }
143} 138}
144 139
@@ -152,26 +147,7 @@ void ath10k_htt_tx_detach(struct ath10k_htt *htt)
152 147
153void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb) 148void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
154{ 149{
155 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb); 150 dev_kfree_skb_any(skb);
156 struct ath10k_htt *htt = &ar->htt;
157
158 if (skb_cb->htt.is_conf) {
159 dev_kfree_skb_any(skb);
160 return;
161 }
162
163 if (skb_cb->is_aborted) {
164 skb_cb->htt.discard = true;
165
166 /* if the skbuff is aborted we need to make sure we'll free up
167 * the tx resources, we can't simply run tx_unref() 2 times
168 * because if htt tx completion came in earlier we'd access
169 * unallocated memory */
170 if (skb_cb->htt.refcount > 1)
171 skb_cb->htt.refcount = 1;
172 }
173
174 ath10k_txrx_tx_unref(htt, skb);
175} 151}
176 152
177int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt) 153int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
@@ -192,10 +168,48 @@ int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
192 cmd = (struct htt_cmd *)skb->data; 168 cmd = (struct htt_cmd *)skb->data;
193 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ; 169 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;
194 170
195 ATH10K_SKB_CB(skb)->htt.is_conf = true; 171 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
172 if (ret) {
173 dev_kfree_skb_any(skb);
174 return ret;
175 }
176
177 return 0;
178}
179
180int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u8 mask, u64 cookie)
181{
182 struct htt_stats_req *req;
183 struct sk_buff *skb;
184 struct htt_cmd *cmd;
185 int len = 0, ret;
186
187 len += sizeof(cmd->hdr);
188 len += sizeof(cmd->stats_req);
189
190 skb = ath10k_htc_alloc_skb(len);
191 if (!skb)
192 return -ENOMEM;
193
194 skb_put(skb, len);
195 cmd = (struct htt_cmd *)skb->data;
196 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;
197
198 req = &cmd->stats_req;
199
200 memset(req, 0, sizeof(*req));
201
202 /* currently we support only max 8 bit masks so no need to worry
203 * about endian support */
204 req->upload_types[0] = mask;
205 req->reset_types[0] = mask;
206 req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
207 req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
208 req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);
196 209
197 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb); 210 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
198 if (ret) { 211 if (ret) {
212 ath10k_warn("failed to send htt type stats request: %d", ret);
199 dev_kfree_skb_any(skb); 213 dev_kfree_skb_any(skb);
200 return ret; 214 return ret;
201 } 215 }
@@ -279,8 +293,6 @@ int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt)
279 293
280#undef desc_offset 294#undef desc_offset
281 295
282 ATH10K_SKB_CB(skb)->htt.is_conf = true;
283
284 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb); 296 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
285 if (ret) { 297 if (ret) {
286 dev_kfree_skb_any(skb); 298 dev_kfree_skb_any(skb);
@@ -293,10 +305,10 @@ int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt)
293int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu) 305int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
294{ 306{
295 struct device *dev = htt->ar->dev; 307 struct device *dev = htt->ar->dev;
296 struct ath10k_skb_cb *skb_cb;
297 struct sk_buff *txdesc = NULL; 308 struct sk_buff *txdesc = NULL;
298 struct htt_cmd *cmd; 309 struct htt_cmd *cmd;
299 u8 vdev_id = ATH10K_SKB_CB(msdu)->htt.vdev_id; 310 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
311 u8 vdev_id = skb_cb->htt.vdev_id;
300 int len = 0; 312 int len = 0;
301 int msdu_id = -1; 313 int msdu_id = -1;
302 int res; 314 int res;
@@ -304,30 +316,30 @@ int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
304 316
305 res = ath10k_htt_tx_inc_pending(htt); 317 res = ath10k_htt_tx_inc_pending(htt);
306 if (res) 318 if (res)
307 return res; 319 goto err;
308 320
309 len += sizeof(cmd->hdr); 321 len += sizeof(cmd->hdr);
310 len += sizeof(cmd->mgmt_tx); 322 len += sizeof(cmd->mgmt_tx);
311 323
312 txdesc = ath10k_htc_alloc_skb(len);
313 if (!txdesc) {
314 res = -ENOMEM;
315 goto err;
316 }
317
318 spin_lock_bh(&htt->tx_lock); 324 spin_lock_bh(&htt->tx_lock);
319 msdu_id = ath10k_htt_tx_alloc_msdu_id(htt); 325 res = ath10k_htt_tx_alloc_msdu_id(htt);
320 if (msdu_id < 0) { 326 if (res < 0) {
321 spin_unlock_bh(&htt->tx_lock); 327 spin_unlock_bh(&htt->tx_lock);
322 res = msdu_id; 328 goto err_tx_dec;
323 goto err;
324 } 329 }
325 htt->pending_tx[msdu_id] = txdesc; 330 msdu_id = res;
331 htt->pending_tx[msdu_id] = msdu;
326 spin_unlock_bh(&htt->tx_lock); 332 spin_unlock_bh(&htt->tx_lock);
327 333
334 txdesc = ath10k_htc_alloc_skb(len);
335 if (!txdesc) {
336 res = -ENOMEM;
337 goto err_free_msdu_id;
338 }
339
328 res = ath10k_skb_map(dev, msdu); 340 res = ath10k_skb_map(dev, msdu);
329 if (res) 341 if (res)
330 goto err; 342 goto err_free_txdesc;
331 343
332 skb_put(txdesc, len); 344 skb_put(txdesc, len);
333 cmd = (struct htt_cmd *)txdesc->data; 345 cmd = (struct htt_cmd *)txdesc->data;
@@ -339,31 +351,27 @@ int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
339 memcpy(cmd->mgmt_tx.hdr, msdu->data, 351 memcpy(cmd->mgmt_tx.hdr, msdu->data,
340 min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN)); 352 min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
341 353
342 /* refcount is decremented by HTC and HTT completions until it reaches 354 skb_cb->htt.frag_len = 0;
343 * zero and is freed */ 355 skb_cb->htt.pad_len = 0;
344 skb_cb = ATH10K_SKB_CB(txdesc);
345 skb_cb->htt.msdu_id = msdu_id;
346 skb_cb->htt.refcount = 2;
347 skb_cb->htt.msdu = msdu;
348 356
349 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc); 357 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
350 if (res) 358 if (res)
351 goto err; 359 goto err_unmap_msdu;
352 360
353 return 0; 361 return 0;
354 362
355err: 363err_unmap_msdu:
356 ath10k_skb_unmap(dev, msdu); 364 ath10k_skb_unmap(dev, msdu);
357 365err_free_txdesc:
358 if (txdesc) 366 dev_kfree_skb_any(txdesc);
359 dev_kfree_skb_any(txdesc); 367err_free_msdu_id:
360 if (msdu_id >= 0) { 368 spin_lock_bh(&htt->tx_lock);
361 spin_lock_bh(&htt->tx_lock); 369 htt->pending_tx[msdu_id] = NULL;
362 htt->pending_tx[msdu_id] = NULL; 370 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
363 ath10k_htt_tx_free_msdu_id(htt, msdu_id); 371 spin_unlock_bh(&htt->tx_lock);
364 spin_unlock_bh(&htt->tx_lock); 372err_tx_dec:
365 }
366 ath10k_htt_tx_dec_pending(htt); 373 ath10k_htt_tx_dec_pending(htt);
374err:
367 return res; 375 return res;
368} 376}
369 377
@@ -373,13 +381,12 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
373 struct htt_cmd *cmd; 381 struct htt_cmd *cmd;
374 struct htt_data_tx_desc_frag *tx_frags; 382 struct htt_data_tx_desc_frag *tx_frags;
375 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data; 383 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
376 struct ath10k_skb_cb *skb_cb; 384 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
377 struct sk_buff *txdesc = NULL; 385 struct sk_buff *txdesc = NULL;
378 struct sk_buff *txfrag = NULL; 386 bool use_frags;
379 u8 vdev_id = ATH10K_SKB_CB(msdu)->htt.vdev_id; 387 u8 vdev_id = ATH10K_SKB_CB(msdu)->htt.vdev_id;
380 u8 tid; 388 u8 tid;
381 int prefetch_len, desc_len, frag_len; 389 int prefetch_len, desc_len;
382 dma_addr_t frags_paddr;
383 int msdu_id = -1; 390 int msdu_id = -1;
384 int res; 391 int res;
385 u8 flags0; 392 u8 flags0;
@@ -387,69 +394,82 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
387 394
388 res = ath10k_htt_tx_inc_pending(htt); 395 res = ath10k_htt_tx_inc_pending(htt);
389 if (res) 396 if (res)
390 return res; 397 goto err;
398
399 spin_lock_bh(&htt->tx_lock);
400 res = ath10k_htt_tx_alloc_msdu_id(htt);
401 if (res < 0) {
402 spin_unlock_bh(&htt->tx_lock);
403 goto err_tx_dec;
404 }
405 msdu_id = res;
406 htt->pending_tx[msdu_id] = msdu;
407 spin_unlock_bh(&htt->tx_lock);
391 408
392 prefetch_len = min(htt->prefetch_len, msdu->len); 409 prefetch_len = min(htt->prefetch_len, msdu->len);
393 prefetch_len = roundup(prefetch_len, 4); 410 prefetch_len = roundup(prefetch_len, 4);
394 411
395 desc_len = sizeof(cmd->hdr) + sizeof(cmd->data_tx) + prefetch_len; 412 desc_len = sizeof(cmd->hdr) + sizeof(cmd->data_tx) + prefetch_len;
396 frag_len = sizeof(*tx_frags) * 2;
397 413
398 txdesc = ath10k_htc_alloc_skb(desc_len); 414 txdesc = ath10k_htc_alloc_skb(desc_len);
399 if (!txdesc) { 415 if (!txdesc) {
400 res = -ENOMEM; 416 res = -ENOMEM;
401 goto err; 417 goto err_free_msdu_id;
402 } 418 }
403 419
404 txfrag = dev_alloc_skb(frag_len); 420 /* Since HTT 3.0 there is no separate mgmt tx command. However in case
405 if (!txfrag) { 421 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
406 res = -ENOMEM; 422 * fragment list host driver specifies directly frame pointer. */
407 goto err; 423 use_frags = htt->target_version_major < 3 ||
408 } 424 !ieee80211_is_mgmt(hdr->frame_control);
409 425
410 if (!IS_ALIGNED((unsigned long)txdesc->data, 4)) { 426 if (!IS_ALIGNED((unsigned long)txdesc->data, 4)) {
411 ath10k_warn("htt alignment check failed. dropping packet.\n"); 427 ath10k_warn("htt alignment check failed. dropping packet.\n");
412 res = -EIO; 428 res = -EIO;
413 goto err; 429 goto err_free_txdesc;
414 } 430 }
415 431
416 spin_lock_bh(&htt->tx_lock); 432 if (use_frags) {
417 msdu_id = ath10k_htt_tx_alloc_msdu_id(htt); 433 skb_cb->htt.frag_len = sizeof(*tx_frags) * 2;
418 if (msdu_id < 0) { 434 skb_cb->htt.pad_len = (unsigned long)msdu->data -
419 spin_unlock_bh(&htt->tx_lock); 435 round_down((unsigned long)msdu->data, 4);
420 res = msdu_id; 436
421 goto err; 437 skb_push(msdu, skb_cb->htt.frag_len + skb_cb->htt.pad_len);
438 } else {
439 skb_cb->htt.frag_len = 0;
440 skb_cb->htt.pad_len = 0;
422 } 441 }
423 htt->pending_tx[msdu_id] = txdesc;
424 spin_unlock_bh(&htt->tx_lock);
425 442
426 res = ath10k_skb_map(dev, msdu); 443 res = ath10k_skb_map(dev, msdu);
427 if (res) 444 if (res)
428 goto err; 445 goto err_pull_txfrag;
429 446
430 /* tx fragment list must be terminated with zero-entry */ 447 if (use_frags) {
431 skb_put(txfrag, frag_len); 448 dma_sync_single_for_cpu(dev, skb_cb->paddr, msdu->len,
432 tx_frags = (struct htt_data_tx_desc_frag *)txfrag->data; 449 DMA_TO_DEVICE);
433 tx_frags[0].paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr); 450
434 tx_frags[0].len = __cpu_to_le32(msdu->len); 451 /* tx fragment list must be terminated with zero-entry */
435 tx_frags[1].paddr = __cpu_to_le32(0); 452 tx_frags = (struct htt_data_tx_desc_frag *)msdu->data;
436 tx_frags[1].len = __cpu_to_le32(0); 453 tx_frags[0].paddr = __cpu_to_le32(skb_cb->paddr +
437 454 skb_cb->htt.frag_len +
438 res = ath10k_skb_map(dev, txfrag); 455 skb_cb->htt.pad_len);
439 if (res) 456 tx_frags[0].len = __cpu_to_le32(msdu->len -
440 goto err; 457 skb_cb->htt.frag_len -
458 skb_cb->htt.pad_len);
459 tx_frags[1].paddr = __cpu_to_le32(0);
460 tx_frags[1].len = __cpu_to_le32(0);
461
462 dma_sync_single_for_device(dev, skb_cb->paddr, msdu->len,
463 DMA_TO_DEVICE);
464 }
441 465
442 ath10k_dbg(ATH10K_DBG_HTT, "txfrag 0x%llx msdu 0x%llx\n", 466 ath10k_dbg(ATH10K_DBG_HTT, "msdu 0x%llx\n",
443 (unsigned long long) ATH10K_SKB_CB(txfrag)->paddr,
444 (unsigned long long) ATH10K_SKB_CB(msdu)->paddr); 467 (unsigned long long) ATH10K_SKB_CB(msdu)->paddr);
445 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "txfrag: ",
446 txfrag->data, frag_len);
447 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "msdu: ", 468 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "msdu: ",
448 msdu->data, msdu->len); 469 msdu->data, msdu->len);
449 470
450 skb_put(txdesc, desc_len); 471 skb_put(txdesc, desc_len);
451 cmd = (struct htt_cmd *)txdesc->data; 472 cmd = (struct htt_cmd *)txdesc->data;
452 memset(cmd, 0, desc_len);
453 473
454 tid = ATH10K_SKB_CB(msdu)->htt.tid; 474 tid = ATH10K_SKB_CB(msdu)->htt.tid;
455 475
@@ -459,8 +479,13 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
459 if (!ieee80211_has_protected(hdr->frame_control)) 479 if (!ieee80211_has_protected(hdr->frame_control))
460 flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT; 480 flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
461 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT; 481 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
462 flags0 |= SM(ATH10K_HW_TXRX_NATIVE_WIFI, 482
463 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE); 483 if (use_frags)
484 flags0 |= SM(ATH10K_HW_TXRX_NATIVE_WIFI,
485 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
486 else
487 flags0 |= SM(ATH10K_HW_TXRX_MGMT,
488 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
464 489
465 flags1 = 0; 490 flags1 = 0;
466 flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID); 491 flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
@@ -468,45 +493,37 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
468 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD; 493 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
469 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD; 494 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
470 495
471 frags_paddr = ATH10K_SKB_CB(txfrag)->paddr;
472
473 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM; 496 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
474 cmd->data_tx.flags0 = flags0; 497 cmd->data_tx.flags0 = flags0;
475 cmd->data_tx.flags1 = __cpu_to_le16(flags1); 498 cmd->data_tx.flags1 = __cpu_to_le16(flags1);
476 cmd->data_tx.len = __cpu_to_le16(msdu->len); 499 cmd->data_tx.len = __cpu_to_le16(msdu->len -
500 skb_cb->htt.frag_len -
501 skb_cb->htt.pad_len);
477 cmd->data_tx.id = __cpu_to_le16(msdu_id); 502 cmd->data_tx.id = __cpu_to_le16(msdu_id);
478 cmd->data_tx.frags_paddr = __cpu_to_le32(frags_paddr); 503 cmd->data_tx.frags_paddr = __cpu_to_le32(skb_cb->paddr);
479 cmd->data_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID); 504 cmd->data_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID);
480 505
481 memcpy(cmd->data_tx.prefetch, msdu->data, prefetch_len); 506 memcpy(cmd->data_tx.prefetch, hdr, prefetch_len);
482
483 /* refcount is decremented by HTC and HTT completions until it reaches
484 * zero and is freed */
485 skb_cb = ATH10K_SKB_CB(txdesc);
486 skb_cb->htt.msdu_id = msdu_id;
487 skb_cb->htt.refcount = 2;
488 skb_cb->htt.txfrag = txfrag;
489 skb_cb->htt.msdu = msdu;
490 507
491 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc); 508 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
492 if (res) 509 if (res)
493 goto err; 510 goto err_unmap_msdu;
494 511
495 return 0; 512 return 0;
496err: 513
497 if (txfrag) 514err_unmap_msdu:
498 ath10k_skb_unmap(dev, txfrag);
499 if (txdesc)
500 dev_kfree_skb_any(txdesc);
501 if (txfrag)
502 dev_kfree_skb_any(txfrag);
503 if (msdu_id >= 0) {
504 spin_lock_bh(&htt->tx_lock);
505 htt->pending_tx[msdu_id] = NULL;
506 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
507 spin_unlock_bh(&htt->tx_lock);
508 }
509 ath10k_htt_tx_dec_pending(htt);
510 ath10k_skb_unmap(dev, msdu); 515 ath10k_skb_unmap(dev, msdu);
516err_pull_txfrag:
517 skb_pull(msdu, skb_cb->htt.frag_len + skb_cb->htt.pad_len);
518err_free_txdesc:
519 dev_kfree_skb_any(txdesc);
520err_free_msdu_id:
521 spin_lock_bh(&htt->tx_lock);
522 htt->pending_tx[msdu_id] = NULL;
523 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
524 spin_unlock_bh(&htt->tx_lock);
525err_tx_dec:
526 ath10k_htt_tx_dec_pending(htt);
527err:
511 return res; 528 return res;
512} 529}
diff --git a/drivers/net/wireless/ath/ath10k/hw.h b/drivers/net/wireless/ath/ath10k/hw.h
index 44ed5af0a204..8c1be7685922 100644
--- a/drivers/net/wireless/ath/ath10k/hw.h
+++ b/drivers/net/wireless/ath/ath10k/hw.h
@@ -24,18 +24,14 @@
24#define SUPPORTED_FW_MAJOR 1 24#define SUPPORTED_FW_MAJOR 1
25#define SUPPORTED_FW_MINOR 0 25#define SUPPORTED_FW_MINOR 0
26#define SUPPORTED_FW_RELEASE 0 26#define SUPPORTED_FW_RELEASE 0
27#define SUPPORTED_FW_BUILD 629 27#define SUPPORTED_FW_BUILD 636
28 28
29/* QCA988X 1.0 definitions */ 29/* QCA988X 1.0 definitions (unsupported) */
30#define QCA988X_HW_1_0_VERSION 0x4000002c 30#define QCA988X_HW_1_0_CHIP_ID_REV 0x0
31#define QCA988X_HW_1_0_FW_DIR "ath10k/QCA988X/hw1.0"
32#define QCA988X_HW_1_0_FW_FILE "firmware.bin"
33#define QCA988X_HW_1_0_OTP_FILE "otp.bin"
34#define QCA988X_HW_1_0_BOARD_DATA_FILE "board.bin"
35#define QCA988X_HW_1_0_PATCH_LOAD_ADDR 0x1234
36 31
37/* QCA988X 2.0 definitions */ 32/* QCA988X 2.0 definitions */
38#define QCA988X_HW_2_0_VERSION 0x4100016c 33#define QCA988X_HW_2_0_VERSION 0x4100016c
34#define QCA988X_HW_2_0_CHIP_ID_REV 0x2
39#define QCA988X_HW_2_0_FW_DIR "ath10k/QCA988X/hw2.0" 35#define QCA988X_HW_2_0_FW_DIR "ath10k/QCA988X/hw2.0"
40#define QCA988X_HW_2_0_FW_FILE "firmware.bin" 36#define QCA988X_HW_2_0_FW_FILE "firmware.bin"
41#define QCA988X_HW_2_0_OTP_FILE "otp.bin" 37#define QCA988X_HW_2_0_OTP_FILE "otp.bin"
@@ -53,6 +49,9 @@ enum ath10k_hw_txrx_mode {
53 ATH10K_HW_TXRX_RAW = 0, 49 ATH10K_HW_TXRX_RAW = 0,
54 ATH10K_HW_TXRX_NATIVE_WIFI = 1, 50 ATH10K_HW_TXRX_NATIVE_WIFI = 1,
55 ATH10K_HW_TXRX_ETHERNET = 2, 51 ATH10K_HW_TXRX_ETHERNET = 2,
52
53 /* Valid for HTT >= 3.0. Used for management frames in TX_FRM. */
54 ATH10K_HW_TXRX_MGMT = 3,
56}; 55};
57 56
58enum ath10k_mcast2ucast_mode { 57enum ath10k_mcast2ucast_mode {
@@ -75,7 +74,11 @@ enum ath10k_mcast2ucast_mode {
75#define TARGET_RX_CHAIN_MASK (BIT(0) | BIT(1) | BIT(2)) 74#define TARGET_RX_CHAIN_MASK (BIT(0) | BIT(1) | BIT(2))
76#define TARGET_RX_TIMEOUT_LO_PRI 100 75#define TARGET_RX_TIMEOUT_LO_PRI 100
77#define TARGET_RX_TIMEOUT_HI_PRI 40 76#define TARGET_RX_TIMEOUT_HI_PRI 40
78#define TARGET_RX_DECAP_MODE ATH10K_HW_TXRX_ETHERNET 77
78/* Native Wifi decap mode is used to align IP frames to 4-byte boundaries and
79 * avoid a very expensive re-alignment in mac80211. */
80#define TARGET_RX_DECAP_MODE ATH10K_HW_TXRX_NATIVE_WIFI
81
79#define TARGET_SCAN_MAX_PENDING_REQS 4 82#define TARGET_SCAN_MAX_PENDING_REQS 4
80#define TARGET_BMISS_OFFLOAD_MAX_VDEV 3 83#define TARGET_BMISS_OFFLOAD_MAX_VDEV 3
81#define TARGET_ROAM_OFFLOAD_MAX_VDEV 3 84#define TARGET_ROAM_OFFLOAD_MAX_VDEV 3
@@ -169,6 +172,10 @@ enum ath10k_mcast2ucast_mode {
169#define SOC_LPO_CAL_ENABLE_LSB 20 172#define SOC_LPO_CAL_ENABLE_LSB 20
170#define SOC_LPO_CAL_ENABLE_MASK 0x00100000 173#define SOC_LPO_CAL_ENABLE_MASK 0x00100000
171 174
175#define SOC_CHIP_ID_ADDRESS 0x000000ec
176#define SOC_CHIP_ID_REV_LSB 8
177#define SOC_CHIP_ID_REV_MASK 0x00000f00
178
172#define WLAN_RESET_CONTROL_COLD_RST_MASK 0x00000008 179#define WLAN_RESET_CONTROL_COLD_RST_MASK 0x00000008
173#define WLAN_RESET_CONTROL_WARM_RST_MASK 0x00000004 180#define WLAN_RESET_CONTROL_WARM_RST_MASK 0x00000004
174#define WLAN_SYSTEM_SLEEP_DISABLE_LSB 0 181#define WLAN_SYSTEM_SLEEP_DISABLE_LSB 0
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index cf2ba4d850c9..99a9bad3f398 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -460,6 +460,11 @@ static int ath10k_vdev_start(struct ath10k_vif *arvif)
460 arg.ssid_len = arvif->vif->bss_conf.ssid_len; 460 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
461 } 461 }
462 462
463 ath10k_dbg(ATH10K_DBG_MAC,
464 "mac vdev %d start center_freq %d phymode %s\n",
465 arg.vdev_id, arg.channel.freq,
466 ath10k_wmi_phymode_str(arg.channel.mode));
467
463 ret = ath10k_wmi_vdev_start(ar, &arg); 468 ret = ath10k_wmi_vdev_start(ar, &arg);
464 if (ret) { 469 if (ret) {
465 ath10k_warn("WMI vdev start failed: ret %d\n", ret); 470 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
@@ -503,13 +508,10 @@ static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
503{ 508{
504 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan; 509 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
505 struct wmi_vdev_start_request_arg arg = {}; 510 struct wmi_vdev_start_request_arg arg = {};
506 enum nl80211_channel_type type;
507 int ret = 0; 511 int ret = 0;
508 512
509 lockdep_assert_held(&ar->conf_mutex); 513 lockdep_assert_held(&ar->conf_mutex);
510 514
511 type = cfg80211_get_chandef_type(&ar->hw->conf.chandef);
512
513 arg.vdev_id = vdev_id; 515 arg.vdev_id = vdev_id;
514 arg.channel.freq = channel->center_freq; 516 arg.channel.freq = channel->center_freq;
515 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1; 517 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
@@ -607,7 +609,7 @@ static int ath10k_monitor_create(struct ath10k *ar)
607 goto vdev_fail; 609 goto vdev_fail;
608 } 610 }
609 611
610 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface created, vdev id: %d\n", 612 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
611 ar->monitor_vdev_id); 613 ar->monitor_vdev_id);
612 614
613 ar->monitor_present = true; 615 ar->monitor_present = true;
@@ -639,7 +641,7 @@ static int ath10k_monitor_destroy(struct ath10k *ar)
639 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id); 641 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
640 ar->monitor_present = false; 642 ar->monitor_present = false;
641 643
642 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface destroyed, vdev id: %d\n", 644 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
643 ar->monitor_vdev_id); 645 ar->monitor_vdev_id);
644 return ret; 646 return ret;
645} 647}
@@ -668,7 +670,7 @@ static void ath10k_control_beaconing(struct ath10k_vif *arvif,
668 arvif->vdev_id); 670 arvif->vdev_id);
669 return; 671 return;
670 } 672 }
671 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d up\n", arvif->vdev_id); 673 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
672} 674}
673 675
674static void ath10k_control_ibss(struct ath10k_vif *arvif, 676static void ath10k_control_ibss(struct ath10k_vif *arvif,
@@ -752,14 +754,14 @@ static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
752 psmode = WMI_STA_PS_MODE_DISABLED; 754 psmode = WMI_STA_PS_MODE_DISABLED;
753 } 755 }
754 756
757 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
758 arvif->vdev_id, psmode ? "enable" : "disable");
759
755 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id, 760 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
756 psmode); 761 psmode);
757 if (ar_iter->ret) 762 if (ar_iter->ret)
758 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n", 763 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
759 psmode, arvif->vdev_id); 764 psmode, arvif->vdev_id);
760 else
761 ath10k_dbg(ATH10K_DBG_MAC, "Set PS Mode: %d for VDEV: %d\n",
762 psmode, arvif->vdev_id);
763} 765}
764 766
765/**********************/ 767/**********************/
@@ -949,7 +951,8 @@ static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
949 arg->peer_ht_rates.num_rates = n; 951 arg->peer_ht_rates.num_rates = n;
950 arg->peer_num_spatial_streams = max((n+7) / 8, 1); 952 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
951 953
952 ath10k_dbg(ATH10K_DBG_MAC, "mcs cnt %d nss %d\n", 954 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
955 arg->addr,
953 arg->peer_ht_rates.num_rates, 956 arg->peer_ht_rates.num_rates,
954 arg->peer_num_spatial_streams); 957 arg->peer_num_spatial_streams);
955} 958}
@@ -969,11 +972,11 @@ static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
969 arg->peer_flags |= WMI_PEER_QOS; 972 arg->peer_flags |= WMI_PEER_QOS;
970 973
971 if (sta->wme && sta->uapsd_queues) { 974 if (sta->wme && sta->uapsd_queues) {
972 ath10k_dbg(ATH10K_DBG_MAC, "uapsd_queues: 0x%X, max_sp: %d\n", 975 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
973 sta->uapsd_queues, sta->max_sp); 976 sta->uapsd_queues, sta->max_sp);
974 977
975 arg->peer_flags |= WMI_PEER_APSD; 978 arg->peer_flags |= WMI_PEER_APSD;
976 arg->peer_flags |= WMI_RC_UAPSD_FLAG; 979 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
977 980
978 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) 981 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
979 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | 982 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
@@ -1048,7 +1051,8 @@ static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1048 arg->peer_vht_rates.tx_mcs_set = 1051 arg->peer_vht_rates.tx_mcs_set =
1049 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); 1052 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1050 1053
1051 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer\n"); 1054 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1055 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1052} 1056}
1053 1057
1054static void ath10k_peer_assoc_h_qos(struct ath10k *ar, 1058static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
@@ -1076,8 +1080,6 @@ static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1076{ 1080{
1077 enum wmi_phy_mode phymode = MODE_UNKNOWN; 1081 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1078 1082
1079 /* FIXME: add VHT */
1080
1081 switch (ar->hw->conf.chandef.chan->band) { 1083 switch (ar->hw->conf.chandef.chan->band) {
1082 case IEEE80211_BAND_2GHZ: 1084 case IEEE80211_BAND_2GHZ:
1083 if (sta->ht_cap.ht_supported) { 1085 if (sta->ht_cap.ht_supported) {
@@ -1091,7 +1093,17 @@ static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1091 1093
1092 break; 1094 break;
1093 case IEEE80211_BAND_5GHZ: 1095 case IEEE80211_BAND_5GHZ:
1094 if (sta->ht_cap.ht_supported) { 1096 /*
1097 * Check VHT first.
1098 */
1099 if (sta->vht_cap.vht_supported) {
1100 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1101 phymode = MODE_11AC_VHT80;
1102 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1103 phymode = MODE_11AC_VHT40;
1104 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1105 phymode = MODE_11AC_VHT20;
1106 } else if (sta->ht_cap.ht_supported) {
1095 if (sta->bandwidth == IEEE80211_STA_RX_BW_40) 1107 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1096 phymode = MODE_11NA_HT40; 1108 phymode = MODE_11NA_HT40;
1097 else 1109 else
@@ -1105,6 +1117,9 @@ static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1105 break; 1117 break;
1106 } 1118 }
1107 1119
1120 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1121 sta->addr, ath10k_wmi_phymode_str(phymode));
1122
1108 arg->peer_phymode = phymode; 1123 arg->peer_phymode = phymode;
1109 WARN_ON(phymode == MODE_UNKNOWN); 1124 WARN_ON(phymode == MODE_UNKNOWN);
1110} 1125}
@@ -1162,15 +1177,15 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1162 1177
1163 rcu_read_unlock(); 1178 rcu_read_unlock();
1164 1179
1180 ath10k_dbg(ATH10K_DBG_MAC,
1181 "mac vdev %d up (associated) bssid %pM aid %d\n",
1182 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1183
1165 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid, 1184 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1166 bss_conf->bssid); 1185 bss_conf->bssid);
1167 if (ret) 1186 if (ret)
1168 ath10k_warn("VDEV: %d up failed: ret %d\n", 1187 ath10k_warn("VDEV: %d up failed: ret %d\n",
1169 arvif->vdev_id, ret); 1188 arvif->vdev_id, ret);
1170 else
1171 ath10k_dbg(ATH10K_DBG_MAC,
1172 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1173 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1174} 1189}
1175 1190
1176/* 1191/*
@@ -1191,10 +1206,11 @@ static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1191 * No idea why this happens, even though VDEV-DOWN is supposed 1206 * No idea why this happens, even though VDEV-DOWN is supposed
1192 * to be analogous to link down, so just stop the VDEV. 1207 * to be analogous to link down, so just stop the VDEV.
1193 */ 1208 */
1209 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1210 arvif->vdev_id);
1211
1212 /* FIXME: check return value */
1194 ret = ath10k_vdev_stop(arvif); 1213 ret = ath10k_vdev_stop(arvif);
1195 if (!ret)
1196 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d stopped\n",
1197 arvif->vdev_id);
1198 1214
1199 /* 1215 /*
1200 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and 1216 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
@@ -1203,12 +1219,10 @@ static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1203 * interfaces as it expects there is no rx when no interface is 1219 * interfaces as it expects there is no rx when no interface is
1204 * running. 1220 * running.
1205 */ 1221 */
1206 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); 1222 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1207 if (ret)
1208 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1209 arvif->vdev_id, ret);
1210 1223
1211 ath10k_wmi_flush_tx(ar); 1224 /* FIXME: why don't we print error if wmi call fails? */
1225 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1212 1226
1213 arvif->def_wep_key_index = 0; 1227 arvif->def_wep_key_index = 0;
1214} 1228}
@@ -1333,8 +1347,8 @@ static int ath10k_update_channel_list(struct ath10k *ar)
1333 continue; 1347 continue;
1334 1348
1335 ath10k_dbg(ATH10K_DBG_WMI, 1349 ath10k_dbg(ATH10K_DBG_WMI,
1336 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", 1350 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1337 __func__, ch - arg.channels, arg.n_channels, 1351 ch - arg.channels, arg.n_channels,
1338 ch->freq, ch->max_power, ch->max_reg_power, 1352 ch->freq, ch->max_power, ch->max_reg_power,
1339 ch->max_antenna_gain, ch->mode); 1353 ch->max_antenna_gain, ch->mode);
1340 1354
@@ -1421,10 +1435,6 @@ static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1421 struct ieee80211_key_conf *key = info->control.hw_key; 1435 struct ieee80211_key_conf *key = info->control.hw_key;
1422 int ret; 1436 int ret;
1423 1437
1424 /* TODO AP mode should be implemented */
1425 if (vif->type != NL80211_IFTYPE_STATION)
1426 return;
1427
1428 if (!ieee80211_has_protected(hdr->frame_control)) 1438 if (!ieee80211_has_protected(hdr->frame_control))
1429 return; 1439 return;
1430 1440
@@ -1438,7 +1448,8 @@ static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1438 if (key->keyidx == arvif->def_wep_key_index) 1448 if (key->keyidx == arvif->def_wep_key_index)
1439 return; 1449 return;
1440 1450
1441 ath10k_dbg(ATH10K_DBG_MAC, "new wep keyidx will be %d\n", key->keyidx); 1451 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d keyidx %d\n",
1452 arvif->vdev_id, key->keyidx);
1442 1453
1443 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 1454 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1444 WMI_VDEV_PARAM_DEF_KEYID, 1455 WMI_VDEV_PARAM_DEF_KEYID,
@@ -1480,6 +1491,12 @@ static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1480 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1491 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1481 int ret; 1492 int ret;
1482 1493
1494 if (ar->htt.target_version_major >= 3) {
1495 /* Since HTT 3.0 there is no separate mgmt tx command */
1496 ret = ath10k_htt_tx(&ar->htt, skb);
1497 goto exit;
1498 }
1499
1483 if (ieee80211_is_mgmt(hdr->frame_control)) 1500 if (ieee80211_is_mgmt(hdr->frame_control))
1484 ret = ath10k_htt_mgmt_tx(&ar->htt, skb); 1501 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1485 else if (ieee80211_is_nullfunc(hdr->frame_control)) 1502 else if (ieee80211_is_nullfunc(hdr->frame_control))
@@ -1491,6 +1508,7 @@ static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1491 else 1508 else
1492 ret = ath10k_htt_tx(&ar->htt, skb); 1509 ret = ath10k_htt_tx(&ar->htt, skb);
1493 1510
1511exit:
1494 if (ret) { 1512 if (ret) {
1495 ath10k_warn("tx failed (%d). dropping packet.\n", ret); 1513 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1496 ieee80211_free_txskb(ar->hw, skb); 1514 ieee80211_free_txskb(ar->hw, skb);
@@ -1534,7 +1552,7 @@ void ath10k_offchan_tx_work(struct work_struct *work)
1534 1552
1535 mutex_lock(&ar->conf_mutex); 1553 mutex_lock(&ar->conf_mutex);
1536 1554
1537 ath10k_dbg(ATH10K_DBG_MAC, "processing offchannel skb %p\n", 1555 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
1538 skb); 1556 skb);
1539 1557
1540 hdr = (struct ieee80211_hdr *)skb->data; 1558 hdr = (struct ieee80211_hdr *)skb->data;
@@ -1546,6 +1564,7 @@ void ath10k_offchan_tx_work(struct work_struct *work)
1546 spin_unlock_bh(&ar->data_lock); 1564 spin_unlock_bh(&ar->data_lock);
1547 1565
1548 if (peer) 1566 if (peer)
1567 /* FIXME: should this use ath10k_warn()? */
1549 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n", 1568 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1550 peer_addr, vdev_id); 1569 peer_addr, vdev_id);
1551 1570
@@ -1643,8 +1662,6 @@ static int ath10k_abort_scan(struct ath10k *ar)
1643 return -EIO; 1662 return -EIO;
1644 } 1663 }
1645 1664
1646 ath10k_wmi_flush_tx(ar);
1647
1648 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); 1665 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1649 if (ret == 0) 1666 if (ret == 0)
1650 ath10k_warn("timed out while waiting for scan to stop\n"); 1667 ath10k_warn("timed out while waiting for scan to stop\n");
@@ -1678,10 +1695,6 @@ static int ath10k_start_scan(struct ath10k *ar,
1678 if (ret) 1695 if (ret)
1679 return ret; 1696 return ret;
1680 1697
1681 /* make sure we submit the command so the completion
1682 * timeout makes sense */
1683 ath10k_wmi_flush_tx(ar);
1684
1685 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); 1698 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1686 if (ret == 0) { 1699 if (ret == 0) {
1687 ath10k_abort_scan(ar); 1700 ath10k_abort_scan(ar);
@@ -1727,8 +1740,10 @@ static void ath10k_tx(struct ieee80211_hw *hw,
1727 /* we must calculate tid before we apply qos workaround 1740 /* we must calculate tid before we apply qos workaround
1728 * as we'd lose the qos control field */ 1741 * as we'd lose the qos control field */
1729 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; 1742 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1730 if (ieee80211_is_data_qos(hdr->frame_control) && 1743 if (ieee80211_is_mgmt(hdr->frame_control)) {
1731 is_unicast_ether_addr(ieee80211_get_DA(hdr))) { 1744 tid = HTT_DATA_TX_EXT_TID_MGMT;
1745 } else if (ieee80211_is_data_qos(hdr->frame_control) &&
1746 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1732 u8 *qc = ieee80211_get_qos_ctl(hdr); 1747 u8 *qc = ieee80211_get_qos_ctl(hdr);
1733 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 1748 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1734 } 1749 }
@@ -1742,7 +1757,7 @@ static void ath10k_tx(struct ieee80211_hw *hw,
1742 ath10k_tx_h_seq_no(skb); 1757 ath10k_tx_h_seq_no(skb);
1743 } 1758 }
1744 1759
1745 memset(ATH10K_SKB_CB(skb), 0, sizeof(*ATH10K_SKB_CB(skb))); 1760 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
1746 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id; 1761 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1747 ATH10K_SKB_CB(skb)->htt.tid = tid; 1762 ATH10K_SKB_CB(skb)->htt.tid = tid;
1748 1763
@@ -1884,7 +1899,7 @@ static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1884 mutex_lock(&ar->conf_mutex); 1899 mutex_lock(&ar->conf_mutex);
1885 1900
1886 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 1901 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1887 ath10k_dbg(ATH10K_DBG_MAC, "Config channel %d mhz\n", 1902 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
1888 conf->chandef.chan->center_freq); 1903 conf->chandef.chan->center_freq);
1889 spin_lock_bh(&ar->data_lock); 1904 spin_lock_bh(&ar->data_lock);
1890 ar->rx_channel = conf->chandef.chan; 1905 ar->rx_channel = conf->chandef.chan;
@@ -1901,7 +1916,6 @@ static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1901 ret = ath10k_monitor_destroy(ar); 1916 ret = ath10k_monitor_destroy(ar);
1902 } 1917 }
1903 1918
1904 ath10k_wmi_flush_tx(ar);
1905 mutex_unlock(&ar->conf_mutex); 1919 mutex_unlock(&ar->conf_mutex);
1906 return ret; 1920 return ret;
1907} 1921}
@@ -1973,7 +1987,7 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
1973 break; 1987 break;
1974 } 1988 }
1975 1989
1976 ath10k_dbg(ATH10K_DBG_MAC, "Add interface: id %d type %d subtype %d\n", 1990 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
1977 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype); 1991 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1978 1992
1979 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, 1993 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
@@ -2052,7 +2066,12 @@ static void ath10k_remove_interface(struct ieee80211_hw *hw,
2052 2066
2053 mutex_lock(&ar->conf_mutex); 2067 mutex_lock(&ar->conf_mutex);
2054 2068
2055 ath10k_dbg(ATH10K_DBG_MAC, "Remove interface: id %d\n", arvif->vdev_id); 2069 spin_lock_bh(&ar->data_lock);
2070 if (arvif->beacon) {
2071 dev_kfree_skb_any(arvif->beacon);
2072 arvif->beacon = NULL;
2073 }
2074 spin_unlock_bh(&ar->data_lock);
2056 2075
2057 ar->free_vdev_map |= 1 << (arvif->vdev_id); 2076 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2058 2077
@@ -2064,6 +2083,9 @@ static void ath10k_remove_interface(struct ieee80211_hw *hw,
2064 kfree(arvif->u.ap.noa_data); 2083 kfree(arvif->u.ap.noa_data);
2065 } 2084 }
2066 2085
2086 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2087 arvif->vdev_id);
2088
2067 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); 2089 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2068 if (ret) 2090 if (ret)
2069 ath10k_warn("WMI vdev delete failed: %d\n", ret); 2091 ath10k_warn("WMI vdev delete failed: %d\n", ret);
@@ -2105,18 +2127,20 @@ static void ath10k_configure_filter(struct ieee80211_hw *hw,
2105 2127
2106 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) && 2128 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2107 !ar->monitor_enabled) { 2129 !ar->monitor_enabled) {
2130 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2131 ar->monitor_vdev_id);
2132
2108 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id); 2133 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2109 if (ret) 2134 if (ret)
2110 ath10k_warn("Unable to start monitor mode\n"); 2135 ath10k_warn("Unable to start monitor mode\n");
2111 else
2112 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode started\n");
2113 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) && 2136 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2114 ar->monitor_enabled) { 2137 ar->monitor_enabled) {
2138 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2139 ar->monitor_vdev_id);
2140
2115 ret = ath10k_monitor_stop(ar); 2141 ret = ath10k_monitor_stop(ar);
2116 if (ret) 2142 if (ret)
2117 ath10k_warn("Unable to stop monitor mode\n"); 2143 ath10k_warn("Unable to stop monitor mode\n");
2118 else
2119 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode stopped\n");
2120 } 2144 }
2121 2145
2122 mutex_unlock(&ar->conf_mutex); 2146 mutex_unlock(&ar->conf_mutex);
@@ -2141,41 +2165,41 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2141 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 2165 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2142 WMI_VDEV_PARAM_BEACON_INTERVAL, 2166 WMI_VDEV_PARAM_BEACON_INTERVAL,
2143 arvif->beacon_interval); 2167 arvif->beacon_interval);
2168 ath10k_dbg(ATH10K_DBG_MAC,
2169 "mac vdev %d beacon_interval %d\n",
2170 arvif->vdev_id, arvif->beacon_interval);
2171
2144 if (ret) 2172 if (ret)
2145 ath10k_warn("Failed to set beacon interval for VDEV: %d\n", 2173 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2146 arvif->vdev_id); 2174 arvif->vdev_id);
2147 else
2148 ath10k_dbg(ATH10K_DBG_MAC,
2149 "Beacon interval: %d set for VDEV: %d\n",
2150 arvif->beacon_interval, arvif->vdev_id);
2151 } 2175 }
2152 2176
2153 if (changed & BSS_CHANGED_BEACON) { 2177 if (changed & BSS_CHANGED_BEACON) {
2178 ath10k_dbg(ATH10K_DBG_MAC,
2179 "vdev %d set beacon tx mode to staggered\n",
2180 arvif->vdev_id);
2181
2154 ret = ath10k_wmi_pdev_set_param(ar, 2182 ret = ath10k_wmi_pdev_set_param(ar,
2155 WMI_PDEV_PARAM_BEACON_TX_MODE, 2183 WMI_PDEV_PARAM_BEACON_TX_MODE,
2156 WMI_BEACON_STAGGERED_MODE); 2184 WMI_BEACON_STAGGERED_MODE);
2157 if (ret) 2185 if (ret)
2158 ath10k_warn("Failed to set beacon mode for VDEV: %d\n", 2186 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2159 arvif->vdev_id); 2187 arvif->vdev_id);
2160 else
2161 ath10k_dbg(ATH10K_DBG_MAC,
2162 "Set staggered beacon mode for VDEV: %d\n",
2163 arvif->vdev_id);
2164 } 2188 }
2165 2189
2166 if (changed & BSS_CHANGED_BEACON_INFO) { 2190 if (changed & BSS_CHANGED_BEACON_INFO) {
2167 arvif->dtim_period = info->dtim_period; 2191 arvif->dtim_period = info->dtim_period;
2168 2192
2193 ath10k_dbg(ATH10K_DBG_MAC,
2194 "mac vdev %d dtim_period %d\n",
2195 arvif->vdev_id, arvif->dtim_period);
2196
2169 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 2197 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2170 WMI_VDEV_PARAM_DTIM_PERIOD, 2198 WMI_VDEV_PARAM_DTIM_PERIOD,
2171 arvif->dtim_period); 2199 arvif->dtim_period);
2172 if (ret) 2200 if (ret)
2173 ath10k_warn("Failed to set dtim period for VDEV: %d\n", 2201 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2174 arvif->vdev_id); 2202 arvif->vdev_id);
2175 else
2176 ath10k_dbg(ATH10K_DBG_MAC,
2177 "Set dtim period: %d for VDEV: %d\n",
2178 arvif->dtim_period, arvif->vdev_id);
2179 } 2203 }
2180 2204
2181 if (changed & BSS_CHANGED_SSID && 2205 if (changed & BSS_CHANGED_SSID &&
@@ -2188,16 +2212,15 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2188 2212
2189 if (changed & BSS_CHANGED_BSSID) { 2213 if (changed & BSS_CHANGED_BSSID) {
2190 if (!is_zero_ether_addr(info->bssid)) { 2214 if (!is_zero_ether_addr(info->bssid)) {
2215 ath10k_dbg(ATH10K_DBG_MAC,
2216 "mac vdev %d create peer %pM\n",
2217 arvif->vdev_id, info->bssid);
2218
2191 ret = ath10k_peer_create(ar, arvif->vdev_id, 2219 ret = ath10k_peer_create(ar, arvif->vdev_id,
2192 info->bssid); 2220 info->bssid);
2193 if (ret) 2221 if (ret)
2194 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n", 2222 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2195 info->bssid, arvif->vdev_id); 2223 info->bssid, arvif->vdev_id);
2196 else
2197 ath10k_dbg(ATH10K_DBG_MAC,
2198 "Added peer: %pM for VDEV: %d\n",
2199 info->bssid, arvif->vdev_id);
2200
2201 2224
2202 if (vif->type == NL80211_IFTYPE_STATION) { 2225 if (vif->type == NL80211_IFTYPE_STATION) {
2203 /* 2226 /*
@@ -2207,11 +2230,12 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2207 memcpy(arvif->u.sta.bssid, info->bssid, 2230 memcpy(arvif->u.sta.bssid, info->bssid,
2208 ETH_ALEN); 2231 ETH_ALEN);
2209 2232
2233 ath10k_dbg(ATH10K_DBG_MAC,
2234 "mac vdev %d start %pM\n",
2235 arvif->vdev_id, info->bssid);
2236
2237 /* FIXME: check return value */
2210 ret = ath10k_vdev_start(arvif); 2238 ret = ath10k_vdev_start(arvif);
2211 if (!ret)
2212 ath10k_dbg(ATH10K_DBG_MAC,
2213 "VDEV: %d started with BSSID: %pM\n",
2214 arvif->vdev_id, info->bssid);
2215 } 2239 }
2216 2240
2217 /* 2241 /*
@@ -2235,16 +2259,15 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2235 else 2259 else
2236 cts_prot = 0; 2260 cts_prot = 0;
2237 2261
2262 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2263 arvif->vdev_id, cts_prot);
2264
2238 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 2265 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2239 WMI_VDEV_PARAM_ENABLE_RTSCTS, 2266 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2240 cts_prot); 2267 cts_prot);
2241 if (ret) 2268 if (ret)
2242 ath10k_warn("Failed to set CTS prot for VDEV: %d\n", 2269 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2243 arvif->vdev_id); 2270 arvif->vdev_id);
2244 else
2245 ath10k_dbg(ATH10K_DBG_MAC,
2246 "Set CTS prot: %d for VDEV: %d\n",
2247 cts_prot, arvif->vdev_id);
2248 } 2271 }
2249 2272
2250 if (changed & BSS_CHANGED_ERP_SLOT) { 2273 if (changed & BSS_CHANGED_ERP_SLOT) {
@@ -2255,16 +2278,15 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2255 else 2278 else
2256 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ 2279 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2257 2280
2281 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2282 arvif->vdev_id, slottime);
2283
2258 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 2284 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2259 WMI_VDEV_PARAM_SLOT_TIME, 2285 WMI_VDEV_PARAM_SLOT_TIME,
2260 slottime); 2286 slottime);
2261 if (ret) 2287 if (ret)
2262 ath10k_warn("Failed to set erp slot for VDEV: %d\n", 2288 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2263 arvif->vdev_id); 2289 arvif->vdev_id);
2264 else
2265 ath10k_dbg(ATH10K_DBG_MAC,
2266 "Set slottime: %d for VDEV: %d\n",
2267 slottime, arvif->vdev_id);
2268 } 2290 }
2269 2291
2270 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 2292 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
@@ -2274,16 +2296,16 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2274 else 2296 else
2275 preamble = WMI_VDEV_PREAMBLE_LONG; 2297 preamble = WMI_VDEV_PREAMBLE_LONG;
2276 2298
2299 ath10k_dbg(ATH10K_DBG_MAC,
2300 "mac vdev %d preamble %dn",
2301 arvif->vdev_id, preamble);
2302
2277 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 2303 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2278 WMI_VDEV_PARAM_PREAMBLE, 2304 WMI_VDEV_PARAM_PREAMBLE,
2279 preamble); 2305 preamble);
2280 if (ret) 2306 if (ret)
2281 ath10k_warn("Failed to set preamble for VDEV: %d\n", 2307 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2282 arvif->vdev_id); 2308 arvif->vdev_id);
2283 else
2284 ath10k_dbg(ATH10K_DBG_MAC,
2285 "Set preamble: %d for VDEV: %d\n",
2286 preamble, arvif->vdev_id);
2287 } 2309 }
2288 2310
2289 if (changed & BSS_CHANGED_ASSOC) { 2311 if (changed & BSS_CHANGED_ASSOC) {
@@ -2474,27 +2496,26 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
2474 /* 2496 /*
2475 * New station addition. 2497 * New station addition.
2476 */ 2498 */
2499 ath10k_dbg(ATH10K_DBG_MAC,
2500 "mac vdev %d peer create %pM (new sta)\n",
2501 arvif->vdev_id, sta->addr);
2502
2477 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr); 2503 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2478 if (ret) 2504 if (ret)
2479 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n", 2505 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2480 sta->addr, arvif->vdev_id); 2506 sta->addr, arvif->vdev_id);
2481 else
2482 ath10k_dbg(ATH10K_DBG_MAC,
2483 "Added peer: %pM for VDEV: %d\n",
2484 sta->addr, arvif->vdev_id);
2485 } else if ((old_state == IEEE80211_STA_NONE && 2507 } else if ((old_state == IEEE80211_STA_NONE &&
2486 new_state == IEEE80211_STA_NOTEXIST)) { 2508 new_state == IEEE80211_STA_NOTEXIST)) {
2487 /* 2509 /*
2488 * Existing station deletion. 2510 * Existing station deletion.
2489 */ 2511 */
2512 ath10k_dbg(ATH10K_DBG_MAC,
2513 "mac vdev %d peer delete %pM (sta gone)\n",
2514 arvif->vdev_id, sta->addr);
2490 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); 2515 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2491 if (ret) 2516 if (ret)
2492 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n", 2517 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2493 sta->addr, arvif->vdev_id); 2518 sta->addr, arvif->vdev_id);
2494 else
2495 ath10k_dbg(ATH10K_DBG_MAC,
2496 "Removed peer: %pM for VDEV: %d\n",
2497 sta->addr, arvif->vdev_id);
2498 2519
2499 if (vif->type == NL80211_IFTYPE_STATION) 2520 if (vif->type == NL80211_IFTYPE_STATION)
2500 ath10k_bss_disassoc(hw, vif); 2521 ath10k_bss_disassoc(hw, vif);
@@ -2505,14 +2526,13 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
2505 /* 2526 /*
2506 * New association. 2527 * New association.
2507 */ 2528 */
2529 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2530 sta->addr);
2531
2508 ret = ath10k_station_assoc(ar, arvif, sta); 2532 ret = ath10k_station_assoc(ar, arvif, sta);
2509 if (ret) 2533 if (ret)
2510 ath10k_warn("Failed to associate station: %pM\n", 2534 ath10k_warn("Failed to associate station: %pM\n",
2511 sta->addr); 2535 sta->addr);
2512 else
2513 ath10k_dbg(ATH10K_DBG_MAC,
2514 "Station %pM moved to assoc state\n",
2515 sta->addr);
2516 } else if (old_state == IEEE80211_STA_ASSOC && 2536 } else if (old_state == IEEE80211_STA_ASSOC &&
2517 new_state == IEEE80211_STA_AUTH && 2537 new_state == IEEE80211_STA_AUTH &&
2518 (vif->type == NL80211_IFTYPE_AP || 2538 (vif->type == NL80211_IFTYPE_AP ||
@@ -2520,14 +2540,13 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
2520 /* 2540 /*
2521 * Disassociation. 2541 * Disassociation.
2522 */ 2542 */
2543 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2544 sta->addr);
2545
2523 ret = ath10k_station_disassoc(ar, arvif, sta); 2546 ret = ath10k_station_disassoc(ar, arvif, sta);
2524 if (ret) 2547 if (ret)
2525 ath10k_warn("Failed to disassociate station: %pM\n", 2548 ath10k_warn("Failed to disassociate station: %pM\n",
2526 sta->addr); 2549 sta->addr);
2527 else
2528 ath10k_dbg(ATH10K_DBG_MAC,
2529 "Station %pM moved to disassociated state\n",
2530 sta->addr);
2531 } 2550 }
2532 2551
2533 mutex_unlock(&ar->conf_mutex); 2552 mutex_unlock(&ar->conf_mutex);
@@ -2747,14 +2766,13 @@ static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2747 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED) 2766 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2748 return; 2767 return;
2749 2768
2769 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
2770 arvif->vdev_id, rts);
2771
2750 ar_iter->ret = ath10k_mac_set_rts(arvif, rts); 2772 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
2751 if (ar_iter->ret) 2773 if (ar_iter->ret)
2752 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n", 2774 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2753 arvif->vdev_id); 2775 arvif->vdev_id);
2754 else
2755 ath10k_dbg(ATH10K_DBG_MAC,
2756 "Set RTS threshold: %d for VDEV: %d\n",
2757 rts, arvif->vdev_id);
2758} 2776}
2759 2777
2760static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 2778static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
@@ -2789,14 +2807,13 @@ static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2789 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED) 2807 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2790 return; 2808 return;
2791 2809
2810 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
2811 arvif->vdev_id, frag);
2812
2792 ar_iter->ret = ath10k_mac_set_frag(arvif, frag); 2813 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
2793 if (ar_iter->ret) 2814 if (ar_iter->ret)
2794 ath10k_warn("Failed to set frag threshold for VDEV: %d\n", 2815 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2795 arvif->vdev_id); 2816 arvif->vdev_id);
2796 else
2797 ath10k_dbg(ATH10K_DBG_MAC,
2798 "Set frag threshold: %d for VDEV: %d\n",
2799 frag, arvif->vdev_id);
2800} 2817}
2801 2818
2802static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value) 2819static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
@@ -2836,8 +2853,7 @@ static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2836 bool empty; 2853 bool empty;
2837 2854
2838 spin_lock_bh(&ar->htt.tx_lock); 2855 spin_lock_bh(&ar->htt.tx_lock);
2839 empty = bitmap_empty(ar->htt.used_msdu_ids, 2856 empty = (ar->htt.num_pending_tx == 0);
2840 ar->htt.max_num_pending_tx);
2841 spin_unlock_bh(&ar->htt.tx_lock); 2857 spin_unlock_bh(&ar->htt.tx_lock);
2842 2858
2843 skip = (ar->state == ATH10K_STATE_WEDGED); 2859 skip = (ar->state == ATH10K_STATE_WEDGED);
@@ -3326,6 +3342,10 @@ int ath10k_mac_register(struct ath10k *ar)
3326 IEEE80211_HW_WANT_MONITOR_VIF | 3342 IEEE80211_HW_WANT_MONITOR_VIF |
3327 IEEE80211_HW_AP_LINK_PS; 3343 IEEE80211_HW_AP_LINK_PS;
3328 3344
3345 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3346 * bytes is used for padding/alignment if necessary. */
3347 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3348
3329 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) 3349 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3330 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS; 3350 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3331 3351
diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index e2f9ef50b1bd..dff23d97bed0 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -36,11 +36,9 @@ static unsigned int ath10k_target_ps;
36module_param(ath10k_target_ps, uint, 0644); 36module_param(ath10k_target_ps, uint, 0644);
37MODULE_PARM_DESC(ath10k_target_ps, "Enable ath10k Target (SoC) PS option"); 37MODULE_PARM_DESC(ath10k_target_ps, "Enable ath10k Target (SoC) PS option");
38 38
39#define QCA988X_1_0_DEVICE_ID (0xabcd)
40#define QCA988X_2_0_DEVICE_ID (0x003c) 39#define QCA988X_2_0_DEVICE_ID (0x003c)
41 40
42static DEFINE_PCI_DEVICE_TABLE(ath10k_pci_id_table) = { 41static DEFINE_PCI_DEVICE_TABLE(ath10k_pci_id_table) = {
43 { PCI_VDEVICE(ATHEROS, QCA988X_1_0_DEVICE_ID) }, /* PCI-E QCA988X V1 */
44 { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */ 42 { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */
45 {0} 43 {0}
46}; 44};
@@ -50,9 +48,9 @@ static int ath10k_pci_diag_read_access(struct ath10k *ar, u32 address,
50 48
51static void ath10k_pci_process_ce(struct ath10k *ar); 49static void ath10k_pci_process_ce(struct ath10k *ar);
52static int ath10k_pci_post_rx(struct ath10k *ar); 50static int ath10k_pci_post_rx(struct ath10k *ar);
53static int ath10k_pci_post_rx_pipe(struct hif_ce_pipe_info *pipe_info, 51static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe *pipe_info,
54 int num); 52 int num);
55static void ath10k_pci_rx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info); 53static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info);
56static void ath10k_pci_stop_ce(struct ath10k *ar); 54static void ath10k_pci_stop_ce(struct ath10k *ar);
57static void ath10k_pci_device_reset(struct ath10k *ar); 55static void ath10k_pci_device_reset(struct ath10k *ar);
58static int ath10k_pci_reset_target(struct ath10k *ar); 56static int ath10k_pci_reset_target(struct ath10k *ar);
@@ -60,43 +58,145 @@ static int ath10k_pci_start_intr(struct ath10k *ar);
60static void ath10k_pci_stop_intr(struct ath10k *ar); 58static void ath10k_pci_stop_intr(struct ath10k *ar);
61 59
62static const struct ce_attr host_ce_config_wlan[] = { 60static const struct ce_attr host_ce_config_wlan[] = {
63 /* host->target HTC control and raw streams */ 61 /* CE0: host->target HTC control and raw streams */
64 { /* CE0 */ CE_ATTR_FLAGS, 0, 16, 256, 0, NULL,}, 62 {
65 /* could be moved to share CE3 */ 63 .flags = CE_ATTR_FLAGS,
66 /* target->host HTT + HTC control */ 64 .src_nentries = 16,
67 { /* CE1 */ CE_ATTR_FLAGS, 0, 0, 512, 512, NULL,}, 65 .src_sz_max = 256,
68 /* target->host WMI */ 66 .dest_nentries = 0,
69 { /* CE2 */ CE_ATTR_FLAGS, 0, 0, 2048, 32, NULL,}, 67 },
70 /* host->target WMI */ 68
71 { /* CE3 */ CE_ATTR_FLAGS, 0, 32, 2048, 0, NULL,}, 69 /* CE1: target->host HTT + HTC control */
72 /* host->target HTT */ 70 {
73 { /* CE4 */ CE_ATTR_FLAGS | CE_ATTR_DIS_INTR, 0, 71 .flags = CE_ATTR_FLAGS,
74 CE_HTT_H2T_MSG_SRC_NENTRIES, 256, 0, NULL,}, 72 .src_nentries = 0,
75 /* unused */ 73 .src_sz_max = 512,
76 { /* CE5 */ CE_ATTR_FLAGS, 0, 0, 0, 0, NULL,}, 74 .dest_nentries = 512,
77 /* Target autonomous hif_memcpy */ 75 },
78 { /* CE6 */ CE_ATTR_FLAGS, 0, 0, 0, 0, NULL,}, 76
79 /* ce_diag, the Diagnostic Window */ 77 /* CE2: target->host WMI */
80 { /* CE7 */ CE_ATTR_FLAGS, 0, 2, DIAG_TRANSFER_LIMIT, 2, NULL,}, 78 {
79 .flags = CE_ATTR_FLAGS,
80 .src_nentries = 0,
81 .src_sz_max = 2048,
82 .dest_nentries = 32,
83 },
84
85 /* CE3: host->target WMI */
86 {
87 .flags = CE_ATTR_FLAGS,
88 .src_nentries = 32,
89 .src_sz_max = 2048,
90 .dest_nentries = 0,
91 },
92
93 /* CE4: host->target HTT */
94 {
95 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
96 .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
97 .src_sz_max = 256,
98 .dest_nentries = 0,
99 },
100
101 /* CE5: unused */
102 {
103 .flags = CE_ATTR_FLAGS,
104 .src_nentries = 0,
105 .src_sz_max = 0,
106 .dest_nentries = 0,
107 },
108
109 /* CE6: target autonomous hif_memcpy */
110 {
111 .flags = CE_ATTR_FLAGS,
112 .src_nentries = 0,
113 .src_sz_max = 0,
114 .dest_nentries = 0,
115 },
116
117 /* CE7: ce_diag, the Diagnostic Window */
118 {
119 .flags = CE_ATTR_FLAGS,
120 .src_nentries = 2,
121 .src_sz_max = DIAG_TRANSFER_LIMIT,
122 .dest_nentries = 2,
123 },
81}; 124};
82 125
83/* Target firmware's Copy Engine configuration. */ 126/* Target firmware's Copy Engine configuration. */
84static const struct ce_pipe_config target_ce_config_wlan[] = { 127static const struct ce_pipe_config target_ce_config_wlan[] = {
85 /* host->target HTC control and raw streams */ 128 /* CE0: host->target HTC control and raw streams */
86 { /* CE0 */ 0, PIPEDIR_OUT, 32, 256, CE_ATTR_FLAGS, 0,}, 129 {
87 /* target->host HTT + HTC control */ 130 .pipenum = 0,
88 { /* CE1 */ 1, PIPEDIR_IN, 32, 512, CE_ATTR_FLAGS, 0,}, 131 .pipedir = PIPEDIR_OUT,
89 /* target->host WMI */ 132 .nentries = 32,
90 { /* CE2 */ 2, PIPEDIR_IN, 32, 2048, CE_ATTR_FLAGS, 0,}, 133 .nbytes_max = 256,
91 /* host->target WMI */ 134 .flags = CE_ATTR_FLAGS,
92 { /* CE3 */ 3, PIPEDIR_OUT, 32, 2048, CE_ATTR_FLAGS, 0,}, 135 .reserved = 0,
93 /* host->target HTT */ 136 },
94 { /* CE4 */ 4, PIPEDIR_OUT, 256, 256, CE_ATTR_FLAGS, 0,}, 137
138 /* CE1: target->host HTT + HTC control */
139 {
140 .pipenum = 1,
141 .pipedir = PIPEDIR_IN,
142 .nentries = 32,
143 .nbytes_max = 512,
144 .flags = CE_ATTR_FLAGS,
145 .reserved = 0,
146 },
147
148 /* CE2: target->host WMI */
149 {
150 .pipenum = 2,
151 .pipedir = PIPEDIR_IN,
152 .nentries = 32,
153 .nbytes_max = 2048,
154 .flags = CE_ATTR_FLAGS,
155 .reserved = 0,
156 },
157
158 /* CE3: host->target WMI */
159 {
160 .pipenum = 3,
161 .pipedir = PIPEDIR_OUT,
162 .nentries = 32,
163 .nbytes_max = 2048,
164 .flags = CE_ATTR_FLAGS,
165 .reserved = 0,
166 },
167
168 /* CE4: host->target HTT */
169 {
170 .pipenum = 4,
171 .pipedir = PIPEDIR_OUT,
172 .nentries = 256,
173 .nbytes_max = 256,
174 .flags = CE_ATTR_FLAGS,
175 .reserved = 0,
176 },
177
95 /* NB: 50% of src nentries, since tx has 2 frags */ 178 /* NB: 50% of src nentries, since tx has 2 frags */
96 /* unused */ 179
97 { /* CE5 */ 5, PIPEDIR_OUT, 32, 2048, CE_ATTR_FLAGS, 0,}, 180 /* CE5: unused */
98 /* Reserved for target autonomous hif_memcpy */ 181 {
99 { /* CE6 */ 6, PIPEDIR_INOUT, 32, 4096, CE_ATTR_FLAGS, 0,}, 182 .pipenum = 5,
183 .pipedir = PIPEDIR_OUT,
184 .nentries = 32,
185 .nbytes_max = 2048,
186 .flags = CE_ATTR_FLAGS,
187 .reserved = 0,
188 },
189
190 /* CE6: Reserved for target autonomous hif_memcpy */
191 {
192 .pipenum = 6,
193 .pipedir = PIPEDIR_INOUT,
194 .nentries = 32,
195 .nbytes_max = 4096,
196 .flags = CE_ATTR_FLAGS,
197 .reserved = 0,
198 },
199
100 /* CE7 used only by Host */ 200 /* CE7 used only by Host */
101}; 201};
102 202
@@ -114,7 +214,7 @@ static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
114 unsigned int completed_nbytes, orig_nbytes, remaining_bytes; 214 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
115 unsigned int id; 215 unsigned int id;
116 unsigned int flags; 216 unsigned int flags;
117 struct ce_state *ce_diag; 217 struct ath10k_ce_pipe *ce_diag;
118 /* Host buffer address in CE space */ 218 /* Host buffer address in CE space */
119 u32 ce_data; 219 u32 ce_data;
120 dma_addr_t ce_data_base = 0; 220 dma_addr_t ce_data_base = 0;
@@ -278,7 +378,7 @@ static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
278 unsigned int completed_nbytes, orig_nbytes, remaining_bytes; 378 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
279 unsigned int id; 379 unsigned int id;
280 unsigned int flags; 380 unsigned int flags;
281 struct ce_state *ce_diag; 381 struct ath10k_ce_pipe *ce_diag;
282 void *data_buf = NULL; 382 void *data_buf = NULL;
283 u32 ce_data; /* Host buffer address in CE space */ 383 u32 ce_data; /* Host buffer address in CE space */
284 dma_addr_t ce_data_base = 0; 384 dma_addr_t ce_data_base = 0;
@@ -437,7 +537,7 @@ static void ath10k_pci_wait(struct ath10k *ar)
437 ath10k_warn("Unable to wakeup target\n"); 537 ath10k_warn("Unable to wakeup target\n");
438} 538}
439 539
440void ath10k_do_pci_wake(struct ath10k *ar) 540int ath10k_do_pci_wake(struct ath10k *ar)
441{ 541{
442 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 542 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
443 void __iomem *pci_addr = ar_pci->mem; 543 void __iomem *pci_addr = ar_pci->mem;
@@ -453,18 +553,19 @@ void ath10k_do_pci_wake(struct ath10k *ar)
453 atomic_inc(&ar_pci->keep_awake_count); 553 atomic_inc(&ar_pci->keep_awake_count);
454 554
455 if (ar_pci->verified_awake) 555 if (ar_pci->verified_awake)
456 return; 556 return 0;
457 557
458 for (;;) { 558 for (;;) {
459 if (ath10k_pci_target_is_awake(ar)) { 559 if (ath10k_pci_target_is_awake(ar)) {
460 ar_pci->verified_awake = true; 560 ar_pci->verified_awake = true;
461 break; 561 return 0;
462 } 562 }
463 563
464 if (tot_delay > PCIE_WAKE_TIMEOUT) { 564 if (tot_delay > PCIE_WAKE_TIMEOUT) {
465 ath10k_warn("target takes too long to wake up (awake count %d)\n", 565 ath10k_warn("target took longer %d us to wake up (awake count %d)\n",
566 PCIE_WAKE_TIMEOUT,
466 atomic_read(&ar_pci->keep_awake_count)); 567 atomic_read(&ar_pci->keep_awake_count));
467 break; 568 return -ETIMEDOUT;
468 } 569 }
469 570
470 udelay(curr_delay); 571 udelay(curr_delay);
@@ -493,7 +594,7 @@ void ath10k_do_pci_sleep(struct ath10k *ar)
493 * FIXME: Handle OOM properly. 594 * FIXME: Handle OOM properly.
494 */ 595 */
495static inline 596static inline
496struct ath10k_pci_compl *get_free_compl(struct hif_ce_pipe_info *pipe_info) 597struct ath10k_pci_compl *get_free_compl(struct ath10k_pci_pipe *pipe_info)
497{ 598{
498 struct ath10k_pci_compl *compl = NULL; 599 struct ath10k_pci_compl *compl = NULL;
499 600
@@ -511,39 +612,28 @@ exit:
511} 612}
512 613
513/* Called by lower (CE) layer when a send to Target completes. */ 614/* Called by lower (CE) layer when a send to Target completes. */
514static void ath10k_pci_ce_send_done(struct ce_state *ce_state, 615static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe *ce_state)
515 void *transfer_context,
516 u32 ce_data,
517 unsigned int nbytes,
518 unsigned int transfer_id)
519{ 616{
520 struct ath10k *ar = ce_state->ar; 617 struct ath10k *ar = ce_state->ar;
521 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 618 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
522 struct hif_ce_pipe_info *pipe_info = &ar_pci->pipe_info[ce_state->id]; 619 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
523 struct ath10k_pci_compl *compl; 620 struct ath10k_pci_compl *compl;
524 bool process = false; 621 void *transfer_context;
525 622 u32 ce_data;
526 do { 623 unsigned int nbytes;
527 /* 624 unsigned int transfer_id;
528 * For the send completion of an item in sendlist, just
529 * increment num_sends_allowed. The upper layer callback will
530 * be triggered when last fragment is done with send.
531 */
532 if (transfer_context == CE_SENDLIST_ITEM_CTXT) {
533 spin_lock_bh(&pipe_info->pipe_lock);
534 pipe_info->num_sends_allowed++;
535 spin_unlock_bh(&pipe_info->pipe_lock);
536 continue;
537 }
538 625
626 while (ath10k_ce_completed_send_next(ce_state, &transfer_context,
627 &ce_data, &nbytes,
628 &transfer_id) == 0) {
539 compl = get_free_compl(pipe_info); 629 compl = get_free_compl(pipe_info);
540 if (!compl) 630 if (!compl)
541 break; 631 break;
542 632
543 compl->send_or_recv = HIF_CE_COMPLETE_SEND; 633 compl->state = ATH10K_PCI_COMPL_SEND;
544 compl->ce_state = ce_state; 634 compl->ce_state = ce_state;
545 compl->pipe_info = pipe_info; 635 compl->pipe_info = pipe_info;
546 compl->transfer_context = transfer_context; 636 compl->skb = transfer_context;
547 compl->nbytes = nbytes; 637 compl->nbytes = nbytes;
548 compl->transfer_id = transfer_id; 638 compl->transfer_id = transfer_id;
549 compl->flags = 0; 639 compl->flags = 0;
@@ -554,46 +644,36 @@ static void ath10k_pci_ce_send_done(struct ce_state *ce_state,
554 spin_lock_bh(&ar_pci->compl_lock); 644 spin_lock_bh(&ar_pci->compl_lock);
555 list_add_tail(&compl->list, &ar_pci->compl_process); 645 list_add_tail(&compl->list, &ar_pci->compl_process);
556 spin_unlock_bh(&ar_pci->compl_lock); 646 spin_unlock_bh(&ar_pci->compl_lock);
557 647 }
558 process = true;
559 } while (ath10k_ce_completed_send_next(ce_state,
560 &transfer_context,
561 &ce_data, &nbytes,
562 &transfer_id) == 0);
563
564 /*
565 * If only some of the items within a sendlist have completed,
566 * don't invoke completion processing until the entire sendlist
567 * has been sent.
568 */
569 if (!process)
570 return;
571 648
572 ath10k_pci_process_ce(ar); 649 ath10k_pci_process_ce(ar);
573} 650}
574 651
575/* Called by lower (CE) layer when data is received from the Target. */ 652/* Called by lower (CE) layer when data is received from the Target. */
576static void ath10k_pci_ce_recv_data(struct ce_state *ce_state, 653static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe *ce_state)
577 void *transfer_context, u32 ce_data,
578 unsigned int nbytes,
579 unsigned int transfer_id,
580 unsigned int flags)
581{ 654{
582 struct ath10k *ar = ce_state->ar; 655 struct ath10k *ar = ce_state->ar;
583 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 656 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
584 struct hif_ce_pipe_info *pipe_info = &ar_pci->pipe_info[ce_state->id]; 657 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
585 struct ath10k_pci_compl *compl; 658 struct ath10k_pci_compl *compl;
586 struct sk_buff *skb; 659 struct sk_buff *skb;
660 void *transfer_context;
661 u32 ce_data;
662 unsigned int nbytes;
663 unsigned int transfer_id;
664 unsigned int flags;
587 665
588 do { 666 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
667 &ce_data, &nbytes, &transfer_id,
668 &flags) == 0) {
589 compl = get_free_compl(pipe_info); 669 compl = get_free_compl(pipe_info);
590 if (!compl) 670 if (!compl)
591 break; 671 break;
592 672
593 compl->send_or_recv = HIF_CE_COMPLETE_RECV; 673 compl->state = ATH10K_PCI_COMPL_RECV;
594 compl->ce_state = ce_state; 674 compl->ce_state = ce_state;
595 compl->pipe_info = pipe_info; 675 compl->pipe_info = pipe_info;
596 compl->transfer_context = transfer_context; 676 compl->skb = transfer_context;
597 compl->nbytes = nbytes; 677 compl->nbytes = nbytes;
598 compl->transfer_id = transfer_id; 678 compl->transfer_id = transfer_id;
599 compl->flags = flags; 679 compl->flags = flags;
@@ -608,12 +688,7 @@ static void ath10k_pci_ce_recv_data(struct ce_state *ce_state,
608 spin_lock_bh(&ar_pci->compl_lock); 688 spin_lock_bh(&ar_pci->compl_lock);
609 list_add_tail(&compl->list, &ar_pci->compl_process); 689 list_add_tail(&compl->list, &ar_pci->compl_process);
610 spin_unlock_bh(&ar_pci->compl_lock); 690 spin_unlock_bh(&ar_pci->compl_lock);
611 691 }
612 } while (ath10k_ce_completed_recv_next(ce_state,
613 &transfer_context,
614 &ce_data, &nbytes,
615 &transfer_id,
616 &flags) == 0);
617 692
618 ath10k_pci_process_ce(ar); 693 ath10k_pci_process_ce(ar);
619} 694}
@@ -625,15 +700,12 @@ static int ath10k_pci_hif_send_head(struct ath10k *ar, u8 pipe_id,
625{ 700{
626 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(nbuf); 701 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(nbuf);
627 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 702 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
628 struct hif_ce_pipe_info *pipe_info = &(ar_pci->pipe_info[pipe_id]); 703 struct ath10k_pci_pipe *pipe_info = &(ar_pci->pipe_info[pipe_id]);
629 struct ce_state *ce_hdl = pipe_info->ce_hdl; 704 struct ath10k_ce_pipe *ce_hdl = pipe_info->ce_hdl;
630 struct ce_sendlist sendlist;
631 unsigned int len; 705 unsigned int len;
632 u32 flags = 0; 706 u32 flags = 0;
633 int ret; 707 int ret;
634 708
635 memset(&sendlist, 0, sizeof(struct ce_sendlist));
636
637 len = min(bytes, nbuf->len); 709 len = min(bytes, nbuf->len);
638 bytes -= len; 710 bytes -= len;
639 711
@@ -648,8 +720,6 @@ static int ath10k_pci_hif_send_head(struct ath10k *ar, u8 pipe_id,
648 "ath10k tx: data: ", 720 "ath10k tx: data: ",
649 nbuf->data, nbuf->len); 721 nbuf->data, nbuf->len);
650 722
651 ath10k_ce_sendlist_buf_add(&sendlist, skb_cb->paddr, len, flags);
652
653 /* Make sure we have resources to handle this request */ 723 /* Make sure we have resources to handle this request */
654 spin_lock_bh(&pipe_info->pipe_lock); 724 spin_lock_bh(&pipe_info->pipe_lock);
655 if (!pipe_info->num_sends_allowed) { 725 if (!pipe_info->num_sends_allowed) {
@@ -660,7 +730,8 @@ static int ath10k_pci_hif_send_head(struct ath10k *ar, u8 pipe_id,
660 pipe_info->num_sends_allowed--; 730 pipe_info->num_sends_allowed--;
661 spin_unlock_bh(&pipe_info->pipe_lock); 731 spin_unlock_bh(&pipe_info->pipe_lock);
662 732
663 ret = ath10k_ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id); 733 ret = ath10k_ce_sendlist_send(ce_hdl, nbuf, transfer_id,
734 skb_cb->paddr, len, flags);
664 if (ret) 735 if (ret)
665 ath10k_warn("CE send failed: %p\n", nbuf); 736 ath10k_warn("CE send failed: %p\n", nbuf);
666 737
@@ -670,7 +741,7 @@ static int ath10k_pci_hif_send_head(struct ath10k *ar, u8 pipe_id,
670static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe) 741static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
671{ 742{
672 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 743 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
673 struct hif_ce_pipe_info *pipe_info = &(ar_pci->pipe_info[pipe]); 744 struct ath10k_pci_pipe *pipe_info = &(ar_pci->pipe_info[pipe]);
674 int ret; 745 int ret;
675 746
676 spin_lock_bh(&pipe_info->pipe_lock); 747 spin_lock_bh(&pipe_info->pipe_lock);
@@ -764,9 +835,9 @@ static void ath10k_pci_hif_set_callbacks(struct ath10k *ar,
764static int ath10k_pci_start_ce(struct ath10k *ar) 835static int ath10k_pci_start_ce(struct ath10k *ar)
765{ 836{
766 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 837 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
767 struct ce_state *ce_diag = ar_pci->ce_diag; 838 struct ath10k_ce_pipe *ce_diag = ar_pci->ce_diag;
768 const struct ce_attr *attr; 839 const struct ce_attr *attr;
769 struct hif_ce_pipe_info *pipe_info; 840 struct ath10k_pci_pipe *pipe_info;
770 struct ath10k_pci_compl *compl; 841 struct ath10k_pci_compl *compl;
771 int i, pipe_num, completions, disable_interrupts; 842 int i, pipe_num, completions, disable_interrupts;
772 843
@@ -805,15 +876,14 @@ static int ath10k_pci_start_ce(struct ath10k *ar)
805 continue; 876 continue;
806 877
807 for (i = 0; i < completions; i++) { 878 for (i = 0; i < completions; i++) {
808 compl = kmalloc(sizeof(struct ath10k_pci_compl), 879 compl = kmalloc(sizeof(*compl), GFP_KERNEL);
809 GFP_KERNEL);
810 if (!compl) { 880 if (!compl) {
811 ath10k_warn("No memory for completion state\n"); 881 ath10k_warn("No memory for completion state\n");
812 ath10k_pci_stop_ce(ar); 882 ath10k_pci_stop_ce(ar);
813 return -ENOMEM; 883 return -ENOMEM;
814 } 884 }
815 885
816 compl->send_or_recv = HIF_CE_COMPLETE_FREE; 886 compl->state = ATH10K_PCI_COMPL_FREE;
817 list_add_tail(&compl->list, &pipe_info->compl_free); 887 list_add_tail(&compl->list, &pipe_info->compl_free);
818 } 888 }
819 } 889 }
@@ -840,7 +910,7 @@ static void ath10k_pci_stop_ce(struct ath10k *ar)
840 * their associated resources */ 910 * their associated resources */
841 spin_lock_bh(&ar_pci->compl_lock); 911 spin_lock_bh(&ar_pci->compl_lock);
842 list_for_each_entry(compl, &ar_pci->compl_process, list) { 912 list_for_each_entry(compl, &ar_pci->compl_process, list) {
843 skb = (struct sk_buff *)compl->transfer_context; 913 skb = compl->skb;
844 ATH10K_SKB_CB(skb)->is_aborted = true; 914 ATH10K_SKB_CB(skb)->is_aborted = true;
845 } 915 }
846 spin_unlock_bh(&ar_pci->compl_lock); 916 spin_unlock_bh(&ar_pci->compl_lock);
@@ -850,7 +920,7 @@ static void ath10k_pci_cleanup_ce(struct ath10k *ar)
850{ 920{
851 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 921 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
852 struct ath10k_pci_compl *compl, *tmp; 922 struct ath10k_pci_compl *compl, *tmp;
853 struct hif_ce_pipe_info *pipe_info; 923 struct ath10k_pci_pipe *pipe_info;
854 struct sk_buff *netbuf; 924 struct sk_buff *netbuf;
855 int pipe_num; 925 int pipe_num;
856 926
@@ -861,7 +931,7 @@ static void ath10k_pci_cleanup_ce(struct ath10k *ar)
861 931
862 list_for_each_entry_safe(compl, tmp, &ar_pci->compl_process, list) { 932 list_for_each_entry_safe(compl, tmp, &ar_pci->compl_process, list) {
863 list_del(&compl->list); 933 list_del(&compl->list);
864 netbuf = (struct sk_buff *)compl->transfer_context; 934 netbuf = compl->skb;
865 dev_kfree_skb_any(netbuf); 935 dev_kfree_skb_any(netbuf);
866 kfree(compl); 936 kfree(compl);
867 } 937 }
@@ -912,12 +982,14 @@ static void ath10k_pci_process_ce(struct ath10k *ar)
912 list_del(&compl->list); 982 list_del(&compl->list);
913 spin_unlock_bh(&ar_pci->compl_lock); 983 spin_unlock_bh(&ar_pci->compl_lock);
914 984
915 if (compl->send_or_recv == HIF_CE_COMPLETE_SEND) { 985 switch (compl->state) {
986 case ATH10K_PCI_COMPL_SEND:
916 cb->tx_completion(ar, 987 cb->tx_completion(ar,
917 compl->transfer_context, 988 compl->skb,
918 compl->transfer_id); 989 compl->transfer_id);
919 send_done = 1; 990 send_done = 1;
920 } else { 991 break;
992 case ATH10K_PCI_COMPL_RECV:
921 ret = ath10k_pci_post_rx_pipe(compl->pipe_info, 1); 993 ret = ath10k_pci_post_rx_pipe(compl->pipe_info, 1);
922 if (ret) { 994 if (ret) {
923 ath10k_warn("Unable to post recv buffer for pipe: %d\n", 995 ath10k_warn("Unable to post recv buffer for pipe: %d\n",
@@ -925,7 +997,7 @@ static void ath10k_pci_process_ce(struct ath10k *ar)
925 break; 997 break;
926 } 998 }
927 999
928 skb = (struct sk_buff *)compl->transfer_context; 1000 skb = compl->skb;
929 nbytes = compl->nbytes; 1001 nbytes = compl->nbytes;
930 1002
931 ath10k_dbg(ATH10K_DBG_PCI, 1003 ath10k_dbg(ATH10K_DBG_PCI,
@@ -944,9 +1016,17 @@ static void ath10k_pci_process_ce(struct ath10k *ar)
944 nbytes, 1016 nbytes,
945 skb->len + skb_tailroom(skb)); 1017 skb->len + skb_tailroom(skb));
946 } 1018 }
1019 break;
1020 case ATH10K_PCI_COMPL_FREE:
1021 ath10k_warn("free completion cannot be processed\n");
1022 break;
1023 default:
1024 ath10k_warn("invalid completion state (%d)\n",
1025 compl->state);
1026 break;
947 } 1027 }
948 1028
949 compl->send_or_recv = HIF_CE_COMPLETE_FREE; 1029 compl->state = ATH10K_PCI_COMPL_FREE;
950 1030
951 /* 1031 /*
952 * Add completion back to the pipe's free list. 1032 * Add completion back to the pipe's free list.
@@ -1037,12 +1117,12 @@ static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1037 &dl_is_polled); 1117 &dl_is_polled);
1038} 1118}
1039 1119
1040static int ath10k_pci_post_rx_pipe(struct hif_ce_pipe_info *pipe_info, 1120static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe *pipe_info,
1041 int num) 1121 int num)
1042{ 1122{
1043 struct ath10k *ar = pipe_info->hif_ce_state; 1123 struct ath10k *ar = pipe_info->hif_ce_state;
1044 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1124 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1045 struct ce_state *ce_state = pipe_info->ce_hdl; 1125 struct ath10k_ce_pipe *ce_state = pipe_info->ce_hdl;
1046 struct sk_buff *skb; 1126 struct sk_buff *skb;
1047 dma_addr_t ce_data; 1127 dma_addr_t ce_data;
1048 int i, ret = 0; 1128 int i, ret = 0;
@@ -1097,7 +1177,7 @@ err:
1097static int ath10k_pci_post_rx(struct ath10k *ar) 1177static int ath10k_pci_post_rx(struct ath10k *ar)
1098{ 1178{
1099 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1179 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1100 struct hif_ce_pipe_info *pipe_info; 1180 struct ath10k_pci_pipe *pipe_info;
1101 const struct ce_attr *attr; 1181 const struct ce_attr *attr;
1102 int pipe_num, ret = 0; 1182 int pipe_num, ret = 0;
1103 1183
@@ -1147,11 +1227,11 @@ static int ath10k_pci_hif_start(struct ath10k *ar)
1147 return 0; 1227 return 0;
1148} 1228}
1149 1229
1150static void ath10k_pci_rx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info) 1230static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1151{ 1231{
1152 struct ath10k *ar; 1232 struct ath10k *ar;
1153 struct ath10k_pci *ar_pci; 1233 struct ath10k_pci *ar_pci;
1154 struct ce_state *ce_hdl; 1234 struct ath10k_ce_pipe *ce_hdl;
1155 u32 buf_sz; 1235 u32 buf_sz;
1156 struct sk_buff *netbuf; 1236 struct sk_buff *netbuf;
1157 u32 ce_data; 1237 u32 ce_data;
@@ -1179,11 +1259,11 @@ static void ath10k_pci_rx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info)
1179 } 1259 }
1180} 1260}
1181 1261
1182static void ath10k_pci_tx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info) 1262static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1183{ 1263{
1184 struct ath10k *ar; 1264 struct ath10k *ar;
1185 struct ath10k_pci *ar_pci; 1265 struct ath10k_pci *ar_pci;
1186 struct ce_state *ce_hdl; 1266 struct ath10k_ce_pipe *ce_hdl;
1187 struct sk_buff *netbuf; 1267 struct sk_buff *netbuf;
1188 u32 ce_data; 1268 u32 ce_data;
1189 unsigned int nbytes; 1269 unsigned int nbytes;
@@ -1206,15 +1286,14 @@ static void ath10k_pci_tx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info)
1206 1286
1207 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf, 1287 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf,
1208 &ce_data, &nbytes, &id) == 0) { 1288 &ce_data, &nbytes, &id) == 0) {
1209 if (netbuf != CE_SENDLIST_ITEM_CTXT) 1289 /*
1210 /* 1290 * Indicate the completion to higer layer to free
1211 * Indicate the completion to higer layer to free 1291 * the buffer
1212 * the buffer 1292 */
1213 */ 1293 ATH10K_SKB_CB(netbuf)->is_aborted = true;
1214 ATH10K_SKB_CB(netbuf)->is_aborted = true; 1294 ar_pci->msg_callbacks_current.tx_completion(ar,
1215 ar_pci->msg_callbacks_current.tx_completion(ar, 1295 netbuf,
1216 netbuf, 1296 id);
1217 id);
1218 } 1297 }
1219} 1298}
1220 1299
@@ -1232,7 +1311,7 @@ static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1232 int pipe_num; 1311 int pipe_num;
1233 1312
1234 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) { 1313 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
1235 struct hif_ce_pipe_info *pipe_info; 1314 struct ath10k_pci_pipe *pipe_info;
1236 1315
1237 pipe_info = &ar_pci->pipe_info[pipe_num]; 1316 pipe_info = &ar_pci->pipe_info[pipe_num];
1238 ath10k_pci_rx_pipe_cleanup(pipe_info); 1317 ath10k_pci_rx_pipe_cleanup(pipe_info);
@@ -1243,7 +1322,7 @@ static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1243static void ath10k_pci_ce_deinit(struct ath10k *ar) 1322static void ath10k_pci_ce_deinit(struct ath10k *ar)
1244{ 1323{
1245 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1324 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1246 struct hif_ce_pipe_info *pipe_info; 1325 struct ath10k_pci_pipe *pipe_info;
1247 int pipe_num; 1326 int pipe_num;
1248 1327
1249 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) { 1328 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
@@ -1293,8 +1372,10 @@ static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1293 void *resp, u32 *resp_len) 1372 void *resp, u32 *resp_len)
1294{ 1373{
1295 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1374 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1296 struct ce_state *ce_tx = ar_pci->pipe_info[BMI_CE_NUM_TO_TARG].ce_hdl; 1375 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1297 struct ce_state *ce_rx = ar_pci->pipe_info[BMI_CE_NUM_TO_HOST].ce_hdl; 1376 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1377 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1378 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
1298 dma_addr_t req_paddr = 0; 1379 dma_addr_t req_paddr = 0;
1299 dma_addr_t resp_paddr = 0; 1380 dma_addr_t resp_paddr = 0;
1300 struct bmi_xfer xfer = {}; 1381 struct bmi_xfer xfer = {};
@@ -1378,13 +1459,16 @@ err_dma:
1378 return ret; 1459 return ret;
1379} 1460}
1380 1461
1381static void ath10k_pci_bmi_send_done(struct ce_state *ce_state, 1462static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
1382 void *transfer_context,
1383 u32 data,
1384 unsigned int nbytes,
1385 unsigned int transfer_id)
1386{ 1463{
1387 struct bmi_xfer *xfer = transfer_context; 1464 struct bmi_xfer *xfer;
1465 u32 ce_data;
1466 unsigned int nbytes;
1467 unsigned int transfer_id;
1468
1469 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer, &ce_data,
1470 &nbytes, &transfer_id))
1471 return;
1388 1472
1389 if (xfer->wait_for_resp) 1473 if (xfer->wait_for_resp)
1390 return; 1474 return;
@@ -1392,14 +1476,17 @@ static void ath10k_pci_bmi_send_done(struct ce_state *ce_state,
1392 complete(&xfer->done); 1476 complete(&xfer->done);
1393} 1477}
1394 1478
1395static void ath10k_pci_bmi_recv_data(struct ce_state *ce_state, 1479static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
1396 void *transfer_context,
1397 u32 data,
1398 unsigned int nbytes,
1399 unsigned int transfer_id,
1400 unsigned int flags)
1401{ 1480{
1402 struct bmi_xfer *xfer = transfer_context; 1481 struct bmi_xfer *xfer;
1482 u32 ce_data;
1483 unsigned int nbytes;
1484 unsigned int transfer_id;
1485 unsigned int flags;
1486
1487 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer, &ce_data,
1488 &nbytes, &transfer_id, &flags))
1489 return;
1403 1490
1404 if (!xfer->wait_for_resp) { 1491 if (!xfer->wait_for_resp) {
1405 ath10k_warn("unexpected: BMI data received; ignoring\n"); 1492 ath10k_warn("unexpected: BMI data received; ignoring\n");
@@ -1679,7 +1766,7 @@ static int ath10k_pci_init_config(struct ath10k *ar)
1679static int ath10k_pci_ce_init(struct ath10k *ar) 1766static int ath10k_pci_ce_init(struct ath10k *ar)
1680{ 1767{
1681 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 1768 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1682 struct hif_ce_pipe_info *pipe_info; 1769 struct ath10k_pci_pipe *pipe_info;
1683 const struct ce_attr *attr; 1770 const struct ce_attr *attr;
1684 int pipe_num; 1771 int pipe_num;
1685 1772
@@ -1895,7 +1982,7 @@ static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
1895 1982
1896static void ath10k_pci_ce_tasklet(unsigned long ptr) 1983static void ath10k_pci_ce_tasklet(unsigned long ptr)
1897{ 1984{
1898 struct hif_ce_pipe_info *pipe = (struct hif_ce_pipe_info *)ptr; 1985 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
1899 struct ath10k_pci *ar_pci = pipe->ar_pci; 1986 struct ath10k_pci *ar_pci = pipe->ar_pci;
1900 1987
1901 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num); 1988 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
@@ -2212,18 +2299,13 @@ static int ath10k_pci_reset_target(struct ath10k *ar)
2212 2299
2213static void ath10k_pci_device_reset(struct ath10k *ar) 2300static void ath10k_pci_device_reset(struct ath10k *ar)
2214{ 2301{
2215 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2216 void __iomem *mem = ar_pci->mem;
2217 int i; 2302 int i;
2218 u32 val; 2303 u32 val;
2219 2304
2220 if (!SOC_GLOBAL_RESET_ADDRESS) 2305 if (!SOC_GLOBAL_RESET_ADDRESS)
2221 return; 2306 return;
2222 2307
2223 if (!mem) 2308 ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS,
2224 return;
2225
2226 ath10k_pci_reg_write32(mem, PCIE_SOC_WAKE_ADDRESS,
2227 PCIE_SOC_WAKE_V_MASK); 2309 PCIE_SOC_WAKE_V_MASK);
2228 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) { 2310 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2229 if (ath10k_pci_target_is_awake(ar)) 2311 if (ath10k_pci_target_is_awake(ar))
@@ -2232,12 +2314,12 @@ static void ath10k_pci_device_reset(struct ath10k *ar)
2232 } 2314 }
2233 2315
2234 /* Put Target, including PCIe, into RESET. */ 2316 /* Put Target, including PCIe, into RESET. */
2235 val = ath10k_pci_reg_read32(mem, SOC_GLOBAL_RESET_ADDRESS); 2317 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
2236 val |= 1; 2318 val |= 1;
2237 ath10k_pci_reg_write32(mem, SOC_GLOBAL_RESET_ADDRESS, val); 2319 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2238 2320
2239 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) { 2321 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2240 if (ath10k_pci_reg_read32(mem, RTC_STATE_ADDRESS) & 2322 if (ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) &
2241 RTC_STATE_COLD_RESET_MASK) 2323 RTC_STATE_COLD_RESET_MASK)
2242 break; 2324 break;
2243 msleep(1); 2325 msleep(1);
@@ -2245,16 +2327,16 @@ static void ath10k_pci_device_reset(struct ath10k *ar)
2245 2327
2246 /* Pull Target, including PCIe, out of RESET. */ 2328 /* Pull Target, including PCIe, out of RESET. */
2247 val &= ~1; 2329 val &= ~1;
2248 ath10k_pci_reg_write32(mem, SOC_GLOBAL_RESET_ADDRESS, val); 2330 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2249 2331
2250 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) { 2332 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2251 if (!(ath10k_pci_reg_read32(mem, RTC_STATE_ADDRESS) & 2333 if (!(ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) &
2252 RTC_STATE_COLD_RESET_MASK)) 2334 RTC_STATE_COLD_RESET_MASK))
2253 break; 2335 break;
2254 msleep(1); 2336 msleep(1);
2255 } 2337 }
2256 2338
2257 ath10k_pci_reg_write32(mem, PCIE_SOC_WAKE_ADDRESS, PCIE_SOC_WAKE_RESET); 2339 ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS, PCIE_SOC_WAKE_RESET);
2258} 2340}
2259 2341
2260static void ath10k_pci_dump_features(struct ath10k_pci *ar_pci) 2342static void ath10k_pci_dump_features(struct ath10k_pci *ar_pci)
@@ -2267,13 +2349,10 @@ static void ath10k_pci_dump_features(struct ath10k_pci *ar_pci)
2267 2349
2268 switch (i) { 2350 switch (i) {
2269 case ATH10K_PCI_FEATURE_MSI_X: 2351 case ATH10K_PCI_FEATURE_MSI_X:
2270 ath10k_dbg(ATH10K_DBG_PCI, "device supports MSI-X\n"); 2352 ath10k_dbg(ATH10K_DBG_BOOT, "device supports MSI-X\n");
2271 break;
2272 case ATH10K_PCI_FEATURE_HW_1_0_WORKAROUND:
2273 ath10k_dbg(ATH10K_DBG_PCI, "QCA988X_1.0 workaround enabled\n");
2274 break; 2353 break;
2275 case ATH10K_PCI_FEATURE_SOC_POWER_SAVE: 2354 case ATH10K_PCI_FEATURE_SOC_POWER_SAVE:
2276 ath10k_dbg(ATH10K_DBG_PCI, "QCA98XX SoC power save enabled\n"); 2355 ath10k_dbg(ATH10K_DBG_BOOT, "QCA98XX SoC power save enabled\n");
2277 break; 2356 break;
2278 } 2357 }
2279 } 2358 }
@@ -2286,7 +2365,7 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2286 int ret = 0; 2365 int ret = 0;
2287 struct ath10k *ar; 2366 struct ath10k *ar;
2288 struct ath10k_pci *ar_pci; 2367 struct ath10k_pci *ar_pci;
2289 u32 lcr_val; 2368 u32 lcr_val, chip_id;
2290 2369
2291 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__); 2370 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
2292 2371
@@ -2298,9 +2377,6 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2298 ar_pci->dev = &pdev->dev; 2377 ar_pci->dev = &pdev->dev;
2299 2378
2300 switch (pci_dev->device) { 2379 switch (pci_dev->device) {
2301 case QCA988X_1_0_DEVICE_ID:
2302 set_bit(ATH10K_PCI_FEATURE_HW_1_0_WORKAROUND, ar_pci->features);
2303 break;
2304 case QCA988X_2_0_DEVICE_ID: 2380 case QCA988X_2_0_DEVICE_ID:
2305 set_bit(ATH10K_PCI_FEATURE_MSI_X, ar_pci->features); 2381 set_bit(ATH10K_PCI_FEATURE_MSI_X, ar_pci->features);
2306 break; 2382 break;
@@ -2322,10 +2398,6 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2322 goto err_ar_pci; 2398 goto err_ar_pci;
2323 } 2399 }
2324 2400
2325 /* Enable QCA988X_1.0 HW workarounds */
2326 if (test_bit(ATH10K_PCI_FEATURE_HW_1_0_WORKAROUND, ar_pci->features))
2327 spin_lock_init(&ar_pci->hw_v1_workaround_lock);
2328
2329 ar_pci->ar = ar; 2401 ar_pci->ar = ar;
2330 ar_pci->fw_indicator_address = FW_INDICATOR_ADDRESS; 2402 ar_pci->fw_indicator_address = FW_INDICATOR_ADDRESS;
2331 atomic_set(&ar_pci->keep_awake_count, 0); 2403 atomic_set(&ar_pci->keep_awake_count, 0);
@@ -2395,9 +2467,20 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2395 2467
2396 spin_lock_init(&ar_pci->ce_lock); 2468 spin_lock_init(&ar_pci->ce_lock);
2397 2469
2398 ar_pci->cacheline_sz = dma_get_cache_alignment(); 2470 ret = ath10k_do_pci_wake(ar);
2471 if (ret) {
2472 ath10k_err("Failed to get chip id: %d\n", ret);
2473 return ret;
2474 }
2475
2476 chip_id = ath10k_pci_read32(ar,
2477 RTC_SOC_BASE_ADDRESS + SOC_CHIP_ID_ADDRESS);
2478
2479 ath10k_do_pci_sleep(ar);
2480
2481 ath10k_dbg(ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
2399 2482
2400 ret = ath10k_core_register(ar); 2483 ret = ath10k_core_register(ar, chip_id);
2401 if (ret) { 2484 if (ret) {
2402 ath10k_err("could not register driver core (%d)\n", ret); 2485 ath10k_err("could not register driver core (%d)\n", ret);
2403 goto err_iomap; 2486 goto err_iomap;
@@ -2414,7 +2497,6 @@ err_region:
2414err_device: 2497err_device:
2415 pci_disable_device(pdev); 2498 pci_disable_device(pdev);
2416err_ar: 2499err_ar:
2417 pci_set_drvdata(pdev, NULL);
2418 ath10k_core_destroy(ar); 2500 ath10k_core_destroy(ar);
2419err_ar_pci: 2501err_ar_pci:
2420 /* call HIF PCI free here */ 2502 /* call HIF PCI free here */
@@ -2442,7 +2524,6 @@ static void ath10k_pci_remove(struct pci_dev *pdev)
2442 2524
2443 ath10k_core_unregister(ar); 2525 ath10k_core_unregister(ar);
2444 2526
2445 pci_set_drvdata(pdev, NULL);
2446 pci_iounmap(pdev, ar_pci->mem); 2527 pci_iounmap(pdev, ar_pci->mem);
2447 pci_release_region(pdev, BAR_NUM); 2528 pci_release_region(pdev, BAR_NUM);
2448 pci_clear_master(pdev); 2529 pci_clear_master(pdev);
@@ -2483,9 +2564,6 @@ module_exit(ath10k_pci_exit);
2483MODULE_AUTHOR("Qualcomm Atheros"); 2564MODULE_AUTHOR("Qualcomm Atheros");
2484MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices"); 2565MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2485MODULE_LICENSE("Dual BSD/GPL"); 2566MODULE_LICENSE("Dual BSD/GPL");
2486MODULE_FIRMWARE(QCA988X_HW_1_0_FW_DIR "/" QCA988X_HW_1_0_FW_FILE);
2487MODULE_FIRMWARE(QCA988X_HW_1_0_FW_DIR "/" QCA988X_HW_1_0_OTP_FILE);
2488MODULE_FIRMWARE(QCA988X_HW_1_0_FW_DIR "/" QCA988X_HW_1_0_BOARD_DATA_FILE);
2489MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE); 2567MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
2490MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_OTP_FILE); 2568MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_OTP_FILE);
2491MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE); 2569MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
diff --git a/drivers/net/wireless/ath/ath10k/pci.h b/drivers/net/wireless/ath/ath10k/pci.h
index 871bb339d56d..7c49f6f96f70 100644
--- a/drivers/net/wireless/ath/ath10k/pci.h
+++ b/drivers/net/wireless/ath/ath10k/pci.h
@@ -43,22 +43,23 @@ struct bmi_xfer {
43 u32 resp_len; 43 u32 resp_len;
44}; 44};
45 45
46enum ath10k_pci_compl_state {
47 ATH10K_PCI_COMPL_FREE = 0,
48 ATH10K_PCI_COMPL_SEND,
49 ATH10K_PCI_COMPL_RECV,
50};
51
46struct ath10k_pci_compl { 52struct ath10k_pci_compl {
47 struct list_head list; 53 struct list_head list;
48 int send_or_recv; 54 enum ath10k_pci_compl_state state;
49 struct ce_state *ce_state; 55 struct ath10k_ce_pipe *ce_state;
50 struct hif_ce_pipe_info *pipe_info; 56 struct ath10k_pci_pipe *pipe_info;
51 void *transfer_context; 57 struct sk_buff *skb;
52 unsigned int nbytes; 58 unsigned int nbytes;
53 unsigned int transfer_id; 59 unsigned int transfer_id;
54 unsigned int flags; 60 unsigned int flags;
55}; 61};
56 62
57/* compl_state.send_or_recv */
58#define HIF_CE_COMPLETE_FREE 0
59#define HIF_CE_COMPLETE_SEND 1
60#define HIF_CE_COMPLETE_RECV 2
61
62/* 63/*
63 * PCI-specific Target state 64 * PCI-specific Target state
64 * 65 *
@@ -152,17 +153,16 @@ struct service_to_pipe {
152 153
153enum ath10k_pci_features { 154enum ath10k_pci_features {
154 ATH10K_PCI_FEATURE_MSI_X = 0, 155 ATH10K_PCI_FEATURE_MSI_X = 0,
155 ATH10K_PCI_FEATURE_HW_1_0_WORKAROUND = 1, 156 ATH10K_PCI_FEATURE_SOC_POWER_SAVE = 1,
156 ATH10K_PCI_FEATURE_SOC_POWER_SAVE = 2,
157 157
158 /* keep last */ 158 /* keep last */
159 ATH10K_PCI_FEATURE_COUNT 159 ATH10K_PCI_FEATURE_COUNT
160}; 160};
161 161
162/* Per-pipe state. */ 162/* Per-pipe state. */
163struct hif_ce_pipe_info { 163struct ath10k_pci_pipe {
164 /* Handle of underlying Copy Engine */ 164 /* Handle of underlying Copy Engine */
165 struct ce_state *ce_hdl; 165 struct ath10k_ce_pipe *ce_hdl;
166 166
167 /* Our pipe number; facilitiates use of pipe_info ptrs. */ 167 /* Our pipe number; facilitiates use of pipe_info ptrs. */
168 u8 pipe_num; 168 u8 pipe_num;
@@ -190,7 +190,6 @@ struct ath10k_pci {
190 struct device *dev; 190 struct device *dev;
191 struct ath10k *ar; 191 struct ath10k *ar;
192 void __iomem *mem; 192 void __iomem *mem;
193 int cacheline_sz;
194 193
195 DECLARE_BITMAP(features, ATH10K_PCI_FEATURE_COUNT); 194 DECLARE_BITMAP(features, ATH10K_PCI_FEATURE_COUNT);
196 195
@@ -219,7 +218,7 @@ struct ath10k_pci {
219 218
220 bool compl_processing; 219 bool compl_processing;
221 220
222 struct hif_ce_pipe_info pipe_info[CE_COUNT_MAX]; 221 struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
223 222
224 struct ath10k_hif_cb msg_callbacks_current; 223 struct ath10k_hif_cb msg_callbacks_current;
225 224
@@ -227,16 +226,13 @@ struct ath10k_pci {
227 u32 fw_indicator_address; 226 u32 fw_indicator_address;
228 227
229 /* Copy Engine used for Diagnostic Accesses */ 228 /* Copy Engine used for Diagnostic Accesses */
230 struct ce_state *ce_diag; 229 struct ath10k_ce_pipe *ce_diag;
231 230
232 /* FIXME: document what this really protects */ 231 /* FIXME: document what this really protects */
233 spinlock_t ce_lock; 232 spinlock_t ce_lock;
234 233
235 /* Map CE id to ce_state */ 234 /* Map CE id to ce_state */
236 struct ce_state *ce_id_to_state[CE_COUNT_MAX]; 235 struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
237
238 /* makes sure that dummy reads are atomic */
239 spinlock_t hw_v1_workaround_lock;
240}; 236};
241 237
242static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar) 238static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
@@ -244,14 +240,18 @@ static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
244 return ar->hif.priv; 240 return ar->hif.priv;
245} 241}
246 242
247static inline u32 ath10k_pci_reg_read32(void __iomem *mem, u32 addr) 243static inline u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
248{ 244{
249 return ioread32(mem + PCIE_LOCAL_BASE_ADDRESS + addr); 245 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
246
247 return ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS + addr);
250} 248}
251 249
252static inline void ath10k_pci_reg_write32(void __iomem *mem, u32 addr, u32 val) 250static inline void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
253{ 251{
254 iowrite32(val, mem + PCIE_LOCAL_BASE_ADDRESS + addr); 252 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
253
254 iowrite32(val, ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS + addr);
255} 255}
256 256
257#define ATH_PCI_RESET_WAIT_MAX 10 /* ms */ 257#define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
@@ -310,23 +310,8 @@ static inline void ath10k_pci_write32(struct ath10k *ar, u32 offset,
310 u32 value) 310 u32 value)
311{ 311{
312 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 312 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
313 void __iomem *addr = ar_pci->mem;
314
315 if (test_bit(ATH10K_PCI_FEATURE_HW_1_0_WORKAROUND, ar_pci->features)) {
316 unsigned long irq_flags;
317 313
318 spin_lock_irqsave(&ar_pci->hw_v1_workaround_lock, irq_flags); 314 iowrite32(value, ar_pci->mem + offset);
319
320 ioread32(addr+offset+4); /* 3rd read prior to write */
321 ioread32(addr+offset+4); /* 2nd read prior to write */
322 ioread32(addr+offset+4); /* 1st read prior to write */
323 iowrite32(value, addr+offset);
324
325 spin_unlock_irqrestore(&ar_pci->hw_v1_workaround_lock,
326 irq_flags);
327 } else {
328 iowrite32(value, addr+offset);
329 }
330} 315}
331 316
332static inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset) 317static inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
@@ -336,15 +321,17 @@ static inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
336 return ioread32(ar_pci->mem + offset); 321 return ioread32(ar_pci->mem + offset);
337} 322}
338 323
339void ath10k_do_pci_wake(struct ath10k *ar); 324int ath10k_do_pci_wake(struct ath10k *ar);
340void ath10k_do_pci_sleep(struct ath10k *ar); 325void ath10k_do_pci_sleep(struct ath10k *ar);
341 326
342static inline void ath10k_pci_wake(struct ath10k *ar) 327static inline int ath10k_pci_wake(struct ath10k *ar)
343{ 328{
344 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 329 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
345 330
346 if (test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features)) 331 if (test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
347 ath10k_do_pci_wake(ar); 332 return ath10k_do_pci_wake(ar);
333
334 return 0;
348} 335}
349 336
350static inline void ath10k_pci_sleep(struct ath10k *ar) 337static inline void ath10k_pci_sleep(struct ath10k *ar)
diff --git a/drivers/net/wireless/ath/ath10k/rx_desc.h b/drivers/net/wireless/ath/ath10k/rx_desc.h
index bfec6c8f2ecb..1c584c4b019c 100644
--- a/drivers/net/wireless/ath/ath10k/rx_desc.h
+++ b/drivers/net/wireless/ath/ath10k/rx_desc.h
@@ -422,10 +422,30 @@ struct rx_mpdu_end {
422#define RX_MSDU_START_INFO1_IP_FRAG (1 << 14) 422#define RX_MSDU_START_INFO1_IP_FRAG (1 << 14)
423#define RX_MSDU_START_INFO1_TCP_ONLY_ACK (1 << 15) 423#define RX_MSDU_START_INFO1_TCP_ONLY_ACK (1 << 15)
424 424
425/* The decapped header (rx_hdr_status) contains the following:
426 * a) 802.11 header
427 * [padding to 4 bytes]
428 * b) HW crypto parameter
429 * - 0 bytes for no security
430 * - 4 bytes for WEP
431 * - 8 bytes for TKIP, AES
432 * [padding to 4 bytes]
433 * c) A-MSDU subframe header (14 bytes) if appliable
434 * d) LLC/SNAP (RFC1042, 8 bytes)
435 *
436 * In case of A-MSDU only first frame in sequence contains (a) and (b). */
425enum rx_msdu_decap_format { 437enum rx_msdu_decap_format {
426 RX_MSDU_DECAP_RAW = 0, 438 RX_MSDU_DECAP_RAW = 0,
427 RX_MSDU_DECAP_NATIVE_WIFI = 1, 439
440 /* Note: QoS frames are reported as non-QoS. The rx_hdr_status in
441 * htt_rx_desc contains the original decapped 802.11 header. */
442 RX_MSDU_DECAP_NATIVE_WIFI = 1,
443
444 /* Payload contains an ethernet header (struct ethhdr). */
428 RX_MSDU_DECAP_ETHERNET2_DIX = 2, 445 RX_MSDU_DECAP_ETHERNET2_DIX = 2,
446
447 /* Payload contains two 48-bit addresses and 2-byte length (14 bytes
448 * total), followed by an RFC1042 header (8 bytes). */
429 RX_MSDU_DECAP_8023_SNAP_LLC = 3 449 RX_MSDU_DECAP_8023_SNAP_LLC = 3
430}; 450};
431 451
diff --git a/drivers/net/wireless/ath/ath10k/trace.h b/drivers/net/wireless/ath/ath10k/trace.h
index 85e806bf7257..90817ddc92ba 100644
--- a/drivers/net/wireless/ath/ath10k/trace.h
+++ b/drivers/net/wireless/ath/ath10k/trace.h
@@ -111,26 +111,29 @@ TRACE_EVENT(ath10k_log_dbg_dump,
111); 111);
112 112
113TRACE_EVENT(ath10k_wmi_cmd, 113TRACE_EVENT(ath10k_wmi_cmd,
114 TP_PROTO(int id, void *buf, size_t buf_len), 114 TP_PROTO(int id, void *buf, size_t buf_len, int ret),
115 115
116 TP_ARGS(id, buf, buf_len), 116 TP_ARGS(id, buf, buf_len, ret),
117 117
118 TP_STRUCT__entry( 118 TP_STRUCT__entry(
119 __field(unsigned int, id) 119 __field(unsigned int, id)
120 __field(size_t, buf_len) 120 __field(size_t, buf_len)
121 __dynamic_array(u8, buf, buf_len) 121 __dynamic_array(u8, buf, buf_len)
122 __field(int, ret)
122 ), 123 ),
123 124
124 TP_fast_assign( 125 TP_fast_assign(
125 __entry->id = id; 126 __entry->id = id;
126 __entry->buf_len = buf_len; 127 __entry->buf_len = buf_len;
128 __entry->ret = ret;
127 memcpy(__get_dynamic_array(buf), buf, buf_len); 129 memcpy(__get_dynamic_array(buf), buf, buf_len);
128 ), 130 ),
129 131
130 TP_printk( 132 TP_printk(
131 "id %d len %zu", 133 "id %d len %zu ret %d",
132 __entry->id, 134 __entry->id,
133 __entry->buf_len 135 __entry->buf_len,
136 __entry->ret
134 ) 137 )
135); 138);
136 139
@@ -158,6 +161,27 @@ TRACE_EVENT(ath10k_wmi_event,
158 ) 161 )
159); 162);
160 163
164TRACE_EVENT(ath10k_htt_stats,
165 TP_PROTO(void *buf, size_t buf_len),
166
167 TP_ARGS(buf, buf_len),
168
169 TP_STRUCT__entry(
170 __field(size_t, buf_len)
171 __dynamic_array(u8, buf, buf_len)
172 ),
173
174 TP_fast_assign(
175 __entry->buf_len = buf_len;
176 memcpy(__get_dynamic_array(buf), buf, buf_len);
177 ),
178
179 TP_printk(
180 "len %zu",
181 __entry->buf_len
182 )
183);
184
161#endif /* _TRACE_H_ || TRACE_HEADER_MULTI_READ*/ 185#endif /* _TRACE_H_ || TRACE_HEADER_MULTI_READ*/
162 186
163/* we don't want to use include/trace/events */ 187/* 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 68b6faefd1d8..5ae373a1e294 100644
--- a/drivers/net/wireless/ath/ath10k/txrx.c
+++ b/drivers/net/wireless/ath/ath10k/txrx.c
@@ -44,40 +44,39 @@ out:
44 spin_unlock_bh(&ar->data_lock); 44 spin_unlock_bh(&ar->data_lock);
45} 45}
46 46
47void ath10k_txrx_tx_unref(struct ath10k_htt *htt, struct sk_buff *txdesc) 47void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
48 const struct htt_tx_done *tx_done)
48{ 49{
49 struct device *dev = htt->ar->dev; 50 struct device *dev = htt->ar->dev;
50 struct ieee80211_tx_info *info; 51 struct ieee80211_tx_info *info;
51 struct sk_buff *txfrag = ATH10K_SKB_CB(txdesc)->htt.txfrag; 52 struct ath10k_skb_cb *skb_cb;
52 struct sk_buff *msdu = ATH10K_SKB_CB(txdesc)->htt.msdu; 53 struct sk_buff *msdu;
53 int ret; 54 int ret;
54 55
55 if (ATH10K_SKB_CB(txdesc)->htt.refcount == 0) 56 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion msdu_id %u discard %d no_ack %d\n",
56 return; 57 tx_done->msdu_id, !!tx_done->discard, !!tx_done->no_ack);
57
58 ATH10K_SKB_CB(txdesc)->htt.refcount--;
59 58
60 if (ATH10K_SKB_CB(txdesc)->htt.refcount > 0) 59 if (tx_done->msdu_id >= htt->max_num_pending_tx) {
60 ath10k_warn("warning: msdu_id %d too big, ignoring\n",
61 tx_done->msdu_id);
61 return; 62 return;
62
63 if (txfrag) {
64 ret = ath10k_skb_unmap(dev, txfrag);
65 if (ret)
66 ath10k_warn("txfrag unmap failed (%d)\n", ret);
67
68 dev_kfree_skb_any(txfrag);
69 } 63 }
70 64
65 msdu = htt->pending_tx[tx_done->msdu_id];
66 skb_cb = ATH10K_SKB_CB(msdu);
67
71 ret = ath10k_skb_unmap(dev, msdu); 68 ret = ath10k_skb_unmap(dev, msdu);
72 if (ret) 69 if (ret)
73 ath10k_warn("data skb unmap failed (%d)\n", ret); 70 ath10k_warn("data skb unmap failed (%d)\n", ret);
74 71
72 if (skb_cb->htt.frag_len)
73 skb_pull(msdu, skb_cb->htt.frag_len + skb_cb->htt.pad_len);
74
75 ath10k_report_offchan_tx(htt->ar, msdu); 75 ath10k_report_offchan_tx(htt->ar, msdu);
76 76
77 info = IEEE80211_SKB_CB(msdu); 77 info = IEEE80211_SKB_CB(msdu);
78 memset(&info->status, 0, sizeof(info->status));
79 78
80 if (ATH10K_SKB_CB(txdesc)->htt.discard) { 79 if (tx_done->discard) {
81 ieee80211_free_txskb(htt->ar->hw, msdu); 80 ieee80211_free_txskb(htt->ar->hw, msdu);
82 goto exit; 81 goto exit;
83 } 82 }
@@ -85,7 +84,7 @@ void ath10k_txrx_tx_unref(struct ath10k_htt *htt, struct sk_buff *txdesc)
85 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 84 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
86 info->flags |= IEEE80211_TX_STAT_ACK; 85 info->flags |= IEEE80211_TX_STAT_ACK;
87 86
88 if (ATH10K_SKB_CB(txdesc)->htt.no_ack) 87 if (tx_done->no_ack)
89 info->flags &= ~IEEE80211_TX_STAT_ACK; 88 info->flags &= ~IEEE80211_TX_STAT_ACK;
90 89
91 ieee80211_tx_status(htt->ar->hw, msdu); 90 ieee80211_tx_status(htt->ar->hw, msdu);
@@ -93,36 +92,12 @@ void ath10k_txrx_tx_unref(struct ath10k_htt *htt, struct sk_buff *txdesc)
93 92
94exit: 93exit:
95 spin_lock_bh(&htt->tx_lock); 94 spin_lock_bh(&htt->tx_lock);
96 htt->pending_tx[ATH10K_SKB_CB(txdesc)->htt.msdu_id] = NULL; 95 htt->pending_tx[tx_done->msdu_id] = NULL;
97 ath10k_htt_tx_free_msdu_id(htt, ATH10K_SKB_CB(txdesc)->htt.msdu_id); 96 ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
98 __ath10k_htt_tx_dec_pending(htt); 97 __ath10k_htt_tx_dec_pending(htt);
99 if (bitmap_empty(htt->used_msdu_ids, htt->max_num_pending_tx)) 98 if (htt->num_pending_tx == 0)
100 wake_up(&htt->empty_tx_wq); 99 wake_up(&htt->empty_tx_wq);
101 spin_unlock_bh(&htt->tx_lock); 100 spin_unlock_bh(&htt->tx_lock);
102
103 dev_kfree_skb_any(txdesc);
104}
105
106void ath10k_txrx_tx_completed(struct ath10k_htt *htt,
107 const struct htt_tx_done *tx_done)
108{
109 struct sk_buff *txdesc;
110
111 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion msdu_id %u discard %d no_ack %d\n",
112 tx_done->msdu_id, !!tx_done->discard, !!tx_done->no_ack);
113
114 if (tx_done->msdu_id >= htt->max_num_pending_tx) {
115 ath10k_warn("warning: msdu_id %d too big, ignoring\n",
116 tx_done->msdu_id);
117 return;
118 }
119
120 txdesc = htt->pending_tx[tx_done->msdu_id];
121
122 ATH10K_SKB_CB(txdesc)->htt.discard = tx_done->discard;
123 ATH10K_SKB_CB(txdesc)->htt.no_ack = tx_done->no_ack;
124
125 ath10k_txrx_tx_unref(htt, txdesc);
126} 101}
127 102
128static const u8 rx_legacy_rate_idx[] = { 103static const u8 rx_legacy_rate_idx[] = {
@@ -293,6 +268,8 @@ void ath10k_process_rx(struct ath10k *ar, struct htt_rx_info *info)
293 status->vht_nss, 268 status->vht_nss,
294 status->freq, 269 status->freq,
295 status->band); 270 status->band);
271 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "rx skb: ",
272 info->skb->data, info->skb->len);
296 273
297 ieee80211_rx(ar->hw, info->skb); 274 ieee80211_rx(ar->hw, info->skb);
298} 275}
diff --git a/drivers/net/wireless/ath/ath10k/txrx.h b/drivers/net/wireless/ath/ath10k/txrx.h
index e78632a76df7..356dc9c04c9e 100644
--- a/drivers/net/wireless/ath/ath10k/txrx.h
+++ b/drivers/net/wireless/ath/ath10k/txrx.h
@@ -19,9 +19,8 @@
19 19
20#include "htt.h" 20#include "htt.h"
21 21
22void ath10k_txrx_tx_unref(struct ath10k_htt *htt, struct sk_buff *txdesc); 22void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
23void ath10k_txrx_tx_completed(struct ath10k_htt *htt, 23 const struct htt_tx_done *tx_done);
24 const struct htt_tx_done *tx_done);
25void ath10k_process_rx(struct ath10k *ar, struct htt_rx_info *info); 24void ath10k_process_rx(struct ath10k *ar, struct htt_rx_info *info);
26 25
27struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id, 26struct ath10k_peer *ath10k_peer_find(struct ath10k *ar, int vdev_id,
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index 48d44e7f386c..33cb19eb3d89 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -23,30 +23,6 @@
23#include "wmi.h" 23#include "wmi.h"
24#include "mac.h" 24#include "mac.h"
25 25
26void ath10k_wmi_flush_tx(struct ath10k *ar)
27{
28 int ret;
29
30 lockdep_assert_held(&ar->conf_mutex);
31
32 if (ar->state == ATH10K_STATE_WEDGED) {
33 ath10k_warn("wmi flush skipped - device is wedged anyway\n");
34 return;
35 }
36
37 ret = wait_event_timeout(ar->wmi.wq,
38 atomic_read(&ar->wmi.pending_tx_count) == 0,
39 5*HZ);
40 if (atomic_read(&ar->wmi.pending_tx_count) == 0)
41 return;
42
43 if (ret == 0)
44 ret = -ETIMEDOUT;
45
46 if (ret < 0)
47 ath10k_warn("wmi flush failed (%d)\n", ret);
48}
49
50int ath10k_wmi_wait_for_service_ready(struct ath10k *ar) 26int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
51{ 27{
52 int ret; 28 int ret;
@@ -85,18 +61,14 @@ static struct sk_buff *ath10k_wmi_alloc_skb(u32 len)
85static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb) 61static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
86{ 62{
87 dev_kfree_skb(skb); 63 dev_kfree_skb(skb);
88
89 if (atomic_sub_return(1, &ar->wmi.pending_tx_count) == 0)
90 wake_up(&ar->wmi.wq);
91} 64}
92 65
93/* WMI command API */ 66static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
94static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, 67 enum wmi_cmd_id cmd_id)
95 enum wmi_cmd_id cmd_id)
96{ 68{
97 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb); 69 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
98 struct wmi_cmd_hdr *cmd_hdr; 70 struct wmi_cmd_hdr *cmd_hdr;
99 int status; 71 int ret;
100 u32 cmd = 0; 72 u32 cmd = 0;
101 73
102 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL) 74 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
@@ -107,25 +79,87 @@ static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
107 cmd_hdr = (struct wmi_cmd_hdr *)skb->data; 79 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
108 cmd_hdr->cmd_id = __cpu_to_le32(cmd); 80 cmd_hdr->cmd_id = __cpu_to_le32(cmd);
109 81
110 if (atomic_add_return(1, &ar->wmi.pending_tx_count) >
111 WMI_MAX_PENDING_TX_COUNT) {
112 /* avoid using up memory when FW hangs */
113 atomic_dec(&ar->wmi.pending_tx_count);
114 return -EBUSY;
115 }
116
117 memset(skb_cb, 0, sizeof(*skb_cb)); 82 memset(skb_cb, 0, sizeof(*skb_cb));
83 ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
84 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len, ret);
118 85
119 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len); 86 if (ret)
87 goto err_pull;
120 88
121 status = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb); 89 return 0;
122 if (status) { 90
91err_pull:
92 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
93 return ret;
94}
95
96static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
97{
98 struct wmi_bcn_tx_arg arg = {0};
99 int ret;
100
101 lockdep_assert_held(&arvif->ar->data_lock);
102
103 if (arvif->beacon == NULL)
104 return;
105
106 arg.vdev_id = arvif->vdev_id;
107 arg.tx_rate = 0;
108 arg.tx_power = 0;
109 arg.bcn = arvif->beacon->data;
110 arg.bcn_len = arvif->beacon->len;
111
112 ret = ath10k_wmi_beacon_send_nowait(arvif->ar, &arg);
113 if (ret)
114 return;
115
116 dev_kfree_skb_any(arvif->beacon);
117 arvif->beacon = NULL;
118}
119
120static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
121 struct ieee80211_vif *vif)
122{
123 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
124
125 ath10k_wmi_tx_beacon_nowait(arvif);
126}
127
128static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
129{
130 spin_lock_bh(&ar->data_lock);
131 ieee80211_iterate_active_interfaces_atomic(ar->hw,
132 IEEE80211_IFACE_ITER_NORMAL,
133 ath10k_wmi_tx_beacons_iter,
134 NULL);
135 spin_unlock_bh(&ar->data_lock);
136}
137
138static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
139{
140 /* try to send pending beacons first. they take priority */
141 ath10k_wmi_tx_beacons_nowait(ar);
142
143 wake_up(&ar->wmi.tx_credits_wq);
144}
145
146static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
147 enum wmi_cmd_id cmd_id)
148{
149 int ret = -EINVAL;
150
151 wait_event_timeout(ar->wmi.tx_credits_wq, ({
152 /* try to send pending beacons first. they take priority */
153 ath10k_wmi_tx_beacons_nowait(ar);
154
155 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
156 (ret != -EAGAIN);
157 }), 3*HZ);
158
159 if (ret)
123 dev_kfree_skb_any(skb); 160 dev_kfree_skb_any(skb);
124 atomic_dec(&ar->wmi.pending_tx_count);
125 return status;
126 }
127 161
128 return 0; 162 return ret;
129} 163}
130 164
131static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb) 165static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
@@ -315,7 +349,9 @@ static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
315 349
316static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb) 350static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
317{ 351{
318 struct wmi_mgmt_rx_event *event = (struct wmi_mgmt_rx_event *)skb->data; 352 struct wmi_mgmt_rx_event_v1 *ev_v1;
353 struct wmi_mgmt_rx_event_v2 *ev_v2;
354 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
319 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 355 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
320 struct ieee80211_hdr *hdr; 356 struct ieee80211_hdr *hdr;
321 u32 rx_status; 357 u32 rx_status;
@@ -325,13 +361,24 @@ static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
325 u32 rate; 361 u32 rate;
326 u32 buf_len; 362 u32 buf_len;
327 u16 fc; 363 u16 fc;
364 int pull_len;
365
366 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
367 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
368 ev_hdr = &ev_v2->hdr.v1;
369 pull_len = sizeof(*ev_v2);
370 } else {
371 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
372 ev_hdr = &ev_v1->hdr;
373 pull_len = sizeof(*ev_v1);
374 }
328 375
329 channel = __le32_to_cpu(event->hdr.channel); 376 channel = __le32_to_cpu(ev_hdr->channel);
330 buf_len = __le32_to_cpu(event->hdr.buf_len); 377 buf_len = __le32_to_cpu(ev_hdr->buf_len);
331 rx_status = __le32_to_cpu(event->hdr.status); 378 rx_status = __le32_to_cpu(ev_hdr->status);
332 snr = __le32_to_cpu(event->hdr.snr); 379 snr = __le32_to_cpu(ev_hdr->snr);
333 phy_mode = __le32_to_cpu(event->hdr.phy_mode); 380 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
334 rate = __le32_to_cpu(event->hdr.rate); 381 rate = __le32_to_cpu(ev_hdr->rate);
335 382
336 memset(status, 0, sizeof(*status)); 383 memset(status, 0, sizeof(*status));
337 384
@@ -358,7 +405,7 @@ static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
358 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR; 405 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
359 status->rate_idx = get_rate_idx(rate, status->band); 406 status->rate_idx = get_rate_idx(rate, status->band);
360 407
361 skb_pull(skb, sizeof(event->hdr)); 408 skb_pull(skb, pull_len);
362 409
363 hdr = (struct ieee80211_hdr *)skb->data; 410 hdr = (struct ieee80211_hdr *)skb->data;
364 fc = le16_to_cpu(hdr->frame_control); 411 fc = le16_to_cpu(hdr->frame_control);
@@ -734,10 +781,8 @@ static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
734 int i = -1; 781 int i = -1;
735 struct wmi_bcn_info *bcn_info; 782 struct wmi_bcn_info *bcn_info;
736 struct ath10k_vif *arvif; 783 struct ath10k_vif *arvif;
737 struct wmi_bcn_tx_arg arg;
738 struct sk_buff *bcn; 784 struct sk_buff *bcn;
739 int vdev_id = 0; 785 int vdev_id = 0;
740 int ret;
741 786
742 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n"); 787 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
743 788
@@ -794,17 +839,17 @@ static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
794 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info); 839 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
795 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info); 840 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
796 841
797 arg.vdev_id = arvif->vdev_id; 842 spin_lock_bh(&ar->data_lock);
798 arg.tx_rate = 0; 843 if (arvif->beacon) {
799 arg.tx_power = 0; 844 ath10k_warn("SWBA overrun on vdev %d\n",
800 arg.bcn = bcn->data; 845 arvif->vdev_id);
801 arg.bcn_len = bcn->len; 846 dev_kfree_skb_any(arvif->beacon);
847 }
802 848
803 ret = ath10k_wmi_beacon_send(ar, &arg); 849 arvif->beacon = bcn;
804 if (ret)
805 ath10k_warn("could not send beacon (%d)\n", ret);
806 850
807 dev_kfree_skb_any(bcn); 851 ath10k_wmi_tx_beacon_nowait(arvif);
852 spin_unlock_bh(&ar->data_lock);
808 } 853 }
809} 854}
810 855
@@ -943,6 +988,9 @@ static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
943 ar->phy_capability = __le32_to_cpu(ev->phy_capability); 988 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
944 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains); 989 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
945 990
991 if (ar->fw_version_build > 636)
992 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
993
946 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) { 994 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
947 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n", 995 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
948 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM); 996 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
@@ -1007,7 +1055,7 @@ static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
1007 return 0; 1055 return 0;
1008} 1056}
1009 1057
1010static void ath10k_wmi_event_process(struct ath10k *ar, struct sk_buff *skb) 1058static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
1011{ 1059{
1012 struct wmi_cmd_hdr *cmd_hdr; 1060 struct wmi_cmd_hdr *cmd_hdr;
1013 enum wmi_event_id id; 1061 enum wmi_event_id id;
@@ -1126,64 +1174,18 @@ static void ath10k_wmi_event_process(struct ath10k *ar, struct sk_buff *skb)
1126 dev_kfree_skb(skb); 1174 dev_kfree_skb(skb);
1127} 1175}
1128 1176
1129static void ath10k_wmi_event_work(struct work_struct *work)
1130{
1131 struct ath10k *ar = container_of(work, struct ath10k,
1132 wmi.wmi_event_work);
1133 struct sk_buff *skb;
1134
1135 for (;;) {
1136 skb = skb_dequeue(&ar->wmi.wmi_event_list);
1137 if (!skb)
1138 break;
1139
1140 ath10k_wmi_event_process(ar, skb);
1141 }
1142}
1143
1144static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
1145{
1146 struct wmi_cmd_hdr *cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
1147 enum wmi_event_id event_id;
1148
1149 event_id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
1150
1151 /* some events require to be handled ASAP
1152 * thus can't be defered to a worker thread */
1153 switch (event_id) {
1154 case WMI_HOST_SWBA_EVENTID:
1155 case WMI_MGMT_RX_EVENTID:
1156 ath10k_wmi_event_process(ar, skb);
1157 return;
1158 default:
1159 break;
1160 }
1161
1162 skb_queue_tail(&ar->wmi.wmi_event_list, skb);
1163 queue_work(ar->workqueue, &ar->wmi.wmi_event_work);
1164}
1165
1166/* WMI Initialization functions */ 1177/* WMI Initialization functions */
1167int ath10k_wmi_attach(struct ath10k *ar) 1178int ath10k_wmi_attach(struct ath10k *ar)
1168{ 1179{
1169 init_completion(&ar->wmi.service_ready); 1180 init_completion(&ar->wmi.service_ready);
1170 init_completion(&ar->wmi.unified_ready); 1181 init_completion(&ar->wmi.unified_ready);
1171 init_waitqueue_head(&ar->wmi.wq); 1182 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1172
1173 skb_queue_head_init(&ar->wmi.wmi_event_list);
1174 INIT_WORK(&ar->wmi.wmi_event_work, ath10k_wmi_event_work);
1175 1183
1176 return 0; 1184 return 0;
1177} 1185}
1178 1186
1179void ath10k_wmi_detach(struct ath10k *ar) 1187void ath10k_wmi_detach(struct ath10k *ar)
1180{ 1188{
1181 /* HTC should've drained the packets already */
1182 if (WARN_ON(atomic_read(&ar->wmi.pending_tx_count) > 0))
1183 ath10k_warn("there are still pending packets\n");
1184
1185 cancel_work_sync(&ar->wmi.wmi_event_work);
1186 skb_queue_purge(&ar->wmi.wmi_event_list);
1187} 1189}
1188 1190
1189int ath10k_wmi_connect_htc_service(struct ath10k *ar) 1191int ath10k_wmi_connect_htc_service(struct ath10k *ar)
@@ -1198,6 +1200,7 @@ int ath10k_wmi_connect_htc_service(struct ath10k *ar)
1198 /* these fields are the same for all service endpoints */ 1200 /* these fields are the same for all service endpoints */
1199 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete; 1201 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
1200 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx; 1202 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
1203 conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
1201 1204
1202 /* connect to control service */ 1205 /* connect to control service */
1203 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL; 1206 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
@@ -2108,7 +2111,8 @@ int ath10k_wmi_peer_assoc(struct ath10k *ar,
2108 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_ASSOC_CMDID); 2111 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_ASSOC_CMDID);
2109} 2112}
2110 2113
2111int ath10k_wmi_beacon_send(struct ath10k *ar, const struct wmi_bcn_tx_arg *arg) 2114int ath10k_wmi_beacon_send_nowait(struct ath10k *ar,
2115 const struct wmi_bcn_tx_arg *arg)
2112{ 2116{
2113 struct wmi_bcn_tx_cmd *cmd; 2117 struct wmi_bcn_tx_cmd *cmd;
2114 struct sk_buff *skb; 2118 struct sk_buff *skb;
@@ -2124,7 +2128,7 @@ int ath10k_wmi_beacon_send(struct ath10k *ar, const struct wmi_bcn_tx_arg *arg)
2124 cmd->hdr.bcn_len = __cpu_to_le32(arg->bcn_len); 2128 cmd->hdr.bcn_len = __cpu_to_le32(arg->bcn_len);
2125 memcpy(cmd->bcn, arg->bcn, arg->bcn_len); 2129 memcpy(cmd->bcn, arg->bcn, arg->bcn_len);
2126 2130
2127 return ath10k_wmi_cmd_send(ar, skb, WMI_BCN_TX_CMDID); 2131 return ath10k_wmi_cmd_send_nowait(ar, skb, WMI_BCN_TX_CMDID);
2128} 2132}
2129 2133
2130static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params, 2134static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
index 2c5a4f8daf2e..2c52c23107dd 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.h
+++ b/drivers/net/wireless/ath/ath10k/wmi.h
@@ -508,6 +508,48 @@ enum wmi_phy_mode {
508 MODE_MAX = 14 508 MODE_MAX = 14
509}; 509};
510 510
511static inline const char *ath10k_wmi_phymode_str(enum wmi_phy_mode mode)
512{
513 switch (mode) {
514 case MODE_11A:
515 return "11a";
516 case MODE_11G:
517 return "11g";
518 case MODE_11B:
519 return "11b";
520 case MODE_11GONLY:
521 return "11gonly";
522 case MODE_11NA_HT20:
523 return "11na-ht20";
524 case MODE_11NG_HT20:
525 return "11ng-ht20";
526 case MODE_11NA_HT40:
527 return "11na-ht40";
528 case MODE_11NG_HT40:
529 return "11ng-ht40";
530 case MODE_11AC_VHT20:
531 return "11ac-vht20";
532 case MODE_11AC_VHT40:
533 return "11ac-vht40";
534 case MODE_11AC_VHT80:
535 return "11ac-vht80";
536 case MODE_11AC_VHT20_2G:
537 return "11ac-vht20-2g";
538 case MODE_11AC_VHT40_2G:
539 return "11ac-vht40-2g";
540 case MODE_11AC_VHT80_2G:
541 return "11ac-vht80-2g";
542 case MODE_UNKNOWN:
543 /* skip */
544 break;
545
546 /* no default handler to allow compiler to check that the
547 * enum is fully handled */
548 };
549
550 return "<unknown>";
551}
552
511#define WMI_CHAN_LIST_TAG 0x1 553#define WMI_CHAN_LIST_TAG 0x1
512#define WMI_SSID_LIST_TAG 0x2 554#define WMI_SSID_LIST_TAG 0x2
513#define WMI_BSSID_LIST_TAG 0x3 555#define WMI_BSSID_LIST_TAG 0x3
@@ -763,14 +805,6 @@ struct wmi_service_ready_event {
763 struct wlan_host_mem_req mem_reqs[1]; 805 struct wlan_host_mem_req mem_reqs[1];
764} __packed; 806} __packed;
765 807
766/*
767 * status consists of upper 16 bits fo int status and lower 16 bits of
768 * module ID that retuned status
769 */
770#define WLAN_INIT_STATUS_SUCCESS 0x0
771#define WLAN_GET_INIT_STATUS_REASON(status) ((status) & 0xffff)
772#define WLAN_GET_INIT_STATUS_MODULE_ID(status) (((status) >> 16) & 0xffff)
773
774#define WMI_SERVICE_READY_TIMEOUT_HZ (5*HZ) 808#define WMI_SERVICE_READY_TIMEOUT_HZ (5*HZ)
775#define WMI_UNIFIED_READY_TIMEOUT_HZ (5*HZ) 809#define WMI_UNIFIED_READY_TIMEOUT_HZ (5*HZ)
776 810
@@ -1268,7 +1302,7 @@ struct wmi_scan_event {
1268 * good idea to pass all the fields in the RX status 1302 * good idea to pass all the fields in the RX status
1269 * descriptor up to the host. 1303 * descriptor up to the host.
1270 */ 1304 */
1271struct wmi_mgmt_rx_hdr { 1305struct wmi_mgmt_rx_hdr_v1 {
1272 __le32 channel; 1306 __le32 channel;
1273 __le32 snr; 1307 __le32 snr;
1274 __le32 rate; 1308 __le32 rate;
@@ -1277,8 +1311,18 @@ struct wmi_mgmt_rx_hdr {
1277 __le32 status; /* %WMI_RX_STATUS_ */ 1311 __le32 status; /* %WMI_RX_STATUS_ */
1278} __packed; 1312} __packed;
1279 1313
1280struct wmi_mgmt_rx_event { 1314struct wmi_mgmt_rx_hdr_v2 {
1281 struct wmi_mgmt_rx_hdr hdr; 1315 struct wmi_mgmt_rx_hdr_v1 v1;
1316 __le32 rssi_ctl[4];
1317} __packed;
1318
1319struct wmi_mgmt_rx_event_v1 {
1320 struct wmi_mgmt_rx_hdr_v1 hdr;
1321 u8 buf[0];
1322} __packed;
1323
1324struct wmi_mgmt_rx_event_v2 {
1325 struct wmi_mgmt_rx_hdr_v2 hdr;
1282 u8 buf[0]; 1326 u8 buf[0];
1283} __packed; 1327} __packed;
1284 1328
@@ -3000,7 +3044,6 @@ struct wmi_force_fw_hang_cmd {
3000 3044
3001#define WMI_MAX_EVENT 0x1000 3045#define WMI_MAX_EVENT 0x1000
3002/* Maximum number of pending TXed WMI packets */ 3046/* Maximum number of pending TXed WMI packets */
3003#define WMI_MAX_PENDING_TX_COUNT 128
3004#define WMI_SKB_HEADROOM sizeof(struct wmi_cmd_hdr) 3047#define WMI_SKB_HEADROOM sizeof(struct wmi_cmd_hdr)
3005 3048
3006/* By default disable power save for IBSS */ 3049/* By default disable power save for IBSS */
@@ -3013,7 +3056,6 @@ int ath10k_wmi_attach(struct ath10k *ar);
3013void ath10k_wmi_detach(struct ath10k *ar); 3056void ath10k_wmi_detach(struct ath10k *ar);
3014int ath10k_wmi_wait_for_service_ready(struct ath10k *ar); 3057int ath10k_wmi_wait_for_service_ready(struct ath10k *ar);
3015int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar); 3058int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar);
3016void ath10k_wmi_flush_tx(struct ath10k *ar);
3017 3059
3018int ath10k_wmi_connect_htc_service(struct ath10k *ar); 3060int ath10k_wmi_connect_htc_service(struct ath10k *ar);
3019int ath10k_wmi_pdev_set_channel(struct ath10k *ar, 3061int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
@@ -3066,7 +3108,8 @@ int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
3066 enum wmi_ap_ps_peer_param param_id, u32 value); 3108 enum wmi_ap_ps_peer_param param_id, u32 value);
3067int ath10k_wmi_scan_chan_list(struct ath10k *ar, 3109int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3068 const struct wmi_scan_chan_list_arg *arg); 3110 const struct wmi_scan_chan_list_arg *arg);
3069int ath10k_wmi_beacon_send(struct ath10k *ar, const struct wmi_bcn_tx_arg *arg); 3111int ath10k_wmi_beacon_send_nowait(struct ath10k *ar,
3112 const struct wmi_bcn_tx_arg *arg);
3070int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar, 3113int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
3071 const struct wmi_pdev_set_wmm_params_arg *arg); 3114 const struct wmi_pdev_set_wmm_params_arg *arg);
3072int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id); 3115int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id);
diff --git a/drivers/net/wireless/ath/ath5k/ahb.c b/drivers/net/wireless/ath/ath5k/ahb.c
index e9bc9e616b69..79bffe165cab 100644
--- a/drivers/net/wireless/ath/ath5k/ahb.c
+++ b/drivers/net/wireless/ath/ath5k/ahb.c
@@ -37,12 +37,9 @@ ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
37{ 37{
38 struct ath5k_hw *ah = common->priv; 38 struct ath5k_hw *ah = common->priv;
39 struct platform_device *pdev = to_platform_device(ah->dev); 39 struct platform_device *pdev = to_platform_device(ah->dev);
40 struct ar231x_board_config *bcfg = pdev->dev.platform_data; 40 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
41 u16 *eeprom, *eeprom_end; 41 u16 *eeprom, *eeprom_end;
42 42
43
44
45 bcfg = pdev->dev.platform_data;
46 eeprom = (u16 *) bcfg->radio; 43 eeprom = (u16 *) bcfg->radio;
47 eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ; 44 eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
48 45
@@ -57,7 +54,7 @@ ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
57int ath5k_hw_read_srev(struct ath5k_hw *ah) 54int ath5k_hw_read_srev(struct ath5k_hw *ah)
58{ 55{
59 struct platform_device *pdev = to_platform_device(ah->dev); 56 struct platform_device *pdev = to_platform_device(ah->dev);
60 struct ar231x_board_config *bcfg = pdev->dev.platform_data; 57 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
61 ah->ah_mac_srev = bcfg->devid; 58 ah->ah_mac_srev = bcfg->devid;
62 return 0; 59 return 0;
63} 60}
@@ -65,7 +62,7 @@ int ath5k_hw_read_srev(struct ath5k_hw *ah)
65static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac) 62static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
66{ 63{
67 struct platform_device *pdev = to_platform_device(ah->dev); 64 struct platform_device *pdev = to_platform_device(ah->dev);
68 struct ar231x_board_config *bcfg = pdev->dev.platform_data; 65 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
69 u8 *cfg_mac; 66 u8 *cfg_mac;
70 67
71 if (to_platform_device(ah->dev)->id == 0) 68 if (to_platform_device(ah->dev)->id == 0)
@@ -87,7 +84,7 @@ static const struct ath_bus_ops ath_ahb_bus_ops = {
87/*Initialization*/ 84/*Initialization*/
88static int ath_ahb_probe(struct platform_device *pdev) 85static int ath_ahb_probe(struct platform_device *pdev)
89{ 86{
90 struct ar231x_board_config *bcfg = pdev->dev.platform_data; 87 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
91 struct ath5k_hw *ah; 88 struct ath5k_hw *ah;
92 struct ieee80211_hw *hw; 89 struct ieee80211_hw *hw;
93 struct resource *res; 90 struct resource *res;
@@ -96,7 +93,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
96 int ret = 0; 93 int ret = 0;
97 u32 reg; 94 u32 reg;
98 95
99 if (!pdev->dev.platform_data) { 96 if (!dev_get_platdata(&pdev->dev)) {
100 dev_err(&pdev->dev, "no platform data specified\n"); 97 dev_err(&pdev->dev, "no platform data specified\n");
101 ret = -EINVAL; 98 ret = -EINVAL;
102 goto err_out; 99 goto err_out;
@@ -193,7 +190,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
193 190
194static int ath_ahb_remove(struct platform_device *pdev) 191static int ath_ahb_remove(struct platform_device *pdev)
195{ 192{
196 struct ar231x_board_config *bcfg = pdev->dev.platform_data; 193 struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
197 struct ieee80211_hw *hw = platform_get_drvdata(pdev); 194 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
198 struct ath5k_hw *ah; 195 struct ath5k_hw *ah;
199 u32 reg; 196 u32 reg;
diff --git a/drivers/net/wireless/ath/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c
index 072e4b531067..2dff2765769b 100644
--- a/drivers/net/wireless/ath/ath9k/ahb.c
+++ b/drivers/net/wireless/ath/ath9k/ahb.c
@@ -54,7 +54,7 @@ static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
54 struct platform_device *pdev = to_platform_device(sc->dev); 54 struct platform_device *pdev = to_platform_device(sc->dev);
55 struct ath9k_platform_data *pdata; 55 struct ath9k_platform_data *pdata;
56 56
57 pdata = (struct ath9k_platform_data *) pdev->dev.platform_data; 57 pdata = dev_get_platdata(&pdev->dev);
58 if (off >= (ARRAY_SIZE(pdata->eeprom_data))) { 58 if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
59 ath_err(common, 59 ath_err(common,
60 "%s: flash read failed, offset %08x is out of range\n", 60 "%s: flash read failed, offset %08x is out of range\n",
@@ -84,7 +84,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
84 struct ath_hw *ah; 84 struct ath_hw *ah;
85 char hw_name[64]; 85 char hw_name[64];
86 86
87 if (!pdev->dev.platform_data) { 87 if (!dev_get_platdata(&pdev->dev)) {
88 dev_err(&pdev->dev, "no platform data specified\n"); 88 dev_err(&pdev->dev, "no platform data specified\n");
89 return -EINVAL; 89 return -EINVAL;
90 } 90 }
diff --git a/drivers/net/wireless/ath/ath9k/antenna.c b/drivers/net/wireless/ath/ath9k/antenna.c
index dd1cc73d7946..bd048cc69a33 100644
--- a/drivers/net/wireless/ath/ath9k/antenna.c
+++ b/drivers/net/wireless/ath/ath9k/antenna.c
@@ -332,7 +332,7 @@ static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
332 } 332 }
333 333
334 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 + 334 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
335 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA) 335 div_ant_conf->lna1_lna2_switch_delta)
336 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2; 336 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
337 else 337 else
338 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1; 338 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
@@ -554,42 +554,22 @@ static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf,
554 ant_conf->fast_div_bias = 0x1; 554 ant_conf->fast_div_bias = 0x1;
555 break; 555 break;
556 case 0x10: /* LNA2 A-B */ 556 case 0x10: /* LNA2 A-B */
557 if ((antcomb->scan == 0) && 557 ant_conf->fast_div_bias = 0x2;
558 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)) {
559 ant_conf->fast_div_bias = 0x3f;
560 } else {
561 ant_conf->fast_div_bias = 0x1;
562 }
563 break; 558 break;
564 case 0x12: /* LNA2 LNA1 */ 559 case 0x12: /* LNA2 LNA1 */
565 ant_conf->fast_div_bias = 0x39; 560 ant_conf->fast_div_bias = 0x3f;
566 break; 561 break;
567 case 0x13: /* LNA2 A+B */ 562 case 0x13: /* LNA2 A+B */
568 if ((antcomb->scan == 0) && 563 ant_conf->fast_div_bias = 0x2;
569 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)) {
570 ant_conf->fast_div_bias = 0x3f;
571 } else {
572 ant_conf->fast_div_bias = 0x1;
573 }
574 break; 564 break;
575 case 0x20: /* LNA1 A-B */ 565 case 0x20: /* LNA1 A-B */
576 if ((antcomb->scan == 0) && 566 ant_conf->fast_div_bias = 0x3;
577 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)) {
578 ant_conf->fast_div_bias = 0x3f;
579 } else {
580 ant_conf->fast_div_bias = 0x4;
581 }
582 break; 567 break;
583 case 0x21: /* LNA1 LNA2 */ 568 case 0x21: /* LNA1 LNA2 */
584 ant_conf->fast_div_bias = 0x6; 569 ant_conf->fast_div_bias = 0x3;
585 break; 570 break;
586 case 0x23: /* LNA1 A+B */ 571 case 0x23: /* LNA1 A+B */
587 if ((antcomb->scan == 0) && 572 ant_conf->fast_div_bias = 0x3;
588 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)) {
589 ant_conf->fast_div_bias = 0x3f;
590 } else {
591 ant_conf->fast_div_bias = 0x6;
592 }
593 break; 573 break;
594 case 0x30: /* A+B A-B */ 574 case 0x30: /* A+B A-B */
595 ant_conf->fast_div_bias = 0x1; 575 ant_conf->fast_div_bias = 0x1;
@@ -638,7 +618,7 @@ static void ath_ant_try_scan(struct ath_ant_comb *antcomb,
638 antcomb->rssi_sub = alt_rssi_avg; 618 antcomb->rssi_sub = alt_rssi_avg;
639 antcomb->scan = false; 619 antcomb->scan = false;
640 if (antcomb->rssi_lna2 > 620 if (antcomb->rssi_lna2 >
641 (antcomb->rssi_lna1 + ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) { 621 (antcomb->rssi_lna1 + conf->lna1_lna2_switch_delta)) {
642 /* use LNA2 as main LNA */ 622 /* use LNA2 as main LNA */
643 if ((antcomb->rssi_add > antcomb->rssi_lna1) && 623 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
644 (antcomb->rssi_add > antcomb->rssi_sub)) { 624 (antcomb->rssi_add > antcomb->rssi_sub)) {
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index 08656473c63e..cb6435e7c6f5 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -626,12 +626,11 @@ static void ar5008_hw_override_ini(struct ath_hw *ah,
626 if (AR_SREV_9287_11_OR_LATER(ah)) 626 if (AR_SREV_9287_11_OR_LATER(ah))
627 val = val & (~AR_PCU_MISC_MODE2_HWWAR2); 627 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
628 628
629 val |= AR_PCU_MISC_MODE2_CFP_IGNORE;
630
629 REG_WRITE(ah, AR_PCU_MISC_MODE2, val); 631 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
630 } 632 }
631 633
632 REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
633 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
634
635 if (AR_SREV_9280_20_OR_LATER(ah)) 634 if (AR_SREV_9280_20_OR_LATER(ah))
636 return; 635 return;
637 /* 636 /*
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_calib.c b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
index 9f589744a9f9..32376ad74011 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
@@ -671,7 +671,7 @@ static bool ar9002_hw_calibrate(struct ath_hw *ah,
671 671
672 nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF); 672 nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
673 if (ah->caldata) 673 if (ah->caldata)
674 nfcal_pending = ah->caldata->nfcal_pending; 674 nfcal_pending = test_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
675 675
676 if (currCal && !nfcal && 676 if (currCal && !nfcal &&
677 (currCal->calState == CAL_RUNNING || 677 (currCal->calState == CAL_RUNNING ||
@@ -861,7 +861,7 @@ static bool ar9002_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
861 ar9002_hw_pa_cal(ah, true); 861 ar9002_hw_pa_cal(ah, true);
862 862
863 if (ah->caldata) 863 if (ah->caldata)
864 ah->caldata->nfcal_pending = true; 864 set_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
865 865
866 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; 866 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
867 867
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_phy.c b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
index 1fc1fa955d44..17970d49d858 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
@@ -485,7 +485,7 @@ static void ar9002_hw_do_getnf(struct ath_hw *ah,
485 if (IS_CHAN_HT40(ah->curchan)) 485 if (IS_CHAN_HT40(ah->curchan))
486 nfarray[3] = sign_extend32(nf, 8); 486 nfarray[3] = sign_extend32(nf, 8);
487 487
488 if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) 488 if (!(ah->rxchainmask & BIT(1)))
489 return; 489 return;
490 490
491 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR); 491 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
@@ -532,6 +532,7 @@ static void ar9002_hw_antdiv_comb_conf_get(struct ath_hw *ah,
532 AR_PHY_9285_ANT_DIV_ALT_LNACONF_S; 532 AR_PHY_9285_ANT_DIV_ALT_LNACONF_S;
533 antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >> 533 antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >>
534 AR_PHY_9285_FAST_DIV_BIAS_S; 534 AR_PHY_9285_FAST_DIV_BIAS_S;
535 antconf->lna1_lna2_switch_delta = -1;
535 antconf->lna1_lna2_delta = -3; 536 antconf->lna1_lna2_delta = -3;
536 antconf->div_group = 0; 537 antconf->div_group = 0;
537} 538}
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index 6988e1d081f2..22934d3ca544 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -727,8 +727,12 @@ static void ar9003_hw_tx_iqcal_load_avg_2_passes(struct ath_hw *ah,
727 REG_RMW_FIELD(ah, AR_PHY_RX_IQCAL_CORR_B0, 727 REG_RMW_FIELD(ah, AR_PHY_RX_IQCAL_CORR_B0,
728 AR_PHY_RX_IQCAL_CORR_B0_LOOPBACK_IQCORR_EN, 0x1); 728 AR_PHY_RX_IQCAL_CORR_B0_LOOPBACK_IQCORR_EN, 0x1);
729 729
730 if (caldata) 730 if (caldata) {
731 caldata->done_txiqcal_once = is_reusable; 731 if (is_reusable)
732 set_bit(TXIQCAL_DONE, &caldata->cal_flags);
733 else
734 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
735 }
732 736
733 return; 737 return;
734} 738}
@@ -961,18 +965,44 @@ static void ar9003_hw_manual_peak_cal(struct ath_hw *ah, u8 chain, bool is_2g)
961} 965}
962 966
963static void ar9003_hw_do_manual_peak_cal(struct ath_hw *ah, 967static void ar9003_hw_do_manual_peak_cal(struct ath_hw *ah,
964 struct ath9k_channel *chan) 968 struct ath9k_channel *chan,
969 bool run_rtt_cal)
965{ 970{
971 struct ath9k_hw_cal_data *caldata = ah->caldata;
966 int i; 972 int i;
967 973
968 if (!AR_SREV_9462(ah) && !AR_SREV_9565(ah) && !AR_SREV_9485(ah)) 974 if (!AR_SREV_9462(ah) && !AR_SREV_9565(ah) && !AR_SREV_9485(ah))
969 return; 975 return;
970 976
977 if ((ah->caps.hw_caps & ATH9K_HW_CAP_RTT) && !run_rtt_cal)
978 return;
979
971 for (i = 0; i < AR9300_MAX_CHAINS; i++) { 980 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
972 if (!(ah->rxchainmask & (1 << i))) 981 if (!(ah->rxchainmask & (1 << i)))
973 continue; 982 continue;
974 ar9003_hw_manual_peak_cal(ah, i, IS_CHAN_2GHZ(chan)); 983 ar9003_hw_manual_peak_cal(ah, i, IS_CHAN_2GHZ(chan));
975 } 984 }
985
986 if (caldata)
987 set_bit(SW_PKDET_DONE, &caldata->cal_flags);
988
989 if ((ah->caps.hw_caps & ATH9K_HW_CAP_RTT) && caldata) {
990 if (IS_CHAN_2GHZ(chan)){
991 caldata->caldac[0] = REG_READ_FIELD(ah,
992 AR_PHY_65NM_RXRF_AGC(0),
993 AR_PHY_65NM_RXRF_AGC_AGC2G_CALDAC_OVR);
994 caldata->caldac[1] = REG_READ_FIELD(ah,
995 AR_PHY_65NM_RXRF_AGC(1),
996 AR_PHY_65NM_RXRF_AGC_AGC2G_CALDAC_OVR);
997 } else {
998 caldata->caldac[0] = REG_READ_FIELD(ah,
999 AR_PHY_65NM_RXRF_AGC(0),
1000 AR_PHY_65NM_RXRF_AGC_AGC5G_CALDAC_OVR);
1001 caldata->caldac[1] = REG_READ_FIELD(ah,
1002 AR_PHY_65NM_RXRF_AGC(1),
1003 AR_PHY_65NM_RXRF_AGC_AGC5G_CALDAC_OVR);
1004 }
1005 }
976} 1006}
977 1007
978static void ar9003_hw_cl_cal_post_proc(struct ath_hw *ah, bool is_reusable) 1008static void ar9003_hw_cl_cal_post_proc(struct ath_hw *ah, bool is_reusable)
@@ -990,7 +1020,7 @@ static void ar9003_hw_cl_cal_post_proc(struct ath_hw *ah, bool is_reusable)
990 txclcal_done = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & 1020 txclcal_done = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) &
991 AR_PHY_AGC_CONTROL_CLC_SUCCESS); 1021 AR_PHY_AGC_CONTROL_CLC_SUCCESS);
992 1022
993 if (caldata->done_txclcal_once) { 1023 if (test_bit(TXCLCAL_DONE, &caldata->cal_flags)) {
994 for (i = 0; i < AR9300_MAX_CHAINS; i++) { 1024 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
995 if (!(ah->txchainmask & (1 << i))) 1025 if (!(ah->txchainmask & (1 << i)))
996 continue; 1026 continue;
@@ -1006,7 +1036,7 @@ static void ar9003_hw_cl_cal_post_proc(struct ath_hw *ah, bool is_reusable)
1006 caldata->tx_clcal[i][j] = 1036 caldata->tx_clcal[i][j] =
1007 REG_READ(ah, CL_TAB_ENTRY(cl_idx[i])); 1037 REG_READ(ah, CL_TAB_ENTRY(cl_idx[i]));
1008 } 1038 }
1009 caldata->done_txclcal_once = true; 1039 set_bit(TXCLCAL_DONE, &caldata->cal_flags);
1010 } 1040 }
1011} 1041}
1012 1042
@@ -1019,6 +1049,7 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
1019 bool is_reusable = true, status = true; 1049 bool is_reusable = true, status = true;
1020 bool run_rtt_cal = false, run_agc_cal, sep_iq_cal = false; 1050 bool run_rtt_cal = false, run_agc_cal, sep_iq_cal = false;
1021 bool rtt = !!(ah->caps.hw_caps & ATH9K_HW_CAP_RTT); 1051 bool rtt = !!(ah->caps.hw_caps & ATH9K_HW_CAP_RTT);
1052 u32 rx_delay = 0;
1022 u32 agc_ctrl = 0, agc_supp_cals = AR_PHY_AGC_CONTROL_OFFSET_CAL | 1053 u32 agc_ctrl = 0, agc_supp_cals = AR_PHY_AGC_CONTROL_OFFSET_CAL |
1023 AR_PHY_AGC_CONTROL_FLTR_CAL | 1054 AR_PHY_AGC_CONTROL_FLTR_CAL |
1024 AR_PHY_AGC_CONTROL_PKDET_CAL; 1055 AR_PHY_AGC_CONTROL_PKDET_CAL;
@@ -1042,17 +1073,22 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
1042 ar9003_hw_rtt_clear_hist(ah); 1073 ar9003_hw_rtt_clear_hist(ah);
1043 } 1074 }
1044 1075
1045 if (rtt && !run_rtt_cal) { 1076 if (rtt) {
1046 agc_ctrl = REG_READ(ah, AR_PHY_AGC_CONTROL); 1077 if (!run_rtt_cal) {
1047 agc_supp_cals &= agc_ctrl; 1078 agc_ctrl = REG_READ(ah, AR_PHY_AGC_CONTROL);
1048 agc_ctrl &= ~(AR_PHY_AGC_CONTROL_OFFSET_CAL | 1079 agc_supp_cals &= agc_ctrl;
1049 AR_PHY_AGC_CONTROL_FLTR_CAL | 1080 agc_ctrl &= ~(AR_PHY_AGC_CONTROL_OFFSET_CAL |
1050 AR_PHY_AGC_CONTROL_PKDET_CAL); 1081 AR_PHY_AGC_CONTROL_FLTR_CAL |
1051 REG_WRITE(ah, AR_PHY_AGC_CONTROL, agc_ctrl); 1082 AR_PHY_AGC_CONTROL_PKDET_CAL);
1083 REG_WRITE(ah, AR_PHY_AGC_CONTROL, agc_ctrl);
1084 } else {
1085 if (ah->ah_flags & AH_FASTCC)
1086 run_agc_cal = true;
1087 }
1052 } 1088 }
1053 1089
1054 if (ah->enabled_cals & TX_CL_CAL) { 1090 if (ah->enabled_cals & TX_CL_CAL) {
1055 if (caldata && caldata->done_txclcal_once) 1091 if (caldata && test_bit(TXCLCAL_DONE, &caldata->cal_flags))
1056 REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, 1092 REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL,
1057 AR_PHY_CL_CAL_ENABLE); 1093 AR_PHY_CL_CAL_ENABLE);
1058 else { 1094 else {
@@ -1076,14 +1112,14 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
1076 * AGC calibration 1112 * AGC calibration
1077 */ 1113 */
1078 if (ah->enabled_cals & TX_IQ_ON_AGC_CAL) { 1114 if (ah->enabled_cals & TX_IQ_ON_AGC_CAL) {
1079 if (caldata && !caldata->done_txiqcal_once) 1115 if (caldata && !test_bit(TXIQCAL_DONE, &caldata->cal_flags))
1080 REG_SET_BIT(ah, AR_PHY_TX_IQCAL_CONTROL_0, 1116 REG_SET_BIT(ah, AR_PHY_TX_IQCAL_CONTROL_0,
1081 AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL); 1117 AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL);
1082 else 1118 else
1083 REG_CLR_BIT(ah, AR_PHY_TX_IQCAL_CONTROL_0, 1119 REG_CLR_BIT(ah, AR_PHY_TX_IQCAL_CONTROL_0,
1084 AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL); 1120 AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL);
1085 txiqcal_done = run_agc_cal = true; 1121 txiqcal_done = run_agc_cal = true;
1086 } else if (caldata && !caldata->done_txiqcal_once) { 1122 } else if (caldata && !test_bit(TXIQCAL_DONE, &caldata->cal_flags)) {
1087 run_agc_cal = true; 1123 run_agc_cal = true;
1088 sep_iq_cal = true; 1124 sep_iq_cal = true;
1089 } 1125 }
@@ -1099,6 +1135,15 @@ skip_tx_iqcal:
1099 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); 1135 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1100 } 1136 }
1101 1137
1138 if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE) {
1139 rx_delay = REG_READ(ah, AR_PHY_RX_DELAY);
1140 /* Disable BB_active */
1141 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1142 udelay(5);
1143 REG_WRITE(ah, AR_PHY_RX_DELAY, AR_PHY_RX_DELAY_DELAY);
1144 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1145 }
1146
1102 if (run_agc_cal || !(ah->ah_flags & AH_FASTCC)) { 1147 if (run_agc_cal || !(ah->ah_flags & AH_FASTCC)) {
1103 /* Calibrate the AGC */ 1148 /* Calibrate the AGC */
1104 REG_WRITE(ah, AR_PHY_AGC_CONTROL, 1149 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
@@ -1110,7 +1155,12 @@ skip_tx_iqcal:
1110 AR_PHY_AGC_CONTROL_CAL, 1155 AR_PHY_AGC_CONTROL_CAL,
1111 0, AH_WAIT_TIMEOUT); 1156 0, AH_WAIT_TIMEOUT);
1112 1157
1113 ar9003_hw_do_manual_peak_cal(ah, chan); 1158 ar9003_hw_do_manual_peak_cal(ah, chan, run_rtt_cal);
1159 }
1160
1161 if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE) {
1162 REG_WRITE(ah, AR_PHY_RX_DELAY, rx_delay);
1163 udelay(5);
1114 } 1164 }
1115 1165
1116 if (ath9k_hw_mci_is_enabled(ah) && IS_CHAN_2GHZ(chan) && run_agc_cal) 1166 if (ath9k_hw_mci_is_enabled(ah) && IS_CHAN_2GHZ(chan) && run_agc_cal)
@@ -1133,19 +1183,23 @@ skip_tx_iqcal:
1133 1183
1134 if (txiqcal_done) 1184 if (txiqcal_done)
1135 ar9003_hw_tx_iq_cal_post_proc(ah, is_reusable); 1185 ar9003_hw_tx_iq_cal_post_proc(ah, is_reusable);
1136 else if (caldata && caldata->done_txiqcal_once) 1186 else if (caldata && test_bit(TXIQCAL_DONE, &caldata->cal_flags))
1137 ar9003_hw_tx_iq_cal_reload(ah); 1187 ar9003_hw_tx_iq_cal_reload(ah);
1138 1188
1139 ar9003_hw_cl_cal_post_proc(ah, is_reusable); 1189 ar9003_hw_cl_cal_post_proc(ah, is_reusable);
1140 1190
1141 if (run_rtt_cal && caldata) { 1191 if (run_rtt_cal && caldata) {
1142 if (is_reusable) { 1192 if (is_reusable) {
1143 if (!ath9k_hw_rfbus_req(ah)) 1193 if (!ath9k_hw_rfbus_req(ah)) {
1144 ath_err(ath9k_hw_common(ah), 1194 ath_err(ath9k_hw_common(ah),
1145 "Could not stop baseband\n"); 1195 "Could not stop baseband\n");
1146 else 1196 } else {
1147 ar9003_hw_rtt_fill_hist(ah); 1197 ar9003_hw_rtt_fill_hist(ah);
1148 1198
1199 if (test_bit(SW_PKDET_DONE, &caldata->cal_flags))
1200 ar9003_hw_rtt_load_hist(ah);
1201 }
1202
1149 ath9k_hw_rfbus_done(ah); 1203 ath9k_hw_rfbus_done(ah);
1150 } 1204 }
1151 1205
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index f4864807e15b..1ec52356b5a1 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -2991,7 +2991,10 @@ static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
2991 case EEP_CHAIN_MASK_REDUCE: 2991 case EEP_CHAIN_MASK_REDUCE:
2992 return (pBase->miscConfiguration >> 0x3) & 0x1; 2992 return (pBase->miscConfiguration >> 0x3) & 0x1;
2993 case EEP_ANT_DIV_CTL1: 2993 case EEP_ANT_DIV_CTL1:
2994 return eep->base_ext1.ant_div_control; 2994 if (AR_SREV_9565(ah))
2995 return AR9300_EEP_ANTDIV_CONTROL_DEFAULT_VALUE;
2996 else
2997 return eep->base_ext1.ant_div_control;
2995 case EEP_ANTENNA_GAIN_5G: 2998 case EEP_ANTENNA_GAIN_5G:
2996 return eep->modalHeader5G.antennaGain; 2999 return eep->modalHeader5G.antennaGain;
2997 case EEP_ANTENNA_GAIN_2G: 3000 case EEP_ANTENNA_GAIN_2G:
@@ -3424,12 +3427,12 @@ static u32 ath9k_hw_ar9003_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
3424 struct ar9300_base_eep_hdr *pBase; 3427 struct ar9300_base_eep_hdr *pBase;
3425 3428
3426 if (!dump_base_hdr) { 3429 if (!dump_base_hdr) {
3427 len += snprintf(buf + len, size - len, 3430 len += scnprintf(buf + len, size - len,
3428 "%20s :\n", "2GHz modal Header"); 3431 "%20s :\n", "2GHz modal Header");
3429 len = ar9003_dump_modal_eeprom(buf, len, size, 3432 len = ar9003_dump_modal_eeprom(buf, len, size,
3430 &eep->modalHeader2G); 3433 &eep->modalHeader2G);
3431 len += snprintf(buf + len, size - len, 3434 len += scnprintf(buf + len, size - len,
3432 "%20s :\n", "5GHz modal Header"); 3435 "%20s :\n", "5GHz modal Header");
3433 len = ar9003_dump_modal_eeprom(buf, len, size, 3436 len = ar9003_dump_modal_eeprom(buf, len, size,
3434 &eep->modalHeader5G); 3437 &eep->modalHeader5G);
3435 goto out; 3438 goto out;
@@ -3479,8 +3482,8 @@ static u32 ath9k_hw_ar9003_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
3479 PR_EEP("Rx Gain", pBase->txrxgain & 0xf); 3482 PR_EEP("Rx Gain", pBase->txrxgain & 0xf);
3480 PR_EEP("SW Reg", le32_to_cpu(pBase->swreg)); 3483 PR_EEP("SW Reg", le32_to_cpu(pBase->swreg));
3481 3484
3482 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", 3485 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
3483 ah->eeprom.ar9300_eep.macAddr); 3486 ah->eeprom.ar9300_eep.macAddr);
3484out: 3487out:
3485 if (len > size) 3488 if (len > size)
3486 len = size; 3489 len = size;
@@ -3656,9 +3659,23 @@ static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
3656 if (AR_SREV_9565(ah)) { 3659 if (AR_SREV_9565(ah)) {
3657 if (common->bt_ant_diversity) { 3660 if (common->bt_ant_diversity) {
3658 regval |= (1 << AR_PHY_ANT_SW_RX_PROT_S); 3661 regval |= (1 << AR_PHY_ANT_SW_RX_PROT_S);
3662
3663 REG_SET_BIT(ah, AR_PHY_RESTART,
3664 AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
3665
3666 /* Force WLAN LNA diversity ON */
3667 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
3668 AR_BTCOEX_WL_LNADIV_FORCE_ON);
3659 } else { 3669 } else {
3660 regval &= ~(1 << AR_PHY_ANT_DIV_LNADIV_S); 3670 regval &= ~(1 << AR_PHY_ANT_DIV_LNADIV_S);
3661 regval &= ~(1 << AR_PHY_ANT_SW_RX_PROT_S); 3671 regval &= ~(1 << AR_PHY_ANT_SW_RX_PROT_S);
3672
3673 REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
3674 (1 << AR_PHY_ANT_SW_RX_PROT_S));
3675
3676 /* Force WLAN LNA diversity OFF */
3677 REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
3678 AR_BTCOEX_WL_LNADIV_FORCE_ON);
3662 } 3679 }
3663 } 3680 }
3664 3681
@@ -3669,7 +3686,8 @@ static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
3669 regval &= (~AR_FAST_DIV_ENABLE); 3686 regval &= (~AR_FAST_DIV_ENABLE);
3670 regval |= ((value >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S; 3687 regval |= ((value >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
3671 3688
3672 if (AR_SREV_9485(ah) && common->bt_ant_diversity) 3689 if ((AR_SREV_9485(ah) || AR_SREV_9565(ah))
3690 && common->bt_ant_diversity)
3673 regval |= AR_FAST_DIV_ENABLE; 3691 regval |= AR_FAST_DIV_ENABLE;
3674 3692
3675 REG_WRITE(ah, AR_PHY_CCK_DETECT, regval); 3693 REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
index 75d4fb41962f..0e5daa58a4fc 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
@@ -52,6 +52,8 @@
52#define AR9300_PAPRD_SCALE_2 0x70000000 52#define AR9300_PAPRD_SCALE_2 0x70000000
53#define AR9300_PAPRD_SCALE_2_S 28 53#define AR9300_PAPRD_SCALE_2_S 28
54 54
55#define AR9300_EEP_ANTDIV_CONTROL_DEFAULT_VALUE 0xc9
56
55/* Delta from which to start power to pdadc table */ 57/* Delta from which to start power to pdadc table */
56/* This offset is used in both open loop and closed loop power control 58/* This offset is used in both open loop and closed loop power control
57 * schemes. In open loop power control, it is not really needed, but for 59 * schemes. In open loop power control, it is not really needed, but for
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_hw.c b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
index 608bb4824e2a..b07f164d65cf 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_hw.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
@@ -364,6 +364,8 @@ static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
364 364
365 INIT_INI_ARRAY(&ah->iniModesFastClock, 365 INIT_INI_ARRAY(&ah->iniModesFastClock,
366 ar9565_1p0_modes_fast_clock); 366 ar9565_1p0_modes_fast_clock);
367 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
368 ar9565_1p0_baseband_core_txfir_coeff_japan_2484);
367 } else { 369 } else {
368 /* mac */ 370 /* mac */
369 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE], 371 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
@@ -628,6 +630,9 @@ static void ar9003_rx_gain_table_mode0(struct ath_hw *ah)
628 else if (AR_SREV_9462_20(ah)) 630 else if (AR_SREV_9462_20(ah))
629 INIT_INI_ARRAY(&ah->iniModesRxGain, 631 INIT_INI_ARRAY(&ah->iniModesRxGain,
630 ar9462_common_rx_gain_table_2p0); 632 ar9462_common_rx_gain_table_2p0);
633 else if (AR_SREV_9565(ah))
634 INIT_INI_ARRAY(&ah->iniModesRxGain,
635 ar9565_1p0_Common_rx_gain_table);
631 else 636 else
632 INIT_INI_ARRAY(&ah->iniModesRxGain, 637 INIT_INI_ARRAY(&ah->iniModesRxGain,
633 ar9300Common_rx_gain_table_2p2); 638 ar9300Common_rx_gain_table_2p2);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mci.c b/drivers/net/wireless/ath/ath9k/ar9003_mci.c
index 8dd069259e7b..7b94a6c7db3d 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_mci.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_mci.c
@@ -753,9 +753,9 @@ int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
753 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT); 753 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
754 754
755 if (caldata) { 755 if (caldata) {
756 caldata->done_txiqcal_once = false; 756 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
757 caldata->done_txclcal_once = false; 757 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
758 caldata->rtt_done = false; 758 clear_bit(RTT_DONE, &caldata->cal_flags);
759 } 759 }
760 760
761 if (!ath9k_hw_init_cal(ah, chan)) 761 if (!ath9k_hw_init_cal(ah, chan))
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index e897648d3233..0131ba2f5d51 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -627,11 +627,10 @@ static void ar9003_hw_override_ini(struct ath_hw *ah)
627 * MAC addr only will fail. 627 * MAC addr only will fail.
628 */ 628 */
629 val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE); 629 val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
630 REG_WRITE(ah, AR_PCU_MISC_MODE2, 630 val |= AR_AGG_WEP_ENABLE_FIX |
631 val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE); 631 AR_AGG_WEP_ENABLE |
632 632 AR_PCU_MISC_MODE2_CFP_IGNORE;
633 REG_SET_BIT(ah, AR_PHY_CCK_DETECT, 633 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
634 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
635 634
636 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { 635 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
637 REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE, 636 REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
@@ -1375,15 +1374,19 @@ static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
1375 AR_PHY_ANT_FAST_DIV_BIAS_S; 1374 AR_PHY_ANT_FAST_DIV_BIAS_S;
1376 1375
1377 if (AR_SREV_9330_11(ah)) { 1376 if (AR_SREV_9330_11(ah)) {
1377 antconf->lna1_lna2_switch_delta = -1;
1378 antconf->lna1_lna2_delta = -9; 1378 antconf->lna1_lna2_delta = -9;
1379 antconf->div_group = 1; 1379 antconf->div_group = 1;
1380 } else if (AR_SREV_9485(ah)) { 1380 } else if (AR_SREV_9485(ah)) {
1381 antconf->lna1_lna2_switch_delta = -1;
1381 antconf->lna1_lna2_delta = -9; 1382 antconf->lna1_lna2_delta = -9;
1382 antconf->div_group = 2; 1383 antconf->div_group = 2;
1383 } else if (AR_SREV_9565(ah)) { 1384 } else if (AR_SREV_9565(ah)) {
1384 antconf->lna1_lna2_delta = -3; 1385 antconf->lna1_lna2_switch_delta = 3;
1386 antconf->lna1_lna2_delta = -9;
1385 antconf->div_group = 3; 1387 antconf->div_group = 3;
1386 } else { 1388 } else {
1389 antconf->lna1_lna2_switch_delta = -1;
1387 antconf->lna1_lna2_delta = -3; 1390 antconf->lna1_lna2_delta = -3;
1388 antconf->div_group = 0; 1391 antconf->div_group = 0;
1389 } 1392 }
@@ -1489,17 +1492,24 @@ static void ar9003_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
1489 } else if (AR_SREV_9565(ah)) { 1492 } else if (AR_SREV_9565(ah)) {
1490 if (enable) { 1493 if (enable) {
1491 REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL, 1494 REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
1495 AR_ANT_DIV_ENABLE);
1496 REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
1492 (1 << AR_PHY_ANT_SW_RX_PROT_S)); 1497 (1 << AR_PHY_ANT_SW_RX_PROT_S));
1493 if (ah->curchan && IS_CHAN_2GHZ(ah->curchan)) 1498 REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
1494 REG_SET_BIT(ah, AR_PHY_RESTART, 1499 AR_FAST_DIV_ENABLE);
1495 AR_PHY_RESTART_ENABLE_DIV_M2FLAG); 1500 REG_SET_BIT(ah, AR_PHY_RESTART,
1501 AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
1496 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, 1502 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
1497 AR_BTCOEX_WL_LNADIV_FORCE_ON); 1503 AR_BTCOEX_WL_LNADIV_FORCE_ON);
1498 } else { 1504 } else {
1499 REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, AR_ANT_DIV_ENABLE); 1505 REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
1506 AR_ANT_DIV_ENABLE);
1500 REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, 1507 REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
1501 (1 << AR_PHY_ANT_SW_RX_PROT_S)); 1508 (1 << AR_PHY_ANT_SW_RX_PROT_S));
1502 REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, AR_FAST_DIV_ENABLE); 1509 REG_CLR_BIT(ah, AR_PHY_CCK_DETECT,
1510 AR_FAST_DIV_ENABLE);
1511 REG_CLR_BIT(ah, AR_PHY_RESTART,
1512 AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
1503 REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV, 1513 REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
1504 AR_BTCOEX_WL_LNADIV_FORCE_ON); 1514 AR_BTCOEX_WL_LNADIV_FORCE_ON);
1505 1515
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.h b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
index 6fd752321e36..fca624322dc8 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
@@ -343,8 +343,12 @@
343 343
344#define AR_PHY_CCA_NOM_VAL_9462_2GHZ -127 344#define AR_PHY_CCA_NOM_VAL_9462_2GHZ -127
345#define AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ -127 345#define AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ -127
346#define AR_PHY_CCA_MAX_GOOD_VAL_9462_2GHZ -60
347#define AR_PHY_CCA_MAX_GOOD_VAL_9462_FCC_2GHZ -95
346#define AR_PHY_CCA_NOM_VAL_9462_5GHZ -127 348#define AR_PHY_CCA_NOM_VAL_9462_5GHZ -127
347#define AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ -127 349#define AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ -127
350#define AR_PHY_CCA_MAX_GOOD_VAL_9462_5GHZ -60
351#define AR_PHY_CCA_MAX_GOOD_VAL_9462_FCC_5GHZ -100
348 352
349#define AR_PHY_CCA_NOM_VAL_9330_2GHZ -118 353#define AR_PHY_CCA_NOM_VAL_9330_2GHZ -118
350 354
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_rtt.c b/drivers/net/wireless/ath/ath9k/ar9003_rtt.c
index 74de3539c2c8..934418872e8e 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_rtt.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_rtt.c
@@ -118,6 +118,27 @@ void ar9003_hw_rtt_load_hist(struct ath_hw *ah)
118 } 118 }
119} 119}
120 120
121static void ar9003_hw_patch_rtt(struct ath_hw *ah, int index, int chain)
122{
123 int agc, caldac;
124
125 if (!test_bit(SW_PKDET_DONE, &ah->caldata->cal_flags))
126 return;
127
128 if ((index != 5) || (chain >= 2))
129 return;
130
131 agc = REG_READ_FIELD(ah, AR_PHY_65NM_RXRF_AGC(chain),
132 AR_PHY_65NM_RXRF_AGC_AGC_OVERRIDE);
133 if (!agc)
134 return;
135
136 caldac = ah->caldata->caldac[chain];
137 ah->caldata->rtt_table[chain][index] &= 0xFFFF05FF;
138 caldac = (caldac & 0x20) | ((caldac & 0x1F) << 7);
139 ah->caldata->rtt_table[chain][index] |= (caldac << 4);
140}
141
121static int ar9003_hw_rtt_fill_hist_entry(struct ath_hw *ah, u8 chain, u32 index) 142static int ar9003_hw_rtt_fill_hist_entry(struct ath_hw *ah, u8 chain, u32 index)
122{ 143{
123 u32 val; 144 u32 val;
@@ -155,13 +176,16 @@ void ar9003_hw_rtt_fill_hist(struct ath_hw *ah)
155 for (i = 0; i < MAX_RTT_TABLE_ENTRY; i++) { 176 for (i = 0; i < MAX_RTT_TABLE_ENTRY; i++) {
156 ah->caldata->rtt_table[chain][i] = 177 ah->caldata->rtt_table[chain][i] =
157 ar9003_hw_rtt_fill_hist_entry(ah, chain, i); 178 ar9003_hw_rtt_fill_hist_entry(ah, chain, i);
179
180 ar9003_hw_patch_rtt(ah, i, chain);
181
158 ath_dbg(ath9k_hw_common(ah), CALIBRATE, 182 ath_dbg(ath9k_hw_common(ah), CALIBRATE,
159 "RTT value at idx %d, chain %d is: 0x%x\n", 183 "RTT value at idx %d, chain %d is: 0x%x\n",
160 i, chain, ah->caldata->rtt_table[chain][i]); 184 i, chain, ah->caldata->rtt_table[chain][i]);
161 } 185 }
162 } 186 }
163 187
164 ah->caldata->rtt_done = true; 188 set_bit(RTT_DONE, &ah->caldata->cal_flags);
165} 189}
166 190
167void ar9003_hw_rtt_clear_hist(struct ath_hw *ah) 191void ar9003_hw_rtt_clear_hist(struct ath_hw *ah)
@@ -176,7 +200,7 @@ void ar9003_hw_rtt_clear_hist(struct ath_hw *ah)
176 } 200 }
177 201
178 if (ah->caldata) 202 if (ah->caldata)
179 ah->caldata->rtt_done = false; 203 clear_bit(RTT_DONE, &ah->caldata->cal_flags);
180} 204}
181 205
182bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan) 206bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan)
@@ -186,11 +210,37 @@ bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan)
186 if (!ah->caldata) 210 if (!ah->caldata)
187 return false; 211 return false;
188 212
189 if (!ah->caldata->rtt_done) 213 if (test_bit(SW_PKDET_DONE, &ah->caldata->cal_flags)) {
214 if (IS_CHAN_2GHZ(chan)){
215 REG_RMW_FIELD(ah, AR_PHY_65NM_RXRF_AGC(0),
216 AR_PHY_65NM_RXRF_AGC_AGC2G_CALDAC_OVR,
217 ah->caldata->caldac[0]);
218 REG_RMW_FIELD(ah, AR_PHY_65NM_RXRF_AGC(1),
219 AR_PHY_65NM_RXRF_AGC_AGC2G_CALDAC_OVR,
220 ah->caldata->caldac[1]);
221 } else {
222 REG_RMW_FIELD(ah, AR_PHY_65NM_RXRF_AGC(0),
223 AR_PHY_65NM_RXRF_AGC_AGC5G_CALDAC_OVR,
224 ah->caldata->caldac[0]);
225 REG_RMW_FIELD(ah, AR_PHY_65NM_RXRF_AGC(1),
226 AR_PHY_65NM_RXRF_AGC_AGC5G_CALDAC_OVR,
227 ah->caldata->caldac[1]);
228 }
229 REG_RMW_FIELD(ah, AR_PHY_65NM_RXRF_AGC(1),
230 AR_PHY_65NM_RXRF_AGC_AGC_OVERRIDE, 0x1);
231 REG_RMW_FIELD(ah, AR_PHY_65NM_RXRF_AGC(0),
232 AR_PHY_65NM_RXRF_AGC_AGC_OVERRIDE, 0x1);
233 }
234
235 if (!test_bit(RTT_DONE, &ah->caldata->cal_flags))
190 return false; 236 return false;
191 237
192 ar9003_hw_rtt_enable(ah); 238 ar9003_hw_rtt_enable(ah);
193 ar9003_hw_rtt_set_mask(ah, 0x10); 239
240 if (test_bit(SW_PKDET_DONE, &ah->caldata->cal_flags))
241 ar9003_hw_rtt_set_mask(ah, 0x30);
242 else
243 ar9003_hw_rtt_set_mask(ah, 0x10);
194 244
195 if (!ath9k_hw_rfbus_req(ah)) { 245 if (!ath9k_hw_rfbus_req(ah)) {
196 ath_err(ath9k_hw_common(ah), "Could not stop baseband\n"); 246 ath_err(ath9k_hw_common(ah), "Could not stop baseband\n");
diff --git a/drivers/net/wireless/ath/ath9k/ar9485_initvals.h b/drivers/net/wireless/ath/ath9k/ar9485_initvals.h
index 88ff1d7b53ab..6f899c692647 100644
--- a/drivers/net/wireless/ath/ath9k/ar9485_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9485_initvals.h
@@ -20,7 +20,17 @@
20 20
21/* AR9485 1.1 */ 21/* AR9485 1.1 */
22 22
23#define ar9485_1_1_mac_postamble ar9300_2p2_mac_postamble 23static const u32 ar9485_1_1_mac_postamble[][5] = {
24 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
25 {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160},
26 {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c},
27 {0x000010b0, 0x00000e60, 0x00001cc0, 0x00007c70, 0x00003e38},
28 {0x00008014, 0x03e803e8, 0x07d007d0, 0x10801600, 0x08400b00},
29 {0x0000801c, 0x128d8027, 0x128d804f, 0x12e00057, 0x12e0002b},
30 {0x00008120, 0x08f04800, 0x08f04800, 0x08f04810, 0x08f04810},
31 {0x000081d0, 0x00003210, 0x00003210, 0x0000320a, 0x0000320a},
32 {0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440},
33};
24 34
25static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = { 35static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = {
26 /* Addr allmodes */ 36 /* Addr allmodes */
@@ -34,6 +44,7 @@ static const u32 ar9485Common_wo_xlna_rx_gain_1_1[][2] = {
34 {0x00009e00, 0x037216a0}, 44 {0x00009e00, 0x037216a0},
35 {0x00009e04, 0x00182020}, 45 {0x00009e04, 0x00182020},
36 {0x00009e18, 0x00000000}, 46 {0x00009e18, 0x00000000},
47 {0x00009e20, 0x000003a8},
37 {0x00009e2c, 0x00004121}, 48 {0x00009e2c, 0x00004121},
38 {0x00009e44, 0x02282324}, 49 {0x00009e44, 0x02282324},
39 {0x0000a000, 0x00060005}, 50 {0x0000a000, 0x00060005},
@@ -174,7 +185,7 @@ static const u32 ar9485Modes_high_power_tx_gain_1_1[][5] = {
174 {0x0000a2e0, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552}, 185 {0x0000a2e0, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
175 {0x0000a2e4, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552}, 186 {0x0000a2e4, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
176 {0x0000a2e8, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552}, 187 {0x0000a2e8, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
177 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, 188 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050da, 0x000050da},
178 {0x0000a458, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 189 {0x0000a458, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
179 {0x0000a500, 0x00022200, 0x00022200, 0x00000000, 0x00000000}, 190 {0x0000a500, 0x00022200, 0x00022200, 0x00000000, 0x00000000},
180 {0x0000a504, 0x05062002, 0x05062002, 0x04000002, 0x04000002}, 191 {0x0000a504, 0x05062002, 0x05062002, 0x04000002, 0x04000002},
@@ -200,14 +211,14 @@ static const u32 ar9485Modes_high_power_tx_gain_1_1[][5] = {
200 {0x0000a554, 0x7d06ffcb, 0x7d06ffcb, 0x57001ce9, 0x57001ce9}, 211 {0x0000a554, 0x7d06ffcb, 0x7d06ffcb, 0x57001ce9, 0x57001ce9},
201 {0x0000a558, 0x8407ff0b, 0x8407ff0b, 0x5a001ceb, 0x5a001ceb}, 212 {0x0000a558, 0x8407ff0b, 0x8407ff0b, 0x5a001ceb, 0x5a001ceb},
202 {0x0000a55c, 0x8907ffcb, 0x8907ffcb, 0x5e001eeb, 0x5e001eeb}, 213 {0x0000a55c, 0x8907ffcb, 0x8907ffcb, 0x5e001eeb, 0x5e001eeb},
203 {0x0000a560, 0x900fff0b, 0x900fff0b, 0x5e001eeb, 0x5e001eeb}, 214 {0x0000a560, 0x900fff0b, 0x900fff0b, 0x62001eee, 0x62001eee},
204 {0x0000a564, 0x960fffcb, 0x960fffcb, 0x5e001eeb, 0x5e001eeb}, 215 {0x0000a564, 0x960fffcb, 0x960fffcb, 0x66001ff6, 0x66001ff6},
205 {0x0000a568, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 216 {0x0000a568, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
206 {0x0000a56c, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 217 {0x0000a56c, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
207 {0x0000a570, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 218 {0x0000a570, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
208 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 219 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
209 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 220 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
210 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 221 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
211 {0x0000a580, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 222 {0x0000a580, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
212 {0x0000a584, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 223 {0x0000a584, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
213 {0x0000a588, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 224 {0x0000a588, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
@@ -263,6 +274,11 @@ static const u32 ar9485Modes_high_power_tx_gain_1_1[][5] = {
263static const u32 ar9485Modes_green_ob_db_tx_gain_1_1[][5] = { 274static const u32 ar9485Modes_green_ob_db_tx_gain_1_1[][5] = {
264 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 275 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
265 {0x000098bc, 0x00000003, 0x00000003, 0x00000003, 0x00000003}, 276 {0x000098bc, 0x00000003, 0x00000003, 0x00000003, 0x00000003},
277 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0x7999a83a, 0x7999a83a},
278 {0x0000a2dc, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
279 {0x0000a2e0, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
280 {0x0000a2e4, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
281 {0x0000a2e8, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
266 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, 282 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8},
267 {0x0000a458, 0x80000000, 0x80000000, 0x80000000, 0x80000000}, 283 {0x0000a458, 0x80000000, 0x80000000, 0x80000000, 0x80000000},
268 {0x0000a500, 0x00022200, 0x00022200, 0x00000006, 0x00000006}, 284 {0x0000a500, 0x00022200, 0x00022200, 0x00000006, 0x00000006},
@@ -297,6 +313,22 @@ static const u32 ar9485Modes_green_ob_db_tx_gain_1_1[][5] = {
297 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 313 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb},
298 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 314 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb},
299 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb}, 315 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x5e001eeb, 0x5e001eeb},
316 {0x0000a580, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
317 {0x0000a584, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
318 {0x0000a588, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
319 {0x0000a58c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
320 {0x0000a590, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
321 {0x0000a594, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
322 {0x0000a598, 0x00000000, 0x00000000, 0x01404501, 0x01404501},
323 {0x0000a59c, 0x00000000, 0x00000000, 0x02808a02, 0x02808a02},
324 {0x0000a5a0, 0x00000000, 0x00000000, 0x02808a02, 0x02808a02},
325 {0x0000a5a4, 0x00000000, 0x00000000, 0x02808803, 0x02808803},
326 {0x0000a5a8, 0x00000000, 0x00000000, 0x04c14b04, 0x04c14b04},
327 {0x0000a5ac, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
328 {0x0000a5b0, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
329 {0x0000a5b4, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
330 {0x0000a5b8, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
331 {0x0000a5bc, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
300 {0x0000b500, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a}, 332 {0x0000b500, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a},
301 {0x0000b504, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a}, 333 {0x0000b504, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a},
302 {0x0000b508, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a}, 334 {0x0000b508, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a},
@@ -341,6 +373,100 @@ static const u32 ar9485Modes_high_ob_db_tx_gain_1_1[][5] = {
341 {0x0000a2e0, 0x00000000, 0x00000000, 0xffc63a84, 0xffc63a84}, 373 {0x0000a2e0, 0x00000000, 0x00000000, 0xffc63a84, 0xffc63a84},
342 {0x0000a2e4, 0x00000000, 0x00000000, 0xfe0fc000, 0xfe0fc000}, 374 {0x0000a2e4, 0x00000000, 0x00000000, 0xfe0fc000, 0xfe0fc000},
343 {0x0000a2e8, 0x00000000, 0x00000000, 0xfff00000, 0xfff00000}, 375 {0x0000a2e8, 0x00000000, 0x00000000, 0xfff00000, 0xfff00000},
376 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050da, 0x000050da},
377 {0x0000a458, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
378 {0x0000a500, 0x00022200, 0x00022200, 0x00000000, 0x00000000},
379 {0x0000a504, 0x05062002, 0x05062002, 0x04000002, 0x04000002},
380 {0x0000a508, 0x0c002e00, 0x0c002e00, 0x08000004, 0x08000004},
381 {0x0000a50c, 0x11062202, 0x11062202, 0x0d000200, 0x0d000200},
382 {0x0000a510, 0x17022e00, 0x17022e00, 0x11000202, 0x11000202},
383 {0x0000a514, 0x1d000ec2, 0x1d000ec2, 0x15000400, 0x15000400},
384 {0x0000a518, 0x25020ec0, 0x25020ec0, 0x19000402, 0x19000402},
385 {0x0000a51c, 0x2b020ec3, 0x2b020ec3, 0x1d000404, 0x1d000404},
386 {0x0000a520, 0x2f001f04, 0x2f001f04, 0x21000603, 0x21000603},
387 {0x0000a524, 0x35001fc4, 0x35001fc4, 0x25000605, 0x25000605},
388 {0x0000a528, 0x3c022f04, 0x3c022f04, 0x2a000a03, 0x2a000a03},
389 {0x0000a52c, 0x41023e85, 0x41023e85, 0x2c000a04, 0x2c000a04},
390 {0x0000a530, 0x48023ec6, 0x48023ec6, 0x34000e20, 0x34000e20},
391 {0x0000a534, 0x4d023f01, 0x4d023f01, 0x35000e21, 0x35000e21},
392 {0x0000a538, 0x53023f4b, 0x53023f4b, 0x43000e62, 0x43000e62},
393 {0x0000a53c, 0x5a027f09, 0x5a027f09, 0x45000e63, 0x45000e63},
394 {0x0000a540, 0x5f027fc9, 0x5f027fc9, 0x49000e65, 0x49000e65},
395 {0x0000a544, 0x6502feca, 0x6502feca, 0x4b000e66, 0x4b000e66},
396 {0x0000a548, 0x6b02ff4a, 0x6b02ff4a, 0x4d001645, 0x4d001645},
397 {0x0000a54c, 0x7203feca, 0x7203feca, 0x51001865, 0x51001865},
398 {0x0000a550, 0x7703ff0b, 0x7703ff0b, 0x55001a86, 0x55001a86},
399 {0x0000a554, 0x7d06ffcb, 0x7d06ffcb, 0x57001ce9, 0x57001ce9},
400 {0x0000a558, 0x8407ff0b, 0x8407ff0b, 0x5a001ceb, 0x5a001ceb},
401 {0x0000a55c, 0x8907ffcb, 0x8907ffcb, 0x5e001eeb, 0x5e001eeb},
402 {0x0000a560, 0x900fff0b, 0x900fff0b, 0x62001eee, 0x62001eee},
403 {0x0000a564, 0x960fffcb, 0x960fffcb, 0x66001ff6, 0x66001ff6},
404 {0x0000a568, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
405 {0x0000a56c, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
406 {0x0000a570, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
407 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
408 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
409 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x66001ff6, 0x66001ff6},
410 {0x0000a580, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
411 {0x0000a584, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
412 {0x0000a588, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
413 {0x0000a58c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
414 {0x0000a590, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
415 {0x0000a594, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
416 {0x0000a598, 0x00000000, 0x00000000, 0x01404501, 0x01404501},
417 {0x0000a59c, 0x00000000, 0x00000000, 0x02808a02, 0x02808a02},
418 {0x0000a5a0, 0x00000000, 0x00000000, 0x02808a02, 0x02808a02},
419 {0x0000a5a4, 0x00000000, 0x00000000, 0x02808803, 0x02808803},
420 {0x0000a5a8, 0x00000000, 0x00000000, 0x04c14b04, 0x04c14b04},
421 {0x0000a5ac, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
422 {0x0000a5b0, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
423 {0x0000a5b4, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
424 {0x0000a5b8, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
425 {0x0000a5bc, 0x00000000, 0x00000000, 0x04c15305, 0x04c15305},
426 {0x0000b500, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
427 {0x0000b504, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
428 {0x0000b508, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
429 {0x0000b50c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
430 {0x0000b510, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
431 {0x0000b514, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
432 {0x0000b518, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
433 {0x0000b51c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
434 {0x0000b520, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
435 {0x0000b524, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
436 {0x0000b528, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
437 {0x0000b52c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
438 {0x0000b530, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
439 {0x0000b534, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
440 {0x0000b538, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
441 {0x0000b53c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
442 {0x0000b540, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
443 {0x0000b544, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
444 {0x0000b548, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
445 {0x0000b54c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
446 {0x0000b550, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
447 {0x0000b554, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
448 {0x0000b558, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
449 {0x0000b55c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
450 {0x0000b560, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
451 {0x0000b564, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
452 {0x0000b568, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
453 {0x0000b56c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
454 {0x0000b570, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
455 {0x0000b574, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
456 {0x0000b578, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
457 {0x0000b57c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
458 {0x00016044, 0x05d6b2db, 0x05d6b2db, 0x05d6b2db, 0x05d6b2db},
459 {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260},
460};
461
462static const u32 ar9485Modes_low_ob_db_tx_gain_1_1[][5] = {
463 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
464 {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002},
465 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0x7999a83a, 0x7999a83a},
466 {0x0000a2dc, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
467 {0x0000a2e0, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
468 {0x0000a2e4, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
469 {0x0000a2e8, 0x00000000, 0x00000000, 0xfe2d3552, 0xfe2d3552},
344 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, 470 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8},
345 {0x0000a458, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 471 {0x0000a458, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
346 {0x0000a500, 0x00022200, 0x00022200, 0x00000000, 0x00000000}, 472 {0x0000a500, 0x00022200, 0x00022200, 0x00000000, 0x00000000},
@@ -427,7 +553,7 @@ static const u32 ar9485Modes_high_ob_db_tx_gain_1_1[][5] = {
427 {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, 553 {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260},
428}; 554};
429 555
430static const u32 ar9485Modes_low_ob_db_tx_gain_1_1[][5] = { 556static const u32 ar9485_modes_lowest_ob_db_tx_gain_1_1[][5] = {
431 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 557 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
432 {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002}, 558 {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002},
433 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0x7999a83a, 0x7999a83a}, 559 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0x7999a83a, 0x7999a83a},
@@ -521,12 +647,15 @@ static const u32 ar9485Modes_low_ob_db_tx_gain_1_1[][5] = {
521 {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, 647 {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260},
522}; 648};
523 649
524#define ar9485_modes_lowest_ob_db_tx_gain_1_1 ar9485Modes_low_ob_db_tx_gain_1_1
525
526static const u32 ar9485Modes_green_spur_ob_db_tx_gain_1_1[][5] = { 650static const u32 ar9485Modes_green_spur_ob_db_tx_gain_1_1[][5] = {
527 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 651 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
528 {0x000098bc, 0x00000003, 0x00000003, 0x00000003, 0x00000003}, 652 {0x000098bc, 0x00000003, 0x00000003, 0x00000003, 0x00000003},
529 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, 653 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0x7999a83a, 0x7999a83a},
654 {0x0000a2dc, 0x00000000, 0x00000000, 0xffad452a, 0xffad452a},
655 {0x0000a2e0, 0x00000000, 0x00000000, 0xffc98634, 0xffc98634},
656 {0x0000a2e4, 0x00000000, 0x00000000, 0xfff60780, 0xfff60780},
657 {0x0000a2e8, 0x00000000, 0x00000000, 0xfffff800, 0xfffff800},
658 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9},
530 {0x0000a458, 0x80000000, 0x80000000, 0x80000000, 0x80000000}, 659 {0x0000a458, 0x80000000, 0x80000000, 0x80000000, 0x80000000},
531 {0x0000a500, 0x00022200, 0x00022200, 0x00000006, 0x00000006}, 660 {0x0000a500, 0x00022200, 0x00022200, 0x00000006, 0x00000006},
532 {0x0000a504, 0x05062002, 0x05062002, 0x03000201, 0x03000201}, 661 {0x0000a504, 0x05062002, 0x05062002, 0x03000201, 0x03000201},
@@ -543,23 +672,39 @@ static const u32 ar9485Modes_green_spur_ob_db_tx_gain_1_1[][5] = {
543 {0x0000a530, 0x48023ec6, 0x48023ec6, 0x310006e0, 0x310006e0}, 672 {0x0000a530, 0x48023ec6, 0x48023ec6, 0x310006e0, 0x310006e0},
544 {0x0000a534, 0x4d023f01, 0x4d023f01, 0x330006e0, 0x330006e0}, 673 {0x0000a534, 0x4d023f01, 0x4d023f01, 0x330006e0, 0x330006e0},
545 {0x0000a538, 0x53023f4b, 0x53023f4b, 0x3e0008e3, 0x3e0008e3}, 674 {0x0000a538, 0x53023f4b, 0x53023f4b, 0x3e0008e3, 0x3e0008e3},
546 {0x0000a53c, 0x5a027f09, 0x5a027f09, 0x410008e5, 0x410008e5}, 675 {0x0000a53c, 0x5a027f09, 0x5a027f09, 0x430008e6, 0x430008e6},
547 {0x0000a540, 0x5f027fc9, 0x5f027fc9, 0x430008e6, 0x430008e6}, 676 {0x0000a540, 0x5f027fc9, 0x5f027fc9, 0x4a0008ec, 0x4a0008ec},
548 {0x0000a544, 0x6502feca, 0x6502feca, 0x4a0008ec, 0x4a0008ec}, 677 {0x0000a544, 0x6502feca, 0x6502feca, 0x4e0008f1, 0x4e0008f1},
549 {0x0000a548, 0x6b02ff4a, 0x6b02ff4a, 0x4e0008f1, 0x4e0008f1}, 678 {0x0000a548, 0x6b02ff4a, 0x6b02ff4a, 0x520008f3, 0x520008f3},
550 {0x0000a54c, 0x7203feca, 0x7203feca, 0x520008f3, 0x520008f3}, 679 {0x0000a54c, 0x7203feca, 0x7203feca, 0x54000eed, 0x54000eed},
551 {0x0000a550, 0x7703ff0b, 0x7703ff0b, 0x54000eed, 0x54000eed}, 680 {0x0000a550, 0x7703ff0b, 0x7703ff0b, 0x58000ef1, 0x58000ef1},
552 {0x0000a554, 0x7d06ffcb, 0x7d06ffcb, 0x58000ef1, 0x58000ef1}, 681 {0x0000a554, 0x7d06ffcb, 0x7d06ffcb, 0x5c000ef3, 0x5c000ef3},
553 {0x0000a558, 0x8407ff0b, 0x8407ff0b, 0x5c000ef3, 0x5c000ef3}, 682 {0x0000a558, 0x8407ff0b, 0x8407ff0b, 0x62000ef6, 0x62000ef6},
554 {0x0000a55c, 0x8907ffcb, 0x8907ffcb, 0x60000ef5, 0x60000ef5}, 683 {0x0000a55c, 0x8907ffcb, 0x8907ffcb, 0x66001ff0, 0x66001ff0},
555 {0x0000a560, 0x900fff0b, 0x900fff0b, 0x62000ef6, 0x62000ef6}, 684 {0x0000a560, 0x900fff0b, 0x900fff0b, 0x68001ff6, 0x68001ff6},
556 {0x0000a564, 0x960fffcb, 0x960fffcb, 0x62000ef6, 0x62000ef6}, 685 {0x0000a564, 0x960fffcb, 0x960fffcb, 0x68001ff6, 0x68001ff6},
557 {0x0000a568, 0x9c1fff0b, 0x9c1fff0b, 0x62000ef6, 0x62000ef6}, 686 {0x0000a568, 0x9c1fff0b, 0x9c1fff0b, 0x68001ff6, 0x68001ff6},
558 {0x0000a56c, 0x9c1fff0b, 0x9c1fff0b, 0x62000ef6, 0x62000ef6}, 687 {0x0000a56c, 0x9c1fff0b, 0x9c1fff0b, 0x68001ff6, 0x68001ff6},
559 {0x0000a570, 0x9c1fff0b, 0x9c1fff0b, 0x62000ef6, 0x62000ef6}, 688 {0x0000a570, 0x9c1fff0b, 0x9c1fff0b, 0x68001ff6, 0x68001ff6},
560 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x62000ef6, 0x62000ef6}, 689 {0x0000a574, 0x9c1fff0b, 0x9c1fff0b, 0x68001ff6, 0x68001ff6},
561 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x62000ef6, 0x62000ef6}, 690 {0x0000a578, 0x9c1fff0b, 0x9c1fff0b, 0x68001ff6, 0x68001ff6},
562 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x62000ef6, 0x62000ef6}, 691 {0x0000a57c, 0x9c1fff0b, 0x9c1fff0b, 0x68001ff6, 0x68001ff6},
692 {0x0000a580, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
693 {0x0000a584, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
694 {0x0000a588, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
695 {0x0000a58c, 0x00000000, 0x00000000, 0x01804000, 0x01804000},
696 {0x0000a590, 0x00000000, 0x00000000, 0x02808a02, 0x02808a02},
697 {0x0000a594, 0x00000000, 0x00000000, 0x0340ca02, 0x0340ca02},
698 {0x0000a598, 0x00000000, 0x00000000, 0x0340cd03, 0x0340cd03},
699 {0x0000a59c, 0x00000000, 0x00000000, 0x0340cd03, 0x0340cd03},
700 {0x0000a5a0, 0x00000000, 0x00000000, 0x06415304, 0x06415304},
701 {0x0000a5a4, 0x00000000, 0x00000000, 0x04c11905, 0x04c11905},
702 {0x0000a5a8, 0x00000000, 0x00000000, 0x06415905, 0x06415905},
703 {0x0000a5ac, 0x00000000, 0x00000000, 0x06415905, 0x06415905},
704 {0x0000a5b0, 0x00000000, 0x00000000, 0x06415905, 0x06415905},
705 {0x0000a5b4, 0x00000000, 0x00000000, 0x06415905, 0x06415905},
706 {0x0000a5b8, 0x00000000, 0x00000000, 0x06415905, 0x06415905},
707 {0x0000a5bc, 0x00000000, 0x00000000, 0x06415905, 0x06415905},
563 {0x0000b500, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a}, 708 {0x0000b500, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a},
564 {0x0000b504, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a}, 709 {0x0000b504, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a},
565 {0x0000b508, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a}, 710 {0x0000b508, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a},
@@ -823,6 +968,7 @@ static const u32 ar9485_common_rx_gain_1_1[][2] = {
823 {0x00009e00, 0x03721b20}, 968 {0x00009e00, 0x03721b20},
824 {0x00009e04, 0x00082020}, 969 {0x00009e04, 0x00082020},
825 {0x00009e18, 0x0300501e}, 970 {0x00009e18, 0x0300501e},
971 {0x00009e20, 0x000003ba},
826 {0x00009e2c, 0x00002e21}, 972 {0x00009e2c, 0x00002e21},
827 {0x00009e44, 0x02182324}, 973 {0x00009e44, 0x02182324},
828 {0x0000a000, 0x00060005}, 974 {0x0000a000, 0x00060005},
@@ -1001,7 +1147,6 @@ static const u32 ar9485_1_1_baseband_postamble[][5] = {
1001 {0x00009e10, 0x7ec88d2e, 0x7ec88d2e, 0x7ec80d2e, 0x7ec80d2e}, 1147 {0x00009e10, 0x7ec88d2e, 0x7ec88d2e, 0x7ec80d2e, 0x7ec80d2e},
1002 {0x00009e14, 0x31395d53, 0x31396053, 0x312e6053, 0x312e5d53}, 1148 {0x00009e14, 0x31395d53, 0x31396053, 0x312e6053, 0x312e5d53},
1003 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 1149 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
1004 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce},
1005 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcf946222, 0xcf946222}, 1150 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcf946222, 0xcf946222},
1006 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302010, 0x50302010}, 1151 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302010, 0x50302010},
1007 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000}, 1152 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000},
@@ -1020,7 +1165,7 @@ static const u32 ar9485_1_1_baseband_postamble[][5] = {
1020 {0x0000a284, 0x00000000, 0x00000000, 0x000002a0, 0x000002a0}, 1165 {0x0000a284, 0x00000000, 0x00000000, 0x000002a0, 0x000002a0},
1021 {0x0000a288, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 1166 {0x0000a288, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1022 {0x0000a28c, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 1167 {0x0000a28c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1023 {0x0000a2c4, 0x00158d18, 0x00158d18, 0x00058d18, 0x00058d18}, 1168 {0x0000a2c4, 0x00158d18, 0x00158d18, 0x00158d18, 0x00158d18},
1024 {0x0000a2d0, 0x00071981, 0x00071981, 0x00071982, 0x00071982}, 1169 {0x0000a2d0, 0x00071981, 0x00071981, 0x00071982, 0x00071982},
1025 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0xf999a83a, 0xf999a83a}, 1170 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0xf999a83a, 0xf999a83a},
1026 {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 1171 {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
@@ -1206,6 +1351,11 @@ static const u32 ar9485_1_1_mac_core[][2] = {
1206 {0x000083d0, 0x000301ff}, 1351 {0x000083d0, 0x000301ff},
1207}; 1352};
1208 1353
1209#define ar9485_1_1_baseband_core_txfir_coeff_japan_2484 ar9462_2p0_baseband_core_txfir_coeff_japan_2484 1354static const u32 ar9485_1_1_baseband_core_txfir_coeff_japan_2484[][2] = {
1355 /* Addr allmodes */
1356 {0x0000a398, 0x00000000},
1357 {0x0000a39c, 0x6f7f0301},
1358 {0x0000a3a0, 0xca9228ee},
1359};
1210 1360
1211#endif /* INITVALS_9485_H */ 1361#endif /* INITVALS_9485_H */
diff --git a/drivers/net/wireless/ath/ath9k/ar9565_1p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar9565_1p0_initvals.h
index e85a8b076c22..a8c757b6124f 100644
--- a/drivers/net/wireless/ath/ath9k/ar9565_1p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9565_1p0_initvals.h
@@ -272,9 +272,9 @@ static const u32 ar9565_1p0_baseband_core[][2] = {
272 {0x0000a398, 0x001f0e0f}, 272 {0x0000a398, 0x001f0e0f},
273 {0x0000a39c, 0x0075393f}, 273 {0x0000a39c, 0x0075393f},
274 {0x0000a3a0, 0xb79f6427}, 274 {0x0000a3a0, 0xb79f6427},
275 {0x0000a3a4, 0x00000000}, 275 {0x0000a3a4, 0x00000011},
276 {0x0000a3a8, 0xaaaaaaaa}, 276 {0x0000a3a8, 0xaaaaaa6e},
277 {0x0000a3ac, 0x3c466478}, 277 {0x0000a3ac, 0x3c466455},
278 {0x0000a3c0, 0x20202020}, 278 {0x0000a3c0, 0x20202020},
279 {0x0000a3c4, 0x22222220}, 279 {0x0000a3c4, 0x22222220},
280 {0x0000a3c8, 0x20200020}, 280 {0x0000a3c8, 0x20200020},
@@ -295,11 +295,11 @@ static const u32 ar9565_1p0_baseband_core[][2] = {
295 {0x0000a404, 0x00000000}, 295 {0x0000a404, 0x00000000},
296 {0x0000a408, 0x0e79e5c6}, 296 {0x0000a408, 0x0e79e5c6},
297 {0x0000a40c, 0x00820820}, 297 {0x0000a40c, 0x00820820},
298 {0x0000a414, 0x1ce739ce}, 298 {0x0000a414, 0x1ce739c5},
299 {0x0000a418, 0x2d001dce}, 299 {0x0000a418, 0x2d001dce},
300 {0x0000a41c, 0x1ce739ce}, 300 {0x0000a41c, 0x1ce739c5},
301 {0x0000a420, 0x000001ce}, 301 {0x0000a420, 0x000001ce},
302 {0x0000a424, 0x1ce739ce}, 302 {0x0000a424, 0x1ce739c5},
303 {0x0000a428, 0x000001ce}, 303 {0x0000a428, 0x000001ce},
304 {0x0000a42c, 0x1ce739ce}, 304 {0x0000a42c, 0x1ce739ce},
305 {0x0000a430, 0x1ce739ce}, 305 {0x0000a430, 0x1ce739ce},
@@ -351,9 +351,9 @@ static const u32 ar9565_1p0_baseband_postamble[][5] = {
351 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3379605e, 0x33795d5e}, 351 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3379605e, 0x33795d5e},
352 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 352 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
353 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 353 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
354 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce}, 354 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003a4, 0x000003a4},
355 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021}, 355 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021},
356 {0x00009e3c, 0xcf946222, 0xcf946222, 0xcf946222, 0xcf946222}, 356 {0x00009e3c, 0xcf946222, 0xcf946222, 0xcf946220, 0xcf946220},
357 {0x00009e44, 0xfe321e27, 0xfe321e27, 0xfe291e27, 0xfe291e27}, 357 {0x00009e44, 0xfe321e27, 0xfe321e27, 0xfe291e27, 0xfe291e27},
358 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012}, 358 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012},
359 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000}, 359 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000},
@@ -452,6 +452,7 @@ static const u32 ar9565_1p0_Common_rx_gain_table[][2] = {
452 /* Addr allmodes */ 452 /* Addr allmodes */
453 {0x00004050, 0x00300300}, 453 {0x00004050, 0x00300300},
454 {0x0000406c, 0x00100000}, 454 {0x0000406c, 0x00100000},
455 {0x00009e20, 0x000003b6},
455 {0x0000a000, 0x00010000}, 456 {0x0000a000, 0x00010000},
456 {0x0000a004, 0x00030002}, 457 {0x0000a004, 0x00030002},
457 {0x0000a008, 0x00050004}, 458 {0x0000a008, 0x00050004},
@@ -1230,4 +1231,11 @@ static const u32 ar9565_1p0_modes_high_power_tx_gain_table[][5] = {
1230 {0x00016054, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 1231 {0x00016054, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1231}; 1232};
1232 1233
1234static const u32 ar9565_1p0_baseband_core_txfir_coeff_japan_2484[][2] = {
1235 /* Addr allmodes */
1236 {0x0000a398, 0x00000000},
1237 {0x0000a39c, 0x6f7f0301},
1238 {0x0000a3a0, 0xca9228ee},
1239};
1240
1233#endif /* INITVALS_9565_1P0_H */ 1241#endif /* INITVALS_9565_1P0_H */
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index da24ba2a5b41..15afde3c348b 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -459,8 +459,8 @@ void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
459 459
460#define ATH_DUMP_BTCOEX(_s, _val) \ 460#define ATH_DUMP_BTCOEX(_s, _val) \
461 do { \ 461 do { \
462 len += snprintf(buf + len, size - len, \ 462 len += scnprintf(buf + len, size - len, \
463 "%20s : %10d\n", _s, (_val)); \ 463 "%20s : %10d\n", _s, (_val)); \
464 } while (0) 464 } while (0)
465 465
466enum bt_op_flags { 466enum bt_op_flags {
@@ -581,7 +581,6 @@ static inline void ath_fill_led_pin(struct ath_softc *sc)
581#define ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI 50 581#define ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI 50
582#define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI 50 582#define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI 50
583 583
584#define ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA -1
585#define ATH_ANT_DIV_COMB_LNA1_DELTA_HI -4 584#define ATH_ANT_DIV_COMB_LNA1_DELTA_HI -4
586#define ATH_ANT_DIV_COMB_LNA1_DELTA_MID -2 585#define ATH_ANT_DIV_COMB_LNA1_DELTA_MID -2
587#define ATH_ANT_DIV_COMB_LNA1_DELTA_LOW 2 586#define ATH_ANT_DIV_COMB_LNA1_DELTA_LOW 2
@@ -626,12 +625,15 @@ void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
626/* Main driver core */ 625/* Main driver core */
627/********************/ 626/********************/
628 627
629#define ATH9K_PCI_CUS198 0x0001 628#define ATH9K_PCI_CUS198 0x0001
630#define ATH9K_PCI_CUS230 0x0002 629#define ATH9K_PCI_CUS230 0x0002
631#define ATH9K_PCI_CUS217 0x0004 630#define ATH9K_PCI_CUS217 0x0004
632#define ATH9K_PCI_WOW 0x0008 631#define ATH9K_PCI_CUS252 0x0008
633#define ATH9K_PCI_BT_ANT_DIV 0x0010 632#define ATH9K_PCI_WOW 0x0010
634#define ATH9K_PCI_D3_L1_WAR 0x0020 633#define ATH9K_PCI_BT_ANT_DIV 0x0020
634#define ATH9K_PCI_D3_L1_WAR 0x0040
635#define ATH9K_PCI_AR9565_1ANT 0x0080
636#define ATH9K_PCI_AR9565_2ANT 0x0100
635 637
636/* 638/*
637 * Default cache line size, in bytes. 639 * Default cache line size, in bytes.
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index b5c16b3a37b9..17be35392bb4 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -334,6 +334,8 @@ void ath9k_beacon_tasklet(unsigned long data)
334 if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) { 334 if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) {
335 sc->beacon.bmisscnt++; 335 sc->beacon.bmisscnt++;
336 336
337 ath9k_hw_check_nav(ah);
338
337 if (!ath9k_hw_check_alive(ah)) 339 if (!ath9k_hw_check_alive(ah))
338 ieee80211_queue_work(sc->hw, &sc->hw_check_work); 340 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
339 341
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 5e8219a91e25..d438a0341e68 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -119,7 +119,7 @@ static void ath9k_hw_update_nfcal_hist_buffer(struct ath_hw *ah,
119 ath_dbg(common, CALIBRATE, 119 ath_dbg(common, CALIBRATE,
120 "NFmid[%d] (%d) > MAX (%d), %s\n", 120 "NFmid[%d] (%d) > MAX (%d), %s\n",
121 i, h[i].privNF, limit->max, 121 i, h[i].privNF, limit->max,
122 (cal->nfcal_interference ? 122 (test_bit(NFCAL_INTF, &cal->cal_flags) ?
123 "not corrected (due to interference)" : 123 "not corrected (due to interference)" :
124 "correcting to MAX")); 124 "correcting to MAX"));
125 125
@@ -130,7 +130,7 @@ static void ath9k_hw_update_nfcal_hist_buffer(struct ath_hw *ah,
130 * we bypass this limit here in order to better deal 130 * we bypass this limit here in order to better deal
131 * with our environment. 131 * with our environment.
132 */ 132 */
133 if (!cal->nfcal_interference) 133 if (!test_bit(NFCAL_INTF, &cal->cal_flags))
134 h[i].privNF = limit->max; 134 h[i].privNF = limit->max;
135 } 135 }
136 } 136 }
@@ -141,7 +141,7 @@ static void ath9k_hw_update_nfcal_hist_buffer(struct ath_hw *ah,
141 * Re-enable the enforcement of the NF maximum again. 141 * Re-enable the enforcement of the NF maximum again.
142 */ 142 */
143 if (!high_nf_mid) 143 if (!high_nf_mid)
144 cal->nfcal_interference = false; 144 clear_bit(NFCAL_INTF, &cal->cal_flags);
145} 145}
146 146
147static bool ath9k_hw_get_nf_thresh(struct ath_hw *ah, 147static bool ath9k_hw_get_nf_thresh(struct ath_hw *ah,
@@ -220,7 +220,7 @@ EXPORT_SYMBOL(ath9k_hw_reset_calvalid);
220void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update) 220void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update)
221{ 221{
222 if (ah->caldata) 222 if (ah->caldata)
223 ah->caldata->nfcal_pending = true; 223 set_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
224 224
225 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, 225 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
226 AR_PHY_AGC_CONTROL_ENABLE_NF); 226 AR_PHY_AGC_CONTROL_ENABLE_NF);
@@ -391,7 +391,7 @@ bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan)
391 } 391 }
392 392
393 h = caldata->nfCalHist; 393 h = caldata->nfCalHist;
394 caldata->nfcal_pending = false; 394 clear_bit(NFCAL_PENDING, &caldata->cal_flags);
395 ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray); 395 ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray);
396 chan->noisefloor = h[0].privNF; 396 chan->noisefloor = h[0].privNF;
397 ah->noise = ath9k_hw_getchan_noise(ah, chan); 397 ah->noise = ath9k_hw_getchan_noise(ah, chan);
@@ -437,12 +437,12 @@ void ath9k_hw_bstuck_nfcal(struct ath_hw *ah)
437 * the baseband update the internal NF value itself, similar to 437 * the baseband update the internal NF value itself, similar to
438 * what is being done after a full reset. 438 * what is being done after a full reset.
439 */ 439 */
440 if (!caldata->nfcal_pending) 440 if (!test_bit(NFCAL_PENDING, &caldata->cal_flags))
441 ath9k_hw_start_nfcal(ah, true); 441 ath9k_hw_start_nfcal(ah, true);
442 else if (!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF)) 442 else if (!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF))
443 ath9k_hw_getnf(ah, ah->curchan); 443 ath9k_hw_getnf(ah, ah->curchan);
444 444
445 caldata->nfcal_interference = true; 445 set_bit(NFCAL_INTF, &caldata->cal_flags);
446} 446}
447EXPORT_SYMBOL(ath9k_hw_bstuck_nfcal); 447EXPORT_SYMBOL(ath9k_hw_bstuck_nfcal);
448 448
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index c088744a6bfb..1be2c787aac9 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -104,37 +104,37 @@ static ssize_t read_file_ani(struct file *file, char __user *user_buf,
104 return -ENOMEM; 104 return -ENOMEM;
105 105
106 if (common->disable_ani) { 106 if (common->disable_ani) {
107 len += snprintf(buf + len, size - len, "%s: %s\n", 107 len += scnprintf(buf + len, size - len, "%s: %s\n",
108 "ANI", "DISABLED"); 108 "ANI", "DISABLED");
109 goto exit; 109 goto exit;
110 } 110 }
111 111
112 len += snprintf(buf + len, size - len, "%15s: %s\n", 112 len += scnprintf(buf + len, size - len, "%15s: %s\n",
113 "ANI", "ENABLED"); 113 "ANI", "ENABLED");
114 len += snprintf(buf + len, size - len, "%15s: %u\n", 114 len += scnprintf(buf + len, size - len, "%15s: %u\n",
115 "ANI RESET", ah->stats.ast_ani_reset); 115 "ANI RESET", ah->stats.ast_ani_reset);
116 len += snprintf(buf + len, size - len, "%15s: %u\n", 116 len += scnprintf(buf + len, size - len, "%15s: %u\n",
117 "SPUR UP", ah->stats.ast_ani_spurup); 117 "SPUR UP", ah->stats.ast_ani_spurup);
118 len += snprintf(buf + len, size - len, "%15s: %u\n", 118 len += scnprintf(buf + len, size - len, "%15s: %u\n",
119 "SPUR DOWN", ah->stats.ast_ani_spurup); 119 "SPUR DOWN", ah->stats.ast_ani_spurup);
120 len += snprintf(buf + len, size - len, "%15s: %u\n", 120 len += scnprintf(buf + len, size - len, "%15s: %u\n",
121 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon); 121 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
122 len += snprintf(buf + len, size - len, "%15s: %u\n", 122 len += scnprintf(buf + len, size - len, "%15s: %u\n",
123 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff); 123 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
124 len += snprintf(buf + len, size - len, "%15s: %u\n", 124 len += scnprintf(buf + len, size - len, "%15s: %u\n",
125 "MRC-CCK ON", ah->stats.ast_ani_ccklow); 125 "MRC-CCK ON", ah->stats.ast_ani_ccklow);
126 len += snprintf(buf + len, size - len, "%15s: %u\n", 126 len += scnprintf(buf + len, size - len, "%15s: %u\n",
127 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh); 127 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
128 len += snprintf(buf + len, size - len, "%15s: %u\n", 128 len += scnprintf(buf + len, size - len, "%15s: %u\n",
129 "FIR-STEP UP", ah->stats.ast_ani_stepup); 129 "FIR-STEP UP", ah->stats.ast_ani_stepup);
130 len += snprintf(buf + len, size - len, "%15s: %u\n", 130 len += scnprintf(buf + len, size - len, "%15s: %u\n",
131 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown); 131 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
132 len += snprintf(buf + len, size - len, "%15s: %u\n", 132 len += scnprintf(buf + len, size - len, "%15s: %u\n",
133 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero); 133 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
134 len += snprintf(buf + len, size - len, "%15s: %u\n", 134 len += scnprintf(buf + len, size - len, "%15s: %u\n",
135 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs); 135 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
136 len += snprintf(buf + len, size - len, "%15s: %u\n", 136 len += scnprintf(buf + len, size - len, "%15s: %u\n",
137 "CCK ERRORS", ah->stats.ast_ani_cckerrs); 137 "CCK ERRORS", ah->stats.ast_ani_cckerrs);
138exit: 138exit:
139 if (len > size) 139 if (len > size)
140 len = size; 140 len = size;
@@ -280,70 +280,70 @@ static ssize_t read_file_antenna_diversity(struct file *file,
280 return -ENOMEM; 280 return -ENOMEM;
281 281
282 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) { 282 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
283 len += snprintf(buf + len, size - len, "%s\n", 283 len += scnprintf(buf + len, size - len, "%s\n",
284 "Antenna Diversity Combining is disabled"); 284 "Antenna Diversity Combining is disabled");
285 goto exit; 285 goto exit;
286 } 286 }
287 287
288 ath9k_ps_wakeup(sc); 288 ath9k_ps_wakeup(sc);
289 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf); 289 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
290 len += snprintf(buf + len, size - len, "Current MAIN config : %s\n", 290 len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
291 lna_conf_str[div_ant_conf.main_lna_conf]); 291 lna_conf_str[div_ant_conf.main_lna_conf]);
292 len += snprintf(buf + len, size - len, "Current ALT config : %s\n", 292 len += scnprintf(buf + len, size - len, "Current ALT config : %s\n",
293 lna_conf_str[div_ant_conf.alt_lna_conf]); 293 lna_conf_str[div_ant_conf.alt_lna_conf]);
294 len += snprintf(buf + len, size - len, "Average MAIN RSSI : %d\n", 294 len += scnprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
295 as_main->rssi_avg); 295 as_main->rssi_avg);
296 len += snprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n", 296 len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
297 as_alt->rssi_avg); 297 as_alt->rssi_avg);
298 ath9k_ps_restore(sc); 298 ath9k_ps_restore(sc);
299 299
300 len += snprintf(buf + len, size - len, "Packet Receive Cnt:\n"); 300 len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
301 len += snprintf(buf + len, size - len, "-------------------\n"); 301 len += scnprintf(buf + len, size - len, "-------------------\n");
302 302
303 len += snprintf(buf + len, size - len, "%30s%15s\n", 303 len += scnprintf(buf + len, size - len, "%30s%15s\n",
304 "MAIN", "ALT"); 304 "MAIN", "ALT");
305 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 305 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
306 "TOTAL COUNT", 306 "TOTAL COUNT",
307 as_main->recv_cnt, 307 as_main->recv_cnt,
308 as_alt->recv_cnt); 308 as_alt->recv_cnt);
309 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 309 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
310 "LNA1", 310 "LNA1",
311 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1], 311 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
312 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]); 312 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
313 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 313 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
314 "LNA2", 314 "LNA2",
315 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2], 315 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
316 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]); 316 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
317 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 317 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
318 "LNA1 + LNA2", 318 "LNA1 + LNA2",
319 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2], 319 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
320 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]); 320 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
321 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 321 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
322 "LNA1 - LNA2", 322 "LNA1 - LNA2",
323 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2], 323 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
324 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]); 324 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
325 325
326 len += snprintf(buf + len, size - len, "\nLNA Config Attempts:\n"); 326 len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
327 len += snprintf(buf + len, size - len, "--------------------\n"); 327 len += scnprintf(buf + len, size - len, "--------------------\n");
328 328
329 len += snprintf(buf + len, size - len, "%30s%15s\n", 329 len += scnprintf(buf + len, size - len, "%30s%15s\n",
330 "MAIN", "ALT"); 330 "MAIN", "ALT");
331 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 331 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
332 "LNA1", 332 "LNA1",
333 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1], 333 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
334 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]); 334 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
335 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 335 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
336 "LNA2", 336 "LNA2",
337 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2], 337 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
338 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]); 338 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
339 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 339 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
340 "LNA1 + LNA2", 340 "LNA1 + LNA2",
341 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2], 341 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
342 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]); 342 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
343 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n", 343 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
344 "LNA1 - LNA2", 344 "LNA1 - LNA2",
345 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2], 345 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
346 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]); 346 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
347 347
348exit: 348exit:
349 if (len > size) 349 if (len > size)
@@ -385,21 +385,21 @@ static ssize_t read_file_dma(struct file *file, char __user *user_buf,
385 (AR_MACMISC_MISC_OBS_BUS_1 << 385 (AR_MACMISC_MISC_OBS_BUS_1 <<
386 AR_MACMISC_MISC_OBS_BUS_MSB_S))); 386 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
387 387
388 len += snprintf(buf + len, DMA_BUF_LEN - len, 388 len += scnprintf(buf + len, DMA_BUF_LEN - len,
389 "Raw DMA Debug values:\n"); 389 "Raw DMA Debug values:\n");
390 390
391 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { 391 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
392 if (i % 4 == 0) 392 if (i % 4 == 0)
393 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); 393 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
394 394
395 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); 395 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
396 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ", 396 len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
397 i, val[i]); 397 i, val[i]);
398 } 398 }
399 399
400 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n"); 400 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
401 len += snprintf(buf + len, DMA_BUF_LEN - len, 401 len += scnprintf(buf + len, DMA_BUF_LEN - len,
402 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); 402 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
403 403
404 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { 404 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
405 if (i == 8) { 405 if (i == 8) {
@@ -412,39 +412,39 @@ static ssize_t read_file_dma(struct file *file, char __user *user_buf,
412 dcuBase++; 412 dcuBase++;
413 } 413 }
414 414
415 len += snprintf(buf + len, DMA_BUF_LEN - len, 415 len += scnprintf(buf + len, DMA_BUF_LEN - len,
416 "%2d %2x %1x %2x %2x\n", 416 "%2d %2x %1x %2x %2x\n",
417 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, 417 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
418 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), 418 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
419 val[2] & (0x7 << (i * 3)) >> (i * 3), 419 val[2] & (0x7 << (i * 3)) >> (i * 3),
420 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); 420 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
421 } 421 }
422 422
423 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); 423 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
424 424
425 len += snprintf(buf + len, DMA_BUF_LEN - len, 425 len += scnprintf(buf + len, DMA_BUF_LEN - len,
426 "qcu_stitch state: %2x qcu_fetch state: %2x\n", 426 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
427 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); 427 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
428 len += snprintf(buf + len, DMA_BUF_LEN - len, 428 len += scnprintf(buf + len, DMA_BUF_LEN - len,
429 "qcu_complete state: %2x dcu_complete state: %2x\n", 429 "qcu_complete state: %2x dcu_complete state: %2x\n",
430 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); 430 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
431 len += snprintf(buf + len, DMA_BUF_LEN - len, 431 len += scnprintf(buf + len, DMA_BUF_LEN - len,
432 "dcu_arb state: %2x dcu_fp state: %2x\n", 432 "dcu_arb state: %2x dcu_fp state: %2x\n",
433 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); 433 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
434 len += snprintf(buf + len, DMA_BUF_LEN - len, 434 len += scnprintf(buf + len, DMA_BUF_LEN - len,
435 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", 435 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
436 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); 436 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
437 len += snprintf(buf + len, DMA_BUF_LEN - len, 437 len += scnprintf(buf + len, DMA_BUF_LEN - len,
438 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", 438 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
439 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); 439 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
440 len += snprintf(buf + len, DMA_BUF_LEN - len, 440 len += scnprintf(buf + len, DMA_BUF_LEN - len,
441 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", 441 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
442 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); 442 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
443 443
444 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n", 444 len += scnprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
445 REG_READ_D(ah, AR_OBS_BUS_1)); 445 REG_READ_D(ah, AR_OBS_BUS_1));
446 len += snprintf(buf + len, DMA_BUF_LEN - len, 446 len += scnprintf(buf + len, DMA_BUF_LEN - len,
447 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR)); 447 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
448 448
449 ath9k_ps_restore(sc); 449 ath9k_ps_restore(sc);
450 450
@@ -530,9 +530,9 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
530 530
531#define PR_IS(a, s) \ 531#define PR_IS(a, s) \
532 do { \ 532 do { \
533 len += snprintf(buf + len, mxlen - len, \ 533 len += scnprintf(buf + len, mxlen - len, \
534 "%21s: %10u\n", a, \ 534 "%21s: %10u\n", a, \
535 sc->debug.stats.istats.s); \ 535 sc->debug.stats.istats.s); \
536 } while (0) 536 } while (0)
537 537
538 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { 538 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
@@ -563,8 +563,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
563 PR_IS("GENTIMER", gen_timer); 563 PR_IS("GENTIMER", gen_timer);
564 PR_IS("TOTAL", total); 564 PR_IS("TOTAL", total);
565 565
566 len += snprintf(buf + len, mxlen - len, 566 len += scnprintf(buf + len, mxlen - len,
567 "SYNC_CAUSE stats:\n"); 567 "SYNC_CAUSE stats:\n");
568 568
569 PR_IS("Sync-All", sync_cause_all); 569 PR_IS("Sync-All", sync_cause_all);
570 PR_IS("RTC-IRQ", sync_rtc_irq); 570 PR_IS("RTC-IRQ", sync_rtc_irq);
@@ -655,16 +655,16 @@ static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
655 655
656 ath_txq_lock(sc, txq); 656 ath_txq_lock(sc, txq);
657 657
658 len += snprintf(buf + len, size - len, "%s: %d ", 658 len += scnprintf(buf + len, size - len, "%s: %d ",
659 "qnum", txq->axq_qnum); 659 "qnum", txq->axq_qnum);
660 len += snprintf(buf + len, size - len, "%s: %2d ", 660 len += scnprintf(buf + len, size - len, "%s: %2d ",
661 "qdepth", txq->axq_depth); 661 "qdepth", txq->axq_depth);
662 len += snprintf(buf + len, size - len, "%s: %2d ", 662 len += scnprintf(buf + len, size - len, "%s: %2d ",
663 "ampdu-depth", txq->axq_ampdu_depth); 663 "ampdu-depth", txq->axq_ampdu_depth);
664 len += snprintf(buf + len, size - len, "%s: %3d ", 664 len += scnprintf(buf + len, size - len, "%s: %3d ",
665 "pending", txq->pending_frames); 665 "pending", txq->pending_frames);
666 len += snprintf(buf + len, size - len, "%s: %d\n", 666 len += scnprintf(buf + len, size - len, "%s: %d\n",
667 "stopped", txq->stopped); 667 "stopped", txq->stopped);
668 668
669 ath_txq_unlock(sc, txq); 669 ath_txq_unlock(sc, txq);
670 return len; 670 return len;
@@ -687,11 +687,11 @@ static ssize_t read_file_queues(struct file *file, char __user *user_buf,
687 687
688 for (i = 0; i < IEEE80211_NUM_ACS; i++) { 688 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
689 txq = sc->tx.txq_map[i]; 689 txq = sc->tx.txq_map[i];
690 len += snprintf(buf + len, size - len, "(%s): ", qname[i]); 690 len += scnprintf(buf + len, size - len, "(%s): ", qname[i]);
691 len += print_queue(sc, txq, buf + len, size - len); 691 len += print_queue(sc, txq, buf + len, size - len);
692 } 692 }
693 693
694 len += snprintf(buf + len, size - len, "(CAB): "); 694 len += scnprintf(buf + len, size - len, "(CAB): ");
695 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len); 695 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
696 696
697 if (len > size) 697 if (len > size)
@@ -716,80 +716,82 @@ static ssize_t read_file_misc(struct file *file, char __user *user_buf,
716 unsigned int reg; 716 unsigned int reg;
717 u32 rxfilter; 717 u32 rxfilter;
718 718
719 len += snprintf(buf + len, sizeof(buf) - len, 719 len += scnprintf(buf + len, sizeof(buf) - len,
720 "BSSID: %pM\n", common->curbssid); 720 "BSSID: %pM\n", common->curbssid);
721 len += snprintf(buf + len, sizeof(buf) - len, 721 len += scnprintf(buf + len, sizeof(buf) - len,
722 "BSSID-MASK: %pM\n", common->bssidmask); 722 "BSSID-MASK: %pM\n", common->bssidmask);
723 len += snprintf(buf + len, sizeof(buf) - len, 723 len += scnprintf(buf + len, sizeof(buf) - len,
724 "OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode)); 724 "OPMODE: %s\n",
725 ath_opmode_to_string(sc->sc_ah->opmode));
725 726
726 ath9k_ps_wakeup(sc); 727 ath9k_ps_wakeup(sc);
727 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah); 728 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
728 ath9k_ps_restore(sc); 729 ath9k_ps_restore(sc);
729 730
730 len += snprintf(buf + len, sizeof(buf) - len, 731 len += scnprintf(buf + len, sizeof(buf) - len,
731 "RXFILTER: 0x%x", rxfilter); 732 "RXFILTER: 0x%x", rxfilter);
732 733
733 if (rxfilter & ATH9K_RX_FILTER_UCAST) 734 if (rxfilter & ATH9K_RX_FILTER_UCAST)
734 len += snprintf(buf + len, sizeof(buf) - len, " UCAST"); 735 len += scnprintf(buf + len, sizeof(buf) - len, " UCAST");
735 if (rxfilter & ATH9K_RX_FILTER_MCAST) 736 if (rxfilter & ATH9K_RX_FILTER_MCAST)
736 len += snprintf(buf + len, sizeof(buf) - len, " MCAST"); 737 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST");
737 if (rxfilter & ATH9K_RX_FILTER_BCAST) 738 if (rxfilter & ATH9K_RX_FILTER_BCAST)
738 len += snprintf(buf + len, sizeof(buf) - len, " BCAST"); 739 len += scnprintf(buf + len, sizeof(buf) - len, " BCAST");
739 if (rxfilter & ATH9K_RX_FILTER_CONTROL) 740 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
740 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL"); 741 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL");
741 if (rxfilter & ATH9K_RX_FILTER_BEACON) 742 if (rxfilter & ATH9K_RX_FILTER_BEACON)
742 len += snprintf(buf + len, sizeof(buf) - len, " BEACON"); 743 len += scnprintf(buf + len, sizeof(buf) - len, " BEACON");
743 if (rxfilter & ATH9K_RX_FILTER_PROM) 744 if (rxfilter & ATH9K_RX_FILTER_PROM)
744 len += snprintf(buf + len, sizeof(buf) - len, " PROM"); 745 len += scnprintf(buf + len, sizeof(buf) - len, " PROM");
745 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ) 746 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
746 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ"); 747 len += scnprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
747 if (rxfilter & ATH9K_RX_FILTER_PHYERR) 748 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
748 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR"); 749 len += scnprintf(buf + len, sizeof(buf) - len, " PHYERR");
749 if (rxfilter & ATH9K_RX_FILTER_MYBEACON) 750 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
750 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON"); 751 len += scnprintf(buf + len, sizeof(buf) - len, " MYBEACON");
751 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR) 752 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
752 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR"); 753 len += scnprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
753 if (rxfilter & ATH9K_RX_FILTER_PSPOLL) 754 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
754 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL"); 755 len += scnprintf(buf + len, sizeof(buf) - len, " PSPOLL");
755 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR) 756 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
756 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR"); 757 len += scnprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
757 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL) 758 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
758 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL"); 759 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
759 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER) 760 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
760 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER"); 761 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
761 762
762 len += snprintf(buf + len, sizeof(buf) - len, "\n"); 763 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
763 764
764 reg = sc->sc_ah->imask; 765 reg = sc->sc_ah->imask;
765 766
766 len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg); 767 len += scnprintf(buf + len, sizeof(buf) - len,
768 "INTERRUPT-MASK: 0x%x", reg);
767 769
768 if (reg & ATH9K_INT_SWBA) 770 if (reg & ATH9K_INT_SWBA)
769 len += snprintf(buf + len, sizeof(buf) - len, " SWBA"); 771 len += scnprintf(buf + len, sizeof(buf) - len, " SWBA");
770 if (reg & ATH9K_INT_BMISS) 772 if (reg & ATH9K_INT_BMISS)
771 len += snprintf(buf + len, sizeof(buf) - len, " BMISS"); 773 len += scnprintf(buf + len, sizeof(buf) - len, " BMISS");
772 if (reg & ATH9K_INT_CST) 774 if (reg & ATH9K_INT_CST)
773 len += snprintf(buf + len, sizeof(buf) - len, " CST"); 775 len += scnprintf(buf + len, sizeof(buf) - len, " CST");
774 if (reg & ATH9K_INT_RX) 776 if (reg & ATH9K_INT_RX)
775 len += snprintf(buf + len, sizeof(buf) - len, " RX"); 777 len += scnprintf(buf + len, sizeof(buf) - len, " RX");
776 if (reg & ATH9K_INT_RXHP) 778 if (reg & ATH9K_INT_RXHP)
777 len += snprintf(buf + len, sizeof(buf) - len, " RXHP"); 779 len += scnprintf(buf + len, sizeof(buf) - len, " RXHP");
778 if (reg & ATH9K_INT_RXLP) 780 if (reg & ATH9K_INT_RXLP)
779 len += snprintf(buf + len, sizeof(buf) - len, " RXLP"); 781 len += scnprintf(buf + len, sizeof(buf) - len, " RXLP");
780 if (reg & ATH9K_INT_BB_WATCHDOG) 782 if (reg & ATH9K_INT_BB_WATCHDOG)
781 len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG"); 783 len += scnprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
782 784
783 len += snprintf(buf + len, sizeof(buf) - len, "\n"); 785 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
784 786
785 ath9k_calculate_iter_data(hw, NULL, &iter_data); 787 ath9k_calculate_iter_data(hw, NULL, &iter_data);
786 788
787 len += snprintf(buf + len, sizeof(buf) - len, 789 len += scnprintf(buf + len, sizeof(buf) - len,
788 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i" 790 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
789 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n", 791 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
790 iter_data.naps, iter_data.nstations, iter_data.nmeshes, 792 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
791 iter_data.nwds, iter_data.nadhocs, 793 iter_data.nwds, iter_data.nadhocs,
792 sc->nvifs, sc->nbcnvifs); 794 sc->nvifs, sc->nbcnvifs);
793 795
794 if (len > sizeof(buf)) 796 if (len > sizeof(buf))
795 len = sizeof(buf); 797 len = sizeof(buf);
@@ -805,27 +807,27 @@ static ssize_t read_file_reset(struct file *file, char __user *user_buf,
805 char buf[512]; 807 char buf[512];
806 unsigned int len = 0; 808 unsigned int len = 0;
807 809
808 len += snprintf(buf + len, sizeof(buf) - len, 810 len += scnprintf(buf + len, sizeof(buf) - len,
809 "%17s: %2d\n", "Baseband Hang", 811 "%17s: %2d\n", "Baseband Hang",
810 sc->debug.stats.reset[RESET_TYPE_BB_HANG]); 812 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
811 len += snprintf(buf + len, sizeof(buf) - len, 813 len += scnprintf(buf + len, sizeof(buf) - len,
812 "%17s: %2d\n", "Baseband Watchdog", 814 "%17s: %2d\n", "Baseband Watchdog",
813 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]); 815 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
814 len += snprintf(buf + len, sizeof(buf) - len, 816 len += scnprintf(buf + len, sizeof(buf) - len,
815 "%17s: %2d\n", "Fatal HW Error", 817 "%17s: %2d\n", "Fatal HW Error",
816 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]); 818 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
817 len += snprintf(buf + len, sizeof(buf) - len, 819 len += scnprintf(buf + len, sizeof(buf) - len,
818 "%17s: %2d\n", "TX HW error", 820 "%17s: %2d\n", "TX HW error",
819 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]); 821 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
820 len += snprintf(buf + len, sizeof(buf) - len, 822 len += scnprintf(buf + len, sizeof(buf) - len,
821 "%17s: %2d\n", "TX Path Hang", 823 "%17s: %2d\n", "TX Path Hang",
822 sc->debug.stats.reset[RESET_TYPE_TX_HANG]); 824 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
823 len += snprintf(buf + len, sizeof(buf) - len, 825 len += scnprintf(buf + len, sizeof(buf) - len,
824 "%17s: %2d\n", "PLL RX Hang", 826 "%17s: %2d\n", "PLL RX Hang",
825 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]); 827 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
826 len += snprintf(buf + len, sizeof(buf) - len, 828 len += scnprintf(buf + len, sizeof(buf) - len,
827 "%17s: %2d\n", "MCI Reset", 829 "%17s: %2d\n", "MCI Reset",
828 sc->debug.stats.reset[RESET_TYPE_MCI]); 830 sc->debug.stats.reset[RESET_TYPE_MCI]);
829 831
830 if (len > sizeof(buf)) 832 if (len > sizeof(buf))
831 len = sizeof(buf); 833 len = sizeof(buf);
@@ -902,14 +904,14 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
902 size_t count, loff_t *ppos) 904 size_t count, loff_t *ppos)
903{ 905{
904#define PHY_ERR(s, p) \ 906#define PHY_ERR(s, p) \
905 len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \ 907 len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \
906 sc->debug.stats.rxstats.phy_err_stats[p]); 908 sc->debug.stats.rxstats.phy_err_stats[p]);
907 909
908#define RXS_ERR(s, e) \ 910#define RXS_ERR(s, e) \
909 do { \ 911 do { \
910 len += snprintf(buf + len, size - len, \ 912 len += scnprintf(buf + len, size - len, \
911 "%22s : %10u\n", s, \ 913 "%22s : %10u\n", s, \
912 sc->debug.stats.rxstats.e); \ 914 sc->debug.stats.rxstats.e);\
913 } while (0) 915 } while (0)
914 916
915 struct ath_softc *sc = file->private_data; 917 struct ath_softc *sc = file->private_data;
@@ -1439,22 +1441,22 @@ static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1439 if (!buf) 1441 if (!buf)
1440 return -ENOMEM; 1442 return -ENOMEM;
1441 1443
1442 len += snprintf(buf + len, size - len, 1444 len += scnprintf(buf + len, size - len,
1443 "Channel Noise Floor : %d\n", ah->noise); 1445 "Channel Noise Floor : %d\n", ah->noise);
1444 len += snprintf(buf + len, size - len, 1446 len += scnprintf(buf + len, size - len,
1445 "Chain | privNF | # Readings | NF Readings\n"); 1447 "Chain | privNF | # Readings | NF Readings\n");
1446 for (i = 0; i < NUM_NF_READINGS; i++) { 1448 for (i = 0; i < NUM_NF_READINGS; i++) {
1447 if (!(chainmask & (1 << i)) || 1449 if (!(chainmask & (1 << i)) ||
1448 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf))) 1450 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1449 continue; 1451 continue;
1450 1452
1451 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount; 1453 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1452 len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t", 1454 len += scnprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1453 i, h[i].privNF, nread); 1455 i, h[i].privNF, nread);
1454 for (j = 0; j < nread; j++) 1456 for (j = 0; j < nread; j++)
1455 len += snprintf(buf + len, size - len, 1457 len += scnprintf(buf + len, size - len,
1456 " %d", h[i].nfCalBuffer[j]); 1458 " %d", h[i].nfCalBuffer[j]);
1457 len += snprintf(buf + len, size - len, "\n"); 1459 len += scnprintf(buf + len, size - len, "\n");
1458 } 1460 }
1459 1461
1460 if (len > size) 1462 if (len > size)
@@ -1543,8 +1545,8 @@ static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1543 return -ENOMEM; 1545 return -ENOMEM;
1544 1546
1545 if (!sc->sc_ah->common.btcoex_enabled) { 1547 if (!sc->sc_ah->common.btcoex_enabled) {
1546 len = snprintf(buf, size, "%s\n", 1548 len = scnprintf(buf, size, "%s\n",
1547 "BTCOEX is disabled"); 1549 "BTCOEX is disabled");
1548 goto exit; 1550 goto exit;
1549 } 1551 }
1550 1552
@@ -1582,43 +1584,43 @@ static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1582 return -ENOMEM; 1584 return -ENOMEM;
1583 1585
1584 if (!an->sta->ht_cap.ht_supported) { 1586 if (!an->sta->ht_cap.ht_supported) {
1585 len = snprintf(buf, size, "%s\n", 1587 len = scnprintf(buf, size, "%s\n",
1586 "HT not supported"); 1588 "HT not supported");
1587 goto exit; 1589 goto exit;
1588 } 1590 }
1589 1591
1590 len = snprintf(buf, size, "Max-AMPDU: %d\n", 1592 len = scnprintf(buf, size, "Max-AMPDU: %d\n",
1591 an->maxampdu); 1593 an->maxampdu);
1592 len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n", 1594 len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1593 an->mpdudensity); 1595 an->mpdudensity);
1594 1596
1595 len += snprintf(buf + len, size - len, 1597 len += scnprintf(buf + len, size - len,
1596 "%2s%7s\n", "AC", "SCHED"); 1598 "%2s%7s\n", "AC", "SCHED");
1597 1599
1598 for (acno = 0, ac = &an->ac[acno]; 1600 for (acno = 0, ac = &an->ac[acno];
1599 acno < IEEE80211_NUM_ACS; acno++, ac++) { 1601 acno < IEEE80211_NUM_ACS; acno++, ac++) {
1600 txq = ac->txq; 1602 txq = ac->txq;
1601 ath_txq_lock(sc, txq); 1603 ath_txq_lock(sc, txq);
1602 len += snprintf(buf + len, size - len, 1604 len += scnprintf(buf + len, size - len,
1603 "%2d%7d\n", 1605 "%2d%7d\n",
1604 acno, ac->sched); 1606 acno, ac->sched);
1605 ath_txq_unlock(sc, txq); 1607 ath_txq_unlock(sc, txq);
1606 } 1608 }
1607 1609
1608 len += snprintf(buf + len, size - len, 1610 len += scnprintf(buf + len, size - len,
1609 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n", 1611 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1610 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE", 1612 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1611 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED"); 1613 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1612 1614
1613 for (tidno = 0, tid = &an->tid[tidno]; 1615 for (tidno = 0, tid = &an->tid[tidno];
1614 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { 1616 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1615 txq = tid->ac->txq; 1617 txq = tid->ac->txq;
1616 ath_txq_lock(sc, txq); 1618 ath_txq_lock(sc, txq);
1617 len += snprintf(buf + len, size - len, 1619 len += scnprintf(buf + len, size - len,
1618 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n", 1620 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1619 tid->tidno, tid->seq_start, tid->seq_next, 1621 tid->tidno, tid->seq_start, tid->seq_next,
1620 tid->baw_size, tid->baw_head, tid->baw_tail, 1622 tid->baw_size, tid->baw_head, tid->baw_tail,
1621 tid->bar_index, tid->sched, tid->paused); 1623 tid->bar_index, tid->sched, tid->paused);
1622 ath_txq_unlock(sc, txq); 1624 ath_txq_unlock(sc, txq);
1623 } 1625 }
1624exit: 1626exit:
diff --git a/drivers/net/wireless/ath/ath9k/debug.h b/drivers/net/wireless/ath/ath9k/debug.h
index 6e1556fa2f3e..d6e3fa4299a4 100644
--- a/drivers/net/wireless/ath/ath9k/debug.h
+++ b/drivers/net/wireless/ath/ath9k/debug.h
@@ -193,12 +193,12 @@ struct ath_tx_stats {
193#define TXSTATS sc->debug.stats.txstats 193#define TXSTATS sc->debug.stats.txstats
194#define PR(str, elem) \ 194#define PR(str, elem) \
195 do { \ 195 do { \
196 len += snprintf(buf + len, size - len, \ 196 len += scnprintf(buf + len, size - len, \
197 "%s%13u%11u%10u%10u\n", str, \ 197 "%s%13u%11u%10u%10u\n", str, \
198 TXSTATS[PR_QNUM(IEEE80211_AC_BE)].elem, \ 198 TXSTATS[PR_QNUM(IEEE80211_AC_BE)].elem,\
199 TXSTATS[PR_QNUM(IEEE80211_AC_BK)].elem, \ 199 TXSTATS[PR_QNUM(IEEE80211_AC_BK)].elem,\
200 TXSTATS[PR_QNUM(IEEE80211_AC_VI)].elem, \ 200 TXSTATS[PR_QNUM(IEEE80211_AC_VI)].elem,\
201 TXSTATS[PR_QNUM(IEEE80211_AC_VO)].elem); \ 201 TXSTATS[PR_QNUM(IEEE80211_AC_VO)].elem); \
202 } while(0) 202 } while(0)
203 203
204#define RX_STAT_INC(c) (sc->debug.stats.rxstats.c++) 204#define RX_STAT_INC(c) (sc->debug.stats.rxstats.c++)
diff --git a/drivers/net/wireless/ath/ath9k/dfs_debug.c b/drivers/net/wireless/ath/ath9k/dfs_debug.c
index 3c6e4138a95d..821599135d8a 100644
--- a/drivers/net/wireless/ath/ath9k/dfs_debug.c
+++ b/drivers/net/wireless/ath/ath9k/dfs_debug.c
@@ -25,11 +25,11 @@
25struct ath_dfs_pool_stats global_dfs_pool_stats = { 0 }; 25struct ath_dfs_pool_stats global_dfs_pool_stats = { 0 };
26 26
27#define ATH9K_DFS_STAT(s, p) \ 27#define ATH9K_DFS_STAT(s, p) \
28 len += snprintf(buf + len, size - len, "%28s : %10u\n", s, \ 28 len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
29 sc->debug.stats.dfs_stats.p); 29 sc->debug.stats.dfs_stats.p);
30#define ATH9K_DFS_POOL_STAT(s, p) \ 30#define ATH9K_DFS_POOL_STAT(s, p) \
31 len += snprintf(buf + len, size - len, "%28s : %10u\n", s, \ 31 len += scnprintf(buf + len, size - len, "%28s : %10u\n", s, \
32 global_dfs_pool_stats.p); 32 global_dfs_pool_stats.p);
33 33
34static ssize_t read_file_dfs(struct file *file, char __user *user_buf, 34static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
35 size_t count, loff_t *ppos) 35 size_t count, loff_t *ppos)
@@ -44,12 +44,12 @@ static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
44 if (buf == NULL) 44 if (buf == NULL)
45 return -ENOMEM; 45 return -ENOMEM;
46 46
47 len += snprintf(buf + len, size - len, "DFS support for " 47 len += scnprintf(buf + len, size - len, "DFS support for "
48 "macVersion = 0x%x, macRev = 0x%x: %s\n", 48 "macVersion = 0x%x, macRev = 0x%x: %s\n",
49 hw_ver->macVersion, hw_ver->macRev, 49 hw_ver->macVersion, hw_ver->macRev,
50 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ? 50 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
51 "enabled" : "disabled"); 51 "enabled" : "disabled");
52 len += snprintf(buf + len, size - len, "Pulse detector statistics:\n"); 52 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
53 ATH9K_DFS_STAT("pulse events reported ", pulses_total); 53 ATH9K_DFS_STAT("pulse events reported ", pulses_total);
54 ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs); 54 ATH9K_DFS_STAT("invalid pulse events ", pulses_no_dfs);
55 ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected); 55 ATH9K_DFS_STAT("DFS pulses detected ", pulses_detected);
@@ -59,11 +59,12 @@ static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
59 ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors); 59 ATH9K_DFS_STAT("Primary channel pulses ", pri_phy_errors);
60 ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors); 60 ATH9K_DFS_STAT("Secondary channel pulses", ext_phy_errors);
61 ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors); 61 ATH9K_DFS_STAT("Dual channel pulses ", dc_phy_errors);
62 len += snprintf(buf + len, size - len, "Radar detector statistics " 62 len += scnprintf(buf + len, size - len, "Radar detector statistics "
63 "(current DFS region: %d)\n", sc->dfs_detector->region); 63 "(current DFS region: %d)\n",
64 sc->dfs_detector->region);
64 ATH9K_DFS_STAT("Pulse events processed ", pulses_processed); 65 ATH9K_DFS_STAT("Pulse events processed ", pulses_processed);
65 ATH9K_DFS_STAT("Radars detected ", radar_detected); 66 ATH9K_DFS_STAT("Radars detected ", radar_detected);
66 len += snprintf(buf + len, size - len, "Global Pool statistics:\n"); 67 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
67 ATH9K_DFS_POOL_STAT("Pool references ", pool_reference); 68 ATH9K_DFS_POOL_STAT("Pool references ", pool_reference);
68 ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated); 69 ATH9K_DFS_POOL_STAT("Pulses allocated ", pulse_allocated);
69 ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error); 70 ATH9K_DFS_POOL_STAT("Pulses alloc error ", pulse_alloc_error);
diff --git a/drivers/net/wireless/ath/ath9k/dfs_pri_detector.c b/drivers/net/wireless/ath/ath9k/dfs_pri_detector.c
index 5ba4b6fe37c0..c718fc379a10 100644
--- a/drivers/net/wireless/ath/ath9k/dfs_pri_detector.c
+++ b/drivers/net/wireless/ath/ath9k/dfs_pri_detector.c
@@ -392,7 +392,7 @@ static struct pri_sequence *pri_detector_add_pulse(struct pri_detector *de,
392 392
393 if (!pseq_handler_create_sequences(de, ts, max_updated_seq)) { 393 if (!pseq_handler_create_sequences(de, ts, max_updated_seq)) {
394 pri_detector_reset(de, ts); 394 pri_detector_reset(de, ts);
395 return false; 395 return NULL;
396 } 396 }
397 397
398 ps = pseq_handler_check_detection(de); 398 ps = pseq_handler_check_detection(de);
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_4k.c b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
index 9ea8e4b779c9..b4091716e9b3 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
@@ -129,10 +129,10 @@ static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
129 struct base_eep_header_4k *pBase = &eep->baseEepHeader; 129 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
130 130
131 if (!dump_base_hdr) { 131 if (!dump_base_hdr) {
132 len += snprintf(buf + len, size - len, 132 len += scnprintf(buf + len, size - len,
133 "%20s :\n", "2GHz modal Header"); 133 "%20s :\n", "2GHz modal Header");
134 len = ath9k_dump_4k_modal_eeprom(buf, len, size, 134 len = ath9k_dump_4k_modal_eeprom(buf, len, size,
135 &eep->modalHeader); 135 &eep->modalHeader);
136 goto out; 136 goto out;
137 } 137 }
138 138
@@ -160,8 +160,8 @@ static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
160 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF); 160 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
161 PR_EEP("TX Gain type", pBase->txGainType); 161 PR_EEP("TX Gain type", pBase->txGainType);
162 162
163 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", 163 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
164 pBase->macAddr); 164 pBase->macAddr);
165 165
166out: 166out:
167 if (len > size) 167 if (len > size)
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_9287.c b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
index 3ae1f3df0637..e1d0c217c104 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
@@ -125,8 +125,8 @@ static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
125 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader; 125 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
126 126
127 if (!dump_base_hdr) { 127 if (!dump_base_hdr) {
128 len += snprintf(buf + len, size - len, 128 len += scnprintf(buf + len, size - len,
129 "%20s :\n", "2GHz modal Header"); 129 "%20s :\n", "2GHz modal Header");
130 len = ar9287_dump_modal_eeprom(buf, len, size, 130 len = ar9287_dump_modal_eeprom(buf, len, size,
131 &eep->modalHeader); 131 &eep->modalHeader);
132 goto out; 132 goto out;
@@ -157,8 +157,8 @@ static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
157 PR_EEP("Power Table Offset", pBase->pwrTableOffset); 157 PR_EEP("Power Table Offset", pBase->pwrTableOffset);
158 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl); 158 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
159 159
160 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", 160 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
161 pBase->macAddr); 161 pBase->macAddr);
162 162
163out: 163out:
164 if (len > size) 164 if (len > size)
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_def.c b/drivers/net/wireless/ath/ath9k/eeprom_def.c
index 1c25368b3836..39107e31e79a 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
@@ -205,12 +205,12 @@ static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
205 struct base_eep_header *pBase = &eep->baseEepHeader; 205 struct base_eep_header *pBase = &eep->baseEepHeader;
206 206
207 if (!dump_base_hdr) { 207 if (!dump_base_hdr) {
208 len += snprintf(buf + len, size - len, 208 len += scnprintf(buf + len, size - len,
209 "%20s :\n", "2GHz modal Header"); 209 "%20s :\n", "2GHz modal Header");
210 len = ath9k_def_dump_modal_eeprom(buf, len, size, 210 len = ath9k_def_dump_modal_eeprom(buf, len, size,
211 &eep->modalHeader[0]); 211 &eep->modalHeader[0]);
212 len += snprintf(buf + len, size - len, 212 len += scnprintf(buf + len, size - len,
213 "%20s :\n", "5GHz modal Header"); 213 "%20s :\n", "5GHz modal Header");
214 len = ath9k_def_dump_modal_eeprom(buf, len, size, 214 len = ath9k_def_dump_modal_eeprom(buf, len, size,
215 &eep->modalHeader[1]); 215 &eep->modalHeader[1]);
216 goto out; 216 goto out;
@@ -240,8 +240,8 @@ static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
240 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF); 240 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
241 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl); 241 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
242 242
243 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", 243 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
244 pBase->macAddr); 244 pBase->macAddr);
245 245
246out: 246out:
247 if (len > size) 247 if (len > size)
diff --git a/drivers/net/wireless/ath/ath9k/gpio.c b/drivers/net/wireless/ath/ath9k/gpio.c
index 4b412aaf4f36..c34f21241da9 100644
--- a/drivers/net/wireless/ath/ath9k/gpio.c
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
@@ -522,22 +522,22 @@ static int ath9k_dump_mci_btcoex(struct ath_softc *sc, u8 *buf, u32 size)
522 ATH_DUMP_BTCOEX("Concurrent Tx", btcoex_hw->mci.concur_tx); 522 ATH_DUMP_BTCOEX("Concurrent Tx", btcoex_hw->mci.concur_tx);
523 ATH_DUMP_BTCOEX("Concurrent RSSI cnt", btcoex->rssi_count); 523 ATH_DUMP_BTCOEX("Concurrent RSSI cnt", btcoex->rssi_count);
524 524
525 len += snprintf(buf + len, size - len, "BT Weights: "); 525 len += scnprintf(buf + len, size - len, "BT Weights: ");
526 for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++) 526 for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++)
527 len += snprintf(buf + len, size - len, "%08x ", 527 len += scnprintf(buf + len, size - len, "%08x ",
528 btcoex_hw->bt_weight[i]); 528 btcoex_hw->bt_weight[i]);
529 len += snprintf(buf + len, size - len, "\n"); 529 len += scnprintf(buf + len, size - len, "\n");
530 len += snprintf(buf + len, size - len, "WLAN Weights: "); 530 len += scnprintf(buf + len, size - len, "WLAN Weights: ");
531 for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++) 531 for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++)
532 len += snprintf(buf + len, size - len, "%08x ", 532 len += scnprintf(buf + len, size - len, "%08x ",
533 btcoex_hw->wlan_weight[i]); 533 btcoex_hw->wlan_weight[i]);
534 len += snprintf(buf + len, size - len, "\n"); 534 len += scnprintf(buf + len, size - len, "\n");
535 len += snprintf(buf + len, size - len, "Tx Priorities: "); 535 len += scnprintf(buf + len, size - len, "Tx Priorities: ");
536 for (i = 0; i < ATH_BTCOEX_STOMP_MAX; i++) 536 for (i = 0; i < ATH_BTCOEX_STOMP_MAX; i++)
537 len += snprintf(buf + len, size - len, "%08x ", 537 len += scnprintf(buf + len, size - len, "%08x ",
538 btcoex_hw->tx_prio[i]); 538 btcoex_hw->tx_prio[i]);
539 539
540 len += snprintf(buf + len, size - len, "\n"); 540 len += scnprintf(buf + len, size - len, "\n");
541 541
542 return len; 542 return len;
543} 543}
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
index c1b45e2f8481..fb071ee4fcfb 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
@@ -37,29 +37,29 @@ static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
37 37
38 ath9k_htc_ps_restore(priv); 38 ath9k_htc_ps_restore(priv);
39 39
40 len += snprintf(buf + len, sizeof(buf) - len, 40 len += scnprintf(buf + len, sizeof(buf) - len,
41 "%20s : %10u\n", "RX", 41 "%20s : %10u\n", "RX",
42 be32_to_cpu(cmd_rsp.rx)); 42 be32_to_cpu(cmd_rsp.rx));
43 43
44 len += snprintf(buf + len, sizeof(buf) - len, 44 len += scnprintf(buf + len, sizeof(buf) - len,
45 "%20s : %10u\n", "RXORN", 45 "%20s : %10u\n", "RXORN",
46 be32_to_cpu(cmd_rsp.rxorn)); 46 be32_to_cpu(cmd_rsp.rxorn));
47 47
48 len += snprintf(buf + len, sizeof(buf) - len, 48 len += scnprintf(buf + len, sizeof(buf) - len,
49 "%20s : %10u\n", "RXEOL", 49 "%20s : %10u\n", "RXEOL",
50 be32_to_cpu(cmd_rsp.rxeol)); 50 be32_to_cpu(cmd_rsp.rxeol));
51 51
52 len += snprintf(buf + len, sizeof(buf) - len, 52 len += scnprintf(buf + len, sizeof(buf) - len,
53 "%20s : %10u\n", "TXURN", 53 "%20s : %10u\n", "TXURN",
54 be32_to_cpu(cmd_rsp.txurn)); 54 be32_to_cpu(cmd_rsp.txurn));
55 55
56 len += snprintf(buf + len, sizeof(buf) - len, 56 len += scnprintf(buf + len, sizeof(buf) - len,
57 "%20s : %10u\n", "TXTO", 57 "%20s : %10u\n", "TXTO",
58 be32_to_cpu(cmd_rsp.txto)); 58 be32_to_cpu(cmd_rsp.txto));
59 59
60 len += snprintf(buf + len, sizeof(buf) - len, 60 len += scnprintf(buf + len, sizeof(buf) - len,
61 "%20s : %10u\n", "CST", 61 "%20s : %10u\n", "CST",
62 be32_to_cpu(cmd_rsp.cst)); 62 be32_to_cpu(cmd_rsp.cst));
63 63
64 if (len > sizeof(buf)) 64 if (len > sizeof(buf))
65 len = sizeof(buf); 65 len = sizeof(buf);
@@ -95,41 +95,41 @@ static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf,
95 95
96 ath9k_htc_ps_restore(priv); 96 ath9k_htc_ps_restore(priv);
97 97
98 len += snprintf(buf + len, sizeof(buf) - len, 98 len += scnprintf(buf + len, sizeof(buf) - len,
99 "%20s : %10u\n", "Xretries", 99 "%20s : %10u\n", "Xretries",
100 be32_to_cpu(cmd_rsp.xretries)); 100 be32_to_cpu(cmd_rsp.xretries));
101 101
102 len += snprintf(buf + len, sizeof(buf) - len, 102 len += scnprintf(buf + len, sizeof(buf) - len,
103 "%20s : %10u\n", "FifoErr", 103 "%20s : %10u\n", "FifoErr",
104 be32_to_cpu(cmd_rsp.fifoerr)); 104 be32_to_cpu(cmd_rsp.fifoerr));
105 105
106 len += snprintf(buf + len, sizeof(buf) - len, 106 len += scnprintf(buf + len, sizeof(buf) - len,
107 "%20s : %10u\n", "Filtered", 107 "%20s : %10u\n", "Filtered",
108 be32_to_cpu(cmd_rsp.filtered)); 108 be32_to_cpu(cmd_rsp.filtered));
109 109
110 len += snprintf(buf + len, sizeof(buf) - len, 110 len += scnprintf(buf + len, sizeof(buf) - len,
111 "%20s : %10u\n", "TimerExp", 111 "%20s : %10u\n", "TimerExp",
112 be32_to_cpu(cmd_rsp.timer_exp)); 112 be32_to_cpu(cmd_rsp.timer_exp));
113 113
114 len += snprintf(buf + len, sizeof(buf) - len, 114 len += scnprintf(buf + len, sizeof(buf) - len,
115 "%20s : %10u\n", "ShortRetries", 115 "%20s : %10u\n", "ShortRetries",
116 be32_to_cpu(cmd_rsp.shortretries)); 116 be32_to_cpu(cmd_rsp.shortretries));
117 117
118 len += snprintf(buf + len, sizeof(buf) - len, 118 len += scnprintf(buf + len, sizeof(buf) - len,
119 "%20s : %10u\n", "LongRetries", 119 "%20s : %10u\n", "LongRetries",
120 be32_to_cpu(cmd_rsp.longretries)); 120 be32_to_cpu(cmd_rsp.longretries));
121 121
122 len += snprintf(buf + len, sizeof(buf) - len, 122 len += scnprintf(buf + len, sizeof(buf) - len,
123 "%20s : %10u\n", "QueueNull", 123 "%20s : %10u\n", "QueueNull",
124 be32_to_cpu(cmd_rsp.qnull)); 124 be32_to_cpu(cmd_rsp.qnull));
125 125
126 len += snprintf(buf + len, sizeof(buf) - len, 126 len += scnprintf(buf + len, sizeof(buf) - len,
127 "%20s : %10u\n", "EncapFail", 127 "%20s : %10u\n", "EncapFail",
128 be32_to_cpu(cmd_rsp.encap_fail)); 128 be32_to_cpu(cmd_rsp.encap_fail));
129 129
130 len += snprintf(buf + len, sizeof(buf) - len, 130 len += scnprintf(buf + len, sizeof(buf) - len,
131 "%20s : %10u\n", "NoBuf", 131 "%20s : %10u\n", "NoBuf",
132 be32_to_cpu(cmd_rsp.nobuf)); 132 be32_to_cpu(cmd_rsp.nobuf));
133 133
134 if (len > sizeof(buf)) 134 if (len > sizeof(buf))
135 len = sizeof(buf); 135 len = sizeof(buf);
@@ -165,17 +165,17 @@ static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf,
165 165
166 ath9k_htc_ps_restore(priv); 166 ath9k_htc_ps_restore(priv);
167 167
168 len += snprintf(buf + len, sizeof(buf) - len, 168 len += scnprintf(buf + len, sizeof(buf) - len,
169 "%20s : %10u\n", "NoBuf", 169 "%20s : %10u\n", "NoBuf",
170 be32_to_cpu(cmd_rsp.nobuf)); 170 be32_to_cpu(cmd_rsp.nobuf));
171 171
172 len += snprintf(buf + len, sizeof(buf) - len, 172 len += scnprintf(buf + len, sizeof(buf) - len,
173 "%20s : %10u\n", "HostSend", 173 "%20s : %10u\n", "HostSend",
174 be32_to_cpu(cmd_rsp.host_send)); 174 be32_to_cpu(cmd_rsp.host_send));
175 175
176 len += snprintf(buf + len, sizeof(buf) - len, 176 len += scnprintf(buf + len, sizeof(buf) - len,
177 "%20s : %10u\n", "HostDone", 177 "%20s : %10u\n", "HostDone",
178 be32_to_cpu(cmd_rsp.host_done)); 178 be32_to_cpu(cmd_rsp.host_done));
179 179
180 if (len > sizeof(buf)) 180 if (len > sizeof(buf))
181 len = sizeof(buf); 181 len = sizeof(buf);
@@ -197,37 +197,37 @@ static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
197 char buf[512]; 197 char buf[512];
198 unsigned int len = 0; 198 unsigned int len = 0;
199 199
200 len += snprintf(buf + len, sizeof(buf) - len, 200 len += scnprintf(buf + len, sizeof(buf) - len,
201 "%20s : %10u\n", "Buffers queued", 201 "%20s : %10u\n", "Buffers queued",
202 priv->debug.tx_stats.buf_queued); 202 priv->debug.tx_stats.buf_queued);
203 len += snprintf(buf + len, sizeof(buf) - len, 203 len += scnprintf(buf + len, sizeof(buf) - len,
204 "%20s : %10u\n", "Buffers completed", 204 "%20s : %10u\n", "Buffers completed",
205 priv->debug.tx_stats.buf_completed); 205 priv->debug.tx_stats.buf_completed);
206 len += snprintf(buf + len, sizeof(buf) - len, 206 len += scnprintf(buf + len, sizeof(buf) - len,
207 "%20s : %10u\n", "SKBs queued", 207 "%20s : %10u\n", "SKBs queued",
208 priv->debug.tx_stats.skb_queued); 208 priv->debug.tx_stats.skb_queued);
209 len += snprintf(buf + len, sizeof(buf) - len, 209 len += scnprintf(buf + len, sizeof(buf) - len,
210 "%20s : %10u\n", "SKBs success", 210 "%20s : %10u\n", "SKBs success",
211 priv->debug.tx_stats.skb_success); 211 priv->debug.tx_stats.skb_success);
212 len += snprintf(buf + len, sizeof(buf) - len, 212 len += scnprintf(buf + len, sizeof(buf) - len,
213 "%20s : %10u\n", "SKBs failed", 213 "%20s : %10u\n", "SKBs failed",
214 priv->debug.tx_stats.skb_failed); 214 priv->debug.tx_stats.skb_failed);
215 len += snprintf(buf + len, sizeof(buf) - len, 215 len += scnprintf(buf + len, sizeof(buf) - len,
216 "%20s : %10u\n", "CAB queued", 216 "%20s : %10u\n", "CAB queued",
217 priv->debug.tx_stats.cab_queued); 217 priv->debug.tx_stats.cab_queued);
218 218
219 len += snprintf(buf + len, sizeof(buf) - len, 219 len += scnprintf(buf + len, sizeof(buf) - len,
220 "%20s : %10u\n", "BE queued", 220 "%20s : %10u\n", "BE queued",
221 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BE]); 221 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BE]);
222 len += snprintf(buf + len, sizeof(buf) - len, 222 len += scnprintf(buf + len, sizeof(buf) - len,
223 "%20s : %10u\n", "BK queued", 223 "%20s : %10u\n", "BK queued",
224 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BK]); 224 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BK]);
225 len += snprintf(buf + len, sizeof(buf) - len, 225 len += scnprintf(buf + len, sizeof(buf) - len,
226 "%20s : %10u\n", "VI queued", 226 "%20s : %10u\n", "VI queued",
227 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VI]); 227 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VI]);
228 len += snprintf(buf + len, sizeof(buf) - len, 228 len += scnprintf(buf + len, sizeof(buf) - len,
229 "%20s : %10u\n", "VO queued", 229 "%20s : %10u\n", "VO queued",
230 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VO]); 230 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VO]);
231 231
232 if (len > sizeof(buf)) 232 if (len > sizeof(buf))
233 len = sizeof(buf); 233 len = sizeof(buf);
@@ -273,8 +273,8 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
273 size_t count, loff_t *ppos) 273 size_t count, loff_t *ppos)
274{ 274{
275#define PHY_ERR(s, p) \ 275#define PHY_ERR(s, p) \
276 len += snprintf(buf + len, size - len, "%20s : %10u\n", s, \ 276 len += scnprintf(buf + len, size - len, "%20s : %10u\n", s, \
277 priv->debug.rx_stats.err_phy_stats[p]); 277 priv->debug.rx_stats.err_phy_stats[p]);
278 278
279 struct ath9k_htc_priv *priv = file->private_data; 279 struct ath9k_htc_priv *priv = file->private_data;
280 char *buf; 280 char *buf;
@@ -285,37 +285,37 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
285 if (buf == NULL) 285 if (buf == NULL)
286 return -ENOMEM; 286 return -ENOMEM;
287 287
288 len += snprintf(buf + len, size - len, 288 len += scnprintf(buf + len, size - len,
289 "%20s : %10u\n", "SKBs allocated", 289 "%20s : %10u\n", "SKBs allocated",
290 priv->debug.rx_stats.skb_allocated); 290 priv->debug.rx_stats.skb_allocated);
291 len += snprintf(buf + len, size - len, 291 len += scnprintf(buf + len, size - len,
292 "%20s : %10u\n", "SKBs completed", 292 "%20s : %10u\n", "SKBs completed",
293 priv->debug.rx_stats.skb_completed); 293 priv->debug.rx_stats.skb_completed);
294 len += snprintf(buf + len, size - len, 294 len += scnprintf(buf + len, size - len,
295 "%20s : %10u\n", "SKBs Dropped", 295 "%20s : %10u\n", "SKBs Dropped",
296 priv->debug.rx_stats.skb_dropped); 296 priv->debug.rx_stats.skb_dropped);
297 297
298 len += snprintf(buf + len, size - len, 298 len += scnprintf(buf + len, size - len,
299 "%20s : %10u\n", "CRC ERR", 299 "%20s : %10u\n", "CRC ERR",
300 priv->debug.rx_stats.err_crc); 300 priv->debug.rx_stats.err_crc);
301 len += snprintf(buf + len, size - len, 301 len += scnprintf(buf + len, size - len,
302 "%20s : %10u\n", "DECRYPT CRC ERR", 302 "%20s : %10u\n", "DECRYPT CRC ERR",
303 priv->debug.rx_stats.err_decrypt_crc); 303 priv->debug.rx_stats.err_decrypt_crc);
304 len += snprintf(buf + len, size - len, 304 len += scnprintf(buf + len, size - len,
305 "%20s : %10u\n", "MIC ERR", 305 "%20s : %10u\n", "MIC ERR",
306 priv->debug.rx_stats.err_mic); 306 priv->debug.rx_stats.err_mic);
307 len += snprintf(buf + len, size - len, 307 len += scnprintf(buf + len, size - len,
308 "%20s : %10u\n", "PRE-DELIM CRC ERR", 308 "%20s : %10u\n", "PRE-DELIM CRC ERR",
309 priv->debug.rx_stats.err_pre_delim); 309 priv->debug.rx_stats.err_pre_delim);
310 len += snprintf(buf + len, size - len, 310 len += scnprintf(buf + len, size - len,
311 "%20s : %10u\n", "POST-DELIM CRC ERR", 311 "%20s : %10u\n", "POST-DELIM CRC ERR",
312 priv->debug.rx_stats.err_post_delim); 312 priv->debug.rx_stats.err_post_delim);
313 len += snprintf(buf + len, size - len, 313 len += scnprintf(buf + len, size - len,
314 "%20s : %10u\n", "DECRYPT BUSY ERR", 314 "%20s : %10u\n", "DECRYPT BUSY ERR",
315 priv->debug.rx_stats.err_decrypt_busy); 315 priv->debug.rx_stats.err_decrypt_busy);
316 len += snprintf(buf + len, size - len, 316 len += scnprintf(buf + len, size - len,
317 "%20s : %10u\n", "TOTAL PHY ERR", 317 "%20s : %10u\n", "TOTAL PHY ERR",
318 priv->debug.rx_stats.err_phy); 318 priv->debug.rx_stats.err_phy);
319 319
320 320
321 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN); 321 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
@@ -372,16 +372,16 @@ static ssize_t read_file_slot(struct file *file, char __user *user_buf,
372 372
373 spin_lock_bh(&priv->tx.tx_lock); 373 spin_lock_bh(&priv->tx.tx_lock);
374 374
375 len += snprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : "); 375 len += scnprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : ");
376 376
377 len += bitmap_scnprintf(buf + len, sizeof(buf) - len, 377 len += bitmap_scnprintf(buf + len, sizeof(buf) - len,
378 priv->tx.tx_slot, MAX_TX_BUF_NUM); 378 priv->tx.tx_slot, MAX_TX_BUF_NUM);
379 379
380 len += snprintf(buf + len, sizeof(buf) - len, "\n"); 380 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
381 381
382 len += snprintf(buf + len, sizeof(buf) - len, 382 len += scnprintf(buf + len, sizeof(buf) - len,
383 "Used slots : %d\n", 383 "Used slots : %d\n",
384 bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); 384 bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM));
385 385
386 spin_unlock_bh(&priv->tx.tx_lock); 386 spin_unlock_bh(&priv->tx.tx_lock);
387 387
@@ -405,30 +405,30 @@ static ssize_t read_file_queue(struct file *file, char __user *user_buf,
405 char buf[512]; 405 char buf[512];
406 unsigned int len = 0; 406 unsigned int len = 0;
407 407
408 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 408 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
409 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue)); 409 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue));
410 410
411 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 411 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
412 "Cab endpoint", skb_queue_len(&priv->tx.cab_ep_queue)); 412 "Cab endpoint", skb_queue_len(&priv->tx.cab_ep_queue));
413 413
414 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 414 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
415 "Data BE endpoint", skb_queue_len(&priv->tx.data_be_queue)); 415 "Data BE endpoint", skb_queue_len(&priv->tx.data_be_queue));
416 416
417 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 417 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
418 "Data BK endpoint", skb_queue_len(&priv->tx.data_bk_queue)); 418 "Data BK endpoint", skb_queue_len(&priv->tx.data_bk_queue));
419 419
420 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 420 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
421 "Data VI endpoint", skb_queue_len(&priv->tx.data_vi_queue)); 421 "Data VI endpoint", skb_queue_len(&priv->tx.data_vi_queue));
422 422
423 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 423 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
424 "Data VO endpoint", skb_queue_len(&priv->tx.data_vo_queue)); 424 "Data VO endpoint", skb_queue_len(&priv->tx.data_vo_queue));
425 425
426 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 426 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
427 "Failed queue", skb_queue_len(&priv->tx.tx_failed)); 427 "Failed queue", skb_queue_len(&priv->tx.tx_failed));
428 428
429 spin_lock_bh(&priv->tx.tx_lock); 429 spin_lock_bh(&priv->tx.tx_lock);
430 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 430 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
431 "Queued count", priv->tx.queued_cnt); 431 "Queued count", priv->tx.queued_cnt);
432 spin_unlock_bh(&priv->tx.tx_lock); 432 spin_unlock_bh(&priv->tx.tx_lock);
433 433
434 if (len > sizeof(buf)) 434 if (len > sizeof(buf))
@@ -507,70 +507,70 @@ static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
507 if (buf == NULL) 507 if (buf == NULL)
508 return -ENOMEM; 508 return -ENOMEM;
509 509
510 len += snprintf(buf + len, size - len, 510 len += scnprintf(buf + len, size - len,
511 "%20s : %10d\n", "Major Version", 511 "%20s : %10d\n", "Major Version",
512 pBase->version >> 12); 512 pBase->version >> 12);
513 len += snprintf(buf + len, size - len, 513 len += scnprintf(buf + len, size - len,
514 "%20s : %10d\n", "Minor Version", 514 "%20s : %10d\n", "Minor Version",
515 pBase->version & 0xFFF); 515 pBase->version & 0xFFF);
516 len += snprintf(buf + len, size - len, 516 len += scnprintf(buf + len, size - len,
517 "%20s : %10d\n", "Checksum", 517 "%20s : %10d\n", "Checksum",
518 pBase->checksum); 518 pBase->checksum);
519 len += snprintf(buf + len, size - len, 519 len += scnprintf(buf + len, size - len,
520 "%20s : %10d\n", "Length", 520 "%20s : %10d\n", "Length",
521 pBase->length); 521 pBase->length);
522 len += snprintf(buf + len, size - len, 522 len += scnprintf(buf + len, size - len,
523 "%20s : %10d\n", "RegDomain1", 523 "%20s : %10d\n", "RegDomain1",
524 pBase->regDmn[0]); 524 pBase->regDmn[0]);
525 len += snprintf(buf + len, size - len, 525 len += scnprintf(buf + len, size - len,
526 "%20s : %10d\n", "RegDomain2", 526 "%20s : %10d\n", "RegDomain2",
527 pBase->regDmn[1]); 527 pBase->regDmn[1]);
528 len += snprintf(buf + len, size - len, 528 len += scnprintf(buf + len, size - len,
529 "%20s : %10d\n", 529 "%20s : %10d\n",
530 "TX Mask", pBase->txMask); 530 "TX Mask", pBase->txMask);
531 len += snprintf(buf + len, size - len, 531 len += scnprintf(buf + len, size - len,
532 "%20s : %10d\n", 532 "%20s : %10d\n",
533 "RX Mask", pBase->rxMask); 533 "RX Mask", pBase->rxMask);
534 len += snprintf(buf + len, size - len, 534 len += scnprintf(buf + len, size - len,
535 "%20s : %10d\n", 535 "%20s : %10d\n",
536 "Allow 5GHz", 536 "Allow 5GHz",
537 !!(pBase->opCapFlags & AR5416_OPFLAGS_11A)); 537 !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
538 len += snprintf(buf + len, size - len, 538 len += scnprintf(buf + len, size - len,
539 "%20s : %10d\n", 539 "%20s : %10d\n",
540 "Allow 2GHz", 540 "Allow 2GHz",
541 !!(pBase->opCapFlags & AR5416_OPFLAGS_11G)); 541 !!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
542 len += snprintf(buf + len, size - len, 542 len += scnprintf(buf + len, size - len,
543 "%20s : %10d\n", 543 "%20s : %10d\n",
544 "Disable 2GHz HT20", 544 "Disable 2GHz HT20",
545 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT20)); 545 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT20));
546 len += snprintf(buf + len, size - len, 546 len += scnprintf(buf + len, size - len,
547 "%20s : %10d\n", 547 "%20s : %10d\n",
548 "Disable 2GHz HT40", 548 "Disable 2GHz HT40",
549 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT40)); 549 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_2G_HT40));
550 len += snprintf(buf + len, size - len, 550 len += scnprintf(buf + len, size - len,
551 "%20s : %10d\n", 551 "%20s : %10d\n",
552 "Disable 5Ghz HT20", 552 "Disable 5Ghz HT20",
553 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT20)); 553 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT20));
554 len += snprintf(buf + len, size - len, 554 len += scnprintf(buf + len, size - len,
555 "%20s : %10d\n", 555 "%20s : %10d\n",
556 "Disable 5Ghz HT40", 556 "Disable 5Ghz HT40",
557 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT40)); 557 !!(pBase->opCapFlags & AR5416_OPFLAGS_N_5G_HT40));
558 len += snprintf(buf + len, size - len, 558 len += scnprintf(buf + len, size - len,
559 "%20s : %10d\n", 559 "%20s : %10d\n",
560 "Big Endian", 560 "Big Endian",
561 !!(pBase->eepMisc & 0x01)); 561 !!(pBase->eepMisc & 0x01));
562 len += snprintf(buf + len, size - len, 562 len += scnprintf(buf + len, size - len,
563 "%20s : %10d\n", 563 "%20s : %10d\n",
564 "Cal Bin Major Ver", 564 "Cal Bin Major Ver",
565 (pBase->binBuildNumber >> 24) & 0xFF); 565 (pBase->binBuildNumber >> 24) & 0xFF);
566 len += snprintf(buf + len, size - len, 566 len += scnprintf(buf + len, size - len,
567 "%20s : %10d\n", 567 "%20s : %10d\n",
568 "Cal Bin Minor Ver", 568 "Cal Bin Minor Ver",
569 (pBase->binBuildNumber >> 16) & 0xFF); 569 (pBase->binBuildNumber >> 16) & 0xFF);
570 len += snprintf(buf + len, size - len, 570 len += scnprintf(buf + len, size - len,
571 "%20s : %10d\n", 571 "%20s : %10d\n",
572 "Cal Bin Build", 572 "Cal Bin Build",
573 (pBase->binBuildNumber >> 8) & 0xFF); 573 (pBase->binBuildNumber >> 8) & 0xFF);
574 574
575 /* 575 /*
576 * UB91 specific data. 576 * UB91 specific data.
@@ -579,10 +579,10 @@ static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
579 struct base_eep_header_4k *pBase4k = 579 struct base_eep_header_4k *pBase4k =
580 &priv->ah->eeprom.map4k.baseEepHeader; 580 &priv->ah->eeprom.map4k.baseEepHeader;
581 581
582 len += snprintf(buf + len, size - len, 582 len += scnprintf(buf + len, size - len,
583 "%20s : %10d\n", 583 "%20s : %10d\n",
584 "TX Gain type", 584 "TX Gain type",
585 pBase4k->txGainType); 585 pBase4k->txGainType);
586 } 586 }
587 587
588 /* 588 /*
@@ -592,19 +592,19 @@ static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
592 struct base_eep_ar9287_header *pBase9287 = 592 struct base_eep_ar9287_header *pBase9287 =
593 &priv->ah->eeprom.map9287.baseEepHeader; 593 &priv->ah->eeprom.map9287.baseEepHeader;
594 594
595 len += snprintf(buf + len, size - len, 595 len += scnprintf(buf + len, size - len,
596 "%20s : %10ddB\n", 596 "%20s : %10ddB\n",
597 "Power Table Offset", 597 "Power Table Offset",
598 pBase9287->pwrTableOffset); 598 pBase9287->pwrTableOffset);
599 599
600 len += snprintf(buf + len, size - len, 600 len += scnprintf(buf + len, size - len,
601 "%20s : %10d\n", 601 "%20s : %10d\n",
602 "OpenLoop Power Ctrl", 602 "OpenLoop Power Ctrl",
603 pBase9287->openLoopPwrCntl); 603 pBase9287->openLoopPwrCntl);
604 } 604 }
605 605
606 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", 606 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
607 pBase->macAddr); 607 pBase->macAddr);
608 if (len > size) 608 if (len > size)
609 len = size; 609 len = size;
610 610
@@ -627,8 +627,8 @@ static ssize_t read_4k_modal_eeprom(struct file *file,
627{ 627{
628#define PR_EEP(_s, _val) \ 628#define PR_EEP(_s, _val) \
629 do { \ 629 do { \
630 len += snprintf(buf + len, size - len, "%20s : %10d\n", \ 630 len += scnprintf(buf + len, size - len, "%20s : %10d\n",\
631 _s, (_val)); \ 631 _s, (_val)); \
632 } while (0) 632 } while (0)
633 633
634 struct ath9k_htc_priv *priv = file->private_data; 634 struct ath9k_htc_priv *priv = file->private_data;
@@ -708,12 +708,12 @@ static ssize_t read_def_modal_eeprom(struct file *file,
708 do { \ 708 do { \
709 if (pBase->opCapFlags & AR5416_OPFLAGS_11G) { \ 709 if (pBase->opCapFlags & AR5416_OPFLAGS_11G) { \
710 pModal = &priv->ah->eeprom.def.modalHeader[1]; \ 710 pModal = &priv->ah->eeprom.def.modalHeader[1]; \
711 len += snprintf(buf + len, size - len, "%20s : %8d%7s", \ 711 len += scnprintf(buf + len, size - len, "%20s : %8d%7s", \
712 _s, (_val), "|"); \ 712 _s, (_val), "|"); \
713 } \ 713 } \
714 if (pBase->opCapFlags & AR5416_OPFLAGS_11A) { \ 714 if (pBase->opCapFlags & AR5416_OPFLAGS_11A) { \
715 pModal = &priv->ah->eeprom.def.modalHeader[0]; \ 715 pModal = &priv->ah->eeprom.def.modalHeader[0]; \
716 len += snprintf(buf + len, size - len, "%9d\n", \ 716 len += scnprintf(buf + len, size - len, "%9d\n",\
717 (_val)); \ 717 (_val)); \
718 } \ 718 } \
719 } while (0) 719 } while (0)
@@ -729,10 +729,10 @@ static ssize_t read_def_modal_eeprom(struct file *file,
729 if (buf == NULL) 729 if (buf == NULL)
730 return -ENOMEM; 730 return -ENOMEM;
731 731
732 len += snprintf(buf + len, size - len, 732 len += scnprintf(buf + len, size - len,
733 "%31s %15s\n", "2G", "5G"); 733 "%31s %15s\n", "2G", "5G");
734 len += snprintf(buf + len, size - len, 734 len += scnprintf(buf + len, size - len,
735 "%32s %16s\n", "====", "====\n"); 735 "%32s %16s\n", "====", "====\n");
736 736
737 PR_EEP("Chain0 Ant. Control", pModal->antCtrlChain[0]); 737 PR_EEP("Chain0 Ant. Control", pModal->antCtrlChain[0]);
738 PR_EEP("Chain1 Ant. Control", pModal->antCtrlChain[1]); 738 PR_EEP("Chain1 Ant. Control", pModal->antCtrlChain[1]);
@@ -814,8 +814,8 @@ static ssize_t read_9287_modal_eeprom(struct file *file,
814{ 814{
815#define PR_EEP(_s, _val) \ 815#define PR_EEP(_s, _val) \
816 do { \ 816 do { \
817 len += snprintf(buf + len, size - len, "%20s : %10d\n", \ 817 len += scnprintf(buf + len, size - len, "%20s : %10d\n",\
818 _s, (_val)); \ 818 _s, (_val)); \
819 } while (0) 819 } while (0)
820 820
821 struct ath9k_htc_priv *priv = file->private_data; 821 struct ath9k_htc_priv *priv = file->private_data;
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index ecc6ec4a1edb..f11e8389a9be 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -549,6 +549,18 @@ static int ath9k_hw_post_init(struct ath_hw *ah)
549 549
550 ath9k_hw_ani_init(ah); 550 ath9k_hw_ani_init(ah);
551 551
552 /*
553 * EEPROM needs to be initialized before we do this.
554 * This is required for regulatory compliance.
555 */
556 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
557 u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
558 if ((regdmn & 0xF0) == CTL_FCC) {
559 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9462_FCC_2GHZ;
560 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9462_FCC_5GHZ;
561 }
562 }
563
552 return 0; 564 return 0;
553} 565}
554 566
@@ -1644,6 +1656,19 @@ hang_check_iter:
1644 return true; 1656 return true;
1645} 1657}
1646 1658
1659void ath9k_hw_check_nav(struct ath_hw *ah)
1660{
1661 struct ath_common *common = ath9k_hw_common(ah);
1662 u32 val;
1663
1664 val = REG_READ(ah, AR_NAV);
1665 if (val != 0xdeadbeef && val > 0x7fff) {
1666 ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
1667 REG_WRITE(ah, AR_NAV, 0);
1668 }
1669}
1670EXPORT_SYMBOL(ath9k_hw_check_nav);
1671
1647bool ath9k_hw_check_alive(struct ath_hw *ah) 1672bool ath9k_hw_check_alive(struct ath_hw *ah)
1648{ 1673{
1649 int count = 50; 1674 int count = 50;
@@ -1822,9 +1847,9 @@ static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1822 * re-using are present. 1847 * re-using are present.
1823 */ 1848 */
1824 if (AR_SREV_9462(ah) && (ah->caldata && 1849 if (AR_SREV_9462(ah) && (ah->caldata &&
1825 (!ah->caldata->done_txiqcal_once || 1850 (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
1826 !ah->caldata->done_txclcal_once || 1851 !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
1827 !ah->caldata->rtt_done))) 1852 !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
1828 goto fail; 1853 goto fail;
1829 1854
1830 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n", 1855 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
@@ -1880,7 +1905,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1880 memset(caldata, 0, sizeof(*caldata)); 1905 memset(caldata, 0, sizeof(*caldata));
1881 ath9k_init_nfcal_hist_buffer(ah, chan); 1906 ath9k_init_nfcal_hist_buffer(ah, chan);
1882 } else if (caldata) { 1907 } else if (caldata) {
1883 caldata->paprd_packet_sent = false; 1908 clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
1884 } 1909 }
1885 ah->noise = ath9k_hw_getchan_noise(ah, chan); 1910 ah->noise = ath9k_hw_getchan_noise(ah, chan);
1886 1911
@@ -2017,8 +2042,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2017 ath9k_hw_init_bb(ah, chan); 2042 ath9k_hw_init_bb(ah, chan);
2018 2043
2019 if (caldata) { 2044 if (caldata) {
2020 caldata->done_txiqcal_once = false; 2045 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
2021 caldata->done_txclcal_once = false; 2046 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
2022 } 2047 }
2023 if (!ath9k_hw_init_cal(ah, chan)) 2048 if (!ath9k_hw_init_cal(ah, chan))
2024 return -EIO; 2049 return -EIO;
@@ -3240,19 +3265,19 @@ void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3240 3265
3241 /* chipsets >= AR9280 are single-chip */ 3266 /* chipsets >= AR9280 are single-chip */
3242 if (AR_SREV_9280_20_OR_LATER(ah)) { 3267 if (AR_SREV_9280_20_OR_LATER(ah)) {
3243 used = snprintf(hw_name, len, 3268 used = scnprintf(hw_name, len,
3244 "Atheros AR%s Rev:%x", 3269 "Atheros AR%s Rev:%x",
3245 ath9k_hw_mac_bb_name(ah->hw_version.macVersion), 3270 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3246 ah->hw_version.macRev); 3271 ah->hw_version.macRev);
3247 } 3272 }
3248 else { 3273 else {
3249 used = snprintf(hw_name, len, 3274 used = scnprintf(hw_name, len,
3250 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x", 3275 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3251 ath9k_hw_mac_bb_name(ah->hw_version.macVersion), 3276 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3252 ah->hw_version.macRev, 3277 ah->hw_version.macRev,
3253 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev & 3278 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
3254 AR_RADIO_SREV_MAJOR)), 3279 & AR_RADIO_SREV_MAJOR)),
3255 ah->hw_version.phyRev); 3280 ah->hw_version.phyRev);
3256 } 3281 }
3257 3282
3258 hw_name[used] = '\0'; 3283 hw_name[used] = '\0';
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 69a907b55a73..2babf931b459 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -98,8 +98,8 @@
98 98
99#define PR_EEP(_s, _val) \ 99#define PR_EEP(_s, _val) \
100 do { \ 100 do { \
101 len += snprintf(buf + len, size - len, "%20s : %10d\n", \ 101 len += scnprintf(buf + len, size - len, "%20s : %10d\n",\
102 _s, (_val)); \ 102 _s, (_val)); \
103 } while (0) 103 } while (0)
104 104
105#define SM(_v, _f) (((_v) << _f##_S) & _f) 105#define SM(_v, _f) (((_v) << _f##_S) & _f)
@@ -404,20 +404,26 @@ enum ath9k_int {
404#define MAX_CL_TAB_ENTRY 16 404#define MAX_CL_TAB_ENTRY 16
405#define CL_TAB_ENTRY(reg_base) (reg_base + (4 * j)) 405#define CL_TAB_ENTRY(reg_base) (reg_base + (4 * j))
406 406
407enum ath9k_cal_flags {
408 RTT_DONE,
409 PAPRD_PACKET_SENT,
410 PAPRD_DONE,
411 NFCAL_PENDING,
412 NFCAL_INTF,
413 TXIQCAL_DONE,
414 TXCLCAL_DONE,
415 SW_PKDET_DONE,
416};
417
407struct ath9k_hw_cal_data { 418struct ath9k_hw_cal_data {
408 u16 channel; 419 u16 channel;
409 u32 channelFlags; 420 u32 channelFlags;
410 u32 chanmode; 421 u32 chanmode;
422 unsigned long cal_flags;
411 int32_t CalValid; 423 int32_t CalValid;
412 int8_t iCoff; 424 int8_t iCoff;
413 int8_t qCoff; 425 int8_t qCoff;
414 bool rtt_done; 426 u8 caldac[2];
415 bool paprd_packet_sent;
416 bool paprd_done;
417 bool nfcal_pending;
418 bool nfcal_interference;
419 bool done_txiqcal_once;
420 bool done_txclcal_once;
421 u16 small_signal_gain[AR9300_MAX_CHAINS]; 427 u16 small_signal_gain[AR9300_MAX_CHAINS];
422 u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ]; 428 u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ];
423 u32 num_measures[AR9300_MAX_CHAINS]; 429 u32 num_measures[AR9300_MAX_CHAINS];
@@ -558,6 +564,7 @@ struct ath_hw_antcomb_conf {
558 u8 main_gaintb; 564 u8 main_gaintb;
559 u8 alt_gaintb; 565 u8 alt_gaintb;
560 int lna1_lna2_delta; 566 int lna1_lna2_delta;
567 int lna1_lna2_switch_delta;
561 u8 div_group; 568 u8 div_group;
562}; 569};
563 570
@@ -1030,6 +1037,7 @@ void ath9k_hw_set11nmac2040(struct ath_hw *ah);
1030void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period); 1037void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period);
1031void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah, 1038void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
1032 const struct ath9k_beacon_state *bs); 1039 const struct ath9k_beacon_state *bs);
1040void ath9k_hw_check_nav(struct ath_hw *ah);
1033bool ath9k_hw_check_alive(struct ath_hw *ah); 1041bool ath9k_hw_check_alive(struct ath_hw *ah);
1034 1042
1035bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode); 1043bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode);
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 9a1f349f9260..e3d11c41a145 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -547,6 +547,26 @@ static void ath9k_init_platform(struct ath_softc *sc)
547 if (sc->driver_data & ATH9K_PCI_CUS217) 547 if (sc->driver_data & ATH9K_PCI_CUS217)
548 ath_info(common, "CUS217 card detected\n"); 548 ath_info(common, "CUS217 card detected\n");
549 549
550 if (sc->driver_data & ATH9K_PCI_CUS252)
551 ath_info(common, "CUS252 card detected\n");
552
553 if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
554 ath_info(common, "WB335 1-ANT card detected\n");
555
556 if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
557 ath_info(common, "WB335 2-ANT card detected\n");
558
559 /*
560 * Some WB335 cards do not support antenna diversity. Since
561 * we use a hardcoded value for AR9565 instead of using the
562 * EEPROM/OTP data, remove the combining feature from
563 * the HW capabilities bitmap.
564 */
565 if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
566 if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
567 pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
568 }
569
550 if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) { 570 if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
551 pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV; 571 pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
552 ath_info(common, "Set BT/WLAN RX diversity capability\n"); 572 ath_info(common, "Set BT/WLAN RX diversity capability\n");
diff --git a/drivers/net/wireless/ath/ath9k/link.c b/drivers/net/wireless/ath/ath9k/link.c
index 2f831db396ac..84a60644f93a 100644
--- a/drivers/net/wireless/ath/ath9k/link.c
+++ b/drivers/net/wireless/ath/ath9k/link.c
@@ -184,7 +184,7 @@ static void ath_paprd_activate(struct ath_softc *sc)
184 struct ath9k_hw_cal_data *caldata = ah->caldata; 184 struct ath9k_hw_cal_data *caldata = ah->caldata;
185 int chain; 185 int chain;
186 186
187 if (!caldata || !caldata->paprd_done) { 187 if (!caldata || !test_bit(PAPRD_DONE, &caldata->cal_flags)) {
188 ath_dbg(common, CALIBRATE, "Failed to activate PAPRD\n"); 188 ath_dbg(common, CALIBRATE, "Failed to activate PAPRD\n");
189 return; 189 return;
190 } 190 }
@@ -256,7 +256,9 @@ void ath_paprd_calibrate(struct work_struct *work)
256 int len = 1800; 256 int len = 1800;
257 int ret; 257 int ret;
258 258
259 if (!caldata || !caldata->paprd_packet_sent || caldata->paprd_done) { 259 if (!caldata ||
260 !test_bit(PAPRD_PACKET_SENT, &caldata->cal_flags) ||
261 test_bit(PAPRD_DONE, &caldata->cal_flags)) {
260 ath_dbg(common, CALIBRATE, "Skipping PAPRD calibration\n"); 262 ath_dbg(common, CALIBRATE, "Skipping PAPRD calibration\n");
261 return; 263 return;
262 } 264 }
@@ -316,7 +318,7 @@ void ath_paprd_calibrate(struct work_struct *work)
316 kfree_skb(skb); 318 kfree_skb(skb);
317 319
318 if (chain_ok) { 320 if (chain_ok) {
319 caldata->paprd_done = true; 321 set_bit(PAPRD_DONE, &caldata->cal_flags);
320 ath_paprd_activate(sc); 322 ath_paprd_activate(sc);
321 } 323 }
322 324
@@ -343,7 +345,7 @@ void ath_ani_calibrate(unsigned long data)
343 u32 cal_interval, short_cal_interval, long_cal_interval; 345 u32 cal_interval, short_cal_interval, long_cal_interval;
344 unsigned long flags; 346 unsigned long flags;
345 347
346 if (ah->caldata && ah->caldata->nfcal_interference) 348 if (ah->caldata && test_bit(NFCAL_INTF, &ah->caldata->cal_flags))
347 long_cal_interval = ATH_LONG_CALINTERVAL_INT; 349 long_cal_interval = ATH_LONG_CALINTERVAL_INT;
348 else 350 else
349 long_cal_interval = ATH_LONG_CALINTERVAL; 351 long_cal_interval = ATH_LONG_CALINTERVAL;
@@ -432,7 +434,7 @@ set_timer:
432 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); 434 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
433 435
434 if (ar9003_is_paprd_enabled(ah) && ah->caldata) { 436 if (ar9003_is_paprd_enabled(ah) && ah->caldata) {
435 if (!ah->caldata->paprd_done) { 437 if (!test_bit(PAPRD_DONE, &ah->caldata->cal_flags)) {
436 ieee80211_queue_work(sc->hw, &sc->paprd_work); 438 ieee80211_queue_work(sc->hw, &sc->paprd_work);
437 } else if (!ah->paprd_table_write_done) { 439 } else if (!ah->paprd_table_write_done) {
438 ath9k_ps_wakeup(sc); 440 ath9k_ps_wakeup(sc);
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index e4f65900132d..cdb3b1e10b95 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -362,6 +362,13 @@ void ath9k_tasklet(unsigned long data)
362 type = RESET_TYPE_BB_WATCHDOG; 362 type = RESET_TYPE_BB_WATCHDOG;
363 363
364 ath9k_queue_reset(sc, type); 364 ath9k_queue_reset(sc, type);
365
366 /*
367 * Increment the ref. counter here so that
368 * interrupts are enabled in the reset routine.
369 */
370 atomic_inc(&ah->intr_ref_cnt);
371 ath_dbg(common, ANY, "FATAL: Skipping interrupts\n");
365 goto out; 372 goto out;
366 } 373 }
367 374
@@ -400,10 +407,9 @@ void ath9k_tasklet(unsigned long data)
400 407
401 ath9k_btcoex_handle_interrupt(sc, status); 408 ath9k_btcoex_handle_interrupt(sc, status);
402 409
403out:
404 /* re-enable hardware interrupt */ 410 /* re-enable hardware interrupt */
405 ath9k_hw_enable_interrupts(ah); 411 ath9k_hw_enable_interrupts(ah);
406 412out:
407 spin_unlock(&sc->sc_pcu_lock); 413 spin_unlock(&sc->sc_pcu_lock);
408 ath9k_ps_restore(sc); 414 ath9k_ps_restore(sc);
409} 415}
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index d089a7cf01c4..7e4c2524b630 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -269,7 +269,200 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_id_table) = {
269 269
270 { PCI_VDEVICE(ATHEROS, 0x0034) }, /* PCI-E AR9462 */ 270 { PCI_VDEVICE(ATHEROS, 0x0034) }, /* PCI-E AR9462 */
271 { PCI_VDEVICE(ATHEROS, 0x0037) }, /* PCI-E AR1111/AR9485 */ 271 { PCI_VDEVICE(ATHEROS, 0x0037) }, /* PCI-E AR1111/AR9485 */
272 { PCI_VDEVICE(ATHEROS, 0x0036) }, /* PCI-E AR9565 */ 272
273 /* CUS252 */
274 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
275 0x0036,
276 PCI_VENDOR_ID_ATHEROS,
277 0x3028),
278 .driver_data = ATH9K_PCI_CUS252 |
279 ATH9K_PCI_AR9565_2ANT |
280 ATH9K_PCI_BT_ANT_DIV },
281 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
282 0x0036,
283 PCI_VENDOR_ID_AZWAVE,
284 0x2176),
285 .driver_data = ATH9K_PCI_CUS252 |
286 ATH9K_PCI_AR9565_2ANT |
287 ATH9K_PCI_BT_ANT_DIV },
288
289 /* WB335 1-ANT */
290 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
291 0x0036,
292 PCI_VENDOR_ID_FOXCONN,
293 0xE068),
294 .driver_data = ATH9K_PCI_AR9565_1ANT },
295 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
296 0x0036,
297 0x185F, /* WNC */
298 0xA119),
299 .driver_data = ATH9K_PCI_AR9565_1ANT },
300 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
301 0x0036,
302 0x11AD, /* LITEON */
303 0x0632),
304 .driver_data = ATH9K_PCI_AR9565_1ANT },
305 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
306 0x0036,
307 0x11AD, /* LITEON */
308 0x6671),
309 .driver_data = ATH9K_PCI_AR9565_1ANT },
310 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
311 0x0036,
312 0x1B9A, /* XAVI */
313 0x2811),
314 .driver_data = ATH9K_PCI_AR9565_1ANT },
315 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
316 0x0036,
317 0x1B9A, /* XAVI */
318 0x2812),
319 .driver_data = ATH9K_PCI_AR9565_1ANT },
320
321 /* WB335 1-ANT / Antenna Diversity */
322 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
323 0x0036,
324 PCI_VENDOR_ID_ATHEROS,
325 0x3025),
326 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
327 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
328 0x0036,
329 PCI_VENDOR_ID_ATHEROS,
330 0x3026),
331 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
332 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
333 0x0036,
334 PCI_VENDOR_ID_ATHEROS,
335 0x302B),
336 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
337 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
338 0x0036,
339 PCI_VENDOR_ID_FOXCONN,
340 0xE069),
341 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
342 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
343 0x0036,
344 0x185F, /* WNC */
345 0x3028),
346 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
347 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
348 0x0036,
349 0x11AD, /* LITEON */
350 0x0622),
351 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
352 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
353 0x0036,
354 0x11AD, /* LITEON */
355 0x0672),
356 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
357 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
358 0x0036,
359 0x11AD, /* LITEON */
360 0x0662),
361 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
362 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
363 0x0036,
364 PCI_VENDOR_ID_AZWAVE,
365 0x213A),
366 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
367 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
368 0x0036,
369 PCI_VENDOR_ID_LENOVO,
370 0x3026),
371 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
372 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
373 0x0036,
374 PCI_VENDOR_ID_HP,
375 0x18E3),
376 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
377 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
378 0x0036,
379 PCI_VENDOR_ID_HP,
380 0x217F),
381 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
382 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
383 0x0036,
384 PCI_VENDOR_ID_DELL,
385 0x020E),
386 .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
387
388 /* WB335 2-ANT */
389 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
390 0x0036,
391 PCI_VENDOR_ID_SAMSUNG,
392 0x411A),
393 .driver_data = ATH9K_PCI_AR9565_2ANT },
394 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
395 0x0036,
396 PCI_VENDOR_ID_SAMSUNG,
397 0x411B),
398 .driver_data = ATH9K_PCI_AR9565_2ANT },
399 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
400 0x0036,
401 PCI_VENDOR_ID_SAMSUNG,
402 0x411C),
403 .driver_data = ATH9K_PCI_AR9565_2ANT },
404 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
405 0x0036,
406 PCI_VENDOR_ID_SAMSUNG,
407 0x411D),
408 .driver_data = ATH9K_PCI_AR9565_2ANT },
409 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
410 0x0036,
411 PCI_VENDOR_ID_SAMSUNG,
412 0x411E),
413 .driver_data = ATH9K_PCI_AR9565_2ANT },
414
415 /* WB335 2-ANT / Antenna-Diversity */
416 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
417 0x0036,
418 PCI_VENDOR_ID_ATHEROS,
419 0x3027),
420 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
421 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
422 0x0036,
423 PCI_VENDOR_ID_ATHEROS,
424 0x302C),
425 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
426 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
427 0x0036,
428 0x11AD, /* LITEON */
429 0x0642),
430 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
431 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
432 0x0036,
433 0x11AD, /* LITEON */
434 0x0652),
435 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
436 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
437 0x0036,
438 0x11AD, /* LITEON */
439 0x0612),
440 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
441 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
442 0x0036,
443 PCI_VENDOR_ID_AZWAVE,
444 0x2130),
445 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
446 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
447 0x0036,
448 0x144F, /* ASKEY */
449 0x7202),
450 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
451 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
452 0x0036,
453 0x1B9A, /* XAVI */
454 0x2810),
455 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
456 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
457 0x0036,
458 0x185F, /* WNC */
459 0x3027),
460 .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
461
462 /* PCI-E AR9565 (WB335) */
463 { PCI_VDEVICE(ATHEROS, 0x0036),
464 .driver_data = ATH9K_PCI_BT_ANT_DIV },
465
273 { 0 } 466 { 0 }
274}; 467};
275 468
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index d3d7c51fa6c8..d829bb62a3fc 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -1387,31 +1387,31 @@ static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
1387 int used_mcs = 0, used_htmode = 0; 1387 int used_mcs = 0, used_htmode = 0;
1388 1388
1389 if (WLAN_RC_PHY_HT(rc->rate_table->info[i].phy)) { 1389 if (WLAN_RC_PHY_HT(rc->rate_table->info[i].phy)) {
1390 used_mcs = snprintf(mcs, 5, "%d", 1390 used_mcs = scnprintf(mcs, 5, "%d",
1391 rc->rate_table->info[i].ratecode); 1391 rc->rate_table->info[i].ratecode);
1392 1392
1393 if (WLAN_RC_PHY_40(rc->rate_table->info[i].phy)) 1393 if (WLAN_RC_PHY_40(rc->rate_table->info[i].phy))
1394 used_htmode = snprintf(htmode, 5, "HT40"); 1394 used_htmode = scnprintf(htmode, 5, "HT40");
1395 else if (WLAN_RC_PHY_20(rc->rate_table->info[i].phy)) 1395 else if (WLAN_RC_PHY_20(rc->rate_table->info[i].phy))
1396 used_htmode = snprintf(htmode, 5, "HT20"); 1396 used_htmode = scnprintf(htmode, 5, "HT20");
1397 else 1397 else
1398 used_htmode = snprintf(htmode, 5, "????"); 1398 used_htmode = scnprintf(htmode, 5, "????");
1399 } 1399 }
1400 1400
1401 mcs[used_mcs] = '\0'; 1401 mcs[used_mcs] = '\0';
1402 htmode[used_htmode] = '\0'; 1402 htmode[used_htmode] = '\0';
1403 1403
1404 len += snprintf(buf + len, max - len, 1404 len += scnprintf(buf + len, max - len,
1405 "%6s %6s %3u.%d: " 1405 "%6s %6s %3u.%d: "
1406 "%10u %10u %10u %10u\n", 1406 "%10u %10u %10u %10u\n",
1407 htmode, 1407 htmode,
1408 mcs, 1408 mcs,
1409 ratekbps / 1000, 1409 ratekbps / 1000,
1410 (ratekbps % 1000) / 100, 1410 (ratekbps % 1000) / 100,
1411 stats->success, 1411 stats->success,
1412 stats->retries, 1412 stats->retries,
1413 stats->xretries, 1413 stats->xretries,
1414 stats->per); 1414 stats->per);
1415 } 1415 }
1416 1416
1417 if (len > max) 1417 if (len > max)
diff --git a/drivers/net/wireless/ath/ath9k/wmi.h b/drivers/net/wireless/ath/ath9k/wmi.h
index fde6da619f30..0db37f230018 100644
--- a/drivers/net/wireless/ath/ath9k/wmi.h
+++ b/drivers/net/wireless/ath/ath9k/wmi.h
@@ -39,7 +39,7 @@ struct wmi_fw_version {
39struct wmi_event_swba { 39struct wmi_event_swba {
40 __be64 tsf; 40 __be64 tsf;
41 u8 beacon_pending; 41 u8 beacon_pending;
42}; 42} __packed;
43 43
44/* 44/*
45 * 64 - HTC header - WMI header - 1 / txstatus 45 * 64 - HTC header - WMI header - 1 / txstatus
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 5ac713d2ff5d..13f5434e7f6c 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -2326,7 +2326,7 @@ static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
2326 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb); 2326 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
2327 2327
2328 if (sc->sc_ah->caldata) 2328 if (sc->sc_ah->caldata)
2329 sc->sc_ah->caldata->paprd_packet_sent = true; 2329 set_bit(PAPRD_PACKET_SENT, &sc->sc_ah->caldata->cal_flags);
2330 2330
2331 if (!(tx_flags & ATH_TX_ERROR)) 2331 if (!(tx_flags & ATH_TX_ERROR))
2332 /* Frame was ACKed */ 2332 /* Frame was ACKed */
diff --git a/drivers/net/wireless/ath/wil6210/pcie_bus.c b/drivers/net/wireless/ath/wil6210/pcie_bus.c
index eb1dc7ad80fb..eeceab39cda2 100644
--- a/drivers/net/wireless/ath/wil6210/pcie_bus.c
+++ b/drivers/net/wireless/ath/wil6210/pcie_bus.c
@@ -197,7 +197,6 @@ static void wil_pcie_remove(struct pci_dev *pdev)
197 pci_iounmap(pdev, wil->csr); 197 pci_iounmap(pdev, wil->csr);
198 pci_release_region(pdev, 0); 198 pci_release_region(pdev, 0);
199 pci_disable_device(pdev); 199 pci_disable_device(pdev);
200 pci_set_drvdata(pdev, NULL);
201} 200}
202 201
203static DEFINE_PCI_DEVICE_TABLE(wil6210_pcie_ids) = { 202static DEFINE_PCI_DEVICE_TABLE(wil6210_pcie_ids) = {
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
index c3462b75bd08..2a23bf2b904d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
@@ -34,6 +34,7 @@
34#include <brcmu_utils.h> 34#include <brcmu_utils.h>
35#include <brcmu_wifi.h> 35#include <brcmu_wifi.h>
36#include "sdio_host.h" 36#include "sdio_host.h"
37#include "sdio_chip.h"
37#include "dhd_dbg.h" 38#include "dhd_dbg.h"
38#include "dhd_bus.h" 39#include "dhd_bus.h"
39 40
@@ -41,13 +42,6 @@
41 42
42#define DMA_ALIGN_MASK 0x03 43#define DMA_ALIGN_MASK 0x03
43 44
44#define SDIO_DEVICE_ID_BROADCOM_43143 43143
45#define SDIO_DEVICE_ID_BROADCOM_43241 0x4324
46#define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
47#define SDIO_DEVICE_ID_BROADCOM_4330 0x4330
48#define SDIO_DEVICE_ID_BROADCOM_4334 0x4334
49#define SDIO_DEVICE_ID_BROADCOM_4335 0x4335
50
51#define SDIO_FUNC1_BLOCKSIZE 64 45#define SDIO_FUNC1_BLOCKSIZE 64
52#define SDIO_FUNC2_BLOCKSIZE 512 46#define SDIO_FUNC2_BLOCKSIZE 512
53 47
@@ -58,7 +52,8 @@ static const struct sdio_device_id brcmf_sdmmc_ids[] = {
58 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329)}, 52 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329)},
59 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4330)}, 53 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4330)},
60 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4334)}, 54 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4334)},
61 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4335)}, 55 {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM,
56 SDIO_DEVICE_ID_BROADCOM_4335_4339)},
62 { /* end: all zeroes */ }, 57 { /* end: all zeroes */ },
63}; 58};
64MODULE_DEVICE_TABLE(sdio, brcmf_sdmmc_ids); 59MODULE_DEVICE_TABLE(sdio, brcmf_sdmmc_ids);
@@ -466,7 +461,7 @@ static int brcmf_sdio_pd_probe(struct platform_device *pdev)
466{ 461{
467 brcmf_dbg(SDIO, "Enter\n"); 462 brcmf_dbg(SDIO, "Enter\n");
468 463
469 brcmfmac_sdio_pdata = pdev->dev.platform_data; 464 brcmfmac_sdio_pdata = dev_get_platdata(&pdev->dev);
470 465
471 if (brcmfmac_sdio_pdata->power_on) 466 if (brcmfmac_sdio_pdata->power_on)
472 brcmfmac_sdio_pdata->power_on(); 467 brcmfmac_sdio_pdata->power_on();
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd.h b/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
index 34af9d183107..899a2ada5b82 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
@@ -97,8 +97,6 @@
97#define WLC_PHY_TYPE_LCN 8 97#define WLC_PHY_TYPE_LCN 8
98#define WLC_PHY_TYPE_NULL 0xf 98#define WLC_PHY_TYPE_NULL 0xf
99 99
100#define BRCMF_EVENTING_MASK_LEN 16
101
102#define TOE_TX_CSUM_OL 0x00000001 100#define TOE_TX_CSUM_OL 0x00000001
103#define TOE_RX_CSUM_OL 0x00000002 101#define TOE_RX_CSUM_OL 0x00000002
104 102
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h b/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
index 7f1340d03f18..a6eb09e5d46f 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
@@ -136,7 +136,7 @@ bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
136 int prec); 136 int prec);
137 137
138/* Receive frame for delivery to OS. Callee disposes of rxp. */ 138/* Receive frame for delivery to OS. Callee disposes of rxp. */
139void brcmf_rx_frames(struct device *dev, struct sk_buff_head *rxlist); 139void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
140 140
141/* Indication from bus module regarding presence/insertion of dongle. */ 141/* Indication from bus module regarding presence/insertion of dongle. */
142int brcmf_attach(uint bus_hdrlen, struct device *dev); 142int brcmf_attach(uint bus_hdrlen, struct device *dev);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
index 40e7f854e10f..64e9cff241b9 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
@@ -509,9 +509,8 @@ netif_rx:
509 } 509 }
510} 510}
511 511
512void brcmf_rx_frames(struct device *dev, struct sk_buff_head *skb_list) 512void brcmf_rx_frame(struct device *dev, struct sk_buff *skb)
513{ 513{
514 struct sk_buff *skb, *pnext;
515 struct brcmf_if *ifp; 514 struct brcmf_if *ifp;
516 struct brcmf_bus *bus_if = dev_get_drvdata(dev); 515 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
517 struct brcmf_pub *drvr = bus_if->drvr; 516 struct brcmf_pub *drvr = bus_if->drvr;
@@ -519,29 +518,24 @@ void brcmf_rx_frames(struct device *dev, struct sk_buff_head *skb_list)
519 u8 ifidx; 518 u8 ifidx;
520 int ret; 519 int ret;
521 520
522 brcmf_dbg(DATA, "Enter: %s: count=%u\n", dev_name(dev), 521 brcmf_dbg(DATA, "Enter: %s: rxp=%p\n", dev_name(dev), skb);
523 skb_queue_len(skb_list));
524 522
525 skb_queue_walk_safe(skb_list, skb, pnext) { 523 /* process and remove protocol-specific header */
526 skb_unlink(skb, skb_list); 524 ret = brcmf_proto_hdrpull(drvr, true, &ifidx, skb);
527 525 ifp = drvr->iflist[ifidx];
528 /* process and remove protocol-specific header */
529 ret = brcmf_proto_hdrpull(drvr, true, &ifidx, skb);
530 ifp = drvr->iflist[ifidx];
531
532 if (ret || !ifp || !ifp->ndev) {
533 if ((ret != -ENODATA) && ifp)
534 ifp->stats.rx_errors++;
535 brcmu_pkt_buf_free_skb(skb);
536 continue;
537 }
538 526
539 rd = (struct brcmf_skb_reorder_data *)skb->cb; 527 if (ret || !ifp || !ifp->ndev) {
540 if (rd->reorder) 528 if ((ret != -ENODATA) && ifp)
541 brcmf_rxreorder_process_info(ifp, rd->reorder, skb); 529 ifp->stats.rx_errors++;
542 else 530 brcmu_pkt_buf_free_skb(skb);
543 brcmf_netif_rx(ifp, skb); 531 return;
544 } 532 }
533
534 rd = (struct brcmf_skb_reorder_data *)skb->cb;
535 if (rd->reorder)
536 brcmf_rxreorder_process_info(ifp, rd->reorder, skb);
537 else
538 brcmf_netif_rx(ifp, skb);
545} 539}
546 540
547void brcmf_txfinalize(struct brcmf_pub *drvr, struct sk_buff *txp, 541void brcmf_txfinalize(struct brcmf_pub *drvr, struct sk_buff *txp,
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 1aa75d5951b8..67f05db4b9b8 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -275,11 +275,6 @@ struct rte_console {
275/* Flags for SDH calls */ 275/* Flags for SDH calls */
276#define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED) 276#define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED)
277 277
278#define BRCMF_SDIO_FW_NAME "brcm/brcmfmac-sdio.bin"
279#define BRCMF_SDIO_NV_NAME "brcm/brcmfmac-sdio.txt"
280MODULE_FIRMWARE(BRCMF_SDIO_FW_NAME);
281MODULE_FIRMWARE(BRCMF_SDIO_NV_NAME);
282
283#define BRCMF_IDLE_IMMEDIATE (-1) /* Enter idle immediately */ 278#define BRCMF_IDLE_IMMEDIATE (-1) /* Enter idle immediately */
284#define BRCMF_IDLE_ACTIVE 0 /* Do not request any SD clock change 279#define BRCMF_IDLE_ACTIVE 0 /* Do not request any SD clock change
285 * when idle 280 * when idle
@@ -454,9 +449,6 @@ struct brcmf_sdio {
454 struct work_struct datawork; 449 struct work_struct datawork;
455 atomic_t dpc_tskcnt; 450 atomic_t dpc_tskcnt;
456 451
457 const struct firmware *firmware;
458 u32 fw_ptr;
459
460 bool txoff; /* Transmit flow-controlled */ 452 bool txoff; /* Transmit flow-controlled */
461 struct brcmf_sdio_count sdcnt; 453 struct brcmf_sdio_count sdcnt;
462 bool sr_enabled; /* SaveRestore enabled */ 454 bool sr_enabled; /* SaveRestore enabled */
@@ -493,6 +485,100 @@ enum brcmf_sdio_frmtype {
493 BRCMF_SDIO_FT_SUB, 485 BRCMF_SDIO_FT_SUB,
494}; 486};
495 487
488#define BCM43143_FIRMWARE_NAME "brcm/brcmfmac43143-sdio.bin"
489#define BCM43143_NVRAM_NAME "brcm/brcmfmac43143-sdio.txt"
490#define BCM43241B0_FIRMWARE_NAME "brcm/brcmfmac43241b0-sdio.bin"
491#define BCM43241B0_NVRAM_NAME "brcm/brcmfmac43241b0-sdio.txt"
492#define BCM43241B4_FIRMWARE_NAME "brcm/brcmfmac43241b4-sdio.bin"
493#define BCM43241B4_NVRAM_NAME "brcm/brcmfmac43241b4-sdio.txt"
494#define BCM4329_FIRMWARE_NAME "brcm/brcmfmac4329-sdio.bin"
495#define BCM4329_NVRAM_NAME "brcm/brcmfmac4329-sdio.txt"
496#define BCM4330_FIRMWARE_NAME "brcm/brcmfmac4330-sdio.bin"
497#define BCM4330_NVRAM_NAME "brcm/brcmfmac4330-sdio.txt"
498#define BCM4334_FIRMWARE_NAME "brcm/brcmfmac4334-sdio.bin"
499#define BCM4334_NVRAM_NAME "brcm/brcmfmac4334-sdio.txt"
500#define BCM4335_FIRMWARE_NAME "brcm/brcmfmac4335-sdio.bin"
501#define BCM4335_NVRAM_NAME "brcm/brcmfmac4335-sdio.txt"
502
503MODULE_FIRMWARE(BCM43143_FIRMWARE_NAME);
504MODULE_FIRMWARE(BCM43143_NVRAM_NAME);
505MODULE_FIRMWARE(BCM43241B0_FIRMWARE_NAME);
506MODULE_FIRMWARE(BCM43241B0_NVRAM_NAME);
507MODULE_FIRMWARE(BCM43241B4_FIRMWARE_NAME);
508MODULE_FIRMWARE(BCM43241B4_NVRAM_NAME);
509MODULE_FIRMWARE(BCM4329_FIRMWARE_NAME);
510MODULE_FIRMWARE(BCM4329_NVRAM_NAME);
511MODULE_FIRMWARE(BCM4330_FIRMWARE_NAME);
512MODULE_FIRMWARE(BCM4330_NVRAM_NAME);
513MODULE_FIRMWARE(BCM4334_FIRMWARE_NAME);
514MODULE_FIRMWARE(BCM4334_NVRAM_NAME);
515MODULE_FIRMWARE(BCM4335_FIRMWARE_NAME);
516MODULE_FIRMWARE(BCM4335_NVRAM_NAME);
517
518struct brcmf_firmware_names {
519 u32 chipid;
520 u32 revmsk;
521 const char *bin;
522 const char *nv;
523};
524
525enum brcmf_firmware_type {
526 BRCMF_FIRMWARE_BIN,
527 BRCMF_FIRMWARE_NVRAM
528};
529
530#define BRCMF_FIRMWARE_NVRAM(name) \
531 name ## _FIRMWARE_NAME, name ## _NVRAM_NAME
532
533static const struct brcmf_firmware_names brcmf_fwname_data[] = {
534 { BCM43143_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM43143) },
535 { BCM43241_CHIP_ID, 0x0000001F, BRCMF_FIRMWARE_NVRAM(BCM43241B0) },
536 { BCM43241_CHIP_ID, 0xFFFFFFE0, BRCMF_FIRMWARE_NVRAM(BCM43241B4) },
537 { BCM4329_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4329) },
538 { BCM4330_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4330) },
539 { BCM4334_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4334) },
540 { BCM4335_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4335) }
541};
542
543
544static const struct firmware *brcmf_sdbrcm_get_fw(struct brcmf_sdio *bus,
545 enum brcmf_firmware_type type)
546{
547 const struct firmware *fw;
548 const char *name;
549 int err, i;
550
551 for (i = 0; i < ARRAY_SIZE(brcmf_fwname_data); i++) {
552 if (brcmf_fwname_data[i].chipid == bus->ci->chip &&
553 brcmf_fwname_data[i].revmsk & BIT(bus->ci->chiprev)) {
554 switch (type) {
555 case BRCMF_FIRMWARE_BIN:
556 name = brcmf_fwname_data[i].bin;
557 break;
558 case BRCMF_FIRMWARE_NVRAM:
559 name = brcmf_fwname_data[i].nv;
560 break;
561 default:
562 brcmf_err("invalid firmware type (%d)\n", type);
563 return NULL;
564 }
565 goto found;
566 }
567 }
568 brcmf_err("Unknown chipid %d [%d]\n",
569 bus->ci->chip, bus->ci->chiprev);
570 return NULL;
571
572found:
573 err = request_firmware(&fw, name, &bus->sdiodev->func[2]->dev);
574 if ((err) || (!fw)) {
575 brcmf_err("fail to request firmware %s (%d)\n", name, err);
576 return NULL;
577 }
578
579 return fw;
580}
581
496static void pkt_align(struct sk_buff *p, int len, int align) 582static void pkt_align(struct sk_buff *p, int len, int align)
497{ 583{
498 uint datalign; 584 uint datalign;
@@ -1406,13 +1492,12 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1406 bus->glom.qlen, pfirst, pfirst->data, 1492 bus->glom.qlen, pfirst, pfirst->data,
1407 pfirst->len, pfirst->next, 1493 pfirst->len, pfirst->next,
1408 pfirst->prev); 1494 pfirst->prev);
1495 skb_unlink(pfirst, &bus->glom);
1496 brcmf_rx_frame(bus->sdiodev->dev, pfirst);
1497 bus->sdcnt.rxglompkts++;
1409 } 1498 }
1410 /* sent any remaining packets up */
1411 if (bus->glom.qlen)
1412 brcmf_rx_frames(bus->sdiodev->dev, &bus->glom);
1413 1499
1414 bus->sdcnt.rxglomframes++; 1500 bus->sdcnt.rxglomframes++;
1415 bus->sdcnt.rxglompkts += bus->glom.qlen;
1416 } 1501 }
1417 return num; 1502 return num;
1418} 1503}
@@ -1557,7 +1642,6 @@ static void brcmf_pad(struct brcmf_sdio *bus, u16 *pad, u16 *rdlen)
1557static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes) 1642static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
1558{ 1643{
1559 struct sk_buff *pkt; /* Packet for event or data frames */ 1644 struct sk_buff *pkt; /* Packet for event or data frames */
1560 struct sk_buff_head pktlist; /* needed for bus interface */
1561 u16 pad; /* Number of pad bytes to read */ 1645 u16 pad; /* Number of pad bytes to read */
1562 uint rxleft = 0; /* Remaining number of frames allowed */ 1646 uint rxleft = 0; /* Remaining number of frames allowed */
1563 int ret; /* Return code from calls */ 1647 int ret; /* Return code from calls */
@@ -1759,9 +1843,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
1759 continue; 1843 continue;
1760 } 1844 }
1761 1845
1762 skb_queue_head_init(&pktlist); 1846 brcmf_rx_frame(bus->sdiodev->dev, pkt);
1763 skb_queue_tail(&pktlist, pkt);
1764 brcmf_rx_frames(bus->sdiodev->dev, &pktlist);
1765 } 1847 }
1766 1848
1767 rxcount = maxframes - rxleft; 1849 rxcount = maxframes - rxleft;
@@ -1786,10 +1868,15 @@ brcmf_sdbrcm_wait_event_wakeup(struct brcmf_sdio *bus)
1786 return; 1868 return;
1787} 1869}
1788 1870
1871/**
1872 * struct brcmf_skbuff_cb reserves first two bytes in sk_buff::cb for
1873 * bus layer usage.
1874 */
1789/* flag marking a dummy skb added for DMA alignment requirement */ 1875/* flag marking a dummy skb added for DMA alignment requirement */
1790#define DUMMY_SKB_FLAG 0x10000 1876#define ALIGN_SKB_FLAG 0x8000
1791/* bit mask of data length chopped from the previous packet */ 1877/* bit mask of data length chopped from the previous packet */
1792#define DUMMY_SKB_CHOP_LEN_MASK 0xffff 1878#define ALIGN_SKB_CHOP_LEN_MASK 0x7fff
1879
1793/** 1880/**
1794 * brcmf_sdio_txpkt_prep - packet preparation for transmit 1881 * brcmf_sdio_txpkt_prep - packet preparation for transmit
1795 * @bus: brcmf_sdio structure pointer 1882 * @bus: brcmf_sdio structure pointer
@@ -1854,7 +1941,7 @@ brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
1854 memcpy(pkt_new->data, 1941 memcpy(pkt_new->data,
1855 pkt_next->data + pkt_next->len - tail_chop, 1942 pkt_next->data + pkt_next->len - tail_chop,
1856 tail_chop); 1943 tail_chop);
1857 *(u32 *)(pkt_new->cb) = DUMMY_SKB_FLAG + tail_chop; 1944 *(u32 *)(pkt_new->cb) = ALIGN_SKB_FLAG + tail_chop;
1858 skb_trim(pkt_next, pkt_next->len - tail_chop); 1945 skb_trim(pkt_next, pkt_next->len - tail_chop);
1859 __skb_queue_after(pktq, pkt_next, pkt_new); 1946 __skb_queue_after(pktq, pkt_next, pkt_new);
1860 } else { 1947 } else {
@@ -1908,8 +1995,8 @@ brcmf_sdio_txpkt_postp(struct brcmf_sdio *bus, struct sk_buff_head *pktq)
1908 1995
1909 skb_queue_walk_safe(pktq, pkt_next, tmp) { 1996 skb_queue_walk_safe(pktq, pkt_next, tmp) {
1910 dummy_flags = *(u32 *)(pkt_next->cb); 1997 dummy_flags = *(u32 *)(pkt_next->cb);
1911 if (dummy_flags & DUMMY_SKB_FLAG) { 1998 if (dummy_flags & ALIGN_SKB_FLAG) {
1912 chop_len = dummy_flags & DUMMY_SKB_CHOP_LEN_MASK; 1999 chop_len = dummy_flags & ALIGN_SKB_CHOP_LEN_MASK;
1913 if (chop_len) { 2000 if (chop_len) {
1914 pkt_prev = pkt_next->prev; 2001 pkt_prev = pkt_next->prev;
1915 memcpy(pkt_prev->data + pkt_prev->len, 2002 memcpy(pkt_prev->data + pkt_prev->len,
@@ -3037,69 +3124,43 @@ static bool brcmf_sdbrcm_download_state(struct brcmf_sdio *bus, bool enter)
3037 return true; 3124 return true;
3038} 3125}
3039 3126
3040static int brcmf_sdbrcm_get_image(char *buf, int len, struct brcmf_sdio *bus)
3041{
3042 if (bus->firmware->size < bus->fw_ptr + len)
3043 len = bus->firmware->size - bus->fw_ptr;
3044
3045 memcpy(buf, &bus->firmware->data[bus->fw_ptr], len);
3046 bus->fw_ptr += len;
3047 return len;
3048}
3049
3050static int brcmf_sdbrcm_download_code_file(struct brcmf_sdio *bus) 3127static int brcmf_sdbrcm_download_code_file(struct brcmf_sdio *bus)
3051{ 3128{
3129 const struct firmware *fw;
3130 int err;
3052 int offset; 3131 int offset;
3053 uint len; 3132 int address;
3054 u8 *memblock = NULL, *memptr; 3133 int len;
3055 int ret; 3134
3056 u8 idx; 3135 fw = brcmf_sdbrcm_get_fw(bus, BRCMF_FIRMWARE_BIN);
3057 3136 if (fw == NULL)
3058 brcmf_dbg(INFO, "Enter\n"); 3137 return -ENOENT;
3059 3138
3060 ret = request_firmware(&bus->firmware, BRCMF_SDIO_FW_NAME, 3139 if (brcmf_sdio_chip_getinfidx(bus->ci, BCMA_CORE_ARM_CR4) !=
3061 &bus->sdiodev->func[2]->dev); 3140 BRCMF_MAX_CORENUM)
3062 if (ret) { 3141 memcpy(&bus->ci->rst_vec, fw->data, sizeof(bus->ci->rst_vec));
3063 brcmf_err("Fail to request firmware %d\n", ret); 3142
3064 return ret; 3143 err = 0;
3065 } 3144 offset = 0;
3066 bus->fw_ptr = 0; 3145 address = bus->ci->rambase;
3067 3146 while (offset < fw->size) {
3068 memptr = memblock = kmalloc(MEMBLOCK + BRCMF_SDALIGN, GFP_ATOMIC); 3147 len = ((offset + MEMBLOCK) < fw->size) ? MEMBLOCK :
3069 if (memblock == NULL) { 3148 fw->size - offset;
3070 ret = -ENOMEM; 3149 err = brcmf_sdio_ramrw(bus->sdiodev, true, address,
3071 goto err; 3150 (u8 *)&fw->data[offset], len);
3072 } 3151 if (err) {
3073 if ((u32)(unsigned long)memblock % BRCMF_SDALIGN)
3074 memptr += (BRCMF_SDALIGN -
3075 ((u32)(unsigned long)memblock % BRCMF_SDALIGN));
3076
3077 offset = bus->ci->rambase;
3078
3079 /* Download image */
3080 len = brcmf_sdbrcm_get_image((char *)memptr, MEMBLOCK, bus);
3081 idx = brcmf_sdio_chip_getinfidx(bus->ci, BCMA_CORE_ARM_CR4);
3082 if (BRCMF_MAX_CORENUM != idx)
3083 memcpy(&bus->ci->rst_vec, memptr, sizeof(bus->ci->rst_vec));
3084 while (len) {
3085 ret = brcmf_sdio_ramrw(bus->sdiodev, true, offset, memptr, len);
3086 if (ret) {
3087 brcmf_err("error %d on writing %d membytes at 0x%08x\n", 3152 brcmf_err("error %d on writing %d membytes at 0x%08x\n",
3088 ret, MEMBLOCK, offset); 3153 err, len, address);
3089 goto err; 3154 goto failure;
3090 } 3155 }
3091 3156 offset += len;
3092 offset += MEMBLOCK; 3157 address += len;
3093 len = brcmf_sdbrcm_get_image((char *)memptr, MEMBLOCK, bus);
3094 } 3158 }
3095 3159
3096err: 3160failure:
3097 kfree(memblock); 3161 release_firmware(fw);
3098 3162
3099 release_firmware(bus->firmware); 3163 return err;
3100 bus->fw_ptr = 0;
3101
3102 return ret;
3103} 3164}
3104 3165
3105/* 3166/*
@@ -3111,7 +3172,8 @@ err:
3111 * by two NULs. 3172 * by two NULs.
3112*/ 3173*/
3113 3174
3114static int brcmf_process_nvram_vars(struct brcmf_sdio *bus) 3175static int brcmf_process_nvram_vars(struct brcmf_sdio *bus,
3176 const struct firmware *nv)
3115{ 3177{
3116 char *varbuf; 3178 char *varbuf;
3117 char *dp; 3179 char *dp;
@@ -3120,12 +3182,12 @@ static int brcmf_process_nvram_vars(struct brcmf_sdio *bus)
3120 int ret = 0; 3182 int ret = 0;
3121 uint buf_len, n, len; 3183 uint buf_len, n, len;
3122 3184
3123 len = bus->firmware->size; 3185 len = nv->size;
3124 varbuf = vmalloc(len); 3186 varbuf = vmalloc(len);
3125 if (!varbuf) 3187 if (!varbuf)
3126 return -ENOMEM; 3188 return -ENOMEM;
3127 3189
3128 memcpy(varbuf, bus->firmware->data, len); 3190 memcpy(varbuf, nv->data, len);
3129 dp = varbuf; 3191 dp = varbuf;
3130 3192
3131 findNewline = false; 3193 findNewline = false;
@@ -3177,18 +3239,16 @@ err:
3177 3239
3178static int brcmf_sdbrcm_download_nvram(struct brcmf_sdio *bus) 3240static int brcmf_sdbrcm_download_nvram(struct brcmf_sdio *bus)
3179{ 3241{
3242 const struct firmware *nv;
3180 int ret; 3243 int ret;
3181 3244
3182 ret = request_firmware(&bus->firmware, BRCMF_SDIO_NV_NAME, 3245 nv = brcmf_sdbrcm_get_fw(bus, BRCMF_FIRMWARE_NVRAM);
3183 &bus->sdiodev->func[2]->dev); 3246 if (nv == NULL)
3184 if (ret) { 3247 return -ENOENT;
3185 brcmf_err("Fail to request nvram %d\n", ret);
3186 return ret;
3187 }
3188 3248
3189 ret = brcmf_process_nvram_vars(bus); 3249 ret = brcmf_process_nvram_vars(bus, nv);
3190 3250
3191 release_firmware(bus->firmware); 3251 release_firmware(nv);
3192 3252
3193 return ret; 3253 return ret;
3194} 3254}
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/fweh.h b/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
index e679214b3c98..14bc24dc5bae 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
@@ -102,7 +102,8 @@ struct brcmf_event;
102 BRCMF_ENUM_DEF(DCS_REQUEST, 73) \ 102 BRCMF_ENUM_DEF(DCS_REQUEST, 73) \
103 BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \ 103 BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \
104 BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \ 104 BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \
105 BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127) 105 BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127) \
106 BRCMF_ENUM_DEF(PSTA_PRIMARY_INTF_IND, 128)
106 107
107#define BRCMF_ENUM_DEF(id, val) \ 108#define BRCMF_ENUM_DEF(id, val) \
108 BRCMF_E_##id = (val), 109 BRCMF_E_##id = (val),
@@ -114,6 +115,8 @@ enum brcmf_fweh_event_code {
114}; 115};
115#undef BRCMF_ENUM_DEF 116#undef BRCMF_ENUM_DEF
116 117
118#define BRCMF_EVENTING_MASK_LEN DIV_ROUND_UP(BRCMF_E_LAST, 8)
119
117/* flags field values in struct brcmf_event_msg */ 120/* flags field values in struct brcmf_event_msg */
118#define BRCMF_EVENT_MSG_LINK 0x01 121#define BRCMF_EVENT_MSG_LINK 0x01
119#define BRCMF_EVENT_MSG_FLUSHTXQ 0x02 122#define BRCMF_EVENT_MSG_FLUSHTXQ 0x02
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c b/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c
index 82f9140f3d35..d0cd0bf95c5a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c
@@ -168,6 +168,7 @@ enum brcmf_fws_skb_state {
168/** 168/**
169 * struct brcmf_skbuff_cb - control buffer associated with skbuff. 169 * struct brcmf_skbuff_cb - control buffer associated with skbuff.
170 * 170 *
171 * @bus_flags: 2 bytes reserved for bus specific parameters
171 * @if_flags: holds interface index and packet related flags. 172 * @if_flags: holds interface index and packet related flags.
172 * @htod: host to device packet identifier (used in PKTTAG tlv). 173 * @htod: host to device packet identifier (used in PKTTAG tlv).
173 * @state: transmit state of the packet. 174 * @state: transmit state of the packet.
@@ -177,6 +178,7 @@ enum brcmf_fws_skb_state {
177 * provides 48 bytes of storage so this structure should not exceed that. 178 * provides 48 bytes of storage so this structure should not exceed that.
178 */ 179 */
179struct brcmf_skbuff_cb { 180struct brcmf_skbuff_cb {
181 u16 bus_flags;
180 u16 if_flags; 182 u16 if_flags;
181 u32 htod; 183 u32 htod;
182 enum brcmf_fws_skb_state state; 184 enum brcmf_fws_skb_state state;
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.c b/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.c
index ca72177388b9..2096a14ef1fb 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.c
@@ -18,6 +18,7 @@
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/mmc/card.h> 20#include <linux/mmc/card.h>
21#include <linux/mmc/sdio_func.h>
21#include <linux/ssb/ssb_regs.h> 22#include <linux/ssb/ssb_regs.h>
22#include <linux/bcma/bcma.h> 23#include <linux/bcma/bcma.h>
23 24
@@ -136,6 +137,8 @@ brcmf_sdio_sb_iscoreup(struct brcmf_sdio_dev *sdiodev,
136 u8 idx; 137 u8 idx;
137 138
138 idx = brcmf_sdio_chip_getinfidx(ci, coreid); 139 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
140 if (idx == BRCMF_MAX_CORENUM)
141 return false;
139 142
140 regdata = brcmf_sdio_regrl(sdiodev, 143 regdata = brcmf_sdio_regrl(sdiodev,
141 CORE_SB(ci->c_inf[idx].base, sbtmstatelow), 144 CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
@@ -154,6 +157,8 @@ brcmf_sdio_ai_iscoreup(struct brcmf_sdio_dev *sdiodev,
154 bool ret; 157 bool ret;
155 158
156 idx = brcmf_sdio_chip_getinfidx(ci, coreid); 159 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
160 if (idx == BRCMF_MAX_CORENUM)
161 return false;
157 162
158 regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, 163 regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
159 NULL); 164 NULL);
@@ -261,6 +266,8 @@ brcmf_sdio_ai_coredisable(struct brcmf_sdio_dev *sdiodev,
261 u32 regdata; 266 u32 regdata;
262 267
263 idx = brcmf_sdio_chip_getinfidx(ci, coreid); 268 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
269 if (idx == BRCMF_MAX_CORENUM)
270 return;
264 271
265 /* if core is already in reset, just return */ 272 /* if core is already in reset, just return */
266 regdata = brcmf_sdio_regrl(sdiodev, 273 regdata = brcmf_sdio_regrl(sdiodev,
@@ -304,6 +311,8 @@ brcmf_sdio_sb_resetcore(struct brcmf_sdio_dev *sdiodev,
304 u8 idx; 311 u8 idx;
305 312
306 idx = brcmf_sdio_chip_getinfidx(ci, coreid); 313 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
314 if (idx == BRCMF_MAX_CORENUM)
315 return;
307 316
308 /* 317 /*
309 * Must do the disable sequence first to work for 318 * Must do the disable sequence first to work for
@@ -368,6 +377,8 @@ brcmf_sdio_ai_resetcore(struct brcmf_sdio_dev *sdiodev,
368 u32 regdata; 377 u32 regdata;
369 378
370 idx = brcmf_sdio_chip_getinfidx(ci, coreid); 379 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
380 if (idx == BRCMF_MAX_CORENUM)
381 return;
371 382
372 /* must disable first to work for arbitrary current core state */ 383 /* must disable first to work for arbitrary current core state */
373 brcmf_sdio_ai_coredisable(sdiodev, ci, coreid, core_bits); 384 brcmf_sdio_ai_coredisable(sdiodev, ci, coreid, core_bits);
@@ -444,6 +455,9 @@ static int brcmf_sdio_chip_recognition(struct brcmf_sdio_dev *sdiodev,
444 NULL); 455 NULL);
445 ci->chip = regdata & CID_ID_MASK; 456 ci->chip = regdata & CID_ID_MASK;
446 ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; 457 ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
458 if (sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 &&
459 ci->chiprev >= 2)
460 ci->chip = BCM4339_CHIP_ID;
447 ci->socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT; 461 ci->socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
448 462
449 brcmf_dbg(INFO, "chipid=0x%x chiprev=%d\n", ci->chip, ci->chiprev); 463 brcmf_dbg(INFO, "chipid=0x%x chiprev=%d\n", ci->chip, ci->chiprev);
@@ -541,6 +555,20 @@ static int brcmf_sdio_chip_recognition(struct brcmf_sdio_dev *sdiodev,
541 ci->ramsize = 0xc0000; 555 ci->ramsize = 0xc0000;
542 ci->rambase = 0x180000; 556 ci->rambase = 0x180000;
543 break; 557 break;
558 case BCM4339_CHIP_ID:
559 ci->c_inf[0].wrapbase = 0x18100000;
560 ci->c_inf[0].cib = 0x2e084411;
561 ci->c_inf[1].id = BCMA_CORE_SDIO_DEV;
562 ci->c_inf[1].base = 0x18005000;
563 ci->c_inf[1].wrapbase = 0x18105000;
564 ci->c_inf[1].cib = 0x15004211;
565 ci->c_inf[2].id = BCMA_CORE_ARM_CR4;
566 ci->c_inf[2].base = 0x18002000;
567 ci->c_inf[2].wrapbase = 0x18102000;
568 ci->c_inf[2].cib = 0x04084411;
569 ci->ramsize = 0xc0000;
570 ci->rambase = 0x180000;
571 break;
544 default: 572 default:
545 brcmf_err("chipid 0x%x is not supported\n", ci->chip); 573 brcmf_err("chipid 0x%x is not supported\n", ci->chip);
546 return -ENODEV; 574 return -ENODEV;
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.h b/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.h
index f0780ee05602..507c61c991fa 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio_chip.h
@@ -54,6 +54,14 @@
54 54
55#define BRCMF_MAX_CORENUM 6 55#define BRCMF_MAX_CORENUM 6
56 56
57/* SDIO device ID */
58#define SDIO_DEVICE_ID_BROADCOM_43143 43143
59#define SDIO_DEVICE_ID_BROADCOM_43241 0x4324
60#define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
61#define SDIO_DEVICE_ID_BROADCOM_4330 0x4330
62#define SDIO_DEVICE_ID_BROADCOM_4334 0x4334
63#define SDIO_DEVICE_ID_BROADCOM_4335_4339 0x4335
64
57struct chip_core_info { 65struct chip_core_info {
58 u16 id; 66 u16 id;
59 u16 rev; 67 u16 rev;
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index f4aea47e0730..422f44c63175 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -435,7 +435,6 @@ static void brcmf_usb_rx_complete(struct urb *urb)
435 struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context; 435 struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context;
436 struct brcmf_usbdev_info *devinfo = req->devinfo; 436 struct brcmf_usbdev_info *devinfo = req->devinfo;
437 struct sk_buff *skb; 437 struct sk_buff *skb;
438 struct sk_buff_head skbq;
439 438
440 brcmf_dbg(USB, "Enter, urb->status=%d\n", urb->status); 439 brcmf_dbg(USB, "Enter, urb->status=%d\n", urb->status);
441 brcmf_usb_del_fromq(devinfo, req); 440 brcmf_usb_del_fromq(devinfo, req);
@@ -450,10 +449,8 @@ static void brcmf_usb_rx_complete(struct urb *urb)
450 } 449 }
451 450
452 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) { 451 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) {
453 skb_queue_head_init(&skbq);
454 skb_queue_tail(&skbq, skb);
455 skb_put(skb, urb->actual_length); 452 skb_put(skb, urb->actual_length);
456 brcmf_rx_frames(devinfo->dev, &skbq); 453 brcmf_rx_frame(devinfo->dev, skb);
457 brcmf_usb_rx_refill(devinfo, req); 454 brcmf_usb_rx_refill(devinfo, req);
458 } else { 455 } else {
459 brcmu_pkt_buf_free_skb(skb); 456 brcmu_pkt_buf_free_skb(skb);
diff --git a/drivers/net/wireless/brcm80211/include/brcm_hw_ids.h b/drivers/net/wireless/brcm80211/include/brcm_hw_ids.h
index c1fe245bb07e..84113ea16f84 100644
--- a/drivers/net/wireless/brcm80211/include/brcm_hw_ids.h
+++ b/drivers/net/wireless/brcm80211/include/brcm_hw_ids.h
@@ -41,5 +41,6 @@
41#define BCM4331_CHIP_ID 0x4331 41#define BCM4331_CHIP_ID 0x4331
42#define BCM4334_CHIP_ID 0x4334 42#define BCM4334_CHIP_ID 0x4334
43#define BCM4335_CHIP_ID 0x4335 43#define BCM4335_CHIP_ID 0x4335
44#define BCM4339_CHIP_ID 0x4339
44 45
45#endif /* _BRCM_HW_IDS_H_ */ 46#endif /* _BRCM_HW_IDS_H_ */
diff --git a/drivers/net/wireless/cw1200/cw1200_spi.c b/drivers/net/wireless/cw1200/cw1200_spi.c
index 899cad34ccd3..8057143849ce 100644
--- a/drivers/net/wireless/cw1200/cw1200_spi.c
+++ b/drivers/net/wireless/cw1200/cw1200_spi.c
@@ -363,7 +363,7 @@ static struct hwbus_ops cw1200_spi_hwbus_ops = {
363static int cw1200_spi_probe(struct spi_device *func) 363static int cw1200_spi_probe(struct spi_device *func)
364{ 364{
365 const struct cw1200_platform_data_spi *plat_data = 365 const struct cw1200_platform_data_spi *plat_data =
366 func->dev.platform_data; 366 dev_get_platdata(&func->dev);
367 struct hwbus_priv *self; 367 struct hwbus_priv *self;
368 int status; 368 int status;
369 369
@@ -441,7 +441,7 @@ static int cw1200_spi_disconnect(struct spi_device *func)
441 } 441 }
442 kfree(self); 442 kfree(self);
443 } 443 }
444 cw1200_spi_off(func->dev.platform_data); 444 cw1200_spi_off(dev_get_platdata(&func->dev));
445 445
446 return 0; 446 return 0;
447} 447}
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index 8711a511fd52..81903e33d5b1 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -11885,7 +11885,6 @@ static int ipw_pci_probe(struct pci_dev *pdev,
11885 pci_release_regions(pdev); 11885 pci_release_regions(pdev);
11886 out_pci_disable_device: 11886 out_pci_disable_device:
11887 pci_disable_device(pdev); 11887 pci_disable_device(pdev);
11888 pci_set_drvdata(pdev, NULL);
11889 out_free_libipw: 11888 out_free_libipw:
11890 free_libipw(priv->net_dev, 0); 11889 free_libipw(priv->net_dev, 0);
11891 out: 11890 out:
@@ -11966,7 +11965,6 @@ static void ipw_pci_remove(struct pci_dev *pdev)
11966 iounmap(priv->hw_base); 11965 iounmap(priv->hw_base);
11967 pci_release_regions(pdev); 11966 pci_release_regions(pdev);
11968 pci_disable_device(pdev); 11967 pci_disable_device(pdev);
11969 pci_set_drvdata(pdev, NULL);
11970 /* wiphy_unregister needs to be here, before free_libipw */ 11968 /* wiphy_unregister needs to be here, before free_libipw */
11971 wiphy_unregister(priv->ieee->wdev.wiphy); 11969 wiphy_unregister(priv->ieee->wdev.wiphy);
11972 kfree(priv->ieee->a_band.channels); 11970 kfree(priv->ieee->a_band.channels);
diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
index 9581d07a4242..dea3b50d68b9 100644
--- a/drivers/net/wireless/iwlegacy/3945-mac.c
+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
@@ -3811,7 +3811,6 @@ out_iounmap:
3811out_pci_release_regions: 3811out_pci_release_regions:
3812 pci_release_regions(pdev); 3812 pci_release_regions(pdev);
3813out_pci_disable_device: 3813out_pci_disable_device:
3814 pci_set_drvdata(pdev, NULL);
3815 pci_disable_device(pdev); 3814 pci_disable_device(pdev);
3816out_ieee80211_free_hw: 3815out_ieee80211_free_hw:
3817 ieee80211_free_hw(il->hw); 3816 ieee80211_free_hw(il->hw);
@@ -3888,7 +3887,6 @@ il3945_pci_remove(struct pci_dev *pdev)
3888 iounmap(il->hw_base); 3887 iounmap(il->hw_base);
3889 pci_release_regions(pdev); 3888 pci_release_regions(pdev);
3890 pci_disable_device(pdev); 3889 pci_disable_device(pdev);
3891 pci_set_drvdata(pdev, NULL);
3892 3890
3893 il_free_channel_map(il); 3891 il_free_channel_map(il);
3894 il_free_geos(il); 3892 il_free_geos(il);
diff --git a/drivers/net/wireless/iwlegacy/4965-mac.c b/drivers/net/wireless/iwlegacy/4965-mac.c
index 5ab50a5b48b1..3982ab76f375 100644
--- a/drivers/net/wireless/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/iwlegacy/4965-mac.c
@@ -6706,7 +6706,6 @@ out_free_eeprom:
6706out_iounmap: 6706out_iounmap:
6707 iounmap(il->hw_base); 6707 iounmap(il->hw_base);
6708out_pci_release_regions: 6708out_pci_release_regions:
6709 pci_set_drvdata(pdev, NULL);
6710 pci_release_regions(pdev); 6709 pci_release_regions(pdev);
6711out_pci_disable_device: 6710out_pci_disable_device:
6712 pci_disable_device(pdev); 6711 pci_disable_device(pdev);
@@ -6787,7 +6786,6 @@ il4965_pci_remove(struct pci_dev *pdev)
6787 iounmap(il->hw_base); 6786 iounmap(il->hw_base);
6788 pci_release_regions(pdev); 6787 pci_release_regions(pdev);
6789 pci_disable_device(pdev); 6788 pci_disable_device(pdev);
6790 pci_set_drvdata(pdev, NULL);
6791 6789
6792 il4965_uninit_drv(il); 6790 il4965_uninit_drv(il);
6793 6791
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index bad95d28d50d..c3f904d422b0 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -1401,6 +1401,10 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
1401 spin_lock_init(&trans_pcie->reg_lock); 1401 spin_lock_init(&trans_pcie->reg_lock);
1402 init_waitqueue_head(&trans_pcie->ucode_write_waitq); 1402 init_waitqueue_head(&trans_pcie->ucode_write_waitq);
1403 1403
1404 err = pci_enable_device(pdev);
1405 if (err)
1406 goto out_no_pci;
1407
1404 if (!cfg->base_params->pcie_l1_allowed) { 1408 if (!cfg->base_params->pcie_l1_allowed) {
1405 /* 1409 /*
1406 * W/A - seems to solve weird behavior. We need to remove this 1410 * W/A - seems to solve weird behavior. We need to remove this
@@ -1412,10 +1416,6 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
1412 PCIE_LINK_STATE_CLKPM); 1416 PCIE_LINK_STATE_CLKPM);
1413 } 1417 }
1414 1418
1415 err = pci_enable_device(pdev);
1416 if (err)
1417 goto out_no_pci;
1418
1419 pci_set_master(pdev); 1419 pci_set_master(pdev);
1420 1420
1421 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); 1421 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 4bb6574f4073..5d39ec880d84 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -1128,7 +1128,7 @@ static int if_spi_probe(struct spi_device *spi)
1128{ 1128{
1129 struct if_spi_card *card; 1129 struct if_spi_card *card;
1130 struct lbs_private *priv = NULL; 1130 struct lbs_private *priv = NULL;
1131 struct libertas_spi_platform_data *pdata = spi->dev.platform_data; 1131 struct libertas_spi_platform_data *pdata = dev_get_platdata(&spi->dev);
1132 int err = 0; 1132 int err = 0;
1133 1133
1134 lbs_deb_enter(LBS_DEB_SPI); 1134 lbs_deb_enter(LBS_DEB_SPI);
diff --git a/drivers/net/wireless/mwifiex/pcie.c b/drivers/net/wireless/mwifiex/pcie.c
index 52da8ee7599a..33fa9432b241 100644
--- a/drivers/net/wireless/mwifiex/pcie.c
+++ b/drivers/net/wireless/mwifiex/pcie.c
@@ -93,7 +93,7 @@ static int mwifiex_pcie_suspend(struct device *dev)
93 struct pci_dev *pdev = to_pci_dev(dev); 93 struct pci_dev *pdev = to_pci_dev(dev);
94 94
95 if (pdev) { 95 if (pdev) {
96 card = (struct pcie_service_card *) pci_get_drvdata(pdev); 96 card = pci_get_drvdata(pdev);
97 if (!card || !card->adapter) { 97 if (!card || !card->adapter) {
98 pr_err("Card or adapter structure is not valid\n"); 98 pr_err("Card or adapter structure is not valid\n");
99 return 0; 99 return 0;
@@ -128,7 +128,7 @@ static int mwifiex_pcie_resume(struct device *dev)
128 struct pci_dev *pdev = to_pci_dev(dev); 128 struct pci_dev *pdev = to_pci_dev(dev);
129 129
130 if (pdev) { 130 if (pdev) {
131 card = (struct pcie_service_card *) pci_get_drvdata(pdev); 131 card = pci_get_drvdata(pdev);
132 if (!card || !card->adapter) { 132 if (!card || !card->adapter) {
133 pr_err("Card or adapter structure is not valid\n"); 133 pr_err("Card or adapter structure is not valid\n");
134 return 0; 134 return 0;
@@ -2037,7 +2037,7 @@ static irqreturn_t mwifiex_pcie_interrupt(int irq, void *context)
2037 goto exit; 2037 goto exit;
2038 } 2038 }
2039 2039
2040 card = (struct pcie_service_card *) pci_get_drvdata(pdev); 2040 card = pci_get_drvdata(pdev);
2041 if (!card || !card->adapter) { 2041 if (!card || !card->adapter) {
2042 pr_debug("info: %s: card=%p adapter=%p\n", __func__, card, 2042 pr_debug("info: %s: card=%p adapter=%p\n", __func__, card,
2043 card ? card->adapter : NULL); 2043 card ? card->adapter : NULL);
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index a3707fd4ef62..b953ad621e0b 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -6093,7 +6093,6 @@ err_iounmap:
6093 if (priv->sram != NULL) 6093 if (priv->sram != NULL)
6094 pci_iounmap(pdev, priv->sram); 6094 pci_iounmap(pdev, priv->sram);
6095 6095
6096 pci_set_drvdata(pdev, NULL);
6097 ieee80211_free_hw(hw); 6096 ieee80211_free_hw(hw);
6098 6097
6099err_free_reg: 6098err_free_reg:
@@ -6147,7 +6146,6 @@ static void mwl8k_remove(struct pci_dev *pdev)
6147unmap: 6146unmap:
6148 pci_iounmap(pdev, priv->regs); 6147 pci_iounmap(pdev, priv->regs);
6149 pci_iounmap(pdev, priv->sram); 6148 pci_iounmap(pdev, priv->sram);
6150 pci_set_drvdata(pdev, NULL);
6151 ieee80211_free_hw(hw); 6149 ieee80211_free_hw(hw);
6152 pci_release_regions(pdev); 6150 pci_release_regions(pdev);
6153 pci_disable_device(pdev); 6151 pci_disable_device(pdev);
diff --git a/drivers/net/wireless/orinoco/orinoco_nortel.c b/drivers/net/wireless/orinoco/orinoco_nortel.c
index d73fdf6185a2..ffb2469eb679 100644
--- a/drivers/net/wireless/orinoco/orinoco_nortel.c
+++ b/drivers/net/wireless/orinoco/orinoco_nortel.c
@@ -234,7 +234,6 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
234 free_irq(pdev->irq, priv); 234 free_irq(pdev->irq, priv);
235 235
236 fail_irq: 236 fail_irq:
237 pci_set_drvdata(pdev, NULL);
238 free_orinocodev(priv); 237 free_orinocodev(priv);
239 238
240 fail_alloc: 239 fail_alloc:
@@ -265,7 +264,6 @@ static void orinoco_nortel_remove_one(struct pci_dev *pdev)
265 264
266 orinoco_if_del(priv); 265 orinoco_if_del(priv);
267 free_irq(pdev->irq, priv); 266 free_irq(pdev->irq, priv);
268 pci_set_drvdata(pdev, NULL);
269 free_orinocodev(priv); 267 free_orinocodev(priv);
270 pci_iounmap(pdev, priv->hw.iobase); 268 pci_iounmap(pdev, priv->hw.iobase);
271 pci_iounmap(pdev, card->attr_io); 269 pci_iounmap(pdev, card->attr_io);
diff --git a/drivers/net/wireless/orinoco/orinoco_pci.c b/drivers/net/wireless/orinoco/orinoco_pci.c
index 677bf14eca84..5ae1191d2532 100644
--- a/drivers/net/wireless/orinoco/orinoco_pci.c
+++ b/drivers/net/wireless/orinoco/orinoco_pci.c
@@ -184,7 +184,6 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
184 free_irq(pdev->irq, priv); 184 free_irq(pdev->irq, priv);
185 185
186 fail_irq: 186 fail_irq:
187 pci_set_drvdata(pdev, NULL);
188 free_orinocodev(priv); 187 free_orinocodev(priv);
189 188
190 fail_alloc: 189 fail_alloc:
@@ -205,7 +204,6 @@ static void orinoco_pci_remove_one(struct pci_dev *pdev)
205 204
206 orinoco_if_del(priv); 205 orinoco_if_del(priv);
207 free_irq(pdev->irq, priv); 206 free_irq(pdev->irq, priv);
208 pci_set_drvdata(pdev, NULL);
209 free_orinocodev(priv); 207 free_orinocodev(priv);
210 pci_iounmap(pdev, priv->hw.iobase); 208 pci_iounmap(pdev, priv->hw.iobase);
211 pci_release_regions(pdev); 209 pci_release_regions(pdev);
diff --git a/drivers/net/wireless/orinoco/orinoco_plx.c b/drivers/net/wireless/orinoco/orinoco_plx.c
index 2559dbd6184b..bbd36d1676ff 100644
--- a/drivers/net/wireless/orinoco/orinoco_plx.c
+++ b/drivers/net/wireless/orinoco/orinoco_plx.c
@@ -273,7 +273,6 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
273 free_irq(pdev->irq, priv); 273 free_irq(pdev->irq, priv);
274 274
275 fail_irq: 275 fail_irq:
276 pci_set_drvdata(pdev, NULL);
277 free_orinocodev(priv); 276 free_orinocodev(priv);
278 277
279 fail_alloc: 278 fail_alloc:
@@ -301,7 +300,6 @@ static void orinoco_plx_remove_one(struct pci_dev *pdev)
301 300
302 orinoco_if_del(priv); 301 orinoco_if_del(priv);
303 free_irq(pdev->irq, priv); 302 free_irq(pdev->irq, priv);
304 pci_set_drvdata(pdev, NULL);
305 free_orinocodev(priv); 303 free_orinocodev(priv);
306 pci_iounmap(pdev, priv->hw.iobase); 304 pci_iounmap(pdev, priv->hw.iobase);
307 pci_iounmap(pdev, card->attr_io); 305 pci_iounmap(pdev, card->attr_io);
diff --git a/drivers/net/wireless/orinoco/orinoco_tmd.c b/drivers/net/wireless/orinoco/orinoco_tmd.c
index 42afeeea2c40..04b08de5fd5d 100644
--- a/drivers/net/wireless/orinoco/orinoco_tmd.c
+++ b/drivers/net/wireless/orinoco/orinoco_tmd.c
@@ -170,7 +170,6 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
170 free_irq(pdev->irq, priv); 170 free_irq(pdev->irq, priv);
171 171
172 fail_irq: 172 fail_irq:
173 pci_set_drvdata(pdev, NULL);
174 free_orinocodev(priv); 173 free_orinocodev(priv);
175 174
176 fail_alloc: 175 fail_alloc:
@@ -195,7 +194,6 @@ static void orinoco_tmd_remove_one(struct pci_dev *pdev)
195 194
196 orinoco_if_del(priv); 195 orinoco_if_del(priv);
197 free_irq(pdev->irq, priv); 196 free_irq(pdev->irq, priv);
198 pci_set_drvdata(pdev, NULL);
199 free_orinocodev(priv); 197 free_orinocodev(priv);
200 pci_iounmap(pdev, priv->hw.iobase); 198 pci_iounmap(pdev, priv->hw.iobase);
201 pci_iounmap(pdev, card->bridge_io); 199 pci_iounmap(pdev, card->bridge_io);
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index 57e3af8ebb4b..f9a07b0d83ac 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -631,7 +631,6 @@ static int p54p_probe(struct pci_dev *pdev,
631 iounmap(priv->map); 631 iounmap(priv->map);
632 632
633 err_free_dev: 633 err_free_dev:
634 pci_set_drvdata(pdev, NULL);
635 p54_free_common(dev); 634 p54_free_common(dev);
636 635
637 err_free_reg: 636 err_free_reg:
diff --git a/drivers/net/wireless/rt2x00/rt2800.h b/drivers/net/wireless/rt2x00/rt2800.h
index fa33b5edf931..e3eb95292a7f 100644
--- a/drivers/net/wireless/rt2x00/rt2800.h
+++ b/drivers/net/wireless/rt2x00/rt2800.h
@@ -52,6 +52,7 @@
52 * RF3322 2.4G 2T2R(RT3352/RT3371/RT3372/RT3391/RT3392) 52 * RF3322 2.4G 2T2R(RT3352/RT3371/RT3372/RT3391/RT3392)
53 * RF3053 2.4G/5G 3T3R(RT3883/RT3563/RT3573/RT3593/RT3662) 53 * RF3053 2.4G/5G 3T3R(RT3883/RT3563/RT3573/RT3593/RT3662)
54 * RF5592 2.4G/5G 2T2R 54 * RF5592 2.4G/5G 2T2R
55 * RF3070 2.4G 1T1R
55 * RF5360 2.4G 1T1R 56 * RF5360 2.4G 1T1R
56 * RF5370 2.4G 1T1R 57 * RF5370 2.4G 1T1R
57 * RF5390 2.4G 1T1R 58 * RF5390 2.4G 1T1R
@@ -70,6 +71,7 @@
70#define RF3322 0x000c 71#define RF3322 0x000c
71#define RF3053 0x000d 72#define RF3053 0x000d
72#define RF5592 0x000f 73#define RF5592 0x000f
74#define RF3070 0x3070
73#define RF3290 0x3290 75#define RF3290 0x3290
74#define RF5360 0x5360 76#define RF5360 0x5360
75#define RF5370 0x5370 77#define RF5370 0x5370
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index 88ce656f96cd..25aaa5e12d4e 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -3152,6 +3152,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
3152 case RF3322: 3152 case RF3322:
3153 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info); 3153 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
3154 break; 3154 break;
3155 case RF3070:
3155 case RF5360: 3156 case RF5360:
3156 case RF5370: 3157 case RF5370:
3157 case RF5372: 3158 case RF5372:
@@ -3166,7 +3167,8 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
3166 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info); 3167 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
3167 } 3168 }
3168 3169
3169 if (rt2x00_rf(rt2x00dev, RF3290) || 3170 if (rt2x00_rf(rt2x00dev, RF3070) ||
3171 rt2x00_rf(rt2x00dev, RF3290) ||
3170 rt2x00_rf(rt2x00dev, RF3322) || 3172 rt2x00_rf(rt2x00dev, RF3322) ||
3171 rt2x00_rf(rt2x00dev, RF5360) || 3173 rt2x00_rf(rt2x00dev, RF5360) ||
3172 rt2x00_rf(rt2x00dev, RF5370) || 3174 rt2x00_rf(rt2x00dev, RF5370) ||
@@ -3315,29 +3317,37 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
3315 rt2800_rfcsr_write(rt2x00dev, 8, 0x80); 3317 rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
3316 3318
3317 if (rt2x00_rt(rt2x00dev, RT3593)) { 3319 if (rt2x00_rt(rt2x00dev, RT3593)) {
3318 if (rt2x00_is_usb(rt2x00dev)) { 3320 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
3319 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
3320 3321
3321 /* Band selection. GPIO #8 controls all paths */ 3322 /* Band selection */
3323 if (rt2x00_is_usb(rt2x00dev) ||
3324 rt2x00_is_pcie(rt2x00dev)) {
3325 /* GPIO #8 controls all paths */
3322 rt2x00_set_field32(&reg, GPIO_CTRL_DIR8, 0); 3326 rt2x00_set_field32(&reg, GPIO_CTRL_DIR8, 0);
3323 if (rf->channel <= 14) 3327 if (rf->channel <= 14)
3324 rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 1); 3328 rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 1);
3325 else 3329 else
3326 rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 0); 3330 rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 0);
3331 }
3327 3332
3333 /* LNA PE control. */
3334 if (rt2x00_is_usb(rt2x00dev)) {
3335 /* GPIO #4 controls PE0 and PE1,
3336 * GPIO #7 controls PE2
3337 */
3328 rt2x00_set_field32(&reg, GPIO_CTRL_DIR4, 0); 3338 rt2x00_set_field32(&reg, GPIO_CTRL_DIR4, 0);
3329 rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0); 3339 rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0);
3330 3340
3331 /* LNA PE control.
3332 * GPIO #4 controls PE0 and PE1,
3333 * GPIO #7 controls PE2
3334 */
3335 rt2x00_set_field32(&reg, GPIO_CTRL_VAL4, 1); 3341 rt2x00_set_field32(&reg, GPIO_CTRL_VAL4, 1);
3336 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1); 3342 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1);
3337 3343 } else if (rt2x00_is_pcie(rt2x00dev)) {
3338 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); 3344 /* GPIO #4 controls PE0, PE1 and PE2 */
3345 rt2x00_set_field32(&reg, GPIO_CTRL_DIR4, 0);
3346 rt2x00_set_field32(&reg, GPIO_CTRL_VAL4, 1);
3339 } 3347 }
3340 3348
3349 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
3350
3341 /* AGC init */ 3351 /* AGC init */
3342 if (rf->channel <= 14) 3352 if (rf->channel <= 14)
3343 reg = 0x1c + 2 * rt2x00dev->lna_gain; 3353 reg = 0x1c + 2 * rt2x00dev->lna_gain;
@@ -4264,6 +4274,7 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
4264 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); 4274 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
4265 break; 4275 break;
4266 case RF3053: 4276 case RF3053:
4277 case RF3070:
4267 case RF3290: 4278 case RF3290:
4268 case RF5360: 4279 case RF5360:
4269 case RF5370: 4280 case RF5370:
@@ -5985,7 +5996,7 @@ static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev)
5985 rt2800_rfcsr_write(rt2x00dev, 20, 0xba); 5996 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
5986 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); 5997 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
5987 rt2800_rfcsr_write(rt2x00dev, 24, 0x16); 5998 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
5988 rt2800_rfcsr_write(rt2x00dev, 25, 0x01); 5999 rt2800_rfcsr_write(rt2x00dev, 25, 0x03);
5989 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f); 6000 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
5990 6001
5991 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { 6002 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
@@ -6653,17 +6664,20 @@ int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
6653 u16 word; 6664 u16 word;
6654 6665
6655 /* 6666 /*
6656 * Initialize all registers. 6667 * Initialize MAC registers.
6657 */ 6668 */
6658 if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) || 6669 if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
6659 rt2800_init_registers(rt2x00dev))) 6670 rt2800_init_registers(rt2x00dev)))
6660 return -EIO; 6671 return -EIO;
6661 6672
6673 /*
6674 * Wait BBP/RF to wake up.
6675 */
6662 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev))) 6676 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev)))
6663 return -EIO; 6677 return -EIO;
6664 6678
6665 /* 6679 /*
6666 * Send signal to firmware during boot time. 6680 * Send signal during boot time to initialize firmware.
6667 */ 6681 */
6668 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); 6682 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
6669 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); 6683 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
@@ -6672,9 +6686,15 @@ int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
6672 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0); 6686 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
6673 msleep(1); 6687 msleep(1);
6674 6688
6689 /*
6690 * Make sure BBP is up and running.
6691 */
6675 if (unlikely(rt2800_wait_bbp_ready(rt2x00dev))) 6692 if (unlikely(rt2800_wait_bbp_ready(rt2x00dev)))
6676 return -EIO; 6693 return -EIO;
6677 6694
6695 /*
6696 * Initialize BBP/RF registers.
6697 */
6678 rt2800_init_bbp(rt2x00dev); 6698 rt2800_init_bbp(rt2x00dev);
6679 rt2800_init_rfcsr(rt2x00dev); 6699 rt2800_init_rfcsr(rt2x00dev);
6680 6700
@@ -7021,6 +7041,7 @@ static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
7021 case RF3022: 7041 case RF3022:
7022 case RF3052: 7042 case RF3052:
7023 case RF3053: 7043 case RF3053:
7044 case RF3070:
7024 case RF3290: 7045 case RF3290:
7025 case RF3320: 7046 case RF3320:
7026 case RF3322: 7047 case RF3322:
@@ -7543,6 +7564,7 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
7543 rt2x00_rf(rt2x00dev, RF2020) || 7564 rt2x00_rf(rt2x00dev, RF2020) ||
7544 rt2x00_rf(rt2x00dev, RF3021) || 7565 rt2x00_rf(rt2x00dev, RF3021) ||
7545 rt2x00_rf(rt2x00dev, RF3022) || 7566 rt2x00_rf(rt2x00dev, RF3022) ||
7567 rt2x00_rf(rt2x00dev, RF3070) ||
7546 rt2x00_rf(rt2x00dev, RF3290) || 7568 rt2x00_rf(rt2x00dev, RF3290) ||
7547 rt2x00_rf(rt2x00dev, RF3320) || 7569 rt2x00_rf(rt2x00dev, RF3320) ||
7548 rt2x00_rf(rt2x00dev, RF3322) || 7570 rt2x00_rf(rt2x00dev, RF3322) ||
@@ -7671,6 +7693,7 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
7671 case RF3320: 7693 case RF3320:
7672 case RF3052: 7694 case RF3052:
7673 case RF3053: 7695 case RF3053:
7696 case RF3070:
7674 case RF3290: 7697 case RF3290:
7675 case RF5360: 7698 case RF5360:
7676 case RF5370: 7699 case RF5370:
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 96961b9a395c..96677ce55da4 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -1176,6 +1176,8 @@ static struct usb_device_id rt2800usb_device_table[] = {
1176 /* Linksys */ 1176 /* Linksys */
1177 { USB_DEVICE(0x13b1, 0x002f) }, 1177 { USB_DEVICE(0x13b1, 0x002f) },
1178 { USB_DEVICE(0x1737, 0x0079) }, 1178 { USB_DEVICE(0x1737, 0x0079) },
1179 /* Logitec */
1180 { USB_DEVICE(0x0789, 0x0170) },
1179 /* Ralink */ 1181 /* Ralink */
1180 { USB_DEVICE(0x148f, 0x3572) }, 1182 { USB_DEVICE(0x148f, 0x3572) },
1181 /* Sitecom */ 1183 /* Sitecom */
@@ -1199,6 +1201,8 @@ static struct usb_device_id rt2800usb_device_table[] = {
1199 { USB_DEVICE(0x050d, 0x1103) }, 1201 { USB_DEVICE(0x050d, 0x1103) },
1200 /* Cameo */ 1202 /* Cameo */
1201 { USB_DEVICE(0x148f, 0xf301) }, 1203 { USB_DEVICE(0x148f, 0xf301) },
1204 /* D-Link */
1205 { USB_DEVICE(0x2001, 0x3c1f) },
1202 /* Edimax */ 1206 /* Edimax */
1203 { USB_DEVICE(0x7392, 0x7733) }, 1207 { USB_DEVICE(0x7392, 0x7733) },
1204 /* Hawking */ 1208 /* Hawking */
@@ -1212,6 +1216,7 @@ static struct usb_device_id rt2800usb_device_table[] = {
1212 { USB_DEVICE(0x0789, 0x016b) }, 1216 { USB_DEVICE(0x0789, 0x016b) },
1213 /* NETGEAR */ 1217 /* NETGEAR */
1214 { USB_DEVICE(0x0846, 0x9012) }, 1218 { USB_DEVICE(0x0846, 0x9012) },
1219 { USB_DEVICE(0x0846, 0x9013) },
1215 { USB_DEVICE(0x0846, 0x9019) }, 1220 { USB_DEVICE(0x0846, 0x9019) },
1216 /* Planex */ 1221 /* Planex */
1217 { USB_DEVICE(0x2019, 0xed19) }, 1222 { USB_DEVICE(0x2019, 0xed19) },
@@ -1220,6 +1225,7 @@ static struct usb_device_id rt2800usb_device_table[] = {
1220 /* Sitecom */ 1225 /* Sitecom */
1221 { USB_DEVICE(0x0df6, 0x0067) }, 1226 { USB_DEVICE(0x0df6, 0x0067) },
1222 { USB_DEVICE(0x0df6, 0x006a) }, 1227 { USB_DEVICE(0x0df6, 0x006a) },
1228 { USB_DEVICE(0x0df6, 0x006e) },
1223 /* ZyXEL */ 1229 /* ZyXEL */
1224 { USB_DEVICE(0x0586, 0x3421) }, 1230 { USB_DEVICE(0x0586, 0x3421) },
1225#endif 1231#endif
@@ -1236,6 +1242,9 @@ static struct usb_device_id rt2800usb_device_table[] = {
1236 { USB_DEVICE(0x2001, 0x3c1c) }, 1242 { USB_DEVICE(0x2001, 0x3c1c) },
1237 { USB_DEVICE(0x2001, 0x3c1d) }, 1243 { USB_DEVICE(0x2001, 0x3c1d) },
1238 { USB_DEVICE(0x2001, 0x3c1e) }, 1244 { USB_DEVICE(0x2001, 0x3c1e) },
1245 { USB_DEVICE(0x2001, 0x3c20) },
1246 { USB_DEVICE(0x2001, 0x3c22) },
1247 { USB_DEVICE(0x2001, 0x3c23) },
1239 /* LG innotek */ 1248 /* LG innotek */
1240 { USB_DEVICE(0x043e, 0x7a22) }, 1249 { USB_DEVICE(0x043e, 0x7a22) },
1241 { USB_DEVICE(0x043e, 0x7a42) }, 1250 { USB_DEVICE(0x043e, 0x7a42) },
@@ -1258,12 +1267,17 @@ static struct usb_device_id rt2800usb_device_table[] = {
1258 { USB_DEVICE(0x043e, 0x7a32) }, 1267 { USB_DEVICE(0x043e, 0x7a32) },
1259 /* AVM GmbH */ 1268 /* AVM GmbH */
1260 { USB_DEVICE(0x057c, 0x8501) }, 1269 { USB_DEVICE(0x057c, 0x8501) },
1261 /* D-Link DWA-160-B2 */ 1270 /* Buffalo */
1271 { USB_DEVICE(0x0411, 0x0241) },
1272 /* D-Link */
1262 { USB_DEVICE(0x2001, 0x3c1a) }, 1273 { USB_DEVICE(0x2001, 0x3c1a) },
1274 { USB_DEVICE(0x2001, 0x3c21) },
1263 /* Proware */ 1275 /* Proware */
1264 { USB_DEVICE(0x043e, 0x7a13) }, 1276 { USB_DEVICE(0x043e, 0x7a13) },
1265 /* Ralink */ 1277 /* Ralink */
1266 { USB_DEVICE(0x148f, 0x5572) }, 1278 { USB_DEVICE(0x148f, 0x5572) },
1279 /* TRENDnet */
1280 { USB_DEVICE(0x20f4, 0x724a) },
1267#endif 1281#endif
1268#ifdef CONFIG_RT2800USB_UNKNOWN 1282#ifdef CONFIG_RT2800USB_UNKNOWN
1269 /* 1283 /*
@@ -1333,6 +1347,7 @@ static struct usb_device_id rt2800usb_device_table[] = {
1333 { USB_DEVICE(0x1d4d, 0x0010) }, 1347 { USB_DEVICE(0x1d4d, 0x0010) },
1334 /* Planex */ 1348 /* Planex */
1335 { USB_DEVICE(0x2019, 0xab24) }, 1349 { USB_DEVICE(0x2019, 0xab24) },
1350 { USB_DEVICE(0x2019, 0xab29) },
1336 /* Qcom */ 1351 /* Qcom */
1337 { USB_DEVICE(0x18e8, 0x6259) }, 1352 { USB_DEVICE(0x18e8, 0x6259) },
1338 /* RadioShack */ 1353 /* RadioShack */
diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index fc207b268e4f..a91506b12a62 100644
--- a/drivers/net/wireless/rtl818x/rtl8180/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c
@@ -1122,7 +1122,6 @@ static int rtl8180_probe(struct pci_dev *pdev,
1122 iounmap(priv->map); 1122 iounmap(priv->map);
1123 1123
1124 err_free_dev: 1124 err_free_dev:
1125 pci_set_drvdata(pdev, NULL);
1126 ieee80211_free_hw(dev); 1125 ieee80211_free_hw(dev);
1127 1126
1128 err_free_reg: 1127 err_free_reg:
diff --git a/drivers/net/wireless/rtlwifi/base.c b/drivers/net/wireless/rtlwifi/base.c
index 8bb4a9a01a18..9a78e3daf742 100644
--- a/drivers/net/wireless/rtlwifi/base.c
+++ b/drivers/net/wireless/rtlwifi/base.c
@@ -1613,6 +1613,35 @@ err_free:
1613} 1613}
1614EXPORT_SYMBOL(rtl_send_smps_action); 1614EXPORT_SYMBOL(rtl_send_smps_action);
1615 1615
1616void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1617{
1618 struct rtl_priv *rtlpriv = rtl_priv(hw);
1619 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1620 enum io_type iotype;
1621
1622 if (!is_hal_stop(rtlhal)) {
1623 switch (operation) {
1624 case SCAN_OPT_BACKUP:
1625 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
1626 rtlpriv->cfg->ops->set_hw_reg(hw,
1627 HW_VAR_IO_CMD,
1628 (u8 *)&iotype);
1629 break;
1630 case SCAN_OPT_RESTORE:
1631 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1632 rtlpriv->cfg->ops->set_hw_reg(hw,
1633 HW_VAR_IO_CMD,
1634 (u8 *)&iotype);
1635 break;
1636 default:
1637 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1638 "Unknown Scan Backup operation.\n");
1639 break;
1640 }
1641 }
1642}
1643EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
1644
1616/* There seem to be issues in mac80211 regarding when del ba frames can be 1645/* There seem to be issues in mac80211 regarding when del ba frames can be
1617 * received. As a work around, we make a fake del_ba if we receive a ba_req; 1646 * received. As a work around, we make a fake del_ba if we receive a ba_req;
1618 * however, rx_agg was opened to let mac80211 release some ba related 1647 * however, rx_agg was opened to let mac80211 release some ba related
diff --git a/drivers/net/wireless/rtlwifi/base.h b/drivers/net/wireless/rtlwifi/base.h
index 0e5fe0902daf..0cd07420777a 100644
--- a/drivers/net/wireless/rtlwifi/base.h
+++ b/drivers/net/wireless/rtlwifi/base.h
@@ -114,7 +114,6 @@ void rtl_init_rfkill(struct ieee80211_hw *hw);
114void rtl_deinit_rfkill(struct ieee80211_hw *hw); 114void rtl_deinit_rfkill(struct ieee80211_hw *hw);
115 115
116void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb); 116void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb);
117void rtl_watch_dog_timer_callback(unsigned long data);
118void rtl_deinit_deferred_work(struct ieee80211_hw *hw); 117void rtl_deinit_deferred_work(struct ieee80211_hw *hw);
119 118
120bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx); 119bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx);
@@ -153,5 +152,6 @@ int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
153bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb); 152bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb);
154struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, 153struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
155 u8 *sa, u8 *bssid, u16 tid); 154 u8 *sa, u8 *bssid, u16 tid);
155void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation);
156 156
157#endif 157#endif
diff --git a/drivers/net/wireless/rtlwifi/efuse.c b/drivers/net/wireless/rtlwifi/efuse.c
index 838a1ed3f194..ae13fb94b2e8 100644
--- a/drivers/net/wireless/rtlwifi/efuse.c
+++ b/drivers/net/wireless/rtlwifi/efuse.c
@@ -1203,20 +1203,18 @@ static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1203 1203
1204static u16 efuse_get_current_size(struct ieee80211_hw *hw) 1204static u16 efuse_get_current_size(struct ieee80211_hw *hw)
1205{ 1205{
1206 int continual = true;
1207 u16 efuse_addr = 0; 1206 u16 efuse_addr = 0;
1208 u8 hworden; 1207 u8 hworden;
1209 u8 efuse_data, word_cnts; 1208 u8 efuse_data, word_cnts;
1210 1209
1211 while (continual && efuse_one_byte_read(hw, efuse_addr, &efuse_data) 1210 while (efuse_one_byte_read(hw, efuse_addr, &efuse_data) &&
1212 && (efuse_addr < EFUSE_MAX_SIZE)) { 1211 efuse_addr < EFUSE_MAX_SIZE) {
1213 if (efuse_data != 0xFF) { 1212 if (efuse_data == 0xFF)
1214 hworden = efuse_data & 0x0F; 1213 break;
1215 word_cnts = efuse_calculate_word_cnts(hworden); 1214
1216 efuse_addr = efuse_addr + (word_cnts * 2) + 1; 1215 hworden = efuse_data & 0x0F;
1217 } else { 1216 word_cnts = efuse_calculate_word_cnts(hworden);
1218 continual = false; 1217 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
1219 }
1220 } 1218 }
1221 1219
1222 return efuse_addr; 1220 return efuse_addr;
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 703f839af6ca..0f494444bcd1 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -736,7 +736,6 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
736 736
737 struct rtl_stats stats = { 737 struct rtl_stats stats = {
738 .signal = 0, 738 .signal = 0,
739 .noise = -98,
740 .rate = 0, 739 .rate = 0,
741 }; 740 };
742 int index = rtlpci->rx_ring[rx_queue_idx].idx; 741 int index = rtlpci->rx_ring[rx_queue_idx].idx;
@@ -2009,7 +2008,6 @@ fail2:
2009fail1: 2008fail1:
2010 if (hw) 2009 if (hw)
2011 ieee80211_free_hw(hw); 2010 ieee80211_free_hw(hw);
2012 pci_set_drvdata(pdev, NULL);
2013 pci_disable_device(pdev); 2011 pci_disable_device(pdev);
2014 2012
2015 return err; 2013 return err;
@@ -2064,8 +2062,6 @@ void rtl_pci_disconnect(struct pci_dev *pdev)
2064 2062
2065 rtl_pci_disable_aspm(hw); 2063 rtl_pci_disable_aspm(hw);
2066 2064
2067 pci_set_drvdata(pdev, NULL);
2068
2069 ieee80211_free_hw(hw); 2065 ieee80211_free_hw(hw);
2070} 2066}
2071EXPORT_SYMBOL(rtl_pci_disconnect); 2067EXPORT_SYMBOL(rtl_pci_disconnect);
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/hw.c b/drivers/net/wireless/rtlwifi/rtl8188ee/hw.c
index b68cae3024fc..e06971be7df7 100644
--- a/drivers/net/wireless/rtlwifi/rtl8188ee/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8188ee/hw.c
@@ -143,6 +143,7 @@ static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw *hw,
143 } else { 143 } else {
144 rtlhal->fw_clk_change_in_progress = false; 144 rtlhal->fw_clk_change_in_progress = false;
145 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); 145 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
146 break;
146 } 147 }
147 } 148 }
148 149
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/phy.c b/drivers/net/wireless/rtlwifi/rtl8188ee/phy.c
index e655c0473225..d67f9c731cc4 100644
--- a/drivers/net/wireless/rtlwifi/rtl8188ee/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8188ee/phy.c
@@ -1136,34 +1136,6 @@ void rtl88e_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
1136 &bw40_pwr[0], channel); 1136 &bw40_pwr[0], channel);
1137} 1137}
1138 1138
1139void rtl88e_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1140{
1141 struct rtl_priv *rtlpriv = rtl_priv(hw);
1142 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1143 enum io_type iotype;
1144
1145 if (!is_hal_stop(rtlhal)) {
1146 switch (operation) {
1147 case SCAN_OPT_BACKUP:
1148 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
1149 rtlpriv->cfg->ops->set_hw_reg(hw,
1150 HW_VAR_IO_CMD,
1151 (u8 *)&iotype);
1152 break;
1153 case SCAN_OPT_RESTORE:
1154 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1155 rtlpriv->cfg->ops->set_hw_reg(hw,
1156 HW_VAR_IO_CMD,
1157 (u8 *)&iotype);
1158 break;
1159 default:
1160 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1161 "Unknown Scan Backup operation.\n");
1162 break;
1163 }
1164 }
1165}
1166
1167void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw *hw) 1139void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
1168{ 1140{
1169 struct rtl_priv *rtlpriv = rtl_priv(hw); 1141 struct rtl_priv *rtlpriv = rtl_priv(hw);
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/phy.h b/drivers/net/wireless/rtlwifi/rtl8188ee/phy.h
index 71ddf4f3f6cc..89f0f1ef1465 100644
--- a/drivers/net/wireless/rtlwifi/rtl8188ee/phy.h
+++ b/drivers/net/wireless/rtlwifi/rtl8188ee/phy.h
@@ -200,20 +200,23 @@ enum _ANT_DIV_TYPE {
200 CGCS_RX_SW_ANTDIV = 0x05, 200 CGCS_RX_SW_ANTDIV = 0x05,
201}; 201};
202 202
203u32 rtl88e_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask); 203u32 rtl88e_phy_query_bb_reg(struct ieee80211_hw *hw,
204void rtl88e_phy_set_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask,
205 u32 data);
206u32 rtl88e_phy_query_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath,
207 u32 regaddr, u32 bitmask); 204 u32 regaddr, u32 bitmask);
208void rtl88e_phy_set_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath, 205void rtl88e_phy_set_bb_reg(struct ieee80211_hw *hw,
209 u32 regaddr, u32 bitmask, u32 data); 206 u32 regaddr, u32 bitmask, u32 data);
207u32 rtl88e_phy_query_rf_reg(struct ieee80211_hw *hw,
208 enum radio_path rfpath, u32 regaddr,
209 u32 bitmask);
210void rtl88e_phy_set_rf_reg(struct ieee80211_hw *hw,
211 enum radio_path rfpath, u32 regaddr,
212 u32 bitmask, u32 data);
210bool rtl88e_phy_mac_config(struct ieee80211_hw *hw); 213bool rtl88e_phy_mac_config(struct ieee80211_hw *hw);
211bool rtl88e_phy_bb_config(struct ieee80211_hw *hw); 214bool rtl88e_phy_bb_config(struct ieee80211_hw *hw);
212bool rtl88e_phy_rf_config(struct ieee80211_hw *hw); 215bool rtl88e_phy_rf_config(struct ieee80211_hw *hw);
213void rtl88e_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw); 216void rtl88e_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw);
214void rtl88e_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel); 217void rtl88e_phy_get_txpower_level(struct ieee80211_hw *hw,
218 long *powerlevel);
215void rtl88e_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 219void rtl88e_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel);
216void rtl88e_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation);
217void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw *hw); 220void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw *hw);
218void rtl88e_phy_set_bw_mode(struct ieee80211_hw *hw, 221void rtl88e_phy_set_bw_mode(struct ieee80211_hw *hw,
219 enum nl80211_channel_type ch_type); 222 enum nl80211_channel_type ch_type);
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/sw.c b/drivers/net/wireless/rtlwifi/rtl8188ee/sw.c
index c254693a1e6a..347af1e4f438 100644
--- a/drivers/net/wireless/rtlwifi/rtl8188ee/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8188ee/sw.c
@@ -30,6 +30,7 @@
30#include "../wifi.h" 30#include "../wifi.h"
31#include "../core.h" 31#include "../core.h"
32#include "../pci.h" 32#include "../pci.h"
33#include "../base.h"
33#include "reg.h" 34#include "reg.h"
34#include "def.h" 35#include "def.h"
35#include "phy.h" 36#include "phy.h"
@@ -244,7 +245,7 @@ static struct rtl_hal_ops rtl8188ee_hal_ops = {
244 .set_bw_mode = rtl88e_phy_set_bw_mode, 245 .set_bw_mode = rtl88e_phy_set_bw_mode,
245 .switch_channel = rtl88e_phy_sw_chnl, 246 .switch_channel = rtl88e_phy_sw_chnl,
246 .dm_watchdog = rtl88e_dm_watchdog, 247 .dm_watchdog = rtl88e_dm_watchdog,
247 .scan_operation_backup = rtl88e_phy_scan_operation_backup, 248 .scan_operation_backup = rtl_phy_scan_operation_backup,
248 .set_rf_power_state = rtl88e_phy_set_rf_power_state, 249 .set_rf_power_state = rtl88e_phy_set_rf_power_state,
249 .led_control = rtl88ee_led_control, 250 .led_control = rtl88ee_led_control,
250 .set_desc = rtl88ee_set_desc, 251 .set_desc = rtl88ee_set_desc,
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
index 68685a898257..aece6c9cccf1 100644
--- a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
@@ -478,7 +478,6 @@ bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
478 478
479 /*rx_status->qual = status->signal; */ 479 /*rx_status->qual = status->signal; */
480 rx_status->signal = status->recvsignalpower + 10; 480 rx_status->signal = status->recvsignalpower + 10;
481 /*rx_status->noise = -status->noise; */
482 if (status->packet_report_type == TX_REPORT2) { 481 if (status->packet_report_type == TX_REPORT2) {
483 status->macid_valid_entry[0] = 482 status->macid_valid_entry[0] =
484 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc); 483 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
index d2d57a27a7c1..e9caa5d4cff0 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
@@ -541,29 +541,6 @@ EXPORT_SYMBOL(rtl92c_dm_write_dig);
541 541
542static void rtl92c_dm_pwdb_monitor(struct ieee80211_hw *hw) 542static void rtl92c_dm_pwdb_monitor(struct ieee80211_hw *hw)
543{ 543{
544 struct rtl_priv *rtlpriv = rtl_priv(hw);
545 long tmpentry_max_pwdb = 0, tmpentry_min_pwdb = 0xff;
546
547 u8 h2c_parameter[3] = { 0 };
548
549 return;
550
551 if (tmpentry_max_pwdb != 0) {
552 rtlpriv->dm.entry_max_undec_sm_pwdb = tmpentry_max_pwdb;
553 } else {
554 rtlpriv->dm.entry_max_undec_sm_pwdb = 0;
555 }
556
557 if (tmpentry_min_pwdb != 0xff) {
558 rtlpriv->dm.entry_min_undec_sm_pwdb = tmpentry_min_pwdb;
559 } else {
560 rtlpriv->dm.entry_min_undec_sm_pwdb = 0;
561 }
562
563 h2c_parameter[2] = (u8) (rtlpriv->dm.undec_sm_pwdb & 0xFF);
564 h2c_parameter[0] = 0;
565
566 rtl92c_fill_h2c_cmd(hw, H2C_RSSI_REPORT, 3, h2c_parameter);
567} 544}
568 545
569void rtl92c_dm_init_edca_turbo(struct ieee80211_hw *hw) 546void rtl92c_dm_init_edca_turbo(struct ieee80211_hw *hw)
@@ -673,7 +650,7 @@ static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
673 s8 cck_index = 0; 650 s8 cck_index = 0;
674 int i; 651 int i;
675 bool is2t = IS_92C_SERIAL(rtlhal->version); 652 bool is2t = IS_92C_SERIAL(rtlhal->version);
676 s8 txpwr_level[2] = {0, 0}; 653 s8 txpwr_level[3] = {0, 0, 0};
677 u8 ofdm_min_index = 6, rf; 654 u8 ofdm_min_index = 6, rf;
678 655
679 rtlpriv->dm.txpower_trackinginit = true; 656 rtlpriv->dm.txpower_trackinginit = true;
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
index 246e5352f2e1..0c0e78263a66 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
@@ -592,36 +592,6 @@ long _rtl92c_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
592} 592}
593EXPORT_SYMBOL(_rtl92c_phy_txpwr_idx_to_dbm); 593EXPORT_SYMBOL(_rtl92c_phy_txpwr_idx_to_dbm);
594 594
595void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
596{
597 struct rtl_priv *rtlpriv = rtl_priv(hw);
598 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
599 enum io_type iotype;
600
601 if (!is_hal_stop(rtlhal)) {
602 switch (operation) {
603 case SCAN_OPT_BACKUP:
604 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
605 rtlpriv->cfg->ops->set_hw_reg(hw,
606 HW_VAR_IO_CMD,
607 (u8 *)&iotype);
608
609 break;
610 case SCAN_OPT_RESTORE:
611 iotype = IO_CMD_RESUME_DM_BY_SCAN;
612 rtlpriv->cfg->ops->set_hw_reg(hw,
613 HW_VAR_IO_CMD,
614 (u8 *)&iotype);
615 break;
616 default:
617 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
618 "Unknown Scan Backup operation\n");
619 break;
620 }
621 }
622}
623EXPORT_SYMBOL(rtl92c_phy_scan_operation_backup);
624
625void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw, 595void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
626 enum nl80211_channel_type ch_type) 596 enum nl80211_channel_type ch_type)
627{ 597{
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h
index cec10d696492..e79dabe9ba1d 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h
@@ -39,9 +39,7 @@
39#define RT_CANNOT_IO(hw) false 39#define RT_CANNOT_IO(hw) false
40#define HIGHPOWER_RADIOA_ARRAYLEN 22 40#define HIGHPOWER_RADIOA_ARRAYLEN 22
41 41
42#define IQK_ADDA_REG_NUM 16
43#define MAX_TOLERANCE 5 42#define MAX_TOLERANCE 5
44#define IQK_DELAY_TIME 1
45 43
46#define APK_BB_REG_NUM 5 44#define APK_BB_REG_NUM 5
47#define APK_AFE_REG_NUM 16 45#define APK_AFE_REG_NUM 16
@@ -205,8 +203,6 @@ void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw,
205void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 203void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel);
206bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, 204bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw,
207 long power_indbm); 205 long power_indbm);
208void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw,
209 u8 operation);
210void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw, 206void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
211 enum nl80211_channel_type ch_type); 207 enum nl80211_channel_type ch_type);
212void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw); 208void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
index 3cfa1bb0f476..fa24de43ce79 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
@@ -152,8 +152,6 @@ enum version_8192c {
152#define IS_VENDOR_UMC_A_CUT(version) ((IS_CHIP_VENDOR_UMC(version)) ? \ 152#define IS_VENDOR_UMC_A_CUT(version) ((IS_CHIP_VENDOR_UMC(version)) ? \
153 ((GET_CVID_CUT_VERSION(version)) ? false : true) : false) 153 ((GET_CVID_CUT_VERSION(version)) ? false : true) : false)
154#define IS_CHIP_VER_B(version) ((version & CHIP_VER_B) ? true : false) 154#define IS_CHIP_VER_B(version) ((version & CHIP_VER_B) ? true : false)
155#define IS_VENDOR_UMC_A_CUT(version) ((IS_CHIP_VENDOR_UMC(version)) ? \
156 ((GET_CVID_CUT_VERSION(version)) ? false : true) : false)
157#define IS_92C_SERIAL(version) ((version & CHIP_92C_BITMASK) ? true : false) 155#define IS_92C_SERIAL(version) ((version & CHIP_92C_BITMASK) ? true : false)
158#define IS_CHIP_VENDOR_UMC(version) \ 156#define IS_CHIP_VENDOR_UMC(version) \
159 ((version & CHIP_VENDOR_UMC) ? true : false) 157 ((version & CHIP_VENDOR_UMC) ? true : false)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h b/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h
index f8973e58c173..94486cca4000 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h
@@ -39,9 +39,7 @@
39#define RT_CANNOT_IO(hw) false 39#define RT_CANNOT_IO(hw) false
40#define HIGHPOWER_RADIOA_ARRAYLEN 22 40#define HIGHPOWER_RADIOA_ARRAYLEN 22
41 41
42#define IQK_ADDA_REG_NUM 16
43#define MAX_TOLERANCE 5 42#define MAX_TOLERANCE 5
44#define IQK_DELAY_TIME 1
45 43
46#define APK_BB_REG_NUM 5 44#define APK_BB_REG_NUM 5
47#define APK_AFE_REG_NUM 16 45#define APK_AFE_REG_NUM 16
@@ -203,8 +201,8 @@ bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw,
203void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw); 201void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw);
204void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel); 202void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel);
205void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 203void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel);
206bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, long power_indbm); 204bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw,
207void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation); 205 long power_indbm);
208void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw, 206void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
209 enum nl80211_channel_type ch_type); 207 enum nl80211_channel_type ch_type);
210void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw); 208void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw);
@@ -217,8 +215,8 @@ void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t);
217void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain); 215void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain);
218bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 216bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
219 enum radio_path rfpath); 217 enum radio_path rfpath);
220bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, u32 rfpath); 218bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw,
221bool rtl92c_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype); 219 u32 rfpath);
222bool rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw, 220bool rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
223 enum rf_pwrstate rfpwr_state); 221 enum rf_pwrstate rfpwr_state);
224void rtl92ce_phy_set_rf_on(struct ieee80211_hw *hw); 222void rtl92ce_phy_set_rf_on(struct ieee80211_hw *hw);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h b/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h
index bd4aef74c056..8922ecb47ad2 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h
@@ -560,7 +560,6 @@
560#define EEPROM_DEFAULT_TXPOWERLEVEL 0x22 560#define EEPROM_DEFAULT_TXPOWERLEVEL 0x22
561#define EEPROM_DEFAULT_HT40_2SDIFF 0x0 561#define EEPROM_DEFAULT_HT40_2SDIFF 0x0
562#define EEPROM_DEFAULT_HT20_DIFF 2 562#define EEPROM_DEFAULT_HT20_DIFF 2
563#define EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF 0x3
564#define EEPROM_DEFAULT_HT40_PWRMAXOFFSET 0 563#define EEPROM_DEFAULT_HT40_PWRMAXOFFSET 0
565#define EEPROM_DEFAULT_HT20_PWRMAXOFFSET 0 564#define EEPROM_DEFAULT_HT20_PWRMAXOFFSET 0
566 565
@@ -639,17 +638,8 @@
639 638
640#define EEPROM_TXPWR_GROUP 0x6F 639#define EEPROM_TXPWR_GROUP 0x6F
641 640
642#define EEPROM_TSSI_A 0x76
643#define EEPROM_TSSI_B 0x77
644#define EEPROM_THERMAL_METER 0x78
645
646#define EEPROM_CHANNELPLAN 0x75 641#define EEPROM_CHANNELPLAN 0x75
647 642
648#define RF_OPTION1 0x79
649#define RF_OPTION2 0x7A
650#define RF_OPTION3 0x7B
651#define RF_OPTION4 0x7C
652
653#define STOPBECON BIT(6) 643#define STOPBECON BIT(6)
654#define STOPHIGHT BIT(5) 644#define STOPHIGHT BIT(5)
655#define STOPMGT BIT(4) 645#define STOPMGT BIT(4)
@@ -689,13 +679,6 @@
689#define RSV_CTRL 0x001C 679#define RSV_CTRL 0x001C
690#define RD_CTRL 0x0524 680#define RD_CTRL 0x0524
691 681
692#define REG_USB_INFO 0xFE17
693#define REG_USB_SPECIAL_OPTION 0xFE55
694
695#define REG_USB_DMA_AGG_TO 0xFE5B
696#define REG_USB_AGG_TO 0xFE5C
697#define REG_USB_AGG_TH 0xFE5D
698
699#define REG_USB_VID 0xFE60 682#define REG_USB_VID 0xFE60
700#define REG_USB_PID 0xFE62 683#define REG_USB_PID 0xFE62
701#define REG_USB_OPTIONAL 0xFE64 684#define REG_USB_OPTIONAL 0xFE64
@@ -1196,9 +1179,6 @@
1196#define POLLING_LLT_THRESHOLD 20 1179#define POLLING_LLT_THRESHOLD 20
1197#define POLLING_READY_TIMEOUT_COUNT 1000 1180#define POLLING_READY_TIMEOUT_COUNT 1000
1198 1181
1199#define MAX_MSS_DENSITY_2T 0x13
1200#define MAX_MSS_DENSITY_1T 0x0A
1201
1202#define EPROM_CMD_OPERATING_MODE_MASK ((1<<7)|(1<<6)) 1182#define EPROM_CMD_OPERATING_MODE_MASK ((1<<7)|(1<<6))
1203#define EPROM_CMD_CONFIG 0x3 1183#define EPROM_CMD_CONFIG 0x3
1204#define EPROM_CMD_LOAD 1 1184#define EPROM_CMD_LOAD 1
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
index 14203561b6ee..b790320d2030 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
@@ -30,6 +30,7 @@
30#include "../wifi.h" 30#include "../wifi.h"
31#include "../core.h" 31#include "../core.h"
32#include "../pci.h" 32#include "../pci.h"
33#include "../base.h"
33#include "reg.h" 34#include "reg.h"
34#include "def.h" 35#include "def.h"
35#include "phy.h" 36#include "phy.h"
@@ -219,7 +220,7 @@ static struct rtl_hal_ops rtl8192ce_hal_ops = {
219 .set_bw_mode = rtl92c_phy_set_bw_mode, 220 .set_bw_mode = rtl92c_phy_set_bw_mode,
220 .switch_channel = rtl92c_phy_sw_chnl, 221 .switch_channel = rtl92c_phy_sw_chnl,
221 .dm_watchdog = rtl92c_dm_watchdog, 222 .dm_watchdog = rtl92c_dm_watchdog,
222 .scan_operation_backup = rtl92c_phy_scan_operation_backup, 223 .scan_operation_backup = rtl_phy_scan_operation_backup,
223 .set_rf_power_state = rtl92c_phy_set_rf_power_state, 224 .set_rf_power_state = rtl92c_phy_set_rf_power_state,
224 .led_control = rtl92ce_led_control, 225 .led_control = rtl92ce_led_control,
225 .set_desc = rtl92ce_set_desc, 226 .set_desc = rtl92ce_set_desc,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
index 6ad23b413eb3..52abf0a862fa 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
@@ -420,7 +420,6 @@ bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw,
420 420
421 /*rx_status->qual = stats->signal; */ 421 /*rx_status->qual = stats->signal; */
422 rx_status->signal = stats->recvsignalpower + 10; 422 rx_status->signal = stats->recvsignalpower + 10;
423 /*rx_status->noise = -stats->noise; */
424 423
425 return true; 424 return true;
426} 425}
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/mac.c b/drivers/net/wireless/rtlwifi/rtl8192cu/mac.c
index da4f587199ee..393685390f3e 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/mac.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/mac.c
@@ -32,6 +32,7 @@
32#include "../usb.h" 32#include "../usb.h"
33#include "../ps.h" 33#include "../ps.h"
34#include "../cam.h" 34#include "../cam.h"
35#include "../stats.h"
35#include "reg.h" 36#include "reg.h"
36#include "def.h" 37#include "def.h"
37#include "phy.h" 38#include "phy.h"
@@ -738,16 +739,6 @@ static u8 _rtl92c_evm_db_to_percentage(char value)
738 return ret_val; 739 return ret_val;
739} 740}
740 741
741static long _rtl92c_translate_todbm(struct ieee80211_hw *hw,
742 u8 signal_strength_index)
743{
744 long signal_power;
745
746 signal_power = (long)((signal_strength_index + 1) >> 1);
747 signal_power -= 95;
748 return signal_power;
749}
750
751static long _rtl92c_signal_scale_mapping(struct ieee80211_hw *hw, 742static long _rtl92c_signal_scale_mapping(struct ieee80211_hw *hw,
752 long currsig) 743 long currsig)
753{ 744{
@@ -913,180 +904,6 @@ static void _rtl92c_query_rxphystatus(struct ieee80211_hw *hw,
913 (hw, total_rssi /= rf_rx_num)); 904 (hw, total_rssi /= rf_rx_num));
914} 905}
915 906
916static void _rtl92c_process_ui_rssi(struct ieee80211_hw *hw,
917 struct rtl_stats *pstats)
918{
919 struct rtl_priv *rtlpriv = rtl_priv(hw);
920 struct rtl_phy *rtlphy = &(rtlpriv->phy);
921 u8 rfpath;
922 u32 last_rssi, tmpval;
923
924 if (pstats->packet_toself || pstats->packet_beacon) {
925 rtlpriv->stats.rssi_calculate_cnt++;
926 if (rtlpriv->stats.ui_rssi.total_num++ >=
927 PHY_RSSI_SLID_WIN_MAX) {
928 rtlpriv->stats.ui_rssi.total_num =
929 PHY_RSSI_SLID_WIN_MAX;
930 last_rssi =
931 rtlpriv->stats.ui_rssi.elements[rtlpriv->
932 stats.ui_rssi.index];
933 rtlpriv->stats.ui_rssi.total_val -= last_rssi;
934 }
935 rtlpriv->stats.ui_rssi.total_val += pstats->signalstrength;
936 rtlpriv->stats.ui_rssi.elements[rtlpriv->stats.ui_rssi.
937 index++] = pstats->signalstrength;
938 if (rtlpriv->stats.ui_rssi.index >= PHY_RSSI_SLID_WIN_MAX)
939 rtlpriv->stats.ui_rssi.index = 0;
940 tmpval = rtlpriv->stats.ui_rssi.total_val /
941 rtlpriv->stats.ui_rssi.total_num;
942 rtlpriv->stats.signal_strength =
943 _rtl92c_translate_todbm(hw, (u8) tmpval);
944 pstats->rssi = rtlpriv->stats.signal_strength;
945 }
946 if (!pstats->is_cck && pstats->packet_toself) {
947 for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath;
948 rfpath++) {
949 if (!rtl8192_phy_check_is_legal_rfpath(hw, rfpath))
950 continue;
951 if (rtlpriv->stats.rx_rssi_percentage[rfpath] == 0) {
952 rtlpriv->stats.rx_rssi_percentage[rfpath] =
953 pstats->rx_mimo_signalstrength[rfpath];
954 }
955 if (pstats->rx_mimo_signalstrength[rfpath] >
956 rtlpriv->stats.rx_rssi_percentage[rfpath]) {
957 rtlpriv->stats.rx_rssi_percentage[rfpath] =
958 ((rtlpriv->stats.
959 rx_rssi_percentage[rfpath] *
960 (RX_SMOOTH_FACTOR - 1)) +
961 (pstats->rx_mimo_signalstrength[rfpath])) /
962 (RX_SMOOTH_FACTOR);
963
964 rtlpriv->stats.rx_rssi_percentage[rfpath] =
965 rtlpriv->stats.rx_rssi_percentage[rfpath] +
966 1;
967 } else {
968 rtlpriv->stats.rx_rssi_percentage[rfpath] =
969 ((rtlpriv->stats.
970 rx_rssi_percentage[rfpath] *
971 (RX_SMOOTH_FACTOR - 1)) +
972 (pstats->rx_mimo_signalstrength[rfpath])) /
973 (RX_SMOOTH_FACTOR);
974 }
975 }
976 }
977}
978
979static void _rtl92c_update_rxsignalstatistics(struct ieee80211_hw *hw,
980 struct rtl_stats *pstats)
981{
982 struct rtl_priv *rtlpriv = rtl_priv(hw);
983 int weighting = 0;
984
985 if (rtlpriv->stats.recv_signal_power == 0)
986 rtlpriv->stats.recv_signal_power = pstats->recvsignalpower;
987 if (pstats->recvsignalpower > rtlpriv->stats.recv_signal_power)
988 weighting = 5;
989 else if (pstats->recvsignalpower < rtlpriv->stats.recv_signal_power)
990 weighting = (-5);
991 rtlpriv->stats.recv_signal_power =
992 (rtlpriv->stats.recv_signal_power * 5 +
993 pstats->recvsignalpower + weighting) / 6;
994}
995
996static void _rtl92c_process_pwdb(struct ieee80211_hw *hw,
997 struct rtl_stats *pstats)
998{
999 struct rtl_priv *rtlpriv = rtl_priv(hw);
1000 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1001 long undec_sm_pwdb = 0;
1002
1003 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
1004 return;
1005 } else {
1006 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
1007 }
1008 if (pstats->packet_toself || pstats->packet_beacon) {
1009 if (undec_sm_pwdb < 0)
1010 undec_sm_pwdb = pstats->rx_pwdb_all;
1011 if (pstats->rx_pwdb_all > (u32) undec_sm_pwdb) {
1012 undec_sm_pwdb = (((undec_sm_pwdb) *
1013 (RX_SMOOTH_FACTOR - 1)) +
1014 (pstats->rx_pwdb_all)) / (RX_SMOOTH_FACTOR);
1015 undec_sm_pwdb += 1;
1016 } else {
1017 undec_sm_pwdb = (((undec_sm_pwdb) *
1018 (RX_SMOOTH_FACTOR - 1)) +
1019 (pstats->rx_pwdb_all)) / (RX_SMOOTH_FACTOR);
1020 }
1021 rtlpriv->dm.undec_sm_pwdb = undec_sm_pwdb;
1022 _rtl92c_update_rxsignalstatistics(hw, pstats);
1023 }
1024}
1025
1026static void _rtl92c_process_LINK_Q(struct ieee80211_hw *hw,
1027 struct rtl_stats *pstats)
1028{
1029 struct rtl_priv *rtlpriv = rtl_priv(hw);
1030 u32 last_evm = 0, n_stream, tmpval;
1031
1032 if (pstats->signalquality != 0) {
1033 if (pstats->packet_toself || pstats->packet_beacon) {
1034 if (rtlpriv->stats.LINK_Q.total_num++ >=
1035 PHY_LINKQUALITY_SLID_WIN_MAX) {
1036 rtlpriv->stats.LINK_Q.total_num =
1037 PHY_LINKQUALITY_SLID_WIN_MAX;
1038 last_evm =
1039 rtlpriv->stats.LINK_Q.elements
1040 [rtlpriv->stats.LINK_Q.index];
1041 rtlpriv->stats.LINK_Q.total_val -=
1042 last_evm;
1043 }
1044 rtlpriv->stats.LINK_Q.total_val +=
1045 pstats->signalquality;
1046 rtlpriv->stats.LINK_Q.elements
1047 [rtlpriv->stats.LINK_Q.index++] =
1048 pstats->signalquality;
1049 if (rtlpriv->stats.LINK_Q.index >=
1050 PHY_LINKQUALITY_SLID_WIN_MAX)
1051 rtlpriv->stats.LINK_Q.index = 0;
1052 tmpval = rtlpriv->stats.LINK_Q.total_val /
1053 rtlpriv->stats.LINK_Q.total_num;
1054 rtlpriv->stats.signal_quality = tmpval;
1055 rtlpriv->stats.last_sigstrength_inpercent = tmpval;
1056 for (n_stream = 0; n_stream < 2;
1057 n_stream++) {
1058 if (pstats->RX_SIGQ[n_stream] != -1) {
1059 if (!rtlpriv->stats.RX_EVM[n_stream]) {
1060 rtlpriv->stats.RX_EVM[n_stream]
1061 = pstats->RX_SIGQ[n_stream];
1062 }
1063 rtlpriv->stats.RX_EVM[n_stream] =
1064 ((rtlpriv->stats.RX_EVM
1065 [n_stream] *
1066 (RX_SMOOTH_FACTOR - 1)) +
1067 (pstats->RX_SIGQ
1068 [n_stream] * 1)) /
1069 (RX_SMOOTH_FACTOR);
1070 }
1071 }
1072 }
1073 } else {
1074 ;
1075 }
1076}
1077
1078static void _rtl92c_process_phyinfo(struct ieee80211_hw *hw,
1079 u8 *buffer,
1080 struct rtl_stats *pcurrent_stats)
1081{
1082 if (!pcurrent_stats->packet_matchbssid &&
1083 !pcurrent_stats->packet_beacon)
1084 return;
1085 _rtl92c_process_ui_rssi(hw, pcurrent_stats);
1086 _rtl92c_process_pwdb(hw, pcurrent_stats);
1087 _rtl92c_process_LINK_Q(hw, pcurrent_stats);
1088}
1089
1090void rtl92c_translate_rx_signal_stuff(struct ieee80211_hw *hw, 907void rtl92c_translate_rx_signal_stuff(struct ieee80211_hw *hw,
1091 struct sk_buff *skb, 908 struct sk_buff *skb,
1092 struct rtl_stats *pstats, 909 struct rtl_stats *pstats,
@@ -1123,5 +940,5 @@ void rtl92c_translate_rx_signal_stuff(struct ieee80211_hw *hw,
1123 _rtl92c_query_rxphystatus(hw, pstats, pdesc, p_drvinfo, 940 _rtl92c_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
1124 packet_matchbssid, packet_toself, 941 packet_matchbssid, packet_toself,
1125 packet_beacon); 942 packet_beacon);
1126 _rtl92c_process_phyinfo(hw, tmp_buf, pstats); 943 rtl_process_phyinfo(hw, tmp_buf, pstats);
1127} 944}
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
index 2bd598526217..9936de716ad5 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
@@ -31,6 +31,7 @@
31#include "../core.h" 31#include "../core.h"
32#include "../usb.h" 32#include "../usb.h"
33#include "../efuse.h" 33#include "../efuse.h"
34#include "../base.h"
34#include "reg.h" 35#include "reg.h"
35#include "def.h" 36#include "def.h"
36#include "phy.h" 37#include "phy.h"
@@ -117,7 +118,7 @@ static struct rtl_hal_ops rtl8192cu_hal_ops = {
117 .set_bw_mode = rtl92c_phy_set_bw_mode, 118 .set_bw_mode = rtl92c_phy_set_bw_mode,
118 .switch_channel = rtl92c_phy_sw_chnl, 119 .switch_channel = rtl92c_phy_sw_chnl,
119 .dm_watchdog = rtl92c_dm_watchdog, 120 .dm_watchdog = rtl92c_dm_watchdog,
120 .scan_operation_backup = rtl92c_phy_scan_operation_backup, 121 .scan_operation_backup = rtl_phy_scan_operation_backup,
121 .set_rf_power_state = rtl92cu_phy_set_rf_power_state, 122 .set_rf_power_state = rtl92cu_phy_set_rf_power_state,
122 .led_control = rtl92cu_led_control, 123 .led_control = rtl92cu_led_control,
123 .enable_hw_sec = rtl92cu_enable_hw_security_config, 124 .enable_hw_sec = rtl92cu_enable_hw_security_config,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
index 763cf1defab5..04c7e57dbce2 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
@@ -349,7 +349,6 @@ bool rtl92cu_rx_query_desc(struct ieee80211_hw *hw,
349 } 349 }
350 /*rx_status->qual = stats->signal; */ 350 /*rx_status->qual = stats->signal; */
351 rx_status->signal = stats->rssi + 10; 351 rx_status->signal = stats->rssi + 10;
352 /*rx_status->noise = -stats->noise; */
353 return true; 352 return true;
354} 353}
355 354
@@ -364,7 +363,6 @@ static void _rtl_rx_process(struct ieee80211_hw *hw, struct sk_buff *skb)
364 u8 *rxdesc; 363 u8 *rxdesc;
365 struct rtl_stats stats = { 364 struct rtl_stats stats = {
366 .signal = 0, 365 .signal = 0,
367 .noise = -98,
368 .rate = 0, 366 .rate = 0,
369 }; 367 };
370 struct rx_fwinfo_92c *p_drvinfo; 368 struct rx_fwinfo_92c *p_drvinfo;
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/dm.c b/drivers/net/wireless/rtlwifi/rtl8192de/dm.c
index f700f7a614b2..7908e1c85819 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/dm.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/dm.c
@@ -840,9 +840,9 @@ static void rtl92d_dm_txpower_tracking_callback_thermalmeter(
840 bool internal_pa = false; 840 bool internal_pa = false;
841 long ele_a = 0, ele_d, temp_cck, val_x, value32; 841 long ele_a = 0, ele_d, temp_cck, val_x, value32;
842 long val_y, ele_c = 0; 842 long val_y, ele_c = 0;
843 u8 ofdm_index[2]; 843 u8 ofdm_index[3];
844 s8 cck_index = 0; 844 s8 cck_index = 0;
845 u8 ofdm_index_old[2] = {0, 0}; 845 u8 ofdm_index_old[3] = {0, 0, 0};
846 s8 cck_index_old = 0; 846 s8 cck_index_old = 0;
847 u8 index; 847 u8 index;
848 int i; 848 int i;
@@ -1118,6 +1118,10 @@ static void rtl92d_dm_txpower_tracking_callback_thermalmeter(
1118 val_x, val_y, ele_a, ele_c, ele_d, 1118 val_x, val_y, ele_a, ele_c, ele_d,
1119 val_x, val_y); 1119 val_x, val_y);
1120 1120
1121 if (cck_index >= CCK_TABLE_SIZE)
1122 cck_index = CCK_TABLE_SIZE - 1;
1123 if (cck_index < 0)
1124 cck_index = 0;
1121 if (rtlhal->current_bandtype == BAND_ON_2_4G) { 1125 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
1122 /* Adjust CCK according to IQK result */ 1126 /* Adjust CCK according to IQK result */
1123 if (!rtlpriv->dm.cck_inch14) { 1127 if (!rtlpriv->dm.cck_inch14) {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/hw.c b/drivers/net/wireless/rtlwifi/rtl8192de/hw.c
index 7dd8f6de0550..c4a7db9135d6 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/hw.c
@@ -1194,25 +1194,7 @@ void rtl92d_linked_set_reg(struct ieee80211_hw *hw)
1194 * mac80211 will send pkt when scan */ 1194 * mac80211 will send pkt when scan */
1195void rtl92de_set_qos(struct ieee80211_hw *hw, int aci) 1195void rtl92de_set_qos(struct ieee80211_hw *hw, int aci)
1196{ 1196{
1197 struct rtl_priv *rtlpriv = rtl_priv(hw);
1198 rtl92d_dm_init_edca_turbo(hw); 1197 rtl92d_dm_init_edca_turbo(hw);
1199 return;
1200 switch (aci) {
1201 case AC1_BK:
1202 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
1203 break;
1204 case AC0_BE:
1205 break;
1206 case AC2_VI:
1207 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
1208 break;
1209 case AC3_VO:
1210 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
1211 break;
1212 default:
1213 RT_ASSERT(false, "invalid aci: %d !\n", aci);
1214 break;
1215 }
1216} 1198}
1217 1199
1218void rtl92de_enable_interrupt(struct ieee80211_hw *hw) 1200void rtl92de_enable_interrupt(struct ieee80211_hw *hw)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/rtlwifi/rtl8192de/phy.c
index 840bac5fa2f8..13196cc4b1d3 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/phy.c
@@ -1022,34 +1022,6 @@ void rtl92d_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
1022 rtl92d_phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0], channel); 1022 rtl92d_phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0], channel);
1023} 1023}
1024 1024
1025void rtl92d_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1026{
1027 struct rtl_priv *rtlpriv = rtl_priv(hw);
1028 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1029 enum io_type iotype;
1030
1031 if (!is_hal_stop(rtlhal)) {
1032 switch (operation) {
1033 case SCAN_OPT_BACKUP:
1034 rtlhal->current_bandtypebackup =
1035 rtlhal->current_bandtype;
1036 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
1037 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
1038 (u8 *)&iotype);
1039 break;
1040 case SCAN_OPT_RESTORE:
1041 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1042 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
1043 (u8 *)&iotype);
1044 break;
1045 default:
1046 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1047 "Unknown Scan Backup operation\n");
1048 break;
1049 }
1050 }
1051}
1052
1053void rtl92d_phy_set_bw_mode(struct ieee80211_hw *hw, 1025void rtl92d_phy_set_bw_mode(struct ieee80211_hw *hw,
1054 enum nl80211_channel_type ch_type) 1026 enum nl80211_channel_type ch_type)
1055{ 1027{
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/phy.h b/drivers/net/wireless/rtlwifi/rtl8192de/phy.h
index 0f993f451cdb..48d5c6835b6a 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/phy.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/phy.h
@@ -39,9 +39,7 @@
39#define RT_CANNOT_IO(hw) false 39#define RT_CANNOT_IO(hw) false
40#define HIGHPOWER_RADIOA_ARRAYLEN 22 40#define HIGHPOWER_RADIOA_ARRAYLEN 22
41 41
42#define IQK_ADDA_REG_NUM 16
43#define MAX_TOLERANCE 5 42#define MAX_TOLERANCE 5
44#define IQK_DELAY_TIME 1
45 43
46#define APK_BB_REG_NUM 5 44#define APK_BB_REG_NUM 5
47#define APK_AFE_REG_NUM 16 45#define APK_AFE_REG_NUM 16
@@ -127,13 +125,16 @@ static inline void rtl92d_release_cckandrw_pagea_ctl(struct ieee80211_hw *hw,
127 *flag); 125 *flag);
128} 126}
129 127
130u32 rtl92d_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask); 128u32 rtl92d_phy_query_bb_reg(struct ieee80211_hw *hw,
131void rtl92d_phy_set_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask,
132 u32 data);
133u32 rtl92d_phy_query_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath,
134 u32 regaddr, u32 bitmask); 129 u32 regaddr, u32 bitmask);
135void rtl92d_phy_set_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath, 130void rtl92d_phy_set_bb_reg(struct ieee80211_hw *hw,
136 u32 regaddr, u32 bitmask, u32 data); 131 u32 regaddr, u32 bitmask, u32 data);
132u32 rtl92d_phy_query_rf_reg(struct ieee80211_hw *hw,
133 enum radio_path rfpath, u32 regaddr,
134 u32 bitmask);
135void rtl92d_phy_set_rf_reg(struct ieee80211_hw *hw,
136 enum radio_path rfpath, u32 regaddr,
137 u32 bitmask, u32 data);
137bool rtl92d_phy_mac_config(struct ieee80211_hw *hw); 138bool rtl92d_phy_mac_config(struct ieee80211_hw *hw);
138bool rtl92d_phy_bb_config(struct ieee80211_hw *hw); 139bool rtl92d_phy_bb_config(struct ieee80211_hw *hw);
139bool rtl92d_phy_rf_config(struct ieee80211_hw *hw); 140bool rtl92d_phy_rf_config(struct ieee80211_hw *hw);
@@ -141,7 +142,6 @@ bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw,
141 enum radio_path rfpath); 142 enum radio_path rfpath);
142void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw); 143void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw);
143void rtl92d_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 144void rtl92d_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel);
144void rtl92d_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation);
145void rtl92d_phy_set_bw_mode(struct ieee80211_hw *hw, 145void rtl92d_phy_set_bw_mode(struct ieee80211_hw *hw,
146 enum nl80211_channel_type ch_type); 146 enum nl80211_channel_type ch_type);
147u8 rtl92d_phy_sw_chnl(struct ieee80211_hw *hw); 147u8 rtl92d_phy_sw_chnl(struct ieee80211_hw *hw);
@@ -169,6 +169,5 @@ void rtl92d_acquire_cckandrw_pagea_ctl(struct ieee80211_hw *hw,
169 unsigned long *flag); 169 unsigned long *flag);
170u8 rtl92d_get_rightchnlplace_for_iqk(u8 chnl); 170u8 rtl92d_get_rightchnlplace_for_iqk(u8 chnl);
171void rtl92d_phy_reload_iqk_setting(struct ieee80211_hw *hw, u8 channel); 171void rtl92d_phy_reload_iqk_setting(struct ieee80211_hw *hw, u8 channel);
172void rtl92d_phy_iq_calibrate(struct ieee80211_hw *hw);
173 172
174#endif 173#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/sw.c b/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
index c18c04bf0c13..edab5a5351b5 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
@@ -30,6 +30,7 @@
30#include "../wifi.h" 30#include "../wifi.h"
31#include "../core.h" 31#include "../core.h"
32#include "../pci.h" 32#include "../pci.h"
33#include "../base.h"
33#include "reg.h" 34#include "reg.h"
34#include "def.h" 35#include "def.h"
35#include "phy.h" 36#include "phy.h"
@@ -236,7 +237,7 @@ static struct rtl_hal_ops rtl8192de_hal_ops = {
236 .set_bw_mode = rtl92d_phy_set_bw_mode, 237 .set_bw_mode = rtl92d_phy_set_bw_mode,
237 .switch_channel = rtl92d_phy_sw_chnl, 238 .switch_channel = rtl92d_phy_sw_chnl,
238 .dm_watchdog = rtl92d_dm_watchdog, 239 .dm_watchdog = rtl92d_dm_watchdog,
239 .scan_operation_backup = rtl92d_phy_scan_operation_backup, 240 .scan_operation_backup = rtl_phy_scan_operation_backup,
240 .set_rf_power_state = rtl92d_phy_set_rf_power_state, 241 .set_rf_power_state = rtl92d_phy_set_rf_power_state,
241 .led_control = rtl92de_led_control, 242 .led_control = rtl92de_led_control,
242 .set_desc = rtl92de_set_desc, 243 .set_desc = rtl92de_set_desc,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/trx.c b/drivers/net/wireless/rtlwifi/rtl8192de/trx.c
index b8ec718a0fab..945ddecf90c9 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/trx.c
@@ -526,7 +526,6 @@ bool rtl92de_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
526 } 526 }
527 /*rx_status->qual = stats->signal; */ 527 /*rx_status->qual = stats->signal; */
528 rx_status->signal = stats->rssi + 10; 528 rx_status->signal = stats->rssi + 10;
529 /*rx_status->noise = -stats->noise; */
530 return true; 529 return true;
531} 530}
532 531
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/reg.h b/drivers/net/wireless/rtlwifi/rtl8192se/reg.h
index 84d1181795b8..c81c83591940 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/reg.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/reg.h
@@ -425,14 +425,9 @@
425#define EXT_IMEM_CODE_DONE BIT(2) 425#define EXT_IMEM_CODE_DONE BIT(2)
426#define IMEM_CHK_RPT BIT(1) 426#define IMEM_CHK_RPT BIT(1)
427#define IMEM_CODE_DONE BIT(0) 427#define IMEM_CODE_DONE BIT(0)
428#define IMEM_CODE_DONE BIT(0)
429#define IMEM_CHK_RPT BIT(1)
430#define EMEM_CODE_DONE BIT(2) 428#define EMEM_CODE_DONE BIT(2)
431#define EMEM_CHK_RPT BIT(3) 429#define EMEM_CHK_RPT BIT(3)
432#define DMEM_CODE_DONE BIT(4)
433#define IMEM_RDY BIT(5) 430#define IMEM_RDY BIT(5)
434#define BASECHG BIT(6)
435#define FWRDY BIT(7)
436#define LOAD_FW_READY (IMEM_CODE_DONE | \ 431#define LOAD_FW_READY (IMEM_CODE_DONE | \
437 IMEM_CHK_RPT | \ 432 IMEM_CHK_RPT | \
438 EMEM_CODE_DONE | \ 433 EMEM_CODE_DONE | \
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/trx.c b/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
index c7095118de6e..222d2e792ca6 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
@@ -330,7 +330,6 @@ bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
330 330
331 /*rx_status->qual = stats->signal; */ 331 /*rx_status->qual = stats->signal; */
332 rx_status->signal = stats->rssi + 10; 332 rx_status->signal = stats->rssi + 10;
333 /*rx_status->noise = -stats->noise; */
334 333
335 return true; 334 return true;
336} 335}
diff --git a/drivers/net/wireless/rtlwifi/rtl8723ae/phy.c b/drivers/net/wireless/rtlwifi/rtl8723ae/phy.c
index eafbb18dd48e..5d318a85eda4 100644
--- a/drivers/net/wireless/rtlwifi/rtl8723ae/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8723ae/phy.c
@@ -934,35 +934,6 @@ static long _phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
934 return pwrout_dbm; 934 return pwrout_dbm;
935} 935}
936 936
937void rtl8723ae_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
938{
939 struct rtl_priv *rtlpriv = rtl_priv(hw);
940 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
941 enum io_type iotype;
942
943 if (!is_hal_stop(rtlhal)) {
944 switch (operation) {
945 case SCAN_OPT_BACKUP:
946 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
947 rtlpriv->cfg->ops->set_hw_reg(hw,
948 HW_VAR_IO_CMD,
949 (u8 *)&iotype);
950
951 break;
952 case SCAN_OPT_RESTORE:
953 iotype = IO_CMD_RESUME_DM_BY_SCAN;
954 rtlpriv->cfg->ops->set_hw_reg(hw,
955 HW_VAR_IO_CMD,
956 (u8 *)&iotype);
957 break;
958 default:
959 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
960 "Unknown Scan Backup operation.\n");
961 break;
962 }
963 }
964}
965
966void rtl8723ae_phy_set_bw_mode_callback(struct ieee80211_hw *hw) 937void rtl8723ae_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
967{ 938{
968 struct rtl_priv *rtlpriv = rtl_priv(hw); 939 struct rtl_priv *rtlpriv = rtl_priv(hw);
diff --git a/drivers/net/wireless/rtlwifi/rtl8723ae/phy.h b/drivers/net/wireless/rtlwifi/rtl8723ae/phy.h
index bbb950dac5ba..007ebdbbe108 100644
--- a/drivers/net/wireless/rtlwifi/rtl8723ae/phy.h
+++ b/drivers/net/wireless/rtlwifi/rtl8723ae/phy.h
@@ -183,27 +183,28 @@ struct tx_power_struct {
183 u32 mcs_original_offset[4][16]; 183 u32 mcs_original_offset[4][16];
184}; 184};
185 185
186u32 rtl8723ae_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, 186u32 rtl8723ae_phy_query_bb_reg(struct ieee80211_hw *hw,
187 u32 bitmask); 187 u32 regaddr, u32 bitmask);
188void rtl8723ae_phy_set_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask, 188void rtl8723ae_phy_set_bb_reg(struct ieee80211_hw *hw,
189 u32 data); 189 u32 regaddr, u32 bitmask, u32 data);
190u32 rtl8723ae_phy_query_rf_reg(struct ieee80211_hw *hw, 190u32 rtl8723ae_phy_query_rf_reg(struct ieee80211_hw *hw,
191 enum radio_path rfpath, u32 regaddr, 191 enum radio_path rfpath, u32 regaddr,
192 u32 bitmask); 192 u32 bitmask);
193void rtl8723ae_phy_set_rf_reg(struct ieee80211_hw *hw, 193void rtl8723ae_phy_set_rf_reg(struct ieee80211_hw *hw,
194 enum radio_path rfpath, u32 regaddr, u32 bitmask, 194 enum radio_path rfpath, u32 regaddr,
195 u32 data); 195 u32 bitmask, u32 data);
196bool rtl8723ae_phy_mac_config(struct ieee80211_hw *hw); 196bool rtl8723ae_phy_mac_config(struct ieee80211_hw *hw);
197bool rtl8723ae_phy_bb_config(struct ieee80211_hw *hw); 197bool rtl8723ae_phy_bb_config(struct ieee80211_hw *hw);
198bool rtl8723ae_phy_rf_config(struct ieee80211_hw *hw); 198bool rtl8723ae_phy_rf_config(struct ieee80211_hw *hw);
199bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw, 199bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw,
200 enum radio_path rfpath); 200 enum radio_path rfpath);
201void rtl8723ae_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw); 201void rtl8723ae_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw);
202void rtl8723ae_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel); 202void rtl8723ae_phy_get_txpower_level(struct ieee80211_hw *hw,
203void rtl8723ae_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 203 long *powerlevel);
204void rtl8723ae_phy_set_txpower_level(struct ieee80211_hw *hw,
205 u8 channel);
204bool rtl8723ae_phy_update_txpower_dbm(struct ieee80211_hw *hw, 206bool rtl8723ae_phy_update_txpower_dbm(struct ieee80211_hw *hw,
205 long power_indbm); 207 long power_indbm);
206void rtl8723ae_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation);
207void rtl8723ae_phy_set_bw_mode_callback(struct ieee80211_hw *hw); 208void rtl8723ae_phy_set_bw_mode_callback(struct ieee80211_hw *hw);
208void rtl8723ae_phy_set_bw_mode(struct ieee80211_hw *hw, 209void rtl8723ae_phy_set_bw_mode(struct ieee80211_hw *hw,
209 enum nl80211_channel_type ch_type); 210 enum nl80211_channel_type ch_type);
diff --git a/drivers/net/wireless/rtlwifi/rtl8723ae/sw.c b/drivers/net/wireless/rtlwifi/rtl8723ae/sw.c
index d9ee2efffe5f..62b204faf773 100644
--- a/drivers/net/wireless/rtlwifi/rtl8723ae/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8723ae/sw.c
@@ -33,6 +33,7 @@
33 33
34#include "../core.h" 34#include "../core.h"
35#include "../pci.h" 35#include "../pci.h"
36#include "../base.h"
36#include "reg.h" 37#include "reg.h"
37#include "def.h" 38#include "def.h"
38#include "phy.h" 39#include "phy.h"
@@ -220,7 +221,7 @@ static struct rtl_hal_ops rtl8723ae_hal_ops = {
220 .set_bw_mode = rtl8723ae_phy_set_bw_mode, 221 .set_bw_mode = rtl8723ae_phy_set_bw_mode,
221 .switch_channel = rtl8723ae_phy_sw_chnl, 222 .switch_channel = rtl8723ae_phy_sw_chnl,
222 .dm_watchdog = rtl8723ae_dm_watchdog, 223 .dm_watchdog = rtl8723ae_dm_watchdog,
223 .scan_operation_backup = rtl8723ae_phy_scan_operation_backup, 224 .scan_operation_backup = rtl_phy_scan_operation_backup,
224 .set_rf_power_state = rtl8723ae_phy_set_rf_power_state, 225 .set_rf_power_state = rtl8723ae_phy_set_rf_power_state,
225 .led_control = rtl8723ae_led_control, 226 .led_control = rtl8723ae_led_control,
226 .set_desc = rtl8723ae_set_desc, 227 .set_desc = rtl8723ae_set_desc,
diff --git a/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c b/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
index bcd82a1020a5..50b7be3f3a60 100644
--- a/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
@@ -359,7 +359,6 @@ bool rtl8723ae_rx_query_desc(struct ieee80211_hw *hw,
359 359
360 /*rx_status->qual = status->signal; */ 360 /*rx_status->qual = status->signal; */
361 rx_status->signal = status->recvsignalpower + 10; 361 rx_status->signal = status->recvsignalpower + 10;
362 /*rx_status->noise = -status->noise; */
363 362
364 return true; 363 return true;
365} 364}
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index e56778cac9bf..6e2b5c5c83c8 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -455,7 +455,6 @@ static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw,
455 struct ieee80211_rx_status rx_status = {0}; 455 struct ieee80211_rx_status rx_status = {0};
456 struct rtl_stats stats = { 456 struct rtl_stats stats = {
457 .signal = 0, 457 .signal = 0,
458 .noise = -98,
459 .rate = 0, 458 .rate = 0,
460 }; 459 };
461 460
@@ -498,7 +497,6 @@ static void _rtl_usb_rx_process_noagg(struct ieee80211_hw *hw,
498 struct ieee80211_rx_status rx_status = {0}; 497 struct ieee80211_rx_status rx_status = {0};
499 struct rtl_stats stats = { 498 struct rtl_stats stats = {
500 .signal = 0, 499 .signal = 0,
501 .noise = -98,
502 .rate = 0, 500 .rate = 0,
503 }; 501 };
504 502
@@ -582,12 +580,15 @@ static void _rtl_rx_work(unsigned long param)
582static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr, 580static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr,
583 unsigned int len) 581 unsigned int len)
584{ 582{
583#if NET_IP_ALIGN != 0
585 unsigned int padding = 0; 584 unsigned int padding = 0;
585#endif
586 586
587 /* make function no-op when possible */ 587 /* make function no-op when possible */
588 if (NET_IP_ALIGN == 0 || len < sizeof(*hdr)) 588 if (NET_IP_ALIGN == 0 || len < sizeof(*hdr))
589 return 0; 589 return 0;
590 590
591#if NET_IP_ALIGN != 0
591 /* alignment calculation as in lbtf_rx() / carl9170_rx_copy_data() */ 592 /* alignment calculation as in lbtf_rx() / carl9170_rx_copy_data() */
592 /* TODO: deduplicate common code, define helper function instead? */ 593 /* TODO: deduplicate common code, define helper function instead? */
593 594
@@ -608,6 +609,7 @@ static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr,
608 padding ^= NET_IP_ALIGN; 609 padding ^= NET_IP_ALIGN;
609 610
610 return padding; 611 return padding;
612#endif
611} 613}
612 614
613#define __RADIO_TAP_SIZE_RSV 32 615#define __RADIO_TAP_SIZE_RSV 32
diff --git a/drivers/net/wireless/rtlwifi/wifi.h b/drivers/net/wireless/rtlwifi/wifi.h
index 703258742d28..d224dc3bb092 100644
--- a/drivers/net/wireless/rtlwifi/wifi.h
+++ b/drivers/net/wireless/rtlwifi/wifi.h
@@ -192,8 +192,6 @@ enum hardware_type {
192(IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal)) 192(IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal))
193#define IS_HARDWARE_TYPE_8723(rtlhal) \ 193#define IS_HARDWARE_TYPE_8723(rtlhal) \
194(IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal)) 194(IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal))
195#define IS_HARDWARE_TYPE_8723U(rtlhal) \
196 (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
197 195
198#define RX_HAL_IS_CCK_RATE(_pdesc)\ 196#define RX_HAL_IS_CCK_RATE(_pdesc)\
199 (_pdesc->rxmcs == DESC92_RATE1M || \ 197 (_pdesc->rxmcs == DESC92_RATE1M || \
diff --git a/drivers/net/wireless/ti/wl1251/spi.c b/drivers/net/wireless/ti/wl1251/spi.c
index c7dc6feab2ff..1342f81e683d 100644
--- a/drivers/net/wireless/ti/wl1251/spi.c
+++ b/drivers/net/wireless/ti/wl1251/spi.c
@@ -243,7 +243,7 @@ static int wl1251_spi_probe(struct spi_device *spi)
243 struct wl1251 *wl; 243 struct wl1251 *wl;
244 int ret; 244 int ret;
245 245
246 pdata = spi->dev.platform_data; 246 pdata = dev_get_platdata(&spi->dev);
247 if (!pdata) { 247 if (!pdata) {
248 wl1251_error("no platform data"); 248 wl1251_error("no platform data");
249 return -ENODEV; 249 return -ENODEV;
diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
index 1c627da85083..591526b99154 100644
--- a/drivers/net/wireless/ti/wl12xx/main.c
+++ b/drivers/net/wireless/ti/wl12xx/main.c
@@ -1704,7 +1704,7 @@ static struct ieee80211_sta_ht_cap wl12xx_ht_cap = {
1704static int wl12xx_setup(struct wl1271 *wl) 1704static int wl12xx_setup(struct wl1271 *wl)
1705{ 1705{
1706 struct wl12xx_priv *priv = wl->priv; 1706 struct wl12xx_priv *priv = wl->priv;
1707 struct wlcore_platdev_data *pdev_data = wl->pdev->dev.platform_data; 1707 struct wlcore_platdev_data *pdev_data = dev_get_platdata(&wl->pdev->dev);
1708 struct wl12xx_platform_data *pdata = pdev_data->pdata; 1708 struct wl12xx_platform_data *pdata = pdev_data->pdata;
1709 1709
1710 wl->rtable = wl12xx_rtable; 1710 wl->rtable = wl12xx_rtable;
diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
index 7aa0eb848c5a..d0daca1d23bc 100644
--- a/drivers/net/wireless/ti/wl18xx/main.c
+++ b/drivers/net/wireless/ti/wl18xx/main.c
@@ -623,6 +623,18 @@ static const int wl18xx_rtable[REG_TABLE_LEN] = {
623 [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR, 623 [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR,
624}; 624};
625 625
626static const struct wl18xx_clk_cfg wl18xx_clk_table_coex[NUM_CLOCK_CONFIGS] = {
627 [CLOCK_CONFIG_16_2_M] = { 8, 121, 0, 0, false },
628 [CLOCK_CONFIG_16_368_M] = { 8, 120, 0, 0, false },
629 [CLOCK_CONFIG_16_8_M] = { 8, 117, 0, 0, false },
630 [CLOCK_CONFIG_19_2_M] = { 10, 128, 0, 0, false },
631 [CLOCK_CONFIG_26_M] = { 11, 104, 0, 0, false },
632 [CLOCK_CONFIG_32_736_M] = { 8, 120, 0, 0, false },
633 [CLOCK_CONFIG_33_6_M] = { 8, 117, 0, 0, false },
634 [CLOCK_CONFIG_38_468_M] = { 10, 128, 0, 0, false },
635 [CLOCK_CONFIG_52_M] = { 11, 104, 0, 0, false },
636};
637
626static const struct wl18xx_clk_cfg wl18xx_clk_table[NUM_CLOCK_CONFIGS] = { 638static const struct wl18xx_clk_cfg wl18xx_clk_table[NUM_CLOCK_CONFIGS] = {
627 [CLOCK_CONFIG_16_2_M] = { 7, 104, 801, 4, true }, 639 [CLOCK_CONFIG_16_2_M] = { 7, 104, 801, 4, true },
628 [CLOCK_CONFIG_16_368_M] = { 9, 132, 3751, 4, true }, 640 [CLOCK_CONFIG_16_368_M] = { 9, 132, 3751, 4, true },
@@ -704,6 +716,23 @@ static int wl18xx_set_clk(struct wl1271 *wl)
704 wl18xx_clk_table[clk_freq].p, wl18xx_clk_table[clk_freq].q, 716 wl18xx_clk_table[clk_freq].p, wl18xx_clk_table[clk_freq].q,
705 wl18xx_clk_table[clk_freq].swallow ? "swallow" : "spit"); 717 wl18xx_clk_table[clk_freq].swallow ? "swallow" : "spit");
706 718
719 /* coex PLL configuration */
720 ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_N,
721 wl18xx_clk_table_coex[clk_freq].n);
722 if (ret < 0)
723 goto out;
724
725 ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_M,
726 wl18xx_clk_table_coex[clk_freq].m);
727 if (ret < 0)
728 goto out;
729
730 /* bypass the swallowing logic */
731 ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
732 PLLSH_COEX_PLL_SWALLOW_EN_VAL1);
733 if (ret < 0)
734 goto out;
735
707 ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_N, 736 ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_N,
708 wl18xx_clk_table[clk_freq].n); 737 wl18xx_clk_table[clk_freq].n);
709 if (ret < 0) 738 if (ret < 0)
@@ -745,6 +774,30 @@ static int wl18xx_set_clk(struct wl1271 *wl)
745 PLLSH_WCS_PLL_SWALLOW_EN_VAL2); 774 PLLSH_WCS_PLL_SWALLOW_EN_VAL2);
746 } 775 }
747 776
777 /* choose WCS PLL */
778 ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_SEL,
779 PLLSH_WL_PLL_SEL_WCS_PLL);
780 if (ret < 0)
781 goto out;
782
783 /* enable both PLLs */
784 ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_EN, PLLSH_WL_PLL_EN_VAL1);
785 if (ret < 0)
786 goto out;
787
788 udelay(1000);
789
790 /* disable coex PLL */
791 ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_EN, PLLSH_WL_PLL_EN_VAL2);
792 if (ret < 0)
793 goto out;
794
795 /* reset the swallowing logic */
796 ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
797 PLLSH_COEX_PLL_SWALLOW_EN_VAL2);
798 if (ret < 0)
799 goto out;
800
748out: 801out:
749 return ret; 802 return ret;
750} 803}
@@ -1175,16 +1228,48 @@ static u32 wl18xx_ap_get_mimo_wide_rate_mask(struct wl1271 *wl,
1175 } 1228 }
1176} 1229}
1177 1230
1231static const char *wl18xx_rdl_name(enum wl18xx_rdl_num rdl_num)
1232{
1233 switch (rdl_num) {
1234 case RDL_1_HP:
1235 return "183xH";
1236 case RDL_2_SP:
1237 return "183x or 180x";
1238 case RDL_3_HP:
1239 return "187xH";
1240 case RDL_4_SP:
1241 return "187x";
1242 case RDL_5_SP:
1243 return "RDL11 - Not Supported";
1244 case RDL_6_SP:
1245 return "180xD";
1246 case RDL_7_SP:
1247 return "RDL13 - Not Supported (1893Q)";
1248 case RDL_8_SP:
1249 return "18xxQ";
1250 case RDL_NONE:
1251 return "UNTRIMMED";
1252 default:
1253 return "UNKNOWN";
1254 }
1255}
1256
1178static int wl18xx_get_pg_ver(struct wl1271 *wl, s8 *ver) 1257static int wl18xx_get_pg_ver(struct wl1271 *wl, s8 *ver)
1179{ 1258{
1180 u32 fuse; 1259 u32 fuse;
1181 s8 rom = 0, metal = 0, pg_ver = 0, rdl_ver = 0; 1260 s8 rom = 0, metal = 0, pg_ver = 0, rdl_ver = 0, package_type = 0;
1182 int ret; 1261 int ret;
1183 1262
1184 ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]); 1263 ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
1185 if (ret < 0) 1264 if (ret < 0)
1186 goto out; 1265 goto out;
1187 1266
1267 ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_2_3, &fuse);
1268 if (ret < 0)
1269 goto out;
1270
1271 package_type = (fuse >> WL18XX_PACKAGE_TYPE_OFFSET) & 1;
1272
1188 ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_1_3, &fuse); 1273 ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_1_3, &fuse);
1189 if (ret < 0) 1274 if (ret < 0)
1190 goto out; 1275 goto out;
@@ -1192,7 +1277,7 @@ static int wl18xx_get_pg_ver(struct wl1271 *wl, s8 *ver)
1192 pg_ver = (fuse & WL18XX_PG_VER_MASK) >> WL18XX_PG_VER_OFFSET; 1277 pg_ver = (fuse & WL18XX_PG_VER_MASK) >> WL18XX_PG_VER_OFFSET;
1193 rom = (fuse & WL18XX_ROM_VER_MASK) >> WL18XX_ROM_VER_OFFSET; 1278 rom = (fuse & WL18XX_ROM_VER_MASK) >> WL18XX_ROM_VER_OFFSET;
1194 1279
1195 if (rom <= 0xE) 1280 if ((rom <= 0xE) && (package_type == WL18XX_PACKAGE_TYPE_WSP))
1196 metal = (fuse & WL18XX_METAL_VER_MASK) >> 1281 metal = (fuse & WL18XX_METAL_VER_MASK) >>
1197 WL18XX_METAL_VER_OFFSET; 1282 WL18XX_METAL_VER_OFFSET;
1198 else 1283 else
@@ -1204,11 +1289,9 @@ static int wl18xx_get_pg_ver(struct wl1271 *wl, s8 *ver)
1204 goto out; 1289 goto out;
1205 1290
1206 rdl_ver = (fuse & WL18XX_RDL_VER_MASK) >> WL18XX_RDL_VER_OFFSET; 1291 rdl_ver = (fuse & WL18XX_RDL_VER_MASK) >> WL18XX_RDL_VER_OFFSET;
1207 if (rdl_ver > RDL_MAX)
1208 rdl_ver = RDL_NONE;
1209 1292
1210 wl1271_info("wl18xx HW: RDL %d, %s, PG %x.%x (ROM %x)", 1293 wl1271_info("wl18xx HW: %s, PG %d.%d (ROM 0x%x)",
1211 rdl_ver, rdl_names[rdl_ver], pg_ver, metal, rom); 1294 wl18xx_rdl_name(rdl_ver), pg_ver, metal, rom);
1212 1295
1213 if (ver) 1296 if (ver)
1214 *ver = pg_ver; 1297 *ver = pg_ver;
diff --git a/drivers/net/wireless/ti/wl18xx/reg.h b/drivers/net/wireless/ti/wl18xx/reg.h
index 05dd8bad2746..a433a75f3cd7 100644
--- a/drivers/net/wireless/ti/wl18xx/reg.h
+++ b/drivers/net/wireless/ti/wl18xx/reg.h
@@ -114,6 +114,11 @@
114#define PLATFORM_DETECTION 0xA0E3E0 114#define PLATFORM_DETECTION 0xA0E3E0
115#define OCS_EN 0xA02080 115#define OCS_EN 0xA02080
116#define PRIMARY_CLK_DETECT 0xA020A6 116#define PRIMARY_CLK_DETECT 0xA020A6
117#define PLLSH_COEX_PLL_N 0xA02384
118#define PLLSH_COEX_PLL_M 0xA02382
119#define PLLSH_COEX_PLL_SWALLOW_EN 0xA0238E
120#define PLLSH_WL_PLL_SEL 0xA02398
121
117#define PLLSH_WCS_PLL_N 0xA02362 122#define PLLSH_WCS_PLL_N 0xA02362
118#define PLLSH_WCS_PLL_M 0xA02360 123#define PLLSH_WCS_PLL_M 0xA02360
119#define PLLSH_WCS_PLL_Q_FACTOR_CFG_1 0xA02364 124#define PLLSH_WCS_PLL_Q_FACTOR_CFG_1 0xA02364
@@ -128,19 +133,30 @@
128#define PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK 0xFFFF 133#define PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK 0xFFFF
129#define PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK 0x000F 134#define PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK 0x000F
130 135
136#define PLLSH_WL_PLL_EN_VAL1 0x7
137#define PLLSH_WL_PLL_EN_VAL2 0x2
138#define PLLSH_COEX_PLL_SWALLOW_EN_VAL1 0x2
139#define PLLSH_COEX_PLL_SWALLOW_EN_VAL2 0x11
140
131#define PLLSH_WCS_PLL_SWALLOW_EN_VAL1 0x1 141#define PLLSH_WCS_PLL_SWALLOW_EN_VAL1 0x1
132#define PLLSH_WCS_PLL_SWALLOW_EN_VAL2 0x12 142#define PLLSH_WCS_PLL_SWALLOW_EN_VAL2 0x12
133 143
144#define PLLSH_WL_PLL_SEL_WCS_PLL 0x0
145#define PLLSH_WL_PLL_SEL_COEX_PLL 0x1
146
134#define WL18XX_REG_FUSE_DATA_1_3 0xA0260C 147#define WL18XX_REG_FUSE_DATA_1_3 0xA0260C
135#define WL18XX_PG_VER_MASK 0x70 148#define WL18XX_PG_VER_MASK 0x70
136#define WL18XX_PG_VER_OFFSET 4 149#define WL18XX_PG_VER_OFFSET 4
137#define WL18XX_ROM_VER_MASK 0x3 150#define WL18XX_ROM_VER_MASK 0x3e00
138#define WL18XX_ROM_VER_OFFSET 0 151#define WL18XX_ROM_VER_OFFSET 9
139#define WL18XX_METAL_VER_MASK 0xC 152#define WL18XX_METAL_VER_MASK 0xC
140#define WL18XX_METAL_VER_OFFSET 2 153#define WL18XX_METAL_VER_OFFSET 2
141#define WL18XX_NEW_METAL_VER_MASK 0x180 154#define WL18XX_NEW_METAL_VER_MASK 0x180
142#define WL18XX_NEW_METAL_VER_OFFSET 7 155#define WL18XX_NEW_METAL_VER_OFFSET 7
143 156
157#define WL18XX_PACKAGE_TYPE_OFFSET 13
158#define WL18XX_PACKAGE_TYPE_WSP 0
159
144#define WL18XX_REG_FUSE_DATA_2_3 0xA02614 160#define WL18XX_REG_FUSE_DATA_2_3 0xA02614
145#define WL18XX_RDL_VER_MASK 0x1f00 161#define WL18XX_RDL_VER_MASK 0x1f00
146#define WL18XX_RDL_VER_OFFSET 8 162#define WL18XX_RDL_VER_OFFSET 8
@@ -201,24 +217,21 @@ enum {
201 NUM_BOARD_TYPES, 217 NUM_BOARD_TYPES,
202}; 218};
203 219
204enum { 220enum wl18xx_rdl_num {
205 RDL_NONE = 0, 221 RDL_NONE = 0,
206 RDL_1_HP = 1, 222 RDL_1_HP = 1,
207 RDL_2_SP = 2, 223 RDL_2_SP = 2,
208 RDL_3_HP = 3, 224 RDL_3_HP = 3,
209 RDL_4_SP = 4, 225 RDL_4_SP = 4,
226 RDL_5_SP = 0x11,
227 RDL_6_SP = 0x12,
228 RDL_7_SP = 0x13,
229 RDL_8_SP = 0x14,
210 230
211 _RDL_LAST, 231 _RDL_LAST,
212 RDL_MAX = _RDL_LAST - 1, 232 RDL_MAX = _RDL_LAST - 1,
213}; 233};
214 234
215static const char * const rdl_names[] = {
216 [RDL_NONE] = "",
217 [RDL_1_HP] = "1853 SISO",
218 [RDL_2_SP] = "1857 MIMO",
219 [RDL_3_HP] = "1893 SISO",
220 [RDL_4_SP] = "1897 MIMO",
221};
222 235
223/* FPGA_SPARE_1 register - used to change the PHY ATPG clock at boot time */ 236/* FPGA_SPARE_1 register - used to change the PHY ATPG clock at boot time */
224#define WL18XX_PHY_FPGA_SPARE_1 0x8093CA40 237#define WL18XX_PHY_FPGA_SPARE_1 0x8093CA40
diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c
index c9e060795d13..9e5416f8764d 100644
--- a/drivers/net/wireless/ti/wlcore/cmd.c
+++ b/drivers/net/wireless/ti/wlcore/cmd.c
@@ -1126,6 +1126,8 @@ int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1126 u16 template_id_2_4 = wl->scan_templ_id_2_4; 1126 u16 template_id_2_4 = wl->scan_templ_id_2_4;
1127 u16 template_id_5 = wl->scan_templ_id_5; 1127 u16 template_id_5 = wl->scan_templ_id_5;
1128 1128
1129 wl1271_debug(DEBUG_SCAN, "build probe request band %d", band);
1130
1129 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len, 1131 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1130 ie_len); 1132 ie_len);
1131 if (!skb) { 1133 if (!skb) {
@@ -1135,8 +1137,6 @@ int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1135 if (ie_len) 1137 if (ie_len)
1136 memcpy(skb_put(skb, ie_len), ie, ie_len); 1138 memcpy(skb_put(skb, ie_len), ie, ie_len);
1137 1139
1138 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1139
1140 if (sched_scan && 1140 if (sched_scan &&
1141 (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) { 1141 (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) {
1142 template_id_2_4 = wl->sched_scan_templ_id_2_4; 1142 template_id_2_4 = wl->sched_scan_templ_id_2_4;
@@ -1172,7 +1172,7 @@ struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1172 if (!skb) 1172 if (!skb)
1173 goto out; 1173 goto out;
1174 1174
1175 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); 1175 wl1271_debug(DEBUG_SCAN, "set ap probe request template");
1176 1176
1177 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]); 1177 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1178 if (wlvif->band == IEEE80211_BAND_2GHZ) 1178 if (wlvif->band == IEEE80211_BAND_2GHZ)
@@ -1607,33 +1607,43 @@ out:
1607 1607
1608static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band, u16 ch) 1608static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band, u16 ch)
1609{ 1609{
1610 int idx = -1; 1610 /*
1611 1611 * map the given band/channel to the respective predefined
1612 * bit expected by the fw
1613 */
1612 switch (band) { 1614 switch (band) {
1613 case IEEE80211_BAND_5GHZ:
1614 if (ch >= 8 && ch <= 16)
1615 idx = ((ch-8)/4 + 18);
1616 else if (ch >= 34 && ch <= 64)
1617 idx = ((ch-34)/2 + 3 + 18);
1618 else if (ch >= 100 && ch <= 140)
1619 idx = ((ch-100)/4 + 15 + 18);
1620 else if (ch >= 149 && ch <= 165)
1621 idx = ((ch-149)/4 + 26 + 18);
1622 else
1623 idx = -1;
1624 break;
1625 case IEEE80211_BAND_2GHZ: 1615 case IEEE80211_BAND_2GHZ:
1616 /* channels 1..14 are mapped to 0..13 */
1626 if (ch >= 1 && ch <= 14) 1617 if (ch >= 1 && ch <= 14)
1627 idx = ch - 1; 1618 return ch - 1;
1628 else 1619 break;
1629 idx = -1; 1620 case IEEE80211_BAND_5GHZ:
1621 switch (ch) {
1622 case 8 ... 16:
1623 /* channels 8,12,16 are mapped to 18,19,20 */
1624 return 18 + (ch-8)/4;
1625 case 34 ... 48:
1626 /* channels 34,36..48 are mapped to 21..28 */
1627 return 21 + (ch-34)/2;
1628 case 52 ... 64:
1629 /* channels 52,56..64 are mapped to 29..32 */
1630 return 29 + (ch-52)/4;
1631 case 100 ... 140:
1632 /* channels 100,104..140 are mapped to 33..43 */
1633 return 33 + (ch-100)/4;
1634 case 149 ... 165:
1635 /* channels 149,153..165 are mapped to 44..48 */
1636 return 44 + (ch-149)/4;
1637 default:
1638 break;
1639 }
1630 break; 1640 break;
1631 default: 1641 default:
1632 wl1271_error("get reg conf ch idx - unknown band: %d", 1642 break;
1633 (int)band);
1634 } 1643 }
1635 1644
1636 return idx; 1645 wl1271_error("%s: unknown band/channel: %d/%d", __func__, band, ch);
1646 return -1;
1637} 1647}
1638 1648
1639void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel, 1649void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel,
@@ -1646,7 +1656,7 @@ void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel,
1646 1656
1647 ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel); 1657 ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel);
1648 1658
1649 if (ch_bit_idx > 0 && ch_bit_idx <= WL1271_MAX_CHANNELS) 1659 if (ch_bit_idx >= 0 && ch_bit_idx <= WL1271_MAX_CHANNELS)
1650 set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending); 1660 set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending);
1651} 1661}
1652 1662
diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 38995f90040d..bbdd10632373 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -1062,7 +1062,8 @@ int wl1271_plt_start(struct wl1271 *wl, const enum plt_mode plt_mode)
1062 static const char* const PLT_MODE[] = { 1062 static const char* const PLT_MODE[] = {
1063 "PLT_OFF", 1063 "PLT_OFF",
1064 "PLT_ON", 1064 "PLT_ON",
1065 "PLT_FEM_DETECT" 1065 "PLT_FEM_DETECT",
1066 "PLT_CHIP_AWAKE"
1066 }; 1067 };
1067 1068
1068 int ret; 1069 int ret;
@@ -1088,9 +1089,11 @@ int wl1271_plt_start(struct wl1271 *wl, const enum plt_mode plt_mode)
1088 if (ret < 0) 1089 if (ret < 0)
1089 goto power_off; 1090 goto power_off;
1090 1091
1091 ret = wl->ops->plt_init(wl); 1092 if (plt_mode != PLT_CHIP_AWAKE) {
1092 if (ret < 0) 1093 ret = wl->ops->plt_init(wl);
1093 goto power_off; 1094 if (ret < 0)
1095 goto power_off;
1096 }
1094 1097
1095 wl->state = WLCORE_STATE_ON; 1098 wl->state = WLCORE_STATE_ON;
1096 wl1271_notice("firmware booted in PLT mode %s (%s)", 1099 wl1271_notice("firmware booted in PLT mode %s (%s)",
@@ -2008,6 +2011,47 @@ out:
2008 mutex_unlock(&wl->mutex); 2011 mutex_unlock(&wl->mutex);
2009} 2012}
2010 2013
2014static void wlcore_pending_auth_complete_work(struct work_struct *work)
2015{
2016 struct delayed_work *dwork;
2017 struct wl1271 *wl;
2018 struct wl12xx_vif *wlvif;
2019 unsigned long time_spare;
2020 int ret;
2021
2022 dwork = container_of(work, struct delayed_work, work);
2023 wlvif = container_of(dwork, struct wl12xx_vif,
2024 pending_auth_complete_work);
2025 wl = wlvif->wl;
2026
2027 mutex_lock(&wl->mutex);
2028
2029 if (unlikely(wl->state != WLCORE_STATE_ON))
2030 goto out;
2031
2032 /*
2033 * Make sure a second really passed since the last auth reply. Maybe
2034 * a second auth reply arrived while we were stuck on the mutex.
2035 * Check for a little less than the timeout to protect from scheduler
2036 * irregularities.
2037 */
2038 time_spare = jiffies +
2039 msecs_to_jiffies(WLCORE_PEND_AUTH_ROC_TIMEOUT - 50);
2040 if (!time_after(time_spare, wlvif->pending_auth_reply_time))
2041 goto out;
2042
2043 ret = wl1271_ps_elp_wakeup(wl);
2044 if (ret < 0)
2045 goto out;
2046
2047 /* cancel the ROC if active */
2048 wlcore_update_inconn_sta(wl, wlvif, NULL, false);
2049
2050 wl1271_ps_elp_sleep(wl);
2051out:
2052 mutex_unlock(&wl->mutex);
2053}
2054
2011static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) 2055static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
2012{ 2056{
2013 u8 policy = find_first_zero_bit(wl->rate_policies_map, 2057 u8 policy = find_first_zero_bit(wl->rate_policies_map,
@@ -2159,6 +2203,8 @@ static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
2159 wlcore_channel_switch_work); 2203 wlcore_channel_switch_work);
2160 INIT_DELAYED_WORK(&wlvif->connection_loss_work, 2204 INIT_DELAYED_WORK(&wlvif->connection_loss_work,
2161 wlcore_connection_loss_work); 2205 wlcore_connection_loss_work);
2206 INIT_DELAYED_WORK(&wlvif->pending_auth_complete_work,
2207 wlcore_pending_auth_complete_work);
2162 INIT_LIST_HEAD(&wlvif->list); 2208 INIT_LIST_HEAD(&wlvif->list);
2163 2209
2164 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, 2210 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
@@ -2376,6 +2422,11 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2376 int ret = 0; 2422 int ret = 0;
2377 u8 role_type; 2423 u8 role_type;
2378 2424
2425 if (wl->plt) {
2426 wl1271_error("Adding Interface not allowed while in PLT mode");
2427 return -EBUSY;
2428 }
2429
2379 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 2430 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2380 IEEE80211_VIF_SUPPORTS_CQM_RSSI; 2431 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
2381 2432
@@ -2590,6 +2641,7 @@ unlock:
2590 cancel_work_sync(&wlvif->rx_streaming_disable_work); 2641 cancel_work_sync(&wlvif->rx_streaming_disable_work);
2591 cancel_delayed_work_sync(&wlvif->connection_loss_work); 2642 cancel_delayed_work_sync(&wlvif->connection_loss_work);
2592 cancel_delayed_work_sync(&wlvif->channel_switch_work); 2643 cancel_delayed_work_sync(&wlvif->channel_switch_work);
2644 cancel_delayed_work_sync(&wlvif->pending_auth_complete_work);
2593 2645
2594 mutex_lock(&wl->mutex); 2646 mutex_lock(&wl->mutex);
2595} 2647}
@@ -2875,6 +2927,25 @@ static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2875 wlvif->rate_set = wlvif->basic_rate_set; 2927 wlvif->rate_set = wlvif->basic_rate_set;
2876} 2928}
2877 2929
2930static void wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2931 bool idle)
2932{
2933 bool cur_idle = !test_bit(WLVIF_FLAG_ACTIVE, &wlvif->flags);
2934
2935 if (idle == cur_idle)
2936 return;
2937
2938 if (idle) {
2939 clear_bit(WLVIF_FLAG_ACTIVE, &wlvif->flags);
2940 } else {
2941 /* The current firmware only supports sched_scan in idle */
2942 if (wl->sched_vif == wlvif)
2943 wl->ops->sched_scan_stop(wl, wlvif);
2944
2945 set_bit(WLVIF_FLAG_ACTIVE, &wlvif->flags);
2946 }
2947}
2948
2878static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, 2949static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2879 struct ieee80211_conf *conf, u32 changed) 2950 struct ieee80211_conf *conf, u32 changed)
2880{ 2951{
@@ -3969,6 +4040,13 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3969 } 4040 }
3970 } else { 4041 } else {
3971 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { 4042 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
4043 /*
4044 * AP might be in ROC in case we have just
4045 * sent auth reply. handle it.
4046 */
4047 if (test_bit(wlvif->role_id, wl->roc_map))
4048 wl12xx_croc(wl, wlvif->role_id);
4049
3972 ret = wl12xx_cmd_role_stop_ap(wl, wlvif); 4050 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
3973 if (ret < 0) 4051 if (ret < 0)
3974 goto out; 4052 goto out;
@@ -4120,6 +4198,9 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
4120 do_join = true; 4198 do_join = true;
4121 } 4199 }
4122 4200
4201 if (changed & BSS_CHANGED_IDLE && !is_ibss)
4202 wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
4203
4123 if (changed & BSS_CHANGED_CQM) { 4204 if (changed & BSS_CHANGED_CQM) {
4124 bool enable = false; 4205 bool enable = false;
4125 if (bss_conf->cqm_rssi_thold) 4206 if (bss_conf->cqm_rssi_thold)
@@ -4656,29 +4737,49 @@ static void wlcore_roc_if_possible(struct wl1271 *wl,
4656 wl12xx_roc(wl, wlvif, wlvif->role_id, wlvif->band, wlvif->channel); 4737 wl12xx_roc(wl, wlvif, wlvif->role_id, wlvif->band, wlvif->channel);
4657} 4738}
4658 4739
4659static void wlcore_update_inconn_sta(struct wl1271 *wl, 4740/*
4660 struct wl12xx_vif *wlvif, 4741 * when wl_sta is NULL, we treat this call as if coming from a
4661 struct wl1271_station *wl_sta, 4742 * pending auth reply.
4662 bool in_connection) 4743 * wl->mutex must be taken and the FW must be awake when the call
4744 * takes place.
4745 */
4746void wlcore_update_inconn_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif,
4747 struct wl1271_station *wl_sta, bool in_conn)
4663{ 4748{
4664 if (in_connection) { 4749 if (in_conn) {
4665 if (WARN_ON(wl_sta->in_connection)) 4750 if (WARN_ON(wl_sta && wl_sta->in_connection))
4666 return; 4751 return;
4667 wl_sta->in_connection = true; 4752
4668 if (!wlvif->inconn_count++) 4753 if (!wlvif->ap_pending_auth_reply &&
4754 !wlvif->inconn_count)
4669 wlcore_roc_if_possible(wl, wlvif); 4755 wlcore_roc_if_possible(wl, wlvif);
4756
4757 if (wl_sta) {
4758 wl_sta->in_connection = true;
4759 wlvif->inconn_count++;
4760 } else {
4761 wlvif->ap_pending_auth_reply = true;
4762 }
4670 } else { 4763 } else {
4671 if (!wl_sta->in_connection) 4764 if (wl_sta && !wl_sta->in_connection)
4765 return;
4766
4767 if (WARN_ON(!wl_sta && !wlvif->ap_pending_auth_reply))
4672 return; 4768 return;
4673 4769
4674 wl_sta->in_connection = false; 4770 if (WARN_ON(wl_sta && !wlvif->inconn_count))
4675 wlvif->inconn_count--;
4676 if (WARN_ON(wlvif->inconn_count < 0))
4677 return; 4771 return;
4678 4772
4679 if (!wlvif->inconn_count) 4773 if (wl_sta) {
4680 if (test_bit(wlvif->role_id, wl->roc_map)) 4774 wl_sta->in_connection = false;
4681 wl12xx_croc(wl, wlvif->role_id); 4775 wlvif->inconn_count--;
4776 } else {
4777 wlvif->ap_pending_auth_reply = false;
4778 }
4779
4780 if (!wlvif->inconn_count && !wlvif->ap_pending_auth_reply &&
4781 test_bit(wlvif->role_id, wl->roc_map))
4782 wl12xx_croc(wl, wlvif->role_id);
4682 } 4783 }
4683} 4784}
4684 4785
@@ -5313,10 +5414,7 @@ static struct ieee80211_rate wl1271_rates_5ghz[] = {
5313 5414
5314/* 5 GHz band channels for WL1273 */ 5415/* 5 GHz band channels for WL1273 */
5315static struct ieee80211_channel wl1271_channels_5ghz[] = { 5416static struct ieee80211_channel wl1271_channels_5ghz[] = {
5316 { .hw_value = 7, .center_freq = 5035, .max_power = WLCORE_MAX_TXPWR },
5317 { .hw_value = 8, .center_freq = 5040, .max_power = WLCORE_MAX_TXPWR }, 5417 { .hw_value = 8, .center_freq = 5040, .max_power = WLCORE_MAX_TXPWR },
5318 { .hw_value = 9, .center_freq = 5045, .max_power = WLCORE_MAX_TXPWR },
5319 { .hw_value = 11, .center_freq = 5055, .max_power = WLCORE_MAX_TXPWR },
5320 { .hw_value = 12, .center_freq = 5060, .max_power = WLCORE_MAX_TXPWR }, 5418 { .hw_value = 12, .center_freq = 5060, .max_power = WLCORE_MAX_TXPWR },
5321 { .hw_value = 16, .center_freq = 5080, .max_power = WLCORE_MAX_TXPWR }, 5419 { .hw_value = 16, .center_freq = 5080, .max_power = WLCORE_MAX_TXPWR },
5322 { .hw_value = 34, .center_freq = 5170, .max_power = WLCORE_MAX_TXPWR }, 5420 { .hw_value = 34, .center_freq = 5170, .max_power = WLCORE_MAX_TXPWR },
@@ -5896,14 +5994,20 @@ static const struct wiphy_wowlan_support wlcore_wowlan_support = {
5896}; 5994};
5897#endif 5995#endif
5898 5996
5997static irqreturn_t wlcore_hardirq(int irq, void *cookie)
5998{
5999 return IRQ_WAKE_THREAD;
6000}
6001
5899static void wlcore_nvs_cb(const struct firmware *fw, void *context) 6002static void wlcore_nvs_cb(const struct firmware *fw, void *context)
5900{ 6003{
5901 struct wl1271 *wl = context; 6004 struct wl1271 *wl = context;
5902 struct platform_device *pdev = wl->pdev; 6005 struct platform_device *pdev = wl->pdev;
5903 struct wlcore_platdev_data *pdev_data = pdev->dev.platform_data; 6006 struct wlcore_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
5904 struct wl12xx_platform_data *pdata = pdev_data->pdata; 6007 struct wl12xx_platform_data *pdata = pdev_data->pdata;
5905 unsigned long irqflags; 6008 unsigned long irqflags;
5906 int ret; 6009 int ret;
6010 irq_handler_t hardirq_fn = NULL;
5907 6011
5908 if (fw) { 6012 if (fw) {
5909 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); 6013 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
@@ -5932,12 +6036,14 @@ static void wlcore_nvs_cb(const struct firmware *fw, void *context)
5932 wl->platform_quirks = pdata->platform_quirks; 6036 wl->platform_quirks = pdata->platform_quirks;
5933 wl->if_ops = pdev_data->if_ops; 6037 wl->if_ops = pdev_data->if_ops;
5934 6038
5935 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 6039 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) {
5936 irqflags = IRQF_TRIGGER_RISING; 6040 irqflags = IRQF_TRIGGER_RISING;
5937 else 6041 hardirq_fn = wlcore_hardirq;
6042 } else {
5938 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 6043 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
6044 }
5939 6045
5940 ret = request_threaded_irq(wl->irq, NULL, wlcore_irq, 6046 ret = request_threaded_irq(wl->irq, hardirq_fn, wlcore_irq,
5941 irqflags, pdev->name, wl); 6047 irqflags, pdev->name, wl);
5942 if (ret < 0) { 6048 if (ret < 0) {
5943 wl1271_error("request_irq() failed: %d", ret); 6049 wl1271_error("request_irq() failed: %d", ret);
diff --git a/drivers/net/wireless/ti/wlcore/ps.c b/drivers/net/wireless/ti/wlcore/ps.c
index 98066d40c2ad..26bfc365ba70 100644
--- a/drivers/net/wireless/ti/wlcore/ps.c
+++ b/drivers/net/wireless/ti/wlcore/ps.c
@@ -83,6 +83,10 @@ void wl1271_ps_elp_sleep(struct wl1271 *wl)
83 struct wl12xx_vif *wlvif; 83 struct wl12xx_vif *wlvif;
84 u32 timeout; 84 u32 timeout;
85 85
86 /* We do not enter elp sleep in PLT mode */
87 if (wl->plt)
88 return;
89
86 if (wl->sleep_auth != WL1271_PSM_ELP) 90 if (wl->sleep_auth != WL1271_PSM_ELP)
87 return; 91 return;
88 92
diff --git a/drivers/net/wireless/ti/wlcore/scan.c b/drivers/net/wireless/ti/wlcore/scan.c
index f407101e525b..13e743df2e31 100644
--- a/drivers/net/wireless/ti/wlcore/scan.c
+++ b/drivers/net/wireless/ti/wlcore/scan.c
@@ -174,17 +174,7 @@ wlcore_scan_get_channels(struct wl1271 *wl,
174 /* if radar is set, we ignore the passive flag */ 174 /* if radar is set, we ignore the passive flag */
175 (radar || 175 (radar ||
176 !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) { 176 !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
177 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", 177
178 req_channels[i]->band,
179 req_channels[i]->center_freq);
180 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
181 req_channels[i]->hw_value,
182 req_channels[i]->flags);
183 wl1271_debug(DEBUG_SCAN, "max_power %d",
184 req_channels[i]->max_power);
185 wl1271_debug(DEBUG_SCAN, "min_dwell_time %d max dwell time %d",
186 min_dwell_time_active,
187 max_dwell_time_active);
188 178
189 if (flags & IEEE80211_CHAN_RADAR) { 179 if (flags & IEEE80211_CHAN_RADAR) {
190 channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS; 180 channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
@@ -222,6 +212,17 @@ wlcore_scan_get_channels(struct wl1271 *wl,
222 *n_pactive_ch); 212 *n_pactive_ch);
223 } 213 }
224 214
215 wl1271_debug(DEBUG_SCAN, "freq %d, ch. %d, flags 0x%x, power %d, min/max_dwell %d/%d%s%s",
216 req_channels[i]->center_freq,
217 req_channels[i]->hw_value,
218 req_channels[i]->flags,
219 req_channels[i]->max_power,
220 min_dwell_time_active,
221 max_dwell_time_active,
222 flags & IEEE80211_CHAN_RADAR ?
223 ", DFS" : "",
224 flags & IEEE80211_CHAN_PASSIVE_SCAN ?
225 ", PASSIVE" : "");
225 j++; 226 j++;
226 } 227 }
227 } 228 }
@@ -364,7 +365,7 @@ wlcore_scan_sched_scan_ssid_list(struct wl1271 *wl,
364 struct cfg80211_ssid *ssids = req->ssids; 365 struct cfg80211_ssid *ssids = req->ssids;
365 int ret = 0, type, i, j, n_match_ssids = 0; 366 int ret = 0, type, i, j, n_match_ssids = 0;
366 367
367 wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list"); 368 wl1271_debug((DEBUG_CMD | DEBUG_SCAN), "cmd sched scan ssid list");
368 369
369 /* count the match sets that contain SSIDs */ 370 /* count the match sets that contain SSIDs */
370 for (i = 0; i < req->n_match_sets; i++) 371 for (i = 0; i < req->n_match_sets; i++)
@@ -442,8 +443,6 @@ wlcore_scan_sched_scan_ssid_list(struct wl1271 *wl,
442 } 443 }
443 } 444 }
444 445
445 wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd));
446
447 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd, 446 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd,
448 sizeof(*cmd), 0); 447 sizeof(*cmd), 0);
449 if (ret < 0) { 448 if (ret < 0) {
diff --git a/drivers/net/wireless/ti/wlcore/spi.c b/drivers/net/wireless/ti/wlcore/spi.c
index 1b0cd98e35f1..b2c018dccf18 100644
--- a/drivers/net/wireless/ti/wlcore/spi.c
+++ b/drivers/net/wireless/ti/wlcore/spi.c
@@ -335,7 +335,7 @@ static int wl1271_probe(struct spi_device *spi)
335 if (!pdev_data) 335 if (!pdev_data)
336 goto out; 336 goto out;
337 337
338 pdev_data->pdata = spi->dev.platform_data; 338 pdev_data->pdata = dev_get_platdata(&spi->dev);
339 if (!pdev_data->pdata) { 339 if (!pdev_data->pdata) {
340 dev_err(&spi->dev, "no platform data\n"); 340 dev_err(&spi->dev, "no platform data\n");
341 ret = -ENODEV; 341 ret = -ENODEV;
diff --git a/drivers/net/wireless/ti/wlcore/testmode.c b/drivers/net/wireless/ti/wlcore/testmode.c
index 527590f2adfb..a3b7d950d8e9 100644
--- a/drivers/net/wireless/ti/wlcore/testmode.c
+++ b/drivers/net/wireless/ti/wlcore/testmode.c
@@ -297,7 +297,8 @@ static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
297 ret = wl1271_plt_stop(wl); 297 ret = wl1271_plt_stop(wl);
298 break; 298 break;
299 case PLT_ON: 299 case PLT_ON:
300 ret = wl1271_plt_start(wl, PLT_ON); 300 case PLT_CHIP_AWAKE:
301 ret = wl1271_plt_start(wl, val);
301 break; 302 break;
302 case PLT_FEM_DETECT: 303 case PLT_FEM_DETECT:
303 ret = wl1271_tm_detect_fem(wl, tb); 304 ret = wl1271_tm_detect_fem(wl, tb);
@@ -361,6 +362,7 @@ int wl1271_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
361{ 362{
362 struct wl1271 *wl = hw->priv; 363 struct wl1271 *wl = hw->priv;
363 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1]; 364 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
365 u32 nla_cmd;
364 int err; 366 int err;
365 367
366 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy); 368 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
@@ -370,7 +372,14 @@ int wl1271_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
370 if (!tb[WL1271_TM_ATTR_CMD_ID]) 372 if (!tb[WL1271_TM_ATTR_CMD_ID])
371 return -EINVAL; 373 return -EINVAL;
372 374
373 switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) { 375 nla_cmd = nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID]);
376
377 /* Only SET_PLT_MODE is allowed in case of mode PLT_CHIP_AWAKE */
378 if (wl->plt_mode == PLT_CHIP_AWAKE &&
379 nla_cmd != WL1271_TM_CMD_SET_PLT_MODE)
380 return -EOPNOTSUPP;
381
382 switch (nla_cmd) {
374 case WL1271_TM_CMD_TEST: 383 case WL1271_TM_CMD_TEST:
375 return wl1271_tm_cmd_test(wl, tb); 384 return wl1271_tm_cmd_test(wl, tb);
376 case WL1271_TM_CMD_INTERROGATE: 385 case WL1271_TM_CMD_INTERROGATE:
diff --git a/drivers/net/wireless/ti/wlcore/tx.c b/drivers/net/wireless/ti/wlcore/tx.c
index 7e93fe63a2c7..87cd707affa2 100644
--- a/drivers/net/wireless/ti/wlcore/tx.c
+++ b/drivers/net/wireless/ti/wlcore/tx.c
@@ -86,19 +86,34 @@ void wl1271_free_tx_id(struct wl1271 *wl, int id)
86EXPORT_SYMBOL(wl1271_free_tx_id); 86EXPORT_SYMBOL(wl1271_free_tx_id);
87 87
88static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl, 88static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
89 struct wl12xx_vif *wlvif,
89 struct sk_buff *skb) 90 struct sk_buff *skb)
90{ 91{
91 struct ieee80211_hdr *hdr; 92 struct ieee80211_hdr *hdr;
92 93
94 hdr = (struct ieee80211_hdr *)(skb->data +
95 sizeof(struct wl1271_tx_hw_descr));
96 if (!ieee80211_is_auth(hdr->frame_control))
97 return;
98
93 /* 99 /*
94 * add the station to the known list before transmitting the 100 * add the station to the known list before transmitting the
95 * authentication response. this way it won't get de-authed by FW 101 * authentication response. this way it won't get de-authed by FW
96 * when transmitting too soon. 102 * when transmitting too soon.
97 */ 103 */
98 hdr = (struct ieee80211_hdr *)(skb->data + 104 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
99 sizeof(struct wl1271_tx_hw_descr)); 105
100 if (ieee80211_is_auth(hdr->frame_control)) 106 /*
101 wl1271_acx_set_inconnection_sta(wl, hdr->addr1); 107 * ROC for 1 second on the AP channel for completing the connection.
108 * Note the ROC will be continued by the update_sta_state callbacks
109 * once the station reaches the associated state.
110 */
111 wlcore_update_inconn_sta(wl, wlvif, NULL, true);
112 wlvif->pending_auth_reply_time = jiffies;
113 cancel_delayed_work(&wlvif->pending_auth_complete_work);
114 ieee80211_queue_delayed_work(wl->hw,
115 &wlvif->pending_auth_complete_work,
116 msecs_to_jiffies(WLCORE_PEND_AUTH_ROC_TIMEOUT));
102} 117}
103 118
104static void wl1271_tx_regulate_link(struct wl1271 *wl, 119static void wl1271_tx_regulate_link(struct wl1271 *wl,
@@ -386,7 +401,7 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
386 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || 401 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
387 (cipher == WLAN_CIPHER_SUITE_WEP104); 402 (cipher == WLAN_CIPHER_SUITE_WEP104);
388 403
389 if (WARN_ON(is_wep && wlvif->default_key != idx)) { 404 if (WARN_ON(is_wep && wlvif && wlvif->default_key != idx)) {
390 ret = wl1271_set_default_wep_key(wl, wlvif, idx); 405 ret = wl1271_set_default_wep_key(wl, wlvif, idx);
391 if (ret < 0) 406 if (ret < 0)
392 return ret; 407 return ret;
@@ -404,7 +419,7 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
404 wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid); 419 wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
405 420
406 if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) { 421 if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) {
407 wl1271_tx_ap_update_inconnection_sta(wl, skb); 422 wl1271_tx_ap_update_inconnection_sta(wl, wlvif, skb);
408 wl1271_tx_regulate_link(wl, wlvif, hlid); 423 wl1271_tx_regulate_link(wl, wlvif, hlid);
409 } 424 }
410 425
diff --git a/drivers/net/wireless/ti/wlcore/tx.h b/drivers/net/wireless/ti/wlcore/tx.h
index 55aa4acf9105..35489c300da1 100644
--- a/drivers/net/wireless/ti/wlcore/tx.h
+++ b/drivers/net/wireless/ti/wlcore/tx.h
@@ -56,6 +56,9 @@
56/* Used for management frames and dummy packets */ 56/* Used for management frames and dummy packets */
57#define WL1271_TID_MGMT 7 57#define WL1271_TID_MGMT 7
58 58
59/* stop a ROC for pending authentication reply after this time (ms) */
60#define WLCORE_PEND_AUTH_ROC_TIMEOUT 1000
61
59struct wl127x_tx_mem { 62struct wl127x_tx_mem {
60 /* 63 /*
61 * Number of extra memory blocks to allocate for this packet 64 * Number of extra memory blocks to allocate for this packet
diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
index 0034979e97cb..54ce5d5e84db 100644
--- a/drivers/net/wireless/ti/wlcore/wlcore.h
+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
@@ -481,6 +481,8 @@ int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
481 struct ieee80211_sta *sta, 481 struct ieee80211_sta *sta,
482 struct ieee80211_key_conf *key_conf); 482 struct ieee80211_key_conf *key_conf);
483void wlcore_regdomain_config(struct wl1271 *wl); 483void wlcore_regdomain_config(struct wl1271 *wl);
484void wlcore_update_inconn_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif,
485 struct wl1271_station *wl_sta, bool in_conn);
484 486
485static inline void 487static inline void
486wlcore_set_ht_cap(struct wl1271 *wl, enum ieee80211_band band, 488wlcore_set_ht_cap(struct wl1271 *wl, enum ieee80211_band band,
diff --git a/drivers/net/wireless/ti/wlcore/wlcore_i.h b/drivers/net/wireless/ti/wlcore/wlcore_i.h
index e5e146435fe7..2a50e089b0e7 100644
--- a/drivers/net/wireless/ti/wlcore/wlcore_i.h
+++ b/drivers/net/wireless/ti/wlcore/wlcore_i.h
@@ -255,6 +255,7 @@ enum wl12xx_vif_flags {
255 WLVIF_FLAG_CS_PROGRESS, 255 WLVIF_FLAG_CS_PROGRESS,
256 WLVIF_FLAG_AP_PROBE_RESP_SET, 256 WLVIF_FLAG_AP_PROBE_RESP_SET,
257 WLVIF_FLAG_IN_USE, 257 WLVIF_FLAG_IN_USE,
258 WLVIF_FLAG_ACTIVE,
258}; 259};
259 260
260struct wl12xx_vif; 261struct wl12xx_vif;
@@ -307,6 +308,7 @@ enum plt_mode {
307 PLT_OFF = 0, 308 PLT_OFF = 0,
308 PLT_ON = 1, 309 PLT_ON = 1,
309 PLT_FEM_DETECT = 2, 310 PLT_FEM_DETECT = 2,
311 PLT_CHIP_AWAKE = 3
310}; 312};
311 313
312struct wl12xx_rx_filter_field { 314struct wl12xx_rx_filter_field {
@@ -456,6 +458,15 @@ struct wl12xx_vif {
456 */ 458 */
457 int hw_queue_base; 459 int hw_queue_base;
458 460
461 /* do we have a pending auth reply? (and ROC) */
462 bool ap_pending_auth_reply;
463
464 /* time when we sent the pending auth reply */
465 unsigned long pending_auth_reply_time;
466
467 /* work for canceling ROC after pending auth reply */
468 struct delayed_work pending_auth_complete_work;
469
459 /* 470 /*
460 * This struct must be last! 471 * This struct must be last!
461 * data that has to be saved acrossed reconfigs (e.g. recovery) 472 * data that has to be saved acrossed reconfigs (e.g. recovery)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 13d6c3929759..d0de412bfa43 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -197,8 +197,8 @@ static inline bool bdaddr_type_is_le(__u8 type)
197 return false; 197 return false;
198} 198}
199 199
200#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0} }) 200#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
201#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff} }) 201#define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
202 202
203/* Copy, swap, convert BD Address */ 203/* Copy, swap, convert BD Address */
204static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) 204static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
@@ -249,6 +249,7 @@ int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
249uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait); 249uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
250int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 250int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
251int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 251int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
252int bt_sock_wait_ready(struct sock *sk, unsigned long flags);
252 253
253void bt_accept_enqueue(struct sock *parent, struct sock *sk); 254void bt_accept_enqueue(struct sock *parent, struct sock *sk);
254void bt_accept_unlink(struct sock *sk); 255void bt_accept_unlink(struct sock *sk);
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 15f10841e2b5..b90eec5e9c06 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -35,6 +35,8 @@
35 35
36#define HCI_MAX_AMP_ASSOC_SIZE 672 36#define HCI_MAX_AMP_ASSOC_SIZE 672
37 37
38#define HCI_MAX_CSB_DATA_SIZE 252
39
38/* HCI dev events */ 40/* HCI dev events */
39#define HCI_DEV_REG 1 41#define HCI_DEV_REG 1
40#define HCI_DEV_UNREG 2 42#define HCI_DEV_UNREG 2
@@ -110,6 +112,7 @@ enum {
110 HCI_SERVICE_CACHE, 112 HCI_SERVICE_CACHE,
111 HCI_DEBUG_KEYS, 113 HCI_DEBUG_KEYS,
112 HCI_UNREGISTER, 114 HCI_UNREGISTER,
115 HCI_USER_CHANNEL,
113 116
114 HCI_LE_SCAN, 117 HCI_LE_SCAN,
115 HCI_SSP_ENABLED, 118 HCI_SSP_ENABLED,
@@ -121,6 +124,7 @@ enum {
121 HCI_LINK_SECURITY, 124 HCI_LINK_SECURITY,
122 HCI_PERIODIC_INQ, 125 HCI_PERIODIC_INQ,
123 HCI_FAST_CONNECTABLE, 126 HCI_FAST_CONNECTABLE,
127 HCI_BREDR_ENABLED,
124}; 128};
125 129
126/* A mask for the flags that are supposed to remain when a reset happens 130/* A mask for the flags that are supposed to remain when a reset happens
@@ -624,6 +628,24 @@ struct hci_rp_logical_link_cancel {
624 __u8 flow_spec_id; 628 __u8 flow_spec_id;
625} __packed; 629} __packed;
626 630
631#define HCI_OP_SET_CSB 0x0441
632struct hci_cp_set_csb {
633 __u8 enable;
634 __u8 lt_addr;
635 __u8 lpo_allowed;
636 __le16 packet_type;
637 __le16 interval_min;
638 __le16 interval_max;
639 __le16 csb_sv_tout;
640} __packed;
641struct hci_rp_set_csb {
642 __u8 status;
643 __u8 lt_addr;
644 __le16 interval;
645} __packed;
646
647#define HCI_OP_START_SYNC_TRAIN 0x0443
648
627#define HCI_OP_SNIFF_MODE 0x0803 649#define HCI_OP_SNIFF_MODE 0x0803
628struct hci_cp_sniff_mode { 650struct hci_cp_sniff_mode {
629 __le16 handle; 651 __le16 handle;
@@ -694,9 +716,6 @@ struct hci_cp_sniff_subrate {
694} __packed; 716} __packed;
695 717
696#define HCI_OP_SET_EVENT_MASK 0x0c01 718#define HCI_OP_SET_EVENT_MASK 0x0c01
697struct hci_cp_set_event_mask {
698 __u8 mask[8];
699} __packed;
700 719
701#define HCI_OP_RESET 0x0c03 720#define HCI_OP_RESET 0x0c03
702 721
@@ -826,6 +845,8 @@ struct hci_rp_read_inq_rsp_tx_power {
826 __s8 tx_power; 845 __s8 tx_power;
827} __packed; 846} __packed;
828 847
848#define HCI_OP_SET_EVENT_MASK_PAGE_2 0x0c63
849
829#define HCI_OP_READ_FLOW_CONTROL_MODE 0x0c66 850#define HCI_OP_READ_FLOW_CONTROL_MODE 0x0c66
830struct hci_rp_read_flow_control_mode { 851struct hci_rp_read_flow_control_mode {
831 __u8 status; 852 __u8 status;
@@ -838,6 +859,50 @@ struct hci_cp_write_le_host_supported {
838 __u8 simul; 859 __u8 simul;
839} __packed; 860} __packed;
840 861
862#define HCI_OP_SET_RESERVED_LT_ADDR 0x0c74
863struct hci_cp_set_reserved_lt_addr {
864 __u8 lt_addr;
865} __packed;
866struct hci_rp_set_reserved_lt_addr {
867 __u8 status;
868 __u8 lt_addr;
869} __packed;
870
871#define HCI_OP_DELETE_RESERVED_LT_ADDR 0x0c75
872struct hci_cp_delete_reserved_lt_addr {
873 __u8 lt_addr;
874} __packed;
875struct hci_rp_delete_reserved_lt_addr {
876 __u8 status;
877 __u8 lt_addr;
878} __packed;
879
880#define HCI_OP_SET_CSB_DATA 0x0c76
881struct hci_cp_set_csb_data {
882 __u8 lt_addr;
883 __u8 fragment;
884 __u8 data_length;
885 __u8 data[HCI_MAX_CSB_DATA_SIZE];
886} __packed;
887struct hci_rp_set_csb_data {
888 __u8 status;
889 __u8 lt_addr;
890} __packed;
891
892#define HCI_OP_READ_SYNC_TRAIN_PARAMS 0x0c77
893
894#define HCI_OP_WRITE_SYNC_TRAIN_PARAMS 0x0c78
895struct hci_cp_write_sync_train_params {
896 __le16 interval_min;
897 __le16 interval_max;
898 __le32 sync_train_tout;
899 __u8 service_data;
900} __packed;
901struct hci_rp_write_sync_train_params {
902 __u8 status;
903 __le16 sync_train_int;
904} __packed;
905
841#define HCI_OP_READ_LOCAL_VERSION 0x1001 906#define HCI_OP_READ_LOCAL_VERSION 0x1001
842struct hci_rp_read_local_version { 907struct hci_rp_read_local_version {
843 __u8 status; 908 __u8 status;
@@ -975,6 +1040,8 @@ struct hci_rp_le_read_local_features {
975 __u8 features[8]; 1040 __u8 features[8];
976} __packed; 1041} __packed;
977 1042
1043#define HCI_OP_LE_SET_RANDOM_ADDR 0x2005
1044
978#define HCI_OP_LE_READ_ADV_TX_POWER 0x2007 1045#define HCI_OP_LE_READ_ADV_TX_POWER 0x2007
979struct hci_rp_le_read_adv_tx_power { 1046struct hci_rp_le_read_adv_tx_power {
980 __u8 status; 1047 __u8 status;
@@ -1438,6 +1505,13 @@ struct hci_ev_num_comp_blocks {
1438 struct hci_comp_blocks_info handles[0]; 1505 struct hci_comp_blocks_info handles[0];
1439} __packed; 1506} __packed;
1440 1507
1508#define HCI_EV_SYNC_TRAIN_COMPLETE 0x4F
1509struct hci_ev_sync_train_complete {
1510 __u8 status;
1511} __packed;
1512
1513#define HCI_EV_SLAVE_PAGE_RESP_TIMEOUT 0x54
1514
1441/* Low energy meta events */ 1515/* Low energy meta events */
1442#define LE_CONN_ROLE_MASTER 0x00 1516#define LE_CONN_ROLE_MASTER 0x00
1443 1517
@@ -1571,6 +1645,7 @@ struct sockaddr_hci {
1571#define HCI_DEV_NONE 0xffff 1645#define HCI_DEV_NONE 0xffff
1572 1646
1573#define HCI_CHANNEL_RAW 0 1647#define HCI_CHANNEL_RAW 0
1648#define HCI_CHANNEL_USER 1
1574#define HCI_CHANNEL_MONITOR 2 1649#define HCI_CHANNEL_MONITOR 2
1575#define HCI_CHANNEL_CONTROL 3 1650#define HCI_CHANNEL_CONTROL 3
1576 1651
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 5769061e6533..e3ea48d6c992 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -140,6 +140,7 @@ struct hci_dev {
140 __u8 bus; 140 __u8 bus;
141 __u8 dev_type; 141 __u8 dev_type;
142 bdaddr_t bdaddr; 142 bdaddr_t bdaddr;
143 bdaddr_t static_addr;
143 __u8 dev_name[HCI_MAX_NAME_LENGTH]; 144 __u8 dev_name[HCI_MAX_NAME_LENGTH];
144 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; 145 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
145 __u8 eir[HCI_MAX_EIR_LENGTH]; 146 __u8 eir[HCI_MAX_EIR_LENGTH];
@@ -1167,7 +1168,6 @@ int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1167int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1168int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
1168int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 1169int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
1169 u8 *randomizer, u8 status); 1170 u8 *randomizer, u8 status);
1170int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
1171int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1171int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1172 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, 1172 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
1173 u8 ssp, u8 *eir, u16 eir_len); 1173 u8 ssp, u8 *eir, u16 eir_len);
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 1a966afbbfa8..f141b5f6e4f1 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -564,6 +564,7 @@ struct l2cap_conn {
564 564
565 __u32 feat_mask; 565 __u32 feat_mask;
566 __u8 fixed_chan_mask; 566 __u8 fixed_chan_mask;
567 bool hs_enabled;
567 568
568 __u8 info_state; 569 __u8 info_state;
569 __u8 info_ident; 570 __u8 info_ident;
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 9944c3e68c5d..2ad433bb9a2e 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -93,6 +93,7 @@ struct mgmt_rp_read_index_list {
93#define MGMT_SETTING_BREDR 0x00000080 93#define MGMT_SETTING_BREDR 0x00000080
94#define MGMT_SETTING_HS 0x00000100 94#define MGMT_SETTING_HS 0x00000100
95#define MGMT_SETTING_LE 0x00000200 95#define MGMT_SETTING_LE 0x00000200
96#define MGMT_SETTING_ADVERTISING 0x00000400
96 97
97#define MGMT_OP_READ_INFO 0x0004 98#define MGMT_OP_READ_INFO 0x0004
98#define MGMT_READ_INFO_SIZE 0 99#define MGMT_READ_INFO_SIZE 0
@@ -351,6 +352,16 @@ struct mgmt_cp_set_device_id {
351} __packed; 352} __packed;
352#define MGMT_SET_DEVICE_ID_SIZE 8 353#define MGMT_SET_DEVICE_ID_SIZE 8
353 354
355#define MGMT_OP_SET_ADVERTISING 0x0029
356
357#define MGMT_OP_SET_BREDR 0x002A
358
359#define MGMT_OP_SET_STATIC_ADDRESS 0x002B
360struct mgmt_cp_set_static_address {
361 bdaddr_t bdaddr;
362} __packed;
363#define MGMT_SET_STATIC_ADDRESS_SIZE 6
364
354#define MGMT_EV_CMD_COMPLETE 0x0001 365#define MGMT_EV_CMD_COMPLETE 0x0001
355struct mgmt_ev_cmd_complete { 366struct mgmt_ev_cmd_complete {
356 __le16 opcode; 367 __le16 opcode;
diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile
index dea6a287daca..6a791e73e39d 100644
--- a/net/bluetooth/Makefile
+++ b/net/bluetooth/Makefile
@@ -11,3 +11,5 @@ obj-$(CONFIG_BT_HIDP) += hidp/
11bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ 11bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
12 hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o \ 12 hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o \
13 a2mp.o amp.o 13 a2mp.o amp.o
14
15subdir-ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 9096137c889c..e6e1278dca89 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -490,6 +490,7 @@ int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
490} 490}
491EXPORT_SYMBOL(bt_sock_ioctl); 491EXPORT_SYMBOL(bt_sock_ioctl);
492 492
493/* This function expects the sk lock to be held when called */
493int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo) 494int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
494{ 495{
495 DECLARE_WAITQUEUE(wait, current); 496 DECLARE_WAITQUEUE(wait, current);
@@ -525,6 +526,46 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
525} 526}
526EXPORT_SYMBOL(bt_sock_wait_state); 527EXPORT_SYMBOL(bt_sock_wait_state);
527 528
529/* This function expects the sk lock to be held when called */
530int bt_sock_wait_ready(struct sock *sk, unsigned long flags)
531{
532 DECLARE_WAITQUEUE(wait, current);
533 unsigned long timeo;
534 int err = 0;
535
536 BT_DBG("sk %p", sk);
537
538 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
539
540 add_wait_queue(sk_sleep(sk), &wait);
541 set_current_state(TASK_INTERRUPTIBLE);
542 while (test_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags)) {
543 if (!timeo) {
544 err = -EAGAIN;
545 break;
546 }
547
548 if (signal_pending(current)) {
549 err = sock_intr_errno(timeo);
550 break;
551 }
552
553 release_sock(sk);
554 timeo = schedule_timeout(timeo);
555 lock_sock(sk);
556 set_current_state(TASK_INTERRUPTIBLE);
557
558 err = sock_error(sk);
559 if (err)
560 break;
561 }
562 __set_current_state(TASK_RUNNING);
563 remove_wait_queue(sk_sleep(sk), &wait);
564
565 return err;
566}
567EXPORT_SYMBOL(bt_sock_wait_ready);
568
528#ifdef CONFIG_PROC_FS 569#ifdef CONFIG_PROC_FS
529struct bt_seq_state { 570struct bt_seq_state {
530 struct bt_sock_list *l; 571 struct bt_sock_list *l;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index f0817121ec5e..514148b7a66b 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -518,6 +518,7 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
518 list_for_each_entry(d, &hci_dev_list, list) { 518 list_for_each_entry(d, &hci_dev_list, list) {
519 if (!test_bit(HCI_UP, &d->flags) || 519 if (!test_bit(HCI_UP, &d->flags) ||
520 test_bit(HCI_RAW, &d->flags) || 520 test_bit(HCI_RAW, &d->flags) ||
521 test_bit(HCI_USER_CHANNEL, &d->dev_flags) ||
521 d->dev_type != HCI_BREDR) 522 d->dev_type != HCI_BREDR)
522 continue; 523 continue;
523 524
@@ -580,6 +581,9 @@ static struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
580{ 581{
581 struct hci_conn *acl; 582 struct hci_conn *acl;
582 583
584 if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
585 return ERR_PTR(-ENOTSUPP);
586
583 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst); 587 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
584 if (!acl) { 588 if (!acl) {
585 acl = hci_conn_add(hdev, ACL_LINK, dst); 589 acl = hci_conn_add(hdev, ACL_LINK, dst);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index fb7356fcfe51..82dbdc6a7e9e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -519,6 +519,8 @@ static void hci_init2_req(struct hci_request *req, unsigned long opt)
519 519
520 if (lmp_bredr_capable(hdev)) 520 if (lmp_bredr_capable(hdev))
521 bredr_setup(req); 521 bredr_setup(req);
522 else
523 clear_bit(HCI_BREDR_ENABLED, &hdev->dev_flags);
522 524
523 if (lmp_le_capable(hdev)) 525 if (lmp_le_capable(hdev))
524 le_setup(req); 526 le_setup(req);
@@ -607,6 +609,34 @@ static void hci_set_le_support(struct hci_request *req)
607 &cp); 609 &cp);
608} 610}
609 611
612static void hci_set_event_mask_page_2(struct hci_request *req)
613{
614 struct hci_dev *hdev = req->hdev;
615 u8 events[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
616
617 /* If Connectionless Slave Broadcast master role is supported
618 * enable all necessary events for it.
619 */
620 if (hdev->features[2][0] & 0x01) {
621 events[1] |= 0x40; /* Triggered Clock Capture */
622 events[1] |= 0x80; /* Synchronization Train Complete */
623 events[2] |= 0x10; /* Slave Page Response Timeout */
624 events[2] |= 0x20; /* CSB Channel Map Change */
625 }
626
627 /* If Connectionless Slave Broadcast slave role is supported
628 * enable all necessary events for it.
629 */
630 if (hdev->features[2][0] & 0x02) {
631 events[2] |= 0x01; /* Synchronization Train Received */
632 events[2] |= 0x02; /* CSB Receive */
633 events[2] |= 0x04; /* CSB Timeout */
634 events[2] |= 0x08; /* Truncated Page Complete */
635 }
636
637 hci_req_add(req, HCI_OP_SET_EVENT_MASK_PAGE_2, sizeof(events), events);
638}
639
610static void hci_init3_req(struct hci_request *req, unsigned long opt) 640static void hci_init3_req(struct hci_request *req, unsigned long opt)
611{ 641{
612 struct hci_dev *hdev = req->hdev; 642 struct hci_dev *hdev = req->hdev;
@@ -648,6 +678,19 @@ static void hci_init3_req(struct hci_request *req, unsigned long opt)
648 } 678 }
649} 679}
650 680
681static void hci_init4_req(struct hci_request *req, unsigned long opt)
682{
683 struct hci_dev *hdev = req->hdev;
684
685 /* Set event mask page 2 if the HCI command for it is supported */
686 if (hdev->commands[22] & 0x04)
687 hci_set_event_mask_page_2(req);
688
689 /* Check for Synchronization Train support */
690 if (hdev->features[2][0] & 0x04)
691 hci_req_add(req, HCI_OP_READ_SYNC_TRAIN_PARAMS, 0, NULL);
692}
693
651static int __hci_init(struct hci_dev *hdev) 694static int __hci_init(struct hci_dev *hdev)
652{ 695{
653 int err; 696 int err;
@@ -667,7 +710,11 @@ static int __hci_init(struct hci_dev *hdev)
667 if (err < 0) 710 if (err < 0)
668 return err; 711 return err;
669 712
670 return __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT); 713 err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT);
714 if (err < 0)
715 return err;
716
717 return __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT);
671} 718}
672 719
673static void hci_scan_req(struct hci_request *req, unsigned long opt) 720static void hci_scan_req(struct hci_request *req, unsigned long opt)
@@ -984,6 +1031,16 @@ int hci_inquiry(void __user *arg)
984 if (!hdev) 1031 if (!hdev)
985 return -ENODEV; 1032 return -ENODEV;
986 1033
1034 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
1035 err = -EBUSY;
1036 goto done;
1037 }
1038
1039 if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
1040 err = -EOPNOTSUPP;
1041 goto done;
1042 }
1043
987 hci_dev_lock(hdev); 1044 hci_dev_lock(hdev);
988 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || 1045 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
989 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { 1046 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) {
@@ -1051,14 +1108,14 @@ static u8 create_ad(struct hci_dev *hdev, u8 *ptr)
1051 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) 1108 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags))
1052 flags |= LE_AD_GENERAL; 1109 flags |= LE_AD_GENERAL;
1053 1110
1054 if (!lmp_bredr_capable(hdev)) 1111 if (test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
1112 if (lmp_le_br_capable(hdev))
1113 flags |= LE_AD_SIM_LE_BREDR_CTRL;
1114 if (lmp_host_le_br_capable(hdev))
1115 flags |= LE_AD_SIM_LE_BREDR_HOST;
1116 } else {
1055 flags |= LE_AD_NO_BREDR; 1117 flags |= LE_AD_NO_BREDR;
1056 1118 }
1057 if (lmp_le_br_capable(hdev))
1058 flags |= LE_AD_SIM_LE_BREDR_CTRL;
1059
1060 if (lmp_host_le_br_capable(hdev))
1061 flags |= LE_AD_SIM_LE_BREDR_HOST;
1062 1119
1063 if (flags) { 1120 if (flags) {
1064 BT_DBG("adv flags 0x%02x", flags); 1121 BT_DBG("adv flags 0x%02x", flags);
@@ -1126,17 +1183,10 @@ void hci_update_ad(struct hci_request *req)
1126 hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp); 1183 hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
1127} 1184}
1128 1185
1129/* ---- HCI ioctl helpers ---- */ 1186static int hci_dev_do_open(struct hci_dev *hdev)
1130
1131int hci_dev_open(__u16 dev)
1132{ 1187{
1133 struct hci_dev *hdev;
1134 int ret = 0; 1188 int ret = 0;
1135 1189
1136 hdev = hci_dev_get(dev);
1137 if (!hdev)
1138 return -ENODEV;
1139
1140 BT_DBG("%s %p", hdev->name, hdev); 1190 BT_DBG("%s %p", hdev->name, hdev);
1141 1191
1142 hci_req_lock(hdev); 1192 hci_req_lock(hdev);
@@ -1172,16 +1222,11 @@ int hci_dev_open(__u16 dev)
1172 ret = hdev->setup(hdev); 1222 ret = hdev->setup(hdev);
1173 1223
1174 if (!ret) { 1224 if (!ret) {
1175 /* Treat all non BR/EDR controllers as raw devices if
1176 * enable_hs is not set.
1177 */
1178 if (hdev->dev_type != HCI_BREDR && !enable_hs)
1179 set_bit(HCI_RAW, &hdev->flags);
1180
1181 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) 1225 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
1182 set_bit(HCI_RAW, &hdev->flags); 1226 set_bit(HCI_RAW, &hdev->flags);
1183 1227
1184 if (!test_bit(HCI_RAW, &hdev->flags)) 1228 if (!test_bit(HCI_RAW, &hdev->flags) &&
1229 !test_bit(HCI_USER_CHANNEL, &hdev->dev_flags))
1185 ret = __hci_init(hdev); 1230 ret = __hci_init(hdev);
1186 } 1231 }
1187 1232
@@ -1192,6 +1237,7 @@ int hci_dev_open(__u16 dev)
1192 set_bit(HCI_UP, &hdev->flags); 1237 set_bit(HCI_UP, &hdev->flags);
1193 hci_notify(hdev, HCI_DEV_UP); 1238 hci_notify(hdev, HCI_DEV_UP);
1194 if (!test_bit(HCI_SETUP, &hdev->dev_flags) && 1239 if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
1240 !test_bit(HCI_USER_CHANNEL, &hdev->dev_flags) &&
1195 mgmt_valid_hdev(hdev)) { 1241 mgmt_valid_hdev(hdev)) {
1196 hci_dev_lock(hdev); 1242 hci_dev_lock(hdev);
1197 mgmt_powered(hdev, 1); 1243 mgmt_powered(hdev, 1);
@@ -1220,10 +1266,37 @@ int hci_dev_open(__u16 dev)
1220 1266
1221done: 1267done:
1222 hci_req_unlock(hdev); 1268 hci_req_unlock(hdev);
1223 hci_dev_put(hdev);
1224 return ret; 1269 return ret;
1225} 1270}
1226 1271
1272/* ---- HCI ioctl helpers ---- */
1273
1274int hci_dev_open(__u16 dev)
1275{
1276 struct hci_dev *hdev;
1277 int err;
1278
1279 hdev = hci_dev_get(dev);
1280 if (!hdev)
1281 return -ENODEV;
1282
1283 /* We need to ensure that no other power on/off work is pending
1284 * before proceeding to call hci_dev_do_open. This is
1285 * particularly important if the setup procedure has not yet
1286 * completed.
1287 */
1288 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags))
1289 cancel_delayed_work(&hdev->power_off);
1290
1291 flush_workqueue(hdev->req_workqueue);
1292
1293 err = hci_dev_do_open(hdev);
1294
1295 hci_dev_put(hdev);
1296
1297 return err;
1298}
1299
1227static int hci_dev_do_close(struct hci_dev *hdev) 1300static int hci_dev_do_close(struct hci_dev *hdev)
1228{ 1301{
1229 BT_DBG("%s %p", hdev->name, hdev); 1302 BT_DBG("%s %p", hdev->name, hdev);
@@ -1328,11 +1401,17 @@ int hci_dev_close(__u16 dev)
1328 if (!hdev) 1401 if (!hdev)
1329 return -ENODEV; 1402 return -ENODEV;
1330 1403
1404 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
1405 err = -EBUSY;
1406 goto done;
1407 }
1408
1331 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) 1409 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags))
1332 cancel_delayed_work(&hdev->power_off); 1410 cancel_delayed_work(&hdev->power_off);
1333 1411
1334 err = hci_dev_do_close(hdev); 1412 err = hci_dev_do_close(hdev);
1335 1413
1414done:
1336 hci_dev_put(hdev); 1415 hci_dev_put(hdev);
1337 return err; 1416 return err;
1338} 1417}
@@ -1348,8 +1427,15 @@ int hci_dev_reset(__u16 dev)
1348 1427
1349 hci_req_lock(hdev); 1428 hci_req_lock(hdev);
1350 1429
1351 if (!test_bit(HCI_UP, &hdev->flags)) 1430 if (!test_bit(HCI_UP, &hdev->flags)) {
1431 ret = -ENETDOWN;
1352 goto done; 1432 goto done;
1433 }
1434
1435 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
1436 ret = -EBUSY;
1437 goto done;
1438 }
1353 1439
1354 /* Drop queues */ 1440 /* Drop queues */
1355 skb_queue_purge(&hdev->rx_q); 1441 skb_queue_purge(&hdev->rx_q);
@@ -1384,10 +1470,15 @@ int hci_dev_reset_stat(__u16 dev)
1384 if (!hdev) 1470 if (!hdev)
1385 return -ENODEV; 1471 return -ENODEV;
1386 1472
1473 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
1474 ret = -EBUSY;
1475 goto done;
1476 }
1477
1387 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); 1478 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
1388 1479
1480done:
1389 hci_dev_put(hdev); 1481 hci_dev_put(hdev);
1390
1391 return ret; 1482 return ret;
1392} 1483}
1393 1484
@@ -1404,6 +1495,16 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
1404 if (!hdev) 1495 if (!hdev)
1405 return -ENODEV; 1496 return -ENODEV;
1406 1497
1498 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
1499 err = -EBUSY;
1500 goto done;
1501 }
1502
1503 if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
1504 err = -EOPNOTSUPP;
1505 goto done;
1506 }
1507
1407 switch (cmd) { 1508 switch (cmd) {
1408 case HCISETAUTH: 1509 case HCISETAUTH:
1409 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, 1510 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
@@ -1462,6 +1563,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
1462 break; 1563 break;
1463 } 1564 }
1464 1565
1566done:
1465 hci_dev_put(hdev); 1567 hci_dev_put(hdev);
1466 return err; 1568 return err;
1467} 1569}
@@ -1534,7 +1636,7 @@ int hci_get_dev_info(void __user *arg)
1534 1636
1535 strcpy(di.name, hdev->name); 1637 strcpy(di.name, hdev->name);
1536 di.bdaddr = hdev->bdaddr; 1638 di.bdaddr = hdev->bdaddr;
1537 di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4); 1639 di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4);
1538 di.flags = hdev->flags; 1640 di.flags = hdev->flags;
1539 di.pkt_type = hdev->pkt_type; 1641 di.pkt_type = hdev->pkt_type;
1540 if (lmp_bredr_capable(hdev)) { 1642 if (lmp_bredr_capable(hdev)) {
@@ -1570,6 +1672,9 @@ static int hci_rfkill_set_block(void *data, bool blocked)
1570 1672
1571 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); 1673 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked);
1572 1674
1675 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags))
1676 return -EBUSY;
1677
1573 if (blocked) { 1678 if (blocked) {
1574 set_bit(HCI_RFKILLED, &hdev->dev_flags); 1679 set_bit(HCI_RFKILLED, &hdev->dev_flags);
1575 if (!test_bit(HCI_SETUP, &hdev->dev_flags)) 1680 if (!test_bit(HCI_SETUP, &hdev->dev_flags))
@@ -1592,7 +1697,7 @@ static void hci_power_on(struct work_struct *work)
1592 1697
1593 BT_DBG("%s", hdev->name); 1698 BT_DBG("%s", hdev->name);
1594 1699
1595 err = hci_dev_open(hdev->id); 1700 err = hci_dev_do_open(hdev);
1596 if (err < 0) { 1701 if (err < 0) {
1597 mgmt_set_powered_failed(hdev, err); 1702 mgmt_set_powered_failed(hdev, err);
1598 return; 1703 return;
@@ -2225,8 +2330,13 @@ int hci_register_dev(struct hci_dev *hdev)
2225 2330
2226 set_bit(HCI_SETUP, &hdev->dev_flags); 2331 set_bit(HCI_SETUP, &hdev->dev_flags);
2227 2332
2228 if (hdev->dev_type != HCI_AMP) 2333 if (hdev->dev_type != HCI_AMP) {
2229 set_bit(HCI_AUTO_OFF, &hdev->dev_flags); 2334 set_bit(HCI_AUTO_OFF, &hdev->dev_flags);
2335 /* Assume BR/EDR support until proven otherwise (such as
2336 * through reading supported features during init.
2337 */
2338 set_bit(HCI_BREDR_ENABLED, &hdev->dev_flags);
2339 }
2230 2340
2231 write_lock(&hci_dev_list_lock); 2341 write_lock(&hci_dev_list_lock);
2232 list_add(&hdev->list, &hci_dev_list); 2342 list_add(&hdev->list, &hci_dev_list);
@@ -3272,15 +3382,13 @@ static void hci_tx_work(struct work_struct *work)
3272 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt, 3382 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt,
3273 hdev->sco_cnt, hdev->le_cnt); 3383 hdev->sco_cnt, hdev->le_cnt);
3274 3384
3275 /* Schedule queues and send stuff to HCI driver */ 3385 if (!test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
3276 3386 /* Schedule queues and send stuff to HCI driver */
3277 hci_sched_acl(hdev); 3387 hci_sched_acl(hdev);
3278 3388 hci_sched_sco(hdev);
3279 hci_sched_sco(hdev); 3389 hci_sched_esco(hdev);
3280 3390 hci_sched_le(hdev);
3281 hci_sched_esco(hdev); 3391 }
3282
3283 hci_sched_le(hdev);
3284 3392
3285 /* Send next queued raw (unknown type) packet */ 3393 /* Send next queued raw (unknown type) packet */
3286 while ((skb = skb_dequeue(&hdev->raw_q))) 3394 while ((skb = skb_dequeue(&hdev->raw_q)))
@@ -3471,7 +3579,8 @@ static void hci_rx_work(struct work_struct *work)
3471 hci_send_to_sock(hdev, skb); 3579 hci_send_to_sock(hdev, skb);
3472 } 3580 }
3473 3581
3474 if (test_bit(HCI_RAW, &hdev->flags)) { 3582 if (test_bit(HCI_RAW, &hdev->flags) ||
3583 test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
3475 kfree_skb(skb); 3584 kfree_skb(skb);
3476 continue; 3585 continue;
3477 } 3586 }
@@ -3526,7 +3635,7 @@ static void hci_cmd_work(struct work_struct *work)
3526 3635
3527 kfree_skb(hdev->sent_cmd); 3636 kfree_skb(hdev->sent_cmd);
3528 3637
3529 hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC); 3638 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
3530 if (hdev->sent_cmd) { 3639 if (hdev->sent_cmd) {
3531 atomic_dec(&hdev->cmd_cnt); 3640 atomic_dec(&hdev->cmd_cnt);
3532 hci_send_frame(skb); 3641 hci_send_frame(skb);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8db3e89fae35..4785ab0795f5 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -297,6 +297,11 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
297 goto done; 297 goto done;
298 } 298 }
299 299
300 /* We need to ensure that we set this back on if someone changed
301 * the scan mode through a raw HCI socket.
302 */
303 set_bit(HCI_BREDR_ENABLED, &hdev->dev_flags);
304
300 old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags); 305 old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
301 old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags); 306 old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
302 307
@@ -994,20 +999,20 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
994 return; 999 return;
995 1000
996 if (!status) { 1001 if (!status) {
997 if (sent->le) 1002 if (sent->le) {
998 hdev->features[1][0] |= LMP_HOST_LE; 1003 hdev->features[1][0] |= LMP_HOST_LE;
999 else 1004 set_bit(HCI_LE_ENABLED, &hdev->dev_flags);
1005 } else {
1000 hdev->features[1][0] &= ~LMP_HOST_LE; 1006 hdev->features[1][0] &= ~LMP_HOST_LE;
1007 clear_bit(HCI_LE_ENABLED, &hdev->dev_flags);
1008 clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
1009 }
1001 1010
1002 if (sent->simul) 1011 if (sent->simul)
1003 hdev->features[1][0] |= LMP_HOST_LE_BREDR; 1012 hdev->features[1][0] |= LMP_HOST_LE_BREDR;
1004 else 1013 else
1005 hdev->features[1][0] &= ~LMP_HOST_LE_BREDR; 1014 hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
1006 } 1015 }
1007
1008 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
1009 !test_bit(HCI_INIT, &hdev->flags))
1010 mgmt_le_enable_complete(hdev, sent->le, status);
1011} 1016}
1012 1017
1013static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev, 1018static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 9bd7d959e384..579886186c3a 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -66,6 +66,46 @@ static struct bt_sock_list hci_sk_list = {
66 .lock = __RW_LOCK_UNLOCKED(hci_sk_list.lock) 66 .lock = __RW_LOCK_UNLOCKED(hci_sk_list.lock)
67}; 67};
68 68
69static bool is_filtered_packet(struct sock *sk, struct sk_buff *skb)
70{
71 struct hci_filter *flt;
72 int flt_type, flt_event;
73
74 /* Apply filter */
75 flt = &hci_pi(sk)->filter;
76
77 if (bt_cb(skb)->pkt_type == HCI_VENDOR_PKT)
78 flt_type = 0;
79 else
80 flt_type = bt_cb(skb)->pkt_type & HCI_FLT_TYPE_BITS;
81
82 if (!test_bit(flt_type, &flt->type_mask))
83 return true;
84
85 /* Extra filter for event packets only */
86 if (bt_cb(skb)->pkt_type != HCI_EVENT_PKT)
87 return false;
88
89 flt_event = (*(__u8 *)skb->data & HCI_FLT_EVENT_BITS);
90
91 if (!hci_test_bit(flt_event, &flt->event_mask))
92 return true;
93
94 /* Check filter only when opcode is set */
95 if (!flt->opcode)
96 return false;
97
98 if (flt_event == HCI_EV_CMD_COMPLETE &&
99 flt->opcode != get_unaligned((__le16 *)(skb->data + 3)))
100 return true;
101
102 if (flt_event == HCI_EV_CMD_STATUS &&
103 flt->opcode != get_unaligned((__le16 *)(skb->data + 4)))
104 return true;
105
106 return false;
107}
108
69/* Send frame to RAW socket */ 109/* Send frame to RAW socket */
70void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb) 110void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
71{ 111{
@@ -77,7 +117,6 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
77 read_lock(&hci_sk_list.lock); 117 read_lock(&hci_sk_list.lock);
78 118
79 sk_for_each(sk, &hci_sk_list.head) { 119 sk_for_each(sk, &hci_sk_list.head) {
80 struct hci_filter *flt;
81 struct sk_buff *nskb; 120 struct sk_buff *nskb;
82 121
83 if (sk->sk_state != BT_BOUND || hci_pi(sk)->hdev != hdev) 122 if (sk->sk_state != BT_BOUND || hci_pi(sk)->hdev != hdev)
@@ -87,31 +126,19 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
87 if (skb->sk == sk) 126 if (skb->sk == sk)
88 continue; 127 continue;
89 128
90 if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) 129 if (hci_pi(sk)->channel == HCI_CHANNEL_RAW) {
91 continue; 130 if (is_filtered_packet(sk, skb))
92
93 /* Apply filter */
94 flt = &hci_pi(sk)->filter;
95
96 if (!test_bit((bt_cb(skb)->pkt_type == HCI_VENDOR_PKT) ?
97 0 : (bt_cb(skb)->pkt_type & HCI_FLT_TYPE_BITS),
98 &flt->type_mask))
99 continue;
100
101 if (bt_cb(skb)->pkt_type == HCI_EVENT_PKT) {
102 int evt = (*(__u8 *)skb->data & HCI_FLT_EVENT_BITS);
103
104 if (!hci_test_bit(evt, &flt->event_mask))
105 continue; 131 continue;
106 132 } else if (hci_pi(sk)->channel == HCI_CHANNEL_USER) {
107 if (flt->opcode && 133 if (!bt_cb(skb)->incoming)
108 ((evt == HCI_EV_CMD_COMPLETE && 134 continue;
109 flt->opcode != 135 if (bt_cb(skb)->pkt_type != HCI_EVENT_PKT &&
110 get_unaligned((__le16 *)(skb->data + 3))) || 136 bt_cb(skb)->pkt_type != HCI_ACLDATA_PKT &&
111 (evt == HCI_EV_CMD_STATUS && 137 bt_cb(skb)->pkt_type != HCI_SCODATA_PKT)
112 flt->opcode !=
113 get_unaligned((__le16 *)(skb->data + 4)))))
114 continue; 138 continue;
139 } else {
140 /* Don't send frame to other channel types */
141 continue;
115 } 142 }
116 143
117 if (!skb_copy) { 144 if (!skb_copy) {
@@ -426,6 +453,12 @@ static int hci_sock_release(struct socket *sock)
426 bt_sock_unlink(&hci_sk_list, sk); 453 bt_sock_unlink(&hci_sk_list, sk);
427 454
428 if (hdev) { 455 if (hdev) {
456 if (hci_pi(sk)->channel == HCI_CHANNEL_USER) {
457 mgmt_index_added(hdev);
458 clear_bit(HCI_USER_CHANNEL, &hdev->dev_flags);
459 hci_dev_close(hdev->id);
460 }
461
429 atomic_dec(&hdev->promisc); 462 atomic_dec(&hdev->promisc);
430 hci_dev_put(hdev); 463 hci_dev_put(hdev);
431 } 464 }
@@ -482,6 +515,9 @@ static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd,
482 if (!hdev) 515 if (!hdev)
483 return -EBADFD; 516 return -EBADFD;
484 517
518 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags))
519 return -EBUSY;
520
485 switch (cmd) { 521 switch (cmd) {
486 case HCISETRAW: 522 case HCISETRAW:
487 if (!capable(CAP_NET_ADMIN)) 523 if (!capable(CAP_NET_ADMIN))
@@ -512,23 +548,32 @@ static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd,
512 if (!capable(CAP_NET_ADMIN)) 548 if (!capable(CAP_NET_ADMIN))
513 return -EPERM; 549 return -EPERM;
514 return hci_sock_blacklist_del(hdev, (void __user *) arg); 550 return hci_sock_blacklist_del(hdev, (void __user *) arg);
515
516 default:
517 if (hdev->ioctl)
518 return hdev->ioctl(hdev, cmd, arg);
519 return -EINVAL;
520 } 551 }
552
553 if (hdev->ioctl)
554 return hdev->ioctl(hdev, cmd, arg);
555
556 return -EINVAL;
521} 557}
522 558
523static int hci_sock_ioctl(struct socket *sock, unsigned int cmd, 559static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
524 unsigned long arg) 560 unsigned long arg)
525{ 561{
526 struct sock *sk = sock->sk;
527 void __user *argp = (void __user *) arg; 562 void __user *argp = (void __user *) arg;
563 struct sock *sk = sock->sk;
528 int err; 564 int err;
529 565
530 BT_DBG("cmd %x arg %lx", cmd, arg); 566 BT_DBG("cmd %x arg %lx", cmd, arg);
531 567
568 lock_sock(sk);
569
570 if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {
571 err = -EBADFD;
572 goto done;
573 }
574
575 release_sock(sk);
576
532 switch (cmd) { 577 switch (cmd) {
533 case HCIGETDEVLIST: 578 case HCIGETDEVLIST:
534 return hci_get_dev_list(argp); 579 return hci_get_dev_list(argp);
@@ -573,13 +618,15 @@ static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
573 618
574 case HCIINQUIRY: 619 case HCIINQUIRY:
575 return hci_inquiry(argp); 620 return hci_inquiry(argp);
576
577 default:
578 lock_sock(sk);
579 err = hci_sock_bound_ioctl(sk, cmd, arg);
580 release_sock(sk);
581 return err;
582 } 621 }
622
623 lock_sock(sk);
624
625 err = hci_sock_bound_ioctl(sk, cmd, arg);
626
627done:
628 release_sock(sk);
629 return err;
583} 630}
584 631
585static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, 632static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
@@ -629,6 +676,56 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
629 hci_pi(sk)->hdev = hdev; 676 hci_pi(sk)->hdev = hdev;
630 break; 677 break;
631 678
679 case HCI_CHANNEL_USER:
680 if (hci_pi(sk)->hdev) {
681 err = -EALREADY;
682 goto done;
683 }
684
685 if (haddr.hci_dev == HCI_DEV_NONE) {
686 err = -EINVAL;
687 goto done;
688 }
689
690 if (!capable(CAP_NET_ADMIN)) {
691 err = -EPERM;
692 goto done;
693 }
694
695 hdev = hci_dev_get(haddr.hci_dev);
696 if (!hdev) {
697 err = -ENODEV;
698 goto done;
699 }
700
701 if (test_bit(HCI_UP, &hdev->flags) ||
702 test_bit(HCI_INIT, &hdev->flags) ||
703 test_bit(HCI_SETUP, &hdev->dev_flags)) {
704 err = -EBUSY;
705 hci_dev_put(hdev);
706 goto done;
707 }
708
709 if (test_and_set_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
710 err = -EUSERS;
711 hci_dev_put(hdev);
712 goto done;
713 }
714
715 mgmt_index_removed(hdev);
716
717 err = hci_dev_open(hdev->id);
718 if (err) {
719 clear_bit(HCI_USER_CHANNEL, &hdev->dev_flags);
720 hci_dev_put(hdev);
721 goto done;
722 }
723
724 atomic_inc(&hdev->promisc);
725
726 hci_pi(sk)->hdev = hdev;
727 break;
728
632 case HCI_CHANNEL_CONTROL: 729 case HCI_CHANNEL_CONTROL:
633 if (haddr.hci_dev != HCI_DEV_NONE) { 730 if (haddr.hci_dev != HCI_DEV_NONE) {
634 err = -EINVAL; 731 err = -EINVAL;
@@ -677,22 +774,30 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr,
677{ 774{
678 struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr; 775 struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr;
679 struct sock *sk = sock->sk; 776 struct sock *sk = sock->sk;
680 struct hci_dev *hdev = hci_pi(sk)->hdev; 777 struct hci_dev *hdev;
778 int err = 0;
681 779
682 BT_DBG("sock %p sk %p", sock, sk); 780 BT_DBG("sock %p sk %p", sock, sk);
683 781
684 if (!hdev) 782 if (peer)
685 return -EBADFD; 783 return -EOPNOTSUPP;
686 784
687 lock_sock(sk); 785 lock_sock(sk);
688 786
787 hdev = hci_pi(sk)->hdev;
788 if (!hdev) {
789 err = -EBADFD;
790 goto done;
791 }
792
689 *addr_len = sizeof(*haddr); 793 *addr_len = sizeof(*haddr);
690 haddr->hci_family = AF_BLUETOOTH; 794 haddr->hci_family = AF_BLUETOOTH;
691 haddr->hci_dev = hdev->id; 795 haddr->hci_dev = hdev->id;
692 haddr->hci_channel= 0; 796 haddr->hci_channel= hci_pi(sk)->channel;
693 797
798done:
694 release_sock(sk); 799 release_sock(sk);
695 return 0; 800 return err;
696} 801}
697 802
698static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, 803static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg,
@@ -767,6 +872,7 @@ static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
767 case HCI_CHANNEL_RAW: 872 case HCI_CHANNEL_RAW:
768 hci_sock_cmsg(sk, msg, skb); 873 hci_sock_cmsg(sk, msg, skb);
769 break; 874 break;
875 case HCI_CHANNEL_USER:
770 case HCI_CHANNEL_CONTROL: 876 case HCI_CHANNEL_CONTROL:
771 case HCI_CHANNEL_MONITOR: 877 case HCI_CHANNEL_MONITOR:
772 sock_recv_timestamp(msg, sk, skb); 878 sock_recv_timestamp(msg, sk, skb);
@@ -801,6 +907,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
801 907
802 switch (hci_pi(sk)->channel) { 908 switch (hci_pi(sk)->channel) {
803 case HCI_CHANNEL_RAW: 909 case HCI_CHANNEL_RAW:
910 case HCI_CHANNEL_USER:
804 break; 911 break;
805 case HCI_CHANNEL_CONTROL: 912 case HCI_CHANNEL_CONTROL:
806 err = mgmt_control(sk, msg, len); 913 err = mgmt_control(sk, msg, len);
@@ -837,7 +944,8 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
837 skb_pull(skb, 1); 944 skb_pull(skb, 1);
838 skb->dev = (void *) hdev; 945 skb->dev = (void *) hdev;
839 946
840 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { 947 if (hci_pi(sk)->channel == HCI_CHANNEL_RAW &&
948 bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
841 u16 opcode = get_unaligned_le16(skb->data); 949 u16 opcode = get_unaligned_le16(skb->data);
842 u16 ogf = hci_opcode_ogf(opcode); 950 u16 ogf = hci_opcode_ogf(opcode);
843 u16 ocf = hci_opcode_ocf(opcode); 951 u16 ocf = hci_opcode_ocf(opcode);
@@ -868,6 +976,14 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
868 goto drop; 976 goto drop;
869 } 977 }
870 978
979 if (hci_pi(sk)->channel == HCI_CHANNEL_USER &&
980 bt_cb(skb)->pkt_type != HCI_COMMAND_PKT &&
981 bt_cb(skb)->pkt_type != HCI_ACLDATA_PKT &&
982 bt_cb(skb)->pkt_type != HCI_SCODATA_PKT) {
983 err = -EINVAL;
984 goto drop;
985 }
986
871 skb_queue_tail(&hdev->raw_q, skb); 987 skb_queue_tail(&hdev->raw_q, skb);
872 queue_work(hdev->workqueue, &hdev->tx_work); 988 queue_work(hdev->workqueue, &hdev->tx_work);
873 } 989 }
@@ -895,7 +1011,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
895 lock_sock(sk); 1011 lock_sock(sk);
896 1012
897 if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) { 1013 if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {
898 err = -EINVAL; 1014 err = -EBADFD;
899 goto done; 1015 goto done;
900 } 1016 }
901 1017
@@ -981,7 +1097,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
981 lock_sock(sk); 1097 lock_sock(sk);
982 1098
983 if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) { 1099 if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {
984 err = -EINVAL; 1100 err = -EBADFD;
985 goto done; 1101 goto done;
986 } 1102 }
987 1103
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 63fa11109a1c..02dba4e6df96 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1016,13 +1016,12 @@ static bool __amp_capable(struct l2cap_chan *chan)
1016{ 1016{
1017 struct l2cap_conn *conn = chan->conn; 1017 struct l2cap_conn *conn = chan->conn;
1018 1018
1019 if (enable_hs && 1019 if (conn->hs_enabled && hci_amp_capable() &&
1020 hci_amp_capable() &&
1021 chan->chan_policy == BT_CHANNEL_POLICY_AMP_PREFERRED && 1020 chan->chan_policy == BT_CHANNEL_POLICY_AMP_PREFERRED &&
1022 conn->fixed_chan_mask & L2CAP_FC_A2MP) 1021 conn->fixed_chan_mask & L2CAP_FC_A2MP)
1023 return true; 1022 return true;
1024 else 1023
1025 return false; 1024 return false;
1026} 1025}
1027 1026
1028static bool l2cap_check_efs(struct l2cap_chan *chan) 1027static bool l2cap_check_efs(struct l2cap_chan *chan)
@@ -1638,6 +1637,10 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
1638 1637
1639 conn->feat_mask = 0; 1638 conn->feat_mask = 0;
1640 1639
1640 if (hcon->type == ACL_LINK)
1641 conn->hs_enabled = test_bit(HCI_HS_ENABLED,
1642 &hcon->hdev->dev_flags);
1643
1641 spin_lock_init(&conn->lock); 1644 spin_lock_init(&conn->lock);
1642 mutex_init(&conn->chan_lock); 1645 mutex_init(&conn->chan_lock);
1643 1646
@@ -3084,14 +3087,14 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
3084 } 3087 }
3085} 3088}
3086 3089
3087static inline bool __l2cap_ews_supported(struct l2cap_chan *chan) 3090static inline bool __l2cap_ews_supported(struct l2cap_conn *conn)
3088{ 3091{
3089 return enable_hs && chan->conn->feat_mask & L2CAP_FEAT_EXT_WINDOW; 3092 return conn->hs_enabled && conn->feat_mask & L2CAP_FEAT_EXT_WINDOW;
3090} 3093}
3091 3094
3092static inline bool __l2cap_efs_supported(struct l2cap_chan *chan) 3095static inline bool __l2cap_efs_supported(struct l2cap_conn *conn)
3093{ 3096{
3094 return enable_hs && chan->conn->feat_mask & L2CAP_FEAT_EXT_FLOW; 3097 return conn->hs_enabled && conn->feat_mask & L2CAP_FEAT_EXT_FLOW;
3095} 3098}
3096 3099
3097static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan, 3100static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan,
@@ -3135,7 +3138,7 @@ static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan,
3135static inline void l2cap_txwin_setup(struct l2cap_chan *chan) 3138static inline void l2cap_txwin_setup(struct l2cap_chan *chan)
3136{ 3139{
3137 if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW && 3140 if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW &&
3138 __l2cap_ews_supported(chan)) { 3141 __l2cap_ews_supported(chan->conn)) {
3139 /* use extended control field */ 3142 /* use extended control field */
3140 set_bit(FLAG_EXT_CTRL, &chan->flags); 3143 set_bit(FLAG_EXT_CTRL, &chan->flags);
3141 chan->tx_win_max = L2CAP_DEFAULT_EXT_WINDOW; 3144 chan->tx_win_max = L2CAP_DEFAULT_EXT_WINDOW;
@@ -3165,7 +3168,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
3165 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state)) 3168 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state))
3166 break; 3169 break;
3167 3170
3168 if (__l2cap_efs_supported(chan)) 3171 if (__l2cap_efs_supported(chan->conn))
3169 set_bit(FLAG_EFS_ENABLE, &chan->flags); 3172 set_bit(FLAG_EFS_ENABLE, &chan->flags);
3170 3173
3171 /* fall through */ 3174 /* fall through */
@@ -3317,7 +3320,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
3317 break; 3320 break;
3318 3321
3319 case L2CAP_CONF_EWS: 3322 case L2CAP_CONF_EWS:
3320 if (!enable_hs) 3323 if (!chan->conn->hs_enabled)
3321 return -ECONNREFUSED; 3324 return -ECONNREFUSED;
3322 3325
3323 set_bit(FLAG_EXT_CTRL, &chan->flags); 3326 set_bit(FLAG_EXT_CTRL, &chan->flags);
@@ -3349,7 +3352,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
3349 } 3352 }
3350 3353
3351 if (remote_efs) { 3354 if (remote_efs) {
3352 if (__l2cap_efs_supported(chan)) 3355 if (__l2cap_efs_supported(chan->conn))
3353 set_bit(FLAG_EFS_ENABLE, &chan->flags); 3356 set_bit(FLAG_EFS_ENABLE, &chan->flags);
3354 else 3357 else
3355 return -ECONNREFUSED; 3358 return -ECONNREFUSED;
@@ -3891,13 +3894,13 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,
3891 if (scid) { 3894 if (scid) {
3892 chan = __l2cap_get_chan_by_scid(conn, scid); 3895 chan = __l2cap_get_chan_by_scid(conn, scid);
3893 if (!chan) { 3896 if (!chan) {
3894 err = -EFAULT; 3897 err = -EBADSLT;
3895 goto unlock; 3898 goto unlock;
3896 } 3899 }
3897 } else { 3900 } else {
3898 chan = __l2cap_get_chan_by_ident(conn, cmd->ident); 3901 chan = __l2cap_get_chan_by_ident(conn, cmd->ident);
3899 if (!chan) { 3902 if (!chan) {
3900 err = -EFAULT; 3903 err = -EBADSLT;
3901 goto unlock; 3904 goto unlock;
3902 } 3905 }
3903 } 3906 }
@@ -3985,7 +3988,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
3985 3988
3986 chan = l2cap_get_chan_by_scid(conn, dcid); 3989 chan = l2cap_get_chan_by_scid(conn, dcid);
3987 if (!chan) 3990 if (!chan)
3988 return -ENOENT; 3991 return -EBADSLT;
3989 3992
3990 if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) { 3993 if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) {
3991 struct l2cap_cmd_rej_cid rej; 3994 struct l2cap_cmd_rej_cid rej;
@@ -4213,7 +4216,7 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
4213 chan = __l2cap_get_chan_by_scid(conn, dcid); 4216 chan = __l2cap_get_chan_by_scid(conn, dcid);
4214 if (!chan) { 4217 if (!chan) {
4215 mutex_unlock(&conn->chan_lock); 4218 mutex_unlock(&conn->chan_lock);
4216 return 0; 4219 return -EBADSLT;
4217 } 4220 }
4218 4221
4219 l2cap_chan_lock(chan); 4222 l2cap_chan_lock(chan);
@@ -4303,7 +4306,7 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
4303 if (!disable_ertm) 4306 if (!disable_ertm)
4304 feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING 4307 feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING
4305 | L2CAP_FEAT_FCS; 4308 | L2CAP_FEAT_FCS;
4306 if (enable_hs) 4309 if (conn->hs_enabled)
4307 feat_mask |= L2CAP_FEAT_EXT_FLOW 4310 feat_mask |= L2CAP_FEAT_EXT_FLOW
4308 | L2CAP_FEAT_EXT_WINDOW; 4311 | L2CAP_FEAT_EXT_WINDOW;
4309 4312
@@ -4314,7 +4317,7 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
4314 u8 buf[12]; 4317 u8 buf[12];
4315 struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf; 4318 struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf;
4316 4319
4317 if (enable_hs) 4320 if (conn->hs_enabled)
4318 l2cap_fixed_chan[0] |= L2CAP_FC_A2MP; 4321 l2cap_fixed_chan[0] |= L2CAP_FC_A2MP;
4319 else 4322 else
4320 l2cap_fixed_chan[0] &= ~L2CAP_FC_A2MP; 4323 l2cap_fixed_chan[0] &= ~L2CAP_FC_A2MP;
@@ -4411,7 +4414,7 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
4411 if (cmd_len != sizeof(*req)) 4414 if (cmd_len != sizeof(*req))
4412 return -EPROTO; 4415 return -EPROTO;
4413 4416
4414 if (!enable_hs) 4417 if (!conn->hs_enabled)
4415 return -EINVAL; 4418 return -EINVAL;
4416 4419
4417 psm = le16_to_cpu(req->psm); 4420 psm = le16_to_cpu(req->psm);
@@ -4445,7 +4448,7 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
4445 hs_hcon = hci_conn_hash_lookup_ba(hdev, AMP_LINK, conn->dst); 4448 hs_hcon = hci_conn_hash_lookup_ba(hdev, AMP_LINK, conn->dst);
4446 if (!hs_hcon) { 4449 if (!hs_hcon) {
4447 hci_dev_put(hdev); 4450 hci_dev_put(hdev);
4448 return -EFAULT; 4451 return -EBADSLT;
4449 } 4452 }
4450 4453
4451 BT_DBG("mgr %p bredr_chan %p hs_hcon %p", mgr, chan, hs_hcon); 4454 BT_DBG("mgr %p bredr_chan %p hs_hcon %p", mgr, chan, hs_hcon);
@@ -4469,7 +4472,7 @@ error:
4469 l2cap_send_cmd(conn, cmd->ident, L2CAP_CREATE_CHAN_RSP, 4472 l2cap_send_cmd(conn, cmd->ident, L2CAP_CREATE_CHAN_RSP,
4470 sizeof(rsp), &rsp); 4473 sizeof(rsp), &rsp);
4471 4474
4472 return -EFAULT; 4475 return 0;
4473} 4476}
4474 4477
4475static void l2cap_send_move_chan_req(struct l2cap_chan *chan, u8 dest_amp_id) 4478static void l2cap_send_move_chan_req(struct l2cap_chan *chan, u8 dest_amp_id)
@@ -4838,7 +4841,7 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn,
4838 4841
4839 BT_DBG("icid 0x%4.4x, dest_amp_id %d", icid, req->dest_amp_id); 4842 BT_DBG("icid 0x%4.4x, dest_amp_id %d", icid, req->dest_amp_id);
4840 4843
4841 if (!enable_hs) 4844 if (!conn->hs_enabled)
4842 return -EINVAL; 4845 return -EINVAL;
4843 4846
4844 chan = l2cap_get_chan_by_dcid(conn, icid); 4847 chan = l2cap_get_chan_by_dcid(conn, icid);
@@ -5219,7 +5222,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
5219 5222
5220 case L2CAP_CONN_RSP: 5223 case L2CAP_CONN_RSP:
5221 case L2CAP_CREATE_CHAN_RSP: 5224 case L2CAP_CREATE_CHAN_RSP:
5222 err = l2cap_connect_create_rsp(conn, cmd, cmd_len, data); 5225 l2cap_connect_create_rsp(conn, cmd, cmd_len, data);
5223 break; 5226 break;
5224 5227
5225 case L2CAP_CONF_REQ: 5228 case L2CAP_CONF_REQ:
@@ -5227,7 +5230,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
5227 break; 5230 break;
5228 5231
5229 case L2CAP_CONF_RSP: 5232 case L2CAP_CONF_RSP:
5230 err = l2cap_config_rsp(conn, cmd, cmd_len, data); 5233 l2cap_config_rsp(conn, cmd, cmd_len, data);
5231 break; 5234 break;
5232 5235
5233 case L2CAP_DISCONN_REQ: 5236 case L2CAP_DISCONN_REQ:
@@ -5235,7 +5238,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
5235 break; 5238 break;
5236 5239
5237 case L2CAP_DISCONN_RSP: 5240 case L2CAP_DISCONN_RSP:
5238 err = l2cap_disconnect_rsp(conn, cmd, cmd_len, data); 5241 l2cap_disconnect_rsp(conn, cmd, cmd_len, data);
5239 break; 5242 break;
5240 5243
5241 case L2CAP_ECHO_REQ: 5244 case L2CAP_ECHO_REQ:
@@ -5250,7 +5253,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
5250 break; 5253 break;
5251 5254
5252 case L2CAP_INFO_RSP: 5255 case L2CAP_INFO_RSP:
5253 err = l2cap_information_rsp(conn, cmd, cmd_len, data); 5256 l2cap_information_rsp(conn, cmd, cmd_len, data);
5254 break; 5257 break;
5255 5258
5256 case L2CAP_CREATE_CHAN_REQ: 5259 case L2CAP_CREATE_CHAN_REQ:
@@ -5262,7 +5265,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
5262 break; 5265 break;
5263 5266
5264 case L2CAP_MOVE_CHAN_RSP: 5267 case L2CAP_MOVE_CHAN_RSP:
5265 err = l2cap_move_channel_rsp(conn, cmd, cmd_len, data); 5268 l2cap_move_channel_rsp(conn, cmd, cmd_len, data);
5266 break; 5269 break;
5267 5270
5268 case L2CAP_MOVE_CHAN_CFM: 5271 case L2CAP_MOVE_CHAN_CFM:
@@ -5270,7 +5273,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
5270 break; 5273 break;
5271 5274
5272 case L2CAP_MOVE_CHAN_CFM_RSP: 5275 case L2CAP_MOVE_CHAN_CFM_RSP:
5273 err = l2cap_move_channel_confirm_rsp(conn, cmd, cmd_len, data); 5276 l2cap_move_channel_confirm_rsp(conn, cmd, cmd_len, data);
5274 break; 5277 break;
5275 5278
5276 default: 5279 default:
@@ -5301,54 +5304,65 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
5301 } 5304 }
5302} 5305}
5303 5306
5307static __le16 l2cap_err_to_reason(int err)
5308{
5309 switch (err) {
5310 case -EBADSLT:
5311 return __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
5312 case -EMSGSIZE:
5313 return __constant_cpu_to_le16(L2CAP_REJ_MTU_EXCEEDED);
5314 case -EINVAL:
5315 case -EPROTO:
5316 default:
5317 return __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
5318 }
5319}
5320
5304static inline void l2cap_le_sig_channel(struct l2cap_conn *conn, 5321static inline void l2cap_le_sig_channel(struct l2cap_conn *conn,
5305 struct sk_buff *skb) 5322 struct sk_buff *skb)
5306{ 5323{
5307 u8 *data = skb->data; 5324 struct hci_conn *hcon = conn->hcon;
5308 int len = skb->len; 5325 struct l2cap_cmd_hdr *cmd;
5309 struct l2cap_cmd_hdr cmd; 5326 u16 len;
5310 int err; 5327 int err;
5311 5328
5312 l2cap_raw_recv(conn, skb); 5329 if (hcon->type != LE_LINK)
5330 goto drop;
5313 5331
5314 while (len >= L2CAP_CMD_HDR_SIZE) { 5332 if (skb->len < L2CAP_CMD_HDR_SIZE)
5315 u16 cmd_len; 5333 goto drop;
5316 memcpy(&cmd, data, L2CAP_CMD_HDR_SIZE);
5317 data += L2CAP_CMD_HDR_SIZE;
5318 len -= L2CAP_CMD_HDR_SIZE;
5319 5334
5320 cmd_len = le16_to_cpu(cmd.len); 5335 cmd = (void *) skb->data;
5336 skb_pull(skb, L2CAP_CMD_HDR_SIZE);
5321 5337
5322 BT_DBG("code 0x%2.2x len %d id 0x%2.2x", cmd.code, cmd_len, 5338 len = le16_to_cpu(cmd->len);
5323 cmd.ident);
5324 5339
5325 if (cmd_len > len || !cmd.ident) { 5340 BT_DBG("code 0x%2.2x len %d id 0x%2.2x", cmd->code, len, cmd->ident);
5326 BT_DBG("corrupted command");
5327 break;
5328 }
5329 5341
5330 err = l2cap_le_sig_cmd(conn, &cmd, data); 5342 if (len != skb->len || !cmd->ident) {
5331 if (err) { 5343 BT_DBG("corrupted command");
5332 struct l2cap_cmd_rej_unk rej; 5344 goto drop;
5345 }
5333 5346
5334 BT_ERR("Wrong link type (%d)", err); 5347 err = l2cap_le_sig_cmd(conn, cmd, skb->data);
5348 if (err) {
5349 struct l2cap_cmd_rej_unk rej;
5335 5350
5336 /* FIXME: Map err to a valid reason */ 5351 BT_ERR("Wrong link type (%d)", err);
5337 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
5338 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ,
5339 sizeof(rej), &rej);
5340 }
5341 5352
5342 data += cmd_len; 5353 rej.reason = l2cap_err_to_reason(err);
5343 len -= cmd_len; 5354 l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ,
5355 sizeof(rej), &rej);
5344 } 5356 }
5345 5357
5358drop:
5346 kfree_skb(skb); 5359 kfree_skb(skb);
5347} 5360}
5348 5361
5349static inline void l2cap_sig_channel(struct l2cap_conn *conn, 5362static inline void l2cap_sig_channel(struct l2cap_conn *conn,
5350 struct sk_buff *skb) 5363 struct sk_buff *skb)
5351{ 5364{
5365 struct hci_conn *hcon = conn->hcon;
5352 u8 *data = skb->data; 5366 u8 *data = skb->data;
5353 int len = skb->len; 5367 int len = skb->len;
5354 struct l2cap_cmd_hdr cmd; 5368 struct l2cap_cmd_hdr cmd;
@@ -5356,6 +5370,9 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
5356 5370
5357 l2cap_raw_recv(conn, skb); 5371 l2cap_raw_recv(conn, skb);
5358 5372
5373 if (hcon->type != ACL_LINK)
5374 goto drop;
5375
5359 while (len >= L2CAP_CMD_HDR_SIZE) { 5376 while (len >= L2CAP_CMD_HDR_SIZE) {
5360 u16 cmd_len; 5377 u16 cmd_len;
5361 memcpy(&cmd, data, L2CAP_CMD_HDR_SIZE); 5378 memcpy(&cmd, data, L2CAP_CMD_HDR_SIZE);
@@ -5378,8 +5395,7 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
5378 5395
5379 BT_ERR("Wrong link type (%d)", err); 5396 BT_ERR("Wrong link type (%d)", err);
5380 5397
5381 /* FIXME: Map err to a valid reason */ 5398 rej.reason = l2cap_err_to_reason(err);
5382 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
5383 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ, 5399 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ,
5384 sizeof(rej), &rej); 5400 sizeof(rej), &rej);
5385 } 5401 }
@@ -5388,6 +5404,7 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
5388 len -= cmd_len; 5404 len -= cmd_len;
5389 } 5405 }
5390 5406
5407drop:
5391 kfree_skb(skb); 5408 kfree_skb(skb);
5392} 5409}
5393 5410
@@ -5784,7 +5801,7 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,
5784 struct sk_buff *skb, u8 event) 5801 struct sk_buff *skb, u8 event)
5785{ 5802{
5786 int err = 0; 5803 int err = 0;
5787 bool skb_in_use = 0; 5804 bool skb_in_use = false;
5788 5805
5789 BT_DBG("chan %p, control %p, skb %p, event %d", chan, control, skb, 5806 BT_DBG("chan %p, control %p, skb %p, event %d", chan, control, skb,
5790 event); 5807 event);
@@ -5805,7 +5822,7 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,
5805 control->txseq); 5822 control->txseq);
5806 5823
5807 chan->buffer_seq = chan->expected_tx_seq; 5824 chan->buffer_seq = chan->expected_tx_seq;
5808 skb_in_use = 1; 5825 skb_in_use = true;
5809 5826
5810 err = l2cap_reassemble_sdu(chan, skb, control); 5827 err = l2cap_reassemble_sdu(chan, skb, control);
5811 if (err) 5828 if (err)
@@ -5841,7 +5858,7 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,
5841 * current frame is stored for later use. 5858 * current frame is stored for later use.
5842 */ 5859 */
5843 skb_queue_tail(&chan->srej_q, skb); 5860 skb_queue_tail(&chan->srej_q, skb);
5844 skb_in_use = 1; 5861 skb_in_use = true;
5845 BT_DBG("Queued %p (queue len %d)", skb, 5862 BT_DBG("Queued %p (queue len %d)", skb,
5846 skb_queue_len(&chan->srej_q)); 5863 skb_queue_len(&chan->srej_q));
5847 5864
@@ -5919,7 +5936,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
5919{ 5936{
5920 int err = 0; 5937 int err = 0;
5921 u16 txseq = control->txseq; 5938 u16 txseq = control->txseq;
5922 bool skb_in_use = 0; 5939 bool skb_in_use = false;
5923 5940
5924 BT_DBG("chan %p, control %p, skb %p, event %d", chan, control, skb, 5941 BT_DBG("chan %p, control %p, skb %p, event %d", chan, control, skb,
5925 event); 5942 event);
@@ -5931,7 +5948,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
5931 /* Keep frame for reassembly later */ 5948 /* Keep frame for reassembly later */
5932 l2cap_pass_to_tx(chan, control); 5949 l2cap_pass_to_tx(chan, control);
5933 skb_queue_tail(&chan->srej_q, skb); 5950 skb_queue_tail(&chan->srej_q, skb);
5934 skb_in_use = 1; 5951 skb_in_use = true;
5935 BT_DBG("Queued %p (queue len %d)", skb, 5952 BT_DBG("Queued %p (queue len %d)", skb,
5936 skb_queue_len(&chan->srej_q)); 5953 skb_queue_len(&chan->srej_q));
5937 5954
@@ -5942,7 +5959,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
5942 5959
5943 l2cap_pass_to_tx(chan, control); 5960 l2cap_pass_to_tx(chan, control);
5944 skb_queue_tail(&chan->srej_q, skb); 5961 skb_queue_tail(&chan->srej_q, skb);
5945 skb_in_use = 1; 5962 skb_in_use = true;
5946 BT_DBG("Queued %p (queue len %d)", skb, 5963 BT_DBG("Queued %p (queue len %d)", skb,
5947 skb_queue_len(&chan->srej_q)); 5964 skb_queue_len(&chan->srej_q));
5948 5965
@@ -5957,7 +5974,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
5957 * the missing frames. 5974 * the missing frames.
5958 */ 5975 */
5959 skb_queue_tail(&chan->srej_q, skb); 5976 skb_queue_tail(&chan->srej_q, skb);
5960 skb_in_use = 1; 5977 skb_in_use = true;
5961 BT_DBG("Queued %p (queue len %d)", skb, 5978 BT_DBG("Queued %p (queue len %d)", skb,
5962 skb_queue_len(&chan->srej_q)); 5979 skb_queue_len(&chan->srej_q));
5963 5980
@@ -5971,7 +5988,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
5971 * SREJ'd frames. 5988 * SREJ'd frames.
5972 */ 5989 */
5973 skb_queue_tail(&chan->srej_q, skb); 5990 skb_queue_tail(&chan->srej_q, skb);
5974 skb_in_use = 1; 5991 skb_in_use = true;
5975 BT_DBG("Queued %p (queue len %d)", skb, 5992 BT_DBG("Queued %p (queue len %d)", skb,
5976 skb_queue_len(&chan->srej_q)); 5993 skb_queue_len(&chan->srej_q));
5977 5994
@@ -6380,8 +6397,12 @@ done:
6380static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm, 6397static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
6381 struct sk_buff *skb) 6398 struct sk_buff *skb)
6382{ 6399{
6400 struct hci_conn *hcon = conn->hcon;
6383 struct l2cap_chan *chan; 6401 struct l2cap_chan *chan;
6384 6402
6403 if (hcon->type != ACL_LINK)
6404 goto drop;
6405
6385 chan = l2cap_global_chan_by_psm(0, psm, conn->src, conn->dst); 6406 chan = l2cap_global_chan_by_psm(0, psm, conn->src, conn->dst);
6386 if (!chan) 6407 if (!chan)
6387 goto drop; 6408 goto drop;
@@ -6404,8 +6425,12 @@ drop:
6404static void l2cap_att_channel(struct l2cap_conn *conn, 6425static void l2cap_att_channel(struct l2cap_conn *conn,
6405 struct sk_buff *skb) 6426 struct sk_buff *skb)
6406{ 6427{
6428 struct hci_conn *hcon = conn->hcon;
6407 struct l2cap_chan *chan; 6429 struct l2cap_chan *chan;
6408 6430
6431 if (hcon->type != LE_LINK)
6432 goto drop;
6433
6409 chan = l2cap_global_chan_by_scid(BT_CONNECTED, L2CAP_CID_ATT, 6434 chan = l2cap_global_chan_by_scid(BT_CONNECTED, L2CAP_CID_ATT,
6410 conn->src, conn->dst); 6435 conn->src, conn->dst);
6411 if (!chan) 6436 if (!chan)
@@ -6441,9 +6466,6 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
6441 BT_DBG("len %d, cid 0x%4.4x", len, cid); 6466 BT_DBG("len %d, cid 0x%4.4x", len, cid);
6442 6467
6443 switch (cid) { 6468 switch (cid) {
6444 case L2CAP_CID_LE_SIGNALING:
6445 l2cap_le_sig_channel(conn, skb);
6446 break;
6447 case L2CAP_CID_SIGNALING: 6469 case L2CAP_CID_SIGNALING:
6448 l2cap_sig_channel(conn, skb); 6470 l2cap_sig_channel(conn, skb);
6449 break; 6471 break;
@@ -6458,6 +6480,10 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
6458 l2cap_att_channel(conn, skb); 6480 l2cap_att_channel(conn, skb);
6459 break; 6481 break;
6460 6482
6483 case L2CAP_CID_LE_SIGNALING:
6484 l2cap_le_sig_channel(conn, skb);
6485 break;
6486
6461 case L2CAP_CID_SMP: 6487 case L2CAP_CID_SMP:
6462 if (smp_sig_channel(conn, skb)) 6488 if (smp_sig_channel(conn, skb))
6463 l2cap_conn_del(conn->hcon, EACCES); 6489 l2cap_conn_del(conn->hcon, EACCES);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 0098af80b213..9119898ef040 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -445,11 +445,6 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
445 break; 445 break;
446 446
447 case BT_CHANNEL_POLICY: 447 case BT_CHANNEL_POLICY:
448 if (!enable_hs) {
449 err = -ENOPROTOOPT;
450 break;
451 }
452
453 if (put_user(chan->chan_policy, (u32 __user *) optval)) 448 if (put_user(chan->chan_policy, (u32 __user *) optval))
454 err = -EFAULT; 449 err = -EFAULT;
455 break; 450 break;
@@ -720,11 +715,6 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
720 break; 715 break;
721 716
722 case BT_CHANNEL_POLICY: 717 case BT_CHANNEL_POLICY:
723 if (!enable_hs) {
724 err = -ENOPROTOOPT;
725 break;
726 }
727
728 if (get_user(opt, (u32 __user *) optval)) { 718 if (get_user(opt, (u32 __user *) optval)) {
729 err = -EFAULT; 719 err = -EFAULT;
730 break; 720 break;
@@ -777,6 +767,12 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
777 if (sk->sk_state != BT_CONNECTED) 767 if (sk->sk_state != BT_CONNECTED)
778 return -ENOTCONN; 768 return -ENOTCONN;
779 769
770 lock_sock(sk);
771 err = bt_sock_wait_ready(sk, msg->msg_flags);
772 release_sock(sk);
773 if (err)
774 return err;
775
780 l2cap_chan_lock(chan); 776 l2cap_chan_lock(chan);
781 err = l2cap_chan_send(chan, msg, len, sk->sk_priority); 777 err = l2cap_chan_send(chan, msg, len, sk->sk_priority);
782 l2cap_chan_unlock(chan); 778 l2cap_chan_unlock(chan);
@@ -799,8 +795,8 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
799 pi->chan->state = BT_CONFIG; 795 pi->chan->state = BT_CONFIG;
800 796
801 __l2cap_connect_rsp_defer(pi->chan); 797 __l2cap_connect_rsp_defer(pi->chan);
802 release_sock(sk); 798 err = 0;
803 return 0; 799 goto done;
804 } 800 }
805 801
806 release_sock(sk); 802 release_sock(sk);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index fedc5399d465..16125ff918f1 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -32,10 +32,8 @@
32#include <net/bluetooth/mgmt.h> 32#include <net/bluetooth/mgmt.h>
33#include <net/bluetooth/smp.h> 33#include <net/bluetooth/smp.h>
34 34
35bool enable_hs;
36
37#define MGMT_VERSION 1 35#define MGMT_VERSION 1
38#define MGMT_REVISION 3 36#define MGMT_REVISION 4
39 37
40static const u16 mgmt_commands[] = { 38static const u16 mgmt_commands[] = {
41 MGMT_OP_READ_INDEX_LIST, 39 MGMT_OP_READ_INDEX_LIST,
@@ -76,6 +74,9 @@ static const u16 mgmt_commands[] = {
76 MGMT_OP_BLOCK_DEVICE, 74 MGMT_OP_BLOCK_DEVICE,
77 MGMT_OP_UNBLOCK_DEVICE, 75 MGMT_OP_UNBLOCK_DEVICE,
78 MGMT_OP_SET_DEVICE_ID, 76 MGMT_OP_SET_DEVICE_ID,
77 MGMT_OP_SET_ADVERTISING,
78 MGMT_OP_SET_BREDR,
79 MGMT_OP_SET_STATIC_ADDRESS,
79}; 80};
80 81
81static const u16 mgmt_events[] = { 82static const u16 mgmt_events[] = {
@@ -339,6 +340,9 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data,
339 if (test_bit(HCI_SETUP, &d->dev_flags)) 340 if (test_bit(HCI_SETUP, &d->dev_flags))
340 continue; 341 continue;
341 342
343 if (test_bit(HCI_USER_CHANNEL, &d->dev_flags))
344 continue;
345
342 if (!mgmt_valid_hdev(d)) 346 if (!mgmt_valid_hdev(d))
343 continue; 347 continue;
344 348
@@ -376,13 +380,13 @@ static u32 get_supported_settings(struct hci_dev *hdev)
376 settings |= MGMT_SETTING_DISCOVERABLE; 380 settings |= MGMT_SETTING_DISCOVERABLE;
377 settings |= MGMT_SETTING_BREDR; 381 settings |= MGMT_SETTING_BREDR;
378 settings |= MGMT_SETTING_LINK_SECURITY; 382 settings |= MGMT_SETTING_LINK_SECURITY;
379 }
380
381 if (enable_hs)
382 settings |= MGMT_SETTING_HS; 383 settings |= MGMT_SETTING_HS;
384 }
383 385
384 if (lmp_le_capable(hdev)) 386 if (lmp_le_capable(hdev)) {
385 settings |= MGMT_SETTING_LE; 387 settings |= MGMT_SETTING_LE;
388 settings |= MGMT_SETTING_ADVERTISING;
389 }
386 390
387 return settings; 391 return settings;
388} 392}
@@ -406,7 +410,7 @@ static u32 get_current_settings(struct hci_dev *hdev)
406 if (test_bit(HCI_PAIRABLE, &hdev->dev_flags)) 410 if (test_bit(HCI_PAIRABLE, &hdev->dev_flags))
407 settings |= MGMT_SETTING_PAIRABLE; 411 settings |= MGMT_SETTING_PAIRABLE;
408 412
409 if (lmp_bredr_capable(hdev)) 413 if (test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
410 settings |= MGMT_SETTING_BREDR; 414 settings |= MGMT_SETTING_BREDR;
411 415
412 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) 416 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
@@ -421,6 +425,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
421 if (test_bit(HCI_HS_ENABLED, &hdev->dev_flags)) 425 if (test_bit(HCI_HS_ENABLED, &hdev->dev_flags))
422 settings |= MGMT_SETTING_HS; 426 settings |= MGMT_SETTING_HS;
423 427
428 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags))
429 settings |= MGMT_SETTING_ADVERTISING;
430
424 return settings; 431 return settings;
425} 432}
426 433
@@ -804,6 +811,12 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
804 811
805 hci_dev_lock(hdev); 812 hci_dev_lock(hdev);
806 813
814 if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) {
815 err = cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
816 MGMT_STATUS_BUSY);
817 goto failed;
818 }
819
807 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) { 820 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) {
808 cancel_delayed_work(&hdev->power_off); 821 cancel_delayed_work(&hdev->power_off);
809 822
@@ -820,12 +833,6 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
820 goto failed; 833 goto failed;
821 } 834 }
822 835
823 if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) {
824 err = cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
825 MGMT_STATUS_BUSY);
826 goto failed;
827 }
828
829 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); 836 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len);
830 if (!cmd) { 837 if (!cmd) {
831 err = -ENOMEM; 838 err = -ENOMEM;
@@ -883,20 +890,71 @@ static int new_settings(struct hci_dev *hdev, struct sock *skip)
883 return mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), skip); 890 return mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), skip);
884} 891}
885 892
893struct cmd_lookup {
894 struct sock *sk;
895 struct hci_dev *hdev;
896 u8 mgmt_status;
897};
898
899static void settings_rsp(struct pending_cmd *cmd, void *data)
900{
901 struct cmd_lookup *match = data;
902
903 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev);
904
905 list_del(&cmd->list);
906
907 if (match->sk == NULL) {
908 match->sk = cmd->sk;
909 sock_hold(match->sk);
910 }
911
912 mgmt_pending_free(cmd);
913}
914
915static void cmd_status_rsp(struct pending_cmd *cmd, void *data)
916{
917 u8 *status = data;
918
919 cmd_status(cmd->sk, cmd->index, cmd->opcode, *status);
920 mgmt_pending_remove(cmd);
921}
922
923static u8 mgmt_bredr_support(struct hci_dev *hdev)
924{
925 if (!lmp_bredr_capable(hdev))
926 return MGMT_STATUS_NOT_SUPPORTED;
927 else if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
928 return MGMT_STATUS_REJECTED;
929 else
930 return MGMT_STATUS_SUCCESS;
931}
932
933static u8 mgmt_le_support(struct hci_dev *hdev)
934{
935 if (!lmp_le_capable(hdev))
936 return MGMT_STATUS_NOT_SUPPORTED;
937 else if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
938 return MGMT_STATUS_REJECTED;
939 else
940 return MGMT_STATUS_SUCCESS;
941}
942
886static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, 943static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
887 u16 len) 944 u16 len)
888{ 945{
889 struct mgmt_cp_set_discoverable *cp = data; 946 struct mgmt_cp_set_discoverable *cp = data;
890 struct pending_cmd *cmd; 947 struct pending_cmd *cmd;
891 u16 timeout; 948 u16 timeout;
892 u8 scan; 949 u8 scan, status;
893 int err; 950 int err;
894 951
895 BT_DBG("request for %s", hdev->name); 952 BT_DBG("request for %s", hdev->name);
896 953
897 if (!lmp_bredr_capable(hdev)) 954 status = mgmt_bredr_support(hdev);
955 if (status)
898 return cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 956 return cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
899 MGMT_STATUS_NOT_SUPPORTED); 957 status);
900 958
901 if (cp->val != 0x00 && cp->val != 0x01) 959 if (cp->val != 0x00 && cp->val != 0x01)
902 return cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 960 return cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
@@ -1045,14 +1103,15 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
1045 struct mgmt_mode *cp = data; 1103 struct mgmt_mode *cp = data;
1046 struct pending_cmd *cmd; 1104 struct pending_cmd *cmd;
1047 struct hci_request req; 1105 struct hci_request req;
1048 u8 scan; 1106 u8 scan, status;
1049 int err; 1107 int err;
1050 1108
1051 BT_DBG("request for %s", hdev->name); 1109 BT_DBG("request for %s", hdev->name);
1052 1110
1053 if (!lmp_bredr_capable(hdev)) 1111 status = mgmt_bredr_support(hdev);
1112 if (status)
1054 return cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, 1113 return cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE,
1055 MGMT_STATUS_NOT_SUPPORTED); 1114 status);
1056 1115
1057 if (cp->val != 0x00 && cp->val != 0x01) 1116 if (cp->val != 0x00 && cp->val != 0x01)
1058 return cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, 1117 return cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE,
@@ -1168,14 +1227,15 @@ static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data,
1168{ 1227{
1169 struct mgmt_mode *cp = data; 1228 struct mgmt_mode *cp = data;
1170 struct pending_cmd *cmd; 1229 struct pending_cmd *cmd;
1171 u8 val; 1230 u8 val, status;
1172 int err; 1231 int err;
1173 1232
1174 BT_DBG("request for %s", hdev->name); 1233 BT_DBG("request for %s", hdev->name);
1175 1234
1176 if (!lmp_bredr_capable(hdev)) 1235 status = mgmt_bredr_support(hdev);
1236 if (status)
1177 return cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, 1237 return cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY,
1178 MGMT_STATUS_NOT_SUPPORTED); 1238 status);
1179 1239
1180 if (cp->val != 0x00 && cp->val != 0x01) 1240 if (cp->val != 0x00 && cp->val != 0x01)
1181 return cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, 1241 return cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY,
@@ -1236,11 +1296,15 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1236{ 1296{
1237 struct mgmt_mode *cp = data; 1297 struct mgmt_mode *cp = data;
1238 struct pending_cmd *cmd; 1298 struct pending_cmd *cmd;
1239 u8 val; 1299 u8 val, status;
1240 int err; 1300 int err;
1241 1301
1242 BT_DBG("request for %s", hdev->name); 1302 BT_DBG("request for %s", hdev->name);
1243 1303
1304 status = mgmt_bredr_support(hdev);
1305 if (status)
1306 return cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status);
1307
1244 if (!lmp_ssp_capable(hdev)) 1308 if (!lmp_ssp_capable(hdev))
1245 return cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, 1309 return cmd_status(sk, hdev->id, MGMT_OP_SET_SSP,
1246 MGMT_STATUS_NOT_SUPPORTED); 1310 MGMT_STATUS_NOT_SUPPORTED);
@@ -1302,23 +1366,64 @@ failed:
1302static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) 1366static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1303{ 1367{
1304 struct mgmt_mode *cp = data; 1368 struct mgmt_mode *cp = data;
1369 bool changed;
1370 u8 status;
1371 int err;
1305 1372
1306 BT_DBG("request for %s", hdev->name); 1373 BT_DBG("request for %s", hdev->name);
1307 1374
1308 if (!enable_hs) 1375 status = mgmt_bredr_support(hdev);
1309 return cmd_status(sk, hdev->id, MGMT_OP_SET_HS, 1376 if (status)
1310 MGMT_STATUS_NOT_SUPPORTED); 1377 return cmd_status(sk, hdev->id, MGMT_OP_SET_HS, status);
1311 1378
1312 if (cp->val != 0x00 && cp->val != 0x01) 1379 if (cp->val != 0x00 && cp->val != 0x01)
1313 return cmd_status(sk, hdev->id, MGMT_OP_SET_HS, 1380 return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
1314 MGMT_STATUS_INVALID_PARAMS); 1381 MGMT_STATUS_INVALID_PARAMS);
1315 1382
1316 if (cp->val) 1383 hci_dev_lock(hdev);
1317 set_bit(HCI_HS_ENABLED, &hdev->dev_flags); 1384
1318 else 1385 if (cp->val) {
1319 clear_bit(HCI_HS_ENABLED, &hdev->dev_flags); 1386 changed = !test_and_set_bit(HCI_HS_ENABLED, &hdev->dev_flags);
1387 } else {
1388 if (hdev_is_powered(hdev)) {
1389 err = cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
1390 MGMT_STATUS_REJECTED);
1391 goto unlock;
1392 }
1393
1394 changed = test_and_clear_bit(HCI_HS_ENABLED, &hdev->dev_flags);
1395 }
1396
1397 err = send_settings_rsp(sk, MGMT_OP_SET_HS, hdev);
1398 if (err < 0)
1399 goto unlock;
1400
1401 if (changed)
1402 err = new_settings(hdev, sk);
1403
1404unlock:
1405 hci_dev_unlock(hdev);
1406 return err;
1407}
1408
1409static void le_enable_complete(struct hci_dev *hdev, u8 status)
1410{
1411 struct cmd_lookup match = { NULL, hdev };
1320 1412
1321 return send_settings_rsp(sk, MGMT_OP_SET_HS, hdev); 1413 if (status) {
1414 u8 mgmt_err = mgmt_status(status);
1415
1416 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp,
1417 &mgmt_err);
1418 return;
1419 }
1420
1421 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match);
1422
1423 new_settings(hdev, match.sk);
1424
1425 if (match.sk)
1426 sock_put(match.sk);
1322} 1427}
1323 1428
1324static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) 1429static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
@@ -1326,6 +1431,7 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1326 struct mgmt_mode *cp = data; 1431 struct mgmt_mode *cp = data;
1327 struct hci_cp_write_le_host_supported hci_cp; 1432 struct hci_cp_write_le_host_supported hci_cp;
1328 struct pending_cmd *cmd; 1433 struct pending_cmd *cmd;
1434 struct hci_request req;
1329 int err; 1435 int err;
1330 u8 val, enabled; 1436 u8 val, enabled;
1331 1437
@@ -1340,7 +1446,7 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1340 MGMT_STATUS_INVALID_PARAMS); 1446 MGMT_STATUS_INVALID_PARAMS);
1341 1447
1342 /* LE-only devices do not allow toggling LE on/off */ 1448 /* LE-only devices do not allow toggling LE on/off */
1343 if (!lmp_bredr_capable(hdev)) 1449 if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
1344 return cmd_status(sk, hdev->id, MGMT_OP_SET_LE, 1450 return cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
1345 MGMT_STATUS_REJECTED); 1451 MGMT_STATUS_REJECTED);
1346 1452
@@ -1357,6 +1463,11 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1357 changed = true; 1463 changed = true;
1358 } 1464 }
1359 1465
1466 if (!val && test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) {
1467 clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
1468 changed = true;
1469 }
1470
1360 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); 1471 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev);
1361 if (err < 0) 1472 if (err < 0)
1362 goto unlock; 1473 goto unlock;
@@ -1367,7 +1478,8 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1367 goto unlock; 1478 goto unlock;
1368 } 1479 }
1369 1480
1370 if (mgmt_pending_find(MGMT_OP_SET_LE, hdev)) { 1481 if (mgmt_pending_find(MGMT_OP_SET_LE, hdev) ||
1482 mgmt_pending_find(MGMT_OP_SET_ADVERTISING, hdev)) {
1371 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE, 1483 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
1372 MGMT_STATUS_BUSY); 1484 MGMT_STATUS_BUSY);
1373 goto unlock; 1485 goto unlock;
@@ -1386,8 +1498,15 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1386 hci_cp.simul = lmp_le_br_capable(hdev); 1498 hci_cp.simul = lmp_le_br_capable(hdev);
1387 } 1499 }
1388 1500
1389 err = hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp), 1501 hci_req_init(&req, hdev);
1390 &hci_cp); 1502
1503 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags) && !val)
1504 hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(val), &val);
1505
1506 hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
1507 &hci_cp);
1508
1509 err = hci_req_run(&req, le_enable_complete);
1391 if (err < 0) 1510 if (err < 0)
1392 mgmt_pending_remove(cmd); 1511 mgmt_pending_remove(cmd);
1393 1512
@@ -1706,6 +1825,12 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
1706 u16 key_count, expected_len; 1825 u16 key_count, expected_len;
1707 int i; 1826 int i;
1708 1827
1828 BT_DBG("request for %s", hdev->name);
1829
1830 if (!lmp_bredr_capable(hdev))
1831 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS,
1832 MGMT_STATUS_NOT_SUPPORTED);
1833
1709 key_count = __le16_to_cpu(cp->key_count); 1834 key_count = __le16_to_cpu(cp->key_count);
1710 1835
1711 expected_len = sizeof(*cp) + key_count * 1836 expected_len = sizeof(*cp) + key_count *
@@ -2685,6 +2810,7 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2685 struct hci_request req; 2810 struct hci_request req;
2686 /* General inquiry access code (GIAC) */ 2811 /* General inquiry access code (GIAC) */
2687 u8 lap[3] = { 0x33, 0x8b, 0x9e }; 2812 u8 lap[3] = { 0x33, 0x8b, 0x9e };
2813 u8 status;
2688 int err; 2814 int err;
2689 2815
2690 BT_DBG("%s", hdev->name); 2816 BT_DBG("%s", hdev->name);
@@ -2721,9 +2847,10 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2721 2847
2722 switch (hdev->discovery.type) { 2848 switch (hdev->discovery.type) {
2723 case DISCOV_TYPE_BREDR: 2849 case DISCOV_TYPE_BREDR:
2724 if (!lmp_bredr_capable(hdev)) { 2850 status = mgmt_bredr_support(hdev);
2851 if (status) {
2725 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 2852 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
2726 MGMT_STATUS_NOT_SUPPORTED); 2853 status);
2727 mgmt_pending_remove(cmd); 2854 mgmt_pending_remove(cmd);
2728 goto failed; 2855 goto failed;
2729 } 2856 }
@@ -2745,15 +2872,16 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2745 2872
2746 case DISCOV_TYPE_LE: 2873 case DISCOV_TYPE_LE:
2747 case DISCOV_TYPE_INTERLEAVED: 2874 case DISCOV_TYPE_INTERLEAVED:
2748 if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { 2875 status = mgmt_le_support(hdev);
2876 if (status) {
2749 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 2877 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
2750 MGMT_STATUS_NOT_SUPPORTED); 2878 status);
2751 mgmt_pending_remove(cmd); 2879 mgmt_pending_remove(cmd);
2752 goto failed; 2880 goto failed;
2753 } 2881 }
2754 2882
2755 if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED && 2883 if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED &&
2756 !lmp_bredr_capable(hdev)) { 2884 !test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
2757 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 2885 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
2758 MGMT_STATUS_NOT_SUPPORTED); 2886 MGMT_STATUS_NOT_SUPPORTED);
2759 mgmt_pending_remove(cmd); 2887 mgmt_pending_remove(cmd);
@@ -3065,6 +3193,135 @@ static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,
3065 return err; 3193 return err;
3066} 3194}
3067 3195
3196static void set_advertising_complete(struct hci_dev *hdev, u8 status)
3197{
3198 struct cmd_lookup match = { NULL, hdev };
3199
3200 if (status) {
3201 u8 mgmt_err = mgmt_status(status);
3202
3203 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev,
3204 cmd_status_rsp, &mgmt_err);
3205 return;
3206 }
3207
3208 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp,
3209 &match);
3210
3211 new_settings(hdev, match.sk);
3212
3213 if (match.sk)
3214 sock_put(match.sk);
3215}
3216
3217static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
3218{
3219 struct mgmt_mode *cp = data;
3220 struct pending_cmd *cmd;
3221 struct hci_request req;
3222 u8 val, enabled, status;
3223 int err;
3224
3225 BT_DBG("request for %s", hdev->name);
3226
3227 status = mgmt_le_support(hdev);
3228 if (status)
3229 return cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
3230 status);
3231
3232 if (cp->val != 0x00 && cp->val != 0x01)
3233 return cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
3234 MGMT_STATUS_INVALID_PARAMS);
3235
3236 hci_dev_lock(hdev);
3237
3238 val = !!cp->val;
3239 enabled = test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
3240
3241 if (!hdev_is_powered(hdev) || val == enabled) {
3242 bool changed = false;
3243
3244 if (val != test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) {
3245 change_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
3246 changed = true;
3247 }
3248
3249 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev);
3250 if (err < 0)
3251 goto unlock;
3252
3253 if (changed)
3254 err = new_settings(hdev, sk);
3255
3256 goto unlock;
3257 }
3258
3259 if (mgmt_pending_find(MGMT_OP_SET_ADVERTISING, hdev) ||
3260 mgmt_pending_find(MGMT_OP_SET_LE, hdev)) {
3261 err = cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
3262 MGMT_STATUS_BUSY);
3263 goto unlock;
3264 }
3265
3266 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len);
3267 if (!cmd) {
3268 err = -ENOMEM;
3269 goto unlock;
3270 }
3271
3272 hci_req_init(&req, hdev);
3273
3274 hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(val), &val);
3275
3276 err = hci_req_run(&req, set_advertising_complete);
3277 if (err < 0)
3278 mgmt_pending_remove(cmd);
3279
3280unlock:
3281 hci_dev_unlock(hdev);
3282 return err;
3283}
3284
3285static int set_static_address(struct sock *sk, struct hci_dev *hdev,
3286 void *data, u16 len)
3287{
3288 struct mgmt_cp_set_static_address *cp = data;
3289 int err;
3290
3291 BT_DBG("%s", hdev->name);
3292
3293 if (!lmp_le_capable(hdev))
3294 return cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
3295 MGMT_STATUS_NOT_SUPPORTED);
3296
3297 if (hdev_is_powered(hdev))
3298 return cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
3299 MGMT_STATUS_REJECTED);
3300
3301 if (bacmp(&cp->bdaddr, BDADDR_ANY)) {
3302 if (!bacmp(&cp->bdaddr, BDADDR_NONE))
3303 return cmd_status(sk, hdev->id,
3304 MGMT_OP_SET_STATIC_ADDRESS,
3305 MGMT_STATUS_INVALID_PARAMS);
3306
3307 /* Two most significant bits shall be set */
3308 if ((cp->bdaddr.b[5] & 0xc0) != 0xc0)
3309 return cmd_status(sk, hdev->id,
3310 MGMT_OP_SET_STATIC_ADDRESS,
3311 MGMT_STATUS_INVALID_PARAMS);
3312 }
3313
3314 hci_dev_lock(hdev);
3315
3316 bacpy(&hdev->static_addr, &cp->bdaddr);
3317
3318 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, 0, NULL, 0);
3319
3320 hci_dev_unlock(hdev);
3321
3322 return err;
3323}
3324
3068static void fast_connectable_complete(struct hci_dev *hdev, u8 status) 3325static void fast_connectable_complete(struct hci_dev *hdev, u8 status)
3069{ 3326{
3070 struct pending_cmd *cmd; 3327 struct pending_cmd *cmd;
@@ -3108,7 +3365,8 @@ static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
3108 3365
3109 BT_DBG("%s", hdev->name); 3366 BT_DBG("%s", hdev->name);
3110 3367
3111 if (!lmp_bredr_capable(hdev) || hdev->hci_ver < BLUETOOTH_VER_1_2) 3368 if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags) ||
3369 hdev->hci_ver < BLUETOOTH_VER_1_2)
3112 return cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 3370 return cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE,
3113 MGMT_STATUS_NOT_SUPPORTED); 3371 MGMT_STATUS_NOT_SUPPORTED);
3114 3372
@@ -3162,6 +3420,121 @@ unlock:
3162 return err; 3420 return err;
3163} 3421}
3164 3422
3423static void set_bredr_complete(struct hci_dev *hdev, u8 status)
3424{
3425 struct pending_cmd *cmd;
3426
3427 BT_DBG("status 0x%02x", status);
3428
3429 hci_dev_lock(hdev);
3430
3431 cmd = mgmt_pending_find(MGMT_OP_SET_BREDR, hdev);
3432 if (!cmd)
3433 goto unlock;
3434
3435 if (status) {
3436 u8 mgmt_err = mgmt_status(status);
3437
3438 /* We need to restore the flag if related HCI commands
3439 * failed.
3440 */
3441 clear_bit(HCI_BREDR_ENABLED, &hdev->dev_flags);
3442
3443 cmd_status(cmd->sk, cmd->index, cmd->opcode, mgmt_err);
3444 } else {
3445 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev);
3446 new_settings(hdev, cmd->sk);
3447 }
3448
3449 mgmt_pending_remove(cmd);
3450
3451unlock:
3452 hci_dev_unlock(hdev);
3453}
3454
3455static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
3456{
3457 struct mgmt_mode *cp = data;
3458 struct pending_cmd *cmd;
3459 struct hci_request req;
3460 int err;
3461
3462 BT_DBG("request for %s", hdev->name);
3463
3464 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev))
3465 return cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR,
3466 MGMT_STATUS_NOT_SUPPORTED);
3467
3468 if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
3469 return cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR,
3470 MGMT_STATUS_REJECTED);
3471
3472 if (cp->val != 0x00 && cp->val != 0x01)
3473 return cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR,
3474 MGMT_STATUS_INVALID_PARAMS);
3475
3476 hci_dev_lock(hdev);
3477
3478 if (cp->val == test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
3479 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev);
3480 goto unlock;
3481 }
3482
3483 if (!hdev_is_powered(hdev)) {
3484 if (!cp->val) {
3485 clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
3486 clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
3487 clear_bit(HCI_SSP_ENABLED, &hdev->dev_flags);
3488 clear_bit(HCI_LINK_SECURITY, &hdev->dev_flags);
3489 clear_bit(HCI_FAST_CONNECTABLE, &hdev->dev_flags);
3490 clear_bit(HCI_HS_ENABLED, &hdev->dev_flags);
3491 }
3492
3493 change_bit(HCI_BREDR_ENABLED, &hdev->dev_flags);
3494
3495 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev);
3496 if (err < 0)
3497 goto unlock;
3498
3499 err = new_settings(hdev, sk);
3500 goto unlock;
3501 }
3502
3503 /* Reject disabling when powered on */
3504 if (!cp->val) {
3505 err = cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR,
3506 MGMT_STATUS_REJECTED);
3507 goto unlock;
3508 }
3509
3510 if (mgmt_pending_find(MGMT_OP_SET_BREDR, hdev)) {
3511 err = cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR,
3512 MGMT_STATUS_BUSY);
3513 goto unlock;
3514 }
3515
3516 cmd = mgmt_pending_add(sk, MGMT_OP_SET_BREDR, hdev, data, len);
3517 if (!cmd) {
3518 err = -ENOMEM;
3519 goto unlock;
3520 }
3521
3522 /* We need to flip the bit already here so that hci_update_ad
3523 * generates the correct flags.
3524 */
3525 set_bit(HCI_BREDR_ENABLED, &hdev->dev_flags);
3526
3527 hci_req_init(&req, hdev);
3528 hci_update_ad(&req);
3529 err = hci_req_run(&req, set_bredr_complete);
3530 if (err < 0)
3531 mgmt_pending_remove(cmd);
3532
3533unlock:
3534 hci_dev_unlock(hdev);
3535 return err;
3536}
3537
3165static bool ltk_is_valid(struct mgmt_ltk_info *key) 3538static bool ltk_is_valid(struct mgmt_ltk_info *key)
3166{ 3539{
3167 if (key->authenticated != 0x00 && key->authenticated != 0x01) 3540 if (key->authenticated != 0x00 && key->authenticated != 0x01)
@@ -3180,6 +3553,12 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
3180 u16 key_count, expected_len; 3553 u16 key_count, expected_len;
3181 int i, err; 3554 int i, err;
3182 3555
3556 BT_DBG("request for %s", hdev->name);
3557
3558 if (!lmp_le_capable(hdev))
3559 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS,
3560 MGMT_STATUS_NOT_SUPPORTED);
3561
3183 key_count = __le16_to_cpu(cp->key_count); 3562 key_count = __le16_to_cpu(cp->key_count);
3184 3563
3185 expected_len = sizeof(*cp) + key_count * 3564 expected_len = sizeof(*cp) + key_count *
@@ -3276,6 +3655,9 @@ static const struct mgmt_handler {
3276 { block_device, false, MGMT_BLOCK_DEVICE_SIZE }, 3655 { block_device, false, MGMT_BLOCK_DEVICE_SIZE },
3277 { unblock_device, false, MGMT_UNBLOCK_DEVICE_SIZE }, 3656 { unblock_device, false, MGMT_UNBLOCK_DEVICE_SIZE },
3278 { set_device_id, false, MGMT_SET_DEVICE_ID_SIZE }, 3657 { set_device_id, false, MGMT_SET_DEVICE_ID_SIZE },
3658 { set_advertising, false, MGMT_SETTING_SIZE },
3659 { set_bredr, false, MGMT_SETTING_SIZE },
3660 { set_static_address, false, MGMT_SET_STATIC_ADDRESS_SIZE },
3279}; 3661};
3280 3662
3281 3663
@@ -3320,6 +3702,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
3320 MGMT_STATUS_INVALID_INDEX); 3702 MGMT_STATUS_INVALID_INDEX);
3321 goto done; 3703 goto done;
3322 } 3704 }
3705
3706 if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
3707 err = cmd_status(sk, index, opcode,
3708 MGMT_STATUS_INVALID_INDEX);
3709 goto done;
3710 }
3323 } 3711 }
3324 3712
3325 if (opcode >= ARRAY_SIZE(mgmt_handlers) || 3713 if (opcode >= ARRAY_SIZE(mgmt_handlers) ||
@@ -3365,14 +3753,6 @@ done:
3365 return err; 3753 return err;
3366} 3754}
3367 3755
3368static void cmd_status_rsp(struct pending_cmd *cmd, void *data)
3369{
3370 u8 *status = data;
3371
3372 cmd_status(cmd->sk, cmd->index, cmd->opcode, *status);
3373 mgmt_pending_remove(cmd);
3374}
3375
3376int mgmt_index_added(struct hci_dev *hdev) 3756int mgmt_index_added(struct hci_dev *hdev)
3377{ 3757{
3378 if (!mgmt_valid_hdev(hdev)) 3758 if (!mgmt_valid_hdev(hdev))
@@ -3393,28 +3773,6 @@ int mgmt_index_removed(struct hci_dev *hdev)
3393 return mgmt_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, NULL); 3773 return mgmt_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, NULL);
3394} 3774}
3395 3775
3396struct cmd_lookup {
3397 struct sock *sk;
3398 struct hci_dev *hdev;
3399 u8 mgmt_status;
3400};
3401
3402static void settings_rsp(struct pending_cmd *cmd, void *data)
3403{
3404 struct cmd_lookup *match = data;
3405
3406 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev);
3407
3408 list_del(&cmd->list);
3409
3410 if (match->sk == NULL) {
3411 match->sk = cmd->sk;
3412 sock_hold(match->sk);
3413 }
3414
3415 mgmt_pending_free(cmd);
3416}
3417
3418static void set_bredr_scan(struct hci_request *req) 3776static void set_bredr_scan(struct hci_request *req)
3419{ 3777{
3420 struct hci_dev *hdev = req->hdev; 3778 struct hci_dev *hdev = req->hdev;
@@ -3481,6 +3839,22 @@ static int powered_update_hci(struct hci_dev *hdev)
3481 cp.simul != lmp_host_le_br_capable(hdev)) 3839 cp.simul != lmp_host_le_br_capable(hdev))
3482 hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, 3840 hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED,
3483 sizeof(cp), &cp); 3841 sizeof(cp), &cp);
3842
3843 /* In case BR/EDR was toggled during the AUTO_OFF phase */
3844 hci_update_ad(&req);
3845 }
3846
3847 if (lmp_le_capable(hdev)) {
3848 /* Set random address to static address if configured */
3849 if (bacmp(&hdev->static_addr, BDADDR_ANY))
3850 hci_req_add(&req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
3851 &hdev->static_addr);
3852 }
3853
3854 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) {
3855 u8 adv = 0x01;
3856
3857 hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(adv), &adv);
3484 } 3858 }
3485 3859
3486 link_sec = test_bit(HCI_LINK_SECURITY, &hdev->dev_flags); 3860 link_sec = test_bit(HCI_LINK_SECURITY, &hdev->dev_flags);
@@ -3489,7 +3863,8 @@ static int powered_update_hci(struct hci_dev *hdev)
3489 sizeof(link_sec), &link_sec); 3863 sizeof(link_sec), &link_sec);
3490 3864
3491 if (lmp_bredr_capable(hdev)) { 3865 if (lmp_bredr_capable(hdev)) {
3492 set_bredr_scan(&req); 3866 if (test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
3867 set_bredr_scan(&req);
3493 update_class(&req); 3868 update_class(&req);
3494 update_name(&req); 3869 update_name(&req);
3495 update_eir(&req); 3870 update_eir(&req);
@@ -4132,44 +4507,6 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
4132 return err; 4507 return err;
4133} 4508}
4134 4509
4135int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
4136{
4137 struct cmd_lookup match = { NULL, hdev };
4138 bool changed = false;
4139 int err = 0;
4140
4141 if (status) {
4142 u8 mgmt_err = mgmt_status(status);
4143
4144 if (enable && test_and_clear_bit(HCI_LE_ENABLED,
4145 &hdev->dev_flags))
4146 err = new_settings(hdev, NULL);
4147
4148 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp,
4149 &mgmt_err);
4150
4151 return err;
4152 }
4153
4154 if (enable) {
4155 if (!test_and_set_bit(HCI_LE_ENABLED, &hdev->dev_flags))
4156 changed = true;
4157 } else {
4158 if (test_and_clear_bit(HCI_LE_ENABLED, &hdev->dev_flags))
4159 changed = true;
4160 }
4161
4162 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match);
4163
4164 if (changed)
4165 err = new_settings(hdev, match.sk);
4166
4167 if (match.sk)
4168 sock_put(match.sk);
4169
4170 return err;
4171}
4172
4173int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 4510int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
4174 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, u8 4511 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, u8
4175 ssp, u8 *eir, u16 eir_len) 4512 ssp, u8 *eir, u16 eir_len)
@@ -4286,6 +4623,3 @@ int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
4286 return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &ev, sizeof(ev), 4623 return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &ev, sizeof(ev),
4287 cmd ? cmd->sk : NULL); 4624 cmd ? cmd->sk : NULL);
4288} 4625}
4289
4290module_param(enable_hs, bool, 0644);
4291MODULE_PARM_DESC(enable_hs, "Enable High Speed support");
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 30b3721dc6d7..072938dc527d 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -544,7 +544,7 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
544 struct sock *sk = sock->sk; 544 struct sock *sk = sock->sk;
545 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; 545 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
546 struct sk_buff *skb; 546 struct sk_buff *skb;
547 int sent = 0; 547 int sent;
548 548
549 if (test_bit(RFCOMM_DEFER_SETUP, &d->flags)) 549 if (test_bit(RFCOMM_DEFER_SETUP, &d->flags))
550 return -ENOTCONN; 550 return -ENOTCONN;
@@ -559,6 +559,10 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
559 559
560 lock_sock(sk); 560 lock_sock(sk);
561 561
562 sent = bt_sock_wait_ready(sk, msg->msg_flags);
563 if (sent)
564 goto done;
565
562 while (len) { 566 while (len) {
563 size_t size = min_t(size_t, len, d->mtu); 567 size_t size = min_t(size_t, len, d->mtu);
564 int err; 568 int err;
@@ -594,6 +598,7 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
594 len -= size; 598 len -= size;
595 } 599 }
596 600
601done:
597 release_sock(sk); 602 release_sock(sk);
598 603
599 return sent; 604 return sent;
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index b5562abdd6e0..884b2081a262 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -847,16 +847,27 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
847 847
848int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) 848int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
849{ 849{
850 __u8 code = skb->data[0]; 850 struct hci_conn *hcon = conn->hcon;
851 __u8 reason; 851 __u8 code, reason;
852 int err = 0; 852 int err = 0;
853 853
854 if (hcon->type != LE_LINK) {
855 kfree_skb(skb);
856 return -ENOTSUPP;
857 }
858
859 if (skb->len < 1) {
860 kfree_skb(skb);
861 return -EILSEQ;
862 }
863
854 if (!test_bit(HCI_LE_ENABLED, &conn->hcon->hdev->dev_flags)) { 864 if (!test_bit(HCI_LE_ENABLED, &conn->hcon->hdev->dev_flags)) {
855 err = -ENOTSUPP; 865 err = -ENOTSUPP;
856 reason = SMP_PAIRING_NOTSUPP; 866 reason = SMP_PAIRING_NOTSUPP;
857 goto done; 867 goto done;
858 } 868 }
859 869
870 code = skb->data[0];
860 skb_pull(skb, sizeof(code)); 871 skb_pull(skb, sizeof(code));
861 872
862 /* 873 /*