blob: 2e427522672deacf20d7cfe48abddbc91da6ad34 [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
Jouni Malinenbce048d2009-03-03 19:23:28 +020037static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc,
38 struct ieee80211_hdr *hdr)
39{
Jouni Malinenc52f33d2009-03-03 19:23:29 +020040 struct ieee80211_hw *hw = sc->pri_wiphy->hw;
41 int i;
42
43 spin_lock_bh(&sc->wiphy_lock);
44 for (i = 0; i < sc->num_sec_wiphy; i++) {
45 struct ath_wiphy *aphy = sc->sec_wiphy[i];
46 if (aphy == NULL)
47 continue;
48 if (compare_ether_addr(hdr->addr1, aphy->hw->wiphy->perm_addr)
49 == 0) {
50 hw = aphy->hw;
51 break;
52 }
53 }
54 spin_unlock_bh(&sc->wiphy_lock);
55 return hw;
Jouni Malinenbce048d2009-03-03 19:23:28 +020056}
57
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070058/*
59 * Setup and link descriptors.
60 *
61 * 11N: we can no longer afford to self link the last descriptor.
62 * MAC acknowledges BA status as long as it copies frames to host
63 * buffer (or rx fifo). This can incorrectly acknowledge packets
64 * to a sender if last desc is self-linked.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070065 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
67{
Sujithcbe61d82009-02-09 13:27:12 +053068 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080069 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070 struct ath_desc *ds;
71 struct sk_buff *skb;
72
73 ATH_RXBUF_RESET(bf);
74
75 ds = bf->bf_desc;
Sujithbe0418a2008-11-18 09:05:55 +053076 ds->ds_link = 0; /* link to null */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070077 ds->ds_data = bf->bf_buf_addr;
78
Sujithbe0418a2008-11-18 09:05:55 +053079 /* virtual addr of the beginning of the buffer. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070080 skb = bf->bf_mpdu;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -070081 BUG_ON(skb == NULL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070082 ds->ds_vdata = skb->data;
83
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080084 /*
85 * setup rx descriptors. The rx_bufsize here tells the hardware
Luis R. Rodriguezb4b6cda2008-11-20 17:15:13 -080086 * how much data it can DMA to us and that we are prepared
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080087 * to process
88 */
Sujithb77f4832008-12-07 21:44:03 +053089 ath9k_hw_setuprxdesc(ah, ds,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -080090 common->rx_bufsize,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070091 0);
92
Sujithb77f4832008-12-07 21:44:03 +053093 if (sc->rx.rxlink == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
95 else
Sujithb77f4832008-12-07 21:44:03 +053096 *sc->rx.rxlink = bf->bf_daddr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070097
Sujithb77f4832008-12-07 21:44:03 +053098 sc->rx.rxlink = &ds->ds_link;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099 ath9k_hw_rxena(ah);
100}
101
Sujithff37e332008-11-24 12:07:55 +0530102static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
103{
104 /* XXX block beacon interrupts */
105 ath9k_hw_setantenna(sc->sc_ah, antenna);
Sujithb77f4832008-12-07 21:44:03 +0530106 sc->rx.defant = antenna;
107 sc->rx.rxotherant = 0;
Sujithff37e332008-11-24 12:07:55 +0530108}
109
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700110static void ath_opmode_init(struct ath_softc *sc)
111{
Sujithcbe61d82009-02-09 13:27:12 +0530112 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700113 struct ath_common *common = ath9k_hw_common(ah);
114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 u32 rfilt, mfilt[2];
116
117 /* configure rx filter */
118 rfilt = ath_calcrxfilter(sc);
119 ath9k_hw_setrxfilter(ah, rfilt);
120
121 /* configure bssid mask */
Felix Fietkau364734f2010-09-14 20:22:44 +0200122 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700123
124 /* configure operational mode */
125 ath9k_hw_setopmode(ah);
126
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700127 /* calculate and install multicast filter */
128 mfilt[0] = mfilt[1] = ~0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700129 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700130}
131
Felix Fietkaub5c804752010-04-15 17:38:48 -0400132static bool ath_rx_edma_buf_link(struct ath_softc *sc,
133 enum ath9k_rx_qtype qtype)
134{
135 struct ath_hw *ah = sc->sc_ah;
136 struct ath_rx_edma *rx_edma;
137 struct sk_buff *skb;
138 struct ath_buf *bf;
139
140 rx_edma = &sc->rx.rx_edma[qtype];
141 if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
142 return false;
143
144 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
145 list_del_init(&bf->list);
146
147 skb = bf->bf_mpdu;
148
149 ATH_RXBUF_RESET(bf);
150 memset(skb->data, 0, ah->caps.rx_status_len);
151 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
152 ah->caps.rx_status_len, DMA_TO_DEVICE);
153
154 SKB_CB_ATHBUF(skb) = bf;
155 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
156 skb_queue_tail(&rx_edma->rx_fifo, skb);
157
158 return true;
159}
160
161static void ath_rx_addbuffer_edma(struct ath_softc *sc,
162 enum ath9k_rx_qtype qtype, int size)
163{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400164 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
165 u32 nbuf = 0;
166
Felix Fietkaub5c804752010-04-15 17:38:48 -0400167 if (list_empty(&sc->rx.rxbuf)) {
168 ath_print(common, ATH_DBG_QUEUE, "No free rx buf available\n");
169 return;
170 }
171
172 while (!list_empty(&sc->rx.rxbuf)) {
173 nbuf++;
174
175 if (!ath_rx_edma_buf_link(sc, qtype))
176 break;
177
178 if (nbuf >= size)
179 break;
180 }
181}
182
183static void ath_rx_remove_buffer(struct ath_softc *sc,
184 enum ath9k_rx_qtype qtype)
185{
186 struct ath_buf *bf;
187 struct ath_rx_edma *rx_edma;
188 struct sk_buff *skb;
189
190 rx_edma = &sc->rx.rx_edma[qtype];
191
192 while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
193 bf = SKB_CB_ATHBUF(skb);
194 BUG_ON(!bf);
195 list_add_tail(&bf->list, &sc->rx.rxbuf);
196 }
197}
198
199static void ath_rx_edma_cleanup(struct ath_softc *sc)
200{
201 struct ath_buf *bf;
202
203 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
204 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
205
206 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
207 if (bf->bf_mpdu)
208 dev_kfree_skb_any(bf->bf_mpdu);
209 }
210
211 INIT_LIST_HEAD(&sc->rx.rxbuf);
212
213 kfree(sc->rx.rx_bufptr);
214 sc->rx.rx_bufptr = NULL;
215}
216
217static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
218{
219 skb_queue_head_init(&rx_edma->rx_fifo);
220 skb_queue_head_init(&rx_edma->rx_buffers);
221 rx_edma->rx_fifo_hwsize = size;
222}
223
224static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
225{
226 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
227 struct ath_hw *ah = sc->sc_ah;
228 struct sk_buff *skb;
229 struct ath_buf *bf;
230 int error = 0, i;
231 u32 size;
232
233
234 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN +
235 ah->caps.rx_status_len,
236 min(common->cachelsz, (u16)64));
237
238 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
239 ah->caps.rx_status_len);
240
241 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
242 ah->caps.rx_lp_qdepth);
243 ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
244 ah->caps.rx_hp_qdepth);
245
246 size = sizeof(struct ath_buf) * nbufs;
247 bf = kzalloc(size, GFP_KERNEL);
248 if (!bf)
249 return -ENOMEM;
250
251 INIT_LIST_HEAD(&sc->rx.rxbuf);
252 sc->rx.rx_bufptr = bf;
253
254 for (i = 0; i < nbufs; i++, bf++) {
255 skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
256 if (!skb) {
257 error = -ENOMEM;
258 goto rx_init_fail;
259 }
260
261 memset(skb->data, 0, common->rx_bufsize);
262 bf->bf_mpdu = skb;
263
264 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
265 common->rx_bufsize,
266 DMA_BIDIRECTIONAL);
267 if (unlikely(dma_mapping_error(sc->dev,
268 bf->bf_buf_addr))) {
269 dev_kfree_skb_any(skb);
270 bf->bf_mpdu = NULL;
271 ath_print(common, ATH_DBG_FATAL,
272 "dma_mapping_error() on RX init\n");
273 error = -ENOMEM;
274 goto rx_init_fail;
275 }
276
277 list_add_tail(&bf->list, &sc->rx.rxbuf);
278 }
279
280 return 0;
281
282rx_init_fail:
283 ath_rx_edma_cleanup(sc);
284 return error;
285}
286
287static void ath_edma_start_recv(struct ath_softc *sc)
288{
289 spin_lock_bh(&sc->rx.rxbuflock);
290
291 ath9k_hw_rxena(sc->sc_ah);
292
293 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP,
294 sc->rx.rx_edma[ATH9K_RX_QUEUE_HP].rx_fifo_hwsize);
295
296 ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP,
297 sc->rx.rx_edma[ATH9K_RX_QUEUE_LP].rx_fifo_hwsize);
298
299 spin_unlock_bh(&sc->rx.rxbuflock);
300
301 ath_opmode_init(sc);
302
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400303 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Felix Fietkaub5c804752010-04-15 17:38:48 -0400304}
305
306static void ath_edma_stop_recv(struct ath_softc *sc)
307{
308 spin_lock_bh(&sc->rx.rxbuflock);
309 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
310 ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
311 spin_unlock_bh(&sc->rx.rxbuflock);
312}
313
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700314int ath_rx_init(struct ath_softc *sc, int nbufs)
315{
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -0700316 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700317 struct sk_buff *skb;
318 struct ath_buf *bf;
319 int error = 0;
320
Sujith797fe5cb2009-03-30 15:28:45 +0530321 spin_lock_init(&sc->rx.rxflushlock);
322 sc->sc_flags &= ~SC_OP_RXFLUSH;
323 spin_lock_init(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700324
Felix Fietkaub5c804752010-04-15 17:38:48 -0400325 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
326 return ath_rx_edma_init(sc, nbufs);
327 } else {
328 common->rx_bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
329 min(common->cachelsz, (u16)64));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700330
Felix Fietkaub5c804752010-04-15 17:38:48 -0400331 ath_print(common, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
332 common->cachelsz, common->rx_bufsize);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700333
Felix Fietkaub5c804752010-04-15 17:38:48 -0400334 /* Initialize rx descriptors */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335
Felix Fietkaub5c804752010-04-15 17:38:48 -0400336 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400337 "rx", nbufs, 1, 0);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400338 if (error != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700339 ath_print(common, ATH_DBG_FATAL,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400340 "failed to allocate rx descriptors: %d\n",
341 error);
Sujith797fe5cb2009-03-30 15:28:45 +0530342 goto err;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700343 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400344
345 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
346 skb = ath_rxbuf_alloc(common, common->rx_bufsize,
347 GFP_KERNEL);
348 if (skb == NULL) {
349 error = -ENOMEM;
350 goto err;
351 }
352
353 bf->bf_mpdu = skb;
354 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
355 common->rx_bufsize,
356 DMA_FROM_DEVICE);
357 if (unlikely(dma_mapping_error(sc->dev,
358 bf->bf_buf_addr))) {
359 dev_kfree_skb_any(skb);
360 bf->bf_mpdu = NULL;
361 ath_print(common, ATH_DBG_FATAL,
362 "dma_mapping_error() on RX init\n");
363 error = -ENOMEM;
364 goto err;
365 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400366 }
367 sc->rx.rxlink = NULL;
Sujith797fe5cb2009-03-30 15:28:45 +0530368 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700369
Sujith797fe5cb2009-03-30 15:28:45 +0530370err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700371 if (error)
372 ath_rx_cleanup(sc);
373
374 return error;
375}
376
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377void ath_rx_cleanup(struct ath_softc *sc)
378{
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -0800379 struct ath_hw *ah = sc->sc_ah;
380 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 struct sk_buff *skb;
382 struct ath_buf *bf;
383
Felix Fietkaub5c804752010-04-15 17:38:48 -0400384 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
385 ath_rx_edma_cleanup(sc);
386 return;
387 } else {
388 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
389 skb = bf->bf_mpdu;
390 if (skb) {
391 dma_unmap_single(sc->dev, bf->bf_buf_addr,
392 common->rx_bufsize,
393 DMA_FROM_DEVICE);
394 dev_kfree_skb(skb);
395 }
Luis R. Rodriguez051b9192009-03-23 18:25:01 -0400396 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397
Felix Fietkaub5c804752010-04-15 17:38:48 -0400398 if (sc->rx.rxdma.dd_desc_len != 0)
399 ath_descdma_cleanup(sc, &sc->rx.rxdma, &sc->rx.rxbuf);
400 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401}
402
403/*
404 * Calculate the receive filter according to the
405 * operating mode and state:
406 *
407 * o always accept unicast, broadcast, and multicast traffic
408 * o maintain current state of phy error reception (the hal
409 * may enable phy error frames for noise immunity work)
410 * o probe request frames are accepted only when operating in
411 * hostap, adhoc, or monitor modes
412 * o enable promiscuous mode according to the interface state
413 * o accept beacons:
414 * - when operating in adhoc mode so the 802.11 layer creates
415 * node table entries for peers,
416 * - when operating in station mode for collecting rssi data when
417 * the station is otherwise quiet, or
418 * - when operating as a repeater so we see repeater-sta beacons
419 * - when scanning
420 */
421
422u32 ath_calcrxfilter(struct ath_softc *sc)
423{
424#define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
Sujith7dcfdcd2008-08-11 14:03:13 +0530425
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426 u32 rfilt;
427
428 rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
429 | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
430 | ATH9K_RX_FILTER_MCAST;
431
Jouni Malinen9c1d8e42010-10-13 17:29:31 +0300432 if (sc->rx.rxfilter & FIF_PROBE_REQ)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433 rfilt |= ATH9K_RX_FILTER_PROBEREQ;
434
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200435 /*
436 * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
437 * mode interface or when in monitor mode. AP mode does not need this
438 * since it receives all in-BSS frames anyway.
439 */
Sujith2660b812009-02-09 13:27:26 +0530440 if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) &&
Sujithb77f4832008-12-07 21:44:03 +0530441 (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
Jouni Malinen217ba9d2009-03-10 10:55:50 +0200442 (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700443 rfilt |= ATH9K_RX_FILTER_PROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444
Sujithd42c6b72009-02-04 08:10:22 +0530445 if (sc->rx.rxfilter & FIF_CONTROL)
446 rfilt |= ATH9K_RX_FILTER_CONTROL;
447
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530448 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
Ben Greearcfda6692010-09-14 12:00:22 -0700449 (sc->nvifs <= 1) &&
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530450 !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
451 rfilt |= ATH9K_RX_FILTER_MYBEACON;
452 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453 rfilt |= ATH9K_RX_FILTER_BEACON;
454
Felix Fietkau7a370812010-09-22 12:34:52 +0200455 if ((AR_SREV_9280_20_OR_LATER(sc->sc_ah) ||
Felix Fietkaue17f83e2010-09-22 12:34:53 +0200456 AR_SREV_9285_12_OR_LATER(sc->sc_ah)) &&
Senthil Balasubramanian66afad02009-09-18 15:06:07 +0530457 (sc->sc_ah->opmode == NL80211_IFTYPE_AP) &&
458 (sc->rx.rxfilter & FIF_PSPOLL))
Vasanthakumar Thiagarajandbaaa142009-02-19 15:41:52 +0530459 rfilt |= ATH9K_RX_FILTER_PSPOLL;
Sujithbe0418a2008-11-18 09:05:55 +0530460
Sujith7ea310b2009-09-03 12:08:43 +0530461 if (conf_is_ht(&sc->hw->conf))
462 rfilt |= ATH9K_RX_FILTER_COMP_BAR;
463
Ben Greearcfda6692010-09-14 12:00:22 -0700464 if (sc->sec_wiphy || (sc->nvifs > 1) ||
465 (sc->rx.rxfilter & FIF_OTHER_BSS)) {
Javier Cardona5eb6ba82009-08-20 19:12:07 -0700466 /* The following may also be needed for other older chips */
467 if (sc->sc_ah->hw_version.macVersion == AR_SREV_VERSION_9160)
468 rfilt |= ATH9K_RX_FILTER_PROM;
Jouni Malinenb93bce22009-03-03 19:23:30 +0200469 rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
470 }
471
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 return rfilt;
Sujith7dcfdcd2008-08-11 14:03:13 +0530473
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474#undef RX_FILTER_PRESERVE
475}
476
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477int ath_startrecv(struct ath_softc *sc)
478{
Sujithcbe61d82009-02-09 13:27:12 +0530479 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480 struct ath_buf *bf, *tbf;
481
Felix Fietkaub5c804752010-04-15 17:38:48 -0400482 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
483 ath_edma_start_recv(sc);
484 return 0;
485 }
486
Sujithb77f4832008-12-07 21:44:03 +0530487 spin_lock_bh(&sc->rx.rxbuflock);
488 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700489 goto start_recv;
490
Sujithb77f4832008-12-07 21:44:03 +0530491 sc->rx.rxlink = NULL;
492 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700493 ath_rx_buf_link(sc, bf);
494 }
495
496 /* We could have deleted elements so the list may be empty now */
Sujithb77f4832008-12-07 21:44:03 +0530497 if (list_empty(&sc->rx.rxbuf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700498 goto start_recv;
499
Sujithb77f4832008-12-07 21:44:03 +0530500 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
Sujithbe0418a2008-11-18 09:05:55 +0530502 ath9k_hw_rxena(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503
504start_recv:
Sujithb77f4832008-12-07 21:44:03 +0530505 spin_unlock_bh(&sc->rx.rxbuflock);
Sujithbe0418a2008-11-18 09:05:55 +0530506 ath_opmode_init(sc);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400507 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
Sujithbe0418a2008-11-18 09:05:55 +0530508
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700509 return 0;
510}
511
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700512bool ath_stoprecv(struct ath_softc *sc)
513{
Sujithcbe61d82009-02-09 13:27:12 +0530514 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700515 bool stopped;
516
Sujithbe0418a2008-11-18 09:05:55 +0530517 ath9k_hw_stoppcurecv(ah);
518 ath9k_hw_setrxfilter(ah, 0);
519 stopped = ath9k_hw_stopdmarecv(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400520
521 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
522 ath_edma_stop_recv(sc);
523 else
524 sc->rx.rxlink = NULL;
Sujithbe0418a2008-11-18 09:05:55 +0530525
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700526 return stopped;
527}
528
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700529void ath_flushrecv(struct ath_softc *sc)
530{
Sujithb77f4832008-12-07 21:44:03 +0530531 spin_lock_bh(&sc->rx.rxflushlock);
Sujith98deeea2008-08-11 14:05:46 +0530532 sc->sc_flags |= SC_OP_RXFLUSH;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400533 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
534 ath_rx_tasklet(sc, 1, true);
535 ath_rx_tasklet(sc, 1, false);
Sujith98deeea2008-08-11 14:05:46 +0530536 sc->sc_flags &= ~SC_OP_RXFLUSH;
Sujithb77f4832008-12-07 21:44:03 +0530537 spin_unlock_bh(&sc->rx.rxflushlock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700538}
539
Jouni Malinencc659652009-05-14 21:28:48 +0300540static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
541{
542 /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
543 struct ieee80211_mgmt *mgmt;
544 u8 *pos, *end, id, elen;
545 struct ieee80211_tim_ie *tim;
546
547 mgmt = (struct ieee80211_mgmt *)skb->data;
548 pos = mgmt->u.beacon.variable;
549 end = skb->data + skb->len;
550
551 while (pos + 2 < end) {
552 id = *pos++;
553 elen = *pos++;
554 if (pos + elen > end)
555 break;
556
557 if (id == WLAN_EID_TIM) {
558 if (elen < sizeof(*tim))
559 break;
560 tim = (struct ieee80211_tim_ie *) pos;
561 if (tim->dtim_count != 0)
562 break;
563 return tim->bitmap_ctrl & 0x01;
564 }
565
566 pos += elen;
567 }
568
569 return false;
570}
571
Jouni Malinencc659652009-05-14 21:28:48 +0300572static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
573{
574 struct ieee80211_mgmt *mgmt;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700575 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300576
577 if (skb->len < 24 + 8 + 2 + 2)
578 return;
579
580 mgmt = (struct ieee80211_mgmt *)skb->data;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700581 if (memcmp(common->curbssid, mgmt->bssid, ETH_ALEN) != 0)
Jouni Malinencc659652009-05-14 21:28:48 +0300582 return; /* not from our current AP */
583
Sujith1b04b932010-01-08 10:36:05 +0530584 sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
Gabor Juhos293dc5d2009-06-19 12:17:48 +0200585
Sujith1b04b932010-01-08 10:36:05 +0530586 if (sc->ps_flags & PS_BEACON_SYNC) {
587 sc->ps_flags &= ~PS_BEACON_SYNC;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700588 ath_print(common, ATH_DBG_PS,
589 "Reconfigure Beacon timers based on "
590 "timestamp from the AP\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300591 ath_beacon_config(sc, NULL);
592 }
593
Jouni Malinencc659652009-05-14 21:28:48 +0300594 if (ath_beacon_dtim_pending_cab(skb)) {
595 /*
596 * Remain awake waiting for buffered broadcast/multicast
Gabor Juhos58f5fff2009-06-17 20:53:20 +0200597 * frames. If the last broadcast/multicast frame is not
598 * received properly, the next beacon frame will work as
599 * a backup trigger for returning into NETWORK SLEEP state,
600 * so we are waiting for it as well.
Jouni Malinencc659652009-05-14 21:28:48 +0300601 */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700602 ath_print(common, ATH_DBG_PS, "Received DTIM beacon indicating "
603 "buffered broadcast/multicast frame(s)\n");
Sujith1b04b932010-01-08 10:36:05 +0530604 sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
Jouni Malinencc659652009-05-14 21:28:48 +0300605 return;
606 }
607
Sujith1b04b932010-01-08 10:36:05 +0530608 if (sc->ps_flags & PS_WAIT_FOR_CAB) {
Jouni Malinencc659652009-05-14 21:28:48 +0300609 /*
610 * This can happen if a broadcast frame is dropped or the AP
611 * fails to send a frame indicating that all CAB frames have
612 * been delivered.
613 */
Sujith1b04b932010-01-08 10:36:05 +0530614 sc->ps_flags &= ~PS_WAIT_FOR_CAB;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700615 ath_print(common, ATH_DBG_PS,
616 "PS wait for CAB frames timed out\n");
Jouni Malinencc659652009-05-14 21:28:48 +0300617 }
Jouni Malinencc659652009-05-14 21:28:48 +0300618}
619
620static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
621{
622 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700623 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jouni Malinencc659652009-05-14 21:28:48 +0300624
625 hdr = (struct ieee80211_hdr *)skb->data;
626
627 /* Process Beacon and CAB receive in PS state */
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -0700628 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
629 && ieee80211_is_beacon(hdr->frame_control))
Jouni Malinencc659652009-05-14 21:28:48 +0300630 ath_rx_ps_beacon(sc, skb);
Sujith1b04b932010-01-08 10:36:05 +0530631 else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
Jouni Malinencc659652009-05-14 21:28:48 +0300632 (ieee80211_is_data(hdr->frame_control) ||
633 ieee80211_is_action(hdr->frame_control)) &&
634 is_multicast_ether_addr(hdr->addr1) &&
635 !ieee80211_has_moredata(hdr->frame_control)) {
Jouni Malinencc659652009-05-14 21:28:48 +0300636 /*
637 * No more broadcast/multicast frames to be received at this
638 * point.
639 */
Senthil Balasubramanian3fac6df2010-09-16 15:12:35 -0400640 sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700641 ath_print(common, ATH_DBG_PS,
642 "All PS CAB frames received, back to sleep\n");
Sujith1b04b932010-01-08 10:36:05 +0530643 } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300644 !is_multicast_ether_addr(hdr->addr1) &&
645 !ieee80211_has_morefrags(hdr->frame_control)) {
Sujith1b04b932010-01-08 10:36:05 +0530646 sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700647 ath_print(common, ATH_DBG_PS,
648 "Going back to sleep after having received "
Pavel Roskinf643e512010-01-29 17:22:12 -0500649 "PS-Poll data (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +0530650 sc->ps_flags & (PS_WAIT_FOR_BEACON |
651 PS_WAIT_FOR_CAB |
652 PS_WAIT_FOR_PSPOLL_DATA |
653 PS_WAIT_FOR_TX_ACK));
Jouni Malinencc659652009-05-14 21:28:48 +0300654 }
655}
656
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -0800657static void ath_rx_send_to_mac80211(struct ieee80211_hw *hw,
658 struct ath_softc *sc, struct sk_buff *skb,
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -0800659 struct ieee80211_rx_status *rxs)
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300660{
661 struct ieee80211_hdr *hdr;
662
663 hdr = (struct ieee80211_hdr *)skb->data;
664
665 /* Send the frame to mac80211 */
666 if (is_multicast_ether_addr(hdr->addr1)) {
667 int i;
668 /*
669 * Deliver broadcast/multicast frames to all suitable
670 * virtual wiphys.
671 */
672 /* TODO: filter based on channel configuration */
673 for (i = 0; i < sc->num_sec_wiphy; i++) {
674 struct ath_wiphy *aphy = sc->sec_wiphy[i];
675 struct sk_buff *nskb;
676 if (aphy == NULL)
677 continue;
678 nskb = skb_copy(skb, GFP_ATOMIC);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -0800679 if (!nskb)
680 continue;
681 ieee80211_rx(aphy->hw, nskb);
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300682 }
Johannes Bergf1d58c22009-06-17 13:13:00 +0200683 ieee80211_rx(sc->hw, skb);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -0800684 } else
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300685 /* Deliver unicast frames based on receiver address */
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -0800686 ieee80211_rx(hw, skb);
Jouni Malinen9d64a3c2009-05-14 21:28:47 +0300687}
688
Felix Fietkaub5c804752010-04-15 17:38:48 -0400689static bool ath_edma_get_buffers(struct ath_softc *sc,
690 enum ath9k_rx_qtype qtype)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691{
Felix Fietkaub5c804752010-04-15 17:38:48 -0400692 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
693 struct ath_hw *ah = sc->sc_ah;
694 struct ath_common *common = ath9k_hw_common(ah);
695 struct sk_buff *skb;
Sujithbe0418a2008-11-18 09:05:55 +0530696 struct ath_buf *bf;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400697 int ret;
698
699 skb = skb_peek(&rx_edma->rx_fifo);
700 if (!skb)
701 return false;
702
703 bf = SKB_CB_ATHBUF(skb);
704 BUG_ON(!bf);
705
Ming Leice9426d2010-05-15 18:25:40 +0800706 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400707 common->rx_bufsize, DMA_FROM_DEVICE);
708
709 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
Ming Leice9426d2010-05-15 18:25:40 +0800710 if (ret == -EINPROGRESS) {
711 /*let device gain the buffer again*/
712 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
713 common->rx_bufsize, DMA_FROM_DEVICE);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400714 return false;
Ming Leice9426d2010-05-15 18:25:40 +0800715 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400716
717 __skb_unlink(skb, &rx_edma->rx_fifo);
718 if (ret == -EINVAL) {
719 /* corrupt descriptor, skip this one and the following one */
720 list_add_tail(&bf->list, &sc->rx.rxbuf);
721 ath_rx_edma_buf_link(sc, qtype);
722 skb = skb_peek(&rx_edma->rx_fifo);
723 if (!skb)
724 return true;
725
726 bf = SKB_CB_ATHBUF(skb);
727 BUG_ON(!bf);
728
729 __skb_unlink(skb, &rx_edma->rx_fifo);
730 list_add_tail(&bf->list, &sc->rx.rxbuf);
731 ath_rx_edma_buf_link(sc, qtype);
Vasanthakumar Thiagarajan083e3e82010-05-10 19:41:34 -0700732 return true;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400733 }
734 skb_queue_tail(&rx_edma->rx_buffers, skb);
735
736 return true;
737}
738
739static struct ath_buf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
740 struct ath_rx_status *rs,
741 enum ath9k_rx_qtype qtype)
742{
743 struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
744 struct sk_buff *skb;
745 struct ath_buf *bf;
746
747 while (ath_edma_get_buffers(sc, qtype));
748 skb = __skb_dequeue(&rx_edma->rx_buffers);
749 if (!skb)
750 return NULL;
751
752 bf = SKB_CB_ATHBUF(skb);
753 ath9k_hw_process_rxdesc_edma(sc->sc_ah, rs, skb->data);
754 return bf;
755}
756
757static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
758 struct ath_rx_status *rs)
759{
760 struct ath_hw *ah = sc->sc_ah;
761 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 struct ath_desc *ds;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400763 struct ath_buf *bf;
764 int ret;
765
766 if (list_empty(&sc->rx.rxbuf)) {
767 sc->rx.rxlink = NULL;
768 return NULL;
769 }
770
771 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
772 ds = bf->bf_desc;
773
774 /*
775 * Must provide the virtual address of the current
776 * descriptor, the physical address, and the virtual
777 * address of the next descriptor in the h/w chain.
778 * This allows the HAL to look ahead to see if the
779 * hardware is done with a descriptor by checking the
780 * done bit in the following descriptor and the address
781 * of the current descriptor the DMA engine is working
782 * on. All this is necessary because of our use of
783 * a self-linked list to avoid rx overruns.
784 */
785 ret = ath9k_hw_rxprocdesc(ah, ds, rs, 0);
786 if (ret == -EINPROGRESS) {
787 struct ath_rx_status trs;
788 struct ath_buf *tbf;
789 struct ath_desc *tds;
790
791 memset(&trs, 0, sizeof(trs));
792 if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
793 sc->rx.rxlink = NULL;
794 return NULL;
795 }
796
797 tbf = list_entry(bf->list.next, struct ath_buf, list);
798
799 /*
800 * On some hardware the descriptor status words could
801 * get corrupted, including the done bit. Because of
802 * this, check if the next descriptor's done bit is
803 * set or not.
804 *
805 * If the next descriptor's done bit is set, the current
806 * descriptor has been corrupted. Force s/w to discard
807 * this descriptor and continue...
808 */
809
810 tds = tbf->bf_desc;
811 ret = ath9k_hw_rxprocdesc(ah, tds, &trs, 0);
812 if (ret == -EINPROGRESS)
813 return NULL;
814 }
815
816 if (!bf->bf_mpdu)
817 return bf;
818
819 /*
820 * Synchronize the DMA transfer with CPU before
821 * 1. accessing the frame
822 * 2. requeueing the same buffer to h/w
823 */
Ming Leice9426d2010-05-15 18:25:40 +0800824 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
Felix Fietkaub5c804752010-04-15 17:38:48 -0400825 common->rx_bufsize,
826 DMA_FROM_DEVICE);
827
828 return bf;
829}
830
Sujithd4357002010-05-20 15:34:38 +0530831/* Assumes you've already done the endian to CPU conversion */
832static bool ath9k_rx_accept(struct ath_common *common,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700833 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530834 struct ieee80211_rx_status *rxs,
835 struct ath_rx_status *rx_stats,
836 bool *decrypt_error)
837{
838 struct ath_hw *ah = common->ah;
Sujithd4357002010-05-20 15:34:38 +0530839 __le16 fc;
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700840 u8 rx_status_len = ah->caps.rx_status_len;
Sujithd4357002010-05-20 15:34:38 +0530841
Sujithd4357002010-05-20 15:34:38 +0530842 fc = hdr->frame_control;
843
844 if (!rx_stats->rs_datalen)
845 return false;
846 /*
847 * rs_status follows rs_datalen so if rs_datalen is too large
848 * we can take a hint that hardware corrupted it, so ignore
849 * those frames.
850 */
Vasanthakumar Thiagarajanb7b1b512010-05-20 14:34:48 -0700851 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
Sujithd4357002010-05-20 15:34:38 +0530852 return false;
853
854 /*
855 * rs_more indicates chained descriptors which can be used
856 * to link buffers together for a sort of scatter-gather
857 * operation.
858 * reject the frame, we don't support scatter-gather yet and
859 * the frame is probably corrupt anyway
860 */
861 if (rx_stats->rs_more)
862 return false;
863
864 /*
865 * The rx_stats->rs_status will not be set until the end of the
866 * chained descriptors so it can be ignored if rs_more is set. The
867 * rs_more will be false at the last element of the chained
868 * descriptors.
869 */
870 if (rx_stats->rs_status != 0) {
871 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
872 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
873 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
874 return false;
875
876 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
877 *decrypt_error = true;
878 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
Felix Fietkau56363dd2010-08-28 18:21:21 +0200879 /*
880 * The MIC error bit is only valid if the frame
881 * is not a control frame or fragment, and it was
882 * decrypted using a valid TKIP key.
883 */
884 if (!ieee80211_is_ctl(fc) &&
885 !ieee80211_has_morefrags(fc) &&
886 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
887 test_bit(rx_stats->rs_keyix, common->tkip_keymap))
Sujithd4357002010-05-20 15:34:38 +0530888 rxs->flag |= RX_FLAG_MMIC_ERROR;
Felix Fietkau56363dd2010-08-28 18:21:21 +0200889 else
890 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
Sujithd4357002010-05-20 15:34:38 +0530891 }
892 /*
893 * Reject error frames with the exception of
894 * decryption and MIC failures. For monitor mode,
895 * we also ignore the CRC error.
896 */
897 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
898 if (rx_stats->rs_status &
899 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
900 ATH9K_RXERR_CRC))
901 return false;
902 } else {
903 if (rx_stats->rs_status &
904 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
905 return false;
906 }
907 }
908 }
909 return true;
910}
911
912static int ath9k_process_rate(struct ath_common *common,
913 struct ieee80211_hw *hw,
914 struct ath_rx_status *rx_stats,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700915 struct ieee80211_rx_status *rxs)
Sujithd4357002010-05-20 15:34:38 +0530916{
917 struct ieee80211_supported_band *sband;
918 enum ieee80211_band band;
919 unsigned int i = 0;
920
921 band = hw->conf.channel->band;
922 sband = hw->wiphy->bands[band];
923
924 if (rx_stats->rs_rate & 0x80) {
925 /* HT rate */
926 rxs->flag |= RX_FLAG_HT;
927 if (rx_stats->rs_flags & ATH9K_RX_2040)
928 rxs->flag |= RX_FLAG_40MHZ;
929 if (rx_stats->rs_flags & ATH9K_RX_GI)
930 rxs->flag |= RX_FLAG_SHORT_GI;
931 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
932 return 0;
933 }
934
935 for (i = 0; i < sband->n_bitrates; i++) {
936 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
937 rxs->rate_idx = i;
938 return 0;
939 }
940 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
941 rxs->flag |= RX_FLAG_SHORTPRE;
942 rxs->rate_idx = i;
943 return 0;
944 }
945 }
946
947 /*
948 * No valid hardware bitrate found -- we should not get here
949 * because hardware has already validated this frame as OK.
950 */
951 ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected "
952 "0x%02x using 1 Mbit\n", rx_stats->rs_rate);
Sujithd4357002010-05-20 15:34:38 +0530953
954 return -EINVAL;
955}
956
957static void ath9k_process_rssi(struct ath_common *common,
958 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -0700959 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +0530960 struct ath_rx_status *rx_stats)
961{
962 struct ath_hw *ah = common->ah;
963 struct ieee80211_sta *sta;
Sujithd4357002010-05-20 15:34:38 +0530964 struct ath_node *an;
965 int last_rssi = ATH_RSSI_DUMMY_MARKER;
966 __le16 fc;
967
Sujithd4357002010-05-20 15:34:38 +0530968 fc = hdr->frame_control;
969
970 rcu_read_lock();
971 /*
972 * XXX: use ieee80211_find_sta! This requires quite a bit of work
973 * under the current ath9k virtual wiphy implementation as we have
974 * no way of tying a vif to wiphy. Typically vifs are attached to
975 * at least one sdata of a wiphy on mac80211 but with ath9k virtual
976 * wiphy you'd have to iterate over every wiphy and each sdata.
977 */
Ben Greear686b9cb2010-09-23 09:44:36 -0700978 if (is_multicast_ether_addr(hdr->addr1))
979 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr2, NULL);
980 else
981 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr2, hdr->addr1);
982
Sujithd4357002010-05-20 15:34:38 +0530983 if (sta) {
984 an = (struct ath_node *) sta->drv_priv;
985 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD &&
986 !rx_stats->rs_moreaggr)
987 ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi);
988 last_rssi = an->last_rssi;
989 }
990 rcu_read_unlock();
991
992 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
993 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
994 ATH_RSSI_EP_MULTIPLIER);
995 if (rx_stats->rs_rssi < 0)
996 rx_stats->rs_rssi = 0;
997
998 /* Update Beacon RSSI, this is used by ANI. */
999 if (ieee80211_is_beacon(fc))
1000 ah->stats.avgbrssi = rx_stats->rs_rssi;
1001}
1002
1003/*
1004 * For Decrypt or Demic errors, we only mark packet status here and always push
1005 * up the frame up to let mac80211 handle the actual error case, be it no
1006 * decryption key or real decryption error. This let us keep statistics there.
1007 */
1008static int ath9k_rx_skb_preprocess(struct ath_common *common,
1009 struct ieee80211_hw *hw,
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001010 struct ieee80211_hdr *hdr,
Sujithd4357002010-05-20 15:34:38 +05301011 struct ath_rx_status *rx_stats,
1012 struct ieee80211_rx_status *rx_status,
1013 bool *decrypt_error)
1014{
Sujithd4357002010-05-20 15:34:38 +05301015 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
1016
1017 /*
1018 * everything but the rate is checked here, the rate check is done
1019 * separately to avoid doing two lookups for a rate for each frame.
1020 */
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001021 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
Sujithd4357002010-05-20 15:34:38 +05301022 return -EINVAL;
1023
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001024 ath9k_process_rssi(common, hw, hdr, rx_stats);
Sujithd4357002010-05-20 15:34:38 +05301025
Vasanthakumar Thiagarajan9f167f62010-05-20 14:34:46 -07001026 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
Sujithd4357002010-05-20 15:34:38 +05301027 return -EINVAL;
1028
Sujithd4357002010-05-20 15:34:38 +05301029 rx_status->band = hw->conf.channel->band;
1030 rx_status->freq = hw->conf.channel->center_freq;
1031 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
1032 rx_status->antenna = rx_stats->rs_antenna;
1033 rx_status->flag |= RX_FLAG_TSFT;
1034
1035 return 0;
1036}
1037
1038static void ath9k_rx_skb_postprocess(struct ath_common *common,
1039 struct sk_buff *skb,
1040 struct ath_rx_status *rx_stats,
1041 struct ieee80211_rx_status *rxs,
1042 bool decrypt_error)
1043{
1044 struct ath_hw *ah = common->ah;
1045 struct ieee80211_hdr *hdr;
1046 int hdrlen, padpos, padsize;
1047 u8 keyix;
1048 __le16 fc;
1049
1050 /* see if any padding is done by the hw and remove it */
1051 hdr = (struct ieee80211_hdr *) skb->data;
1052 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1053 fc = hdr->frame_control;
1054 padpos = ath9k_cmn_padpos(hdr->frame_control);
1055
1056 /* The MAC header is padded to have 32-bit boundary if the
1057 * packet payload is non-zero. The general calculation for
1058 * padsize would take into account odd header lengths:
1059 * padsize = (4 - padpos % 4) % 4; However, since only
1060 * even-length headers are used, padding can only be 0 or 2
1061 * bytes and we can optimize this a bit. In addition, we must
1062 * not try to remove padding from short control frames that do
1063 * not have payload. */
1064 padsize = padpos & 3;
1065 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1066 memmove(skb->data + padsize, skb->data, padpos);
1067 skb_pull(skb, padsize);
1068 }
1069
1070 keyix = rx_stats->rs_keyix;
1071
1072 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1073 ieee80211_has_protected(fc)) {
1074 rxs->flag |= RX_FLAG_DECRYPTED;
1075 } else if (ieee80211_has_protected(fc)
1076 && !decrypt_error && skb->len >= hdrlen + 4) {
1077 keyix = skb->data[hdrlen + 3] >> 6;
1078
1079 if (test_bit(keyix, common->keymap))
1080 rxs->flag |= RX_FLAG_DECRYPTED;
1081 }
1082 if (ah->sw_mgmt_crypto &&
1083 (rxs->flag & RX_FLAG_DECRYPTED) &&
1084 ieee80211_is_mgmt(fc))
1085 /* Use software decrypt for management frames. */
1086 rxs->flag &= ~RX_FLAG_DECRYPTED;
1087}
Felix Fietkaub5c804752010-04-15 17:38:48 -04001088
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001089static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
1090 struct ath_hw_antcomb_conf ant_conf,
1091 int main_rssi_avg)
1092{
1093 antcomb->quick_scan_cnt = 0;
1094
1095 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
1096 antcomb->rssi_lna2 = main_rssi_avg;
1097 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
1098 antcomb->rssi_lna1 = main_rssi_avg;
1099
1100 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
1101 case (0x10): /* LNA2 A-B */
1102 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1103 antcomb->first_quick_scan_conf =
1104 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1105 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1106 break;
1107 case (0x20): /* LNA1 A-B */
1108 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1109 antcomb->first_quick_scan_conf =
1110 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1111 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1112 break;
1113 case (0x21): /* LNA1 LNA2 */
1114 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
1115 antcomb->first_quick_scan_conf =
1116 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1117 antcomb->second_quick_scan_conf =
1118 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1119 break;
1120 case (0x12): /* LNA2 LNA1 */
1121 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
1122 antcomb->first_quick_scan_conf =
1123 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1124 antcomb->second_quick_scan_conf =
1125 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1126 break;
1127 case (0x13): /* LNA2 A+B */
1128 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1129 antcomb->first_quick_scan_conf =
1130 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1131 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1132 break;
1133 case (0x23): /* LNA1 A+B */
1134 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1135 antcomb->first_quick_scan_conf =
1136 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1137 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1138 break;
1139 default:
1140 break;
1141 }
1142}
1143
1144static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
1145 struct ath_hw_antcomb_conf *div_ant_conf,
1146 int main_rssi_avg, int alt_rssi_avg,
1147 int alt_ratio)
1148{
1149 /* alt_good */
1150 switch (antcomb->quick_scan_cnt) {
1151 case 0:
1152 /* set alt to main, and alt to first conf */
1153 div_ant_conf->main_lna_conf = antcomb->main_conf;
1154 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
1155 break;
1156 case 1:
1157 /* set alt to main, and alt to first conf */
1158 div_ant_conf->main_lna_conf = antcomb->main_conf;
1159 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
1160 antcomb->rssi_first = main_rssi_avg;
1161 antcomb->rssi_second = alt_rssi_avg;
1162
1163 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1164 /* main is LNA1 */
1165 if (ath_is_alt_ant_ratio_better(alt_ratio,
1166 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1167 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1168 main_rssi_avg, alt_rssi_avg,
1169 antcomb->total_pkt_count))
1170 antcomb->first_ratio = true;
1171 else
1172 antcomb->first_ratio = false;
1173 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1174 if (ath_is_alt_ant_ratio_better(alt_ratio,
1175 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1176 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1177 main_rssi_avg, alt_rssi_avg,
1178 antcomb->total_pkt_count))
1179 antcomb->first_ratio = true;
1180 else
1181 antcomb->first_ratio = false;
1182 } else {
1183 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1184 (alt_rssi_avg > main_rssi_avg +
1185 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1186 (alt_rssi_avg > main_rssi_avg)) &&
1187 (antcomb->total_pkt_count > 50))
1188 antcomb->first_ratio = true;
1189 else
1190 antcomb->first_ratio = false;
1191 }
1192 break;
1193 case 2:
1194 antcomb->alt_good = false;
1195 antcomb->scan_not_start = false;
1196 antcomb->scan = false;
1197 antcomb->rssi_first = main_rssi_avg;
1198 antcomb->rssi_third = alt_rssi_avg;
1199
1200 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
1201 antcomb->rssi_lna1 = alt_rssi_avg;
1202 else if (antcomb->second_quick_scan_conf ==
1203 ATH_ANT_DIV_COMB_LNA2)
1204 antcomb->rssi_lna2 = alt_rssi_avg;
1205 else if (antcomb->second_quick_scan_conf ==
1206 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
1207 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
1208 antcomb->rssi_lna2 = main_rssi_avg;
1209 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
1210 antcomb->rssi_lna1 = main_rssi_avg;
1211 }
1212
1213 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
1214 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
1215 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1216 else
1217 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
1218
1219 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1220 if (ath_is_alt_ant_ratio_better(alt_ratio,
1221 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1222 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1223 main_rssi_avg, alt_rssi_avg,
1224 antcomb->total_pkt_count))
1225 antcomb->second_ratio = true;
1226 else
1227 antcomb->second_ratio = false;
1228 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1229 if (ath_is_alt_ant_ratio_better(alt_ratio,
1230 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1231 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1232 main_rssi_avg, alt_rssi_avg,
1233 antcomb->total_pkt_count))
1234 antcomb->second_ratio = true;
1235 else
1236 antcomb->second_ratio = false;
1237 } else {
1238 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1239 (alt_rssi_avg > main_rssi_avg +
1240 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1241 (alt_rssi_avg > main_rssi_avg)) &&
1242 (antcomb->total_pkt_count > 50))
1243 antcomb->second_ratio = true;
1244 else
1245 antcomb->second_ratio = false;
1246 }
1247
1248 /* set alt to the conf with maximun ratio */
1249 if (antcomb->first_ratio && antcomb->second_ratio) {
1250 if (antcomb->rssi_second > antcomb->rssi_third) {
1251 /* first alt*/
1252 if ((antcomb->first_quick_scan_conf ==
1253 ATH_ANT_DIV_COMB_LNA1) ||
1254 (antcomb->first_quick_scan_conf ==
1255 ATH_ANT_DIV_COMB_LNA2))
1256 /* Set alt LNA1 or LNA2*/
1257 if (div_ant_conf->main_lna_conf ==
1258 ATH_ANT_DIV_COMB_LNA2)
1259 div_ant_conf->alt_lna_conf =
1260 ATH_ANT_DIV_COMB_LNA1;
1261 else
1262 div_ant_conf->alt_lna_conf =
1263 ATH_ANT_DIV_COMB_LNA2;
1264 else
1265 /* Set alt to A+B or A-B */
1266 div_ant_conf->alt_lna_conf =
1267 antcomb->first_quick_scan_conf;
1268 } else if ((antcomb->second_quick_scan_conf ==
1269 ATH_ANT_DIV_COMB_LNA1) ||
1270 (antcomb->second_quick_scan_conf ==
1271 ATH_ANT_DIV_COMB_LNA2)) {
1272 /* Set alt LNA1 or LNA2 */
1273 if (div_ant_conf->main_lna_conf ==
1274 ATH_ANT_DIV_COMB_LNA2)
1275 div_ant_conf->alt_lna_conf =
1276 ATH_ANT_DIV_COMB_LNA1;
1277 else
1278 div_ant_conf->alt_lna_conf =
1279 ATH_ANT_DIV_COMB_LNA2;
1280 } else {
1281 /* Set alt to A+B or A-B */
1282 div_ant_conf->alt_lna_conf =
1283 antcomb->second_quick_scan_conf;
1284 }
1285 } else if (antcomb->first_ratio) {
1286 /* first alt */
1287 if ((antcomb->first_quick_scan_conf ==
1288 ATH_ANT_DIV_COMB_LNA1) ||
1289 (antcomb->first_quick_scan_conf ==
1290 ATH_ANT_DIV_COMB_LNA2))
1291 /* Set alt LNA1 or LNA2 */
1292 if (div_ant_conf->main_lna_conf ==
1293 ATH_ANT_DIV_COMB_LNA2)
1294 div_ant_conf->alt_lna_conf =
1295 ATH_ANT_DIV_COMB_LNA1;
1296 else
1297 div_ant_conf->alt_lna_conf =
1298 ATH_ANT_DIV_COMB_LNA2;
1299 else
1300 /* Set alt to A+B or A-B */
1301 div_ant_conf->alt_lna_conf =
1302 antcomb->first_quick_scan_conf;
1303 } else if (antcomb->second_ratio) {
1304 /* second alt */
1305 if ((antcomb->second_quick_scan_conf ==
1306 ATH_ANT_DIV_COMB_LNA1) ||
1307 (antcomb->second_quick_scan_conf ==
1308 ATH_ANT_DIV_COMB_LNA2))
1309 /* Set alt LNA1 or LNA2 */
1310 if (div_ant_conf->main_lna_conf ==
1311 ATH_ANT_DIV_COMB_LNA2)
1312 div_ant_conf->alt_lna_conf =
1313 ATH_ANT_DIV_COMB_LNA1;
1314 else
1315 div_ant_conf->alt_lna_conf =
1316 ATH_ANT_DIV_COMB_LNA2;
1317 else
1318 /* Set alt to A+B or A-B */
1319 div_ant_conf->alt_lna_conf =
1320 antcomb->second_quick_scan_conf;
1321 } else {
1322 /* main is largest */
1323 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
1324 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
1325 /* Set alt LNA1 or LNA2 */
1326 if (div_ant_conf->main_lna_conf ==
1327 ATH_ANT_DIV_COMB_LNA2)
1328 div_ant_conf->alt_lna_conf =
1329 ATH_ANT_DIV_COMB_LNA1;
1330 else
1331 div_ant_conf->alt_lna_conf =
1332 ATH_ANT_DIV_COMB_LNA2;
1333 else
1334 /* Set alt to A+B or A-B */
1335 div_ant_conf->alt_lna_conf = antcomb->main_conf;
1336 }
1337 break;
1338 default:
1339 break;
1340 }
1341}
1342
John W. Linville9bad82b2010-09-15 15:26:13 -04001343static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf)
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001344{
1345 /* Adjust the fast_div_bias based on main and alt lna conf */
1346 switch ((ant_conf->main_lna_conf << 4) | ant_conf->alt_lna_conf) {
1347 case (0x01): /* A-B LNA2 */
1348 ant_conf->fast_div_bias = 0x3b;
1349 break;
1350 case (0x02): /* A-B LNA1 */
1351 ant_conf->fast_div_bias = 0x3d;
1352 break;
1353 case (0x03): /* A-B A+B */
1354 ant_conf->fast_div_bias = 0x1;
1355 break;
1356 case (0x10): /* LNA2 A-B */
1357 ant_conf->fast_div_bias = 0x7;
1358 break;
1359 case (0x12): /* LNA2 LNA1 */
1360 ant_conf->fast_div_bias = 0x2;
1361 break;
1362 case (0x13): /* LNA2 A+B */
1363 ant_conf->fast_div_bias = 0x7;
1364 break;
1365 case (0x20): /* LNA1 A-B */
1366 ant_conf->fast_div_bias = 0x6;
1367 break;
1368 case (0x21): /* LNA1 LNA2 */
1369 ant_conf->fast_div_bias = 0x0;
1370 break;
1371 case (0x23): /* LNA1 A+B */
1372 ant_conf->fast_div_bias = 0x6;
1373 break;
1374 case (0x30): /* A+B A-B */
1375 ant_conf->fast_div_bias = 0x1;
1376 break;
1377 case (0x31): /* A+B LNA2 */
1378 ant_conf->fast_div_bias = 0x3b;
1379 break;
1380 case (0x32): /* A+B LNA1 */
1381 ant_conf->fast_div_bias = 0x3d;
1382 break;
1383 default:
1384 break;
1385 }
1386}
1387
1388/* Antenna diversity and combining */
1389static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
1390{
1391 struct ath_hw_antcomb_conf div_ant_conf;
1392 struct ath_ant_comb *antcomb = &sc->ant_comb;
1393 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
1394 int curr_main_set, curr_bias;
1395 int main_rssi = rs->rs_rssi_ctl0;
1396 int alt_rssi = rs->rs_rssi_ctl1;
1397 int rx_ant_conf, main_ant_conf;
1398 bool short_scan = false;
1399
1400 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
1401 ATH_ANT_RX_MASK;
1402 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
1403 ATH_ANT_RX_MASK;
1404
1405 /* Record packet only when alt_rssi is positive */
1406 if (alt_rssi > 0) {
1407 antcomb->total_pkt_count++;
1408 antcomb->main_total_rssi += main_rssi;
1409 antcomb->alt_total_rssi += alt_rssi;
1410 if (main_ant_conf == rx_ant_conf)
1411 antcomb->main_recv_cnt++;
1412 else
1413 antcomb->alt_recv_cnt++;
1414 }
1415
1416 /* Short scan check */
1417 if (antcomb->scan && antcomb->alt_good) {
1418 if (time_after(jiffies, antcomb->scan_start_time +
1419 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
1420 short_scan = true;
1421 else
1422 if (antcomb->total_pkt_count ==
1423 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
1424 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1425 antcomb->total_pkt_count);
1426 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
1427 short_scan = true;
1428 }
1429 }
1430
1431 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
1432 rs->rs_moreaggr) && !short_scan)
1433 return;
1434
1435 if (antcomb->total_pkt_count) {
1436 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1437 antcomb->total_pkt_count);
1438 main_rssi_avg = (antcomb->main_total_rssi /
1439 antcomb->total_pkt_count);
1440 alt_rssi_avg = (antcomb->alt_total_rssi /
1441 antcomb->total_pkt_count);
1442 }
1443
1444
1445 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
1446 curr_alt_set = div_ant_conf.alt_lna_conf;
1447 curr_main_set = div_ant_conf.main_lna_conf;
1448 curr_bias = div_ant_conf.fast_div_bias;
1449
1450 antcomb->count++;
1451
1452 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1453 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1454 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1455 main_rssi_avg);
1456 antcomb->alt_good = true;
1457 } else {
1458 antcomb->alt_good = false;
1459 }
1460
1461 antcomb->count = 0;
1462 antcomb->scan = true;
1463 antcomb->scan_not_start = true;
1464 }
1465
1466 if (!antcomb->scan) {
1467 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1468 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1469 /* Switch main and alt LNA */
1470 div_ant_conf.main_lna_conf =
1471 ATH_ANT_DIV_COMB_LNA2;
1472 div_ant_conf.alt_lna_conf =
1473 ATH_ANT_DIV_COMB_LNA1;
1474 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1475 div_ant_conf.main_lna_conf =
1476 ATH_ANT_DIV_COMB_LNA1;
1477 div_ant_conf.alt_lna_conf =
1478 ATH_ANT_DIV_COMB_LNA2;
1479 }
1480
1481 goto div_comb_done;
1482 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1483 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1484 /* Set alt to another LNA */
1485 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1486 div_ant_conf.alt_lna_conf =
1487 ATH_ANT_DIV_COMB_LNA1;
1488 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1489 div_ant_conf.alt_lna_conf =
1490 ATH_ANT_DIV_COMB_LNA2;
1491
1492 goto div_comb_done;
1493 }
1494
1495 if ((alt_rssi_avg < (main_rssi_avg +
1496 ATH_ANT_DIV_COMB_LNA1_LNA2_DELTA)))
1497 goto div_comb_done;
1498 }
1499
1500 if (!antcomb->scan_not_start) {
1501 switch (curr_alt_set) {
1502 case ATH_ANT_DIV_COMB_LNA2:
1503 antcomb->rssi_lna2 = alt_rssi_avg;
1504 antcomb->rssi_lna1 = main_rssi_avg;
1505 antcomb->scan = true;
1506 /* set to A+B */
1507 div_ant_conf.main_lna_conf =
1508 ATH_ANT_DIV_COMB_LNA1;
1509 div_ant_conf.alt_lna_conf =
1510 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1511 break;
1512 case ATH_ANT_DIV_COMB_LNA1:
1513 antcomb->rssi_lna1 = alt_rssi_avg;
1514 antcomb->rssi_lna2 = main_rssi_avg;
1515 antcomb->scan = true;
1516 /* set to A+B */
1517 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1518 div_ant_conf.alt_lna_conf =
1519 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1520 break;
1521 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1522 antcomb->rssi_add = alt_rssi_avg;
1523 antcomb->scan = true;
1524 /* set to A-B */
1525 div_ant_conf.alt_lna_conf =
1526 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1527 break;
1528 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1529 antcomb->rssi_sub = alt_rssi_avg;
1530 antcomb->scan = false;
1531 if (antcomb->rssi_lna2 >
1532 (antcomb->rssi_lna1 +
1533 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1534 /* use LNA2 as main LNA */
1535 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1536 (antcomb->rssi_add > antcomb->rssi_sub)) {
1537 /* set to A+B */
1538 div_ant_conf.main_lna_conf =
1539 ATH_ANT_DIV_COMB_LNA2;
1540 div_ant_conf.alt_lna_conf =
1541 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1542 } else if (antcomb->rssi_sub >
1543 antcomb->rssi_lna1) {
1544 /* set to A-B */
1545 div_ant_conf.main_lna_conf =
1546 ATH_ANT_DIV_COMB_LNA2;
1547 div_ant_conf.alt_lna_conf =
1548 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1549 } else {
1550 /* set to LNA1 */
1551 div_ant_conf.main_lna_conf =
1552 ATH_ANT_DIV_COMB_LNA2;
1553 div_ant_conf.alt_lna_conf =
1554 ATH_ANT_DIV_COMB_LNA1;
1555 }
1556 } else {
1557 /* use LNA1 as main LNA */
1558 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1559 (antcomb->rssi_add > antcomb->rssi_sub)) {
1560 /* set to A+B */
1561 div_ant_conf.main_lna_conf =
1562 ATH_ANT_DIV_COMB_LNA1;
1563 div_ant_conf.alt_lna_conf =
1564 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1565 } else if (antcomb->rssi_sub >
1566 antcomb->rssi_lna1) {
1567 /* set to A-B */
1568 div_ant_conf.main_lna_conf =
1569 ATH_ANT_DIV_COMB_LNA1;
1570 div_ant_conf.alt_lna_conf =
1571 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1572 } else {
1573 /* set to LNA2 */
1574 div_ant_conf.main_lna_conf =
1575 ATH_ANT_DIV_COMB_LNA1;
1576 div_ant_conf.alt_lna_conf =
1577 ATH_ANT_DIV_COMB_LNA2;
1578 }
1579 }
1580 break;
1581 default:
1582 break;
1583 }
1584 } else {
1585 if (!antcomb->alt_good) {
1586 antcomb->scan_not_start = false;
1587 /* Set alt to another LNA */
1588 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1589 div_ant_conf.main_lna_conf =
1590 ATH_ANT_DIV_COMB_LNA2;
1591 div_ant_conf.alt_lna_conf =
1592 ATH_ANT_DIV_COMB_LNA1;
1593 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1594 div_ant_conf.main_lna_conf =
1595 ATH_ANT_DIV_COMB_LNA1;
1596 div_ant_conf.alt_lna_conf =
1597 ATH_ANT_DIV_COMB_LNA2;
1598 }
1599 goto div_comb_done;
1600 }
1601 }
1602
1603 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1604 main_rssi_avg, alt_rssi_avg,
1605 alt_ratio);
1606
1607 antcomb->quick_scan_cnt++;
1608
1609div_comb_done:
1610 ath_ant_div_conf_fast_divbias(&div_ant_conf);
1611
1612 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1613
1614 antcomb->scan_start_time = jiffies;
1615 antcomb->total_pkt_count = 0;
1616 antcomb->main_total_rssi = 0;
1617 antcomb->alt_total_rssi = 0;
1618 antcomb->main_recv_cnt = 0;
1619 antcomb->alt_recv_cnt = 0;
1620}
1621
Felix Fietkaub5c804752010-04-15 17:38:48 -04001622int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1623{
1624 struct ath_buf *bf;
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001625 struct sk_buff *skb = NULL, *requeue_skb;
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001626 struct ieee80211_rx_status *rxs;
Sujithcbe61d82009-02-09 13:27:12 +05301627 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001628 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001629 /*
1630 * The hw can techncically differ from common->hw when using ath9k
1631 * virtual wiphy so to account for that we iterate over the active
1632 * wiphys and find the appropriate wiphy and therefore hw.
1633 */
1634 struct ieee80211_hw *hw = NULL;
Sujithbe0418a2008-11-18 09:05:55 +05301635 struct ieee80211_hdr *hdr;
Luis R. Rodriguezc9b14172009-11-04 16:47:22 -08001636 int retval;
Sujithbe0418a2008-11-18 09:05:55 +05301637 bool decrypt_error = false;
Felix Fietkau29bffa92010-03-29 20:14:23 -07001638 struct ath_rx_status rs;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001639 enum ath9k_rx_qtype qtype;
1640 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1641 int dma_type;
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001642 u8 rx_status_len = ah->caps.rx_status_len;
Felix Fietkaua6d20552010-06-12 00:33:54 -04001643 u64 tsf = 0;
1644 u32 tsf_lower = 0;
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001645 unsigned long flags;
Sujithbe0418a2008-11-18 09:05:55 +05301646
Felix Fietkaub5c804752010-04-15 17:38:48 -04001647 if (edma)
Felix Fietkaub5c804752010-04-15 17:38:48 -04001648 dma_type = DMA_BIDIRECTIONAL;
Ming Lei56824222010-05-14 21:15:38 +08001649 else
1650 dma_type = DMA_FROM_DEVICE;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001651
1652 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
Sujithb77f4832008-12-07 21:44:03 +05301653 spin_lock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001654
Felix Fietkaua6d20552010-06-12 00:33:54 -04001655 tsf = ath9k_hw_gettsf64(ah);
1656 tsf_lower = tsf & 0xffffffff;
1657
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001658 do {
1659 /* If handling rx interrupt and flush is in progress => exit */
Sujith98deeea2008-08-11 14:05:46 +05301660 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001661 break;
1662
Felix Fietkau29bffa92010-03-29 20:14:23 -07001663 memset(&rs, 0, sizeof(rs));
Felix Fietkaub5c804752010-04-15 17:38:48 -04001664 if (edma)
1665 bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
1666 else
1667 bf = ath_get_next_rx_buf(sc, &rs);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001668
Felix Fietkaub5c804752010-04-15 17:38:48 -04001669 if (!bf)
1670 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001671
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001672 skb = bf->bf_mpdu;
Sujithbe0418a2008-11-18 09:05:55 +05301673 if (!skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001674 continue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001675
Vasanthakumar Thiagarajan5c6dd922010-05-20 14:34:47 -07001676 hdr = (struct ieee80211_hdr *) (skb->data + rx_status_len);
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001677 rxs = IEEE80211_SKB_RXCB(skb);
1678
Luis R. Rodriguezb4afffc2009-11-02 11:36:08 -08001679 hw = ath_get_virt_hw(sc, hdr);
1680
Felix Fietkau29bffa92010-03-29 20:14:23 -07001681 ath_debug_stat_rx(sc, &rs);
Sujith1395d3f2010-01-08 10:36:11 +05301682
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301683 /*
Sujithbe0418a2008-11-18 09:05:55 +05301684 * If we're asked to flush receive queue, directly
1685 * chain it back at the queue without processing it.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001686 */
Sujithbe0418a2008-11-18 09:05:55 +05301687 if (flush)
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001688 goto requeue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001689
Jan Friedrichc8f3b722010-08-02 23:55:50 +02001690 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1691 rxs, &decrypt_error);
1692 if (retval)
1693 goto requeue;
1694
Felix Fietkaua6d20552010-06-12 00:33:54 -04001695 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1696 if (rs.rs_tstamp > tsf_lower &&
1697 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1698 rxs->mactime -= 0x100000000ULL;
1699
1700 if (rs.rs_tstamp < tsf_lower &&
1701 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1702 rxs->mactime += 0x100000000ULL;
1703
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001704 /* Ensure we always have an skb to requeue once we are done
1705 * processing the current buffer's skb */
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001706 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001707
1708 /* If there is no memory we ignore the current RX'd frame,
1709 * tell hardware it can give us a new frame using the old
Sujithb77f4832008-12-07 21:44:03 +05301710 * skb and put it at the tail of the sc->rx.rxbuf list for
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001711 * processing. */
1712 if (!requeue_skb)
1713 goto requeue;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001714
Vasanthakumar Thiagarajan9bf9fca2008-12-15 20:40:46 +05301715 /* Unmap the frame */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001716 dma_unmap_single(sc->dev, bf->bf_buf_addr,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001717 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001718 dma_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001719
Felix Fietkaub5c804752010-04-15 17:38:48 -04001720 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
1721 if (ah->caps.rx_status_len)
1722 skb_pull(skb, ah->caps.rx_status_len);
Sujithbe0418a2008-11-18 09:05:55 +05301723
Sujithd4357002010-05-20 15:34:38 +05301724 ath9k_rx_skb_postprocess(common, skb, &rs,
1725 rxs, decrypt_error);
Sujithbe0418a2008-11-18 09:05:55 +05301726
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001727 /* We will now give hardware our shiny new allocated skb */
1728 bf->bf_mpdu = requeue_skb;
Gabor Juhos7da3c552009-01-14 20:17:03 +01001729 bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
Luis R. Rodriguezcc861f72009-11-04 09:11:34 -08001730 common->rx_bufsize,
Felix Fietkaub5c804752010-04-15 17:38:48 -04001731 dma_type);
Gabor Juhos7da3c552009-01-14 20:17:03 +01001732 if (unlikely(dma_mapping_error(sc->dev,
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001733 bf->bf_buf_addr))) {
1734 dev_kfree_skb_any(requeue_skb);
1735 bf->bf_mpdu = NULL;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001736 ath_print(common, ATH_DBG_FATAL,
1737 "dma_mapping_error() on RX\n");
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001738 ath_rx_send_to_mac80211(hw, sc, skb, rxs);
Luis R. Rodriguezf8316df2008-12-03 03:35:29 -08001739 break;
1740 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001741
1742 /*
1743 * change the default rx antenna if rx diversity chooses the
1744 * other antenna 3 times in a row.
1745 */
Felix Fietkau29bffa92010-03-29 20:14:23 -07001746 if (sc->rx.defant != rs.rs_antenna) {
Sujithb77f4832008-12-07 21:44:03 +05301747 if (++sc->rx.rxotherant >= 3)
Felix Fietkau29bffa92010-03-29 20:14:23 -07001748 ath_setdefantenna(sc, rs.rs_antenna);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001749 } else {
Sujithb77f4832008-12-07 21:44:03 +05301750 sc->rx.rxotherant = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001751 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301752
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001753 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Vasanthakumar Thiagarajanededf1f2010-05-22 23:58:13 -07001754 if (unlikely(ath9k_check_auto_sleep(sc) ||
1755 (sc->ps_flags & (PS_WAIT_FOR_BEACON |
1756 PS_WAIT_FOR_CAB |
1757 PS_WAIT_FOR_PSPOLL_DATA))))
Jouni Malinencc659652009-05-14 21:28:48 +03001758 ath_rx_ps(sc, skb);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001759 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinencc659652009-05-14 21:28:48 +03001760
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -07001761 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
1762 ath_ant_comb_scan(sc, &rs);
1763
Luis R. Rodriguez5ca42622009-11-04 08:20:42 -08001764 ath_rx_send_to_mac80211(hw, sc, skb, rxs);
Jouni Malinencc659652009-05-14 21:28:48 +03001765
Luis R. Rodriguezcb71d9b2008-11-21 17:41:33 -08001766requeue:
Felix Fietkaub5c804752010-04-15 17:38:48 -04001767 if (edma) {
1768 list_add_tail(&bf->list, &sc->rx.rxbuf);
1769 ath_rx_edma_buf_link(sc, qtype);
1770 } else {
1771 list_move_tail(&bf->list, &sc->rx.rxbuf);
1772 ath_rx_buf_link(sc, bf);
1773 }
Sujithbe0418a2008-11-18 09:05:55 +05301774 } while (1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001775
Sujithb77f4832008-12-07 21:44:03 +05301776 spin_unlock_bh(&sc->rx.rxbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001777
1778 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001779}