blob: b2b12a293c7044fc156971d1aac059f0124b2f4b [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040018#include "ar9003_mac.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070019
Felix Fietkaub5c804752010-04-15 17:38:48 -040020#define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb))
21
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -070022static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
23 int mindelta, int main_rssi_avg,
24 int alt_rssi_avg, int pkt_count)
25{
26 return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
27 (alt_rssi_avg > main_rssi_avg + maxdelta)) ||
28 (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50);
29}
30
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -070031static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
32{
33 return sc->ps_enabled &&
34 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
35}
36
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037/*
38 * Setup and link descriptors.
39 *
40 * 11N: we can no longer afford to self link the last descriptor.
41 * MAC acknowledges BA status as long as it copies frames to host
42 * buffer (or rx fifo). This can incorrectly acknowledge packets
43 * to a sender if last desc is self-linked.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070044 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070045static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
46{
Sujithcbe61d82009-02-09 13:27:12 +053047 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080048 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070049 struct ath_desc *ds;
50 struct sk_buff *skb;
51
52 ATH_RXBUF_RESET(bf);
53
54 ds = bf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +053055 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070056 ds->ds_data = bf->bf_buf_addr;
57
Sujithbe0418a2008-11-18 09:05:55 +053058 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070059 skb = bf->bf_mpdu;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -070060 BUG_ON(skb == NULL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070061 ds->ds_vdata = skb->data;
62
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080063 /*
64 * setup rx descriptors. The rx_bufsize here tells the hardware
Luis R. Rodriguezb4b6cda2008-11-20 17:15:13 -080065 * how much data it can DMA to us and that we are prepared
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080066 * to process
67 */
Sujithb77f4832008-12-07 21:44:03 +053068 ath9k_hw_setuprxdesc(ah, ds,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080069 common->rx_bufsize,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070 0);
71
Sujithb77f4832008-12-07 21:44:03 +053072 if (sc->rx.rxlink == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
74 else
Sujithb77f4832008-12-07 21:44:03 +053075 *sc->rx.rxlink = bf->bf_daddr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithb77f4832008-12-07 21:44:03 +053077 sc->rx.rxlink = &ds->ds_link;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078 ath9k_hw_rxena(ah);
79}
80
Sujithff37e332008-11-24 12:07:55 +053081static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
82{
83 /* XXX block beacon interrupts */
84 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +053085 sc->rx.defant = antenna;
86 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +053087}
88
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089static void ath_opmode_init(struct ath_softc *sc)
90{
Sujithcbe61d82009-02-09 13:27:12 +053091 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -070092 struct ath_common *common = ath9k_hw_common(ah);
93
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 u32 rfilt, mfilt[2];
95
96 /* configure rx filter */
97 rfilt = ath_calcrxfilter(sc);
98 ath9k_hw_setrxfilter(ah, rfilt);
99
100 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +0200101 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700102
103 /* configure operational mode */
104 ath9k_hw_setopmode(ah);
105
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700106 /* calculate and install multicast filter */
107 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700109}
110
Felix Fietkaub5c804752010-04-15 17:38:48 -0400111static bool ath_rx_edma_buf_link(struct ath_softc *sc,
112 enum ath9k_rx_qtype qtype)
113{
114 struct ath_hw *ah = sc->sc_ah;
115 struct ath_rx_edma *rx_edma;
116 struct sk_buff *skb;
117 struct ath_buf *bf;
118
119 rx_edma = &sc->rx.rx_edma[qtype];
120 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
121 return false;
122
123 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
124 list_del_init(&bf->list);
125
126 skb = bf->bf_mpdu;
127
128 ATH_RXBUF_RESET(bf);
129 memset(skb->data, 0, ah->caps.rx_status_len);
130 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
131 ah->caps.rx_status_len, DMA_TO_DEVICE);
132
133 SKB_CB_ATHBUF(skb) = bf;
134 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
135 skb_queue_tail(&rx_edma->rx_fifo, skb);
136
137 return true;
138}
139
140static void ath_rx_addbuffer_edma(struct ath_softc *sc,
141 enum ath9k_rx_qtype qtype, int size)
142{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400143 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
144 u32 nbuf = 0;
145
Felix Fietkaub5c804752010-04-15 17:38:48 -0400146 if (list_empty(&sc->rx.rxbuf)) {
Joe Perches226afe62010-12-02 19:12:37 -0800147 ath_dbg(common, ATH_DBG_QUEUE, "No free rx buf available\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400148 return;
149 }
150
151 while (!list_empty(&sc->rx.rxbuf)) {
152 nbuf++;
153
154 if (!ath_rx_edma_buf_link(sc, qtype))
155 break;
156
157 if (nbuf >= size)
158 break;
159 }
160}
161
162static void ath_rx_remove_buffer(struct ath_softc *sc,
163 enum ath9k_rx_qtype qtype)
164{
165 struct ath_buf *bf;
166 struct ath_rx_edma *rx_edma;
167 struct sk_buff *skb;
168
169 rx_edma = &sc->rx.rx_edma[qtype];
170
171 while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
172 bf = SKB_CB_ATHBUF(skb);
173 BUG_ON(!bf);
174 list_add_tail(&bf->list, &sc->rx.rxbuf);
175 }
176}
177
178static void ath_rx_edma_cleanup(struct ath_softc *sc)
179{
180 struct ath_buf *bf;
181
182 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
183 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
184
185 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
186 if (bf->bf_mpdu)
187 dev_kfree_skb_any(bf->bf_mpdu);
188 }
189
190 INIT_LIST_HEAD(&sc->rx.rxbuf);
191
192 kfree(sc->rx.rx_bufptr);
193 sc->rx.rx_bufptr = NULL;
194}
195
196static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
197{
198 skb_queue_head_init(&rx_edma->rx_fifo);
199 skb_queue_head_init(&rx_edma->rx_buffers);
200 rx_edma->rx_fifo_hwsize = size;
201}
202
203static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
204{
205 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
206 struct ath_hw *ah = sc->sc_ah;
207 struct sk_buff *skb;
208 struct ath_buf *bf;
209 int error = 0, i;
210 u32 size;
211
212
213 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN +
214 ah->caps.rx_status_len,
215 min(common->cachelsz, (u16)64));
216
217 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
218 ah->caps.rx_status_len);
219
220 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
221 ah->caps.rx_lp_qdepth);
222 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
223 ah->caps.rx_hp_qdepth);
224
225 size = sizeof(struct ath_buf) * nbufs;
226 bf = kzalloc(size, GFP_KERNEL);
227 if (!bf)
228 return -ENOMEM;
229
230 INIT_LIST_HEAD(&sc->rx.rxbuf);
231 sc->rx.rx_bufptr = bf;
232
233 for (i = 0; i < nbufs; i++, bf++) {
234 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
235 if (!skb) {
236 error = -ENOMEM;
237 goto rx_init_fail;
238 }
239
240 memset(skb->data, 0, common->rx_bufsize);
241 bf->bf_mpdu = skb;
242
243 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
244 common->rx_bufsize,
245 DMA_BIDIRECTIONAL);
246 if (unlikely(dma_mapping_error(sc->dev,
247 bf->bf_buf_addr))) {
248 dev_kfree_skb_any(skb);
249 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700250 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800251 ath_err(common,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400252 "dma_mapping_error() on RX init\n");
253 error = -ENOMEM;
254 goto rx_init_fail;
255 }
256
257 list_add_tail(&bf->list, &sc->rx.rxbuf);
258 }
259
260 return 0;
261
262rx_init_fail:
263 ath_rx_edma_cleanup(sc);
264 return error;
265}
266
267static void ath_edma_start_recv(struct ath_softc *sc)
268{
269 spin_lock_bh(&sc->rx.rxbuflock);
270
271 ath9k_hw_rxena(sc->sc_ah);
272
273 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
274 sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
275
276 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
277 sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
278
Felix Fietkaub5c804752010-04-15 17:38:48 -0400279 ath_opmode_init(sc);
280
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400281 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700282
283 spin_unlock_bh(&sc->rx.rxbuflock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400284}
285
286static void ath_edma_stop_recv(struct ath_softc *sc)
287{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400288 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
289 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400290}
291
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700292int ath_rx_init(struct ath_softc *sc, int nbufs)
293{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700294 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700295 struct sk_buff *skb;
296 struct ath_buf *bf;
297 int error = 0;
298
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700299 spin_lock_init(&sc->sc_pcu_lock);
Sujith797fe5cb2009-03-30 15:28:45 +0530300 sc->sc_flags &= ~SC_OP_RXFLUSH;
301 spin_lock_init(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700302
Felix Fietkaub5c804752010-04-15 17:38:48 -0400303 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
304 return ath_rx_edma_init(sc, nbufs);
305 } else {
306 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
307 min(common->cachelsz, (u16)64));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700308
Joe Perches226afe62010-12-02 19:12:37 -0800309 ath_dbg(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
310 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700311
Felix Fietkaub5c804752010-04-15 17:38:48 -0400312 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700313
Felix Fietkaub5c804752010-04-15 17:38:48 -0400314 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400315 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400316 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800317 ath_err(common,
318 "failed to allocate rx descriptors: %d\n",
319 error);
Sujith797fe5cb2009-03-30 15:28:45 +0530320 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700321 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400322
323 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
324 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
325 GFP_KERNEL);
326 if (skb == NULL) {
327 error = -ENOMEM;
328 goto err;
329 }
330
331 bf->bf_mpdu = skb;
332 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
333 common->rx_bufsize,
334 DMA_FROM_DEVICE);
335 if (unlikely(dma_mapping_error(sc->dev,
336 bf->bf_buf_addr))) {
337 dev_kfree_skb_any(skb);
338 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -0700339 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -0800340 ath_err(common,
341 "dma_mapping_error() on RX init\n");
Felix Fietkaub5c804752010-04-15 17:38:48 -0400342 error = -ENOMEM;
343 goto err;
344 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400345 }
346 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530347 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700348
Sujith797fe5cb2009-03-30 15:28:45 +0530349err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350 if (error)
351 ath_rx_cleanup(sc);
352
353 return error;
354}
355
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700356void ath_rx_cleanup(struct ath_softc *sc)
357{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800358 struct ath_hw *ah = sc->sc_ah;
359 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700360 struct sk_buff *skb;
361 struct ath_buf *bf;
362
Felix Fietkaub5c804752010-04-15 17:38:48 -0400363 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
364 ath_rx_edma_cleanup(sc);
365 return;
366 } else {
367 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
368 skb = bf->bf_mpdu;
369 if (skb) {
370 dma_unmap_single(sc->dev, bf->bf_buf_addr,
371 common->rx_bufsize,
372 DMA_FROM_DEVICE);
373 dev_kfree_skb(skb);
Ben Greear6cf9e992010-10-14 12:45:30 -0700374 bf->bf_buf_addr = 0;
375 bf->bf_mpdu = NULL;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400376 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400377 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700378
Felix Fietkaub5c804752010-04-15 17:38:48 -0400379 if (sc->rx.rxdma.dd_desc_len != 0)
380 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
381 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700382}
383
384/*
385 * Calculate the receive filter according to the
386 * operating mode and state:
387 *
388 * o always accept unicast, broadcast, and multicast traffic
389 * o maintain current state of phy error reception (the hal
390 * may enable phy error frames for noise immunity work)
391 * o probe request frames are accepted only when operating in
392 * hostap, adhoc, or monitor modes
393 * o enable promiscuous mode according to the interface state
394 * o accept beacons:
395 * - when operating in adhoc mode so the 802.11 layer creates
396 * node table entries for peers,
397 * - when operating in station mode for collecting rssi data when
398 * the station is otherwise quiet, or
399 * - when operating as a repeater so we see repeater-sta beacons
400 * - when scanning
401 */
402
403u32 ath_calcrxfilter(struct ath_softc *sc)
404{
405#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
Sujith7dcfdcd2008-08-11 14:03:13 +0530406
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700407 u32 rfilt;
408
409 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
410 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
411 | ATH9K_RX_FILTER_MCAST;
412
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300413 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
415
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200416 /*
417 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
418 * mode interface or when in monitor mode. AP mode does not need this
419 * since it receives all in-BSS frames anyway.
420 */
Sujith2660b812009-02-09 13:27:26 +0530421 if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) &&
Sujithb77f4832008-12-07 21:44:03 +0530422 (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530423 (sc->sc_ah->is_monitoring))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700424 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
Sujithd42c6b72009-02-04 08:10:22 +0530426 if (sc->rx.rxfilter & FIF_CONTROL)
427 rfilt |= ATH9K_RX_FILTER_CONTROL;
428
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530429 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700430 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530431 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
432 rfilt |= ATH9K_RX_FILTER_MYBEACON;
433 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434 rfilt |= ATH9K_RX_FILTER_BEACON;
435
Felix Fietkau7a370812010-09-22 12:34:52 +0200436 if ((AR_SREV_9280_20_OR_LATER(sc->sc_ah) ||
Felix Fietkaue17f83e2010-09-22 12:34:53 +0200437 AR_SREV_9285_12_OR_LATER(sc->sc_ah)) &&
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530438 (sc->sc_ah->opmode == NL80211_IFTYPE_AP) &&
439 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530440 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530441
Sujith7ea310b2009-09-03 12:08:43 +0530442 if (conf_is_ht(&sc->hw->conf))
443 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
444
Felix Fietkau7545daf2011-01-24 19:23:16 +0100445 if (sc->nvifs > 1 || (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700446 /* The following may also be needed for other older chips */
447 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
448 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200449 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
450 }
451
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700452 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530453
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454#undef RX_FILTER_PRESERVE
455}
456
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457int ath_startrecv(struct ath_softc *sc)
458{
Sujithcbe61d82009-02-09 13:27:12 +0530459 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460 struct ath_buf *bf, *tbf;
461
Felix Fietkaub5c804752010-04-15 17:38:48 -0400462 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
463 ath_edma_start_recv(sc);
464 return 0;
465 }
466
Sujithb77f4832008-12-07 21:44:03 +0530467 spin_lock_bh(&sc->rx.rxbuflock);
468 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469 goto start_recv;
470
Sujithb77f4832008-12-07 21:44:03 +0530471 sc->rx.rxlink = NULL;
472 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473 ath_rx_buf_link(sc, bf);
474 }
475
476 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530477 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478 goto start_recv;
479
Sujithb77f4832008-12-07 21:44:03 +0530480 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530482 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483
484start_recv:
Sujithbe0418a2008-11-18 09:05:55 +0530485 ath_opmode_init(sc);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400486 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530487
Luis R. Rodriguez7583c5502010-10-20 16:07:04 -0700488 spin_unlock_bh(&sc->rx.rxbuflock);
489
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490 return 0;
491}
492
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700493bool ath_stoprecv(struct ath_softc *sc)
494{
Sujithcbe61d82009-02-09 13:27:12 +0530495 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496 bool stopped;
497
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700498 spin_lock_bh(&sc->rx.rxbuflock);
Felix Fietkaud47844a2010-11-20 03:08:47 +0100499 ath9k_hw_abortpcurecv(ah);
Sujithbe0418a2008-11-18 09:05:55 +0530500 ath9k_hw_setrxfilter(ah, 0);
501 stopped = ath9k_hw_stopdmarecv(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400502
503 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
504 ath_edma_stop_recv(sc);
505 else
506 sc->rx.rxlink = NULL;
Luis R. Rodriguez1e450282010-10-20 16:07:03 -0700507 spin_unlock_bh(&sc->rx.rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530508
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530509 if (!(ah->ah_flags & AH_UNPLUGGED) &&
510 unlikely(!stopped)) {
Ben Greeard7fd1b502010-12-06 13:13:07 -0800511 ath_err(ath9k_hw_common(sc->sc_ah),
512 "Could not stop RX, we could be "
513 "confusing the DMA engine when we start RX up\n");
514 ATH_DBG_WARN_ON_ONCE(!stopped);
515 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516 return stopped;
517}
518
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700519void ath_flushrecv(struct ath_softc *sc)
520{
Sujith98deeea2008-08-11 14:05:46 +0530521 sc->sc_flags |= SC_OP_RXFLUSH;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400522 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
523 ath_rx_tasklet(sc, 1, true);
524 ath_rx_tasklet(sc, 1, false);
Sujith98deeea2008-08-11 14:05:46 +0530525 sc->sc_flags &= ~SC_OP_RXFLUSH;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700526}
527
Jouni Malinencc659652009-05-14 21:28:48 +0300528static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
529{
530 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
531 struct ieee80211_mgmt *mgmt;
532 u8 *pos, *end, id, elen;
533 struct ieee80211_tim_ie *tim;
534
535 mgmt = (struct ieee80211_mgmt *)skb->data;
536 pos = mgmt->u.beacon.variable;
537 end = skb->data + skb->len;
538
539 while (pos + 2 < end) {
540 id = *pos++;
541 elen = *pos++;
542 if (pos + elen > end)
543 break;
544
545 if (id == WLAN_EID_TIM) {
546 if (elen < sizeof(*tim))
547 break;
548 tim = (struct ieee80211_tim_ie *) pos;
549 if (tim->dtim_count != 0)
550 break;
551 return tim->bitmap_ctrl & 0x01;
552 }
553
554 pos += elen;
555 }
556
557 return false;
558}
559
Jouni Malinencc659652009-05-14 21:28:48 +0300560static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
561{
562 struct ieee80211_mgmt *mgmt;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700563 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300564
565 if (skb->len < 24 + 8 + 2 + 2)
566 return;
567
568 mgmt = (struct ieee80211_mgmt *)skb->data;
Ben Greear48014162011-01-15 19:13:48 +0000569 if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0) {
570 /* TODO: This doesn't work well if you have stations
571 * associated to two different APs because curbssid
572 * is just the last AP that any of the stations associated
573 * with.
574 */
Jouni Malinencc659652009-05-14 21:28:48 +0300575 return; /* not from our current AP */
Ben Greear48014162011-01-15 19:13:48 +0000576 }
Jouni Malinencc659652009-05-14 21:28:48 +0300577
Sujith1b04b932010-01-08 10:36:05 +0530578 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200579
Sujith1b04b932010-01-08 10:36:05 +0530580 if (sc->ps_flags & PS_BEACON_SYNC) {
581 sc->ps_flags &= ~PS_BEACON_SYNC;
Joe Perches226afe62010-12-02 19:12:37 -0800582 ath_dbg(common, ATH_DBG_PS,
583 "Reconfigure Beacon timers based on timestamp from the AP\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300584 ath_beacon_config(sc, NULL);
585 }
586
Jouni Malinencc659652009-05-14 21:28:48 +0300587 if (ath_beacon_dtim_pending_cab(skb)) {
588 /*
589 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200590 * frames. If the last broadcast/multicast frame is not
591 * received properly, the next beacon frame will work as
592 * a backup trigger for returning into NETWORK SLEEP state,
593 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300594 */
Joe Perches226afe62010-12-02 19:12:37 -0800595 ath_dbg(common, ATH_DBG_PS,
596 "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530597 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300598 return;
599 }
600
Sujith1b04b932010-01-08 10:36:05 +0530601 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300602 /*
603 * This can happen if a broadcast frame is dropped or the AP
604 * fails to send a frame indicating that all CAB frames have
605 * been delivered.
606 */
Sujith1b04b932010-01-08 10:36:05 +0530607 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Joe Perches226afe62010-12-02 19:12:37 -0800608 ath_dbg(common, ATH_DBG_PS,
609 "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300610 }
Jouni Malinencc659652009-05-14 21:28:48 +0300611}
612
613static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
614{
615 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700616 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300617
618 hdr = (struct ieee80211_hdr *)skb->data;
619
620 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700621 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
622 && ieee80211_is_beacon(hdr->frame_control))
Jouni Malinencc659652009-05-14 21:28:48 +0300623 ath_rx_ps_beacon(sc, skb);
Sujith1b04b932010-01-08 10:36:05 +0530624 else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
Jouni Malinencc659652009-05-14 21:28:48 +0300625 (ieee80211_is_data(hdr->frame_control) ||
626 ieee80211_is_action(hdr->frame_control)) &&
627 is_multicast_ether_addr(hdr->addr1) &&
628 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300629 /*
630 * No more broadcast/multicast frames to be received at this
631 * point.
632 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400633 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Joe Perches226afe62010-12-02 19:12:37 -0800634 ath_dbg(common, ATH_DBG_PS,
635 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530636 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300637 !is_multicast_ether_addr(hdr->addr1) &&
638 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530639 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Joe Perches226afe62010-12-02 19:12:37 -0800640 ath_dbg(common, ATH_DBG_PS,
641 "Going back to sleep after having received PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530642 sc->ps_flags & (PS_WAIT_FOR_BEACON |
643 PS_WAIT_FOR_CAB |
644 PS_WAIT_FOR_PSPOLL_DATA |
645 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300646 }
647}
648
Felix Fietkaub5c804752010-04-15 17:38:48 -0400649static bool ath_edma_get_buffers(struct ath_softc *sc,
650 enum ath9k_rx_qtype qtype)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700651{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400652 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
653 struct ath_hw *ah = sc->sc_ah;
654 struct ath_common *common = ath9k_hw_common(ah);
655 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530656 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400657 int ret;
658
659 skb = skb_peek(&rx_edma->rx_fifo);
660 if (!skb)
661 return false;
662
663 bf = SKB_CB_ATHBUF(skb);
664 BUG_ON(!bf);
665
Ming Leice9426d2010-05-15 18:25:40 +0800666 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400667 common->rx_bufsize, DMA_FROM_DEVICE);
668
669 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800670 if (ret == -EINPROGRESS) {
671 /*let device gain the buffer again*/
672 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
673 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400674 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800675 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400676
677 __skb_unlink(skb, &rx_edma->rx_fifo);
678 if (ret == -EINVAL) {
679 /* corrupt descriptor, skip this one and the following one */
680 list_add_tail(&bf->list, &sc->rx.rxbuf);
681 ath_rx_edma_buf_link(sc, qtype);
682 skb = skb_peek(&rx_edma->rx_fifo);
683 if (!skb)
684 return true;
685
686 bf = SKB_CB_ATHBUF(skb);
687 BUG_ON(!bf);
688
689 __skb_unlink(skb, &rx_edma->rx_fifo);
690 list_add_tail(&bf->list, &sc->rx.rxbuf);
691 ath_rx_edma_buf_link(sc, qtype);
Vasanthakumar Thiagarajan083e3e82010-05-10 19:41:34 -0700692 return true;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400693 }
694 skb_queue_tail(&rx_edma->rx_buffers, skb);
695
696 return true;
697}
698
699static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
700 struct ath_rx_status *rs,
701 enum ath9k_rx_qtype qtype)
702{
703 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
704 struct sk_buff *skb;
705 struct ath_buf *bf;
706
707 while (ath_edma_get_buffers(sc, qtype));
708 skb = __skb_dequeue(&rx_edma->rx_buffers);
709 if (!skb)
710 return NULL;
711
712 bf = SKB_CB_ATHBUF(skb);
713 ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
714 return bf;
715}
716
717static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
718 struct ath_rx_status *rs)
719{
720 struct ath_hw *ah = sc->sc_ah;
721 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400723 struct ath_buf *bf;
724 int ret;
725
726 if (list_empty(&sc->rx.rxbuf)) {
727 sc->rx.rxlink = NULL;
728 return NULL;
729 }
730
731 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
732 ds = bf->bf_desc;
733
734 /*
735 * Must provide the virtual address of the current
736 * descriptor, the physical address, and the virtual
737 * address of the next descriptor in the h/w chain.
738 * This allows the HAL to look ahead to see if the
739 * hardware is done with a descriptor by checking the
740 * done bit in the following descriptor and the address
741 * of the current descriptor the DMA engine is working
742 * on. All this is necessary because of our use of
743 * a self-linked list to avoid rx overruns.
744 */
745 ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
746 if (ret == -EINPROGRESS) {
747 struct ath_rx_status trs;
748 struct ath_buf *tbf;
749 struct ath_desc *tds;
750
751 memset(&trs, 0, sizeof(trs));
752 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
753 sc->rx.rxlink = NULL;
754 return NULL;
755 }
756
757 tbf = list_entry(bf->list.next, struct ath_buf, list);
758
759 /*
760 * On some hardware the descriptor status words could
761 * get corrupted, including the done bit. Because of
762 * this, check if the next descriptor's done bit is
763 * set or not.
764 *
765 * If the next descriptor's done bit is set, the current
766 * descriptor has been corrupted. Force s/w to discard
767 * this descriptor and continue...
768 */
769
770 tds = tbf->bf_desc;
771 ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
772 if (ret == -EINPROGRESS)
773 return NULL;
774 }
775
776 if (!bf->bf_mpdu)
777 return bf;
778
779 /*
780 * Synchronize the DMA transfer with CPU before
781 * 1. accessing the frame
782 * 2. requeueing the same buffer to h/w
783 */
Ming Leice9426d2010-05-15 18:25:40 +0800784 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400785 common->rx_bufsize,
786 DMA_FROM_DEVICE);
787
788 return bf;
789}
790
Sujithd4357002010-05-20 15:34:38 +0530791/* Assumes you've already done the endian to CPU conversion */
792static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700793 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530794 struct ieee80211_rx_status *rxs,
795 struct ath_rx_status *rx_stats,
796 bool *decrypt_error)
797{
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530798#define is_mc_or_valid_tkip_keyix ((is_mc || \
799 (rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \
800 test_bit(rx_stats->rs_keyix, common->tkip_keymap))))
801
Sujithd4357002010-05-20 15:34:38 +0530802 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530803 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700804 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530805
Sujithd4357002010-05-20 15:34:38 +0530806 fc = hdr->frame_control;
807
808 if (!rx_stats->rs_datalen)
809 return false;
810 /*
811 * rs_status follows rs_datalen so if rs_datalen is too large
812 * we can take a hint that hardware corrupted it, so ignore
813 * those frames.
814 */
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700815 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
Sujithd4357002010-05-20 15:34:38 +0530816 return false;
817
818 /*
819 * rs_more indicates chained descriptors which can be used
820 * to link buffers together for a sort of scatter-gather
821 * operation.
822 * reject the frame, we don't support scatter-gather yet and
823 * the frame is probably corrupt anyway
824 */
825 if (rx_stats->rs_more)
826 return false;
827
828 /*
829 * The rx_stats->rs_status will not be set until the end of the
830 * chained descriptors so it can be ignored if rs_more is set. The
831 * rs_more will be false at the last element of the chained
832 * descriptors.
833 */
834 if (rx_stats->rs_status != 0) {
835 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
836 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
837 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
838 return false;
839
840 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
841 *decrypt_error = true;
842 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530843 bool is_mc;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200844 /*
845 * The MIC error bit is only valid if the frame
846 * is not a control frame or fragment, and it was
847 * decrypted using a valid TKIP key.
848 */
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530849 is_mc = !!is_multicast_ether_addr(hdr->addr1);
850
Felix Fietkau56363dd2010-08-28 18:21:21 +0200851 if (!ieee80211_is_ctl(fc) &&
852 !ieee80211_has_morefrags(fc) &&
853 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
Senthil Balasubramanian38852b22010-12-06 19:09:27 +0530854 is_mc_or_valid_tkip_keyix)
Sujithd4357002010-05-20 15:34:38 +0530855 rxs->flag |= RX_FLAG_MMIC_ERROR;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200856 else
857 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
Sujithd4357002010-05-20 15:34:38 +0530858 }
859 /*
860 * Reject error frames with the exception of
861 * decryption and MIC failures. For monitor mode,
862 * we also ignore the CRC error.
863 */
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530864 if (ah->is_monitoring) {
Sujithd4357002010-05-20 15:34:38 +0530865 if (rx_stats->rs_status &
866 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
867 ATH9K_RXERR_CRC))
868 return false;
869 } else {
870 if (rx_stats->rs_status &
871 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
872 return false;
873 }
874 }
875 }
876 return true;
877}
878
879static int ath9k_process_rate(struct ath_common *common,
880 struct ieee80211_hw *hw,
881 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700882 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530883{
884 struct ieee80211_supported_band *sband;
885 enum ieee80211_band band;
886 unsigned int i = 0;
887
888 band = hw->conf.channel->band;
889 sband = hw->wiphy->bands[band];
890
891 if (rx_stats->rs_rate & 0x80) {
892 /* HT rate */
893 rxs->flag |= RX_FLAG_HT;
894 if (rx_stats->rs_flags & ATH9K_RX_2040)
895 rxs->flag |= RX_FLAG_40MHZ;
896 if (rx_stats->rs_flags & ATH9K_RX_GI)
897 rxs->flag |= RX_FLAG_SHORT_GI;
898 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
899 return 0;
900 }
901
902 for (i = 0; i < sband->n_bitrates; i++) {
903 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
904 rxs->rate_idx = i;
905 return 0;
906 }
907 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
908 rxs->flag |= RX_FLAG_SHORTPRE;
909 rxs->rate_idx = i;
910 return 0;
911 }
912 }
913
914 /*
915 * No valid hardware bitrate found -- we should not get here
916 * because hardware has already validated this frame as OK.
917 */
Joe Perches226afe62010-12-02 19:12:37 -0800918 ath_dbg(common, ATH_DBG_XMIT,
919 "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
920 rx_stats->rs_rate);
Sujithd4357002010-05-20 15:34:38 +0530921
922 return -EINVAL;
923}
924
925static void ath9k_process_rssi(struct ath_common *common,
926 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700927 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530928 struct ath_rx_status *rx_stats)
929{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100930 struct ath_softc *sc = hw->priv;
Sujithd4357002010-05-20 15:34:38 +0530931 struct ath_hw *ah = common->ah;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200932 int last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530933 __le16 fc;
934
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200935 if (ah->opmode != NL80211_IFTYPE_STATION)
936 return;
937
Sujithd4357002010-05-20 15:34:38 +0530938 fc = hdr->frame_control;
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200939 if (!ieee80211_is_beacon(fc) ||
Ben Greear48014162011-01-15 19:13:48 +0000940 compare_ether_addr(hdr->addr3, common->curbssid)) {
941 /* TODO: This doesn't work well if you have stations
942 * associated to two different APs because curbssid
943 * is just the last AP that any of the stations associated
944 * with.
945 */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200946 return;
Ben Greear48014162011-01-15 19:13:48 +0000947 }
Sujithd4357002010-05-20 15:34:38 +0530948
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200949 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
Felix Fietkau9ac586152011-01-24 19:23:18 +0100950 ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
Ben Greear686b9cb2010-09-23 09:44:36 -0700951
Felix Fietkau9ac586152011-01-24 19:23:18 +0100952 last_rssi = sc->last_rssi;
Sujithd4357002010-05-20 15:34:38 +0530953 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
954 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
955 ATH_RSSI_EP_MULTIPLIER);
956 if (rx_stats->rs_rssi < 0)
957 rx_stats->rs_rssi = 0;
958
959 /* Update Beacon RSSI, this is used by ANI. */
Felix Fietkau9fa23e12010-10-15 20:03:31 +0200960 ah->stats.avgbrssi = rx_stats->rs_rssi;
Sujithd4357002010-05-20 15:34:38 +0530961}
962
963/*
964 * For Decrypt or Demic errors, we only mark packet status here and always push
965 * up the frame up to let mac80211 handle the actual error case, be it no
966 * decryption key or real decryption error. This let us keep statistics there.
967 */
968static int ath9k_rx_skb_preprocess(struct ath_common *common,
969 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700970 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530971 struct ath_rx_status *rx_stats,
972 struct ieee80211_rx_status *rx_status,
973 bool *decrypt_error)
974{
Sujithd4357002010-05-20 15:34:38 +0530975 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
976
977 /*
978 * everything but the rate is checked here, the rate check is done
979 * separately to avoid doing two lookups for a rate for each frame.
980 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700981 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +0530982 return -EINVAL;
983
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700984 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +0530985
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700986 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +0530987 return -EINVAL;
988
Sujithd4357002010-05-20 15:34:38 +0530989 rx_status->band = hw->conf.channel->band;
990 rx_status->freq = hw->conf.channel->center_freq;
991 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
992 rx_status->antenna = rx_stats->rs_antenna;
993 rx_status->flag |= RX_FLAG_TSFT;
994
995 return 0;
996}
997
998static void ath9k_rx_skb_postprocess(struct ath_common *common,
999 struct sk_buff *skb,
1000 struct ath_rx_status *rx_stats,
1001 struct ieee80211_rx_status *rxs,
1002 bool decrypt_error)
1003{
1004 struct ath_hw *ah = common->ah;
1005 struct ieee80211_hdr *hdr;
1006 int hdrlen, padpos, padsize;
1007 u8 keyix;
1008 __le16 fc;
1009
1010 /* see if any padding is done by the hw and remove it */
1011 hdr = (struct ieee80211_hdr *) skb->data;
1012 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1013 fc = hdr->frame_control;
1014 padpos = ath9k_cmn_padpos(hdr->frame_control);
1015
1016 /* The MAC header is padded to have 32-bit boundary if the
1017 * packet payload is non-zero. The general calculation for
1018 * padsize would take into account odd header lengths:
1019 * padsize = (4 - padpos % 4) % 4; However, since only
1020 * even-length headers are used, padding can only be 0 or 2
1021 * bytes and we can optimize this a bit. In addition, we must
1022 * not try to remove padding from short control frames that do
1023 * not have payload. */
1024 padsize = padpos & 3;
1025 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1026 memmove(skb->data + padsize, skb->data, padpos);
1027 skb_pull(skb, padsize);
1028 }
1029
1030 keyix = rx_stats->rs_keyix;
1031
1032 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1033 ieee80211_has_protected(fc)) {
1034 rxs->flag |= RX_FLAG_DECRYPTED;
1035 } else if (ieee80211_has_protected(fc)
1036 && !decrypt_error && skb->len >= hdrlen + 4) {
1037 keyix = skb->data[hdrlen + 3] >> 6;
1038
1039 if (test_bit(keyix, common->keymap))
1040 rxs->flag |= RX_FLAG_DECRYPTED;
1041 }
1042 if (ah->sw_mgmt_crypto &&
1043 (rxs->flag & RX_FLAG_DECRYPTED) &&
1044 ieee80211_is_mgmt(fc))
1045 /* Use software decrypt for management frames. */
1046 rxs->flag &= ~RX_FLAG_DECRYPTED;
1047}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001048
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001049static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
1050 struct ath_hw_antcomb_conf ant_conf,
1051 int main_rssi_avg)
1052{
1053 antcomb->quick_scan_cnt = 0;
1054
1055 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
1056 antcomb->rssi_lna2 = main_rssi_avg;
1057 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
1058 antcomb->rssi_lna1 = main_rssi_avg;
1059
1060 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
1061 case (0x10): /* LNA2 A-B */
1062 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1063 antcomb->first_quick_scan_conf =
1064 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1065 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1066 break;
1067 case (0x20): /* LNA1 A-B */
1068 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1069 antcomb->first_quick_scan_conf =
1070 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1071 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1072 break;
1073 case (0x21): /* LNA1 LNA2 */
1074 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
1075 antcomb->first_quick_scan_conf =
1076 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1077 antcomb->second_quick_scan_conf =
1078 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1079 break;
1080 case (0x12): /* LNA2 LNA1 */
1081 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
1082 antcomb->first_quick_scan_conf =
1083 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1084 antcomb->second_quick_scan_conf =
1085 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1086 break;
1087 case (0x13): /* LNA2 A+B */
1088 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1089 antcomb->first_quick_scan_conf =
1090 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1091 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1092 break;
1093 case (0x23): /* LNA1 A+B */
1094 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1095 antcomb->first_quick_scan_conf =
1096 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1097 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1098 break;
1099 default:
1100 break;
1101 }
1102}
1103
1104static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
1105 struct ath_hw_antcomb_conf *div_ant_conf,
1106 int main_rssi_avg, int alt_rssi_avg,
1107 int alt_ratio)
1108{
1109 /* alt_good */
1110 switch (antcomb->quick_scan_cnt) {
1111 case 0:
1112 /* set alt to main, and alt to first conf */
1113 div_ant_conf->main_lna_conf = antcomb->main_conf;
1114 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
1115 break;
1116 case 1:
1117 /* set alt to main, and alt to first conf */
1118 div_ant_conf->main_lna_conf = antcomb->main_conf;
1119 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
1120 antcomb->rssi_first = main_rssi_avg;
1121 antcomb->rssi_second = alt_rssi_avg;
1122
1123 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1124 /* main is LNA1 */
1125 if (ath_is_alt_ant_ratio_better(alt_ratio,
1126 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1127 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1128 main_rssi_avg, alt_rssi_avg,
1129 antcomb->total_pkt_count))
1130 antcomb->first_ratio = true;
1131 else
1132 antcomb->first_ratio = false;
1133 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1134 if (ath_is_alt_ant_ratio_better(alt_ratio,
1135 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1136 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1137 main_rssi_avg, alt_rssi_avg,
1138 antcomb->total_pkt_count))
1139 antcomb->first_ratio = true;
1140 else
1141 antcomb->first_ratio = false;
1142 } else {
1143 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1144 (alt_rssi_avg > main_rssi_avg +
1145 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1146 (alt_rssi_avg > main_rssi_avg)) &&
1147 (antcomb->total_pkt_count > 50))
1148 antcomb->first_ratio = true;
1149 else
1150 antcomb->first_ratio = false;
1151 }
1152 break;
1153 case 2:
1154 antcomb->alt_good = false;
1155 antcomb->scan_not_start = false;
1156 antcomb->scan = false;
1157 antcomb->rssi_first = main_rssi_avg;
1158 antcomb->rssi_third = alt_rssi_avg;
1159
1160 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
1161 antcomb->rssi_lna1 = alt_rssi_avg;
1162 else if (antcomb->second_quick_scan_conf ==
1163 ATH_ANT_DIV_COMB_LNA2)
1164 antcomb->rssi_lna2 = alt_rssi_avg;
1165 else if (antcomb->second_quick_scan_conf ==
1166 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
1167 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
1168 antcomb->rssi_lna2 = main_rssi_avg;
1169 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
1170 antcomb->rssi_lna1 = main_rssi_avg;
1171 }
1172
1173 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
1174 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
1175 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1176 else
1177 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
1178
1179 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1180 if (ath_is_alt_ant_ratio_better(alt_ratio,
1181 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1182 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1183 main_rssi_avg, alt_rssi_avg,
1184 antcomb->total_pkt_count))
1185 antcomb->second_ratio = true;
1186 else
1187 antcomb->second_ratio = false;
1188 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1189 if (ath_is_alt_ant_ratio_better(alt_ratio,
1190 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1191 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1192 main_rssi_avg, alt_rssi_avg,
1193 antcomb->total_pkt_count))
1194 antcomb->second_ratio = true;
1195 else
1196 antcomb->second_ratio = false;
1197 } else {
1198 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1199 (alt_rssi_avg > main_rssi_avg +
1200 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1201 (alt_rssi_avg > main_rssi_avg)) &&
1202 (antcomb->total_pkt_count > 50))
1203 antcomb->second_ratio = true;
1204 else
1205 antcomb->second_ratio = false;
1206 }
1207
1208 /* set alt to the conf with maximun ratio */
1209 if (antcomb->first_ratio && antcomb->second_ratio) {
1210 if (antcomb->rssi_second > antcomb->rssi_third) {
1211 /* first alt*/
1212 if ((antcomb->first_quick_scan_conf ==
1213 ATH_ANT_DIV_COMB_LNA1) ||
1214 (antcomb->first_quick_scan_conf ==
1215 ATH_ANT_DIV_COMB_LNA2))
1216 /* Set alt LNA1 or LNA2*/
1217 if (div_ant_conf->main_lna_conf ==
1218 ATH_ANT_DIV_COMB_LNA2)
1219 div_ant_conf->alt_lna_conf =
1220 ATH_ANT_DIV_COMB_LNA1;
1221 else
1222 div_ant_conf->alt_lna_conf =
1223 ATH_ANT_DIV_COMB_LNA2;
1224 else
1225 /* Set alt to A+B or A-B */
1226 div_ant_conf->alt_lna_conf =
1227 antcomb->first_quick_scan_conf;
1228 } else if ((antcomb->second_quick_scan_conf ==
1229 ATH_ANT_DIV_COMB_LNA1) ||
1230 (antcomb->second_quick_scan_conf ==
1231 ATH_ANT_DIV_COMB_LNA2)) {
1232 /* Set alt LNA1 or LNA2 */
1233 if (div_ant_conf->main_lna_conf ==
1234 ATH_ANT_DIV_COMB_LNA2)
1235 div_ant_conf->alt_lna_conf =
1236 ATH_ANT_DIV_COMB_LNA1;
1237 else
1238 div_ant_conf->alt_lna_conf =
1239 ATH_ANT_DIV_COMB_LNA2;
1240 } else {
1241 /* Set alt to A+B or A-B */
1242 div_ant_conf->alt_lna_conf =
1243 antcomb->second_quick_scan_conf;
1244 }
1245 } else if (antcomb->first_ratio) {
1246 /* first alt */
1247 if ((antcomb->first_quick_scan_conf ==
1248 ATH_ANT_DIV_COMB_LNA1) ||
1249 (antcomb->first_quick_scan_conf ==
1250 ATH_ANT_DIV_COMB_LNA2))
1251 /* Set alt LNA1 or LNA2 */
1252 if (div_ant_conf->main_lna_conf ==
1253 ATH_ANT_DIV_COMB_LNA2)
1254 div_ant_conf->alt_lna_conf =
1255 ATH_ANT_DIV_COMB_LNA1;
1256 else
1257 div_ant_conf->alt_lna_conf =
1258 ATH_ANT_DIV_COMB_LNA2;
1259 else
1260 /* Set alt to A+B or A-B */
1261 div_ant_conf->alt_lna_conf =
1262 antcomb->first_quick_scan_conf;
1263 } else if (antcomb->second_ratio) {
1264 /* second alt */
1265 if ((antcomb->second_quick_scan_conf ==
1266 ATH_ANT_DIV_COMB_LNA1) ||
1267 (antcomb->second_quick_scan_conf ==
1268 ATH_ANT_DIV_COMB_LNA2))
1269 /* Set alt LNA1 or LNA2 */
1270 if (div_ant_conf->main_lna_conf ==
1271 ATH_ANT_DIV_COMB_LNA2)
1272 div_ant_conf->alt_lna_conf =
1273 ATH_ANT_DIV_COMB_LNA1;
1274 else
1275 div_ant_conf->alt_lna_conf =
1276 ATH_ANT_DIV_COMB_LNA2;
1277 else
1278 /* Set alt to A+B or A-B */
1279 div_ant_conf->alt_lna_conf =
1280 antcomb->second_quick_scan_conf;
1281 } else {
1282 /* main is largest */
1283 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
1284 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
1285 /* Set alt LNA1 or LNA2 */
1286 if (div_ant_conf->main_lna_conf ==
1287 ATH_ANT_DIV_COMB_LNA2)
1288 div_ant_conf->alt_lna_conf =
1289 ATH_ANT_DIV_COMB_LNA1;
1290 else
1291 div_ant_conf->alt_lna_conf =
1292 ATH_ANT_DIV_COMB_LNA2;
1293 else
1294 /* Set alt to A+B or A-B */
1295 div_ant_conf->alt_lna_conf = antcomb->main_conf;
1296 }
1297 break;
1298 default:
1299 break;
1300 }
1301}
1302
John W. Linville9bad82b2010-09-15 15:26:13 -04001303static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001304{
1305 /* Adjust the fast_div_bias based on main and alt lna conf */
1306 switch ((ant_conf->main_lna_conf << 4) | ant_conf->alt_lna_conf) {
1307 case (0x01): /* A-B LNA2 */
1308 ant_conf->fast_div_bias = 0x3b;
1309 break;
1310 case (0x02): /* A-B LNA1 */
1311 ant_conf->fast_div_bias = 0x3d;
1312 break;
1313 case (0x03): /* A-B A+B */
1314 ant_conf->fast_div_bias = 0x1;
1315 break;
1316 case (0x10): /* LNA2 A-B */
1317 ant_conf->fast_div_bias = 0x7;
1318 break;
1319 case (0x12): /* LNA2 LNA1 */
1320 ant_conf->fast_div_bias = 0x2;
1321 break;
1322 case (0x13): /* LNA2 A+B */
1323 ant_conf->fast_div_bias = 0x7;
1324 break;
1325 case (0x20): /* LNA1 A-B */
1326 ant_conf->fast_div_bias = 0x6;
1327 break;
1328 case (0x21): /* LNA1 LNA2 */
1329 ant_conf->fast_div_bias = 0x0;
1330 break;
1331 case (0x23): /* LNA1 A+B */
1332 ant_conf->fast_div_bias = 0x6;
1333 break;
1334 case (0x30): /* A+B A-B */
1335 ant_conf->fast_div_bias = 0x1;
1336 break;
1337 case (0x31): /* A+B LNA2 */
1338 ant_conf->fast_div_bias = 0x3b;
1339 break;
1340 case (0x32): /* A+B LNA1 */
1341 ant_conf->fast_div_bias = 0x3d;
1342 break;
1343 default:
1344 break;
1345 }
1346}
1347
1348/* Antenna diversity and combining */
1349static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
1350{
1351 struct ath_hw_antcomb_conf div_ant_conf;
1352 struct ath_ant_comb *antcomb = &sc->ant_comb;
1353 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
1354 int curr_main_set, curr_bias;
1355 int main_rssi = rs->rs_rssi_ctl0;
1356 int alt_rssi = rs->rs_rssi_ctl1;
1357 int rx_ant_conf, main_ant_conf;
1358 bool short_scan = false;
1359
1360 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
1361 ATH_ANT_RX_MASK;
1362 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
1363 ATH_ANT_RX_MASK;
1364
1365 /* Record packet only when alt_rssi is positive */
1366 if (alt_rssi > 0) {
1367 antcomb->total_pkt_count++;
1368 antcomb->main_total_rssi += main_rssi;
1369 antcomb->alt_total_rssi += alt_rssi;
1370 if (main_ant_conf == rx_ant_conf)
1371 antcomb->main_recv_cnt++;
1372 else
1373 antcomb->alt_recv_cnt++;
1374 }
1375
1376 /* Short scan check */
1377 if (antcomb->scan && antcomb->alt_good) {
1378 if (time_after(jiffies, antcomb->scan_start_time +
1379 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
1380 short_scan = true;
1381 else
1382 if (antcomb->total_pkt_count ==
1383 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
1384 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1385 antcomb->total_pkt_count);
1386 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
1387 short_scan = true;
1388 }
1389 }
1390
1391 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
1392 rs->rs_moreaggr) && !short_scan)
1393 return;
1394
1395 if (antcomb->total_pkt_count) {
1396 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1397 antcomb->total_pkt_count);
1398 main_rssi_avg = (antcomb->main_total_rssi /
1399 antcomb->total_pkt_count);
1400 alt_rssi_avg = (antcomb->alt_total_rssi /
1401 antcomb->total_pkt_count);
1402 }
1403
1404
1405 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
1406 curr_alt_set = div_ant_conf.alt_lna_conf;
1407 curr_main_set = div_ant_conf.main_lna_conf;
1408 curr_bias = div_ant_conf.fast_div_bias;
1409
1410 antcomb->count++;
1411
1412 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1413 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1414 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1415 main_rssi_avg);
1416 antcomb->alt_good = true;
1417 } else {
1418 antcomb->alt_good = false;
1419 }
1420
1421 antcomb->count = 0;
1422 antcomb->scan = true;
1423 antcomb->scan_not_start = true;
1424 }
1425
1426 if (!antcomb->scan) {
1427 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1428 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1429 /* Switch main and alt LNA */
1430 div_ant_conf.main_lna_conf =
1431 ATH_ANT_DIV_COMB_LNA2;
1432 div_ant_conf.alt_lna_conf =
1433 ATH_ANT_DIV_COMB_LNA1;
1434 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1435 div_ant_conf.main_lna_conf =
1436 ATH_ANT_DIV_COMB_LNA1;
1437 div_ant_conf.alt_lna_conf =
1438 ATH_ANT_DIV_COMB_LNA2;
1439 }
1440
1441 goto div_comb_done;
1442 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1443 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1444 /* Set alt to another LNA */
1445 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1446 div_ant_conf.alt_lna_conf =
1447 ATH_ANT_DIV_COMB_LNA1;
1448 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1449 div_ant_conf.alt_lna_conf =
1450 ATH_ANT_DIV_COMB_LNA2;
1451
1452 goto div_comb_done;
1453 }
1454
1455 if ((alt_rssi_avg < (main_rssi_avg +
1456 ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA)))
1457 goto div_comb_done;
1458 }
1459
1460 if (!antcomb->scan_not_start) {
1461 switch (curr_alt_set) {
1462 case ATH_ANT_DIV_COMB_LNA2:
1463 antcomb->rssi_lna2 = alt_rssi_avg;
1464 antcomb->rssi_lna1 = main_rssi_avg;
1465 antcomb->scan = true;
1466 /* set to A+B */
1467 div_ant_conf.main_lna_conf =
1468 ATH_ANT_DIV_COMB_LNA1;
1469 div_ant_conf.alt_lna_conf =
1470 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1471 break;
1472 case ATH_ANT_DIV_COMB_LNA1:
1473 antcomb->rssi_lna1 = alt_rssi_avg;
1474 antcomb->rssi_lna2 = main_rssi_avg;
1475 antcomb->scan = true;
1476 /* set to A+B */
1477 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1478 div_ant_conf.alt_lna_conf =
1479 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1480 break;
1481 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1482 antcomb->rssi_add = alt_rssi_avg;
1483 antcomb->scan = true;
1484 /* set to A-B */
1485 div_ant_conf.alt_lna_conf =
1486 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1487 break;
1488 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1489 antcomb->rssi_sub = alt_rssi_avg;
1490 antcomb->scan = false;
1491 if (antcomb->rssi_lna2 >
1492 (antcomb->rssi_lna1 +
1493 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1494 /* use LNA2 as main LNA */
1495 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1496 (antcomb->rssi_add > antcomb->rssi_sub)) {
1497 /* set to A+B */
1498 div_ant_conf.main_lna_conf =
1499 ATH_ANT_DIV_COMB_LNA2;
1500 div_ant_conf.alt_lna_conf =
1501 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1502 } else if (antcomb->rssi_sub >
1503 antcomb->rssi_lna1) {
1504 /* set to A-B */
1505 div_ant_conf.main_lna_conf =
1506 ATH_ANT_DIV_COMB_LNA2;
1507 div_ant_conf.alt_lna_conf =
1508 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1509 } else {
1510 /* set to LNA1 */
1511 div_ant_conf.main_lna_conf =
1512 ATH_ANT_DIV_COMB_LNA2;
1513 div_ant_conf.alt_lna_conf =
1514 ATH_ANT_DIV_COMB_LNA1;
1515 }
1516 } else {
1517 /* use LNA1 as main LNA */
1518 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1519 (antcomb->rssi_add > antcomb->rssi_sub)) {
1520 /* set to A+B */
1521 div_ant_conf.main_lna_conf =
1522 ATH_ANT_DIV_COMB_LNA1;
1523 div_ant_conf.alt_lna_conf =
1524 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1525 } else if (antcomb->rssi_sub >
1526 antcomb->rssi_lna1) {
1527 /* set to A-B */
1528 div_ant_conf.main_lna_conf =
1529 ATH_ANT_DIV_COMB_LNA1;
1530 div_ant_conf.alt_lna_conf =
1531 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1532 } else {
1533 /* set to LNA2 */
1534 div_ant_conf.main_lna_conf =
1535 ATH_ANT_DIV_COMB_LNA1;
1536 div_ant_conf.alt_lna_conf =
1537 ATH_ANT_DIV_COMB_LNA2;
1538 }
1539 }
1540 break;
1541 default:
1542 break;
1543 }
1544 } else {
1545 if (!antcomb->alt_good) {
1546 antcomb->scan_not_start = false;
1547 /* Set alt to another LNA */
1548 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1549 div_ant_conf.main_lna_conf =
1550 ATH_ANT_DIV_COMB_LNA2;
1551 div_ant_conf.alt_lna_conf =
1552 ATH_ANT_DIV_COMB_LNA1;
1553 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1554 div_ant_conf.main_lna_conf =
1555 ATH_ANT_DIV_COMB_LNA1;
1556 div_ant_conf.alt_lna_conf =
1557 ATH_ANT_DIV_COMB_LNA2;
1558 }
1559 goto div_comb_done;
1560 }
1561 }
1562
1563 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1564 main_rssi_avg, alt_rssi_avg,
1565 alt_ratio);
1566
1567 antcomb->quick_scan_cnt++;
1568
1569div_comb_done:
1570 ath_ant_div_conf_fast_divbias(&div_ant_conf);
1571
1572 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1573
1574 antcomb->scan_start_time = jiffies;
1575 antcomb->total_pkt_count = 0;
1576 antcomb->main_total_rssi = 0;
1577 antcomb->alt_total_rssi = 0;
1578 antcomb->main_recv_cnt = 0;
1579 antcomb->alt_recv_cnt = 0;
1580}
1581
Felix Fietkaub5c804752010-04-15 17:38:48 -04001582int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1583{
1584 struct ath_buf *bf;
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001585 struct sk_buff *skb = NULL, *requeue_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001586 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301587 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001588 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001589 /*
Mohammed Shafi Shajakhancae6b742010-12-07 21:23:16 +05301590 * The hw can technically differ from common->hw when using ath9k
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001591 * virtual wiphy so to account for that we iterate over the active
1592 * wiphys and find the appropriate wiphy and therefore hw.
1593 */
Felix Fietkau7545daf2011-01-24 19:23:16 +01001594 struct ieee80211_hw *hw = sc->hw;
Sujithbe0418a2008-11-18 09:05:55 +05301595 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001596 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301597 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001598 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001599 enum ath9k_rx_qtype qtype;
1600 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1601 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001602 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001603 u64 tsf = 0;
1604 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001605 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301606
Felix Fietkaub5c804752010-04-15 17:38:48 -04001607 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001608 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001609 else
1610 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001611
1612 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301613 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001614
Felix Fietkaua6d20552010-06-12 00:33:54 -04001615 tsf = ath9k_hw_gettsf64(ah);
1616 tsf_lower = tsf & 0xffffffff;
1617
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001618 do {
1619 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +05301620 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001621 break;
1622
Felix Fietkau29bffa92010-03-29 20:14:23 -07001623 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001624 if (edma)
1625 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1626 else
1627 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001628
Felix Fietkaub5c804752010-04-15 17:38:48 -04001629 if (!bf)
1630 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001631
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001632 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301633 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001634 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001635
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001636 hdr = (struct ieee80211_hdr *) (skb->data + rx_status_len);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001637 rxs = IEEE80211_SKB_RXCB(skb);
1638
Felix Fietkau29bffa92010-03-29 20:14:23 -07001639 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301640
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301641 /*
Sujithbe0418a2008-11-18 09:05:55 +05301642 * If we're asked to flush receive queue, directly
1643 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001644 */
Sujithbe0418a2008-11-18 09:05:55 +05301645 if (flush)
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001646 goto requeue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001647
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001648 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1649 rxs, &decrypt_error);
1650 if (retval)
1651 goto requeue;
1652
Felix Fietkaua6d20552010-06-12 00:33:54 -04001653 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1654 if (rs.rs_tstamp > tsf_lower &&
1655 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1656 rxs->mactime -= 0x100000000ULL;
1657
1658 if (rs.rs_tstamp < tsf_lower &&
1659 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1660 rxs->mactime += 0x100000000ULL;
1661
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001662 /* Ensure we always have an skb to requeue once we are done
1663 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001664 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001665
1666 /* If there is no memory we ignore the current RX'd frame,
1667 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301668 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001669 * processing. */
1670 if (!requeue_skb)
1671 goto requeue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001672
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301673 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001674 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001675 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001676 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001677
Felix Fietkaub5c804752010-04-15 17:38:48 -04001678 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1679 if (ah->caps.rx_status_len)
1680 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301681
Sujithd4357002010-05-20 15:34:38 +05301682 ath9k_rx_skb_postprocess(common, skb, &rs,
1683 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301684
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001685 /* We will now give hardware our shiny new allocated skb */
1686 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001687 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001688 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001689 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001690 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001691 bf->bf_buf_addr))) {
1692 dev_kfree_skb_any(requeue_skb);
1693 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07001694 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08001695 ath_err(common, "dma_mapping_error() on RX\n");
Felix Fietkau7545daf2011-01-24 19:23:16 +01001696 ieee80211_rx(hw, skb);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001697 break;
1698 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001699
1700 /*
1701 * change the default rx antenna if rx diversity chooses the
1702 * other antenna 3 times in a row.
1703 */
Felix Fietkau29bffa92010-03-29 20:14:23 -07001704 if (sc->rx.defant != rs.rs_antenna) {
Sujithb77f4832008-12-07 21:44:03 +05301705 if (++sc->rx.rxotherant >= 3)
Felix Fietkau29bffa92010-03-29 20:14:23 -07001706 ath_setdefantenna(sc, rs.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001707 } else {
Sujithb77f4832008-12-07 21:44:03 +05301708 sc->rx.rxotherant = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001709 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301710
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001711 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301712
1713 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -07001714 PS_WAIT_FOR_CAB |
Mohammed Shafi Shajakhanaaef24b2010-12-07 20:40:58 +05301715 PS_WAIT_FOR_PSPOLL_DATA)) ||
1716 unlikely(ath9k_check_auto_sleep(sc)))
Jouni Malinencc659652009-05-14 21:28:48 +03001717 ath_rx_ps(sc, skb);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001718 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001719
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001720 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
1721 ath_ant_comb_scan(sc, &rs);
1722
Felix Fietkau7545daf2011-01-24 19:23:16 +01001723 ieee80211_rx(hw, skb);
Jouni Malinencc659652009-05-14 21:28:48 +03001724
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001725requeue:
Felix Fietkaub5c804752010-04-15 17:38:48 -04001726 if (edma) {
1727 list_add_tail(&bf->list, &sc->rx.rxbuf);
1728 ath_rx_edma_buf_link(sc, qtype);
1729 } else {
1730 list_move_tail(&bf->list, &sc->rx.rxbuf);
1731 ath_rx_buf_link(sc, bf);
1732 }
Sujithbe0418a2008-11-18 09:05:55 +05301733 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734
Sujithb77f4832008-12-07 21:44:03 +05301735 spin_unlock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736
1737 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001738}