Merge branch 'master' of git://git.infradead.org/users/linville/wireless
[linux-2.6-block.git] / drivers / net / wireless / ath / ath9k / recv.c
index 70dc8ecdad4d7994caf7083dbe7e2cc1a9101f5b..49843500fe7cd5faafd5f809fcf5515b2e50b4ab 100644 (file)
@@ -205,14 +205,22 @@ static void ath_rx_remove_buffer(struct ath_softc *sc,
 
 static void ath_rx_edma_cleanup(struct ath_softc *sc)
 {
+       struct ath_hw *ah = sc->sc_ah;
+       struct ath_common *common = ath9k_hw_common(ah);
        struct ath_buf *bf;
 
        ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
        ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
 
        list_for_each_entry(bf, &sc->rx.rxbuf, list) {
-               if (bf->bf_mpdu)
+               if (bf->bf_mpdu) {
+                       dma_unmap_single(sc->dev, bf->bf_buf_addr,
+                                       common->rx_bufsize,
+                                       DMA_BIDIRECTIONAL);
                        dev_kfree_skb_any(bf->bf_mpdu);
+                       bf->bf_buf_addr = 0;
+                       bf->bf_mpdu = NULL;
+               }
        }
 
        INIT_LIST_HEAD(&sc->rx.rxbuf);
@@ -601,7 +609,6 @@ static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
                ath_dbg(common, ATH_DBG_PS,
                        "Reconfigure Beacon timers based on timestamp from the AP\n");
                ath_set_beacon(sc);
-               sc->ps_flags &= ~PS_TSFOOR_SYNC;
        }
 
        if (ath_beacon_dtim_pending_cab(skb)) {
@@ -762,7 +769,7 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
         * on.  All this is necessary because of our use of
         * a self-linked list to avoid rx overruns.
         */
-       ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
+       ret = ath9k_hw_rxprocdesc(ah, ds, rs);
        if (ret == -EINPROGRESS) {
                struct ath_rx_status trs;
                struct ath_buf *tbf;
@@ -788,7 +795,7 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
                 */
 
                tds = tbf->bf_desc;
-               ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
+               ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
                if (ret == -EINPROGRESS)
                        return NULL;
        }
@@ -815,16 +822,20 @@ static bool ath9k_rx_accept(struct ath_common *common,
                            struct ath_rx_status *rx_stats,
                            bool *decrypt_error)
 {
-#define is_mc_or_valid_tkip_keyix ((is_mc ||                   \
-               (rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \
-               test_bit(rx_stats->rs_keyix, common->tkip_keymap))))
-
+       bool is_mc, is_valid_tkip, strip_mic, mic_error;
        struct ath_hw *ah = common->ah;
        __le16 fc;
        u8 rx_status_len = ah->caps.rx_status_len;
 
        fc = hdr->frame_control;
 
+       is_mc = !!is_multicast_ether_addr(hdr->addr1);
+       is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
+               test_bit(rx_stats->rs_keyix, common->tkip_keymap);
+       strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
+               !(rx_stats->rs_status &
+               (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC));
+
        if (!rx_stats->rs_datalen)
                return false;
         /*
@@ -839,6 +850,11 @@ static bool ath9k_rx_accept(struct ath_common *common,
        if (rx_stats->rs_more)
                return true;
 
+       mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
+               !ieee80211_has_morefrags(fc) &&
+               !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
+               (rx_stats->rs_status & ATH9K_RXERR_MIC);
+
        /*
         * The rx_stats->rs_status will not be set until the end of the
         * chained descriptors so it can be ignored if rs_more is set. The
@@ -846,30 +862,18 @@ static bool ath9k_rx_accept(struct ath_common *common,
         * descriptors.
         */
        if (rx_stats->rs_status != 0) {
-               if (rx_stats->rs_status & ATH9K_RXERR_CRC)
+               if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
                        rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
+                       mic_error = false;
+               }
                if (rx_stats->rs_status & ATH9K_RXERR_PHY)
                        return false;
 
                if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
                        *decrypt_error = true;
-               } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
-                       bool is_mc;
-                       /*
-                        * The MIC error bit is only valid if the frame
-                        * is not a control frame or fragment, and it was
-                        * decrypted using a valid TKIP key.
-                        */
-                       is_mc = !!is_multicast_ether_addr(hdr->addr1);
-
-                       if (!ieee80211_is_ctl(fc) &&
-                           !ieee80211_has_morefrags(fc) &&
-                           !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
-                           is_mc_or_valid_tkip_keyix)
-                               rxs->flag |= RX_FLAG_MMIC_ERROR;
-                       else
-                               rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
+                       mic_error = false;
                }
+
                /*
                 * Reject error frames with the exception of
                 * decryption and MIC failures. For monitor mode,
@@ -887,6 +891,18 @@ static bool ath9k_rx_accept(struct ath_common *common,
                        }
                }
        }
+
+       /*
+        * For unicast frames the MIC error bit can have false positives,
+        * so all MIC error reports need to be validated in software.
+        * False negatives are not common, so skip software verification
+        * if the hardware considers the MIC valid.
+        */
+       if (strip_mic)
+               rxs->flag |= RX_FLAG_MMIC_STRIPPED;
+       else if (is_mc && mic_error)
+               rxs->flag |= RX_FLAG_MMIC_ERROR;
+
        return true;
 }
 
@@ -929,7 +945,7 @@ static int ath9k_process_rate(struct ath_common *common,
         * No valid hardware bitrate found -- we should not get here
         * because hardware has already validated this frame as OK.
         */
-       ath_dbg(common, ATH_DBG_XMIT,
+       ath_dbg(common, ATH_DBG_ANY,
                "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
                rx_stats->rs_rate);
 
@@ -944,22 +960,11 @@ static void ath9k_process_rssi(struct ath_common *common,
        struct ath_softc *sc = hw->priv;
        struct ath_hw *ah = common->ah;
        int last_rssi;
-       __le16 fc;
-
-       if ((ah->opmode != NL80211_IFTYPE_STATION) &&
-           (ah->opmode != NL80211_IFTYPE_ADHOC))
-               return;
 
-       fc = hdr->frame_control;
-       if (!ieee80211_is_beacon(fc) ||
-           compare_ether_addr(hdr->addr3, common->curbssid)) {
-               /* TODO:  This doesn't work well if you have stations
-                * associated to two different APs because curbssid
-                * is just the last AP that any of the stations associated
-                * with.
-                */
+       if (!rx_stats->is_mybeacon ||
+           ((ah->opmode != NL80211_IFTYPE_STATION) &&
+            (ah->opmode != NL80211_IFTYPE_ADHOC)))
                return;
-       }
 
        if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
                ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
@@ -987,6 +992,8 @@ static int ath9k_rx_skb_preprocess(struct ath_common *common,
                                   struct ieee80211_rx_status *rx_status,
                                   bool *decrypt_error)
 {
+       struct ath_hw *ah = common->ah;
+
        memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
 
        /*
@@ -1007,7 +1014,7 @@ static int ath9k_rx_skb_preprocess(struct ath_common *common,
 
        rx_status->band = hw->conf.channel->band;
        rx_status->freq = hw->conf.channel->center_freq;
-       rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
+       rx_status->signal = ah->noise + rx_stats->rs_rssi;
        rx_status->antenna = rx_stats->rs_antenna;
        rx_status->flag |= RX_FLAG_MACTIME_MPDU;
 
@@ -1775,11 +1782,6 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
        struct ieee80211_rx_status *rxs;
        struct ath_hw *ah = sc->sc_ah;
        struct ath_common *common = ath9k_hw_common(ah);
-       /*
-        * The hw can technically differ from common->hw when using ath9k
-        * virtual wiphy so to account for that we iterate over the active
-        * wiphys and find the appropriate wiphy and therefore hw.
-        */
        struct ieee80211_hw *hw = sc->hw;
        struct ieee80211_hdr *hdr;
        int retval;
@@ -1833,6 +1835,11 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
 
                hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
                rxs = IEEE80211_SKB_RXCB(hdr_skb);
+               if (ieee80211_is_beacon(hdr->frame_control) &&
+                   !compare_ether_addr(hdr->addr3, common->curbssid))
+                       rs.is_mybeacon = true;
+               else
+                       rs.is_mybeacon = false;
 
                ath_debug_stat_rx(sc, &rs);
 
@@ -1840,7 +1847,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
                 * If we're asked to flush receive queue, directly
                 * chain it back at the queue without processing it.
                 */
-               if (flush)
+               if (sc->sc_flags & SC_OP_RXFLUSH)
                        goto requeue_drop_frag;
 
                retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
@@ -1939,6 +1946,9 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
                        sc->rx.rxotherant = 0;
                }
 
+               if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
+                       skb_trim(skb, skb->len - 8);
+
                spin_lock_irqsave(&sc->sc_pm_lock, flags);
 
                if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
@@ -1948,7 +1958,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
                        ath_rx_ps(sc, skb);
                spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
 
-               if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
+               if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
                        ath_ant_comb_scan(sc, &rs);
 
                ieee80211_rx(hw, skb);
@@ -1965,11 +1975,17 @@ requeue:
                } else {
                        list_move_tail(&bf->list, &sc->rx.rxbuf);
                        ath_rx_buf_link(sc, bf);
-                       ath9k_hw_rxena(ah);
+                       if (!flush)
+                               ath9k_hw_rxena(ah);
                }
        } while (1);
 
        spin_unlock_bh(&sc->rx.rxbuflock);
 
+       if (!(ah->imask & ATH9K_INT_RXEOL)) {
+               ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
+               ath9k_hw_set_interrupts(ah, ah->imask);
+       }
+
        return 0;
 }