Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 17 | #include "ath9k.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 18 | #include "ar9003_mac.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 19 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 20 | #define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb)) |
| 21 | |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 22 | static inline bool ath9k_check_auto_sleep(struct ath_softc *sc) |
| 23 | { |
| 24 | return sc->ps_enabled && |
| 25 | (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP); |
| 26 | } |
| 27 | |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 28 | static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc, |
| 29 | struct ieee80211_hdr *hdr) |
| 30 | { |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 31 | struct ieee80211_hw *hw = sc->pri_wiphy->hw; |
| 32 | int i; |
| 33 | |
| 34 | spin_lock_bh(&sc->wiphy_lock); |
| 35 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 36 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 37 | if (aphy == NULL) |
| 38 | continue; |
| 39 | if (compare_ether_addr(hdr->addr1, aphy->hw->wiphy->perm_addr) |
| 40 | == 0) { |
| 41 | hw = aphy->hw; |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | spin_unlock_bh(&sc->wiphy_lock); |
| 46 | return hw; |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 49 | /* |
| 50 | * Setup and link descriptors. |
| 51 | * |
| 52 | * 11N: we can no longer afford to self link the last descriptor. |
| 53 | * MAC acknowledges BA status as long as it copies frames to host |
| 54 | * buffer (or rx fifo). This can incorrectly acknowledge packets |
| 55 | * to a sender if last desc is self-linked. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 56 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 57 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) |
| 58 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 59 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 60 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 61 | struct ath_desc *ds; |
| 62 | struct sk_buff *skb; |
| 63 | |
| 64 | ATH_RXBUF_RESET(bf); |
| 65 | |
| 66 | ds = bf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 67 | ds->ds_link = 0; /* link to null */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 68 | ds->ds_data = bf->bf_buf_addr; |
| 69 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 70 | /* virtual addr of the beginning of the buffer. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 71 | skb = bf->bf_mpdu; |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 72 | BUG_ON(skb == NULL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 73 | ds->ds_vdata = skb->data; |
| 74 | |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 75 | /* |
| 76 | * setup rx descriptors. The rx_bufsize here tells the hardware |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 77 | * 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] | 78 | * to process |
| 79 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 80 | ath9k_hw_setuprxdesc(ah, ds, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 81 | common->rx_bufsize, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 82 | 0); |
| 83 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 84 | if (sc->rx.rxlink == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 85 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
| 86 | else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 87 | *sc->rx.rxlink = bf->bf_daddr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 88 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 89 | sc->rx.rxlink = &ds->ds_link; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 90 | ath9k_hw_rxena(ah); |
| 91 | } |
| 92 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 93 | static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) |
| 94 | { |
| 95 | /* XXX block beacon interrupts */ |
| 96 | ath9k_hw_setantenna(sc->sc_ah, antenna); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 97 | sc->rx.defant = antenna; |
| 98 | sc->rx.rxotherant = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 99 | } |
| 100 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 101 | static void ath_opmode_init(struct ath_softc *sc) |
| 102 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 103 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 104 | struct ath_common *common = ath9k_hw_common(ah); |
| 105 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 106 | u32 rfilt, mfilt[2]; |
| 107 | |
| 108 | /* configure rx filter */ |
| 109 | rfilt = ath_calcrxfilter(sc); |
| 110 | ath9k_hw_setrxfilter(ah, rfilt); |
| 111 | |
| 112 | /* configure bssid mask */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 113 | if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 114 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 115 | |
| 116 | /* configure operational mode */ |
| 117 | ath9k_hw_setopmode(ah); |
| 118 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 119 | /* calculate and install multicast filter */ |
| 120 | mfilt[0] = mfilt[1] = ~0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 121 | ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 124 | static bool ath_rx_edma_buf_link(struct ath_softc *sc, |
| 125 | enum ath9k_rx_qtype qtype) |
| 126 | { |
| 127 | struct ath_hw *ah = sc->sc_ah; |
| 128 | struct ath_rx_edma *rx_edma; |
| 129 | struct sk_buff *skb; |
| 130 | struct ath_buf *bf; |
| 131 | |
| 132 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 133 | if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize) |
| 134 | return false; |
| 135 | |
| 136 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
| 137 | list_del_init(&bf->list); |
| 138 | |
| 139 | skb = bf->bf_mpdu; |
| 140 | |
| 141 | ATH_RXBUF_RESET(bf); |
| 142 | memset(skb->data, 0, ah->caps.rx_status_len); |
| 143 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 144 | ah->caps.rx_status_len, DMA_TO_DEVICE); |
| 145 | |
| 146 | SKB_CB_ATHBUF(skb) = bf; |
| 147 | ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype); |
| 148 | skb_queue_tail(&rx_edma->rx_fifo, skb); |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | static void ath_rx_addbuffer_edma(struct ath_softc *sc, |
| 154 | enum ath9k_rx_qtype qtype, int size) |
| 155 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 156 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 157 | u32 nbuf = 0; |
| 158 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 159 | if (list_empty(&sc->rx.rxbuf)) { |
| 160 | ath_print(common, ATH_DBG_QUEUE, "No free rx buf available\n"); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | while (!list_empty(&sc->rx.rxbuf)) { |
| 165 | nbuf++; |
| 166 | |
| 167 | if (!ath_rx_edma_buf_link(sc, qtype)) |
| 168 | break; |
| 169 | |
| 170 | if (nbuf >= size) |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | static void ath_rx_remove_buffer(struct ath_softc *sc, |
| 176 | enum ath9k_rx_qtype qtype) |
| 177 | { |
| 178 | struct ath_buf *bf; |
| 179 | struct ath_rx_edma *rx_edma; |
| 180 | struct sk_buff *skb; |
| 181 | |
| 182 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 183 | |
| 184 | while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) { |
| 185 | bf = SKB_CB_ATHBUF(skb); |
| 186 | BUG_ON(!bf); |
| 187 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static void ath_rx_edma_cleanup(struct ath_softc *sc) |
| 192 | { |
| 193 | struct ath_buf *bf; |
| 194 | |
| 195 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
| 196 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 197 | |
| 198 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 199 | if (bf->bf_mpdu) |
| 200 | dev_kfree_skb_any(bf->bf_mpdu); |
| 201 | } |
| 202 | |
| 203 | INIT_LIST_HEAD(&sc->rx.rxbuf); |
| 204 | |
| 205 | kfree(sc->rx.rx_bufptr); |
| 206 | sc->rx.rx_bufptr = NULL; |
| 207 | } |
| 208 | |
| 209 | static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size) |
| 210 | { |
| 211 | skb_queue_head_init(&rx_edma->rx_fifo); |
| 212 | skb_queue_head_init(&rx_edma->rx_buffers); |
| 213 | rx_edma->rx_fifo_hwsize = size; |
| 214 | } |
| 215 | |
| 216 | static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) |
| 217 | { |
| 218 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 219 | struct ath_hw *ah = sc->sc_ah; |
| 220 | struct sk_buff *skb; |
| 221 | struct ath_buf *bf; |
| 222 | int error = 0, i; |
| 223 | u32 size; |
| 224 | |
| 225 | |
| 226 | common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN + |
| 227 | ah->caps.rx_status_len, |
| 228 | min(common->cachelsz, (u16)64)); |
| 229 | |
| 230 | ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize - |
| 231 | ah->caps.rx_status_len); |
| 232 | |
| 233 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP], |
| 234 | ah->caps.rx_lp_qdepth); |
| 235 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP], |
| 236 | ah->caps.rx_hp_qdepth); |
| 237 | |
| 238 | size = sizeof(struct ath_buf) * nbufs; |
| 239 | bf = kzalloc(size, GFP_KERNEL); |
| 240 | if (!bf) |
| 241 | return -ENOMEM; |
| 242 | |
| 243 | INIT_LIST_HEAD(&sc->rx.rxbuf); |
| 244 | sc->rx.rx_bufptr = bf; |
| 245 | |
| 246 | for (i = 0; i < nbufs; i++, bf++) { |
| 247 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL); |
| 248 | if (!skb) { |
| 249 | error = -ENOMEM; |
| 250 | goto rx_init_fail; |
| 251 | } |
| 252 | |
| 253 | memset(skb->data, 0, common->rx_bufsize); |
| 254 | bf->bf_mpdu = skb; |
| 255 | |
| 256 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 257 | common->rx_bufsize, |
| 258 | DMA_BIDIRECTIONAL); |
| 259 | if (unlikely(dma_mapping_error(sc->dev, |
| 260 | bf->bf_buf_addr))) { |
| 261 | dev_kfree_skb_any(skb); |
| 262 | bf->bf_mpdu = NULL; |
| 263 | ath_print(common, ATH_DBG_FATAL, |
| 264 | "dma_mapping_error() on RX init\n"); |
| 265 | error = -ENOMEM; |
| 266 | goto rx_init_fail; |
| 267 | } |
| 268 | |
| 269 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | |
| 274 | rx_init_fail: |
| 275 | ath_rx_edma_cleanup(sc); |
| 276 | return error; |
| 277 | } |
| 278 | |
| 279 | static void ath_edma_start_recv(struct ath_softc *sc) |
| 280 | { |
| 281 | spin_lock_bh(&sc->rx.rxbuflock); |
| 282 | |
| 283 | ath9k_hw_rxena(sc->sc_ah); |
| 284 | |
| 285 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP, |
| 286 | sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize); |
| 287 | |
| 288 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP, |
| 289 | sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize); |
| 290 | |
| 291 | spin_unlock_bh(&sc->rx.rxbuflock); |
| 292 | |
| 293 | ath_opmode_init(sc); |
| 294 | |
Luis R. Rodriguez | 40346b6 | 2010-06-12 00:33:44 -0400 | [diff] [blame] | 295 | ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_SCANNING)); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static void ath_edma_stop_recv(struct ath_softc *sc) |
| 299 | { |
| 300 | spin_lock_bh(&sc->rx.rxbuflock); |
| 301 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 302 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
| 303 | spin_unlock_bh(&sc->rx.rxbuflock); |
| 304 | } |
| 305 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 306 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
| 307 | { |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 308 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 309 | struct sk_buff *skb; |
| 310 | struct ath_buf *bf; |
| 311 | int error = 0; |
| 312 | |
Sujith | 797fe5c | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 313 | spin_lock_init(&sc->rx.rxflushlock); |
| 314 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
| 315 | spin_lock_init(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 316 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 317 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 318 | return ath_rx_edma_init(sc, nbufs); |
| 319 | } else { |
| 320 | common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN, |
| 321 | min(common->cachelsz, (u16)64)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 322 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 323 | ath_print(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", |
| 324 | common->cachelsz, common->rx_bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 325 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 326 | /* Initialize rx descriptors */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 327 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 328 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 329 | "rx", nbufs, 1, 0); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 330 | if (error != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 331 | ath_print(common, ATH_DBG_FATAL, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 332 | "failed to allocate rx descriptors: %d\n", |
| 333 | error); |
Sujith | 797fe5c | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 334 | goto err; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 335 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 336 | |
| 337 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 338 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, |
| 339 | GFP_KERNEL); |
| 340 | if (skb == NULL) { |
| 341 | error = -ENOMEM; |
| 342 | goto err; |
| 343 | } |
| 344 | |
| 345 | bf->bf_mpdu = skb; |
| 346 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 347 | common->rx_bufsize, |
| 348 | DMA_FROM_DEVICE); |
| 349 | if (unlikely(dma_mapping_error(sc->dev, |
| 350 | bf->bf_buf_addr))) { |
| 351 | dev_kfree_skb_any(skb); |
| 352 | bf->bf_mpdu = NULL; |
| 353 | ath_print(common, ATH_DBG_FATAL, |
| 354 | "dma_mapping_error() on RX init\n"); |
| 355 | error = -ENOMEM; |
| 356 | goto err; |
| 357 | } |
| 358 | bf->bf_dmacontext = bf->bf_buf_addr; |
| 359 | } |
| 360 | sc->rx.rxlink = NULL; |
Sujith | 797fe5c | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 361 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 362 | |
Sujith | 797fe5c | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 363 | err: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 364 | if (error) |
| 365 | ath_rx_cleanup(sc); |
| 366 | |
| 367 | return error; |
| 368 | } |
| 369 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 370 | void ath_rx_cleanup(struct ath_softc *sc) |
| 371 | { |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 372 | struct ath_hw *ah = sc->sc_ah; |
| 373 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 374 | struct sk_buff *skb; |
| 375 | struct ath_buf *bf; |
| 376 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 377 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 378 | ath_rx_edma_cleanup(sc); |
| 379 | return; |
| 380 | } else { |
| 381 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 382 | skb = bf->bf_mpdu; |
| 383 | if (skb) { |
| 384 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
| 385 | common->rx_bufsize, |
| 386 | DMA_FROM_DEVICE); |
| 387 | dev_kfree_skb(skb); |
| 388 | } |
Luis R. Rodriguez | 051b919 | 2009-03-23 18:25:01 -0400 | [diff] [blame] | 389 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 390 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 391 | if (sc->rx.rxdma.dd_desc_len != 0) |
| 392 | ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf); |
| 393 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Calculate the receive filter according to the |
| 398 | * operating mode and state: |
| 399 | * |
| 400 | * o always accept unicast, broadcast, and multicast traffic |
| 401 | * o maintain current state of phy error reception (the hal |
| 402 | * may enable phy error frames for noise immunity work) |
| 403 | * o probe request frames are accepted only when operating in |
| 404 | * hostap, adhoc, or monitor modes |
| 405 | * o enable promiscuous mode according to the interface state |
| 406 | * o accept beacons: |
| 407 | * - when operating in adhoc mode so the 802.11 layer creates |
| 408 | * node table entries for peers, |
| 409 | * - when operating in station mode for collecting rssi data when |
| 410 | * the station is otherwise quiet, or |
| 411 | * - when operating as a repeater so we see repeater-sta beacons |
| 412 | * - when scanning |
| 413 | */ |
| 414 | |
| 415 | u32 ath_calcrxfilter(struct ath_softc *sc) |
| 416 | { |
| 417 | #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR) |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 418 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 419 | u32 rfilt; |
| 420 | |
| 421 | rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE) |
| 422 | | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST |
| 423 | | ATH9K_RX_FILTER_MCAST; |
| 424 | |
| 425 | /* If not a STA, enable processing of Probe Requests */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 426 | if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 427 | rfilt |= ATH9K_RX_FILTER_PROBEREQ; |
| 428 | |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 429 | /* |
| 430 | * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station |
| 431 | * mode interface or when in monitor mode. AP mode does not need this |
| 432 | * since it receives all in-BSS frames anyway. |
| 433 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 434 | if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) && |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 435 | (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) || |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 436 | (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 437 | rfilt |= ATH9K_RX_FILTER_PROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 438 | |
Sujith | d42c6b7 | 2009-02-04 08:10:22 +0530 | [diff] [blame] | 439 | if (sc->rx.rxfilter & FIF_CONTROL) |
| 440 | rfilt |= ATH9K_RX_FILTER_CONTROL; |
| 441 | |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 442 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) && |
| 443 | !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC)) |
| 444 | rfilt |= ATH9K_RX_FILTER_MYBEACON; |
| 445 | else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 446 | rfilt |= ATH9K_RX_FILTER_BEACON; |
| 447 | |
Senthil Balasubramanian | 66afad0 | 2009-09-18 15:06:07 +0530 | [diff] [blame] | 448 | if ((AR_SREV_9280_10_OR_LATER(sc->sc_ah) || |
| 449 | AR_SREV_9285_10_OR_LATER(sc->sc_ah)) && |
| 450 | (sc->sc_ah->opmode == NL80211_IFTYPE_AP) && |
| 451 | (sc->rx.rxfilter & FIF_PSPOLL)) |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 452 | rfilt |= ATH9K_RX_FILTER_PSPOLL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 453 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 454 | if (conf_is_ht(&sc->hw->conf)) |
| 455 | rfilt |= ATH9K_RX_FILTER_COMP_BAR; |
| 456 | |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 457 | if (sc->sec_wiphy || (sc->rx.rxfilter & FIF_OTHER_BSS)) { |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 458 | /* TODO: only needed if more than one BSSID is in use in |
| 459 | * station/adhoc mode */ |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 460 | /* The following may also be needed for other older chips */ |
| 461 | if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160) |
| 462 | rfilt |= ATH9K_RX_FILTER_PROM; |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 463 | rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL; |
| 464 | } |
| 465 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 466 | return rfilt; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 467 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 468 | #undef RX_FILTER_PRESERVE |
| 469 | } |
| 470 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 471 | int ath_startrecv(struct ath_softc *sc) |
| 472 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 473 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 474 | struct ath_buf *bf, *tbf; |
| 475 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 476 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 477 | ath_edma_start_recv(sc); |
| 478 | return 0; |
| 479 | } |
| 480 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 481 | spin_lock_bh(&sc->rx.rxbuflock); |
| 482 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 483 | goto start_recv; |
| 484 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 485 | sc->rx.rxlink = NULL; |
| 486 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 487 | ath_rx_buf_link(sc, bf); |
| 488 | } |
| 489 | |
| 490 | /* We could have deleted elements so the list may be empty now */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 491 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 492 | goto start_recv; |
| 493 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 494 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 495 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 496 | ath9k_hw_rxena(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 497 | |
| 498 | start_recv: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 499 | spin_unlock_bh(&sc->rx.rxbuflock); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 500 | ath_opmode_init(sc); |
Luis R. Rodriguez | 40346b6 | 2010-06-12 00:33:44 -0400 | [diff] [blame] | 501 | ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_SCANNING)); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 502 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 503 | return 0; |
| 504 | } |
| 505 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 506 | bool ath_stoprecv(struct ath_softc *sc) |
| 507 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 508 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 509 | bool stopped; |
| 510 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 511 | ath9k_hw_stoppcurecv(ah); |
| 512 | ath9k_hw_setrxfilter(ah, 0); |
| 513 | stopped = ath9k_hw_stopdmarecv(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 514 | |
| 515 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 516 | ath_edma_stop_recv(sc); |
| 517 | else |
| 518 | sc->rx.rxlink = NULL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 519 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 520 | return stopped; |
| 521 | } |
| 522 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 523 | void ath_flushrecv(struct ath_softc *sc) |
| 524 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 525 | spin_lock_bh(&sc->rx.rxflushlock); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 526 | sc->sc_flags |= SC_OP_RXFLUSH; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 527 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 528 | ath_rx_tasklet(sc, 1, true); |
| 529 | ath_rx_tasklet(sc, 1, false); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 530 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 531 | spin_unlock_bh(&sc->rx.rxflushlock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 534 | static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) |
| 535 | { |
| 536 | /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */ |
| 537 | struct ieee80211_mgmt *mgmt; |
| 538 | u8 *pos, *end, id, elen; |
| 539 | struct ieee80211_tim_ie *tim; |
| 540 | |
| 541 | mgmt = (struct ieee80211_mgmt *)skb->data; |
| 542 | pos = mgmt->u.beacon.variable; |
| 543 | end = skb->data + skb->len; |
| 544 | |
| 545 | while (pos + 2 < end) { |
| 546 | id = *pos++; |
| 547 | elen = *pos++; |
| 548 | if (pos + elen > end) |
| 549 | break; |
| 550 | |
| 551 | if (id == WLAN_EID_TIM) { |
| 552 | if (elen < sizeof(*tim)) |
| 553 | break; |
| 554 | tim = (struct ieee80211_tim_ie *) pos; |
| 555 | if (tim->dtim_count != 0) |
| 556 | break; |
| 557 | return tim->bitmap_ctrl & 0x01; |
| 558 | } |
| 559 | |
| 560 | pos += elen; |
| 561 | } |
| 562 | |
| 563 | return false; |
| 564 | } |
| 565 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 566 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) |
| 567 | { |
| 568 | struct ieee80211_mgmt *mgmt; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 569 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 570 | |
| 571 | if (skb->len < 24 + 8 + 2 + 2) |
| 572 | return; |
| 573 | |
| 574 | mgmt = (struct ieee80211_mgmt *)skb->data; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 575 | if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 576 | return; /* not from our current AP */ |
| 577 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 578 | sc->ps_flags &= ~PS_WAIT_FOR_BEACON; |
Gabor Juhos | 293dc5d | 2009-06-19 12:17:48 +0200 | [diff] [blame] | 579 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 580 | if (sc->ps_flags & PS_BEACON_SYNC) { |
| 581 | sc->ps_flags &= ~PS_BEACON_SYNC; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 582 | ath_print(common, ATH_DBG_PS, |
| 583 | "Reconfigure Beacon timers based on " |
| 584 | "timestamp from the AP\n"); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 585 | ath_beacon_config(sc, NULL); |
| 586 | } |
| 587 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 588 | if (ath_beacon_dtim_pending_cab(skb)) { |
| 589 | /* |
| 590 | * Remain awake waiting for buffered broadcast/multicast |
Gabor Juhos | 58f5fff | 2009-06-17 20:53:20 +0200 | [diff] [blame] | 591 | * frames. If the last broadcast/multicast frame is not |
| 592 | * received properly, the next beacon frame will work as |
| 593 | * a backup trigger for returning into NETWORK SLEEP state, |
| 594 | * so we are waiting for it as well. |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 595 | */ |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 596 | ath_print(common, ATH_DBG_PS, "Received DTIM beacon indicating " |
| 597 | "buffered broadcast/multicast frame(s)\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 598 | sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON; |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 599 | return; |
| 600 | } |
| 601 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 602 | if (sc->ps_flags & PS_WAIT_FOR_CAB) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 603 | /* |
| 604 | * This can happen if a broadcast frame is dropped or the AP |
| 605 | * fails to send a frame indicating that all CAB frames have |
| 606 | * been delivered. |
| 607 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 608 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 609 | ath_print(common, ATH_DBG_PS, |
| 610 | "PS wait for CAB frames timed out\n"); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 611 | } |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) |
| 615 | { |
| 616 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 617 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 618 | |
| 619 | hdr = (struct ieee80211_hdr *)skb->data; |
| 620 | |
| 621 | /* Process Beacon and CAB receive in PS state */ |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 622 | if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc)) |
| 623 | && ieee80211_is_beacon(hdr->frame_control)) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 624 | ath_rx_ps_beacon(sc, skb); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 625 | else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 626 | (ieee80211_is_data(hdr->frame_control) || |
| 627 | ieee80211_is_action(hdr->frame_control)) && |
| 628 | is_multicast_ether_addr(hdr->addr1) && |
| 629 | !ieee80211_has_moredata(hdr->frame_control)) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 630 | /* |
| 631 | * No more broadcast/multicast frames to be received at this |
| 632 | * point. |
| 633 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 634 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 635 | ath_print(common, ATH_DBG_PS, |
| 636 | "All PS CAB frames received, back to sleep\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 637 | } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) && |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 638 | !is_multicast_ether_addr(hdr->addr1) && |
| 639 | !ieee80211_has_morefrags(hdr->frame_control)) { |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 640 | sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 641 | ath_print(common, ATH_DBG_PS, |
| 642 | "Going back to sleep after having received " |
Pavel Roskin | f643e51 | 2010-01-29 17:22:12 -0500 | [diff] [blame] | 643 | "PS-Poll data (0x%lx)\n", |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 644 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 645 | PS_WAIT_FOR_CAB | |
| 646 | PS_WAIT_FOR_PSPOLL_DATA | |
| 647 | PS_WAIT_FOR_TX_ACK)); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 651 | static void ath_rx_send_to_mac80211(struct ieee80211_hw *hw, |
| 652 | struct ath_softc *sc, struct sk_buff *skb, |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 653 | struct ieee80211_rx_status *rxs) |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 654 | { |
| 655 | struct ieee80211_hdr *hdr; |
| 656 | |
| 657 | hdr = (struct ieee80211_hdr *)skb->data; |
| 658 | |
| 659 | /* Send the frame to mac80211 */ |
| 660 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 661 | int i; |
| 662 | /* |
| 663 | * Deliver broadcast/multicast frames to all suitable |
| 664 | * virtual wiphys. |
| 665 | */ |
| 666 | /* TODO: filter based on channel configuration */ |
| 667 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 668 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 669 | struct sk_buff *nskb; |
| 670 | if (aphy == NULL) |
| 671 | continue; |
| 672 | nskb = skb_copy(skb, GFP_ATOMIC); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 673 | if (!nskb) |
| 674 | continue; |
| 675 | ieee80211_rx(aphy->hw, nskb); |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 676 | } |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 677 | ieee80211_rx(sc->hw, skb); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 678 | } else |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 679 | /* Deliver unicast frames based on receiver address */ |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 680 | ieee80211_rx(hw, skb); |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 681 | } |
| 682 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 683 | static bool ath_edma_get_buffers(struct ath_softc *sc, |
| 684 | enum ath9k_rx_qtype qtype) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 685 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 686 | struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype]; |
| 687 | struct ath_hw *ah = sc->sc_ah; |
| 688 | struct ath_common *common = ath9k_hw_common(ah); |
| 689 | struct sk_buff *skb; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 690 | struct ath_buf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 691 | int ret; |
| 692 | |
| 693 | skb = skb_peek(&rx_edma->rx_fifo); |
| 694 | if (!skb) |
| 695 | return false; |
| 696 | |
| 697 | bf = SKB_CB_ATHBUF(skb); |
| 698 | BUG_ON(!bf); |
| 699 | |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 700 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 701 | common->rx_bufsize, DMA_FROM_DEVICE); |
| 702 | |
| 703 | ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data); |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 704 | if (ret == -EINPROGRESS) { |
| 705 | /*let device gain the buffer again*/ |
| 706 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 707 | common->rx_bufsize, DMA_FROM_DEVICE); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 708 | return false; |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 709 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 710 | |
| 711 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 712 | if (ret == -EINVAL) { |
| 713 | /* corrupt descriptor, skip this one and the following one */ |
| 714 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 715 | ath_rx_edma_buf_link(sc, qtype); |
| 716 | skb = skb_peek(&rx_edma->rx_fifo); |
| 717 | if (!skb) |
| 718 | return true; |
| 719 | |
| 720 | bf = SKB_CB_ATHBUF(skb); |
| 721 | BUG_ON(!bf); |
| 722 | |
| 723 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 724 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 725 | ath_rx_edma_buf_link(sc, qtype); |
Vasanthakumar Thiagarajan | 083e3e8 | 2010-05-10 19:41:34 -0700 | [diff] [blame] | 726 | return true; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 727 | } |
| 728 | skb_queue_tail(&rx_edma->rx_buffers, skb); |
| 729 | |
| 730 | return true; |
| 731 | } |
| 732 | |
| 733 | static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc, |
| 734 | struct ath_rx_status *rs, |
| 735 | enum ath9k_rx_qtype qtype) |
| 736 | { |
| 737 | struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype]; |
| 738 | struct sk_buff *skb; |
| 739 | struct ath_buf *bf; |
| 740 | |
| 741 | while (ath_edma_get_buffers(sc, qtype)); |
| 742 | skb = __skb_dequeue(&rx_edma->rx_buffers); |
| 743 | if (!skb) |
| 744 | return NULL; |
| 745 | |
| 746 | bf = SKB_CB_ATHBUF(skb); |
| 747 | ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data); |
| 748 | return bf; |
| 749 | } |
| 750 | |
| 751 | static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc, |
| 752 | struct ath_rx_status *rs) |
| 753 | { |
| 754 | struct ath_hw *ah = sc->sc_ah; |
| 755 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 756 | struct ath_desc *ds; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 757 | struct ath_buf *bf; |
| 758 | int ret; |
| 759 | |
| 760 | if (list_empty(&sc->rx.rxbuf)) { |
| 761 | sc->rx.rxlink = NULL; |
| 762 | return NULL; |
| 763 | } |
| 764 | |
| 765 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
| 766 | ds = bf->bf_desc; |
| 767 | |
| 768 | /* |
| 769 | * Must provide the virtual address of the current |
| 770 | * descriptor, the physical address, and the virtual |
| 771 | * address of the next descriptor in the h/w chain. |
| 772 | * This allows the HAL to look ahead to see if the |
| 773 | * hardware is done with a descriptor by checking the |
| 774 | * done bit in the following descriptor and the address |
| 775 | * of the current descriptor the DMA engine is working |
| 776 | * on. All this is necessary because of our use of |
| 777 | * a self-linked list to avoid rx overruns. |
| 778 | */ |
| 779 | ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0); |
| 780 | if (ret == -EINPROGRESS) { |
| 781 | struct ath_rx_status trs; |
| 782 | struct ath_buf *tbf; |
| 783 | struct ath_desc *tds; |
| 784 | |
| 785 | memset(&trs, 0, sizeof(trs)); |
| 786 | if (list_is_last(&bf->list, &sc->rx.rxbuf)) { |
| 787 | sc->rx.rxlink = NULL; |
| 788 | return NULL; |
| 789 | } |
| 790 | |
| 791 | tbf = list_entry(bf->list.next, struct ath_buf, list); |
| 792 | |
| 793 | /* |
| 794 | * On some hardware the descriptor status words could |
| 795 | * get corrupted, including the done bit. Because of |
| 796 | * this, check if the next descriptor's done bit is |
| 797 | * set or not. |
| 798 | * |
| 799 | * If the next descriptor's done bit is set, the current |
| 800 | * descriptor has been corrupted. Force s/w to discard |
| 801 | * this descriptor and continue... |
| 802 | */ |
| 803 | |
| 804 | tds = tbf->bf_desc; |
| 805 | ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0); |
| 806 | if (ret == -EINPROGRESS) |
| 807 | return NULL; |
| 808 | } |
| 809 | |
| 810 | if (!bf->bf_mpdu) |
| 811 | return bf; |
| 812 | |
| 813 | /* |
| 814 | * Synchronize the DMA transfer with CPU before |
| 815 | * 1. accessing the frame |
| 816 | * 2. requeueing the same buffer to h/w |
| 817 | */ |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 818 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 819 | common->rx_bufsize, |
| 820 | DMA_FROM_DEVICE); |
| 821 | |
| 822 | return bf; |
| 823 | } |
| 824 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 825 | /* Assumes you've already done the endian to CPU conversion */ |
| 826 | static bool ath9k_rx_accept(struct ath_common *common, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 827 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 828 | struct ieee80211_rx_status *rxs, |
| 829 | struct ath_rx_status *rx_stats, |
| 830 | bool *decrypt_error) |
| 831 | { |
| 832 | struct ath_hw *ah = common->ah; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 833 | __le16 fc; |
Vasanthakumar Thiagarajan | b7b1b51 | 2010-05-20 14:34:48 -0700 | [diff] [blame] | 834 | u8 rx_status_len = ah->caps.rx_status_len; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 835 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 836 | fc = hdr->frame_control; |
| 837 | |
| 838 | if (!rx_stats->rs_datalen) |
| 839 | return false; |
| 840 | /* |
| 841 | * rs_status follows rs_datalen so if rs_datalen is too large |
| 842 | * we can take a hint that hardware corrupted it, so ignore |
| 843 | * those frames. |
| 844 | */ |
Vasanthakumar Thiagarajan | b7b1b51 | 2010-05-20 14:34:48 -0700 | [diff] [blame] | 845 | if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 846 | return false; |
| 847 | |
| 848 | /* |
| 849 | * rs_more indicates chained descriptors which can be used |
| 850 | * to link buffers together for a sort of scatter-gather |
| 851 | * operation. |
| 852 | * reject the frame, we don't support scatter-gather yet and |
| 853 | * the frame is probably corrupt anyway |
| 854 | */ |
| 855 | if (rx_stats->rs_more) |
| 856 | return false; |
| 857 | |
| 858 | /* |
| 859 | * The rx_stats->rs_status will not be set until the end of the |
| 860 | * chained descriptors so it can be ignored if rs_more is set. The |
| 861 | * rs_more will be false at the last element of the chained |
| 862 | * descriptors. |
| 863 | */ |
| 864 | if (rx_stats->rs_status != 0) { |
| 865 | if (rx_stats->rs_status & ATH9K_RXERR_CRC) |
| 866 | rxs->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 867 | if (rx_stats->rs_status & ATH9K_RXERR_PHY) |
| 868 | return false; |
| 869 | |
| 870 | if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) { |
| 871 | *decrypt_error = true; |
| 872 | } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) { |
| 873 | if (ieee80211_is_ctl(fc)) |
| 874 | /* |
| 875 | * Sometimes, we get invalid |
| 876 | * MIC failures on valid control frames. |
| 877 | * Remove these mic errors. |
| 878 | */ |
| 879 | rx_stats->rs_status &= ~ATH9K_RXERR_MIC; |
| 880 | else |
| 881 | rxs->flag |= RX_FLAG_MMIC_ERROR; |
| 882 | } |
| 883 | /* |
| 884 | * Reject error frames with the exception of |
| 885 | * decryption and MIC failures. For monitor mode, |
| 886 | * we also ignore the CRC error. |
| 887 | */ |
| 888 | if (ah->opmode == NL80211_IFTYPE_MONITOR) { |
| 889 | if (rx_stats->rs_status & |
| 890 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | |
| 891 | ATH9K_RXERR_CRC)) |
| 892 | return false; |
| 893 | } else { |
| 894 | if (rx_stats->rs_status & |
| 895 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) { |
| 896 | return false; |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | return true; |
| 901 | } |
| 902 | |
| 903 | static int ath9k_process_rate(struct ath_common *common, |
| 904 | struct ieee80211_hw *hw, |
| 905 | struct ath_rx_status *rx_stats, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 906 | struct ieee80211_rx_status *rxs) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 907 | { |
| 908 | struct ieee80211_supported_band *sband; |
| 909 | enum ieee80211_band band; |
| 910 | unsigned int i = 0; |
| 911 | |
| 912 | band = hw->conf.channel->band; |
| 913 | sband = hw->wiphy->bands[band]; |
| 914 | |
| 915 | if (rx_stats->rs_rate & 0x80) { |
| 916 | /* HT rate */ |
| 917 | rxs->flag |= RX_FLAG_HT; |
| 918 | if (rx_stats->rs_flags & ATH9K_RX_2040) |
| 919 | rxs->flag |= RX_FLAG_40MHZ; |
| 920 | if (rx_stats->rs_flags & ATH9K_RX_GI) |
| 921 | rxs->flag |= RX_FLAG_SHORT_GI; |
| 922 | rxs->rate_idx = rx_stats->rs_rate & 0x7f; |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | for (i = 0; i < sband->n_bitrates; i++) { |
| 927 | if (sband->bitrates[i].hw_value == rx_stats->rs_rate) { |
| 928 | rxs->rate_idx = i; |
| 929 | return 0; |
| 930 | } |
| 931 | if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) { |
| 932 | rxs->flag |= RX_FLAG_SHORTPRE; |
| 933 | rxs->rate_idx = i; |
| 934 | return 0; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * No valid hardware bitrate found -- we should not get here |
| 940 | * because hardware has already validated this frame as OK. |
| 941 | */ |
| 942 | ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected " |
| 943 | "0x%02x using 1 Mbit\n", rx_stats->rs_rate); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 944 | |
| 945 | return -EINVAL; |
| 946 | } |
| 947 | |
| 948 | static void ath9k_process_rssi(struct ath_common *common, |
| 949 | struct ieee80211_hw *hw, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 950 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 951 | struct ath_rx_status *rx_stats) |
| 952 | { |
| 953 | struct ath_hw *ah = common->ah; |
| 954 | struct ieee80211_sta *sta; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 955 | struct ath_node *an; |
| 956 | int last_rssi = ATH_RSSI_DUMMY_MARKER; |
| 957 | __le16 fc; |
| 958 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 959 | fc = hdr->frame_control; |
| 960 | |
| 961 | rcu_read_lock(); |
| 962 | /* |
| 963 | * XXX: use ieee80211_find_sta! This requires quite a bit of work |
| 964 | * under the current ath9k virtual wiphy implementation as we have |
| 965 | * no way of tying a vif to wiphy. Typically vifs are attached to |
| 966 | * at least one sdata of a wiphy on mac80211 but with ath9k virtual |
| 967 | * wiphy you'd have to iterate over every wiphy and each sdata. |
| 968 | */ |
| 969 | sta = ieee80211_find_sta_by_hw(hw, hdr->addr2); |
| 970 | if (sta) { |
| 971 | an = (struct ath_node *) sta->drv_priv; |
| 972 | if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && |
| 973 | !rx_stats->rs_moreaggr) |
| 974 | ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi); |
| 975 | last_rssi = an->last_rssi; |
| 976 | } |
| 977 | rcu_read_unlock(); |
| 978 | |
| 979 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) |
| 980 | rx_stats->rs_rssi = ATH_EP_RND(last_rssi, |
| 981 | ATH_RSSI_EP_MULTIPLIER); |
| 982 | if (rx_stats->rs_rssi < 0) |
| 983 | rx_stats->rs_rssi = 0; |
| 984 | |
| 985 | /* Update Beacon RSSI, this is used by ANI. */ |
| 986 | if (ieee80211_is_beacon(fc)) |
| 987 | ah->stats.avgbrssi = rx_stats->rs_rssi; |
| 988 | } |
| 989 | |
| 990 | /* |
| 991 | * For Decrypt or Demic errors, we only mark packet status here and always push |
| 992 | * up the frame up to let mac80211 handle the actual error case, be it no |
| 993 | * decryption key or real decryption error. This let us keep statistics there. |
| 994 | */ |
| 995 | static int ath9k_rx_skb_preprocess(struct ath_common *common, |
| 996 | struct ieee80211_hw *hw, |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 997 | struct ieee80211_hdr *hdr, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 998 | struct ath_rx_status *rx_stats, |
| 999 | struct ieee80211_rx_status *rx_status, |
| 1000 | bool *decrypt_error) |
| 1001 | { |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 1002 | memset(rx_status, 0, sizeof(struct ieee80211_rx_status)); |
| 1003 | |
| 1004 | /* |
| 1005 | * everything but the rate is checked here, the rate check is done |
| 1006 | * separately to avoid doing two lookups for a rate for each frame. |
| 1007 | */ |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 1008 | if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 1009 | return -EINVAL; |
| 1010 | |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 1011 | ath9k_process_rssi(common, hw, hdr, rx_stats); |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 1012 | |
Vasanthakumar Thiagarajan | 9f167f6 | 2010-05-20 14:34:46 -0700 | [diff] [blame] | 1013 | if (ath9k_process_rate(common, hw, rx_stats, rx_status)) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 1014 | return -EINVAL; |
| 1015 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 1016 | rx_status->band = hw->conf.channel->band; |
| 1017 | rx_status->freq = hw->conf.channel->center_freq; |
| 1018 | rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi; |
| 1019 | rx_status->antenna = rx_stats->rs_antenna; |
| 1020 | rx_status->flag |= RX_FLAG_TSFT; |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | static void ath9k_rx_skb_postprocess(struct ath_common *common, |
| 1026 | struct sk_buff *skb, |
| 1027 | struct ath_rx_status *rx_stats, |
| 1028 | struct ieee80211_rx_status *rxs, |
| 1029 | bool decrypt_error) |
| 1030 | { |
| 1031 | struct ath_hw *ah = common->ah; |
| 1032 | struct ieee80211_hdr *hdr; |
| 1033 | int hdrlen, padpos, padsize; |
| 1034 | u8 keyix; |
| 1035 | __le16 fc; |
| 1036 | |
| 1037 | /* see if any padding is done by the hw and remove it */ |
| 1038 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1039 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 1040 | fc = hdr->frame_control; |
| 1041 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 1042 | |
| 1043 | /* The MAC header is padded to have 32-bit boundary if the |
| 1044 | * packet payload is non-zero. The general calculation for |
| 1045 | * padsize would take into account odd header lengths: |
| 1046 | * padsize = (4 - padpos % 4) % 4; However, since only |
| 1047 | * even-length headers are used, padding can only be 0 or 2 |
| 1048 | * bytes and we can optimize this a bit. In addition, we must |
| 1049 | * not try to remove padding from short control frames that do |
| 1050 | * not have payload. */ |
| 1051 | padsize = padpos & 3; |
| 1052 | if (padsize && skb->len>=padpos+padsize+FCS_LEN) { |
| 1053 | memmove(skb->data + padsize, skb->data, padpos); |
| 1054 | skb_pull(skb, padsize); |
| 1055 | } |
| 1056 | |
| 1057 | keyix = rx_stats->rs_keyix; |
| 1058 | |
| 1059 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error && |
| 1060 | ieee80211_has_protected(fc)) { |
| 1061 | rxs->flag |= RX_FLAG_DECRYPTED; |
| 1062 | } else if (ieee80211_has_protected(fc) |
| 1063 | && !decrypt_error && skb->len >= hdrlen + 4) { |
| 1064 | keyix = skb->data[hdrlen + 3] >> 6; |
| 1065 | |
| 1066 | if (test_bit(keyix, common->keymap)) |
| 1067 | rxs->flag |= RX_FLAG_DECRYPTED; |
| 1068 | } |
| 1069 | if (ah->sw_mgmt_crypto && |
| 1070 | (rxs->flag & RX_FLAG_DECRYPTED) && |
| 1071 | ieee80211_is_mgmt(fc)) |
| 1072 | /* Use software decrypt for management frames. */ |
| 1073 | rxs->flag &= ~RX_FLAG_DECRYPTED; |
| 1074 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1075 | |
| 1076 | int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) |
| 1077 | { |
| 1078 | struct ath_buf *bf; |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1079 | struct sk_buff *skb = NULL, *requeue_skb; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1080 | struct ieee80211_rx_status *rxs; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1081 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 1082 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 1083 | /* |
| 1084 | * The hw can techncically differ from common->hw when using ath9k |
| 1085 | * virtual wiphy so to account for that we iterate over the active |
| 1086 | * wiphys and find the appropriate wiphy and therefore hw. |
| 1087 | */ |
| 1088 | struct ieee80211_hw *hw = NULL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1089 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c9b1417 | 2009-11-04 16:47:22 -0800 | [diff] [blame] | 1090 | int retval; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1091 | bool decrypt_error = false; |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1092 | struct ath_rx_status rs; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1093 | enum ath9k_rx_qtype qtype; |
| 1094 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
| 1095 | int dma_type; |
Vasanthakumar Thiagarajan | 5c6dd92 | 2010-05-20 14:34:47 -0700 | [diff] [blame] | 1096 | u8 rx_status_len = ah->caps.rx_status_len; |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1097 | u64 tsf = 0; |
| 1098 | u32 tsf_lower = 0; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1099 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1100 | if (edma) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1101 | dma_type = DMA_BIDIRECTIONAL; |
Ming Lei | 5682422 | 2010-05-14 21:15:38 +0800 | [diff] [blame] | 1102 | else |
| 1103 | dma_type = DMA_FROM_DEVICE; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1104 | |
| 1105 | qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1106 | spin_lock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1107 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1108 | tsf = ath9k_hw_gettsf64(ah); |
| 1109 | tsf_lower = tsf & 0xffffffff; |
| 1110 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1111 | do { |
| 1112 | /* If handling rx interrupt and flush is in progress => exit */ |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 1113 | if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1116 | memset(&rs, 0, sizeof(rs)); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1117 | if (edma) |
| 1118 | bf = ath_edma_get_next_rx_buf(sc, &rs, qtype); |
| 1119 | else |
| 1120 | bf = ath_get_next_rx_buf(sc, &rs); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1121 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1122 | if (!bf) |
| 1123 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1124 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1125 | skb = bf->bf_mpdu; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1126 | if (!skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1127 | continue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1128 | |
Vasanthakumar Thiagarajan | 5c6dd92 | 2010-05-20 14:34:47 -0700 | [diff] [blame] | 1129 | hdr = (struct ieee80211_hdr *) (skb->data + rx_status_len); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1130 | rxs = IEEE80211_SKB_RXCB(skb); |
| 1131 | |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 1132 | hw = ath_get_virt_hw(sc, hdr); |
| 1133 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1134 | ath_debug_stat_rx(sc, &rs); |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 1135 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1136 | /* |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1137 | * If we're asked to flush receive queue, directly |
| 1138 | * chain it back at the queue without processing it. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1139 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1140 | if (flush) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1141 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1142 | |
Jan Friedrich | c8f3b72 | 2010-08-02 23:55:50 +0200 | [diff] [blame] | 1143 | retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs, |
| 1144 | rxs, &decrypt_error); |
| 1145 | if (retval) |
| 1146 | goto requeue; |
| 1147 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 1148 | rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp; |
| 1149 | if (rs.rs_tstamp > tsf_lower && |
| 1150 | unlikely(rs.rs_tstamp - tsf_lower > 0x10000000)) |
| 1151 | rxs->mactime -= 0x100000000ULL; |
| 1152 | |
| 1153 | if (rs.rs_tstamp < tsf_lower && |
| 1154 | unlikely(tsf_lower - rs.rs_tstamp > 0x10000000)) |
| 1155 | rxs->mactime += 0x100000000ULL; |
| 1156 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1157 | /* Ensure we always have an skb to requeue once we are done |
| 1158 | * processing the current buffer's skb */ |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1159 | requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1160 | |
| 1161 | /* If there is no memory we ignore the current RX'd frame, |
| 1162 | * tell hardware it can give us a new frame using the old |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1163 | * 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] | 1164 | * processing. */ |
| 1165 | if (!requeue_skb) |
| 1166 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1167 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1168 | /* Unmap the frame */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1169 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1170 | common->rx_bufsize, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1171 | dma_type); |
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 | skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len); |
| 1174 | if (ah->caps.rx_status_len) |
| 1175 | skb_pull(skb, ah->caps.rx_status_len); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1176 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 1177 | ath9k_rx_skb_postprocess(common, skb, &rs, |
| 1178 | rxs, decrypt_error); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1179 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1180 | /* We will now give hardware our shiny new allocated skb */ |
| 1181 | bf->bf_mpdu = requeue_skb; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1182 | 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] | 1183 | common->rx_bufsize, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1184 | dma_type); |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1185 | if (unlikely(dma_mapping_error(sc->dev, |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1186 | bf->bf_buf_addr))) { |
| 1187 | dev_kfree_skb_any(requeue_skb); |
| 1188 | bf->bf_mpdu = NULL; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1189 | ath_print(common, ATH_DBG_FATAL, |
| 1190 | "dma_mapping_error() on RX\n"); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1191 | ath_rx_send_to_mac80211(hw, sc, skb, rxs); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1192 | break; |
| 1193 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1194 | bf->bf_dmacontext = bf->bf_buf_addr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1195 | |
| 1196 | /* |
| 1197 | * change the default rx antenna if rx diversity chooses the |
| 1198 | * other antenna 3 times in a row. |
| 1199 | */ |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1200 | if (sc->rx.defant != rs.rs_antenna) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1201 | if (++sc->rx.rxotherant >= 3) |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 1202 | ath_setdefantenna(sc, rs.rs_antenna); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1203 | } else { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1204 | sc->rx.rxotherant = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1205 | } |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1206 | |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 1207 | if (unlikely(ath9k_check_auto_sleep(sc) || |
| 1208 | (sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 1209 | PS_WAIT_FOR_CAB | |
| 1210 | PS_WAIT_FOR_PSPOLL_DATA)))) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1211 | ath_rx_ps(sc, skb); |
| 1212 | |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 1213 | ath_rx_send_to_mac80211(hw, sc, skb, rxs); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1214 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1215 | requeue: |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1216 | if (edma) { |
| 1217 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 1218 | ath_rx_edma_buf_link(sc, qtype); |
| 1219 | } else { |
| 1220 | list_move_tail(&bf->list, &sc->rx.rxbuf); |
| 1221 | ath_rx_buf_link(sc, bf); |
| 1222 | } |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1223 | } while (1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1224 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1225 | spin_unlock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1226 | |
| 1227 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1228 | } |