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