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>
33 * Driver for the Atheros Wireless LAN controller.
35 * This software is derived from work of Atsushi Onoe; his contribution
36 * is greatly appreciated.
42 * This is needed for register operations which are performed
43 * by the driver - eg, calls to ath_hal_gettsf32().
45 * It's also required for any AH_DEBUG checks in here, eg the
46 * module dependencies.
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/sysctl.h>
55 #include <sys/malloc.h>
57 #include <sys/mutex.h>
58 #include <sys/kernel.h>
59 #include <sys/socket.h>
60 #include <sys/sockio.h>
61 #include <sys/errno.h>
62 #include <sys/callout.h>
64 #include <sys/endian.h>
65 #include <sys/kthread.h>
66 #include <sys/taskqueue.h>
68 #include <sys/module.h>
72 #include <net/if_var.h>
73 #include <net/if_dl.h>
74 #include <net/if_media.h>
75 #include <net/if_types.h>
76 #include <net/if_arp.h>
77 #include <net/ethernet.h>
78 #include <net/if_llc.h>
80 #include <netproto/802_11/ieee80211_var.h>
81 #include <netproto/802_11/ieee80211_regdomain.h>
82 #ifdef IEEE80211_SUPPORT_SUPERG
83 #include <netproto/802_11/ieee80211_superg.h>
85 #ifdef IEEE80211_SUPPORT_TDMA
86 #include <netproto/802_11/ieee80211_tdma.h>
92 #include <netinet/in.h>
93 #include <netinet/if_ether.h>
96 #include <dev/netif/ath/ath/if_athvar.h>
97 #include <dev/netif/ath/ath_hal/ah_devid.h> /* XXX for softled */
98 #include <dev/netif/ath/ath_hal/ah_diagcodes.h>
100 #include <dev/netif/ath/ath/if_ath_debug.h>
101 #include <dev/netif/ath/ath/if_ath_misc.h>
102 #include <dev/netif/ath/ath/if_ath_tsf.h>
103 #include <dev/netif/ath/ath/if_ath_tx.h>
104 #include <dev/netif/ath/ath/if_ath_sysctl.h>
105 #include <dev/netif/ath/ath/if_ath_led.h>
106 #include <dev/netif/ath/ath/if_ath_keycache.h>
107 #include <dev/netif/ath/ath/if_ath_rx.h>
108 #include <dev/netif/ath/ath/if_ath_beacon.h>
109 #include <dev/netif/ath/ath/if_athdfs.h>
112 #include <dev/netif/ath/ath_tx99/ath_tx99.h>
115 #include <dev/netif/ath/ath/if_ath_rx_edma.h>
118 #include <dev/netif/ath/ath/if_ath_alq.h>
122 * some general macros
124 #define INCR(_l, _sz) (_l) ++; (_l) &= ((_sz) - 1)
125 #define DECR(_l, _sz) (_l) --; (_l) &= ((_sz) - 1)
127 MALLOC_DECLARE(M_ATHDEV);
132 * + Make sure the FIFO is correctly flushed and reinitialised
134 * + Verify multi-descriptor frames work!
135 * + There's a "memory use after free" which needs to be tracked down
136 * and fixed ASAP. I've seen this in the legacy path too, so it
137 * may be a generic RX path issue.
141 * XXX shuffle the function orders so these pre-declarations aren't
144 static int ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype,
146 static int ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype);
147 static void ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf);
148 static void ath_edma_recv_proc_queue(struct ath_softc *sc,
149 HAL_RX_QUEUE qtype, int dosched);
150 static int ath_edma_recv_proc_deferred_queue(struct ath_softc *sc,
151 HAL_RX_QUEUE qtype, int dosched);
154 ath_edma_stoprecv(struct ath_softc *sc, int dodelay)
156 struct ath_hal *ah = sc->sc_ah;
159 ath_hal_stoppcurecv(ah);
160 ath_hal_setrxfilter(ah, 0);
161 ath_hal_stopdmarecv(ah);
165 /* Flush RX pending for each queue */
166 /* XXX should generic-ify this */
167 if (sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending) {
168 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending);
169 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending = NULL;
172 if (sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending) {
173 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending);
174 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending = NULL;
180 * Re-initialise the FIFO given the current buffer contents.
181 * Specifically, walk from head -> tail, pushing the FIFO contents
182 * back into the FIFO.
185 ath_edma_reinit_fifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
187 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
191 ATH_RX_LOCK_ASSERT(sc);
194 for (j = 0; j < re->m_fifo_depth; j++) {
196 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
197 "%s: Q%d: pos=%i, addr=0x%jx\n",
201 (uintmax_t)bf->bf_daddr);
202 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
203 INCR(i, re->m_fifolen);
206 /* Ensure this worked out right */
207 if (i != re->m_fifo_tail) {
208 device_printf(sc->sc_dev, "%s: i (%d) != tail! (%d)\n",
218 * XXX TODO: this needs to reallocate the FIFO entries when a reset
219 * occurs, in case the FIFO is filled up and no new descriptors get
220 * thrown into the FIFO.
223 ath_edma_startrecv(struct ath_softc *sc)
225 struct ath_hal *ah = sc->sc_ah;
233 * Entries should only be written out if the
236 * XXX This isn't correct. I should be looking
237 * at the value of AR_RXDP_SIZE (0x0070) to determine
238 * how many entries are in here.
240 * A warm reset will clear the registers but not the FIFO.
242 * And I believe this is actually the address of the last
243 * handled buffer rather than the current FIFO pointer.
244 * So if no frames have been (yet) seen, we'll reinit the
247 * I'll chase that up at some point.
249 if (ath_hal_getrxbuf(sc->sc_ah, HAL_RX_QUEUE_HP) == 0) {
250 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
251 "%s: Re-initing HP FIFO\n", __func__);
252 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_HP);
254 if (ath_hal_getrxbuf(sc->sc_ah, HAL_RX_QUEUE_LP) == 0) {
255 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
256 "%s: Re-initing LP FIFO\n", __func__);
257 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_LP);
260 /* Add up to m_fifolen entries in each queue */
262 * These must occur after the above write so the FIFO buffers
263 * are pushed/tracked in the same order as the hardware will
266 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_HP,
267 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_fifolen);
269 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_LP,
270 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_fifolen);
273 ath_hal_startpcurecv(ah);
281 ath_edma_recv_sched_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
285 ath_edma_recv_proc_queue(sc, qtype, dosched);
286 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
290 ath_edma_recv_sched(struct ath_softc *sc, int dosched)
293 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, dosched);
294 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, dosched);
295 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
299 ath_edma_recv_flush(struct ath_softc *sc)
302 DPRINTF(sc, ATH_DEBUG_RECV, "%s: called\n", __func__);
309 * Flush any active frames from FIFO -> deferred list
311 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 0);
312 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 0);
315 * Process what's in the deferred queue
317 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 0);
318 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 0);
326 * Process frames from the current queue into the deferred queue.
329 ath_edma_recv_proc_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
332 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
333 struct ath_rx_status *rs;
337 struct ath_hal *ah = sc->sc_ah;
342 tsf = ath_hal_gettsf64(ah);
343 nf = ath_hal_getchannoise(ah, sc->sc_curchan);
344 sc->sc_stats.ast_rx_noise = nf;
349 bf = re->m_fifo[re->m_fifo_head];
350 /* This shouldn't occur! */
352 device_printf(sc->sc_dev, "%s: Q%d: NULL bf?\n",
361 * Sync descriptor memory - this also syncs the buffer for us.
362 * EDMA descriptors are in cached memory.
364 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
365 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
366 rs = &bf->bf_status.ds_rxstat;
367 bf->bf_rxstatus = ath_hal_rxprocdesc(ah, ds, bf->bf_daddr,
370 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
371 ath_printrxbuf(sc, bf, 0, bf->bf_rxstatus == HAL_OK);
372 #endif /* ATH_DEBUG */
374 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS))
375 if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS,
376 sc->sc_rx_statuslen, (char *) ds);
377 #endif /* ATH_DEBUG */
378 if (bf->bf_rxstatus == HAL_EINPROGRESS)
382 * Completed descriptor.
384 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
385 "%s: Q%d: completed!\n", __func__, qtype);
389 * We've been synced already, so unmap.
391 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
394 * Remove the FIFO entry and place it on the completion
397 re->m_fifo[re->m_fifo_head] = NULL;
398 TAILQ_INSERT_TAIL(&sc->sc_rx_rxlist[qtype], bf, bf_list);
400 /* Bump the descriptor FIFO stats */
401 INCR(re->m_fifo_head, re->m_fifolen);
403 /* XXX check it doesn't fall below 0 */
404 } while (re->m_fifo_depth > 0);
406 /* Append some more fresh frames to the FIFO */
408 ath_edma_rxfifo_alloc(sc, qtype, re->m_fifolen);
412 /* rx signal state monitoring */
413 ath_hal_rxmonitor(ah, &sc->sc_halstats, sc->sc_curchan);
415 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
416 "ath edma rx proc: npkts=%d\n",
419 /* Handle resched and kickpcu appropriately */
421 if (dosched && sc->sc_kickpcu) {
422 ATH_KTR(sc, ATH_KTR_ERROR, 0,
423 "ath_edma_recv_proc_queue(): kickpcu");
425 device_printf(sc->sc_dev,
426 "%s: handled npkts %d\n",
430 * XXX TODO: what should occur here? Just re-poke and
431 * re-enable the RX FIFO?
441 * Flush the deferred queue.
443 * This destructively flushes the deferred queue - it doesn't
444 * call the wireless stack on each mbuf.
447 ath_edma_flush_deferred_queue(struct ath_softc *sc)
449 struct ath_buf *bf, *next;
451 ATH_RX_LOCK_ASSERT(sc);
453 /* Free in one set, inside the lock */
454 TAILQ_FOREACH_SAFE(bf,
455 &sc->sc_rx_rxlist[HAL_RX_QUEUE_LP], bf_list, next) {
456 /* Free the buffer/mbuf */
457 ath_edma_rxbuf_free(sc, bf);
459 TAILQ_FOREACH_SAFE(bf,
460 &sc->sc_rx_rxlist[HAL_RX_QUEUE_HP], bf_list, next) {
461 /* Free the buffer/mbuf */
462 ath_edma_rxbuf_free(sc, bf);
467 ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
472 struct ath_buf *bf, *next;
473 struct ath_rx_status *rs;
480 nf = ath_hal_getchannoise(sc->sc_ah, sc->sc_curchan);
482 * XXX TODO: the NF/TSF should be stamped on the bufs themselves,
483 * otherwise we may end up adding in the wrong values if this
484 * is delayed too far..
486 tsf = ath_hal_gettsf64(sc->sc_ah);
488 /* Copy the list over */
490 TAILQ_CONCAT(&rxlist, &sc->sc_rx_rxlist[qtype], bf_list);
493 /* Handle the completed descriptors */
494 TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
496 * Skip the RX descriptor status - start at the data offset
498 m_adj(bf->bf_m, sc->sc_rx_statuslen);
500 /* Handle the frame */
502 rs = &bf->bf_status.ds_rxstat;
505 if (ath_rx_pkt(sc, rs, bf->bf_rxstatus, tsf, nf, qtype, bf, m))
513 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
514 "ath edma rx deferred proc: ngood=%d\n",
517 /* Free in one set, inside the lock */
519 TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
520 /* Free the buffer/mbuf */
521 ath_edma_rxbuf_free(sc, bf);
529 ath_edma_recv_tasklet(void *arg, int npending)
531 struct ath_softc *sc = (struct ath_softc *) arg;
532 struct ifnet *ifp = sc->sc_ifp;
533 #ifdef IEEE80211_SUPPORT_SUPERG
534 struct ieee80211com *ic = ifp->if_l2com;
537 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: called; npending=%d\n",
542 if (sc->sc_inreset_cnt > 0) {
543 device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; skipping\n",
551 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 1);
552 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 1);
554 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 1);
555 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 1);
557 /* XXX inside IF_LOCK ? */
558 if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
559 #ifdef IEEE80211_SUPPORT_SUPERG
560 ieee80211_ff_age_all(ic, 100);
562 if (! IFQ_IS_EMPTY(&ifp->if_snd))
565 if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
566 taskqueue_enqueue(sc->sc_tq, &sc->sc_dfstask);
574 * Allocate an RX mbuf for the given ath_buf and initialise
577 * + Allocate a 4KB mbuf;
578 * + Setup the DMA map for the given buffer;
582 ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
589 ATH_RX_LOCK_ASSERT(sc);
591 m = m_getm(NULL, sc->sc_edma_bufsize, M_NOWAIT, MT_DATA);
593 return (ENOBUFS); /* XXX ?*/
595 /* XXX warn/enforce alignment */
597 len = m->m_ext.ext_size;
599 device_printf(sc->sc_dev, "%s: called: m=%p, size=%d, mtod=%p\n",
606 m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
609 * Populate ath_buf fields.
611 bf->bf_desc = mtod(m, struct ath_desc *);
612 bf->bf_lastds = bf->bf_desc; /* XXX only really for TX? */
616 * Zero the descriptor and ensure it makes it out to the
617 * bounce buffer if one is required.
619 * XXX PREWRITE will copy the whole buffer; we only needed it
620 * to sync the first 32 DWORDS. Oh well.
622 memset(bf->bf_desc, '\0', sc->sc_rx_statuslen);
625 * Create DMA mapping.
627 error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
628 bf->bf_dmamap, m, bf->bf_segs, &bf->bf_nseg, BUS_DMA_NOWAIT);
631 device_printf(sc->sc_dev, "%s: failed; error=%d\n",
639 * Set daddr to the physical mapping page.
641 bf->bf_daddr = bf->bf_segs[0].ds_addr;
644 * Prepare for the upcoming read.
646 * We need to both sync some data into the buffer (the zero'ed
647 * descriptor payload) and also prepare for the read that's going
650 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
651 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
658 * Allocate a RX buffer.
660 static struct ath_buf *
661 ath_edma_rxbuf_alloc(struct ath_softc *sc)
666 ATH_RX_LOCK_ASSERT(sc);
668 /* Allocate buffer */
669 bf = TAILQ_FIRST(&sc->sc_rxbuf);
670 /* XXX shouldn't happen upon startup? */
672 device_printf(sc->sc_dev, "%s: nothing on rxbuf?!\n",
677 /* Remove it from the free list */
678 TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list);
680 /* Assign RX mbuf to it */
681 error = ath_edma_rxbuf_init(sc, bf);
683 device_printf(sc->sc_dev,
684 "%s: bf=%p, rxbuf alloc failed! error=%d\n",
688 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
696 ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf)
699 ATH_RX_LOCK_ASSERT(sc);
702 * Only unload the frame if we haven't consumed
703 * the mbuf via ath_rx_pkt().
706 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
712 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
716 * Allocate up to 'n' entries and push them onto the hardware FIFO.
718 * Return how many entries were successfully pushed onto the
722 ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype, int nbufs)
724 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
728 ATH_RX_LOCK_ASSERT(sc);
731 * Allocate buffers until the FIFO is full or nbufs is reached.
733 for (i = 0; i < nbufs && re->m_fifo_depth < re->m_fifolen; i++) {
734 /* Ensure the FIFO is already blank, complain loudly! */
735 if (re->m_fifo[re->m_fifo_tail] != NULL) {
736 device_printf(sc->sc_dev,
737 "%s: Q%d: fifo[%d] != NULL (%p)\n",
741 re->m_fifo[re->m_fifo_tail]);
744 ath_edma_rxbuf_free(sc, re->m_fifo[re->m_fifo_tail]);
746 /* XXX check it's not < 0 */
747 re->m_fifo[re->m_fifo_tail] = NULL;
750 bf = ath_edma_rxbuf_alloc(sc);
751 /* XXX should ensure the FIFO is not NULL? */
753 device_printf(sc->sc_dev,
754 "%s: Q%d: alloc failed: i=%d, nbufs=%d?\n",
762 re->m_fifo[re->m_fifo_tail] = bf;
764 /* Write to the RX FIFO */
765 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
766 "%s: Q%d: putrxbuf=%p (0x%jx)\n",
770 (uintmax_t) bf->bf_daddr);
771 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
774 INCR(re->m_fifo_tail, re->m_fifolen);
778 * Return how many were allocated.
780 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: Q%d: nbufs=%d, nalloced=%d\n",
789 ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype)
791 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
794 ATH_RX_LOCK_ASSERT(sc);
796 for (i = 0; i < re->m_fifolen; i++) {
797 if (re->m_fifo[i] != NULL) {
799 struct ath_buf *bf = re->m_fifo[i];
801 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
802 ath_printrxbuf(sc, bf, 0, HAL_OK);
804 ath_edma_rxbuf_free(sc, re->m_fifo[i]);
805 re->m_fifo[i] = NULL;
810 if (re->m_rxpending != NULL) {
811 m_freem(re->m_rxpending);
812 re->m_rxpending = NULL;
814 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
820 * Setup the initial RX FIFO structure.
823 ath_edma_setup_rxfifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
825 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
827 ATH_RX_LOCK_ASSERT(sc);
829 if (! ath_hal_getrxfifodepth(sc->sc_ah, qtype, &re->m_fifolen)) {
830 device_printf(sc->sc_dev, "%s: qtype=%d, failed\n",
835 device_printf(sc->sc_dev, "%s: type=%d, FIFO depth = %d entries\n",
840 /* Allocate ath_buf FIFO array, pre-zero'ed */
841 re->m_fifo = malloc(sizeof(struct ath_buf *) * re->m_fifolen,
844 if (re->m_fifo == NULL) {
845 device_printf(sc->sc_dev, "%s: malloc failed\n",
851 * Set initial "empty" state.
853 re->m_rxpending = NULL;
854 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
860 ath_edma_rxfifo_free(struct ath_softc *sc, HAL_RX_QUEUE qtype)
862 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
864 device_printf(sc->sc_dev, "%s: called; qtype=%d\n",
868 free(re->m_fifo, M_ATHDEV);
874 ath_edma_dma_rxsetup(struct ath_softc *sc)
879 * Create RX DMA tag and buffers.
881 error = ath_descdma_setup_rx_edma(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
882 "rx", ath_rxbuf, sc->sc_rx_statuslen);
887 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_HP);
888 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_LP);
895 ath_edma_dma_rxteardown(struct ath_softc *sc)
899 ath_edma_flush_deferred_queue(sc);
900 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_HP);
901 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_HP);
903 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_LP);
904 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_LP);
907 /* Free RX ath_buf */
908 /* Free RX DMA tag */
909 if (sc->sc_rxdma.dd_desc_len != 0)
910 ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
916 ath_recv_setup_edma(struct ath_softc *sc)
919 /* Set buffer size to 4k */
920 sc->sc_edma_bufsize = 4096;
922 /* Fetch EDMA field and buffer sizes */
923 (void) ath_hal_getrxstatuslen(sc->sc_ah, &sc->sc_rx_statuslen);
925 /* Configure the hardware with the RX buffer size */
926 (void) ath_hal_setrxbufsize(sc->sc_ah, sc->sc_edma_bufsize -
927 sc->sc_rx_statuslen);
929 device_printf(sc->sc_dev, "RX status length: %d\n",
930 sc->sc_rx_statuslen);
931 device_printf(sc->sc_dev, "RX buffer size: %d\n",
932 sc->sc_edma_bufsize);
934 sc->sc_rx.recv_stop = ath_edma_stoprecv;
935 sc->sc_rx.recv_start = ath_edma_startrecv;
936 sc->sc_rx.recv_flush = ath_edma_recv_flush;
937 sc->sc_rx.recv_tasklet = ath_edma_recv_tasklet;
938 sc->sc_rx.recv_rxbuf_init = ath_edma_rxbuf_init;
940 sc->sc_rx.recv_setup = ath_edma_dma_rxsetup;
941 sc->sc_rx.recv_teardown = ath_edma_dma_rxteardown;
943 sc->sc_rx.recv_sched = ath_edma_recv_sched;
944 sc->sc_rx.recv_sched_queue = ath_edma_recv_sched_queue;