2 * Copyright (c) 2010 Atheros Communications Inc.
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.
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.
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,
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; \
40 int get_hw_qnum(u16 queue, int *hwq_map)
44 return hwq_map[WME_AC_VO];
46 return hwq_map[WME_AC_VI];
48 return hwq_map[WME_AC_BE];
50 return hwq_map[WME_AC_BK];
52 return hwq_map[WME_AC_BE];
56 void ath9k_htc_check_stop_queues(struct ath9k_htc_priv *priv)
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);
65 spin_unlock_bh(&priv->tx.tx_lock);
68 void ath9k_htc_check_wake_queues(struct ath9k_htc_priv *priv)
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);
76 spin_unlock_bh(&priv->tx.tx_lock);
79 static enum htc_endpoint_id get_htc_epid(struct ath9k_htc_priv *priv,
82 enum htc_endpoint_id epid;
86 TX_QSTAT_INC(WME_AC_VO);
87 epid = priv->data_vo_ep;
90 TX_QSTAT_INC(WME_AC_VI);
91 epid = priv->data_vi_ep;
94 TX_QSTAT_INC(WME_AC_BE);
95 epid = priv->data_be_ep;
99 TX_QSTAT_INC(WME_AC_BK);
100 epid = priv->data_bk_ep;
107 int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
108 struct ath9k_tx_queue_info *qinfo)
110 struct ath_hw *ah = priv->ah;
112 struct ath9k_tx_queue_info qi;
114 ath9k_hw_get_txq_props(ah, qnum, &qi);
116 qi.tqi_aifs = qinfo->tqi_aifs;
117 qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
118 qi.tqi_cwmax = qinfo->tqi_cwmax;
119 qi.tqi_burstTime = qinfo->tqi_burstTime;
120 qi.tqi_readyTime = qinfo->tqi_readyTime;
122 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
123 ath_err(ath9k_hw_common(ah),
124 "Unable to update hardware queue %u!\n", qnum);
127 ath9k_hw_resettxqueue(ah, qnum);
133 int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
134 struct sk_buff *skb, bool is_cab)
136 struct ieee80211_hdr *hdr;
137 struct ieee80211_mgmt *mgmt;
138 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
139 struct ieee80211_sta *sta = tx_info->control.sta;
140 struct ieee80211_vif *vif = tx_info->control.vif;
141 struct ath9k_htc_sta *ista;
142 struct ath9k_htc_vif *avp = NULL;
143 struct ath9k_htc_tx_ctl *tx_ctl;
149 tx_ctl = HTC_SKB_CB(skb);
150 memset(tx_ctl, 0, sizeof(*tx_ctl));
152 hdr = (struct ieee80211_hdr *) skb->data;
153 fc = hdr->frame_control;
156 * Find out on which interface this packet has to be
160 avp = (struct ath9k_htc_vif *) vif->drv_priv;
161 vif_idx = avp->index;
163 if (!priv->ah->is_monitoring) {
164 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
165 "VIF is null, but no monitor interface !\n");
169 vif_idx = priv->mon_vif_idx;
173 * Find out which station this packet is destined for.
176 ista = (struct ath9k_htc_sta *) sta->drv_priv;
177 sta_idx = ista->index;
179 sta_idx = priv->vif_sta_pos[vif_idx];
182 if (ieee80211_is_data(fc)) {
183 struct tx_frame_hdr tx_hdr;
187 memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
189 tx_hdr.node_idx = sta_idx;
190 tx_hdr.vif_idx = vif_idx;
192 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
193 tx_ctl->type = ATH9K_HTC_AMPDU;
194 tx_hdr.data_type = ATH9K_HTC_AMPDU;
196 tx_ctl->type = ATH9K_HTC_NORMAL;
197 tx_hdr.data_type = ATH9K_HTC_NORMAL;
200 if (ieee80211_is_data_qos(fc)) {
201 qc = ieee80211_get_qos_ctl(hdr);
202 tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
205 /* Check for RTS protection */
206 if (priv->hw->wiphy->rts_threshold != (u32) -1)
207 if (skb->len > priv->hw->wiphy->rts_threshold)
208 flags |= ATH9K_HTC_TX_RTSCTS;
211 if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
212 (vif && vif->bss_conf.use_cts_prot))
213 flags |= ATH9K_HTC_TX_CTSONLY;
215 tx_hdr.flags = cpu_to_be32(flags);
216 tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
217 if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
218 tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
220 tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
222 tx_fhdr = skb_push(skb, sizeof(tx_hdr));
223 memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
227 tx_ctl->epid = priv->cab_ep;
231 qnum = skb_get_queue_mapping(skb);
232 tx_ctl->epid = get_htc_epid(priv, qnum);
234 struct tx_mgmt_hdr mgmt_hdr;
236 memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
239 * Set the TSF adjust value for probe response
242 if (avp && unlikely(ieee80211_is_probe_resp(fc))) {
243 mgmt = (struct ieee80211_mgmt *)skb->data;
244 mgmt->u.probe_resp.timestamp = avp->tsfadjust;
247 tx_ctl->type = ATH9K_HTC_MGMT;
249 mgmt_hdr.node_idx = sta_idx;
250 mgmt_hdr.vif_idx = vif_idx;
254 mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
255 if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
256 mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
258 mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
260 tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
261 memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
262 tx_ctl->epid = priv->mgmt_ep;
265 return htc_send(priv->htc, skb);
268 static bool ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
269 struct ath9k_htc_sta *ista, u8 tid)
273 spin_lock_bh(&priv->tx.tx_lock);
274 if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
276 spin_unlock_bh(&priv->tx.tx_lock);
281 void ath9k_tx_tasklet(unsigned long data)
283 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
284 struct ieee80211_vif *vif;
285 struct ieee80211_sta *sta;
286 struct ieee80211_hdr *hdr;
287 struct ieee80211_tx_info *tx_info;
288 struct sk_buff *skb = NULL;
291 while ((skb = skb_dequeue(&priv->tx.tx_queue)) != NULL) {
293 hdr = (struct ieee80211_hdr *) skb->data;
294 fc = hdr->frame_control;
295 tx_info = IEEE80211_SKB_CB(skb);
296 vif = tx_info->control.vif;
298 memset(&tx_info->status, 0, sizeof(tx_info->status));
305 sta = ieee80211_find_sta(vif, hdr->addr1);
308 ieee80211_tx_status(priv->hw, skb);
312 /* Check if we need to start aggregation */
314 if (sta && conf_is_ht(&priv->hw->conf) &&
315 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
316 if (ieee80211_is_data_qos(fc)) {
318 struct ath9k_htc_sta *ista;
320 qc = ieee80211_get_qos_ctl(hdr);
322 ista = (struct ath9k_htc_sta *)sta->drv_priv;
324 if (ath9k_htc_check_tx_aggr(priv, ista, tid)) {
325 ieee80211_start_tx_ba_session(sta, tid, 0);
326 spin_lock_bh(&priv->tx.tx_lock);
327 ista->tid_state[tid] = AGGR_PROGRESS;
328 spin_unlock_bh(&priv->tx.tx_lock);
336 spin_lock_bh(&priv->tx.tx_lock);
337 if (WARN_ON(--priv->tx.queued_cnt < 0))
338 priv->tx.queued_cnt = 0;
339 spin_unlock_bh(&priv->tx.tx_lock);
341 /* Send status to mac80211 */
342 ieee80211_tx_status(priv->hw, skb);
345 /* Wake TX queues if needed */
346 ath9k_htc_check_wake_queues(priv);
349 void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
350 enum htc_endpoint_id ep_id, bool txok)
352 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
353 struct ath_common *common = ath9k_hw_common(priv->ah);
354 struct ieee80211_tx_info *tx_info;
359 if (ep_id == priv->mgmt_ep) {
360 skb_pull(skb, sizeof(struct tx_mgmt_hdr));
361 } else if ((ep_id == priv->data_bk_ep) ||
362 (ep_id == priv->data_be_ep) ||
363 (ep_id == priv->data_vi_ep) ||
364 (ep_id == priv->data_vo_ep) ||
365 (ep_id == priv->cab_ep)) {
366 skb_pull(skb, sizeof(struct tx_frame_hdr));
368 ath_err(common, "Unsupported TX EPID: %d\n", ep_id);
369 dev_kfree_skb_any(skb);
373 tx_info = IEEE80211_SKB_CB(skb);
376 tx_info->flags |= IEEE80211_TX_STAT_ACK;
378 skb_queue_tail(&priv->tx.tx_queue, skb);
379 tasklet_schedule(&priv->tx_tasklet);
382 int ath9k_tx_init(struct ath9k_htc_priv *priv)
384 skb_queue_head_init(&priv->tx.tx_queue);
388 void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
393 bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
395 struct ath_hw *ah = priv->ah;
396 struct ath_common *common = ath9k_hw_common(ah);
397 struct ath9k_tx_queue_info qi;
400 memset(&qi, 0, sizeof(qi));
401 ATH9K_HTC_INIT_TXQ(subtype);
403 qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
407 if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
408 ath_err(common, "qnum %u out of range, max %zu!\n",
409 qnum, ARRAY_SIZE(priv->hwq_map));
410 ath9k_hw_releasetxqueue(ah, qnum);
414 priv->hwq_map[subtype] = qnum;
418 int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
420 struct ath9k_tx_queue_info qi;
422 memset(&qi, 0, sizeof(qi));
423 ATH9K_HTC_INIT_TXQ(0);
425 return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
433 * Calculate the RX filter to be set in the HW.
435 u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
437 #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
439 struct ath_hw *ah = priv->ah;
442 rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
443 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
444 | ATH9K_RX_FILTER_MCAST;
446 if (priv->rxfilter & FIF_PROBE_REQ)
447 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
450 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
451 * mode interface or when in monitor mode. AP mode does not need this
452 * since it receives all in-BSS frames anyway.
454 if (((ah->opmode != NL80211_IFTYPE_AP) &&
455 (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
457 rfilt |= ATH9K_RX_FILTER_PROM;
459 if (priv->rxfilter & FIF_CONTROL)
460 rfilt |= ATH9K_RX_FILTER_CONTROL;
462 if ((ah->opmode == NL80211_IFTYPE_STATION) &&
463 !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
464 rfilt |= ATH9K_RX_FILTER_MYBEACON;
466 rfilt |= ATH9K_RX_FILTER_BEACON;
468 if (conf_is_ht(&priv->hw->conf)) {
469 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
470 rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
473 if (priv->rxfilter & FIF_PSPOLL)
474 rfilt |= ATH9K_RX_FILTER_PSPOLL;
478 #undef RX_FILTER_PRESERVE
482 * Recv initialization for opmode change.
484 static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
486 struct ath_hw *ah = priv->ah;
489 /* configure rx filter */
490 rfilt = ath9k_htc_calcrxfilter(priv);
491 ath9k_hw_setrxfilter(ah, rfilt);
493 /* calculate and install multicast filter */
494 mfilt[0] = mfilt[1] = ~0;
495 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
498 void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
500 ath9k_hw_rxena(priv->ah);
501 ath9k_htc_opmode_init(priv);
502 ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
503 priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
506 static void ath9k_process_rate(struct ieee80211_hw *hw,
507 struct ieee80211_rx_status *rxs,
508 u8 rx_rate, u8 rs_flags)
510 struct ieee80211_supported_band *sband;
511 enum ieee80211_band band;
514 if (rx_rate & 0x80) {
516 rxs->flag |= RX_FLAG_HT;
517 if (rs_flags & ATH9K_RX_2040)
518 rxs->flag |= RX_FLAG_40MHZ;
519 if (rs_flags & ATH9K_RX_GI)
520 rxs->flag |= RX_FLAG_SHORT_GI;
521 rxs->rate_idx = rx_rate & 0x7f;
525 band = hw->conf.channel->band;
526 sband = hw->wiphy->bands[band];
528 for (i = 0; i < sband->n_bitrates; i++) {
529 if (sband->bitrates[i].hw_value == rx_rate) {
533 if (sband->bitrates[i].hw_value_short == rx_rate) {
535 rxs->flag |= RX_FLAG_SHORTPRE;
542 static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
543 struct ath9k_htc_rxbuf *rxbuf,
544 struct ieee80211_rx_status *rx_status)
547 struct ieee80211_hdr *hdr;
548 struct ieee80211_hw *hw = priv->hw;
549 struct sk_buff *skb = rxbuf->skb;
550 struct ath_common *common = ath9k_hw_common(priv->ah);
551 struct ath_htc_rx_status *rxstatus;
552 int hdrlen, padpos, padsize;
553 int last_rssi = ATH_RSSI_DUMMY_MARKER;
556 if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
557 ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
562 rxstatus = (struct ath_htc_rx_status *)skb->data;
564 if (be16_to_cpu(rxstatus->rs_datalen) -
565 (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
567 "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
568 rxstatus->rs_datalen, skb->len);
572 ath9k_htc_err_stat_rx(priv, rxstatus);
574 /* Get the RX status information */
575 memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
576 skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
578 hdr = (struct ieee80211_hdr *)skb->data;
579 fc = hdr->frame_control;
580 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
582 padpos = ath9k_cmn_padpos(fc);
584 padsize = padpos & 3;
585 if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
586 memmove(skb->data + padsize, skb->data, padpos);
587 skb_pull(skb, padsize);
590 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
592 if (rxbuf->rxstatus.rs_status != 0) {
593 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
594 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
595 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
598 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
600 } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
601 if (ieee80211_is_ctl(fc))
603 * Sometimes, we get invalid
604 * MIC failures on valid control frames.
605 * Remove these mic errors.
607 rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
609 rx_status->flag |= RX_FLAG_MMIC_ERROR;
613 * Reject error frames with the exception of
614 * decryption and MIC failures. For monitor mode,
615 * we also ignore the CRC error.
617 if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
618 if (rxbuf->rxstatus.rs_status &
619 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
623 if (rxbuf->rxstatus.rs_status &
624 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
630 if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
632 keyix = rxbuf->rxstatus.rs_keyix;
633 if (keyix != ATH9K_RXKEYIX_INVALID) {
634 rx_status->flag |= RX_FLAG_DECRYPTED;
635 } else if (ieee80211_has_protected(fc) &&
636 skb->len >= hdrlen + 4) {
637 keyix = skb->data[hdrlen + 3] >> 6;
638 if (test_bit(keyix, common->keymap))
639 rx_status->flag |= RX_FLAG_DECRYPTED;
643 ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
644 rxbuf->rxstatus.rs_flags);
646 if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
647 !rxbuf->rxstatus.rs_moreaggr)
648 ATH_RSSI_LPF(priv->rx.last_rssi,
649 rxbuf->rxstatus.rs_rssi);
651 last_rssi = priv->rx.last_rssi;
653 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
654 rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
655 ATH_RSSI_EP_MULTIPLIER);
657 if (rxbuf->rxstatus.rs_rssi < 0)
658 rxbuf->rxstatus.rs_rssi = 0;
660 if (ieee80211_is_beacon(fc))
661 priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
663 rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
664 rx_status->band = hw->conf.channel->band;
665 rx_status->freq = hw->conf.channel->center_freq;
666 rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
667 rx_status->antenna = rxbuf->rxstatus.rs_antenna;
668 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
677 * FIXME: Handle FLUSH later on.
679 void ath9k_rx_tasklet(unsigned long data)
681 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
682 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
683 struct ieee80211_rx_status rx_status;
686 struct ieee80211_hdr *hdr;
689 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
690 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
691 if (tmp_buf->in_process) {
698 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
705 if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
706 dev_kfree_skb_any(rxbuf->skb);
710 memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
711 sizeof(struct ieee80211_rx_status));
713 hdr = (struct ieee80211_hdr *) skb->data;
715 if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
716 ieee80211_queue_work(priv->hw, &priv->ps_work);
718 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
720 ieee80211_rx(priv->hw, skb);
722 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
724 rxbuf->in_process = false;
726 list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
728 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
733 void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
734 enum htc_endpoint_id ep_id)
736 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
737 struct ath_hw *ah = priv->ah;
738 struct ath_common *common = ath9k_hw_common(ah);
739 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
741 spin_lock(&priv->rx.rxbuflock);
742 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
743 if (!tmp_buf->in_process) {
748 spin_unlock(&priv->rx.rxbuflock);
751 ath_dbg(common, ATH_DBG_ANY,
752 "No free RX buffer\n");
756 spin_lock(&priv->rx.rxbuflock);
758 rxbuf->in_process = true;
759 spin_unlock(&priv->rx.rxbuflock);
761 tasklet_schedule(&priv->rx_tasklet);
764 dev_kfree_skb_any(skb);
767 /* FIXME: Locking for cleanup/init */
769 void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
771 struct ath9k_htc_rxbuf *rxbuf, *tbuf;
773 list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
774 list_del(&rxbuf->list);
776 dev_kfree_skb_any(rxbuf->skb);
781 int ath9k_rx_init(struct ath9k_htc_priv *priv)
783 struct ath_hw *ah = priv->ah;
784 struct ath_common *common = ath9k_hw_common(ah);
785 struct ath9k_htc_rxbuf *rxbuf;
788 INIT_LIST_HEAD(&priv->rx.rxbuf);
789 spin_lock_init(&priv->rx.rxbuflock);
791 for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
792 rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
794 ath_err(common, "Unable to allocate RX buffers\n");
797 list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
803 ath9k_rx_cleanup(priv);