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> |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame^] | 18 | #include <linux/relay.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 19 | #include "ath9k.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 20 | #include "ar9003_mac.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 21 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 22 | #define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb)) |
| 23 | |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 24 | static inline bool ath9k_check_auto_sleep(struct ath_softc *sc) |
| 25 | { |
| 26 | return sc->ps_enabled && |
| 27 | (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP); |
| 28 | } |
| 29 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 30 | /* |
| 31 | * Setup and link descriptors. |
| 32 | * |
| 33 | * 11N: we can no longer afford to self link the last descriptor. |
| 34 | * MAC acknowledges BA status as long as it copies frames to host |
| 35 | * buffer (or rx fifo). This can incorrectly acknowledge packets |
| 36 | * to a sender if last desc is self-linked. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 37 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 38 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) |
| 39 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 40 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 41 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 42 | struct ath_desc *ds; |
| 43 | struct sk_buff *skb; |
| 44 | |
| 45 | ATH_RXBUF_RESET(bf); |
| 46 | |
| 47 | ds = bf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 48 | ds->ds_link = 0; /* link to null */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 49 | ds->ds_data = bf->bf_buf_addr; |
| 50 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 51 | /* virtual addr of the beginning of the buffer. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 52 | skb = bf->bf_mpdu; |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 53 | BUG_ON(skb == NULL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 54 | ds->ds_vdata = skb->data; |
| 55 | |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 56 | /* |
| 57 | * setup rx descriptors. The rx_bufsize here tells the hardware |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 58 | * 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] | 59 | * to process |
| 60 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 61 | ath9k_hw_setuprxdesc(ah, ds, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 62 | common->rx_bufsize, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 63 | 0); |
| 64 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 65 | if (sc->rx.rxlink == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 66 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
| 67 | else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 68 | *sc->rx.rxlink = bf->bf_daddr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 69 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 70 | sc->rx.rxlink = &ds->ds_link; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 73 | static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) |
| 74 | { |
| 75 | /* XXX block beacon interrupts */ |
| 76 | ath9k_hw_setantenna(sc->sc_ah, antenna); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 77 | sc->rx.defant = antenna; |
| 78 | sc->rx.rxotherant = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 79 | } |
| 80 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 81 | static void ath_opmode_init(struct ath_softc *sc) |
| 82 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 83 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 84 | struct ath_common *common = ath9k_hw_common(ah); |
| 85 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 86 | u32 rfilt, mfilt[2]; |
| 87 | |
| 88 | /* configure rx filter */ |
| 89 | rfilt = ath_calcrxfilter(sc); |
| 90 | ath9k_hw_setrxfilter(ah, rfilt); |
| 91 | |
| 92 | /* configure bssid mask */ |
Felix Fietkau | 364734f | 2010-09-14 20:22:44 +0200 | [diff] [blame] | 93 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 94 | |
| 95 | /* configure operational mode */ |
| 96 | ath9k_hw_setopmode(ah); |
| 97 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 98 | /* calculate and install multicast filter */ |
| 99 | mfilt[0] = mfilt[1] = ~0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 100 | ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 103 | static bool ath_rx_edma_buf_link(struct ath_softc *sc, |
| 104 | enum ath9k_rx_qtype qtype) |
| 105 | { |
| 106 | struct ath_hw *ah = sc->sc_ah; |
| 107 | struct ath_rx_edma *rx_edma; |
| 108 | struct sk_buff *skb; |
| 109 | struct ath_buf *bf; |
| 110 | |
| 111 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 112 | if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize) |
| 113 | return false; |
| 114 | |
| 115 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
| 116 | list_del_init(&bf->list); |
| 117 | |
| 118 | skb = bf->bf_mpdu; |
| 119 | |
| 120 | ATH_RXBUF_RESET(bf); |
| 121 | memset(skb->data, 0, ah->caps.rx_status_len); |
| 122 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 123 | ah->caps.rx_status_len, DMA_TO_DEVICE); |
| 124 | |
| 125 | SKB_CB_ATHBUF(skb) = bf; |
| 126 | ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype); |
| 127 | skb_queue_tail(&rx_edma->rx_fifo, skb); |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | static void ath_rx_addbuffer_edma(struct ath_softc *sc, |
| 133 | enum ath9k_rx_qtype qtype, int size) |
| 134 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 135 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Mohammed Shafi Shajakhan | 6a01f0c | 2012-02-28 20:54:44 +0530 | [diff] [blame] | 136 | struct ath_buf *bf, *tbf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 137 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 138 | if (list_empty(&sc->rx.rxbuf)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 139 | ath_dbg(common, QUEUE, "No free rx buf available\n"); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | |
Mohammed Shafi Shajakhan | 6a01f0c | 2012-02-28 20:54:44 +0530 | [diff] [blame] | 143 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 144 | if (!ath_rx_edma_buf_link(sc, qtype)) |
| 145 | break; |
| 146 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void ath_rx_remove_buffer(struct ath_softc *sc, |
| 150 | enum ath9k_rx_qtype qtype) |
| 151 | { |
| 152 | struct ath_buf *bf; |
| 153 | struct ath_rx_edma *rx_edma; |
| 154 | struct sk_buff *skb; |
| 155 | |
| 156 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 157 | |
| 158 | while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) { |
| 159 | bf = SKB_CB_ATHBUF(skb); |
| 160 | BUG_ON(!bf); |
| 161 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | static void ath_rx_edma_cleanup(struct ath_softc *sc) |
| 166 | { |
Mohammed Shafi Shajakhan | ba54238 | 2011-09-23 14:33:14 +0530 | [diff] [blame] | 167 | struct ath_hw *ah = sc->sc_ah; |
| 168 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 169 | struct ath_buf *bf; |
| 170 | |
| 171 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
| 172 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 173 | |
| 174 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
Mohammed Shafi Shajakhan | ba54238 | 2011-09-23 14:33:14 +0530 | [diff] [blame] | 175 | if (bf->bf_mpdu) { |
| 176 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
| 177 | common->rx_bufsize, |
| 178 | DMA_BIDIRECTIONAL); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 179 | dev_kfree_skb_any(bf->bf_mpdu); |
Mohammed Shafi Shajakhan | ba54238 | 2011-09-23 14:33:14 +0530 | [diff] [blame] | 180 | bf->bf_buf_addr = 0; |
| 181 | bf->bf_mpdu = NULL; |
| 182 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 183 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size) |
| 187 | { |
| 188 | skb_queue_head_init(&rx_edma->rx_fifo); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 189 | rx_edma->rx_fifo_hwsize = size; |
| 190 | } |
| 191 | |
| 192 | static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) |
| 193 | { |
| 194 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 195 | struct ath_hw *ah = sc->sc_ah; |
| 196 | struct sk_buff *skb; |
| 197 | struct ath_buf *bf; |
| 198 | int error = 0, i; |
| 199 | u32 size; |
| 200 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 201 | ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize - |
| 202 | ah->caps.rx_status_len); |
| 203 | |
| 204 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP], |
| 205 | ah->caps.rx_lp_qdepth); |
| 206 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP], |
| 207 | ah->caps.rx_hp_qdepth); |
| 208 | |
| 209 | size = sizeof(struct ath_buf) * nbufs; |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 210 | bf = devm_kzalloc(sc->dev, size, GFP_KERNEL); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 211 | if (!bf) |
| 212 | return -ENOMEM; |
| 213 | |
| 214 | INIT_LIST_HEAD(&sc->rx.rxbuf); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 215 | |
| 216 | for (i = 0; i < nbufs; i++, bf++) { |
| 217 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL); |
| 218 | if (!skb) { |
| 219 | error = -ENOMEM; |
| 220 | goto rx_init_fail; |
| 221 | } |
| 222 | |
| 223 | memset(skb->data, 0, common->rx_bufsize); |
| 224 | bf->bf_mpdu = skb; |
| 225 | |
| 226 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 227 | common->rx_bufsize, |
| 228 | DMA_BIDIRECTIONAL); |
| 229 | if (unlikely(dma_mapping_error(sc->dev, |
| 230 | bf->bf_buf_addr))) { |
| 231 | dev_kfree_skb_any(skb); |
| 232 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 233 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 234 | ath_err(common, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 235 | "dma_mapping_error() on RX init\n"); |
| 236 | error = -ENOMEM; |
| 237 | goto rx_init_fail; |
| 238 | } |
| 239 | |
| 240 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 241 | } |
| 242 | |
| 243 | return 0; |
| 244 | |
| 245 | rx_init_fail: |
| 246 | ath_rx_edma_cleanup(sc); |
| 247 | return error; |
| 248 | } |
| 249 | |
| 250 | static void ath_edma_start_recv(struct ath_softc *sc) |
| 251 | { |
| 252 | spin_lock_bh(&sc->rx.rxbuflock); |
| 253 | |
| 254 | ath9k_hw_rxena(sc->sc_ah); |
| 255 | |
| 256 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP, |
| 257 | sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize); |
| 258 | |
| 259 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP, |
| 260 | sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize); |
| 261 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 262 | ath_opmode_init(sc); |
| 263 | |
Sujith Manoharan | 4cb54fa | 2012-06-04 16:27:52 +0530 | [diff] [blame] | 264 | ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)); |
Luis R. Rodriguez | 7583c550 | 2010-10-20 16:07:04 -0700 | [diff] [blame] | 265 | |
| 266 | spin_unlock_bh(&sc->rx.rxbuflock); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static void ath_edma_stop_recv(struct ath_softc *sc) |
| 270 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 271 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 272 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 273 | } |
| 274 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 275 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
| 276 | { |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 277 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 278 | struct sk_buff *skb; |
| 279 | struct ath_buf *bf; |
| 280 | int error = 0; |
| 281 | |
Luis R. Rodriguez | 4bdd1e9 | 2010-10-26 15:27:24 -0700 | [diff] [blame] | 282 | spin_lock_init(&sc->sc_pcu_lock); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 283 | spin_lock_init(&sc->rx.rxbuflock); |
Sujith Manoharan | 781b14a | 2012-06-04 20:23:55 +0530 | [diff] [blame] | 284 | clear_bit(SC_OP_RXFLUSH, &sc->sc_flags); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 285 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 286 | common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 + |
| 287 | sc->sc_ah->caps.rx_status_len; |
| 288 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 289 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 290 | return ath_rx_edma_init(sc, nbufs); |
| 291 | } else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 292 | ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 293 | common->cachelsz, common->rx_bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 294 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 295 | /* Initialize rx descriptors */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 296 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 297 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 298 | "rx", nbufs, 1, 0); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 299 | if (error != 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 300 | ath_err(common, |
| 301 | "failed to allocate rx descriptors: %d\n", |
| 302 | error); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 303 | goto err; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 304 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 305 | |
| 306 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 307 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, |
| 308 | GFP_KERNEL); |
| 309 | if (skb == NULL) { |
| 310 | error = -ENOMEM; |
| 311 | goto err; |
| 312 | } |
| 313 | |
| 314 | bf->bf_mpdu = skb; |
| 315 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 316 | common->rx_bufsize, |
| 317 | DMA_FROM_DEVICE); |
| 318 | if (unlikely(dma_mapping_error(sc->dev, |
| 319 | bf->bf_buf_addr))) { |
| 320 | dev_kfree_skb_any(skb); |
| 321 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 322 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 323 | ath_err(common, |
| 324 | "dma_mapping_error() on RX init\n"); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 325 | error = -ENOMEM; |
| 326 | goto err; |
| 327 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 328 | } |
| 329 | sc->rx.rxlink = NULL; |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 330 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 331 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 332 | err: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 333 | if (error) |
| 334 | ath_rx_cleanup(sc); |
| 335 | |
| 336 | return error; |
| 337 | } |
| 338 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 339 | void ath_rx_cleanup(struct ath_softc *sc) |
| 340 | { |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 341 | struct ath_hw *ah = sc->sc_ah; |
| 342 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 343 | struct sk_buff *skb; |
| 344 | struct ath_buf *bf; |
| 345 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 346 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 347 | ath_rx_edma_cleanup(sc); |
| 348 | return; |
| 349 | } else { |
| 350 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 351 | skb = bf->bf_mpdu; |
| 352 | if (skb) { |
| 353 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
| 354 | common->rx_bufsize, |
| 355 | DMA_FROM_DEVICE); |
| 356 | dev_kfree_skb(skb); |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 357 | bf->bf_buf_addr = 0; |
| 358 | bf->bf_mpdu = NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 359 | } |
Luis R. Rodriguez | 051b919 | 2009-03-23 18:25:01 -0400 | [diff] [blame] | 360 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 361 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /* |
| 365 | * Calculate the receive filter according to the |
| 366 | * operating mode and state: |
| 367 | * |
| 368 | * o always accept unicast, broadcast, and multicast traffic |
| 369 | * o maintain current state of phy error reception (the hal |
| 370 | * may enable phy error frames for noise immunity work) |
| 371 | * o probe request frames are accepted only when operating in |
| 372 | * hostap, adhoc, or monitor modes |
| 373 | * o enable promiscuous mode according to the interface state |
| 374 | * o accept beacons: |
| 375 | * - when operating in adhoc mode so the 802.11 layer creates |
| 376 | * node table entries for peers, |
| 377 | * - when operating in station mode for collecting rssi data when |
| 378 | * the station is otherwise quiet, or |
| 379 | * - when operating as a repeater so we see repeater-sta beacons |
| 380 | * - when scanning |
| 381 | */ |
| 382 | |
| 383 | u32 ath_calcrxfilter(struct ath_softc *sc) |
| 384 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 385 | u32 rfilt; |
| 386 | |
Felix Fietkau | ac06697 | 2011-10-08 15:49:57 +0200 | [diff] [blame] | 387 | rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 388 | | ATH9K_RX_FILTER_MCAST; |
| 389 | |
Jouni Malinen | 9c1d8e4 | 2010-10-13 17:29:31 +0300 | [diff] [blame] | 390 | if (sc->rx.rxfilter & FIF_PROBE_REQ) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 391 | rfilt |= ATH9K_RX_FILTER_PROBEREQ; |
| 392 | |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 393 | /* |
| 394 | * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station |
| 395 | * mode interface or when in monitor mode. AP mode does not need this |
| 396 | * since it receives all in-BSS frames anyway. |
| 397 | */ |
Felix Fietkau | 2e28694 | 2011-03-09 01:48:12 +0100 | [diff] [blame] | 398 | if (sc->sc_ah->is_monitoring) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 399 | rfilt |= ATH9K_RX_FILTER_PROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 400 | |
Sujith | d42c6b7 | 2009-02-04 08:10:22 +0530 | [diff] [blame] | 401 | if (sc->rx.rxfilter & FIF_CONTROL) |
| 402 | rfilt |= ATH9K_RX_FILTER_CONTROL; |
| 403 | |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 404 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) && |
Ben Greear | cfda669 | 2010-09-14 12:00:22 -0700 | [diff] [blame] | 405 | (sc->nvifs <= 1) && |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 406 | !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC)) |
| 407 | rfilt |= ATH9K_RX_FILTER_MYBEACON; |
| 408 | else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 409 | rfilt |= ATH9K_RX_FILTER_BEACON; |
| 410 | |
Felix Fietkau | 264bbec | 2011-04-07 19:24:23 +0200 | [diff] [blame] | 411 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || |
Senthil Balasubramanian | 66afad0 | 2009-09-18 15:06:07 +0530 | [diff] [blame] | 412 | (sc->rx.rxfilter & FIF_PSPOLL)) |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 413 | rfilt |= ATH9K_RX_FILTER_PSPOLL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 414 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 415 | if (conf_is_ht(&sc->hw->conf)) |
| 416 | rfilt |= ATH9K_RX_FILTER_COMP_BAR; |
| 417 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 418 | if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) { |
Thomas Wagner | a549459 | 2012-09-25 21:32:55 +0530 | [diff] [blame] | 419 | /* This is needed for older chips */ |
| 420 | if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160) |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 421 | rfilt |= ATH9K_RX_FILTER_PROM; |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 422 | rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL; |
| 423 | } |
| 424 | |
Gabor Juhos | b3d7aa4 | 2012-07-03 19:13:33 +0200 | [diff] [blame] | 425 | if (AR_SREV_9550(sc->sc_ah)) |
| 426 | rfilt |= ATH9K_RX_FILTER_4ADDRESS; |
| 427 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 428 | return rfilt; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 429 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 432 | int ath_startrecv(struct ath_softc *sc) |
| 433 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 434 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 435 | struct ath_buf *bf, *tbf; |
| 436 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 437 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 438 | ath_edma_start_recv(sc); |
| 439 | return 0; |
| 440 | } |
| 441 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 442 | spin_lock_bh(&sc->rx.rxbuflock); |
| 443 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 444 | goto start_recv; |
| 445 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 446 | sc->rx.rxlink = NULL; |
| 447 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 448 | ath_rx_buf_link(sc, bf); |
| 449 | } |
| 450 | |
| 451 | /* We could have deleted elements so the list may be empty now */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 452 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 453 | goto start_recv; |
| 454 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 455 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 456 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 457 | ath9k_hw_rxena(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 458 | |
| 459 | start_recv: |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 460 | ath_opmode_init(sc); |
Sujith Manoharan | 4cb54fa | 2012-06-04 16:27:52 +0530 | [diff] [blame] | 461 | ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 462 | |
Luis R. Rodriguez | 7583c550 | 2010-10-20 16:07:04 -0700 | [diff] [blame] | 463 | spin_unlock_bh(&sc->rx.rxbuflock); |
| 464 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 465 | return 0; |
| 466 | } |
| 467 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 468 | bool ath_stoprecv(struct ath_softc *sc) |
| 469 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 470 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | 5882da02 | 2011-04-08 20:13:18 +0200 | [diff] [blame] | 471 | bool stopped, reset = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 472 | |
Luis R. Rodriguez | 1e45028 | 2010-10-20 16:07:03 -0700 | [diff] [blame] | 473 | spin_lock_bh(&sc->rx.rxbuflock); |
Felix Fietkau | d47844a | 2010-11-20 03:08:47 +0100 | [diff] [blame] | 474 | ath9k_hw_abortpcurecv(ah); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 475 | ath9k_hw_setrxfilter(ah, 0); |
Felix Fietkau | 5882da02 | 2011-04-08 20:13:18 +0200 | [diff] [blame] | 476 | stopped = ath9k_hw_stopdmarecv(ah, &reset); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 477 | |
| 478 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 479 | ath_edma_stop_recv(sc); |
| 480 | else |
| 481 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | 1e45028 | 2010-10-20 16:07:03 -0700 | [diff] [blame] | 482 | spin_unlock_bh(&sc->rx.rxbuflock); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 483 | |
Rajkumar Manoharan | d584747 | 2010-12-20 14:39:51 +0530 | [diff] [blame] | 484 | if (!(ah->ah_flags & AH_UNPLUGGED) && |
| 485 | unlikely(!stopped)) { |
Ben Greear | d7fd1b50 | 2010-12-06 13:13:07 -0800 | [diff] [blame] | 486 | ath_err(ath9k_hw_common(sc->sc_ah), |
| 487 | "Could not stop RX, we could be " |
| 488 | "confusing the DMA engine when we start RX up\n"); |
| 489 | ATH_DBG_WARN_ON_ONCE(!stopped); |
| 490 | } |
Felix Fietkau | 2232d31 | 2011-04-15 00:41:43 +0200 | [diff] [blame] | 491 | return stopped && !reset; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 494 | void ath_flushrecv(struct ath_softc *sc) |
| 495 | { |
Sujith Manoharan | 781b14a | 2012-06-04 20:23:55 +0530 | [diff] [blame] | 496 | set_bit(SC_OP_RXFLUSH, &sc->sc_flags); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 497 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 498 | ath_rx_tasklet(sc, 1, true); |
| 499 | ath_rx_tasklet(sc, 1, false); |
Sujith Manoharan | 781b14a | 2012-06-04 20:23:55 +0530 | [diff] [blame] | 500 | clear_bit(SC_OP_RXFLUSH, &sc->sc_flags); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 503 | static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) |
| 504 | { |
| 505 | /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */ |
| 506 | struct ieee80211_mgmt *mgmt; |
| 507 | u8 *pos, *end, id, elen; |
| 508 | struct ieee80211_tim_ie *tim; |
| 509 | |
| 510 | mgmt = (struct ieee80211_mgmt *)skb->data; |
| 511 | pos = mgmt->u.beacon.variable; |
| 512 | end = skb->data + skb->len; |
| 513 | |
| 514 | while (pos + 2 < end) { |
| 515 | id = *pos++; |
| 516 | elen = *pos++; |
| 517 | if (pos + elen > end) |
| 518 | break; |
| 519 | |
| 520 | if (id == WLAN_EID_TIM) { |
| 521 | if (elen < sizeof(*tim)) |
| 522 | break; |
| 523 | tim = (struct ieee80211_tim_ie *) pos; |
| 524 | if (tim->dtim_count != 0) |
| 525 | break; |
| 526 | return tim->bitmap_ctrl & 0x01; |
| 527 | } |
| 528 | |
| 529 | pos += elen; |
| 530 | } |
| 531 | |
| 532 | return false; |
| 533 | } |
| 534 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 535 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) |
| 536 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 537 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 538 | |
| 539 | if (skb->len < 24 + 8 + 2 + 2) |
| 540 | return; |
| 541 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 542 | sc->ps_flags &= ~PS_WAIT_FOR_BEACON; |
Gabor Juhos | 293dc5d | 2009-06-19 12:17:48 +0200 | [diff] [blame] | 543 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 544 | if (sc->ps_flags & PS_BEACON_SYNC) { |
| 545 | sc->ps_flags &= ~PS_BEACON_SYNC; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 546 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 547 | "Reconfigure Beacon timers based on timestamp from the AP\n"); |
Sujith Manoharan | ef4ad63 | 2012-07-17 17:15:56 +0530 | [diff] [blame] | 548 | ath9k_set_beacon(sc); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 549 | } |
| 550 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 551 | if (ath_beacon_dtim_pending_cab(skb)) { |
| 552 | /* |
| 553 | * Remain awake waiting for buffered broadcast/multicast |
Gabor Juhos | 58f5fff | 2009-06-17 20:53:20 +0200 | [diff] [blame] | 554 | * frames. If the last broadcast/multicast frame is not |
| 555 | * received properly, the next beacon frame will work as |
| 556 | * a backup trigger for returning into NETWORK SLEEP state, |
| 557 | * so we are waiting for it as well. |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 558 | */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 559 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 560 | "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 561 | sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON; |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 562 | return; |
| 563 | } |
| 564 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 565 | if (sc->ps_flags & PS_WAIT_FOR_CAB) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 566 | /* |
| 567 | * This can happen if a broadcast frame is dropped or the AP |
| 568 | * fails to send a frame indicating that all CAB frames have |
| 569 | * been delivered. |
| 570 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 571 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 572 | ath_dbg(common, PS, "PS wait for CAB frames timed out\n"); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 573 | } |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 574 | } |
| 575 | |
Rajkumar Manoharan | f73c604 | 2011-09-26 22:16:56 +0530 | [diff] [blame] | 576 | 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] | 577 | { |
| 578 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 579 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 580 | |
| 581 | hdr = (struct ieee80211_hdr *)skb->data; |
| 582 | |
| 583 | /* Process Beacon and CAB receive in PS state */ |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 584 | if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc)) |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 585 | && mybeacon) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 586 | ath_rx_ps_beacon(sc, skb); |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 587 | } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && |
| 588 | (ieee80211_is_data(hdr->frame_control) || |
| 589 | ieee80211_is_action(hdr->frame_control)) && |
| 590 | is_multicast_ether_addr(hdr->addr1) && |
| 591 | !ieee80211_has_moredata(hdr->frame_control)) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 592 | /* |
| 593 | * No more broadcast/multicast frames to be received at this |
| 594 | * point. |
| 595 | */ |
Senthil Balasubramanian | 3fac6df | 2010-09-16 15:12:35 -0400 | [diff] [blame] | 596 | sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 597 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 598 | "All PS CAB frames received, back to sleep\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 599 | } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) && |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 600 | !is_multicast_ether_addr(hdr->addr1) && |
| 601 | !ieee80211_has_morefrags(hdr->frame_control)) { |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 602 | sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 603 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 604 | "Going back to sleep after having received PS-Poll data (0x%lx)\n", |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 605 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 606 | PS_WAIT_FOR_CAB | |
| 607 | PS_WAIT_FOR_PSPOLL_DATA | |
| 608 | PS_WAIT_FOR_TX_ACK)); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 612 | static bool ath_edma_get_buffers(struct ath_softc *sc, |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 613 | enum ath9k_rx_qtype qtype, |
| 614 | struct ath_rx_status *rs, |
| 615 | struct ath_buf **dest) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 616 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 617 | struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype]; |
| 618 | struct ath_hw *ah = sc->sc_ah; |
| 619 | struct ath_common *common = ath9k_hw_common(ah); |
| 620 | struct sk_buff *skb; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 621 | struct ath_buf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 622 | int ret; |
| 623 | |
| 624 | skb = skb_peek(&rx_edma->rx_fifo); |
| 625 | if (!skb) |
| 626 | return false; |
| 627 | |
| 628 | bf = SKB_CB_ATHBUF(skb); |
| 629 | BUG_ON(!bf); |
| 630 | |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 631 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 632 | common->rx_bufsize, DMA_FROM_DEVICE); |
| 633 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 634 | ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data); |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 635 | if (ret == -EINPROGRESS) { |
| 636 | /*let device gain the buffer again*/ |
| 637 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 638 | common->rx_bufsize, DMA_FROM_DEVICE); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 639 | return false; |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 640 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 641 | |
| 642 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 643 | if (ret == -EINVAL) { |
| 644 | /* corrupt descriptor, skip this one and the following one */ |
| 645 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 646 | ath_rx_edma_buf_link(sc, qtype); |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 647 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 648 | skb = skb_peek(&rx_edma->rx_fifo); |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 649 | if (skb) { |
| 650 | bf = SKB_CB_ATHBUF(skb); |
| 651 | BUG_ON(!bf); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 652 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 653 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 654 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 655 | ath_rx_edma_buf_link(sc, qtype); |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 656 | } |
Tom Hughes | 6bb51c7 | 2012-06-27 18:21:15 +0100 | [diff] [blame] | 657 | |
| 658 | bf = NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 659 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 660 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 661 | *dest = bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 662 | return true; |
| 663 | } |
| 664 | |
| 665 | static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc, |
| 666 | struct ath_rx_status *rs, |
| 667 | enum ath9k_rx_qtype qtype) |
| 668 | { |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 669 | struct ath_buf *bf = NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 670 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 671 | while (ath_edma_get_buffers(sc, qtype, rs, &bf)) { |
| 672 | if (!bf) |
| 673 | continue; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 674 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 675 | return bf; |
| 676 | } |
| 677 | return NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc, |
| 681 | struct ath_rx_status *rs) |
| 682 | { |
| 683 | struct ath_hw *ah = sc->sc_ah; |
| 684 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 685 | struct ath_desc *ds; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 686 | struct ath_buf *bf; |
| 687 | int ret; |
| 688 | |
| 689 | if (list_empty(&sc->rx.rxbuf)) { |
| 690 | sc->rx.rxlink = NULL; |
| 691 | return NULL; |
| 692 | } |
| 693 | |
| 694 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
| 695 | ds = bf->bf_desc; |
| 696 | |
| 697 | /* |
| 698 | * Must provide the virtual address of the current |
| 699 | * descriptor, the physical address, and the virtual |
| 700 | * address of the next descriptor in the h/w chain. |
| 701 | * This allows the HAL to look ahead to see if the |
| 702 | * hardware is done with a descriptor by checking the |
| 703 | * done bit in the following descriptor and the address |
| 704 | * of the current descriptor the DMA engine is working |
| 705 | * on. All this is necessary because of our use of |
| 706 | * a self-linked list to avoid rx overruns. |
| 707 | */ |
Rajkumar Manoharan | 3de2111 | 2011-08-13 10:28:11 +0530 | [diff] [blame] | 708 | ret = ath9k_hw_rxprocdesc(ah, ds, rs); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 709 | if (ret == -EINPROGRESS) { |
| 710 | struct ath_rx_status trs; |
| 711 | struct ath_buf *tbf; |
| 712 | struct ath_desc *tds; |
| 713 | |
| 714 | memset(&trs, 0, sizeof(trs)); |
| 715 | if (list_is_last(&bf->list, &sc->rx.rxbuf)) { |
| 716 | sc->rx.rxlink = NULL; |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | tbf = list_entry(bf->list.next, struct ath_buf, list); |
| 721 | |
| 722 | /* |
| 723 | * On some hardware the descriptor status words could |
| 724 | * get corrupted, including the done bit. Because of |
| 725 | * this, check if the next descriptor's done bit is |
| 726 | * set or not. |
| 727 | * |
| 728 | * If the next descriptor's done bit is set, the current |
| 729 | * descriptor has been corrupted. Force s/w to discard |
| 730 | * this descriptor and continue... |
| 731 | */ |
| 732 | |
| 733 | tds = tbf->bf_desc; |
Rajkumar Manoharan | 3de2111 | 2011-08-13 10:28:11 +0530 | [diff] [blame] | 734 | ret = ath9k_hw_rxprocdesc(ah, tds, &trs); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 735 | if (ret == -EINPROGRESS) |
| 736 | return NULL; |
| 737 | } |
| 738 | |
| 739 | if (!bf->bf_mpdu) |
| 740 | return bf; |
| 741 | |
| 742 | /* |
| 743 | * Synchronize the DMA transfer with CPU before |
| 744 | * 1. accessing the frame |
| 745 | * 2. requeueing the same buffer to h/w |
| 746 | */ |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 747 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 748 | common->rx_bufsize, |
| 749 | DMA_FROM_DEVICE); |
| 750 | |
| 751 | return bf; |
| 752 | } |
| 753 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 754 | /* Assumes you've already done the endian to CPU conversion */ |
| 755 | static bool ath9k_rx_accept(struct ath_common *common, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 756 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 757 | struct ieee80211_rx_status *rxs, |
| 758 | struct ath_rx_status *rx_stats, |
| 759 | bool *decrypt_error) |
| 760 | { |
Felix Fietkau | ec20599 | 2011-10-08 22:02:59 +0200 | [diff] [blame] | 761 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 762 | bool is_mc, is_valid_tkip, strip_mic, mic_error; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 763 | struct ath_hw *ah = common->ah; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 764 | __le16 fc; |
Vasanthakumar Thiagarajan | b7b1b51 | 2010-05-20 14:34:48 -0700 | [diff] [blame] | 765 | u8 rx_status_len = ah->caps.rx_status_len; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 766 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 767 | fc = hdr->frame_control; |
| 768 | |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 769 | is_mc = !!is_multicast_ether_addr(hdr->addr1); |
| 770 | is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && |
| 771 | test_bit(rx_stats->rs_keyix, common->tkip_keymap); |
Bill Jordan | 152e585 | 2011-08-19 11:10:22 -0400 | [diff] [blame] | 772 | strip_mic = is_valid_tkip && ieee80211_is_data(fc) && |
Michael Liang | 2a5783b | 2012-04-20 17:11:57 +0800 | [diff] [blame] | 773 | ieee80211_has_protected(fc) && |
Bill Jordan | 152e585 | 2011-08-19 11:10:22 -0400 | [diff] [blame] | 774 | !(rx_stats->rs_status & |
Felix Fietkau | 846d936 | 2011-10-08 22:02:58 +0200 | [diff] [blame] | 775 | (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC | |
| 776 | ATH9K_RXERR_KEYMISS)); |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 777 | |
Felix Fietkau | f88373f | 2012-02-05 21:15:17 +0100 | [diff] [blame] | 778 | /* |
| 779 | * Key miss events are only relevant for pairwise keys where the |
| 780 | * descriptor does contain a valid key index. This has been observed |
| 781 | * mostly with CCMP encryption. |
| 782 | */ |
Felix Fietkau | bed3d9c | 2012-06-23 19:23:31 +0200 | [diff] [blame] | 783 | if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID || |
| 784 | !test_bit(rx_stats->rs_keyix, common->ccmp_keymap)) |
Felix Fietkau | f88373f | 2012-02-05 21:15:17 +0100 | [diff] [blame] | 785 | rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS; |
| 786 | |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 787 | if (!rx_stats->rs_datalen) { |
| 788 | RX_STAT_INC(rx_len_err); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 789 | return false; |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 792 | /* |
| 793 | * rs_status follows rs_datalen so if rs_datalen is too large |
| 794 | * we can take a hint that hardware corrupted it, so ignore |
| 795 | * those frames. |
| 796 | */ |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 797 | if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) { |
| 798 | RX_STAT_INC(rx_len_err); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 799 | return false; |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 800 | } |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 801 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 802 | /* Only use error bits from the last fragment */ |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 803 | if (rx_stats->rs_more) |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 804 | return true; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 805 | |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 806 | mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) && |
| 807 | !ieee80211_has_morefrags(fc) && |
| 808 | !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) && |
| 809 | (rx_stats->rs_status & ATH9K_RXERR_MIC); |
| 810 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 811 | /* |
| 812 | * The rx_stats->rs_status will not be set until the end of the |
| 813 | * chained descriptors so it can be ignored if rs_more is set. The |
| 814 | * rs_more will be false at the last element of the chained |
| 815 | * descriptors. |
| 816 | */ |
| 817 | if (rx_stats->rs_status != 0) { |
Felix Fietkau | 846d936 | 2011-10-08 22:02:58 +0200 | [diff] [blame] | 818 | u8 status_mask; |
| 819 | |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 820 | if (rx_stats->rs_status & ATH9K_RXERR_CRC) { |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 821 | rxs->flag |= RX_FLAG_FAILED_FCS_CRC; |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 822 | mic_error = false; |
| 823 | } |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 824 | if (rx_stats->rs_status & ATH9K_RXERR_PHY) |
| 825 | return false; |
| 826 | |
Felix Fietkau | 846d936 | 2011-10-08 22:02:58 +0200 | [diff] [blame] | 827 | if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) || |
| 828 | (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) { |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 829 | *decrypt_error = true; |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 830 | mic_error = false; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 831 | } |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 832 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 833 | /* |
| 834 | * Reject error frames with the exception of |
| 835 | * decryption and MIC failures. For monitor mode, |
| 836 | * we also ignore the CRC error. |
| 837 | */ |
Felix Fietkau | 846d936 | 2011-10-08 22:02:58 +0200 | [diff] [blame] | 838 | status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | |
| 839 | ATH9K_RXERR_KEYMISS; |
| 840 | |
Felix Fietkau | ec20599 | 2011-10-08 22:02:59 +0200 | [diff] [blame] | 841 | if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL)) |
Felix Fietkau | 846d936 | 2011-10-08 22:02:58 +0200 | [diff] [blame] | 842 | status_mask |= ATH9K_RXERR_CRC; |
| 843 | |
| 844 | if (rx_stats->rs_status & ~status_mask) |
| 845 | return false; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 846 | } |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 847 | |
| 848 | /* |
| 849 | * For unicast frames the MIC error bit can have false positives, |
| 850 | * so all MIC error reports need to be validated in software. |
| 851 | * False negatives are not common, so skip software verification |
| 852 | * if the hardware considers the MIC valid. |
| 853 | */ |
| 854 | if (strip_mic) |
| 855 | rxs->flag |= RX_FLAG_MMIC_STRIPPED; |
| 856 | else if (is_mc && mic_error) |
| 857 | rxs->flag |= RX_FLAG_MMIC_ERROR; |
| 858 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 859 | return true; |
| 860 | } |
| 861 | |
| 862 | static int ath9k_process_rate(struct ath_common *common, |
| 863 | struct ieee80211_hw *hw, |
| 864 | struct ath_rx_status *rx_stats, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 865 | struct ieee80211_rx_status *rxs) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 866 | { |
| 867 | struct ieee80211_supported_band *sband; |
| 868 | enum ieee80211_band band; |
| 869 | unsigned int i = 0; |
Ben Greear | 990e08a | 2012-04-17 15:19:03 -0700 | [diff] [blame] | 870 | struct ath_softc __maybe_unused *sc = common->priv; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 871 | |
| 872 | band = hw->conf.channel->band; |
| 873 | sband = hw->wiphy->bands[band]; |
| 874 | |
| 875 | if (rx_stats->rs_rate & 0x80) { |
| 876 | /* HT rate */ |
| 877 | rxs->flag |= RX_FLAG_HT; |
| 878 | if (rx_stats->rs_flags & ATH9K_RX_2040) |
| 879 | rxs->flag |= RX_FLAG_40MHZ; |
| 880 | if (rx_stats->rs_flags & ATH9K_RX_GI) |
| 881 | rxs->flag |= RX_FLAG_SHORT_GI; |
| 882 | rxs->rate_idx = rx_stats->rs_rate & 0x7f; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | for (i = 0; i < sband->n_bitrates; i++) { |
| 887 | if (sband->bitrates[i].hw_value == rx_stats->rs_rate) { |
| 888 | rxs->rate_idx = i; |
| 889 | return 0; |
| 890 | } |
| 891 | if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) { |
| 892 | rxs->flag |= RX_FLAG_SHORTPRE; |
| 893 | rxs->rate_idx = i; |
| 894 | return 0; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | /* |
| 899 | * No valid hardware bitrate found -- we should not get here |
| 900 | * because hardware has already validated this frame as OK. |
| 901 | */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 902 | ath_dbg(common, ANY, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 903 | "unsupported hw bitrate detected 0x%02x using 1 Mbit\n", |
| 904 | rx_stats->rs_rate); |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 905 | RX_STAT_INC(rx_rate_err); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 906 | return -EINVAL; |
| 907 | } |
| 908 | |
| 909 | static void ath9k_process_rssi(struct ath_common *common, |
| 910 | struct ieee80211_hw *hw, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 911 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 912 | struct ath_rx_status *rx_stats) |
| 913 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 914 | struct ath_softc *sc = hw->priv; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 915 | struct ath_hw *ah = common->ah; |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 916 | int last_rssi; |
Felix Fietkau | 2ef1675 | 2012-03-03 15:17:06 +0100 | [diff] [blame] | 917 | int rssi = rx_stats->rs_rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 918 | |
Rajkumar Manoharan | cf3af74 | 2011-08-27 16:17:47 +0530 | [diff] [blame] | 919 | if (!rx_stats->is_mybeacon || |
| 920 | ((ah->opmode != NL80211_IFTYPE_STATION) && |
| 921 | (ah->opmode != NL80211_IFTYPE_ADHOC))) |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 922 | return; |
| 923 | |
Felix Fietkau | 9fa23e1 | 2010-10-15 20:03:31 +0200 | [diff] [blame] | 924 | if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr) |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 925 | ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi); |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 926 | |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 927 | last_rssi = sc->last_rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 928 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) |
Felix Fietkau | 2ef1675 | 2012-03-03 15:17:06 +0100 | [diff] [blame] | 929 | rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER); |
| 930 | if (rssi < 0) |
| 931 | rssi = 0; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 932 | |
| 933 | /* Update Beacon RSSI, this is used by ANI. */ |
Felix Fietkau | 2ef1675 | 2012-03-03 15:17:06 +0100 | [diff] [blame] | 934 | ah->stats.avgbrssi = rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | /* |
| 938 | * For Decrypt or Demic errors, we only mark packet status here and always push |
| 939 | * up the frame up to let mac80211 handle the actual error case, be it no |
| 940 | * decryption key or real decryption error. This let us keep statistics there. |
| 941 | */ |
| 942 | static int ath9k_rx_skb_preprocess(struct ath_common *common, |
| 943 | struct ieee80211_hw *hw, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 944 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 945 | struct ath_rx_status *rx_stats, |
| 946 | struct ieee80211_rx_status *rx_status, |
| 947 | bool *decrypt_error) |
| 948 | { |
Felix Fietkau | f749b94 | 2011-07-28 14:08:57 +0200 | [diff] [blame] | 949 | struct ath_hw *ah = common->ah; |
| 950 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 951 | /* |
| 952 | * everything but the rate is checked here, the rate check is done |
| 953 | * separately to avoid doing two lookups for a rate for each frame. |
| 954 | */ |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 955 | if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 956 | return -EINVAL; |
| 957 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 958 | /* Only use status info from the last fragment */ |
| 959 | if (rx_stats->rs_more) |
| 960 | return 0; |
| 961 | |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 962 | ath9k_process_rssi(common, hw, hdr, rx_stats); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 963 | |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 964 | if (ath9k_process_rate(common, hw, rx_stats, rx_status)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 965 | return -EINVAL; |
| 966 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 967 | rx_status->band = hw->conf.channel->band; |
| 968 | rx_status->freq = hw->conf.channel->center_freq; |
Felix Fietkau | f749b94 | 2011-07-28 14:08:57 +0200 | [diff] [blame] | 969 | rx_status->signal = ah->noise + rx_stats->rs_rssi; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 970 | rx_status->antenna = rx_stats->rs_antenna; |
Thomas Pedersen | 96d2137 | 2012-12-10 14:48:01 -0800 | [diff] [blame] | 971 | rx_status->flag |= RX_FLAG_MACTIME_END; |
Felix Fietkau | 2ef1675 | 2012-03-03 15:17:06 +0100 | [diff] [blame] | 972 | if (rx_stats->rs_moreaggr) |
| 973 | rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | static void ath9k_rx_skb_postprocess(struct ath_common *common, |
| 979 | struct sk_buff *skb, |
| 980 | struct ath_rx_status *rx_stats, |
| 981 | struct ieee80211_rx_status *rxs, |
| 982 | bool decrypt_error) |
| 983 | { |
| 984 | struct ath_hw *ah = common->ah; |
| 985 | struct ieee80211_hdr *hdr; |
| 986 | int hdrlen, padpos, padsize; |
| 987 | u8 keyix; |
| 988 | __le16 fc; |
| 989 | |
| 990 | /* see if any padding is done by the hw and remove it */ |
| 991 | hdr = (struct ieee80211_hdr *) skb->data; |
| 992 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 993 | fc = hdr->frame_control; |
| 994 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 995 | |
| 996 | /* The MAC header is padded to have 32-bit boundary if the |
| 997 | * packet payload is non-zero. The general calculation for |
| 998 | * padsize would take into account odd header lengths: |
| 999 | * padsize = (4 - padpos % 4) % 4; However, since only |
| 1000 | * even-length headers are used, padding can only be 0 or 2 |
| 1001 | * bytes and we can optimize this a bit. In addition, we must |
| 1002 | * not try to remove padding from short control frames that do |
| 1003 | * not have payload. */ |
| 1004 | padsize = padpos & 3; |
| 1005 | if (padsize && skb->len>=padpos+padsize+FCS_LEN) { |
| 1006 | memmove(skb->data + padsize, skb->data, padpos); |
| 1007 | skb_pull(skb, padsize); |
| 1008 | } |
| 1009 | |
| 1010 | keyix = rx_stats->rs_keyix; |
| 1011 | |
| 1012 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error && |
| 1013 | ieee80211_has_protected(fc)) { |
| 1014 | rxs->flag |= RX_FLAG_DECRYPTED; |
| 1015 | } else if (ieee80211_has_protected(fc) |
| 1016 | && !decrypt_error && skb->len >= hdrlen + 4) { |
| 1017 | keyix = skb->data[hdrlen + 3] >> 6; |
| 1018 | |
| 1019 | if (test_bit(keyix, common->keymap)) |
| 1020 | rxs->flag |= RX_FLAG_DECRYPTED; |
| 1021 | } |
| 1022 | if (ah->sw_mgmt_crypto && |
| 1023 | (rxs->flag & RX_FLAG_DECRYPTED) && |
| 1024 | ieee80211_is_mgmt(fc)) |
| 1025 | /* Use software decrypt for management frames. */ |
| 1026 | rxs->flag &= ~RX_FLAG_DECRYPTED; |
| 1027 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1028 | |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame^] | 1029 | static s8 fix_rssi_inv_only(u8 rssi_val) |
| 1030 | { |
| 1031 | if (rssi_val == 128) |
| 1032 | rssi_val = 0; |
| 1033 | return (s8) rssi_val; |
| 1034 | } |
| 1035 | |
| 1036 | |
| 1037 | static void ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr, |
| 1038 | struct ath_rx_status *rs, u64 tsf) |
| 1039 | { |
| 1040 | #ifdef CONFIG_ATH_DEBUG |
| 1041 | struct ath_hw *ah = sc->sc_ah; |
| 1042 | u8 bins[SPECTRAL_HT20_NUM_BINS]; |
| 1043 | u8 *vdata = (u8 *)hdr; |
| 1044 | struct fft_sample_ht20 fft_sample; |
| 1045 | struct ath_radar_info *radar_info; |
| 1046 | struct ath_ht20_mag_info *mag_info; |
| 1047 | int len = rs->rs_datalen; |
| 1048 | int i, dc_pos; |
| 1049 | |
| 1050 | /* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer |
| 1051 | * via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT |
| 1052 | * yet, but this is supposed to be possible as well. |
| 1053 | */ |
| 1054 | if (rs->rs_phyerr != ATH9K_PHYERR_RADAR && |
| 1055 | rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT && |
| 1056 | rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL) |
| 1057 | return; |
| 1058 | |
| 1059 | /* Variation in the data length is possible and will be fixed later. |
| 1060 | * Note that we only support HT20 for now. |
| 1061 | * |
| 1062 | * TODO: add HT20_40 support as well. |
| 1063 | */ |
| 1064 | if ((len > SPECTRAL_HT20_TOTAL_DATA_LEN + 2) || |
| 1065 | (len < SPECTRAL_HT20_TOTAL_DATA_LEN - 1)) |
| 1066 | return; |
| 1067 | |
| 1068 | /* check if spectral scan bit is set. This does not have to be checked |
| 1069 | * if received through a SPECTRAL phy error, but shouldn't hurt. |
| 1070 | */ |
| 1071 | radar_info = ((struct ath_radar_info *)&vdata[len]) - 1; |
| 1072 | if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK)) |
| 1073 | return; |
| 1074 | |
| 1075 | fft_sample.tlv.type = ATH_FFT_SAMPLE_HT20; |
| 1076 | fft_sample.tlv.length = sizeof(fft_sample) - sizeof(fft_sample.tlv); |
| 1077 | |
| 1078 | fft_sample.freq = ah->curchan->chan->center_freq; |
| 1079 | fft_sample.rssi = fix_rssi_inv_only(rs->rs_rssi_ctl0); |
| 1080 | fft_sample.noise = ah->noise; |
| 1081 | |
| 1082 | switch (len - SPECTRAL_HT20_TOTAL_DATA_LEN) { |
| 1083 | case 0: |
| 1084 | /* length correct, nothing to do. */ |
| 1085 | memcpy(bins, vdata, SPECTRAL_HT20_NUM_BINS); |
| 1086 | break; |
| 1087 | case -1: |
| 1088 | /* first byte missing, duplicate it. */ |
| 1089 | memcpy(&bins[1], vdata, SPECTRAL_HT20_NUM_BINS - 1); |
| 1090 | bins[0] = vdata[0]; |
| 1091 | break; |
| 1092 | case 2: |
| 1093 | /* MAC added 2 extra bytes at bin 30 and 32, remove them. */ |
| 1094 | memcpy(bins, vdata, 30); |
| 1095 | bins[30] = vdata[31]; |
| 1096 | memcpy(&bins[31], &vdata[33], SPECTRAL_HT20_NUM_BINS - 31); |
| 1097 | break; |
| 1098 | case 1: |
| 1099 | /* MAC added 2 extra bytes AND first byte is missing. */ |
| 1100 | bins[0] = vdata[0]; |
| 1101 | memcpy(&bins[0], vdata, 30); |
| 1102 | bins[31] = vdata[31]; |
| 1103 | memcpy(&bins[32], &vdata[33], SPECTRAL_HT20_NUM_BINS - 32); |
| 1104 | break; |
| 1105 | default: |
| 1106 | return; |
| 1107 | } |
| 1108 | |
| 1109 | /* DC value (value in the middle) is the blind spot of the spectral |
| 1110 | * sample and invalid, interpolate it. |
| 1111 | */ |
| 1112 | dc_pos = SPECTRAL_HT20_NUM_BINS / 2; |
| 1113 | bins[dc_pos] = (bins[dc_pos + 1] + bins[dc_pos - 1]) / 2; |
| 1114 | |
| 1115 | /* mag data is at the end of the frame, in front of radar_info */ |
| 1116 | mag_info = ((struct ath_ht20_mag_info *)radar_info) - 1; |
| 1117 | |
| 1118 | /* Apply exponent and grab further auxiliary information. */ |
| 1119 | for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) |
| 1120 | fft_sample.data[i] = bins[i] << mag_info->max_exp; |
| 1121 | |
| 1122 | fft_sample.max_magnitude = spectral_max_magnitude(mag_info->all_bins); |
| 1123 | fft_sample.max_index = spectral_max_index(mag_info->all_bins); |
| 1124 | fft_sample.bitmap_weight = spectral_bitmap_weight(mag_info->all_bins); |
| 1125 | fft_sample.tsf = tsf; |
| 1126 | |
| 1127 | ath_debug_send_fft_sample(sc, &fft_sample.tlv); |
| 1128 | #endif |
| 1129 | } |
| 1130 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1131 | int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) |
| 1132 | { |
| 1133 | struct ath_buf *bf; |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1134 | struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1135 | struct ieee80211_rx_status *rxs; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1136 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1137 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1138 | struct ieee80211_hw *hw = sc->hw; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1139 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c9b1417 | 2009-11-04 16:47:22 -0800 | [diff] [blame] | 1140 | int retval; |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1141 | struct ath_rx_status rs; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1142 | enum ath9k_rx_qtype qtype; |
| 1143 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
| 1144 | int dma_type; |
Vasanthakumar Thiagarajan | 5c6dd92 | 2010-05-20 14:34:47 -0700 | [diff] [blame] | 1145 | u8 rx_status_len = ah->caps.rx_status_len; |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1146 | u64 tsf = 0; |
| 1147 | u32 tsf_lower = 0; |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1148 | unsigned long flags; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1149 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1150 | if (edma) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1151 | dma_type = DMA_BIDIRECTIONAL; |
Ming Lei | 5682422 | 2010-05-14 21:15:38 +0800 | [diff] [blame] | 1152 | else |
| 1153 | dma_type = DMA_FROM_DEVICE; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1154 | |
| 1155 | qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1156 | spin_lock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1157 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1158 | tsf = ath9k_hw_gettsf64(ah); |
| 1159 | tsf_lower = tsf & 0xffffffff; |
| 1160 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1161 | do { |
Lorenzo Bianconi | e1352fd | 2012-08-10 11:00:24 +0200 | [diff] [blame] | 1162 | bool decrypt_error = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1163 | /* If handling rx interrupt and flush is in progress => exit */ |
Sujith Manoharan | 781b14a | 2012-06-04 20:23:55 +0530 | [diff] [blame] | 1164 | if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags) && (flush == 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1165 | break; |
| 1166 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1167 | memset(&rs, 0, sizeof(rs)); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1168 | if (edma) |
| 1169 | bf = ath_edma_get_next_rx_buf(sc, &rs, qtype); |
| 1170 | else |
| 1171 | bf = ath_get_next_rx_buf(sc, &rs); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1172 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1173 | if (!bf) |
| 1174 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1175 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1176 | skb = bf->bf_mpdu; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1177 | if (!skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1178 | continue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1179 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1180 | /* |
| 1181 | * Take frame header from the first fragment and RX status from |
| 1182 | * the last one. |
| 1183 | */ |
| 1184 | if (sc->rx.frag) |
| 1185 | hdr_skb = sc->rx.frag; |
| 1186 | else |
| 1187 | hdr_skb = skb; |
| 1188 | |
| 1189 | hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len); |
| 1190 | rxs = IEEE80211_SKB_RXCB(hdr_skb); |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1191 | if (ieee80211_is_beacon(hdr->frame_control)) { |
| 1192 | RX_STAT_INC(rx_beacons); |
| 1193 | if (!is_zero_ether_addr(common->curbssid) && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 1194 | ether_addr_equal(hdr->addr3, common->curbssid)) |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1195 | rs.is_mybeacon = true; |
| 1196 | else |
| 1197 | rs.is_mybeacon = false; |
| 1198 | } |
Rajkumar Manoharan | cf3af74 | 2011-08-27 16:17:47 +0530 | [diff] [blame] | 1199 | else |
| 1200 | rs.is_mybeacon = false; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1201 | |
Mohammed Shafi Shajakhan | be41b05 | 2012-10-08 21:30:51 +0530 | [diff] [blame] | 1202 | if (ieee80211_is_data_present(hdr->frame_control) && |
| 1203 | !ieee80211_is_qos_nullfunc(hdr->frame_control)) |
| 1204 | sc->rx.num_pkts++; |
| 1205 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1206 | ath_debug_stat_rx(sc, &rs); |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 1207 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1208 | /* |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1209 | * If we're asked to flush receive queue, directly |
| 1210 | * chain it back at the queue without processing it. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1211 | */ |
Sujith Manoharan | 781b14a | 2012-06-04 20:23:55 +0530 | [diff] [blame] | 1212 | if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags)) { |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1213 | RX_STAT_INC(rx_drop_rxflush); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1214 | goto requeue_drop_frag; |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1215 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1216 | |
Ashok Nagarajan | ffb1c56 | 2012-03-09 18:57:39 -0800 | [diff] [blame] | 1217 | memset(rxs, 0, sizeof(struct ieee80211_rx_status)); |
| 1218 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1219 | rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp; |
| 1220 | if (rs.rs_tstamp > tsf_lower && |
| 1221 | unlikely(rs.rs_tstamp - tsf_lower > 0x10000000)) |
| 1222 | rxs->mactime -= 0x100000000ULL; |
| 1223 | |
| 1224 | if (rs.rs_tstamp < tsf_lower && |
| 1225 | unlikely(tsf_lower - rs.rs_tstamp > 0x10000000)) |
| 1226 | rxs->mactime += 0x100000000ULL; |
| 1227 | |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame^] | 1228 | if ((rs.rs_status & ATH9K_RXERR_PHY)) |
| 1229 | ath_process_fft(sc, hdr, &rs, rxs->mactime); |
| 1230 | |
Zefir Kurtisi | 83c7657 | 2011-11-16 11:09:44 +0100 | [diff] [blame] | 1231 | retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs, |
| 1232 | rxs, &decrypt_error); |
| 1233 | if (retval) |
| 1234 | goto requeue_drop_frag; |
| 1235 | |
Rajkumar Manoharan | 01e1891 | 2012-03-15 05:34:27 +0530 | [diff] [blame] | 1236 | if (rs.is_mybeacon) { |
| 1237 | sc->hw_busy_count = 0; |
| 1238 | ath_start_rx_poll(sc, 3); |
| 1239 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1240 | /* Ensure we always have an skb to requeue once we are done |
| 1241 | * processing the current buffer's skb */ |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1242 | requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1243 | |
| 1244 | /* If there is no memory we ignore the current RX'd frame, |
| 1245 | * tell hardware it can give us a new frame using the old |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1246 | * 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] | 1247 | * processing. */ |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1248 | if (!requeue_skb) { |
| 1249 | RX_STAT_INC(rx_oom_err); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1250 | goto requeue_drop_frag; |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1251 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1252 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1253 | /* Unmap the frame */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1254 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1255 | common->rx_bufsize, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1256 | dma_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1257 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1258 | skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len); |
| 1259 | if (ah->caps.rx_status_len) |
| 1260 | skb_pull(skb, ah->caps.rx_status_len); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1261 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1262 | if (!rs.rs_more) |
| 1263 | ath9k_rx_skb_postprocess(common, hdr_skb, &rs, |
| 1264 | rxs, decrypt_error); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1265 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1266 | /* We will now give hardware our shiny new allocated skb */ |
| 1267 | bf->bf_mpdu = requeue_skb; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1268 | 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] | 1269 | common->rx_bufsize, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1270 | dma_type); |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1271 | if (unlikely(dma_mapping_error(sc->dev, |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1272 | bf->bf_buf_addr))) { |
| 1273 | dev_kfree_skb_any(requeue_skb); |
| 1274 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 1275 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1276 | ath_err(common, "dma_mapping_error() on RX\n"); |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1277 | ieee80211_rx(hw, skb); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1278 | break; |
| 1279 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1280 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1281 | if (rs.rs_more) { |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1282 | RX_STAT_INC(rx_frags); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1283 | /* |
| 1284 | * rs_more indicates chained descriptors which can be |
| 1285 | * used to link buffers together for a sort of |
| 1286 | * scatter-gather operation. |
| 1287 | */ |
| 1288 | if (sc->rx.frag) { |
| 1289 | /* too many fragments - cannot handle frame */ |
| 1290 | dev_kfree_skb_any(sc->rx.frag); |
| 1291 | dev_kfree_skb_any(skb); |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1292 | RX_STAT_INC(rx_too_many_frags_err); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1293 | skb = NULL; |
| 1294 | } |
| 1295 | sc->rx.frag = skb; |
| 1296 | goto requeue; |
| 1297 | } |
| 1298 | |
| 1299 | if (sc->rx.frag) { |
| 1300 | int space = skb->len - skb_tailroom(hdr_skb); |
| 1301 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1302 | if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) { |
| 1303 | dev_kfree_skb(skb); |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1304 | RX_STAT_INC(rx_oom_err); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1305 | goto requeue_drop_frag; |
| 1306 | } |
| 1307 | |
Eric Dumazet | b5447ff | 2012-03-15 13:43:29 -0700 | [diff] [blame] | 1308 | sc->rx.frag = NULL; |
| 1309 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1310 | skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len), |
| 1311 | skb->len); |
| 1312 | dev_kfree_skb_any(skb); |
| 1313 | skb = hdr_skb; |
| 1314 | } |
| 1315 | |
Mohammed Shafi Shajakhan | eb840a8 | 2011-11-29 20:30:35 +0530 | [diff] [blame] | 1316 | |
| 1317 | if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) { |
| 1318 | |
| 1319 | /* |
| 1320 | * change the default rx antenna if rx diversity |
| 1321 | * chooses the other antenna 3 times in a row. |
| 1322 | */ |
| 1323 | if (sc->rx.defant != rs.rs_antenna) { |
| 1324 | if (++sc->rx.rxotherant >= 3) |
| 1325 | ath_setdefantenna(sc, rs.rs_antenna); |
| 1326 | } else { |
| 1327 | sc->rx.rxotherant = 0; |
| 1328 | } |
| 1329 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1330 | } |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1331 | |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 1332 | if (rxs->flag & RX_FLAG_MMIC_STRIPPED) |
| 1333 | skb_trim(skb, skb->len - 8); |
| 1334 | |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1335 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Mohammed Shafi Shajakhan | aaef24b | 2010-12-07 20:40:58 +0530 | [diff] [blame] | 1336 | if ((sc->ps_flags & (PS_WAIT_FOR_BEACON | |
Rajkumar Manoharan | f73c604 | 2011-09-26 22:16:56 +0530 | [diff] [blame] | 1337 | PS_WAIT_FOR_CAB | |
| 1338 | PS_WAIT_FOR_PSPOLL_DATA)) || |
| 1339 | ath9k_check_auto_sleep(sc)) |
| 1340 | ath_rx_ps(sc, skb, rs.is_mybeacon); |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1341 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1342 | |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 1343 | 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] | 1344 | ath_ant_comb_scan(sc, &rs); |
| 1345 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1346 | ieee80211_rx(hw, skb); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1347 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1348 | requeue_drop_frag: |
| 1349 | if (sc->rx.frag) { |
| 1350 | dev_kfree_skb_any(sc->rx.frag); |
| 1351 | sc->rx.frag = NULL; |
| 1352 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1353 | requeue: |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1354 | if (edma) { |
| 1355 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 1356 | ath_rx_edma_buf_link(sc, qtype); |
| 1357 | } else { |
| 1358 | list_move_tail(&bf->list, &sc->rx.rxbuf); |
| 1359 | ath_rx_buf_link(sc, bf); |
Felix Fietkau | 3483288 | 2011-09-14 21:23:03 +0200 | [diff] [blame] | 1360 | if (!flush) |
| 1361 | ath9k_hw_rxena(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1362 | } |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1363 | } while (1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1364 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1365 | spin_unlock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1366 | |
Rajkumar Manoharan | 29ab0b3 | 2011-08-13 10:28:10 +0530 | [diff] [blame] | 1367 | if (!(ah->imask & ATH9K_INT_RXEOL)) { |
| 1368 | ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 1369 | ath9k_hw_set_interrupts(ah); |
Rajkumar Manoharan | 29ab0b3 | 2011-08-13 10:28:10 +0530 | [diff] [blame] | 1370 | } |
| 1371 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1372 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1373 | } |