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