xref: /freebsd/sys/dev/ath/if_ath_tx_edma.c (revision bd3b336251cce7ec386049af36803cc7b13a290c)
13fdfc330SAdrian Chadd /*-
23fdfc330SAdrian Chadd  * Copyright (c) 2012 Adrian Chadd <adrian@FreeBSD.org>
33fdfc330SAdrian Chadd  * All rights reserved.
43fdfc330SAdrian Chadd  *
53fdfc330SAdrian Chadd  * Redistribution and use in source and binary forms, with or without
63fdfc330SAdrian Chadd  * modification, are permitted provided that the following conditions
73fdfc330SAdrian Chadd  * are met:
83fdfc330SAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
93fdfc330SAdrian Chadd  *    notice, this list of conditions and the following disclaimer,
103fdfc330SAdrian Chadd  *    without modification.
113fdfc330SAdrian Chadd  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
123fdfc330SAdrian Chadd  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
133fdfc330SAdrian Chadd  *    redistribution must be conditioned upon including a substantially
143fdfc330SAdrian Chadd  *    similar Disclaimer requirement for further binary redistribution.
153fdfc330SAdrian Chadd  *
163fdfc330SAdrian Chadd  * NO WARRANTY
173fdfc330SAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
183fdfc330SAdrian Chadd  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
193fdfc330SAdrian Chadd  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
203fdfc330SAdrian Chadd  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
213fdfc330SAdrian Chadd  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
223fdfc330SAdrian Chadd  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
233fdfc330SAdrian Chadd  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
243fdfc330SAdrian Chadd  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
253fdfc330SAdrian Chadd  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
263fdfc330SAdrian Chadd  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
273fdfc330SAdrian Chadd  * THE POSSIBILITY OF SUCH DAMAGES.
283fdfc330SAdrian Chadd  */
293fdfc330SAdrian Chadd 
303fdfc330SAdrian Chadd #include <sys/cdefs.h>
313fdfc330SAdrian Chadd __FBSDID("$FreeBSD$");
323fdfc330SAdrian Chadd 
333fdfc330SAdrian Chadd /*
343fdfc330SAdrian Chadd  * Driver for the Atheros Wireless LAN controller.
353fdfc330SAdrian Chadd  *
363fdfc330SAdrian Chadd  * This software is derived from work of Atsushi Onoe; his contribution
373fdfc330SAdrian Chadd  * is greatly appreciated.
383fdfc330SAdrian Chadd  */
393fdfc330SAdrian Chadd 
403fdfc330SAdrian Chadd #include "opt_inet.h"
413fdfc330SAdrian Chadd #include "opt_ath.h"
423fdfc330SAdrian Chadd /*
433fdfc330SAdrian Chadd  * This is needed for register operations which are performed
443fdfc330SAdrian Chadd  * by the driver - eg, calls to ath_hal_gettsf32().
453fdfc330SAdrian Chadd  *
463fdfc330SAdrian Chadd  * It's also required for any AH_DEBUG checks in here, eg the
473fdfc330SAdrian Chadd  * module dependencies.
483fdfc330SAdrian Chadd  */
493fdfc330SAdrian Chadd #include "opt_ah.h"
503fdfc330SAdrian Chadd #include "opt_wlan.h"
513fdfc330SAdrian Chadd 
523fdfc330SAdrian Chadd #include <sys/param.h>
533fdfc330SAdrian Chadd #include <sys/systm.h>
543fdfc330SAdrian Chadd #include <sys/sysctl.h>
553fdfc330SAdrian Chadd #include <sys/mbuf.h>
563fdfc330SAdrian Chadd #include <sys/malloc.h>
573fdfc330SAdrian Chadd #include <sys/lock.h>
583fdfc330SAdrian Chadd #include <sys/mutex.h>
593fdfc330SAdrian Chadd #include <sys/kernel.h>
603fdfc330SAdrian Chadd #include <sys/socket.h>
613fdfc330SAdrian Chadd #include <sys/sockio.h>
623fdfc330SAdrian Chadd #include <sys/errno.h>
633fdfc330SAdrian Chadd #include <sys/callout.h>
643fdfc330SAdrian Chadd #include <sys/bus.h>
653fdfc330SAdrian Chadd #include <sys/endian.h>
663fdfc330SAdrian Chadd #include <sys/kthread.h>
673fdfc330SAdrian Chadd #include <sys/taskqueue.h>
683fdfc330SAdrian Chadd #include <sys/priv.h>
693fdfc330SAdrian Chadd #include <sys/module.h>
703fdfc330SAdrian Chadd #include <sys/ktr.h>
713fdfc330SAdrian Chadd #include <sys/smp.h>	/* for mp_ncpus */
723fdfc330SAdrian Chadd 
733fdfc330SAdrian Chadd #include <machine/bus.h>
743fdfc330SAdrian Chadd 
753fdfc330SAdrian Chadd #include <net/if.h>
7676039bc8SGleb Smirnoff #include <net/if_var.h>
773fdfc330SAdrian Chadd #include <net/if_dl.h>
783fdfc330SAdrian Chadd #include <net/if_media.h>
793fdfc330SAdrian Chadd #include <net/if_types.h>
803fdfc330SAdrian Chadd #include <net/if_arp.h>
813fdfc330SAdrian Chadd #include <net/ethernet.h>
823fdfc330SAdrian Chadd #include <net/if_llc.h>
833fdfc330SAdrian Chadd 
843fdfc330SAdrian Chadd #include <net80211/ieee80211_var.h>
853fdfc330SAdrian Chadd #include <net80211/ieee80211_regdomain.h>
863fdfc330SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG
873fdfc330SAdrian Chadd #include <net80211/ieee80211_superg.h>
883fdfc330SAdrian Chadd #endif
893fdfc330SAdrian Chadd #ifdef IEEE80211_SUPPORT_TDMA
903fdfc330SAdrian Chadd #include <net80211/ieee80211_tdma.h>
913fdfc330SAdrian Chadd #endif
923fdfc330SAdrian Chadd 
933fdfc330SAdrian Chadd #include <net/bpf.h>
943fdfc330SAdrian Chadd 
953fdfc330SAdrian Chadd #ifdef INET
963fdfc330SAdrian Chadd #include <netinet/in.h>
973fdfc330SAdrian Chadd #include <netinet/if_ether.h>
983fdfc330SAdrian Chadd #endif
993fdfc330SAdrian Chadd 
1003fdfc330SAdrian Chadd #include <dev/ath/if_athvar.h>
1013fdfc330SAdrian Chadd #include <dev/ath/ath_hal/ah_devid.h>		/* XXX for softled */
1023fdfc330SAdrian Chadd #include <dev/ath/ath_hal/ah_diagcodes.h>
1033fdfc330SAdrian Chadd 
1043fdfc330SAdrian Chadd #include <dev/ath/if_ath_debug.h>
1053fdfc330SAdrian Chadd #include <dev/ath/if_ath_misc.h>
1063fdfc330SAdrian Chadd #include <dev/ath/if_ath_tsf.h>
1073fdfc330SAdrian Chadd #include <dev/ath/if_ath_tx.h>
1083fdfc330SAdrian Chadd #include <dev/ath/if_ath_sysctl.h>
1093fdfc330SAdrian Chadd #include <dev/ath/if_ath_led.h>
1103fdfc330SAdrian Chadd #include <dev/ath/if_ath_keycache.h>
1113fdfc330SAdrian Chadd #include <dev/ath/if_ath_rx.h>
1123fdfc330SAdrian Chadd #include <dev/ath/if_ath_beacon.h>
1133fdfc330SAdrian Chadd #include <dev/ath/if_athdfs.h>
114b45de1ebSAdrian Chadd #include <dev/ath/if_ath_descdma.h>
1153fdfc330SAdrian Chadd 
1163fdfc330SAdrian Chadd #ifdef ATH_TX99_DIAG
1173fdfc330SAdrian Chadd #include <dev/ath/ath_tx99/ath_tx99.h>
1183fdfc330SAdrian Chadd #endif
1193fdfc330SAdrian Chadd 
1203fdfc330SAdrian Chadd #include <dev/ath/if_ath_tx_edma.h>
1213fdfc330SAdrian Chadd 
122b69b0dccSAdrian Chadd #ifdef	ATH_DEBUG_ALQ
123b69b0dccSAdrian Chadd #include <dev/ath/if_ath_alq.h>
124b69b0dccSAdrian Chadd #endif
125b69b0dccSAdrian Chadd 
1263fdfc330SAdrian Chadd /*
1273fdfc330SAdrian Chadd  * some general macros
1283fdfc330SAdrian Chadd  */
1293fdfc330SAdrian Chadd #define	INCR(_l, _sz)		(_l) ++; (_l) &= ((_sz) - 1)
1303fdfc330SAdrian Chadd #define	DECR(_l, _sz)		(_l) --; (_l) &= ((_sz) - 1)
1313fdfc330SAdrian Chadd 
132ba3fd9d8SAdrian Chadd /*
133ba3fd9d8SAdrian Chadd  * XXX doesn't belong here, and should be tunable
134ba3fd9d8SAdrian Chadd  */
135ba3fd9d8SAdrian Chadd #define	ATH_TXSTATUS_RING_SIZE	512
136ba3fd9d8SAdrian Chadd 
1373fdfc330SAdrian Chadd MALLOC_DECLARE(M_ATHDEV);
1383fdfc330SAdrian Chadd 
139ae3815fdSAdrian Chadd static void ath_edma_tx_processq(struct ath_softc *sc, int dosched);
140ae3815fdSAdrian Chadd 
14149236b4eSAdrian Chadd #ifdef	ATH_DEBUG_ALQ
14249236b4eSAdrian Chadd static void
14349236b4eSAdrian Chadd ath_tx_alq_edma_push(struct ath_softc *sc, int txq, int nframes,
14449236b4eSAdrian Chadd     int fifo_depth, int frame_cnt)
14549236b4eSAdrian Chadd {
14649236b4eSAdrian Chadd 	struct if_ath_alq_tx_fifo_push aq;
14749236b4eSAdrian Chadd 
14849236b4eSAdrian Chadd 	aq.txq = htobe32(txq);
14949236b4eSAdrian Chadd 	aq.nframes = htobe32(nframes);
15049236b4eSAdrian Chadd 	aq.fifo_depth = htobe32(fifo_depth);
15149236b4eSAdrian Chadd 	aq.frame_cnt = htobe32(frame_cnt);
15249236b4eSAdrian Chadd 
15349236b4eSAdrian Chadd 	if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TX_FIFO_PUSH,
15449236b4eSAdrian Chadd 	    sizeof(aq),
15549236b4eSAdrian Chadd 	    (const char *) &aq);
15649236b4eSAdrian Chadd }
15749236b4eSAdrian Chadd #endif	/* ATH_DEBUG_ALQ */
15849236b4eSAdrian Chadd 
1594f5ec72aSAdrian Chadd /*
1604f5ec72aSAdrian Chadd  * XXX TODO: push an aggregate as a single FIFO slot, even though
1614f5ec72aSAdrian Chadd  * it may not meet the TXOP for say, DBA-gated traffic in TDMA mode.
1624f5ec72aSAdrian Chadd  *
1634f5ec72aSAdrian Chadd  * The TX completion code handles a TX FIFO slot having multiple frames,
1644f5ec72aSAdrian Chadd  * aggregate or otherwise, but it may just make things easier to deal
1654f5ec72aSAdrian Chadd  * with.
1664f5ec72aSAdrian Chadd  *
1674f5ec72aSAdrian Chadd  * XXX TODO: track the number of aggregate subframes and put that in the
1684f5ec72aSAdrian Chadd  * push alq message.
1694f5ec72aSAdrian Chadd  */
17049236b4eSAdrian Chadd static void
17149236b4eSAdrian Chadd ath_tx_edma_push_staging_list(struct ath_softc *sc, struct ath_txq *txq,
17249236b4eSAdrian Chadd     int limit)
17349236b4eSAdrian Chadd {
17449236b4eSAdrian Chadd 	struct ath_buf *bf, *bf_last;
17549236b4eSAdrian Chadd 	struct ath_buf *bfi, *bfp;
17649236b4eSAdrian Chadd 	int i, sqdepth;
17749236b4eSAdrian Chadd 	TAILQ_HEAD(axq_q_f_s, ath_buf)  sq;
17849236b4eSAdrian Chadd 
17949236b4eSAdrian Chadd 	ATH_TXQ_LOCK_ASSERT(txq);
18049236b4eSAdrian Chadd 
18149236b4eSAdrian Chadd 	/*
18249236b4eSAdrian Chadd 	 * Don't bother doing any work if it's full.
18349236b4eSAdrian Chadd 	 */
18449236b4eSAdrian Chadd 	if (txq->axq_fifo_depth >= HAL_TXFIFO_DEPTH)
18549236b4eSAdrian Chadd 		return;
18649236b4eSAdrian Chadd 
18749236b4eSAdrian Chadd 	if (TAILQ_EMPTY(&txq->axq_q))
18849236b4eSAdrian Chadd 		return;
18949236b4eSAdrian Chadd 
19049236b4eSAdrian Chadd 	TAILQ_INIT(&sq);
19149236b4eSAdrian Chadd 
19249236b4eSAdrian Chadd 	/*
19349236b4eSAdrian Chadd 	 * First pass - walk sq, queue up to 'limit' entries,
19449236b4eSAdrian Chadd 	 * subtract them from the staging queue.
19549236b4eSAdrian Chadd 	 */
19649236b4eSAdrian Chadd 	sqdepth = 0;
19749236b4eSAdrian Chadd 	for (i = 0; i < limit; i++) {
19849236b4eSAdrian Chadd 		/* Grab the head entry */
19949236b4eSAdrian Chadd 		bf = ATH_TXQ_FIRST(txq);
20049236b4eSAdrian Chadd 		if (bf == NULL)
20149236b4eSAdrian Chadd 			break;
20249236b4eSAdrian Chadd 		ATH_TXQ_REMOVE(txq, bf, bf_list);
20349236b4eSAdrian Chadd 
20449236b4eSAdrian Chadd 		/* Queue it into our staging list */
20549236b4eSAdrian Chadd 		TAILQ_INSERT_TAIL(&sq, bf, bf_list);
2061a9bf047SAdrian Chadd 
2071a9bf047SAdrian Chadd 		/* Ensure the flags are cleared */
2081a9bf047SAdrian Chadd 		bf->bf_flags &= ~(ATH_BUF_FIFOPTR | ATH_BUF_FIFOEND);
20949236b4eSAdrian Chadd 		sqdepth++;
21049236b4eSAdrian Chadd 	}
21149236b4eSAdrian Chadd 
21249236b4eSAdrian Chadd 	/*
21349236b4eSAdrian Chadd 	 * Ok, so now we have a staging list of up to 'limit'
21449236b4eSAdrian Chadd 	 * frames from the txq.  Now let's wrap that up
21549236b4eSAdrian Chadd 	 * into its own list and pass that to the hardware
21649236b4eSAdrian Chadd 	 * as one FIFO entry.
21749236b4eSAdrian Chadd 	 */
21849236b4eSAdrian Chadd 
21949236b4eSAdrian Chadd 	bf = TAILQ_FIRST(&sq);
22049236b4eSAdrian Chadd 	bf_last = TAILQ_LAST(&sq, axq_q_s);
22149236b4eSAdrian Chadd 
22249236b4eSAdrian Chadd 	/*
22349236b4eSAdrian Chadd 	 * Ok, so here's the gymnastics reqiured to make this
22449236b4eSAdrian Chadd 	 * all sensible.
22549236b4eSAdrian Chadd 	 */
22649236b4eSAdrian Chadd 
22749236b4eSAdrian Chadd 	/*
22849236b4eSAdrian Chadd 	 * Tag the first/last buffer appropriately.
22949236b4eSAdrian Chadd 	 */
23049236b4eSAdrian Chadd 	bf->bf_flags |= ATH_BUF_FIFOPTR;
23149236b4eSAdrian Chadd 	bf_last->bf_flags |= ATH_BUF_FIFOEND;
23249236b4eSAdrian Chadd 
23349236b4eSAdrian Chadd 	/*
23449236b4eSAdrian Chadd 	 * Walk the descriptor list and link them appropriately.
23549236b4eSAdrian Chadd 	 */
23649236b4eSAdrian Chadd 	bfp = NULL;
23749236b4eSAdrian Chadd 	TAILQ_FOREACH(bfi, &sq, bf_list) {
23849236b4eSAdrian Chadd 		if (bfp != NULL) {
23949236b4eSAdrian Chadd 			ath_hal_settxdesclink(sc->sc_ah, bfp->bf_lastds,
24049236b4eSAdrian Chadd 			    bfi->bf_daddr);
24149236b4eSAdrian Chadd 		}
24249236b4eSAdrian Chadd 		bfp = bfi;
24349236b4eSAdrian Chadd 	}
24449236b4eSAdrian Chadd 
24549236b4eSAdrian Chadd 	i = 0;
24649236b4eSAdrian Chadd 	TAILQ_FOREACH(bfi, &sq, bf_list) {
24749236b4eSAdrian Chadd #ifdef	ATH_DEBUG
24849236b4eSAdrian Chadd 		if (sc->sc_debug & ATH_DEBUG_XMIT_DESC)
24949236b4eSAdrian Chadd 			ath_printtxbuf(sc, bfi, txq->axq_qnum, i, 0);
25049236b4eSAdrian Chadd #endif/* ATH_DEBUG */
25149236b4eSAdrian Chadd #ifdef	ATH_DEBUG_ALQ
25249236b4eSAdrian Chadd 		if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
25349236b4eSAdrian Chadd 			ath_tx_alq_post(sc, bfi);
25449236b4eSAdrian Chadd #endif /* ATH_DEBUG_ALQ */
25549236b4eSAdrian Chadd 		i++;
25649236b4eSAdrian Chadd 	}
25749236b4eSAdrian Chadd 
25849236b4eSAdrian Chadd 	/*
25949236b4eSAdrian Chadd 	 * We now need to push this set of frames onto the tail
26049236b4eSAdrian Chadd 	 * of the FIFO queue.  We don't adjust the aggregate
26149236b4eSAdrian Chadd 	 * count, only the queue depth counter(s).
26249236b4eSAdrian Chadd 	 * We also need to blank the link pointer now.
26349236b4eSAdrian Chadd 	 */
26449236b4eSAdrian Chadd 
26549236b4eSAdrian Chadd 	TAILQ_CONCAT(&txq->fifo.axq_q, &sq, bf_list);
26649236b4eSAdrian Chadd 	/* Bump total queue tracking in FIFO queue */
26749236b4eSAdrian Chadd 	txq->fifo.axq_depth += sqdepth;
26849236b4eSAdrian Chadd 
26949236b4eSAdrian Chadd 	/* Bump FIFO queue */
27049236b4eSAdrian Chadd 	txq->axq_fifo_depth++;
271*bd3b3362SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_XMIT | ATH_DEBUG_TX_PROC,
27249236b4eSAdrian Chadd 	    "%s: queued %d packets; depth=%d, fifo depth=%d\n",
27349236b4eSAdrian Chadd 	    __func__, sqdepth, txq->fifo.axq_depth, txq->axq_fifo_depth);
27449236b4eSAdrian Chadd 
27549236b4eSAdrian Chadd 	/* Push the first entry into the hardware */
27649236b4eSAdrian Chadd 	ath_hal_puttxbuf(sc->sc_ah, txq->axq_qnum, bf->bf_daddr);
27749236b4eSAdrian Chadd 
27849236b4eSAdrian Chadd 	/* Push start on the DMA if it's not already started */
27949236b4eSAdrian Chadd 	ath_hal_txstart(sc->sc_ah, txq->axq_qnum);
28049236b4eSAdrian Chadd 
28149236b4eSAdrian Chadd #ifdef	ATH_DEBUG_ALQ
28249236b4eSAdrian Chadd 	ath_tx_alq_edma_push(sc, txq->axq_qnum, sqdepth,
28349236b4eSAdrian Chadd 	    txq->axq_fifo_depth,
28449236b4eSAdrian Chadd 	    txq->fifo.axq_depth);
28549236b4eSAdrian Chadd #endif /* ATH_DEBUG_ALQ */
28649236b4eSAdrian Chadd }
28749236b4eSAdrian Chadd 
2884f5ec72aSAdrian Chadd #define	TX_BATCH_SIZE	32
2894f5ec72aSAdrian Chadd 
29092e84e43SAdrian Chadd /*
29192e84e43SAdrian Chadd  * Push some frames into the TX FIFO if we have space.
29292e84e43SAdrian Chadd  */
2934aa8818bSAdrian Chadd static void
2944aa8818bSAdrian Chadd ath_edma_tx_fifo_fill(struct ath_softc *sc, struct ath_txq *txq)
2954aa8818bSAdrian Chadd {
2964aa8818bSAdrian Chadd 
297b837332dSAdrian Chadd 	ATH_TXQ_LOCK_ASSERT(txq);
2984aa8818bSAdrian Chadd 
299*bd3b3362SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_TX_PROC,
300*bd3b3362SAdrian Chadd 	    "%s: Q%d: called; fifo.depth=%d, fifo depth=%d, depth=%d, aggr_depth=%d\n",
30192e84e43SAdrian Chadd 	    __func__,
302*bd3b3362SAdrian Chadd 	    txq->axq_qnum,
303*bd3b3362SAdrian Chadd 	    txq->fifo.axq_depth,
304*bd3b3362SAdrian Chadd 	    txq->axq_fifo_depth,
305*bd3b3362SAdrian Chadd 	    txq->axq_depth,
306*bd3b3362SAdrian Chadd 	    txq->axq_aggr_depth);
3074aa8818bSAdrian Chadd 
30892e84e43SAdrian Chadd 	/*
309*bd3b3362SAdrian Chadd 	 * For now, push up to 32 frames per TX FIFO slot.
31049236b4eSAdrian Chadd 	 * If more are in the hardware queue then they'll
31149236b4eSAdrian Chadd 	 * get populated when we try to send another frame
31249236b4eSAdrian Chadd 	 * or complete a frame - so at most there'll be
313*bd3b3362SAdrian Chadd 	 * 32 non-AMPDU frames per node/TID anyway.
31492e84e43SAdrian Chadd 	 *
31549236b4eSAdrian Chadd 	 * Note that the hardware staging queue will limit
31649236b4eSAdrian Chadd 	 * how many frames in total we will have pushed into
31749236b4eSAdrian Chadd 	 * here.
31849236b4eSAdrian Chadd 	 *
31949236b4eSAdrian Chadd 	 * Later on, we'll want to push less frames into
32049236b4eSAdrian Chadd 	 * the TX FIFO since we don't want to necessarily
32149236b4eSAdrian Chadd 	 * fill tens or hundreds of milliseconds of potential
32249236b4eSAdrian Chadd 	 * frames.
32349236b4eSAdrian Chadd 	 *
32449236b4eSAdrian Chadd 	 * However, we need more frames right now because of
32549236b4eSAdrian Chadd 	 * how the MAC implements the frame scheduling policy.
32649236b4eSAdrian Chadd 	 * It only ungates a single FIFO entry at a time,
32749236b4eSAdrian Chadd 	 * and will run that until CHNTIME expires or the
32849236b4eSAdrian Chadd 	 * end of that FIFO entry descriptor list is reached.
32949236b4eSAdrian Chadd 	 * So for TDMA we suffer a big performance penalty -
33049236b4eSAdrian Chadd 	 * single TX FIFO entries mean the MAC only sends out
33149236b4eSAdrian Chadd 	 * one frame per DBA event, which turned out on average
33249236b4eSAdrian Chadd 	 * 6ms per TX frame.
33349236b4eSAdrian Chadd 	 *
33449236b4eSAdrian Chadd 	 * So, for aggregates it's okay - it'll push two at a
33549236b4eSAdrian Chadd 	 * time and this will just do them more efficiently.
33649236b4eSAdrian Chadd 	 * For non-aggregates it'll do 4 at a time, up to the
33749236b4eSAdrian Chadd 	 * non-aggr limit (non_aggr, which is 32.)  They should
33849236b4eSAdrian Chadd 	 * be time based rather than a hard count, but I also
33949236b4eSAdrian Chadd 	 * do need sleep.
34092e84e43SAdrian Chadd 	 */
3414f5ec72aSAdrian Chadd 
3424f5ec72aSAdrian Chadd 	/*
3434f5ec72aSAdrian Chadd 	 * Do some basic, basic batching to the hardware
3444f5ec72aSAdrian Chadd 	 * queue.
3454f5ec72aSAdrian Chadd 	 *
3464f5ec72aSAdrian Chadd 	 * If we have TX_BATCH_SIZE entries in the staging
3474f5ec72aSAdrian Chadd 	 * queue, then let's try to send them all in one hit.
3484f5ec72aSAdrian Chadd 	 *
3494f5ec72aSAdrian Chadd 	 * Ensure we don't push more than TX_BATCH_SIZE worth
3504f5ec72aSAdrian Chadd 	 * in, otherwise we end up draining 8 slots worth of
3514f5ec72aSAdrian Chadd 	 * 32 frames into the hardware queue and then we don't
3524f5ec72aSAdrian Chadd 	 * attempt to push more frames in until we empty the
3534f5ec72aSAdrian Chadd 	 * FIFO.
3544f5ec72aSAdrian Chadd 	 */
3554f5ec72aSAdrian Chadd 	if (txq->axq_depth >= TX_BATCH_SIZE / 2 &&
3564f5ec72aSAdrian Chadd 	    txq->fifo.axq_depth <= TX_BATCH_SIZE) {
3574f5ec72aSAdrian Chadd 		ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
3584f5ec72aSAdrian Chadd 	}
3594f5ec72aSAdrian Chadd 
3604f5ec72aSAdrian Chadd 	/*
3614f5ec72aSAdrian Chadd 	 * Aggregate check: if we have less than two FIFO slots
3624f5ec72aSAdrian Chadd 	 * busy and we have some aggregate frames, queue it.
3634f5ec72aSAdrian Chadd 	 *
3644f5ec72aSAdrian Chadd 	 * Now, ideally we'd just check to see if the scheduler
3654f5ec72aSAdrian Chadd 	 * has given us aggregate frames and push them into the FIFO
3664f5ec72aSAdrian Chadd 	 * as individual slots, as honestly we should just be pushing
3674f5ec72aSAdrian Chadd 	 * a single aggregate in as one FIFO slot.
3684f5ec72aSAdrian Chadd 	 *
3694f5ec72aSAdrian Chadd 	 * Let's do that next once I know this works.
3704f5ec72aSAdrian Chadd 	 */
3714f5ec72aSAdrian Chadd 	else if (txq->axq_aggr_depth > 0 && txq->axq_fifo_depth < 2)
3724f5ec72aSAdrian Chadd 		ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
3734f5ec72aSAdrian Chadd 
3744f5ec72aSAdrian Chadd 	/*
3754f5ec72aSAdrian Chadd 	 *
3764f5ec72aSAdrian Chadd 	 * If we have less, and the TXFIFO isn't empty, let's
3774f5ec72aSAdrian Chadd 	 * wait until we've finished sending the FIFO.
3784f5ec72aSAdrian Chadd 	 *
3794f5ec72aSAdrian Chadd 	 * If we have less, and the TXFIFO is empty, then
3804f5ec72aSAdrian Chadd 	 * send them.
3814f5ec72aSAdrian Chadd 	 */
3824f5ec72aSAdrian Chadd 	else if (txq->axq_fifo_depth == 0) {
3834f5ec72aSAdrian Chadd 		ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
3844f5ec72aSAdrian Chadd 	}
3854aa8818bSAdrian Chadd }
3864aa8818bSAdrian Chadd 
387746bab5bSAdrian Chadd /*
388746bab5bSAdrian Chadd  * Re-initialise the DMA FIFO with the current contents of
3893ae723d4SAdrian Chadd  * said TXQ.
390746bab5bSAdrian Chadd  *
391746bab5bSAdrian Chadd  * This should only be called as part of the chip reset path, as it
392746bab5bSAdrian Chadd  * assumes the FIFO is currently empty.
393746bab5bSAdrian Chadd  */
394746bab5bSAdrian Chadd static void
395746bab5bSAdrian Chadd ath_edma_dma_restart(struct ath_softc *sc, struct ath_txq *txq)
396746bab5bSAdrian Chadd {
39792e84e43SAdrian Chadd 	struct ath_buf *bf;
39892e84e43SAdrian Chadd 	int i = 0;
39992e84e43SAdrian Chadd 	int fifostart = 1;
40092e84e43SAdrian Chadd 	int old_fifo_depth;
401746bab5bSAdrian Chadd 
40292e84e43SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_RESET, "%s: Q%d: called\n",
403746bab5bSAdrian Chadd 	    __func__,
404746bab5bSAdrian Chadd 	    txq->axq_qnum);
4054aa8818bSAdrian Chadd 
406b837332dSAdrian Chadd 	ATH_TXQ_LOCK_ASSERT(txq);
40792e84e43SAdrian Chadd 
40892e84e43SAdrian Chadd 	/*
40992e84e43SAdrian Chadd 	 * Let's log if the tracked FIFO depth doesn't match
41092e84e43SAdrian Chadd 	 * what we actually push in.
41192e84e43SAdrian Chadd 	 */
41292e84e43SAdrian Chadd 	old_fifo_depth = txq->axq_fifo_depth;
41392e84e43SAdrian Chadd 	txq->axq_fifo_depth = 0;
41492e84e43SAdrian Chadd 
41592e84e43SAdrian Chadd 	/*
41692e84e43SAdrian Chadd 	 * Walk the FIFO staging list, looking for "head" entries.
41792e84e43SAdrian Chadd 	 * Since we may have a partially completed list of frames,
41892e84e43SAdrian Chadd 	 * we push the first frame we see into the FIFO and re-mark
41992e84e43SAdrian Chadd 	 * it as the head entry.  We then skip entries until we see
42092e84e43SAdrian Chadd 	 * FIFO end, at which point we get ready to push another
42192e84e43SAdrian Chadd 	 * entry into the FIFO.
42292e84e43SAdrian Chadd 	 */
42392e84e43SAdrian Chadd 	TAILQ_FOREACH(bf, &txq->fifo.axq_q, bf_list) {
42492e84e43SAdrian Chadd 		/*
42592e84e43SAdrian Chadd 		 * If we're looking for FIFOEND and we haven't found
42692e84e43SAdrian Chadd 		 * it, skip.
42792e84e43SAdrian Chadd 		 *
42892e84e43SAdrian Chadd 		 * If we're looking for FIFOEND and we've found it,
42992e84e43SAdrian Chadd 		 * reset for another descriptor.
43092e84e43SAdrian Chadd 		 */
43192e84e43SAdrian Chadd #ifdef	ATH_DEBUG
43292e84e43SAdrian Chadd 		if (sc->sc_debug & ATH_DEBUG_XMIT_DESC)
43392e84e43SAdrian Chadd 			ath_printtxbuf(sc, bf, txq->axq_qnum, i, 0);
43492e84e43SAdrian Chadd #endif/* ATH_DEBUG */
43592e84e43SAdrian Chadd #ifdef	ATH_DEBUG_ALQ
43692e84e43SAdrian Chadd 		if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
43792e84e43SAdrian Chadd 			ath_tx_alq_post(sc, bf);
43892e84e43SAdrian Chadd #endif /* ATH_DEBUG_ALQ */
43992e84e43SAdrian Chadd 
44092e84e43SAdrian Chadd 		if (fifostart == 0) {
44192e84e43SAdrian Chadd 			if (bf->bf_flags & ATH_BUF_FIFOEND)
44292e84e43SAdrian Chadd 				fifostart = 1;
44392e84e43SAdrian Chadd 			continue;
44492e84e43SAdrian Chadd 		}
44592e84e43SAdrian Chadd 
44692e84e43SAdrian Chadd 		/* Make sure we're not overflowing the FIFO! */
44792e84e43SAdrian Chadd 		if (txq->axq_fifo_depth >= HAL_TXFIFO_DEPTH) {
44892e84e43SAdrian Chadd 			device_printf(sc->sc_dev,
44992e84e43SAdrian Chadd 			    "%s: Q%d: more frames in the queue; FIFO depth=%d?!\n",
45092e84e43SAdrian Chadd 			    __func__,
45192e84e43SAdrian Chadd 			    txq->axq_qnum,
45292e84e43SAdrian Chadd 			    txq->axq_fifo_depth);
45392e84e43SAdrian Chadd 		}
45492e84e43SAdrian Chadd 
45592e84e43SAdrian Chadd #if 0
45692e84e43SAdrian Chadd 		DPRINTF(sc, ATH_DEBUG_RESET,
45792e84e43SAdrian Chadd 		    "%s: Q%d: depth=%d: pushing bf=%p; start=%d, end=%d\n",
45892e84e43SAdrian Chadd 		    __func__,
45992e84e43SAdrian Chadd 		    txq->axq_qnum,
46092e84e43SAdrian Chadd 		    txq->axq_fifo_depth,
46192e84e43SAdrian Chadd 		    bf,
46292e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOPTR),
46392e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOEND));
46492e84e43SAdrian Chadd #endif
46592e84e43SAdrian Chadd 
46692e84e43SAdrian Chadd 		/*
46792e84e43SAdrian Chadd 		 * Set this to be the first buffer in the FIFO
46892e84e43SAdrian Chadd 		 * list - even if it's also the last buffer in
46992e84e43SAdrian Chadd 		 * a FIFO list!
47092e84e43SAdrian Chadd 		 */
47192e84e43SAdrian Chadd 		bf->bf_flags |= ATH_BUF_FIFOPTR;
47292e84e43SAdrian Chadd 
47392e84e43SAdrian Chadd 		/* Push it into the FIFO and bump the FIFO count */
47492e84e43SAdrian Chadd 		ath_hal_puttxbuf(sc->sc_ah, txq->axq_qnum, bf->bf_daddr);
47592e84e43SAdrian Chadd 		txq->axq_fifo_depth++;
47692e84e43SAdrian Chadd 
47792e84e43SAdrian Chadd 		/*
47892e84e43SAdrian Chadd 		 * If this isn't the last entry either, let's
47992e84e43SAdrian Chadd 		 * clear fifostart so we continue looking for
48092e84e43SAdrian Chadd 		 * said last entry.
48192e84e43SAdrian Chadd 		 */
48292e84e43SAdrian Chadd 		if (! (bf->bf_flags & ATH_BUF_FIFOEND))
48392e84e43SAdrian Chadd 			fifostart = 0;
48492e84e43SAdrian Chadd 		i++;
48592e84e43SAdrian Chadd 	}
48692e84e43SAdrian Chadd 
48792e84e43SAdrian Chadd 	/* Only bother starting the queue if there's something in it */
48892e84e43SAdrian Chadd 	if (i > 0)
48992e84e43SAdrian Chadd 		ath_hal_txstart(sc->sc_ah, txq->axq_qnum);
49092e84e43SAdrian Chadd 
49192e84e43SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_RESET, "%s: Q%d: FIFO depth was %d, is %d\n",
49292e84e43SAdrian Chadd 	    __func__,
49392e84e43SAdrian Chadd 	    txq->axq_qnum,
49492e84e43SAdrian Chadd 	    old_fifo_depth,
49592e84e43SAdrian Chadd 	    txq->axq_fifo_depth);
49692e84e43SAdrian Chadd 
49792e84e43SAdrian Chadd 	/* And now, let's check! */
49892e84e43SAdrian Chadd 	if (txq->axq_fifo_depth != old_fifo_depth) {
49992e84e43SAdrian Chadd 		device_printf(sc->sc_dev,
50092e84e43SAdrian Chadd 		    "%s: Q%d: FIFO depth should be %d, is %d\n",
50192e84e43SAdrian Chadd 		    __func__,
50292e84e43SAdrian Chadd 		    txq->axq_qnum,
50392e84e43SAdrian Chadd 		    old_fifo_depth,
50492e84e43SAdrian Chadd 		    txq->axq_fifo_depth);
50592e84e43SAdrian Chadd 	}
506746bab5bSAdrian Chadd }
507746bab5bSAdrian Chadd 
508746bab5bSAdrian Chadd /*
5093ae723d4SAdrian Chadd  * Hand off this frame to a hardware queue.
5103ae723d4SAdrian Chadd  *
5113ae723d4SAdrian Chadd  * Things are a bit hairy in the EDMA world.  The TX FIFO is only
5123ae723d4SAdrian Chadd  * 8 entries deep, so we need to keep track of exactly what we've
5133ae723d4SAdrian Chadd  * pushed into the FIFO and what's just sitting in the TX queue,
5143ae723d4SAdrian Chadd  * waiting to go out.
5153ae723d4SAdrian Chadd  *
5163ae723d4SAdrian Chadd  * So this is split into two halves - frames get appended to the
5173ae723d4SAdrian Chadd  * TXQ; then a scheduler is called to push some frames into the
5183ae723d4SAdrian Chadd  * actual TX FIFO.
5193ae723d4SAdrian Chadd  */
5203ae723d4SAdrian Chadd static void
5213ae723d4SAdrian Chadd ath_edma_xmit_handoff_hw(struct ath_softc *sc, struct ath_txq *txq,
5223ae723d4SAdrian Chadd     struct ath_buf *bf)
5233ae723d4SAdrian Chadd {
5243ae723d4SAdrian Chadd 
5250acf45edSAdrian Chadd 	ATH_TXQ_LOCK(txq);
5263ae723d4SAdrian Chadd 
5273ae723d4SAdrian Chadd 	KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
5283ae723d4SAdrian Chadd 	    ("%s: busy status 0x%x", __func__, bf->bf_flags));
5293ae723d4SAdrian Chadd 
5303ae723d4SAdrian Chadd 	/*
5313ae723d4SAdrian Chadd 	 * XXX TODO: write a hard-coded check to ensure that
5323ae723d4SAdrian Chadd 	 * the queue id in the TX descriptor matches txq->axq_qnum.
5333ae723d4SAdrian Chadd 	 */
5343ae723d4SAdrian Chadd 
5353ae723d4SAdrian Chadd 	/* Update aggr stats */
5363ae723d4SAdrian Chadd 	if (bf->bf_state.bfs_aggr)
5373ae723d4SAdrian Chadd 		txq->axq_aggr_depth++;
5383ae723d4SAdrian Chadd 
5393ae723d4SAdrian Chadd 	/* Push and update frame stats */
5403ae723d4SAdrian Chadd 	ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
5413ae723d4SAdrian Chadd 
54292e84e43SAdrian Chadd 	/*
54392e84e43SAdrian Chadd 	 * Finally, call the FIFO schedule routine to schedule some
54492e84e43SAdrian Chadd 	 * frames to the FIFO.
54592e84e43SAdrian Chadd 	 */
54692e84e43SAdrian Chadd 	ath_edma_tx_fifo_fill(sc, txq);
5470acf45edSAdrian Chadd 	ATH_TXQ_UNLOCK(txq);
5483ae723d4SAdrian Chadd }
5493ae723d4SAdrian Chadd 
5503ae723d4SAdrian Chadd /*
5513ae723d4SAdrian Chadd  * Hand off this frame to a multicast software queue.
5523ae723d4SAdrian Chadd  *
553e3f06688SAdrian Chadd  * The EDMA TX CABQ will get a list of chained frames, chained
554e3f06688SAdrian Chadd  * together using the next pointer.  The single head of that
555e3f06688SAdrian Chadd  * particular queue is pushed to the hardware CABQ.
5563ae723d4SAdrian Chadd  */
5573ae723d4SAdrian Chadd static void
5583ae723d4SAdrian Chadd ath_edma_xmit_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq,
5593ae723d4SAdrian Chadd     struct ath_buf *bf)
5603ae723d4SAdrian Chadd {
5613ae723d4SAdrian Chadd 
5629e7259a2SAdrian Chadd 	ATH_TX_LOCK_ASSERT(sc);
5633ae723d4SAdrian Chadd 	KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
5643ae723d4SAdrian Chadd 	    ("%s: busy status 0x%x", __func__, bf->bf_flags));
5653ae723d4SAdrian Chadd 
5660acf45edSAdrian Chadd 	ATH_TXQ_LOCK(txq);
5673ae723d4SAdrian Chadd 	/*
5683ae723d4SAdrian Chadd 	 * XXX this is mostly duplicated in ath_tx_handoff_mcast().
5693ae723d4SAdrian Chadd 	 */
5709e7259a2SAdrian Chadd 	if (ATH_TXQ_LAST(txq, axq_q_s) != NULL) {
5713ae723d4SAdrian Chadd 		struct ath_buf *bf_last = ATH_TXQ_LAST(txq, axq_q_s);
5723ae723d4SAdrian Chadd 		struct ieee80211_frame *wh;
5733ae723d4SAdrian Chadd 
5743ae723d4SAdrian Chadd 		/* mark previous frame */
5753ae723d4SAdrian Chadd 		wh = mtod(bf_last->bf_m, struct ieee80211_frame *);
5763ae723d4SAdrian Chadd 		wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
5773ae723d4SAdrian Chadd 
578caedab2cSAdrian Chadd 		/* re-sync buffer to memory */
5793ae723d4SAdrian Chadd 		bus_dmamap_sync(sc->sc_dmat, bf_last->bf_dmamap,
5803ae723d4SAdrian Chadd 		   BUS_DMASYNC_PREWRITE);
5819cda8c80SAdrian Chadd 
5829cda8c80SAdrian Chadd 		/* link descriptor */
5839e7259a2SAdrian Chadd 		ath_hal_settxdesclink(sc->sc_ah,
5849e7259a2SAdrian Chadd 		    bf_last->bf_lastds,
5859e7259a2SAdrian Chadd 		    bf->bf_daddr);
5863ae723d4SAdrian Chadd 	}
587e3f06688SAdrian Chadd #ifdef	ATH_DEBUG_ALQ
588e3f06688SAdrian Chadd 	if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
589e3f06688SAdrian Chadd 		ath_tx_alq_post(sc, bf);
590e3f06688SAdrian Chadd #endif	/* ATH_DEBUG_ALQ */
5913ae723d4SAdrian Chadd 	ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
5920acf45edSAdrian Chadd 	ATH_TXQ_UNLOCK(txq);
5933ae723d4SAdrian Chadd }
5943ae723d4SAdrian Chadd 
5953ae723d4SAdrian Chadd /*
596746bab5bSAdrian Chadd  * Handoff this frame to the hardware.
597746bab5bSAdrian Chadd  *
598746bab5bSAdrian Chadd  * For the multicast queue, this will treat it as a software queue
599746bab5bSAdrian Chadd  * and append it to the list, after updating the MORE_DATA flag
600746bab5bSAdrian Chadd  * in the previous frame.  The cabq processing code will ensure
601746bab5bSAdrian Chadd  * that the queue contents gets transferred over.
602746bab5bSAdrian Chadd  *
603746bab5bSAdrian Chadd  * For the hardware queues, this will queue a frame to the queue
604746bab5bSAdrian Chadd  * like before, then populate the FIFO from that.  Since the
605746bab5bSAdrian Chadd  * EDMA hardware has 8 FIFO slots per TXQ, this ensures that
606746bab5bSAdrian Chadd  * frames such as management frames don't get prematurely dropped.
607746bab5bSAdrian Chadd  *
608746bab5bSAdrian Chadd  * This does imply that a similar flush-hwq-to-fifoq method will
609746bab5bSAdrian Chadd  * need to be called from the processq function, before the
610746bab5bSAdrian Chadd  * per-node software scheduler is called.
611746bab5bSAdrian Chadd  */
612746bab5bSAdrian Chadd static void
613746bab5bSAdrian Chadd ath_edma_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq,
614746bab5bSAdrian Chadd     struct ath_buf *bf)
615746bab5bSAdrian Chadd {
616746bab5bSAdrian Chadd 
6174aa8818bSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_XMIT_DESC,
6184aa8818bSAdrian Chadd 	    "%s: called; bf=%p, txq=%p, qnum=%d\n",
619746bab5bSAdrian Chadd 	    __func__,
620746bab5bSAdrian Chadd 	    bf,
621746bab5bSAdrian Chadd 	    txq,
622746bab5bSAdrian Chadd 	    txq->axq_qnum);
623746bab5bSAdrian Chadd 
6243ae723d4SAdrian Chadd 	if (txq->axq_qnum == ATH_TXQ_SWQ)
6253ae723d4SAdrian Chadd 		ath_edma_xmit_handoff_mcast(sc, txq, bf);
6263ae723d4SAdrian Chadd 	else
6273ae723d4SAdrian Chadd 		ath_edma_xmit_handoff_hw(sc, txq, bf);
628746bab5bSAdrian Chadd }
629746bab5bSAdrian Chadd 
6303fdfc330SAdrian Chadd static int
63179607afeSAdrian Chadd ath_edma_setup_txfifo(struct ath_softc *sc, int qnum)
63279607afeSAdrian Chadd {
63379607afeSAdrian Chadd 	struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
63479607afeSAdrian Chadd 
63579607afeSAdrian Chadd 	te->m_fifo = malloc(sizeof(struct ath_buf *) * HAL_TXFIFO_DEPTH,
63679607afeSAdrian Chadd 	    M_ATHDEV,
63779607afeSAdrian Chadd 	    M_NOWAIT | M_ZERO);
63879607afeSAdrian Chadd 	if (te->m_fifo == NULL) {
63979607afeSAdrian Chadd 		device_printf(sc->sc_dev, "%s: malloc failed\n",
64079607afeSAdrian Chadd 		    __func__);
64179607afeSAdrian Chadd 		return (-ENOMEM);
64279607afeSAdrian Chadd 	}
64379607afeSAdrian Chadd 
64479607afeSAdrian Chadd 	/*
64579607afeSAdrian Chadd 	 * Set initial "empty" state.
64679607afeSAdrian Chadd 	 */
64779607afeSAdrian Chadd 	te->m_fifo_head = te->m_fifo_tail = te->m_fifo_depth = 0;
64879607afeSAdrian Chadd 
64979607afeSAdrian Chadd 	return (0);
65079607afeSAdrian Chadd }
65179607afeSAdrian Chadd 
65279607afeSAdrian Chadd static int
65379607afeSAdrian Chadd ath_edma_free_txfifo(struct ath_softc *sc, int qnum)
65479607afeSAdrian Chadd {
65579607afeSAdrian Chadd 	struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
65679607afeSAdrian Chadd 
65779607afeSAdrian Chadd 	/* XXX TODO: actually deref the ath_buf entries? */
65879607afeSAdrian Chadd 	free(te->m_fifo, M_ATHDEV);
65979607afeSAdrian Chadd 	return (0);
66079607afeSAdrian Chadd }
66179607afeSAdrian Chadd 
66279607afeSAdrian Chadd static int
6633fdfc330SAdrian Chadd ath_edma_dma_txsetup(struct ath_softc *sc)
6643fdfc330SAdrian Chadd {
665ba3fd9d8SAdrian Chadd 	int error;
66679607afeSAdrian Chadd 	int i;
6673fdfc330SAdrian Chadd 
668ba3fd9d8SAdrian Chadd 	error = ath_descdma_alloc_desc(sc, &sc->sc_txsdma,
669ba3fd9d8SAdrian Chadd 	    NULL, "txcomp", sc->sc_tx_statuslen, ATH_TXSTATUS_RING_SIZE);
670ba3fd9d8SAdrian Chadd 	if (error != 0)
671ba3fd9d8SAdrian Chadd 		return (error);
672ba3fd9d8SAdrian Chadd 
673ba3fd9d8SAdrian Chadd 	ath_hal_setuptxstatusring(sc->sc_ah,
674ba3fd9d8SAdrian Chadd 	    (void *) sc->sc_txsdma.dd_desc,
675ba3fd9d8SAdrian Chadd 	    sc->sc_txsdma.dd_desc_paddr,
676ba3fd9d8SAdrian Chadd 	    ATH_TXSTATUS_RING_SIZE);
677ba3fd9d8SAdrian Chadd 
67879607afeSAdrian Chadd 	for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
67979607afeSAdrian Chadd 		ath_edma_setup_txfifo(sc, i);
68079607afeSAdrian Chadd 	}
68179607afeSAdrian Chadd 
6823fdfc330SAdrian Chadd 	return (0);
6833fdfc330SAdrian Chadd }
6843fdfc330SAdrian Chadd 
6853fdfc330SAdrian Chadd static int
6863fdfc330SAdrian Chadd ath_edma_dma_txteardown(struct ath_softc *sc)
6873fdfc330SAdrian Chadd {
68879607afeSAdrian Chadd 	int i;
68979607afeSAdrian Chadd 
69079607afeSAdrian Chadd 	for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
69179607afeSAdrian Chadd 		ath_edma_free_txfifo(sc, i);
69279607afeSAdrian Chadd 	}
6933fdfc330SAdrian Chadd 
694ba3fd9d8SAdrian Chadd 	ath_descdma_cleanup(sc, &sc->sc_txsdma, NULL);
6953fdfc330SAdrian Chadd 	return (0);
6963fdfc330SAdrian Chadd }
6973fdfc330SAdrian Chadd 
6983ae723d4SAdrian Chadd /*
699788e6aa9SAdrian Chadd  * Drain all TXQs, potentially after completing the existing completed
700788e6aa9SAdrian Chadd  * frames.
7013ae723d4SAdrian Chadd  */
702788e6aa9SAdrian Chadd static void
703788e6aa9SAdrian Chadd ath_edma_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
704f8418db5SAdrian Chadd {
7054aa8818bSAdrian Chadd 	int i;
706f8418db5SAdrian Chadd 
707ae3815fdSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_RESET, "%s: called\n", __func__);
7084aa8818bSAdrian Chadd 
7094aa8818bSAdrian Chadd 	(void) ath_stoptxdma(sc);
7104aa8818bSAdrian Chadd 
7114aa8818bSAdrian Chadd 	/*
7124aa8818bSAdrian Chadd 	 * If reset type is noloss, the TX FIFO needs to be serviced
7134aa8818bSAdrian Chadd 	 * and those frames need to be handled.
7144aa8818bSAdrian Chadd 	 *
7154aa8818bSAdrian Chadd 	 * Otherwise, just toss everything in each TX queue.
7164aa8818bSAdrian Chadd 	 */
717ae3815fdSAdrian Chadd 	if (reset_type == ATH_RESET_NOLOSS) {
718ae3815fdSAdrian Chadd 		ath_edma_tx_processq(sc, 0);
7198328d6e4SAdrian Chadd 		for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
7208328d6e4SAdrian Chadd 			if (ATH_TXQ_SETUP(sc, i)) {
7218328d6e4SAdrian Chadd 				ATH_TXQ_LOCK(&sc->sc_txq[i]);
7228328d6e4SAdrian Chadd 				/*
7238328d6e4SAdrian Chadd 				 * Free the holding buffer; DMA is now
7248328d6e4SAdrian Chadd 				 * stopped.
7258328d6e4SAdrian Chadd 				 */
7268328d6e4SAdrian Chadd 				ath_txq_freeholdingbuf(sc, &sc->sc_txq[i]);
7278328d6e4SAdrian Chadd 				/*
7288328d6e4SAdrian Chadd 				 * Reset the link pointer to NULL; there's
7298328d6e4SAdrian Chadd 				 * no frames to chain DMA to.
7308328d6e4SAdrian Chadd 				 */
7318328d6e4SAdrian Chadd 				sc->sc_txq[i].axq_link = NULL;
7328328d6e4SAdrian Chadd 				ATH_TXQ_UNLOCK(&sc->sc_txq[i]);
7338328d6e4SAdrian Chadd 			}
7348328d6e4SAdrian Chadd 		}
735ae3815fdSAdrian Chadd 	} else {
7364aa8818bSAdrian Chadd 		for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
7374aa8818bSAdrian Chadd 			if (ATH_TXQ_SETUP(sc, i))
7384aa8818bSAdrian Chadd 				ath_tx_draintxq(sc, &sc->sc_txq[i]);
7394aa8818bSAdrian Chadd 		}
740ae3815fdSAdrian Chadd 	}
741ae3815fdSAdrian Chadd 
742ae3815fdSAdrian Chadd 	/* XXX dump out the TX completion FIFO contents */
743ae3815fdSAdrian Chadd 
744ae3815fdSAdrian Chadd 	/* XXX dump out the frames */
7454aa8818bSAdrian Chadd 
7464aa8818bSAdrian Chadd 	sc->sc_wd_timer = 0;
747f8418db5SAdrian Chadd }
748f8418db5SAdrian Chadd 
7493ae723d4SAdrian Chadd /*
750ae3815fdSAdrian Chadd  * TX completion tasklet.
7513ae723d4SAdrian Chadd  */
752ae3815fdSAdrian Chadd 
753f8418db5SAdrian Chadd static void
754f8418db5SAdrian Chadd ath_edma_tx_proc(void *arg, int npending)
755f8418db5SAdrian Chadd {
756f8418db5SAdrian Chadd 	struct ath_softc *sc = (struct ath_softc *) arg;
757ae3815fdSAdrian Chadd 
75892e84e43SAdrian Chadd #if 0
759ae3815fdSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: called, npending=%d\n",
760ae3815fdSAdrian Chadd 	    __func__, npending);
76192e84e43SAdrian Chadd #endif
762ae3815fdSAdrian Chadd 	ath_edma_tx_processq(sc, 1);
763ae3815fdSAdrian Chadd }
764ae3815fdSAdrian Chadd 
765ae3815fdSAdrian Chadd /*
766ae3815fdSAdrian Chadd  * Process the TX status queue.
767ae3815fdSAdrian Chadd  */
768ae3815fdSAdrian Chadd static void
769ae3815fdSAdrian Chadd ath_edma_tx_processq(struct ath_softc *sc, int dosched)
770ae3815fdSAdrian Chadd {
7713ae723d4SAdrian Chadd 	struct ath_hal *ah = sc->sc_ah;
7723ae723d4SAdrian Chadd 	HAL_STATUS status;
7733ae723d4SAdrian Chadd 	struct ath_tx_status ts;
7743ae723d4SAdrian Chadd 	struct ath_txq *txq;
7754aa8818bSAdrian Chadd 	struct ath_buf *bf;
7764aa8818bSAdrian Chadd 	struct ieee80211_node *ni;
777208be709SAdrian Chadd 	int nacked = 0;
778d40c846aSAdrian Chadd 	int idx;
7794f5ec72aSAdrian Chadd 	int i;
780d40c846aSAdrian Chadd 
781d40c846aSAdrian Chadd #ifdef	ATH_DEBUG
782d40c846aSAdrian Chadd 	/* XXX */
783d40c846aSAdrian Chadd 	uint32_t txstatus[32];
784d40c846aSAdrian Chadd #endif
785f8418db5SAdrian Chadd 
786d40c846aSAdrian Chadd 	for (idx = 0; ; idx++) {
7874aa8818bSAdrian Chadd 		bzero(&ts, sizeof(ts));
7884aa8818bSAdrian Chadd 
7893ae723d4SAdrian Chadd 		ATH_TXSTATUS_LOCK(sc);
7904c5038c7SAdrian Chadd #ifdef	ATH_DEBUG
791d40c846aSAdrian Chadd 		ath_hal_gettxrawtxdesc(ah, txstatus);
7924c5038c7SAdrian Chadd #endif
793ae3815fdSAdrian Chadd 		status = ath_hal_txprocdesc(ah, NULL, (void *) &ts);
7943ae723d4SAdrian Chadd 		ATH_TXSTATUS_UNLOCK(sc);
7953ae723d4SAdrian Chadd 
79692e84e43SAdrian Chadd 		if (status == HAL_EINPROGRESS)
79792e84e43SAdrian Chadd 			break;
79892e84e43SAdrian Chadd 
799d40c846aSAdrian Chadd #ifdef	ATH_DEBUG
800d40c846aSAdrian Chadd 		if (sc->sc_debug & ATH_DEBUG_TX_PROC)
80192e84e43SAdrian Chadd 			if (ts.ts_queue_id != sc->sc_bhalq)
802d40c846aSAdrian Chadd 			ath_printtxstatbuf(sc, NULL, txstatus, ts.ts_queue_id,
803d40c846aSAdrian Chadd 			    idx, (status == HAL_OK));
804d40c846aSAdrian Chadd #endif
805d40c846aSAdrian Chadd 
8063ae723d4SAdrian Chadd 		/*
8074aa8818bSAdrian Chadd 		 * If there is an error with this descriptor, continue
8084aa8818bSAdrian Chadd 		 * processing.
8094aa8818bSAdrian Chadd 		 *
8104aa8818bSAdrian Chadd 		 * XXX TBD: log some statistics?
8114aa8818bSAdrian Chadd 		 */
8124aa8818bSAdrian Chadd 		if (status == HAL_EIO) {
8134aa8818bSAdrian Chadd 			device_printf(sc->sc_dev, "%s: invalid TX status?\n",
8144aa8818bSAdrian Chadd 			    __func__);
815b92b5f6eSAdrian Chadd 			break;
8164aa8818bSAdrian Chadd 		}
8174aa8818bSAdrian Chadd 
81869cbcb21SAdrian Chadd #if defined(ATH_DEBUG_ALQ) && defined(ATH_DEBUG)
819*bd3b3362SAdrian Chadd 		if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXSTATUS)) {
820b69b0dccSAdrian Chadd 			if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_TXSTATUS,
821b69b0dccSAdrian Chadd 			    sc->sc_tx_statuslen,
822b69b0dccSAdrian Chadd 			    (char *) txstatus);
823*bd3b3362SAdrian Chadd 		}
824b69b0dccSAdrian Chadd #endif /* ATH_DEBUG_ALQ */
825b69b0dccSAdrian Chadd 
8264aa8818bSAdrian Chadd 		/*
8273ae723d4SAdrian Chadd 		 * At this point we have a valid status descriptor.
8283ae723d4SAdrian Chadd 		 * The QID and descriptor ID (which currently isn't set)
8293ae723d4SAdrian Chadd 		 * is part of the status.
8303ae723d4SAdrian Chadd 		 *
8313ae723d4SAdrian Chadd 		 * We then assume that the descriptor in question is the
8323ae723d4SAdrian Chadd 		 * -head- of the given QID.  Eventually we should verify
8333ae723d4SAdrian Chadd 		 * this by using the descriptor ID.
8343ae723d4SAdrian Chadd 		 */
8354aa8818bSAdrian Chadd 
8364aa8818bSAdrian Chadd 		/*
8374aa8818bSAdrian Chadd 		 * The beacon queue is not currently a "real" queue.
8384aa8818bSAdrian Chadd 		 * Frames aren't pushed onto it and the lock isn't setup.
8394aa8818bSAdrian Chadd 		 * So skip it for now; the beacon handling code will
8404aa8818bSAdrian Chadd 		 * free and alloc more beacon buffers as appropriate.
8414aa8818bSAdrian Chadd 		 */
8424aa8818bSAdrian Chadd 		if (ts.ts_queue_id == sc->sc_bhalq)
8434aa8818bSAdrian Chadd 			continue;
8443ae723d4SAdrian Chadd 
8453ae723d4SAdrian Chadd 		txq = &sc->sc_txq[ts.ts_queue_id];
8464aa8818bSAdrian Chadd 
847b837332dSAdrian Chadd 		ATH_TXQ_LOCK(txq);
84892e84e43SAdrian Chadd 		bf = ATH_TXQ_FIRST(&txq->fifo);
8494aa8818bSAdrian Chadd 
85092e84e43SAdrian Chadd 		/*
85192e84e43SAdrian Chadd 		 * Work around the situation where I'm seeing notifications
85292e84e43SAdrian Chadd 		 * for Q1 when no frames are available.  That needs to be
85392e84e43SAdrian Chadd 		 * debugged but not by crashing _here_.
85492e84e43SAdrian Chadd 		 */
85592e84e43SAdrian Chadd 		if (bf == NULL) {
85692e84e43SAdrian Chadd 			device_printf(sc->sc_dev, "%s: Q%d: empty?\n",
8574aa8818bSAdrian Chadd 			    __func__,
85892e84e43SAdrian Chadd 			    ts.ts_queue_id);
859b92b5f6eSAdrian Chadd 			ATH_TXQ_UNLOCK(txq);
86092e84e43SAdrian Chadd 			continue;
86192e84e43SAdrian Chadd 		}
86292e84e43SAdrian Chadd 
86392e84e43SAdrian Chadd 		DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d, bf=%p, start=%d, end=%d\n",
86492e84e43SAdrian Chadd 		    __func__,
86592e84e43SAdrian Chadd 		    ts.ts_queue_id, bf,
86692e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOPTR),
86792e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOEND));
8684aa8818bSAdrian Chadd 
869d40c846aSAdrian Chadd 		/* XXX TODO: actually output debugging info about this */
870d40c846aSAdrian Chadd 
8714aa8818bSAdrian Chadd #if 0
8724aa8818bSAdrian Chadd 		/* XXX assert the buffer/descriptor matches the status descid */
8734aa8818bSAdrian Chadd 		if (ts.ts_desc_id != bf->bf_descid) {
8744aa8818bSAdrian Chadd 			device_printf(sc->sc_dev,
8754aa8818bSAdrian Chadd 			    "%s: mismatched descid (qid=%d, tsdescid=%d, "
8764aa8818bSAdrian Chadd 			    "bfdescid=%d\n",
8774aa8818bSAdrian Chadd 			    __func__,
8784aa8818bSAdrian Chadd 			    ts.ts_queue_id,
8794aa8818bSAdrian Chadd 			    ts.ts_desc_id,
8804aa8818bSAdrian Chadd 			    bf->bf_descid);
8813ae723d4SAdrian Chadd 		}
8824aa8818bSAdrian Chadd #endif
8834aa8818bSAdrian Chadd 
8844aa8818bSAdrian Chadd 		/* This removes the buffer and decrements the queue depth */
88592e84e43SAdrian Chadd 		ATH_TXQ_REMOVE(&txq->fifo, bf, bf_list);
8864aa8818bSAdrian Chadd 		if (bf->bf_state.bfs_aggr)
8874aa8818bSAdrian Chadd 			txq->axq_aggr_depth--;
88892e84e43SAdrian Chadd 
88992e84e43SAdrian Chadd 		/*
89092e84e43SAdrian Chadd 		 * If this was the end of a FIFO set, decrement FIFO depth
89192e84e43SAdrian Chadd 		 */
89292e84e43SAdrian Chadd 		if (bf->bf_flags & ATH_BUF_FIFOEND)
8934aa8818bSAdrian Chadd 			txq->axq_fifo_depth--;
89492e84e43SAdrian Chadd 
89592e84e43SAdrian Chadd 		/*
89692e84e43SAdrian Chadd 		 * If this isn't the final buffer in a FIFO set, mark
89792e84e43SAdrian Chadd 		 * the buffer as busy so it goes onto the holding queue.
89892e84e43SAdrian Chadd 		 */
89992e84e43SAdrian Chadd 		if (! (bf->bf_flags & ATH_BUF_FIFOEND))
90092e84e43SAdrian Chadd 			bf->bf_flags |= ATH_BUF_BUSY;
90192e84e43SAdrian Chadd 
90292e84e43SAdrian Chadd 		DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d: FIFO depth is now %d (%d)\n",
90392e84e43SAdrian Chadd 		    __func__,
90492e84e43SAdrian Chadd 		    txq->axq_qnum,
90592e84e43SAdrian Chadd 		    txq->axq_fifo_depth,
90692e84e43SAdrian Chadd 		    txq->fifo.axq_depth);
90792e84e43SAdrian Chadd 
9084aa8818bSAdrian Chadd 		/* XXX assert FIFO depth >= 0 */
909b837332dSAdrian Chadd 		ATH_TXQ_UNLOCK(txq);
9104aa8818bSAdrian Chadd 
9114aa8818bSAdrian Chadd 		/*
91292e84e43SAdrian Chadd 		 * Outside of the TX lock - if the buffer is end
91392e84e43SAdrian Chadd 		 * end buffer in this FIFO, we don't need a holding
91492e84e43SAdrian Chadd 		 * buffer any longer.
91592e84e43SAdrian Chadd 		 */
91692e84e43SAdrian Chadd 		if (bf->bf_flags & ATH_BUF_FIFOEND) {
917caedab2cSAdrian Chadd 			ATH_TXQ_LOCK(txq);
91892e84e43SAdrian Chadd 			ath_txq_freeholdingbuf(sc, txq);
919caedab2cSAdrian Chadd 			ATH_TXQ_UNLOCK(txq);
92092e84e43SAdrian Chadd 		}
92192e84e43SAdrian Chadd 
92292e84e43SAdrian Chadd 		/*
9234aa8818bSAdrian Chadd 		 * First we need to make sure ts_rate is valid.
9244aa8818bSAdrian Chadd 		 *
9254aa8818bSAdrian Chadd 		 * Pre-EDMA chips pass the whole TX descriptor to
9264aa8818bSAdrian Chadd 		 * the proctxdesc function which will then fill out
9274aa8818bSAdrian Chadd 		 * ts_rate based on the ts_finaltsi (final TX index)
9284aa8818bSAdrian Chadd 		 * in the TX descriptor.  However the TX completion
9294aa8818bSAdrian Chadd 		 * FIFO doesn't have this information.  So here we
9304aa8818bSAdrian Chadd 		 * do a separate HAL call to populate that information.
9313345c65bSAdrian Chadd 		 *
9323345c65bSAdrian Chadd 		 * The same problem exists with ts_longretry.
9333345c65bSAdrian Chadd 		 * The FreeBSD HAL corrects ts_longretry in the HAL layer;
9343345c65bSAdrian Chadd 		 * the AR9380 HAL currently doesn't.  So until the HAL
9353345c65bSAdrian Chadd 		 * is imported and this can be added, we correct for it
9363345c65bSAdrian Chadd 		 * here.
9374aa8818bSAdrian Chadd 		 */
9384aa8818bSAdrian Chadd 		/* XXX TODO */
9394aa8818bSAdrian Chadd 		/* XXX faked for now. Ew. */
9404aa8818bSAdrian Chadd 		if (ts.ts_finaltsi < 4) {
9414aa8818bSAdrian Chadd 			ts.ts_rate =
9424aa8818bSAdrian Chadd 			    bf->bf_state.bfs_rc[ts.ts_finaltsi].ratecode;
9433345c65bSAdrian Chadd 			switch (ts.ts_finaltsi) {
9443345c65bSAdrian Chadd 			case 3: ts.ts_longretry +=
9453345c65bSAdrian Chadd 			    bf->bf_state.bfs_rc[2].tries;
9463345c65bSAdrian Chadd 			case 2: ts.ts_longretry +=
9473345c65bSAdrian Chadd 			    bf->bf_state.bfs_rc[1].tries;
9483345c65bSAdrian Chadd 			case 1: ts.ts_longretry +=
9493345c65bSAdrian Chadd 			    bf->bf_state.bfs_rc[0].tries;
9503345c65bSAdrian Chadd 			}
9514aa8818bSAdrian Chadd 		} else {
9524aa8818bSAdrian Chadd 			device_printf(sc->sc_dev, "%s: finaltsi=%d\n",
9534aa8818bSAdrian Chadd 			    __func__,
9544aa8818bSAdrian Chadd 			    ts.ts_finaltsi);
9554aa8818bSAdrian Chadd 			ts.ts_rate = bf->bf_state.bfs_rc[0].ratecode;
9564aa8818bSAdrian Chadd 		}
9574aa8818bSAdrian Chadd 
9584aa8818bSAdrian Chadd 		/*
9594aa8818bSAdrian Chadd 		 * XXX This is terrible.
9604aa8818bSAdrian Chadd 		 *
9614aa8818bSAdrian Chadd 		 * Right now, some code uses the TX status that is
9624aa8818bSAdrian Chadd 		 * passed in here, but the completion handlers in the
9634aa8818bSAdrian Chadd 		 * software TX path also use bf_status.ds_txstat.
9644aa8818bSAdrian Chadd 		 * Ew.  That should all go away.
9654aa8818bSAdrian Chadd 		 *
9664aa8818bSAdrian Chadd 		 * XXX It's also possible the rate control completion
9674aa8818bSAdrian Chadd 		 * routine is called twice.
9684aa8818bSAdrian Chadd 		 */
9694aa8818bSAdrian Chadd 		memcpy(&bf->bf_status, &ts, sizeof(ts));
9704aa8818bSAdrian Chadd 
9714aa8818bSAdrian Chadd 		ni = bf->bf_node;
9724aa8818bSAdrian Chadd 
9734aa8818bSAdrian Chadd 		/* Update RSSI */
9744aa8818bSAdrian Chadd 		/* XXX duplicate from ath_tx_processq */
9754aa8818bSAdrian Chadd 		if (ni != NULL && ts.ts_status == 0 &&
9764aa8818bSAdrian Chadd 		    ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) {
9774aa8818bSAdrian Chadd 			nacked++;
9784aa8818bSAdrian Chadd 			sc->sc_stats.ast_tx_rssi = ts.ts_rssi;
9794aa8818bSAdrian Chadd 			ATH_RSSI_LPF(sc->sc_halstats.ns_avgtxrssi,
9804aa8818bSAdrian Chadd 			    ts.ts_rssi);
9814aa8818bSAdrian Chadd 		}
9824aa8818bSAdrian Chadd 
9834aa8818bSAdrian Chadd 		/* Handle frame completion and rate control update */
9844aa8818bSAdrian Chadd 		ath_tx_process_buf_completion(sc, txq, &ts, bf);
9854aa8818bSAdrian Chadd 
9864f5ec72aSAdrian Chadd 		/* NB: bf is invalid at this point */
9874aa8818bSAdrian Chadd 	}
9884aa8818bSAdrian Chadd 
9894aa8818bSAdrian Chadd 	sc->sc_wd_timer = 0;
9904aa8818bSAdrian Chadd 
9914aa8818bSAdrian Chadd 	/*
9924aa8818bSAdrian Chadd 	 * XXX It's inefficient to do this if the FIFO queue is full,
9934aa8818bSAdrian Chadd 	 * but there's no easy way right now to only populate
9944aa8818bSAdrian Chadd 	 * the txq task for _one_ TXQ.  This should be fixed.
9954aa8818bSAdrian Chadd 	 */
9964f5ec72aSAdrian Chadd 	if (dosched) {
9974f5ec72aSAdrian Chadd 		/* Attempt to schedule more hardware frames to the TX FIFO */
9984f5ec72aSAdrian Chadd 		for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
9994f5ec72aSAdrian Chadd 			if (ATH_TXQ_SETUP(sc, i)) {
10004f5ec72aSAdrian Chadd 				ATH_TXQ_LOCK(&sc->sc_txq[i]);
10014f5ec72aSAdrian Chadd 				ath_edma_tx_fifo_fill(sc, &sc->sc_txq[i]);
10024f5ec72aSAdrian Chadd 				ATH_TXQ_UNLOCK(&sc->sc_txq[i]);
10034f5ec72aSAdrian Chadd 			}
10044f5ec72aSAdrian Chadd 		}
10054f5ec72aSAdrian Chadd 		/* Kick software scheduler */
100621bca442SAdrian Chadd 		ath_tx_swq_kick(sc);
1007f8418db5SAdrian Chadd 	}
10084f5ec72aSAdrian Chadd }
1009f8418db5SAdrian Chadd 
1010f8418db5SAdrian Chadd static void
1011f8418db5SAdrian Chadd ath_edma_attach_comp_func(struct ath_softc *sc)
1012f8418db5SAdrian Chadd {
1013f8418db5SAdrian Chadd 
1014f8418db5SAdrian Chadd 	TASK_INIT(&sc->sc_txtask, 0, ath_edma_tx_proc, sc);
1015f8418db5SAdrian Chadd }
1016f8418db5SAdrian Chadd 
10173fdfc330SAdrian Chadd void
10183fdfc330SAdrian Chadd ath_xmit_setup_edma(struct ath_softc *sc)
10193fdfc330SAdrian Chadd {
10203fdfc330SAdrian Chadd 
10213fdfc330SAdrian Chadd 	/* Fetch EDMA field and buffer sizes */
10223fdfc330SAdrian Chadd 	(void) ath_hal_gettxdesclen(sc->sc_ah, &sc->sc_tx_desclen);
10233fdfc330SAdrian Chadd 	(void) ath_hal_gettxstatuslen(sc->sc_ah, &sc->sc_tx_statuslen);
10243fdfc330SAdrian Chadd 	(void) ath_hal_getntxmaps(sc->sc_ah, &sc->sc_tx_nmaps);
10253fdfc330SAdrian Chadd 
1026516a0ac2SAdrian Chadd 	if (bootverbose) {
10273fdfc330SAdrian Chadd 		device_printf(sc->sc_dev, "TX descriptor length: %d\n",
10283fdfc330SAdrian Chadd 		    sc->sc_tx_desclen);
10293fdfc330SAdrian Chadd 		device_printf(sc->sc_dev, "TX status length: %d\n",
10303fdfc330SAdrian Chadd 		    sc->sc_tx_statuslen);
10313fdfc330SAdrian Chadd 		device_printf(sc->sc_dev, "TX buffers per descriptor: %d\n",
10323fdfc330SAdrian Chadd 		    sc->sc_tx_nmaps);
1033516a0ac2SAdrian Chadd 	}
10343fdfc330SAdrian Chadd 
10353fdfc330SAdrian Chadd 	sc->sc_tx.xmit_setup = ath_edma_dma_txsetup;
10363fdfc330SAdrian Chadd 	sc->sc_tx.xmit_teardown = ath_edma_dma_txteardown;
1037f8418db5SAdrian Chadd 	sc->sc_tx.xmit_attach_comp_func = ath_edma_attach_comp_func;
1038746bab5bSAdrian Chadd 
1039746bab5bSAdrian Chadd 	sc->sc_tx.xmit_dma_restart = ath_edma_dma_restart;
1040746bab5bSAdrian Chadd 	sc->sc_tx.xmit_handoff = ath_edma_xmit_handoff;
1041788e6aa9SAdrian Chadd 	sc->sc_tx.xmit_drain = ath_edma_tx_drain;
10423fdfc330SAdrian Chadd }
1043