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, MERCHANTABILITY
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/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>
71 #if defined(__DragonFly__)
74 #include <sys/smp.h> /* for mp_ncpus */
75 #include <machine/bus.h>
79 #include <net/if_var.h>
80 #include <net/if_dl.h>
81 #include <net/if_media.h>
82 #include <net/if_types.h>
83 #include <net/if_arp.h>
84 #include <net/ethernet.h>
85 #include <net/if_llc.h>
86 #if defined(__DragonFly__)
87 #include <net/ifq_var.h>
90 #include <netproto/802_11/ieee80211_var.h>
91 #include <netproto/802_11/ieee80211_regdomain.h>
92 #ifdef IEEE80211_SUPPORT_SUPERG
93 #include <netproto/802_11/ieee80211_superg.h>
95 #ifdef IEEE80211_SUPPORT_TDMA
96 #include <netproto/802_11/ieee80211_tdma.h>
102 #include <netinet/in.h>
103 #include <netinet/if_ether.h>
106 #include <dev/netif/ath/ath/if_athvar.h>
107 #include <dev/netif/ath/ath_hal/ah_devid.h> /* XXX for softled */
108 #include <dev/netif/ath/ath_hal/ah_diagcodes.h>
110 #include <dev/netif/ath/ath/if_ath_debug.h>
111 #include <dev/netif/ath/ath/if_ath_misc.h>
112 #include <dev/netif/ath/ath/if_ath_tsf.h>
113 #include <dev/netif/ath/ath/if_ath_tx.h>
114 #include <dev/netif/ath/ath/if_ath_sysctl.h>
115 #include <dev/netif/ath/ath/if_ath_led.h>
116 #include <dev/netif/ath/ath/if_ath_keycache.h>
117 #include <dev/netif/ath/ath/if_ath_rx.h>
118 #include <dev/netif/ath/ath/if_ath_beacon.h>
119 #include <dev/netif/ath/ath/if_athdfs.h>
120 #include <dev/netif/ath/ath/if_ath_descdma.h>
123 #include <dev/netif/ath/ath_tx99/ath_tx99.h>
126 #include <dev/netif/ath/ath/if_ath_rx_edma.h>
129 #include <dev/netif/ath/ath/if_ath_alq.h>
133 * some general macros
135 #define INCR(_l, _sz) (_l) ++; (_l) &= ((_sz) - 1)
136 #define DECR(_l, _sz) (_l) --; (_l) &= ((_sz) - 1)
138 MALLOC_DECLARE(M_ATHDEV);
143 * + Make sure the FIFO is correctly flushed and reinitialised
145 * + Verify multi-descriptor frames work!
146 * + There's a "memory use after free" which needs to be tracked down
147 * and fixed ASAP. I've seen this in the legacy path too, so it
148 * may be a generic RX path issue.
152 * XXX shuffle the function orders so these pre-declarations aren't
155 static int ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype,
157 static int ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype);
158 static void ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf);
159 static void ath_edma_recv_proc_queue(struct ath_softc *sc,
160 HAL_RX_QUEUE qtype, int dosched);
161 static int ath_edma_recv_proc_deferred_queue(struct ath_softc *sc,
162 HAL_RX_QUEUE qtype, int dosched);
165 ath_edma_stoprecv(struct ath_softc *sc, int dodelay)
167 struct ath_hal *ah = sc->sc_ah;
171 ath_hal_stoppcurecv(ah);
172 ath_hal_setrxfilter(ah, 0);
177 if (ath_hal_stopdmarecv(ah) == AH_TRUE)
178 sc->sc_rx_stopped = 1;
181 * Give the various bus FIFOs (not EDMA descriptor FIFO)
182 * time to finish flushing out data.
186 /* Flush RX pending for each queue */
187 /* XXX should generic-ify this */
188 if (sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending) {
189 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending);
190 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_rxpending = NULL;
193 if (sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending) {
194 m_freem(sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending);
195 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_rxpending = NULL;
201 * Re-initialise the FIFO given the current buffer contents.
202 * Specifically, walk from head -> tail, pushing the FIFO contents
203 * back into the FIFO.
206 ath_edma_reinit_fifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
208 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
212 ATH_RX_LOCK_ASSERT(sc);
215 for (j = 0; j < re->m_fifo_depth; j++) {
217 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
218 "%s: Q%d: pos=%i, addr=0x%jx\n",
222 (uintmax_t)bf->bf_daddr);
223 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
224 INCR(i, re->m_fifolen);
227 /* Ensure this worked out right */
228 if (i != re->m_fifo_tail) {
229 device_printf(sc->sc_dev, "%s: i (%d) != tail! (%d)\n",
240 ath_edma_startrecv(struct ath_softc *sc)
242 struct ath_hal *ah = sc->sc_ah;
247 * Sanity check - are we being called whilst RX
248 * isn't stopped? If so, we may end up pushing
249 * too many entries into the RX FIFO and
257 * In theory the hardware has been initialised, right?
259 if (sc->sc_rx_resetted == 1) {
260 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
261 "%s: Re-initing HP FIFO\n", __func__);
262 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_HP);
263 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
264 "%s: Re-initing LP FIFO\n", __func__);
265 ath_edma_reinit_fifo(sc, HAL_RX_QUEUE_LP);
266 sc->sc_rx_resetted = 0;
268 device_printf(sc->sc_dev,
269 "%s: called without resetting chip?\n",
273 /* Add up to m_fifolen entries in each queue */
275 * These must occur after the above write so the FIFO buffers
276 * are pushed/tracked in the same order as the hardware will
279 * XXX TODO: is this really necessary? We should've stopped
280 * the hardware already and reinitialised it, so it's a no-op.
282 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_HP,
283 sc->sc_rxedma[HAL_RX_QUEUE_HP].m_fifolen);
285 ath_edma_rxfifo_alloc(sc, HAL_RX_QUEUE_LP,
286 sc->sc_rxedma[HAL_RX_QUEUE_LP].m_fifolen);
289 ath_hal_startpcurecv(ah);
292 * We're now doing RX DMA!
294 sc->sc_rx_stopped = 0;
302 ath_edma_recv_sched_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
307 ath_power_set_power_state(sc, HAL_PM_AWAKE);
310 ath_edma_recv_proc_queue(sc, qtype, dosched);
313 ath_power_restore_power_state(sc);
316 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
320 ath_edma_recv_sched(struct ath_softc *sc, int dosched)
324 ath_power_set_power_state(sc, HAL_PM_AWAKE);
327 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, dosched);
328 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, dosched);
331 ath_power_restore_power_state(sc);
334 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask);
338 ath_edma_recv_flush(struct ath_softc *sc)
341 DPRINTF(sc, ATH_DEBUG_RECV, "%s: called\n", __func__);
348 ath_power_set_power_state(sc, HAL_PM_AWAKE);
352 * Flush any active frames from FIFO -> deferred list
354 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 0);
355 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 0);
358 * Process what's in the deferred queue
361 * XXX: If we read the tsf/channoise here and then pass it in,
362 * we could restore the power state before processing
363 * the deferred queue.
365 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 0);
366 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 0);
369 ath_power_restore_power_state(sc);
378 * Process frames from the current queue into the deferred queue.
381 ath_edma_recv_proc_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
384 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
385 struct ath_rx_status *rs;
389 struct ath_hal *ah = sc->sc_ah;
394 tsf = ath_hal_gettsf64(ah);
395 nf = ath_hal_getchannoise(ah, sc->sc_curchan);
396 sc->sc_stats.ast_rx_noise = nf;
401 if (sc->sc_rx_resetted == 1) {
403 * XXX We shouldn't ever be scheduled if
404 * receive has been stopped - so complain
407 device_printf(sc->sc_dev,
408 "%s: sc_rx_resetted=1! Bad!\n",
416 bf = re->m_fifo[re->m_fifo_head];
417 /* This shouldn't occur! */
419 device_printf(sc->sc_dev, "%s: Q%d: NULL bf?\n",
428 * Sync descriptor memory - this also syncs the buffer for us.
429 * EDMA descriptors are in cached memory.
431 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
432 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
433 rs = &bf->bf_status.ds_rxstat;
434 bf->bf_rxstatus = ath_hal_rxprocdesc(ah, ds, bf->bf_daddr,
437 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
438 ath_printrxbuf(sc, bf, 0, bf->bf_rxstatus == HAL_OK);
439 #endif /* ATH_DEBUG */
441 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS))
442 if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_RXSTATUS,
443 sc->sc_rx_statuslen, (char *) ds);
444 #endif /* ATH_DEBUG */
445 if (bf->bf_rxstatus == HAL_EINPROGRESS)
449 * Completed descriptor.
451 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
452 "%s: Q%d: completed!\n", __func__, qtype);
456 * We've been synced already, so unmap.
458 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
461 * Remove the FIFO entry and place it on the completion
464 re->m_fifo[re->m_fifo_head] = NULL;
465 TAILQ_INSERT_TAIL(&sc->sc_rx_rxlist[qtype], bf, bf_list);
467 /* Bump the descriptor FIFO stats */
468 INCR(re->m_fifo_head, re->m_fifolen);
470 /* XXX check it doesn't fall below 0 */
471 } while (re->m_fifo_depth > 0);
473 /* Append some more fresh frames to the FIFO */
475 ath_edma_rxfifo_alloc(sc, qtype, re->m_fifolen);
479 /* rx signal state monitoring */
480 ath_hal_rxmonitor(ah, &sc->sc_halstats, sc->sc_curchan);
482 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
483 "ath edma rx proc: npkts=%d\n",
490 * Flush the deferred queue.
492 * This destructively flushes the deferred queue - it doesn't
493 * call the wireless stack on each mbuf.
496 ath_edma_flush_deferred_queue(struct ath_softc *sc)
500 ATH_RX_LOCK_ASSERT(sc);
502 /* Free in one set, inside the lock */
503 while (! TAILQ_EMPTY(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP])) {
504 bf = TAILQ_FIRST(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP]);
505 TAILQ_REMOVE(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP], bf, bf_list);
506 /* Free the buffer/mbuf */
507 ath_edma_rxbuf_free(sc, bf);
509 while (! TAILQ_EMPTY(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP])) {
510 bf = TAILQ_FIRST(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP]);
511 TAILQ_REMOVE(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP], bf, bf_list);
512 /* Free the buffer/mbuf */
513 ath_edma_rxbuf_free(sc, bf);
518 ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
523 struct ath_buf *bf, *next;
524 struct ath_rx_status *rs;
531 nf = ath_hal_getchannoise(sc->sc_ah, sc->sc_curchan);
533 * XXX TODO: the NF/TSF should be stamped on the bufs themselves,
534 * otherwise we may end up adding in the wrong values if this
535 * is delayed too far..
537 tsf = ath_hal_gettsf64(sc->sc_ah);
539 /* Copy the list over */
541 TAILQ_CONCAT(&rxlist, &sc->sc_rx_rxlist[qtype], bf_list);
544 /* Handle the completed descriptors */
546 * XXX is this SAFE call needed? The ath_buf entries
547 * aren't modified by ath_rx_pkt, right?
549 TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
551 * Skip the RX descriptor status - start at the data offset
553 m_adj(bf->bf_m, sc->sc_rx_statuslen);
555 /* Handle the frame */
557 rs = &bf->bf_status.ds_rxstat;
560 if (ath_rx_pkt(sc, rs, bf->bf_rxstatus, tsf, nf, qtype, bf, m))
568 ATH_KTR(sc, ATH_KTR_INTERRUPTS, 1,
569 "ath edma rx deferred proc: ngood=%d\n",
572 /* Free in one set, inside the lock */
574 while (! TAILQ_EMPTY(&rxlist)) {
575 bf = TAILQ_FIRST(&rxlist);
576 TAILQ_REMOVE(&rxlist, bf, bf_list);
577 /* Free the buffer/mbuf */
578 ath_edma_rxbuf_free(sc, bf);
586 ath_edma_recv_tasklet(void *arg, int npending)
588 struct ath_softc *sc = (struct ath_softc *) arg;
589 #ifdef IEEE80211_SUPPORT_SUPERG
590 struct ieee80211com *ic = &sc->sc_ic;
593 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: called; npending=%d\n",
598 if (sc->sc_inreset_cnt > 0) {
599 device_printf(sc->sc_dev, "%s: sc_inreset_cnt > 0; skipping\n",
608 ath_power_set_power_state(sc, HAL_PM_AWAKE);
611 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_HP, 1);
612 ath_edma_recv_proc_queue(sc, HAL_RX_QUEUE_LP, 1);
614 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_HP, 1);
615 ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 1);
618 * XXX: If we read the tsf/channoise here and then pass it in,
619 * we could restore the power state before processing
620 * the deferred queue.
623 ath_power_restore_power_state(sc);
626 #ifdef IEEE80211_SUPPORT_SUPERG
627 ieee80211_ff_age_all(ic, 100);
629 if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
630 taskqueue_enqueue(sc->sc_tq, &sc->sc_dfstask);
638 * Allocate an RX mbuf for the given ath_buf and initialise
641 * + Allocate a 4KB mbuf;
642 * + Setup the DMA map for the given buffer;
646 ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
653 ATH_RX_LOCK_ASSERT(sc);
655 #if defined(__DragonFly__)
656 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, sc->sc_edma_bufsize);
658 m = m_getm(NULL, sc->sc_edma_bufsize, M_NOWAIT, MT_DATA);
661 return (ENOBUFS); /* XXX ?*/
663 /* XXX warn/enforce alignment */
665 len = m->m_ext.ext_size;
667 device_printf(sc->sc_dev, "%s: called: m=%p, size=%d, mtod=%p\n",
674 m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
677 * Populate ath_buf fields.
679 bf->bf_desc = mtod(m, struct ath_desc *);
680 bf->bf_lastds = bf->bf_desc; /* XXX only really for TX? */
684 * Zero the descriptor and ensure it makes it out to the
685 * bounce buffer if one is required.
687 * XXX PREWRITE will copy the whole buffer; we only needed it
688 * to sync the first 32 DWORDS. Oh well.
690 memset(bf->bf_desc, '\0', sc->sc_rx_statuslen);
693 * Create DMA mapping.
695 #if defined(__DragonFly__)
696 error = bus_dmamap_load_mbuf_segment(
697 sc->sc_dmat, bf->bf_dmamap, m,
698 bf->bf_segs, 1, &bf->bf_nseg, BUS_DMA_NOWAIT);
700 error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
701 bf->bf_dmamap, m, bf->bf_segs, &bf->bf_nseg, BUS_DMA_NOWAIT);
705 device_printf(sc->sc_dev, "%s: failed; error=%d\n",
713 * Set daddr to the physical mapping page.
715 bf->bf_daddr = bf->bf_segs[0].ds_addr;
718 * Prepare for the upcoming read.
720 * We need to both sync some data into the buffer (the zero'ed
721 * descriptor payload) and also prepare for the read that's going
724 bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
725 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
732 * Allocate a RX buffer.
734 static struct ath_buf *
735 ath_edma_rxbuf_alloc(struct ath_softc *sc)
740 ATH_RX_LOCK_ASSERT(sc);
742 /* Allocate buffer */
743 bf = TAILQ_FIRST(&sc->sc_rxbuf);
744 /* XXX shouldn't happen upon startup? */
746 device_printf(sc->sc_dev, "%s: nothing on rxbuf?!\n",
751 /* Remove it from the free list */
752 TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list);
754 /* Assign RX mbuf to it */
755 error = ath_edma_rxbuf_init(sc, bf);
757 device_printf(sc->sc_dev,
758 "%s: bf=%p, rxbuf alloc failed! error=%d\n",
762 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
770 ath_edma_rxbuf_free(struct ath_softc *sc, struct ath_buf *bf)
773 ATH_RX_LOCK_ASSERT(sc);
776 * Only unload the frame if we haven't consumed
777 * the mbuf via ath_rx_pkt().
780 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
786 TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
790 * Allocate up to 'n' entries and push them onto the hardware FIFO.
792 * Return how many entries were successfully pushed onto the
796 ath_edma_rxfifo_alloc(struct ath_softc *sc, HAL_RX_QUEUE qtype, int nbufs)
798 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
802 ATH_RX_LOCK_ASSERT(sc);
805 * Allocate buffers until the FIFO is full or nbufs is reached.
807 for (i = 0; i < nbufs && re->m_fifo_depth < re->m_fifolen; i++) {
808 /* Ensure the FIFO is already blank, complain loudly! */
809 if (re->m_fifo[re->m_fifo_tail] != NULL) {
810 device_printf(sc->sc_dev,
811 "%s: Q%d: fifo[%d] != NULL (%p)\n",
815 re->m_fifo[re->m_fifo_tail]);
818 ath_edma_rxbuf_free(sc, re->m_fifo[re->m_fifo_tail]);
820 /* XXX check it's not < 0 */
821 re->m_fifo[re->m_fifo_tail] = NULL;
824 bf = ath_edma_rxbuf_alloc(sc);
825 /* XXX should ensure the FIFO is not NULL? */
827 device_printf(sc->sc_dev,
828 "%s: Q%d: alloc failed: i=%d, nbufs=%d?\n",
836 re->m_fifo[re->m_fifo_tail] = bf;
838 /* Write to the RX FIFO */
839 DPRINTF(sc, ATH_DEBUG_EDMA_RX,
840 "%s: Q%d: putrxbuf=%p (0x%jx)\n",
844 (uintmax_t) bf->bf_daddr);
845 ath_hal_putrxbuf(sc->sc_ah, bf->bf_daddr, qtype);
848 INCR(re->m_fifo_tail, re->m_fifolen);
852 * Return how many were allocated.
854 DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: Q%d: nbufs=%d, nalloced=%d\n",
863 ath_edma_rxfifo_flush(struct ath_softc *sc, HAL_RX_QUEUE qtype)
865 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
868 ATH_RX_LOCK_ASSERT(sc);
870 for (i = 0; i < re->m_fifolen; i++) {
871 if (re->m_fifo[i] != NULL) {
873 struct ath_buf *bf = re->m_fifo[i];
875 if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
876 ath_printrxbuf(sc, bf, 0, HAL_OK);
878 ath_edma_rxbuf_free(sc, re->m_fifo[i]);
879 re->m_fifo[i] = NULL;
884 if (re->m_rxpending != NULL) {
885 m_freem(re->m_rxpending);
886 re->m_rxpending = NULL;
888 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
894 * Setup the initial RX FIFO structure.
897 ath_edma_setup_rxfifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
899 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
901 ATH_RX_LOCK_ASSERT(sc);
903 if (! ath_hal_getrxfifodepth(sc->sc_ah, qtype, &re->m_fifolen)) {
904 device_printf(sc->sc_dev, "%s: qtype=%d, failed\n",
911 device_printf(sc->sc_dev,
912 "%s: type=%d, FIFO depth = %d entries\n",
917 /* Allocate ath_buf FIFO array, pre-zero'ed */
918 /* DragonFly: note use of M_INTWAIT */
919 re->m_fifo = kmalloc(sizeof(struct ath_buf *) * re->m_fifolen,
920 M_ATHDEV, M_INTWAIT | M_ZERO);
921 if (re->m_fifo == NULL) {
922 device_printf(sc->sc_dev, "%s: malloc failed\n",
928 * Set initial "empty" state.
930 re->m_rxpending = NULL;
931 re->m_fifo_head = re->m_fifo_tail = re->m_fifo_depth = 0;
937 ath_edma_rxfifo_free(struct ath_softc *sc, HAL_RX_QUEUE qtype)
939 struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
941 device_printf(sc->sc_dev, "%s: called; qtype=%d\n",
945 kfree(re->m_fifo, M_ATHDEV);
951 ath_edma_dma_rxsetup(struct ath_softc *sc)
956 * Create RX DMA tag and buffers.
958 error = ath_descdma_setup_rx_edma(sc, &sc->sc_rxdma, &sc->sc_rxbuf,
959 "rx", ath_rxbuf, sc->sc_rx_statuslen);
964 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_HP);
965 (void) ath_edma_setup_rxfifo(sc, HAL_RX_QUEUE_LP);
972 ath_edma_dma_rxteardown(struct ath_softc *sc)
976 ath_edma_flush_deferred_queue(sc);
977 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_HP);
978 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_HP);
980 ath_edma_rxfifo_flush(sc, HAL_RX_QUEUE_LP);
981 ath_edma_rxfifo_free(sc, HAL_RX_QUEUE_LP);
984 /* Free RX ath_buf */
985 /* Free RX DMA tag */
986 if (sc->sc_rxdma.dd_desc_len != 0)
987 ath_descdma_cleanup(sc, &sc->sc_rxdma, &sc->sc_rxbuf);
993 ath_recv_setup_edma(struct ath_softc *sc)
996 /* Set buffer size to 4k */
997 sc->sc_edma_bufsize = 4096;
999 /* Fetch EDMA field and buffer sizes */
1000 (void) ath_hal_getrxstatuslen(sc->sc_ah, &sc->sc_rx_statuslen);
1002 /* Configure the hardware with the RX buffer size */
1003 (void) ath_hal_setrxbufsize(sc->sc_ah, sc->sc_edma_bufsize -
1004 sc->sc_rx_statuslen);
1007 device_printf(sc->sc_dev, "RX status length: %d\n",
1008 sc->sc_rx_statuslen);
1009 device_printf(sc->sc_dev, "RX buffer size: %d\n",
1010 sc->sc_edma_bufsize);
1013 sc->sc_rx.recv_stop = ath_edma_stoprecv;
1014 sc->sc_rx.recv_start = ath_edma_startrecv;
1015 sc->sc_rx.recv_flush = ath_edma_recv_flush;
1016 sc->sc_rx.recv_tasklet = ath_edma_recv_tasklet;
1017 sc->sc_rx.recv_rxbuf_init = ath_edma_rxbuf_init;
1019 sc->sc_rx.recv_setup = ath_edma_dma_rxsetup;
1020 sc->sc_rx.recv_teardown = ath_edma_dma_rxteardown;
1022 sc->sc_rx.recv_sched = ath_edma_recv_sched;
1023 sc->sc_rx.recv_sched_queue = ath_edma_recv_sched_queue;