diff options
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/recv.c')
-rw-r--r-- | drivers/net/wireless/ath/ath9k/recv.c | 404 |
1 files changed, 104 insertions, 300 deletions
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c index ec0abf823995..1ca42e5148c8 100644 --- a/drivers/net/wireless/ath/ath9k/recv.c +++ b/drivers/net/wireless/ath/ath9k/recv.c | |||
@@ -48,6 +48,7 @@ static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc, | |||
48 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) | 48 | static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) |
49 | { | 49 | { |
50 | struct ath_hw *ah = sc->sc_ah; | 50 | struct ath_hw *ah = sc->sc_ah; |
51 | struct ath_common *common = ath9k_hw_common(ah); | ||
51 | struct ath_desc *ds; | 52 | struct ath_desc *ds; |
52 | struct sk_buff *skb; | 53 | struct sk_buff *skb; |
53 | 54 | ||
@@ -59,14 +60,16 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) | |||
59 | 60 | ||
60 | /* virtual addr of the beginning of the buffer. */ | 61 | /* virtual addr of the beginning of the buffer. */ |
61 | skb = bf->bf_mpdu; | 62 | skb = bf->bf_mpdu; |
62 | ASSERT(skb != NULL); | 63 | BUG_ON(skb == NULL); |
63 | ds->ds_vdata = skb->data; | 64 | ds->ds_vdata = skb->data; |
64 | 65 | ||
65 | /* setup rx descriptors. The rx.bufsize here tells the harware | 66 | /* |
67 | * setup rx descriptors. The rx_bufsize here tells the hardware | ||
66 | * how much data it can DMA to us and that we are prepared | 68 | * how much data it can DMA to us and that we are prepared |
67 | * to process */ | 69 | * to process |
70 | */ | ||
68 | ath9k_hw_setuprxdesc(ah, ds, | 71 | ath9k_hw_setuprxdesc(ah, ds, |
69 | sc->rx.bufsize, | 72 | common->rx_bufsize, |
70 | 0); | 73 | 0); |
71 | 74 | ||
72 | if (sc->rx.rxlink == NULL) | 75 | if (sc->rx.rxlink == NULL) |
@@ -86,192 +89,11 @@ static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) | |||
86 | sc->rx.rxotherant = 0; | 89 | sc->rx.rxotherant = 0; |
87 | } | 90 | } |
88 | 91 | ||
89 | /* | ||
90 | * Extend 15-bit time stamp from rx descriptor to | ||
91 | * a full 64-bit TSF using the current h/w TSF. | ||
92 | */ | ||
93 | static u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp) | ||
94 | { | ||
95 | u64 tsf; | ||
96 | |||
97 | tsf = ath9k_hw_gettsf64(sc->sc_ah); | ||
98 | if ((tsf & 0x7fff) < rstamp) | ||
99 | tsf -= 0x8000; | ||
100 | return (tsf & ~0x7fff) | rstamp; | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * For Decrypt or Demic errors, we only mark packet status here and always push | ||
105 | * up the frame up to let mac80211 handle the actual error case, be it no | ||
106 | * decryption key or real decryption error. This let us keep statistics there. | ||
107 | */ | ||
108 | static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds, | ||
109 | struct ieee80211_rx_status *rx_status, bool *decrypt_error, | ||
110 | struct ath_softc *sc) | ||
111 | { | ||
112 | struct ieee80211_hdr *hdr; | ||
113 | u8 ratecode; | ||
114 | __le16 fc; | ||
115 | struct ieee80211_hw *hw; | ||
116 | struct ieee80211_sta *sta; | ||
117 | struct ath_node *an; | ||
118 | int last_rssi = ATH_RSSI_DUMMY_MARKER; | ||
119 | |||
120 | |||
121 | hdr = (struct ieee80211_hdr *)skb->data; | ||
122 | fc = hdr->frame_control; | ||
123 | memset(rx_status, 0, sizeof(struct ieee80211_rx_status)); | ||
124 | hw = ath_get_virt_hw(sc, hdr); | ||
125 | |||
126 | if (ds->ds_rxstat.rs_more) { | ||
127 | /* | ||
128 | * Frame spans multiple descriptors; this cannot happen yet | ||
129 | * as we don't support jumbograms. If not in monitor mode, | ||
130 | * discard the frame. Enable this if you want to see | ||
131 | * error frames in Monitor mode. | ||
132 | */ | ||
133 | if (sc->sc_ah->opmode != NL80211_IFTYPE_MONITOR) | ||
134 | goto rx_next; | ||
135 | } else if (ds->ds_rxstat.rs_status != 0) { | ||
136 | if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC) | ||
137 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; | ||
138 | if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) | ||
139 | goto rx_next; | ||
140 | |||
141 | if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) { | ||
142 | *decrypt_error = true; | ||
143 | } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) { | ||
144 | if (ieee80211_is_ctl(fc)) | ||
145 | /* | ||
146 | * Sometimes, we get invalid | ||
147 | * MIC failures on valid control frames. | ||
148 | * Remove these mic errors. | ||
149 | */ | ||
150 | ds->ds_rxstat.rs_status &= ~ATH9K_RXERR_MIC; | ||
151 | else | ||
152 | rx_status->flag |= RX_FLAG_MMIC_ERROR; | ||
153 | } | ||
154 | /* | ||
155 | * Reject error frames with the exception of | ||
156 | * decryption and MIC failures. For monitor mode, | ||
157 | * we also ignore the CRC error. | ||
158 | */ | ||
159 | if (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR) { | ||
160 | if (ds->ds_rxstat.rs_status & | ||
161 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | | ||
162 | ATH9K_RXERR_CRC)) | ||
163 | goto rx_next; | ||
164 | } else { | ||
165 | if (ds->ds_rxstat.rs_status & | ||
166 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) { | ||
167 | goto rx_next; | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | |||
172 | ratecode = ds->ds_rxstat.rs_rate; | ||
173 | |||
174 | if (ratecode & 0x80) { | ||
175 | /* HT rate */ | ||
176 | rx_status->flag |= RX_FLAG_HT; | ||
177 | if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040) | ||
178 | rx_status->flag |= RX_FLAG_40MHZ; | ||
179 | if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI) | ||
180 | rx_status->flag |= RX_FLAG_SHORT_GI; | ||
181 | rx_status->rate_idx = ratecode & 0x7f; | ||
182 | } else { | ||
183 | int i = 0, cur_band, n_rates; | ||
184 | |||
185 | cur_band = hw->conf.channel->band; | ||
186 | n_rates = sc->sbands[cur_band].n_bitrates; | ||
187 | |||
188 | for (i = 0; i < n_rates; i++) { | ||
189 | if (sc->sbands[cur_band].bitrates[i].hw_value == | ||
190 | ratecode) { | ||
191 | rx_status->rate_idx = i; | ||
192 | break; | ||
193 | } | ||
194 | |||
195 | if (sc->sbands[cur_band].bitrates[i].hw_value_short == | ||
196 | ratecode) { | ||
197 | rx_status->rate_idx = i; | ||
198 | rx_status->flag |= RX_FLAG_SHORTPRE; | ||
199 | break; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | rcu_read_lock(); | ||
205 | sta = ieee80211_find_sta(sc->hw, hdr->addr2); | ||
206 | if (sta) { | ||
207 | an = (struct ath_node *) sta->drv_priv; | ||
208 | if (ds->ds_rxstat.rs_rssi != ATH9K_RSSI_BAD && | ||
209 | !ds->ds_rxstat.rs_moreaggr) | ||
210 | ATH_RSSI_LPF(an->last_rssi, ds->ds_rxstat.rs_rssi); | ||
211 | last_rssi = an->last_rssi; | ||
212 | } | ||
213 | rcu_read_unlock(); | ||
214 | |||
215 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) | ||
216 | ds->ds_rxstat.rs_rssi = ATH_EP_RND(last_rssi, | ||
217 | ATH_RSSI_EP_MULTIPLIER); | ||
218 | if (ds->ds_rxstat.rs_rssi < 0) | ||
219 | ds->ds_rxstat.rs_rssi = 0; | ||
220 | else if (ds->ds_rxstat.rs_rssi > 127) | ||
221 | ds->ds_rxstat.rs_rssi = 127; | ||
222 | |||
223 | /* Update Beacon RSSI, this is used by ANI. */ | ||
224 | if (ieee80211_is_beacon(fc)) | ||
225 | sc->sc_ah->stats.avgbrssi = ds->ds_rxstat.rs_rssi; | ||
226 | |||
227 | rx_status->mactime = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp); | ||
228 | rx_status->band = hw->conf.channel->band; | ||
229 | rx_status->freq = hw->conf.channel->center_freq; | ||
230 | rx_status->noise = sc->ani.noise_floor; | ||
231 | rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + ds->ds_rxstat.rs_rssi; | ||
232 | rx_status->antenna = ds->ds_rxstat.rs_antenna; | ||
233 | |||
234 | /* | ||
235 | * Theory for reporting quality: | ||
236 | * | ||
237 | * At a hardware RSSI of 45 you will be able to use MCS 7 reliably. | ||
238 | * At a hardware RSSI of 45 you will be able to use MCS 15 reliably. | ||
239 | * At a hardware RSSI of 35 you should be able use 54 Mbps reliably. | ||
240 | * | ||
241 | * MCS 7 is the highets MCS index usable by a 1-stream device. | ||
242 | * MCS 15 is the highest MCS index usable by a 2-stream device. | ||
243 | * | ||
244 | * All ath9k devices are either 1-stream or 2-stream. | ||
245 | * | ||
246 | * How many bars you see is derived from the qual reporting. | ||
247 | * | ||
248 | * A more elaborate scheme can be used here but it requires tables | ||
249 | * of SNR/throughput for each possible mode used. For the MCS table | ||
250 | * you can refer to the wireless wiki: | ||
251 | * | ||
252 | * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n | ||
253 | * | ||
254 | */ | ||
255 | if (conf_is_ht(&hw->conf)) | ||
256 | rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 45; | ||
257 | else | ||
258 | rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 35; | ||
259 | |||
260 | /* rssi can be more than 45 though, anything above that | ||
261 | * should be considered at 100% */ | ||
262 | if (rx_status->qual > 100) | ||
263 | rx_status->qual = 100; | ||
264 | |||
265 | rx_status->flag |= RX_FLAG_TSFT; | ||
266 | |||
267 | return 1; | ||
268 | rx_next: | ||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static void ath_opmode_init(struct ath_softc *sc) | 92 | static void ath_opmode_init(struct ath_softc *sc) |
273 | { | 93 | { |
274 | struct ath_hw *ah = sc->sc_ah; | 94 | struct ath_hw *ah = sc->sc_ah; |
95 | struct ath_common *common = ath9k_hw_common(ah); | ||
96 | |||
275 | u32 rfilt, mfilt[2]; | 97 | u32 rfilt, mfilt[2]; |
276 | 98 | ||
277 | /* configure rx filter */ | 99 | /* configure rx filter */ |
@@ -280,13 +102,13 @@ static void ath_opmode_init(struct ath_softc *sc) | |||
280 | 102 | ||
281 | /* configure bssid mask */ | 103 | /* configure bssid mask */ |
282 | if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) | 104 | if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) |
283 | ath9k_hw_setbssidmask(sc); | 105 | ath_hw_setbssidmask(common); |
284 | 106 | ||
285 | /* configure operational mode */ | 107 | /* configure operational mode */ |
286 | ath9k_hw_setopmode(ah); | 108 | ath9k_hw_setopmode(ah); |
287 | 109 | ||
288 | /* Handle any link-level address change. */ | 110 | /* Handle any link-level address change. */ |
289 | ath9k_hw_setmac(ah, sc->sc_ah->macaddr); | 111 | ath9k_hw_setmac(ah, common->macaddr); |
290 | 112 | ||
291 | /* calculate and install multicast filter */ | 113 | /* calculate and install multicast filter */ |
292 | mfilt[0] = mfilt[1] = ~0; | 114 | mfilt[0] = mfilt[1] = ~0; |
@@ -295,6 +117,7 @@ static void ath_opmode_init(struct ath_softc *sc) | |||
295 | 117 | ||
296 | int ath_rx_init(struct ath_softc *sc, int nbufs) | 118 | int ath_rx_init(struct ath_softc *sc, int nbufs) |
297 | { | 119 | { |
120 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | ||
298 | struct sk_buff *skb; | 121 | struct sk_buff *skb; |
299 | struct ath_buf *bf; | 122 | struct ath_buf *bf; |
300 | int error = 0; | 123 | int error = 0; |
@@ -303,24 +126,24 @@ int ath_rx_init(struct ath_softc *sc, int nbufs) | |||
303 | sc->sc_flags &= ~SC_OP_RXFLUSH; | 126 | sc->sc_flags &= ~SC_OP_RXFLUSH; |
304 | spin_lock_init(&sc->rx.rxbuflock); | 127 | spin_lock_init(&sc->rx.rxbuflock); |
305 | 128 | ||
306 | sc->rx.bufsize = roundup(IEEE80211_MAX_MPDU_LEN, | 129 | common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN, |
307 | min(sc->common.cachelsz, (u16)64)); | 130 | min(common->cachelsz, (u16)64)); |
308 | 131 | ||
309 | DPRINTF(sc, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", | 132 | ath_print(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", |
310 | sc->common.cachelsz, sc->rx.bufsize); | 133 | common->cachelsz, common->rx_bufsize); |
311 | 134 | ||
312 | /* Initialize rx descriptors */ | 135 | /* Initialize rx descriptors */ |
313 | 136 | ||
314 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, | 137 | error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, |
315 | "rx", nbufs, 1); | 138 | "rx", nbufs, 1); |
316 | if (error != 0) { | 139 | if (error != 0) { |
317 | DPRINTF(sc, ATH_DBG_FATAL, | 140 | ath_print(common, ATH_DBG_FATAL, |
318 | "failed to allocate rx descriptors: %d\n", error); | 141 | "failed to allocate rx descriptors: %d\n", error); |
319 | goto err; | 142 | goto err; |
320 | } | 143 | } |
321 | 144 | ||
322 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { | 145 | list_for_each_entry(bf, &sc->rx.rxbuf, list) { |
323 | skb = ath_rxbuf_alloc(&sc->common, sc->rx.bufsize, GFP_KERNEL); | 146 | skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL); |
324 | if (skb == NULL) { | 147 | if (skb == NULL) { |
325 | error = -ENOMEM; | 148 | error = -ENOMEM; |
326 | goto err; | 149 | goto err; |
@@ -328,14 +151,14 @@ int ath_rx_init(struct ath_softc *sc, int nbufs) | |||
328 | 151 | ||
329 | bf->bf_mpdu = skb; | 152 | bf->bf_mpdu = skb; |
330 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, | 153 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
331 | sc->rx.bufsize, | 154 | common->rx_bufsize, |
332 | DMA_FROM_DEVICE); | 155 | DMA_FROM_DEVICE); |
333 | if (unlikely(dma_mapping_error(sc->dev, | 156 | if (unlikely(dma_mapping_error(sc->dev, |
334 | bf->bf_buf_addr))) { | 157 | bf->bf_buf_addr))) { |
335 | dev_kfree_skb_any(skb); | 158 | dev_kfree_skb_any(skb); |
336 | bf->bf_mpdu = NULL; | 159 | bf->bf_mpdu = NULL; |
337 | DPRINTF(sc, ATH_DBG_FATAL, | 160 | ath_print(common, ATH_DBG_FATAL, |
338 | "dma_mapping_error() on RX init\n"); | 161 | "dma_mapping_error() on RX init\n"); |
339 | error = -ENOMEM; | 162 | error = -ENOMEM; |
340 | goto err; | 163 | goto err; |
341 | } | 164 | } |
@@ -352,6 +175,8 @@ err: | |||
352 | 175 | ||
353 | void ath_rx_cleanup(struct ath_softc *sc) | 176 | void ath_rx_cleanup(struct ath_softc *sc) |
354 | { | 177 | { |
178 | struct ath_hw *ah = sc->sc_ah; | ||
179 | struct ath_common *common = ath9k_hw_common(ah); | ||
355 | struct sk_buff *skb; | 180 | struct sk_buff *skb; |
356 | struct ath_buf *bf; | 181 | struct ath_buf *bf; |
357 | 182 | ||
@@ -359,7 +184,7 @@ void ath_rx_cleanup(struct ath_softc *sc) | |||
359 | skb = bf->bf_mpdu; | 184 | skb = bf->bf_mpdu; |
360 | if (skb) { | 185 | if (skb) { |
361 | dma_unmap_single(sc->dev, bf->bf_buf_addr, | 186 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
362 | sc->rx.bufsize, DMA_FROM_DEVICE); | 187 | common->rx_bufsize, DMA_FROM_DEVICE); |
363 | dev_kfree_skb(skb); | 188 | dev_kfree_skb(skb); |
364 | } | 189 | } |
365 | } | 190 | } |
@@ -420,7 +245,10 @@ u32 ath_calcrxfilter(struct ath_softc *sc) | |||
420 | else | 245 | else |
421 | rfilt |= ATH9K_RX_FILTER_BEACON; | 246 | rfilt |= ATH9K_RX_FILTER_BEACON; |
422 | 247 | ||
423 | if (sc->rx.rxfilter & FIF_PSPOLL) | 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)) | ||
424 | rfilt |= ATH9K_RX_FILTER_PSPOLL; | 252 | rfilt |= ATH9K_RX_FILTER_PSPOLL; |
425 | 253 | ||
426 | if (conf_is_ht(&sc->hw->conf)) | 254 | if (conf_is_ht(&sc->hw->conf)) |
@@ -527,20 +355,22 @@ static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) | |||
527 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) | 355 | static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) |
528 | { | 356 | { |
529 | struct ieee80211_mgmt *mgmt; | 357 | struct ieee80211_mgmt *mgmt; |
358 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | ||
530 | 359 | ||
531 | if (skb->len < 24 + 8 + 2 + 2) | 360 | if (skb->len < 24 + 8 + 2 + 2) |
532 | return; | 361 | return; |
533 | 362 | ||
534 | mgmt = (struct ieee80211_mgmt *)skb->data; | 363 | mgmt = (struct ieee80211_mgmt *)skb->data; |
535 | if (memcmp(sc->curbssid, mgmt->bssid, ETH_ALEN) != 0) | 364 | if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) |
536 | return; /* not from our current AP */ | 365 | return; /* not from our current AP */ |
537 | 366 | ||
538 | sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON; | 367 | sc->ps_flags &= ~PS_WAIT_FOR_BEACON; |
539 | 368 | ||
540 | if (sc->sc_flags & SC_OP_BEACON_SYNC) { | 369 | if (sc->ps_flags & PS_BEACON_SYNC) { |
541 | sc->sc_flags &= ~SC_OP_BEACON_SYNC; | 370 | sc->ps_flags &= ~PS_BEACON_SYNC; |
542 | DPRINTF(sc, ATH_DBG_PS, "Reconfigure Beacon timers based on " | 371 | ath_print(common, ATH_DBG_PS, |
543 | "timestamp from the AP\n"); | 372 | "Reconfigure Beacon timers based on " |
373 | "timestamp from the AP\n"); | ||
544 | ath_beacon_config(sc, NULL); | 374 | ath_beacon_config(sc, NULL); |
545 | } | 375 | } |
546 | 376 | ||
@@ -552,34 +382,36 @@ static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) | |||
552 | * a backup trigger for returning into NETWORK SLEEP state, | 382 | * a backup trigger for returning into NETWORK SLEEP state, |
553 | * so we are waiting for it as well. | 383 | * so we are waiting for it as well. |
554 | */ | 384 | */ |
555 | DPRINTF(sc, ATH_DBG_PS, "Received DTIM beacon indicating " | 385 | ath_print(common, ATH_DBG_PS, "Received DTIM beacon indicating " |
556 | "buffered broadcast/multicast frame(s)\n"); | 386 | "buffered broadcast/multicast frame(s)\n"); |
557 | sc->sc_flags |= SC_OP_WAIT_FOR_CAB | SC_OP_WAIT_FOR_BEACON; | 387 | sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON; |
558 | return; | 388 | return; |
559 | } | 389 | } |
560 | 390 | ||
561 | if (sc->sc_flags & SC_OP_WAIT_FOR_CAB) { | 391 | if (sc->ps_flags & PS_WAIT_FOR_CAB) { |
562 | /* | 392 | /* |
563 | * This can happen if a broadcast frame is dropped or the AP | 393 | * This can happen if a broadcast frame is dropped or the AP |
564 | * fails to send a frame indicating that all CAB frames have | 394 | * fails to send a frame indicating that all CAB frames have |
565 | * been delivered. | 395 | * been delivered. |
566 | */ | 396 | */ |
567 | sc->sc_flags &= ~SC_OP_WAIT_FOR_CAB; | 397 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
568 | DPRINTF(sc, ATH_DBG_PS, "PS wait for CAB frames timed out\n"); | 398 | ath_print(common, ATH_DBG_PS, |
399 | "PS wait for CAB frames timed out\n"); | ||
569 | } | 400 | } |
570 | } | 401 | } |
571 | 402 | ||
572 | static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) | 403 | static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) |
573 | { | 404 | { |
574 | struct ieee80211_hdr *hdr; | 405 | struct ieee80211_hdr *hdr; |
406 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | ||
575 | 407 | ||
576 | hdr = (struct ieee80211_hdr *)skb->data; | 408 | hdr = (struct ieee80211_hdr *)skb->data; |
577 | 409 | ||
578 | /* Process Beacon and CAB receive in PS state */ | 410 | /* Process Beacon and CAB receive in PS state */ |
579 | if ((sc->sc_flags & SC_OP_WAIT_FOR_BEACON) && | 411 | if ((sc->ps_flags & PS_WAIT_FOR_BEACON) && |
580 | ieee80211_is_beacon(hdr->frame_control)) | 412 | ieee80211_is_beacon(hdr->frame_control)) |
581 | ath_rx_ps_beacon(sc, skb); | 413 | ath_rx_ps_beacon(sc, skb); |
582 | else if ((sc->sc_flags & SC_OP_WAIT_FOR_CAB) && | 414 | else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && |
583 | (ieee80211_is_data(hdr->frame_control) || | 415 | (ieee80211_is_data(hdr->frame_control) || |
584 | ieee80211_is_action(hdr->frame_control)) && | 416 | ieee80211_is_action(hdr->frame_control)) && |
585 | is_multicast_ether_addr(hdr->addr1) && | 417 | is_multicast_ether_addr(hdr->addr1) && |
@@ -588,24 +420,26 @@ static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) | |||
588 | * No more broadcast/multicast frames to be received at this | 420 | * No more broadcast/multicast frames to be received at this |
589 | * point. | 421 | * point. |
590 | */ | 422 | */ |
591 | sc->sc_flags &= ~SC_OP_WAIT_FOR_CAB; | 423 | sc->ps_flags &= ~PS_WAIT_FOR_CAB; |
592 | DPRINTF(sc, ATH_DBG_PS, "All PS CAB frames received, back to " | 424 | ath_print(common, ATH_DBG_PS, |
593 | "sleep\n"); | 425 | "All PS CAB frames received, back to sleep\n"); |
594 | } else if ((sc->sc_flags & SC_OP_WAIT_FOR_PSPOLL_DATA) && | 426 | } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) && |
595 | !is_multicast_ether_addr(hdr->addr1) && | 427 | !is_multicast_ether_addr(hdr->addr1) && |
596 | !ieee80211_has_morefrags(hdr->frame_control)) { | 428 | !ieee80211_has_morefrags(hdr->frame_control)) { |
597 | sc->sc_flags &= ~SC_OP_WAIT_FOR_PSPOLL_DATA; | 429 | sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA; |
598 | DPRINTF(sc, ATH_DBG_PS, "Going back to sleep after having " | 430 | ath_print(common, ATH_DBG_PS, |
599 | "received PS-Poll data (0x%x)\n", | 431 | "Going back to sleep after having received " |
600 | sc->sc_flags & (SC_OP_WAIT_FOR_BEACON | | 432 | "PS-Poll data (0x%lx)\n", |
601 | SC_OP_WAIT_FOR_CAB | | 433 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
602 | SC_OP_WAIT_FOR_PSPOLL_DATA | | 434 | PS_WAIT_FOR_CAB | |
603 | SC_OP_WAIT_FOR_TX_ACK)); | 435 | PS_WAIT_FOR_PSPOLL_DATA | |
436 | PS_WAIT_FOR_TX_ACK)); | ||
604 | } | 437 | } |
605 | } | 438 | } |
606 | 439 | ||
607 | static void ath_rx_send_to_mac80211(struct ath_softc *sc, struct sk_buff *skb, | 440 | static void ath_rx_send_to_mac80211(struct ieee80211_hw *hw, |
608 | struct ieee80211_rx_status *rx_status) | 441 | struct ath_softc *sc, struct sk_buff *skb, |
442 | struct ieee80211_rx_status *rxs) | ||
609 | { | 443 | { |
610 | struct ieee80211_hdr *hdr; | 444 | struct ieee80211_hdr *hdr; |
611 | 445 | ||
@@ -625,19 +459,14 @@ static void ath_rx_send_to_mac80211(struct ath_softc *sc, struct sk_buff *skb, | |||
625 | if (aphy == NULL) | 459 | if (aphy == NULL) |
626 | continue; | 460 | continue; |
627 | nskb = skb_copy(skb, GFP_ATOMIC); | 461 | nskb = skb_copy(skb, GFP_ATOMIC); |
628 | if (nskb) { | 462 | if (!nskb) |
629 | memcpy(IEEE80211_SKB_RXCB(nskb), rx_status, | 463 | continue; |
630 | sizeof(*rx_status)); | 464 | ieee80211_rx(aphy->hw, nskb); |
631 | ieee80211_rx(aphy->hw, nskb); | ||
632 | } | ||
633 | } | 465 | } |
634 | memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status)); | ||
635 | ieee80211_rx(sc->hw, skb); | 466 | ieee80211_rx(sc->hw, skb); |
636 | } else { | 467 | } else |
637 | /* Deliver unicast frames based on receiver address */ | 468 | /* Deliver unicast frames based on receiver address */ |
638 | memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status)); | 469 | ieee80211_rx(hw, skb); |
639 | ieee80211_rx(ath_get_virt_hw(sc, hdr), skb); | ||
640 | } | ||
641 | } | 470 | } |
642 | 471 | ||
643 | int ath_rx_tasklet(struct ath_softc *sc, int flush) | 472 | int ath_rx_tasklet(struct ath_softc *sc, int flush) |
@@ -648,14 +477,20 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush) | |||
648 | 477 | ||
649 | struct ath_buf *bf; | 478 | struct ath_buf *bf; |
650 | struct ath_desc *ds; | 479 | struct ath_desc *ds; |
480 | struct ath_rx_status *rx_stats; | ||
651 | struct sk_buff *skb = NULL, *requeue_skb; | 481 | struct sk_buff *skb = NULL, *requeue_skb; |
652 | struct ieee80211_rx_status rx_status; | 482 | struct ieee80211_rx_status *rxs; |
653 | struct ath_hw *ah = sc->sc_ah; | 483 | struct ath_hw *ah = sc->sc_ah; |
484 | struct ath_common *common = ath9k_hw_common(ah); | ||
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; | ||
654 | struct ieee80211_hdr *hdr; | 491 | struct ieee80211_hdr *hdr; |
655 | int hdrlen, padsize, retval; | 492 | int retval; |
656 | bool decrypt_error = false; | 493 | bool decrypt_error = false; |
657 | u8 keyix; | ||
658 | __le16 fc; | ||
659 | 494 | ||
660 | spin_lock_bh(&sc->rx.rxbuflock); | 495 | spin_lock_bh(&sc->rx.rxbuflock); |
661 | 496 | ||
@@ -727,9 +562,17 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush) | |||
727 | * 2. requeueing the same buffer to h/w | 562 | * 2. requeueing the same buffer to h/w |
728 | */ | 563 | */ |
729 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, | 564 | dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr, |
730 | sc->rx.bufsize, | 565 | common->rx_bufsize, |
731 | DMA_FROM_DEVICE); | 566 | DMA_FROM_DEVICE); |
732 | 567 | ||
568 | hdr = (struct ieee80211_hdr *) skb->data; | ||
569 | rxs = IEEE80211_SKB_RXCB(skb); | ||
570 | |||
571 | hw = ath_get_virt_hw(sc, hdr); | ||
572 | rx_stats = &ds->ds_rxstat; | ||
573 | |||
574 | ath_debug_stat_rx(sc, bf); | ||
575 | |||
733 | /* | 576 | /* |
734 | * If we're asked to flush receive queue, directly | 577 | * If we're asked to flush receive queue, directly |
735 | * chain it back at the queue without processing it. | 578 | * chain it back at the queue without processing it. |
@@ -737,19 +580,14 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush) | |||
737 | if (flush) | 580 | if (flush) |
738 | goto requeue; | 581 | goto requeue; |
739 | 582 | ||
740 | if (!ds->ds_rxstat.rs_datalen) | 583 | retval = ath9k_cmn_rx_skb_preprocess(common, hw, skb, rx_stats, |
741 | goto requeue; | 584 | rxs, &decrypt_error); |
742 | 585 | if (retval) | |
743 | /* The status portion of the descriptor could get corrupted. */ | ||
744 | if (sc->rx.bufsize < ds->ds_rxstat.rs_datalen) | ||
745 | goto requeue; | ||
746 | |||
747 | if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc)) | ||
748 | goto requeue; | 586 | goto requeue; |
749 | 587 | ||
750 | /* Ensure we always have an skb to requeue once we are done | 588 | /* Ensure we always have an skb to requeue once we are done |
751 | * processing the current buffer's skb */ | 589 | * processing the current buffer's skb */ |
752 | requeue_skb = ath_rxbuf_alloc(&sc->common, sc->rx.bufsize, GFP_ATOMIC); | 590 | requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); |
753 | 591 | ||
754 | /* If there is no memory we ignore the current RX'd frame, | 592 | /* If there is no memory we ignore the current RX'd frame, |
755 | * tell hardware it can give us a new frame using the old | 593 | * tell hardware it can give us a new frame using the old |
@@ -760,60 +598,26 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush) | |||
760 | 598 | ||
761 | /* Unmap the frame */ | 599 | /* Unmap the frame */ |
762 | dma_unmap_single(sc->dev, bf->bf_buf_addr, | 600 | dma_unmap_single(sc->dev, bf->bf_buf_addr, |
763 | sc->rx.bufsize, | 601 | common->rx_bufsize, |
764 | DMA_FROM_DEVICE); | 602 | DMA_FROM_DEVICE); |
765 | 603 | ||
766 | skb_put(skb, ds->ds_rxstat.rs_datalen); | 604 | skb_put(skb, rx_stats->rs_datalen); |
767 | |||
768 | /* see if any padding is done by the hw and remove it */ | ||
769 | hdr = (struct ieee80211_hdr *)skb->data; | ||
770 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); | ||
771 | fc = hdr->frame_control; | ||
772 | |||
773 | /* The MAC header is padded to have 32-bit boundary if the | ||
774 | * packet payload is non-zero. The general calculation for | ||
775 | * padsize would take into account odd header lengths: | ||
776 | * padsize = (4 - hdrlen % 4) % 4; However, since only | ||
777 | * even-length headers are used, padding can only be 0 or 2 | ||
778 | * bytes and we can optimize this a bit. In addition, we must | ||
779 | * not try to remove padding from short control frames that do | ||
780 | * not have payload. */ | ||
781 | padsize = hdrlen & 3; | ||
782 | if (padsize && hdrlen >= 24) { | ||
783 | memmove(skb->data + padsize, skb->data, hdrlen); | ||
784 | skb_pull(skb, padsize); | ||
785 | } | ||
786 | |||
787 | keyix = ds->ds_rxstat.rs_keyix; | ||
788 | 605 | ||
789 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) { | 606 | ath9k_cmn_rx_skb_postprocess(common, skb, rx_stats, |
790 | rx_status.flag |= RX_FLAG_DECRYPTED; | 607 | rxs, decrypt_error); |
791 | } else if (ieee80211_has_protected(fc) | ||
792 | && !decrypt_error && skb->len >= hdrlen + 4) { | ||
793 | keyix = skb->data[hdrlen + 3] >> 6; | ||
794 | |||
795 | if (test_bit(keyix, sc->keymap)) | ||
796 | rx_status.flag |= RX_FLAG_DECRYPTED; | ||
797 | } | ||
798 | if (ah->sw_mgmt_crypto && | ||
799 | (rx_status.flag & RX_FLAG_DECRYPTED) && | ||
800 | ieee80211_is_mgmt(fc)) { | ||
801 | /* Use software decrypt for management frames. */ | ||
802 | rx_status.flag &= ~RX_FLAG_DECRYPTED; | ||
803 | } | ||
804 | 608 | ||
805 | /* We will now give hardware our shiny new allocated skb */ | 609 | /* We will now give hardware our shiny new allocated skb */ |
806 | bf->bf_mpdu = requeue_skb; | 610 | bf->bf_mpdu = requeue_skb; |
807 | bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data, | 611 | bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data, |
808 | sc->rx.bufsize, | 612 | common->rx_bufsize, |
809 | DMA_FROM_DEVICE); | 613 | DMA_FROM_DEVICE); |
810 | if (unlikely(dma_mapping_error(sc->dev, | 614 | if (unlikely(dma_mapping_error(sc->dev, |
811 | bf->bf_buf_addr))) { | 615 | bf->bf_buf_addr))) { |
812 | dev_kfree_skb_any(requeue_skb); | 616 | dev_kfree_skb_any(requeue_skb); |
813 | bf->bf_mpdu = NULL; | 617 | bf->bf_mpdu = NULL; |
814 | DPRINTF(sc, ATH_DBG_FATAL, | 618 | ath_print(common, ATH_DBG_FATAL, |
815 | "dma_mapping_error() on RX\n"); | 619 | "dma_mapping_error() on RX\n"); |
816 | ath_rx_send_to_mac80211(sc, skb, &rx_status); | 620 | ath_rx_send_to_mac80211(hw, sc, skb, rxs); |
817 | break; | 621 | break; |
818 | } | 622 | } |
819 | bf->bf_dmacontext = bf->bf_buf_addr; | 623 | bf->bf_dmacontext = bf->bf_buf_addr; |
@@ -824,17 +628,17 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush) | |||
824 | */ | 628 | */ |
825 | if (sc->rx.defant != ds->ds_rxstat.rs_antenna) { | 629 | if (sc->rx.defant != ds->ds_rxstat.rs_antenna) { |
826 | if (++sc->rx.rxotherant >= 3) | 630 | if (++sc->rx.rxotherant >= 3) |
827 | ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna); | 631 | ath_setdefantenna(sc, rx_stats->rs_antenna); |
828 | } else { | 632 | } else { |
829 | sc->rx.rxotherant = 0; | 633 | sc->rx.rxotherant = 0; |
830 | } | 634 | } |
831 | 635 | ||
832 | if (unlikely(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON | | 636 | if (unlikely(sc->ps_flags & (PS_WAIT_FOR_BEACON | |
833 | SC_OP_WAIT_FOR_CAB | | 637 | PS_WAIT_FOR_CAB | |
834 | SC_OP_WAIT_FOR_PSPOLL_DATA))) | 638 | PS_WAIT_FOR_PSPOLL_DATA))) |
835 | ath_rx_ps(sc, skb); | 639 | ath_rx_ps(sc, skb); |
836 | 640 | ||
837 | ath_rx_send_to_mac80211(sc, skb, &rx_status); | 641 | ath_rx_send_to_mac80211(hw, sc, skb, rxs); |
838 | 642 | ||
839 | requeue: | 643 | requeue: |
840 | list_move_tail(&bf->list, &sc->rx.rxbuf); | 644 | list_move_tail(&bf->list, &sc->rx.rxbuf); |