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