Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 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. |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 17 | #include "ath9k.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 18 | #include "ar9003_mac.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 19 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 20 | #define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb)) |
| 21 | |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 22 | static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta, |
| 23 | int mindelta, int main_rssi_avg, |
| 24 | int alt_rssi_avg, int pkt_count) |
| 25 | { |
| 26 | return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) && |
| 27 | (alt_rssi_avg > main_rssi_avg + maxdelta)) || |
| 28 | (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50); |
| 29 | } |
| 30 | |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 31 | static inline bool ath9k_check_auto_sleep(struct ath_softc *sc) |
| 32 | { |
| 33 | return sc->ps_enabled && |
| 34 | (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP); |
| 35 | } |
| 36 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 37 | /* |
| 38 | * Setup and link descriptors. |
| 39 | * |
| 40 | * 11N: we can no longer afford to self link the last descriptor. |
| 41 | * MAC acknowledges BA status as long as it copies frames to host |
| 42 | * buffer (or rx fifo). This can incorrectly acknowledge packets |
| 43 | * to a sender if last desc is self-linked. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 44 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 45 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) |
| 46 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 47 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 48 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 49 | struct ath_desc *ds; |
| 50 | struct sk_buff *skb; |
| 51 | |
| 52 | ATH_RXBUF_RESET(bf); |
| 53 | |
| 54 | ds = bf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 55 | ds->ds_link = 0; /* link to null */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 56 | ds->ds_data = bf->bf_buf_addr; |
| 57 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 58 | /* virtual addr of the beginning of the buffer. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 59 | skb = bf->bf_mpdu; |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 60 | BUG_ON(skb == NULL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 61 | ds->ds_vdata = skb->data; |
| 62 | |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 63 | /* |
| 64 | * setup rx descriptors. The rx_bufsize here tells the hardware |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 65 | * how much data it can DMA to us and that we are prepared |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 66 | * to process |
| 67 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 68 | ath9k_hw_setuprxdesc(ah, ds, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 69 | common->rx_bufsize, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 70 | 0); |
| 71 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 72 | if (sc->rx.rxlink == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 73 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
| 74 | else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 75 | *sc->rx.rxlink = bf->bf_daddr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 76 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 77 | sc->rx.rxlink = &ds->ds_link; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 80 | static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) |
| 81 | { |
| 82 | /* XXX block beacon interrupts */ |
| 83 | ath9k_hw_setantenna(sc->sc_ah, antenna); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 84 | sc->rx.defant = antenna; |
| 85 | sc->rx.rxotherant = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 86 | } |
| 87 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 88 | static void ath_opmode_init(struct ath_softc *sc) |
| 89 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 90 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 91 | struct ath_common *common = ath9k_hw_common(ah); |
| 92 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 93 | u32 rfilt, mfilt[2]; |
| 94 | |
| 95 | /* configure rx filter */ |
| 96 | rfilt = ath_calcrxfilter(sc); |
| 97 | ath9k_hw_setrxfilter(ah, rfilt); |
| 98 | |
| 99 | /* configure bssid mask */ |
Felix Fietkau | 364734f | 2010-09-14 20:22:44 +0200 | [diff] [blame] | 100 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 101 | |
| 102 | /* configure operational mode */ |
| 103 | ath9k_hw_setopmode(ah); |
| 104 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 105 | /* calculate and install multicast filter */ |
| 106 | mfilt[0] = mfilt[1] = ~0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 107 | ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 110 | static bool ath_rx_edma_buf_link(struct ath_softc *sc, |
| 111 | enum ath9k_rx_qtype qtype) |
| 112 | { |
| 113 | struct ath_hw *ah = sc->sc_ah; |
| 114 | struct ath_rx_edma *rx_edma; |
| 115 | struct sk_buff *skb; |
| 116 | struct ath_buf *bf; |
| 117 | |
| 118 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 119 | if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize) |
| 120 | return false; |
| 121 | |
| 122 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
| 123 | list_del_init(&bf->list); |
| 124 | |
| 125 | skb = bf->bf_mpdu; |
| 126 | |
| 127 | ATH_RXBUF_RESET(bf); |
| 128 | memset(skb->data, 0, ah->caps.rx_status_len); |
| 129 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 130 | ah->caps.rx_status_len, DMA_TO_DEVICE); |
| 131 | |
| 132 | SKB_CB_ATHBUF(skb) = bf; |
| 133 | ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype); |
| 134 | skb_queue_tail(&rx_edma->rx_fifo, skb); |
| 135 | |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | static void ath_rx_addbuffer_edma(struct ath_softc *sc, |
| 140 | enum ath9k_rx_qtype qtype, int size) |
| 141 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 142 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 143 | u32 nbuf = 0; |
| 144 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 145 | if (list_empty(&sc->rx.rxbuf)) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 146 | ath_dbg(common, ATH_DBG_QUEUE, "No free rx buf available\n"); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | |
| 150 | while (!list_empty(&sc->rx.rxbuf)) { |
| 151 | nbuf++; |
| 152 | |
| 153 | if (!ath_rx_edma_buf_link(sc, qtype)) |
| 154 | break; |
| 155 | |
| 156 | if (nbuf >= size) |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | static void ath_rx_remove_buffer(struct ath_softc *sc, |
| 162 | enum ath9k_rx_qtype qtype) |
| 163 | { |
| 164 | struct ath_buf *bf; |
| 165 | struct ath_rx_edma *rx_edma; |
| 166 | struct sk_buff *skb; |
| 167 | |
| 168 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 169 | |
| 170 | while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) { |
| 171 | bf = SKB_CB_ATHBUF(skb); |
| 172 | BUG_ON(!bf); |
| 173 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | static void ath_rx_edma_cleanup(struct ath_softc *sc) |
| 178 | { |
| 179 | struct ath_buf *bf; |
| 180 | |
| 181 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
| 182 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 183 | |
| 184 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 185 | if (bf->bf_mpdu) |
| 186 | dev_kfree_skb_any(bf->bf_mpdu); |
| 187 | } |
| 188 | |
| 189 | INIT_LIST_HEAD(&sc->rx.rxbuf); |
| 190 | |
| 191 | kfree(sc->rx.rx_bufptr); |
| 192 | sc->rx.rx_bufptr = NULL; |
| 193 | } |
| 194 | |
| 195 | static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size) |
| 196 | { |
| 197 | skb_queue_head_init(&rx_edma->rx_fifo); |
| 198 | skb_queue_head_init(&rx_edma->rx_buffers); |
| 199 | rx_edma->rx_fifo_hwsize = size; |
| 200 | } |
| 201 | |
| 202 | static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) |
| 203 | { |
| 204 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 205 | struct ath_hw *ah = sc->sc_ah; |
| 206 | struct sk_buff *skb; |
| 207 | struct ath_buf *bf; |
| 208 | int error = 0, i; |
| 209 | u32 size; |
| 210 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 211 | ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize - |
| 212 | ah->caps.rx_status_len); |
| 213 | |
| 214 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP], |
| 215 | ah->caps.rx_lp_qdepth); |
| 216 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP], |
| 217 | ah->caps.rx_hp_qdepth); |
| 218 | |
| 219 | size = sizeof(struct ath_buf) * nbufs; |
| 220 | bf = kzalloc(size, GFP_KERNEL); |
| 221 | if (!bf) |
| 222 | return -ENOMEM; |
| 223 | |
| 224 | INIT_LIST_HEAD(&sc->rx.rxbuf); |
| 225 | sc->rx.rx_bufptr = bf; |
| 226 | |
| 227 | for (i = 0; i < nbufs; i++, bf++) { |
| 228 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL); |
| 229 | if (!skb) { |
| 230 | error = -ENOMEM; |
| 231 | goto rx_init_fail; |
| 232 | } |
| 233 | |
| 234 | memset(skb->data, 0, common->rx_bufsize); |
| 235 | bf->bf_mpdu = skb; |
| 236 | |
| 237 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 238 | common->rx_bufsize, |
| 239 | DMA_BIDIRECTIONAL); |
| 240 | if (unlikely(dma_mapping_error(sc->dev, |
| 241 | bf->bf_buf_addr))) { |
| 242 | dev_kfree_skb_any(skb); |
| 243 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 244 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 245 | ath_err(common, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 246 | "dma_mapping_error() on RX init\n"); |
| 247 | error = -ENOMEM; |
| 248 | goto rx_init_fail; |
| 249 | } |
| 250 | |
| 251 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 252 | } |
| 253 | |
| 254 | return 0; |
| 255 | |
| 256 | rx_init_fail: |
| 257 | ath_rx_edma_cleanup(sc); |
| 258 | return error; |
| 259 | } |
| 260 | |
| 261 | static void ath_edma_start_recv(struct ath_softc *sc) |
| 262 | { |
| 263 | spin_lock_bh(&sc->rx.rxbuflock); |
| 264 | |
| 265 | ath9k_hw_rxena(sc->sc_ah); |
| 266 | |
| 267 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP, |
| 268 | sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize); |
| 269 | |
| 270 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP, |
| 271 | sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize); |
| 272 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 273 | ath_opmode_init(sc); |
| 274 | |
Luis R. Rodriguez | 48a6a46 | 2010-09-16 15:12:28 -0400 | [diff] [blame] | 275 | ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL)); |
Luis R. Rodriguez | 7583c550 | 2010-10-20 16:07:04 -0700 | [diff] [blame] | 276 | |
| 277 | spin_unlock_bh(&sc->rx.rxbuflock); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | static void ath_edma_stop_recv(struct ath_softc *sc) |
| 281 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 282 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 283 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 286 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
| 287 | { |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 288 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 289 | struct sk_buff *skb; |
| 290 | struct ath_buf *bf; |
| 291 | int error = 0; |
| 292 | |
Luis R. Rodriguez | 4bdd1e9 | 2010-10-26 15:27:24 -0700 | [diff] [blame] | 293 | spin_lock_init(&sc->sc_pcu_lock); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 294 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
| 295 | spin_lock_init(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 296 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 297 | common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 + |
| 298 | sc->sc_ah->caps.rx_status_len; |
| 299 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 300 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 301 | return ath_rx_edma_init(sc, nbufs); |
| 302 | } else { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 303 | ath_dbg(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", |
| 304 | common->cachelsz, common->rx_bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 305 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 306 | /* Initialize rx descriptors */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 307 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 308 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 309 | "rx", nbufs, 1, 0); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 310 | if (error != 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 311 | ath_err(common, |
| 312 | "failed to allocate rx descriptors: %d\n", |
| 313 | error); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 314 | goto err; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 315 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 316 | |
| 317 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 318 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, |
| 319 | GFP_KERNEL); |
| 320 | if (skb == NULL) { |
| 321 | error = -ENOMEM; |
| 322 | goto err; |
| 323 | } |
| 324 | |
| 325 | bf->bf_mpdu = skb; |
| 326 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 327 | common->rx_bufsize, |
| 328 | DMA_FROM_DEVICE); |
| 329 | if (unlikely(dma_mapping_error(sc->dev, |
| 330 | bf->bf_buf_addr))) { |
| 331 | dev_kfree_skb_any(skb); |
| 332 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 333 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 334 | ath_err(common, |
| 335 | "dma_mapping_error() on RX init\n"); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 336 | error = -ENOMEM; |
| 337 | goto err; |
| 338 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 339 | } |
| 340 | sc->rx.rxlink = NULL; |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 341 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 342 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 343 | err: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 344 | if (error) |
| 345 | ath_rx_cleanup(sc); |
| 346 | |
| 347 | return error; |
| 348 | } |
| 349 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 350 | void ath_rx_cleanup(struct ath_softc *sc) |
| 351 | { |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 352 | struct ath_hw *ah = sc->sc_ah; |
| 353 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 354 | struct sk_buff *skb; |
| 355 | struct ath_buf *bf; |
| 356 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 357 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 358 | ath_rx_edma_cleanup(sc); |
| 359 | return; |
| 360 | } else { |
| 361 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 362 | skb = bf->bf_mpdu; |
| 363 | if (skb) { |
| 364 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
| 365 | common->rx_bufsize, |
| 366 | DMA_FROM_DEVICE); |
| 367 | dev_kfree_skb(skb); |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 368 | bf->bf_buf_addr = 0; |
| 369 | bf->bf_mpdu = NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 370 | } |
Luis R. Rodriguez | 051b919 | 2009-03-23 18:25:01 -0400 | [diff] [blame] | 371 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 372 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 373 | if (sc->rx.rxdma.dd_desc_len != 0) |
| 374 | ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf); |
| 375 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Calculate the receive filter according to the |
| 380 | * operating mode and state: |
| 381 | * |
| 382 | * o always accept unicast, broadcast, and multicast traffic |
| 383 | * o maintain current state of phy error reception (the hal |
| 384 | * may enable phy error frames for noise immunity work) |
| 385 | * o probe request frames are accepted only when operating in |
| 386 | * hostap, adhoc, or monitor modes |
| 387 | * o enable promiscuous mode according to the interface state |
| 388 | * o accept beacons: |
| 389 | * - when operating in adhoc mode so the 802.11 layer creates |
| 390 | * node table entries for peers, |
| 391 | * - when operating in station mode for collecting rssi data when |
| 392 | * the station is otherwise quiet, or |
| 393 | * - when operating as a repeater so we see repeater-sta beacons |
| 394 | * - when scanning |
| 395 | */ |
| 396 | |
| 397 | u32 ath_calcrxfilter(struct ath_softc *sc) |
| 398 | { |
| 399 | #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR) |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 400 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 401 | u32 rfilt; |
| 402 | |
| 403 | rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE) |
| 404 | | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST |
| 405 | | ATH9K_RX_FILTER_MCAST; |
| 406 | |
Jouni Malinen | 9c1d8e4 | 2010-10-13 17:29:31 +0300 | [diff] [blame] | 407 | if (sc->rx.rxfilter & FIF_PROBE_REQ) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 408 | rfilt |= ATH9K_RX_FILTER_PROBEREQ; |
| 409 | |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 410 | /* |
| 411 | * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station |
| 412 | * mode interface or when in monitor mode. AP mode does not need this |
| 413 | * since it receives all in-BSS frames anyway. |
| 414 | */ |
Felix Fietkau | 2e28694 | 2011-03-09 01:48:12 +0100 | [diff] [blame] | 415 | if (sc->sc_ah->is_monitoring) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 416 | rfilt |= ATH9K_RX_FILTER_PROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 417 | |
Sujith | d42c6b7 | 2009-02-04 08:10:22 +0530 | [diff] [blame] | 418 | if (sc->rx.rxfilter & FIF_CONTROL) |
| 419 | rfilt |= ATH9K_RX_FILTER_CONTROL; |
| 420 | |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 421 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) && |
Ben Greear | cfda669 | 2010-09-14 12:00:22 -0700 | [diff] [blame] | 422 | (sc->nvifs <= 1) && |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 423 | !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC)) |
| 424 | rfilt |= ATH9K_RX_FILTER_MYBEACON; |
| 425 | else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 426 | rfilt |= ATH9K_RX_FILTER_BEACON; |
| 427 | |
Felix Fietkau | 264bbec | 2011-04-07 19:24:23 +0200 | [diff] [blame] | 428 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || |
Senthil Balasubramanian | 66afad0 | 2009-09-18 15:06:07 +0530 | [diff] [blame] | 429 | (sc->rx.rxfilter & FIF_PSPOLL)) |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 430 | rfilt |= ATH9K_RX_FILTER_PSPOLL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 431 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 432 | if (conf_is_ht(&sc->hw->conf)) |
| 433 | rfilt |= ATH9K_RX_FILTER_COMP_BAR; |
| 434 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 435 | if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) { |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 436 | /* The following may also be needed for other older chips */ |
| 437 | if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160) |
| 438 | rfilt |= ATH9K_RX_FILTER_PROM; |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 439 | rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL; |
| 440 | } |
| 441 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 442 | return rfilt; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 443 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 444 | #undef RX_FILTER_PRESERVE |
| 445 | } |
| 446 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 447 | int ath_startrecv(struct ath_softc *sc) |
| 448 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 449 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 450 | struct ath_buf *bf, *tbf; |
| 451 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 452 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 453 | ath_edma_start_recv(sc); |
| 454 | return 0; |
| 455 | } |
| 456 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 457 | spin_lock_bh(&sc->rx.rxbuflock); |
| 458 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 459 | goto start_recv; |
| 460 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 461 | sc->rx.rxlink = NULL; |
| 462 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 463 | ath_rx_buf_link(sc, bf); |
| 464 | } |
| 465 | |
| 466 | /* We could have deleted elements so the list may be empty now */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 467 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 468 | goto start_recv; |
| 469 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 470 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 471 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 472 | ath9k_hw_rxena(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 473 | |
| 474 | start_recv: |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 475 | ath_opmode_init(sc); |
Luis R. Rodriguez | 48a6a46 | 2010-09-16 15:12:28 -0400 | [diff] [blame] | 476 | ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL)); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 477 | |
Luis R. Rodriguez | 7583c550 | 2010-10-20 16:07:04 -0700 | [diff] [blame] | 478 | spin_unlock_bh(&sc->rx.rxbuflock); |
| 479 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 480 | return 0; |
| 481 | } |
| 482 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 483 | bool ath_stoprecv(struct ath_softc *sc) |
| 484 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 485 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 486 | bool stopped; |
| 487 | |
Luis R. Rodriguez | 1e45028 | 2010-10-20 16:07:03 -0700 | [diff] [blame] | 488 | spin_lock_bh(&sc->rx.rxbuflock); |
Felix Fietkau | d47844a | 2010-11-20 03:08:47 +0100 | [diff] [blame] | 489 | ath9k_hw_abortpcurecv(ah); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 490 | ath9k_hw_setrxfilter(ah, 0); |
| 491 | stopped = ath9k_hw_stopdmarecv(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 492 | |
| 493 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 494 | ath_edma_stop_recv(sc); |
| 495 | else |
| 496 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | 1e45028 | 2010-10-20 16:07:03 -0700 | [diff] [blame] | 497 | spin_unlock_bh(&sc->rx.rxbuflock); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 498 | |
Rajkumar Manoharan | d584747 | 2010-12-20 14:39:51 +0530 | [diff] [blame] | 499 | if (!(ah->ah_flags & AH_UNPLUGGED) && |
| 500 | unlikely(!stopped)) { |
Ben Greear | d7fd1b50 | 2010-12-06 13:13:07 -0800 | [diff] [blame] | 501 | ath_err(ath9k_hw_common(sc->sc_ah), |
| 502 | "Could not stop RX, we could be " |
| 503 | "confusing the DMA engine when we start RX up\n"); |
| 504 | ATH_DBG_WARN_ON_ONCE(!stopped); |
| 505 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 506 | return stopped; |
| 507 | } |
| 508 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 509 | void ath_flushrecv(struct ath_softc *sc) |
| 510 | { |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 511 | sc->sc_flags |= SC_OP_RXFLUSH; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 512 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 513 | ath_rx_tasklet(sc, 1, true); |
| 514 | ath_rx_tasklet(sc, 1, false); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 515 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 518 | static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) |
| 519 | { |
| 520 | /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */ |
| 521 | struct ieee80211_mgmt *mgmt; |
| 522 | u8 *pos, *end, id, elen; |
| 523 | struct ieee80211_tim_ie *tim; |
| 524 | |
| 525 | mgmt = (struct ieee80211_mgmt *)skb->data; |
| 526 | pos = mgmt->u.beacon.variable; |
| 527 | end = skb->data + skb->len; |
| 528 | |
| 529 | while (pos + 2 < end) { |
| 530 | id = *pos++; |
| 531 | elen = *pos++; |
| 532 | if (pos + elen > end) |
| 533 | break; |
| 534 | |
| 535 | if (id == WLAN_EID_TIM) { |
| 536 | if (elen < sizeof(*tim)) |
| 537 | break; |
| 538 | tim = (struct ieee80211_tim_ie *) pos; |
| 539 | if (tim->dtim_count != 0) |
| 540 | break; |
| 541 | return tim->bitmap_ctrl & 0x01; |
| 542 | } |
| 543 | |
| 544 | pos += elen; |
| 545 | } |
| 546 | |
| 547 | return false; |
| 548 | } |
| 549 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 550 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) |
| 551 | { |
| 552 | struct ieee80211_mgmt *mgmt; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 553 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 554 | |
| 555 | if (skb->len < 24 + 8 + 2 + 2) |
| 556 | return; |
| 557 | |
| 558 | mgmt = (struct ieee80211_mgmt *)skb->data; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 559 | if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) { |
| 560 | /* TODO: This doesn't work well if you have stations |
| 561 | * associated to two different APs because curbssid |
| 562 | * is just the last AP that any of the stations associated |
| 563 | * with. |
| 564 | */ |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 565 | return; /* not from our current AP */ |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 566 | } |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 567 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 568 | sc->ps_flags &= ~PS_WAIT_FOR_BEACON; |
Gabor Juhos | 293dc5d | 2009-06-19 12:17:48 +0200 | [diff] [blame] | 569 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 570 | if (sc->ps_flags & PS_BEACON_SYNC) { |
| 571 | sc->ps_flags &= ~PS_BEACON_SYNC; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 572 | ath_dbg(common, ATH_DBG_PS, |
| 573 | "Reconfigure Beacon timers based on timestamp from the AP\n"); |
Rajkumar Manoharan | 99e4d43 | 2011-04-04 22:56:19 +0530 | [diff] [blame] | 574 | ath_set_beacon(sc); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 575 | } |
| 576 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 577 | if (ath_beacon_dtim_pending_cab(skb)) { |
| 578 | /* |
| 579 | * Remain awake waiting for buffered broadcast/multicast |
Gabor Juhos | 58f5fff | 2009-06-17 20:53:20 +0200 | [diff] [blame] | 580 | * frames. If the last broadcast/multicast frame is not |
| 581 | * received properly, the next beacon frame will work as |
| 582 | * a backup trigger for returning into NETWORK SLEEP state, |
| 583 | * so we are waiting for it as well. |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 584 | */ |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 585 | ath_dbg(common, ATH_DBG_PS, |
| 586 | "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 587 | sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON; |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 588 | return; |
| 589 | } |
| 590 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 591 | if (sc->ps_flags & PS_WAIT_FOR_CAB) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 592 | /* |
| 593 | * This can happen if a broadcast frame is dropped or the AP |
| 594 | * fails to send a frame indicating that all CAB frames have |
| 595 | * been delivered. |
| 596 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 597 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 598 | ath_dbg(common, ATH_DBG_PS, |
| 599 | "PS wait for CAB frames timed out\n"); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 600 | } |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) |
| 604 | { |
| 605 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 606 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 607 | |
| 608 | hdr = (struct ieee80211_hdr *)skb->data; |
| 609 | |
| 610 | /* Process Beacon and CAB receive in PS state */ |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 611 | if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc)) |
| 612 | && ieee80211_is_beacon(hdr->frame_control)) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 613 | ath_rx_ps_beacon(sc, skb); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 614 | else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 615 | (ieee80211_is_data(hdr->frame_control) || |
| 616 | ieee80211_is_action(hdr->frame_control)) && |
| 617 | is_multicast_ether_addr(hdr->addr1) && |
| 618 | !ieee80211_has_moredata(hdr->frame_control)) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 619 | /* |
| 620 | * No more broadcast/multicast frames to be received at this |
| 621 | * point. |
| 622 | */ |
Senthil Balasubramanian | 3fac6df | 2010-09-16 15:12:35 -0400 | [diff] [blame] | 623 | sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON); |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 624 | ath_dbg(common, ATH_DBG_PS, |
| 625 | "All PS CAB frames received, back to sleep\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 626 | } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) && |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 627 | !is_multicast_ether_addr(hdr->addr1) && |
| 628 | !ieee80211_has_morefrags(hdr->frame_control)) { |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 629 | sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 630 | ath_dbg(common, ATH_DBG_PS, |
| 631 | "Going back to sleep after having received PS-Poll data (0x%lx)\n", |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 632 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 633 | PS_WAIT_FOR_CAB | |
| 634 | PS_WAIT_FOR_PSPOLL_DATA | |
| 635 | PS_WAIT_FOR_TX_ACK)); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 639 | static bool ath_edma_get_buffers(struct ath_softc *sc, |
| 640 | enum ath9k_rx_qtype qtype) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 641 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 642 | struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype]; |
| 643 | struct ath_hw *ah = sc->sc_ah; |
| 644 | struct ath_common *common = ath9k_hw_common(ah); |
| 645 | struct sk_buff *skb; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 646 | struct ath_buf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 647 | int ret; |
| 648 | |
| 649 | skb = skb_peek(&rx_edma->rx_fifo); |
| 650 | if (!skb) |
| 651 | return false; |
| 652 | |
| 653 | bf = SKB_CB_ATHBUF(skb); |
| 654 | BUG_ON(!bf); |
| 655 | |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 656 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 657 | common->rx_bufsize, DMA_FROM_DEVICE); |
| 658 | |
| 659 | ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data); |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 660 | if (ret == -EINPROGRESS) { |
| 661 | /*let device gain the buffer again*/ |
| 662 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 663 | common->rx_bufsize, DMA_FROM_DEVICE); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 664 | return false; |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 665 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 666 | |
| 667 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 668 | if (ret == -EINVAL) { |
| 669 | /* corrupt descriptor, skip this one and the following one */ |
| 670 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 671 | ath_rx_edma_buf_link(sc, qtype); |
| 672 | skb = skb_peek(&rx_edma->rx_fifo); |
| 673 | if (!skb) |
| 674 | return true; |
| 675 | |
| 676 | bf = SKB_CB_ATHBUF(skb); |
| 677 | BUG_ON(!bf); |
| 678 | |
| 679 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 680 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 681 | ath_rx_edma_buf_link(sc, qtype); |
Vasanthakumar Thiagarajan | 083e3e8 | 2010-05-10 19:41:34 -0700 | [diff] [blame] | 682 | return true; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 683 | } |
| 684 | skb_queue_tail(&rx_edma->rx_buffers, skb); |
| 685 | |
| 686 | return true; |
| 687 | } |
| 688 | |
| 689 | static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc, |
| 690 | struct ath_rx_status *rs, |
| 691 | enum ath9k_rx_qtype qtype) |
| 692 | { |
| 693 | struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype]; |
| 694 | struct sk_buff *skb; |
| 695 | struct ath_buf *bf; |
| 696 | |
| 697 | while (ath_edma_get_buffers(sc, qtype)); |
| 698 | skb = __skb_dequeue(&rx_edma->rx_buffers); |
| 699 | if (!skb) |
| 700 | return NULL; |
| 701 | |
| 702 | bf = SKB_CB_ATHBUF(skb); |
| 703 | ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data); |
| 704 | return bf; |
| 705 | } |
| 706 | |
| 707 | static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc, |
| 708 | struct ath_rx_status *rs) |
| 709 | { |
| 710 | struct ath_hw *ah = sc->sc_ah; |
| 711 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 712 | struct ath_desc *ds; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 713 | struct ath_buf *bf; |
| 714 | int ret; |
| 715 | |
| 716 | if (list_empty(&sc->rx.rxbuf)) { |
| 717 | sc->rx.rxlink = NULL; |
| 718 | return NULL; |
| 719 | } |
| 720 | |
| 721 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
| 722 | ds = bf->bf_desc; |
| 723 | |
| 724 | /* |
| 725 | * Must provide the virtual address of the current |
| 726 | * descriptor, the physical address, and the virtual |
| 727 | * address of the next descriptor in the h/w chain. |
| 728 | * This allows the HAL to look ahead to see if the |
| 729 | * hardware is done with a descriptor by checking the |
| 730 | * done bit in the following descriptor and the address |
| 731 | * of the current descriptor the DMA engine is working |
| 732 | * on. All this is necessary because of our use of |
| 733 | * a self-linked list to avoid rx overruns. |
| 734 | */ |
| 735 | ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0); |
| 736 | if (ret == -EINPROGRESS) { |
| 737 | struct ath_rx_status trs; |
| 738 | struct ath_buf *tbf; |
| 739 | struct ath_desc *tds; |
| 740 | |
| 741 | memset(&trs, 0, sizeof(trs)); |
| 742 | if (list_is_last(&bf->list, &sc->rx.rxbuf)) { |
| 743 | sc->rx.rxlink = NULL; |
| 744 | return NULL; |
| 745 | } |
| 746 | |
| 747 | tbf = list_entry(bf->list.next, struct ath_buf, list); |
| 748 | |
| 749 | /* |
| 750 | * On some hardware the descriptor status words could |
| 751 | * get corrupted, including the done bit. Because of |
| 752 | * this, check if the next descriptor's done bit is |
| 753 | * set or not. |
| 754 | * |
| 755 | * If the next descriptor's done bit is set, the current |
| 756 | * descriptor has been corrupted. Force s/w to discard |
| 757 | * this descriptor and continue... |
| 758 | */ |
| 759 | |
| 760 | tds = tbf->bf_desc; |
| 761 | ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0); |
| 762 | if (ret == -EINPROGRESS) |
| 763 | return NULL; |
| 764 | } |
| 765 | |
| 766 | if (!bf->bf_mpdu) |
| 767 | return bf; |
| 768 | |
| 769 | /* |
| 770 | * Synchronize the DMA transfer with CPU before |
| 771 | * 1. accessing the frame |
| 772 | * 2. requeueing the same buffer to h/w |
| 773 | */ |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 774 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 775 | common->rx_bufsize, |
| 776 | DMA_FROM_DEVICE); |
| 777 | |
| 778 | return bf; |
| 779 | } |
| 780 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 781 | /* Assumes you've already done the endian to CPU conversion */ |
| 782 | static bool ath9k_rx_accept(struct ath_common *common, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 783 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 784 | struct ieee80211_rx_status *rxs, |
| 785 | struct ath_rx_status *rx_stats, |
| 786 | bool *decrypt_error) |
| 787 | { |
Senthil Balasubramanian | 38852b2 | 2010-12-06 19:09:27 +0530 | [diff] [blame] | 788 | #define is_mc_or_valid_tkip_keyix ((is_mc || \ |
| 789 | (rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \ |
| 790 | test_bit(rx_stats->rs_keyix, common->tkip_keymap)))) |
| 791 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 792 | struct ath_hw *ah = common->ah; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 793 | __le16 fc; |
Vasanthakumar Thiagarajan | b7b1b51 | 2010-05-20 14:34:48 -0700 | [diff] [blame] | 794 | u8 rx_status_len = ah->caps.rx_status_len; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 795 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 796 | fc = hdr->frame_control; |
| 797 | |
| 798 | if (!rx_stats->rs_datalen) |
| 799 | return false; |
| 800 | /* |
| 801 | * rs_status follows rs_datalen so if rs_datalen is too large |
| 802 | * we can take a hint that hardware corrupted it, so ignore |
| 803 | * those frames. |
| 804 | */ |
Vasanthakumar Thiagarajan | b7b1b51 | 2010-05-20 14:34:48 -0700 | [diff] [blame] | 805 | if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 806 | return false; |
| 807 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 808 | /* Only use error bits from the last fragment */ |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 809 | if (rx_stats->rs_more) |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 810 | return true; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 811 | |
| 812 | /* |
| 813 | * The rx_stats->rs_status will not be set until the end of the |
| 814 | * chained descriptors so it can be ignored if rs_more is set. The |
| 815 | * rs_more will be false at the last element of the chained |
| 816 | * descriptors. |
| 817 | */ |
| 818 | if (rx_stats->rs_status != 0) { |
| 819 | if (rx_stats->rs_status & ATH9K_RXERR_CRC) |
| 820 | rxs->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 821 | if (rx_stats->rs_status & ATH9K_RXERR_PHY) |
| 822 | return false; |
| 823 | |
| 824 | if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) { |
| 825 | *decrypt_error = true; |
| 826 | } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) { |
Senthil Balasubramanian | 38852b2 | 2010-12-06 19:09:27 +0530 | [diff] [blame] | 827 | bool is_mc; |
Felix Fietkau | 56363dd | 2010-08-28 18:21:21 +0200 | [diff] [blame] | 828 | /* |
| 829 | * The MIC error bit is only valid if the frame |
| 830 | * is not a control frame or fragment, and it was |
| 831 | * decrypted using a valid TKIP key. |
| 832 | */ |
Senthil Balasubramanian | 38852b2 | 2010-12-06 19:09:27 +0530 | [diff] [blame] | 833 | is_mc = !!is_multicast_ether_addr(hdr->addr1); |
| 834 | |
Felix Fietkau | 56363dd | 2010-08-28 18:21:21 +0200 | [diff] [blame] | 835 | if (!ieee80211_is_ctl(fc) && |
| 836 | !ieee80211_has_morefrags(fc) && |
| 837 | !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) && |
Senthil Balasubramanian | 38852b2 | 2010-12-06 19:09:27 +0530 | [diff] [blame] | 838 | is_mc_or_valid_tkip_keyix) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 839 | rxs->flag |= RX_FLAG_MMIC_ERROR; |
Felix Fietkau | 56363dd | 2010-08-28 18:21:21 +0200 | [diff] [blame] | 840 | else |
| 841 | rx_stats->rs_status &= ~ATH9K_RXERR_MIC; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 842 | } |
| 843 | /* |
| 844 | * Reject error frames with the exception of |
| 845 | * decryption and MIC failures. For monitor mode, |
| 846 | * we also ignore the CRC error. |
| 847 | */ |
Rajkumar Manoharan | 5f841b4 | 2010-10-27 18:31:15 +0530 | [diff] [blame] | 848 | if (ah->is_monitoring) { |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 849 | if (rx_stats->rs_status & |
| 850 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | |
| 851 | ATH9K_RXERR_CRC)) |
| 852 | return false; |
| 853 | } else { |
| 854 | if (rx_stats->rs_status & |
| 855 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) { |
| 856 | return false; |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | return true; |
| 861 | } |
| 862 | |
| 863 | static int ath9k_process_rate(struct ath_common *common, |
| 864 | struct ieee80211_hw *hw, |
| 865 | struct ath_rx_status *rx_stats, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 866 | struct ieee80211_rx_status *rxs) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 867 | { |
| 868 | struct ieee80211_supported_band *sband; |
| 869 | enum ieee80211_band band; |
| 870 | unsigned int i = 0; |
| 871 | |
| 872 | band = hw->conf.channel->band; |
| 873 | sband = hw->wiphy->bands[band]; |
| 874 | |
| 875 | if (rx_stats->rs_rate & 0x80) { |
| 876 | /* HT rate */ |
| 877 | rxs->flag |= RX_FLAG_HT; |
| 878 | if (rx_stats->rs_flags & ATH9K_RX_2040) |
| 879 | rxs->flag |= RX_FLAG_40MHZ; |
| 880 | if (rx_stats->rs_flags & ATH9K_RX_GI) |
| 881 | rxs->flag |= RX_FLAG_SHORT_GI; |
| 882 | rxs->rate_idx = rx_stats->rs_rate & 0x7f; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | for (i = 0; i < sband->n_bitrates; i++) { |
| 887 | if (sband->bitrates[i].hw_value == rx_stats->rs_rate) { |
| 888 | rxs->rate_idx = i; |
| 889 | return 0; |
| 890 | } |
| 891 | if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) { |
| 892 | rxs->flag |= RX_FLAG_SHORTPRE; |
| 893 | rxs->rate_idx = i; |
| 894 | return 0; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | /* |
| 899 | * No valid hardware bitrate found -- we should not get here |
| 900 | * because hardware has already validated this frame as OK. |
| 901 | */ |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 902 | ath_dbg(common, ATH_DBG_XMIT, |
| 903 | "unsupported hw bitrate detected 0x%02x using 1 Mbit\n", |
| 904 | rx_stats->rs_rate); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 905 | |
| 906 | return -EINVAL; |
| 907 | } |
| 908 | |
| 909 | static void ath9k_process_rssi(struct ath_common *common, |
| 910 | struct ieee80211_hw *hw, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 911 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 912 | struct ath_rx_status *rx_stats) |
| 913 | { |
Felix Fietkau | 9ac5861 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 914 | struct ath_softc *sc = hw->priv; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 915 | struct ath_hw *ah = common->ah; |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 916 | int last_rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 917 | __le16 fc; |
| 918 | |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 919 | if (ah->opmode != NL80211_IFTYPE_STATION) |
| 920 | return; |
| 921 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 922 | fc = hdr->frame_control; |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 923 | if (!ieee80211_is_beacon(fc) || |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 924 | compare_ether_addr(hdr->addr3, common->curbssid)) { |
| 925 | /* TODO: This doesn't work well if you have stations |
| 926 | * associated to two different APs because curbssid |
| 927 | * is just the last AP that any of the stations associated |
| 928 | * with. |
| 929 | */ |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 930 | return; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 931 | } |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 932 | |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 933 | if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr) |
Felix Fietkau | 9ac5861 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 934 | ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi); |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 935 | |
Felix Fietkau | 9ac5861 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 936 | last_rssi = sc->last_rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 937 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) |
| 938 | rx_stats->rs_rssi = ATH_EP_RND(last_rssi, |
| 939 | ATH_RSSI_EP_MULTIPLIER); |
| 940 | if (rx_stats->rs_rssi < 0) |
| 941 | rx_stats->rs_rssi = 0; |
| 942 | |
| 943 | /* Update Beacon RSSI, this is used by ANI. */ |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 944 | ah->stats.avgbrssi = rx_stats->rs_rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /* |
| 948 | * For Decrypt or Demic errors, we only mark packet status here and always push |
| 949 | * up the frame up to let mac80211 handle the actual error case, be it no |
| 950 | * decryption key or real decryption error. This let us keep statistics there. |
| 951 | */ |
| 952 | static int ath9k_rx_skb_preprocess(struct ath_common *common, |
| 953 | struct ieee80211_hw *hw, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 954 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 955 | struct ath_rx_status *rx_stats, |
| 956 | struct ieee80211_rx_status *rx_status, |
| 957 | bool *decrypt_error) |
| 958 | { |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 959 | memset(rx_status, 0, sizeof(struct ieee80211_rx_status)); |
| 960 | |
| 961 | /* |
| 962 | * everything but the rate is checked here, the rate check is done |
| 963 | * separately to avoid doing two lookups for a rate for each frame. |
| 964 | */ |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 965 | if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 966 | return -EINVAL; |
| 967 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 968 | /* Only use status info from the last fragment */ |
| 969 | if (rx_stats->rs_more) |
| 970 | return 0; |
| 971 | |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 972 | ath9k_process_rssi(common, hw, hdr, rx_stats); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 973 | |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 974 | if (ath9k_process_rate(common, hw, rx_stats, rx_status)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 975 | return -EINVAL; |
| 976 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 977 | rx_status->band = hw->conf.channel->band; |
| 978 | rx_status->freq = hw->conf.channel->center_freq; |
| 979 | rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi; |
| 980 | rx_status->antenna = rx_stats->rs_antenna; |
Johannes Berg | 6ebacbb | 2011-02-23 15:06:08 +0100 | [diff] [blame] | 981 | rx_status->flag |= RX_FLAG_MACTIME_MPDU; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static void ath9k_rx_skb_postprocess(struct ath_common *common, |
| 987 | struct sk_buff *skb, |
| 988 | struct ath_rx_status *rx_stats, |
| 989 | struct ieee80211_rx_status *rxs, |
| 990 | bool decrypt_error) |
| 991 | { |
| 992 | struct ath_hw *ah = common->ah; |
| 993 | struct ieee80211_hdr *hdr; |
| 994 | int hdrlen, padpos, padsize; |
| 995 | u8 keyix; |
| 996 | __le16 fc; |
| 997 | |
| 998 | /* see if any padding is done by the hw and remove it */ |
| 999 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1000 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 1001 | fc = hdr->frame_control; |
| 1002 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 1003 | |
| 1004 | /* The MAC header is padded to have 32-bit boundary if the |
| 1005 | * packet payload is non-zero. The general calculation for |
| 1006 | * padsize would take into account odd header lengths: |
| 1007 | * padsize = (4 - padpos % 4) % 4; However, since only |
| 1008 | * even-length headers are used, padding can only be 0 or 2 |
| 1009 | * bytes and we can optimize this a bit. In addition, we must |
| 1010 | * not try to remove padding from short control frames that do |
| 1011 | * not have payload. */ |
| 1012 | padsize = padpos & 3; |
| 1013 | if (padsize && skb->len>=padpos+padsize+FCS_LEN) { |
| 1014 | memmove(skb->data + padsize, skb->data, padpos); |
| 1015 | skb_pull(skb, padsize); |
| 1016 | } |
| 1017 | |
| 1018 | keyix = rx_stats->rs_keyix; |
| 1019 | |
| 1020 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error && |
| 1021 | ieee80211_has_protected(fc)) { |
| 1022 | rxs->flag |= RX_FLAG_DECRYPTED; |
| 1023 | } else if (ieee80211_has_protected(fc) |
| 1024 | && !decrypt_error && skb->len >= hdrlen + 4) { |
| 1025 | keyix = skb->data[hdrlen + 3] >> 6; |
| 1026 | |
| 1027 | if (test_bit(keyix, common->keymap)) |
| 1028 | rxs->flag |= RX_FLAG_DECRYPTED; |
| 1029 | } |
| 1030 | if (ah->sw_mgmt_crypto && |
| 1031 | (rxs->flag & RX_FLAG_DECRYPTED) && |
| 1032 | ieee80211_is_mgmt(fc)) |
| 1033 | /* Use software decrypt for management frames. */ |
| 1034 | rxs->flag &= ~RX_FLAG_DECRYPTED; |
| 1035 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1036 | |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 1037 | static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb, |
| 1038 | struct ath_hw_antcomb_conf ant_conf, |
| 1039 | int main_rssi_avg) |
| 1040 | { |
| 1041 | antcomb->quick_scan_cnt = 0; |
| 1042 | |
| 1043 | if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2) |
| 1044 | antcomb->rssi_lna2 = main_rssi_avg; |
| 1045 | else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1) |
| 1046 | antcomb->rssi_lna1 = main_rssi_avg; |
| 1047 | |
| 1048 | switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) { |
| 1049 | case (0x10): /* LNA2 A-B */ |
| 1050 | antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1051 | antcomb->first_quick_scan_conf = |
| 1052 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1053 | antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1; |
| 1054 | break; |
| 1055 | case (0x20): /* LNA1 A-B */ |
| 1056 | antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1057 | antcomb->first_quick_scan_conf = |
| 1058 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1059 | antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2; |
| 1060 | break; |
| 1061 | case (0x21): /* LNA1 LNA2 */ |
| 1062 | antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2; |
| 1063 | antcomb->first_quick_scan_conf = |
| 1064 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1065 | antcomb->second_quick_scan_conf = |
| 1066 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1067 | break; |
| 1068 | case (0x12): /* LNA2 LNA1 */ |
| 1069 | antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1; |
| 1070 | antcomb->first_quick_scan_conf = |
| 1071 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1072 | antcomb->second_quick_scan_conf = |
| 1073 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1074 | break; |
| 1075 | case (0x13): /* LNA2 A+B */ |
| 1076 | antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1077 | antcomb->first_quick_scan_conf = |
| 1078 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1079 | antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1; |
| 1080 | break; |
| 1081 | case (0x23): /* LNA1 A+B */ |
| 1082 | antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1083 | antcomb->first_quick_scan_conf = |
| 1084 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1085 | antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2; |
| 1086 | break; |
| 1087 | default: |
| 1088 | break; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb, |
| 1093 | struct ath_hw_antcomb_conf *div_ant_conf, |
| 1094 | int main_rssi_avg, int alt_rssi_avg, |
| 1095 | int alt_ratio) |
| 1096 | { |
| 1097 | /* alt_good */ |
| 1098 | switch (antcomb->quick_scan_cnt) { |
| 1099 | case 0: |
| 1100 | /* set alt to main, and alt to first conf */ |
| 1101 | div_ant_conf->main_lna_conf = antcomb->main_conf; |
| 1102 | div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf; |
| 1103 | break; |
| 1104 | case 1: |
| 1105 | /* set alt to main, and alt to first conf */ |
| 1106 | div_ant_conf->main_lna_conf = antcomb->main_conf; |
| 1107 | div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf; |
| 1108 | antcomb->rssi_first = main_rssi_avg; |
| 1109 | antcomb->rssi_second = alt_rssi_avg; |
| 1110 | |
| 1111 | if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) { |
| 1112 | /* main is LNA1 */ |
| 1113 | if (ath_is_alt_ant_ratio_better(alt_ratio, |
| 1114 | ATH_ANT_DIV_COMB_LNA1_DELTA_HI, |
| 1115 | ATH_ANT_DIV_COMB_LNA1_DELTA_LOW, |
| 1116 | main_rssi_avg, alt_rssi_avg, |
| 1117 | antcomb->total_pkt_count)) |
| 1118 | antcomb->first_ratio = true; |
| 1119 | else |
| 1120 | antcomb->first_ratio = false; |
| 1121 | } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) { |
| 1122 | if (ath_is_alt_ant_ratio_better(alt_ratio, |
| 1123 | ATH_ANT_DIV_COMB_LNA1_DELTA_MID, |
| 1124 | ATH_ANT_DIV_COMB_LNA1_DELTA_LOW, |
| 1125 | main_rssi_avg, alt_rssi_avg, |
| 1126 | antcomb->total_pkt_count)) |
| 1127 | antcomb->first_ratio = true; |
| 1128 | else |
| 1129 | antcomb->first_ratio = false; |
| 1130 | } else { |
| 1131 | if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) && |
| 1132 | (alt_rssi_avg > main_rssi_avg + |
| 1133 | ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) || |
| 1134 | (alt_rssi_avg > main_rssi_avg)) && |
| 1135 | (antcomb->total_pkt_count > 50)) |
| 1136 | antcomb->first_ratio = true; |
| 1137 | else |
| 1138 | antcomb->first_ratio = false; |
| 1139 | } |
| 1140 | break; |
| 1141 | case 2: |
| 1142 | antcomb->alt_good = false; |
| 1143 | antcomb->scan_not_start = false; |
| 1144 | antcomb->scan = false; |
| 1145 | antcomb->rssi_first = main_rssi_avg; |
| 1146 | antcomb->rssi_third = alt_rssi_avg; |
| 1147 | |
| 1148 | if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) |
| 1149 | antcomb->rssi_lna1 = alt_rssi_avg; |
| 1150 | else if (antcomb->second_quick_scan_conf == |
| 1151 | ATH_ANT_DIV_COMB_LNA2) |
| 1152 | antcomb->rssi_lna2 = alt_rssi_avg; |
| 1153 | else if (antcomb->second_quick_scan_conf == |
| 1154 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) { |
| 1155 | if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) |
| 1156 | antcomb->rssi_lna2 = main_rssi_avg; |
| 1157 | else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) |
| 1158 | antcomb->rssi_lna1 = main_rssi_avg; |
| 1159 | } |
| 1160 | |
| 1161 | if (antcomb->rssi_lna2 > antcomb->rssi_lna1 + |
| 1162 | ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA) |
| 1163 | div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2; |
| 1164 | else |
| 1165 | div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1; |
| 1166 | |
| 1167 | if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) { |
| 1168 | if (ath_is_alt_ant_ratio_better(alt_ratio, |
| 1169 | ATH_ANT_DIV_COMB_LNA1_DELTA_HI, |
| 1170 | ATH_ANT_DIV_COMB_LNA1_DELTA_LOW, |
| 1171 | main_rssi_avg, alt_rssi_avg, |
| 1172 | antcomb->total_pkt_count)) |
| 1173 | antcomb->second_ratio = true; |
| 1174 | else |
| 1175 | antcomb->second_ratio = false; |
| 1176 | } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) { |
| 1177 | if (ath_is_alt_ant_ratio_better(alt_ratio, |
| 1178 | ATH_ANT_DIV_COMB_LNA1_DELTA_MID, |
| 1179 | ATH_ANT_DIV_COMB_LNA1_DELTA_LOW, |
| 1180 | main_rssi_avg, alt_rssi_avg, |
| 1181 | antcomb->total_pkt_count)) |
| 1182 | antcomb->second_ratio = true; |
| 1183 | else |
| 1184 | antcomb->second_ratio = false; |
| 1185 | } else { |
| 1186 | if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) && |
| 1187 | (alt_rssi_avg > main_rssi_avg + |
| 1188 | ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) || |
| 1189 | (alt_rssi_avg > main_rssi_avg)) && |
| 1190 | (antcomb->total_pkt_count > 50)) |
| 1191 | antcomb->second_ratio = true; |
| 1192 | else |
| 1193 | antcomb->second_ratio = false; |
| 1194 | } |
| 1195 | |
| 1196 | /* set alt to the conf with maximun ratio */ |
| 1197 | if (antcomb->first_ratio && antcomb->second_ratio) { |
| 1198 | if (antcomb->rssi_second > antcomb->rssi_third) { |
| 1199 | /* first alt*/ |
| 1200 | if ((antcomb->first_quick_scan_conf == |
| 1201 | ATH_ANT_DIV_COMB_LNA1) || |
| 1202 | (antcomb->first_quick_scan_conf == |
| 1203 | ATH_ANT_DIV_COMB_LNA2)) |
| 1204 | /* Set alt LNA1 or LNA2*/ |
| 1205 | if (div_ant_conf->main_lna_conf == |
| 1206 | ATH_ANT_DIV_COMB_LNA2) |
| 1207 | div_ant_conf->alt_lna_conf = |
| 1208 | ATH_ANT_DIV_COMB_LNA1; |
| 1209 | else |
| 1210 | div_ant_conf->alt_lna_conf = |
| 1211 | ATH_ANT_DIV_COMB_LNA2; |
| 1212 | else |
| 1213 | /* Set alt to A+B or A-B */ |
| 1214 | div_ant_conf->alt_lna_conf = |
| 1215 | antcomb->first_quick_scan_conf; |
| 1216 | } else if ((antcomb->second_quick_scan_conf == |
| 1217 | ATH_ANT_DIV_COMB_LNA1) || |
| 1218 | (antcomb->second_quick_scan_conf == |
| 1219 | ATH_ANT_DIV_COMB_LNA2)) { |
| 1220 | /* Set alt LNA1 or LNA2 */ |
| 1221 | if (div_ant_conf->main_lna_conf == |
| 1222 | ATH_ANT_DIV_COMB_LNA2) |
| 1223 | div_ant_conf->alt_lna_conf = |
| 1224 | ATH_ANT_DIV_COMB_LNA1; |
| 1225 | else |
| 1226 | div_ant_conf->alt_lna_conf = |
| 1227 | ATH_ANT_DIV_COMB_LNA2; |
| 1228 | } else { |
| 1229 | /* Set alt to A+B or A-B */ |
| 1230 | div_ant_conf->alt_lna_conf = |
| 1231 | antcomb->second_quick_scan_conf; |
| 1232 | } |
| 1233 | } else if (antcomb->first_ratio) { |
| 1234 | /* first alt */ |
| 1235 | if ((antcomb->first_quick_scan_conf == |
| 1236 | ATH_ANT_DIV_COMB_LNA1) || |
| 1237 | (antcomb->first_quick_scan_conf == |
| 1238 | ATH_ANT_DIV_COMB_LNA2)) |
| 1239 | /* Set alt LNA1 or LNA2 */ |
| 1240 | if (div_ant_conf->main_lna_conf == |
| 1241 | ATH_ANT_DIV_COMB_LNA2) |
| 1242 | div_ant_conf->alt_lna_conf = |
| 1243 | ATH_ANT_DIV_COMB_LNA1; |
| 1244 | else |
| 1245 | div_ant_conf->alt_lna_conf = |
| 1246 | ATH_ANT_DIV_COMB_LNA2; |
| 1247 | else |
| 1248 | /* Set alt to A+B or A-B */ |
| 1249 | div_ant_conf->alt_lna_conf = |
| 1250 | antcomb->first_quick_scan_conf; |
| 1251 | } else if (antcomb->second_ratio) { |
| 1252 | /* second alt */ |
| 1253 | if ((antcomb->second_quick_scan_conf == |
| 1254 | ATH_ANT_DIV_COMB_LNA1) || |
| 1255 | (antcomb->second_quick_scan_conf == |
| 1256 | ATH_ANT_DIV_COMB_LNA2)) |
| 1257 | /* Set alt LNA1 or LNA2 */ |
| 1258 | if (div_ant_conf->main_lna_conf == |
| 1259 | ATH_ANT_DIV_COMB_LNA2) |
| 1260 | div_ant_conf->alt_lna_conf = |
| 1261 | ATH_ANT_DIV_COMB_LNA1; |
| 1262 | else |
| 1263 | div_ant_conf->alt_lna_conf = |
| 1264 | ATH_ANT_DIV_COMB_LNA2; |
| 1265 | else |
| 1266 | /* Set alt to A+B or A-B */ |
| 1267 | div_ant_conf->alt_lna_conf = |
| 1268 | antcomb->second_quick_scan_conf; |
| 1269 | } else { |
| 1270 | /* main is largest */ |
| 1271 | if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) || |
| 1272 | (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)) |
| 1273 | /* Set alt LNA1 or LNA2 */ |
| 1274 | if (div_ant_conf->main_lna_conf == |
| 1275 | ATH_ANT_DIV_COMB_LNA2) |
| 1276 | div_ant_conf->alt_lna_conf = |
| 1277 | ATH_ANT_DIV_COMB_LNA1; |
| 1278 | else |
| 1279 | div_ant_conf->alt_lna_conf = |
| 1280 | ATH_ANT_DIV_COMB_LNA2; |
| 1281 | else |
| 1282 | /* Set alt to A+B or A-B */ |
| 1283 | div_ant_conf->alt_lna_conf = antcomb->main_conf; |
| 1284 | } |
| 1285 | break; |
| 1286 | default: |
| 1287 | break; |
| 1288 | } |
| 1289 | } |
| 1290 | |
John W. Linville | 9bad82b | 2010-09-15 15:26:13 -0400 | [diff] [blame] | 1291 | static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf) |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 1292 | { |
| 1293 | /* Adjust the fast_div_bias based on main and alt lna conf */ |
| 1294 | switch ((ant_conf->main_lna_conf << 4) | ant_conf->alt_lna_conf) { |
| 1295 | case (0x01): /* A-B LNA2 */ |
| 1296 | ant_conf->fast_div_bias = 0x3b; |
| 1297 | break; |
| 1298 | case (0x02): /* A-B LNA1 */ |
| 1299 | ant_conf->fast_div_bias = 0x3d; |
| 1300 | break; |
| 1301 | case (0x03): /* A-B A+B */ |
| 1302 | ant_conf->fast_div_bias = 0x1; |
| 1303 | break; |
| 1304 | case (0x10): /* LNA2 A-B */ |
| 1305 | ant_conf->fast_div_bias = 0x7; |
| 1306 | break; |
| 1307 | case (0x12): /* LNA2 LNA1 */ |
| 1308 | ant_conf->fast_div_bias = 0x2; |
| 1309 | break; |
| 1310 | case (0x13): /* LNA2 A+B */ |
| 1311 | ant_conf->fast_div_bias = 0x7; |
| 1312 | break; |
| 1313 | case (0x20): /* LNA1 A-B */ |
| 1314 | ant_conf->fast_div_bias = 0x6; |
| 1315 | break; |
| 1316 | case (0x21): /* LNA1 LNA2 */ |
| 1317 | ant_conf->fast_div_bias = 0x0; |
| 1318 | break; |
| 1319 | case (0x23): /* LNA1 A+B */ |
| 1320 | ant_conf->fast_div_bias = 0x6; |
| 1321 | break; |
| 1322 | case (0x30): /* A+B A-B */ |
| 1323 | ant_conf->fast_div_bias = 0x1; |
| 1324 | break; |
| 1325 | case (0x31): /* A+B LNA2 */ |
| 1326 | ant_conf->fast_div_bias = 0x3b; |
| 1327 | break; |
| 1328 | case (0x32): /* A+B LNA1 */ |
| 1329 | ant_conf->fast_div_bias = 0x3d; |
| 1330 | break; |
| 1331 | default: |
| 1332 | break; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | /* Antenna diversity and combining */ |
| 1337 | static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs) |
| 1338 | { |
| 1339 | struct ath_hw_antcomb_conf div_ant_conf; |
| 1340 | struct ath_ant_comb *antcomb = &sc->ant_comb; |
| 1341 | int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set; |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 1342 | int curr_main_set; |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 1343 | int main_rssi = rs->rs_rssi_ctl0; |
| 1344 | int alt_rssi = rs->rs_rssi_ctl1; |
| 1345 | int rx_ant_conf, main_ant_conf; |
| 1346 | bool short_scan = false; |
| 1347 | |
| 1348 | rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) & |
| 1349 | ATH_ANT_RX_MASK; |
| 1350 | main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) & |
| 1351 | ATH_ANT_RX_MASK; |
| 1352 | |
| 1353 | /* Record packet only when alt_rssi is positive */ |
| 1354 | if (alt_rssi > 0) { |
| 1355 | antcomb->total_pkt_count++; |
| 1356 | antcomb->main_total_rssi += main_rssi; |
| 1357 | antcomb->alt_total_rssi += alt_rssi; |
| 1358 | if (main_ant_conf == rx_ant_conf) |
| 1359 | antcomb->main_recv_cnt++; |
| 1360 | else |
| 1361 | antcomb->alt_recv_cnt++; |
| 1362 | } |
| 1363 | |
| 1364 | /* Short scan check */ |
| 1365 | if (antcomb->scan && antcomb->alt_good) { |
| 1366 | if (time_after(jiffies, antcomb->scan_start_time + |
| 1367 | msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR))) |
| 1368 | short_scan = true; |
| 1369 | else |
| 1370 | if (antcomb->total_pkt_count == |
| 1371 | ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) { |
| 1372 | alt_ratio = ((antcomb->alt_recv_cnt * 100) / |
| 1373 | antcomb->total_pkt_count); |
| 1374 | if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO) |
| 1375 | short_scan = true; |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) || |
| 1380 | rs->rs_moreaggr) && !short_scan) |
| 1381 | return; |
| 1382 | |
| 1383 | if (antcomb->total_pkt_count) { |
| 1384 | alt_ratio = ((antcomb->alt_recv_cnt * 100) / |
| 1385 | antcomb->total_pkt_count); |
| 1386 | main_rssi_avg = (antcomb->main_total_rssi / |
| 1387 | antcomb->total_pkt_count); |
| 1388 | alt_rssi_avg = (antcomb->alt_total_rssi / |
| 1389 | antcomb->total_pkt_count); |
| 1390 | } |
| 1391 | |
| 1392 | |
| 1393 | ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf); |
| 1394 | curr_alt_set = div_ant_conf.alt_lna_conf; |
| 1395 | curr_main_set = div_ant_conf.main_lna_conf; |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 1396 | |
| 1397 | antcomb->count++; |
| 1398 | |
| 1399 | if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) { |
| 1400 | if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) { |
| 1401 | ath_lnaconf_alt_good_scan(antcomb, div_ant_conf, |
| 1402 | main_rssi_avg); |
| 1403 | antcomb->alt_good = true; |
| 1404 | } else { |
| 1405 | antcomb->alt_good = false; |
| 1406 | } |
| 1407 | |
| 1408 | antcomb->count = 0; |
| 1409 | antcomb->scan = true; |
| 1410 | antcomb->scan_not_start = true; |
| 1411 | } |
| 1412 | |
| 1413 | if (!antcomb->scan) { |
| 1414 | if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) { |
| 1415 | if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) { |
| 1416 | /* Switch main and alt LNA */ |
| 1417 | div_ant_conf.main_lna_conf = |
| 1418 | ATH_ANT_DIV_COMB_LNA2; |
| 1419 | div_ant_conf.alt_lna_conf = |
| 1420 | ATH_ANT_DIV_COMB_LNA1; |
| 1421 | } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) { |
| 1422 | div_ant_conf.main_lna_conf = |
| 1423 | ATH_ANT_DIV_COMB_LNA1; |
| 1424 | div_ant_conf.alt_lna_conf = |
| 1425 | ATH_ANT_DIV_COMB_LNA2; |
| 1426 | } |
| 1427 | |
| 1428 | goto div_comb_done; |
| 1429 | } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) && |
| 1430 | (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) { |
| 1431 | /* Set alt to another LNA */ |
| 1432 | if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) |
| 1433 | div_ant_conf.alt_lna_conf = |
| 1434 | ATH_ANT_DIV_COMB_LNA1; |
| 1435 | else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) |
| 1436 | div_ant_conf.alt_lna_conf = |
| 1437 | ATH_ANT_DIV_COMB_LNA2; |
| 1438 | |
| 1439 | goto div_comb_done; |
| 1440 | } |
| 1441 | |
| 1442 | if ((alt_rssi_avg < (main_rssi_avg + |
| 1443 | ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA))) |
| 1444 | goto div_comb_done; |
| 1445 | } |
| 1446 | |
| 1447 | if (!antcomb->scan_not_start) { |
| 1448 | switch (curr_alt_set) { |
| 1449 | case ATH_ANT_DIV_COMB_LNA2: |
| 1450 | antcomb->rssi_lna2 = alt_rssi_avg; |
| 1451 | antcomb->rssi_lna1 = main_rssi_avg; |
| 1452 | antcomb->scan = true; |
| 1453 | /* set to A+B */ |
| 1454 | div_ant_conf.main_lna_conf = |
| 1455 | ATH_ANT_DIV_COMB_LNA1; |
| 1456 | div_ant_conf.alt_lna_conf = |
| 1457 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1458 | break; |
| 1459 | case ATH_ANT_DIV_COMB_LNA1: |
| 1460 | antcomb->rssi_lna1 = alt_rssi_avg; |
| 1461 | antcomb->rssi_lna2 = main_rssi_avg; |
| 1462 | antcomb->scan = true; |
| 1463 | /* set to A+B */ |
| 1464 | div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2; |
| 1465 | div_ant_conf.alt_lna_conf = |
| 1466 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1467 | break; |
| 1468 | case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2: |
| 1469 | antcomb->rssi_add = alt_rssi_avg; |
| 1470 | antcomb->scan = true; |
| 1471 | /* set to A-B */ |
| 1472 | div_ant_conf.alt_lna_conf = |
| 1473 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1474 | break; |
| 1475 | case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2: |
| 1476 | antcomb->rssi_sub = alt_rssi_avg; |
| 1477 | antcomb->scan = false; |
| 1478 | if (antcomb->rssi_lna2 > |
| 1479 | (antcomb->rssi_lna1 + |
| 1480 | ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) { |
| 1481 | /* use LNA2 as main LNA */ |
| 1482 | if ((antcomb->rssi_add > antcomb->rssi_lna1) && |
| 1483 | (antcomb->rssi_add > antcomb->rssi_sub)) { |
| 1484 | /* set to A+B */ |
| 1485 | div_ant_conf.main_lna_conf = |
| 1486 | ATH_ANT_DIV_COMB_LNA2; |
| 1487 | div_ant_conf.alt_lna_conf = |
| 1488 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1489 | } else if (antcomb->rssi_sub > |
| 1490 | antcomb->rssi_lna1) { |
| 1491 | /* set to A-B */ |
| 1492 | div_ant_conf.main_lna_conf = |
| 1493 | ATH_ANT_DIV_COMB_LNA2; |
| 1494 | div_ant_conf.alt_lna_conf = |
| 1495 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1496 | } else { |
| 1497 | /* set to LNA1 */ |
| 1498 | div_ant_conf.main_lna_conf = |
| 1499 | ATH_ANT_DIV_COMB_LNA2; |
| 1500 | div_ant_conf.alt_lna_conf = |
| 1501 | ATH_ANT_DIV_COMB_LNA1; |
| 1502 | } |
| 1503 | } else { |
| 1504 | /* use LNA1 as main LNA */ |
| 1505 | if ((antcomb->rssi_add > antcomb->rssi_lna2) && |
| 1506 | (antcomb->rssi_add > antcomb->rssi_sub)) { |
| 1507 | /* set to A+B */ |
| 1508 | div_ant_conf.main_lna_conf = |
| 1509 | ATH_ANT_DIV_COMB_LNA1; |
| 1510 | div_ant_conf.alt_lna_conf = |
| 1511 | ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2; |
| 1512 | } else if (antcomb->rssi_sub > |
| 1513 | antcomb->rssi_lna1) { |
| 1514 | /* set to A-B */ |
| 1515 | div_ant_conf.main_lna_conf = |
| 1516 | ATH_ANT_DIV_COMB_LNA1; |
| 1517 | div_ant_conf.alt_lna_conf = |
| 1518 | ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2; |
| 1519 | } else { |
| 1520 | /* set to LNA2 */ |
| 1521 | div_ant_conf.main_lna_conf = |
| 1522 | ATH_ANT_DIV_COMB_LNA1; |
| 1523 | div_ant_conf.alt_lna_conf = |
| 1524 | ATH_ANT_DIV_COMB_LNA2; |
| 1525 | } |
| 1526 | } |
| 1527 | break; |
| 1528 | default: |
| 1529 | break; |
| 1530 | } |
| 1531 | } else { |
| 1532 | if (!antcomb->alt_good) { |
| 1533 | antcomb->scan_not_start = false; |
| 1534 | /* Set alt to another LNA */ |
| 1535 | if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) { |
| 1536 | div_ant_conf.main_lna_conf = |
| 1537 | ATH_ANT_DIV_COMB_LNA2; |
| 1538 | div_ant_conf.alt_lna_conf = |
| 1539 | ATH_ANT_DIV_COMB_LNA1; |
| 1540 | } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) { |
| 1541 | div_ant_conf.main_lna_conf = |
| 1542 | ATH_ANT_DIV_COMB_LNA1; |
| 1543 | div_ant_conf.alt_lna_conf = |
| 1544 | ATH_ANT_DIV_COMB_LNA2; |
| 1545 | } |
| 1546 | goto div_comb_done; |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf, |
| 1551 | main_rssi_avg, alt_rssi_avg, |
| 1552 | alt_ratio); |
| 1553 | |
| 1554 | antcomb->quick_scan_cnt++; |
| 1555 | |
| 1556 | div_comb_done: |
| 1557 | ath_ant_div_conf_fast_divbias(&div_ant_conf); |
| 1558 | |
| 1559 | ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf); |
| 1560 | |
| 1561 | antcomb->scan_start_time = jiffies; |
| 1562 | antcomb->total_pkt_count = 0; |
| 1563 | antcomb->main_total_rssi = 0; |
| 1564 | antcomb->alt_total_rssi = 0; |
| 1565 | antcomb->main_recv_cnt = 0; |
| 1566 | antcomb->alt_recv_cnt = 0; |
| 1567 | } |
| 1568 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1569 | int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) |
| 1570 | { |
| 1571 | struct ath_buf *bf; |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1572 | struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1573 | struct ieee80211_rx_status *rxs; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1574 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1575 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 1576 | /* |
Mohammed Shafi Shajakhan | cae6b74 | 2010-12-07 21:23:16 +0530 | [diff] [blame] | 1577 | * The hw can technically differ from common->hw when using ath9k |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 1578 | * virtual wiphy so to account for that we iterate over the active |
| 1579 | * wiphys and find the appropriate wiphy and therefore hw. |
| 1580 | */ |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1581 | struct ieee80211_hw *hw = sc->hw; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1582 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c9b1417 | 2009-11-04 16:47:22 -0800 | [diff] [blame] | 1583 | int retval; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1584 | bool decrypt_error = false; |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1585 | struct ath_rx_status rs; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1586 | enum ath9k_rx_qtype qtype; |
| 1587 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
| 1588 | int dma_type; |
Vasanthakumar Thiagarajan | 5c6dd92 | 2010-05-20 14:34:47 -0700 | [diff] [blame] | 1589 | u8 rx_status_len = ah->caps.rx_status_len; |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1590 | u64 tsf = 0; |
| 1591 | u32 tsf_lower = 0; |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1592 | unsigned long flags; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1593 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1594 | if (edma) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1595 | dma_type = DMA_BIDIRECTIONAL; |
Ming Lei | 5682422 | 2010-05-14 21:15:38 +0800 | [diff] [blame] | 1596 | else |
| 1597 | dma_type = DMA_FROM_DEVICE; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1598 | |
| 1599 | qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1600 | spin_lock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1601 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1602 | tsf = ath9k_hw_gettsf64(ah); |
| 1603 | tsf_lower = tsf & 0xffffffff; |
| 1604 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1605 | do { |
| 1606 | /* If handling rx interrupt and flush is in progress => exit */ |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 1607 | if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1608 | break; |
| 1609 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1610 | memset(&rs, 0, sizeof(rs)); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1611 | if (edma) |
| 1612 | bf = ath_edma_get_next_rx_buf(sc, &rs, qtype); |
| 1613 | else |
| 1614 | bf = ath_get_next_rx_buf(sc, &rs); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1615 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1616 | if (!bf) |
| 1617 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1618 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1619 | skb = bf->bf_mpdu; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1620 | if (!skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1621 | continue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1622 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1623 | /* |
| 1624 | * Take frame header from the first fragment and RX status from |
| 1625 | * the last one. |
| 1626 | */ |
| 1627 | if (sc->rx.frag) |
| 1628 | hdr_skb = sc->rx.frag; |
| 1629 | else |
| 1630 | hdr_skb = skb; |
| 1631 | |
| 1632 | hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len); |
| 1633 | rxs = IEEE80211_SKB_RXCB(hdr_skb); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1634 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1635 | ath_debug_stat_rx(sc, &rs); |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 1636 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1637 | /* |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1638 | * If we're asked to flush receive queue, directly |
| 1639 | * chain it back at the queue without processing it. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1640 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1641 | if (flush) |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1642 | goto requeue_drop_frag; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1643 | |
Jan Friedrich | c8f3b72 | 2010-08-02 23:55:50 +0200 | [diff] [blame] | 1644 | retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs, |
| 1645 | rxs, &decrypt_error); |
| 1646 | if (retval) |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1647 | goto requeue_drop_frag; |
Jan Friedrich | c8f3b72 | 2010-08-02 23:55:50 +0200 | [diff] [blame] | 1648 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1649 | rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp; |
| 1650 | if (rs.rs_tstamp > tsf_lower && |
| 1651 | unlikely(rs.rs_tstamp - tsf_lower > 0x10000000)) |
| 1652 | rxs->mactime -= 0x100000000ULL; |
| 1653 | |
| 1654 | if (rs.rs_tstamp < tsf_lower && |
| 1655 | unlikely(tsf_lower - rs.rs_tstamp > 0x10000000)) |
| 1656 | rxs->mactime += 0x100000000ULL; |
| 1657 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1658 | /* Ensure we always have an skb to requeue once we are done |
| 1659 | * processing the current buffer's skb */ |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1660 | requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1661 | |
| 1662 | /* If there is no memory we ignore the current RX'd frame, |
| 1663 | * tell hardware it can give us a new frame using the old |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1664 | * skb and put it at the tail of the sc->rx.rxbuf list for |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1665 | * processing. */ |
| 1666 | if (!requeue_skb) |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1667 | goto requeue_drop_frag; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1668 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1669 | /* Unmap the frame */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1670 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1671 | common->rx_bufsize, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1672 | dma_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1673 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1674 | skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len); |
| 1675 | if (ah->caps.rx_status_len) |
| 1676 | skb_pull(skb, ah->caps.rx_status_len); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1677 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1678 | if (!rs.rs_more) |
| 1679 | ath9k_rx_skb_postprocess(common, hdr_skb, &rs, |
| 1680 | rxs, decrypt_error); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1681 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1682 | /* We will now give hardware our shiny new allocated skb */ |
| 1683 | bf->bf_mpdu = requeue_skb; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1684 | bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1685 | common->rx_bufsize, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1686 | dma_type); |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1687 | if (unlikely(dma_mapping_error(sc->dev, |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1688 | bf->bf_buf_addr))) { |
| 1689 | dev_kfree_skb_any(requeue_skb); |
| 1690 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 1691 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1692 | ath_err(common, "dma_mapping_error() on RX\n"); |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1693 | ieee80211_rx(hw, skb); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1694 | break; |
| 1695 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1696 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1697 | if (rs.rs_more) { |
| 1698 | /* |
| 1699 | * rs_more indicates chained descriptors which can be |
| 1700 | * used to link buffers together for a sort of |
| 1701 | * scatter-gather operation. |
| 1702 | */ |
| 1703 | if (sc->rx.frag) { |
| 1704 | /* too many fragments - cannot handle frame */ |
| 1705 | dev_kfree_skb_any(sc->rx.frag); |
| 1706 | dev_kfree_skb_any(skb); |
| 1707 | skb = NULL; |
| 1708 | } |
| 1709 | sc->rx.frag = skb; |
| 1710 | goto requeue; |
| 1711 | } |
| 1712 | |
| 1713 | if (sc->rx.frag) { |
| 1714 | int space = skb->len - skb_tailroom(hdr_skb); |
| 1715 | |
| 1716 | sc->rx.frag = NULL; |
| 1717 | |
| 1718 | if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) { |
| 1719 | dev_kfree_skb(skb); |
| 1720 | goto requeue_drop_frag; |
| 1721 | } |
| 1722 | |
| 1723 | skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len), |
| 1724 | skb->len); |
| 1725 | dev_kfree_skb_any(skb); |
| 1726 | skb = hdr_skb; |
| 1727 | } |
| 1728 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1729 | /* |
| 1730 | * change the default rx antenna if rx diversity chooses the |
| 1731 | * other antenna 3 times in a row. |
| 1732 | */ |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1733 | if (sc->rx.defant != rs.rs_antenna) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1734 | if (++sc->rx.rxotherant >= 3) |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1735 | ath_setdefantenna(sc, rs.rs_antenna); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1736 | } else { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1737 | sc->rx.rxotherant = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1738 | } |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1739 | |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1740 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Mohammed Shafi Shajakhan | aaef24b | 2010-12-07 20:40:58 +0530 | [diff] [blame] | 1741 | |
| 1742 | if ((sc->ps_flags & (PS_WAIT_FOR_BEACON | |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 1743 | PS_WAIT_FOR_CAB | |
Mohammed Shafi Shajakhan | aaef24b | 2010-12-07 20:40:58 +0530 | [diff] [blame] | 1744 | PS_WAIT_FOR_PSPOLL_DATA)) || |
Mohammed Shafi Shajakhan | cedc7e3 | 2011-04-22 13:12:23 +0530 | [diff] [blame^] | 1745 | ath9k_check_auto_sleep(sc)) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1746 | ath_rx_ps(sc, skb); |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1747 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1748 | |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 1749 | if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) |
| 1750 | ath_ant_comb_scan(sc, &rs); |
| 1751 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1752 | ieee80211_rx(hw, skb); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1753 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1754 | requeue_drop_frag: |
| 1755 | if (sc->rx.frag) { |
| 1756 | dev_kfree_skb_any(sc->rx.frag); |
| 1757 | sc->rx.frag = NULL; |
| 1758 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1759 | requeue: |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1760 | if (edma) { |
| 1761 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 1762 | ath_rx_edma_buf_link(sc, qtype); |
| 1763 | } else { |
| 1764 | list_move_tail(&bf->list, &sc->rx.rxbuf); |
| 1765 | ath_rx_buf_link(sc, bf); |
Felix Fietkau | 9529497 | 2011-04-07 19:30:32 +0200 | [diff] [blame] | 1766 | ath9k_hw_rxena(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1767 | } |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1768 | } while (1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1769 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1770 | spin_unlock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1771 | |
| 1772 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1773 | } |