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 static inline int strip_drv_header(struct ath9k_htc_priv *priv,
110 struct ath_common *common = ath9k_hw_common(priv->ah);
111 struct ath9k_htc_tx_ctl *tx_ctl;
113 tx_ctl = HTC_SKB_CB(skb);
115 if (tx_ctl->epid == priv->mgmt_ep) {
116 skb_pull(skb, sizeof(struct tx_mgmt_hdr));
117 } else if ((tx_ctl->epid == priv->data_bk_ep) ||
118 (tx_ctl->epid == priv->data_be_ep) ||
119 (tx_ctl->epid == priv->data_vi_ep) ||
120 (tx_ctl->epid == priv->data_vo_ep) ||
121 (tx_ctl->epid == priv->cab_ep)) {
122 skb_pull(skb, sizeof(struct tx_frame_hdr));
124 ath_err(common, "Unsupported EPID: %d\n", tx_ctl->epid);
131 int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
132 struct ath9k_tx_queue_info *qinfo)
134 struct ath_hw *ah = priv->ah;
136 struct ath9k_tx_queue_info qi;
138 ath9k_hw_get_txq_props(ah, qnum, &qi);
140 qi.tqi_aifs = qinfo->tqi_aifs;
141 qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
142 qi.tqi_cwmax = qinfo->tqi_cwmax;
143 qi.tqi_burstTime = qinfo->tqi_burstTime;
144 qi.tqi_readyTime = qinfo->tqi_readyTime;
146 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
147 ath_err(ath9k_hw_common(ah),
148 "Unable to update hardware queue %u!\n", qnum);
151 ath9k_hw_resettxqueue(ah, qnum);
157 int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
158 struct sk_buff *skb, bool is_cab)
160 struct ieee80211_hdr *hdr;
161 struct ieee80211_mgmt *mgmt;
162 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
163 struct ieee80211_sta *sta = tx_info->control.sta;
164 struct ieee80211_vif *vif = tx_info->control.vif;
165 struct ath9k_htc_sta *ista;
166 struct ath9k_htc_vif *avp = NULL;
167 struct ath9k_htc_tx_ctl *tx_ctl;
173 tx_ctl = HTC_SKB_CB(skb);
174 memset(tx_ctl, 0, sizeof(*tx_ctl));
176 hdr = (struct ieee80211_hdr *) skb->data;
177 fc = hdr->frame_control;
180 * Find out on which interface this packet has to be
184 avp = (struct ath9k_htc_vif *) vif->drv_priv;
185 vif_idx = avp->index;
187 if (!priv->ah->is_monitoring) {
188 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
189 "VIF is null, but no monitor interface !\n");
193 vif_idx = priv->mon_vif_idx;
197 * Find out which station this packet is destined for.
200 ista = (struct ath9k_htc_sta *) sta->drv_priv;
201 sta_idx = ista->index;
203 sta_idx = priv->vif_sta_pos[vif_idx];
206 if (ieee80211_is_data(fc)) {
207 struct tx_frame_hdr tx_hdr;
211 memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
213 tx_hdr.node_idx = sta_idx;
214 tx_hdr.vif_idx = vif_idx;
216 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
217 tx_ctl->type = ATH9K_HTC_AMPDU;
218 tx_hdr.data_type = ATH9K_HTC_AMPDU;
220 tx_ctl->type = ATH9K_HTC_NORMAL;
221 tx_hdr.data_type = ATH9K_HTC_NORMAL;
224 if (ieee80211_is_data_qos(fc)) {
225 qc = ieee80211_get_qos_ctl(hdr);
226 tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
229 /* Check for RTS protection */
230 if (priv->hw->wiphy->rts_threshold != (u32) -1)
231 if (skb->len > priv->hw->wiphy->rts_threshold)
232 flags |= ATH9K_HTC_TX_RTSCTS;
235 if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
236 (vif && vif->bss_conf.use_cts_prot))
237 flags |= ATH9K_HTC_TX_CTSONLY;
239 tx_hdr.flags = cpu_to_be32(flags);
240 tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
241 if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
242 tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
244 tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
246 tx_fhdr = skb_push(skb, sizeof(tx_hdr));
247 memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
251 tx_ctl->epid = priv->cab_ep;
255 qnum = skb_get_queue_mapping(skb);
256 tx_ctl->epid = get_htc_epid(priv, qnum);
258 struct tx_mgmt_hdr mgmt_hdr;
260 memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
263 * Set the TSF adjust value for probe response
266 if (avp && unlikely(ieee80211_is_probe_resp(fc))) {
267 mgmt = (struct ieee80211_mgmt *)skb->data;
268 mgmt->u.probe_resp.timestamp = avp->tsfadjust;
271 tx_ctl->type = ATH9K_HTC_MGMT;
273 mgmt_hdr.node_idx = sta_idx;
274 mgmt_hdr.vif_idx = vif_idx;
278 mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
279 if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
280 mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
282 mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
284 tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
285 memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
286 tx_ctl->epid = priv->mgmt_ep;
289 return htc_send(priv->htc, skb);
292 static bool ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
293 struct ath9k_htc_sta *ista, u8 tid)
297 spin_lock_bh(&priv->tx.tx_lock);
298 if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
300 spin_unlock_bh(&priv->tx.tx_lock);
305 void ath9k_tx_tasklet(unsigned long data)
307 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
308 struct ath9k_htc_tx_ctl *tx_ctl;
309 struct ieee80211_vif *vif;
310 struct ieee80211_sta *sta;
311 struct ieee80211_hdr *hdr;
312 struct ieee80211_tx_info *tx_info;
313 struct sk_buff *skb = NULL;
317 while ((skb = skb_dequeue(&priv->tx.tx_queue)) != NULL) {
319 if (strip_drv_header(priv, skb) < 0) {
320 dev_kfree_skb_any(skb);
324 tx_ctl = HTC_SKB_CB(skb);
325 hdr = (struct ieee80211_hdr *) skb->data;
326 fc = hdr->frame_control;
327 tx_info = IEEE80211_SKB_CB(skb);
328 vif = tx_info->control.vif;
331 memset(&tx_info->status, 0, sizeof(tx_info->status));
334 * URB submission failed for this frame, it never reached
340 tx_info->flags |= IEEE80211_TX_STAT_ACK;
347 sta = ieee80211_find_sta(vif, hdr->addr1);
350 ieee80211_tx_status(priv->hw, skb);
354 /* Check if we need to start aggregation */
356 if (sta && conf_is_ht(&priv->hw->conf) &&
357 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
358 if (ieee80211_is_data_qos(fc)) {
360 struct ath9k_htc_sta *ista;
362 qc = ieee80211_get_qos_ctl(hdr);
364 ista = (struct ath9k_htc_sta *)sta->drv_priv;
366 if (ath9k_htc_check_tx_aggr(priv, ista, tid)) {
367 ieee80211_start_tx_ba_session(sta, tid, 0);
368 spin_lock_bh(&priv->tx.tx_lock);
369 ista->tid_state[tid] = AGGR_PROGRESS;
370 spin_unlock_bh(&priv->tx.tx_lock);
378 spin_lock_bh(&priv->tx.tx_lock);
379 if (WARN_ON(--priv->tx.queued_cnt < 0))
380 priv->tx.queued_cnt = 0;
381 spin_unlock_bh(&priv->tx.tx_lock);
383 /* Send status to mac80211 */
384 ieee80211_tx_status(priv->hw, skb);
387 /* Wake TX queues if needed */
388 ath9k_htc_check_wake_queues(priv);
391 void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
392 enum htc_endpoint_id ep_id, bool txok)
394 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
395 struct ath9k_htc_tx_ctl *tx_ctl;
397 tx_ctl = HTC_SKB_CB(skb);
400 skb_queue_tail(&priv->tx.tx_queue, skb);
401 tasklet_schedule(&priv->tx_tasklet);
404 int ath9k_tx_init(struct ath9k_htc_priv *priv)
406 skb_queue_head_init(&priv->tx.tx_queue);
410 void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
415 bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
417 struct ath_hw *ah = priv->ah;
418 struct ath_common *common = ath9k_hw_common(ah);
419 struct ath9k_tx_queue_info qi;
422 memset(&qi, 0, sizeof(qi));
423 ATH9K_HTC_INIT_TXQ(subtype);
425 qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
429 if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
430 ath_err(common, "qnum %u out of range, max %zu!\n",
431 qnum, ARRAY_SIZE(priv->hwq_map));
432 ath9k_hw_releasetxqueue(ah, qnum);
436 priv->hwq_map[subtype] = qnum;
440 int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
442 struct ath9k_tx_queue_info qi;
444 memset(&qi, 0, sizeof(qi));
445 ATH9K_HTC_INIT_TXQ(0);
447 return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
455 * Calculate the RX filter to be set in the HW.
457 u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
459 #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
461 struct ath_hw *ah = priv->ah;
464 rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
465 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
466 | ATH9K_RX_FILTER_MCAST;
468 if (priv->rxfilter & FIF_PROBE_REQ)
469 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
472 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
473 * mode interface or when in monitor mode. AP mode does not need this
474 * since it receives all in-BSS frames anyway.
476 if (((ah->opmode != NL80211_IFTYPE_AP) &&
477 (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
479 rfilt |= ATH9K_RX_FILTER_PROM;
481 if (priv->rxfilter & FIF_CONTROL)
482 rfilt |= ATH9K_RX_FILTER_CONTROL;
484 if ((ah->opmode == NL80211_IFTYPE_STATION) &&
485 !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
486 rfilt |= ATH9K_RX_FILTER_MYBEACON;
488 rfilt |= ATH9K_RX_FILTER_BEACON;
490 if (conf_is_ht(&priv->hw->conf)) {
491 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
492 rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
495 if (priv->rxfilter & FIF_PSPOLL)
496 rfilt |= ATH9K_RX_FILTER_PSPOLL;
500 #undef RX_FILTER_PRESERVE
504 * Recv initialization for opmode change.
506 static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
508 struct ath_hw *ah = priv->ah;
511 /* configure rx filter */
512 rfilt = ath9k_htc_calcrxfilter(priv);
513 ath9k_hw_setrxfilter(ah, rfilt);
515 /* calculate and install multicast filter */
516 mfilt[0] = mfilt[1] = ~0;
517 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
520 void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
522 ath9k_hw_rxena(priv->ah);
523 ath9k_htc_opmode_init(priv);
524 ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
525 priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
528 static void ath9k_process_rate(struct ieee80211_hw *hw,
529 struct ieee80211_rx_status *rxs,
530 u8 rx_rate, u8 rs_flags)
532 struct ieee80211_supported_band *sband;
533 enum ieee80211_band band;
536 if (rx_rate & 0x80) {
538 rxs->flag |= RX_FLAG_HT;
539 if (rs_flags & ATH9K_RX_2040)
540 rxs->flag |= RX_FLAG_40MHZ;
541 if (rs_flags & ATH9K_RX_GI)
542 rxs->flag |= RX_FLAG_SHORT_GI;
543 rxs->rate_idx = rx_rate & 0x7f;
547 band = hw->conf.channel->band;
548 sband = hw->wiphy->bands[band];
550 for (i = 0; i < sband->n_bitrates; i++) {
551 if (sband->bitrates[i].hw_value == rx_rate) {
555 if (sband->bitrates[i].hw_value_short == rx_rate) {
557 rxs->flag |= RX_FLAG_SHORTPRE;
564 static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
565 struct ath9k_htc_rxbuf *rxbuf,
566 struct ieee80211_rx_status *rx_status)
569 struct ieee80211_hdr *hdr;
570 struct ieee80211_hw *hw = priv->hw;
571 struct sk_buff *skb = rxbuf->skb;
572 struct ath_common *common = ath9k_hw_common(priv->ah);
573 struct ath_htc_rx_status *rxstatus;
574 int hdrlen, padpos, padsize;
575 int last_rssi = ATH_RSSI_DUMMY_MARKER;
578 if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
579 ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
584 rxstatus = (struct ath_htc_rx_status *)skb->data;
586 if (be16_to_cpu(rxstatus->rs_datalen) -
587 (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
589 "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
590 rxstatus->rs_datalen, skb->len);
594 ath9k_htc_err_stat_rx(priv, rxstatus);
596 /* Get the RX status information */
597 memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
598 skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
600 hdr = (struct ieee80211_hdr *)skb->data;
601 fc = hdr->frame_control;
602 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
604 padpos = ath9k_cmn_padpos(fc);
606 padsize = padpos & 3;
607 if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
608 memmove(skb->data + padsize, skb->data, padpos);
609 skb_pull(skb, padsize);
612 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
614 if (rxbuf->rxstatus.rs_status != 0) {
615 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
616 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
617 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
620 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
622 } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
623 if (ieee80211_is_ctl(fc))
625 * Sometimes, we get invalid
626 * MIC failures on valid control frames.
627 * Remove these mic errors.
629 rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
631 rx_status->flag |= RX_FLAG_MMIC_ERROR;
635 * Reject error frames with the exception of
636 * decryption and MIC failures. For monitor mode,
637 * we also ignore the CRC error.
639 if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
640 if (rxbuf->rxstatus.rs_status &
641 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
645 if (rxbuf->rxstatus.rs_status &
646 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
652 if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
654 keyix = rxbuf->rxstatus.rs_keyix;
655 if (keyix != ATH9K_RXKEYIX_INVALID) {
656 rx_status->flag |= RX_FLAG_DECRYPTED;
657 } else if (ieee80211_has_protected(fc) &&
658 skb->len >= hdrlen + 4) {
659 keyix = skb->data[hdrlen + 3] >> 6;
660 if (test_bit(keyix, common->keymap))
661 rx_status->flag |= RX_FLAG_DECRYPTED;
665 ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
666 rxbuf->rxstatus.rs_flags);
668 if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
669 !rxbuf->rxstatus.rs_moreaggr)
670 ATH_RSSI_LPF(priv->rx.last_rssi,
671 rxbuf->rxstatus.rs_rssi);
673 last_rssi = priv->rx.last_rssi;
675 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
676 rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
677 ATH_RSSI_EP_MULTIPLIER);
679 if (rxbuf->rxstatus.rs_rssi < 0)
680 rxbuf->rxstatus.rs_rssi = 0;
682 if (ieee80211_is_beacon(fc))
683 priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
685 rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
686 rx_status->band = hw->conf.channel->band;
687 rx_status->freq = hw->conf.channel->center_freq;
688 rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
689 rx_status->antenna = rxbuf->rxstatus.rs_antenna;
690 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
699 * FIXME: Handle FLUSH later on.
701 void ath9k_rx_tasklet(unsigned long data)
703 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
704 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
705 struct ieee80211_rx_status rx_status;
708 struct ieee80211_hdr *hdr;
711 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
712 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
713 if (tmp_buf->in_process) {
720 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
727 if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
728 dev_kfree_skb_any(rxbuf->skb);
732 memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
733 sizeof(struct ieee80211_rx_status));
735 hdr = (struct ieee80211_hdr *) skb->data;
737 if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
738 ieee80211_queue_work(priv->hw, &priv->ps_work);
740 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
742 ieee80211_rx(priv->hw, skb);
744 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
746 rxbuf->in_process = false;
748 list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
750 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
755 void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
756 enum htc_endpoint_id ep_id)
758 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
759 struct ath_hw *ah = priv->ah;
760 struct ath_common *common = ath9k_hw_common(ah);
761 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
763 spin_lock(&priv->rx.rxbuflock);
764 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
765 if (!tmp_buf->in_process) {
770 spin_unlock(&priv->rx.rxbuflock);
773 ath_dbg(common, ATH_DBG_ANY,
774 "No free RX buffer\n");
778 spin_lock(&priv->rx.rxbuflock);
780 rxbuf->in_process = true;
781 spin_unlock(&priv->rx.rxbuflock);
783 tasklet_schedule(&priv->rx_tasklet);
786 dev_kfree_skb_any(skb);
789 /* FIXME: Locking for cleanup/init */
791 void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
793 struct ath9k_htc_rxbuf *rxbuf, *tbuf;
795 list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
796 list_del(&rxbuf->list);
798 dev_kfree_skb_any(rxbuf->skb);
803 int ath9k_rx_init(struct ath9k_htc_priv *priv)
805 struct ath_hw *ah = priv->ah;
806 struct ath_common *common = ath9k_hw_common(ah);
807 struct ath9k_htc_rxbuf *rxbuf;
810 INIT_LIST_HEAD(&priv->rx.rxbuf);
811 spin_lock_init(&priv->rx.rxbuflock);
813 for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
814 rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
816 ath_err(common, "Unable to allocate RX buffers\n");
819 list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
825 ath9k_rx_cleanup(priv);