ath9k: fix signal strength reporting issues
[pandora-kernel.git] / drivers / net / wireless / ath / ath9k / recv.c
index 0e666fb..1b1b279 100644 (file)
@@ -169,22 +169,17 @@ static void ath_rx_addbuffer_edma(struct ath_softc *sc,
                                  enum ath9k_rx_qtype qtype, int size)
 {
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       u32 nbuf = 0;
+       struct ath_buf *bf, *tbf;
 
        if (list_empty(&sc->rx.rxbuf)) {
                ath_dbg(common, QUEUE, "No free rx buf available\n");
                return;
        }
 
-       while (!list_empty(&sc->rx.rxbuf)) {
-               nbuf++;
-
+       list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
                if (!ath_rx_edma_buf_link(sc, qtype))
                        break;
 
-               if (nbuf >= size)
-                       break;
-       }
 }
 
 static void ath_rx_remove_buffer(struct ath_softc *sc,
@@ -232,7 +227,6 @@ static void ath_rx_edma_cleanup(struct ath_softc *sc)
 static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
 {
        skb_queue_head_init(&rx_edma->rx_fifo);
-       skb_queue_head_init(&rx_edma->rx_buffers);
        rx_edma->rx_fifo_hwsize = size;
 }
 
@@ -658,7 +652,9 @@ static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
 }
 
 static bool ath_edma_get_buffers(struct ath_softc *sc,
-                                enum ath9k_rx_qtype qtype)
+                                enum ath9k_rx_qtype qtype,
+                                struct ath_rx_status *rs,
+                                struct ath_buf **dest)
 {
        struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
        struct ath_hw *ah = sc->sc_ah;
@@ -677,7 +673,7 @@ static bool ath_edma_get_buffers(struct ath_softc *sc,
        dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
                                common->rx_bufsize, DMA_FROM_DEVICE);
 
-       ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
+       ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
        if (ret == -EINPROGRESS) {
                /*let device gain the buffer again*/
                dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
@@ -690,20 +686,21 @@ static bool ath_edma_get_buffers(struct ath_softc *sc,
                /* corrupt descriptor, skip this one and the following one */
                list_add_tail(&bf->list, &sc->rx.rxbuf);
                ath_rx_edma_buf_link(sc, qtype);
-               skb = skb_peek(&rx_edma->rx_fifo);
-               if (!skb)
-                       return true;
 
-               bf = SKB_CB_ATHBUF(skb);
-               BUG_ON(!bf);
+               skb = skb_peek(&rx_edma->rx_fifo);
+               if (skb) {
+                       bf = SKB_CB_ATHBUF(skb);
+                       BUG_ON(!bf);
 
-               __skb_unlink(skb, &rx_edma->rx_fifo);
-               list_add_tail(&bf->list, &sc->rx.rxbuf);
-               ath_rx_edma_buf_link(sc, qtype);
-               return true;
+                       __skb_unlink(skb, &rx_edma->rx_fifo);
+                       list_add_tail(&bf->list, &sc->rx.rxbuf);
+                       ath_rx_edma_buf_link(sc, qtype);
+               } else {
+                       bf = NULL;
+               }
        }
-       skb_queue_tail(&rx_edma->rx_buffers, skb);
 
+       *dest = bf;
        return true;
 }
 
@@ -711,18 +708,15 @@ static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
                                                struct ath_rx_status *rs,
                                                enum ath9k_rx_qtype qtype)
 {
-       struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
-       struct sk_buff *skb;
-       struct ath_buf *bf;
+       struct ath_buf *bf = NULL;
 
-       while (ath_edma_get_buffers(sc, qtype));
-       skb = __skb_dequeue(&rx_edma->rx_buffers);
-       if (!skb)
-               return NULL;
+       while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
+               if (!bf)
+                       continue;
 
-       bf = SKB_CB_ATHBUF(skb);
-       ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
-       return bf;
+               return bf;
+       }
+       return NULL;
 }
 
 static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
@@ -822,6 +816,14 @@ static bool ath9k_rx_accept(struct ath_common *common,
                (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
                 ATH9K_RXERR_KEYMISS));
 
+       /*
+        * Key miss events are only relevant for pairwise keys where the
+        * descriptor does contain a valid key index. This has been observed
+        * mostly with CCMP encryption.
+        */
+       if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID)
+               rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
+
        if (!rx_stats->rs_datalen)
                return false;
         /*
@@ -946,6 +948,7 @@ static void ath9k_process_rssi(struct ath_common *common,
        struct ath_softc *sc = hw->priv;
        struct ath_hw *ah = common->ah;
        int last_rssi;
+       int rssi = rx_stats->rs_rssi;
 
        if (!rx_stats->is_mybeacon ||
            ((ah->opmode != NL80211_IFTYPE_STATION) &&
@@ -957,13 +960,12 @@ static void ath9k_process_rssi(struct ath_common *common,
 
        last_rssi = sc->last_rssi;
        if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
-               rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
-                                             ATH_RSSI_EP_MULTIPLIER);
-       if (rx_stats->rs_rssi < 0)
-               rx_stats->rs_rssi = 0;
+               rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
+       if (rssi < 0)
+               rssi = 0;
 
        /* Update Beacon RSSI, this is used by ANI. */
-       ah->stats.avgbrssi = rx_stats->rs_rssi;
+       ah->stats.avgbrssi = rssi;
 }
 
 /*
@@ -1003,6 +1005,8 @@ static int ath9k_rx_skb_preprocess(struct ath_common *common,
        rx_status->signal = ah->noise + rx_stats->rs_rssi;
        rx_status->antenna = rx_stats->rs_antenna;
        rx_status->flag |= RX_FLAG_MACTIME_MPDU;
+       if (rx_stats->rs_moreaggr)
+               rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
 
        return 0;
 }