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