2 * Copyright (c) 2012 Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 * Driver for the Atheros Wireless LAN controller.
36 * This software is derived from work of Atsushi Onoe; his contribution
37 * is greatly appreciated.
43 * This is needed for register operations which are performed
44 * by the driver - eg, calls to ath_hal_gettsf32().
46 * It's also required for any AH_DEBUG checks in here, eg the
47 * module dependencies.
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/sysctl.h>
56 #include <sys/malloc.h>
58 #include <sys/mutex.h>
59 #include <sys/kernel.h>
60 #include <sys/socket.h>
61 #include <sys/sockio.h>
62 #include <sys/errno.h>
63 #include <sys/callout.h>
65 #include <sys/endian.h>
66 #include <sys/kthread.h>
67 #include <sys/taskqueue.h>
69 #include <sys/module.h>
73 #include <net/if_var.h>
74 #include <net/if_dl.h>
75 #include <net/if_media.h>
76 #include <net/if_types.h>
77 #include <net/if_arp.h>
78 #include <net/ethernet.h>
79 #include <net/if_llc.h>
80 #include <net/ifq_var.h>
82 #include <netproto/802_11/ieee80211_var.h>
83 #include <netproto/802_11/ieee80211_regdomain.h>
84 #ifdef IEEE80211_SUPPORT_SUPERG
85 #include <netproto/802_11/ieee80211_superg.h>
87 #ifdef IEEE80211_SUPPORT_TDMA
88 #include <netproto/802_11/ieee80211_tdma.h>
94 #include <netinet/in.h>
95 #include <netinet/if_ether.h>
98 #include <dev/netif/ath/ath/if_athvar.h>
99 #include <dev/netif/ath/ath_hal/ah_devid.h> /* XXX for softled */
100 #include <dev/netif/ath/ath_hal/ah_diagcodes.h>
102 #include <dev/netif/ath/ath/if_ath_debug.h>
103 #include <dev/netif/ath/ath/if_ath_misc.h>
104 #include <dev/netif/ath/ath/if_ath_tsf.h>
105 #include <dev/netif/ath/ath/if_ath_tx.h>
106 #include <dev/netif/ath/ath/if_ath_sysctl.h>
107 #include <dev/netif/ath/ath/if_ath_led.h>
108 #include <dev/netif/ath/ath/if_ath_keycache.h>
109 #include <dev/netif/ath/ath/if_ath_rx.h>
110 #include <dev/netif/ath/ath/if_ath_beacon.h>
111 #include <dev/netif/ath/ath/if_athdfs.h>
114 #include <dev/netif/ath/ath_tx99/ath_tx99.h>
117 #include <dev/netif/ath/ath/if_ath_rx_edma.h>
120 #include <dev/netif/ath/ath/if_ath_alq.h>
124 * some general macros
126 #define INCR(_l, _sz) (_l) ++; (_l) &= ((_sz) - 1)
127 #define DECR(_l, _sz) (_l) --; (_l) &= ((_sz) - 1)
129 MALLOC_DECLARE(M_ATHDEV);
134 * + Make sure the FIFO is correctly flushed and reinitialised
136 * + Verify multi-descriptor frames work!
137 * + There's a "memory use after free" which needs to be tracked down
138 * and fixed ASAP. I've seen this in the legacy path too, so it
139 * may be a generic RX path issue.
143 * XXX shuffle the function orders so these pre-declarations aren't
146 static int ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype,
148 static int ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype);
149 static void ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf);
150 static void ath_edma_recv_proc_queue(struct ath_softc *sc,
151 HAL_RX_QUEUE qtype, int dosched);
152 static int ath_edma_recv_proc_deferred_queue(struct ath_softc *sc,
153 HAL_RX_QUEUE qtype, int dosched);
156 ath_edma_stoprecv(struct ath_softc *sc, int dodelay)
158 struct ath_hal *ah = sc->sc_ah;
162 ath_hal_stoppcurecv(ah);
163 ath_hal_setrxfilter(ah, 0);
168 if (ath_hal_stopdmarecv(ah) == AH_TRUE)
169 sc->sc_rx_stopped = 1;
172 * Give the various bus FIFOs (not EDMA descriptor FIFO)
173 * time to finish flushing out data.
177 /* Flush RX pending for each queue */
178 /* XXX should generic-ify this */
179 if (sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending) {
180 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending);
181 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending = NULL;
184 if (sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending) {
185 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending);
186 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending = NULL;
192 * Re-initialise the FIFO given the current buffer contents.
193 * Specifically, walk from head -> tail, pushing the FIFO contents
194 * back into the FIFO.
197 ath_edma_reinit_fifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
199 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
203 ATH_RX_LOCK_ASSERT(sc);
206 for (j = 0; j < re->m_fifo_depth; j++) {
208 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
209 "%s: Q%d: pos=%i, addr=0x%jx\n",
213 (uintmax_t)bf->bf_daddr);
214 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
215 INCR(i, re->m_fifolen);
218 /* Ensure this worked out right */
219 if (i != re->m_fifo_tail) {
220 device_printf(sc->sc_dev, "%s: i (%d) != tail! (%d)\n",
231 ath_edma_startrecv(struct ath_softc *sc)
233 struct ath_hal *ah = sc->sc_ah;
238 * Sanity check - are we being called whilst RX
239 * isn't stopped? If so, we may end up pushing
240 * too many entries into the RX FIFO and
248 * In theory the hardware has been initialised, right?
250 if (sc->sc_rx_resetted == 1) {
251 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
252 "%s: Re-initing HP FIFO\n", __func__);
253 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_HP);
254 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
255 "%s: Re-initing LP FIFO\n", __func__);
256 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_LP);
257 sc->sc_rx_resetted = 0;
259 device_printf(sc->sc_dev,
260 "%s: called without resetting chip?\n",
264 /* Add up to m_fifolen entries in each queue */
266 * These must occur after the above write so the FIFO buffers
267 * are pushed/tracked in the same order as the hardware will
270 * XXX TODO: is this really necessary? We should've stopped
271 * the hardware already and reinitialised it, so it's a no-op.
273 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_HP,
274 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_fifolen);
276 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_LP,
277 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_fifolen);
280 ath_hal_startpcurecv(ah);
283 * We're now doing RX DMA!
285 sc->sc_rx_stopped = 0;
293 ath_edma_recv_sched_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
298 ath_power_set_power_state(sc, HAL_PM_AWAKE);
301 ath_edma_recv_proc_queue(sc, qtype, dosched);
304 ath_power_restore_power_state(sc);
307 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
311 ath_edma_recv_sched(struct ath_softc *sc, int dosched)
315 ath_power_set_power_state(sc, HAL_PM_AWAKE);
318 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, dosched);
319 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, dosched);
322 ath_power_restore_power_state(sc);
325 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
329 ath_edma_recv_flush(struct ath_softc *sc)
332 DPRINTF(sc, ATH_DEBUG_RECV, "%s: called\n", __func__);
339 ath_power_set_power_state(sc, HAL_PM_AWAKE);
343 * Flush any active frames from FIFO -> deferred list
345 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 0);
346 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 0);
349 * Process what's in the deferred queue
352 * XXX: If we read the tsf/channoise here and then pass it in,
353 * we could restore the power state before processing
354 * the deferred queue.
356 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 0);
357 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 0);
360 ath_power_restore_power_state(sc);
369 * Process frames from the current queue into the deferred queue.
372 ath_edma_recv_proc_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
375 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
376 struct ath_rx_status *rs;
380 struct ath_hal *ah = sc->sc_ah;
385 tsf = ath_hal_gettsf64(ah);
386 nf = ath_hal_getchannoise(ah, sc->sc_curchan);
387 sc->sc_stats.ast_rx_noise = nf;
392 if (sc->sc_rx_resetted == 1) {
394 * XXX We shouldn't ever be scheduled if
395 * receive has been stopped - so complain
398 device_printf(sc->sc_dev,
399 "%s: sc_rx_resetted=1! Bad!\n",
407 bf = re->m_fifo[re->m_fifo_head];
408 /* This shouldn't occur! */
410 device_printf(sc->sc_dev, "%s: Q%d: NULL bf?\n",
419 * Sync descriptor memory - this also syncs the buffer for us.
420 * EDMA descriptors are in cached memory.
422 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
423 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
424 rs = &bf->bf_status.ds_rxstat;
425 bf->bf_rxstatus = ath_hal_rxprocdesc(ah, ds, bf->bf_daddr,
428 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
429 ath_printrxbuf(sc, bf, 0, bf->bf_rxstatus == HAL_OK);
430 #endif /* ATH_DEBUG */
432 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS))
433 if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS,
434 sc->sc_rx_statuslen, (char *) ds);
435 #endif /* ATH_DEBUG */
436 if (bf->bf_rxstatus == HAL_EINPROGRESS)
440 * Completed descriptor.
442 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
443 "%s: Q%d: completed!\n", __func__, qtype);
447 * We've been synced already, so unmap.
449 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
452 * Remove the FIFO entry and place it on the completion
455 re->m_fifo[re->m_fifo_head] = NULL;
456 TAILQ_INSERT_TAIL(&sc->sc_rx_rxlist[qtype], bf, bf_list);
458 /* Bump the descriptor FIFO stats */
459 INCR(re->m_fifo_head, re->m_fifolen);
461 /* XXX check it doesn't fall below 0 */
462 } while (re->m_fifo_depth > 0);
464 /* Append some more fresh frames to the FIFO */
466 ath_edma_rxfifo_alloc(sc, qtype, re->m_fifolen);
470 /* rx signal state monitoring */
471 ath_hal_rxmonitor(ah, &sc->sc_halstats, sc->sc_curchan);
473 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
474 "ath edma rx proc: npkts=%d\n",
481 * Flush the deferred queue.
483 * This destructively flushes the deferred queue - it doesn't
484 * call the wireless stack on each mbuf.
487 ath_edma_flush_deferred_queue(struct ath_softc *sc)
491 ATH_RX_LOCK_ASSERT(sc);
493 /* Free in one set, inside the lock */
494 while (! TAILQ_EMPTY(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP])) {
495 bf = TAILQ_FIRST(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP]);
496 TAILQ_REMOVE(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP], bf, bf_list);
497 /* Free the buffer/mbuf */
498 ath_edma_rxbuf_free(sc, bf);
500 while (! TAILQ_EMPTY(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP])) {
501 bf = TAILQ_FIRST(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP]);
502 TAILQ_REMOVE(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP], bf, bf_list);
503 /* Free the buffer/mbuf */
504 ath_edma_rxbuf_free(sc, bf);
509 ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
514 struct ath_buf *bf, *next;
515 struct ath_rx_status *rs;
522 nf = ath_hal_getchannoise(sc->sc_ah, sc->sc_curchan);
524 * XXX TODO: the NF/TSF should be stamped on the bufs themselves,
525 * otherwise we may end up adding in the wrong values if this
526 * is delayed too far..
528 tsf = ath_hal_gettsf64(sc->sc_ah);
530 /* Copy the list over */
532 TAILQ_CONCAT(&rxlist, &sc->sc_rx_rxlist[qtype], bf_list);
535 /* Handle the completed descriptors */
537 * XXX is this SAFE call needed? The ath_buf entries
538 * aren't modified by ath_rx_pkt, right?
540 TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
542 * Skip the RX descriptor status - start at the data offset
544 m_adj(bf->bf_m, sc->sc_rx_statuslen);
546 /* Handle the frame */
548 rs = &bf->bf_status.ds_rxstat;
551 if (ath_rx_pkt(sc, rs, bf->bf_rxstatus, tsf, nf, qtype, bf, m))
559 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
560 "ath edma rx deferred proc: ngood=%d\n",
563 /* Free in one set, inside the lock */
565 while (! TAILQ_EMPTY(&rxlist)) {
566 bf = TAILQ_FIRST(&rxlist);
567 TAILQ_REMOVE(&rxlist, bf, bf_list);
568 /* Free the buffer/mbuf */
569 ath_edma_rxbuf_free(sc, bf);
577 ath_edma_recv_tasklet(void *arg, int npending)
579 struct ath_softc *sc = (struct ath_softc *) arg;
580 struct ifnet *ifp = sc->sc_ifp;
581 #ifdef IEEE80211_SUPPORT_SUPERG
582 struct ieee80211com *ic = ifp->if_l2com;
585 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: called; npending=%d\n",
590 if (sc->sc_inreset_cnt > 0) {
591 device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; skipping\n",
600 ath_power_set_power_state(sc, HAL_PM_AWAKE);
603 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 1);
604 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 1);
606 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 1);
607 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 1);
610 * XXX: If we read the tsf/channoise here and then pass it in,
611 * we could restore the power state before processing
612 * the deferred queue.
615 ath_power_restore_power_state(sc);
618 /* XXX inside IF_LOCK ? */
619 #if defined(__DragonFly__)
620 if (!ifq_is_oactive(&ifp->if_snd)) {
622 if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
624 #ifdef IEEE80211_SUPPORT_SUPERG
625 ieee80211_ff_age_all(ic, 100);
627 #if defined(__DragonFly__)
628 if (! ifq_is_empty(&ifp->if_snd))
631 if (! IFQ_IS_EMPTY(&ifp->if_snd))
635 if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
636 taskqueue_enqueue(sc->sc_tq, &sc->sc_dfstask);
644 * Allocate an RX mbuf for the given ath_buf and initialise
647 * + Allocate a 4KB mbuf;
648 * + Setup the DMA map for the given buffer;
652 ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
659 ATH_RX_LOCK_ASSERT(sc);
661 #if defined(__DragonFly__)
662 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, sc->sc_edma_bufsize);
664 m = m_getm(NULL, sc->sc_edma_bufsize, M_NOWAIT, MT_DATA);
667 return (ENOBUFS); /* XXX ?*/
669 /* XXX warn/enforce alignment */
671 len = m->m_ext.ext_size;
673 device_printf(sc->sc_dev, "%s: called: m=%p, size=%d, mtod=%p\n",
680 m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
683 * Populate ath_buf fields.
685 bf->bf_desc = mtod(m, struct ath_desc *);
686 bf->bf_lastds = bf->bf_desc; /* XXX only really for TX? */
690 * Zero the descriptor and ensure it makes it out to the
691 * bounce buffer if one is required.
693 * XXX PREWRITE will copy the whole buffer; we only needed it
694 * to sync the first 32 DWORDS. Oh well.
696 memset(bf->bf_desc, '\0', sc->sc_rx_statuslen);
699 * Create DMA mapping.
701 #if defined(__DragonFly__)
702 error = bus_dmamap_load_mbuf_segment(
703 sc->sc_dmat, bf->bf_dmamap, m,
704 bf->bf_segs, 1, &bf->bf_nseg, BUS_DMA_NOWAIT);
706 error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
707 bf->bf_dmamap, m, bf->bf_segs, &bf->bf_nseg, BUS_DMA_NOWAIT);
711 device_printf(sc->sc_dev, "%s: failed; error=%d\n",
719 * Set daddr to the physical mapping page.
721 bf->bf_daddr = bf->bf_segs[0].ds_addr;
724 * Prepare for the upcoming read.
726 * We need to both sync some data into the buffer (the zero'ed
727 * descriptor payload) and also prepare for the read that's going
730 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
731 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
738 * Allocate a RX buffer.
740 static struct ath_buf *
741 ath_edma_rxbuf_alloc(struct ath_softc *sc)
746 ATH_RX_LOCK_ASSERT(sc);
748 /* Allocate buffer */
749 bf = TAILQ_FIRST(&sc->sc_rxbuf);
750 /* XXX shouldn't happen upon startup? */
752 device_printf(sc->sc_dev, "%s: nothing on rxbuf?!\n",
757 /* Remove it from the free list */
758 TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list);
760 /* Assign RX mbuf to it */
761 error = ath_edma_rxbuf_init(sc, bf);
763 device_printf(sc->sc_dev,
764 "%s: bf=%p, rxbuf alloc failed! error=%d\n",
768 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
776 ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf)
779 ATH_RX_LOCK_ASSERT(sc);
782 * Only unload the frame if we haven't consumed
783 * the mbuf via ath_rx_pkt().
786 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
792 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
796 * Allocate up to 'n' entries and push them onto the hardware FIFO.
798 * Return how many entries were successfully pushed onto the
802 ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype, int nbufs)
804 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
808 ATH_RX_LOCK_ASSERT(sc);
811 * Allocate buffers until the FIFO is full or nbufs is reached.
813 for (i = 0; i < nbufs && re->m_fifo_depth < re->m_fifolen; i++) {
814 /* Ensure the FIFO is already blank, complain loudly! */
815 if (re->m_fifo[re->m_fifo_tail] != NULL) {
816 device_printf(sc->sc_dev,
817 "%s: Q%d: fifo[%d] != NULL (%p)\n",
821 re->m_fifo[re->m_fifo_tail]);
824 ath_edma_rxbuf_free(sc, re->m_fifo[re->m_fifo_tail]);
826 /* XXX check it's not < 0 */
827 re->m_fifo[re->m_fifo_tail] = NULL;
830 bf = ath_edma_rxbuf_alloc(sc);
831 /* XXX should ensure the FIFO is not NULL? */
833 device_printf(sc->sc_dev,
834 "%s: Q%d: alloc failed: i=%d, nbufs=%d?\n",
842 re->m_fifo[re->m_fifo_tail] = bf;
844 /* Write to the RX FIFO */
845 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
846 "%s: Q%d: putrxbuf=%p (0x%jx)\n",
850 (uintmax_t) bf->bf_daddr);
851 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
854 INCR(re->m_fifo_tail, re->m_fifolen);
858 * Return how many were allocated.
860 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: Q%d: nbufs=%d, nalloced=%d\n",
869 ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype)
871 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
874 ATH_RX_LOCK_ASSERT(sc);
876 for (i = 0; i < re->m_fifolen; i++) {
877 if (re->m_fifo[i] != NULL) {
879 struct ath_buf *bf = re->m_fifo[i];
881 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
882 ath_printrxbuf(sc, bf, 0, HAL_OK);
884 ath_edma_rxbuf_free(sc, re->m_fifo[i]);
885 re->m_fifo[i] = NULL;
890 if (re->m_rxpending != NULL) {
891 m_freem(re->m_rxpending);
892 re->m_rxpending = NULL;
894 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
900 * Setup the initial RX FIFO structure.
903 ath_edma_setup_rxfifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
905 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
907 ATH_RX_LOCK_ASSERT(sc);
909 if (! ath_hal_getrxfifodepth(sc->sc_ah, qtype, &re->m_fifolen)) {
910 device_printf(sc->sc_dev, "%s: qtype=%d, failed\n",
917 device_printf(sc->sc_dev,
918 "%s: type=%d, FIFO depth = %d entries\n",
923 /* Allocate ath_buf FIFO array, pre-zero'ed */
924 re->m_fifo = kmalloc(sizeof(struct ath_buf *) * re->m_fifolen,
925 M_ATHDEV, M_INTWAIT | M_ZERO);
926 if (re->m_fifo == NULL) {
927 device_printf(sc->sc_dev, "%s: malloc failed\n",
933 * Set initial "empty" state.
935 re->m_rxpending = NULL;
936 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
942 ath_edma_rxfifo_free(struct ath_softc *sc, HAL_RX_QUEUE qtype)
944 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
946 device_printf(sc->sc_dev, "%s: called; qtype=%d\n",
950 kfree(re->m_fifo, M_ATHDEV);
956 ath_edma_dma_rxsetup(struct ath_softc *sc)
961 * Create RX DMA tag and buffers.
963 error = ath_descdma_setup_rx_edma(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
964 "rx", ath_rxbuf, sc->sc_rx_statuslen);
969 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_HP);
970 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_LP);
977 ath_edma_dma_rxteardown(struct ath_softc *sc)
981 ath_edma_flush_deferred_queue(sc);
982 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_HP);
983 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_HP);
985 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_LP);
986 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_LP);
989 /* Free RX ath_buf */
990 /* Free RX DMA tag */
991 if (sc->sc_rxdma.dd_desc_len != 0)
992 ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
998 ath_recv_setup_edma(struct ath_softc *sc)
1001 /* Set buffer size to 4k */
1002 sc->sc_edma_bufsize = 4096;
1004 /* Fetch EDMA field and buffer sizes */
1005 (void) ath_hal_getrxstatuslen(sc->sc_ah, &sc->sc_rx_statuslen);
1007 /* Configure the hardware with the RX buffer size */
1008 (void) ath_hal_setrxbufsize(sc->sc_ah, sc->sc_edma_bufsize -
1009 sc->sc_rx_statuslen);
1012 device_printf(sc->sc_dev, "RX status length: %d\n",
1013 sc->sc_rx_statuslen);
1014 device_printf(sc->sc_dev, "RX buffer size: %d\n",
1015 sc->sc_edma_bufsize);
1018 sc->sc_rx.recv_stop = ath_edma_stoprecv;
1019 sc->sc_rx.recv_start = ath_edma_startrecv;
1020 sc->sc_rx.recv_flush = ath_edma_recv_flush;
1021 sc->sc_rx.recv_tasklet = ath_edma_recv_tasklet;
1022 sc->sc_rx.recv_rxbuf_init = ath_edma_rxbuf_init;
1024 sc->sc_rx.recv_setup = ath_edma_dma_rxsetup;
1025 sc->sc_rx.recv_teardown = ath_edma_dma_rxteardown;
1027 sc->sc_rx.recv_sched = ath_edma_recv_sched;
1028 sc->sc_rx.recv_sched_queue = ath_edma_recv_sched_queue;