Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Atheros Communications Inc. |
| 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 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 17 | #include "core.h" |
| 18 | |
| 19 | /* |
| 20 | * Setup and link descriptors. |
| 21 | * |
| 22 | * 11N: we can no longer afford to self link the last descriptor. |
| 23 | * MAC acknowledges BA status as long as it copies frames to host |
| 24 | * buffer (or rx fifo). This can incorrectly acknowledge packets |
| 25 | * to a sender if last desc is self-linked. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 26 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 27 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) |
| 28 | { |
| 29 | struct ath_hal *ah = sc->sc_ah; |
| 30 | struct ath_desc *ds; |
| 31 | struct sk_buff *skb; |
| 32 | |
| 33 | ATH_RXBUF_RESET(bf); |
| 34 | |
| 35 | ds = bf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 36 | ds->ds_link = 0; /* link to null */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 37 | ds->ds_data = bf->bf_buf_addr; |
| 38 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 39 | /* virtual addr of the beginning of the buffer. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 40 | skb = bf->bf_mpdu; |
| 41 | ASSERT(skb != NULL); |
| 42 | ds->ds_vdata = skb->data; |
| 43 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 44 | /* setup rx descriptors. The rx.bufsize here tells the harware |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 45 | * how much data it can DMA to us and that we are prepared |
| 46 | * to process */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 47 | ath9k_hw_setuprxdesc(ah, ds, |
| 48 | sc->rx.bufsize, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 49 | 0); |
| 50 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 51 | if (sc->rx.rxlink == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 52 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
| 53 | else |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 54 | *sc->rx.rxlink = bf->bf_daddr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 55 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 56 | sc->rx.rxlink = &ds->ds_link; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 57 | ath9k_hw_rxena(ah); |
| 58 | } |
| 59 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 60 | static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) |
| 61 | { |
| 62 | /* XXX block beacon interrupts */ |
| 63 | ath9k_hw_setantenna(sc->sc_ah, antenna); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 64 | sc->rx.defant = antenna; |
| 65 | sc->rx.rxotherant = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Extend 15-bit time stamp from rx descriptor to |
| 70 | * a full 64-bit TSF using the current h/w TSF. |
| 71 | */ |
| 72 | static u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp) |
| 73 | { |
| 74 | u64 tsf; |
| 75 | |
| 76 | tsf = ath9k_hw_gettsf64(sc->sc_ah); |
| 77 | if ((tsf & 0x7fff) < rstamp) |
| 78 | tsf -= 0x8000; |
| 79 | return (tsf & ~0x7fff) | rstamp; |
| 80 | } |
| 81 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 82 | static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc, u32 len) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 83 | { |
| 84 | struct sk_buff *skb; |
| 85 | u32 off; |
| 86 | |
| 87 | /* |
| 88 | * Cache-line-align. This is important (for the |
| 89 | * 5210 at least) as not doing so causes bogus data |
| 90 | * in rx'd frames. |
| 91 | */ |
| 92 | |
Luis R. Rodriguez | b4b6cda | 2008-11-20 17:15:13 -0800 | [diff] [blame] | 93 | /* Note: the kernel can allocate a value greater than |
| 94 | * what we ask it to give us. We really only need 4 KB as that |
| 95 | * is this hardware supports and in fact we need at least 3849 |
| 96 | * as that is the MAX AMSDU size this hardware supports. |
| 97 | * Unfortunately this means we may get 8 KB here from the |
| 98 | * kernel... and that is actually what is observed on some |
| 99 | * systems :( */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 100 | skb = dev_alloc_skb(len + sc->sc_cachelsz - 1); |
| 101 | if (skb != NULL) { |
| 102 | off = ((unsigned long) skb->data) % sc->sc_cachelsz; |
| 103 | if (off != 0) |
| 104 | skb_reserve(skb, sc->sc_cachelsz - off); |
| 105 | } else { |
| 106 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 107 | "skbuff alloc of size %u failed\n", len); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | return skb; |
| 112 | } |
| 113 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 114 | /* |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 115 | * For Decrypt or Demic errors, we only mark packet status here and always push |
| 116 | * up the frame up to let mac80211 handle the actual error case, be it no |
| 117 | * decryption key or real decryption error. This let us keep statistics there. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 118 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 119 | static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds, |
| 120 | struct ieee80211_rx_status *rx_status, bool *decrypt_error, |
| 121 | struct ath_softc *sc) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 122 | { |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 123 | struct ieee80211_hdr *hdr; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 124 | u8 ratecode; |
| 125 | __le16 fc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 126 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 127 | hdr = (struct ieee80211_hdr *)skb->data; |
| 128 | fc = hdr->frame_control; |
| 129 | memset(rx_status, 0, sizeof(struct ieee80211_rx_status)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 130 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 131 | if (ds->ds_rxstat.rs_more) { |
| 132 | /* |
| 133 | * Frame spans multiple descriptors; this cannot happen yet |
| 134 | * as we don't support jumbograms. If not in monitor mode, |
| 135 | * discard the frame. Enable this if you want to see |
| 136 | * error frames in Monitor mode. |
| 137 | */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 138 | if (sc->sc_ah->ah_opmode != NL80211_IFTYPE_MONITOR) |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 139 | goto rx_next; |
| 140 | } else if (ds->ds_rxstat.rs_status != 0) { |
| 141 | if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC) |
| 142 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 143 | if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) |
| 144 | goto rx_next; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 145 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 146 | if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) { |
| 147 | *decrypt_error = true; |
| 148 | } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) { |
| 149 | if (ieee80211_is_ctl(fc)) |
| 150 | /* |
| 151 | * Sometimes, we get invalid |
| 152 | * MIC failures on valid control frames. |
| 153 | * Remove these mic errors. |
| 154 | */ |
| 155 | ds->ds_rxstat.rs_status &= ~ATH9K_RXERR_MIC; |
| 156 | else |
| 157 | rx_status->flag |= RX_FLAG_MMIC_ERROR; |
| 158 | } |
| 159 | /* |
| 160 | * Reject error frames with the exception of |
| 161 | * decryption and MIC failures. For monitor mode, |
| 162 | * we also ignore the CRC error. |
| 163 | */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 164 | if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_MONITOR) { |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 165 | if (ds->ds_rxstat.rs_status & |
| 166 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | |
| 167 | ATH9K_RXERR_CRC)) |
| 168 | goto rx_next; |
| 169 | } else { |
| 170 | if (ds->ds_rxstat.rs_status & |
| 171 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) { |
| 172 | goto rx_next; |
| 173 | } |
| 174 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 177 | ratecode = ds->ds_rxstat.rs_rate; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 178 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 179 | if (ratecode & 0x80) { |
Jouni Malinen | baad1d9 | 2008-12-12 14:38:34 +0200 | [diff] [blame] | 180 | /* HT rate */ |
| 181 | rx_status->flag |= RX_FLAG_HT; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 182 | if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) |
Jouni Malinen | baad1d9 | 2008-12-12 14:38:34 +0200 | [diff] [blame] | 183 | rx_status->flag |= RX_FLAG_40MHZ; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 184 | if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI) |
Jouni Malinen | baad1d9 | 2008-12-12 14:38:34 +0200 | [diff] [blame] | 185 | rx_status->flag |= RX_FLAG_SHORT_GI; |
| 186 | rx_status->rate_idx = ratecode & 0x7f; |
| 187 | } else { |
| 188 | int i = 0, cur_band, n_rates; |
| 189 | struct ieee80211_hw *hw = sc->hw; |
| 190 | |
| 191 | cur_band = hw->conf.channel->band; |
| 192 | n_rates = sc->sbands[cur_band].n_bitrates; |
| 193 | |
| 194 | for (i = 0; i < n_rates; i++) { |
| 195 | if (sc->sbands[cur_band].bitrates[i].hw_value == |
| 196 | ratecode) { |
| 197 | rx_status->rate_idx = i; |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | if (sc->sbands[cur_band].bitrates[i].hw_value_short == |
| 202 | ratecode) { |
| 203 | rx_status->rate_idx = i; |
| 204 | rx_status->flag |= RX_FLAG_SHORTPRE; |
| 205 | break; |
| 206 | } |
| 207 | } |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | rx_status->mactime = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp); |
| 211 | rx_status->band = sc->hw->conf.channel->band; |
| 212 | rx_status->freq = sc->hw->conf.channel->center_freq; |
| 213 | rx_status->noise = sc->sc_ani.sc_noise_floor; |
| 214 | rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 215 | rx_status->antenna = ds->ds_rxstat.rs_antenna; |
| 216 | |
| 217 | /* at 45 you will be able to use MCS 15 reliably. A more elaborate |
| 218 | * scheme can be used here but it requires tables of SNR/throughput for |
| 219 | * each possible mode used. */ |
| 220 | rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 45; |
| 221 | |
| 222 | /* rssi can be more than 45 though, anything above that |
| 223 | * should be considered at 100% */ |
| 224 | if (rx_status->qual > 100) |
| 225 | rx_status->qual = 100; |
| 226 | |
| 227 | rx_status->flag |= RX_FLAG_TSFT; |
| 228 | |
| 229 | return 1; |
| 230 | rx_next: |
| 231 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static void ath_opmode_init(struct ath_softc *sc) |
| 235 | { |
| 236 | struct ath_hal *ah = sc->sc_ah; |
| 237 | u32 rfilt, mfilt[2]; |
| 238 | |
| 239 | /* configure rx filter */ |
| 240 | rfilt = ath_calcrxfilter(sc); |
| 241 | ath9k_hw_setrxfilter(ah, rfilt); |
| 242 | |
| 243 | /* configure bssid mask */ |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 244 | if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 245 | ath9k_hw_setbssidmask(ah, sc->sc_bssidmask); |
| 246 | |
| 247 | /* configure operational mode */ |
| 248 | ath9k_hw_setopmode(ah); |
| 249 | |
| 250 | /* Handle any link-level address change. */ |
| 251 | ath9k_hw_setmac(ah, sc->sc_myaddr); |
| 252 | |
| 253 | /* calculate and install multicast filter */ |
| 254 | mfilt[0] = mfilt[1] = ~0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 255 | ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
| 259 | { |
| 260 | struct sk_buff *skb; |
| 261 | struct ath_buf *bf; |
| 262 | int error = 0; |
| 263 | |
| 264 | do { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 265 | spin_lock_init(&sc->rx.rxflushlock); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 266 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 267 | spin_lock_init(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 268 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 269 | sc->rx.bufsize = roundup(IEEE80211_MAX_MPDU_LEN, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 270 | min(sc->sc_cachelsz, |
| 271 | (u16)64)); |
| 272 | |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 273 | DPRINTF(sc, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 274 | sc->sc_cachelsz, sc->rx.bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 275 | |
| 276 | /* Initialize rx descriptors */ |
| 277 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 278 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 279 | "rx", nbufs, 1); |
| 280 | if (error != 0) { |
| 281 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 282 | "failed to allocate rx descriptors: %d\n", error); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 283 | break; |
| 284 | } |
| 285 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 286 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
| 287 | skb = ath_rxbuf_alloc(sc, sc->rx.bufsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 288 | if (skb == NULL) { |
| 289 | error = -ENOMEM; |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | bf->bf_mpdu = skb; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 294 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 295 | sc->rx.bufsize, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 296 | DMA_FROM_DEVICE); |
| 297 | if (unlikely(dma_mapping_error(sc->dev, |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 298 | bf->bf_buf_addr))) { |
| 299 | dev_kfree_skb_any(skb); |
| 300 | bf->bf_mpdu = NULL; |
| 301 | DPRINTF(sc, ATH_DBG_CONFIG, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 302 | "dma_mapping_error() on RX init\n"); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 303 | error = -ENOMEM; |
| 304 | break; |
| 305 | } |
Sujith | 927e70e | 2008-08-14 13:26:34 +0530 | [diff] [blame] | 306 | bf->bf_dmacontext = bf->bf_buf_addr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 307 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 308 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 309 | |
| 310 | } while (0); |
| 311 | |
| 312 | if (error) |
| 313 | ath_rx_cleanup(sc); |
| 314 | |
| 315 | return error; |
| 316 | } |
| 317 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 318 | void ath_rx_cleanup(struct ath_softc *sc) |
| 319 | { |
| 320 | struct sk_buff *skb; |
| 321 | struct ath_buf *bf; |
| 322 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 323 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 324 | skb = bf->bf_mpdu; |
| 325 | if (skb) |
| 326 | dev_kfree_skb(skb); |
| 327 | } |
| 328 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 329 | if (sc->rx.rxdma.dd_desc_len != 0) |
| 330 | ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Calculate the receive filter according to the |
| 335 | * operating mode and state: |
| 336 | * |
| 337 | * o always accept unicast, broadcast, and multicast traffic |
| 338 | * o maintain current state of phy error reception (the hal |
| 339 | * may enable phy error frames for noise immunity work) |
| 340 | * o probe request frames are accepted only when operating in |
| 341 | * hostap, adhoc, or monitor modes |
| 342 | * o enable promiscuous mode according to the interface state |
| 343 | * o accept beacons: |
| 344 | * - when operating in adhoc mode so the 802.11 layer creates |
| 345 | * node table entries for peers, |
| 346 | * - when operating in station mode for collecting rssi data when |
| 347 | * the station is otherwise quiet, or |
| 348 | * - when operating as a repeater so we see repeater-sta beacons |
| 349 | * - when scanning |
| 350 | */ |
| 351 | |
| 352 | u32 ath_calcrxfilter(struct ath_softc *sc) |
| 353 | { |
| 354 | #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR) |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 355 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 356 | u32 rfilt; |
| 357 | |
| 358 | rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE) |
| 359 | | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST |
| 360 | | ATH9K_RX_FILTER_MCAST; |
| 361 | |
| 362 | /* If not a STA, enable processing of Probe Requests */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 363 | if (sc->sc_ah->ah_opmode != NL80211_IFTYPE_STATION) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 364 | rfilt |= ATH9K_RX_FILTER_PROBEREQ; |
| 365 | |
| 366 | /* Can't set HOSTAP into promiscous mode */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 367 | if (((sc->sc_ah->ah_opmode != NL80211_IFTYPE_AP) && |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 368 | (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) || |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 369 | (sc->sc_ah->ah_opmode == NL80211_IFTYPE_MONITOR)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 370 | rfilt |= ATH9K_RX_FILTER_PROM; |
| 371 | /* ??? To prevent from sending ACK */ |
| 372 | rfilt &= ~ATH9K_RX_FILTER_UCAST; |
| 373 | } |
| 374 | |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 375 | if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_STATION || |
| 376 | sc->sc_ah->ah_opmode == NL80211_IFTYPE_ADHOC) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 377 | rfilt |= ATH9K_RX_FILTER_BEACON; |
| 378 | |
| 379 | /* If in HOSTAP mode, want to enable reception of PSPOLL frames |
| 380 | & beacon frames */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 381 | if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_AP) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 382 | rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 383 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 384 | return rfilt; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 385 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 386 | #undef RX_FILTER_PRESERVE |
| 387 | } |
| 388 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 389 | int ath_startrecv(struct ath_softc *sc) |
| 390 | { |
| 391 | struct ath_hal *ah = sc->sc_ah; |
| 392 | struct ath_buf *bf, *tbf; |
| 393 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 394 | spin_lock_bh(&sc->rx.rxbuflock); |
| 395 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 396 | goto start_recv; |
| 397 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 398 | sc->rx.rxlink = NULL; |
| 399 | list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 400 | ath_rx_buf_link(sc, bf); |
| 401 | } |
| 402 | |
| 403 | /* We could have deleted elements so the list may be empty now */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 404 | if (list_empty(&sc->rx.rxbuf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 405 | goto start_recv; |
| 406 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 407 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 408 | ath9k_hw_putrxbuf(ah, bf->bf_daddr); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 409 | ath9k_hw_rxena(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 410 | |
| 411 | start_recv: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 412 | spin_unlock_bh(&sc->rx.rxbuflock); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 413 | ath_opmode_init(sc); |
| 414 | ath9k_hw_startpcureceive(ah); |
| 415 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 419 | bool ath_stoprecv(struct ath_softc *sc) |
| 420 | { |
| 421 | struct ath_hal *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 422 | bool stopped; |
| 423 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 424 | ath9k_hw_stoppcurecv(ah); |
| 425 | ath9k_hw_setrxfilter(ah, 0); |
| 426 | stopped = ath9k_hw_stopdmarecv(ah); |
| 427 | mdelay(3); /* 3ms is long enough for 1 frame */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 428 | sc->rx.rxlink = NULL; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 429 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 430 | return stopped; |
| 431 | } |
| 432 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 433 | void ath_flushrecv(struct ath_softc *sc) |
| 434 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 435 | spin_lock_bh(&sc->rx.rxflushlock); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 436 | sc->sc_flags |= SC_OP_RXFLUSH; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 437 | ath_rx_tasklet(sc, 1); |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 438 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 439 | spin_unlock_bh(&sc->rx.rxflushlock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 442 | int ath_rx_tasklet(struct ath_softc *sc, int flush) |
| 443 | { |
| 444 | #define PA2DESC(_sc, _pa) \ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 445 | ((struct ath_desc *)((caddr_t)(_sc)->rx.rxdma.dd_desc + \ |
| 446 | ((_pa) - (_sc)->rx.rxdma.dd_desc_paddr))) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 447 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 448 | struct ath_buf *bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 449 | struct ath_desc *ds; |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 450 | struct sk_buff *skb = NULL, *requeue_skb; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 451 | struct ieee80211_rx_status rx_status; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 452 | struct ath_hal *ah = sc->sc_ah; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 453 | struct ieee80211_hdr *hdr; |
| 454 | int hdrlen, padsize, retval; |
| 455 | bool decrypt_error = false; |
| 456 | u8 keyix; |
| 457 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 458 | spin_lock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 459 | |
| 460 | do { |
| 461 | /* If handling rx interrupt and flush is in progress => exit */ |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 462 | if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 463 | break; |
| 464 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 465 | if (list_empty(&sc->rx.rxbuf)) { |
| 466 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 470 | bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 471 | ds = bf->bf_desc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * Must provide the virtual address of the current |
| 475 | * descriptor, the physical address, and the virtual |
| 476 | * address of the next descriptor in the h/w chain. |
| 477 | * This allows the HAL to look ahead to see if the |
| 478 | * hardware is done with a descriptor by checking the |
| 479 | * done bit in the following descriptor and the address |
| 480 | * of the current descriptor the DMA engine is working |
| 481 | * on. All this is necessary because of our use of |
| 482 | * a self-linked list to avoid rx overruns. |
| 483 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 484 | retval = ath9k_hw_rxprocdesc(ah, ds, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 485 | bf->bf_daddr, |
| 486 | PA2DESC(sc, ds->ds_link), |
| 487 | 0); |
| 488 | if (retval == -EINPROGRESS) { |
| 489 | struct ath_buf *tbf; |
| 490 | struct ath_desc *tds; |
| 491 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 492 | if (list_is_last(&bf->list, &sc->rx.rxbuf)) { |
| 493 | sc->rx.rxlink = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 494 | break; |
| 495 | } |
| 496 | |
| 497 | tbf = list_entry(bf->list.next, struct ath_buf, list); |
| 498 | |
| 499 | /* |
| 500 | * On some hardware the descriptor status words could |
| 501 | * get corrupted, including the done bit. Because of |
| 502 | * this, check if the next descriptor's done bit is |
| 503 | * set or not. |
| 504 | * |
| 505 | * If the next descriptor's done bit is set, the current |
| 506 | * descriptor has been corrupted. Force s/w to discard |
| 507 | * this descriptor and continue... |
| 508 | */ |
| 509 | |
| 510 | tds = tbf->bf_desc; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 511 | retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr, |
| 512 | PA2DESC(sc, tds->ds_link), 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 513 | if (retval == -EINPROGRESS) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 514 | break; |
| 515 | } |
| 516 | } |
| 517 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 518 | skb = bf->bf_mpdu; |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 519 | if (!skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 520 | continue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 521 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 522 | /* |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 523 | * Synchronize the DMA transfer with CPU before |
| 524 | * 1. accessing the frame |
| 525 | * 2. requeueing the same buffer to h/w |
| 526 | */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 527 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 528 | sc->rx.bufsize, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 529 | DMA_FROM_DEVICE); |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 530 | |
| 531 | /* |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 532 | * If we're asked to flush receive queue, directly |
| 533 | * chain it back at the queue without processing it. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 534 | */ |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 535 | if (flush) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 536 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 537 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 538 | if (!ds->ds_rxstat.rs_datalen) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 539 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 540 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 541 | /* The status portion of the descriptor could get corrupted. */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 542 | if (sc->rx.bufsize < ds->ds_rxstat.rs_datalen) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 543 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 544 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 545 | if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc)) |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 546 | goto requeue; |
| 547 | |
| 548 | /* Ensure we always have an skb to requeue once we are done |
| 549 | * processing the current buffer's skb */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 550 | requeue_skb = ath_rxbuf_alloc(sc, sc->rx.bufsize); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 551 | |
| 552 | /* If there is no memory we ignore the current RX'd frame, |
| 553 | * tell hardware it can give us a new frame using the old |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 554 | * 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] | 555 | * processing. */ |
| 556 | if (!requeue_skb) |
| 557 | goto requeue; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 558 | |
Vasanthakumar Thiagarajan | 9bf9fca | 2008-12-15 20:40:46 +0530 | [diff] [blame] | 559 | /* Unmap the frame */ |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 560 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 561 | sc->rx.bufsize, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 562 | DMA_FROM_DEVICE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 563 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 564 | skb_put(skb, ds->ds_rxstat.rs_datalen); |
| 565 | skb->protocol = cpu_to_be16(ETH_P_CONTROL); |
| 566 | |
| 567 | /* see if any padding is done by the hw and remove it */ |
| 568 | hdr = (struct ieee80211_hdr *)skb->data; |
| 569 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 570 | |
Jouni Malinen | 9c5f89b | 2008-12-11 18:22:13 +0200 | [diff] [blame] | 571 | /* The MAC header is padded to have 32-bit boundary if the |
| 572 | * packet payload is non-zero. The general calculation for |
| 573 | * padsize would take into account odd header lengths: |
| 574 | * padsize = (4 - hdrlen % 4) % 4; However, since only |
| 575 | * even-length headers are used, padding can only be 0 or 2 |
| 576 | * bytes and we can optimize this a bit. In addition, we must |
| 577 | * not try to remove padding from short control frames that do |
| 578 | * not have payload. */ |
| 579 | padsize = hdrlen & 3; |
| 580 | if (padsize && hdrlen >= 24) { |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 581 | memmove(skb->data + padsize, skb->data, hdrlen); |
| 582 | skb_pull(skb, padsize); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 585 | keyix = ds->ds_rxstat.rs_keyix; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 586 | |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 587 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) { |
| 588 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 589 | } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED) |
| 590 | && !decrypt_error && skb->len >= hdrlen + 4) { |
| 591 | keyix = skb->data[hdrlen + 3] >> 6; |
| 592 | |
| 593 | if (test_bit(keyix, sc->sc_keymap)) |
| 594 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 595 | } |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 596 | if (ah->sw_mgmt_crypto && |
| 597 | (rx_status.flag & RX_FLAG_DECRYPTED) && |
| 598 | ieee80211_is_mgmt(hdr->frame_control)) { |
| 599 | /* Use software decrypt for management frames. */ |
| 600 | rx_status.flag &= ~RX_FLAG_DECRYPTED; |
| 601 | } |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 602 | |
| 603 | /* Send the frame to mac80211 */ |
| 604 | __ieee80211_rx(sc->hw, skb, &rx_status); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 605 | |
| 606 | /* We will now give hardware our shiny new allocated skb */ |
| 607 | bf->bf_mpdu = requeue_skb; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 608 | bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data, |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 609 | sc->rx.bufsize, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 610 | DMA_FROM_DEVICE); |
| 611 | if (unlikely(dma_mapping_error(sc->dev, |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 612 | bf->bf_buf_addr))) { |
| 613 | dev_kfree_skb_any(requeue_skb); |
| 614 | bf->bf_mpdu = NULL; |
| 615 | DPRINTF(sc, ATH_DBG_CONFIG, |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 616 | "dma_mapping_error() on RX\n"); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 617 | break; |
| 618 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 619 | bf->bf_dmacontext = bf->bf_buf_addr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 620 | |
| 621 | /* |
| 622 | * change the default rx antenna if rx diversity chooses the |
| 623 | * other antenna 3 times in a row. |
| 624 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 625 | if (sc->rx.defant != ds->ds_rxstat.rs_antenna) { |
| 626 | if (++sc->rx.rxotherant >= 3) |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 627 | ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 628 | } else { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 629 | sc->rx.rxotherant = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 630 | } |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame^] | 631 | |
| 632 | if (ieee80211_is_beacon(hdr->frame_control) && |
| 633 | (sc->sc_flags & SC_OP_WAIT_FOR_BEACON)) { |
| 634 | sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON; |
| 635 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP); |
| 636 | } |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 637 | requeue: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 638 | list_move_tail(&bf->list, &sc->rx.rxbuf); |
Luis R. Rodriguez | cb71d9b | 2008-11-21 17:41:33 -0800 | [diff] [blame] | 639 | ath_rx_buf_link(sc, bf); |
Sujith | be0418a | 2008-11-18 09:05:55 +0530 | [diff] [blame] | 640 | } while (1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 641 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 642 | spin_unlock_bh(&sc->rx.rxbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 643 | |
| 644 | return 0; |
| 645 | #undef PA2DESC |
| 646 | } |