Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 17 | #include <linux/dma-mapping.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 18 | #include "ath9k.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 19 | #include "ar9003_mac.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 21 | #define SKB_CB_ATHBUF(__skb) (*((struct ath_rxbuf **)__skb->cb)) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 22 | |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 23 | static inline bool ath9k_check_auto_sleep(struct ath_softc *sc) |
| 24 | { |
| 25 | return sc->ps_enabled && |
| 26 | (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP); |
| 27 | } |
| 28 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 29 | /* |
| 30 | * Setup and link descriptors. |
| 31 | * |
| 32 | * 11N: we can no longer afford to self link the last descriptor. |
| 33 | * MAC acknowledges BA status as long as it copies frames to host |
| 34 | * buffer (or rx fifo). This can incorrectly acknowledge packets |
| 35 | * to a sender if last desc is self-linked. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 36 | */ |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 37 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 38 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 39 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 40 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 41 | struct ath_desc *ds; |
| 42 | struct sk_buff *skb; |
| 43 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 44 | ds = bf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 45 | ds->ds_link = 0; /* link to null */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 46 | ds->ds_data = bf->bf_buf_addr; |
| 47 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 48 | /* virtual addr of the beginning of the buffer. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 49 | skb = bf->bf_mpdu; |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 50 | BUG_ON(skb == NULL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 51 | ds->ds_vdata = skb->data; |
| 52 | |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 53 | /* |
| 54 | * setup rx descriptors. The rx_bufsize here tells the hardware |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 55 | * 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] | 56 | * to process |
| 57 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 58 | ath9k_hw_setuprxdesc(ah, ds, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 59 | common->rx_bufsize, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 60 | 0); |
| 61 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 62 | if (sc->rx.rxlink == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 63 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
| 64 | else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 65 | *sc->rx.rxlink = bf->bf_daddr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 66 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 67 | sc->rx.rxlink = &ds->ds_link; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 70 | static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf) |
Felix Fietkau | e96542e | 2013-08-10 15:59:15 +0200 | [diff] [blame] | 71 | { |
| 72 | if (sc->rx.buf_hold) |
| 73 | ath_rx_buf_link(sc, sc->rx.buf_hold); |
| 74 | |
| 75 | sc->rx.buf_hold = bf; |
| 76 | } |
| 77 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 78 | static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) |
| 79 | { |
| 80 | /* XXX block beacon interrupts */ |
| 81 | ath9k_hw_setantenna(sc->sc_ah, antenna); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 82 | sc->rx.defant = antenna; |
| 83 | sc->rx.rxotherant = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 86 | static void ath_opmode_init(struct ath_softc *sc) |
| 87 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 88 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 89 | struct ath_common *common = ath9k_hw_common(ah); |
| 90 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 91 | u32 rfilt, mfilt[2]; |
| 92 | |
| 93 | /* configure rx filter */ |
| 94 | rfilt = ath_calcrxfilter(sc); |
| 95 | ath9k_hw_setrxfilter(ah, rfilt); |
| 96 | |
| 97 | /* configure bssid mask */ |
Felix Fietkau | 364734f | 2010-09-14 20:22:44 +0200 | [diff] [blame] | 98 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 99 | |
| 100 | /* configure operational mode */ |
| 101 | ath9k_hw_setopmode(ah); |
| 102 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 103 | /* calculate and install multicast filter */ |
| 104 | mfilt[0] = mfilt[1] = ~0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 105 | ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 108 | static bool ath_rx_edma_buf_link(struct ath_softc *sc, |
| 109 | enum ath9k_rx_qtype qtype) |
| 110 | { |
| 111 | struct ath_hw *ah = sc->sc_ah; |
| 112 | struct ath_rx_edma *rx_edma; |
| 113 | struct sk_buff *skb; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 114 | struct ath_rxbuf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 115 | |
| 116 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 117 | if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize) |
| 118 | return false; |
| 119 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 120 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 121 | list_del_init(&bf->list); |
| 122 | |
| 123 | skb = bf->bf_mpdu; |
| 124 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 125 | memset(skb->data, 0, ah->caps.rx_status_len); |
| 126 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 127 | ah->caps.rx_status_len, DMA_TO_DEVICE); |
| 128 | |
| 129 | SKB_CB_ATHBUF(skb) = bf; |
| 130 | ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype); |
Sujith Manoharan | 07236bf | 2013-04-23 12:22:18 +0530 | [diff] [blame] | 131 | __skb_queue_tail(&rx_edma->rx_fifo, skb); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 132 | |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | static void ath_rx_addbuffer_edma(struct ath_softc *sc, |
Sujith Manoharan | 7a897203 | 2013-04-23 12:22:16 +0530 | [diff] [blame] | 137 | enum ath9k_rx_qtype qtype) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 138 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 139 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 140 | struct ath_rxbuf *bf, *tbf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 141 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 142 | if (list_empty(&sc->rx.rxbuf)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 143 | ath_dbg(common, QUEUE, "No free rx buf available\n"); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | |
Mohammed Shafi Shajakhan | 6a01f0c | 2012-02-28 20:54:44 +0530 | [diff] [blame] | 147 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 148 | if (!ath_rx_edma_buf_link(sc, qtype)) |
| 149 | break; |
| 150 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static void ath_rx_remove_buffer(struct ath_softc *sc, |
| 154 | enum ath9k_rx_qtype qtype) |
| 155 | { |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 156 | struct ath_rxbuf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 157 | struct ath_rx_edma *rx_edma; |
| 158 | struct sk_buff *skb; |
| 159 | |
| 160 | rx_edma = &sc->rx.rx_edma[qtype]; |
| 161 | |
Sujith Manoharan | 07236bf | 2013-04-23 12:22:18 +0530 | [diff] [blame] | 162 | while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 163 | bf = SKB_CB_ATHBUF(skb); |
| 164 | BUG_ON(!bf); |
| 165 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static void ath_rx_edma_cleanup(struct ath_softc *sc) |
| 170 | { |
Mohammed Shafi Shajakhan | ba54238 | 2011-09-23 14:33:14 +0530 | [diff] [blame] | 171 | struct ath_hw *ah = sc->sc_ah; |
| 172 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 173 | struct ath_rxbuf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 174 | |
| 175 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
| 176 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 177 | |
| 178 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
Mohammed Shafi Shajakhan | ba54238 | 2011-09-23 14:33:14 +0530 | [diff] [blame] | 179 | if (bf->bf_mpdu) { |
| 180 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
| 181 | common->rx_bufsize, |
| 182 | DMA_BIDIRECTIONAL); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 183 | dev_kfree_skb_any(bf->bf_mpdu); |
Mohammed Shafi Shajakhan | ba54238 | 2011-09-23 14:33:14 +0530 | [diff] [blame] | 184 | bf->bf_buf_addr = 0; |
| 185 | bf->bf_mpdu = NULL; |
| 186 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 187 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size) |
| 191 | { |
Sujith Manoharan | 5d07cca | 2013-08-14 21:15:57 +0530 | [diff] [blame] | 192 | __skb_queue_head_init(&rx_edma->rx_fifo); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 193 | rx_edma->rx_fifo_hwsize = size; |
| 194 | } |
| 195 | |
| 196 | static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) |
| 197 | { |
| 198 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 199 | struct ath_hw *ah = sc->sc_ah; |
| 200 | struct sk_buff *skb; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 201 | struct ath_rxbuf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 202 | int error = 0, i; |
| 203 | u32 size; |
| 204 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 205 | ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize - |
| 206 | ah->caps.rx_status_len); |
| 207 | |
| 208 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP], |
| 209 | ah->caps.rx_lp_qdepth); |
| 210 | ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP], |
| 211 | ah->caps.rx_hp_qdepth); |
| 212 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 213 | size = sizeof(struct ath_rxbuf) * nbufs; |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 214 | bf = devm_kzalloc(sc->dev, size, GFP_KERNEL); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 215 | if (!bf) |
| 216 | return -ENOMEM; |
| 217 | |
| 218 | INIT_LIST_HEAD(&sc->rx.rxbuf); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 219 | |
| 220 | for (i = 0; i < nbufs; i++, bf++) { |
| 221 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL); |
| 222 | if (!skb) { |
| 223 | error = -ENOMEM; |
| 224 | goto rx_init_fail; |
| 225 | } |
| 226 | |
| 227 | memset(skb->data, 0, common->rx_bufsize); |
| 228 | bf->bf_mpdu = skb; |
| 229 | |
| 230 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 231 | common->rx_bufsize, |
| 232 | DMA_BIDIRECTIONAL); |
| 233 | if (unlikely(dma_mapping_error(sc->dev, |
| 234 | bf->bf_buf_addr))) { |
| 235 | dev_kfree_skb_any(skb); |
| 236 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 237 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 238 | ath_err(common, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 239 | "dma_mapping_error() on RX init\n"); |
| 240 | error = -ENOMEM; |
| 241 | goto rx_init_fail; |
| 242 | } |
| 243 | |
| 244 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | |
| 249 | rx_init_fail: |
| 250 | ath_rx_edma_cleanup(sc); |
| 251 | return error; |
| 252 | } |
| 253 | |
| 254 | static void ath_edma_start_recv(struct ath_softc *sc) |
| 255 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 256 | ath9k_hw_rxena(sc->sc_ah); |
Sujith Manoharan | 7a897203 | 2013-04-23 12:22:16 +0530 | [diff] [blame] | 257 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP); |
| 258 | ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 259 | ath_opmode_init(sc); |
Sujith Manoharan | 4cb54fa | 2012-06-04 16:27:52 +0530 | [diff] [blame] | 260 | ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void ath_edma_stop_recv(struct ath_softc *sc) |
| 264 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 265 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP); |
| 266 | ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 269 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
| 270 | { |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 271 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 272 | struct sk_buff *skb; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 273 | struct ath_rxbuf *bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 274 | int error = 0; |
| 275 | |
Luis R. Rodriguez | 4bdd1e9 | 2010-10-26 15:27:24 -0700 | [diff] [blame] | 276 | spin_lock_init(&sc->sc_pcu_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 277 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 278 | common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 + |
| 279 | sc->sc_ah->caps.rx_status_len; |
| 280 | |
Sujith Manoharan | e87f3d5 | 2013-04-23 12:22:17 +0530 | [diff] [blame] | 281 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 282 | return ath_rx_edma_init(sc, nbufs); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 283 | |
Sujith Manoharan | e87f3d5 | 2013-04-23 12:22:17 +0530 | [diff] [blame] | 284 | ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n", |
| 285 | common->cachelsz, common->rx_bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 286 | |
Sujith Manoharan | e87f3d5 | 2013-04-23 12:22:17 +0530 | [diff] [blame] | 287 | /* Initialize rx descriptors */ |
| 288 | |
| 289 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
| 290 | "rx", nbufs, 1, 0); |
| 291 | if (error != 0) { |
| 292 | ath_err(common, |
| 293 | "failed to allocate rx descriptors: %d\n", |
| 294 | error); |
| 295 | goto err; |
| 296 | } |
| 297 | |
| 298 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 299 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, |
| 300 | GFP_KERNEL); |
| 301 | if (skb == NULL) { |
| 302 | error = -ENOMEM; |
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 | |
Sujith Manoharan | e87f3d5 | 2013-04-23 12:22:17 +0530 | [diff] [blame] | 306 | bf->bf_mpdu = skb; |
| 307 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 308 | common->rx_bufsize, |
| 309 | DMA_FROM_DEVICE); |
| 310 | if (unlikely(dma_mapping_error(sc->dev, |
| 311 | bf->bf_buf_addr))) { |
| 312 | dev_kfree_skb_any(skb); |
| 313 | bf->bf_mpdu = NULL; |
| 314 | bf->bf_buf_addr = 0; |
| 315 | ath_err(common, |
| 316 | "dma_mapping_error() on RX init\n"); |
| 317 | error = -ENOMEM; |
| 318 | goto err; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 319 | } |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 320 | } |
Sujith Manoharan | e87f3d5 | 2013-04-23 12:22:17 +0530 | [diff] [blame] | 321 | sc->rx.rxlink = NULL; |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 322 | err: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 323 | if (error) |
| 324 | ath_rx_cleanup(sc); |
| 325 | |
| 326 | return error; |
| 327 | } |
| 328 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 329 | void ath_rx_cleanup(struct ath_softc *sc) |
| 330 | { |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 331 | struct ath_hw *ah = sc->sc_ah; |
| 332 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 333 | struct sk_buff *skb; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 334 | struct ath_rxbuf *bf; |
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 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 337 | ath_rx_edma_cleanup(sc); |
| 338 | return; |
Sujith Manoharan | e87f3d5 | 2013-04-23 12:22:17 +0530 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 342 | skb = bf->bf_mpdu; |
| 343 | if (skb) { |
| 344 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
| 345 | common->rx_bufsize, |
| 346 | DMA_FROM_DEVICE); |
| 347 | dev_kfree_skb(skb); |
| 348 | bf->bf_buf_addr = 0; |
| 349 | bf->bf_mpdu = NULL; |
Luis R. Rodriguez | 051b919 | 2009-03-23 18:25:01 -0400 | [diff] [blame] | 350 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 351 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /* |
| 355 | * Calculate the receive filter according to the |
| 356 | * operating mode and state: |
| 357 | * |
| 358 | * o always accept unicast, broadcast, and multicast traffic |
| 359 | * o maintain current state of phy error reception (the hal |
| 360 | * may enable phy error frames for noise immunity work) |
| 361 | * o probe request frames are accepted only when operating in |
| 362 | * hostap, adhoc, or monitor modes |
| 363 | * o enable promiscuous mode according to the interface state |
| 364 | * o accept beacons: |
| 365 | * - when operating in adhoc mode so the 802.11 layer creates |
| 366 | * node table entries for peers, |
| 367 | * - when operating in station mode for collecting rssi data when |
| 368 | * the station is otherwise quiet, or |
| 369 | * - when operating as a repeater so we see repeater-sta beacons |
| 370 | * - when scanning |
| 371 | */ |
| 372 | |
| 373 | u32 ath_calcrxfilter(struct ath_softc *sc) |
| 374 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 375 | u32 rfilt; |
| 376 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 377 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 378 | return 0; |
| 379 | |
Felix Fietkau | ac06697 | 2011-10-08 15:49:57 +0200 | [diff] [blame] | 380 | rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 381 | | ATH9K_RX_FILTER_MCAST; |
| 382 | |
Zefir Kurtisi | 73e4937 | 2013-04-03 18:31:31 +0200 | [diff] [blame] | 383 | /* if operating on a DFS channel, enable radar pulse detection */ |
| 384 | if (sc->hw->conf.radar_enabled) |
| 385 | rfilt |= ATH9K_RX_FILTER_PHYRADAR | ATH9K_RX_FILTER_PHYERR; |
| 386 | |
Jouni Malinen | 9c1d8e4 | 2010-10-13 17:29:31 +0300 | [diff] [blame] | 387 | if (sc->rx.rxfilter & FIF_PROBE_REQ) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 388 | rfilt |= ATH9K_RX_FILTER_PROBEREQ; |
| 389 | |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 390 | /* |
| 391 | * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station |
| 392 | * mode interface or when in monitor mode. AP mode does not need this |
| 393 | * since it receives all in-BSS frames anyway. |
| 394 | */ |
Felix Fietkau | 2e28694 | 2011-03-09 01:48:12 +0100 | [diff] [blame] | 395 | if (sc->sc_ah->is_monitoring) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 396 | rfilt |= ATH9K_RX_FILTER_PROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 397 | |
Sujith | d42c6b7 | 2009-02-04 08:10:22 +0530 | [diff] [blame] | 398 | if (sc->rx.rxfilter & FIF_CONTROL) |
| 399 | rfilt |= ATH9K_RX_FILTER_CONTROL; |
| 400 | |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 401 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) && |
Ben Greear | cfda669 | 2010-09-14 12:00:22 -0700 | [diff] [blame] | 402 | (sc->nvifs <= 1) && |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 403 | !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC)) |
| 404 | rfilt |= ATH9K_RX_FILTER_MYBEACON; |
| 405 | else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 406 | rfilt |= ATH9K_RX_FILTER_BEACON; |
| 407 | |
Felix Fietkau | 264bbec | 2011-04-07 19:24:23 +0200 | [diff] [blame] | 408 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || |
Senthil Balasubramanian | 66afad0 | 2009-09-18 15:06:07 +0530 | [diff] [blame] | 409 | (sc->rx.rxfilter & FIF_PSPOLL)) |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 410 | rfilt |= ATH9K_RX_FILTER_PSPOLL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 411 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 412 | if (conf_is_ht(&sc->hw->conf)) |
| 413 | rfilt |= ATH9K_RX_FILTER_COMP_BAR; |
| 414 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 415 | if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) { |
Thomas Wagner | a549459 | 2012-09-25 21:32:55 +0530 | [diff] [blame] | 416 | /* This is needed for older chips */ |
| 417 | if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160) |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 418 | rfilt |= ATH9K_RX_FILTER_PROM; |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 419 | rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL; |
| 420 | } |
| 421 | |
Sujith Manoharan | 2c32305 | 2013-12-31 08:12:02 +0530 | [diff] [blame] | 422 | if (AR_SREV_9550(sc->sc_ah) || AR_SREV_9531(sc->sc_ah)) |
Gabor Juhos | b3d7aa4 | 2012-07-03 19:13:33 +0200 | [diff] [blame] | 423 | rfilt |= ATH9K_RX_FILTER_4ADDRESS; |
| 424 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 425 | return rfilt; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 426 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 429 | int ath_startrecv(struct ath_softc *sc) |
| 430 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 431 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 432 | struct ath_rxbuf *bf, *tbf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 433 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 434 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 435 | ath_edma_start_recv(sc); |
| 436 | return 0; |
| 437 | } |
| 438 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 439 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 440 | goto start_recv; |
| 441 | |
Felix Fietkau | e96542e | 2013-08-10 15:59:15 +0200 | [diff] [blame] | 442 | sc->rx.buf_hold = NULL; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 443 | sc->rx.rxlink = NULL; |
| 444 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 445 | ath_rx_buf_link(sc, bf); |
| 446 | } |
| 447 | |
| 448 | /* We could have deleted elements so the list may be empty now */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 449 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 450 | goto start_recv; |
| 451 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 452 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 453 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 454 | ath9k_hw_rxena(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 455 | |
| 456 | start_recv: |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 457 | ath_opmode_init(sc); |
Sujith Manoharan | 4cb54fa | 2012-06-04 16:27:52 +0530 | [diff] [blame] | 458 | ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 459 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
Felix Fietkau | 4b883f0 | 2013-01-09 16:16:56 +0100 | [diff] [blame] | 463 | static void ath_flushrecv(struct ath_softc *sc) |
| 464 | { |
| 465 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 466 | ath_rx_tasklet(sc, 1, true); |
| 467 | ath_rx_tasklet(sc, 1, false); |
| 468 | } |
| 469 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 470 | bool ath_stoprecv(struct ath_softc *sc) |
| 471 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 472 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | 5882da02 | 2011-04-08 20:13:18 +0200 | [diff] [blame] | 473 | bool stopped, reset = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 474 | |
Felix Fietkau | d47844a | 2010-11-20 03:08:47 +0100 | [diff] [blame] | 475 | ath9k_hw_abortpcurecv(ah); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 476 | ath9k_hw_setrxfilter(ah, 0); |
Felix Fietkau | 5882da02 | 2011-04-08 20:13:18 +0200 | [diff] [blame] | 477 | stopped = ath9k_hw_stopdmarecv(ah, &reset); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 478 | |
Felix Fietkau | 4b883f0 | 2013-01-09 16:16:56 +0100 | [diff] [blame] | 479 | ath_flushrecv(sc); |
| 480 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 481 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 482 | ath_edma_stop_recv(sc); |
| 483 | else |
| 484 | sc->rx.rxlink = NULL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 485 | |
Rajkumar Manoharan | d584747 | 2010-12-20 14:39:51 +0530 | [diff] [blame] | 486 | if (!(ah->ah_flags & AH_UNPLUGGED) && |
| 487 | unlikely(!stopped)) { |
Ben Greear | d7fd1b50 | 2010-12-06 13:13:07 -0800 | [diff] [blame] | 488 | ath_err(ath9k_hw_common(sc->sc_ah), |
| 489 | "Could not stop RX, we could be " |
| 490 | "confusing the DMA engine when we start RX up\n"); |
| 491 | ATH_DBG_WARN_ON_ONCE(!stopped); |
| 492 | } |
Felix Fietkau | 2232d31 | 2011-04-15 00:41:43 +0200 | [diff] [blame] | 493 | return stopped && !reset; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 496 | static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) |
| 497 | { |
| 498 | /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */ |
| 499 | struct ieee80211_mgmt *mgmt; |
| 500 | u8 *pos, *end, id, elen; |
| 501 | struct ieee80211_tim_ie *tim; |
| 502 | |
| 503 | mgmt = (struct ieee80211_mgmt *)skb->data; |
| 504 | pos = mgmt->u.beacon.variable; |
| 505 | end = skb->data + skb->len; |
| 506 | |
| 507 | while (pos + 2 < end) { |
| 508 | id = *pos++; |
| 509 | elen = *pos++; |
| 510 | if (pos + elen > end) |
| 511 | break; |
| 512 | |
| 513 | if (id == WLAN_EID_TIM) { |
| 514 | if (elen < sizeof(*tim)) |
| 515 | break; |
| 516 | tim = (struct ieee80211_tim_ie *) pos; |
| 517 | if (tim->dtim_count != 0) |
| 518 | break; |
| 519 | return tim->bitmap_ctrl & 0x01; |
| 520 | } |
| 521 | |
| 522 | pos += elen; |
| 523 | } |
| 524 | |
| 525 | return false; |
| 526 | } |
| 527 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 528 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) |
| 529 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 530 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 531 | |
| 532 | if (skb->len < 24 + 8 + 2 + 2) |
| 533 | return; |
| 534 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 535 | sc->ps_flags &= ~PS_WAIT_FOR_BEACON; |
Gabor Juhos | 293dc5d | 2009-06-19 12:17:48 +0200 | [diff] [blame] | 536 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 537 | if (sc->ps_flags & PS_BEACON_SYNC) { |
| 538 | sc->ps_flags &= ~PS_BEACON_SYNC; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 539 | ath_dbg(common, PS, |
Sujith Manoharan | 1a6404a | 2013-02-04 15:38:24 +0530 | [diff] [blame] | 540 | "Reconfigure beacon timers based on synchronized timestamp\n"); |
Ben Greear | 76c9398 | 2014-04-30 12:02:05 -0700 | [diff] [blame] | 541 | if (!(WARN_ON_ONCE(sc->cur_beacon_conf.beacon_interval == 0))) |
| 542 | ath9k_set_beacon(sc); |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 543 | if (sc->p2p_ps_vif) |
| 544 | ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 545 | } |
| 546 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 547 | if (ath_beacon_dtim_pending_cab(skb)) { |
| 548 | /* |
| 549 | * Remain awake waiting for buffered broadcast/multicast |
Gabor Juhos | 58f5fff | 2009-06-17 20:53:20 +0200 | [diff] [blame] | 550 | * frames. If the last broadcast/multicast frame is not |
| 551 | * received properly, the next beacon frame will work as |
| 552 | * a backup trigger for returning into NETWORK SLEEP state, |
| 553 | * so we are waiting for it as well. |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 554 | */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 555 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 556 | "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 557 | sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON; |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 558 | return; |
| 559 | } |
| 560 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 561 | if (sc->ps_flags & PS_WAIT_FOR_CAB) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 562 | /* |
| 563 | * This can happen if a broadcast frame is dropped or the AP |
| 564 | * fails to send a frame indicating that all CAB frames have |
| 565 | * been delivered. |
| 566 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 567 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 568 | ath_dbg(common, PS, "PS wait for CAB frames timed out\n"); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 569 | } |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 570 | } |
| 571 | |
Rajkumar Manoharan | f73c604 | 2011-09-26 22:16:56 +0530 | [diff] [blame] | 572 | 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] | 573 | { |
| 574 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 575 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 576 | |
| 577 | hdr = (struct ieee80211_hdr *)skb->data; |
| 578 | |
| 579 | /* Process Beacon and CAB receive in PS state */ |
Vasanthakumar Thiagarajan | ededf1f | 2010-05-22 23:58:13 -0700 | [diff] [blame] | 580 | 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] | 581 | && mybeacon) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 582 | ath_rx_ps_beacon(sc, skb); |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 583 | } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && |
| 584 | (ieee80211_is_data(hdr->frame_control) || |
| 585 | ieee80211_is_action(hdr->frame_control)) && |
| 586 | is_multicast_ether_addr(hdr->addr1) && |
| 587 | !ieee80211_has_moredata(hdr->frame_control)) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 588 | /* |
| 589 | * No more broadcast/multicast frames to be received at this |
| 590 | * point. |
| 591 | */ |
Senthil Balasubramanian | 3fac6df | 2010-09-16 15:12:35 -0400 | [diff] [blame] | 592 | sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 593 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 594 | "All PS CAB frames received, back to sleep\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 595 | } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) && |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 596 | !is_multicast_ether_addr(hdr->addr1) && |
| 597 | !ieee80211_has_morefrags(hdr->frame_control)) { |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 598 | sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 599 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 600 | "Going back to sleep after having received PS-Poll data (0x%lx)\n", |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 601 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 602 | PS_WAIT_FOR_CAB | |
| 603 | PS_WAIT_FOR_PSPOLL_DATA | |
| 604 | PS_WAIT_FOR_TX_ACK)); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 608 | static bool ath_edma_get_buffers(struct ath_softc *sc, |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 609 | enum ath9k_rx_qtype qtype, |
| 610 | struct ath_rx_status *rs, |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 611 | struct ath_rxbuf **dest) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 612 | { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 613 | struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype]; |
| 614 | struct ath_hw *ah = sc->sc_ah; |
| 615 | struct ath_common *common = ath9k_hw_common(ah); |
| 616 | struct sk_buff *skb; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 617 | struct ath_rxbuf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 618 | int ret; |
| 619 | |
| 620 | skb = skb_peek(&rx_edma->rx_fifo); |
| 621 | if (!skb) |
| 622 | return false; |
| 623 | |
| 624 | bf = SKB_CB_ATHBUF(skb); |
| 625 | BUG_ON(!bf); |
| 626 | |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 627 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 628 | common->rx_bufsize, DMA_FROM_DEVICE); |
| 629 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 630 | ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data); |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 631 | if (ret == -EINPROGRESS) { |
| 632 | /*let device gain the buffer again*/ |
| 633 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
| 634 | common->rx_bufsize, DMA_FROM_DEVICE); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 635 | return false; |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 636 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 637 | |
| 638 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 639 | if (ret == -EINVAL) { |
| 640 | /* corrupt descriptor, skip this one and the following one */ |
| 641 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 642 | ath_rx_edma_buf_link(sc, qtype); |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 643 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 644 | skb = skb_peek(&rx_edma->rx_fifo); |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 645 | if (skb) { |
| 646 | bf = SKB_CB_ATHBUF(skb); |
| 647 | BUG_ON(!bf); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 648 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 649 | __skb_unlink(skb, &rx_edma->rx_fifo); |
| 650 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
| 651 | ath_rx_edma_buf_link(sc, qtype); |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 652 | } |
Tom Hughes | 6bb51c7 | 2012-06-27 18:21:15 +0100 | [diff] [blame] | 653 | |
| 654 | bf = NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 655 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 656 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 657 | *dest = bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 658 | return true; |
| 659 | } |
| 660 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 661 | static struct ath_rxbuf *ath_edma_get_next_rx_buf(struct ath_softc *sc, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 662 | struct ath_rx_status *rs, |
| 663 | enum ath9k_rx_qtype qtype) |
| 664 | { |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 665 | struct ath_rxbuf *bf = NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 666 | |
Felix Fietkau | 3a2923e | 2012-03-03 15:17:05 +0100 | [diff] [blame] | 667 | while (ath_edma_get_buffers(sc, qtype, rs, &bf)) { |
| 668 | if (!bf) |
| 669 | continue; |
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 | return bf; |
| 672 | } |
| 673 | return NULL; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 674 | } |
| 675 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 676 | static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 677 | struct ath_rx_status *rs) |
| 678 | { |
| 679 | struct ath_hw *ah = sc->sc_ah; |
| 680 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 681 | struct ath_desc *ds; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 682 | struct ath_rxbuf *bf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 683 | int ret; |
| 684 | |
| 685 | if (list_empty(&sc->rx.rxbuf)) { |
| 686 | sc->rx.rxlink = NULL; |
| 687 | return NULL; |
| 688 | } |
| 689 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 690 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list); |
Felix Fietkau | e96542e | 2013-08-10 15:59:15 +0200 | [diff] [blame] | 691 | if (bf == sc->rx.buf_hold) |
| 692 | return NULL; |
| 693 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 694 | ds = bf->bf_desc; |
| 695 | |
| 696 | /* |
| 697 | * Must provide the virtual address of the current |
| 698 | * descriptor, the physical address, and the virtual |
| 699 | * address of the next descriptor in the h/w chain. |
| 700 | * This allows the HAL to look ahead to see if the |
| 701 | * hardware is done with a descriptor by checking the |
| 702 | * done bit in the following descriptor and the address |
| 703 | * of the current descriptor the DMA engine is working |
| 704 | * on. All this is necessary because of our use of |
| 705 | * a self-linked list to avoid rx overruns. |
| 706 | */ |
Rajkumar Manoharan | 3de2111 | 2011-08-13 10:28:11 +0530 | [diff] [blame] | 707 | ret = ath9k_hw_rxprocdesc(ah, ds, rs); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 708 | if (ret == -EINPROGRESS) { |
| 709 | struct ath_rx_status trs; |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 710 | struct ath_rxbuf *tbf; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 711 | struct ath_desc *tds; |
| 712 | |
| 713 | memset(&trs, 0, sizeof(trs)); |
| 714 | if (list_is_last(&bf->list, &sc->rx.rxbuf)) { |
| 715 | sc->rx.rxlink = NULL; |
| 716 | return NULL; |
| 717 | } |
| 718 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 719 | tbf = list_entry(bf->list.next, struct ath_rxbuf, list); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 720 | |
| 721 | /* |
| 722 | * On some hardware the descriptor status words could |
| 723 | * get corrupted, including the done bit. Because of |
| 724 | * this, check if the next descriptor's done bit is |
| 725 | * set or not. |
| 726 | * |
| 727 | * If the next descriptor's done bit is set, the current |
| 728 | * descriptor has been corrupted. Force s/w to discard |
| 729 | * this descriptor and continue... |
| 730 | */ |
| 731 | |
| 732 | tds = tbf->bf_desc; |
Rajkumar Manoharan | 3de2111 | 2011-08-13 10:28:11 +0530 | [diff] [blame] | 733 | ret = ath9k_hw_rxprocdesc(ah, tds, &trs); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 734 | if (ret == -EINPROGRESS) |
| 735 | return NULL; |
Felix Fietkau | 723e711 | 2013-04-08 00:04:11 +0200 | [diff] [blame] | 736 | |
| 737 | /* |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 738 | * Re-check previous descriptor, in case it has been filled |
| 739 | * in the mean time. |
Felix Fietkau | 723e711 | 2013-04-08 00:04:11 +0200 | [diff] [blame] | 740 | */ |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 741 | ret = ath9k_hw_rxprocdesc(ah, ds, rs); |
| 742 | if (ret == -EINPROGRESS) { |
| 743 | /* |
| 744 | * mark descriptor as zero-length and set the 'more' |
| 745 | * flag to ensure that both buffers get discarded |
| 746 | */ |
| 747 | rs->rs_datalen = 0; |
| 748 | rs->rs_more = true; |
| 749 | } |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 750 | } |
| 751 | |
Felix Fietkau | a3dc48e | 2013-01-09 16:16:52 +0100 | [diff] [blame] | 752 | list_del(&bf->list); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 753 | if (!bf->bf_mpdu) |
| 754 | return bf; |
| 755 | |
| 756 | /* |
| 757 | * Synchronize the DMA transfer with CPU before |
| 758 | * 1. accessing the frame |
| 759 | * 2. requeueing the same buffer to h/w |
| 760 | */ |
Ming Lei | ce9426d | 2010-05-15 18:25:40 +0800 | [diff] [blame] | 761 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 762 | common->rx_bufsize, |
| 763 | DMA_FROM_DEVICE); |
| 764 | |
| 765 | return bf; |
| 766 | } |
| 767 | |
Sujith Manoharan | e0dd1a9 | 2013-08-14 09:11:13 +0530 | [diff] [blame] | 768 | static void ath9k_process_tsf(struct ath_rx_status *rs, |
| 769 | struct ieee80211_rx_status *rxs, |
| 770 | u64 tsf) |
| 771 | { |
| 772 | u32 tsf_lower = tsf & 0xffffffff; |
| 773 | |
| 774 | rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp; |
| 775 | if (rs->rs_tstamp > tsf_lower && |
| 776 | unlikely(rs->rs_tstamp - tsf_lower > 0x10000000)) |
| 777 | rxs->mactime -= 0x100000000ULL; |
| 778 | |
| 779 | if (rs->rs_tstamp < tsf_lower && |
| 780 | unlikely(tsf_lower - rs->rs_tstamp > 0x10000000)) |
| 781 | rxs->mactime += 0x100000000ULL; |
| 782 | } |
| 783 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 784 | /* |
| 785 | * For Decrypt or Demic errors, we only mark packet status here and always push |
| 786 | * up the frame up to let mac80211 handle the actual error case, be it no |
| 787 | * decryption key or real decryption error. This let us keep statistics there. |
| 788 | */ |
Felix Fietkau | 723e711 | 2013-04-08 00:04:11 +0200 | [diff] [blame] | 789 | static int ath9k_rx_skb_preprocess(struct ath_softc *sc, |
Sujith Manoharan | 6f38482 | 2013-08-14 09:11:18 +0530 | [diff] [blame] | 790 | struct sk_buff *skb, |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 791 | struct ath_rx_status *rx_stats, |
| 792 | struct ieee80211_rx_status *rx_status, |
Sujith Manoharan | e0dd1a9 | 2013-08-14 09:11:13 +0530 | [diff] [blame] | 793 | bool *decrypt_error, u64 tsf) |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 794 | { |
Felix Fietkau | 723e711 | 2013-04-08 00:04:11 +0200 | [diff] [blame] | 795 | struct ieee80211_hw *hw = sc->hw; |
| 796 | struct ath_hw *ah = sc->sc_ah; |
| 797 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | 6f38482 | 2013-08-14 09:11:18 +0530 | [diff] [blame] | 798 | struct ieee80211_hdr *hdr; |
Felix Fietkau | 723e711 | 2013-04-08 00:04:11 +0200 | [diff] [blame] | 799 | bool discard_current = sc->rx.discard_next; |
| 800 | |
Sujith Manoharan | 5871d2d | 2013-08-14 09:11:11 +0530 | [diff] [blame] | 801 | /* |
| 802 | * Discard corrupt descriptors which are marked in |
| 803 | * ath_get_next_rx_buf(). |
| 804 | */ |
Felix Fietkau | 723e711 | 2013-04-08 00:04:11 +0200 | [diff] [blame] | 805 | if (discard_current) |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 806 | goto corrupt; |
| 807 | |
| 808 | sc->rx.discard_next = false; |
Felix Fietkau | f749b94 | 2011-07-28 14:08:57 +0200 | [diff] [blame] | 809 | |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 810 | /* |
Sujith Manoharan | 5871d2d | 2013-08-14 09:11:11 +0530 | [diff] [blame] | 811 | * Discard zero-length packets. |
| 812 | */ |
| 813 | if (!rx_stats->rs_datalen) { |
| 814 | RX_STAT_INC(rx_len_err); |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 815 | goto corrupt; |
Sujith Manoharan | 5871d2d | 2013-08-14 09:11:11 +0530 | [diff] [blame] | 816 | } |
| 817 | |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 818 | /* |
| 819 | * rs_status follows rs_datalen so if rs_datalen is too large |
| 820 | * we can take a hint that hardware corrupted it, so ignore |
| 821 | * those frames. |
| 822 | */ |
Sujith Manoharan | 5871d2d | 2013-08-14 09:11:11 +0530 | [diff] [blame] | 823 | if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) { |
| 824 | RX_STAT_INC(rx_len_err); |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 825 | goto corrupt; |
Sujith Manoharan | 5871d2d | 2013-08-14 09:11:11 +0530 | [diff] [blame] | 826 | } |
| 827 | |
Sujith Manoharan | 4a47064 | 2013-08-14 09:11:12 +0530 | [diff] [blame] | 828 | /* Only use status info from the last fragment */ |
| 829 | if (rx_stats->rs_more) |
| 830 | return 0; |
| 831 | |
Sujith Manoharan | b092559 | 2013-08-14 09:11:20 +0530 | [diff] [blame] | 832 | /* |
| 833 | * Return immediately if the RX descriptor has been marked |
| 834 | * as corrupt based on the various error bits. |
| 835 | * |
| 836 | * This is different from the other corrupt descriptor |
| 837 | * condition handled above. |
| 838 | */ |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 839 | if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC) |
| 840 | goto corrupt; |
Sujith Manoharan | b092559 | 2013-08-14 09:11:20 +0530 | [diff] [blame] | 841 | |
Sujith Manoharan | 6f38482 | 2013-08-14 09:11:18 +0530 | [diff] [blame] | 842 | hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len); |
| 843 | |
Sujith Manoharan | e0dd1a9 | 2013-08-14 09:11:13 +0530 | [diff] [blame] | 844 | ath9k_process_tsf(rx_stats, rx_status, tsf); |
Sujith Manoharan | 5e85a32 | 2013-08-14 09:11:16 +0530 | [diff] [blame] | 845 | ath_debug_stat_rx(sc, rx_stats); |
Sujith Manoharan | e0dd1a9 | 2013-08-14 09:11:13 +0530 | [diff] [blame] | 846 | |
Sujith Manoharan | 5871d2d | 2013-08-14 09:11:11 +0530 | [diff] [blame] | 847 | /* |
Sujith Manoharan | 6b87d71 | 2013-08-14 09:11:15 +0530 | [diff] [blame] | 848 | * Process PHY errors and return so that the packet |
| 849 | * can be dropped. |
| 850 | */ |
| 851 | if (rx_stats->rs_status & ATH9K_RXERR_PHY) { |
| 852 | ath9k_dfs_process_phyerr(sc, hdr, rx_stats, rx_status->mactime); |
| 853 | if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime)) |
| 854 | RX_STAT_INC(rx_spectral); |
| 855 | |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 856 | return -EINVAL; |
Sujith Manoharan | 6b87d71 | 2013-08-14 09:11:15 +0530 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | /* |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 860 | * everything but the rate is checked here, the rate check is done |
| 861 | * separately to avoid doing two lookups for a rate for each frame. |
| 862 | */ |
John W. Linville | f3b6a48 | 2014-03-04 13:05:12 -0500 | [diff] [blame] | 863 | if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error, sc->rx.rxfilter)) |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 864 | return -EINVAL; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 865 | |
Oleksij Rempel | 1cc47a5 | 2014-01-15 17:07:15 +0100 | [diff] [blame] | 866 | if (ath_is_mybeacon(common, hdr)) { |
| 867 | RX_STAT_INC(rx_beacons); |
| 868 | rx_stats->is_mybeacon = true; |
| 869 | } |
Sujith Manoharan | 6f38482 | 2013-08-14 09:11:18 +0530 | [diff] [blame] | 870 | |
Sujith Manoharan | ff9a93f | 2014-01-09 08:51:14 +0530 | [diff] [blame] | 871 | /* |
| 872 | * This shouldn't happen, but have a safety check anyway. |
| 873 | */ |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 874 | if (WARN_ON(!ah->curchan)) |
| 875 | return -EINVAL; |
Sujith Manoharan | ff9a93f | 2014-01-09 08:51:14 +0530 | [diff] [blame] | 876 | |
Oleksij Rempel | 1274603 | 2014-02-04 10:27:40 +0100 | [diff] [blame] | 877 | if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) { |
| 878 | /* |
| 879 | * No valid hardware bitrate found -- we should not get here |
| 880 | * because hardware has already validated this frame as OK. |
| 881 | */ |
| 882 | ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n", |
| 883 | rx_stats->rs_rate); |
| 884 | RX_STAT_INC(rx_rate_err); |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 885 | return -EINVAL; |
Sujith Manoharan | 7c5c73c | 2013-08-14 09:11:21 +0530 | [diff] [blame] | 886 | } |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 887 | |
Oleksij Rempel | 32efb0c | 2014-02-04 10:27:39 +0100 | [diff] [blame] | 888 | ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status); |
Sujith Manoharan | 74a9775 | 2013-06-03 09:19:23 +0530 | [diff] [blame] | 889 | |
Sujith Manoharan | ff9a93f | 2014-01-09 08:51:14 +0530 | [diff] [blame] | 890 | rx_status->band = ah->curchan->chan->band; |
| 891 | rx_status->freq = ah->curchan->chan->center_freq; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 892 | rx_status->antenna = rx_stats->rs_antenna; |
Thomas Pedersen | 96d2137 | 2012-12-10 14:48:01 -0800 | [diff] [blame] | 893 | rx_status->flag |= RX_FLAG_MACTIME_END; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 894 | |
Sujith Manoharan | a5525d9 | 2013-08-14 09:11:17 +0530 | [diff] [blame] | 895 | #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT |
| 896 | if (ieee80211_is_data_present(hdr->frame_control) && |
| 897 | !ieee80211_is_qos_nullfunc(hdr->frame_control)) |
| 898 | sc->rx.num_pkts++; |
| 899 | #endif |
| 900 | |
Felix Fietkau | b7b146c | 2014-02-24 22:26:06 +0100 | [diff] [blame] | 901 | return 0; |
| 902 | |
| 903 | corrupt: |
| 904 | sc->rx.discard_next = rx_stats->rs_more; |
| 905 | return -EINVAL; |
Sujith | d435700 | 2010-05-20 15:34:38 +0530 | [diff] [blame] | 906 | } |
| 907 | |
Sujith Manoharan | c3124df | 2013-08-14 21:15:56 +0530 | [diff] [blame] | 908 | /* |
| 909 | * Run the LNA combining algorithm only in these cases: |
| 910 | * |
| 911 | * Standalone WLAN cards with both LNA/Antenna diversity |
| 912 | * enabled in the EEPROM. |
| 913 | * |
| 914 | * WLAN+BT cards which are in the supported card list |
| 915 | * in ath_pci_id_table and the user has loaded the |
| 916 | * driver with "bt_ant_diversity" set to true. |
| 917 | */ |
| 918 | static void ath9k_antenna_check(struct ath_softc *sc, |
| 919 | struct ath_rx_status *rs) |
| 920 | { |
| 921 | struct ath_hw *ah = sc->sc_ah; |
| 922 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
| 923 | struct ath_common *common = ath9k_hw_common(ah); |
| 924 | |
| 925 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) |
| 926 | return; |
| 927 | |
| 928 | /* |
Sujith Manoharan | c3124df | 2013-08-14 21:15:56 +0530 | [diff] [blame] | 929 | * Change the default rx antenna if rx diversity |
| 930 | * chooses the other antenna 3 times in a row. |
| 931 | */ |
| 932 | if (sc->rx.defant != rs->rs_antenna) { |
| 933 | if (++sc->rx.rxotherant >= 3) |
| 934 | ath_setdefantenna(sc, rs->rs_antenna); |
| 935 | } else { |
| 936 | sc->rx.rxotherant = 0; |
| 937 | } |
| 938 | |
| 939 | if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) { |
| 940 | if (common->bt_ant_diversity) |
| 941 | ath_ant_comb_scan(sc, rs); |
| 942 | } else { |
| 943 | ath_ant_comb_scan(sc, rs); |
| 944 | } |
| 945 | } |
| 946 | |
Christian Lamparter | 21fbbca | 2013-01-30 23:37:41 +0100 | [diff] [blame] | 947 | static void ath9k_apply_ampdu_details(struct ath_softc *sc, |
| 948 | struct ath_rx_status *rs, struct ieee80211_rx_status *rxs) |
| 949 | { |
| 950 | if (rs->rs_isaggr) { |
| 951 | rxs->flag |= RX_FLAG_AMPDU_DETAILS | RX_FLAG_AMPDU_LAST_KNOWN; |
| 952 | |
| 953 | rxs->ampdu_reference = sc->rx.ampdu_ref; |
| 954 | |
| 955 | if (!rs->rs_moreaggr) { |
| 956 | rxs->flag |= RX_FLAG_AMPDU_IS_LAST; |
| 957 | sc->rx.ampdu_ref++; |
| 958 | } |
| 959 | |
| 960 | if (rs->rs_flags & ATH9K_RX_DELIM_CRC_PRE) |
| 961 | rxs->flag |= RX_FLAG_AMPDU_DELIM_CRC_ERROR; |
| 962 | } |
| 963 | } |
| 964 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 965 | int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) |
| 966 | { |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 967 | struct ath_rxbuf *bf; |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 968 | struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 969 | struct ieee80211_rx_status *rxs; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 970 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 971 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 972 | struct ieee80211_hw *hw = sc->hw; |
Luis R. Rodriguez | c9b1417 | 2009-11-04 16:47:22 -0800 | [diff] [blame] | 973 | int retval; |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 974 | struct ath_rx_status rs; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 975 | enum ath9k_rx_qtype qtype; |
| 976 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
| 977 | int dma_type; |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 978 | u64 tsf = 0; |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 979 | unsigned long flags; |
Felix Fietkau | 2e1cd49 | 2013-04-08 00:04:10 +0200 | [diff] [blame] | 980 | dma_addr_t new_buf_addr; |
Tim Harvey | c82552c | 2014-04-21 16:14:57 -0700 | [diff] [blame] | 981 | unsigned int budget = 512; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 982 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 983 | if (edma) |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 984 | dma_type = DMA_BIDIRECTIONAL; |
Ming Lei | 5682422 | 2010-05-14 21:15:38 +0800 | [diff] [blame] | 985 | else |
| 986 | dma_type = DMA_FROM_DEVICE; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 987 | |
| 988 | qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 989 | |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 990 | tsf = ath9k_hw_gettsf64(ah); |
Felix Fietkau | a6d2055 | 2010-06-12 00:33:54 -0400 | [diff] [blame] | 991 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 992 | do { |
Lorenzo Bianconi | e1352fd | 2012-08-10 11:00:24 +0200 | [diff] [blame] | 993 | bool decrypt_error = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 994 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 995 | memset(&rs, 0, sizeof(rs)); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 996 | if (edma) |
| 997 | bf = ath_edma_get_next_rx_buf(sc, &rs, qtype); |
| 998 | else |
| 999 | bf = ath_get_next_rx_buf(sc, &rs); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1000 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1001 | if (!bf) |
| 1002 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1003 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1004 | skb = bf->bf_mpdu; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1005 | if (!skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1006 | continue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1007 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1008 | /* |
| 1009 | * Take frame header from the first fragment and RX status from |
| 1010 | * the last one. |
| 1011 | */ |
| 1012 | if (sc->rx.frag) |
| 1013 | hdr_skb = sc->rx.frag; |
| 1014 | else |
| 1015 | hdr_skb = skb; |
| 1016 | |
Sujith Manoharan | f6307dd | 2013-08-14 09:11:09 +0530 | [diff] [blame] | 1017 | rxs = IEEE80211_SKB_RXCB(hdr_skb); |
Ashok Nagarajan | ffb1c56 | 2012-03-09 18:57:39 -0800 | [diff] [blame] | 1018 | memset(rxs, 0, sizeof(struct ieee80211_rx_status)); |
| 1019 | |
Sujith Manoharan | 6f38482 | 2013-08-14 09:11:18 +0530 | [diff] [blame] | 1020 | retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs, |
Sujith Manoharan | e0dd1a9 | 2013-08-14 09:11:13 +0530 | [diff] [blame] | 1021 | &decrypt_error, tsf); |
Zefir Kurtisi | 83c7657 | 2011-11-16 11:09:44 +0100 | [diff] [blame] | 1022 | if (retval) |
| 1023 | goto requeue_drop_frag; |
| 1024 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1025 | /* Ensure we always have an skb to requeue once we are done |
| 1026 | * processing the current buffer's skb */ |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 1027 | requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1028 | |
| 1029 | /* If there is no memory we ignore the current RX'd frame, |
| 1030 | * tell hardware it can give us a new frame using the old |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1031 | * 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] | 1032 | * processing. */ |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1033 | if (!requeue_skb) { |
| 1034 | RX_STAT_INC(rx_oom_err); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1035 | goto requeue_drop_frag; |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1036 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1037 | |
Felix Fietkau | 2e1cd49 | 2013-04-08 00:04:10 +0200 | [diff] [blame] | 1038 | /* We will now give hardware our shiny new allocated skb */ |
| 1039 | new_buf_addr = dma_map_single(sc->dev, requeue_skb->data, |
| 1040 | common->rx_bufsize, dma_type); |
| 1041 | if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) { |
| 1042 | dev_kfree_skb_any(requeue_skb); |
| 1043 | goto requeue_drop_frag; |
| 1044 | } |
| 1045 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 1046 | /* Unmap the frame */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 1047 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Felix Fietkau | 2e1cd49 | 2013-04-08 00:04:10 +0200 | [diff] [blame] | 1048 | common->rx_bufsize, dma_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1049 | |
Sujith Manoharan | 176f0e8 | 2013-04-23 12:22:19 +0530 | [diff] [blame] | 1050 | bf->bf_mpdu = requeue_skb; |
| 1051 | bf->bf_buf_addr = new_buf_addr; |
| 1052 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1053 | skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len); |
| 1054 | if (ah->caps.rx_status_len) |
| 1055 | skb_pull(skb, ah->caps.rx_status_len); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1056 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1057 | if (!rs.rs_more) |
Oleksij Rempel | 5a078fc | 2014-02-04 10:27:47 +0100 | [diff] [blame] | 1058 | ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs, |
| 1059 | rxs, decrypt_error); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1060 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1061 | if (rs.rs_more) { |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1062 | RX_STAT_INC(rx_frags); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1063 | /* |
| 1064 | * rs_more indicates chained descriptors which can be |
| 1065 | * used to link buffers together for a sort of |
| 1066 | * scatter-gather operation. |
| 1067 | */ |
| 1068 | if (sc->rx.frag) { |
| 1069 | /* too many fragments - cannot handle frame */ |
| 1070 | dev_kfree_skb_any(sc->rx.frag); |
| 1071 | dev_kfree_skb_any(skb); |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1072 | RX_STAT_INC(rx_too_many_frags_err); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1073 | skb = NULL; |
| 1074 | } |
| 1075 | sc->rx.frag = skb; |
| 1076 | goto requeue; |
| 1077 | } |
| 1078 | |
| 1079 | if (sc->rx.frag) { |
| 1080 | int space = skb->len - skb_tailroom(hdr_skb); |
| 1081 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1082 | if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) { |
| 1083 | dev_kfree_skb(skb); |
Ben Greear | 1507218 | 2012-04-03 09:18:59 -0700 | [diff] [blame] | 1084 | RX_STAT_INC(rx_oom_err); |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1085 | goto requeue_drop_frag; |
| 1086 | } |
| 1087 | |
Eric Dumazet | b5447ff | 2012-03-15 13:43:29 -0700 | [diff] [blame] | 1088 | sc->rx.frag = NULL; |
| 1089 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1090 | skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len), |
| 1091 | skb->len); |
| 1092 | dev_kfree_skb_any(skb); |
| 1093 | skb = hdr_skb; |
| 1094 | } |
| 1095 | |
Felix Fietkau | 66760ea | 2011-07-13 23:35:05 +0800 | [diff] [blame] | 1096 | if (rxs->flag & RX_FLAG_MMIC_STRIPPED) |
| 1097 | skb_trim(skb, skb->len - 8); |
| 1098 | |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1099 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Mohammed Shafi Shajakhan | aaef24b | 2010-12-07 20:40:58 +0530 | [diff] [blame] | 1100 | if ((sc->ps_flags & (PS_WAIT_FOR_BEACON | |
Rajkumar Manoharan | f73c604 | 2011-09-26 22:16:56 +0530 | [diff] [blame] | 1101 | PS_WAIT_FOR_CAB | |
| 1102 | PS_WAIT_FOR_PSPOLL_DATA)) || |
| 1103 | ath9k_check_auto_sleep(sc)) |
| 1104 | ath_rx_ps(sc, skb, rs.is_mybeacon); |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1105 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1106 | |
Sujith Manoharan | c3124df | 2013-08-14 21:15:56 +0530 | [diff] [blame] | 1107 | ath9k_antenna_check(sc, &rs); |
Christian Lamparter | 21fbbca | 2013-01-30 23:37:41 +0100 | [diff] [blame] | 1108 | ath9k_apply_ampdu_details(sc, &rs, rxs); |
Sujith Manoharan | 350e2dc | 2014-01-13 07:29:30 +0530 | [diff] [blame] | 1109 | ath_debug_rate_stats(sc, &rs, skb); |
Christian Lamparter | 21fbbca | 2013-01-30 23:37:41 +0100 | [diff] [blame] | 1110 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1111 | ieee80211_rx(hw, skb); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 1112 | |
Felix Fietkau | 0d95521 | 2011-01-26 18:23:27 +0100 | [diff] [blame] | 1113 | requeue_drop_frag: |
| 1114 | if (sc->rx.frag) { |
| 1115 | dev_kfree_skb_any(sc->rx.frag); |
| 1116 | sc->rx.frag = NULL; |
| 1117 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 1118 | requeue: |
Felix Fietkau | a3dc48e | 2013-01-09 16:16:52 +0100 | [diff] [blame] | 1119 | list_add_tail(&bf->list, &sc->rx.rxbuf); |
Felix Fietkau | a3dc48e | 2013-01-09 16:16:52 +0100 | [diff] [blame] | 1120 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1121 | if (edma) { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1122 | ath_rx_edma_buf_link(sc, qtype); |
| 1123 | } else { |
Felix Fietkau | e96542e | 2013-08-10 15:59:15 +0200 | [diff] [blame] | 1124 | ath_rx_buf_relink(sc, bf); |
Tim Harvey | 3a75813 | 2014-04-21 16:14:56 -0700 | [diff] [blame] | 1125 | if (!flush) |
| 1126 | ath9k_hw_rxena(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 1127 | } |
Tim Harvey | c82552c | 2014-04-21 16:14:57 -0700 | [diff] [blame] | 1128 | |
| 1129 | if (!budget--) |
| 1130 | break; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 1131 | } while (1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1132 | |
Rajkumar Manoharan | 29ab0b3 | 2011-08-13 10:28:10 +0530 | [diff] [blame] | 1133 | if (!(ah->imask & ATH9K_INT_RXEOL)) { |
| 1134 | ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 1135 | ath9k_hw_set_interrupts(ah); |
Rajkumar Manoharan | 29ab0b3 | 2011-08-13 10:28:10 +0530 | [diff] [blame] | 1136 | } |
| 1137 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1138 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1139 | } |