Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 17 | #include "ath9k.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 18 | |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 19 | static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc, |
| 20 | struct ieee80211_hdr *hdr) |
| 21 | { |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 22 | struct ieee80211_hw *hw = sc->pri_wiphy->hw; |
| 23 | int i; |
| 24 | |
| 25 | spin_lock_bh(&sc->wiphy_lock); |
| 26 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 27 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 28 | if (aphy == NULL) |
| 29 | continue; |
| 30 | if (compare_ether_addr(hdr->addr1, aphy->hw->wiphy->perm_addr) |
| 31 | == 0) { |
| 32 | hw = aphy->hw; |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | spin_unlock_bh(&sc->wiphy_lock); |
| 37 | return hw; |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Setup and link descriptors. |
| 42 | * |
| 43 | * 11N: we can no longer afford to self link the last descriptor. |
| 44 | * MAC acknowledges BA status as long as it copies frames to host |
| 45 | * buffer (or rx fifo). This can incorrectly acknowledge packets |
| 46 | * to a sender if last desc is self-linked. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 47 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 48 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) |
| 49 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 50 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 51 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 52 | struct ath_desc *ds; |
| 53 | struct sk_buff *skb; |
| 54 | |
| 55 | ATH_RXBUF_RESET(bf); |
| 56 | |
| 57 | ds = bf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 58 | ds->ds_link = 0; /* link to null */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 59 | ds->ds_data = bf->bf_buf_addr; |
| 60 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 61 | /* virtual addr of the beginning of the buffer. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 62 | skb = bf->bf_mpdu; |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 63 | BUG_ON(skb == NULL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 64 | ds->ds_vdata = skb->data; |
| 65 | |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 66 | /* |
| 67 | * setup rx descriptors. The rx_bufsize here tells the hardware |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 68 | * 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] | 69 | * to process |
| 70 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 71 | ath9k_hw_setuprxdesc(ah, ds, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 72 | common->rx_bufsize, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 73 | 0); |
| 74 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 75 | if (sc->rx.rxlink == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 76 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
| 77 | else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 78 | *sc->rx.rxlink = bf->bf_daddr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 79 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 80 | sc->rx.rxlink = &ds->ds_link; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 81 | ath9k_hw_rxena(ah); |
| 82 | } |
| 83 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 84 | static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) |
| 85 | { |
| 86 | /* XXX block beacon interrupts */ |
| 87 | ath9k_hw_setantenna(sc->sc_ah, antenna); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 88 | sc->rx.defant = antenna; |
| 89 | sc->rx.rxotherant = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 90 | } |
| 91 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 92 | static void ath_opmode_init(struct ath_softc *sc) |
| 93 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 94 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 95 | struct ath_common *common = ath9k_hw_common(ah); |
| 96 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 97 | u32 rfilt, mfilt[2]; |
| 98 | |
| 99 | /* configure rx filter */ |
| 100 | rfilt = ath_calcrxfilter(sc); |
| 101 | ath9k_hw_setrxfilter(ah, rfilt); |
| 102 | |
| 103 | /* configure bssid mask */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 104 | if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 105 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 106 | |
| 107 | /* configure operational mode */ |
| 108 | ath9k_hw_setopmode(ah); |
| 109 | |
| 110 | /* Handle any link-level address change. */ |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 111 | ath9k_hw_setmac(ah, common->macaddr); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 112 | |
| 113 | /* calculate and install multicast filter */ |
| 114 | mfilt[0] = mfilt[1] = ~0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 115 | ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
| 119 | { |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 120 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 121 | struct sk_buff *skb; |
| 122 | struct ath_buf *bf; |
| 123 | int error = 0; |
| 124 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 125 | spin_lock_init(&sc->rx.rxflushlock); |
| 126 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
| 127 | spin_lock_init(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 128 | |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 129 | common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN, |
| 130 | min(common->cachelsz, (u16)64)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 131 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 132 | ath_print(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 133 | common->cachelsz, common->rx_bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 134 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 135 | /* Initialize rx descriptors */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 136 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 137 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
| 138 | "rx", nbufs, 1); |
| 139 | if (error != 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 140 | ath_print(common, ATH_DBG_FATAL, |
| 141 | "failed to allocate rx descriptors: %d\n", error); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 142 | goto err; |
| 143 | } |
| 144 | |
| 145 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 146 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 147 | if (skb == NULL) { |
| 148 | error = -ENOMEM; |
| 149 | goto err; |
| 150 | } |
| 151 | |
| 152 | bf->bf_mpdu = skb; |
| 153 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 154 | common->rx_bufsize, |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 155 | DMA_FROM_DEVICE); |
| 156 | if (unlikely(dma_mapping_error(sc->dev, |
| 157 | bf->bf_buf_addr))) { |
| 158 | dev_kfree_skb_any(skb); |
| 159 | bf->bf_mpdu = NULL; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 160 | ath_print(common, ATH_DBG_FATAL, |
| 161 | "dma_mapping_error() on RX init\n"); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 162 | error = -ENOMEM; |
| 163 | goto err; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 164 | } |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 165 | bf->bf_dmacontext = bf->bf_buf_addr; |
| 166 | } |
| 167 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 168 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 169 | err: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 170 | if (error) |
| 171 | ath_rx_cleanup(sc); |
| 172 | |
| 173 | return error; |
| 174 | } |
| 175 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 176 | void ath_rx_cleanup(struct ath_softc *sc) |
| 177 | { |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 178 | struct ath_hw *ah = sc->sc_ah; |
| 179 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 180 | struct sk_buff *skb; |
| 181 | struct ath_buf *bf; |
| 182 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 183 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 184 | skb = bf->bf_mpdu; |
Luis R. Rodriguez | 051b919 | 2009-03-23 18:25:01 -0400 | [diff] [blame] | 185 | if (skb) { |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 186 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 187 | common->rx_bufsize, DMA_FROM_DEVICE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 188 | dev_kfree_skb(skb); |
Luis R. Rodriguez | 051b919 | 2009-03-23 18:25:01 -0400 | [diff] [blame] | 189 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 192 | if (sc->rx.rxdma.dd_desc_len != 0) |
| 193 | ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Calculate the receive filter according to the |
| 198 | * operating mode and state: |
| 199 | * |
| 200 | * o always accept unicast, broadcast, and multicast traffic |
| 201 | * o maintain current state of phy error reception (the hal |
| 202 | * may enable phy error frames for noise immunity work) |
| 203 | * o probe request frames are accepted only when operating in |
| 204 | * hostap, adhoc, or monitor modes |
| 205 | * o enable promiscuous mode according to the interface state |
| 206 | * o accept beacons: |
| 207 | * - when operating in adhoc mode so the 802.11 layer creates |
| 208 | * node table entries for peers, |
| 209 | * - when operating in station mode for collecting rssi data when |
| 210 | * the station is otherwise quiet, or |
| 211 | * - when operating as a repeater so we see repeater-sta beacons |
| 212 | * - when scanning |
| 213 | */ |
| 214 | |
| 215 | u32 ath_calcrxfilter(struct ath_softc *sc) |
| 216 | { |
| 217 | #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR) |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 218 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 219 | u32 rfilt; |
| 220 | |
| 221 | rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE) |
| 222 | | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST |
| 223 | | ATH9K_RX_FILTER_MCAST; |
| 224 | |
| 225 | /* If not a STA, enable processing of Probe Requests */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 226 | if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 227 | rfilt |= ATH9K_RX_FILTER_PROBEREQ; |
| 228 | |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 229 | /* |
| 230 | * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station |
| 231 | * mode interface or when in monitor mode. AP mode does not need this |
| 232 | * since it receives all in-BSS frames anyway. |
| 233 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 234 | if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) && |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 235 | (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) || |
Jouni Malinen | 217ba9d | 2009-03-10 10:55:50 +0200 | [diff] [blame] | 236 | (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 237 | rfilt |= ATH9K_RX_FILTER_PROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 238 | |
Sujith | d42c6b7 | 2009-02-04 08:10:22 +0530 | [diff] [blame] | 239 | if (sc->rx.rxfilter & FIF_CONTROL) |
| 240 | rfilt |= ATH9K_RX_FILTER_CONTROL; |
| 241 | |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 242 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) && |
| 243 | !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC)) |
| 244 | rfilt |= ATH9K_RX_FILTER_MYBEACON; |
| 245 | else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 246 | rfilt |= ATH9K_RX_FILTER_BEACON; |
| 247 | |
Senthil Balasubramanian | 66afad0 | 2009-09-18 15:06:07 +0530 | [diff] [blame] | 248 | if ((AR_SREV_9280_10_OR_LATER(sc->sc_ah) || |
| 249 | AR_SREV_9285_10_OR_LATER(sc->sc_ah)) && |
| 250 | (sc->sc_ah->opmode == NL80211_IFTYPE_AP) && |
| 251 | (sc->rx.rxfilter & FIF_PSPOLL)) |
Vasanthakumar Thiagarajan | dbaaa14 | 2009-02-19 15:41:52 +0530 | [diff] [blame] | 252 | rfilt |= ATH9K_RX_FILTER_PSPOLL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 253 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 254 | if (conf_is_ht(&sc->hw->conf)) |
| 255 | rfilt |= ATH9K_RX_FILTER_COMP_BAR; |
| 256 | |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 257 | if (sc->sec_wiphy || (sc->rx.rxfilter & FIF_OTHER_BSS)) { |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 258 | /* TODO: only needed if more than one BSSID is in use in |
| 259 | * station/adhoc mode */ |
Javier Cardona | 5eb6ba8 | 2009-08-20 19:12:07 -0700 | [diff] [blame] | 260 | /* The following may also be needed for other older chips */ |
| 261 | if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160) |
| 262 | rfilt |= ATH9K_RX_FILTER_PROM; |
Jouni Malinen | b93bce2 | 2009-03-03 19:23:30 +0200 | [diff] [blame] | 263 | rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL; |
| 264 | } |
| 265 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 266 | return rfilt; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 267 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 268 | #undef RX_FILTER_PRESERVE |
| 269 | } |
| 270 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 271 | int ath_startrecv(struct ath_softc *sc) |
| 272 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 273 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 274 | struct ath_buf *bf, *tbf; |
| 275 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 276 | spin_lock_bh(&sc->rx.rxbuflock); |
| 277 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 278 | goto start_recv; |
| 279 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 280 | sc->rx.rxlink = NULL; |
| 281 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 282 | ath_rx_buf_link(sc, bf); |
| 283 | } |
| 284 | |
| 285 | /* We could have deleted elements so the list may be empty now */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 286 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 287 | goto start_recv; |
| 288 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 289 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 290 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 291 | ath9k_hw_rxena(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 292 | |
| 293 | start_recv: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 294 | spin_unlock_bh(&sc->rx.rxbuflock); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 295 | ath_opmode_init(sc); |
| 296 | ath9k_hw_startpcureceive(ah); |
| 297 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 301 | bool ath_stoprecv(struct ath_softc *sc) |
| 302 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 303 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 304 | bool stopped; |
| 305 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 306 | ath9k_hw_stoppcurecv(ah); |
| 307 | ath9k_hw_setrxfilter(ah, 0); |
| 308 | stopped = ath9k_hw_stopdmarecv(ah); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 309 | sc->rx.rxlink = NULL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 310 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 311 | return stopped; |
| 312 | } |
| 313 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 314 | void ath_flushrecv(struct ath_softc *sc) |
| 315 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 316 | spin_lock_bh(&sc->rx.rxflushlock); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 317 | sc->sc_flags |= SC_OP_RXFLUSH; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 318 | ath_rx_tasklet(sc, 1); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 319 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 320 | spin_unlock_bh(&sc->rx.rxflushlock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 323 | static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) |
| 324 | { |
| 325 | /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */ |
| 326 | struct ieee80211_mgmt *mgmt; |
| 327 | u8 *pos, *end, id, elen; |
| 328 | struct ieee80211_tim_ie *tim; |
| 329 | |
| 330 | mgmt = (struct ieee80211_mgmt *)skb->data; |
| 331 | pos = mgmt->u.beacon.variable; |
| 332 | end = skb->data + skb->len; |
| 333 | |
| 334 | while (pos + 2 < end) { |
| 335 | id = *pos++; |
| 336 | elen = *pos++; |
| 337 | if (pos + elen > end) |
| 338 | break; |
| 339 | |
| 340 | if (id == WLAN_EID_TIM) { |
| 341 | if (elen < sizeof(*tim)) |
| 342 | break; |
| 343 | tim = (struct ieee80211_tim_ie *) pos; |
| 344 | if (tim->dtim_count != 0) |
| 345 | break; |
| 346 | return tim->bitmap_ctrl & 0x01; |
| 347 | } |
| 348 | |
| 349 | pos += elen; |
| 350 | } |
| 351 | |
| 352 | return false; |
| 353 | } |
| 354 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 355 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) |
| 356 | { |
| 357 | struct ieee80211_mgmt *mgmt; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 358 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 359 | |
| 360 | if (skb->len < 24 + 8 + 2 + 2) |
| 361 | return; |
| 362 | |
| 363 | mgmt = (struct ieee80211_mgmt *)skb->data; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 364 | if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 365 | return; /* not from our current AP */ |
| 366 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 367 | sc->ps_flags &= ~PS_WAIT_FOR_BEACON; |
Gabor Juhos | 293dc5d | 2009-06-19 12:17:48 +0200 | [diff] [blame] | 368 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 369 | if (sc->ps_flags & PS_BEACON_SYNC) { |
| 370 | sc->ps_flags &= ~PS_BEACON_SYNC; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 371 | ath_print(common, ATH_DBG_PS, |
| 372 | "Reconfigure Beacon timers based on " |
| 373 | "timestamp from the AP\n"); |
Jouni Malinen | ccdfeab | 2009-05-20 21:59:08 +0300 | [diff] [blame] | 374 | ath_beacon_config(sc, NULL); |
| 375 | } |
| 376 | |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 377 | if (ath_beacon_dtim_pending_cab(skb)) { |
| 378 | /* |
| 379 | * Remain awake waiting for buffered broadcast/multicast |
Gabor Juhos | 58f5fff | 2009-06-17 20:53:20 +0200 | [diff] [blame] | 380 | * frames. If the last broadcast/multicast frame is not |
| 381 | * received properly, the next beacon frame will work as |
| 382 | * a backup trigger for returning into NETWORK SLEEP state, |
| 383 | * so we are waiting for it as well. |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 384 | */ |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 385 | ath_print(common, ATH_DBG_PS, "Received DTIM beacon indicating " |
| 386 | "buffered broadcast/multicast frame(s)\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 387 | sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON; |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 388 | return; |
| 389 | } |
| 390 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 391 | if (sc->ps_flags & PS_WAIT_FOR_CAB) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 392 | /* |
| 393 | * This can happen if a broadcast frame is dropped or the AP |
| 394 | * fails to send a frame indicating that all CAB frames have |
| 395 | * been delivered. |
| 396 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 397 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 398 | ath_print(common, ATH_DBG_PS, |
| 399 | "PS wait for CAB frames timed out\n"); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 400 | } |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) |
| 404 | { |
| 405 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 406 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 407 | |
| 408 | hdr = (struct ieee80211_hdr *)skb->data; |
| 409 | |
| 410 | /* Process Beacon and CAB receive in PS state */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 411 | if ((sc->ps_flags & PS_WAIT_FOR_BEACON) && |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 412 | ieee80211_is_beacon(hdr->frame_control)) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 413 | ath_rx_ps_beacon(sc, skb); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 414 | else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 415 | (ieee80211_is_data(hdr->frame_control) || |
| 416 | ieee80211_is_action(hdr->frame_control)) && |
| 417 | is_multicast_ether_addr(hdr->addr1) && |
| 418 | !ieee80211_has_moredata(hdr->frame_control)) { |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 419 | /* |
| 420 | * No more broadcast/multicast frames to be received at this |
| 421 | * point. |
| 422 | */ |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 423 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 424 | ath_print(common, ATH_DBG_PS, |
| 425 | "All PS CAB frames received, back to sleep\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 426 | } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) && |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 427 | !is_multicast_ether_addr(hdr->addr1) && |
| 428 | !ieee80211_has_morefrags(hdr->frame_control)) { |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 429 | sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 430 | ath_print(common, ATH_DBG_PS, |
| 431 | "Going back to sleep after having received " |
| 432 | "PS-Poll data (0x%x)\n", |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 433 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 434 | PS_WAIT_FOR_CAB | |
| 435 | PS_WAIT_FOR_PSPOLL_DATA | |
| 436 | PS_WAIT_FOR_TX_ACK)); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 440 | static void ath_rx_send_to_mac80211(struct ieee80211_hw *hw, |
| 441 | struct ath_softc *sc, struct sk_buff *skb, |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 442 | struct ieee80211_rx_status *rxs) |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 443 | { |
| 444 | struct ieee80211_hdr *hdr; |
| 445 | |
| 446 | hdr = (struct ieee80211_hdr *)skb->data; |
| 447 | |
| 448 | /* Send the frame to mac80211 */ |
| 449 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 450 | int i; |
| 451 | /* |
| 452 | * Deliver broadcast/multicast frames to all suitable |
| 453 | * virtual wiphys. |
| 454 | */ |
| 455 | /* TODO: filter based on channel configuration */ |
| 456 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 457 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 458 | struct sk_buff *nskb; |
| 459 | if (aphy == NULL) |
| 460 | continue; |
| 461 | nskb = skb_copy(skb, GFP_ATOMIC); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 462 | if (!nskb) |
| 463 | continue; |
| 464 | ieee80211_rx(aphy->hw, nskb); |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 465 | } |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 466 | ieee80211_rx(sc->hw, skb); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 467 | } else |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 468 | /* Deliver unicast frames based on receiver address */ |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 469 | ieee80211_rx(hw, skb); |
Jouni Malinen | 9d64a3c | 2009-05-14 21:28:47 +0300 | [diff] [blame] | 470 | } |
| 471 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 472 | int ath_rx_tasklet(struct ath_softc *sc, int flush) |
| 473 | { |
| 474 | #define PA2DESC(_sc, _pa) \ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 475 | ((struct ath_desc *)((caddr_t)(_sc)->rx.rxdma.dd_desc + \ |
| 476 | ((_pa) - (_sc)->rx.rxdma.dd_desc_paddr))) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 477 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 478 | struct ath_buf *bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 479 | struct ath_desc *ds; |
Luis R. Rodriguez | 26ab264 | 2009-11-02 18:49:56 -0800 | [diff] [blame] | 480 | struct ath_rx_status *rx_stats; |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 481 | struct sk_buff *skb = NULL, *requeue_skb; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 482 | struct ieee80211_rx_status *rxs; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 483 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 27c51f1 | 2009-09-10 11:08:14 -0700 | [diff] [blame] | 484 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 485 | /* |
| 486 | * The hw can techncically differ from common->hw when using ath9k |
| 487 | * virtual wiphy so to account for that we iterate over the active |
| 488 | * wiphys and find the appropriate wiphy and therefore hw. |
| 489 | */ |
| 490 | struct ieee80211_hw *hw = NULL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 491 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | c9b1417 | 2009-11-04 16:47:22 -0800 | [diff] [blame] | 492 | int retval; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 493 | bool decrypt_error = false; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 494 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 495 | spin_lock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 496 | |
| 497 | do { |
| 498 | /* If handling rx interrupt and flush is in progress => exit */ |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 499 | if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 500 | break; |
| 501 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 502 | if (list_empty(&sc->rx.rxbuf)) { |
| 503 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 504 | break; |
| 505 | } |
| 506 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 507 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 508 | ds = bf->bf_desc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 509 | |
| 510 | /* |
| 511 | * Must provide the virtual address of the current |
| 512 | * descriptor, the physical address, and the virtual |
| 513 | * address of the next descriptor in the h/w chain. |
| 514 | * This allows the HAL to look ahead to see if the |
| 515 | * hardware is done with a descriptor by checking the |
| 516 | * done bit in the following descriptor and the address |
| 517 | * of the current descriptor the DMA engine is working |
| 518 | * on. All this is necessary because of our use of |
| 519 | * a self-linked list to avoid rx overruns. |
| 520 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 521 | retval = ath9k_hw_rxprocdesc(ah, ds, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 522 | bf->bf_daddr, |
| 523 | PA2DESC(sc, ds->ds_link), |
| 524 | 0); |
| 525 | if (retval == -EINPROGRESS) { |
| 526 | struct ath_buf *tbf; |
| 527 | struct ath_desc *tds; |
| 528 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 529 | if (list_is_last(&bf->list, &sc->rx.rxbuf)) { |
| 530 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 531 | break; |
| 532 | } |
| 533 | |
| 534 | tbf = list_entry(bf->list.next, struct ath_buf, list); |
| 535 | |
| 536 | /* |
| 537 | * On some hardware the descriptor status words could |
| 538 | * get corrupted, including the done bit. Because of |
| 539 | * this, check if the next descriptor's done bit is |
| 540 | * set or not. |
| 541 | * |
| 542 | * If the next descriptor's done bit is set, the current |
| 543 | * descriptor has been corrupted. Force s/w to discard |
| 544 | * this descriptor and continue... |
| 545 | */ |
| 546 | |
| 547 | tds = tbf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 548 | retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr, |
| 549 | PA2DESC(sc, tds->ds_link), 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 550 | if (retval == -EINPROGRESS) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 551 | break; |
| 552 | } |
| 553 | } |
| 554 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 555 | skb = bf->bf_mpdu; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 556 | if (!skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 557 | continue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 558 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 559 | /* |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 560 | * Synchronize the DMA transfer with CPU before |
| 561 | * 1. accessing the frame |
| 562 | * 2. requeueing the same buffer to h/w |
| 563 | */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 564 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 565 | common->rx_bufsize, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 566 | DMA_FROM_DEVICE); |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 567 | |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 568 | hdr = (struct ieee80211_hdr *) skb->data; |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 569 | rxs = IEEE80211_SKB_RXCB(skb); |
| 570 | |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 571 | hw = ath_get_virt_hw(sc, hdr); |
Luis R. Rodriguez | 26ab264 | 2009-11-02 18:49:56 -0800 | [diff] [blame] | 572 | rx_stats = &ds->ds_rxstat; |
Luis R. Rodriguez | b4afffc | 2009-11-02 11:36:08 -0800 | [diff] [blame] | 573 | |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame^] | 574 | ath_debug_stat_rx(sc, bf); |
| 575 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 576 | /* |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 577 | * If we're asked to flush receive queue, directly |
| 578 | * chain it back at the queue without processing it. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 579 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 580 | if (flush) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 581 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 582 | |
Luis R. Rodriguez | db86f07 | 2009-11-05 08:44:39 -0800 | [diff] [blame] | 583 | retval = ath9k_cmn_rx_skb_preprocess(common, hw, skb, rx_stats, |
| 584 | rxs, &decrypt_error); |
Luis R. Rodriguez | 1e875e9 | 2009-11-04 16:34:33 -0800 | [diff] [blame] | 585 | if (retval) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 586 | goto requeue; |
| 587 | |
| 588 | /* Ensure we always have an skb to requeue once we are done |
| 589 | * processing the current buffer's skb */ |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 590 | requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 591 | |
| 592 | /* If there is no memory we ignore the current RX'd frame, |
| 593 | * tell hardware it can give us a new frame using the old |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 594 | * 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] | 595 | * processing. */ |
| 596 | if (!requeue_skb) |
| 597 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 598 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 599 | /* Unmap the frame */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 600 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 601 | common->rx_bufsize, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 602 | DMA_FROM_DEVICE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 603 | |
Luis R. Rodriguez | 26ab264 | 2009-11-02 18:49:56 -0800 | [diff] [blame] | 604 | skb_put(skb, rx_stats->rs_datalen); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 605 | |
Luis R. Rodriguez | db86f07 | 2009-11-05 08:44:39 -0800 | [diff] [blame] | 606 | ath9k_cmn_rx_skb_postprocess(common, skb, rx_stats, |
| 607 | rxs, decrypt_error); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 608 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 609 | /* We will now give hardware our shiny new allocated skb */ |
| 610 | bf->bf_mpdu = requeue_skb; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 611 | bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data, |
Luis R. Rodriguez | cc861f7 | 2009-11-04 09:11:34 -0800 | [diff] [blame] | 612 | common->rx_bufsize, |
| 613 | DMA_FROM_DEVICE); |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 614 | if (unlikely(dma_mapping_error(sc->dev, |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 615 | bf->bf_buf_addr))) { |
| 616 | dev_kfree_skb_any(requeue_skb); |
| 617 | bf->bf_mpdu = NULL; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 618 | ath_print(common, ATH_DBG_FATAL, |
| 619 | "dma_mapping_error() on RX\n"); |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 620 | ath_rx_send_to_mac80211(hw, sc, skb, rxs); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 621 | break; |
| 622 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 623 | bf->bf_dmacontext = bf->bf_buf_addr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 624 | |
| 625 | /* |
| 626 | * change the default rx antenna if rx diversity chooses the |
| 627 | * other antenna 3 times in a row. |
| 628 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 629 | if (sc->rx.defant != ds->ds_rxstat.rs_antenna) { |
| 630 | if (++sc->rx.rxotherant >= 3) |
Luis R. Rodriguez | 26ab264 | 2009-11-02 18:49:56 -0800 | [diff] [blame] | 631 | ath_setdefantenna(sc, rx_stats->rs_antenna); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 632 | } else { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 633 | sc->rx.rxotherant = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 634 | } |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 635 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 636 | if (unlikely(sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 637 | PS_WAIT_FOR_CAB | |
| 638 | PS_WAIT_FOR_PSPOLL_DATA))) |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 639 | ath_rx_ps(sc, skb); |
| 640 | |
Luis R. Rodriguez | 5ca4262 | 2009-11-04 08:20:42 -0800 | [diff] [blame] | 641 | ath_rx_send_to_mac80211(hw, sc, skb, rxs); |
Jouni Malinen | cc65965 | 2009-05-14 21:28:48 +0300 | [diff] [blame] | 642 | |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 643 | requeue: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 644 | list_move_tail(&bf->list, &sc->rx.rxbuf); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 645 | ath_rx_buf_link(sc, bf); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 646 | } while (1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 647 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 648 | spin_unlock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 649 | |
| 650 | return 0; |
| 651 | #undef PA2DESC |
| 652 | } |