]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
723a3a9c5cd91426262ee1770149a40a85981c64
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / ath / ath9k / htc_drv_txrx.c
1 /*
2 * Copyright (c) 2010 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 "htc.h"
18
19 /******/
20 /* TX */
21 /******/
22
23 static const int subtype_txq_to_hwq[] = {
24 [WME_AC_BE] = ATH_TXQ_AC_BE,
25 [WME_AC_BK] = ATH_TXQ_AC_BK,
26 [WME_AC_VI] = ATH_TXQ_AC_VI,
27 [WME_AC_VO] = ATH_TXQ_AC_VO,
28 };
29
30 #define ATH9K_HTC_INIT_TXQ(subtype) do { \
31 qi.tqi_subtype = subtype_txq_to_hwq[subtype]; \
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
40 int get_hw_qnum(u16 queue, int *hwq_map)
41 {
42 switch (queue) {
43 case 0:
44 return hwq_map[WME_AC_VO];
45 case 1:
46 return hwq_map[WME_AC_VI];
47 case 2:
48 return hwq_map[WME_AC_BE];
49 case 3:
50 return hwq_map[WME_AC_BK];
51 default:
52 return hwq_map[WME_AC_BE];
53 }
54 }
55
56 void 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
68 void 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
79 int 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
95 void 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
102 static inline enum htc_endpoint_id get_htc_epid(struct ath9k_htc_priv *priv,
103 u16 qnum)
104 {
105 enum htc_endpoint_id epid;
106
107 switch (qnum) {
108 case 0:
109 TX_QSTAT_INC(WME_AC_VO);
110 epid = priv->data_vo_ep;
111 break;
112 case 1:
113 TX_QSTAT_INC(WME_AC_VI);
114 epid = priv->data_vi_ep;
115 break;
116 case 2:
117 TX_QSTAT_INC(WME_AC_BE);
118 epid = priv->data_be_ep;
119 break;
120 case 3:
121 default:
122 TX_QSTAT_INC(WME_AC_BK);
123 epid = priv->data_bk_ep;
124 break;
125 }
126
127 return epid;
128 }
129
130 static inline struct sk_buff_head*
131 get_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
154 /*
155 * Removes the driver header and returns the TX slot number
156 */
157 static 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;
162 int slot;
163
164 tx_ctl = HTC_SKB_CB(skb);
165
166 if (tx_ctl->epid == priv->mgmt_ep) {
167 struct tx_mgmt_hdr *tx_mhdr =
168 (struct tx_mgmt_hdr *)skb->data;
169 slot = tx_mhdr->cookie;
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)) {
176 struct tx_frame_hdr *tx_fhdr =
177 (struct tx_frame_hdr *)skb->data;
178 slot = tx_fhdr->cookie;
179 skb_pull(skb, sizeof(struct tx_frame_hdr));
180 } else {
181 ath_err(common, "Unsupported EPID: %d\n", tx_ctl->epid);
182 slot = -EINVAL;
183 }
184
185 return slot;
186 }
187
188 int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
189 struct ath9k_tx_queue_info *qinfo)
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)) {
204 ath_err(ath9k_hw_common(ah),
205 "Unable to update hardware queue %u!\n", qnum);
206 error = -EIO;
207 } else {
208 ath9k_hw_resettxqueue(ah, qnum);
209 }
210
211 return error;
212 }
213
214 static 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
260 static 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
335 int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
336 struct sk_buff *skb,
337 u8 slot, bool is_cab)
338 {
339 struct ieee80211_hdr *hdr;
340 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
341 struct ieee80211_sta *sta = tx_info->control.sta;
342 struct ieee80211_vif *vif = tx_info->control.vif;
343 struct ath9k_htc_sta *ista;
344 struct ath9k_htc_vif *avp = NULL;
345 u8 sta_idx, vif_idx;
346
347 hdr = (struct ieee80211_hdr *) skb->data;
348
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) {
358 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
359 "VIF is null, but no monitor interface !\n");
360 return -EINVAL;
361 }
362
363 vif_idx = priv->mon_vif_idx;
364 }
365
366 /*
367 * Find out which station this packet is destined for.
368 */
369 if (sta) {
370 ista = (struct ath9k_htc_sta *) sta->drv_priv;
371 sta_idx = ista->index;
372 } else {
373 sta_idx = priv->vif_sta_pos[vif_idx];
374 }
375
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);
382
383
384 return htc_send(priv->htc, skb);
385 }
386
387 static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
388 struct ath9k_htc_sta *ista, u8 tid)
389 {
390 bool ret = false;
391
392 spin_lock_bh(&priv->tx.tx_lock);
393 if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
394 ret = true;
395 spin_unlock_bh(&priv->tx.tx_lock);
396
397 return ret;
398 }
399
400 static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
401 struct ieee80211_vif *vif,
402 struct sk_buff *skb)
403 {
404 struct ieee80211_sta *sta;
405 struct ieee80211_hdr *hdr;
406 __le16 fc;
407
408 hdr = (struct ieee80211_hdr *) skb->data;
409 fc = hdr->frame_control;
410
411 rcu_read_lock();
412
413 sta = ieee80211_find_sta(vif, hdr->addr1);
414 if (!sta) {
415 rcu_read_unlock();
416 return;
417 }
418
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;
424
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 }
439
440 static void ath9k_htc_tx_process(struct ath9k_htc_priv *priv,
441 struct sk_buff *skb,
442 struct __wmi_event_txstatus *txs)
443 {
444 struct ieee80211_vif *vif;
445 struct ath9k_htc_tx_ctl *tx_ctl;
446 struct ieee80211_tx_info *tx_info;
447 struct ieee80211_tx_rate *rate;
448 struct ieee80211_conf *cur_conf = &priv->hw->conf;
449 struct ieee80211_supported_band *sband;
450 bool txok;
451 int slot;
452
453 slot = strip_drv_header(priv, skb);
454 if (slot < 0) {
455 dev_kfree_skb_any(skb);
456 return;
457 }
458
459 tx_ctl = HTC_SKB_CB(skb);
460 txok = tx_ctl->txok;
461 tx_info = IEEE80211_SKB_CB(skb);
462 vif = tx_info->control.vif;
463 rate = &tx_info->status.rates[0];
464 sband = priv->hw->wiphy->bands[cur_conf->channel->band];
465
466 memset(&tx_info->status, 0, sizeof(tx_info->status));
467
468 /*
469 * URB submission failed for this frame, it never reached
470 * the target.
471 */
472 if (!txok || !vif || !txs)
473 goto send_mac80211;
474
475 if (txs->ts_flags & ATH9K_HTC_TXSTAT_ACK)
476 tx_info->flags |= IEEE80211_TX_STAT_ACK;
477
478 if (txs->ts_flags & ATH9K_HTC_TXSTAT_FILT)
479 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
480
481 if (txs->ts_flags & ATH9K_HTC_TXSTAT_RTC_CTS)
482 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
483
484 rate->count = 1;
485 rate->idx = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_RATE);
486
487 if (txs->ts_flags & ATH9K_HTC_TXSTAT_MCS) {
488 rate->flags |= IEEE80211_TX_RC_MCS;
489
490 if (txs->ts_flags & ATH9K_HTC_TXSTAT_CW40)
491 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
492 if (txs->ts_flags & ATH9K_HTC_TXSTAT_SGI)
493 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
494 } else {
495 if (cur_conf->channel->band == IEEE80211_BAND_5GHZ)
496 rate->idx += 4; /* No CCK rates */
497 }
498
499 ath9k_htc_check_tx_aggr(priv, vif, skb);
500
501 send_mac80211:
502 spin_lock_bh(&priv->tx.tx_lock);
503 if (WARN_ON(--priv->tx.queued_cnt < 0))
504 priv->tx.queued_cnt = 0;
505 spin_unlock_bh(&priv->tx.tx_lock);
506
507 ath9k_htc_tx_clear_slot(priv, slot);
508
509 /* Send status to mac80211 */
510 ieee80211_tx_status(priv->hw, skb);
511 }
512
513 static inline void ath9k_htc_tx_drainq(struct ath9k_htc_priv *priv,
514 struct sk_buff_head *queue)
515 {
516 struct sk_buff *skb;
517
518 while ((skb = skb_dequeue(queue)) != NULL) {
519 ath9k_htc_tx_process(priv, skb, NULL);
520 }
521 }
522
523 void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv)
524 {
525 struct ath9k_htc_tx_event *event, *tmp;
526
527 spin_lock_bh(&priv->tx.tx_lock);
528 priv->tx.flags |= ATH9K_HTC_OP_TX_DRAIN;
529 spin_unlock_bh(&priv->tx.tx_lock);
530
531 /*
532 * Ensure that all pending TX frames are flushed,
533 * and that the TX completion/failed tasklets is killed.
534 */
535 htc_stop(priv->htc);
536 tasklet_kill(&priv->wmi->wmi_event_tasklet);
537 tasklet_kill(&priv->tx_failed_tasklet);
538
539 ath9k_htc_tx_drainq(priv, &priv->tx.mgmt_ep_queue);
540 ath9k_htc_tx_drainq(priv, &priv->tx.cab_ep_queue);
541 ath9k_htc_tx_drainq(priv, &priv->tx.data_be_queue);
542 ath9k_htc_tx_drainq(priv, &priv->tx.data_bk_queue);
543 ath9k_htc_tx_drainq(priv, &priv->tx.data_vi_queue);
544 ath9k_htc_tx_drainq(priv, &priv->tx.data_vo_queue);
545 ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
546
547 /*
548 * The TX cleanup timer has already been killed.
549 */
550 spin_lock_bh(&priv->wmi->event_lock);
551 list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
552 list_del(&event->list);
553 kfree(event);
554 }
555 spin_unlock_bh(&priv->wmi->event_lock);
556
557 spin_lock_bh(&priv->tx.tx_lock);
558 priv->tx.flags &= ~ATH9K_HTC_OP_TX_DRAIN;
559 spin_unlock_bh(&priv->tx.tx_lock);
560 }
561
562 void ath9k_tx_failed_tasklet(unsigned long data)
563 {
564 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
565
566 spin_lock_bh(&priv->tx.tx_lock);
567 if (priv->tx.flags & ATH9K_HTC_OP_TX_DRAIN) {
568 spin_unlock_bh(&priv->tx.tx_lock);
569 return;
570 }
571 spin_unlock_bh(&priv->tx.tx_lock);
572
573 ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
574 }
575
576 static inline bool check_cookie(struct ath9k_htc_priv *priv,
577 struct sk_buff *skb,
578 u8 cookie, u8 epid)
579 {
580 u8 fcookie = 0;
581
582 if (epid == priv->mgmt_ep) {
583 struct tx_mgmt_hdr *hdr;
584 hdr = (struct tx_mgmt_hdr *) skb->data;
585 fcookie = hdr->cookie;
586 } else if ((epid == priv->data_bk_ep) ||
587 (epid == priv->data_be_ep) ||
588 (epid == priv->data_vi_ep) ||
589 (epid == priv->data_vo_ep) ||
590 (epid == priv->cab_ep)) {
591 struct tx_frame_hdr *hdr;
592 hdr = (struct tx_frame_hdr *) skb->data;
593 fcookie = hdr->cookie;
594 }
595
596 if (fcookie == cookie)
597 return true;
598
599 return false;
600 }
601
602 static struct sk_buff* ath9k_htc_tx_get_packet(struct ath9k_htc_priv *priv,
603 struct __wmi_event_txstatus *txs)
604 {
605 struct ath_common *common = ath9k_hw_common(priv->ah);
606 struct sk_buff_head *epid_queue;
607 struct sk_buff *skb, *tmp;
608 unsigned long flags;
609 u8 epid = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_EPID);
610
611 epid_queue = get_htc_epid_queue(priv, epid);
612 if (!epid_queue)
613 return NULL;
614
615 spin_lock_irqsave(&epid_queue->lock, flags);
616 skb_queue_walk_safe(epid_queue, skb, tmp) {
617 if (check_cookie(priv, skb, txs->cookie, epid)) {
618 __skb_unlink(skb, epid_queue);
619 spin_unlock_irqrestore(&epid_queue->lock, flags);
620 return skb;
621 }
622 }
623 spin_unlock_irqrestore(&epid_queue->lock, flags);
624
625 ath_dbg(common, ATH_DBG_XMIT,
626 "No matching packet for cookie: %d, epid: %d\n",
627 txs->cookie, epid);
628
629 return NULL;
630 }
631
632 void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event)
633 {
634 struct wmi_event_txstatus *txs = (struct wmi_event_txstatus *)wmi_event;
635 struct __wmi_event_txstatus *__txs;
636 struct sk_buff *skb;
637 struct ath9k_htc_tx_event *tx_pend;
638 int i;
639
640 for (i = 0; i < txs->cnt; i++) {
641 WARN_ON(txs->cnt > HTC_MAX_TX_STATUS);
642
643 __txs = &txs->txstatus[i];
644
645 skb = ath9k_htc_tx_get_packet(priv, __txs);
646 if (!skb) {
647 /*
648 * Store this event, so that the TX cleanup
649 * routine can check later for the needed packet.
650 */
651 tx_pend = kzalloc(sizeof(struct ath9k_htc_tx_event),
652 GFP_ATOMIC);
653 if (!tx_pend)
654 continue;
655
656 memcpy(&tx_pend->txs, __txs,
657 sizeof(struct __wmi_event_txstatus));
658
659 spin_lock(&priv->wmi->event_lock);
660 list_add_tail(&tx_pend->list,
661 &priv->wmi->pending_tx_events);
662 spin_unlock(&priv->wmi->event_lock);
663
664 continue;
665 }
666
667 ath9k_htc_tx_process(priv, skb, __txs);
668 }
669
670 /* Wake TX queues if needed */
671 ath9k_htc_check_wake_queues(priv);
672 }
673
674 void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
675 enum htc_endpoint_id ep_id, bool txok)
676 {
677 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
678 struct ath9k_htc_tx_ctl *tx_ctl;
679 struct sk_buff_head *epid_queue;
680
681 tx_ctl = HTC_SKB_CB(skb);
682 tx_ctl->txok = txok;
683 tx_ctl->timestamp = jiffies;
684
685 if (!txok) {
686 skb_queue_tail(&priv->tx.tx_failed, skb);
687 tasklet_schedule(&priv->tx_failed_tasklet);
688 return;
689 }
690
691 epid_queue = get_htc_epid_queue(priv, ep_id);
692 if (!epid_queue) {
693 dev_kfree_skb_any(skb);
694 return;
695 }
696
697 skb_queue_tail(epid_queue, skb);
698 }
699
700 static inline bool check_packet(struct ath9k_htc_priv *priv, struct sk_buff *skb)
701 {
702 struct ath_common *common = ath9k_hw_common(priv->ah);
703 struct ath9k_htc_tx_ctl *tx_ctl;
704
705 tx_ctl = HTC_SKB_CB(skb);
706
707 if (time_after(jiffies,
708 tx_ctl->timestamp +
709 msecs_to_jiffies(ATH9K_HTC_TX_TIMEOUT_INTERVAL))) {
710 ath_dbg(common, ATH_DBG_XMIT,
711 "Dropping a packet due to TX timeout\n");
712 return true;
713 }
714
715 return false;
716 }
717
718 static void ath9k_htc_tx_cleanup_queue(struct ath9k_htc_priv *priv,
719 struct sk_buff_head *epid_queue)
720 {
721 bool process = false;
722 unsigned long flags;
723 struct sk_buff *skb, *tmp;
724 struct sk_buff_head queue;
725
726 skb_queue_head_init(&queue);
727
728 spin_lock_irqsave(&epid_queue->lock, flags);
729 skb_queue_walk_safe(epid_queue, skb, tmp) {
730 if (check_packet(priv, skb)) {
731 __skb_unlink(skb, epid_queue);
732 __skb_queue_tail(&queue, skb);
733 process = true;
734 }
735 }
736 spin_unlock_irqrestore(&epid_queue->lock, flags);
737
738 if (process) {
739 skb_queue_walk_safe(&queue, skb, tmp) {
740 __skb_unlink(skb, &queue);
741 ath9k_htc_tx_process(priv, skb, NULL);
742 }
743 }
744 }
745
746 void ath9k_htc_tx_cleanup_timer(unsigned long data)
747 {
748 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) data;
749 struct ath_common *common = ath9k_hw_common(priv->ah);
750 struct ath9k_htc_tx_event *event, *tmp;
751 struct sk_buff *skb;
752
753 spin_lock(&priv->wmi->event_lock);
754 list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
755
756 skb = ath9k_htc_tx_get_packet(priv, &event->txs);
757 if (skb) {
758 ath_dbg(common, ATH_DBG_XMIT,
759 "Found packet for cookie: %d, epid: %d\n",
760 event->txs.cookie,
761 MS(event->txs.ts_rate, ATH9K_HTC_TXSTAT_EPID));
762
763 ath9k_htc_tx_process(priv, skb, &event->txs);
764 list_del(&event->list);
765 kfree(event);
766 continue;
767 }
768
769 if (++event->count >= ATH9K_HTC_TX_TIMEOUT_COUNT) {
770 list_del(&event->list);
771 kfree(event);
772 }
773 }
774 spin_unlock(&priv->wmi->event_lock);
775
776 /*
777 * Check if status-pending packets have to be cleaned up.
778 */
779 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.mgmt_ep_queue);
780 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.cab_ep_queue);
781 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_be_queue);
782 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_bk_queue);
783 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vi_queue);
784 ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vo_queue);
785
786 /* Wake TX queues if needed */
787 ath9k_htc_check_wake_queues(priv);
788
789 mod_timer(&priv->tx.cleanup_timer,
790 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
791 }
792
793 int ath9k_tx_init(struct ath9k_htc_priv *priv)
794 {
795 skb_queue_head_init(&priv->tx.mgmt_ep_queue);
796 skb_queue_head_init(&priv->tx.cab_ep_queue);
797 skb_queue_head_init(&priv->tx.data_be_queue);
798 skb_queue_head_init(&priv->tx.data_bk_queue);
799 skb_queue_head_init(&priv->tx.data_vi_queue);
800 skb_queue_head_init(&priv->tx.data_vo_queue);
801 skb_queue_head_init(&priv->tx.tx_failed);
802 return 0;
803 }
804
805 void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
806 {
807
808 }
809
810 bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
811 {
812 struct ath_hw *ah = priv->ah;
813 struct ath_common *common = ath9k_hw_common(ah);
814 struct ath9k_tx_queue_info qi;
815 int qnum;
816
817 memset(&qi, 0, sizeof(qi));
818 ATH9K_HTC_INIT_TXQ(subtype);
819
820 qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
821 if (qnum == -1)
822 return false;
823
824 if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
825 ath_err(common, "qnum %u out of range, max %zu!\n",
826 qnum, ARRAY_SIZE(priv->hwq_map));
827 ath9k_hw_releasetxqueue(ah, qnum);
828 return false;
829 }
830
831 priv->hwq_map[subtype] = qnum;
832 return true;
833 }
834
835 int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
836 {
837 struct ath9k_tx_queue_info qi;
838
839 memset(&qi, 0, sizeof(qi));
840 ATH9K_HTC_INIT_TXQ(0);
841
842 return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
843 }
844
845 /******/
846 /* RX */
847 /******/
848
849 /*
850 * Calculate the RX filter to be set in the HW.
851 */
852 u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
853 {
854 #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
855
856 struct ath_hw *ah = priv->ah;
857 u32 rfilt;
858
859 rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
860 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
861 | ATH9K_RX_FILTER_MCAST;
862
863 if (priv->rxfilter & FIF_PROBE_REQ)
864 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
865
866 /*
867 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
868 * mode interface or when in monitor mode. AP mode does not need this
869 * since it receives all in-BSS frames anyway.
870 */
871 if (((ah->opmode != NL80211_IFTYPE_AP) &&
872 (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
873 ah->is_monitoring)
874 rfilt |= ATH9K_RX_FILTER_PROM;
875
876 if (priv->rxfilter & FIF_CONTROL)
877 rfilt |= ATH9K_RX_FILTER_CONTROL;
878
879 if ((ah->opmode == NL80211_IFTYPE_STATION) &&
880 !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
881 rfilt |= ATH9K_RX_FILTER_MYBEACON;
882 else
883 rfilt |= ATH9K_RX_FILTER_BEACON;
884
885 if (conf_is_ht(&priv->hw->conf)) {
886 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
887 rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
888 }
889
890 if (priv->rxfilter & FIF_PSPOLL)
891 rfilt |= ATH9K_RX_FILTER_PSPOLL;
892
893 return rfilt;
894
895 #undef RX_FILTER_PRESERVE
896 }
897
898 /*
899 * Recv initialization for opmode change.
900 */
901 static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
902 {
903 struct ath_hw *ah = priv->ah;
904 u32 rfilt, mfilt[2];
905
906 /* configure rx filter */
907 rfilt = ath9k_htc_calcrxfilter(priv);
908 ath9k_hw_setrxfilter(ah, rfilt);
909
910 /* calculate and install multicast filter */
911 mfilt[0] = mfilt[1] = ~0;
912 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
913 }
914
915 void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
916 {
917 ath9k_hw_rxena(priv->ah);
918 ath9k_htc_opmode_init(priv);
919 ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
920 priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
921 }
922
923 static 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
942 band = hw->conf.channel->band;
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
959 static 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);
968 struct ath_htc_rx_status *rxstatus;
969 int hdrlen, padpos, padsize;
970 int last_rssi = ATH_RSSI_DUMMY_MARKER;
971 __le16 fc;
972
973 if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
974 ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
975 skb->len);
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) {
983 ath_err(common,
984 "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
985 rxstatus->rs_datalen, skb->len);
986 goto rx_next;
987 }
988
989 ath9k_htc_err_stat_rx(priv, rxstatus);
990
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
995 hdr = (struct ieee80211_hdr *)skb->data;
996 fc = hdr->frame_control;
997 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
998
999 padpos = ath9k_cmn_padpos(fc);
1000
1001 padsize = padpos & 3;
1002 if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
1003 memmove(skb->data + padsize, skb->data, padpos);
1004 skb_pull(skb, padsize);
1005 }
1006
1007 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
1008
1009 if (rxbuf->rxstatus.rs_status != 0) {
1010 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
1011 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
1012 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
1013 goto rx_next;
1014
1015 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
1016 /* FIXME */
1017 } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
1018 if (ieee80211_is_ctl(fc))
1019 /*
1020 * Sometimes, we get invalid
1021 * MIC failures on valid control frames.
1022 * Remove these mic errors.
1023 */
1024 rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
1025 else
1026 rx_status->flag |= RX_FLAG_MMIC_ERROR;
1027 }
1028
1029 /*
1030 * Reject error frames with the exception of
1031 * decryption and MIC failures. For monitor mode,
1032 * we also ignore the CRC error.
1033 */
1034 if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
1035 if (rxbuf->rxstatus.rs_status &
1036 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
1037 ATH9K_RXERR_CRC))
1038 goto rx_next;
1039 } else {
1040 if (rxbuf->rxstatus.rs_status &
1041 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
1042 goto rx_next;
1043 }
1044 }
1045 }
1046
1047 if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
1048 u8 keyix;
1049 keyix = rxbuf->rxstatus.rs_keyix;
1050 if (keyix != ATH9K_RXKEYIX_INVALID) {
1051 rx_status->flag |= RX_FLAG_DECRYPTED;
1052 } else if (ieee80211_has_protected(fc) &&
1053 skb->len >= hdrlen + 4) {
1054 keyix = skb->data[hdrlen + 3] >> 6;
1055 if (test_bit(keyix, common->keymap))
1056 rx_status->flag |= RX_FLAG_DECRYPTED;
1057 }
1058 }
1059
1060 ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
1061 rxbuf->rxstatus.rs_flags);
1062
1063 if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
1064 !rxbuf->rxstatus.rs_moreaggr)
1065 ATH_RSSI_LPF(priv->rx.last_rssi,
1066 rxbuf->rxstatus.rs_rssi);
1067
1068 last_rssi = priv->rx.last_rssi;
1069
1070 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
1071 rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
1072 ATH_RSSI_EP_MULTIPLIER);
1073
1074 if (rxbuf->rxstatus.rs_rssi < 0)
1075 rxbuf->rxstatus.rs_rssi = 0;
1076
1077 if (ieee80211_is_beacon(fc))
1078 priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
1079
1080 rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
1081 rx_status->band = hw->conf.channel->band;
1082 rx_status->freq = hw->conf.channel->center_freq;
1083 rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
1084 rx_status->antenna = rxbuf->rxstatus.rs_antenna;
1085 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
1086
1087 return true;
1088
1089 rx_next:
1090 return false;
1091 }
1092
1093 /*
1094 * FIXME: Handle FLUSH later on.
1095 */
1096 void ath9k_rx_tasklet(unsigned long data)
1097 {
1098 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
1099 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
1100 struct ieee80211_rx_status rx_status;
1101 struct sk_buff *skb;
1102 unsigned long flags;
1103 struct ieee80211_hdr *hdr;
1104
1105 do {
1106 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
1107 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
1108 if (tmp_buf->in_process) {
1109 rxbuf = tmp_buf;
1110 break;
1111 }
1112 }
1113
1114 if (rxbuf == NULL) {
1115 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
1116 break;
1117 }
1118
1119 if (!rxbuf->skb)
1120 goto requeue;
1121
1122 if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
1123 dev_kfree_skb_any(rxbuf->skb);
1124 goto requeue;
1125 }
1126
1127 memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
1128 sizeof(struct ieee80211_rx_status));
1129 skb = rxbuf->skb;
1130 hdr = (struct ieee80211_hdr *) skb->data;
1131
1132 if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
1133 ieee80211_queue_work(priv->hw, &priv->ps_work);
1134
1135 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
1136
1137 ieee80211_rx(priv->hw, skb);
1138
1139 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
1140 requeue:
1141 rxbuf->in_process = false;
1142 rxbuf->skb = NULL;
1143 list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
1144 rxbuf = NULL;
1145 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
1146 } while (1);
1147
1148 }
1149
1150 void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
1151 enum htc_endpoint_id ep_id)
1152 {
1153 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
1154 struct ath_hw *ah = priv->ah;
1155 struct ath_common *common = ath9k_hw_common(ah);
1156 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
1157
1158 spin_lock(&priv->rx.rxbuflock);
1159 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
1160 if (!tmp_buf->in_process) {
1161 rxbuf = tmp_buf;
1162 break;
1163 }
1164 }
1165 spin_unlock(&priv->rx.rxbuflock);
1166
1167 if (rxbuf == NULL) {
1168 ath_dbg(common, ATH_DBG_ANY,
1169 "No free RX buffer\n");
1170 goto err;
1171 }
1172
1173 spin_lock(&priv->rx.rxbuflock);
1174 rxbuf->skb = skb;
1175 rxbuf->in_process = true;
1176 spin_unlock(&priv->rx.rxbuflock);
1177
1178 tasklet_schedule(&priv->rx_tasklet);
1179 return;
1180 err:
1181 dev_kfree_skb_any(skb);
1182 }
1183
1184 /* FIXME: Locking for cleanup/init */
1185
1186 void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
1187 {
1188 struct ath9k_htc_rxbuf *rxbuf, *tbuf;
1189
1190 list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
1191 list_del(&rxbuf->list);
1192 if (rxbuf->skb)
1193 dev_kfree_skb_any(rxbuf->skb);
1194 kfree(rxbuf);
1195 }
1196 }
1197
1198 int ath9k_rx_init(struct ath9k_htc_priv *priv)
1199 {
1200 struct ath_hw *ah = priv->ah;
1201 struct ath_common *common = ath9k_hw_common(ah);
1202 struct ath9k_htc_rxbuf *rxbuf;
1203 int i = 0;
1204
1205 INIT_LIST_HEAD(&priv->rx.rxbuf);
1206 spin_lock_init(&priv->rx.rxbuflock);
1207
1208 for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
1209 rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
1210 if (rxbuf == NULL) {
1211 ath_err(common, "Unable to allocate RX buffers\n");
1212 goto err;
1213 }
1214 list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
1215 }
1216
1217 return 0;
1218
1219 err:
1220 ath9k_rx_cleanup(priv);
1221 return -ENOMEM;
1222 }