ath9k: make rfkill configurable
[deliverable/linux.git] / drivers / net / wireless / ath / ath9k / htc_drv_txrx.c
CommitLineData
fb9987d0 1/*
5b68138e 2 * Copyright (c) 2010-2011 Atheros Communications Inc.
fb9987d0
S
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 "htc.h"
18
19/******/
20/* TX */
21/******/
22
066dae93 23static const int subtype_txq_to_hwq[] = {
bea843c7
SM
24 [IEEE80211_AC_BE] = ATH_TXQ_AC_BE,
25 [IEEE80211_AC_BK] = ATH_TXQ_AC_BK,
26 [IEEE80211_AC_VI] = ATH_TXQ_AC_VI,
27 [IEEE80211_AC_VO] = ATH_TXQ_AC_VO,
066dae93
FF
28};
29
ca74b83b 30#define ATH9K_HTC_INIT_TXQ(subtype) do { \
066dae93 31 qi.tqi_subtype = subtype_txq_to_hwq[subtype]; \
ca74b83b
S
32 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT; \
33 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT; \
34 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT; \
35 qi.tqi_physCompBuf = 0; \
36 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE | \
37 TXQ_FLAG_TXDESCINT_ENABLE; \
38 } while (0)
39
fb9987d0
S
40int get_hw_qnum(u16 queue, int *hwq_map)
41{
42 switch (queue) {
43 case 0:
bea843c7 44 return hwq_map[IEEE80211_AC_VO];
fb9987d0 45 case 1:
bea843c7 46 return hwq_map[IEEE80211_AC_VI];
fb9987d0 47 case 2:
bea843c7 48 return hwq_map[IEEE80211_AC_BE];
fb9987d0 49 case 3:
bea843c7 50 return hwq_map[IEEE80211_AC_BK];
fb9987d0 51 default:
bea843c7 52 return hwq_map[IEEE80211_AC_BE];
fb9987d0
S
53 }
54}
55
8e86a547
SM
56void ath9k_htc_check_stop_queues(struct ath9k_htc_priv *priv)
57{
58 spin_lock_bh(&priv->tx.tx_lock);
59 priv->tx.queued_cnt++;
60 if ((priv->tx.queued_cnt >= ATH9K_HTC_TX_THRESHOLD) &&
61 !(priv->tx.flags & ATH9K_HTC_OP_TX_QUEUES_STOP)) {
62 priv->tx.flags |= ATH9K_HTC_OP_TX_QUEUES_STOP;
63 ieee80211_stop_queues(priv->hw);
64 }
65 spin_unlock_bh(&priv->tx.tx_lock);
66}
67
68void ath9k_htc_check_wake_queues(struct ath9k_htc_priv *priv)
69{
70 spin_lock_bh(&priv->tx.tx_lock);
71 if ((priv->tx.queued_cnt < ATH9K_HTC_TX_THRESHOLD) &&
72 (priv->tx.flags & ATH9K_HTC_OP_TX_QUEUES_STOP)) {
73 priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
74 ieee80211_wake_queues(priv->hw);
75 }
76 spin_unlock_bh(&priv->tx.tx_lock);
77}
78
2c5d57f0
SM
79int ath9k_htc_tx_get_slot(struct ath9k_htc_priv *priv)
80{
81 int slot;
82
83 spin_lock_bh(&priv->tx.tx_lock);
84 slot = find_first_zero_bit(priv->tx.tx_slot, MAX_TX_BUF_NUM);
85 if (slot >= MAX_TX_BUF_NUM) {
86 spin_unlock_bh(&priv->tx.tx_lock);
87 return -ENOBUFS;
88 }
89 __set_bit(slot, priv->tx.tx_slot);
90 spin_unlock_bh(&priv->tx.tx_lock);
91
92 return slot;
93}
94
95void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv *priv, int slot)
96{
97 spin_lock_bh(&priv->tx.tx_lock);
98 __clear_bit(slot, priv->tx.tx_slot);
99 spin_unlock_bh(&priv->tx.tx_lock);
100}
101
27876a29
SM
102static inline enum htc_endpoint_id get_htc_epid(struct ath9k_htc_priv *priv,
103 u16 qnum)
d67ee533
SM
104{
105 enum htc_endpoint_id epid;
106
107 switch (qnum) {
108 case 0:
bea843c7 109 TX_QSTAT_INC(IEEE80211_AC_VO);
d67ee533
SM
110 epid = priv->data_vo_ep;
111 break;
112 case 1:
bea843c7 113 TX_QSTAT_INC(IEEE80211_AC_VI);
d67ee533
SM
114 epid = priv->data_vi_ep;
115 break;
116 case 2:
bea843c7 117 TX_QSTAT_INC(IEEE80211_AC_BE);
d67ee533
SM
118 epid = priv->data_be_ep;
119 break;
120 case 3:
121 default:
bea843c7 122 TX_QSTAT_INC(IEEE80211_AC_BK);
d67ee533
SM
123 epid = priv->data_bk_ep;
124 break;
125 }
126
127 return epid;
128}
129
27876a29
SM
130static inline struct sk_buff_head*
131get_htc_epid_queue(struct ath9k_htc_priv *priv, u8 epid)
132{
133 struct ath_common *common = ath9k_hw_common(priv->ah);
134 struct sk_buff_head *epid_queue = NULL;
135
136 if (epid == priv->mgmt_ep)
137 epid_queue = &priv->tx.mgmt_ep_queue;
138 else if (epid == priv->cab_ep)
139 epid_queue = &priv->tx.cab_ep_queue;
140 else if (epid == priv->data_be_ep)
141 epid_queue = &priv->tx.data_be_queue;
142 else if (epid == priv->data_bk_ep)
143 epid_queue = &priv->tx.data_bk_queue;
144 else if (epid == priv->data_vi_ep)
145 epid_queue = &priv->tx.data_vi_queue;
146 else if (epid == priv->data_vo_ep)
147 epid_queue = &priv->tx.data_vo_queue;
148 else
149 ath_err(common, "Invalid EPID: %d\n", epid);
150
151 return epid_queue;
152}
153
2c5d57f0
SM
154/*
155 * Removes the driver header and returns the TX slot number
156 */
729bd3ab
SM
157static inline int strip_drv_header(struct ath9k_htc_priv *priv,
158 struct sk_buff *skb)
159{
160 struct ath_common *common = ath9k_hw_common(priv->ah);
161 struct ath9k_htc_tx_ctl *tx_ctl;
2c5d57f0 162 int slot;
729bd3ab
SM
163
164 tx_ctl = HTC_SKB_CB(skb);
165
166 if (tx_ctl->epid == priv->mgmt_ep) {
2c5d57f0
SM
167 struct tx_mgmt_hdr *tx_mhdr =
168 (struct tx_mgmt_hdr *)skb->data;
169 slot = tx_mhdr->cookie;
729bd3ab
SM
170 skb_pull(skb, sizeof(struct tx_mgmt_hdr));
171 } else if ((tx_ctl->epid == priv->data_bk_ep) ||
172 (tx_ctl->epid == priv->data_be_ep) ||
173 (tx_ctl->epid == priv->data_vi_ep) ||
174 (tx_ctl->epid == priv->data_vo_ep) ||
175 (tx_ctl->epid == priv->cab_ep)) {
2c5d57f0
SM
176 struct tx_frame_hdr *tx_fhdr =
177 (struct tx_frame_hdr *)skb->data;
178 slot = tx_fhdr->cookie;
729bd3ab
SM
179 skb_pull(skb, sizeof(struct tx_frame_hdr));
180 } else {
181 ath_err(common, "Unsupported EPID: %d\n", tx_ctl->epid);
2c5d57f0 182 slot = -EINVAL;
729bd3ab
SM
183 }
184
2c5d57f0 185 return slot;
729bd3ab
SM
186}
187
e1572c5e
S
188int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
189 struct ath9k_tx_queue_info *qinfo)
fb9987d0
S
190{
191 struct ath_hw *ah = priv->ah;
192 int error = 0;
193 struct ath9k_tx_queue_info qi;
194
195 ath9k_hw_get_txq_props(ah, qnum, &qi);
196
197 qi.tqi_aifs = qinfo->tqi_aifs;
198 qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
199 qi.tqi_cwmax = qinfo->tqi_cwmax;
200 qi.tqi_burstTime = qinfo->tqi_burstTime;
201 qi.tqi_readyTime = qinfo->tqi_readyTime;
202
203 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
3800276a
JP
204 ath_err(ath9k_hw_common(ah),
205 "Unable to update hardware queue %u!\n", qnum);
fb9987d0
S
206 error = -EIO;
207 } else {
208 ath9k_hw_resettxqueue(ah, qnum);
209 }
210
211 return error;
212}
213
821f9414
SM
214static void ath9k_htc_tx_mgmt(struct ath9k_htc_priv *priv,
215 struct ath9k_htc_vif *avp,
216 struct sk_buff *skb,
217 u8 sta_idx, u8 vif_idx, u8 slot)
218{
219 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
220 struct ieee80211_mgmt *mgmt;
221 struct ieee80211_hdr *hdr;
222 struct tx_mgmt_hdr mgmt_hdr;
223 struct ath9k_htc_tx_ctl *tx_ctl;
224 u8 *tx_fhdr;
225
226 tx_ctl = HTC_SKB_CB(skb);
227 hdr = (struct ieee80211_hdr *) skb->data;
228
229 memset(tx_ctl, 0, sizeof(*tx_ctl));
230 memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
231
232 /*
233 * Set the TSF adjust value for probe response
234 * frame also.
235 */
236 if (avp && unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
237 mgmt = (struct ieee80211_mgmt *)skb->data;
238 mgmt->u.probe_resp.timestamp = avp->tsfadjust;
239 }
240
241 tx_ctl->type = ATH9K_HTC_MGMT;
242
243 mgmt_hdr.node_idx = sta_idx;
244 mgmt_hdr.vif_idx = vif_idx;
245 mgmt_hdr.tidno = 0;
246 mgmt_hdr.flags = 0;
247 mgmt_hdr.cookie = slot;
248
249 mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
250 if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
251 mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
252 else
253 mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
254
255 tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
256 memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
257 tx_ctl->epid = priv->mgmt_ep;
258}
259
260static void ath9k_htc_tx_data(struct ath9k_htc_priv *priv,
261 struct ieee80211_vif *vif,
262 struct sk_buff *skb,
263 u8 sta_idx, u8 vif_idx, u8 slot,
264 bool is_cab)
265{
266 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
267 struct ieee80211_hdr *hdr;
268 struct ath9k_htc_tx_ctl *tx_ctl;
269 struct tx_frame_hdr tx_hdr;
270 u32 flags = 0;
271 u8 *qc, *tx_fhdr;
272 u16 qnum;
273
274 tx_ctl = HTC_SKB_CB(skb);
275 hdr = (struct ieee80211_hdr *) skb->data;
276
277 memset(tx_ctl, 0, sizeof(*tx_ctl));
278 memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
279
280 tx_hdr.node_idx = sta_idx;
281 tx_hdr.vif_idx = vif_idx;
282 tx_hdr.cookie = slot;
283
284 /*
285 * This is a bit redundant but it helps to get
286 * the per-packet index quickly when draining the
287 * TX queue in the HIF layer. Otherwise we would
288 * have to parse the packet contents ...
289 */
290 tx_ctl->sta_idx = sta_idx;
291
292 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
293 tx_ctl->type = ATH9K_HTC_AMPDU;
294 tx_hdr.data_type = ATH9K_HTC_AMPDU;
295 } else {
296 tx_ctl->type = ATH9K_HTC_NORMAL;
297 tx_hdr.data_type = ATH9K_HTC_NORMAL;
298 }
299
300 if (ieee80211_is_data_qos(hdr->frame_control)) {
301 qc = ieee80211_get_qos_ctl(hdr);
302 tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
303 }
304
305 /* Check for RTS protection */
306 if (priv->hw->wiphy->rts_threshold != (u32) -1)
307 if (skb->len > priv->hw->wiphy->rts_threshold)
308 flags |= ATH9K_HTC_TX_RTSCTS;
309
310 /* CTS-to-self */
311 if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
312 (vif && vif->bss_conf.use_cts_prot))
313 flags |= ATH9K_HTC_TX_CTSONLY;
314
315 tx_hdr.flags = cpu_to_be32(flags);
316 tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
317 if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
318 tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
319 else
320 tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
321
322 tx_fhdr = skb_push(skb, sizeof(tx_hdr));
323 memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
324
325 if (is_cab) {
326 CAB_STAT_INC;
327 tx_ctl->epid = priv->cab_ep;
328 return;
329 }
330
331 qnum = skb_get_queue_mapping(skb);
332 tx_ctl->epid = get_htc_epid(priv, qnum);
333}
334
7d547eb4 335int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
36323f81 336 struct ieee80211_sta *sta,
2c5d57f0
SM
337 struct sk_buff *skb,
338 u8 slot, bool is_cab)
fb9987d0
S
339{
340 struct ieee80211_hdr *hdr;
341 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
a97b478c 342 struct ieee80211_vif *vif = tx_info->control.vif;
fb9987d0 343 struct ath9k_htc_sta *ista;
9b674a02 344 struct ath9k_htc_vif *avp = NULL;
da93f106 345 u8 sta_idx, vif_idx;
fb9987d0
S
346
347 hdr = (struct ieee80211_hdr *) skb->data;
fb9987d0 348
a97b478c
SM
349 /*
350 * Find out on which interface this packet has to be
351 * sent out.
352 */
353 if (vif) {
354 avp = (struct ath9k_htc_vif *) vif->drv_priv;
355 vif_idx = avp->index;
356 } else {
357 if (!priv->ah->is_monitoring) {
d2182b69 358 ath_dbg(ath9k_hw_common(priv->ah), XMIT,
a97b478c
SM
359 "VIF is null, but no monitor interface !\n");
360 return -EINVAL;
361 }
362
363 vif_idx = priv->mon_vif_idx;
364 }
da93f106 365
a97b478c
SM
366 /*
367 * Find out which station this packet is destined for.
368 */
fb9987d0
S
369 if (sta) {
370 ista = (struct ath9k_htc_sta *) sta->drv_priv;
371 sta_idx = ista->index;
372 } else {
a97b478c 373 sta_idx = priv->vif_sta_pos[vif_idx];
fb9987d0
S
374 }
375
821f9414
SM
376 if (ieee80211_is_data(hdr->frame_control))
377 ath9k_htc_tx_data(priv, vif, skb,
378 sta_idx, vif_idx, slot, is_cab);
379 else
380 ath9k_htc_tx_mgmt(priv, avp, skb,
381 sta_idx, vif_idx, slot);
fb9987d0 382
fb9987d0 383
d67ee533 384 return htc_send(priv->htc, skb);
fb9987d0
S
385}
386
f2820f45
SM
387static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
388 struct ath9k_htc_sta *ista, u8 tid)
d7ca2139
S
389{
390 bool ret = false;
391
658ef04f 392 spin_lock_bh(&priv->tx.tx_lock);
d7ca2139
S
393 if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
394 ret = true;
658ef04f 395 spin_unlock_bh(&priv->tx.tx_lock);
d7ca2139
S
396
397 return ret;
398}
399
f2820f45
SM
400static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
401 struct ieee80211_vif *vif,
402 struct sk_buff *skb)
fb9987d0 403{
fb9987d0
S
404 struct ieee80211_sta *sta;
405 struct ieee80211_hdr *hdr;
fb9987d0
S
406 __le16 fc;
407
f2820f45
SM
408 hdr = (struct ieee80211_hdr *) skb->data;
409 fc = hdr->frame_control;
fb9987d0 410
f2820f45 411 rcu_read_lock();
729bd3ab 412
f2820f45
SM
413 sta = ieee80211_find_sta(vif, hdr->addr1);
414 if (!sta) {
415 rcu_read_unlock();
416 return;
417 }
ef98c3cd 418
f2820f45
SM
419 if (sta && conf_is_ht(&priv->hw->conf) &&
420 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
421 if (ieee80211_is_data_qos(fc)) {
422 u8 *qc, tid;
423 struct ath9k_htc_sta *ista;
fb9987d0 424
f2820f45
SM
425 qc = ieee80211_get_qos_ctl(hdr);
426 tid = qc[0] & 0xf;
427 ista = (struct ath9k_htc_sta *)sta->drv_priv;
428 if (__ath9k_htc_check_tx_aggr(priv, ista, tid)) {
429 ieee80211_start_tx_ba_session(sta, tid, 0);
430 spin_lock_bh(&priv->tx.tx_lock);
431 ista->tid_state[tid] = AGGR_PROGRESS;
432 spin_unlock_bh(&priv->tx.tx_lock);
433 }
434 }
435 }
436
437 rcu_read_unlock();
438}
729bd3ab 439
f2820f45 440static void ath9k_htc_tx_process(struct ath9k_htc_priv *priv,
27876a29
SM
441 struct sk_buff *skb,
442 struct __wmi_event_txstatus *txs)
f2820f45
SM
443{
444 struct ieee80211_vif *vif;
445 struct ath9k_htc_tx_ctl *tx_ctl;
446 struct ieee80211_tx_info *tx_info;
27876a29
SM
447 struct ieee80211_tx_rate *rate;
448 struct ieee80211_conf *cur_conf = &priv->hw->conf;
f2820f45
SM
449 bool txok;
450 int slot;
729bd3ab 451
f2820f45
SM
452 slot = strip_drv_header(priv, skb);
453 if (slot < 0) {
454 dev_kfree_skb_any(skb);
455 return;
456 }
2299423b 457
f2820f45
SM
458 tx_ctl = HTC_SKB_CB(skb);
459 txok = tx_ctl->txok;
460 tx_info = IEEE80211_SKB_CB(skb);
461 vif = tx_info->control.vif;
27876a29 462 rate = &tx_info->status.rates[0];
fb9987d0 463
f2820f45 464 memset(&tx_info->status, 0, sizeof(tx_info->status));
ef98c3cd 465
f2820f45
SM
466 /*
467 * URB submission failed for this frame, it never reached
468 * the target.
469 */
27876a29 470 if (!txok || !vif || !txs)
f2820f45 471 goto send_mac80211;
ef98c3cd 472
27876a29
SM
473 if (txs->ts_flags & ATH9K_HTC_TXSTAT_ACK)
474 tx_info->flags |= IEEE80211_TX_STAT_ACK;
475
476 if (txs->ts_flags & ATH9K_HTC_TXSTAT_FILT)
477 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
478
479 if (txs->ts_flags & ATH9K_HTC_TXSTAT_RTC_CTS)
480 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
481
482 rate->count = 1;
483 rate->idx = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_RATE);
484
485 if (txs->ts_flags & ATH9K_HTC_TXSTAT_MCS) {
486 rate->flags |= IEEE80211_TX_RC_MCS;
487
488 if (txs->ts_flags & ATH9K_HTC_TXSTAT_CW40)
489 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
490 if (txs->ts_flags & ATH9K_HTC_TXSTAT_SGI)
491 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
492 } else {
675a0b04 493 if (cur_conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
27876a29
SM
494 rate->idx += 4; /* No CCK rates */
495 }
fb9987d0 496
f2820f45 497 ath9k_htc_check_tx_aggr(priv, vif, skb);
fb9987d0 498
f2820f45
SM
499send_mac80211:
500 spin_lock_bh(&priv->tx.tx_lock);
501 if (WARN_ON(--priv->tx.queued_cnt < 0))
502 priv->tx.queued_cnt = 0;
503 spin_unlock_bh(&priv->tx.tx_lock);
fb9987d0 504
f2820f45 505 ath9k_htc_tx_clear_slot(priv, slot);
fb9987d0 506
f2820f45
SM
507 /* Send status to mac80211 */
508 ieee80211_tx_status(priv->hw, skb);
509}
8e86a547 510
27876a29
SM
511static inline void ath9k_htc_tx_drainq(struct ath9k_htc_priv *priv,
512 struct sk_buff_head *queue)
513{
514 struct sk_buff *skb;
515
516 while ((skb = skb_dequeue(queue)) != NULL) {
517 ath9k_htc_tx_process(priv, skb, NULL);
518 }
519}
520
b587fc81
SM
521void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv)
522{
859c3ca1
SM
523 struct ath9k_htc_tx_event *event, *tmp;
524
27876a29
SM
525 spin_lock_bh(&priv->tx.tx_lock);
526 priv->tx.flags |= ATH9K_HTC_OP_TX_DRAIN;
527 spin_unlock_bh(&priv->tx.tx_lock);
b587fc81
SM
528
529 /*
530 * Ensure that all pending TX frames are flushed,
27876a29 531 * and that the TX completion/failed tasklets is killed.
b587fc81
SM
532 */
533 htc_stop(priv->htc);
27876a29
SM
534 tasklet_kill(&priv->wmi->wmi_event_tasklet);
535 tasklet_kill(&priv->tx_failed_tasklet);
b587fc81 536
27876a29
SM
537 ath9k_htc_tx_drainq(priv, &priv->tx.mgmt_ep_queue);
538 ath9k_htc_tx_drainq(priv, &priv->tx.cab_ep_queue);
539 ath9k_htc_tx_drainq(priv, &priv->tx.data_be_queue);
540 ath9k_htc_tx_drainq(priv, &priv->tx.data_bk_queue);
541 ath9k_htc_tx_drainq(priv, &priv->tx.data_vi_queue);
542 ath9k_htc_tx_drainq(priv, &priv->tx.data_vo_queue);
543 ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
b587fc81 544
859c3ca1
SM
545 /*
546 * The TX cleanup timer has already been killed.
547 */
548 spin_lock_bh(&priv->wmi->event_lock);
549 list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
550 list_del(&event->list);
551 kfree(event);
552 }
553 spin_unlock_bh(&priv->wmi->event_lock);
554
27876a29
SM
555 spin_lock_bh(&priv->tx.tx_lock);
556 priv->tx.flags &= ~ATH9K_HTC_OP_TX_DRAIN;
557 spin_unlock_bh(&priv->tx.tx_lock);
b587fc81
SM
558}
559
27876a29 560void ath9k_tx_failed_tasklet(unsigned long data)
f2820f45
SM
561{
562 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
2c5d57f0 563
27876a29
SM
564 spin_lock_bh(&priv->tx.tx_lock);
565 if (priv->tx.flags & ATH9K_HTC_OP_TX_DRAIN) {
566 spin_unlock_bh(&priv->tx.tx_lock);
567 return;
568 }
569 spin_unlock_bh(&priv->tx.tx_lock);
570
571 ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
572}
573
574static inline bool check_cookie(struct ath9k_htc_priv *priv,
575 struct sk_buff *skb,
576 u8 cookie, u8 epid)
577{
578 u8 fcookie = 0;
579
580 if (epid == priv->mgmt_ep) {
581 struct tx_mgmt_hdr *hdr;
582 hdr = (struct tx_mgmt_hdr *) skb->data;
583 fcookie = hdr->cookie;
584 } else if ((epid == priv->data_bk_ep) ||
585 (epid == priv->data_be_ep) ||
586 (epid == priv->data_vi_ep) ||
587 (epid == priv->data_vo_ep) ||
588 (epid == priv->cab_ep)) {
589 struct tx_frame_hdr *hdr;
590 hdr = (struct tx_frame_hdr *) skb->data;
591 fcookie = hdr->cookie;
592 }
593
594 if (fcookie == cookie)
595 return true;
596
597 return false;
598}
599
600static struct sk_buff* ath9k_htc_tx_get_packet(struct ath9k_htc_priv *priv,
601 struct __wmi_event_txstatus *txs)
602{
603 struct ath_common *common = ath9k_hw_common(priv->ah);
604 struct sk_buff_head *epid_queue;
605 struct sk_buff *skb, *tmp;
606 unsigned long flags;
607 u8 epid = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_EPID);
608
609 epid_queue = get_htc_epid_queue(priv, epid);
610 if (!epid_queue)
611 return NULL;
612
613 spin_lock_irqsave(&epid_queue->lock, flags);
614 skb_queue_walk_safe(epid_queue, skb, tmp) {
615 if (check_cookie(priv, skb, txs->cookie, epid)) {
616 __skb_unlink(skb, epid_queue);
617 spin_unlock_irqrestore(&epid_queue->lock, flags);
618 return skb;
619 }
fb9987d0 620 }
27876a29
SM
621 spin_unlock_irqrestore(&epid_queue->lock, flags);
622
d2182b69 623 ath_dbg(common, XMIT, "No matching packet for cookie: %d, epid: %d\n",
27876a29 624 txs->cookie, epid);
7757dfed 625
27876a29
SM
626 return NULL;
627}
628
629void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event)
630{
631 struct wmi_event_txstatus *txs = (struct wmi_event_txstatus *)wmi_event;
632 struct __wmi_event_txstatus *__txs;
633 struct sk_buff *skb;
859c3ca1 634 struct ath9k_htc_tx_event *tx_pend;
27876a29
SM
635 int i;
636
637 for (i = 0; i < txs->cnt; i++) {
638 WARN_ON(txs->cnt > HTC_MAX_TX_STATUS);
639
640 __txs = &txs->txstatus[i];
641
642 skb = ath9k_htc_tx_get_packet(priv, __txs);
859c3ca1
SM
643 if (!skb) {
644 /*
645 * Store this event, so that the TX cleanup
646 * routine can check later for the needed packet.
647 */
648 tx_pend = kzalloc(sizeof(struct ath9k_htc_tx_event),
649 GFP_ATOMIC);
650 if (!tx_pend)
651 continue;
652
653 memcpy(&tx_pend->txs, __txs,
654 sizeof(struct __wmi_event_txstatus));
655
656 spin_lock(&priv->wmi->event_lock);
657 list_add_tail(&tx_pend->list,
658 &priv->wmi->pending_tx_events);
659 spin_unlock(&priv->wmi->event_lock);
660
27876a29 661 continue;
859c3ca1 662 }
27876a29
SM
663
664 ath9k_htc_tx_process(priv, skb, __txs);
b587fc81
SM
665 }
666
7757dfed 667 /* Wake TX queues if needed */
8e86a547 668 ath9k_htc_check_wake_queues(priv);
fb9987d0
S
669}
670
671void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
672 enum htc_endpoint_id ep_id, bool txok)
673{
674 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
729bd3ab 675 struct ath9k_htc_tx_ctl *tx_ctl;
27876a29 676 struct sk_buff_head *epid_queue;
fb9987d0 677
729bd3ab
SM
678 tx_ctl = HTC_SKB_CB(skb);
679 tx_ctl->txok = txok;
859c3ca1 680 tx_ctl->timestamp = jiffies;
fb9987d0 681
27876a29 682 if (!txok) {
b587fc81 683 skb_queue_tail(&priv->tx.tx_failed, skb);
27876a29
SM
684 tasklet_schedule(&priv->tx_failed_tasklet);
685 return;
686 }
687
688 epid_queue = get_htc_epid_queue(priv, ep_id);
689 if (!epid_queue) {
690 dev_kfree_skb_any(skb);
691 return;
692 }
b587fc81 693
27876a29 694 skb_queue_tail(epid_queue, skb);
fb9987d0
S
695}
696
859c3ca1
SM
697static inline bool check_packet(struct ath9k_htc_priv *priv, struct sk_buff *skb)
698{
699 struct ath_common *common = ath9k_hw_common(priv->ah);
700 struct ath9k_htc_tx_ctl *tx_ctl;
701
702 tx_ctl = HTC_SKB_CB(skb);
703
704 if (time_after(jiffies,
705 tx_ctl->timestamp +
706 msecs_to_jiffies(ATH9K_HTC_TX_TIMEOUT_INTERVAL))) {
d2182b69 707 ath_dbg(common, XMIT, "Dropping a packet due to TX timeout\n");
859c3ca1
SM
708 return true;
709 }
710
711 return false;
712}
713
714static void ath9k_htc_tx_cleanup_queue(struct ath9k_htc_priv *priv,
715 struct sk_buff_head *epid_queue)
716{
717 bool process = false;
718 unsigned long flags;
719 struct sk_buff *skb, *tmp;
720 struct sk_buff_head queue;
721
722 skb_queue_head_init(&queue);
723
724 spin_lock_irqsave(&epid_queue->lock, flags);
725 skb_queue_walk_safe(epid_queue, skb, tmp) {
726 if (check_packet(priv, skb)) {
727 __skb_unlink(skb, epid_queue);
728 __skb_queue_tail(&queue, skb);
729 process = true;
730 }
731 }
732 spin_unlock_irqrestore(&epid_queue->lock, flags);
733
734 if (process) {
735 skb_queue_walk_safe(&queue, skb, tmp) {
736 __skb_unlink(skb, &queue);
737 ath9k_htc_tx_process(priv, skb, NULL);
738 }
739 }
740}
741
742void ath9k_htc_tx_cleanup_timer(unsigned long data)
743{
744 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) data;
745 struct ath_common *common = ath9k_hw_common(priv->ah);
746 struct ath9k_htc_tx_event *event, *tmp;
747 struct sk_buff *skb;
748
749 spin_lock(&priv->wmi->event_lock);
750 list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
751
752 skb = ath9k_htc_tx_get_packet(priv, &event->txs);
753 if (skb) {
d2182b69 754 ath_dbg(common, XMIT,
859c3ca1
SM
755 "Found packet for cookie: %d, epid: %d\n",
756 event->txs.cookie,
757 MS(event->txs.ts_rate, ATH9K_HTC_TXSTAT_EPID));
758
759 ath9k_htc_tx_process(priv, skb, &event->txs);
760 list_del(&event->list);
761 kfree(event);
762 continue;
763 }
764
765 if (++event->count >= ATH9K_HTC_TX_TIMEOUT_COUNT) {
766 list_del(&event->list);
767 kfree(event);
768 }
769 }
770 spin_unlock(&priv->wmi->event_lock);
771
772 /*
773 * Check if status-pending packets have to be cleaned up.
774 */
775 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.mgmt_ep_queue);
776 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.cab_ep_queue);
777 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_be_queue);
778 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_bk_queue);
779 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vi_queue);
780 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vo_queue);
781
782 /* Wake TX queues if needed */
783 ath9k_htc_check_wake_queues(priv);
784
785 mod_timer(&priv->tx.cleanup_timer,
786 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
787}
788
fb9987d0
S
789int ath9k_tx_init(struct ath9k_htc_priv *priv)
790{
27876a29
SM
791 skb_queue_head_init(&priv->tx.mgmt_ep_queue);
792 skb_queue_head_init(&priv->tx.cab_ep_queue);
793 skb_queue_head_init(&priv->tx.data_be_queue);
794 skb_queue_head_init(&priv->tx.data_bk_queue);
795 skb_queue_head_init(&priv->tx.data_vi_queue);
796 skb_queue_head_init(&priv->tx.data_vo_queue);
b587fc81 797 skb_queue_head_init(&priv->tx.tx_failed);
fb9987d0
S
798 return 0;
799}
800
801void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
802{
803
804}
805
e8c35a77 806bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
fb9987d0
S
807{
808 struct ath_hw *ah = priv->ah;
809 struct ath_common *common = ath9k_hw_common(ah);
810 struct ath9k_tx_queue_info qi;
811 int qnum;
812
813 memset(&qi, 0, sizeof(qi));
ca74b83b 814 ATH9K_HTC_INIT_TXQ(subtype);
fb9987d0
S
815
816 qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
817 if (qnum == -1)
818 return false;
819
820 if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
3800276a
JP
821 ath_err(common, "qnum %u out of range, max %zu!\n",
822 qnum, ARRAY_SIZE(priv->hwq_map));
fb9987d0
S
823 ath9k_hw_releasetxqueue(ah, qnum);
824 return false;
825 }
826
827 priv->hwq_map[subtype] = qnum;
828 return true;
829}
830
ca74b83b
S
831int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
832{
833 struct ath9k_tx_queue_info qi;
834
835 memset(&qi, 0, sizeof(qi));
836 ATH9K_HTC_INIT_TXQ(0);
837
838 return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
839}
840
fb9987d0
S
841/******/
842/* RX */
843/******/
844
0995d110
S
845/*
846 * Calculate the RX filter to be set in the HW.
847 */
848u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
849{
850#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
851
852 struct ath_hw *ah = priv->ah;
853 u32 rfilt;
854
855 rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
856 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
857 | ATH9K_RX_FILTER_MCAST;
858
94a40c0c 859 if (priv->rxfilter & FIF_PROBE_REQ)
0995d110
S
860 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
861
862 /*
863 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
864 * mode interface or when in monitor mode. AP mode does not need this
865 * since it receives all in-BSS frames anyway.
866 */
867 if (((ah->opmode != NL80211_IFTYPE_AP) &&
868 (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
4825f54a 869 ah->is_monitoring)
0995d110
S
870 rfilt |= ATH9K_RX_FILTER_PROM;
871
872 if (priv->rxfilter & FIF_CONTROL)
873 rfilt |= ATH9K_RX_FILTER_CONTROL;
874
875 if ((ah->opmode == NL80211_IFTYPE_STATION) &&
33a5315f 876 (priv->nvifs <= 1) &&
0995d110
S
877 !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
878 rfilt |= ATH9K_RX_FILTER_MYBEACON;
879 else
880 rfilt |= ATH9K_RX_FILTER_BEACON;
881
4825f54a 882 if (conf_is_ht(&priv->hw->conf)) {
0995d110 883 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
4825f54a
SM
884 rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
885 }
886
887 if (priv->rxfilter & FIF_PSPOLL)
888 rfilt |= ATH9K_RX_FILTER_PSPOLL;
0995d110 889
594e65b6 890 if (priv->nvifs > 1 || priv->rxfilter & FIF_OTHER_BSS)
33a5315f
SM
891 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
892
0995d110
S
893 return rfilt;
894
895#undef RX_FILTER_PRESERVE
896}
897
898/*
899 * Recv initialization for opmode change.
900 */
901static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
902{
903 struct ath_hw *ah = priv->ah;
0995d110
S
904 u32 rfilt, mfilt[2];
905
906 /* configure rx filter */
907 rfilt = ath9k_htc_calcrxfilter(priv);
908 ath9k_hw_setrxfilter(ah, rfilt);
909
0995d110
S
910 /* calculate and install multicast filter */
911 mfilt[0] = mfilt[1] = ~0;
912 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
913}
914
fb9987d0
S
915void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
916{
917 ath9k_hw_rxena(priv->ah);
0995d110 918 ath9k_htc_opmode_init(priv);
d8a2c51c 919 ath9k_hw_startpcureceive(priv->ah, test_bit(OP_SCANNING, &priv->op_flags));
fb9987d0
S
920 priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
921}
922
923static void ath9k_process_rate(struct ieee80211_hw *hw,
924 struct ieee80211_rx_status *rxs,
925 u8 rx_rate, u8 rs_flags)
926{
927 struct ieee80211_supported_band *sband;
928 enum ieee80211_band band;
929 unsigned int i = 0;
930
931 if (rx_rate & 0x80) {
932 /* HT rate */
933 rxs->flag |= RX_FLAG_HT;
934 if (rs_flags & ATH9K_RX_2040)
935 rxs->flag |= RX_FLAG_40MHZ;
936 if (rs_flags & ATH9K_RX_GI)
937 rxs->flag |= RX_FLAG_SHORT_GI;
938 rxs->rate_idx = rx_rate & 0x7f;
939 return;
940 }
941
675a0b04 942 band = hw->conf.chandef.chan->band;
fb9987d0
S
943 sband = hw->wiphy->bands[band];
944
945 for (i = 0; i < sband->n_bitrates; i++) {
946 if (sband->bitrates[i].hw_value == rx_rate) {
947 rxs->rate_idx = i;
948 return;
949 }
950 if (sband->bitrates[i].hw_value_short == rx_rate) {
951 rxs->rate_idx = i;
952 rxs->flag |= RX_FLAG_SHORTPRE;
953 return;
954 }
955 }
956
957}
958
959static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
960 struct ath9k_htc_rxbuf *rxbuf,
961 struct ieee80211_rx_status *rx_status)
962
963{
964 struct ieee80211_hdr *hdr;
965 struct ieee80211_hw *hw = priv->hw;
966 struct sk_buff *skb = rxbuf->skb;
967 struct ath_common *common = ath9k_hw_common(priv->ah);
4f824719 968 struct ath_htc_rx_status *rxstatus;
c60c9929 969 int hdrlen, padsize;
fb9987d0
S
970 int last_rssi = ATH_RSSI_DUMMY_MARKER;
971 __le16 fc;
972
b1563a4c
SM
973 if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
974 ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
975 skb->len);
4f824719
S
976 goto rx_next;
977 }
978
979 rxstatus = (struct ath_htc_rx_status *)skb->data;
980
981 if (be16_to_cpu(rxstatus->rs_datalen) -
982 (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
3800276a
JP
983 ath_err(common,
984 "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
985 rxstatus->rs_datalen, skb->len);
4f824719
S
986 goto rx_next;
987 }
988
719c4cf6
SM
989 ath9k_htc_err_stat_rx(priv, rxstatus);
990
4f824719
S
991 /* Get the RX status information */
992 memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
993 skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
994
fb9987d0
S
995 hdr = (struct ieee80211_hdr *)skb->data;
996 fc = hdr->frame_control;
997 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
998
c60c9929
FF
999 padsize = hdrlen & 3;
1000 if (padsize && skb->len >= hdrlen+padsize+FCS_LEN) {
1001 memmove(skb->data + padsize, skb->data, hdrlen);
fb9987d0
S
1002 skb_pull(skb, padsize);
1003 }
1004
1005 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
1006
1007 if (rxbuf->rxstatus.rs_status != 0) {
1008 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
1009 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
1010 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
1011 goto rx_next;
1012
1013 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
1014 /* FIXME */
1015 } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
1016 if (ieee80211_is_ctl(fc))
1017 /*
1018 * Sometimes, we get invalid
1019 * MIC failures on valid control frames.
1020 * Remove these mic errors.
1021 */
1022 rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
1023 else
1024 rx_status->flag |= RX_FLAG_MMIC_ERROR;
1025 }
1026
1027 /*
1028 * Reject error frames with the exception of
1029 * decryption and MIC failures. For monitor mode,
1030 * we also ignore the CRC error.
1031 */
1032 if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
1033 if (rxbuf->rxstatus.rs_status &
1034 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
1035 ATH9K_RXERR_CRC))
1036 goto rx_next;
1037 } else {
1038 if (rxbuf->rxstatus.rs_status &
1039 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
1040 goto rx_next;
1041 }
1042 }
1043 }
1044
1045 if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
1046 u8 keyix;
1047 keyix = rxbuf->rxstatus.rs_keyix;
1048 if (keyix != ATH9K_RXKEYIX_INVALID) {
1049 rx_status->flag |= RX_FLAG_DECRYPTED;
1050 } else if (ieee80211_has_protected(fc) &&
1051 skb->len >= hdrlen + 4) {
1052 keyix = skb->data[hdrlen + 3] >> 6;
1053 if (test_bit(keyix, common->keymap))
1054 rx_status->flag |= RX_FLAG_DECRYPTED;
1055 }
1056 }
1057
1058 ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
1059 rxbuf->rxstatus.rs_flags);
1060
7c277349
SM
1061 if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
1062 !rxbuf->rxstatus.rs_moreaggr)
1063 ATH_RSSI_LPF(priv->rx.last_rssi,
1064 rxbuf->rxstatus.rs_rssi);
fb9987d0 1065
7c277349 1066 last_rssi = priv->rx.last_rssi;
fb9987d0 1067
838f4279
FF
1068 if (ieee80211_is_beacon(hdr->frame_control) &&
1069 !is_zero_ether_addr(common->curbssid) &&
1070 ether_addr_equal(hdr->addr3, common->curbssid)) {
1071 s8 rssi = rxbuf->rxstatus.rs_rssi;
fb9987d0 1072
838f4279
FF
1073 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
1074 rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
fb9987d0 1075
838f4279
FF
1076 if (rssi < 0)
1077 rssi = 0;
1078
1079 priv->ah->stats.avgbrssi = rssi;
1080 }
fb9987d0 1081
7f1f5a00 1082 rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
675a0b04
KB
1083 rx_status->band = hw->conf.chandef.chan->band;
1084 rx_status->freq = hw->conf.chandef.chan->center_freq;
fb9987d0
S
1085 rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
1086 rx_status->antenna = rxbuf->rxstatus.rs_antenna;
75d7dbc2 1087 rx_status->flag |= RX_FLAG_MACTIME_END;
fb9987d0
S
1088
1089 return true;
1090
1091rx_next:
1092 return false;
1093}
1094
1095/*
1096 * FIXME: Handle FLUSH later on.
1097 */
1098void ath9k_rx_tasklet(unsigned long data)
1099{
1100 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1101 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
1102 struct ieee80211_rx_status rx_status;
1103 struct sk_buff *skb;
1104 unsigned long flags;
bde748a4 1105 struct ieee80211_hdr *hdr;
fb9987d0
S
1106
1107 do {
1108 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
1109 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
1110 if (tmp_buf->in_process) {
1111 rxbuf = tmp_buf;
1112 break;
1113 }
1114 }
1115
1116 if (rxbuf == NULL) {
1117 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
1118 break;
1119 }
1120
1121 if (!rxbuf->skb)
1122 goto requeue;
1123
1124 if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
1125 dev_kfree_skb_any(rxbuf->skb);
1126 goto requeue;
1127 }
1128
1129 memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
1130 sizeof(struct ieee80211_rx_status));
1131 skb = rxbuf->skb;
bde748a4
VN
1132 hdr = (struct ieee80211_hdr *) skb->data;
1133
1134 if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
1135 ieee80211_queue_work(priv->hw, &priv->ps_work);
1136
fb9987d0
S
1137 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
1138
1139 ieee80211_rx(priv->hw, skb);
1140
1141 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
1142requeue:
1143 rxbuf->in_process = false;
1144 rxbuf->skb = NULL;
1145 list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
1146 rxbuf = NULL;
1147 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
1148 } while (1);
1149
1150}
1151
1152void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
1153 enum htc_endpoint_id ep_id)
1154{
1155 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
1156 struct ath_hw *ah = priv->ah;
1157 struct ath_common *common = ath9k_hw_common(ah);
1158 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
fb9987d0
S
1159
1160 spin_lock(&priv->rx.rxbuflock);
1161 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
1162 if (!tmp_buf->in_process) {
1163 rxbuf = tmp_buf;
1164 break;
1165 }
1166 }
1167 spin_unlock(&priv->rx.rxbuflock);
1168
1169 if (rxbuf == NULL) {
d2182b69 1170 ath_dbg(common, ANY, "No free RX buffer\n");
fb9987d0
S
1171 goto err;
1172 }
1173
fb9987d0 1174 spin_lock(&priv->rx.rxbuflock);
fb9987d0
S
1175 rxbuf->skb = skb;
1176 rxbuf->in_process = true;
1177 spin_unlock(&priv->rx.rxbuflock);
1178
1179 tasklet_schedule(&priv->rx_tasklet);
1180 return;
1181err:
1182 dev_kfree_skb_any(skb);
fb9987d0
S
1183}
1184
1185/* FIXME: Locking for cleanup/init */
1186
1187void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
1188{
1189 struct ath9k_htc_rxbuf *rxbuf, *tbuf;
1190
1191 list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
1192 list_del(&rxbuf->list);
1193 if (rxbuf->skb)
1194 dev_kfree_skb_any(rxbuf->skb);
1195 kfree(rxbuf);
1196 }
1197}
1198
1199int ath9k_rx_init(struct ath9k_htc_priv *priv)
1200{
fb9987d0
S
1201 int i = 0;
1202
1203 INIT_LIST_HEAD(&priv->rx.rxbuf);
1204 spin_lock_init(&priv->rx.rxbuflock);
1205
1206 for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
14f8dc49
JP
1207 struct ath9k_htc_rxbuf *rxbuf =
1208 kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
1209 if (rxbuf == NULL)
fb9987d0 1210 goto err;
14f8dc49 1211
fb9987d0
S
1212 list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
1213 }
1214
1215 return 0;
1216
1217err:
1218 ath9k_rx_cleanup(priv);
1219 return -ENOMEM;
1220}
This page took 0.636072 seconds and 5 git commands to generate.