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>
71 #include <sys/smp.h> /* for mp_ncpus */
73 #include <machine/bus.h>
76 #include <net/if_dl.h>
77 #include <net/if_media.h>
78 #include <net/if_types.h>
79 #include <net/if_arp.h>
80 #include <net/ethernet.h>
81 #include <net/if_llc.h>
83 #include <net80211/ieee80211_var.h>
84 #include <net80211/ieee80211_regdomain.h>
85 #ifdef IEEE80211_SUPPORT_SUPERG
86 #include <net80211/ieee80211_superg.h>
88 #ifdef IEEE80211_SUPPORT_TDMA
89 #include <net80211/ieee80211_tdma.h>
95 #include <netinet/in.h>
96 #include <netinet/if_ether.h>
99 #include <dev/ath/if_athvar.h>
100 #include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */
101 #include <dev/ath/ath_hal/ah_diagcodes.h>
103 #include <dev/ath/if_ath_debug.h>
104 #include <dev/ath/if_ath_misc.h>
105 #include <dev/ath/if_ath_tsf.h>
106 #include <dev/ath/if_ath_tx.h>
107 #include <dev/ath/if_ath_sysctl.h>
108 #include <dev/ath/if_ath_led.h>
109 #include <dev/ath/if_ath_keycache.h>
110 #include <dev/ath/if_ath_rx.h>
111 #include <dev/ath/if_ath_beacon.h>
112 #include <dev/ath/if_athdfs.h>
115 #include <dev/ath/ath_tx99/ath_tx99.h>
118 #include <dev/ath/if_ath_rx_edma.h>
121 #include <dev/ath/if_ath_alq.h>
125 * some general macros
127 #define INCR(_l, _sz) (_l) ++; (_l) &= ((_sz) - 1)
128 #define DECR(_l, _sz) (_l) --; (_l) &= ((_sz) - 1)
130 MALLOC_DECLARE(M_ATHDEV);
135 * + Make sure the FIFO is correctly flushed and reinitialised
137 * + Verify multi-descriptor frames work!
138 * + There's a "memory use after free" which needs to be tracked down
139 * and fixed ASAP. I've seen this in the legacy path too, so it
140 * may be a generic RX path issue.
144 * XXX shuffle the function orders so these pre-declarations aren't
147 static int ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype,
149 static int ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype);
150 static void ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf);
151 static void ath_edma_recv_proc_queue(struct ath_softc *sc,
152 HAL_RX_QUEUE qtype, int dosched);
153 static int ath_edma_recv_proc_deferred_queue(struct ath_softc *sc,
154 HAL_RX_QUEUE qtype, int dosched);
157 ath_edma_stoprecv(struct ath_softc *sc, int dodelay)
159 struct ath_hal *ah = sc->sc_ah;
162 ath_hal_stoppcurecv(ah);
163 ath_hal_setrxfilter(ah, 0);
164 ath_hal_stopdmarecv(ah);
168 /* Flush RX pending for each queue */
169 /* XXX should generic-ify this */
170 if (sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending) {
171 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending);
172 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending = NULL;
175 if (sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending) {
176 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending);
177 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending = NULL;
183 * Re-initialise the FIFO given the current buffer contents.
184 * Specifically, walk from head -> tail, pushing the FIFO contents
185 * back into the FIFO.
188 ath_edma_reinit_fifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
190 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
194 ATH_RX_LOCK_ASSERT(sc);
197 for (j = 0; j < re->m_fifo_depth; j++) {
199 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
200 "%s: Q%d: pos=%i, addr=0x%jx\n",
204 (uintmax_t)bf->bf_daddr);
205 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
206 INCR(i, re->m_fifolen);
209 /* Ensure this worked out right */
210 if (i != re->m_fifo_tail) {
211 device_printf(sc->sc_dev, "%s: i (%d) != tail! (%d)\n",
221 * XXX TODO: this needs to reallocate the FIFO entries when a reset
222 * occurs, in case the FIFO is filled up and no new descriptors get
223 * thrown into the FIFO.
226 ath_edma_startrecv(struct ath_softc *sc)
228 struct ath_hal *ah = sc->sc_ah;
236 * Entries should only be written out if the
239 * XXX This isn't correct. I should be looking
240 * at the value of AR_RXDP_SIZE (0x0070) to determine
241 * how many entries are in here.
243 * A warm reset will clear the registers but not the FIFO.
245 * And I believe this is actually the address of the last
246 * handled buffer rather than the current FIFO pointer.
247 * So if no frames have been (yet) seen, we'll reinit the
250 * I'll chase that up at some point.
252 if (ath_hal_getrxbuf(sc->sc_ah, HAL_RX_QUEUE_HP) == 0) {
253 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
254 "%s: Re-initing HP FIFO\n", __func__);
255 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_HP);
257 if (ath_hal_getrxbuf(sc->sc_ah, HAL_RX_QUEUE_LP) == 0) {
258 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
259 "%s: Re-initing LP FIFO\n", __func__);
260 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_LP);
263 /* Add up to m_fifolen entries in each queue */
265 * These must occur after the above write so the FIFO buffers
266 * are pushed/tracked in the same order as the hardware will
269 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_HP,
270 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_fifolen);
272 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_LP,
273 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_fifolen);
276 ath_hal_startpcurecv(ah);
284 ath_edma_recv_sched_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
288 ath_edma_recv_proc_queue(sc, qtype, dosched);
289 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
293 ath_edma_recv_sched(struct ath_softc *sc, int dosched)
296 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, dosched);
297 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, dosched);
298 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
302 ath_edma_recv_flush(struct ath_softc *sc)
305 DPRINTF(sc, ATH_DEBUG_RECV, "%s: called\n", __func__);
312 * Flush any active frames from FIFO -> deferred list
314 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 0);
315 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 0);
318 * Process what's in the deferred queue
320 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 0);
321 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 0);
329 * Process frames from the current queue into the deferred queue.
332 ath_edma_recv_proc_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
335 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
336 struct ath_rx_status *rs;
340 struct ath_hal *ah = sc->sc_ah;
345 tsf = ath_hal_gettsf64(ah);
346 nf = ath_hal_getchannoise(ah, sc->sc_curchan);
347 sc->sc_stats.ast_rx_noise = nf;
352 bf = re->m_fifo[re->m_fifo_head];
353 /* This shouldn't occur! */
355 device_printf(sc->sc_dev, "%s: Q%d: NULL bf?\n",
364 * Sync descriptor memory - this also syncs the buffer for us.
365 * EDMA descriptors are in cached memory.
367 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
368 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
369 rs = &bf->bf_status.ds_rxstat;
370 bf->bf_rxstatus = ath_hal_rxprocdesc(ah, ds, bf->bf_daddr,
373 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
374 ath_printrxbuf(sc, bf, 0, bf->bf_rxstatus == HAL_OK);
375 #endif /* ATH_DEBUG */
377 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS))
378 if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS,
379 sc->sc_rx_statuslen, (char *) ds);
380 #endif /* ATH_DEBUG */
381 if (bf->bf_rxstatus == HAL_EINPROGRESS)
385 * Completed descriptor.
387 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
388 "%s: Q%d: completed!\n", __func__, qtype);
392 * We've been synced already, so unmap.
394 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
397 * Remove the FIFO entry and place it on the completion
400 re->m_fifo[re->m_fifo_head] = NULL;
401 TAILQ_INSERT_TAIL(&sc->sc_rx_rxlist[qtype], bf, bf_list);
403 /* Bump the descriptor FIFO stats */
404 INCR(re->m_fifo_head, re->m_fifolen);
406 /* XXX check it doesn't fall below 0 */
407 } while (re->m_fifo_depth > 0);
409 /* Append some more fresh frames to the FIFO */
411 ath_edma_rxfifo_alloc(sc, qtype, re->m_fifolen);
415 /* rx signal state monitoring */
416 ath_hal_rxmonitor(ah, &sc->sc_halstats, sc->sc_curchan);
418 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
419 "ath edma rx proc: npkts=%d\n",
422 /* Handle resched and kickpcu appropriately */
424 if (dosched && sc->sc_kickpcu) {
425 ATH_KTR(sc, ATH_KTR_ERROR, 0,
426 "ath_edma_recv_proc_queue(): kickpcu");
428 device_printf(sc->sc_dev,
429 "%s: handled npkts %d\n",
433 * XXX TODO: what should occur here? Just re-poke and
434 * re-enable the RX FIFO?
444 * Flush the deferred queue.
446 * This destructively flushes the deferred queue - it doesn't
447 * call the wireless stack on each mbuf.
450 ath_edma_flush_deferred_queue(struct ath_softc *sc)
452 struct ath_buf *bf, *next;
454 ATH_RX_LOCK_ASSERT(sc);
456 /* Free in one set, inside the lock */
457 TAILQ_FOREACH_SAFE(bf,
458 &sc->sc_rx_rxlist[HAL_RX_QUEUE_LP], bf_list, next) {
459 /* Free the buffer/mbuf */
460 ath_edma_rxbuf_free(sc, bf);
462 TAILQ_FOREACH_SAFE(bf,
463 &sc->sc_rx_rxlist[HAL_RX_QUEUE_HP], bf_list, next) {
464 /* Free the buffer/mbuf */
465 ath_edma_rxbuf_free(sc, bf);
470 ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
475 struct ath_buf *bf, *next;
476 struct ath_rx_status *rs;
483 nf = ath_hal_getchannoise(sc->sc_ah, sc->sc_curchan);
485 * XXX TODO: the NF/TSF should be stamped on the bufs themselves,
486 * otherwise we may end up adding in the wrong values if this
487 * is delayed too far..
489 tsf = ath_hal_gettsf64(sc->sc_ah);
491 /* Copy the list over */
493 TAILQ_CONCAT(&rxlist, &sc->sc_rx_rxlist[qtype], bf_list);
496 /* Handle the completed descriptors */
497 TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
499 * Skip the RX descriptor status - start at the data offset
501 m_adj(bf->bf_m, sc->sc_rx_statuslen);
503 /* Handle the frame */
505 rs = &bf->bf_status.ds_rxstat;
508 if (ath_rx_pkt(sc, rs, bf->bf_rxstatus, tsf, nf, qtype, bf, m))
516 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
517 "ath edma rx deferred proc: ngood=%d\n",
520 /* Free in one set, inside the lock */
522 TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
523 /* Free the buffer/mbuf */
524 ath_edma_rxbuf_free(sc, bf);
532 ath_edma_recv_tasklet(void *arg, int npending)
534 struct ath_softc *sc = (struct ath_softc *) arg;
535 struct ifnet *ifp = sc->sc_ifp;
536 #ifdef IEEE80211_SUPPORT_SUPERG
537 struct ieee80211com *ic = ifp->if_l2com;
540 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: called; npending=%d\n",
545 if (sc->sc_inreset_cnt > 0) {
546 device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; skipping\n",
554 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 1);
555 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 1);
557 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 1);
558 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 1);
560 /* XXX inside IF_LOCK ? */
561 if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
562 #ifdef IEEE80211_SUPPORT_SUPERG
563 ieee80211_ff_age_all(ic, 100);
565 if (! IFQ_IS_EMPTY(&ifp->if_snd))
568 if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
569 taskqueue_enqueue(sc->sc_tq, &sc->sc_dfstask);
577 * Allocate an RX mbuf for the given ath_buf and initialise
580 * + Allocate a 4KB mbuf;
581 * + Setup the DMA map for the given buffer;
585 ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
592 ATH_RX_LOCK_ASSERT(sc);
594 m = m_getm(NULL, sc->sc_edma_bufsize, M_NOWAIT, MT_DATA);
596 return (ENOBUFS); /* XXX ?*/
598 /* XXX warn/enforce alignment */
600 len = m->m_ext.ext_size;
602 device_printf(sc->sc_dev, "%s: called: m=%p, size=%d, mtod=%p\n",
609 m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
612 * Populate ath_buf fields.
614 bf->bf_desc = mtod(m, struct ath_desc *);
615 bf->bf_lastds = bf->bf_desc; /* XXX only really for TX? */
619 * Zero the descriptor and ensure it makes it out to the
620 * bounce buffer if one is required.
622 * XXX PREWRITE will copy the whole buffer; we only needed it
623 * to sync the first 32 DWORDS. Oh well.
625 memset(bf->bf_desc, '\0', sc->sc_rx_statuslen);
628 * Create DMA mapping.
630 error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
631 bf->bf_dmamap, m, bf->bf_segs, &bf->bf_nseg, BUS_DMA_NOWAIT);
634 device_printf(sc->sc_dev, "%s: failed; error=%d\n",
642 * Set daddr to the physical mapping page.
644 bf->bf_daddr = bf->bf_segs[0].ds_addr;
647 * Prepare for the upcoming read.
649 * We need to both sync some data into the buffer (the zero'ed
650 * descriptor payload) and also prepare for the read that's going
653 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
654 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
661 * Allocate a RX buffer.
663 static struct ath_buf *
664 ath_edma_rxbuf_alloc(struct ath_softc *sc)
669 ATH_RX_LOCK_ASSERT(sc);
671 /* Allocate buffer */
672 bf = TAILQ_FIRST(&sc->sc_rxbuf);
673 /* XXX shouldn't happen upon startup? */
675 device_printf(sc->sc_dev, "%s: nothing on rxbuf?!\n",
680 /* Remove it from the free list */
681 TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list);
683 /* Assign RX mbuf to it */
684 error = ath_edma_rxbuf_init(sc, bf);
686 device_printf(sc->sc_dev,
687 "%s: bf=%p, rxbuf alloc failed! error=%d\n",
691 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
699 ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf)
702 ATH_RX_LOCK_ASSERT(sc);
705 * Only unload the frame if we haven't consumed
706 * the mbuf via ath_rx_pkt().
709 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
715 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
719 * Allocate up to 'n' entries and push them onto the hardware FIFO.
721 * Return how many entries were successfully pushed onto the
725 ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype, int nbufs)
727 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
731 ATH_RX_LOCK_ASSERT(sc);
734 * Allocate buffers until the FIFO is full or nbufs is reached.
736 for (i = 0; i < nbufs && re->m_fifo_depth < re->m_fifolen; i++) {
737 /* Ensure the FIFO is already blank, complain loudly! */
738 if (re->m_fifo[re->m_fifo_tail] != NULL) {
739 device_printf(sc->sc_dev,
740 "%s: Q%d: fifo[%d] != NULL (%p)\n",
744 re->m_fifo[re->m_fifo_tail]);
747 ath_edma_rxbuf_free(sc, re->m_fifo[re->m_fifo_tail]);
749 /* XXX check it's not < 0 */
750 re->m_fifo[re->m_fifo_tail] = NULL;
753 bf = ath_edma_rxbuf_alloc(sc);
754 /* XXX should ensure the FIFO is not NULL? */
756 device_printf(sc->sc_dev,
757 "%s: Q%d: alloc failed: i=%d, nbufs=%d?\n",
765 re->m_fifo[re->m_fifo_tail] = bf;
767 /* Write to the RX FIFO */
768 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
769 "%s: Q%d: putrxbuf=%p (0x%jx)\n",
773 (uintmax_t) bf->bf_daddr);
774 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
777 INCR(re->m_fifo_tail, re->m_fifolen);
781 * Return how many were allocated.
783 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: Q%d: nbufs=%d, nalloced=%d\n",
792 ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype)
794 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
797 ATH_RX_LOCK_ASSERT(sc);
799 for (i = 0; i < re->m_fifolen; i++) {
800 if (re->m_fifo[i] != NULL) {
802 struct ath_buf *bf = re->m_fifo[i];
804 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
805 ath_printrxbuf(sc, bf, 0, HAL_OK);
807 ath_edma_rxbuf_free(sc, re->m_fifo[i]);
808 re->m_fifo[i] = NULL;
813 if (re->m_rxpending != NULL) {
814 m_freem(re->m_rxpending);
815 re->m_rxpending = NULL;
817 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
823 * Setup the initial RX FIFO structure.
826 ath_edma_setup_rxfifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
828 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
830 ATH_RX_LOCK_ASSERT(sc);
832 if (! ath_hal_getrxfifodepth(sc->sc_ah, qtype, &re->m_fifolen)) {
833 device_printf(sc->sc_dev, "%s: qtype=%d, failed\n",
838 device_printf(sc->sc_dev, "%s: type=%d, FIFO depth = %d entries\n",
843 /* Allocate ath_buf FIFO array, pre-zero'ed */
844 re->m_fifo = malloc(sizeof(struct ath_buf *) * re->m_fifolen,
847 if (re->m_fifo == NULL) {
848 device_printf(sc->sc_dev, "%s: malloc failed\n",
854 * Set initial "empty" state.
856 re->m_rxpending = NULL;
857 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
863 ath_edma_rxfifo_free(struct ath_softc *sc, HAL_RX_QUEUE qtype)
865 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
867 device_printf(sc->sc_dev, "%s: called; qtype=%d\n",
871 free(re->m_fifo, M_ATHDEV);
877 ath_edma_dma_rxsetup(struct ath_softc *sc)
882 * Create RX DMA tag and buffers.
884 error = ath_descdma_setup_rx_edma(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
885 "rx", ath_rxbuf, sc->sc_rx_statuslen);
890 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_HP);
891 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_LP);
898 ath_edma_dma_rxteardown(struct ath_softc *sc)
902 ath_edma_flush_deferred_queue(sc);
903 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_HP);
904 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_HP);
906 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_LP);
907 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_LP);
910 /* Free RX ath_buf */
911 /* Free RX DMA tag */
912 if (sc->sc_rxdma.dd_desc_len != 0)
913 ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
919 ath_recv_setup_edma(struct ath_softc *sc)
922 /* Set buffer size to 4k */
923 sc->sc_edma_bufsize = 4096;
925 /* Fetch EDMA field and buffer sizes */
926 (void) ath_hal_getrxstatuslen(sc->sc_ah, &sc->sc_rx_statuslen);
928 /* Configure the hardware with the RX buffer size */
929 (void) ath_hal_setrxbufsize(sc->sc_ah, sc->sc_edma_bufsize -
930 sc->sc_rx_statuslen);
932 device_printf(sc->sc_dev, "RX status length: %d\n",
933 sc->sc_rx_statuslen);
934 device_printf(sc->sc_dev, "RX buffer size: %d\n",
935 sc->sc_edma_bufsize);
937 sc->sc_rx.recv_stop = ath_edma_stoprecv;
938 sc->sc_rx.recv_start = ath_edma_startrecv;
939 sc->sc_rx.recv_flush = ath_edma_recv_flush;
940 sc->sc_rx.recv_tasklet = ath_edma_recv_tasklet;
941 sc->sc_rx.recv_rxbuf_init = ath_edma_rxbuf_init;
943 sc->sc_rx.recv_setup = ath_edma_dma_rxsetup;
944 sc->sc_rx.recv_teardown = ath_edma_dma_rxteardown;
946 sc->sc_rx.recv_sched = ath_edma_recv_sched;
947 sc->sc_rx.recv_sched_queue = ath_edma_recv_sched_queue;