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 int ath9k_htc_tx_get_slot(struct ath9k_htc_priv *priv)
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);
89 __set_bit(slot, priv->tx.tx_slot);
90 spin_unlock_bh(&priv->tx.tx_lock);
95 void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv *priv, int slot)
97 spin_lock_bh(&priv->tx.tx_lock);
98 __clear_bit(slot, priv->tx.tx_slot);
99 spin_unlock_bh(&priv->tx.tx_lock);
102 static enum htc_endpoint_id get_htc_epid(struct ath9k_htc_priv *priv,
105 enum htc_endpoint_id epid;
109 TX_QSTAT_INC(WME_AC_VO);
110 epid = priv->data_vo_ep;
113 TX_QSTAT_INC(WME_AC_VI);
114 epid = priv->data_vi_ep;
117 TX_QSTAT_INC(WME_AC_BE);
118 epid = priv->data_be_ep;
122 TX_QSTAT_INC(WME_AC_BK);
123 epid = priv->data_bk_ep;
131 * Removes the driver header and returns the TX slot number
133 static inline int strip_drv_header(struct ath9k_htc_priv *priv,
136 struct ath_common *common = ath9k_hw_common(priv->ah);
137 struct ath9k_htc_tx_ctl *tx_ctl;
140 tx_ctl = HTC_SKB_CB(skb);
142 if (tx_ctl->epid == priv->mgmt_ep) {
143 struct tx_mgmt_hdr *tx_mhdr =
144 (struct tx_mgmt_hdr *)skb->data;
145 slot = tx_mhdr->cookie;
146 skb_pull(skb, sizeof(struct tx_mgmt_hdr));
147 } else if ((tx_ctl->epid == priv->data_bk_ep) ||
148 (tx_ctl->epid == priv->data_be_ep) ||
149 (tx_ctl->epid == priv->data_vi_ep) ||
150 (tx_ctl->epid == priv->data_vo_ep) ||
151 (tx_ctl->epid == priv->cab_ep)) {
152 struct tx_frame_hdr *tx_fhdr =
153 (struct tx_frame_hdr *)skb->data;
154 slot = tx_fhdr->cookie;
155 skb_pull(skb, sizeof(struct tx_frame_hdr));
157 ath_err(common, "Unsupported EPID: %d\n", tx_ctl->epid);
164 int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
165 struct ath9k_tx_queue_info *qinfo)
167 struct ath_hw *ah = priv->ah;
169 struct ath9k_tx_queue_info qi;
171 ath9k_hw_get_txq_props(ah, qnum, &qi);
173 qi.tqi_aifs = qinfo->tqi_aifs;
174 qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
175 qi.tqi_cwmax = qinfo->tqi_cwmax;
176 qi.tqi_burstTime = qinfo->tqi_burstTime;
177 qi.tqi_readyTime = qinfo->tqi_readyTime;
179 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
180 ath_err(ath9k_hw_common(ah),
181 "Unable to update hardware queue %u!\n", qnum);
184 ath9k_hw_resettxqueue(ah, qnum);
190 int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
192 u8 slot, bool is_cab)
194 struct ieee80211_hdr *hdr;
195 struct ieee80211_mgmt *mgmt;
196 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
197 struct ieee80211_sta *sta = tx_info->control.sta;
198 struct ieee80211_vif *vif = tx_info->control.vif;
199 struct ath9k_htc_sta *ista;
200 struct ath9k_htc_vif *avp = NULL;
201 struct ath9k_htc_tx_ctl *tx_ctl;
207 tx_ctl = HTC_SKB_CB(skb);
208 memset(tx_ctl, 0, sizeof(*tx_ctl));
210 hdr = (struct ieee80211_hdr *) skb->data;
211 fc = hdr->frame_control;
214 * Find out on which interface this packet has to be
218 avp = (struct ath9k_htc_vif *) vif->drv_priv;
219 vif_idx = avp->index;
221 if (!priv->ah->is_monitoring) {
222 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
223 "VIF is null, but no monitor interface !\n");
227 vif_idx = priv->mon_vif_idx;
231 * Find out which station this packet is destined for.
234 ista = (struct ath9k_htc_sta *) sta->drv_priv;
235 sta_idx = ista->index;
237 sta_idx = priv->vif_sta_pos[vif_idx];
240 if (ieee80211_is_data(fc)) {
241 struct tx_frame_hdr tx_hdr;
245 memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
247 tx_hdr.node_idx = sta_idx;
248 tx_hdr.vif_idx = vif_idx;
249 tx_hdr.cookie = slot;
251 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
252 tx_ctl->type = ATH9K_HTC_AMPDU;
253 tx_hdr.data_type = ATH9K_HTC_AMPDU;
255 tx_ctl->type = ATH9K_HTC_NORMAL;
256 tx_hdr.data_type = ATH9K_HTC_NORMAL;
259 if (ieee80211_is_data_qos(fc)) {
260 qc = ieee80211_get_qos_ctl(hdr);
261 tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
264 /* Check for RTS protection */
265 if (priv->hw->wiphy->rts_threshold != (u32) -1)
266 if (skb->len > priv->hw->wiphy->rts_threshold)
267 flags |= ATH9K_HTC_TX_RTSCTS;
270 if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
271 (vif && vif->bss_conf.use_cts_prot))
272 flags |= ATH9K_HTC_TX_CTSONLY;
274 tx_hdr.flags = cpu_to_be32(flags);
275 tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
276 if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
277 tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
279 tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
281 tx_fhdr = skb_push(skb, sizeof(tx_hdr));
282 memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
286 tx_ctl->epid = priv->cab_ep;
290 qnum = skb_get_queue_mapping(skb);
291 tx_ctl->epid = get_htc_epid(priv, qnum);
293 struct tx_mgmt_hdr mgmt_hdr;
295 memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
298 * Set the TSF adjust value for probe response
301 if (avp && unlikely(ieee80211_is_probe_resp(fc))) {
302 mgmt = (struct ieee80211_mgmt *)skb->data;
303 mgmt->u.probe_resp.timestamp = avp->tsfadjust;
306 tx_ctl->type = ATH9K_HTC_MGMT;
308 mgmt_hdr.node_idx = sta_idx;
309 mgmt_hdr.vif_idx = vif_idx;
312 mgmt_hdr.cookie = slot;
314 mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
315 if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
316 mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
318 mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
320 tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
321 memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
322 tx_ctl->epid = priv->mgmt_ep;
325 return htc_send(priv->htc, skb);
328 static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
329 struct ath9k_htc_sta *ista, u8 tid)
333 spin_lock_bh(&priv->tx.tx_lock);
334 if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
336 spin_unlock_bh(&priv->tx.tx_lock);
341 static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
342 struct ieee80211_vif *vif,
345 struct ieee80211_sta *sta;
346 struct ieee80211_hdr *hdr;
349 hdr = (struct ieee80211_hdr *) skb->data;
350 fc = hdr->frame_control;
354 sta = ieee80211_find_sta(vif, hdr->addr1);
360 if (sta && conf_is_ht(&priv->hw->conf) &&
361 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
362 if (ieee80211_is_data_qos(fc)) {
364 struct ath9k_htc_sta *ista;
366 qc = ieee80211_get_qos_ctl(hdr);
368 ista = (struct ath9k_htc_sta *)sta->drv_priv;
369 if (__ath9k_htc_check_tx_aggr(priv, ista, tid)) {
370 ieee80211_start_tx_ba_session(sta, tid, 0);
371 spin_lock_bh(&priv->tx.tx_lock);
372 ista->tid_state[tid] = AGGR_PROGRESS;
373 spin_unlock_bh(&priv->tx.tx_lock);
381 static void ath9k_htc_tx_process(struct ath9k_htc_priv *priv,
384 struct ieee80211_vif *vif;
385 struct ath9k_htc_tx_ctl *tx_ctl;
386 struct ieee80211_tx_info *tx_info;
390 slot = strip_drv_header(priv, skb);
392 dev_kfree_skb_any(skb);
396 tx_ctl = HTC_SKB_CB(skb);
398 tx_info = IEEE80211_SKB_CB(skb);
399 vif = tx_info->control.vif;
401 memset(&tx_info->status, 0, sizeof(tx_info->status));
404 * URB submission failed for this frame, it never reached
410 tx_info->flags |= IEEE80211_TX_STAT_ACK;
412 ath9k_htc_check_tx_aggr(priv, vif, skb);
415 spin_lock_bh(&priv->tx.tx_lock);
416 if (WARN_ON(--priv->tx.queued_cnt < 0))
417 priv->tx.queued_cnt = 0;
418 spin_unlock_bh(&priv->tx.tx_lock);
420 ath9k_htc_tx_clear_slot(priv, slot);
422 /* Send status to mac80211 */
423 ieee80211_tx_status(priv->hw, skb);
426 void ath9k_tx_tasklet(unsigned long data)
428 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
429 struct sk_buff *skb = NULL;
431 while ((skb = skb_dequeue(&priv->tx.tx_queue)) != NULL) {
432 ath9k_htc_tx_process(priv, skb);
435 /* Wake TX queues if needed */
436 ath9k_htc_check_wake_queues(priv);
439 void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
440 enum htc_endpoint_id ep_id, bool txok)
442 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
443 struct ath9k_htc_tx_ctl *tx_ctl;
445 tx_ctl = HTC_SKB_CB(skb);
448 skb_queue_tail(&priv->tx.tx_queue, skb);
449 tasklet_schedule(&priv->tx_tasklet);
452 int ath9k_tx_init(struct ath9k_htc_priv *priv)
454 skb_queue_head_init(&priv->tx.tx_queue);
458 void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
463 bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
465 struct ath_hw *ah = priv->ah;
466 struct ath_common *common = ath9k_hw_common(ah);
467 struct ath9k_tx_queue_info qi;
470 memset(&qi, 0, sizeof(qi));
471 ATH9K_HTC_INIT_TXQ(subtype);
473 qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
477 if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
478 ath_err(common, "qnum %u out of range, max %zu!\n",
479 qnum, ARRAY_SIZE(priv->hwq_map));
480 ath9k_hw_releasetxqueue(ah, qnum);
484 priv->hwq_map[subtype] = qnum;
488 int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
490 struct ath9k_tx_queue_info qi;
492 memset(&qi, 0, sizeof(qi));
493 ATH9K_HTC_INIT_TXQ(0);
495 return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
503 * Calculate the RX filter to be set in the HW.
505 u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
507 #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
509 struct ath_hw *ah = priv->ah;
512 rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
513 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
514 | ATH9K_RX_FILTER_MCAST;
516 if (priv->rxfilter & FIF_PROBE_REQ)
517 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
520 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
521 * mode interface or when in monitor mode. AP mode does not need this
522 * since it receives all in-BSS frames anyway.
524 if (((ah->opmode != NL80211_IFTYPE_AP) &&
525 (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
527 rfilt |= ATH9K_RX_FILTER_PROM;
529 if (priv->rxfilter & FIF_CONTROL)
530 rfilt |= ATH9K_RX_FILTER_CONTROL;
532 if ((ah->opmode == NL80211_IFTYPE_STATION) &&
533 !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
534 rfilt |= ATH9K_RX_FILTER_MYBEACON;
536 rfilt |= ATH9K_RX_FILTER_BEACON;
538 if (conf_is_ht(&priv->hw->conf)) {
539 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
540 rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
543 if (priv->rxfilter & FIF_PSPOLL)
544 rfilt |= ATH9K_RX_FILTER_PSPOLL;
548 #undef RX_FILTER_PRESERVE
552 * Recv initialization for opmode change.
554 static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
556 struct ath_hw *ah = priv->ah;
559 /* configure rx filter */
560 rfilt = ath9k_htc_calcrxfilter(priv);
561 ath9k_hw_setrxfilter(ah, rfilt);
563 /* calculate and install multicast filter */
564 mfilt[0] = mfilt[1] = ~0;
565 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
568 void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
570 ath9k_hw_rxena(priv->ah);
571 ath9k_htc_opmode_init(priv);
572 ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
573 priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
576 static void ath9k_process_rate(struct ieee80211_hw *hw,
577 struct ieee80211_rx_status *rxs,
578 u8 rx_rate, u8 rs_flags)
580 struct ieee80211_supported_band *sband;
581 enum ieee80211_band band;
584 if (rx_rate & 0x80) {
586 rxs->flag |= RX_FLAG_HT;
587 if (rs_flags & ATH9K_RX_2040)
588 rxs->flag |= RX_FLAG_40MHZ;
589 if (rs_flags & ATH9K_RX_GI)
590 rxs->flag |= RX_FLAG_SHORT_GI;
591 rxs->rate_idx = rx_rate & 0x7f;
595 band = hw->conf.channel->band;
596 sband = hw->wiphy->bands[band];
598 for (i = 0; i < sband->n_bitrates; i++) {
599 if (sband->bitrates[i].hw_value == rx_rate) {
603 if (sband->bitrates[i].hw_value_short == rx_rate) {
605 rxs->flag |= RX_FLAG_SHORTPRE;
612 static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
613 struct ath9k_htc_rxbuf *rxbuf,
614 struct ieee80211_rx_status *rx_status)
617 struct ieee80211_hdr *hdr;
618 struct ieee80211_hw *hw = priv->hw;
619 struct sk_buff *skb = rxbuf->skb;
620 struct ath_common *common = ath9k_hw_common(priv->ah);
621 struct ath_htc_rx_status *rxstatus;
622 int hdrlen, padpos, padsize;
623 int last_rssi = ATH_RSSI_DUMMY_MARKER;
626 if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
627 ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
632 rxstatus = (struct ath_htc_rx_status *)skb->data;
634 if (be16_to_cpu(rxstatus->rs_datalen) -
635 (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
637 "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
638 rxstatus->rs_datalen, skb->len);
642 ath9k_htc_err_stat_rx(priv, rxstatus);
644 /* Get the RX status information */
645 memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
646 skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
648 hdr = (struct ieee80211_hdr *)skb->data;
649 fc = hdr->frame_control;
650 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
652 padpos = ath9k_cmn_padpos(fc);
654 padsize = padpos & 3;
655 if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
656 memmove(skb->data + padsize, skb->data, padpos);
657 skb_pull(skb, padsize);
660 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
662 if (rxbuf->rxstatus.rs_status != 0) {
663 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
664 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
665 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
668 if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
670 } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
671 if (ieee80211_is_ctl(fc))
673 * Sometimes, we get invalid
674 * MIC failures on valid control frames.
675 * Remove these mic errors.
677 rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
679 rx_status->flag |= RX_FLAG_MMIC_ERROR;
683 * Reject error frames with the exception of
684 * decryption and MIC failures. For monitor mode,
685 * we also ignore the CRC error.
687 if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
688 if (rxbuf->rxstatus.rs_status &
689 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
693 if (rxbuf->rxstatus.rs_status &
694 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
700 if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
702 keyix = rxbuf->rxstatus.rs_keyix;
703 if (keyix != ATH9K_RXKEYIX_INVALID) {
704 rx_status->flag |= RX_FLAG_DECRYPTED;
705 } else if (ieee80211_has_protected(fc) &&
706 skb->len >= hdrlen + 4) {
707 keyix = skb->data[hdrlen + 3] >> 6;
708 if (test_bit(keyix, common->keymap))
709 rx_status->flag |= RX_FLAG_DECRYPTED;
713 ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
714 rxbuf->rxstatus.rs_flags);
716 if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
717 !rxbuf->rxstatus.rs_moreaggr)
718 ATH_RSSI_LPF(priv->rx.last_rssi,
719 rxbuf->rxstatus.rs_rssi);
721 last_rssi = priv->rx.last_rssi;
723 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
724 rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
725 ATH_RSSI_EP_MULTIPLIER);
727 if (rxbuf->rxstatus.rs_rssi < 0)
728 rxbuf->rxstatus.rs_rssi = 0;
730 if (ieee80211_is_beacon(fc))
731 priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
733 rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
734 rx_status->band = hw->conf.channel->band;
735 rx_status->freq = hw->conf.channel->center_freq;
736 rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
737 rx_status->antenna = rxbuf->rxstatus.rs_antenna;
738 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
747 * FIXME: Handle FLUSH later on.
749 void ath9k_rx_tasklet(unsigned long data)
751 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
752 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
753 struct ieee80211_rx_status rx_status;
756 struct ieee80211_hdr *hdr;
759 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
760 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
761 if (tmp_buf->in_process) {
768 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
775 if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
776 dev_kfree_skb_any(rxbuf->skb);
780 memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
781 sizeof(struct ieee80211_rx_status));
783 hdr = (struct ieee80211_hdr *) skb->data;
785 if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
786 ieee80211_queue_work(priv->hw, &priv->ps_work);
788 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
790 ieee80211_rx(priv->hw, skb);
792 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
794 rxbuf->in_process = false;
796 list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
798 spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
803 void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
804 enum htc_endpoint_id ep_id)
806 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
807 struct ath_hw *ah = priv->ah;
808 struct ath_common *common = ath9k_hw_common(ah);
809 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
811 spin_lock(&priv->rx.rxbuflock);
812 list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
813 if (!tmp_buf->in_process) {
818 spin_unlock(&priv->rx.rxbuflock);
821 ath_dbg(common, ATH_DBG_ANY,
822 "No free RX buffer\n");
826 spin_lock(&priv->rx.rxbuflock);
828 rxbuf->in_process = true;
829 spin_unlock(&priv->rx.rxbuflock);
831 tasklet_schedule(&priv->rx_tasklet);
834 dev_kfree_skb_any(skb);
837 /* FIXME: Locking for cleanup/init */
839 void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
841 struct ath9k_htc_rxbuf *rxbuf, *tbuf;
843 list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
844 list_del(&rxbuf->list);
846 dev_kfree_skb_any(rxbuf->skb);
851 int ath9k_rx_init(struct ath9k_htc_priv *priv)
853 struct ath_hw *ah = priv->ah;
854 struct ath_common *common = ath9k_hw_common(ah);
855 struct ath9k_htc_rxbuf *rxbuf;
858 INIT_LIST_HEAD(&priv->rx.rxbuf);
859 spin_lock_init(&priv->rx.rxbuflock);
861 for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
862 rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
864 ath_err(common, "Unable to allocate RX buffers\n");
867 list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
873 ath9k_rx_cleanup(priv);