aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-03-25 19:25:39 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-25 19:25:39 -0400
commit0fc31966035d7a540c011b6c967ce8eae1db121b (patch)
tree83f328a064cb123a10f5977c69ec3e28396970bc /drivers/net/wireless/ath
parent2c5f4f8422e8cf3dd15638226e964f2e13132267 (diff)
parent49c0ca17ee8dd3530f688052d4eb2ae6d3e55119 (diff)
Merge branch 'for-davem' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next
John W. Linville says: ==================== Please pull this batch of wireless updates intended for 3.15! For the mac80211 bits, Johannes says: "This has a whole bunch of bugfixes for things that went into -next previously as well as some other bugfixes I didn't want to rush into 3.14 at this point. The rest of it is some cleanups and a few small features, the biggest of which is probably Janusz's regulatory DFS CAC time code." For the Bluetooth bits, Gustavo says: "One more pull request to 3.15. This is mostly and bug fix pull request, it contains several fixes and clean up all over the tree, plus some small new features." For the NFC bits, Samuel says: "This is the NFC pull request for 3.15. With this one we have: - Support for ISO 15693 a.k.a. NFC vicinity a.k.a. Type 5 tags. ISO 15693 are long range (1 - 2 meters) vicinity tags/cards. The kernel now supports those through the NFC netlink and digital APIs. - Support for TI's trf7970a chipset. This chipset relies on the NFC digital layer and the driver currently supports type 2, 4A and 5 tags. - Support for NXP's pn544 secure firmare download. The pn544 C3 chipsets relies on a different firmware download protocal than the C2 one. We now support both and use the right one depending on the version we detect at runtime. - Support for 4A tags from the NFC digital layer. - A bunch of cleanups and minor fixes from Axel Lin and Thierry Escande." For the iwlwifi bits, Emmanuel says: "We were sending a host command while the mutex wasn't held. This led to hard-to-catch races." And... "I have a fix for a "merge damage" which is not really a merge damage: it enables scheduled scan which has been disabled in wireless.git. Since you merged wireless.git into wireless-next.git, this can now be fixed in wireless-next.git. Besides this, Alex made a workaround for a hardware bug. This fix allows us to consume less power in S3. Arik and Eliad continue to work on D0i3 which is a run-time power saving feature. Eliad also contributes a few bits to the rate scaling logic to which Eyal adds his own contribution. Avri dives deep in the power code - newer firmware will allow to enable power save in newer scenarios. Johannes made a few clean-ups. I have the regular amount of BT Coex boring stuff. I disable uAPSD since we identified firmware bugs that cause packet loss. One thing that do stand out is the udev event that we now send when the FW asserts. I hope it will allow us to debug the FW more easily." Also included is one last iwlwifi pull for a build breakage fix... For the Atheros bits, Kalle says: "Michal now did some optimisations and was able to improve throughput by 100 Mbps on our MIPS based AP135 platform. Chun-Yeow added some workarounds to be able to better use ad-hoc mode. Ben improved log messages and added support for MSDU chaining. And, as usual, also some smaller fixes." Beyond that... Andrea Merello continues his rtl8180 refactoring, in preparation for a long-awaited rtl8187 driver. We get a new driver (rsi) for the RS9113 chip, from Fariya Fatima. And, of course, we get the usual round of updates for ath9k, brcmfmac, mwifiex, wil6210, etc. as well. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireless/ath')
-rw-r--r--drivers/net/wireless/ath/ath.h10
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.c16
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.h9
-rw-r--r--drivers/net/wireless/ath/ath10k/core.h34
-rw-r--r--drivers/net/wireless/ath/ath10k/hif.h25
-rw-r--r--drivers/net/wireless/ath/ath10k/htc.c25
-rw-r--r--drivers/net/wireless/ath/ath10k/htt.h18
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_rx.c236
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_tx.c205
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.c268
-rw-r--r--drivers/net/wireless/ath/ath10k/pci.c389
-rw-r--r--drivers/net/wireless/ath/ath10k/pci.h28
-rw-r--r--drivers/net/wireless/ath/ath10k/txrx.c24
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.c18
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/Makefile3
-rw-r--r--drivers/net/wireless/ath/ath9k/ahb.c11
-rw-r--r--drivers/net/wireless/ath/ath9k/ani.c11
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c85
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c63
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h22
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c165
-rw-r--r--drivers/net/wireless/ath/ath9k/common-beacon.c180
-rw-r--r--drivers/net/wireless/ath/ath9k/common-beacon.h26
-rw-r--r--drivers/net/wireless/ath/ath9k/common.h14
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c60
-rw-r--r--drivers/net/wireless/ath/ath9k/htc.h25
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_beacon.c252
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_init.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_main.c53
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_txrx.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/link.c16
-rw-r--r--drivers/net/wireless/ath/ath9k/mac.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c45
-rw-r--r--drivers/net/wireless/ath/ath9k/mci.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/tx99.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/wow.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c11
-rw-r--r--drivers/net/wireless/ath/wil6210/cfg80211.c43
-rw-r--r--drivers/net/wireless/ath/wil6210/debugfs.c64
-rw-r--r--drivers/net/wireless/ath/wil6210/interrupt.c33
-rw-r--r--drivers/net/wireless/ath/wil6210/main.c119
-rw-r--r--drivers/net/wireless/ath/wil6210/netdev.c5
-rw-r--r--drivers/net/wireless/ath/wil6210/pcie_bus.c5
-rw-r--r--drivers/net/wireless/ath/wil6210/txrx.c223
-rw-r--r--drivers/net/wireless/ath/wil6210/wil6210.h82
-rw-r--r--drivers/net/wireless/ath/wil6210/wmi.c20
49 files changed, 1595 insertions, 1383 deletions
diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index d239acc26125..a889fd66fc63 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -56,6 +56,15 @@ enum ath_device_state {
56 ATH_HW_INITIALIZED, 56 ATH_HW_INITIALIZED,
57}; 57};
58 58
59enum ath_op_flags {
60 ATH_OP_INVALID,
61 ATH_OP_BEACONS,
62 ATH_OP_ANI_RUN,
63 ATH_OP_PRIM_STA_VIF,
64 ATH_OP_HW_RESET,
65 ATH_OP_SCANNING,
66};
67
59enum ath_bus_type { 68enum ath_bus_type {
60 ATH_PCI, 69 ATH_PCI,
61 ATH_AHB, 70 ATH_AHB,
@@ -130,6 +139,7 @@ struct ath_common {
130 struct ieee80211_hw *hw; 139 struct ieee80211_hw *hw;
131 int debug_mask; 140 int debug_mask;
132 enum ath_device_state state; 141 enum ath_device_state state;
142 unsigned long op_flags;
133 143
134 struct ath_ani ani; 144 struct ath_ani ani;
135 145
diff --git a/drivers/net/wireless/ath/ath10k/ce.c b/drivers/net/wireless/ath/ath10k/ce.c
index d44d618b05f9..a79499c82350 100644
--- a/drivers/net/wireless/ath/ath10k/ce.c
+++ b/drivers/net/wireless/ath/ath10k/ce.c
@@ -266,12 +266,12 @@ static inline void ath10k_ce_engine_int_status_clear(struct ath10k *ar,
266 * ath10k_ce_sendlist_send. 266 * ath10k_ce_sendlist_send.
267 * The caller takes responsibility for any needed locking. 267 * The caller takes responsibility for any needed locking.
268 */ 268 */
269static int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state, 269int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
270 void *per_transfer_context, 270 void *per_transfer_context,
271 u32 buffer, 271 u32 buffer,
272 unsigned int nbytes, 272 unsigned int nbytes,
273 unsigned int transfer_id, 273 unsigned int transfer_id,
274 unsigned int flags) 274 unsigned int flags)
275{ 275{
276 struct ath10k *ar = ce_state->ar; 276 struct ath10k *ar = ce_state->ar;
277 struct ath10k_ce_ring *src_ring = ce_state->src_ring; 277 struct ath10k_ce_ring *src_ring = ce_state->src_ring;
@@ -1067,9 +1067,9 @@ struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
1067 * 1067 *
1068 * For the lack of a better place do the check here. 1068 * For the lack of a better place do the check here.
1069 */ 1069 */
1070 BUILD_BUG_ON(TARGET_NUM_MSDU_DESC > 1070 BUILD_BUG_ON(2*TARGET_NUM_MSDU_DESC >
1071 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1)); 1071 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1072 BUILD_BUG_ON(TARGET_10X_NUM_MSDU_DESC > 1072 BUILD_BUG_ON(2*TARGET_10X_NUM_MSDU_DESC >
1073 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1)); 1073 (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1074 1074
1075 ret = ath10k_pci_wake(ar); 1075 ret = ath10k_pci_wake(ar);
diff --git a/drivers/net/wireless/ath/ath10k/ce.h b/drivers/net/wireless/ath/ath10k/ce.h
index 67dbde6a5c74..8eb7f99ed992 100644
--- a/drivers/net/wireless/ath/ath10k/ce.h
+++ b/drivers/net/wireless/ath/ath10k/ce.h
@@ -23,7 +23,7 @@
23 23
24/* Maximum number of Copy Engine's supported */ 24/* Maximum number of Copy Engine's supported */
25#define CE_COUNT_MAX 8 25#define CE_COUNT_MAX 8
26#define CE_HTT_H2T_MSG_SRC_NENTRIES 2048 26#define CE_HTT_H2T_MSG_SRC_NENTRIES 4096
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
@@ -152,6 +152,13 @@ int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
152 unsigned int transfer_id, 152 unsigned int transfer_id,
153 unsigned int flags); 153 unsigned int flags);
154 154
155int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
156 void *per_transfer_context,
157 u32 buffer,
158 unsigned int nbytes,
159 unsigned int transfer_id,
160 unsigned int flags);
161
155void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state, 162void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
156 void (*send_cb)(struct ath10k_ce_pipe *), 163 void (*send_cb)(struct ath10k_ce_pipe *),
157 int disable_interrupts); 164 int disable_interrupts);
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index 1fc26fe057e8..0e71979d837c 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -62,16 +62,13 @@ struct ath10k;
62 62
63struct ath10k_skb_cb { 63struct ath10k_skb_cb {
64 dma_addr_t paddr; 64 dma_addr_t paddr;
65 bool is_mapped;
66 bool is_aborted;
67 u8 vdev_id; 65 u8 vdev_id;
68 66
69 struct { 67 struct {
70 u8 tid; 68 u8 tid;
71 bool is_offchan; 69 bool is_offchan;
72 70 struct ath10k_htt_txbuf *txbuf;
73 u8 frag_len; 71 u32 txbuf_paddr;
74 u8 pad_len;
75 } __packed htt; 72 } __packed htt;
76 73
77 struct { 74 struct {
@@ -87,32 +84,6 @@ static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
87 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data; 84 return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
88} 85}
89 86
90static inline int ath10k_skb_map(struct device *dev, struct sk_buff *skb)
91{
92 if (ATH10K_SKB_CB(skb)->is_mapped)
93 return -EINVAL;
94
95 ATH10K_SKB_CB(skb)->paddr = dma_map_single(dev, skb->data, skb->len,
96 DMA_TO_DEVICE);
97
98 if (unlikely(dma_mapping_error(dev, ATH10K_SKB_CB(skb)->paddr)))
99 return -EIO;
100
101 ATH10K_SKB_CB(skb)->is_mapped = true;
102 return 0;
103}
104
105static inline int ath10k_skb_unmap(struct device *dev, struct sk_buff *skb)
106{
107 if (!ATH10K_SKB_CB(skb)->is_mapped)
108 return -EINVAL;
109
110 dma_unmap_single(dev, ATH10K_SKB_CB(skb)->paddr, skb->len,
111 DMA_TO_DEVICE);
112 ATH10K_SKB_CB(skb)->is_mapped = false;
113 return 0;
114}
115
116static inline u32 host_interest_item_address(u32 item_offset) 87static inline u32 host_interest_item_address(u32 item_offset)
117{ 88{
118 return QCA988X_HOST_INTEREST_ADDRESS + item_offset; 89 return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
@@ -288,6 +259,7 @@ struct ath10k_vif {
288 259
289 u8 fixed_rate; 260 u8 fixed_rate;
290 u8 fixed_nss; 261 u8 fixed_nss;
262 u8 force_sgi;
291}; 263};
292 264
293struct ath10k_vif_iter { 265struct ath10k_vif_iter {
diff --git a/drivers/net/wireless/ath/ath10k/hif.h b/drivers/net/wireless/ath/ath10k/hif.h
index dcdea68bcc0a..2ac7beacddca 100644
--- a/drivers/net/wireless/ath/ath10k/hif.h
+++ b/drivers/net/wireless/ath/ath10k/hif.h
@@ -21,6 +21,14 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include "core.h" 22#include "core.h"
23 23
24struct ath10k_hif_sg_item {
25 u16 transfer_id;
26 void *transfer_context; /* NULL = tx completion callback not called */
27 void *vaddr; /* for debugging mostly */
28 u32 paddr;
29 u16 len;
30};
31
24struct ath10k_hif_cb { 32struct ath10k_hif_cb {
25 int (*tx_completion)(struct ath10k *ar, 33 int (*tx_completion)(struct ath10k *ar,
26 struct sk_buff *wbuf, 34 struct sk_buff *wbuf,
@@ -31,11 +39,9 @@ struct ath10k_hif_cb {
31}; 39};
32 40
33struct ath10k_hif_ops { 41struct ath10k_hif_ops {
34 /* Send the head of a buffer to HIF for transmission to the target. */ 42 /* send a scatter-gather list to the target */
35 int (*send_head)(struct ath10k *ar, u8 pipe_id, 43 int (*tx_sg)(struct ath10k *ar, u8 pipe_id,
36 unsigned int transfer_id, 44 struct ath10k_hif_sg_item *items, int n_items);
37 unsigned int nbytes,
38 struct sk_buff *buf);
39 45
40 /* 46 /*
41 * API to handle HIF-specific BMI message exchanges, this API is 47 * API to handle HIF-specific BMI message exchanges, this API is
@@ -86,12 +92,11 @@ struct ath10k_hif_ops {
86}; 92};
87 93
88 94
89static inline int ath10k_hif_send_head(struct ath10k *ar, u8 pipe_id, 95static inline int ath10k_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
90 unsigned int transfer_id, 96 struct ath10k_hif_sg_item *items,
91 unsigned int nbytes, 97 int n_items)
92 struct sk_buff *buf)
93{ 98{
94 return ar->hif.ops->send_head(ar, pipe_id, transfer_id, nbytes, buf); 99 return ar->hif.ops->tx_sg(ar, pipe_id, items, n_items);
95} 100}
96 101
97static inline int ath10k_hif_exchange_bmi_msg(struct ath10k *ar, 102static inline int ath10k_hif_exchange_bmi_msg(struct ath10k *ar,
diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
index edc57ab505c8..7f1bccd3597f 100644
--- a/drivers/net/wireless/ath/ath10k/htc.c
+++ b/drivers/net/wireless/ath/ath10k/htc.c
@@ -63,7 +63,9 @@ static struct sk_buff *ath10k_htc_build_tx_ctrl_skb(void *ar)
63static inline void ath10k_htc_restore_tx_skb(struct ath10k_htc *htc, 63static inline void ath10k_htc_restore_tx_skb(struct ath10k_htc *htc,
64 struct sk_buff *skb) 64 struct sk_buff *skb)
65{ 65{
66 ath10k_skb_unmap(htc->ar->dev, skb); 66 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
67
68 dma_unmap_single(htc->ar->dev, skb_cb->paddr, skb->len, DMA_TO_DEVICE);
67 skb_pull(skb, sizeof(struct ath10k_htc_hdr)); 69 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
68} 70}
69 71
@@ -122,6 +124,9 @@ int ath10k_htc_send(struct ath10k_htc *htc,
122 struct sk_buff *skb) 124 struct sk_buff *skb)
123{ 125{
124 struct ath10k_htc_ep *ep = &htc->endpoint[eid]; 126 struct ath10k_htc_ep *ep = &htc->endpoint[eid];
127 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
128 struct ath10k_hif_sg_item sg_item;
129 struct device *dev = htc->ar->dev;
125 int credits = 0; 130 int credits = 0;
126 int ret; 131 int ret;
127 132
@@ -157,19 +162,25 @@ int ath10k_htc_send(struct ath10k_htc *htc,
157 162
158 ath10k_htc_prepare_tx_skb(ep, skb); 163 ath10k_htc_prepare_tx_skb(ep, skb);
159 164
160 ret = ath10k_skb_map(htc->ar->dev, skb); 165 skb_cb->paddr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
166 ret = dma_mapping_error(dev, skb_cb->paddr);
161 if (ret) 167 if (ret)
162 goto err_credits; 168 goto err_credits;
163 169
164 ret = ath10k_hif_send_head(htc->ar, ep->ul_pipe_id, ep->eid, 170 sg_item.transfer_id = ep->eid;
165 skb->len, skb); 171 sg_item.transfer_context = skb;
172 sg_item.vaddr = skb->data;
173 sg_item.paddr = skb_cb->paddr;
174 sg_item.len = skb->len;
175
176 ret = ath10k_hif_tx_sg(htc->ar, ep->ul_pipe_id, &sg_item, 1);
166 if (ret) 177 if (ret)
167 goto err_unmap; 178 goto err_unmap;
168 179
169 return 0; 180 return 0;
170 181
171err_unmap: 182err_unmap:
172 ath10k_skb_unmap(htc->ar->dev, skb); 183 dma_unmap_single(dev, skb_cb->paddr, skb->len, DMA_TO_DEVICE);
173err_credits: 184err_credits:
174 if (ep->tx_credit_flow_enabled) { 185 if (ep->tx_credit_flow_enabled) {
175 spin_lock_bh(&htc->tx_lock); 186 spin_lock_bh(&htc->tx_lock);
@@ -191,10 +202,8 @@ static int ath10k_htc_tx_completion_handler(struct ath10k *ar,
191 struct ath10k_htc *htc = &ar->htc; 202 struct ath10k_htc *htc = &ar->htc;
192 struct ath10k_htc_ep *ep = &htc->endpoint[eid]; 203 struct ath10k_htc_ep *ep = &htc->endpoint[eid];
193 204
194 if (!skb) { 205 if (WARN_ON_ONCE(!skb))
195 ath10k_warn("invalid sk_buff completion - NULL pointer. firmware crashed?\n");
196 return 0; 206 return 0;
197 }
198 207
199 ath10k_htc_notify_tx_completion(ep, skb); 208 ath10k_htc_notify_tx_completion(ep, skb);
200 /* the skb now belongs to the completion handler */ 209 /* the skb now belongs to the completion handler */
diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/ath/ath10k/htt.h
index b93ae355bc08..654867fc1ae7 100644
--- a/drivers/net/wireless/ath/ath10k/htt.h
+++ b/drivers/net/wireless/ath/ath10k/htt.h
@@ -20,6 +20,7 @@
20 20
21#include <linux/bug.h> 21#include <linux/bug.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/dmapool.h>
23 24
24#include "htc.h" 25#include "htc.h"
25#include "rx_desc.h" 26#include "rx_desc.h"
@@ -1181,11 +1182,20 @@ struct htt_rx_info {
1181 u32 info1; 1182 u32 info1;
1182 u32 info2; 1183 u32 info2;
1183 } rate; 1184 } rate;
1185
1186 u32 tsf;
1184 bool fcs_err; 1187 bool fcs_err;
1185 bool amsdu_more; 1188 bool amsdu_more;
1186 bool mic_err; 1189 bool mic_err;
1187}; 1190};
1188 1191
1192struct ath10k_htt_txbuf {
1193 struct htt_data_tx_desc_frag frags[2];
1194 struct ath10k_htc_hdr htc_hdr;
1195 struct htt_cmd_hdr cmd_hdr;
1196 struct htt_data_tx_desc cmd_tx;
1197} __packed;
1198
1189struct ath10k_htt { 1199struct ath10k_htt {
1190 struct ath10k *ar; 1200 struct ath10k *ar;
1191 enum ath10k_htc_ep_id eid; 1201 enum ath10k_htc_ep_id eid;
@@ -1267,11 +1277,18 @@ struct ath10k_htt {
1267 struct sk_buff **pending_tx; 1277 struct sk_buff **pending_tx;
1268 unsigned long *used_msdu_ids; /* bitmap */ 1278 unsigned long *used_msdu_ids; /* bitmap */
1269 wait_queue_head_t empty_tx_wq; 1279 wait_queue_head_t empty_tx_wq;
1280 struct dma_pool *tx_pool;
1270 1281
1271 /* set if host-fw communication goes haywire 1282 /* set if host-fw communication goes haywire
1272 * used to avoid further failures */ 1283 * used to avoid further failures */
1273 bool rx_confused; 1284 bool rx_confused;
1274 struct tasklet_struct rx_replenish_task; 1285 struct tasklet_struct rx_replenish_task;
1286
1287 /* This is used to group tx/rx completions separately and process them
1288 * in batches to reduce cache stalls */
1289 struct tasklet_struct txrx_compl_task;
1290 struct sk_buff_head tx_compl_q;
1291 struct sk_buff_head rx_compl_q;
1275}; 1292};
1276 1293
1277#define RX_HTT_HDR_STATUS_LEN 64 1294#define RX_HTT_HDR_STATUS_LEN 64
@@ -1343,4 +1360,5 @@ int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt);
1343void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id); 1360void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id);
1344int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *); 1361int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *);
1345int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *); 1362int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *);
1363
1346#endif 1364#endif
diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index 4767c24bf819..cdcbe2de95f9 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -43,7 +43,7 @@
43 43
44 44
45static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb); 45static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb);
46 46static void ath10k_htt_txrx_compl_task(unsigned long ptr);
47 47
48static int ath10k_htt_rx_ring_size(struct ath10k_htt *htt) 48static int ath10k_htt_rx_ring_size(struct ath10k_htt *htt)
49{ 49{
@@ -225,18 +225,16 @@ static void ath10k_htt_rx_ring_refill_retry(unsigned long arg)
225 ath10k_htt_rx_msdu_buff_replenish(htt); 225 ath10k_htt_rx_msdu_buff_replenish(htt);
226} 226}
227 227
228static unsigned ath10k_htt_rx_ring_elems(struct ath10k_htt *htt)
229{
230 return (__le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr) -
231 htt->rx_ring.sw_rd_idx.msdu_payld) & htt->rx_ring.size_mask;
232}
233
234void ath10k_htt_rx_detach(struct ath10k_htt *htt) 228void ath10k_htt_rx_detach(struct ath10k_htt *htt)
235{ 229{
236 int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld; 230 int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld;
237 231
238 del_timer_sync(&htt->rx_ring.refill_retry_timer); 232 del_timer_sync(&htt->rx_ring.refill_retry_timer);
239 tasklet_kill(&htt->rx_replenish_task); 233 tasklet_kill(&htt->rx_replenish_task);
234 tasklet_kill(&htt->txrx_compl_task);
235
236 skb_queue_purge(&htt->tx_compl_q);
237 skb_queue_purge(&htt->rx_compl_q);
240 238
241 while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) { 239 while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) {
242 struct sk_buff *skb = 240 struct sk_buff *skb =
@@ -270,10 +268,12 @@ static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
270 int idx; 268 int idx;
271 struct sk_buff *msdu; 269 struct sk_buff *msdu;
272 270
273 spin_lock_bh(&htt->rx_ring.lock); 271 lockdep_assert_held(&htt->rx_ring.lock);
274 272
275 if (ath10k_htt_rx_ring_elems(htt) == 0) 273 if (htt->rx_ring.fill_cnt == 0) {
276 ath10k_warn("htt rx ring is empty!\n"); 274 ath10k_warn("tried to pop sk_buff from an empty rx ring\n");
275 return NULL;
276 }
277 277
278 idx = htt->rx_ring.sw_rd_idx.msdu_payld; 278 idx = htt->rx_ring.sw_rd_idx.msdu_payld;
279 msdu = htt->rx_ring.netbufs_ring[idx]; 279 msdu = htt->rx_ring.netbufs_ring[idx];
@@ -283,7 +283,6 @@ static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
283 htt->rx_ring.sw_rd_idx.msdu_payld = idx; 283 htt->rx_ring.sw_rd_idx.msdu_payld = idx;
284 htt->rx_ring.fill_cnt--; 284 htt->rx_ring.fill_cnt--;
285 285
286 spin_unlock_bh(&htt->rx_ring.lock);
287 return msdu; 286 return msdu;
288} 287}
289 288
@@ -307,8 +306,7 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
307 struct sk_buff *msdu; 306 struct sk_buff *msdu;
308 struct htt_rx_desc *rx_desc; 307 struct htt_rx_desc *rx_desc;
309 308
310 if (ath10k_htt_rx_ring_elems(htt) == 0) 309 lockdep_assert_held(&htt->rx_ring.lock);
311 ath10k_warn("htt rx ring is empty!\n");
312 310
313 if (htt->rx_confused) { 311 if (htt->rx_confused) {
314 ath10k_warn("htt is confused. refusing rx\n"); 312 ath10k_warn("htt is confused. refusing rx\n");
@@ -400,6 +398,7 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
400 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0), 398 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
401 RX_MSDU_START_INFO0_MSDU_LENGTH); 399 RX_MSDU_START_INFO0_MSDU_LENGTH);
402 msdu_chained = rx_desc->frag_info.ring2_more_count; 400 msdu_chained = rx_desc->frag_info.ring2_more_count;
401 msdu_chaining = msdu_chained;
403 402
404 if (msdu_len_invalid) 403 if (msdu_len_invalid)
405 msdu_len = 0; 404 msdu_len = 0;
@@ -427,7 +426,6 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
427 426
428 msdu->next = next; 427 msdu->next = next;
429 msdu = next; 428 msdu = next;
430 msdu_chaining = 1;
431 } 429 }
432 430
433 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) & 431 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
@@ -529,6 +527,12 @@ int ath10k_htt_rx_attach(struct ath10k_htt *htt)
529 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task, 527 tasklet_init(&htt->rx_replenish_task, ath10k_htt_rx_replenish_task,
530 (unsigned long)htt); 528 (unsigned long)htt);
531 529
530 skb_queue_head_init(&htt->tx_compl_q);
531 skb_queue_head_init(&htt->rx_compl_q);
532
533 tasklet_init(&htt->txrx_compl_task, ath10k_htt_txrx_compl_task,
534 (unsigned long)htt);
535
532 ath10k_dbg(ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n", 536 ath10k_dbg(ATH10K_DBG_BOOT, "htt rx ring size %d fill_level %d\n",
533 htt->rx_ring.size, htt->rx_ring.fill_level); 537 htt->rx_ring.size, htt->rx_ring.fill_level);
534 return 0; 538 return 0;
@@ -632,6 +636,12 @@ struct amsdu_subframe_hdr {
632 __be16 len; 636 __be16 len;
633} __packed; 637} __packed;
634 638
639static int ath10k_htt_rx_nwifi_hdrlen(struct ieee80211_hdr *hdr)
640{
641 /* nwifi header is padded to 4 bytes. this fixes 4addr rx */
642 return round_up(ieee80211_hdrlen(hdr->frame_control), 4);
643}
644
635static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt, 645static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
636 struct htt_rx_info *info) 646 struct htt_rx_info *info)
637{ 647{
@@ -681,7 +691,7 @@ static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
681 case RX_MSDU_DECAP_NATIVE_WIFI: 691 case RX_MSDU_DECAP_NATIVE_WIFI:
682 /* pull decapped header and copy DA */ 692 /* pull decapped header and copy DA */
683 hdr = (struct ieee80211_hdr *)skb->data; 693 hdr = (struct ieee80211_hdr *)skb->data;
684 hdr_len = ieee80211_hdrlen(hdr->frame_control); 694 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
685 memcpy(addr, ieee80211_get_DA(hdr), ETH_ALEN); 695 memcpy(addr, ieee80211_get_DA(hdr), ETH_ALEN);
686 skb_pull(skb, hdr_len); 696 skb_pull(skb, hdr_len);
687 697
@@ -768,7 +778,7 @@ static void ath10k_htt_rx_msdu(struct ath10k_htt *htt, struct htt_rx_info *info)
768 case RX_MSDU_DECAP_NATIVE_WIFI: 778 case RX_MSDU_DECAP_NATIVE_WIFI:
769 /* Pull decapped header */ 779 /* Pull decapped header */
770 hdr = (struct ieee80211_hdr *)skb->data; 780 hdr = (struct ieee80211_hdr *)skb->data;
771 hdr_len = ieee80211_hdrlen(hdr->frame_control); 781 hdr_len = ath10k_htt_rx_nwifi_hdrlen(hdr);
772 skb_pull(skb, hdr_len); 782 skb_pull(skb, hdr_len);
773 783
774 /* Push original header */ 784 /* Push original header */
@@ -846,6 +856,20 @@ static bool ath10k_htt_rx_has_mic_err(struct sk_buff *skb)
846 return false; 856 return false;
847} 857}
848 858
859static bool ath10k_htt_rx_is_mgmt(struct sk_buff *skb)
860{
861 struct htt_rx_desc *rxd;
862 u32 flags;
863
864 rxd = (void *)skb->data - sizeof(*rxd);
865 flags = __le32_to_cpu(rxd->attention.flags);
866
867 if (flags & RX_ATTENTION_FLAGS_MGMT_TYPE)
868 return true;
869
870 return false;
871}
872
849static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb) 873static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
850{ 874{
851 struct htt_rx_desc *rxd; 875 struct htt_rx_desc *rxd;
@@ -877,6 +901,57 @@ static int ath10k_htt_rx_get_csum_state(struct sk_buff *skb)
877 return CHECKSUM_UNNECESSARY; 901 return CHECKSUM_UNNECESSARY;
878} 902}
879 903
904static int ath10k_unchain_msdu(struct sk_buff *msdu_head)
905{
906 struct sk_buff *next = msdu_head->next;
907 struct sk_buff *to_free = next;
908 int space;
909 int total_len = 0;
910
911 /* TODO: Might could optimize this by using
912 * skb_try_coalesce or similar method to
913 * decrease copying, or maybe get mac80211 to
914 * provide a way to just receive a list of
915 * skb?
916 */
917
918 msdu_head->next = NULL;
919
920 /* Allocate total length all at once. */
921 while (next) {
922 total_len += next->len;
923 next = next->next;
924 }
925
926 space = total_len - skb_tailroom(msdu_head);
927 if ((space > 0) &&
928 (pskb_expand_head(msdu_head, 0, space, GFP_ATOMIC) < 0)) {
929 /* TODO: bump some rx-oom error stat */
930 /* put it back together so we can free the
931 * whole list at once.
932 */
933 msdu_head->next = to_free;
934 return -1;
935 }
936
937 /* Walk list again, copying contents into
938 * msdu_head
939 */
940 next = to_free;
941 while (next) {
942 skb_copy_from_linear_data(next, skb_put(msdu_head, next->len),
943 next->len);
944 next = next->next;
945 }
946
947 /* If here, we have consolidated skb. Free the
948 * fragments and pass the main skb on up the
949 * stack.
950 */
951 ath10k_htt_rx_free_msdu_chain(to_free);
952 return 0;
953}
954
880static void ath10k_htt_rx_handler(struct ath10k_htt *htt, 955static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
881 struct htt_rx_indication *rx) 956 struct htt_rx_indication *rx)
882{ 957{
@@ -888,6 +963,8 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
888 u8 *fw_desc; 963 u8 *fw_desc;
889 int i, j; 964 int i, j;
890 965
966 lockdep_assert_held(&htt->rx_ring.lock);
967
891 memset(&info, 0, sizeof(info)); 968 memset(&info, 0, sizeof(info));
892 969
893 fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes); 970 fw_desc_len = __le16_to_cpu(rx->prefix.fw_rx_desc_bytes);
@@ -940,7 +1017,8 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
940 status = info.status; 1017 status = info.status;
941 1018
942 /* Skip mgmt frames while we handle this in WMI */ 1019 /* Skip mgmt frames while we handle this in WMI */
943 if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL) { 1020 if (status == HTT_RX_IND_MPDU_STATUS_MGMT_CTRL ||
1021 ath10k_htt_rx_is_mgmt(msdu_head)) {
944 ath10k_dbg(ATH10K_DBG_HTT, "htt rx mgmt ctrl\n"); 1022 ath10k_dbg(ATH10K_DBG_HTT, "htt rx mgmt ctrl\n");
945 ath10k_htt_rx_free_msdu_chain(msdu_head); 1023 ath10k_htt_rx_free_msdu_chain(msdu_head);
946 continue; 1024 continue;
@@ -964,10 +1042,8 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
964 continue; 1042 continue;
965 } 1043 }
966 1044
967 /* FIXME: we do not support chaining yet. 1045 if (msdu_chaining &&
968 * this needs investigation */ 1046 (ath10k_unchain_msdu(msdu_head) < 0)) {
969 if (msdu_chaining) {
970 ath10k_warn("htt rx msdu_chaining is true\n");
971 ath10k_htt_rx_free_msdu_chain(msdu_head); 1047 ath10k_htt_rx_free_msdu_chain(msdu_head);
972 continue; 1048 continue;
973 } 1049 }
@@ -990,6 +1066,7 @@ static void ath10k_htt_rx_handler(struct ath10k_htt *htt,
990 info.rate.info0 = rx->ppdu.info0; 1066 info.rate.info0 = rx->ppdu.info0;
991 info.rate.info1 = __le32_to_cpu(rx->ppdu.info1); 1067 info.rate.info1 = __le32_to_cpu(rx->ppdu.info1);
992 info.rate.info2 = __le32_to_cpu(rx->ppdu.info2); 1068 info.rate.info2 = __le32_to_cpu(rx->ppdu.info2);
1069 info.tsf = __le32_to_cpu(rx->ppdu.tsf);
993 1070
994 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head); 1071 hdr = ath10k_htt_rx_skb_get_hdr(msdu_head);
995 1072
@@ -1023,8 +1100,11 @@ static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1023 1100
1024 msdu_head = NULL; 1101 msdu_head = NULL;
1025 msdu_tail = NULL; 1102 msdu_tail = NULL;
1103
1104 spin_lock_bh(&htt->rx_ring.lock);
1026 msdu_chaining = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len, 1105 msdu_chaining = ath10k_htt_rx_amsdu_pop(htt, &fw_desc, &fw_desc_len,
1027 &msdu_head, &msdu_tail); 1106 &msdu_head, &msdu_tail);
1107 spin_unlock_bh(&htt->rx_ring.lock);
1028 1108
1029 ath10k_dbg(ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n"); 1109 ath10k_dbg(ATH10K_DBG_HTT_DUMP, "htt rx frag ahead\n");
1030 1110
@@ -1116,6 +1196,45 @@ end:
1116 } 1196 }
1117} 1197}
1118 1198
1199static void ath10k_htt_rx_frm_tx_compl(struct ath10k *ar,
1200 struct sk_buff *skb)
1201{
1202 struct ath10k_htt *htt = &ar->htt;
1203 struct htt_resp *resp = (struct htt_resp *)skb->data;
1204 struct htt_tx_done tx_done = {};
1205 int status = MS(resp->data_tx_completion.flags, HTT_DATA_TX_STATUS);
1206 __le16 msdu_id;
1207 int i;
1208
1209 lockdep_assert_held(&htt->tx_lock);
1210
1211 switch (status) {
1212 case HTT_DATA_TX_STATUS_NO_ACK:
1213 tx_done.no_ack = true;
1214 break;
1215 case HTT_DATA_TX_STATUS_OK:
1216 break;
1217 case HTT_DATA_TX_STATUS_DISCARD:
1218 case HTT_DATA_TX_STATUS_POSTPONE:
1219 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1220 tx_done.discard = true;
1221 break;
1222 default:
1223 ath10k_warn("unhandled tx completion status %d\n", status);
1224 tx_done.discard = true;
1225 break;
1226 }
1227
1228 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
1229 resp->data_tx_completion.num_msdus);
1230
1231 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1232 msdu_id = resp->data_tx_completion.msdus[i];
1233 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1234 ath10k_txrx_tx_unref(htt, &tx_done);
1235 }
1236}
1237
1119void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb) 1238void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1120{ 1239{
1121 struct ath10k_htt *htt = &ar->htt; 1240 struct ath10k_htt *htt = &ar->htt;
@@ -1134,10 +1253,12 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1134 complete(&htt->target_version_received); 1253 complete(&htt->target_version_received);
1135 break; 1254 break;
1136 } 1255 }
1137 case HTT_T2H_MSG_TYPE_RX_IND: { 1256 case HTT_T2H_MSG_TYPE_RX_IND:
1138 ath10k_htt_rx_handler(htt, &resp->rx_ind); 1257 spin_lock_bh(&htt->rx_ring.lock);
1139 break; 1258 __skb_queue_tail(&htt->rx_compl_q, skb);
1140 } 1259 spin_unlock_bh(&htt->rx_ring.lock);
1260 tasklet_schedule(&htt->txrx_compl_task);
1261 return;
1141 case HTT_T2H_MSG_TYPE_PEER_MAP: { 1262 case HTT_T2H_MSG_TYPE_PEER_MAP: {
1142 struct htt_peer_map_event ev = { 1263 struct htt_peer_map_event ev = {
1143 .vdev_id = resp->peer_map.vdev_id, 1264 .vdev_id = resp->peer_map.vdev_id,
@@ -1172,44 +1293,17 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1172 break; 1293 break;
1173 } 1294 }
1174 1295
1296 spin_lock_bh(&htt->tx_lock);
1175 ath10k_txrx_tx_unref(htt, &tx_done); 1297 ath10k_txrx_tx_unref(htt, &tx_done);
1298 spin_unlock_bh(&htt->tx_lock);
1176 break; 1299 break;
1177 } 1300 }
1178 case HTT_T2H_MSG_TYPE_TX_COMPL_IND: { 1301 case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
1179 struct htt_tx_done tx_done = {}; 1302 spin_lock_bh(&htt->tx_lock);
1180 int status = MS(resp->data_tx_completion.flags, 1303 __skb_queue_tail(&htt->tx_compl_q, skb);
1181 HTT_DATA_TX_STATUS); 1304 spin_unlock_bh(&htt->tx_lock);
1182 __le16 msdu_id; 1305 tasklet_schedule(&htt->txrx_compl_task);
1183 int i; 1306 return;
1184
1185 switch (status) {
1186 case HTT_DATA_TX_STATUS_NO_ACK:
1187 tx_done.no_ack = true;
1188 break;
1189 case HTT_DATA_TX_STATUS_OK:
1190 break;
1191 case HTT_DATA_TX_STATUS_DISCARD:
1192 case HTT_DATA_TX_STATUS_POSTPONE:
1193 case HTT_DATA_TX_STATUS_DOWNLOAD_FAIL:
1194 tx_done.discard = true;
1195 break;
1196 default:
1197 ath10k_warn("unhandled tx completion status %d\n",
1198 status);
1199 tx_done.discard = true;
1200 break;
1201 }
1202
1203 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion num_msdus %d\n",
1204 resp->data_tx_completion.num_msdus);
1205
1206 for (i = 0; i < resp->data_tx_completion.num_msdus; i++) {
1207 msdu_id = resp->data_tx_completion.msdus[i];
1208 tx_done.msdu_id = __le16_to_cpu(msdu_id);
1209 ath10k_txrx_tx_unref(htt, &tx_done);
1210 }
1211 break;
1212 }
1213 case HTT_T2H_MSG_TYPE_SEC_IND: { 1307 case HTT_T2H_MSG_TYPE_SEC_IND: {
1214 struct ath10k *ar = htt->ar; 1308 struct ath10k *ar = htt->ar;
1215 struct htt_security_indication *ev = &resp->security_indication; 1309 struct htt_security_indication *ev = &resp->security_indication;
@@ -1249,3 +1343,25 @@ void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
1249 /* Free the indication buffer */ 1343 /* Free the indication buffer */
1250 dev_kfree_skb_any(skb); 1344 dev_kfree_skb_any(skb);
1251} 1345}
1346
1347static void ath10k_htt_txrx_compl_task(unsigned long ptr)
1348{
1349 struct ath10k_htt *htt = (struct ath10k_htt *)ptr;
1350 struct htt_resp *resp;
1351 struct sk_buff *skb;
1352
1353 spin_lock_bh(&htt->tx_lock);
1354 while ((skb = __skb_dequeue(&htt->tx_compl_q))) {
1355 ath10k_htt_rx_frm_tx_compl(htt->ar, skb);
1356 dev_kfree_skb_any(skb);
1357 }
1358 spin_unlock_bh(&htt->tx_lock);
1359
1360 spin_lock_bh(&htt->rx_ring.lock);
1361 while ((skb = __skb_dequeue(&htt->rx_compl_q))) {
1362 resp = (struct htt_resp *)skb->data;
1363 ath10k_htt_rx_handler(htt, &resp->rx_ind);
1364 dev_kfree_skb_any(skb);
1365 }
1366 spin_unlock_bh(&htt->rx_ring.lock);
1367}
diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireless/ath/ath10k/htt_tx.c
index acaa046dc93b..7a3e2e40dd5c 100644
--- a/drivers/net/wireless/ath/ath10k/htt_tx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_tx.c
@@ -109,6 +109,14 @@ int ath10k_htt_tx_attach(struct ath10k_htt *htt)
109 return -ENOMEM; 109 return -ENOMEM;
110 } 110 }
111 111
112 htt->tx_pool = dma_pool_create("ath10k htt tx pool", htt->ar->dev,
113 sizeof(struct ath10k_htt_txbuf), 4, 0);
114 if (!htt->tx_pool) {
115 kfree(htt->used_msdu_ids);
116 kfree(htt->pending_tx);
117 return -ENOMEM;
118 }
119
112 return 0; 120 return 0;
113} 121}
114 122
@@ -117,9 +125,7 @@ static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt)
117 struct htt_tx_done tx_done = {0}; 125 struct htt_tx_done tx_done = {0};
118 int msdu_id; 126 int msdu_id;
119 127
120 /* No locks needed. Called after communication with the device has 128 spin_lock_bh(&htt->tx_lock);
121 * been stopped. */
122
123 for (msdu_id = 0; msdu_id < htt->max_num_pending_tx; msdu_id++) { 129 for (msdu_id = 0; msdu_id < htt->max_num_pending_tx; msdu_id++) {
124 if (!test_bit(msdu_id, htt->used_msdu_ids)) 130 if (!test_bit(msdu_id, htt->used_msdu_ids))
125 continue; 131 continue;
@@ -132,6 +138,7 @@ static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt)
132 138
133 ath10k_txrx_tx_unref(htt, &tx_done); 139 ath10k_txrx_tx_unref(htt, &tx_done);
134 } 140 }
141 spin_unlock_bh(&htt->tx_lock);
135} 142}
136 143
137void ath10k_htt_tx_detach(struct ath10k_htt *htt) 144void ath10k_htt_tx_detach(struct ath10k_htt *htt)
@@ -139,6 +146,7 @@ void ath10k_htt_tx_detach(struct ath10k_htt *htt)
139 ath10k_htt_tx_cleanup_pending(htt); 146 ath10k_htt_tx_cleanup_pending(htt);
140 kfree(htt->pending_tx); 147 kfree(htt->pending_tx);
141 kfree(htt->used_msdu_ids); 148 kfree(htt->used_msdu_ids);
149 dma_pool_destroy(htt->tx_pool);
142 return; 150 return;
143} 151}
144 152
@@ -334,7 +342,9 @@ int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
334 goto err_free_msdu_id; 342 goto err_free_msdu_id;
335 } 343 }
336 344
337 res = ath10k_skb_map(dev, msdu); 345 skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
346 DMA_TO_DEVICE);
347 res = dma_mapping_error(dev, skb_cb->paddr);
338 if (res) 348 if (res)
339 goto err_free_txdesc; 349 goto err_free_txdesc;
340 350
@@ -348,8 +358,7 @@ int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
348 memcpy(cmd->mgmt_tx.hdr, msdu->data, 358 memcpy(cmd->mgmt_tx.hdr, msdu->data,
349 min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN)); 359 min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
350 360
351 skb_cb->htt.frag_len = 0; 361 skb_cb->htt.txbuf = NULL;
352 skb_cb->htt.pad_len = 0;
353 362
354 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc); 363 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
355 if (res) 364 if (res)
@@ -358,7 +367,7 @@ int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
358 return 0; 367 return 0;
359 368
360err_unmap_msdu: 369err_unmap_msdu:
361 ath10k_skb_unmap(dev, msdu); 370 dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
362err_free_txdesc: 371err_free_txdesc:
363 dev_kfree_skb_any(txdesc); 372 dev_kfree_skb_any(txdesc);
364err_free_msdu_id: 373err_free_msdu_id:
@@ -375,19 +384,19 @@ err:
375int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu) 384int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
376{ 385{
377 struct device *dev = htt->ar->dev; 386 struct device *dev = htt->ar->dev;
378 struct htt_cmd *cmd;
379 struct htt_data_tx_desc_frag *tx_frags;
380 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data; 387 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
381 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu); 388 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
382 struct sk_buff *txdesc = NULL; 389 struct ath10k_hif_sg_item sg_items[2];
383 bool use_frags; 390 struct htt_data_tx_desc_frag *frags;
384 u8 vdev_id = ATH10K_SKB_CB(msdu)->vdev_id; 391 u8 vdev_id = skb_cb->vdev_id;
385 u8 tid; 392 u8 tid = skb_cb->htt.tid;
386 int prefetch_len, desc_len; 393 int prefetch_len;
387 int msdu_id = -1;
388 int res; 394 int res;
389 u8 flags0; 395 u8 flags0 = 0;
390 u16 flags1; 396 u16 msdu_id, flags1 = 0;
397 dma_addr_t paddr;
398 u32 frags_paddr;
399 bool use_frags;
391 400
392 res = ath10k_htt_tx_inc_pending(htt); 401 res = ath10k_htt_tx_inc_pending(htt);
393 if (res) 402 if (res)
@@ -406,114 +415,120 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
406 prefetch_len = min(htt->prefetch_len, msdu->len); 415 prefetch_len = min(htt->prefetch_len, msdu->len);
407 prefetch_len = roundup(prefetch_len, 4); 416 prefetch_len = roundup(prefetch_len, 4);
408 417
409 desc_len = sizeof(cmd->hdr) + sizeof(cmd->data_tx) + prefetch_len;
410
411 txdesc = ath10k_htc_alloc_skb(desc_len);
412 if (!txdesc) {
413 res = -ENOMEM;
414 goto err_free_msdu_id;
415 }
416
417 /* Since HTT 3.0 there is no separate mgmt tx command. However in case 418 /* Since HTT 3.0 there is no separate mgmt tx command. However in case
418 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx 419 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
419 * fragment list host driver specifies directly frame pointer. */ 420 * fragment list host driver specifies directly frame pointer. */
420 use_frags = htt->target_version_major < 3 || 421 use_frags = htt->target_version_major < 3 ||
421 !ieee80211_is_mgmt(hdr->frame_control); 422 !ieee80211_is_mgmt(hdr->frame_control);
422 423
423 if (!IS_ALIGNED((unsigned long)txdesc->data, 4)) { 424 skb_cb->htt.txbuf = dma_pool_alloc(htt->tx_pool, GFP_ATOMIC,
424 ath10k_warn("htt alignment check failed. dropping packet.\n"); 425 &paddr);
425 res = -EIO; 426 if (!skb_cb->htt.txbuf)
426 goto err_free_txdesc; 427 goto err_free_msdu_id;
427 } 428 skb_cb->htt.txbuf_paddr = paddr;
428 429
429 if (use_frags) { 430 skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
430 skb_cb->htt.frag_len = sizeof(*tx_frags) * 2; 431 DMA_TO_DEVICE);
431 skb_cb->htt.pad_len = (unsigned long)msdu->data - 432 res = dma_mapping_error(dev, skb_cb->paddr);
432 round_down((unsigned long)msdu->data, 4); 433 if (res)
434 goto err_free_txbuf;
433 435
434 skb_push(msdu, skb_cb->htt.frag_len + skb_cb->htt.pad_len); 436 if (likely(use_frags)) {
435 } else { 437 frags = skb_cb->htt.txbuf->frags;
436 skb_cb->htt.frag_len = 0;
437 skb_cb->htt.pad_len = 0;
438 }
439 438
440 res = ath10k_skb_map(dev, msdu); 439 frags[0].paddr = __cpu_to_le32(skb_cb->paddr);
441 if (res) 440 frags[0].len = __cpu_to_le32(msdu->len);
442 goto err_pull_txfrag; 441 frags[1].paddr = 0;
443 442 frags[1].len = 0;
444 if (use_frags) {
445 dma_sync_single_for_cpu(dev, skb_cb->paddr, msdu->len,
446 DMA_TO_DEVICE);
447
448 /* tx fragment list must be terminated with zero-entry */
449 tx_frags = (struct htt_data_tx_desc_frag *)msdu->data;
450 tx_frags[0].paddr = __cpu_to_le32(skb_cb->paddr +
451 skb_cb->htt.frag_len +
452 skb_cb->htt.pad_len);
453 tx_frags[0].len = __cpu_to_le32(msdu->len -
454 skb_cb->htt.frag_len -
455 skb_cb->htt.pad_len);
456 tx_frags[1].paddr = __cpu_to_le32(0);
457 tx_frags[1].len = __cpu_to_le32(0);
458
459 dma_sync_single_for_device(dev, skb_cb->paddr, msdu->len,
460 DMA_TO_DEVICE);
461 }
462 443
463 ath10k_dbg(ATH10K_DBG_HTT, "tx-msdu 0x%llx\n", 444 flags0 |= SM(ATH10K_HW_TXRX_NATIVE_WIFI,
464 (unsigned long long) ATH10K_SKB_CB(msdu)->paddr); 445 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
465 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "tx-msdu: ",
466 msdu->data, msdu->len);
467 446
468 skb_put(txdesc, desc_len); 447 frags_paddr = skb_cb->htt.txbuf_paddr;
469 cmd = (struct htt_cmd *)txdesc->data; 448 } else {
449 flags0 |= SM(ATH10K_HW_TXRX_MGMT,
450 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
470 451
471 tid = ATH10K_SKB_CB(msdu)->htt.tid; 452 frags_paddr = skb_cb->paddr;
453 }
472 454
473 ath10k_dbg(ATH10K_DBG_HTT, "htt data tx using tid %hhu\n", tid); 455 /* Normally all commands go through HTC which manages tx credits for
456 * each endpoint and notifies when tx is completed.
457 *
458 * HTT endpoint is creditless so there's no need to care about HTC
459 * flags. In that case it is trivial to fill the HTC header here.
460 *
461 * MSDU transmission is considered completed upon HTT event. This
462 * implies no relevant resources can be freed until after the event is
463 * received. That's why HTC tx completion handler itself is ignored by
464 * setting NULL to transfer_context for all sg items.
465 *
466 * There is simply no point in pushing HTT TX_FRM through HTC tx path
467 * as it's a waste of resources. By bypassing HTC it is possible to
468 * avoid extra memory allocations, compress data structures and thus
469 * improve performance. */
470
471 skb_cb->htt.txbuf->htc_hdr.eid = htt->eid;
472 skb_cb->htt.txbuf->htc_hdr.len = __cpu_to_le16(
473 sizeof(skb_cb->htt.txbuf->cmd_hdr) +
474 sizeof(skb_cb->htt.txbuf->cmd_tx) +
475 prefetch_len);
476 skb_cb->htt.txbuf->htc_hdr.flags = 0;
474 477
475 flags0 = 0;
476 if (!ieee80211_has_protected(hdr->frame_control)) 478 if (!ieee80211_has_protected(hdr->frame_control))
477 flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT; 479 flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
478 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
479 480
480 if (use_frags) 481 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
481 flags0 |= SM(ATH10K_HW_TXRX_NATIVE_WIFI,
482 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
483 else
484 flags0 |= SM(ATH10K_HW_TXRX_MGMT,
485 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
486 482
487 flags1 = 0;
488 flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID); 483 flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
489 flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID); 484 flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
490 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD; 485 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
491 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD; 486 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
492 487
493 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM; 488 skb_cb->htt.txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
494 cmd->data_tx.flags0 = flags0; 489 skb_cb->htt.txbuf->cmd_tx.flags0 = flags0;
495 cmd->data_tx.flags1 = __cpu_to_le16(flags1); 490 skb_cb->htt.txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
496 cmd->data_tx.len = __cpu_to_le16(msdu->len - 491 skb_cb->htt.txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
497 skb_cb->htt.frag_len - 492 skb_cb->htt.txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
498 skb_cb->htt.pad_len); 493 skb_cb->htt.txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
499 cmd->data_tx.id = __cpu_to_le16(msdu_id); 494 skb_cb->htt.txbuf->cmd_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID);
500 cmd->data_tx.frags_paddr = __cpu_to_le32(skb_cb->paddr); 495
501 cmd->data_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID); 496 ath10k_dbg(ATH10K_DBG_HTT,
502 497 "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %08x, msdu_paddr %08x vdev %hhu tid %hhu\n",
503 memcpy(cmd->data_tx.prefetch, hdr, prefetch_len); 498 flags0, flags1, msdu->len, msdu_id, frags_paddr,
499 (u32)skb_cb->paddr, vdev_id, tid);
500 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
501 msdu->data, msdu->len);
504 502
505 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc); 503 sg_items[0].transfer_id = 0;
504 sg_items[0].transfer_context = NULL;
505 sg_items[0].vaddr = &skb_cb->htt.txbuf->htc_hdr;
506 sg_items[0].paddr = skb_cb->htt.txbuf_paddr +
507 sizeof(skb_cb->htt.txbuf->frags);
508 sg_items[0].len = sizeof(skb_cb->htt.txbuf->htc_hdr) +
509 sizeof(skb_cb->htt.txbuf->cmd_hdr) +
510 sizeof(skb_cb->htt.txbuf->cmd_tx);
511
512 sg_items[1].transfer_id = 0;
513 sg_items[1].transfer_context = NULL;
514 sg_items[1].vaddr = msdu->data;
515 sg_items[1].paddr = skb_cb->paddr;
516 sg_items[1].len = prefetch_len;
517
518 res = ath10k_hif_tx_sg(htt->ar,
519 htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
520 sg_items, ARRAY_SIZE(sg_items));
506 if (res) 521 if (res)
507 goto err_unmap_msdu; 522 goto err_unmap_msdu;
508 523
509 return 0; 524 return 0;
510 525
511err_unmap_msdu: 526err_unmap_msdu:
512 ath10k_skb_unmap(dev, msdu); 527 dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
513err_pull_txfrag: 528err_free_txbuf:
514 skb_pull(msdu, skb_cb->htt.frag_len + skb_cb->htt.pad_len); 529 dma_pool_free(htt->tx_pool,
515err_free_txdesc: 530 skb_cb->htt.txbuf,
516 dev_kfree_skb_any(txdesc); 531 skb_cb->htt.txbuf_paddr);
517err_free_msdu_id: 532err_free_msdu_id:
518 spin_lock_bh(&htt->tx_lock); 533 spin_lock_bh(&htt->tx_lock);
519 htt->pending_tx[msdu_id] = NULL; 534 htt->pending_tx[msdu_id] = NULL;
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index e17f5d732b5a..511a2f81e7af 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -323,13 +323,15 @@ static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
323 323
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr); 324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
325 if (ret) { 325 if (ret) {
326 ath10k_warn("Failed to create wmi peer: %i\n", ret); 326 ath10k_warn("Failed to create wmi peer %pM on vdev %i: %i\n",
327 addr, vdev_id, ret);
327 return ret; 328 return ret;
328 } 329 }
329 330
330 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); 331 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
331 if (ret) { 332 if (ret) {
332 ath10k_warn("Failed to wait for created wmi peer: %i\n", ret); 333 ath10k_warn("Failed to wait for created wmi peer %pM on vdev %i: %i\n",
334 addr, vdev_id, ret);
333 return ret; 335 return ret;
334 } 336 }
335 spin_lock_bh(&ar->data_lock); 337 spin_lock_bh(&ar->data_lock);
@@ -349,7 +351,8 @@ static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
349 ret = ath10k_wmi_pdev_set_param(ar, param, 351 ret = ath10k_wmi_pdev_set_param(ar, param,
350 ATH10K_KICKOUT_THRESHOLD); 352 ATH10K_KICKOUT_THRESHOLD);
351 if (ret) { 353 if (ret) {
352 ath10k_warn("Failed to set kickout threshold: %d\n", ret); 354 ath10k_warn("Failed to set kickout threshold on vdev %i: %d\n",
355 arvif->vdev_id, ret);
353 return ret; 356 return ret;
354 } 357 }
355 358
@@ -357,8 +360,8 @@ static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
357 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, 360 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
358 ATH10K_KEEPALIVE_MIN_IDLE); 361 ATH10K_KEEPALIVE_MIN_IDLE);
359 if (ret) { 362 if (ret) {
360 ath10k_warn("Failed to set keepalive minimum idle time : %d\n", 363 ath10k_warn("Failed to set keepalive minimum idle time on vdev %i : %d\n",
361 ret); 364 arvif->vdev_id, ret);
362 return ret; 365 return ret;
363 } 366 }
364 367
@@ -366,8 +369,8 @@ static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
366 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, 369 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
367 ATH10K_KEEPALIVE_MAX_IDLE); 370 ATH10K_KEEPALIVE_MAX_IDLE);
368 if (ret) { 371 if (ret) {
369 ath10k_warn("Failed to set keepalive maximum idle time: %d\n", 372 ath10k_warn("Failed to set keepalive maximum idle time on vdev %i: %d\n",
370 ret); 373 arvif->vdev_id, ret);
371 return ret; 374 return ret;
372 } 375 }
373 376
@@ -375,8 +378,8 @@ static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
375 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, 378 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
376 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); 379 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
377 if (ret) { 380 if (ret) {
378 ath10k_warn("Failed to set keepalive maximum unresponsive time: %d\n", 381 ath10k_warn("Failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
379 ret); 382 arvif->vdev_id, ret);
380 return ret; 383 return ret;
381 } 384 }
382 385
@@ -529,13 +532,15 @@ static int ath10k_vdev_start(struct ath10k_vif *arvif)
529 532
530 ret = ath10k_wmi_vdev_start(ar, &arg); 533 ret = ath10k_wmi_vdev_start(ar, &arg);
531 if (ret) { 534 if (ret) {
532 ath10k_warn("WMI vdev start failed: ret %d\n", ret); 535 ath10k_warn("WMI vdev %i start failed: ret %d\n",
536 arg.vdev_id, ret);
533 return ret; 537 return ret;
534 } 538 }
535 539
536 ret = ath10k_vdev_setup_sync(ar); 540 ret = ath10k_vdev_setup_sync(ar);
537 if (ret) { 541 if (ret) {
538 ath10k_warn("vdev setup failed %d\n", ret); 542 ath10k_warn("vdev %i setup failed %d\n",
543 arg.vdev_id, ret);
539 return ret; 544 return ret;
540 } 545 }
541 546
@@ -553,13 +558,15 @@ static int ath10k_vdev_stop(struct ath10k_vif *arvif)
553 558
554 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); 559 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
555 if (ret) { 560 if (ret) {
556 ath10k_warn("WMI vdev stop failed: ret %d\n", ret); 561 ath10k_warn("WMI vdev %i stop failed: ret %d\n",
562 arvif->vdev_id, ret);
557 return ret; 563 return ret;
558 } 564 }
559 565
560 ret = ath10k_vdev_setup_sync(ar); 566 ret = ath10k_vdev_setup_sync(ar);
561 if (ret) { 567 if (ret) {
562 ath10k_warn("vdev setup failed %d\n", ret); 568 ath10k_warn("vdev %i setup sync failed %d\n",
569 arvif->vdev_id, ret);
563 return ret; 570 return ret;
564 } 571 }
565 572
@@ -597,19 +604,22 @@ static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
597 604
598 ret = ath10k_wmi_vdev_start(ar, &arg); 605 ret = ath10k_wmi_vdev_start(ar, &arg);
599 if (ret) { 606 if (ret) {
600 ath10k_warn("Monitor vdev start failed: ret %d\n", ret); 607 ath10k_warn("Monitor vdev %i start failed: ret %d\n",
608 vdev_id, ret);
601 return ret; 609 return ret;
602 } 610 }
603 611
604 ret = ath10k_vdev_setup_sync(ar); 612 ret = ath10k_vdev_setup_sync(ar);
605 if (ret) { 613 if (ret) {
606 ath10k_warn("Monitor vdev setup failed %d\n", ret); 614 ath10k_warn("Monitor vdev %i setup failed %d\n",
615 vdev_id, ret);
607 return ret; 616 return ret;
608 } 617 }
609 618
610 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); 619 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
611 if (ret) { 620 if (ret) {
612 ath10k_warn("Monitor vdev up failed: %d\n", ret); 621 ath10k_warn("Monitor vdev %i up failed: %d\n",
622 vdev_id, ret);
613 goto vdev_stop; 623 goto vdev_stop;
614 } 624 }
615 625
@@ -621,7 +631,8 @@ static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
621vdev_stop: 631vdev_stop:
622 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); 632 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
623 if (ret) 633 if (ret)
624 ath10k_warn("Monitor vdev stop failed: %d\n", ret); 634 ath10k_warn("Monitor vdev %i stop failed: %d\n",
635 ar->monitor_vdev_id, ret);
625 636
626 return ret; 637 return ret;
627} 638}
@@ -644,15 +655,18 @@ static int ath10k_monitor_stop(struct ath10k *ar)
644 655
645 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); 656 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
646 if (ret) 657 if (ret)
647 ath10k_warn("Monitor vdev down failed: %d\n", ret); 658 ath10k_warn("Monitor vdev %i down failed: %d\n",
659 ar->monitor_vdev_id, ret);
648 660
649 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); 661 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
650 if (ret) 662 if (ret)
651 ath10k_warn("Monitor vdev stop failed: %d\n", ret); 663 ath10k_warn("Monitor vdev %i stop failed: %d\n",
664 ar->monitor_vdev_id, ret);
652 665
653 ret = ath10k_vdev_setup_sync(ar); 666 ret = ath10k_vdev_setup_sync(ar);
654 if (ret) 667 if (ret)
655 ath10k_warn("Monitor_down sync failed: %d\n", ret); 668 ath10k_warn("Monitor_down sync failed, vdev %i: %d\n",
669 ar->monitor_vdev_id, ret);
656 670
657 ar->monitor_enabled = false; 671 ar->monitor_enabled = false;
658 return ret; 672 return ret;
@@ -682,7 +696,8 @@ static int ath10k_monitor_create(struct ath10k *ar)
682 WMI_VDEV_TYPE_MONITOR, 696 WMI_VDEV_TYPE_MONITOR,
683 0, ar->mac_addr); 697 0, ar->mac_addr);
684 if (ret) { 698 if (ret) {
685 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret); 699 ath10k_warn("WMI vdev %i monitor create failed: ret %d\n",
700 ar->monitor_vdev_id, ret);
686 goto vdev_fail; 701 goto vdev_fail;
687 } 702 }
688 703
@@ -711,7 +726,8 @@ static int ath10k_monitor_destroy(struct ath10k *ar)
711 726
712 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); 727 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
713 if (ret) { 728 if (ret) {
714 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret); 729 ath10k_warn("WMI vdev %i monitor delete failed: %d\n",
730 ar->monitor_vdev_id, ret);
715 return ret; 731 return ret;
716 } 732 }
717 733
@@ -839,7 +855,9 @@ static void ath10k_control_beaconing(struct ath10k_vif *arvif,
839 855
840 spin_lock_bh(&arvif->ar->data_lock); 856 spin_lock_bh(&arvif->ar->data_lock);
841 if (arvif->beacon) { 857 if (arvif->beacon) {
842 ath10k_skb_unmap(arvif->ar->dev, arvif->beacon); 858 dma_unmap_single(arvif->ar->dev,
859 ATH10K_SKB_CB(arvif->beacon)->paddr,
860 arvif->beacon->len, DMA_TO_DEVICE);
843 dev_kfree_skb_any(arvif->beacon); 861 dev_kfree_skb_any(arvif->beacon);
844 862
845 arvif->beacon = NULL; 863 arvif->beacon = NULL;
@@ -862,8 +880,8 @@ static void ath10k_control_beaconing(struct ath10k_vif *arvif,
862 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, 880 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
863 arvif->bssid); 881 arvif->bssid);
864 if (ret) { 882 if (ret) {
865 ath10k_warn("Failed to bring up VDEV: %d\n", 883 ath10k_warn("Failed to bring up vdev %d: %i\n",
866 arvif->vdev_id); 884 arvif->vdev_id, ret);
867 ath10k_vdev_stop(arvif); 885 ath10k_vdev_stop(arvif);
868 return; 886 return;
869 } 887 }
@@ -943,8 +961,8 @@ static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
943 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, 961 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
944 conf->dynamic_ps_timeout); 962 conf->dynamic_ps_timeout);
945 if (ret) { 963 if (ret) {
946 ath10k_warn("Failed to set inactivity time for VDEV: %d\n", 964 ath10k_warn("Failed to set inactivity time for vdev %d: %i\n",
947 arvif->vdev_id); 965 arvif->vdev_id, ret);
948 return ret; 966 return ret;
949 } 967 }
950 } else { 968 } else {
@@ -1196,8 +1214,8 @@ static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1196 WMI_AP_PS_PEER_PARAM_UAPSD, 1214 WMI_AP_PS_PEER_PARAM_UAPSD,
1197 uapsd); 1215 uapsd);
1198 if (ret) { 1216 if (ret) {
1199 ath10k_warn("failed to set ap ps peer param uapsd: %d\n", 1217 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1200 ret); 1218 arvif->vdev_id, ret);
1201 return ret; 1219 return ret;
1202 } 1220 }
1203 1221
@@ -1206,8 +1224,8 @@ static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1206 WMI_AP_PS_PEER_PARAM_MAX_SP, 1224 WMI_AP_PS_PEER_PARAM_MAX_SP,
1207 max_sp); 1225 max_sp);
1208 if (ret) { 1226 if (ret) {
1209 ath10k_warn("failed to set ap ps peer param max sp: %d\n", 1227 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1210 ret); 1228 arvif->vdev_id, ret);
1211 return ret; 1229 return ret;
1212 } 1230 }
1213 1231
@@ -1218,8 +1236,8 @@ static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1218 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr, 1236 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1219 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10); 1237 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1220 if (ret) { 1238 if (ret) {
1221 ath10k_warn("failed to set ap ps peer param ageout time: %d\n", 1239 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1222 ret); 1240 arvif->vdev_id, ret);
1223 return ret; 1241 return ret;
1224 } 1242 }
1225 } 1243 }
@@ -1411,8 +1429,8 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1411 1429
1412 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); 1430 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1413 if (!ap_sta) { 1431 if (!ap_sta) {
1414 ath10k_warn("Failed to find station entry for %pM\n", 1432 ath10k_warn("Failed to find station entry for %pM, vdev %i\n",
1415 bss_conf->bssid); 1433 bss_conf->bssid, arvif->vdev_id);
1416 rcu_read_unlock(); 1434 rcu_read_unlock();
1417 return; 1435 return;
1418 } 1436 }
@@ -1424,8 +1442,8 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1424 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta, 1442 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1425 bss_conf, &peer_arg); 1443 bss_conf, &peer_arg);
1426 if (ret) { 1444 if (ret) {
1427 ath10k_warn("Peer assoc prepare failed for %pM\n: %d", 1445 ath10k_warn("Peer assoc prepare failed for %pM vdev %i\n: %d",
1428 bss_conf->bssid, ret); 1446 bss_conf->bssid, arvif->vdev_id, ret);
1429 rcu_read_unlock(); 1447 rcu_read_unlock();
1430 return; 1448 return;
1431 } 1449 }
@@ -1434,14 +1452,15 @@ static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1434 1452
1435 ret = ath10k_wmi_peer_assoc(ar, &peer_arg); 1453 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1436 if (ret) { 1454 if (ret) {
1437 ath10k_warn("Peer assoc failed for %pM\n: %d", 1455 ath10k_warn("Peer assoc failed for %pM vdev %i\n: %d",
1438 bss_conf->bssid, ret); 1456 bss_conf->bssid, arvif->vdev_id, ret);
1439 return; 1457 return;
1440 } 1458 }
1441 1459
1442 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); 1460 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1443 if (ret) { 1461 if (ret) {
1444 ath10k_warn("failed to setup peer SMPS: %d\n", ret); 1462 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1463 arvif->vdev_id, ret);
1445 return; 1464 return;
1446 } 1465 }
1447 1466
@@ -1514,34 +1533,35 @@ static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1514 1533
1515 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg); 1534 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1516 if (ret) { 1535 if (ret) {
1517 ath10k_warn("WMI peer assoc prepare failed for %pM\n", 1536 ath10k_warn("WMI peer assoc prepare failed for %pM vdev %i: %i\n",
1518 sta->addr); 1537 sta->addr, arvif->vdev_id, ret);
1519 return ret; 1538 return ret;
1520 } 1539 }
1521 1540
1522 ret = ath10k_wmi_peer_assoc(ar, &peer_arg); 1541 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1523 if (ret) { 1542 if (ret) {
1524 ath10k_warn("Peer assoc failed for STA %pM\n: %d", 1543 ath10k_warn("Peer assoc failed for STA %pM vdev %i: %d\n",
1525 sta->addr, ret); 1544 sta->addr, arvif->vdev_id, ret);
1526 return ret; 1545 return ret;
1527 } 1546 }
1528 1547
1529 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap); 1548 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1530 if (ret) { 1549 if (ret) {
1531 ath10k_warn("failed to setup peer SMPS: %d\n", ret); 1550 ath10k_warn("failed to setup peer SMPS for vdev: %d\n", ret);
1532 return ret; 1551 return ret;
1533 } 1552 }
1534 1553
1535 ret = ath10k_install_peer_wep_keys(arvif, sta->addr); 1554 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1536 if (ret) { 1555 if (ret) {
1537 ath10k_warn("could not install peer wep keys (%d)\n", ret); 1556 ath10k_warn("could not install peer wep keys for vdev %i: %d\n",
1557 arvif->vdev_id, ret);
1538 return ret; 1558 return ret;
1539 } 1559 }
1540 1560
1541 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); 1561 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1542 if (ret) { 1562 if (ret) {
1543 ath10k_warn("could not set qos params for STA %pM, %d\n", 1563 ath10k_warn("could not set qos params for STA %pM for vdev %i: %d\n",
1544 sta->addr, ret); 1564 sta->addr, arvif->vdev_id, ret);
1545 return ret; 1565 return ret;
1546 } 1566 }
1547 1567
@@ -1557,7 +1577,8 @@ static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1557 1577
1558 ret = ath10k_clear_peer_keys(arvif, sta->addr); 1578 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1559 if (ret) { 1579 if (ret) {
1560 ath10k_warn("could not clear all peer wep keys (%d)\n", ret); 1580 ath10k_warn("could not clear all peer wep keys for vdev %i: %d\n",
1581 arvif->vdev_id, ret);
1561 return ret; 1582 return ret;
1562 } 1583 }
1563 1584
@@ -2524,7 +2545,8 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2524 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, 2545 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2525 arvif->vdev_subtype, vif->addr); 2546 arvif->vdev_subtype, vif->addr);
2526 if (ret) { 2547 if (ret) {
2527 ath10k_warn("WMI vdev create failed: ret %d\n", ret); 2548 ath10k_warn("WMI vdev %i create failed: ret %d\n",
2549 arvif->vdev_id, ret);
2528 goto err; 2550 goto err;
2529 } 2551 }
2530 2552
@@ -2535,7 +2557,8 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2535 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param, 2557 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2536 arvif->def_wep_key_idx); 2558 arvif->def_wep_key_idx);
2537 if (ret) { 2559 if (ret) {
2538 ath10k_warn("Failed to set default keyid: %d\n", ret); 2560 ath10k_warn("Failed to set vdev %i default keyid: %d\n",
2561 arvif->vdev_id, ret);
2539 goto err_vdev_delete; 2562 goto err_vdev_delete;
2540 } 2563 }
2541 2564
@@ -2544,21 +2567,23 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2544 ATH10K_HW_TXRX_NATIVE_WIFI); 2567 ATH10K_HW_TXRX_NATIVE_WIFI);
2545 /* 10.X firmware does not support this VDEV parameter. Do not warn */ 2568 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2546 if (ret && ret != -EOPNOTSUPP) { 2569 if (ret && ret != -EOPNOTSUPP) {
2547 ath10k_warn("Failed to set TX encap: %d\n", ret); 2570 ath10k_warn("Failed to set vdev %i TX encap: %d\n",
2571 arvif->vdev_id, ret);
2548 goto err_vdev_delete; 2572 goto err_vdev_delete;
2549 } 2573 }
2550 2574
2551 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { 2575 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2552 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr); 2576 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2553 if (ret) { 2577 if (ret) {
2554 ath10k_warn("Failed to create peer for AP: %d\n", ret); 2578 ath10k_warn("Failed to create vdev %i peer for AP: %d\n",
2579 arvif->vdev_id, ret);
2555 goto err_vdev_delete; 2580 goto err_vdev_delete;
2556 } 2581 }
2557 2582
2558 ret = ath10k_mac_set_kickout(arvif); 2583 ret = ath10k_mac_set_kickout(arvif);
2559 if (ret) { 2584 if (ret) {
2560 ath10k_warn("Failed to set kickout parameters: %d\n", 2585 ath10k_warn("Failed to set vdev %i kickout parameters: %d\n",
2561 ret); 2586 arvif->vdev_id, ret);
2562 goto err_peer_delete; 2587 goto err_peer_delete;
2563 } 2588 }
2564 } 2589 }
@@ -2569,7 +2594,8 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2569 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 2594 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2570 param, value); 2595 param, value);
2571 if (ret) { 2596 if (ret) {
2572 ath10k_warn("Failed to set RX wake policy: %d\n", ret); 2597 ath10k_warn("Failed to set vdev %i RX wake policy: %d\n",
2598 arvif->vdev_id, ret);
2573 goto err_peer_delete; 2599 goto err_peer_delete;
2574 } 2600 }
2575 2601
@@ -2578,7 +2604,8 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2578 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 2604 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2579 param, value); 2605 param, value);
2580 if (ret) { 2606 if (ret) {
2581 ath10k_warn("Failed to set TX wake thresh: %d\n", ret); 2607 ath10k_warn("Failed to set vdev %i TX wake thresh: %d\n",
2608 arvif->vdev_id, ret);
2582 goto err_peer_delete; 2609 goto err_peer_delete;
2583 } 2610 }
2584 2611
@@ -2587,7 +2614,8 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
2587 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 2614 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2588 param, value); 2615 param, value);
2589 if (ret) { 2616 if (ret) {
2590 ath10k_warn("Failed to set PSPOLL count: %d\n", ret); 2617 ath10k_warn("Failed to set vdev %i PSPOLL count: %d\n",
2618 arvif->vdev_id, ret);
2591 goto err_peer_delete; 2619 goto err_peer_delete;
2592 } 2620 }
2593 } 2621 }
@@ -2651,17 +2679,19 @@ static void ath10k_remove_interface(struct ieee80211_hw *hw,
2651 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { 2679 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2652 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr); 2680 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2653 if (ret) 2681 if (ret)
2654 ath10k_warn("Failed to remove peer for AP: %d\n", ret); 2682 ath10k_warn("Failed to remove peer for AP vdev %i: %d\n",
2683 arvif->vdev_id, ret);
2655 2684
2656 kfree(arvif->u.ap.noa_data); 2685 kfree(arvif->u.ap.noa_data);
2657 } 2686 }
2658 2687
2659 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n", 2688 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
2660 arvif->vdev_id); 2689 arvif->vdev_id);
2661 2690
2662 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); 2691 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2663 if (ret) 2692 if (ret)
2664 ath10k_warn("WMI vdev delete failed: %d\n", ret); 2693 ath10k_warn("WMI vdev %i delete failed: %d\n",
2694 arvif->vdev_id, ret);
2665 2695
2666 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) 2696 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2667 ar->monitor_present = false; 2697 ar->monitor_present = false;
@@ -2750,8 +2780,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2750 arvif->vdev_id, arvif->beacon_interval); 2780 arvif->vdev_id, arvif->beacon_interval);
2751 2781
2752 if (ret) 2782 if (ret)
2753 ath10k_warn("Failed to set beacon interval for VDEV: %d\n", 2783 ath10k_warn("Failed to set beacon interval for vdev %d: %i\n",
2754 arvif->vdev_id); 2784 arvif->vdev_id, ret);
2755 } 2785 }
2756 2786
2757 if (changed & BSS_CHANGED_BEACON) { 2787 if (changed & BSS_CHANGED_BEACON) {
@@ -2763,8 +2793,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2763 ret = ath10k_wmi_pdev_set_param(ar, pdev_param, 2793 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
2764 WMI_BEACON_STAGGERED_MODE); 2794 WMI_BEACON_STAGGERED_MODE);
2765 if (ret) 2795 if (ret)
2766 ath10k_warn("Failed to set beacon mode for VDEV: %d\n", 2796 ath10k_warn("Failed to set beacon mode for vdev %d: %i\n",
2767 arvif->vdev_id); 2797 arvif->vdev_id, ret);
2768 } 2798 }
2769 2799
2770 if (changed & BSS_CHANGED_BEACON_INFO) { 2800 if (changed & BSS_CHANGED_BEACON_INFO) {
@@ -2778,8 +2808,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2778 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, 2808 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2779 arvif->dtim_period); 2809 arvif->dtim_period);
2780 if (ret) 2810 if (ret)
2781 ath10k_warn("Failed to set dtim period for VDEV: %d\n", 2811 ath10k_warn("Failed to set dtim period for vdev %d: %i\n",
2782 arvif->vdev_id); 2812 arvif->vdev_id, ret);
2783 } 2813 }
2784 2814
2785 if (changed & BSS_CHANGED_SSID && 2815 if (changed & BSS_CHANGED_SSID &&
@@ -2799,7 +2829,7 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2799 ret = ath10k_peer_create(ar, arvif->vdev_id, 2829 ret = ath10k_peer_create(ar, arvif->vdev_id,
2800 info->bssid); 2830 info->bssid);
2801 if (ret) 2831 if (ret)
2802 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n", 2832 ath10k_warn("Failed to add peer %pM for vdev %d when changing bssid: %i\n",
2803 info->bssid, arvif->vdev_id, ret); 2833 info->bssid, arvif->vdev_id, ret);
2804 2834
2805 if (vif->type == NL80211_IFTYPE_STATION) { 2835 if (vif->type == NL80211_IFTYPE_STATION) {
@@ -2815,8 +2845,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2815 2845
2816 ret = ath10k_vdev_start(arvif); 2846 ret = ath10k_vdev_start(arvif);
2817 if (ret) { 2847 if (ret) {
2818 ath10k_warn("failed to start vdev: %d\n", 2848 ath10k_warn("failed to start vdev %i: %d\n",
2819 ret); 2849 arvif->vdev_id, ret);
2820 goto exit; 2850 goto exit;
2821 } 2851 }
2822 2852
@@ -2851,8 +2881,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2851 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, 2881 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2852 cts_prot); 2882 cts_prot);
2853 if (ret) 2883 if (ret)
2854 ath10k_warn("Failed to set CTS prot for VDEV: %d\n", 2884 ath10k_warn("Failed to set CTS prot for vdev %d: %d\n",
2855 arvif->vdev_id); 2885 arvif->vdev_id, ret);
2856 } 2886 }
2857 2887
2858 if (changed & BSS_CHANGED_ERP_SLOT) { 2888 if (changed & BSS_CHANGED_ERP_SLOT) {
@@ -2870,8 +2900,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2870 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, 2900 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2871 slottime); 2901 slottime);
2872 if (ret) 2902 if (ret)
2873 ath10k_warn("Failed to set erp slot for VDEV: %d\n", 2903 ath10k_warn("Failed to set erp slot for vdev %d: %i\n",
2874 arvif->vdev_id); 2904 arvif->vdev_id, ret);
2875 } 2905 }
2876 2906
2877 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 2907 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
@@ -2889,8 +2919,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2889 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, 2919 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2890 preamble); 2920 preamble);
2891 if (ret) 2921 if (ret)
2892 ath10k_warn("Failed to set preamble for VDEV: %d\n", 2922 ath10k_warn("Failed to set preamble for vdev %d: %i\n",
2893 arvif->vdev_id); 2923 arvif->vdev_id, ret);
2894 } 2924 }
2895 2925
2896 if (changed & BSS_CHANGED_ASSOC) { 2926 if (changed & BSS_CHANGED_ASSOC) {
@@ -3021,8 +3051,8 @@ static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3021 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, 3051 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3022 key->keyidx); 3052 key->keyidx);
3023 if (ret) 3053 if (ret)
3024 ath10k_warn("failed to set group key as default key: %d\n", 3054 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3025 ret); 3055 arvif->vdev_id, ret);
3026} 3056}
3027 3057
3028static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3058static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
@@ -3082,7 +3112,8 @@ static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3082 3112
3083 ret = ath10k_install_key(arvif, key, cmd, peer_addr); 3113 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3084 if (ret) { 3114 if (ret) {
3085 ath10k_warn("ath10k_install_key failed (%d)\n", ret); 3115 ath10k_warn("key installation failed for vdev %i peer %pM: %d\n",
3116 arvif->vdev_id, peer_addr, ret);
3086 goto exit; 3117 goto exit;
3087 } 3118 }
3088 3119
@@ -3179,6 +3210,13 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3179 int max_num_peers; 3210 int max_num_peers;
3180 int ret = 0; 3211 int ret = 0;
3181 3212
3213 if (old_state == IEEE80211_STA_NOTEXIST &&
3214 new_state == IEEE80211_STA_NONE) {
3215 memset(arsta, 0, sizeof(*arsta));
3216 arsta->arvif = arvif;
3217 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3218 }
3219
3182 /* cancel must be done outside the mutex to avoid deadlock */ 3220 /* cancel must be done outside the mutex to avoid deadlock */
3183 if ((old_state == IEEE80211_STA_NONE && 3221 if ((old_state == IEEE80211_STA_NONE &&
3184 new_state == IEEE80211_STA_NOTEXIST)) 3222 new_state == IEEE80211_STA_NOTEXIST))
@@ -3208,10 +3246,6 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3208 "mac vdev %d peer create %pM (new sta) num_peers %d\n", 3246 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3209 arvif->vdev_id, sta->addr, ar->num_peers); 3247 arvif->vdev_id, sta->addr, ar->num_peers);
3210 3248
3211 memset(arsta, 0, sizeof(*arsta));
3212 arsta->arvif = arvif;
3213 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3214
3215 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr); 3249 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3216 if (ret) 3250 if (ret)
3217 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n", 3251 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
@@ -3226,8 +3260,8 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3226 arvif->vdev_id, sta->addr); 3260 arvif->vdev_id, sta->addr);
3227 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); 3261 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3228 if (ret) 3262 if (ret)
3229 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n", 3263 ath10k_warn("Failed to delete peer %pM for vdev %d: %i\n",
3230 sta->addr, arvif->vdev_id); 3264 sta->addr, arvif->vdev_id, ret);
3231 3265
3232 if (vif->type == NL80211_IFTYPE_STATION) 3266 if (vif->type == NL80211_IFTYPE_STATION)
3233 ath10k_bss_disassoc(hw, vif); 3267 ath10k_bss_disassoc(hw, vif);
@@ -3243,8 +3277,8 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3243 3277
3244 ret = ath10k_station_assoc(ar, arvif, sta); 3278 ret = ath10k_station_assoc(ar, arvif, sta);
3245 if (ret) 3279 if (ret)
3246 ath10k_warn("Failed to associate station: %pM\n", 3280 ath10k_warn("Failed to associate station %pM for vdev %i: %i\n",
3247 sta->addr); 3281 sta->addr, arvif->vdev_id, ret);
3248 } else if (old_state == IEEE80211_STA_ASSOC && 3282 } else if (old_state == IEEE80211_STA_ASSOC &&
3249 new_state == IEEE80211_STA_AUTH && 3283 new_state == IEEE80211_STA_AUTH &&
3250 (vif->type == NL80211_IFTYPE_AP || 3284 (vif->type == NL80211_IFTYPE_AP ||
@@ -3257,8 +3291,8 @@ static int ath10k_sta_state(struct ieee80211_hw *hw,
3257 3291
3258 ret = ath10k_station_disassoc(ar, arvif, sta); 3292 ret = ath10k_station_disassoc(ar, arvif, sta);
3259 if (ret) 3293 if (ret)
3260 ath10k_warn("Failed to disassociate station: %pM\n", 3294 ath10k_warn("Failed to disassociate station: %pM vdev %i ret %i\n",
3261 sta->addr); 3295 sta->addr, arvif->vdev_id, ret);
3262 } 3296 }
3263exit: 3297exit:
3264 mutex_unlock(&ar->conf_mutex); 3298 mutex_unlock(&ar->conf_mutex);
@@ -3539,7 +3573,8 @@ static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3539 }), ATH10K_FLUSH_TIMEOUT_HZ); 3573 }), ATH10K_FLUSH_TIMEOUT_HZ);
3540 3574
3541 if (ret <= 0 || skip) 3575 if (ret <= 0 || skip)
3542 ath10k_warn("tx not flushed\n"); 3576 ath10k_warn("tx not flushed (skip %i ar-state %i): %i\n",
3577 skip, ar->state, ret);
3543 3578
3544skip: 3579skip:
3545 mutex_unlock(&ar->conf_mutex); 3580 mutex_unlock(&ar->conf_mutex);
@@ -3905,7 +3940,8 @@ static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3905 3940
3906static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif, 3941static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3907 u8 fixed_rate, 3942 u8 fixed_rate,
3908 u8 fixed_nss) 3943 u8 fixed_nss,
3944 u8 force_sgi)
3909{ 3945{
3910 struct ath10k *ar = arvif->ar; 3946 struct ath10k *ar = arvif->ar;
3911 u32 vdev_param; 3947 u32 vdev_param;
@@ -3914,12 +3950,16 @@ static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3914 mutex_lock(&ar->conf_mutex); 3950 mutex_lock(&ar->conf_mutex);
3915 3951
3916 if (arvif->fixed_rate == fixed_rate && 3952 if (arvif->fixed_rate == fixed_rate &&
3917 arvif->fixed_nss == fixed_nss) 3953 arvif->fixed_nss == fixed_nss &&
3954 arvif->force_sgi == force_sgi)
3918 goto exit; 3955 goto exit;
3919 3956
3920 if (fixed_rate == WMI_FIXED_RATE_NONE) 3957 if (fixed_rate == WMI_FIXED_RATE_NONE)
3921 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n"); 3958 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3922 3959
3960 if (force_sgi)
3961 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
3962
3923 vdev_param = ar->wmi.vdev_param->fixed_rate; 3963 vdev_param = ar->wmi.vdev_param->fixed_rate;
3924 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, 3964 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3925 vdev_param, fixed_rate); 3965 vdev_param, fixed_rate);
@@ -3945,6 +3985,19 @@ static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3945 3985
3946 arvif->fixed_nss = fixed_nss; 3986 arvif->fixed_nss = fixed_nss;
3947 3987
3988 vdev_param = ar->wmi.vdev_param->sgi;
3989 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3990 force_sgi);
3991
3992 if (ret) {
3993 ath10k_warn("Could not set sgi param %d: %d\n",
3994 force_sgi, ret);
3995 ret = -EINVAL;
3996 goto exit;
3997 }
3998
3999 arvif->force_sgi = force_sgi;
4000
3948exit: 4001exit:
3949 mutex_unlock(&ar->conf_mutex); 4002 mutex_unlock(&ar->conf_mutex);
3950 return ret; 4003 return ret;
@@ -3959,6 +4012,11 @@ static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3959 enum ieee80211_band band = ar->hw->conf.chandef.chan->band; 4012 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
3960 u8 fixed_rate = WMI_FIXED_RATE_NONE; 4013 u8 fixed_rate = WMI_FIXED_RATE_NONE;
3961 u8 fixed_nss = ar->num_rf_chains; 4014 u8 fixed_nss = ar->num_rf_chains;
4015 u8 force_sgi;
4016
4017 force_sgi = mask->control[band].gi;
4018 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4019 return -EINVAL;
3962 4020
3963 if (!ath10k_default_bitrate_mask(ar, band, mask)) { 4021 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
3964 if (!ath10k_get_fixed_rate_nss(mask, band, 4022 if (!ath10k_get_fixed_rate_nss(mask, band,
@@ -3967,7 +4025,13 @@ static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3967 return -EINVAL; 4025 return -EINVAL;
3968 } 4026 }
3969 4027
3970 return ath10k_set_fixed_rate_param(arvif, fixed_rate, fixed_nss); 4028 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4029 ath10k_warn("Could not force SGI usage for default rate settings\n");
4030 return -EINVAL;
4031 }
4032
4033 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4034 fixed_nss, force_sgi);
3971} 4035}
3972 4036
3973static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw, 4037static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
@@ -4060,6 +4124,16 @@ static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4060 ieee80211_queue_work(hw, &arsta->update_wk); 4124 ieee80211_queue_work(hw, &arsta->update_wk);
4061} 4125}
4062 4126
4127static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4128{
4129 /*
4130 * FIXME: Return 0 for time being. Need to figure out whether FW
4131 * has the API to fetch 64-bit local TSF
4132 */
4133
4134 return 0;
4135}
4136
4063static const struct ieee80211_ops ath10k_ops = { 4137static const struct ieee80211_ops ath10k_ops = {
4064 .tx = ath10k_tx, 4138 .tx = ath10k_tx,
4065 .start = ath10k_start, 4139 .start = ath10k_start,
@@ -4085,6 +4159,7 @@ static const struct ieee80211_ops ath10k_ops = {
4085 .set_bitrate_mask = ath10k_set_bitrate_mask, 4159 .set_bitrate_mask = ath10k_set_bitrate_mask,
4086 .channel_switch_beacon = ath10k_channel_switch_beacon, 4160 .channel_switch_beacon = ath10k_channel_switch_beacon,
4087 .sta_rc_update = ath10k_sta_rc_update, 4161 .sta_rc_update = ath10k_sta_rc_update,
4162 .get_tsf = ath10k_get_tsf,
4088#ifdef CONFIG_PM 4163#ifdef CONFIG_PM
4089 .suspend = ath10k_suspend, 4164 .suspend = ath10k_suspend,
4090 .resume = ath10k_resume, 4165 .resume = ath10k_resume,
@@ -4361,7 +4436,7 @@ struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4361 ath10k_get_arvif_iter, 4436 ath10k_get_arvif_iter,
4362 &arvif_iter); 4437 &arvif_iter);
4363 if (!arvif_iter.arvif) { 4438 if (!arvif_iter.arvif) {
4364 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id); 4439 ath10k_warn("No VIF found for vdev %d\n", vdev_id);
4365 return NULL; 4440 return NULL;
4366 } 4441 }
4367 4442
@@ -4442,7 +4517,8 @@ int ath10k_mac_register(struct ath10k *ar)
4442 IEEE80211_HW_HAS_RATE_CONTROL | 4517 IEEE80211_HW_HAS_RATE_CONTROL |
4443 IEEE80211_HW_SUPPORTS_STATIC_SMPS | 4518 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4444 IEEE80211_HW_WANT_MONITOR_VIF | 4519 IEEE80211_HW_WANT_MONITOR_VIF |
4445 IEEE80211_HW_AP_LINK_PS; 4520 IEEE80211_HW_AP_LINK_PS |
4521 IEEE80211_HW_SPECTRUM_MGMT;
4446 4522
4447 /* MSDU can have HTT TX fragment pushed in front. The additional 4 4523 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4448 * bytes is used for padding/alignment if necessary. */ 4524 * bytes is used for padding/alignment if necessary. */
@@ -4500,7 +4576,7 @@ int ath10k_mac_register(struct ath10k *ar)
4500 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, 4576 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4501 ath10k_reg_notifier); 4577 ath10k_reg_notifier);
4502 if (ret) { 4578 if (ret) {
4503 ath10k_err("Regulatory initialization failed\n"); 4579 ath10k_err("Regulatory initialization failed: %i\n", ret);
4504 goto err_free; 4580 goto err_free;
4505 } 4581 }
4506 4582
diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index 34f09106f423..9d242d801d9d 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -58,12 +58,10 @@ static DEFINE_PCI_DEVICE_TABLE(ath10k_pci_id_table) = {
58static int ath10k_pci_diag_read_access(struct ath10k *ar, u32 address, 58static int ath10k_pci_diag_read_access(struct ath10k *ar, u32 address,
59 u32 *data); 59 u32 *data);
60 60
61static void ath10k_pci_process_ce(struct ath10k *ar);
62static int ath10k_pci_post_rx(struct ath10k *ar); 61static int ath10k_pci_post_rx(struct ath10k *ar);
63static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe *pipe_info, 62static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe *pipe_info,
64 int num); 63 int num);
65static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info); 64static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info);
66static void ath10k_pci_stop_ce(struct ath10k *ar);
67static int ath10k_pci_cold_reset(struct ath10k *ar); 65static int ath10k_pci_cold_reset(struct ath10k *ar);
68static int ath10k_pci_warm_reset(struct ath10k *ar); 66static int ath10k_pci_warm_reset(struct ath10k *ar);
69static int ath10k_pci_wait_for_target_init(struct ath10k *ar); 67static int ath10k_pci_wait_for_target_init(struct ath10k *ar);
@@ -74,7 +72,6 @@ static void ath10k_pci_free_irq(struct ath10k *ar);
74static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe, 72static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
75 struct ath10k_ce_pipe *rx_pipe, 73 struct ath10k_ce_pipe *rx_pipe,
76 struct bmi_xfer *xfer); 74 struct bmi_xfer *xfer);
77static void ath10k_pci_cleanup_ce(struct ath10k *ar);
78 75
79static const struct ce_attr host_ce_config_wlan[] = { 76static const struct ce_attr host_ce_config_wlan[] = {
80 /* CE0: host->target HTC control and raw streams */ 77 /* CE0: host->target HTC control and raw streams */
@@ -679,34 +676,12 @@ void ath10k_do_pci_sleep(struct ath10k *ar)
679 } 676 }
680} 677}
681 678
682/*
683 * FIXME: Handle OOM properly.
684 */
685static inline
686struct ath10k_pci_compl *get_free_compl(struct ath10k_pci_pipe *pipe_info)
687{
688 struct ath10k_pci_compl *compl = NULL;
689
690 spin_lock_bh(&pipe_info->pipe_lock);
691 if (list_empty(&pipe_info->compl_free)) {
692 ath10k_warn("Completion buffers are full\n");
693 goto exit;
694 }
695 compl = list_first_entry(&pipe_info->compl_free,
696 struct ath10k_pci_compl, list);
697 list_del(&compl->list);
698exit:
699 spin_unlock_bh(&pipe_info->pipe_lock);
700 return compl;
701}
702
703/* Called by lower (CE) layer when a send to Target completes. */ 679/* Called by lower (CE) layer when a send to Target completes. */
704static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe *ce_state) 680static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe *ce_state)
705{ 681{
706 struct ath10k *ar = ce_state->ar; 682 struct ath10k *ar = ce_state->ar;
707 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 683 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
708 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id]; 684 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
709 struct ath10k_pci_compl *compl;
710 void *transfer_context; 685 void *transfer_context;
711 u32 ce_data; 686 u32 ce_data;
712 unsigned int nbytes; 687 unsigned int nbytes;
@@ -715,27 +690,12 @@ static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe *ce_state)
715 while (ath10k_ce_completed_send_next(ce_state, &transfer_context, 690 while (ath10k_ce_completed_send_next(ce_state, &transfer_context,
716 &ce_data, &nbytes, 691 &ce_data, &nbytes,
717 &transfer_id) == 0) { 692 &transfer_id) == 0) {
718 compl = get_free_compl(pipe_info); 693 /* no need to call tx completion for NULL pointers */
719 if (!compl) 694 if (transfer_context == NULL)
720 break; 695 continue;
721
722 compl->state = ATH10K_PCI_COMPL_SEND;
723 compl->ce_state = ce_state;
724 compl->pipe_info = pipe_info;
725 compl->skb = transfer_context;
726 compl->nbytes = nbytes;
727 compl->transfer_id = transfer_id;
728 compl->flags = 0;
729 696
730 /* 697 cb->tx_completion(ar, transfer_context, transfer_id);
731 * Add the completion to the processing queue.
732 */
733 spin_lock_bh(&ar_pci->compl_lock);
734 list_add_tail(&compl->list, &ar_pci->compl_process);
735 spin_unlock_bh(&ar_pci->compl_lock);
736 } 698 }
737
738 ath10k_pci_process_ce(ar);
739} 699}
740 700
741/* Called by lower (CE) layer when data is received from the Target. */ 701/* Called by lower (CE) layer when data is received from the Target. */
@@ -744,77 +704,100 @@ static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe *ce_state)
744 struct ath10k *ar = ce_state->ar; 704 struct ath10k *ar = ce_state->ar;
745 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 705 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
746 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id]; 706 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
747 struct ath10k_pci_compl *compl; 707 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
748 struct sk_buff *skb; 708 struct sk_buff *skb;
749 void *transfer_context; 709 void *transfer_context;
750 u32 ce_data; 710 u32 ce_data;
751 unsigned int nbytes; 711 unsigned int nbytes, max_nbytes;
752 unsigned int transfer_id; 712 unsigned int transfer_id;
753 unsigned int flags; 713 unsigned int flags;
714 int err;
754 715
755 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context, 716 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
756 &ce_data, &nbytes, &transfer_id, 717 &ce_data, &nbytes, &transfer_id,
757 &flags) == 0) { 718 &flags) == 0) {
758 compl = get_free_compl(pipe_info); 719 err = ath10k_pci_post_rx_pipe(pipe_info, 1);
759 if (!compl) 720 if (unlikely(err)) {
760 break; 721 /* FIXME: retry */
761 722 ath10k_warn("failed to replenish CE rx ring %d: %d\n",
762 compl->state = ATH10K_PCI_COMPL_RECV; 723 pipe_info->pipe_num, err);
763 compl->ce_state = ce_state; 724 }
764 compl->pipe_info = pipe_info;
765 compl->skb = transfer_context;
766 compl->nbytes = nbytes;
767 compl->transfer_id = transfer_id;
768 compl->flags = flags;
769 725
770 skb = transfer_context; 726 skb = transfer_context;
727 max_nbytes = skb->len + skb_tailroom(skb);
771 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr, 728 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
772 skb->len + skb_tailroom(skb), 729 max_nbytes, DMA_FROM_DEVICE);
773 DMA_FROM_DEVICE);
774 /*
775 * Add the completion to the processing queue.
776 */
777 spin_lock_bh(&ar_pci->compl_lock);
778 list_add_tail(&compl->list, &ar_pci->compl_process);
779 spin_unlock_bh(&ar_pci->compl_lock);
780 }
781 730
782 ath10k_pci_process_ce(ar); 731 if (unlikely(max_nbytes < nbytes)) {
732 ath10k_warn("rxed more than expected (nbytes %d, max %d)",
733 nbytes, max_nbytes);
734 dev_kfree_skb_any(skb);
735 continue;
736 }
737
738 skb_put(skb, nbytes);
739 cb->rx_completion(ar, skb, pipe_info->pipe_num);
740 }
783} 741}
784 742
785/* Send the first nbytes bytes of the buffer */ 743static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
786static int ath10k_pci_hif_send_head(struct ath10k *ar, u8 pipe_id, 744 struct ath10k_hif_sg_item *items, int n_items)
787 unsigned int transfer_id,
788 unsigned int bytes, struct sk_buff *nbuf)
789{ 745{
790 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(nbuf);
791 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 746 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
792 struct ath10k_pci_pipe *pipe_info = &(ar_pci->pipe_info[pipe_id]); 747 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
793 struct ath10k_ce_pipe *ce_hdl = pipe_info->ce_hdl; 748 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
794 unsigned int len; 749 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
795 u32 flags = 0; 750 unsigned int nentries_mask = src_ring->nentries_mask;
796 int ret; 751 unsigned int sw_index = src_ring->sw_index;
752 unsigned int write_index = src_ring->write_index;
753 int err, i;
797 754
798 len = min(bytes, nbuf->len); 755 spin_lock_bh(&ar_pci->ce_lock);
799 bytes -= len;
800 756
801 if (len & 3) 757 if (unlikely(CE_RING_DELTA(nentries_mask,
802 ath10k_warn("skb not aligned to 4-byte boundary (%d)\n", len); 758 write_index, sw_index - 1) < n_items)) {
759 err = -ENOBUFS;
760 goto unlock;
761 }
803 762
804 ath10k_dbg(ATH10K_DBG_PCI, 763 for (i = 0; i < n_items - 1; i++) {
805 "pci send data vaddr %p paddr 0x%llx len %d as %d bytes\n", 764 ath10k_dbg(ATH10K_DBG_PCI,
806 nbuf->data, (unsigned long long) skb_cb->paddr, 765 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
807 nbuf->len, len); 766 i, items[i].paddr, items[i].len, n_items);
808 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL, 767 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL, "item data: ",
809 "ath10k tx: data: ", 768 items[i].vaddr, items[i].len);
810 nbuf->data, nbuf->len);
811
812 ret = ath10k_ce_send(ce_hdl, nbuf, skb_cb->paddr, len, transfer_id,
813 flags);
814 if (ret)
815 ath10k_warn("failed to send sk_buff to CE: %p\n", nbuf);
816 769
817 return ret; 770 err = ath10k_ce_send_nolock(ce_pipe,
771 items[i].transfer_context,
772 items[i].paddr,
773 items[i].len,
774 items[i].transfer_id,
775 CE_SEND_FLAG_GATHER);
776 if (err)
777 goto unlock;
778 }
779
780 /* `i` is equal to `n_items -1` after for() */
781
782 ath10k_dbg(ATH10K_DBG_PCI,
783 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
784 i, items[i].paddr, items[i].len, n_items);
785 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL, "item data: ",
786 items[i].vaddr, items[i].len);
787
788 err = ath10k_ce_send_nolock(ce_pipe,
789 items[i].transfer_context,
790 items[i].paddr,
791 items[i].len,
792 items[i].transfer_id,
793 0);
794 if (err)
795 goto unlock;
796
797 err = 0;
798unlock:
799 spin_unlock_bh(&ar_pci->ce_lock);
800 return err;
818} 801}
819 802
820static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe) 803static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
@@ -903,52 +886,6 @@ static void ath10k_pci_hif_set_callbacks(struct ath10k *ar,
903 sizeof(ar_pci->msg_callbacks_current)); 886 sizeof(ar_pci->msg_callbacks_current));
904} 887}
905 888
906static int ath10k_pci_alloc_compl(struct ath10k *ar)
907{
908 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
909 const struct ce_attr *attr;
910 struct ath10k_pci_pipe *pipe_info;
911 struct ath10k_pci_compl *compl;
912 int i, pipe_num, completions;
913
914 spin_lock_init(&ar_pci->compl_lock);
915 INIT_LIST_HEAD(&ar_pci->compl_process);
916
917 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
918 pipe_info = &ar_pci->pipe_info[pipe_num];
919
920 spin_lock_init(&pipe_info->pipe_lock);
921 INIT_LIST_HEAD(&pipe_info->compl_free);
922
923 /* Handle Diagnostic CE specially */
924 if (pipe_info->ce_hdl == ar_pci->ce_diag)
925 continue;
926
927 attr = &host_ce_config_wlan[pipe_num];
928 completions = 0;
929
930 if (attr->src_nentries)
931 completions += attr->src_nentries;
932
933 if (attr->dest_nentries)
934 completions += attr->dest_nentries;
935
936 for (i = 0; i < completions; i++) {
937 compl = kmalloc(sizeof(*compl), GFP_KERNEL);
938 if (!compl) {
939 ath10k_warn("No memory for completion state\n");
940 ath10k_pci_cleanup_ce(ar);
941 return -ENOMEM;
942 }
943
944 compl->state = ATH10K_PCI_COMPL_FREE;
945 list_add_tail(&compl->list, &pipe_info->compl_free);
946 }
947 }
948
949 return 0;
950}
951
952static int ath10k_pci_setup_ce_irq(struct ath10k *ar) 889static int ath10k_pci_setup_ce_irq(struct ath10k *ar)
953{ 890{
954 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); 891 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
@@ -993,147 +930,6 @@ static void ath10k_pci_kill_tasklet(struct ath10k *ar)
993 tasklet_kill(&ar_pci->pipe_info[i].intr); 930 tasklet_kill(&ar_pci->pipe_info[i].intr);
994} 931}
995 932
996static void ath10k_pci_stop_ce(struct ath10k *ar)
997{
998 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
999 struct ath10k_pci_compl *compl;
1000 struct sk_buff *skb;
1001
1002 /* Mark pending completions as aborted, so that upper layers free up
1003 * their associated resources */
1004 spin_lock_bh(&ar_pci->compl_lock);
1005 list_for_each_entry(compl, &ar_pci->compl_process, list) {
1006 skb = compl->skb;
1007 ATH10K_SKB_CB(skb)->is_aborted = true;
1008 }
1009 spin_unlock_bh(&ar_pci->compl_lock);
1010}
1011
1012static void ath10k_pci_cleanup_ce(struct ath10k *ar)
1013{
1014 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1015 struct ath10k_pci_compl *compl, *tmp;
1016 struct ath10k_pci_pipe *pipe_info;
1017 struct sk_buff *netbuf;
1018 int pipe_num;
1019
1020 /* Free pending completions. */
1021 spin_lock_bh(&ar_pci->compl_lock);
1022 if (!list_empty(&ar_pci->compl_process))
1023 ath10k_warn("pending completions still present! possible memory leaks.\n");
1024
1025 list_for_each_entry_safe(compl, tmp, &ar_pci->compl_process, list) {
1026 list_del(&compl->list);
1027 netbuf = compl->skb;
1028 dev_kfree_skb_any(netbuf);
1029 kfree(compl);
1030 }
1031 spin_unlock_bh(&ar_pci->compl_lock);
1032
1033 /* Free unused completions for each pipe. */
1034 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1035 pipe_info = &ar_pci->pipe_info[pipe_num];
1036
1037 spin_lock_bh(&pipe_info->pipe_lock);
1038 list_for_each_entry_safe(compl, tmp,
1039 &pipe_info->compl_free, list) {
1040 list_del(&compl->list);
1041 kfree(compl);
1042 }
1043 spin_unlock_bh(&pipe_info->pipe_lock);
1044 }
1045}
1046
1047static void ath10k_pci_process_ce(struct ath10k *ar)
1048{
1049 struct ath10k_pci *ar_pci = ar->hif.priv;
1050 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
1051 struct ath10k_pci_compl *compl;
1052 struct sk_buff *skb;
1053 unsigned int nbytes;
1054 int ret, send_done = 0;
1055
1056 /* Upper layers aren't ready to handle tx/rx completions in parallel so
1057 * we must serialize all completion processing. */
1058
1059 spin_lock_bh(&ar_pci->compl_lock);
1060 if (ar_pci->compl_processing) {
1061 spin_unlock_bh(&ar_pci->compl_lock);
1062 return;
1063 }
1064 ar_pci->compl_processing = true;
1065 spin_unlock_bh(&ar_pci->compl_lock);
1066
1067 for (;;) {
1068 spin_lock_bh(&ar_pci->compl_lock);
1069 if (list_empty(&ar_pci->compl_process)) {
1070 spin_unlock_bh(&ar_pci->compl_lock);
1071 break;
1072 }
1073 compl = list_first_entry(&ar_pci->compl_process,
1074 struct ath10k_pci_compl, list);
1075 list_del(&compl->list);
1076 spin_unlock_bh(&ar_pci->compl_lock);
1077
1078 switch (compl->state) {
1079 case ATH10K_PCI_COMPL_SEND:
1080 cb->tx_completion(ar,
1081 compl->skb,
1082 compl->transfer_id);
1083 send_done = 1;
1084 break;
1085 case ATH10K_PCI_COMPL_RECV:
1086 ret = ath10k_pci_post_rx_pipe(compl->pipe_info, 1);
1087 if (ret) {
1088 ath10k_warn("failed to post RX buffer for pipe %d: %d\n",
1089 compl->pipe_info->pipe_num, ret);
1090 break;
1091 }
1092
1093 skb = compl->skb;
1094 nbytes = compl->nbytes;
1095
1096 ath10k_dbg(ATH10K_DBG_PCI,
1097 "ath10k_pci_ce_recv_data netbuf=%p nbytes=%d\n",
1098 skb, nbytes);
1099 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL,
1100 "ath10k rx: ", skb->data, nbytes);
1101
1102 if (skb->len + skb_tailroom(skb) >= nbytes) {
1103 skb_trim(skb, 0);
1104 skb_put(skb, nbytes);
1105 cb->rx_completion(ar, skb,
1106 compl->pipe_info->pipe_num);
1107 } else {
1108 ath10k_warn("rxed more than expected (nbytes %d, max %d)",
1109 nbytes,
1110 skb->len + skb_tailroom(skb));
1111 }
1112 break;
1113 case ATH10K_PCI_COMPL_FREE:
1114 ath10k_warn("free completion cannot be processed\n");
1115 break;
1116 default:
1117 ath10k_warn("invalid completion state (%d)\n",
1118 compl->state);
1119 break;
1120 }
1121
1122 compl->state = ATH10K_PCI_COMPL_FREE;
1123
1124 /*
1125 * Add completion back to the pipe's free list.
1126 */
1127 spin_lock_bh(&compl->pipe_info->pipe_lock);
1128 list_add_tail(&compl->list, &compl->pipe_info->compl_free);
1129 spin_unlock_bh(&compl->pipe_info->pipe_lock);
1130 }
1131
1132 spin_lock_bh(&ar_pci->compl_lock);
1133 ar_pci->compl_processing = false;
1134 spin_unlock_bh(&ar_pci->compl_lock);
1135}
1136
1137/* TODO - temporary mapping while we have too few CE's */ 933/* TODO - temporary mapping while we have too few CE's */
1138static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, 934static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar,
1139 u16 service_id, u8 *ul_pipe, 935 u16 service_id, u8 *ul_pipe,
@@ -1305,17 +1101,11 @@ static int ath10k_pci_hif_start(struct ath10k *ar)
1305 ath10k_pci_free_early_irq(ar); 1101 ath10k_pci_free_early_irq(ar);
1306 ath10k_pci_kill_tasklet(ar); 1102 ath10k_pci_kill_tasklet(ar);
1307 1103
1308 ret = ath10k_pci_alloc_compl(ar);
1309 if (ret) {
1310 ath10k_warn("failed to allocate CE completions: %d\n", ret);
1311 goto err_early_irq;
1312 }
1313
1314 ret = ath10k_pci_request_irq(ar); 1104 ret = ath10k_pci_request_irq(ar);
1315 if (ret) { 1105 if (ret) {
1316 ath10k_warn("failed to post RX buffers for all pipes: %d\n", 1106 ath10k_warn("failed to post RX buffers for all pipes: %d\n",
1317 ret); 1107 ret);
1318 goto err_free_compl; 1108 goto err_early_irq;
1319 } 1109 }
1320 1110
1321 ret = ath10k_pci_setup_ce_irq(ar); 1111 ret = ath10k_pci_setup_ce_irq(ar);
@@ -1339,10 +1129,6 @@ err_stop:
1339 ath10k_ce_disable_interrupts(ar); 1129 ath10k_ce_disable_interrupts(ar);
1340 ath10k_pci_free_irq(ar); 1130 ath10k_pci_free_irq(ar);
1341 ath10k_pci_kill_tasklet(ar); 1131 ath10k_pci_kill_tasklet(ar);
1342 ath10k_pci_stop_ce(ar);
1343 ath10k_pci_process_ce(ar);
1344err_free_compl:
1345 ath10k_pci_cleanup_ce(ar);
1346err_early_irq: 1132err_early_irq:
1347 /* Though there should be no interrupts (device was reset) 1133 /* Though there should be no interrupts (device was reset)
1348 * power_down() expects the early IRQ to be installed as per the 1134 * power_down() expects the early IRQ to be installed as per the
@@ -1413,18 +1199,10 @@ static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1413 1199
1414 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf, 1200 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf,
1415 &ce_data, &nbytes, &id) == 0) { 1201 &ce_data, &nbytes, &id) == 0) {
1416 /* 1202 /* no need to call tx completion for NULL pointers */
1417 * Indicate the completion to higer layer to free 1203 if (!netbuf)
1418 * the buffer
1419 */
1420
1421 if (!netbuf) {
1422 ath10k_warn("invalid sk_buff on CE %d - NULL pointer. firmware crashed?\n",
1423 ce_hdl->id);
1424 continue; 1204 continue;
1425 }
1426 1205
1427 ATH10K_SKB_CB(netbuf)->is_aborted = true;
1428 ar_pci->msg_callbacks_current.tx_completion(ar, 1206 ar_pci->msg_callbacks_current.tx_completion(ar,
1429 netbuf, 1207 netbuf,
1430 id); 1208 id);
@@ -1482,7 +1260,6 @@ static void ath10k_pci_hif_stop(struct ath10k *ar)
1482 1260
1483 ath10k_pci_free_irq(ar); 1261 ath10k_pci_free_irq(ar);
1484 ath10k_pci_kill_tasklet(ar); 1262 ath10k_pci_kill_tasklet(ar);
1485 ath10k_pci_stop_ce(ar);
1486 1263
1487 ret = ath10k_pci_request_early_irq(ar); 1264 ret = ath10k_pci_request_early_irq(ar);
1488 if (ret) 1265 if (ret)
@@ -1492,8 +1269,6 @@ static void ath10k_pci_hif_stop(struct ath10k *ar)
1492 * not DMA nor interrupt. We process the leftovers and then free 1269 * not DMA nor interrupt. We process the leftovers and then free
1493 * everything else up. */ 1270 * everything else up. */
1494 1271
1495 ath10k_pci_process_ce(ar);
1496 ath10k_pci_cleanup_ce(ar);
1497 ath10k_pci_buffer_cleanup(ar); 1272 ath10k_pci_buffer_cleanup(ar);
1498 1273
1499 /* Make the sure the device won't access any structures on the host by 1274 /* Make the sure the device won't access any structures on the host by
@@ -2269,7 +2044,7 @@ static int ath10k_pci_hif_resume(struct ath10k *ar)
2269#endif 2044#endif
2270 2045
2271static const struct ath10k_hif_ops ath10k_pci_hif_ops = { 2046static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
2272 .send_head = ath10k_pci_hif_send_head, 2047 .tx_sg = ath10k_pci_hif_tx_sg,
2273 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg, 2048 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2274 .start = ath10k_pci_hif_start, 2049 .start = ath10k_pci_hif_start,
2275 .stop = ath10k_pci_hif_stop, 2050 .stop = ath10k_pci_hif_stop,
diff --git a/drivers/net/wireless/ath/ath10k/pci.h b/drivers/net/wireless/ath/ath10k/pci.h
index a4f32038c440..b43fdb4f7319 100644
--- a/drivers/net/wireless/ath/ath10k/pci.h
+++ b/drivers/net/wireless/ath/ath10k/pci.h
@@ -43,23 +43,6 @@ 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
52struct ath10k_pci_compl {
53 struct list_head list;
54 enum ath10k_pci_compl_state state;
55 struct ath10k_ce_pipe *ce_state;
56 struct ath10k_pci_pipe *pipe_info;
57 struct sk_buff *skb;
58 unsigned int nbytes;
59 unsigned int transfer_id;
60 unsigned int flags;
61};
62
63/* 46/*
64 * PCI-specific Target state 47 * PCI-specific Target state
65 * 48 *
@@ -175,9 +158,6 @@ struct ath10k_pci_pipe {
175 /* protects compl_free and num_send_allowed */ 158 /* protects compl_free and num_send_allowed */
176 spinlock_t pipe_lock; 159 spinlock_t pipe_lock;
177 160
178 /* List of free CE completion slots */
179 struct list_head compl_free;
180
181 struct ath10k_pci *ar_pci; 161 struct ath10k_pci *ar_pci;
182 struct tasklet_struct intr; 162 struct tasklet_struct intr;
183}; 163};
@@ -205,14 +185,6 @@ struct ath10k_pci {
205 atomic_t keep_awake_count; 185 atomic_t keep_awake_count;
206 bool verified_awake; 186 bool verified_awake;
207 187
208 /* List of CE completions to be processed */
209 struct list_head compl_process;
210
211 /* protects compl_processing and compl_process */
212 spinlock_t compl_lock;
213
214 bool compl_processing;
215
216 struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX]; 188 struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
217 189
218 struct ath10k_hif_cb msg_callbacks_current; 190 struct ath10k_hif_cb msg_callbacks_current;
diff --git a/drivers/net/wireless/ath/ath10k/txrx.c b/drivers/net/wireless/ath/ath10k/txrx.c
index ec6f82521b0e..0541dd939ce9 100644
--- a/drivers/net/wireless/ath/ath10k/txrx.c
+++ b/drivers/net/wireless/ath/ath10k/txrx.c
@@ -51,7 +51,8 @@ void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
51 struct ieee80211_tx_info *info; 51 struct ieee80211_tx_info *info;
52 struct ath10k_skb_cb *skb_cb; 52 struct ath10k_skb_cb *skb_cb;
53 struct sk_buff *msdu; 53 struct sk_buff *msdu;
54 int ret; 54
55 lockdep_assert_held(&htt->tx_lock);
55 56
56 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion msdu_id %u discard %d no_ack %d\n", 57 ath10k_dbg(ATH10K_DBG_HTT, "htt tx completion msdu_id %u discard %d no_ack %d\n",
57 tx_done->msdu_id, !!tx_done->discard, !!tx_done->no_ack); 58 tx_done->msdu_id, !!tx_done->discard, !!tx_done->no_ack);
@@ -65,12 +66,12 @@ void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
65 msdu = htt->pending_tx[tx_done->msdu_id]; 66 msdu = htt->pending_tx[tx_done->msdu_id];
66 skb_cb = ATH10K_SKB_CB(msdu); 67 skb_cb = ATH10K_SKB_CB(msdu);
67 68
68 ret = ath10k_skb_unmap(dev, msdu); 69 dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
69 if (ret)
70 ath10k_warn("data skb unmap failed (%d)\n", ret);
71 70
72 if (skb_cb->htt.frag_len) 71 if (skb_cb->htt.txbuf)
73 skb_pull(msdu, skb_cb->htt.frag_len + skb_cb->htt.pad_len); 72 dma_pool_free(htt->tx_pool,
73 skb_cb->htt.txbuf,
74 skb_cb->htt.txbuf_paddr);
74 75
75 ath10k_report_offchan_tx(htt->ar, msdu); 76 ath10k_report_offchan_tx(htt->ar, msdu);
76 77
@@ -92,13 +93,11 @@ void ath10k_txrx_tx_unref(struct ath10k_htt *htt,
92 /* we do not own the msdu anymore */ 93 /* we do not own the msdu anymore */
93 94
94exit: 95exit:
95 spin_lock_bh(&htt->tx_lock);
96 htt->pending_tx[tx_done->msdu_id] = NULL; 96 htt->pending_tx[tx_done->msdu_id] = NULL;
97 ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id); 97 ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id);
98 __ath10k_htt_tx_dec_pending(htt); 98 __ath10k_htt_tx_dec_pending(htt);
99 if (htt->num_pending_tx == 0) 99 if (htt->num_pending_tx == 0)
100 wake_up(&htt->empty_tx_wq); 100 wake_up(&htt->empty_tx_wq);
101 spin_unlock_bh(&htt->tx_lock);
102} 101}
103 102
104static const u8 rx_legacy_rate_idx[] = { 103static const u8 rx_legacy_rate_idx[] = {
@@ -258,6 +257,12 @@ void ath10k_process_rx(struct ath10k *ar, struct htt_rx_info *info)
258 status->band = ch->band; 257 status->band = ch->band;
259 status->freq = ch->center_freq; 258 status->freq = ch->center_freq;
260 259
260 if (info->rate.info0 & HTT_RX_INDICATION_INFO0_END_VALID) {
261 /* TSF available only in 32-bit */
262 status->mactime = info->tsf & 0xffffffff;
263 status->flag |= RX_FLAG_MACTIME_END;
264 }
265
261 ath10k_dbg(ATH10K_DBG_DATA, 266 ath10k_dbg(ATH10K_DBG_DATA,
262 "rx skb %p len %u %s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i\n", 267 "rx skb %p len %u %s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i\n",
263 info->skb, 268 info->skb,
@@ -378,7 +383,8 @@ void ath10k_peer_unmap_event(struct ath10k_htt *htt,
378 spin_lock_bh(&ar->data_lock); 383 spin_lock_bh(&ar->data_lock);
379 peer = ath10k_peer_find_by_id(ar, ev->peer_id); 384 peer = ath10k_peer_find_by_id(ar, ev->peer_id);
380 if (!peer) { 385 if (!peer) {
381 ath10k_warn("unknown peer id %d\n", ev->peer_id); 386 ath10k_warn("peer-unmap-event: unknown peer id %d\n",
387 ev->peer_id);
382 goto exit; 388 goto exit;
383 } 389 }
384 390
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index 91e501b5499e..cb1f7b5bcf4c 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -1360,7 +1360,7 @@ static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1360 struct wmi_bcn_info *bcn_info; 1360 struct wmi_bcn_info *bcn_info;
1361 struct ath10k_vif *arvif; 1361 struct ath10k_vif *arvif;
1362 struct sk_buff *bcn; 1362 struct sk_buff *bcn;
1363 int vdev_id = 0; 1363 int ret, vdev_id = 0;
1364 1364
1365 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n"); 1365 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
1366 1366
@@ -1435,16 +1435,27 @@ static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1435 ath10k_warn("SWBA overrun on vdev %d\n", 1435 ath10k_warn("SWBA overrun on vdev %d\n",
1436 arvif->vdev_id); 1436 arvif->vdev_id);
1437 1437
1438 ath10k_skb_unmap(ar->dev, arvif->beacon); 1438 dma_unmap_single(arvif->ar->dev,
1439 ATH10K_SKB_CB(arvif->beacon)->paddr,
1440 arvif->beacon->len, DMA_TO_DEVICE);
1439 dev_kfree_skb_any(arvif->beacon); 1441 dev_kfree_skb_any(arvif->beacon);
1440 } 1442 }
1441 1443
1442 ath10k_skb_map(ar->dev, bcn); 1444 ATH10K_SKB_CB(bcn)->paddr = dma_map_single(arvif->ar->dev,
1445 bcn->data, bcn->len,
1446 DMA_TO_DEVICE);
1447 ret = dma_mapping_error(arvif->ar->dev,
1448 ATH10K_SKB_CB(bcn)->paddr);
1449 if (ret) {
1450 ath10k_warn("failed to map beacon: %d\n", ret);
1451 goto skip;
1452 }
1443 1453
1444 arvif->beacon = bcn; 1454 arvif->beacon = bcn;
1445 arvif->beacon_sent = false; 1455 arvif->beacon_sent = false;
1446 1456
1447 ath10k_wmi_tx_beacon_nowait(arvif); 1457 ath10k_wmi_tx_beacon_nowait(arvif);
1458skip:
1448 spin_unlock_bh(&ar->data_lock); 1459 spin_unlock_bh(&ar->data_lock);
1449 } 1460 }
1450} 1461}
@@ -3382,7 +3393,6 @@ int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3382 ci->max_power = ch->max_power; 3393 ci->max_power = ch->max_power;
3383 ci->reg_power = ch->max_reg_power; 3394 ci->reg_power = ch->max_reg_power;
3384 ci->antenna_max = ch->max_antenna_gain; 3395 ci->antenna_max = ch->max_antenna_gain;
3385 ci->antenna_max = 0;
3386 3396
3387 /* mode & flags share storage */ 3397 /* mode & flags share storage */
3388 ci->mode = ch->mode; 3398 ci->mode = ch->mode;
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index ef35da84f63b..4b18434ba697 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -751,6 +751,9 @@ ath5k_txbuf_setup(struct ath5k_hw *ah, struct ath5k_buf *bf,
751 bf->skbaddr = dma_map_single(ah->dev, skb->data, skb->len, 751 bf->skbaddr = dma_map_single(ah->dev, skb->data, skb->len,
752 DMA_TO_DEVICE); 752 DMA_TO_DEVICE);
753 753
754 if (dma_mapping_error(ah->dev, bf->skbaddr))
755 return -ENOSPC;
756
754 ieee80211_get_tx_rates(info->control.vif, (control) ? control->sta : NULL, skb, bf->rates, 757 ieee80211_get_tx_rates(info->control.vif, (control) ? control->sta : NULL, skb, bf->rates,
755 ARRAY_SIZE(bf->rates)); 758 ARRAY_SIZE(bf->rates));
756 759
diff --git a/drivers/net/wireless/ath/ath9k/Makefile b/drivers/net/wireless/ath/ath9k/Makefile
index b58fe99ef745..8e1c7b0fe76c 100644
--- a/drivers/net/wireless/ath/ath9k/Makefile
+++ b/drivers/net/wireless/ath/ath9k/Makefile
@@ -52,7 +52,8 @@ obj-$(CONFIG_ATH9K_HW) += ath9k_hw.o
52 52
53obj-$(CONFIG_ATH9K_COMMON) += ath9k_common.o 53obj-$(CONFIG_ATH9K_COMMON) += ath9k_common.o
54ath9k_common-y:= common.o \ 54ath9k_common-y:= common.o \
55 common-init.o 55 common-init.o \
56 common-beacon.o
56 57
57ath9k_htc-y += htc_hst.o \ 58ath9k_htc-y += htc_hst.o \
58 hif_usb.o \ 59 hif_usb.o \
diff --git a/drivers/net/wireless/ath/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c
index 2dff2765769b..a0398fe3eb28 100644
--- a/drivers/net/wireless/ath/ath9k/ahb.c
+++ b/drivers/net/wireless/ath/ath9k/ahb.c
@@ -39,6 +39,10 @@ static const struct platform_device_id ath9k_platform_id_table[] = {
39 .name = "qca955x_wmac", 39 .name = "qca955x_wmac",
40 .driver_data = AR9300_DEVID_QCA955X, 40 .driver_data = AR9300_DEVID_QCA955X,
41 }, 41 },
42 {
43 .name = "qca953x_wmac",
44 .driver_data = AR9300_DEVID_AR953X,
45 },
42 {}, 46 {},
43}; 47};
44 48
@@ -82,6 +86,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
82 int irq; 86 int irq;
83 int ret = 0; 87 int ret = 0;
84 struct ath_hw *ah; 88 struct ath_hw *ah;
89 struct ath_common *common;
85 char hw_name[64]; 90 char hw_name[64];
86 91
87 if (!dev_get_platdata(&pdev->dev)) { 92 if (!dev_get_platdata(&pdev->dev)) {
@@ -124,9 +129,6 @@ static int ath_ahb_probe(struct platform_device *pdev)
124 sc->mem = mem; 129 sc->mem = mem;
125 sc->irq = irq; 130 sc->irq = irq;
126 131
127 /* Will be cleared in ath9k_start() */
128 set_bit(SC_OP_INVALID, &sc->sc_flags);
129
130 ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc); 132 ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
131 if (ret) { 133 if (ret) {
132 dev_err(&pdev->dev, "request_irq failed\n"); 134 dev_err(&pdev->dev, "request_irq failed\n");
@@ -144,6 +146,9 @@ static int ath_ahb_probe(struct platform_device *pdev)
144 wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n", 146 wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n",
145 hw_name, (unsigned long)mem, irq); 147 hw_name, (unsigned long)mem, irq);
146 148
149 common = ath9k_hw_common(sc->sc_ah);
150 /* Will be cleared in ath9k_start() */
151 set_bit(ATH_OP_INVALID, &common->op_flags);
147 return 0; 152 return 0;
148 153
149 err_irq: 154 err_irq:
diff --git a/drivers/net/wireless/ath/ath9k/ani.c b/drivers/net/wireless/ath/ath9k/ani.c
index 2ce5079007b6..6d47783f2e5b 100644
--- a/drivers/net/wireless/ath/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ath9k/ani.c
@@ -318,17 +318,6 @@ void ath9k_ani_reset(struct ath_hw *ah, bool is_scanning)
318 BUG_ON(aniState == NULL); 318 BUG_ON(aniState == NULL);
319 ah->stats.ast_ani_reset++; 319 ah->stats.ast_ani_reset++;
320 320
321 /* only allow a subset of functions in AP mode */
322 if (ah->opmode == NL80211_IFTYPE_AP) {
323 if (IS_CHAN_2GHZ(chan)) {
324 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
325 ATH9K_ANI_FIRSTEP_LEVEL);
326 if (AR_SREV_9300_20_OR_LATER(ah))
327 ah->ani_function |= ATH9K_ANI_MRC_CCK;
328 } else
329 ah->ani_function = 0;
330 }
331
332 ofdm_nil = max_t(int, ATH9K_ANI_OFDM_DEF_LEVEL, 321 ofdm_nil = max_t(int, ATH9K_ANI_OFDM_DEF_LEVEL,
333 aniState->ofdmNoiseImmunityLevel); 322 aniState->ofdmNoiseImmunityLevel);
334 cck_nil = max_t(int, ATH9K_ANI_CCK_DEF_LEVEL, 323 cck_nil = max_t(int, ATH9K_ANI_CCK_DEF_LEVEL,
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index ff415e863ee9..3b3e91057a4c 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -26,10 +26,6 @@ static const int firstep_table[] =
26/* level: 0 1 2 3 4 5 6 7 8 */ 26/* level: 0 1 2 3 4 5 6 7 8 */
27 { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */ 27 { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
28 28
29static const int cycpwrThr1_table[] =
30/* level: 0 1 2 3 4 5 6 7 8 */
31 { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
32
33/* 29/*
34 * register values to turn OFDM weak signal detection OFF 30 * register values to turn OFDM weak signal detection OFF
35 */ 31 */
@@ -921,7 +917,7 @@ static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
921 struct ath_common *common = ath9k_hw_common(ah); 917 struct ath_common *common = ath9k_hw_common(ah);
922 struct ath9k_channel *chan = ah->curchan; 918 struct ath9k_channel *chan = ah->curchan;
923 struct ar5416AniState *aniState = &ah->ani; 919 struct ar5416AniState *aniState = &ah->ani;
924 s32 value, value2; 920 s32 value;
925 921
926 switch (cmd & ah->ani_function) { 922 switch (cmd & ah->ani_function) {
927 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{ 923 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
@@ -1008,42 +1004,11 @@ static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
1008 case ATH9K_ANI_FIRSTEP_LEVEL:{ 1004 case ATH9K_ANI_FIRSTEP_LEVEL:{
1009 u32 level = param; 1005 u32 level = param;
1010 1006
1011 if (level >= ARRAY_SIZE(firstep_table)) { 1007 value = level * 2;
1012 ath_dbg(common, ANI,
1013 "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
1014 level, ARRAY_SIZE(firstep_table));
1015 return false;
1016 }
1017
1018 /*
1019 * make register setting relative to default
1020 * from INI file & cap value
1021 */
1022 value = firstep_table[level] -
1023 firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
1024 aniState->iniDef.firstep;
1025 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
1026 value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
1027 if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
1028 value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
1029 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG, 1008 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
1030 AR_PHY_FIND_SIG_FIRSTEP, 1009 AR_PHY_FIND_SIG_FIRSTEP, value);
1031 value);
1032 /*
1033 * we need to set first step low register too
1034 * make register setting relative to default
1035 * from INI file & cap value
1036 */
1037 value2 = firstep_table[level] -
1038 firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
1039 aniState->iniDef.firstepLow;
1040 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
1041 value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
1042 if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
1043 value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
1044
1045 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW, 1010 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
1046 AR_PHY_FIND_SIG_FIRSTEP_LOW, value2); 1011 AR_PHY_FIND_SIG_FIRSTEP_LOW, value);
1047 1012
1048 if (level != aniState->firstepLevel) { 1013 if (level != aniState->firstepLevel) {
1049 ath_dbg(common, ANI, 1014 ath_dbg(common, ANI,
@@ -1060,7 +1025,7 @@ static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
1060 aniState->firstepLevel, 1025 aniState->firstepLevel,
1061 level, 1026 level,
1062 ATH9K_ANI_FIRSTEP_LVL, 1027 ATH9K_ANI_FIRSTEP_LVL,
1063 value2, 1028 value,
1064 aniState->iniDef.firstepLow); 1029 aniState->iniDef.firstepLow);
1065 if (level > aniState->firstepLevel) 1030 if (level > aniState->firstepLevel)
1066 ah->stats.ast_ani_stepup++; 1031 ah->stats.ast_ani_stepup++;
@@ -1073,41 +1038,13 @@ static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
1073 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{ 1038 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
1074 u32 level = param; 1039 u32 level = param;
1075 1040
1076 if (level >= ARRAY_SIZE(cycpwrThr1_table)) { 1041 value = (level + 1) * 2;
1077 ath_dbg(common, ANI,
1078 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
1079 level, ARRAY_SIZE(cycpwrThr1_table));
1080 return false;
1081 }
1082 /*
1083 * make register setting relative to default
1084 * from INI file & cap value
1085 */
1086 value = cycpwrThr1_table[level] -
1087 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
1088 aniState->iniDef.cycpwrThr1;
1089 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
1090 value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
1091 if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
1092 value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
1093 REG_RMW_FIELD(ah, AR_PHY_TIMING5, 1042 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
1094 AR_PHY_TIMING5_CYCPWR_THR1, 1043 AR_PHY_TIMING5_CYCPWR_THR1, value);
1095 value);
1096 1044
1097 /* 1045 if (IS_CHAN_HT40(ah->curchan))
1098 * set AR_PHY_EXT_CCA for extension channel 1046 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1099 * make register setting relative to default 1047 AR_PHY_EXT_TIMING5_CYCPWR_THR1, value);
1100 * from INI file & cap value
1101 */
1102 value2 = cycpwrThr1_table[level] -
1103 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
1104 aniState->iniDef.cycpwrThr1Ext;
1105 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
1106 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
1107 if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
1108 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
1109 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1110 AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2);
1111 1048
1112 if (level != aniState->spurImmunityLevel) { 1049 if (level != aniState->spurImmunityLevel) {
1113 ath_dbg(common, ANI, 1050 ath_dbg(common, ANI,
@@ -1124,7 +1061,7 @@ static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
1124 aniState->spurImmunityLevel, 1061 aniState->spurImmunityLevel,
1125 level, 1062 level,
1126 ATH9K_ANI_SPUR_IMMUNE_LVL, 1063 ATH9K_ANI_SPUR_IMMUNE_LVL,
1127 value2, 1064 value,
1128 aniState->iniDef.cycpwrThr1Ext); 1065 aniState->iniDef.cycpwrThr1Ext);
1129 if (level > aniState->spurImmunityLevel) 1066 if (level > aniState->spurImmunityLevel)
1130 ah->stats.ast_ani_spurup++; 1067 ah->stats.ast_ani_spurup++;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index b8daff78b9d1..235053ba7737 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -23,8 +23,8 @@
23#define COMP_HDR_LEN 4 23#define COMP_HDR_LEN 4
24#define COMP_CKSUM_LEN 2 24#define COMP_CKSUM_LEN 2
25 25
26#define LE16(x) __constant_cpu_to_le16(x) 26#define LE16(x) cpu_to_le16(x)
27#define LE32(x) __constant_cpu_to_le32(x) 27#define LE32(x) cpu_to_le32(x)
28 28
29/* Local defines to distinguish between extension and control CTL's */ 29/* Local defines to distinguish between extension and control CTL's */
30#define EXT_ADDITIVE (0x8000) 30#define EXT_ADDITIVE (0x8000)
@@ -4792,43 +4792,54 @@ static void ar9003_hw_power_control_override(struct ath_hw *ah,
4792 4792
4793tempslope: 4793tempslope:
4794 if (AR_SREV_9550(ah) || AR_SREV_9531(ah)) { 4794 if (AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
4795 u8 txmask = (eep->baseEepHeader.txrxMask & 0xf0) >> 4;
4796
4795 /* 4797 /*
4796 * AR955x has tempSlope register for each chain. 4798 * AR955x has tempSlope register for each chain.
4797 * Check whether temp_compensation feature is enabled or not. 4799 * Check whether temp_compensation feature is enabled or not.
4798 */ 4800 */
4799 if (eep->baseEepHeader.featureEnable & 0x1) { 4801 if (eep->baseEepHeader.featureEnable & 0x1) {
4800 if (frequency < 4000) { 4802 if (frequency < 4000) {
4801 REG_RMW_FIELD(ah, AR_PHY_TPC_19, 4803 if (txmask & BIT(0))
4802 AR_PHY_TPC_19_ALPHA_THERM, 4804 REG_RMW_FIELD(ah, AR_PHY_TPC_19,
4803 eep->base_ext2.tempSlopeLow); 4805 AR_PHY_TPC_19_ALPHA_THERM,
4804 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B1, 4806 eep->base_ext2.tempSlopeLow);
4805 AR_PHY_TPC_19_ALPHA_THERM, 4807 if (txmask & BIT(1))
4806 temp_slope); 4808 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B1,
4807 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B2, 4809 AR_PHY_TPC_19_ALPHA_THERM,
4808 AR_PHY_TPC_19_ALPHA_THERM, 4810 temp_slope);
4809 eep->base_ext2.tempSlopeHigh); 4811 if (txmask & BIT(2))
4812 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B2,
4813 AR_PHY_TPC_19_ALPHA_THERM,
4814 eep->base_ext2.tempSlopeHigh);
4810 } else { 4815 } else {
4811 REG_RMW_FIELD(ah, AR_PHY_TPC_19, 4816 if (txmask & BIT(0))
4812 AR_PHY_TPC_19_ALPHA_THERM, 4817 REG_RMW_FIELD(ah, AR_PHY_TPC_19,
4813 temp_slope); 4818 AR_PHY_TPC_19_ALPHA_THERM,
4814 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B1, 4819 temp_slope);
4815 AR_PHY_TPC_19_ALPHA_THERM, 4820 if (txmask & BIT(1))
4816 temp_slope1); 4821 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B1,
4817 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B2, 4822 AR_PHY_TPC_19_ALPHA_THERM,
4818 AR_PHY_TPC_19_ALPHA_THERM, 4823 temp_slope1);
4819 temp_slope2); 4824 if (txmask & BIT(2))
4825 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B2,
4826 AR_PHY_TPC_19_ALPHA_THERM,
4827 temp_slope2);
4820 } 4828 }
4821 } else { 4829 } else {
4822 /* 4830 /*
4823 * If temp compensation is not enabled, 4831 * If temp compensation is not enabled,
4824 * set all registers to 0. 4832 * set all registers to 0.
4825 */ 4833 */
4826 REG_RMW_FIELD(ah, AR_PHY_TPC_19, 4834 if (txmask & BIT(0))
4827 AR_PHY_TPC_19_ALPHA_THERM, 0); 4835 REG_RMW_FIELD(ah, AR_PHY_TPC_19,
4828 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B1, 4836 AR_PHY_TPC_19_ALPHA_THERM, 0);
4829 AR_PHY_TPC_19_ALPHA_THERM, 0); 4837 if (txmask & BIT(1))
4830 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B2, 4838 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B1,
4831 AR_PHY_TPC_19_ALPHA_THERM, 0); 4839 AR_PHY_TPC_19_ALPHA_THERM, 0);
4840 if (txmask & BIT(2))
4841 REG_RMW_FIELD(ah, AR_PHY_TPC_19_B2,
4842 AR_PHY_TPC_19_ALPHA_THERM, 0);
4832 } 4843 }
4833 } else { 4844 } else {
4834 REG_RMW_FIELD(ah, AR_PHY_TPC_19, 4845 REG_RMW_FIELD(ah, AR_PHY_TPC_19,
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index f995c374a9b4..44d74495c4de 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -403,20 +403,10 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
403#define ATH_BCBUF 8 403#define ATH_BCBUF 8
404#define ATH_DEFAULT_BINTVAL 100 /* TU */ 404#define ATH_DEFAULT_BINTVAL 100 /* TU */
405#define ATH_DEFAULT_BMISS_LIMIT 10 405#define ATH_DEFAULT_BMISS_LIMIT 10
406#define IEEE80211_MS_TO_TU(x) (((x) * 1000) / 1024)
407 406
408#define TSF_TO_TU(_h,_l) \ 407#define TSF_TO_TU(_h,_l) \
409 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10)) 408 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
410 409
411struct ath_beacon_config {
412 int beacon_interval;
413 u16 dtim_period;
414 u16 bmiss_timeout;
415 u8 dtim_count;
416 bool enable_beacon;
417 bool ibss_creator;
418};
419
420struct ath_beacon { 410struct ath_beacon {
421 enum { 411 enum {
422 OK, /* no change needed */ 412 OK, /* no change needed */
@@ -426,11 +416,9 @@ struct ath_beacon {
426 416
427 u32 beaconq; 417 u32 beaconq;
428 u32 bmisscnt; 418 u32 bmisscnt;
429 u32 bc_tstamp;
430 struct ieee80211_vif *bslot[ATH_BCBUF]; 419 struct ieee80211_vif *bslot[ATH_BCBUF];
431 int slottime; 420 int slottime;
432 int slotupdate; 421 int slotupdate;
433 struct ath9k_tx_queue_info beacon_qi;
434 struct ath_descdma bdma; 422 struct ath_descdma bdma;
435 struct ath_txq *cabq; 423 struct ath_txq *cabq;
436 struct list_head bbuf; 424 struct list_head bbuf;
@@ -697,15 +685,6 @@ void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
697#define ATH_TXPOWER_MAX 100 /* .5 dBm units */ 685#define ATH_TXPOWER_MAX 100 /* .5 dBm units */
698#define MAX_GTT_CNT 5 686#define MAX_GTT_CNT 5
699 687
700enum sc_op_flags {
701 SC_OP_INVALID,
702 SC_OP_BEACONS,
703 SC_OP_ANI_RUN,
704 SC_OP_PRIM_STA_VIF,
705 SC_OP_HW_RESET,
706 SC_OP_SCANNING,
707};
708
709/* Powersave flags */ 688/* Powersave flags */
710#define PS_WAIT_FOR_BEACON BIT(0) 689#define PS_WAIT_FOR_BEACON BIT(0)
711#define PS_WAIT_FOR_CAB BIT(1) 690#define PS_WAIT_FOR_CAB BIT(1)
@@ -735,7 +714,6 @@ struct ath_softc {
735 struct completion paprd_complete; 714 struct completion paprd_complete;
736 wait_queue_head_t tx_wait; 715 wait_queue_head_t tx_wait;
737 716
738 unsigned long sc_flags;
739 unsigned long driver_data; 717 unsigned long driver_data;
740 718
741 u8 gtt_cnt; 719 u8 gtt_cnt;
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index 02eb4f10332b..471e0f624e81 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -328,7 +328,7 @@ void ath9k_beacon_tasklet(unsigned long data)
328 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); 328 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
329 int slot; 329 int slot;
330 330
331 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) { 331 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
332 ath_dbg(common, RESET, 332 ath_dbg(common, RESET,
333 "reset work is pending, skip beaconing now\n"); 333 "reset work is pending, skip beaconing now\n");
334 return; 334 return;
@@ -447,33 +447,6 @@ static void ath9k_beacon_init(struct ath_softc *sc, u32 nexttbtt,
447 ath9k_hw_enable_interrupts(ah); 447 ath9k_hw_enable_interrupts(ah);
448} 448}
449 449
450/* Calculate the modulo of a 64 bit TSF snapshot with a TU divisor */
451static u32 ath9k_mod_tsf64_tu(u64 tsf, u32 div_tu)
452{
453 u32 tsf_mod, tsf_hi, tsf_lo, mod_hi, mod_lo;
454
455 tsf_mod = tsf & (BIT(10) - 1);
456 tsf_hi = tsf >> 32;
457 tsf_lo = ((u32) tsf) >> 10;
458
459 mod_hi = tsf_hi % div_tu;
460 mod_lo = ((mod_hi << 22) + tsf_lo) % div_tu;
461
462 return (mod_lo << 10) | tsf_mod;
463}
464
465static u32 ath9k_get_next_tbtt(struct ath_softc *sc, u64 tsf,
466 unsigned int interval)
467{
468 struct ath_hw *ah = sc->sc_ah;
469 unsigned int offset;
470
471 tsf += TU_TO_USEC(FUDGE + ah->config.sw_beacon_response_time);
472 offset = ath9k_mod_tsf64_tu(tsf, interval);
473
474 return (u32) tsf + TU_TO_USEC(interval) - offset;
475}
476
477/* 450/*
478 * For multi-bss ap support beacons are either staggered evenly over N slots or 451 * For multi-bss ap support beacons are either staggered evenly over N slots or
479 * burst together. For the former arrange for the SWBA to be delivered for each 452 * burst together. For the former arrange for the SWBA to be delivered for each
@@ -483,109 +456,18 @@ static void ath9k_beacon_config_ap(struct ath_softc *sc,
483 struct ath_beacon_config *conf) 456 struct ath_beacon_config *conf)
484{ 457{
485 struct ath_hw *ah = sc->sc_ah; 458 struct ath_hw *ah = sc->sc_ah;
486 struct ath_common *common = ath9k_hw_common(ah);
487 u32 nexttbtt, intval;
488
489 /* NB: the beacon interval is kept internally in TU's */
490 intval = TU_TO_USEC(conf->beacon_interval);
491 intval /= ATH_BCBUF;
492 nexttbtt = ath9k_get_next_tbtt(sc, ath9k_hw_gettsf64(ah),
493 conf->beacon_interval);
494
495 if (conf->enable_beacon)
496 ah->imask |= ATH9K_INT_SWBA;
497 else
498 ah->imask &= ~ATH9K_INT_SWBA;
499 459
500 ath_dbg(common, BEACON, 460 ath9k_cmn_beacon_config_ap(ah, conf, ATH_BCBUF);
501 "AP (%s) nexttbtt: %u intval: %u conf_intval: %u\n", 461 ath9k_beacon_init(sc, conf->nexttbtt, conf->intval, false);
502 (conf->enable_beacon) ? "Enable" : "Disable",
503 nexttbtt, intval, conf->beacon_interval);
504
505 ath9k_beacon_init(sc, nexttbtt, intval, false);
506} 462}
507 463
508/* 464static void ath9k_beacon_config_sta(struct ath_hw *ah,
509 * This sets up the beacon timers according to the timestamp of the last
510 * received beacon and the current TSF, configures PCF and DTIM
511 * handling, programs the sleep registers so the hardware will wakeup in
512 * time to receive beacons, and configures the beacon miss handling so
513 * we'll receive a BMISS interrupt when we stop seeing beacons from the AP
514 * we've associated with.
515 */
516static void ath9k_beacon_config_sta(struct ath_softc *sc,
517 struct ath_beacon_config *conf) 465 struct ath_beacon_config *conf)
518{ 466{
519 struct ath_hw *ah = sc->sc_ah;
520 struct ath_common *common = ath9k_hw_common(ah);
521 struct ath9k_beacon_state bs; 467 struct ath9k_beacon_state bs;
522 int dtim_intval;
523 u32 nexttbtt = 0, intval;
524 u64 tsf;
525 468
526 /* No need to configure beacon if we are not associated */ 469 if (ath9k_cmn_beacon_config_sta(ah, conf, &bs) == -EPERM)
527 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
528 ath_dbg(common, BEACON,
529 "STA is not yet associated..skipping beacon config\n");
530 return; 470 return;
531 }
532
533 memset(&bs, 0, sizeof(bs));
534 intval = conf->beacon_interval;
535
536 /*
537 * Setup dtim parameters according to
538 * last beacon we received (which may be none).
539 */
540 dtim_intval = intval * conf->dtim_period;
541
542 /*
543 * Pull nexttbtt forward to reflect the current
544 * TSF and calculate dtim state for the result.
545 */
546 tsf = ath9k_hw_gettsf64(ah);
547 nexttbtt = ath9k_get_next_tbtt(sc, tsf, intval);
548
549 bs.bs_intval = TU_TO_USEC(intval);
550 bs.bs_dtimperiod = conf->dtim_period * bs.bs_intval;
551 bs.bs_nexttbtt = nexttbtt;
552 bs.bs_nextdtim = nexttbtt;
553 if (conf->dtim_period > 1)
554 bs.bs_nextdtim = ath9k_get_next_tbtt(sc, tsf, dtim_intval);
555
556 /*
557 * Calculate the number of consecutive beacons to miss* before taking
558 * a BMISS interrupt. The configuration is specified in TU so we only
559 * need calculate based on the beacon interval. Note that we clamp the
560 * result to at most 15 beacons.
561 */
562 bs.bs_bmissthreshold = DIV_ROUND_UP(conf->bmiss_timeout, intval);
563 if (bs.bs_bmissthreshold > 15)
564 bs.bs_bmissthreshold = 15;
565 else if (bs.bs_bmissthreshold <= 0)
566 bs.bs_bmissthreshold = 1;
567
568 /*
569 * Calculate sleep duration. The configuration is given in ms.
570 * We ensure a multiple of the beacon period is used. Also, if the sleep
571 * duration is greater than the DTIM period then it makes senses
572 * to make it a multiple of that.
573 *
574 * XXX fixed at 100ms
575 */
576
577 bs.bs_sleepduration = TU_TO_USEC(roundup(IEEE80211_MS_TO_TU(100),
578 intval));
579 if (bs.bs_sleepduration > bs.bs_dtimperiod)
580 bs.bs_sleepduration = bs.bs_dtimperiod;
581
582 /* TSF out of range threshold fixed at 1 second */
583 bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
584
585 ath_dbg(common, BEACON, "bmiss: %u sleep: %u\n",
586 bs.bs_bmissthreshold, bs.bs_sleepduration);
587
588 /* Set the computed STA beacon timers */
589 471
590 ath9k_hw_disable_interrupts(ah); 472 ath9k_hw_disable_interrupts(ah);
591 ath9k_hw_set_sta_beacon_timers(ah, &bs); 473 ath9k_hw_set_sta_beacon_timers(ah, &bs);
@@ -600,36 +482,19 @@ static void ath9k_beacon_config_adhoc(struct ath_softc *sc,
600{ 482{
601 struct ath_hw *ah = sc->sc_ah; 483 struct ath_hw *ah = sc->sc_ah;
602 struct ath_common *common = ath9k_hw_common(ah); 484 struct ath_common *common = ath9k_hw_common(ah);
603 u32 intval, nexttbtt;
604 485
605 ath9k_reset_beacon_status(sc); 486 ath9k_reset_beacon_status(sc);
606 487
607 intval = TU_TO_USEC(conf->beacon_interval); 488 ath9k_cmn_beacon_config_adhoc(ah, conf);
608
609 if (conf->ibss_creator)
610 nexttbtt = intval;
611 else
612 nexttbtt = ath9k_get_next_tbtt(sc, ath9k_hw_gettsf64(ah),
613 conf->beacon_interval);
614
615 if (conf->enable_beacon)
616 ah->imask |= ATH9K_INT_SWBA;
617 else
618 ah->imask &= ~ATH9K_INT_SWBA;
619
620 ath_dbg(common, BEACON,
621 "IBSS (%s) nexttbtt: %u intval: %u conf_intval: %u\n",
622 (conf->enable_beacon) ? "Enable" : "Disable",
623 nexttbtt, intval, conf->beacon_interval);
624 489
625 ath9k_beacon_init(sc, nexttbtt, intval, conf->ibss_creator); 490 ath9k_beacon_init(sc, conf->nexttbtt, conf->intval, conf->ibss_creator);
626 491
627 /* 492 /*
628 * Set the global 'beacon has been configured' flag for the 493 * Set the global 'beacon has been configured' flag for the
629 * joiner case in IBSS mode. 494 * joiner case in IBSS mode.
630 */ 495 */
631 if (!conf->ibss_creator && conf->enable_beacon) 496 if (!conf->ibss_creator && conf->enable_beacon)
632 set_bit(SC_OP_BEACONS, &sc->sc_flags); 497 set_bit(ATH_OP_BEACONS, &common->op_flags);
633} 498}
634 499
635static bool ath9k_allow_beacon_config(struct ath_softc *sc, 500static bool ath9k_allow_beacon_config(struct ath_softc *sc,
@@ -649,7 +514,7 @@ static bool ath9k_allow_beacon_config(struct ath_softc *sc,
649 514
650 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) { 515 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
651 if ((vif->type == NL80211_IFTYPE_STATION) && 516 if ((vif->type == NL80211_IFTYPE_STATION) &&
652 test_bit(SC_OP_BEACONS, &sc->sc_flags) && 517 test_bit(ATH_OP_BEACONS, &common->op_flags) &&
653 !avp->primary_sta_vif) { 518 !avp->primary_sta_vif) {
654 ath_dbg(common, CONFIG, 519 ath_dbg(common, CONFIG,
655 "Beacon already configured for a station interface\n"); 520 "Beacon already configured for a station interface\n");
@@ -700,6 +565,8 @@ void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
700{ 565{
701 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 566 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
702 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf; 567 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
568 struct ath_hw *ah = sc->sc_ah;
569 struct ath_common *common = ath9k_hw_common(ah);
703 unsigned long flags; 570 unsigned long flags;
704 bool skip_beacon = false; 571 bool skip_beacon = false;
705 572
@@ -712,7 +579,7 @@ void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
712 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) { 579 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
713 ath9k_cache_beacon_config(sc, bss_conf); 580 ath9k_cache_beacon_config(sc, bss_conf);
714 ath9k_set_beacon(sc); 581 ath9k_set_beacon(sc);
715 set_bit(SC_OP_BEACONS, &sc->sc_flags); 582 set_bit(ATH_OP_BEACONS, &common->op_flags);
716 return; 583 return;
717 } 584 }
718 585
@@ -751,13 +618,13 @@ void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
751 } 618 }
752 619
753 /* 620 /*
754 * Do not set the SC_OP_BEACONS flag for IBSS joiner mode 621 * Do not set the ATH_OP_BEACONS flag for IBSS joiner mode
755 * here, it is done in ath9k_beacon_config_adhoc(). 622 * here, it is done in ath9k_beacon_config_adhoc().
756 */ 623 */
757 if (cur_conf->enable_beacon && !skip_beacon) 624 if (cur_conf->enable_beacon && !skip_beacon)
758 set_bit(SC_OP_BEACONS, &sc->sc_flags); 625 set_bit(ATH_OP_BEACONS, &common->op_flags);
759 else 626 else
760 clear_bit(SC_OP_BEACONS, &sc->sc_flags); 627 clear_bit(ATH_OP_BEACONS, &common->op_flags);
761 } 628 }
762} 629}
763 630
@@ -775,7 +642,7 @@ void ath9k_set_beacon(struct ath_softc *sc)
775 ath9k_beacon_config_adhoc(sc, cur_conf); 642 ath9k_beacon_config_adhoc(sc, cur_conf);
776 break; 643 break;
777 case NL80211_IFTYPE_STATION: 644 case NL80211_IFTYPE_STATION:
778 ath9k_beacon_config_sta(sc, cur_conf); 645 ath9k_beacon_config_sta(sc->sc_ah, cur_conf);
779 break; 646 break;
780 default: 647 default:
781 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n"); 648 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n");
diff --git a/drivers/net/wireless/ath/ath9k/common-beacon.c b/drivers/net/wireless/ath/ath9k/common-beacon.c
new file mode 100644
index 000000000000..775d1d20ce0b
--- /dev/null
+++ b/drivers/net/wireless/ath/ath9k/common-beacon.c
@@ -0,0 +1,180 @@
1/*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "common.h"
18
19#define FUDGE 2
20
21/* Calculate the modulo of a 64 bit TSF snapshot with a TU divisor */
22static u32 ath9k_mod_tsf64_tu(u64 tsf, u32 div_tu)
23{
24 u32 tsf_mod, tsf_hi, tsf_lo, mod_hi, mod_lo;
25
26 tsf_mod = tsf & (BIT(10) - 1);
27 tsf_hi = tsf >> 32;
28 tsf_lo = ((u32) tsf) >> 10;
29
30 mod_hi = tsf_hi % div_tu;
31 mod_lo = ((mod_hi << 22) + tsf_lo) % div_tu;
32
33 return (mod_lo << 10) | tsf_mod;
34}
35
36static u32 ath9k_get_next_tbtt(struct ath_hw *ah, u64 tsf,
37 unsigned int interval)
38{
39 unsigned int offset;
40
41 tsf += TU_TO_USEC(FUDGE + ah->config.sw_beacon_response_time);
42 offset = ath9k_mod_tsf64_tu(tsf, interval);
43
44 return (u32) tsf + TU_TO_USEC(interval) - offset;
45}
46
47/*
48 * This sets up the beacon timers according to the timestamp of the last
49 * received beacon and the current TSF, configures PCF and DTIM
50 * handling, programs the sleep registers so the hardware will wakeup in
51 * time to receive beacons, and configures the beacon miss handling so
52 * we'll receive a BMISS interrupt when we stop seeing beacons from the AP
53 * we've associated with.
54 */
55int ath9k_cmn_beacon_config_sta(struct ath_hw *ah,
56 struct ath_beacon_config *conf,
57 struct ath9k_beacon_state *bs)
58{
59 struct ath_common *common = ath9k_hw_common(ah);
60 int dtim_intval;
61 u64 tsf;
62
63 /* No need to configure beacon if we are not associated */
64 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
65 ath_dbg(common, BEACON,
66 "STA is not yet associated..skipping beacon config\n");
67 return -EPERM;
68 }
69
70 memset(bs, 0, sizeof(*bs));
71 conf->intval = conf->beacon_interval;
72
73 /*
74 * Setup dtim parameters according to
75 * last beacon we received (which may be none).
76 */
77 dtim_intval = conf->intval * conf->dtim_period;
78
79 /*
80 * Pull nexttbtt forward to reflect the current
81 * TSF and calculate dtim state for the result.
82 */
83 tsf = ath9k_hw_gettsf64(ah);
84 conf->nexttbtt = ath9k_get_next_tbtt(ah, tsf, conf->intval);
85
86 bs->bs_intval = TU_TO_USEC(conf->intval);
87 bs->bs_dtimperiod = conf->dtim_period * bs->bs_intval;
88 bs->bs_nexttbtt = conf->nexttbtt;
89 bs->bs_nextdtim = conf->nexttbtt;
90 if (conf->dtim_period > 1)
91 bs->bs_nextdtim = ath9k_get_next_tbtt(ah, tsf, dtim_intval);
92
93 /*
94 * Calculate the number of consecutive beacons to miss* before taking
95 * a BMISS interrupt. The configuration is specified in TU so we only
96 * need calculate based on the beacon interval. Note that we clamp the
97 * result to at most 15 beacons.
98 */
99 bs->bs_bmissthreshold = DIV_ROUND_UP(conf->bmiss_timeout, conf->intval);
100 if (bs->bs_bmissthreshold > 15)
101 bs->bs_bmissthreshold = 15;
102 else if (bs->bs_bmissthreshold <= 0)
103 bs->bs_bmissthreshold = 1;
104
105 /*
106 * Calculate sleep duration. The configuration is given in ms.
107 * We ensure a multiple of the beacon period is used. Also, if the sleep
108 * duration is greater than the DTIM period then it makes senses
109 * to make it a multiple of that.
110 *
111 * XXX fixed at 100ms
112 */
113
114 bs->bs_sleepduration = TU_TO_USEC(roundup(IEEE80211_MS_TO_TU(100),
115 conf->intval));
116 if (bs->bs_sleepduration > bs->bs_dtimperiod)
117 bs->bs_sleepduration = bs->bs_dtimperiod;
118
119 /* TSF out of range threshold fixed at 1 second */
120 bs->bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
121
122 ath_dbg(common, BEACON, "bmiss: %u sleep: %u\n",
123 bs->bs_bmissthreshold, bs->bs_sleepduration);
124 return 0;
125}
126EXPORT_SYMBOL(ath9k_cmn_beacon_config_sta);
127
128void ath9k_cmn_beacon_config_adhoc(struct ath_hw *ah,
129 struct ath_beacon_config *conf)
130{
131 struct ath_common *common = ath9k_hw_common(ah);
132
133 conf->intval = TU_TO_USEC(conf->beacon_interval);
134
135 if (conf->ibss_creator)
136 conf->nexttbtt = conf->intval;
137 else
138 conf->nexttbtt = ath9k_get_next_tbtt(ah, ath9k_hw_gettsf64(ah),
139 conf->beacon_interval);
140
141 if (conf->enable_beacon)
142 ah->imask |= ATH9K_INT_SWBA;
143 else
144 ah->imask &= ~ATH9K_INT_SWBA;
145
146 ath_dbg(common, BEACON,
147 "IBSS (%s) nexttbtt: %u intval: %u conf_intval: %u\n",
148 (conf->enable_beacon) ? "Enable" : "Disable",
149 conf->nexttbtt, conf->intval, conf->beacon_interval);
150}
151EXPORT_SYMBOL(ath9k_cmn_beacon_config_adhoc);
152
153/*
154 * For multi-bss ap support beacons are either staggered evenly over N slots or
155 * burst together. For the former arrange for the SWBA to be delivered for each
156 * slot. Slots that are not occupied will generate nothing.
157 */
158void ath9k_cmn_beacon_config_ap(struct ath_hw *ah,
159 struct ath_beacon_config *conf,
160 unsigned int bc_buf)
161{
162 struct ath_common *common = ath9k_hw_common(ah);
163
164 /* NB: the beacon interval is kept internally in TU's */
165 conf->intval = TU_TO_USEC(conf->beacon_interval);
166 conf->intval /= bc_buf;
167 conf->nexttbtt = ath9k_get_next_tbtt(ah, ath9k_hw_gettsf64(ah),
168 conf->beacon_interval);
169
170 if (conf->enable_beacon)
171 ah->imask |= ATH9K_INT_SWBA;
172 else
173 ah->imask &= ~ATH9K_INT_SWBA;
174
175 ath_dbg(common, BEACON,
176 "AP (%s) nexttbtt: %u intval: %u conf_intval: %u\n",
177 (conf->enable_beacon) ? "Enable" : "Disable",
178 conf->nexttbtt, conf->intval, conf->beacon_interval);
179}
180EXPORT_SYMBOL(ath9k_cmn_beacon_config_ap);
diff --git a/drivers/net/wireless/ath/ath9k/common-beacon.h b/drivers/net/wireless/ath/ath9k/common-beacon.h
new file mode 100644
index 000000000000..3665d27f0dc7
--- /dev/null
+++ b/drivers/net/wireless/ath/ath9k/common-beacon.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (c) 2009-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17struct ath_beacon_config;
18
19int ath9k_cmn_beacon_config_sta(struct ath_hw *ah,
20 struct ath_beacon_config *conf,
21 struct ath9k_beacon_state *bs);
22void ath9k_cmn_beacon_config_adhoc(struct ath_hw *ah,
23 struct ath_beacon_config *conf);
24void ath9k_cmn_beacon_config_ap(struct ath_hw *ah,
25 struct ath_beacon_config *conf,
26 unsigned int bc_buf);
diff --git a/drivers/net/wireless/ath/ath9k/common.h b/drivers/net/wireless/ath/ath9k/common.h
index 4c449e35bd65..ca38116838f0 100644
--- a/drivers/net/wireless/ath/ath9k/common.h
+++ b/drivers/net/wireless/ath/ath9k/common.h
@@ -22,6 +22,7 @@
22#include "hw-ops.h" 22#include "hw-ops.h"
23 23
24#include "common-init.h" 24#include "common-init.h"
25#include "common-beacon.h"
25 26
26/* Common header for Atheros 802.11n base driver cores */ 27/* Common header for Atheros 802.11n base driver cores */
27 28
@@ -44,6 +45,19 @@
44#define ATH_EP_RND(x, mul) \ 45#define ATH_EP_RND(x, mul) \
45 (((x) + ((mul)/2)) / (mul)) 46 (((x) + ((mul)/2)) / (mul))
46 47
48#define IEEE80211_MS_TO_TU(x) (((x) * 1000) / 1024)
49
50struct ath_beacon_config {
51 int beacon_interval;
52 u16 dtim_period;
53 u16 bmiss_timeout;
54 u8 dtim_count;
55 bool enable_beacon;
56 bool ibss_creator;
57 u32 nexttbtt;
58 u32 intval;
59};
60
47bool ath9k_cmn_rx_accept(struct ath_common *common, 61bool ath9k_cmn_rx_accept(struct ath_common *common,
48 struct ieee80211_hdr *hdr, 62 struct ieee80211_hdr *hdr,
49 struct ieee80211_rx_status *rxs, 63 struct ieee80211_rx_status *rxs,
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index f8924efdad55..780ff1bee6f6 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -139,43 +139,41 @@ static ssize_t read_file_ani(struct file *file, char __user *user_buf,
139 const unsigned int size = 1024; 139 const unsigned int size = 1024;
140 ssize_t retval = 0; 140 ssize_t retval = 0;
141 char *buf; 141 char *buf;
142 int i;
143 struct {
144 const char *name;
145 unsigned int val;
146 } ani_info[] = {
147 { "ANI RESET", ah->stats.ast_ani_reset },
148 { "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
149 { "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
150 { "SPUR UP", ah->stats.ast_ani_spurup },
151 { "SPUR DOWN", ah->stats.ast_ani_spurup },
152 { "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
153 { "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
154 { "MRC-CCK ON", ah->stats.ast_ani_ccklow },
155 { "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
156 { "FIR-STEP UP", ah->stats.ast_ani_stepup },
157 { "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
158 { "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
159 { "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
160 { "CCK ERRORS", ah->stats.ast_ani_cckerrs },
161 };
142 162
143 buf = kzalloc(size, GFP_KERNEL); 163 buf = kzalloc(size, GFP_KERNEL);
144 if (buf == NULL) 164 if (buf == NULL)
145 return -ENOMEM; 165 return -ENOMEM;
146 166
147 if (common->disable_ani) { 167 len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
148 len += scnprintf(buf + len, size - len, "%s: %s\n", 168 common->disable_ani ? "DISABLED" : "ENABLED");
149 "ANI", "DISABLED"); 169
170 if (common->disable_ani)
150 goto exit; 171 goto exit;
151 }
152 172
153 len += scnprintf(buf + len, size - len, "%15s: %s\n", 173 for (i = 0; i < ARRAY_SIZE(ani_info); i++)
154 "ANI", "ENABLED"); 174 len += scnprintf(buf + len, size - len, "%15s: %u\n",
155 len += scnprintf(buf + len, size - len, "%15s: %u\n", 175 ani_info[i].name, ani_info[i].val);
156 "ANI RESET", ah->stats.ast_ani_reset); 176
157 len += scnprintf(buf + len, size - len, "%15s: %u\n",
158 "SPUR UP", ah->stats.ast_ani_spurup);
159 len += scnprintf(buf + len, size - len, "%15s: %u\n",
160 "SPUR DOWN", ah->stats.ast_ani_spurup);
161 len += scnprintf(buf + len, size - len, "%15s: %u\n",
162 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
163 len += scnprintf(buf + len, size - len, "%15s: %u\n",
164 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
165 len += scnprintf(buf + len, size - len, "%15s: %u\n",
166 "MRC-CCK ON", ah->stats.ast_ani_ccklow);
167 len += scnprintf(buf + len, size - len, "%15s: %u\n",
168 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
169 len += scnprintf(buf + len, size - len, "%15s: %u\n",
170 "FIR-STEP UP", ah->stats.ast_ani_stepup);
171 len += scnprintf(buf + len, size - len, "%15s: %u\n",
172 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
173 len += scnprintf(buf + len, size - len, "%15s: %u\n",
174 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
175 len += scnprintf(buf + len, size - len, "%15s: %u\n",
176 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
177 len += scnprintf(buf + len, size - len, "%15s: %u\n",
178 "CCK ERRORS", ah->stats.ast_ani_cckerrs);
179exit: 177exit:
180 if (len > size) 178 if (len > size)
181 len = size; 179 len = size;
@@ -210,7 +208,7 @@ static ssize_t write_file_ani(struct file *file,
210 common->disable_ani = !ani; 208 common->disable_ani = !ani;
211 209
212 if (common->disable_ani) { 210 if (common->disable_ani) {
213 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags); 211 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
214 ath_stop_ani(sc); 212 ath_stop_ani(sc);
215 } else { 213 } else {
216 ath_check_ani(sc); 214 ath_check_ani(sc);
diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h
index 3baf9ceae601..dab1f0cab993 100644
--- a/drivers/net/wireless/ath/ath9k/htc.h
+++ b/drivers/net/wireless/ath/ath9k/htc.h
@@ -39,7 +39,6 @@
39#define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */ 39#define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */
40 40
41#define ATH_DEFAULT_BMISS_LIMIT 10 41#define ATH_DEFAULT_BMISS_LIMIT 10
42#define IEEE80211_MS_TO_TU(x) (((x) * 1000) / 1024)
43#define TSF_TO_TU(_h, _l) \ 42#define TSF_TO_TU(_h, _l) \
44 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10)) 43 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
45 44
@@ -406,12 +405,18 @@ static inline void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv,
406#define DEFAULT_SWBA_RESPONSE 40 /* in TUs */ 405#define DEFAULT_SWBA_RESPONSE 40 /* in TUs */
407#define MIN_SWBA_RESPONSE 10 /* in TUs */ 406#define MIN_SWBA_RESPONSE 10 /* in TUs */
408 407
409struct htc_beacon_config { 408struct htc_beacon {
409 enum {
410 OK, /* no change needed */
411 UPDATE, /* update pending */
412 COMMIT /* beacon sent, commit change */
413 } updateslot; /* slot time update fsm */
414
410 struct ieee80211_vif *bslot[ATH9K_HTC_MAX_BCN_VIF]; 415 struct ieee80211_vif *bslot[ATH9K_HTC_MAX_BCN_VIF];
411 u16 beacon_interval; 416 u32 bmisscnt;
412 u16 dtim_period; 417 u32 beaconq;
413 u16 bmiss_timeout; 418 int slottime;
414 u32 bmiss_cnt; 419 int slotupdate;
415}; 420};
416 421
417struct ath_btcoex { 422struct ath_btcoex {
@@ -439,12 +444,8 @@ static inline void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv)
439} 444}
440#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */ 445#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
441 446
442#define OP_INVALID BIT(0)
443#define OP_SCANNING BIT(1)
444#define OP_ENABLE_BEACON BIT(2)
445#define OP_BT_PRIORITY_DETECTED BIT(3) 447#define OP_BT_PRIORITY_DETECTED BIT(3)
446#define OP_BT_SCAN BIT(4) 448#define OP_BT_SCAN BIT(4)
447#define OP_ANI_RUNNING BIT(5)
448#define OP_TSF_RESET BIT(6) 449#define OP_TSF_RESET BIT(6)
449 450
450struct ath9k_htc_priv { 451struct ath9k_htc_priv {
@@ -489,7 +490,8 @@ struct ath9k_htc_priv {
489 struct ath9k_hw_cal_data caldata; 490 struct ath9k_hw_cal_data caldata;
490 491
491 spinlock_t beacon_lock; 492 spinlock_t beacon_lock;
492 struct htc_beacon_config cur_beacon_conf; 493 struct ath_beacon_config cur_beacon_conf;
494 struct htc_beacon beacon;
493 495
494 struct ath9k_htc_rx rx; 496 struct ath9k_htc_rx rx;
495 struct ath9k_htc_tx tx; 497 struct ath9k_htc_tx tx;
@@ -514,7 +516,6 @@ struct ath9k_htc_priv {
514 struct work_struct led_work; 516 struct work_struct led_work;
515#endif 517#endif
516 518
517 int beaconq;
518 int cabq; 519 int cabq;
519 int hwq_map[IEEE80211_NUM_ACS]; 520 int hwq_map[IEEE80211_NUM_ACS];
520 521
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
index a00ddb9e737e..e8b6ec3c1dbb 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_beacon.c
@@ -26,7 +26,7 @@ void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv)
26 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); 26 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
27 memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info)); 27 memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info));
28 28
29 ath9k_hw_get_txq_props(ah, priv->beaconq, &qi); 29 ath9k_hw_get_txq_props(ah, priv->beacon.beaconq, &qi);
30 30
31 if (priv->ah->opmode == NL80211_IFTYPE_AP || 31 if (priv->ah->opmode == NL80211_IFTYPE_AP ||
32 priv->ah->opmode == NL80211_IFTYPE_MESH_POINT) { 32 priv->ah->opmode == NL80211_IFTYPE_MESH_POINT) {
@@ -54,212 +54,78 @@ void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv)
54 54
55 } 55 }
56 56
57 if (!ath9k_hw_set_txq_props(ah, priv->beaconq, &qi)) { 57 if (!ath9k_hw_set_txq_props(ah, priv->beacon.beaconq, &qi)) {
58 ath_err(ath9k_hw_common(ah), 58 ath_err(ath9k_hw_common(ah),
59 "Unable to update beacon queue %u!\n", priv->beaconq); 59 "Unable to update beacon queue %u!\n", priv->beacon.beaconq);
60 } else { 60 } else {
61 ath9k_hw_resettxqueue(ah, priv->beaconq); 61 ath9k_hw_resettxqueue(ah, priv->beacon.beaconq);
62 } 62 }
63} 63}
64 64
65 65/*
66static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv, 66 * Both nexttbtt and intval have to be in usecs.
67 struct htc_beacon_config *bss_conf) 67 */
68static void ath9k_htc_beacon_init(struct ath9k_htc_priv *priv,
69 struct ath_beacon_config *conf,
70 bool reset_tsf)
68{ 71{
69 struct ath_common *common = ath9k_hw_common(priv->ah); 72 struct ath_hw *ah = priv->ah;
70 struct ath9k_beacon_state bs;
71 enum ath9k_int imask = 0;
72 int dtimperiod, dtimcount;
73 int bmiss_timeout;
74 u32 nexttbtt = 0, intval, tsftu;
75 __be32 htc_imask = 0;
76 u64 tsf;
77 int num_beacons, offset, dtim_dec_count;
78 int ret __attribute__ ((unused)); 73 int ret __attribute__ ((unused));
74 __be32 htc_imask = 0;
79 u8 cmd_rsp; 75 u8 cmd_rsp;
80 76
81 memset(&bs, 0, sizeof(bs)); 77 if (conf->intval >= TU_TO_USEC(DEFAULT_SWBA_RESPONSE))
82 78 ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE;
83 intval = bss_conf->beacon_interval; 79 else
84 bmiss_timeout = (ATH_DEFAULT_BMISS_LIMIT * bss_conf->beacon_interval); 80 ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE;
85
86 /*
87 * Setup dtim parameters according to
88 * last beacon we received (which may be none).
89 */
90 dtimperiod = bss_conf->dtim_period;
91 if (dtimperiod <= 0) /* NB: 0 if not known */
92 dtimperiod = 1;
93 dtimcount = 1;
94 if (dtimcount >= dtimperiod) /* NB: sanity check */
95 dtimcount = 0;
96
97 /*
98 * Pull nexttbtt forward to reflect the current
99 * TSF and calculate dtim state for the result.
100 */
101 tsf = ath9k_hw_gettsf64(priv->ah);
102 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
103
104 num_beacons = tsftu / intval + 1;
105 offset = tsftu % intval;
106 nexttbtt = tsftu - offset;
107 if (offset)
108 nexttbtt += intval;
109
110 /* DTIM Beacon every dtimperiod Beacon */
111 dtim_dec_count = num_beacons % dtimperiod;
112 dtimcount -= dtim_dec_count;
113 if (dtimcount < 0)
114 dtimcount += dtimperiod;
115
116 bs.bs_intval = TU_TO_USEC(intval);
117 bs.bs_nexttbtt = TU_TO_USEC(nexttbtt);
118 bs.bs_dtimperiod = dtimperiod * bs.bs_intval;
119 bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount * bs.bs_intval;
120
121 /*
122 * Calculate the number of consecutive beacons to miss* before taking
123 * a BMISS interrupt. The configuration is specified in TU so we only
124 * need calculate based on the beacon interval. Note that we clamp the
125 * result to at most 15 beacons.
126 */
127 bs.bs_bmissthreshold = DIV_ROUND_UP(bmiss_timeout, intval);
128 if (bs.bs_bmissthreshold > 15)
129 bs.bs_bmissthreshold = 15;
130 else if (bs.bs_bmissthreshold <= 0)
131 bs.bs_bmissthreshold = 1;
132
133 /*
134 * Calculate sleep duration. The configuration is given in ms.
135 * We ensure a multiple of the beacon period is used. Also, if the sleep
136 * duration is greater than the DTIM period then it makes senses
137 * to make it a multiple of that.
138 *
139 * XXX fixed at 100ms
140 */
141
142 bs.bs_sleepduration = TU_TO_USEC(roundup(IEEE80211_MS_TO_TU(100),
143 intval));
144 if (bs.bs_sleepduration > bs.bs_dtimperiod)
145 bs.bs_sleepduration = bs.bs_dtimperiod;
146
147 /* TSF out of range threshold fixed at 1 second */
148 bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
149
150 ath_dbg(common, CONFIG, "intval: %u tsf: %llu tsftu: %u\n",
151 intval, tsf, tsftu);
152 ath_dbg(common, CONFIG, "bmiss: %u sleep: %u\n",
153 bs.bs_bmissthreshold, bs.bs_sleepduration);
154
155 /* Set the computed STA beacon timers */
156 81
157 WMI_CMD(WMI_DISABLE_INTR_CMDID); 82 WMI_CMD(WMI_DISABLE_INTR_CMDID);
158 ath9k_hw_set_sta_beacon_timers(priv->ah, &bs); 83 if (reset_tsf)
159 imask |= ATH9K_INT_BMISS; 84 ath9k_hw_reset_tsf(ah);
160 htc_imask = cpu_to_be32(imask); 85 ath9k_htc_beaconq_config(priv);
86 ath9k_hw_beaconinit(ah, conf->nexttbtt, conf->intval);
87 priv->beacon.bmisscnt = 0;
88 htc_imask = cpu_to_be32(ah->imask);
161 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 89 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
162} 90}
163 91
164static void ath9k_htc_beacon_config_ap(struct ath9k_htc_priv *priv, 92static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv,
165 struct htc_beacon_config *bss_conf) 93 struct ath_beacon_config *bss_conf)
166{ 94{
167 struct ath_common *common = ath9k_hw_common(priv->ah); 95 struct ath9k_beacon_state bs;
168 enum ath9k_int imask = 0; 96 enum ath9k_int imask = 0;
169 u32 nexttbtt, intval, tsftu;
170 __be32 htc_imask = 0; 97 __be32 htc_imask = 0;
171 int ret __attribute__ ((unused)); 98 int ret __attribute__ ((unused));
172 u8 cmd_rsp; 99 u8 cmd_rsp;
173 u64 tsf;
174
175 intval = bss_conf->beacon_interval;
176 intval /= ATH9K_HTC_MAX_BCN_VIF;
177 nexttbtt = intval;
178 100
179 /* 101 if (ath9k_cmn_beacon_config_sta(priv->ah, bss_conf, &bs) == -EPERM)
180 * To reduce beacon misses under heavy TX load, 102 return;
181 * set the beacon response time to a larger value.
182 */
183 if (intval > DEFAULT_SWBA_RESPONSE)
184 priv->ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE;
185 else
186 priv->ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE;
187
188 if (test_bit(OP_TSF_RESET, &priv->op_flags)) {
189 ath9k_hw_reset_tsf(priv->ah);
190 clear_bit(OP_TSF_RESET, &priv->op_flags);
191 } else {
192 /*
193 * Pull nexttbtt forward to reflect the current TSF.
194 */
195 tsf = ath9k_hw_gettsf64(priv->ah);
196 tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
197 do {
198 nexttbtt += intval;
199 } while (nexttbtt < tsftu);
200 }
201
202 if (test_bit(OP_ENABLE_BEACON, &priv->op_flags))
203 imask |= ATH9K_INT_SWBA;
204
205 ath_dbg(common, CONFIG,
206 "AP Beacon config, intval: %d, nexttbtt: %u, resp_time: %d imask: 0x%x\n",
207 bss_conf->beacon_interval, nexttbtt,
208 priv->ah->config.sw_beacon_response_time, imask);
209
210 ath9k_htc_beaconq_config(priv);
211 103
212 WMI_CMD(WMI_DISABLE_INTR_CMDID); 104 WMI_CMD(WMI_DISABLE_INTR_CMDID);
213 ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval)); 105 ath9k_hw_set_sta_beacon_timers(priv->ah, &bs);
214 priv->cur_beacon_conf.bmiss_cnt = 0; 106 imask |= ATH9K_INT_BMISS;
215 htc_imask = cpu_to_be32(imask); 107 htc_imask = cpu_to_be32(imask);
216 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 108 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
217} 109}
218 110
219static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv, 111static void ath9k_htc_beacon_config_ap(struct ath9k_htc_priv *priv,
220 struct htc_beacon_config *bss_conf) 112 struct ath_beacon_config *conf)
221{ 113{
222 struct ath_common *common = ath9k_hw_common(priv->ah); 114 struct ath_hw *ah = priv->ah;
223 enum ath9k_int imask = 0; 115 ah->imask = 0;
224 u32 nexttbtt, intval, tsftu;
225 __be32 htc_imask = 0;
226 int ret __attribute__ ((unused));
227 u8 cmd_rsp;
228 u64 tsf;
229
230 intval = bss_conf->beacon_interval;
231 nexttbtt = intval;
232
233 /*
234 * Pull nexttbtt forward to reflect the current TSF.
235 */
236 tsf = ath9k_hw_gettsf64(priv->ah);
237 tsftu = TSF_TO_TU(tsf >> 32, tsf) + FUDGE;
238 do {
239 nexttbtt += intval;
240 } while (nexttbtt < tsftu);
241
242 /*
243 * Only one IBSS interfce is allowed.
244 */
245 if (intval > DEFAULT_SWBA_RESPONSE)
246 priv->ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE;
247 else
248 priv->ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE;
249 116
250 if (test_bit(OP_ENABLE_BEACON, &priv->op_flags)) 117 ath9k_cmn_beacon_config_ap(ah, conf, ATH9K_HTC_MAX_BCN_VIF);
251 imask |= ATH9K_INT_SWBA; 118 ath9k_htc_beacon_init(priv, conf, false);
119}
252 120
253 ath_dbg(common, CONFIG, 121static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv,
254 "IBSS Beacon config, intval: %d, nexttbtt: %u, resp_time: %d, imask: 0x%x\n", 122 struct ath_beacon_config *conf)
255 bss_conf->beacon_interval, nexttbtt, 123{
256 priv->ah->config.sw_beacon_response_time, imask); 124 struct ath_hw *ah = priv->ah;
125 ah->imask = 0;
257 126
258 WMI_CMD(WMI_DISABLE_INTR_CMDID); 127 ath9k_cmn_beacon_config_adhoc(ah, conf);
259 ath9k_hw_beaconinit(priv->ah, TU_TO_USEC(nexttbtt), TU_TO_USEC(intval)); 128 ath9k_htc_beacon_init(priv, conf, conf->ibss_creator);
260 priv->cur_beacon_conf.bmiss_cnt = 0;
261 htc_imask = cpu_to_be32(imask);
262 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask);
263} 129}
264 130
265void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb, 131void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
@@ -279,7 +145,7 @@ static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv,
279 145
280 spin_lock_bh(&priv->beacon_lock); 146 spin_lock_bh(&priv->beacon_lock);
281 147
282 vif = priv->cur_beacon_conf.bslot[slot]; 148 vif = priv->beacon.bslot[slot];
283 149
284 skb = ieee80211_get_buffered_bc(priv->hw, vif); 150 skb = ieee80211_get_buffered_bc(priv->hw, vif);
285 151
@@ -340,10 +206,10 @@ static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv,
340 206
341 spin_lock_bh(&priv->beacon_lock); 207 spin_lock_bh(&priv->beacon_lock);
342 208
343 vif = priv->cur_beacon_conf.bslot[slot]; 209 vif = priv->beacon.bslot[slot];
344 avp = (struct ath9k_htc_vif *)vif->drv_priv; 210 avp = (struct ath9k_htc_vif *)vif->drv_priv;
345 211
346 if (unlikely(test_bit(OP_SCANNING, &priv->op_flags))) { 212 if (unlikely(test_bit(ATH_OP_SCANNING, &common->op_flags))) {
347 spin_unlock_bh(&priv->beacon_lock); 213 spin_unlock_bh(&priv->beacon_lock);
348 return; 214 return;
349 } 215 }
@@ -423,8 +289,8 @@ void ath9k_htc_swba(struct ath9k_htc_priv *priv,
423 int slot; 289 int slot;
424 290
425 if (swba->beacon_pending != 0) { 291 if (swba->beacon_pending != 0) {
426 priv->cur_beacon_conf.bmiss_cnt++; 292 priv->beacon.bmisscnt++;
427 if (priv->cur_beacon_conf.bmiss_cnt > BSTUCK_THRESHOLD) { 293 if (priv->beacon.bmisscnt > BSTUCK_THRESHOLD) {
428 ath_dbg(common, BSTUCK, "Beacon stuck, HW reset\n"); 294 ath_dbg(common, BSTUCK, "Beacon stuck, HW reset\n");
429 ieee80211_queue_work(priv->hw, 295 ieee80211_queue_work(priv->hw,
430 &priv->fatal_work); 296 &priv->fatal_work);
@@ -432,16 +298,16 @@ void ath9k_htc_swba(struct ath9k_htc_priv *priv,
432 return; 298 return;
433 } 299 }
434 300
435 if (priv->cur_beacon_conf.bmiss_cnt) { 301 if (priv->beacon.bmisscnt) {
436 ath_dbg(common, BSTUCK, 302 ath_dbg(common, BSTUCK,
437 "Resuming beacon xmit after %u misses\n", 303 "Resuming beacon xmit after %u misses\n",
438 priv->cur_beacon_conf.bmiss_cnt); 304 priv->beacon.bmisscnt);
439 priv->cur_beacon_conf.bmiss_cnt = 0; 305 priv->beacon.bmisscnt = 0;
440 } 306 }
441 307
442 slot = ath9k_htc_choose_bslot(priv, swba); 308 slot = ath9k_htc_choose_bslot(priv, swba);
443 spin_lock_bh(&priv->beacon_lock); 309 spin_lock_bh(&priv->beacon_lock);
444 if (priv->cur_beacon_conf.bslot[slot] == NULL) { 310 if (priv->beacon.bslot[slot] == NULL) {
445 spin_unlock_bh(&priv->beacon_lock); 311 spin_unlock_bh(&priv->beacon_lock);
446 return; 312 return;
447 } 313 }
@@ -460,13 +326,13 @@ void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv,
460 326
461 spin_lock_bh(&priv->beacon_lock); 327 spin_lock_bh(&priv->beacon_lock);
462 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) { 328 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) {
463 if (priv->cur_beacon_conf.bslot[i] == NULL) { 329 if (priv->beacon.bslot[i] == NULL) {
464 avp->bslot = i; 330 avp->bslot = i;
465 break; 331 break;
466 } 332 }
467 } 333 }
468 334
469 priv->cur_beacon_conf.bslot[avp->bslot] = vif; 335 priv->beacon.bslot[avp->bslot] = vif;
470 spin_unlock_bh(&priv->beacon_lock); 336 spin_unlock_bh(&priv->beacon_lock);
471 337
472 ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n", 338 ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n",
@@ -480,7 +346,7 @@ void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv,
480 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 346 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
481 347
482 spin_lock_bh(&priv->beacon_lock); 348 spin_lock_bh(&priv->beacon_lock);
483 priv->cur_beacon_conf.bslot[avp->bslot] = NULL; 349 priv->beacon.bslot[avp->bslot] = NULL;
484 spin_unlock_bh(&priv->beacon_lock); 350 spin_unlock_bh(&priv->beacon_lock);
485 351
486 ath_dbg(common, CONFIG, "Removed interface at beacon slot: %d\n", 352 ath_dbg(common, CONFIG, "Removed interface at beacon slot: %d\n",
@@ -496,7 +362,7 @@ void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv,
496{ 362{
497 struct ath_common *common = ath9k_hw_common(priv->ah); 363 struct ath_common *common = ath9k_hw_common(priv->ah);
498 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 364 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv;
499 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 365 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf;
500 u64 tsfadjust; 366 u64 tsfadjust;
501 367
502 if (avp->bslot == 0) 368 if (avp->bslot == 0)
@@ -528,7 +394,7 @@ static bool ath9k_htc_check_beacon_config(struct ath9k_htc_priv *priv,
528 struct ieee80211_vif *vif) 394 struct ieee80211_vif *vif)
529{ 395{
530 struct ath_common *common = ath9k_hw_common(priv->ah); 396 struct ath_common *common = ath9k_hw_common(priv->ah);
531 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 397 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf;
532 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 398 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
533 bool beacon_configured; 399 bool beacon_configured;
534 400
@@ -583,7 +449,7 @@ void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
583 struct ieee80211_vif *vif) 449 struct ieee80211_vif *vif)
584{ 450{
585 struct ath_common *common = ath9k_hw_common(priv->ah); 451 struct ath_common *common = ath9k_hw_common(priv->ah);
586 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 452 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf;
587 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 453 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
588 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 454 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
589 455
@@ -619,7 +485,7 @@ void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
619void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv) 485void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv)
620{ 486{
621 struct ath_common *common = ath9k_hw_common(priv->ah); 487 struct ath_common *common = ath9k_hw_common(priv->ah);
622 struct htc_beacon_config *cur_conf = &priv->cur_beacon_conf; 488 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf;
623 489
624 switch (priv->ah->opmode) { 490 switch (priv->ah->opmode) {
625 case NL80211_IFTYPE_STATION: 491 case NL80211_IFTYPE_STATION:
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index b22fb64403d9..8a3bd5fe3a54 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -405,8 +405,8 @@ static int ath9k_init_queues(struct ath9k_htc_priv *priv)
405 for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++) 405 for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++)
406 priv->hwq_map[i] = -1; 406 priv->hwq_map[i] = -1;
407 407
408 priv->beaconq = ath9k_hw_beaconq_setup(priv->ah); 408 priv->beacon.beaconq = ath9k_hw_beaconq_setup(priv->ah);
409 if (priv->beaconq == -1) { 409 if (priv->beacon.beaconq == -1) {
410 ath_err(common, "Unable to setup BEACON xmit queue\n"); 410 ath_err(common, "Unable to setup BEACON xmit queue\n");
411 goto err; 411 goto err;
412 } 412 }
@@ -459,8 +459,6 @@ static int ath9k_init_priv(struct ath9k_htc_priv *priv,
459 struct ath_common *common; 459 struct ath_common *common;
460 int i, ret = 0, csz = 0; 460 int i, ret = 0, csz = 0;
461 461
462 set_bit(OP_INVALID, &priv->op_flags);
463
464 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); 462 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
465 if (!ah) 463 if (!ah)
466 return -ENOMEM; 464 return -ENOMEM;
@@ -485,6 +483,7 @@ static int ath9k_init_priv(struct ath9k_htc_priv *priv,
485 common->priv = priv; 483 common->priv = priv;
486 common->debug_mask = ath9k_debug; 484 common->debug_mask = ath9k_debug;
487 common->btcoex_enabled = ath9k_htc_btcoex_enable == 1; 485 common->btcoex_enabled = ath9k_htc_btcoex_enable == 1;
486 set_bit(ATH_OP_INVALID, &common->op_flags);
488 487
489 spin_lock_init(&priv->beacon_lock); 488 spin_lock_init(&priv->beacon_lock);
490 spin_lock_init(&priv->tx.tx_lock); 489 spin_lock_init(&priv->tx.tx_lock);
@@ -520,7 +519,8 @@ static int ath9k_init_priv(struct ath9k_htc_priv *priv,
520 goto err_queues; 519 goto err_queues;
521 520
522 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) 521 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++)
523 priv->cur_beacon_conf.bslot[i] = NULL; 522 priv->beacon.bslot[i] = NULL;
523 priv->beacon.slottime = ATH9K_SLOT_TIME_9;
524 524
525 ath9k_cmn_init_channels_rates(common); 525 ath9k_cmn_init_channels_rates(common);
526 ath9k_cmn_init_crypto(ah); 526 ath9k_cmn_init_crypto(ah);
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
index 90dad4172b0a..f46cd0250e48 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
@@ -250,7 +250,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
250 u8 cmd_rsp; 250 u8 cmd_rsp;
251 int ret; 251 int ret;
252 252
253 if (test_bit(OP_INVALID, &priv->op_flags)) 253 if (test_bit(ATH_OP_INVALID, &common->op_flags))
254 return -EIO; 254 return -EIO;
255 255
256 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); 256 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
@@ -304,7 +304,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
304 304
305 htc_start(priv->htc); 305 htc_start(priv->htc);
306 306
307 if (!test_bit(OP_SCANNING, &priv->op_flags) && 307 if (!test_bit(ATH_OP_SCANNING, &common->op_flags) &&
308 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) 308 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
309 ath9k_htc_vif_reconfig(priv); 309 ath9k_htc_vif_reconfig(priv);
310 310
@@ -748,7 +748,7 @@ void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
748 common->ani.shortcal_timer = timestamp; 748 common->ani.shortcal_timer = timestamp;
749 common->ani.checkani_timer = timestamp; 749 common->ani.checkani_timer = timestamp;
750 750
751 set_bit(OP_ANI_RUNNING, &priv->op_flags); 751 set_bit(ATH_OP_ANI_RUN, &common->op_flags);
752 752
753 ieee80211_queue_delayed_work(common->hw, &priv->ani_work, 753 ieee80211_queue_delayed_work(common->hw, &priv->ani_work,
754 msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); 754 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
@@ -756,8 +756,9 @@ void ath9k_htc_start_ani(struct ath9k_htc_priv *priv)
756 756
757void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) 757void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv)
758{ 758{
759 struct ath_common *common = ath9k_hw_common(priv->ah);
759 cancel_delayed_work_sync(&priv->ani_work); 760 cancel_delayed_work_sync(&priv->ani_work);
760 clear_bit(OP_ANI_RUNNING, &priv->op_flags); 761 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
761} 762}
762 763
763void ath9k_htc_ani_work(struct work_struct *work) 764void ath9k_htc_ani_work(struct work_struct *work)
@@ -942,7 +943,7 @@ static int ath9k_htc_start(struct ieee80211_hw *hw)
942 ath_dbg(common, CONFIG, 943 ath_dbg(common, CONFIG,
943 "Failed to update capability in target\n"); 944 "Failed to update capability in target\n");
944 945
945 clear_bit(OP_INVALID, &priv->op_flags); 946 clear_bit(ATH_OP_INVALID, &common->op_flags);
946 htc_start(priv->htc); 947 htc_start(priv->htc);
947 948
948 spin_lock_bh(&priv->tx.tx_lock); 949 spin_lock_bh(&priv->tx.tx_lock);
@@ -971,7 +972,7 @@ static void ath9k_htc_stop(struct ieee80211_hw *hw)
971 972
972 mutex_lock(&priv->mutex); 973 mutex_lock(&priv->mutex);
973 974
974 if (test_bit(OP_INVALID, &priv->op_flags)) { 975 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
975 ath_dbg(common, ANY, "Device not present\n"); 976 ath_dbg(common, ANY, "Device not present\n");
976 mutex_unlock(&priv->mutex); 977 mutex_unlock(&priv->mutex);
977 return; 978 return;
@@ -1013,7 +1014,7 @@ static void ath9k_htc_stop(struct ieee80211_hw *hw)
1013 ath9k_htc_ps_restore(priv); 1014 ath9k_htc_ps_restore(priv);
1014 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); 1015 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1015 1016
1016 set_bit(OP_INVALID, &priv->op_flags); 1017 set_bit(ATH_OP_INVALID, &common->op_flags);
1017 1018
1018 ath_dbg(common, CONFIG, "Driver halt\n"); 1019 ath_dbg(common, CONFIG, "Driver halt\n");
1019 mutex_unlock(&priv->mutex); 1020 mutex_unlock(&priv->mutex);
@@ -1087,7 +1088,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1087 ath9k_htc_set_opmode(priv); 1088 ath9k_htc_set_opmode(priv);
1088 1089
1089 if ((priv->ah->opmode == NL80211_IFTYPE_AP) && 1090 if ((priv->ah->opmode == NL80211_IFTYPE_AP) &&
1090 !test_bit(OP_ANI_RUNNING, &priv->op_flags)) { 1091 !test_bit(ATH_OP_ANI_RUN, &common->op_flags)) {
1091 ath9k_hw_set_tsfadjust(priv->ah, true); 1092 ath9k_hw_set_tsfadjust(priv->ah, true);
1092 ath9k_htc_start_ani(priv); 1093 ath9k_htc_start_ani(priv);
1093 } 1094 }
@@ -1245,13 +1246,14 @@ static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1245 u64 multicast) 1246 u64 multicast)
1246{ 1247{
1247 struct ath9k_htc_priv *priv = hw->priv; 1248 struct ath9k_htc_priv *priv = hw->priv;
1249 struct ath_common *common = ath9k_hw_common(priv->ah);
1248 u32 rfilt; 1250 u32 rfilt;
1249 1251
1250 mutex_lock(&priv->mutex); 1252 mutex_lock(&priv->mutex);
1251 changed_flags &= SUPPORTED_FILTERS; 1253 changed_flags &= SUPPORTED_FILTERS;
1252 *total_flags &= SUPPORTED_FILTERS; 1254 *total_flags &= SUPPORTED_FILTERS;
1253 1255
1254 if (test_bit(OP_INVALID, &priv->op_flags)) { 1256 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
1255 ath_dbg(ath9k_hw_common(priv->ah), ANY, 1257 ath_dbg(ath9k_hw_common(priv->ah), ANY,
1256 "Unable to configure filter on invalid state\n"); 1258 "Unable to configure filter on invalid state\n");
1257 mutex_unlock(&priv->mutex); 1259 mutex_unlock(&priv->mutex);
@@ -1476,6 +1478,7 @@ static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1476 common->curaid = bss_conf->aid; 1478 common->curaid = bss_conf->aid;
1477 common->last_rssi = ATH_RSSI_DUMMY_MARKER; 1479 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
1478 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); 1480 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1481 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1479 } 1482 }
1480} 1483}
1481 1484
@@ -1497,6 +1500,7 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1497 struct ath9k_htc_priv *priv = hw->priv; 1500 struct ath9k_htc_priv *priv = hw->priv;
1498 struct ath_hw *ah = priv->ah; 1501 struct ath_hw *ah = priv->ah;
1499 struct ath_common *common = ath9k_hw_common(ah); 1502 struct ath_common *common = ath9k_hw_common(ah);
1503 int slottime;
1500 1504
1501 mutex_lock(&priv->mutex); 1505 mutex_lock(&priv->mutex);
1502 ath9k_htc_ps_wakeup(priv); 1506 ath9k_htc_ps_wakeup(priv);
@@ -1508,6 +1512,9 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1508 bss_conf->assoc ? 1512 bss_conf->assoc ?
1509 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--; 1513 priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--;
1510 1514
1515 if (!bss_conf->assoc)
1516 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1517
1511 if (priv->ah->opmode == NL80211_IFTYPE_STATION) { 1518 if (priv->ah->opmode == NL80211_IFTYPE_STATION) {
1512 ath9k_htc_choose_set_bssid(priv); 1519 ath9k_htc_choose_set_bssid(priv);
1513 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1)) 1520 if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1))
@@ -1529,7 +1536,7 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1529 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n", 1536 ath_dbg(common, CONFIG, "Beacon enabled for BSS: %pM\n",
1530 bss_conf->bssid); 1537 bss_conf->bssid);
1531 ath9k_htc_set_tsfadjust(priv, vif); 1538 ath9k_htc_set_tsfadjust(priv, vif);
1532 set_bit(OP_ENABLE_BEACON, &priv->op_flags); 1539 priv->cur_beacon_conf.enable_beacon = 1;
1533 ath9k_htc_beacon_config(priv, vif); 1540 ath9k_htc_beacon_config(priv, vif);
1534 } 1541 }
1535 1542
@@ -1543,7 +1550,7 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1543 ath_dbg(common, CONFIG, 1550 ath_dbg(common, CONFIG,
1544 "Beacon disabled for BSS: %pM\n", 1551 "Beacon disabled for BSS: %pM\n",
1545 bss_conf->bssid); 1552 bss_conf->bssid);
1546 clear_bit(OP_ENABLE_BEACON, &priv->op_flags); 1553 priv->cur_beacon_conf.enable_beacon = 0;
1547 ath9k_htc_beacon_config(priv, vif); 1554 ath9k_htc_beacon_config(priv, vif);
1548 } 1555 }
1549 } 1556 }
@@ -1569,11 +1576,21 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1569 1576
1570 if (changed & BSS_CHANGED_ERP_SLOT) { 1577 if (changed & BSS_CHANGED_ERP_SLOT) {
1571 if (bss_conf->use_short_slot) 1578 if (bss_conf->use_short_slot)
1572 ah->slottime = 9; 1579 slottime = 9;
1573 else 1580 else
1574 ah->slottime = 20; 1581 slottime = 20;
1575 1582 if (vif->type == NL80211_IFTYPE_AP) {
1576 ath9k_hw_init_global_settings(ah); 1583 /*
1584 * Defer update, so that connected stations can adjust
1585 * their settings at the same time.
1586 * See beacon.c for more details
1587 */
1588 priv->beacon.slottime = slottime;
1589 priv->beacon.updateslot = UPDATE;
1590 } else {
1591 ah->slottime = slottime;
1592 ath9k_hw_init_global_settings(ah);
1593 }
1577 } 1594 }
1578 1595
1579 if (changed & BSS_CHANGED_HT) 1596 if (changed & BSS_CHANGED_HT)
@@ -1670,10 +1687,11 @@ static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1670static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) 1687static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1671{ 1688{
1672 struct ath9k_htc_priv *priv = hw->priv; 1689 struct ath9k_htc_priv *priv = hw->priv;
1690 struct ath_common *common = ath9k_hw_common(priv->ah);
1673 1691
1674 mutex_lock(&priv->mutex); 1692 mutex_lock(&priv->mutex);
1675 spin_lock_bh(&priv->beacon_lock); 1693 spin_lock_bh(&priv->beacon_lock);
1676 set_bit(OP_SCANNING, &priv->op_flags); 1694 set_bit(ATH_OP_SCANNING, &common->op_flags);
1677 spin_unlock_bh(&priv->beacon_lock); 1695 spin_unlock_bh(&priv->beacon_lock);
1678 cancel_work_sync(&priv->ps_work); 1696 cancel_work_sync(&priv->ps_work);
1679 ath9k_htc_stop_ani(priv); 1697 ath9k_htc_stop_ani(priv);
@@ -1683,10 +1701,11 @@ static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1683static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) 1701static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1684{ 1702{
1685 struct ath9k_htc_priv *priv = hw->priv; 1703 struct ath9k_htc_priv *priv = hw->priv;
1704 struct ath_common *common = ath9k_hw_common(priv->ah);
1686 1705
1687 mutex_lock(&priv->mutex); 1706 mutex_lock(&priv->mutex);
1688 spin_lock_bh(&priv->beacon_lock); 1707 spin_lock_bh(&priv->beacon_lock);
1689 clear_bit(OP_SCANNING, &priv->op_flags); 1708 clear_bit(ATH_OP_SCANNING, &common->op_flags);
1690 spin_unlock_bh(&priv->beacon_lock); 1709 spin_unlock_bh(&priv->beacon_lock);
1691 ath9k_htc_ps_wakeup(priv); 1710 ath9k_htc_ps_wakeup(priv);
1692 ath9k_htc_vif_reconfig(priv); 1711 ath9k_htc_vif_reconfig(priv);
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
index 47b2bfcd8223..e8149e3dbdd5 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
@@ -924,9 +924,10 @@ static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
924 924
925void ath9k_host_rx_init(struct ath9k_htc_priv *priv) 925void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
926{ 926{
927 struct ath_common *common = ath9k_hw_common(priv->ah);
927 ath9k_hw_rxena(priv->ah); 928 ath9k_hw_rxena(priv->ah);
928 ath9k_htc_opmode_init(priv); 929 ath9k_htc_opmode_init(priv);
929 ath9k_hw_startpcureceive(priv->ah, test_bit(OP_SCANNING, &priv->op_flags)); 930 ath9k_hw_startpcureceive(priv->ah, test_bit(ATH_OP_SCANNING, &common->op_flags));
930} 931}
931 932
932static inline void convert_htc_flag(struct ath_rx_status *rx_stats, 933static inline void convert_htc_flag(struct ath_rx_status *rx_stats,
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 2509c2ff0828..0992f7c70e1a 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -882,7 +882,7 @@ static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
882 AR_IMR_RXORN | 882 AR_IMR_RXORN |
883 AR_IMR_BCNMISC; 883 AR_IMR_BCNMISC;
884 884
885 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) 885 if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah))
886 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL; 886 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
887 887
888 if (AR_SREV_9300_20_OR_LATER(ah)) { 888 if (AR_SREV_9300_20_OR_LATER(ah)) {
@@ -3048,6 +3048,7 @@ static struct {
3048 { AR_SREV_VERSION_9462, "9462" }, 3048 { AR_SREV_VERSION_9462, "9462" },
3049 { AR_SREV_VERSION_9550, "9550" }, 3049 { AR_SREV_VERSION_9550, "9550" },
3050 { AR_SREV_VERSION_9565, "9565" }, 3050 { AR_SREV_VERSION_9565, "9565" },
3051 { AR_SREV_VERSION_9531, "9531" },
3051}; 3052};
3052 3053
3053/* For devices with external radios */ 3054/* For devices with external radios */
diff --git a/drivers/net/wireless/ath/ath9k/link.c b/drivers/net/wireless/ath/ath9k/link.c
index 30dcef5aba10..72a715fe8f24 100644
--- a/drivers/net/wireless/ath/ath9k/link.c
+++ b/drivers/net/wireless/ath/ath9k/link.c
@@ -115,13 +115,14 @@ void ath_hw_pll_work(struct work_struct *work)
115 u32 pll_sqsum; 115 u32 pll_sqsum;
116 struct ath_softc *sc = container_of(work, struct ath_softc, 116 struct ath_softc *sc = container_of(work, struct ath_softc,
117 hw_pll_work.work); 117 hw_pll_work.work);
118 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
118 /* 119 /*
119 * ensure that the PLL WAR is executed only 120 * ensure that the PLL WAR is executed only
120 * after the STA is associated (or) if the 121 * after the STA is associated (or) if the
121 * beaconing had started in interfaces that 122 * beaconing had started in interfaces that
122 * uses beacons. 123 * uses beacons.
123 */ 124 */
124 if (!test_bit(SC_OP_BEACONS, &sc->sc_flags)) 125 if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
125 return; 126 return;
126 127
127 if (sc->tx99_state) 128 if (sc->tx99_state)
@@ -414,7 +415,7 @@ void ath_start_ani(struct ath_softc *sc)
414 unsigned long timestamp = jiffies_to_msecs(jiffies); 415 unsigned long timestamp = jiffies_to_msecs(jiffies);
415 416
416 if (common->disable_ani || 417 if (common->disable_ani ||
417 !test_bit(SC_OP_ANI_RUN, &sc->sc_flags) || 418 !test_bit(ATH_OP_ANI_RUN, &common->op_flags) ||
418 (sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) 419 (sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
419 return; 420 return;
420 421
@@ -438,6 +439,7 @@ void ath_stop_ani(struct ath_softc *sc)
438void ath_check_ani(struct ath_softc *sc) 439void ath_check_ani(struct ath_softc *sc)
439{ 440{
440 struct ath_hw *ah = sc->sc_ah; 441 struct ath_hw *ah = sc->sc_ah;
442 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
441 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf; 443 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
442 444
443 /* 445 /*
@@ -453,23 +455,23 @@ void ath_check_ani(struct ath_softc *sc)
453 * Disable ANI only when there are no 455 * Disable ANI only when there are no
454 * associated stations. 456 * associated stations.
455 */ 457 */
456 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) 458 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags))
457 goto stop_ani; 459 goto stop_ani;
458 } 460 }
459 } else if (ah->opmode == NL80211_IFTYPE_STATION) { 461 } else if (ah->opmode == NL80211_IFTYPE_STATION) {
460 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) 462 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags))
461 goto stop_ani; 463 goto stop_ani;
462 } 464 }
463 465
464 if (!test_bit(SC_OP_ANI_RUN, &sc->sc_flags)) { 466 if (!test_bit(ATH_OP_ANI_RUN, &common->op_flags)) {
465 set_bit(SC_OP_ANI_RUN, &sc->sc_flags); 467 set_bit(ATH_OP_ANI_RUN, &common->op_flags);
466 ath_start_ani(sc); 468 ath_start_ani(sc);
467 } 469 }
468 470
469 return; 471 return;
470 472
471stop_ani: 473stop_ani:
472 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags); 474 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
473 ath_stop_ani(sc); 475 ath_stop_ani(sc);
474} 476}
475 477
diff --git a/drivers/net/wireless/ath/ath9k/mac.c b/drivers/net/wireless/ath/ath9k/mac.c
index 5f727588ca27..51ce36f108f9 100644
--- a/drivers/net/wireless/ath/ath9k/mac.c
+++ b/drivers/net/wireless/ath/ath9k/mac.c
@@ -827,7 +827,7 @@ void ath9k_hw_enable_interrupts(struct ath_hw *ah)
827 return; 827 return;
828 } 828 }
829 829
830 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) 830 if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah))
831 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL; 831 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
832 832
833 async_mask = AR_INTR_MAC_IRQ; 833 async_mask = AR_INTR_MAC_IRQ;
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 42a18037004e..d69853b848ce 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -229,16 +229,16 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
229 ath9k_cmn_update_txpow(ah, sc->curtxpow, 229 ath9k_cmn_update_txpow(ah, sc->curtxpow,
230 sc->config.txpowlimit, &sc->curtxpow); 230 sc->config.txpowlimit, &sc->curtxpow);
231 231
232 clear_bit(SC_OP_HW_RESET, &sc->sc_flags); 232 clear_bit(ATH_OP_HW_RESET, &common->op_flags);
233 ath9k_hw_set_interrupts(ah); 233 ath9k_hw_set_interrupts(ah);
234 ath9k_hw_enable_interrupts(ah); 234 ath9k_hw_enable_interrupts(ah);
235 235
236 if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) { 236 if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) {
237 if (!test_bit(SC_OP_BEACONS, &sc->sc_flags)) 237 if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
238 goto work; 238 goto work;
239 239
240 if (ah->opmode == NL80211_IFTYPE_STATION && 240 if (ah->opmode == NL80211_IFTYPE_STATION &&
241 test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) { 241 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
242 spin_lock_irqsave(&sc->sc_pm_lock, flags); 242 spin_lock_irqsave(&sc->sc_pm_lock, flags);
243 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON; 243 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
244 spin_unlock_irqrestore(&sc->sc_pm_lock, flags); 244 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
@@ -336,7 +336,7 @@ static int ath_set_channel(struct ath_softc *sc, struct cfg80211_chan_def *chand
336 int old_pos = -1; 336 int old_pos = -1;
337 int r; 337 int r;
338 338
339 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) 339 if (test_bit(ATH_OP_INVALID, &common->op_flags))
340 return -EIO; 340 return -EIO;
341 341
342 offchannel = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); 342 offchannel = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
@@ -402,7 +402,7 @@ static int ath_set_channel(struct ath_softc *sc, struct cfg80211_chan_def *chand
402 chan->center_freq); 402 chan->center_freq);
403 } else { 403 } else {
404 /* perform spectral scan if requested. */ 404 /* perform spectral scan if requested. */
405 if (test_bit(SC_OP_SCANNING, &sc->sc_flags) && 405 if (test_bit(ATH_OP_SCANNING, &common->op_flags) &&
406 sc->spectral_mode == SPECTRAL_CHANSCAN) 406 sc->spectral_mode == SPECTRAL_CHANSCAN)
407 ath9k_spectral_scan_trigger(hw); 407 ath9k_spectral_scan_trigger(hw);
408 } 408 }
@@ -566,6 +566,7 @@ irqreturn_t ath_isr(int irq, void *dev)
566 566
567 struct ath_softc *sc = dev; 567 struct ath_softc *sc = dev;
568 struct ath_hw *ah = sc->sc_ah; 568 struct ath_hw *ah = sc->sc_ah;
569 struct ath_common *common = ath9k_hw_common(ah);
569 enum ath9k_int status; 570 enum ath9k_int status;
570 u32 sync_cause = 0; 571 u32 sync_cause = 0;
571 bool sched = false; 572 bool sched = false;
@@ -575,7 +576,7 @@ irqreturn_t ath_isr(int irq, void *dev)
575 * touch anything. Note this can happen early 576 * touch anything. Note this can happen early
576 * on if the IRQ is shared. 577 * on if the IRQ is shared.
577 */ 578 */
578 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) 579 if (test_bit(ATH_OP_INVALID, &common->op_flags))
579 return IRQ_NONE; 580 return IRQ_NONE;
580 581
581 /* shared irq, not for us */ 582 /* shared irq, not for us */
@@ -583,7 +584,7 @@ irqreturn_t ath_isr(int irq, void *dev)
583 if (!ath9k_hw_intrpend(ah)) 584 if (!ath9k_hw_intrpend(ah))
584 return IRQ_NONE; 585 return IRQ_NONE;
585 586
586 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) { 587 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
587 ath9k_hw_kill_interrupts(ah); 588 ath9k_hw_kill_interrupts(ah);
588 return IRQ_HANDLED; 589 return IRQ_HANDLED;
589 } 590 }
@@ -684,10 +685,11 @@ int ath_reset(struct ath_softc *sc)
684 685
685void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type) 686void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
686{ 687{
688 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
687#ifdef CONFIG_ATH9K_DEBUGFS 689#ifdef CONFIG_ATH9K_DEBUGFS
688 RESET_STAT_INC(sc, type); 690 RESET_STAT_INC(sc, type);
689#endif 691#endif
690 set_bit(SC_OP_HW_RESET, &sc->sc_flags); 692 set_bit(ATH_OP_HW_RESET, &common->op_flags);
691 ieee80211_queue_work(sc->hw, &sc->hw_reset_work); 693 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
692} 694}
693 695
@@ -768,7 +770,7 @@ static int ath9k_start(struct ieee80211_hw *hw)
768 770
769 ath_mci_enable(sc); 771 ath_mci_enable(sc);
770 772
771 clear_bit(SC_OP_INVALID, &sc->sc_flags); 773 clear_bit(ATH_OP_INVALID, &common->op_flags);
772 sc->sc_ah->is_monitoring = false; 774 sc->sc_ah->is_monitoring = false;
773 775
774 if (!ath_complete_reset(sc, false)) 776 if (!ath_complete_reset(sc, false))
@@ -885,7 +887,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)
885 887
886 ath_cancel_work(sc); 888 ath_cancel_work(sc);
887 889
888 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) { 890 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
889 ath_dbg(common, ANY, "Device not present\n"); 891 ath_dbg(common, ANY, "Device not present\n");
890 mutex_unlock(&sc->mutex); 892 mutex_unlock(&sc->mutex);
891 return; 893 return;
@@ -940,7 +942,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)
940 942
941 ath9k_ps_restore(sc); 943 ath9k_ps_restore(sc);
942 944
943 set_bit(SC_OP_INVALID, &sc->sc_flags); 945 set_bit(ATH_OP_INVALID, &common->op_flags);
944 sc->ps_idle = prev_idle; 946 sc->ps_idle = prev_idle;
945 947
946 mutex_unlock(&sc->mutex); 948 mutex_unlock(&sc->mutex);
@@ -1081,7 +1083,7 @@ static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
1081 */ 1083 */
1082 if (ah->opmode == NL80211_IFTYPE_STATION && 1084 if (ah->opmode == NL80211_IFTYPE_STATION &&
1083 old_opmode == NL80211_IFTYPE_AP && 1085 old_opmode == NL80211_IFTYPE_AP &&
1084 test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) { 1086 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
1085 ieee80211_iterate_active_interfaces_atomic( 1087 ieee80211_iterate_active_interfaces_atomic(
1086 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, 1088 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1087 ath9k_sta_vif_iter, sc); 1089 ath9k_sta_vif_iter, sc);
@@ -1590,7 +1592,7 @@ static void ath9k_set_assoc_state(struct ath_softc *sc,
1590 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 1592 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1591 unsigned long flags; 1593 unsigned long flags;
1592 1594
1593 set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags); 1595 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1594 avp->primary_sta_vif = true; 1596 avp->primary_sta_vif = true;
1595 1597
1596 /* 1598 /*
@@ -1625,8 +1627,9 @@ static void ath9k_bss_assoc_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1625{ 1627{
1626 struct ath_softc *sc = data; 1628 struct ath_softc *sc = data;
1627 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 1629 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1630 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1628 1631
1629 if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) 1632 if (test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags))
1630 return; 1633 return;
1631 1634
1632 if (bss_conf->assoc) 1635 if (bss_conf->assoc)
@@ -1657,18 +1660,18 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1657 bss_conf->bssid, bss_conf->assoc); 1660 bss_conf->bssid, bss_conf->assoc);
1658 1661
1659 if (avp->primary_sta_vif && !bss_conf->assoc) { 1662 if (avp->primary_sta_vif && !bss_conf->assoc) {
1660 clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags); 1663 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1661 avp->primary_sta_vif = false; 1664 avp->primary_sta_vif = false;
1662 1665
1663 if (ah->opmode == NL80211_IFTYPE_STATION) 1666 if (ah->opmode == NL80211_IFTYPE_STATION)
1664 clear_bit(SC_OP_BEACONS, &sc->sc_flags); 1667 clear_bit(ATH_OP_BEACONS, &common->op_flags);
1665 } 1668 }
1666 1669
1667 ieee80211_iterate_active_interfaces_atomic( 1670 ieee80211_iterate_active_interfaces_atomic(
1668 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, 1671 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1669 ath9k_bss_assoc_iter, sc); 1672 ath9k_bss_assoc_iter, sc);
1670 1673
1671 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags) && 1674 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags) &&
1672 ah->opmode == NL80211_IFTYPE_STATION) { 1675 ah->opmode == NL80211_IFTYPE_STATION) {
1673 memset(common->curbssid, 0, ETH_ALEN); 1676 memset(common->curbssid, 0, ETH_ALEN);
1674 common->curaid = 0; 1677 common->curaid = 0;
@@ -1897,7 +1900,7 @@ static void ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1897 return; 1900 return;
1898 } 1901 }
1899 1902
1900 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) { 1903 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
1901 ath_dbg(common, ANY, "Device not present\n"); 1904 ath_dbg(common, ANY, "Device not present\n");
1902 mutex_unlock(&sc->mutex); 1905 mutex_unlock(&sc->mutex);
1903 return; 1906 return;
@@ -2070,13 +2073,15 @@ static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2070static void ath9k_sw_scan_start(struct ieee80211_hw *hw) 2073static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2071{ 2074{
2072 struct ath_softc *sc = hw->priv; 2075 struct ath_softc *sc = hw->priv;
2073 set_bit(SC_OP_SCANNING, &sc->sc_flags); 2076 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2077 set_bit(ATH_OP_SCANNING, &common->op_flags);
2074} 2078}
2075 2079
2076static void ath9k_sw_scan_complete(struct ieee80211_hw *hw) 2080static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2077{ 2081{
2078 struct ath_softc *sc = hw->priv; 2082 struct ath_softc *sc = hw->priv;
2079 clear_bit(SC_OP_SCANNING, &sc->sc_flags); 2083 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2084 clear_bit(ATH_OP_SCANNING, &common->op_flags);
2080} 2085}
2081 2086
2082static void ath9k_channel_switch_beacon(struct ieee80211_hw *hw, 2087static void ath9k_channel_switch_beacon(struct ieee80211_hw *hw,
diff --git a/drivers/net/wireless/ath/ath9k/mci.c b/drivers/net/wireless/ath/ath9k/mci.c
index 71799fcade54..a0dbcc412384 100644
--- a/drivers/net/wireless/ath/ath9k/mci.c
+++ b/drivers/net/wireless/ath/ath9k/mci.c
@@ -555,7 +555,7 @@ void ath_mci_intr(struct ath_softc *sc)
555 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM; 555 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM;
556 556
557 while (more_data == MCI_GPM_MORE) { 557 while (more_data == MCI_GPM_MORE) {
558 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) 558 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
559 return; 559 return;
560 560
561 pgpm = mci->gpm_buf.bf_addr; 561 pgpm = mci->gpm_buf.bf_addr;
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index 55724b02316b..25304adece57 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -784,6 +784,7 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
784{ 784{
785 struct ath_softc *sc; 785 struct ath_softc *sc;
786 struct ieee80211_hw *hw; 786 struct ieee80211_hw *hw;
787 struct ath_common *common;
787 u8 csz; 788 u8 csz;
788 u32 val; 789 u32 val;
789 int ret = 0; 790 int ret = 0;
@@ -858,9 +859,6 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
858 sc->mem = pcim_iomap_table(pdev)[0]; 859 sc->mem = pcim_iomap_table(pdev)[0];
859 sc->driver_data = id->driver_data; 860 sc->driver_data = id->driver_data;
860 861
861 /* Will be cleared in ath9k_start() */
862 set_bit(SC_OP_INVALID, &sc->sc_flags);
863
864 ret = request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath9k", sc); 862 ret = request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath9k", sc);
865 if (ret) { 863 if (ret) {
866 dev_err(&pdev->dev, "request_irq failed\n"); 864 dev_err(&pdev->dev, "request_irq failed\n");
@@ -879,6 +877,10 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
879 wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n", 877 wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n",
880 hw_name, (unsigned long)sc->mem, pdev->irq); 878 hw_name, (unsigned long)sc->mem, pdev->irq);
881 879
880 /* Will be cleared in ath9k_start() */
881 common = ath9k_hw_common(sc->sc_ah);
882 set_bit(ATH_OP_INVALID, &common->op_flags);
883
882 return 0; 884 return 0;
883 885
884err_init: 886err_init:
diff --git a/drivers/net/wireless/ath/ath9k/tx99.c b/drivers/net/wireless/ath/ath9k/tx99.c
index b686a7498450..a65cfb91adca 100644
--- a/drivers/net/wireless/ath/ath9k/tx99.c
+++ b/drivers/net/wireless/ath/ath9k/tx99.c
@@ -108,7 +108,7 @@ static int ath9k_tx99_init(struct ath_softc *sc)
108 struct ath_tx_control txctl; 108 struct ath_tx_control txctl;
109 int r; 109 int r;
110 110
111 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) { 111 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
112 ath_err(common, 112 ath_err(common,
113 "driver is in invalid state unable to use TX99"); 113 "driver is in invalid state unable to use TX99");
114 return -EINVAL; 114 return -EINVAL;
diff --git a/drivers/net/wireless/ath/ath9k/wow.c b/drivers/net/wireless/ath/ath9k/wow.c
index 1b3230fa3651..2879887f5691 100644
--- a/drivers/net/wireless/ath/ath9k/wow.c
+++ b/drivers/net/wireless/ath/ath9k/wow.c
@@ -198,7 +198,7 @@ int ath9k_suspend(struct ieee80211_hw *hw,
198 ath_cancel_work(sc); 198 ath_cancel_work(sc);
199 ath_stop_ani(sc); 199 ath_stop_ani(sc);
200 200
201 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) { 201 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
202 ath_dbg(common, ANY, "Device not present\n"); 202 ath_dbg(common, ANY, "Device not present\n");
203 ret = -EINVAL; 203 ret = -EINVAL;
204 goto fail_wow; 204 goto fail_wow;
@@ -224,7 +224,7 @@ int ath9k_suspend(struct ieee80211_hw *hw,
224 * STA. 224 * STA.
225 */ 225 */
226 226
227 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) { 227 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
228 ath_dbg(common, WOW, "None of the STA vifs are associated\n"); 228 ath_dbg(common, WOW, "None of the STA vifs are associated\n");
229 ret = 1; 229 ret = 1;
230 goto fail_wow; 230 goto fail_wow;
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index fafacfed44ea..f76e6b9bb8e6 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1699,7 +1699,7 @@ int ath_cabq_update(struct ath_softc *sc)
1699 1699
1700 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi); 1700 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
1701 1701
1702 qi.tqi_readyTime = (cur_conf->beacon_interval * 1702 qi.tqi_readyTime = (TU_TO_USEC(cur_conf->beacon_interval) *
1703 ATH_CABQ_READY_TIME) / 100; 1703 ATH_CABQ_READY_TIME) / 100;
1704 ath_txq_update(sc, qnum, &qi); 1704 ath_txq_update(sc, qnum, &qi);
1705 1705
@@ -1769,7 +1769,7 @@ bool ath_drain_all_txq(struct ath_softc *sc)
1769 int i; 1769 int i;
1770 u32 npend = 0; 1770 u32 npend = 0;
1771 1771
1772 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) 1772 if (test_bit(ATH_OP_INVALID, &common->op_flags))
1773 return true; 1773 return true;
1774 1774
1775 ath9k_hw_abort_tx_dma(ah); 1775 ath9k_hw_abort_tx_dma(ah);
@@ -1817,11 +1817,12 @@ void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1817 */ 1817 */
1818void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq) 1818void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1819{ 1819{
1820 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1820 struct ath_atx_ac *ac, *last_ac; 1821 struct ath_atx_ac *ac, *last_ac;
1821 struct ath_atx_tid *tid, *last_tid; 1822 struct ath_atx_tid *tid, *last_tid;
1822 bool sent = false; 1823 bool sent = false;
1823 1824
1824 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags) || 1825 if (test_bit(ATH_OP_HW_RESET, &common->op_flags) ||
1825 list_empty(&txq->axq_acq)) 1826 list_empty(&txq->axq_acq))
1826 return; 1827 return;
1827 1828
@@ -2471,7 +2472,7 @@ static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
2471 2472
2472 ath_txq_lock(sc, txq); 2473 ath_txq_lock(sc, txq);
2473 for (;;) { 2474 for (;;) {
2474 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) 2475 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
2475 break; 2476 break;
2476 2477
2477 if (list_empty(&txq->axq_q)) { 2478 if (list_empty(&txq->axq_q)) {
@@ -2554,7 +2555,7 @@ void ath_tx_edma_tasklet(struct ath_softc *sc)
2554 int status; 2555 int status;
2555 2556
2556 for (;;) { 2557 for (;;) {
2557 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) 2558 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
2558 break; 2559 break;
2559 2560
2560 status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts); 2561 status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts);
diff --git a/drivers/net/wireless/ath/wil6210/cfg80211.c b/drivers/net/wireless/ath/wil6210/cfg80211.c
index 743930357061..4806a49cb61b 100644
--- a/drivers/net/wireless/ath/wil6210/cfg80211.c
+++ b/drivers/net/wireless/ath/wil6210/cfg80211.c
@@ -179,7 +179,7 @@ static int wil_cfg80211_get_station(struct wiphy *wiphy,
179 179
180 int cid = wil_find_cid(wil, mac); 180 int cid = wil_find_cid(wil, mac);
181 181
182 wil_info(wil, "%s(%pM) CID %d\n", __func__, mac, cid); 182 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
183 if (cid < 0) 183 if (cid < 0)
184 return cid; 184 return cid;
185 185
@@ -218,7 +218,7 @@ static int wil_cfg80211_dump_station(struct wiphy *wiphy,
218 return -ENOENT; 218 return -ENOENT;
219 219
220 memcpy(mac, wil->sta[cid].addr, ETH_ALEN); 220 memcpy(mac, wil->sta[cid].addr, ETH_ALEN);
221 wil_info(wil, "%s(%pM) CID %d\n", __func__, mac, cid); 221 wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
222 222
223 rc = wil_cid_fill_sinfo(wil, cid, sinfo); 223 rc = wil_cid_fill_sinfo(wil, cid, sinfo);
224 224
@@ -265,6 +265,7 @@ static int wil_cfg80211_scan(struct wiphy *wiphy,
265 u16 chnl[4]; 265 u16 chnl[4];
266 } __packed cmd; 266 } __packed cmd;
267 uint i, n; 267 uint i, n;
268 int rc;
268 269
269 if (wil->scan_request) { 270 if (wil->scan_request) {
270 wil_err(wil, "Already scanning\n"); 271 wil_err(wil, "Already scanning\n");
@@ -282,7 +283,7 @@ static int wil_cfg80211_scan(struct wiphy *wiphy,
282 283
283 /* FW don't support scan after connection attempt */ 284 /* FW don't support scan after connection attempt */
284 if (test_bit(wil_status_dontscan, &wil->status)) { 285 if (test_bit(wil_status_dontscan, &wil->status)) {
285 wil_err(wil, "Scan after connect attempt not supported\n"); 286 wil_err(wil, "Can't scan now\n");
286 return -EBUSY; 287 return -EBUSY;
287 } 288 }
288 289
@@ -305,8 +306,13 @@ static int wil_cfg80211_scan(struct wiphy *wiphy,
305 request->channels[i]->center_freq); 306 request->channels[i]->center_freq);
306 } 307 }
307 308
308 return wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) + 309 rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
309 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0])); 310 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
311
312 if (rc)
313 wil->scan_request = NULL;
314
315 return rc;
310} 316}
311 317
312static int wil_cfg80211_connect(struct wiphy *wiphy, 318static int wil_cfg80211_connect(struct wiphy *wiphy,
@@ -321,6 +327,10 @@ static int wil_cfg80211_connect(struct wiphy *wiphy,
321 int ch; 327 int ch;
322 int rc = 0; 328 int rc = 0;
323 329
330 if (test_bit(wil_status_fwconnecting, &wil->status) ||
331 test_bit(wil_status_fwconnected, &wil->status))
332 return -EALREADY;
333
324 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, 334 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
325 sme->ssid, sme->ssid_len, 335 sme->ssid, sme->ssid_len,
326 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); 336 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
@@ -402,10 +412,7 @@ static int wil_cfg80211_connect(struct wiphy *wiphy,
402 412
403 memcpy(conn.bssid, bss->bssid, ETH_ALEN); 413 memcpy(conn.bssid, bss->bssid, ETH_ALEN);
404 memcpy(conn.dst_mac, bss->bssid, ETH_ALEN); 414 memcpy(conn.dst_mac, bss->bssid, ETH_ALEN);
405 /* 415
406 * FW don't support scan after connection attempt
407 */
408 set_bit(wil_status_dontscan, &wil->status);
409 set_bit(wil_status_fwconnecting, &wil->status); 416 set_bit(wil_status_fwconnecting, &wil->status);
410 417
411 rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn)); 418 rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
@@ -414,7 +421,6 @@ static int wil_cfg80211_connect(struct wiphy *wiphy,
414 mod_timer(&wil->connect_timer, 421 mod_timer(&wil->connect_timer,
415 jiffies + msecs_to_jiffies(2000)); 422 jiffies + msecs_to_jiffies(2000));
416 } else { 423 } else {
417 clear_bit(wil_status_dontscan, &wil->status);
418 clear_bit(wil_status_fwconnecting, &wil->status); 424 clear_bit(wil_status_fwconnecting, &wil->status);
419 } 425 }
420 426
@@ -603,18 +609,20 @@ static int wil_cfg80211_start_ap(struct wiphy *wiphy,
603 if (wil_fix_bcon(wil, bcon)) 609 if (wil_fix_bcon(wil, bcon))
604 wil_dbg_misc(wil, "Fixed bcon\n"); 610 wil_dbg_misc(wil, "Fixed bcon\n");
605 611
612 mutex_lock(&wil->mutex);
613
606 rc = wil_reset(wil); 614 rc = wil_reset(wil);
607 if (rc) 615 if (rc)
608 return rc; 616 goto out;
609 617
610 /* Rx VRING. */ 618 /* Rx VRING. */
611 rc = wil_rx_init(wil); 619 rc = wil_rx_init(wil);
612 if (rc) 620 if (rc)
613 return rc; 621 goto out;
614 622
615 rc = wmi_set_ssid(wil, info->ssid_len, info->ssid); 623 rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
616 if (rc) 624 if (rc)
617 return rc; 625 goto out;
618 626
619 /* MAC address - pre-requisite for other commands */ 627 /* MAC address - pre-requisite for other commands */
620 wmi_set_mac_address(wil, ndev->dev_addr); 628 wmi_set_mac_address(wil, ndev->dev_addr);
@@ -638,11 +646,13 @@ static int wil_cfg80211_start_ap(struct wiphy *wiphy,
638 rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype, 646 rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
639 channel->hw_value); 647 channel->hw_value);
640 if (rc) 648 if (rc)
641 return rc; 649 goto out;
642 650
643 651
644 netif_carrier_on(ndev); 652 netif_carrier_on(ndev);
645 653
654out:
655 mutex_unlock(&wil->mutex);
646 return rc; 656 return rc;
647} 657}
648 658
@@ -652,8 +662,11 @@ static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
652 int rc = 0; 662 int rc = 0;
653 struct wil6210_priv *wil = wiphy_to_wil(wiphy); 663 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
654 664
665 mutex_lock(&wil->mutex);
666
655 rc = wmi_pcp_stop(wil); 667 rc = wmi_pcp_stop(wil);
656 668
669 mutex_unlock(&wil->mutex);
657 return rc; 670 return rc;
658} 671}
659 672
@@ -661,7 +674,11 @@ static int wil_cfg80211_del_station(struct wiphy *wiphy,
661 struct net_device *dev, u8 *mac) 674 struct net_device *dev, u8 *mac)
662{ 675{
663 struct wil6210_priv *wil = wiphy_to_wil(wiphy); 676 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
677
678 mutex_lock(&wil->mutex);
664 wil6210_disconnect(wil, mac); 679 wil6210_disconnect(wil, mac);
680 mutex_unlock(&wil->mutex);
681
665 return 0; 682 return 0;
666} 683}
667 684
diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index 1d09a4b0a0f4..ecdabe4adec3 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -398,6 +398,44 @@ static const struct file_operations fops_reset = {
398 .open = simple_open, 398 .open = simple_open,
399}; 399};
400 400
401static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
402 const char *prefix)
403{
404 char printbuf[16 * 3 + 2];
405 int i = 0;
406 while (i < len) {
407 int l = min(len - i, 16);
408 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
409 sizeof(printbuf), false);
410 seq_printf(s, "%s%s\n", prefix, printbuf);
411 i += l;
412 }
413}
414
415static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
416{
417 int i = 0;
418 int len = skb_headlen(skb);
419 void *p = skb->data;
420 int nr_frags = skb_shinfo(skb)->nr_frags;
421
422 seq_printf(s, " len = %d\n", len);
423 wil_seq_hexdump(s, p, len, " : ");
424
425 if (nr_frags) {
426 seq_printf(s, " nr_frags = %d\n", nr_frags);
427 for (i = 0; i < nr_frags; i++) {
428 const struct skb_frag_struct *frag =
429 &skb_shinfo(skb)->frags[i];
430
431 len = skb_frag_size(frag);
432 p = skb_frag_address_safe(frag);
433 seq_printf(s, " [%2d] : len = %d\n", i, len);
434 wil_seq_hexdump(s, p, len, " : ");
435 }
436 }
437}
438
401/*---------Tx/Rx descriptor------------*/ 439/*---------Tx/Rx descriptor------------*/
402static int wil_txdesc_debugfs_show(struct seq_file *s, void *data) 440static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
403{ 441{
@@ -438,26 +476,9 @@ static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
438 seq_printf(s, " SKB = %p\n", skb); 476 seq_printf(s, " SKB = %p\n", skb);
439 477
440 if (skb) { 478 if (skb) {
441 char printbuf[16 * 3 + 2]; 479 skb_get(skb);
442 int i = 0; 480 wil_seq_print_skb(s, skb);
443 int len = le16_to_cpu(d->dma.length); 481 kfree_skb(skb);
444 void *p = skb->data;
445
446 if (len != skb_headlen(skb)) {
447 seq_printf(s, "!!! len: desc = %d skb = %d\n",
448 len, skb_headlen(skb));
449 len = min_t(int, len, skb_headlen(skb));
450 }
451
452 seq_printf(s, " len = %d\n", len);
453
454 while (i < len) {
455 int l = min(len - i, 16);
456 hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
457 sizeof(printbuf), false);
458 seq_printf(s, " : %s\n", printbuf);
459 i += l;
460 }
461 } 482 }
462 seq_printf(s, "}\n"); 483 seq_printf(s, "}\n");
463 } else { 484 } else {
@@ -631,7 +652,8 @@ static int wil_sta_debugfs_show(struct seq_file *s, void *data)
631 status = "connected"; 652 status = "connected";
632 break; 653 break;
633 } 654 }
634 seq_printf(s, "[%d] %pM %s\n", i, p->addr, status); 655 seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
656 (p->data_port_open ? " data_port_open" : ""));
635 657
636 if (p->status == wil_sta_connected) { 658 if (p->status == wil_sta_connected) {
637 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) { 659 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
diff --git a/drivers/net/wireless/ath/wil6210/interrupt.c b/drivers/net/wireless/ath/wil6210/interrupt.c
index 10919f95a83c..5824cd41e4ba 100644
--- a/drivers/net/wireless/ath/wil6210/interrupt.c
+++ b/drivers/net/wireless/ath/wil6210/interrupt.c
@@ -195,8 +195,12 @@ static irqreturn_t wil6210_irq_rx(int irq, void *cookie)
195 if (isr & BIT_DMA_EP_RX_ICR_RX_DONE) { 195 if (isr & BIT_DMA_EP_RX_ICR_RX_DONE) {
196 wil_dbg_irq(wil, "RX done\n"); 196 wil_dbg_irq(wil, "RX done\n");
197 isr &= ~BIT_DMA_EP_RX_ICR_RX_DONE; 197 isr &= ~BIT_DMA_EP_RX_ICR_RX_DONE;
198 wil_dbg_txrx(wil, "NAPI schedule\n"); 198 if (test_bit(wil_status_reset_done, &wil->status)) {
199 napi_schedule(&wil->napi_rx); 199 wil_dbg_txrx(wil, "NAPI(Rx) schedule\n");
200 napi_schedule(&wil->napi_rx);
201 } else {
202 wil_err(wil, "Got Rx interrupt while in reset\n");
203 }
200 } 204 }
201 205
202 if (isr) 206 if (isr)
@@ -226,10 +230,15 @@ static irqreturn_t wil6210_irq_tx(int irq, void *cookie)
226 230
227 if (isr & BIT_DMA_EP_TX_ICR_TX_DONE) { 231 if (isr & BIT_DMA_EP_TX_ICR_TX_DONE) {
228 wil_dbg_irq(wil, "TX done\n"); 232 wil_dbg_irq(wil, "TX done\n");
229 napi_schedule(&wil->napi_tx);
230 isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE; 233 isr &= ~BIT_DMA_EP_TX_ICR_TX_DONE;
231 /* clear also all VRING interrupts */ 234 /* clear also all VRING interrupts */
232 isr &= ~(BIT(25) - 1UL); 235 isr &= ~(BIT(25) - 1UL);
236 if (test_bit(wil_status_reset_done, &wil->status)) {
237 wil_dbg_txrx(wil, "NAPI(Tx) schedule\n");
238 napi_schedule(&wil->napi_tx);
239 } else {
240 wil_err(wil, "Got Tx interrupt while in reset\n");
241 }
233 } 242 }
234 243
235 if (isr) 244 if (isr)
@@ -319,6 +328,7 @@ static irqreturn_t wil6210_irq_misc_thread(int irq, void *cookie)
319 if (isr & ISR_MISC_FW_ERROR) { 328 if (isr & ISR_MISC_FW_ERROR) {
320 wil_notify_fw_error(wil); 329 wil_notify_fw_error(wil);
321 isr &= ~ISR_MISC_FW_ERROR; 330 isr &= ~ISR_MISC_FW_ERROR;
331 wil_fw_error_recovery(wil);
322 } 332 }
323 333
324 if (isr & ISR_MISC_MBOX_EVT) { 334 if (isr & ISR_MISC_MBOX_EVT) {
@@ -493,6 +503,23 @@ free0:
493 503
494 return rc; 504 return rc;
495} 505}
506/* can't use wil_ioread32_and_clear because ICC value is not ser yet */
507static inline void wil_clear32(void __iomem *addr)
508{
509 u32 x = ioread32(addr);
510
511 iowrite32(x, addr);
512}
513
514void wil6210_clear_irq(struct wil6210_priv *wil)
515{
516 wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_RX_ICR) +
517 offsetof(struct RGF_ICR, ICR));
518 wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_TX_ICR) +
519 offsetof(struct RGF_ICR, ICR));
520 wil_clear32(wil->csr + HOSTADDR(RGF_DMA_EP_MISC_ICR) +
521 offsetof(struct RGF_ICR, ICR));
522}
496 523
497int wil6210_init_irq(struct wil6210_priv *wil, int irq) 524int wil6210_init_irq(struct wil6210_priv *wil, int irq)
498{ 525{
diff --git a/drivers/net/wireless/ath/wil6210/main.c b/drivers/net/wireless/ath/wil6210/main.c
index 41c362dee032..95f4efe9ef37 100644
--- a/drivers/net/wireless/ath/wil6210/main.c
+++ b/drivers/net/wireless/ath/wil6210/main.c
@@ -21,6 +21,10 @@
21#include "wil6210.h" 21#include "wil6210.h"
22#include "txrx.h" 22#include "txrx.h"
23 23
24static bool no_fw_recovery;
25module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
26MODULE_PARM_DESC(no_fw_recovery, " disable FW error recovery");
27
24/* 28/*
25 * Due to a hardware issue, 29 * Due to a hardware issue,
26 * one has to read/write to/from NIC in 32-bit chunks; 30 * one has to read/write to/from NIC in 32-bit chunks;
@@ -59,6 +63,7 @@ static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
59 uint i; 63 uint i;
60 struct wil_sta_info *sta = &wil->sta[cid]; 64 struct wil_sta_info *sta = &wil->sta[cid];
61 65
66 sta->data_port_open = false;
62 if (sta->status != wil_sta_unused) { 67 if (sta->status != wil_sta_unused) {
63 wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING); 68 wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING);
64 sta->status = wil_sta_unused; 69 sta->status = wil_sta_unused;
@@ -112,8 +117,6 @@ static void _wil6210_disconnect(struct wil6210_priv *wil, void *bssid)
112 GFP_KERNEL); 117 GFP_KERNEL);
113 } 118 }
114 clear_bit(wil_status_fwconnecting, &wil->status); 119 clear_bit(wil_status_fwconnecting, &wil->status);
115 wil_dbg_misc(wil, "clear_bit(wil_status_dontscan)\n");
116 clear_bit(wil_status_dontscan, &wil->status);
117 break; 120 break;
118 default: 121 default:
119 /* AP-like interface and monitor: 122 /* AP-like interface and monitor:
@@ -130,7 +133,9 @@ static void wil_disconnect_worker(struct work_struct *work)
130 struct wil6210_priv *wil = container_of(work, 133 struct wil6210_priv *wil = container_of(work,
131 struct wil6210_priv, disconnect_worker); 134 struct wil6210_priv, disconnect_worker);
132 135
136 mutex_lock(&wil->mutex);
133 _wil6210_disconnect(wil, NULL); 137 _wil6210_disconnect(wil, NULL);
138 mutex_unlock(&wil->mutex);
134} 139}
135 140
136static void wil_connect_timer_fn(ulong x) 141static void wil_connect_timer_fn(ulong x)
@@ -145,6 +150,38 @@ static void wil_connect_timer_fn(ulong x)
145 schedule_work(&wil->disconnect_worker); 150 schedule_work(&wil->disconnect_worker);
146} 151}
147 152
153static void wil_fw_error_worker(struct work_struct *work)
154{
155 struct wil6210_priv *wil = container_of(work,
156 struct wil6210_priv, fw_error_worker);
157 struct wireless_dev *wdev = wil->wdev;
158
159 wil_dbg_misc(wil, "fw error worker\n");
160
161 if (no_fw_recovery)
162 return;
163
164 mutex_lock(&wil->mutex);
165 switch (wdev->iftype) {
166 case NL80211_IFTYPE_STATION:
167 case NL80211_IFTYPE_P2P_CLIENT:
168 case NL80211_IFTYPE_MONITOR:
169 wil_info(wil, "fw error recovery started...\n");
170 wil_reset(wil);
171
172 /* need to re-allocate Rx ring after reset */
173 wil_rx_init(wil);
174 break;
175 case NL80211_IFTYPE_AP:
176 case NL80211_IFTYPE_P2P_GO:
177 /* recovery in these modes is done by upper layers */
178 break;
179 default:
180 break;
181 }
182 mutex_unlock(&wil->mutex);
183}
184
148static int wil_find_free_vring(struct wil6210_priv *wil) 185static int wil_find_free_vring(struct wil6210_priv *wil)
149{ 186{
150 int i; 187 int i;
@@ -197,6 +234,7 @@ int wil_priv_init(struct wil6210_priv *wil)
197 INIT_WORK(&wil->connect_worker, wil_connect_worker); 234 INIT_WORK(&wil->connect_worker, wil_connect_worker);
198 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker); 235 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
199 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker); 236 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
237 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
200 238
201 INIT_LIST_HEAD(&wil->pending_wmi_ev); 239 INIT_LIST_HEAD(&wil->pending_wmi_ev);
202 spin_lock_init(&wil->wmi_ev_lock); 240 spin_lock_init(&wil->wmi_ev_lock);
@@ -223,7 +261,10 @@ void wil6210_disconnect(struct wil6210_priv *wil, void *bssid)
223void wil_priv_deinit(struct wil6210_priv *wil) 261void wil_priv_deinit(struct wil6210_priv *wil)
224{ 262{
225 cancel_work_sync(&wil->disconnect_worker); 263 cancel_work_sync(&wil->disconnect_worker);
264 cancel_work_sync(&wil->fw_error_worker);
265 mutex_lock(&wil->mutex);
226 wil6210_disconnect(wil, NULL); 266 wil6210_disconnect(wil, NULL);
267 mutex_unlock(&wil->mutex);
227 wmi_event_flush(wil); 268 wmi_event_flush(wil);
228 destroy_workqueue(wil->wmi_wq_conn); 269 destroy_workqueue(wil->wmi_wq_conn);
229 destroy_workqueue(wil->wmi_wq); 270 destroy_workqueue(wil->wmi_wq);
@@ -231,40 +272,78 @@ void wil_priv_deinit(struct wil6210_priv *wil)
231 272
232static void wil_target_reset(struct wil6210_priv *wil) 273static void wil_target_reset(struct wil6210_priv *wil)
233{ 274{
275 int delay = 0;
276 u32 hw_state;
277 u32 rev_id;
278
234 wil_dbg_misc(wil, "Resetting...\n"); 279 wil_dbg_misc(wil, "Resetting...\n");
235 280
281 /* register read */
282#define R(a) ioread32(wil->csr + HOSTADDR(a))
236 /* register write */ 283 /* register write */
237#define W(a, v) iowrite32(v, wil->csr + HOSTADDR(a)) 284#define W(a, v) iowrite32(v, wil->csr + HOSTADDR(a))
238 /* register set = read, OR, write */ 285 /* register set = read, OR, write */
239#define S(a, v) iowrite32(ioread32(wil->csr + HOSTADDR(a)) | v, \ 286#define S(a, v) W(a, R(a) | v)
240 wil->csr + HOSTADDR(a)) 287 /* register clear = read, AND with inverted, write */
288#define C(a, v) W(a, R(a) & ~v)
241 289
290 wil->hw_version = R(RGF_USER_FW_REV_ID);
291 rev_id = wil->hw_version & 0xff;
242 /* hpal_perst_from_pad_src_n_mask */ 292 /* hpal_perst_from_pad_src_n_mask */
243 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(6)); 293 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(6));
244 /* car_perst_rst_src_n_mask */ 294 /* car_perst_rst_src_n_mask */
245 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(7)); 295 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(7));
296 wmb(); /* order is important here */
246 297
247 W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */ 298 W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */
248 W(RGF_USER_USER_CPU_0, BIT(1)); /* user_cpu_man_rst */ 299 W(RGF_USER_USER_CPU_0, BIT(1)); /* user_cpu_man_rst */
300 wmb(); /* order is important here */
249 301
250 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000); 302 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
251 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F); 303 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
252 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000170); 304 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000170);
253 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FC00); 305 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FC00);
306 wmb(); /* order is important here */
254 307
255 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0); 308 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
256 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0); 309 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
257 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0); 310 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
258 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0); 311 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
312 wmb(); /* order is important here */
259 313
260 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001); 314 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
261 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080); 315 if (rev_id == 1) {
316 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
317 } else {
318 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
319 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
320 }
262 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0); 321 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
322 wmb(); /* order is important here */
323
324 /* wait until device ready */
325 do {
326 msleep(1);
327 hw_state = R(RGF_USER_HW_MACHINE_STATE);
328 if (delay++ > 100) {
329 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
330 hw_state);
331 return;
332 }
333 } while (hw_state != HW_MACHINE_BOOT_DONE);
334
335 if (rev_id == 2)
336 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
263 337
264 wil_dbg_misc(wil, "Reset completed\n"); 338 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
339 wmb(); /* order is important here */
265 340
341 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay);
342
343#undef R
266#undef W 344#undef W
267#undef S 345#undef S
346#undef C
268} 347}
269 348
270void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r) 349void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
@@ -299,11 +378,24 @@ int wil_reset(struct wil6210_priv *wil)
299{ 378{
300 int rc; 379 int rc;
301 380
381 WARN_ON(!mutex_is_locked(&wil->mutex));
382
302 cancel_work_sync(&wil->disconnect_worker); 383 cancel_work_sync(&wil->disconnect_worker);
303 wil6210_disconnect(wil, NULL); 384 wil6210_disconnect(wil, NULL);
304 385
386 wil->status = 0; /* prevent NAPI from being scheduled */
387 if (test_bit(wil_status_napi_en, &wil->status)) {
388 napi_synchronize(&wil->napi_rx);
389 }
390
391 if (wil->scan_request) {
392 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
393 wil->scan_request);
394 cfg80211_scan_done(wil->scan_request, true);
395 wil->scan_request = NULL;
396 }
397
305 wil6210_disable_irq(wil); 398 wil6210_disable_irq(wil);
306 wil->status = 0;
307 399
308 wmi_event_flush(wil); 400 wmi_event_flush(wil);
309 401
@@ -313,6 +405,8 @@ int wil_reset(struct wil6210_priv *wil)
313 /* TODO: put MAC in reset */ 405 /* TODO: put MAC in reset */
314 wil_target_reset(wil); 406 wil_target_reset(wil);
315 407
408 wil_rx_fini(wil);
409
316 /* init after reset */ 410 /* init after reset */
317 wil->pending_connect_cid = -1; 411 wil->pending_connect_cid = -1;
318 reinit_completion(&wil->wmi_ready); 412 reinit_completion(&wil->wmi_ready);
@@ -326,6 +420,11 @@ int wil_reset(struct wil6210_priv *wil)
326 return rc; 420 return rc;
327} 421}
328 422
423void wil_fw_error_recovery(struct wil6210_priv *wil)
424{
425 wil_dbg_misc(wil, "starting fw error recovery\n");
426 schedule_work(&wil->fw_error_worker);
427}
329 428
330void wil_link_on(struct wil6210_priv *wil) 429void wil_link_on(struct wil6210_priv *wil)
331{ 430{
@@ -353,6 +452,8 @@ static int __wil_up(struct wil6210_priv *wil)
353 struct wireless_dev *wdev = wil->wdev; 452 struct wireless_dev *wdev = wil->wdev;
354 int rc; 453 int rc;
355 454
455 WARN_ON(!mutex_is_locked(&wil->mutex));
456
356 rc = wil_reset(wil); 457 rc = wil_reset(wil);
357 if (rc) 458 if (rc)
358 return rc; 459 return rc;
@@ -394,6 +495,7 @@ static int __wil_up(struct wil6210_priv *wil)
394 495
395 napi_enable(&wil->napi_rx); 496 napi_enable(&wil->napi_rx);
396 napi_enable(&wil->napi_tx); 497 napi_enable(&wil->napi_tx);
498 set_bit(wil_status_napi_en, &wil->status);
397 499
398 return 0; 500 return 0;
399} 501}
@@ -411,6 +513,9 @@ int wil_up(struct wil6210_priv *wil)
411 513
412static int __wil_down(struct wil6210_priv *wil) 514static int __wil_down(struct wil6210_priv *wil)
413{ 515{
516 WARN_ON(!mutex_is_locked(&wil->mutex));
517
518 clear_bit(wil_status_napi_en, &wil->status);
414 napi_disable(&wil->napi_rx); 519 napi_disable(&wil->napi_rx);
415 napi_disable(&wil->napi_tx); 520 napi_disable(&wil->napi_tx);
416 521
diff --git a/drivers/net/wireless/ath/wil6210/netdev.c b/drivers/net/wireless/ath/wil6210/netdev.c
index 717178f09aa8..fdcaeb820e75 100644
--- a/drivers/net/wireless/ath/wil6210/netdev.c
+++ b/drivers/net/wireless/ath/wil6210/netdev.c
@@ -127,8 +127,9 @@ void *wil_if_alloc(struct device *dev, void __iomem *csr)
127 127
128 ndev->netdev_ops = &wil_netdev_ops; 128 ndev->netdev_ops = &wil_netdev_ops;
129 ndev->ieee80211_ptr = wdev; 129 ndev->ieee80211_ptr = wdev;
130 ndev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM; 130 ndev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
131 ndev->features |= NETIF_F_HW_CSUM | NETIF_F_RXCSUM; 131 NETIF_F_SG | NETIF_F_GRO;
132 ndev->features |= ndev->hw_features;
132 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy)); 133 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
133 wdev->netdev = ndev; 134 wdev->netdev = ndev;
134 135
diff --git a/drivers/net/wireless/ath/wil6210/pcie_bus.c b/drivers/net/wireless/ath/wil6210/pcie_bus.c
index e1c8cc4a4b92..f1e1bb338d68 100644
--- a/drivers/net/wireless/ath/wil6210/pcie_bus.c
+++ b/drivers/net/wireless/ath/wil6210/pcie_bus.c
@@ -68,10 +68,14 @@ static int wil_if_pcie_enable(struct wil6210_priv *wil)
68 goto stop_master; 68 goto stop_master;
69 69
70 /* need reset here to obtain MAC */ 70 /* need reset here to obtain MAC */
71 mutex_lock(&wil->mutex);
71 rc = wil_reset(wil); 72 rc = wil_reset(wil);
73 mutex_unlock(&wil->mutex);
72 if (rc) 74 if (rc)
73 goto release_irq; 75 goto release_irq;
74 76
77 wil_info(wil, "HW version: 0x%08x\n", wil->hw_version);
78
75 return 0; 79 return 0;
76 80
77 release_irq: 81 release_irq:
@@ -149,6 +153,7 @@ static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
149 pci_set_drvdata(pdev, wil); 153 pci_set_drvdata(pdev, wil);
150 wil->pdev = pdev; 154 wil->pdev = pdev;
151 155
156 wil6210_clear_irq(wil);
152 /* FW should raise IRQ when ready */ 157 /* FW should raise IRQ when ready */
153 rc = wil_if_pcie_enable(wil); 158 rc = wil_if_pcie_enable(wil);
154 if (rc) { 159 if (rc) {
diff --git a/drivers/net/wireless/ath/wil6210/txrx.c b/drivers/net/wireless/ath/wil6210/txrx.c
index 092081e209da..c8c547457eb4 100644
--- a/drivers/net/wireless/ath/wil6210/txrx.c
+++ b/drivers/net/wireless/ath/wil6210/txrx.c
@@ -104,6 +104,23 @@ static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring)
104 return 0; 104 return 0;
105} 105}
106 106
107static void wil_txdesc_unmap(struct device *dev, struct vring_tx_desc *d,
108 struct wil_ctx *ctx)
109{
110 dma_addr_t pa = wil_desc_addr(&d->dma.addr);
111 u16 dmalen = le16_to_cpu(d->dma.length);
112 switch (ctx->mapped_as) {
113 case wil_mapped_as_single:
114 dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
115 break;
116 case wil_mapped_as_page:
117 dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
118 break;
119 default:
120 break;
121 }
122}
123
107static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring, 124static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring,
108 int tx) 125 int tx)
109{ 126{
@@ -122,15 +139,7 @@ static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring,
122 139
123 ctx = &vring->ctx[vring->swtail]; 140 ctx = &vring->ctx[vring->swtail];
124 *d = *_d; 141 *d = *_d;
125 pa = wil_desc_addr(&d->dma.addr); 142 wil_txdesc_unmap(dev, d, ctx);
126 dmalen = le16_to_cpu(d->dma.length);
127 if (vring->ctx[vring->swtail].mapped_as_page) {
128 dma_unmap_page(dev, pa, dmalen,
129 DMA_TO_DEVICE);
130 } else {
131 dma_unmap_single(dev, pa, dmalen,
132 DMA_TO_DEVICE);
133 }
134 if (ctx->skb) 143 if (ctx->skb)
135 dev_kfree_skb_any(ctx->skb); 144 dev_kfree_skb_any(ctx->skb);
136 vring->swtail = wil_vring_next_tail(vring); 145 vring->swtail = wil_vring_next_tail(vring);
@@ -479,7 +488,7 @@ static int wil_rx_refill(struct wil6210_priv *wil, int count)
479 */ 488 */
480void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev) 489void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev)
481{ 490{
482 int rc; 491 gro_result_t rc;
483 struct wil6210_priv *wil = ndev_to_wil(ndev); 492 struct wil6210_priv *wil = ndev_to_wil(ndev);
484 unsigned int len = skb->len; 493 unsigned int len = skb->len;
485 struct vring_rx_desc *d = wil_skb_rxdesc(skb); 494 struct vring_rx_desc *d = wil_skb_rxdesc(skb);
@@ -488,17 +497,17 @@ void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev)
488 497
489 skb_orphan(skb); 498 skb_orphan(skb);
490 499
491 rc = netif_receive_skb(skb); 500 rc = napi_gro_receive(&wil->napi_rx, skb);
492 501
493 if (likely(rc == NET_RX_SUCCESS)) { 502 if (unlikely(rc == GRO_DROP)) {
503 ndev->stats.rx_dropped++;
504 stats->rx_dropped++;
505 wil_dbg_txrx(wil, "Rx drop %d bytes\n", len);
506 } else {
494 ndev->stats.rx_packets++; 507 ndev->stats.rx_packets++;
495 stats->rx_packets++; 508 stats->rx_packets++;
496 ndev->stats.rx_bytes += len; 509 ndev->stats.rx_bytes += len;
497 stats->rx_bytes += len; 510 stats->rx_bytes += len;
498
499 } else {
500 ndev->stats.rx_dropped++;
501 stats->rx_dropped++;
502 } 511 }
503} 512}
504 513
@@ -548,6 +557,11 @@ int wil_rx_init(struct wil6210_priv *wil)
548 struct vring *vring = &wil->vring_rx; 557 struct vring *vring = &wil->vring_rx;
549 int rc; 558 int rc;
550 559
560 if (vring->va) {
561 wil_err(wil, "Rx ring already allocated\n");
562 return -EINVAL;
563 }
564
551 vring->size = WIL6210_RX_RING_SIZE; 565 vring->size = WIL6210_RX_RING_SIZE;
552 rc = wil_vring_alloc(wil, vring); 566 rc = wil_vring_alloc(wil, vring);
553 if (rc) 567 if (rc)
@@ -588,7 +602,7 @@ int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
588 .ring_size = cpu_to_le16(size), 602 .ring_size = cpu_to_le16(size),
589 }, 603 },
590 .ringid = id, 604 .ringid = id,
591 .cidxtid = (cid & 0xf) | ((tid & 0xf) << 4), 605 .cidxtid = mk_cidxtid(cid, tid),
592 .encap_trans_type = WMI_VRING_ENC_TYPE_802_3, 606 .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
593 .mac_ctrl = 0, 607 .mac_ctrl = 0,
594 .to_resolution = 0, 608 .to_resolution = 0,
@@ -604,6 +618,7 @@ int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
604 struct wmi_vring_cfg_done_event cmd; 618 struct wmi_vring_cfg_done_event cmd;
605 } __packed reply; 619 } __packed reply;
606 struct vring *vring = &wil->vring_tx[id]; 620 struct vring *vring = &wil->vring_tx[id];
621 struct vring_tx_data *txdata = &wil->vring_tx_data[id];
607 622
608 if (vring->va) { 623 if (vring->va) {
609 wil_err(wil, "Tx ring [%d] already allocated\n", id); 624 wil_err(wil, "Tx ring [%d] already allocated\n", id);
@@ -611,6 +626,7 @@ int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
611 goto out; 626 goto out;
612 } 627 }
613 628
629 memset(txdata, 0, sizeof(*txdata));
614 vring->size = size; 630 vring->size = size;
615 rc = wil_vring_alloc(wil, vring); 631 rc = wil_vring_alloc(wil, vring);
616 if (rc) 632 if (rc)
@@ -634,6 +650,8 @@ int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
634 } 650 }
635 vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr); 651 vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
636 652
653 txdata->enabled = 1;
654
637 return 0; 655 return 0;
638 out_free: 656 out_free:
639 wil_vring_free(wil, vring, 1); 657 wil_vring_free(wil, vring, 1);
@@ -646,9 +664,16 @@ void wil_vring_fini_tx(struct wil6210_priv *wil, int id)
646{ 664{
647 struct vring *vring = &wil->vring_tx[id]; 665 struct vring *vring = &wil->vring_tx[id];
648 666
667 WARN_ON(!mutex_is_locked(&wil->mutex));
668
649 if (!vring->va) 669 if (!vring->va)
650 return; 670 return;
651 671
672 /* make sure NAPI won't touch this vring */
673 wil->vring_tx_data[id].enabled = 0;
674 if (test_bit(wil_status_napi_en, &wil->status))
675 napi_synchronize(&wil->napi_tx);
676
652 wil_vring_free(wil, vring, 1); 677 wil_vring_free(wil, vring, 1);
653} 678}
654 679
@@ -662,6 +687,10 @@ static struct vring *wil_find_tx_vring(struct wil6210_priv *wil,
662 if (cid < 0) 687 if (cid < 0)
663 return NULL; 688 return NULL;
664 689
690 if (!wil->sta[cid].data_port_open &&
691 (skb->protocol != cpu_to_be16(ETH_P_PAE)))
692 return NULL;
693
665 /* TODO: fix for multiple TID */ 694 /* TODO: fix for multiple TID */
666 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) { 695 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
667 if (wil->vring2cid_tid[i][0] == cid) { 696 if (wil->vring2cid_tid[i][0] == cid) {
@@ -700,12 +729,19 @@ static struct vring *wil_tx_bcast(struct wil6210_priv *wil,
700 struct vring *v, *v2; 729 struct vring *v, *v2;
701 struct sk_buff *skb2; 730 struct sk_buff *skb2;
702 int i; 731 int i;
732 u8 cid;
703 733
704 /* find 1-st vring */ 734 /* find 1-st vring eligible for data */
705 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { 735 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
706 v = &wil->vring_tx[i]; 736 v = &wil->vring_tx[i];
707 if (v->va) 737 if (!v->va)
708 goto found; 738 continue;
739
740 cid = wil->vring2cid_tid[i][0];
741 if (!wil->sta[cid].data_port_open)
742 continue;
743
744 goto found;
709 } 745 }
710 746
711 wil_err(wil, "Tx while no vrings active?\n"); 747 wil_err(wil, "Tx while no vrings active?\n");
@@ -721,6 +757,10 @@ found:
721 v2 = &wil->vring_tx[i]; 757 v2 = &wil->vring_tx[i];
722 if (!v2->va) 758 if (!v2->va)
723 continue; 759 continue;
760 cid = wil->vring2cid_tid[i][0];
761 if (!wil->sta[cid].data_port_open)
762 continue;
763
724 skb2 = skb_copy(skb, GFP_ATOMIC); 764 skb2 = skb_copy(skb, GFP_ATOMIC);
725 if (skb2) { 765 if (skb2) {
726 wil_dbg_txrx(wil, "BCAST DUP -> ring %d\n", i); 766 wil_dbg_txrx(wil, "BCAST DUP -> ring %d\n", i);
@@ -759,6 +799,13 @@ static int wil_tx_desc_map(struct vring_tx_desc *d, dma_addr_t pa, u32 len,
759 return 0; 799 return 0;
760} 800}
761 801
802static inline
803void wil_tx_desc_set_nr_frags(struct vring_tx_desc *d, int nr_frags)
804{
805 d->mac.d[2] |= ((nr_frags + 1) <<
806 MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS);
807}
808
762static int wil_tx_desc_offload_cksum_set(struct wil6210_priv *wil, 809static int wil_tx_desc_offload_cksum_set(struct wil6210_priv *wil,
763 struct vring_tx_desc *d, 810 struct vring_tx_desc *d,
764 struct sk_buff *skb) 811 struct sk_buff *skb)
@@ -823,8 +870,6 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
823 870
824 wil_dbg_txrx(wil, "%s()\n", __func__); 871 wil_dbg_txrx(wil, "%s()\n", __func__);
825 872
826 if (avail < vring->size/8)
827 netif_tx_stop_all_queues(wil_to_ndev(wil));
828 if (avail < 1 + nr_frags) { 873 if (avail < 1 + nr_frags) {
829 wil_err(wil, "Tx ring full. No space for %d fragments\n", 874 wil_err(wil, "Tx ring full. No space for %d fragments\n",
830 1 + nr_frags); 875 1 + nr_frags);
@@ -842,6 +887,7 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
842 887
843 if (unlikely(dma_mapping_error(dev, pa))) 888 if (unlikely(dma_mapping_error(dev, pa)))
844 return -EINVAL; 889 return -EINVAL;
890 vring->ctx[i].mapped_as = wil_mapped_as_single;
845 /* 1-st segment */ 891 /* 1-st segment */
846 wil_tx_desc_map(d, pa, skb_headlen(skb), vring_index); 892 wil_tx_desc_map(d, pa, skb_headlen(skb), vring_index);
847 /* Process TCP/UDP checksum offloading */ 893 /* Process TCP/UDP checksum offloading */
@@ -851,8 +897,8 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
851 goto dma_error; 897 goto dma_error;
852 } 898 }
853 899
854 d->mac.d[2] |= ((nr_frags + 1) << 900 vring->ctx[i].nr_frags = nr_frags;
855 MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS); 901 wil_tx_desc_set_nr_frags(d, nr_frags);
856 if (nr_frags) 902 if (nr_frags)
857 *_d = *d; 903 *_d = *d;
858 904
@@ -867,8 +913,13 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
867 DMA_TO_DEVICE); 913 DMA_TO_DEVICE);
868 if (unlikely(dma_mapping_error(dev, pa))) 914 if (unlikely(dma_mapping_error(dev, pa)))
869 goto dma_error; 915 goto dma_error;
916 vring->ctx[i].mapped_as = wil_mapped_as_page;
870 wil_tx_desc_map(d, pa, len, vring_index); 917 wil_tx_desc_map(d, pa, len, vring_index);
871 vring->ctx[i].mapped_as_page = 1; 918 /* no need to check return code -
919 * if it succeeded for 1-st descriptor,
920 * it will succeed here too
921 */
922 wil_tx_desc_offload_cksum_set(wil, d, skb);
872 *_d = *d; 923 *_d = *d;
873 } 924 }
874 /* for the last seg only */ 925 /* for the last seg only */
@@ -897,7 +948,6 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
897 /* unmap what we have mapped */ 948 /* unmap what we have mapped */
898 nr_frags = f + 1; /* frags mapped + one for skb head */ 949 nr_frags = f + 1; /* frags mapped + one for skb head */
899 for (f = 0; f < nr_frags; f++) { 950 for (f = 0; f < nr_frags; f++) {
900 u16 dmalen;
901 struct wil_ctx *ctx; 951 struct wil_ctx *ctx;
902 952
903 i = (swhead + f) % vring->size; 953 i = (swhead + f) % vring->size;
@@ -905,12 +955,7 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
905 _d = &(vring->va[i].tx); 955 _d = &(vring->va[i].tx);
906 *d = *_d; 956 *d = *_d;
907 _d->dma.status = TX_DMA_STATUS_DU; 957 _d->dma.status = TX_DMA_STATUS_DU;
908 pa = wil_desc_addr(&d->dma.addr); 958 wil_txdesc_unmap(dev, d, ctx);
909 dmalen = le16_to_cpu(d->dma.length);
910 if (ctx->mapped_as_page)
911 dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
912 else
913 dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
914 959
915 if (ctx->skb) 960 if (ctx->skb)
916 dev_kfree_skb_any(ctx->skb); 961 dev_kfree_skb_any(ctx->skb);
@@ -927,11 +972,15 @@ netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
927 struct wil6210_priv *wil = ndev_to_wil(ndev); 972 struct wil6210_priv *wil = ndev_to_wil(ndev);
928 struct ethhdr *eth = (void *)skb->data; 973 struct ethhdr *eth = (void *)skb->data;
929 struct vring *vring; 974 struct vring *vring;
975 static bool pr_once_fw;
930 int rc; 976 int rc;
931 977
932 wil_dbg_txrx(wil, "%s()\n", __func__); 978 wil_dbg_txrx(wil, "%s()\n", __func__);
933 if (!test_bit(wil_status_fwready, &wil->status)) { 979 if (!test_bit(wil_status_fwready, &wil->status)) {
934 wil_err(wil, "FW not ready\n"); 980 if (!pr_once_fw) {
981 wil_err(wil, "FW not ready\n");
982 pr_once_fw = true;
983 }
935 goto drop; 984 goto drop;
936 } 985 }
937 if (!test_bit(wil_status_fwconnected, &wil->status)) { 986 if (!test_bit(wil_status_fwconnected, &wil->status)) {
@@ -942,6 +991,7 @@ netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
942 wil_err(wil, "Xmit in monitor mode not supported\n"); 991 wil_err(wil, "Xmit in monitor mode not supported\n");
943 goto drop; 992 goto drop;
944 } 993 }
994 pr_once_fw = false;
945 995
946 /* find vring */ 996 /* find vring */
947 if (is_unicast_ether_addr(eth->h_dest)) { 997 if (is_unicast_ether_addr(eth->h_dest)) {
@@ -956,6 +1006,10 @@ netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
956 /* set up vring entry */ 1006 /* set up vring entry */
957 rc = wil_tx_vring(wil, vring, skb); 1007 rc = wil_tx_vring(wil, vring, skb);
958 1008
1009 /* do we still have enough room in the vring? */
1010 if (wil_vring_avail_tx(vring) < vring->size/8)
1011 netif_tx_stop_all_queues(wil_to_ndev(wil));
1012
959 switch (rc) { 1013 switch (rc) {
960 case 0: 1014 case 0:
961 /* statistics will be updated on the tx_complete */ 1015 /* statistics will be updated on the tx_complete */
@@ -985,69 +1039,82 @@ int wil_tx_complete(struct wil6210_priv *wil, int ringid)
985 struct net_device *ndev = wil_to_ndev(wil); 1039 struct net_device *ndev = wil_to_ndev(wil);
986 struct device *dev = wil_to_dev(wil); 1040 struct device *dev = wil_to_dev(wil);
987 struct vring *vring = &wil->vring_tx[ringid]; 1041 struct vring *vring = &wil->vring_tx[ringid];
1042 struct vring_tx_data *txdata = &wil->vring_tx_data[ringid];
988 int done = 0; 1043 int done = 0;
989 int cid = wil->vring2cid_tid[ringid][0]; 1044 int cid = wil->vring2cid_tid[ringid][0];
990 struct wil_net_stats *stats = &wil->sta[cid].stats; 1045 struct wil_net_stats *stats = &wil->sta[cid].stats;
1046 volatile struct vring_tx_desc *_d;
991 1047
992 if (!vring->va) { 1048 if (!vring->va) {
993 wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid); 1049 wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid);
994 return 0; 1050 return 0;
995 } 1051 }
996 1052
1053 if (!txdata->enabled) {
1054 wil_info(wil, "Tx irq[%d]: vring disabled\n", ringid);
1055 return 0;
1056 }
1057
997 wil_dbg_txrx(wil, "%s(%d)\n", __func__, ringid); 1058 wil_dbg_txrx(wil, "%s(%d)\n", __func__, ringid);
998 1059
999 while (!wil_vring_is_empty(vring)) { 1060 while (!wil_vring_is_empty(vring)) {
1000 volatile struct vring_tx_desc *_d = 1061 int new_swtail;
1001 &vring->va[vring->swtail].tx;
1002 struct vring_tx_desc dd, *d = &dd;
1003 dma_addr_t pa;
1004 u16 dmalen;
1005 struct wil_ctx *ctx = &vring->ctx[vring->swtail]; 1062 struct wil_ctx *ctx = &vring->ctx[vring->swtail];
1006 struct sk_buff *skb = ctx->skb; 1063 /**
1007 1064 * For the fragmented skb, HW will set DU bit only for the
1008 *d = *_d; 1065 * last fragment. look for it
1066 */
1067 int lf = (vring->swtail + ctx->nr_frags) % vring->size;
1068 /* TODO: check we are not past head */
1009 1069
1010 if (!(d->dma.status & TX_DMA_STATUS_DU)) 1070 _d = &vring->va[lf].tx;
1071 if (!(_d->dma.status & TX_DMA_STATUS_DU))
1011 break; 1072 break;
1012 1073
1013 dmalen = le16_to_cpu(d->dma.length); 1074 new_swtail = (lf + 1) % vring->size;
1014 trace_wil6210_tx_done(ringid, vring->swtail, dmalen, 1075 while (vring->swtail != new_swtail) {
1015 d->dma.error); 1076 struct vring_tx_desc dd, *d = &dd;
1016 wil_dbg_txrx(wil, 1077 u16 dmalen;
1017 "Tx[%3d] : %d bytes, status 0x%02x err 0x%02x\n", 1078 struct wil_ctx *ctx = &vring->ctx[vring->swtail];
1018 vring->swtail, dmalen, d->dma.status, 1079 struct sk_buff *skb = ctx->skb;
1019 d->dma.error); 1080 _d = &vring->va[vring->swtail].tx;
1020 wil_hex_dump_txrx("TxC ", DUMP_PREFIX_NONE, 32, 4, 1081
1021 (const void *)d, sizeof(*d), false); 1082 *d = *_d;
1022
1023 pa = wil_desc_addr(&d->dma.addr);
1024 if (ctx->mapped_as_page)
1025 dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
1026 else
1027 dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
1028
1029 if (skb) {
1030 if (d->dma.error == 0) {
1031 ndev->stats.tx_packets++;
1032 stats->tx_packets++;
1033 ndev->stats.tx_bytes += skb->len;
1034 stats->tx_bytes += skb->len;
1035 } else {
1036 ndev->stats.tx_errors++;
1037 stats->tx_errors++;
1038 }
1039 1083
1040 dev_kfree_skb_any(skb); 1084 dmalen = le16_to_cpu(d->dma.length);
1085 trace_wil6210_tx_done(ringid, vring->swtail, dmalen,
1086 d->dma.error);
1087 wil_dbg_txrx(wil,
1088 "Tx[%3d] : %d bytes, status 0x%02x err 0x%02x\n",
1089 vring->swtail, dmalen, d->dma.status,
1090 d->dma.error);
1091 wil_hex_dump_txrx("TxC ", DUMP_PREFIX_NONE, 32, 4,
1092 (const void *)d, sizeof(*d), false);
1093
1094 wil_txdesc_unmap(dev, d, ctx);
1095
1096 if (skb) {
1097 if (d->dma.error == 0) {
1098 ndev->stats.tx_packets++;
1099 stats->tx_packets++;
1100 ndev->stats.tx_bytes += skb->len;
1101 stats->tx_bytes += skb->len;
1102 } else {
1103 ndev->stats.tx_errors++;
1104 stats->tx_errors++;
1105 }
1106
1107 dev_kfree_skb_any(skb);
1108 }
1109 memset(ctx, 0, sizeof(*ctx));
1110 /* There is no need to touch HW descriptor:
1111 * - ststus bit TX_DMA_STATUS_DU is set by design,
1112 * so hardware will not try to process this desc.,
1113 * - rest of descriptor will be initialized on Tx.
1114 */
1115 vring->swtail = wil_vring_next_tail(vring);
1116 done++;
1041 } 1117 }
1042 memset(ctx, 0, sizeof(*ctx));
1043 /*
1044 * There is no need to touch HW descriptor:
1045 * - ststus bit TX_DMA_STATUS_DU is set by design,
1046 * so hardware will not try to process this desc.,
1047 * - rest of descriptor will be initialized on Tx.
1048 */
1049 vring->swtail = wil_vring_next_tail(vring);
1050 done++;
1051 } 1118 }
1052 if (wil_vring_avail_tx(vring) > vring->size/4) 1119 if (wil_vring_avail_tx(vring) > vring->size/4)
1053 netif_tx_wake_all_queues(wil_to_ndev(wil)); 1120 netif_tx_wake_all_queues(wil_to_ndev(wil));
diff --git a/drivers/net/wireless/ath/wil6210/wil6210.h b/drivers/net/wireless/ath/wil6210/wil6210.h
index 980dccc82b32..2a2dec75f026 100644
--- a/drivers/net/wireless/ath/wil6210/wil6210.h
+++ b/drivers/net/wireless/ath/wil6210/wil6210.h
@@ -74,23 +74,21 @@ struct RGF_ICR {
74} __packed; 74} __packed;
75 75
76/* registers - FW addresses */ 76/* registers - FW addresses */
77#define RGF_USER_USER_SCRATCH_PAD (0x8802bc) 77#define RGF_USER_HW_MACHINE_STATE (0x8801dc)
78#define RGF_USER_USER_ICR (0x880b4c) /* struct RGF_ICR */ 78 #define HW_MACHINE_BOOT_DONE (0x3fffffd)
79 #define BIT_USER_USER_ICR_SW_INT_2 BIT(18)
80#define RGF_USER_CLKS_CTL_SW_RST_MASK_0 (0x880b14)
81#define RGF_USER_MAC_CPU_0 (0x8801fc)
82#define RGF_USER_USER_CPU_0 (0x8801e0) 79#define RGF_USER_USER_CPU_0 (0x8801e0)
80#define RGF_USER_MAC_CPU_0 (0x8801fc)
81#define RGF_USER_USER_SCRATCH_PAD (0x8802bc)
82#define RGF_USER_FW_REV_ID (0x880a8c) /* chip revision */
83#define RGF_USER_CLKS_CTL_0 (0x880abc)
84 #define BIT_USER_CLKS_RST_PWGD BIT(11) /* reset on "power good" */
83#define RGF_USER_CLKS_CTL_SW_RST_VEC_0 (0x880b04) 85#define RGF_USER_CLKS_CTL_SW_RST_VEC_0 (0x880b04)
84#define RGF_USER_CLKS_CTL_SW_RST_VEC_1 (0x880b08) 86#define RGF_USER_CLKS_CTL_SW_RST_VEC_1 (0x880b08)
85#define RGF_USER_CLKS_CTL_SW_RST_VEC_2 (0x880b0c) 87#define RGF_USER_CLKS_CTL_SW_RST_VEC_2 (0x880b0c)
86#define RGF_USER_CLKS_CTL_SW_RST_VEC_3 (0x880b10) 88#define RGF_USER_CLKS_CTL_SW_RST_VEC_3 (0x880b10)
87 89#define RGF_USER_CLKS_CTL_SW_RST_MASK_0 (0x880b14)
88#define RGF_DMA_PSEUDO_CAUSE (0x881c68) 90#define RGF_USER_USER_ICR (0x880b4c) /* struct RGF_ICR */
89#define RGF_DMA_PSEUDO_CAUSE_MASK_SW (0x881c6c) 91 #define BIT_USER_USER_ICR_SW_INT_2 BIT(18)
90#define RGF_DMA_PSEUDO_CAUSE_MASK_FW (0x881c70)
91 #define BIT_DMA_PSEUDO_CAUSE_RX BIT(0)
92 #define BIT_DMA_PSEUDO_CAUSE_TX BIT(1)
93 #define BIT_DMA_PSEUDO_CAUSE_MISC BIT(2)
94 92
95#define RGF_DMA_EP_TX_ICR (0x881bb4) /* struct RGF_ICR */ 93#define RGF_DMA_EP_TX_ICR (0x881bb4) /* struct RGF_ICR */
96 #define BIT_DMA_EP_TX_ICR_TX_DONE BIT(0) 94 #define BIT_DMA_EP_TX_ICR_TX_DONE BIT(0)
@@ -105,13 +103,22 @@ struct RGF_ICR {
105/* Interrupt moderation control */ 103/* Interrupt moderation control */
106#define RGF_DMA_ITR_CNT_TRSH (0x881c5c) 104#define RGF_DMA_ITR_CNT_TRSH (0x881c5c)
107#define RGF_DMA_ITR_CNT_DATA (0x881c60) 105#define RGF_DMA_ITR_CNT_DATA (0x881c60)
108#define RGF_DMA_ITR_CNT_CRL (0x881C64) 106#define RGF_DMA_ITR_CNT_CRL (0x881c64)
109 #define BIT_DMA_ITR_CNT_CRL_EN BIT(0) 107 #define BIT_DMA_ITR_CNT_CRL_EN BIT(0)
110 #define BIT_DMA_ITR_CNT_CRL_EXT_TICK BIT(1) 108 #define BIT_DMA_ITR_CNT_CRL_EXT_TICK BIT(1)
111 #define BIT_DMA_ITR_CNT_CRL_FOREVER BIT(2) 109 #define BIT_DMA_ITR_CNT_CRL_FOREVER BIT(2)
112 #define BIT_DMA_ITR_CNT_CRL_CLR BIT(3) 110 #define BIT_DMA_ITR_CNT_CRL_CLR BIT(3)
113 #define BIT_DMA_ITR_CNT_CRL_REACH_TRSH BIT(4) 111 #define BIT_DMA_ITR_CNT_CRL_REACH_TRSH BIT(4)
114 112
113#define RGF_DMA_PSEUDO_CAUSE (0x881c68)
114#define RGF_DMA_PSEUDO_CAUSE_MASK_SW (0x881c6c)
115#define RGF_DMA_PSEUDO_CAUSE_MASK_FW (0x881c70)
116 #define BIT_DMA_PSEUDO_CAUSE_RX BIT(0)
117 #define BIT_DMA_PSEUDO_CAUSE_TX BIT(1)
118 #define BIT_DMA_PSEUDO_CAUSE_MISC BIT(2)
119
120#define RGF_PCIE_LOS_COUNTER_CTL (0x882dc4)
121
115/* popular locations */ 122/* popular locations */
116#define HOST_MBOX HOSTADDR(RGF_USER_USER_SCRATCH_PAD) 123#define HOST_MBOX HOSTADDR(RGF_USER_USER_SCRATCH_PAD)
117#define HOST_SW_INT (HOSTADDR(RGF_USER_USER_ICR) + \ 124#define HOST_SW_INT (HOSTADDR(RGF_USER_USER_ICR) + \
@@ -125,6 +132,31 @@ struct RGF_ICR {
125 132
126/* Hardware definitions end */ 133/* Hardware definitions end */
127 134
135/**
136 * mk_cidxtid - construct @cidxtid field
137 * @cid: CID value
138 * @tid: TID value
139 *
140 * @cidxtid field encoded as bits 0..3 - CID; 4..7 - TID
141 */
142static inline u8 mk_cidxtid(u8 cid, u8 tid)
143{
144 return ((tid & 0xf) << 4) | (cid & 0xf);
145}
146
147/**
148 * parse_cidxtid - parse @cidxtid field
149 * @cid: store CID value here
150 * @tid: store TID value here
151 *
152 * @cidxtid field encoded as bits 0..3 - CID; 4..7 - TID
153 */
154static inline void parse_cidxtid(u8 cidxtid, u8 *cid, u8 *tid)
155{
156 *cid = cidxtid & 0xf;
157 *tid = (cidxtid >> 4) & 0xf;
158}
159
128struct wil6210_mbox_ring { 160struct wil6210_mbox_ring {
129 u32 base; 161 u32 base;
130 u16 entry_size; /* max. size of mbox entry, incl. all headers */ 162 u16 entry_size; /* max. size of mbox entry, incl. all headers */
@@ -184,12 +216,19 @@ struct pending_wmi_event {
184 } __packed event; 216 } __packed event;
185}; 217};
186 218
219enum { /* for wil_ctx.mapped_as */
220 wil_mapped_as_none = 0,
221 wil_mapped_as_single = 1,
222 wil_mapped_as_page = 2,
223};
224
187/** 225/**
188 * struct wil_ctx - software context for Vring descriptor 226 * struct wil_ctx - software context for Vring descriptor
189 */ 227 */
190struct wil_ctx { 228struct wil_ctx {
191 struct sk_buff *skb; 229 struct sk_buff *skb;
192 u8 mapped_as_page:1; 230 u8 nr_frags;
231 u8 mapped_as;
193}; 232};
194 233
195union vring_desc; 234union vring_desc;
@@ -204,6 +243,14 @@ struct vring {
204 struct wil_ctx *ctx; /* ctx[size] - software context */ 243 struct wil_ctx *ctx; /* ctx[size] - software context */
205}; 244};
206 245
246/**
247 * Additional data for Tx Vring
248 */
249struct vring_tx_data {
250 int enabled;
251
252};
253
207enum { /* for wil6210_priv.status */ 254enum { /* for wil6210_priv.status */
208 wil_status_fwready = 0, 255 wil_status_fwready = 0,
209 wil_status_fwconnecting, 256 wil_status_fwconnecting,
@@ -211,6 +258,7 @@ enum { /* for wil6210_priv.status */
211 wil_status_dontscan, 258 wil_status_dontscan,
212 wil_status_reset_done, 259 wil_status_reset_done,
213 wil_status_irqen, /* FIXME: interrupts enabled - for debug */ 260 wil_status_irqen, /* FIXME: interrupts enabled - for debug */
261 wil_status_napi_en, /* NAPI enabled protected by wil->mutex */
214}; 262};
215 263
216struct pci_dev; 264struct pci_dev;
@@ -296,6 +344,7 @@ struct wil_sta_info {
296 u8 addr[ETH_ALEN]; 344 u8 addr[ETH_ALEN];
297 enum wil_sta_status status; 345 enum wil_sta_status status;
298 struct wil_net_stats stats; 346 struct wil_net_stats stats;
347 bool data_port_open; /* can send any data, not only EAPOL */
299 /* Rx BACK */ 348 /* Rx BACK */
300 struct wil_tid_ampdu_rx *tid_rx[WIL_STA_TID_NUM]; 349 struct wil_tid_ampdu_rx *tid_rx[WIL_STA_TID_NUM];
301 unsigned long tid_rx_timer_expired[BITS_TO_LONGS(WIL_STA_TID_NUM)]; 350 unsigned long tid_rx_timer_expired[BITS_TO_LONGS(WIL_STA_TID_NUM)];
@@ -309,6 +358,7 @@ struct wil6210_priv {
309 void __iomem *csr; 358 void __iomem *csr;
310 ulong status; 359 ulong status;
311 u32 fw_version; 360 u32 fw_version;
361 u32 hw_version;
312 u8 n_mids; /* number of additional MIDs as reported by FW */ 362 u8 n_mids; /* number of additional MIDs as reported by FW */
313 /* profile */ 363 /* profile */
314 u32 monitor_flags; 364 u32 monitor_flags;
@@ -329,6 +379,7 @@ struct wil6210_priv {
329 struct workqueue_struct *wmi_wq_conn; /* for connect worker */ 379 struct workqueue_struct *wmi_wq_conn; /* for connect worker */
330 struct work_struct connect_worker; 380 struct work_struct connect_worker;
331 struct work_struct disconnect_worker; 381 struct work_struct disconnect_worker;
382 struct work_struct fw_error_worker; /* for FW error recovery */
332 struct timer_list connect_timer; 383 struct timer_list connect_timer;
333 int pending_connect_cid; 384 int pending_connect_cid;
334 struct list_head pending_wmi_ev; 385 struct list_head pending_wmi_ev;
@@ -343,6 +394,7 @@ struct wil6210_priv {
343 /* DMA related */ 394 /* DMA related */
344 struct vring vring_rx; 395 struct vring vring_rx;
345 struct vring vring_tx[WIL6210_MAX_TX_RINGS]; 396 struct vring vring_tx[WIL6210_MAX_TX_RINGS];
397 struct vring_tx_data vring_tx_data[WIL6210_MAX_TX_RINGS];
346 u8 vring2cid_tid[WIL6210_MAX_TX_RINGS][2]; /* [0] - CID, [1] - TID */ 398 u8 vring2cid_tid[WIL6210_MAX_TX_RINGS][2]; /* [0] - CID, [1] - TID */
347 struct wil_sta_info sta[WIL6210_MAX_CID]; 399 struct wil_sta_info sta[WIL6210_MAX_CID];
348 /* scan */ 400 /* scan */
@@ -406,6 +458,7 @@ void wil_if_remove(struct wil6210_priv *wil);
406int wil_priv_init(struct wil6210_priv *wil); 458int wil_priv_init(struct wil6210_priv *wil);
407void wil_priv_deinit(struct wil6210_priv *wil); 459void wil_priv_deinit(struct wil6210_priv *wil);
408int wil_reset(struct wil6210_priv *wil); 460int wil_reset(struct wil6210_priv *wil);
461void wil_fw_error_recovery(struct wil6210_priv *wil);
409void wil_link_on(struct wil6210_priv *wil); 462void wil_link_on(struct wil6210_priv *wil);
410void wil_link_off(struct wil6210_priv *wil); 463void wil_link_off(struct wil6210_priv *wil);
411int wil_up(struct wil6210_priv *wil); 464int wil_up(struct wil6210_priv *wil);
@@ -439,6 +492,7 @@ int wmi_rxon(struct wil6210_priv *wil, bool on);
439int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_m, u32 *t_r); 492int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_m, u32 *t_r);
440int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, u16 reason); 493int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, u16 reason);
441 494
495void wil6210_clear_irq(struct wil6210_priv *wil);
442int wil6210_init_irq(struct wil6210_priv *wil, int irq); 496int wil6210_init_irq(struct wil6210_priv *wil, int irq);
443void wil6210_fini_irq(struct wil6210_priv *wil, int irq); 497void wil6210_fini_irq(struct wil6210_priv *wil, int irq);
444void wil6210_disable_irq(struct wil6210_priv *wil); 498void wil6210_disable_irq(struct wil6210_priv *wil);
diff --git a/drivers/net/wireless/ath/wil6210/wmi.c b/drivers/net/wireless/ath/wil6210/wmi.c
index 24eed0963581..2ba56eef0c45 100644
--- a/drivers/net/wireless/ath/wil6210/wmi.c
+++ b/drivers/net/wireless/ath/wil6210/wmi.c
@@ -462,7 +462,9 @@ static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
462 462
463 wil->sinfo_gen++; 463 wil->sinfo_gen++;
464 464
465 mutex_lock(&wil->mutex);
465 wil6210_disconnect(wil, evt->bssid); 466 wil6210_disconnect(wil, evt->bssid);
467 mutex_unlock(&wil->mutex);
466} 468}
467 469
468static void wmi_evt_notify(struct wil6210_priv *wil, int id, void *d, int len) 470static void wmi_evt_notify(struct wil6210_priv *wil, int id, void *d, int len)
@@ -550,9 +552,16 @@ static void wmi_evt_linkup(struct wil6210_priv *wil, int id, void *d, int len)
550{ 552{
551 struct net_device *ndev = wil_to_ndev(wil); 553 struct net_device *ndev = wil_to_ndev(wil);
552 struct wmi_data_port_open_event *evt = d; 554 struct wmi_data_port_open_event *evt = d;
555 u8 cid = evt->cid;
553 556
554 wil_dbg_wmi(wil, "Link UP for CID %d\n", evt->cid); 557 wil_dbg_wmi(wil, "Link UP for CID %d\n", cid);
555 558
559 if (cid >= ARRAY_SIZE(wil->sta)) {
560 wil_err(wil, "Link UP for invalid CID %d\n", cid);
561 return;
562 }
563
564 wil->sta[cid].data_port_open = true;
556 netif_carrier_on(ndev); 565 netif_carrier_on(ndev);
557} 566}
558 567
@@ -560,10 +569,17 @@ static void wmi_evt_linkdown(struct wil6210_priv *wil, int id, void *d, int len)
560{ 569{
561 struct net_device *ndev = wil_to_ndev(wil); 570 struct net_device *ndev = wil_to_ndev(wil);
562 struct wmi_wbe_link_down_event *evt = d; 571 struct wmi_wbe_link_down_event *evt = d;
572 u8 cid = evt->cid;
563 573
564 wil_dbg_wmi(wil, "Link DOWN for CID %d, reason %d\n", 574 wil_dbg_wmi(wil, "Link DOWN for CID %d, reason %d\n",
565 evt->cid, le32_to_cpu(evt->reason)); 575 cid, le32_to_cpu(evt->reason));
576
577 if (cid >= ARRAY_SIZE(wil->sta)) {
578 wil_err(wil, "Link DOWN for invalid CID %d\n", cid);
579 return;
580 }
566 581
582 wil->sta[cid].data_port_open = false;
567 netif_carrier_off(ndev); 583 netif_carrier_off(ndev);
568} 584}
569 585