blob: 000e189e104a4852dd4fe59fcdf54ba100f604fb [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
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. Rodriguezf078f202008-08-04 00:16:41 -070017#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. Rodriguezf078f202008-08-04 00:16:41 -070026 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027static 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;
Sujithbe0418a2008-11-18 09:05:55 +053036 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037 ds->ds_data = bf->bf_buf_addr;
38
Sujithbe0418a2008-11-18 09:05:55 +053039 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070040 skb = bf->bf_mpdu;
41 ASSERT(skb != NULL);
42 ds->ds_vdata = skb->data;
43
44 /* setup rx descriptors */
Sujithbe0418a2008-11-18 09:05:55 +053045 ath9k_hw_setuprxdesc(ah, ds,
46 skb_tailroom(skb), /* buffer size */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070047 0);
48
49 if (sc->sc_rxlink == NULL)
50 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
51 else
52 *sc->sc_rxlink = bf->bf_daddr;
53
54 sc->sc_rxlink = &ds->ds_link;
55 ath9k_hw_rxena(ah);
56}
57
Sujithbe0418a2008-11-18 09:05:55 +053058static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc, u32 len)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070059{
60 struct sk_buff *skb;
61 u32 off;
62
63 /*
64 * Cache-line-align. This is important (for the
65 * 5210 at least) as not doing so causes bogus data
66 * in rx'd frames.
67 */
68
69 skb = dev_alloc_skb(len + sc->sc_cachelsz - 1);
70 if (skb != NULL) {
71 off = ((unsigned long) skb->data) % sc->sc_cachelsz;
72 if (off != 0)
73 skb_reserve(skb, sc->sc_cachelsz - off);
74 } else {
75 DPRINTF(sc, ATH_DBG_FATAL,
76 "%s: skbuff alloc of size %u failed\n",
77 __func__, len);
78 return NULL;
79 }
80
81 return skb;
82}
83
Sujithbe0418a2008-11-18 09:05:55 +053084static void ath_rx_requeue(struct ath_softc *sc, struct ath_buf *bf)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085{
Sujithbe0418a2008-11-18 09:05:55 +053086 struct sk_buff *skb;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
88 ASSERT(bf != NULL);
89
Sujithbe0418a2008-11-18 09:05:55 +053090 if (bf->bf_mpdu == NULL) {
91 skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
92 if (skb != NULL) {
93 bf->bf_mpdu = skb;
94 bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
95 skb_end_pointer(skb) - skb->head,
96 PCI_DMA_FROMDEVICE);
97 bf->bf_dmacontext = bf->bf_buf_addr;
98
99 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100 }
Sujithbe0418a2008-11-18 09:05:55 +0530101
102 list_move_tail(&bf->list, &sc->sc_rxbuf);
103 ath_rx_buf_link(sc, bf);
104}
105
106
107static int ath_rate2idx(struct ath_softc *sc, int rate)
108{
109 int i = 0, cur_band, n_rates;
110 struct ieee80211_hw *hw = sc->hw;
111
112 cur_band = hw->conf.channel->band;
113 n_rates = sc->sbands[cur_band].n_bitrates;
114
115 for (i = 0; i < n_rates; i++) {
116 if (sc->sbands[cur_band].bitrates[i].bitrate == rate)
117 break;
118 }
119
120 /*
121 * NB:mac80211 validates rx rate index against the supported legacy rate
122 * index only (should be done against ht rates also), return the highest
123 * legacy rate index for rx rate which does not match any one of the
124 * supported basic and extended rates to make mac80211 happy.
125 * The following hack will be cleaned up once the issue with
126 * the rx rate index validation in mac80211 is fixed.
127 */
128 if (i == n_rates)
129 return n_rates - 1;
130
131 return i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700132}
133
134/*
Sujithbe0418a2008-11-18 09:05:55 +0530135 * For Decrypt or Demic errors, we only mark packet status here and always push
136 * up the frame up to let mac80211 handle the actual error case, be it no
137 * decryption key or real decryption error. This let us keep statistics there.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700138 */
Sujithbe0418a2008-11-18 09:05:55 +0530139static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds,
140 struct ieee80211_rx_status *rx_status, bool *decrypt_error,
141 struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700142{
Sujithbe0418a2008-11-18 09:05:55 +0530143 struct ieee80211_hdr *hdr;
144 int ratekbps;
145 u8 ratecode;
146 __le16 fc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700147
Sujithbe0418a2008-11-18 09:05:55 +0530148 hdr = (struct ieee80211_hdr *)skb->data;
149 fc = hdr->frame_control;
150 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700151
Sujithbe0418a2008-11-18 09:05:55 +0530152 if (ds->ds_rxstat.rs_more) {
153 /*
154 * Frame spans multiple descriptors; this cannot happen yet
155 * as we don't support jumbograms. If not in monitor mode,
156 * discard the frame. Enable this if you want to see
157 * error frames in Monitor mode.
158 */
159 if (sc->sc_ah->ah_opmode != ATH9K_M_MONITOR)
160 goto rx_next;
161 } else if (ds->ds_rxstat.rs_status != 0) {
162 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
163 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
164 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY)
165 goto rx_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700166
Sujithbe0418a2008-11-18 09:05:55 +0530167 if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) {
168 *decrypt_error = true;
169 } else if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) {
170 if (ieee80211_is_ctl(fc))
171 /*
172 * Sometimes, we get invalid
173 * MIC failures on valid control frames.
174 * Remove these mic errors.
175 */
176 ds->ds_rxstat.rs_status &= ~ATH9K_RXERR_MIC;
177 else
178 rx_status->flag |= RX_FLAG_MMIC_ERROR;
179 }
180 /*
181 * Reject error frames with the exception of
182 * decryption and MIC failures. For monitor mode,
183 * we also ignore the CRC error.
184 */
185 if (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR) {
186 if (ds->ds_rxstat.rs_status &
187 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
188 ATH9K_RXERR_CRC))
189 goto rx_next;
190 } else {
191 if (ds->ds_rxstat.rs_status &
192 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
193 goto rx_next;
194 }
195 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700196 }
197
Sujithbe0418a2008-11-18 09:05:55 +0530198 ratecode = ds->ds_rxstat.rs_rate;
199 ratekbps = sc->sc_hwmap[ratecode].rateKbps;
200
201 /* HT rate */
202 if (ratecode & 0x80) {
203 if (ds->ds_rxstat.rs_flags & ATH9K_RX_2040)
204 ratekbps = (ratekbps * 27) / 13;
205 if (ds->ds_rxstat.rs_flags & ATH9K_RX_GI)
206 ratekbps = (ratekbps * 10) / 9;
207 }
208
209 rx_status->mactime = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
210 rx_status->band = sc->hw->conf.channel->band;
211 rx_status->freq = sc->hw->conf.channel->center_freq;
212 rx_status->noise = sc->sc_ani.sc_noise_floor;
213 rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi;
214 rx_status->rate_idx = ath_rate2idx(sc, (ratekbps / 100));
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;
230rx_next:
231 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700232}
233
234static 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 */
Sujith60b67f52008-08-07 10:52:38 +0530244 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700245 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;
255
256 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
257 DPRINTF(sc, ATH_DBG_CONFIG ,
258 "%s: RX filter 0x%x, MC filter %08x:%08x\n",
259 __func__, rfilt, mfilt[0], mfilt[1]);
260}
261
262int ath_rx_init(struct ath_softc *sc, int nbufs)
263{
264 struct sk_buff *skb;
265 struct ath_buf *bf;
266 int error = 0;
267
268 do {
269 spin_lock_init(&sc->sc_rxflushlock);
Sujith98deeea2008-08-11 14:05:46 +0530270 sc->sc_flags &= ~SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700271 spin_lock_init(&sc->sc_rxbuflock);
272
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700273 sc->sc_rxbufsize = roundup(IEEE80211_MAX_MPDU_LEN,
274 min(sc->sc_cachelsz,
275 (u16)64));
276
277 DPRINTF(sc, ATH_DBG_CONFIG, "%s: cachelsz %u rxbufsize %u\n",
278 __func__, sc->sc_cachelsz, sc->sc_rxbufsize);
279
280 /* Initialize rx descriptors */
281
282 error = ath_descdma_setup(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
283 "rx", nbufs, 1);
284 if (error != 0) {
285 DPRINTF(sc, ATH_DBG_FATAL,
286 "%s: failed to allocate rx descriptors: %d\n",
287 __func__, error);
288 break;
289 }
290
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700291 list_for_each_entry(bf, &sc->sc_rxbuf, list) {
292 skb = ath_rxbuf_alloc(sc, sc->sc_rxbufsize);
293 if (skb == NULL) {
294 error = -ENOMEM;
295 break;
296 }
297
298 bf->bf_mpdu = skb;
Sujith927e70e2008-08-14 13:26:34 +0530299 bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
300 skb_end_pointer(skb) - skb->head,
301 PCI_DMA_FROMDEVICE);
302 bf->bf_dmacontext = bf->bf_buf_addr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700303 }
304 sc->sc_rxlink = NULL;
305
306 } while (0);
307
308 if (error)
309 ath_rx_cleanup(sc);
310
311 return error;
312}
313
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700314void ath_rx_cleanup(struct ath_softc *sc)
315{
316 struct sk_buff *skb;
317 struct ath_buf *bf;
318
319 list_for_each_entry(bf, &sc->sc_rxbuf, list) {
320 skb = bf->bf_mpdu;
321 if (skb)
322 dev_kfree_skb(skb);
323 }
324
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700325 if (sc->sc_rxdma.dd_desc_len != 0)
326 ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
327}
328
329/*
330 * Calculate the receive filter according to the
331 * operating mode and state:
332 *
333 * o always accept unicast, broadcast, and multicast traffic
334 * o maintain current state of phy error reception (the hal
335 * may enable phy error frames for noise immunity work)
336 * o probe request frames are accepted only when operating in
337 * hostap, adhoc, or monitor modes
338 * o enable promiscuous mode according to the interface state
339 * o accept beacons:
340 * - when operating in adhoc mode so the 802.11 layer creates
341 * node table entries for peers,
342 * - when operating in station mode for collecting rssi data when
343 * the station is otherwise quiet, or
344 * - when operating as a repeater so we see repeater-sta beacons
345 * - when scanning
346 */
347
348u32 ath_calcrxfilter(struct ath_softc *sc)
349{
350#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
Sujith7dcfdcd2008-08-11 14:03:13 +0530351
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700352 u32 rfilt;
353
354 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
355 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
356 | ATH9K_RX_FILTER_MCAST;
357
358 /* If not a STA, enable processing of Probe Requests */
Sujithb4696c8b2008-08-11 14:04:52 +0530359 if (sc->sc_ah->ah_opmode != ATH9K_M_STA)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700360 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
361
362 /* Can't set HOSTAP into promiscous mode */
Sujithb4696c8b2008-08-11 14:04:52 +0530363 if (((sc->sc_ah->ah_opmode != ATH9K_M_HOSTAP) &&
Sujith7dcfdcd2008-08-11 14:03:13 +0530364 (sc->rx_filter & FIF_PROMISC_IN_BSS)) ||
Sujithb4696c8b2008-08-11 14:04:52 +0530365 (sc->sc_ah->ah_opmode == ATH9K_M_MONITOR)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700366 rfilt |= ATH9K_RX_FILTER_PROM;
367 /* ??? To prevent from sending ACK */
368 rfilt &= ~ATH9K_RX_FILTER_UCAST;
369 }
370
Luis R. Rodriguezffb82672008-11-03 14:43:01 -0800371 if (sc->sc_ah->ah_opmode == ATH9K_M_STA ||
Sujithbe0418a2008-11-18 09:05:55 +0530372 sc->sc_ah->ah_opmode == ATH9K_M_IBSS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700373 rfilt |= ATH9K_RX_FILTER_BEACON;
374
375 /* If in HOSTAP mode, want to enable reception of PSPOLL frames
376 & beacon frames */
Sujithb4696c8b2008-08-11 14:04:52 +0530377 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700378 rfilt |= (ATH9K_RX_FILTER_BEACON | ATH9K_RX_FILTER_PSPOLL);
Sujithbe0418a2008-11-18 09:05:55 +0530379
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700380 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530381
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700382#undef RX_FILTER_PRESERVE
383}
384
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700385int ath_startrecv(struct ath_softc *sc)
386{
387 struct ath_hal *ah = sc->sc_ah;
388 struct ath_buf *bf, *tbf;
389
390 spin_lock_bh(&sc->sc_rxbuflock);
391 if (list_empty(&sc->sc_rxbuf))
392 goto start_recv;
393
394 sc->sc_rxlink = NULL;
395 list_for_each_entry_safe(bf, tbf, &sc->sc_rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700396 ath_rx_buf_link(sc, bf);
397 }
398
399 /* We could have deleted elements so the list may be empty now */
400 if (list_empty(&sc->sc_rxbuf))
401 goto start_recv;
402
403 bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
404 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530405 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700406
407start_recv:
408 spin_unlock_bh(&sc->sc_rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530409 ath_opmode_init(sc);
410 ath9k_hw_startpcureceive(ah);
411
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412 return 0;
413}
414
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700415bool ath_stoprecv(struct ath_softc *sc)
416{
417 struct ath_hal *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700418 bool stopped;
419
Sujithbe0418a2008-11-18 09:05:55 +0530420 ath9k_hw_stoppcurecv(ah);
421 ath9k_hw_setrxfilter(ah, 0);
422 stopped = ath9k_hw_stopdmarecv(ah);
423 mdelay(3); /* 3ms is long enough for 1 frame */
424 sc->sc_rxlink = NULL;
425
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426 return stopped;
427}
428
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700429void ath_flushrecv(struct ath_softc *sc)
430{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700431 spin_lock_bh(&sc->sc_rxflushlock);
Sujith98deeea2008-08-11 14:05:46 +0530432 sc->sc_flags |= SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433 ath_rx_tasklet(sc, 1);
Sujith98deeea2008-08-11 14:05:46 +0530434 sc->sc_flags &= ~SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435 spin_unlock_bh(&sc->sc_rxflushlock);
436}
437
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438int ath_rx_tasklet(struct ath_softc *sc, int flush)
439{
440#define PA2DESC(_sc, _pa) \
441 ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
442 ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
443
Sujithbe0418a2008-11-18 09:05:55 +0530444 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 struct ath_desc *ds;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700446 struct sk_buff *skb = NULL;
Sujithbe0418a2008-11-18 09:05:55 +0530447 struct ieee80211_rx_status rx_status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448 struct ath_hal *ah = sc->sc_ah;
Sujithbe0418a2008-11-18 09:05:55 +0530449 struct ieee80211_hdr *hdr;
450 int hdrlen, padsize, retval;
451 bool decrypt_error = false;
452 u8 keyix;
453
454 spin_lock_bh(&sc->sc_rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455
456 do {
457 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +0530458 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459 break;
460
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461 if (list_empty(&sc->sc_rxbuf)) {
462 sc->sc_rxlink = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463 break;
464 }
465
466 bf = list_first_entry(&sc->sc_rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467 ds = bf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468
469 /*
470 * Must provide the virtual address of the current
471 * descriptor, the physical address, and the virtual
472 * address of the next descriptor in the h/w chain.
473 * This allows the HAL to look ahead to see if the
474 * hardware is done with a descriptor by checking the
475 * done bit in the following descriptor and the address
476 * of the current descriptor the DMA engine is working
477 * on. All this is necessary because of our use of
478 * a self-linked list to avoid rx overruns.
479 */
Sujithbe0418a2008-11-18 09:05:55 +0530480 retval = ath9k_hw_rxprocdesc(ah, ds,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 bf->bf_daddr,
482 PA2DESC(sc, ds->ds_link),
483 0);
484 if (retval == -EINPROGRESS) {
485 struct ath_buf *tbf;
486 struct ath_desc *tds;
487
488 if (list_is_last(&bf->list, &sc->sc_rxbuf)) {
Sujithbe0418a2008-11-18 09:05:55 +0530489 sc->sc_rxlink = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490 break;
491 }
492
493 tbf = list_entry(bf->list.next, struct ath_buf, list);
494
495 /*
496 * On some hardware the descriptor status words could
497 * get corrupted, including the done bit. Because of
498 * this, check if the next descriptor's done bit is
499 * set or not.
500 *
501 * If the next descriptor's done bit is set, the current
502 * descriptor has been corrupted. Force s/w to discard
503 * this descriptor and continue...
504 */
505
506 tds = tbf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +0530507 retval = ath9k_hw_rxprocdesc(ah, tds, tbf->bf_daddr,
508 PA2DESC(sc, tds->ds_link), 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700509 if (retval == -EINPROGRESS) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510 break;
511 }
512 }
513
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700514 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +0530515 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700518 /*
Sujithbe0418a2008-11-18 09:05:55 +0530519 * If we're asked to flush receive queue, directly
520 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700521 */
Sujithbe0418a2008-11-18 09:05:55 +0530522 if (flush)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523 goto rx_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700524
Sujithbe0418a2008-11-18 09:05:55 +0530525 if (!ds->ds_rxstat.rs_datalen)
526 goto rx_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700527
Sujithbe0418a2008-11-18 09:05:55 +0530528 /* The status portion of the descriptor could get corrupted. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700529 if (sc->sc_rxbufsize < ds->ds_rxstat.rs_datalen)
530 goto rx_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700531
Sujithbe0418a2008-11-18 09:05:55 +0530532 if (!ath_rx_prepare(skb, ds, &rx_status, &decrypt_error, sc))
533 goto rx_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700534
Sujithbe0418a2008-11-18 09:05:55 +0530535 /* Sync and unmap the frame */
536 pci_dma_sync_single_for_cpu(sc->pdev, bf->bf_buf_addr,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700537 skb_tailroom(skb),
538 PCI_DMA_FROMDEVICE);
Sujithbe0418a2008-11-18 09:05:55 +0530539 pci_unmap_single(sc->pdev, bf->bf_buf_addr,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700540 sc->sc_rxbufsize,
541 PCI_DMA_FROMDEVICE);
542
Sujithbe0418a2008-11-18 09:05:55 +0530543 skb_put(skb, ds->ds_rxstat.rs_datalen);
544 skb->protocol = cpu_to_be16(ETH_P_CONTROL);
545
546 /* see if any padding is done by the hw and remove it */
547 hdr = (struct ieee80211_hdr *)skb->data;
548 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
549
550 if (hdrlen & 3) {
551 padsize = hdrlen % 4;
552 memmove(skb->data + padsize, skb->data, hdrlen);
553 skb_pull(skb, padsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554 }
555
Sujithbe0418a2008-11-18 09:05:55 +0530556 keyix = ds->ds_rxstat.rs_keyix;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700557
Sujithbe0418a2008-11-18 09:05:55 +0530558 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) {
559 rx_status.flag |= RX_FLAG_DECRYPTED;
560 } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
561 && !decrypt_error && skb->len >= hdrlen + 4) {
562 keyix = skb->data[hdrlen + 3] >> 6;
563
564 if (test_bit(keyix, sc->sc_keymap))
565 rx_status.flag |= RX_FLAG_DECRYPTED;
566 }
567
568 /* Send the frame to mac80211 */
569 __ieee80211_rx(sc->hw, skb, &rx_status);
570 bf->bf_mpdu = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571
572 /*
573 * change the default rx antenna if rx diversity chooses the
574 * other antenna 3 times in a row.
575 */
576 if (sc->sc_defant != ds->ds_rxstat.rs_antenna) {
577 if (++sc->sc_rxotherant >= 3)
Sujithbe0418a2008-11-18 09:05:55 +0530578 ath_setdefantenna(sc, ds->ds_rxstat.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700579 } else {
580 sc->sc_rxotherant = 0;
581 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700582rx_next:
Sujithbe0418a2008-11-18 09:05:55 +0530583 ath_rx_requeue(sc, bf);
584 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700585
Sujithbe0418a2008-11-18 09:05:55 +0530586 spin_unlock_bh(&sc->sc_rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700587
588 return 0;
589#undef PA2DESC
590}