xref: /freebsd/sys/dev/ath/if_ath_tx_edma.c (revision 4f5ec72aa42401b2a7663df78d9d5c440542daec)
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 
159*4f5ec72aSAdrian Chadd /*
160*4f5ec72aSAdrian Chadd  * XXX TODO: push an aggregate as a single FIFO slot, even though
161*4f5ec72aSAdrian Chadd  * it may not meet the TXOP for say, DBA-gated traffic in TDMA mode.
162*4f5ec72aSAdrian Chadd  *
163*4f5ec72aSAdrian Chadd  * The TX completion code handles a TX FIFO slot having multiple frames,
164*4f5ec72aSAdrian Chadd  * aggregate or otherwise, but it may just make things easier to deal
165*4f5ec72aSAdrian Chadd  * with.
166*4f5ec72aSAdrian Chadd  *
167*4f5ec72aSAdrian Chadd  * XXX TODO: track the number of aggregate subframes and put that in the
168*4f5ec72aSAdrian Chadd  * push alq message.
169*4f5ec72aSAdrian 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++;
27149236b4eSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_XMIT,
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 
288*4f5ec72aSAdrian Chadd #define	TX_BATCH_SIZE	32
289*4f5ec72aSAdrian 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 
29992e84e43SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d: called\n",
30092e84e43SAdrian Chadd 	    __func__,
30192e84e43SAdrian Chadd 	    txq->axq_qnum);
3024aa8818bSAdrian Chadd 
30392e84e43SAdrian Chadd 	/*
30449236b4eSAdrian Chadd 	 * For now, push up to 4 frames per TX FIFO slot.
30549236b4eSAdrian Chadd 	 * If more are in the hardware queue then they'll
30649236b4eSAdrian Chadd 	 * get populated when we try to send another frame
30749236b4eSAdrian Chadd 	 * or complete a frame - so at most there'll be
30849236b4eSAdrian Chadd 	 * 32 non-AMPDU frames per TXQ.
30992e84e43SAdrian Chadd 	 *
31049236b4eSAdrian Chadd 	 * Note that the hardware staging queue will limit
31149236b4eSAdrian Chadd 	 * how many frames in total we will have pushed into
31249236b4eSAdrian Chadd 	 * here.
31349236b4eSAdrian Chadd 	 *
31449236b4eSAdrian Chadd 	 * Later on, we'll want to push less frames into
31549236b4eSAdrian Chadd 	 * the TX FIFO since we don't want to necessarily
31649236b4eSAdrian Chadd 	 * fill tens or hundreds of milliseconds of potential
31749236b4eSAdrian Chadd 	 * frames.
31849236b4eSAdrian Chadd 	 *
31949236b4eSAdrian Chadd 	 * However, we need more frames right now because of
32049236b4eSAdrian Chadd 	 * how the MAC implements the frame scheduling policy.
32149236b4eSAdrian Chadd 	 * It only ungates a single FIFO entry at a time,
32249236b4eSAdrian Chadd 	 * and will run that until CHNTIME expires or the
32349236b4eSAdrian Chadd 	 * end of that FIFO entry descriptor list is reached.
32449236b4eSAdrian Chadd 	 * So for TDMA we suffer a big performance penalty -
32549236b4eSAdrian Chadd 	 * single TX FIFO entries mean the MAC only sends out
32649236b4eSAdrian Chadd 	 * one frame per DBA event, which turned out on average
32749236b4eSAdrian Chadd 	 * 6ms per TX frame.
32849236b4eSAdrian Chadd 	 *
32949236b4eSAdrian Chadd 	 * So, for aggregates it's okay - it'll push two at a
33049236b4eSAdrian Chadd 	 * time and this will just do them more efficiently.
33149236b4eSAdrian Chadd 	 * For non-aggregates it'll do 4 at a time, up to the
33249236b4eSAdrian Chadd 	 * non-aggr limit (non_aggr, which is 32.)  They should
33349236b4eSAdrian Chadd 	 * be time based rather than a hard count, but I also
33449236b4eSAdrian Chadd 	 * do need sleep.
33592e84e43SAdrian Chadd 	 */
336*4f5ec72aSAdrian Chadd 
337*4f5ec72aSAdrian Chadd 	/*
338*4f5ec72aSAdrian Chadd 	 * Do some basic, basic batching to the hardware
339*4f5ec72aSAdrian Chadd 	 * queue.
340*4f5ec72aSAdrian Chadd 	 *
341*4f5ec72aSAdrian Chadd 	 * If we have TX_BATCH_SIZE entries in the staging
342*4f5ec72aSAdrian Chadd 	 * queue, then let's try to send them all in one hit.
343*4f5ec72aSAdrian Chadd 	 *
344*4f5ec72aSAdrian Chadd 	 * Ensure we don't push more than TX_BATCH_SIZE worth
345*4f5ec72aSAdrian Chadd 	 * in, otherwise we end up draining 8 slots worth of
346*4f5ec72aSAdrian Chadd 	 * 32 frames into the hardware queue and then we don't
347*4f5ec72aSAdrian Chadd 	 * attempt to push more frames in until we empty the
348*4f5ec72aSAdrian Chadd 	 * FIFO.
349*4f5ec72aSAdrian Chadd 	 */
350*4f5ec72aSAdrian Chadd 	if (txq->axq_depth >= TX_BATCH_SIZE / 2 &&
351*4f5ec72aSAdrian Chadd 	    txq->fifo.axq_depth <= TX_BATCH_SIZE) {
352*4f5ec72aSAdrian Chadd 		ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
353*4f5ec72aSAdrian Chadd 	}
354*4f5ec72aSAdrian Chadd 
355*4f5ec72aSAdrian Chadd 	/*
356*4f5ec72aSAdrian Chadd 	 * Aggregate check: if we have less than two FIFO slots
357*4f5ec72aSAdrian Chadd 	 * busy and we have some aggregate frames, queue it.
358*4f5ec72aSAdrian Chadd 	 *
359*4f5ec72aSAdrian Chadd 	 * Now, ideally we'd just check to see if the scheduler
360*4f5ec72aSAdrian Chadd 	 * has given us aggregate frames and push them into the FIFO
361*4f5ec72aSAdrian Chadd 	 * as individual slots, as honestly we should just be pushing
362*4f5ec72aSAdrian Chadd 	 * a single aggregate in as one FIFO slot.
363*4f5ec72aSAdrian Chadd 	 *
364*4f5ec72aSAdrian Chadd 	 * Let's do that next once I know this works.
365*4f5ec72aSAdrian Chadd 	 */
366*4f5ec72aSAdrian Chadd 	else if (txq->axq_aggr_depth > 0 && txq->axq_fifo_depth < 2)
367*4f5ec72aSAdrian Chadd 		ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
368*4f5ec72aSAdrian Chadd 
369*4f5ec72aSAdrian Chadd 	/*
370*4f5ec72aSAdrian Chadd 	 *
371*4f5ec72aSAdrian Chadd 	 * If we have less, and the TXFIFO isn't empty, let's
372*4f5ec72aSAdrian Chadd 	 * wait until we've finished sending the FIFO.
373*4f5ec72aSAdrian Chadd 	 *
374*4f5ec72aSAdrian Chadd 	 * If we have less, and the TXFIFO is empty, then
375*4f5ec72aSAdrian Chadd 	 * send them.
376*4f5ec72aSAdrian Chadd 	 */
377*4f5ec72aSAdrian Chadd 	else if (txq->axq_fifo_depth == 0) {
378*4f5ec72aSAdrian Chadd 		ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
379*4f5ec72aSAdrian Chadd 	}
3804aa8818bSAdrian Chadd }
3814aa8818bSAdrian Chadd 
382746bab5bSAdrian Chadd /*
383746bab5bSAdrian Chadd  * Re-initialise the DMA FIFO with the current contents of
3843ae723d4SAdrian Chadd  * said TXQ.
385746bab5bSAdrian Chadd  *
386746bab5bSAdrian Chadd  * This should only be called as part of the chip reset path, as it
387746bab5bSAdrian Chadd  * assumes the FIFO is currently empty.
388746bab5bSAdrian Chadd  */
389746bab5bSAdrian Chadd static void
390746bab5bSAdrian Chadd ath_edma_dma_restart(struct ath_softc *sc, struct ath_txq *txq)
391746bab5bSAdrian Chadd {
39292e84e43SAdrian Chadd 	struct ath_buf *bf;
39392e84e43SAdrian Chadd 	int i = 0;
39492e84e43SAdrian Chadd 	int fifostart = 1;
39592e84e43SAdrian Chadd 	int old_fifo_depth;
396746bab5bSAdrian Chadd 
39792e84e43SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_RESET, "%s: Q%d: called\n",
398746bab5bSAdrian Chadd 	    __func__,
399746bab5bSAdrian Chadd 	    txq->axq_qnum);
4004aa8818bSAdrian Chadd 
401b837332dSAdrian Chadd 	ATH_TXQ_LOCK_ASSERT(txq);
40292e84e43SAdrian Chadd 
40392e84e43SAdrian Chadd 	/*
40492e84e43SAdrian Chadd 	 * Let's log if the tracked FIFO depth doesn't match
40592e84e43SAdrian Chadd 	 * what we actually push in.
40692e84e43SAdrian Chadd 	 */
40792e84e43SAdrian Chadd 	old_fifo_depth = txq->axq_fifo_depth;
40892e84e43SAdrian Chadd 	txq->axq_fifo_depth = 0;
40992e84e43SAdrian Chadd 
41092e84e43SAdrian Chadd 	/*
41192e84e43SAdrian Chadd 	 * Walk the FIFO staging list, looking for "head" entries.
41292e84e43SAdrian Chadd 	 * Since we may have a partially completed list of frames,
41392e84e43SAdrian Chadd 	 * we push the first frame we see into the FIFO and re-mark
41492e84e43SAdrian Chadd 	 * it as the head entry.  We then skip entries until we see
41592e84e43SAdrian Chadd 	 * FIFO end, at which point we get ready to push another
41692e84e43SAdrian Chadd 	 * entry into the FIFO.
41792e84e43SAdrian Chadd 	 */
41892e84e43SAdrian Chadd 	TAILQ_FOREACH(bf, &txq->fifo.axq_q, bf_list) {
41992e84e43SAdrian Chadd 		/*
42092e84e43SAdrian Chadd 		 * If we're looking for FIFOEND and we haven't found
42192e84e43SAdrian Chadd 		 * it, skip.
42292e84e43SAdrian Chadd 		 *
42392e84e43SAdrian Chadd 		 * If we're looking for FIFOEND and we've found it,
42492e84e43SAdrian Chadd 		 * reset for another descriptor.
42592e84e43SAdrian Chadd 		 */
42692e84e43SAdrian Chadd #ifdef	ATH_DEBUG
42792e84e43SAdrian Chadd 		if (sc->sc_debug & ATH_DEBUG_XMIT_DESC)
42892e84e43SAdrian Chadd 			ath_printtxbuf(sc, bf, txq->axq_qnum, i, 0);
42992e84e43SAdrian Chadd #endif/* ATH_DEBUG */
43092e84e43SAdrian Chadd #ifdef	ATH_DEBUG_ALQ
43192e84e43SAdrian Chadd 		if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
43292e84e43SAdrian Chadd 			ath_tx_alq_post(sc, bf);
43392e84e43SAdrian Chadd #endif /* ATH_DEBUG_ALQ */
43492e84e43SAdrian Chadd 
43592e84e43SAdrian Chadd 		if (fifostart == 0) {
43692e84e43SAdrian Chadd 			if (bf->bf_flags & ATH_BUF_FIFOEND)
43792e84e43SAdrian Chadd 				fifostart = 1;
43892e84e43SAdrian Chadd 			continue;
43992e84e43SAdrian Chadd 		}
44092e84e43SAdrian Chadd 
44192e84e43SAdrian Chadd 		/* Make sure we're not overflowing the FIFO! */
44292e84e43SAdrian Chadd 		if (txq->axq_fifo_depth >= HAL_TXFIFO_DEPTH) {
44392e84e43SAdrian Chadd 			device_printf(sc->sc_dev,
44492e84e43SAdrian Chadd 			    "%s: Q%d: more frames in the queue; FIFO depth=%d?!\n",
44592e84e43SAdrian Chadd 			    __func__,
44692e84e43SAdrian Chadd 			    txq->axq_qnum,
44792e84e43SAdrian Chadd 			    txq->axq_fifo_depth);
44892e84e43SAdrian Chadd 		}
44992e84e43SAdrian Chadd 
45092e84e43SAdrian Chadd #if 0
45192e84e43SAdrian Chadd 		DPRINTF(sc, ATH_DEBUG_RESET,
45292e84e43SAdrian Chadd 		    "%s: Q%d: depth=%d: pushing bf=%p; start=%d, end=%d\n",
45392e84e43SAdrian Chadd 		    __func__,
45492e84e43SAdrian Chadd 		    txq->axq_qnum,
45592e84e43SAdrian Chadd 		    txq->axq_fifo_depth,
45692e84e43SAdrian Chadd 		    bf,
45792e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOPTR),
45892e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOEND));
45992e84e43SAdrian Chadd #endif
46092e84e43SAdrian Chadd 
46192e84e43SAdrian Chadd 		/*
46292e84e43SAdrian Chadd 		 * Set this to be the first buffer in the FIFO
46392e84e43SAdrian Chadd 		 * list - even if it's also the last buffer in
46492e84e43SAdrian Chadd 		 * a FIFO list!
46592e84e43SAdrian Chadd 		 */
46692e84e43SAdrian Chadd 		bf->bf_flags |= ATH_BUF_FIFOPTR;
46792e84e43SAdrian Chadd 
46892e84e43SAdrian Chadd 		/* Push it into the FIFO and bump the FIFO count */
46992e84e43SAdrian Chadd 		ath_hal_puttxbuf(sc->sc_ah, txq->axq_qnum, bf->bf_daddr);
47092e84e43SAdrian Chadd 		txq->axq_fifo_depth++;
47192e84e43SAdrian Chadd 
47292e84e43SAdrian Chadd 		/*
47392e84e43SAdrian Chadd 		 * If this isn't the last entry either, let's
47492e84e43SAdrian Chadd 		 * clear fifostart so we continue looking for
47592e84e43SAdrian Chadd 		 * said last entry.
47692e84e43SAdrian Chadd 		 */
47792e84e43SAdrian Chadd 		if (! (bf->bf_flags & ATH_BUF_FIFOEND))
47892e84e43SAdrian Chadd 			fifostart = 0;
47992e84e43SAdrian Chadd 		i++;
48092e84e43SAdrian Chadd 	}
48192e84e43SAdrian Chadd 
48292e84e43SAdrian Chadd 	/* Only bother starting the queue if there's something in it */
48392e84e43SAdrian Chadd 	if (i > 0)
48492e84e43SAdrian Chadd 		ath_hal_txstart(sc->sc_ah, txq->axq_qnum);
48592e84e43SAdrian Chadd 
48692e84e43SAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_RESET, "%s: Q%d: FIFO depth was %d, is %d\n",
48792e84e43SAdrian Chadd 	    __func__,
48892e84e43SAdrian Chadd 	    txq->axq_qnum,
48992e84e43SAdrian Chadd 	    old_fifo_depth,
49092e84e43SAdrian Chadd 	    txq->axq_fifo_depth);
49192e84e43SAdrian Chadd 
49292e84e43SAdrian Chadd 	/* And now, let's check! */
49392e84e43SAdrian Chadd 	if (txq->axq_fifo_depth != old_fifo_depth) {
49492e84e43SAdrian Chadd 		device_printf(sc->sc_dev,
49592e84e43SAdrian Chadd 		    "%s: Q%d: FIFO depth should be %d, is %d\n",
49692e84e43SAdrian Chadd 		    __func__,
49792e84e43SAdrian Chadd 		    txq->axq_qnum,
49892e84e43SAdrian Chadd 		    old_fifo_depth,
49992e84e43SAdrian Chadd 		    txq->axq_fifo_depth);
50092e84e43SAdrian Chadd 	}
501746bab5bSAdrian Chadd }
502746bab5bSAdrian Chadd 
503746bab5bSAdrian Chadd /*
5043ae723d4SAdrian Chadd  * Hand off this frame to a hardware queue.
5053ae723d4SAdrian Chadd  *
5063ae723d4SAdrian Chadd  * Things are a bit hairy in the EDMA world.  The TX FIFO is only
5073ae723d4SAdrian Chadd  * 8 entries deep, so we need to keep track of exactly what we've
5083ae723d4SAdrian Chadd  * pushed into the FIFO and what's just sitting in the TX queue,
5093ae723d4SAdrian Chadd  * waiting to go out.
5103ae723d4SAdrian Chadd  *
5113ae723d4SAdrian Chadd  * So this is split into two halves - frames get appended to the
5123ae723d4SAdrian Chadd  * TXQ; then a scheduler is called to push some frames into the
5133ae723d4SAdrian Chadd  * actual TX FIFO.
5143ae723d4SAdrian Chadd  */
5153ae723d4SAdrian Chadd static void
5163ae723d4SAdrian Chadd ath_edma_xmit_handoff_hw(struct ath_softc *sc, struct ath_txq *txq,
5173ae723d4SAdrian Chadd     struct ath_buf *bf)
5183ae723d4SAdrian Chadd {
5193ae723d4SAdrian Chadd 
5200acf45edSAdrian Chadd 	ATH_TXQ_LOCK(txq);
5213ae723d4SAdrian Chadd 
5223ae723d4SAdrian Chadd 	KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
5233ae723d4SAdrian Chadd 	    ("%s: busy status 0x%x", __func__, bf->bf_flags));
5243ae723d4SAdrian Chadd 
5253ae723d4SAdrian Chadd 	/*
5263ae723d4SAdrian Chadd 	 * XXX TODO: write a hard-coded check to ensure that
5273ae723d4SAdrian Chadd 	 * the queue id in the TX descriptor matches txq->axq_qnum.
5283ae723d4SAdrian Chadd 	 */
5293ae723d4SAdrian Chadd 
5303ae723d4SAdrian Chadd 	/* Update aggr stats */
5313ae723d4SAdrian Chadd 	if (bf->bf_state.bfs_aggr)
5323ae723d4SAdrian Chadd 		txq->axq_aggr_depth++;
5333ae723d4SAdrian Chadd 
5343ae723d4SAdrian Chadd 	/* Push and update frame stats */
5353ae723d4SAdrian Chadd 	ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
5363ae723d4SAdrian Chadd 
53792e84e43SAdrian Chadd 	/*
53892e84e43SAdrian Chadd 	 * Finally, call the FIFO schedule routine to schedule some
53992e84e43SAdrian Chadd 	 * frames to the FIFO.
54092e84e43SAdrian Chadd 	 */
54192e84e43SAdrian Chadd 	ath_edma_tx_fifo_fill(sc, txq);
5420acf45edSAdrian Chadd 	ATH_TXQ_UNLOCK(txq);
5433ae723d4SAdrian Chadd }
5443ae723d4SAdrian Chadd 
5453ae723d4SAdrian Chadd /*
5463ae723d4SAdrian Chadd  * Hand off this frame to a multicast software queue.
5473ae723d4SAdrian Chadd  *
548e3f06688SAdrian Chadd  * The EDMA TX CABQ will get a list of chained frames, chained
549e3f06688SAdrian Chadd  * together using the next pointer.  The single head of that
550e3f06688SAdrian Chadd  * particular queue is pushed to the hardware CABQ.
5513ae723d4SAdrian Chadd  */
5523ae723d4SAdrian Chadd static void
5533ae723d4SAdrian Chadd ath_edma_xmit_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq,
5543ae723d4SAdrian Chadd     struct ath_buf *bf)
5553ae723d4SAdrian Chadd {
5563ae723d4SAdrian Chadd 
5579e7259a2SAdrian Chadd 	ATH_TX_LOCK_ASSERT(sc);
5583ae723d4SAdrian Chadd 	KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
5593ae723d4SAdrian Chadd 	    ("%s: busy status 0x%x", __func__, bf->bf_flags));
5603ae723d4SAdrian Chadd 
5610acf45edSAdrian Chadd 	ATH_TXQ_LOCK(txq);
5623ae723d4SAdrian Chadd 	/*
5633ae723d4SAdrian Chadd 	 * XXX this is mostly duplicated in ath_tx_handoff_mcast().
5643ae723d4SAdrian Chadd 	 */
5659e7259a2SAdrian Chadd 	if (ATH_TXQ_LAST(txq, axq_q_s) != NULL) {
5663ae723d4SAdrian Chadd 		struct ath_buf *bf_last = ATH_TXQ_LAST(txq, axq_q_s);
5673ae723d4SAdrian Chadd 		struct ieee80211_frame *wh;
5683ae723d4SAdrian Chadd 
5693ae723d4SAdrian Chadd 		/* mark previous frame */
5703ae723d4SAdrian Chadd 		wh = mtod(bf_last->bf_m, struct ieee80211_frame *);
5713ae723d4SAdrian Chadd 		wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
5723ae723d4SAdrian Chadd 
573caedab2cSAdrian Chadd 		/* re-sync buffer to memory */
5743ae723d4SAdrian Chadd 		bus_dmamap_sync(sc->sc_dmat, bf_last->bf_dmamap,
5753ae723d4SAdrian Chadd 		   BUS_DMASYNC_PREWRITE);
5769cda8c80SAdrian Chadd 
5779cda8c80SAdrian Chadd 		/* link descriptor */
5789e7259a2SAdrian Chadd 		ath_hal_settxdesclink(sc->sc_ah,
5799e7259a2SAdrian Chadd 		    bf_last->bf_lastds,
5809e7259a2SAdrian Chadd 		    bf->bf_daddr);
5813ae723d4SAdrian Chadd 	}
582e3f06688SAdrian Chadd #ifdef	ATH_DEBUG_ALQ
583e3f06688SAdrian Chadd 	if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
584e3f06688SAdrian Chadd 		ath_tx_alq_post(sc, bf);
585e3f06688SAdrian Chadd #endif	/* ATH_DEBUG_ALQ */
5863ae723d4SAdrian Chadd 	ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
5870acf45edSAdrian Chadd 	ATH_TXQ_UNLOCK(txq);
5883ae723d4SAdrian Chadd }
5893ae723d4SAdrian Chadd 
5903ae723d4SAdrian Chadd /*
591746bab5bSAdrian Chadd  * Handoff this frame to the hardware.
592746bab5bSAdrian Chadd  *
593746bab5bSAdrian Chadd  * For the multicast queue, this will treat it as a software queue
594746bab5bSAdrian Chadd  * and append it to the list, after updating the MORE_DATA flag
595746bab5bSAdrian Chadd  * in the previous frame.  The cabq processing code will ensure
596746bab5bSAdrian Chadd  * that the queue contents gets transferred over.
597746bab5bSAdrian Chadd  *
598746bab5bSAdrian Chadd  * For the hardware queues, this will queue a frame to the queue
599746bab5bSAdrian Chadd  * like before, then populate the FIFO from that.  Since the
600746bab5bSAdrian Chadd  * EDMA hardware has 8 FIFO slots per TXQ, this ensures that
601746bab5bSAdrian Chadd  * frames such as management frames don't get prematurely dropped.
602746bab5bSAdrian Chadd  *
603746bab5bSAdrian Chadd  * This does imply that a similar flush-hwq-to-fifoq method will
604746bab5bSAdrian Chadd  * need to be called from the processq function, before the
605746bab5bSAdrian Chadd  * per-node software scheduler is called.
606746bab5bSAdrian Chadd  */
607746bab5bSAdrian Chadd static void
608746bab5bSAdrian Chadd ath_edma_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq,
609746bab5bSAdrian Chadd     struct ath_buf *bf)
610746bab5bSAdrian Chadd {
611746bab5bSAdrian Chadd 
6124aa8818bSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_XMIT_DESC,
6134aa8818bSAdrian Chadd 	    "%s: called; bf=%p, txq=%p, qnum=%d\n",
614746bab5bSAdrian Chadd 	    __func__,
615746bab5bSAdrian Chadd 	    bf,
616746bab5bSAdrian Chadd 	    txq,
617746bab5bSAdrian Chadd 	    txq->axq_qnum);
618746bab5bSAdrian Chadd 
6193ae723d4SAdrian Chadd 	if (txq->axq_qnum == ATH_TXQ_SWQ)
6203ae723d4SAdrian Chadd 		ath_edma_xmit_handoff_mcast(sc, txq, bf);
6213ae723d4SAdrian Chadd 	else
6223ae723d4SAdrian Chadd 		ath_edma_xmit_handoff_hw(sc, txq, bf);
623746bab5bSAdrian Chadd }
624746bab5bSAdrian Chadd 
6253fdfc330SAdrian Chadd static int
62679607afeSAdrian Chadd ath_edma_setup_txfifo(struct ath_softc *sc, int qnum)
62779607afeSAdrian Chadd {
62879607afeSAdrian Chadd 	struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
62979607afeSAdrian Chadd 
63079607afeSAdrian Chadd 	te->m_fifo = malloc(sizeof(struct ath_buf *) * HAL_TXFIFO_DEPTH,
63179607afeSAdrian Chadd 	    M_ATHDEV,
63279607afeSAdrian Chadd 	    M_NOWAIT | M_ZERO);
63379607afeSAdrian Chadd 	if (te->m_fifo == NULL) {
63479607afeSAdrian Chadd 		device_printf(sc->sc_dev, "%s: malloc failed\n",
63579607afeSAdrian Chadd 		    __func__);
63679607afeSAdrian Chadd 		return (-ENOMEM);
63779607afeSAdrian Chadd 	}
63879607afeSAdrian Chadd 
63979607afeSAdrian Chadd 	/*
64079607afeSAdrian Chadd 	 * Set initial "empty" state.
64179607afeSAdrian Chadd 	 */
64279607afeSAdrian Chadd 	te->m_fifo_head = te->m_fifo_tail = te->m_fifo_depth = 0;
64379607afeSAdrian Chadd 
64479607afeSAdrian Chadd 	return (0);
64579607afeSAdrian Chadd }
64679607afeSAdrian Chadd 
64779607afeSAdrian Chadd static int
64879607afeSAdrian Chadd ath_edma_free_txfifo(struct ath_softc *sc, int qnum)
64979607afeSAdrian Chadd {
65079607afeSAdrian Chadd 	struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
65179607afeSAdrian Chadd 
65279607afeSAdrian Chadd 	/* XXX TODO: actually deref the ath_buf entries? */
65379607afeSAdrian Chadd 	free(te->m_fifo, M_ATHDEV);
65479607afeSAdrian Chadd 	return (0);
65579607afeSAdrian Chadd }
65679607afeSAdrian Chadd 
65779607afeSAdrian Chadd static int
6583fdfc330SAdrian Chadd ath_edma_dma_txsetup(struct ath_softc *sc)
6593fdfc330SAdrian Chadd {
660ba3fd9d8SAdrian Chadd 	int error;
66179607afeSAdrian Chadd 	int i;
6623fdfc330SAdrian Chadd 
663ba3fd9d8SAdrian Chadd 	error = ath_descdma_alloc_desc(sc, &sc->sc_txsdma,
664ba3fd9d8SAdrian Chadd 	    NULL, "txcomp", sc->sc_tx_statuslen, ATH_TXSTATUS_RING_SIZE);
665ba3fd9d8SAdrian Chadd 	if (error != 0)
666ba3fd9d8SAdrian Chadd 		return (error);
667ba3fd9d8SAdrian Chadd 
668ba3fd9d8SAdrian Chadd 	ath_hal_setuptxstatusring(sc->sc_ah,
669ba3fd9d8SAdrian Chadd 	    (void *) sc->sc_txsdma.dd_desc,
670ba3fd9d8SAdrian Chadd 	    sc->sc_txsdma.dd_desc_paddr,
671ba3fd9d8SAdrian Chadd 	    ATH_TXSTATUS_RING_SIZE);
672ba3fd9d8SAdrian Chadd 
67379607afeSAdrian Chadd 	for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
67479607afeSAdrian Chadd 		ath_edma_setup_txfifo(sc, i);
67579607afeSAdrian Chadd 	}
67679607afeSAdrian Chadd 
6773fdfc330SAdrian Chadd 	return (0);
6783fdfc330SAdrian Chadd }
6793fdfc330SAdrian Chadd 
6803fdfc330SAdrian Chadd static int
6813fdfc330SAdrian Chadd ath_edma_dma_txteardown(struct ath_softc *sc)
6823fdfc330SAdrian Chadd {
68379607afeSAdrian Chadd 	int i;
68479607afeSAdrian Chadd 
68579607afeSAdrian Chadd 	for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
68679607afeSAdrian Chadd 		ath_edma_free_txfifo(sc, i);
68779607afeSAdrian Chadd 	}
6883fdfc330SAdrian Chadd 
689ba3fd9d8SAdrian Chadd 	ath_descdma_cleanup(sc, &sc->sc_txsdma, NULL);
6903fdfc330SAdrian Chadd 	return (0);
6913fdfc330SAdrian Chadd }
6923fdfc330SAdrian Chadd 
6933ae723d4SAdrian Chadd /*
694788e6aa9SAdrian Chadd  * Drain all TXQs, potentially after completing the existing completed
695788e6aa9SAdrian Chadd  * frames.
6963ae723d4SAdrian Chadd  */
697788e6aa9SAdrian Chadd static void
698788e6aa9SAdrian Chadd ath_edma_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
699f8418db5SAdrian Chadd {
7004aa8818bSAdrian Chadd 	int i;
701f8418db5SAdrian Chadd 
702ae3815fdSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_RESET, "%s: called\n", __func__);
7034aa8818bSAdrian Chadd 
7044aa8818bSAdrian Chadd 	(void) ath_stoptxdma(sc);
7054aa8818bSAdrian Chadd 
7064aa8818bSAdrian Chadd 	/*
7074aa8818bSAdrian Chadd 	 * If reset type is noloss, the TX FIFO needs to be serviced
7084aa8818bSAdrian Chadd 	 * and those frames need to be handled.
7094aa8818bSAdrian Chadd 	 *
7104aa8818bSAdrian Chadd 	 * Otherwise, just toss everything in each TX queue.
7114aa8818bSAdrian Chadd 	 */
712ae3815fdSAdrian Chadd 	if (reset_type == ATH_RESET_NOLOSS) {
713ae3815fdSAdrian Chadd 		ath_edma_tx_processq(sc, 0);
7148328d6e4SAdrian Chadd 		for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
7158328d6e4SAdrian Chadd 			if (ATH_TXQ_SETUP(sc, i)) {
7168328d6e4SAdrian Chadd 				ATH_TXQ_LOCK(&sc->sc_txq[i]);
7178328d6e4SAdrian Chadd 				/*
7188328d6e4SAdrian Chadd 				 * Free the holding buffer; DMA is now
7198328d6e4SAdrian Chadd 				 * stopped.
7208328d6e4SAdrian Chadd 				 */
7218328d6e4SAdrian Chadd 				ath_txq_freeholdingbuf(sc, &sc->sc_txq[i]);
7228328d6e4SAdrian Chadd 				/*
7238328d6e4SAdrian Chadd 				 * Reset the link pointer to NULL; there's
7248328d6e4SAdrian Chadd 				 * no frames to chain DMA to.
7258328d6e4SAdrian Chadd 				 */
7268328d6e4SAdrian Chadd 				sc->sc_txq[i].axq_link = NULL;
7278328d6e4SAdrian Chadd 				ATH_TXQ_UNLOCK(&sc->sc_txq[i]);
7288328d6e4SAdrian Chadd 			}
7298328d6e4SAdrian Chadd 		}
730ae3815fdSAdrian Chadd 	} else {
7314aa8818bSAdrian Chadd 		for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
7324aa8818bSAdrian Chadd 			if (ATH_TXQ_SETUP(sc, i))
7334aa8818bSAdrian Chadd 				ath_tx_draintxq(sc, &sc->sc_txq[i]);
7344aa8818bSAdrian Chadd 		}
735ae3815fdSAdrian Chadd 	}
736ae3815fdSAdrian Chadd 
737ae3815fdSAdrian Chadd 	/* XXX dump out the TX completion FIFO contents */
738ae3815fdSAdrian Chadd 
739ae3815fdSAdrian Chadd 	/* XXX dump out the frames */
7404aa8818bSAdrian Chadd 
7414aa8818bSAdrian Chadd 	sc->sc_wd_timer = 0;
742f8418db5SAdrian Chadd }
743f8418db5SAdrian Chadd 
7443ae723d4SAdrian Chadd /*
745ae3815fdSAdrian Chadd  * TX completion tasklet.
7463ae723d4SAdrian Chadd  */
747ae3815fdSAdrian Chadd 
748f8418db5SAdrian Chadd static void
749f8418db5SAdrian Chadd ath_edma_tx_proc(void *arg, int npending)
750f8418db5SAdrian Chadd {
751f8418db5SAdrian Chadd 	struct ath_softc *sc = (struct ath_softc *) arg;
752ae3815fdSAdrian Chadd 
75392e84e43SAdrian Chadd #if 0
754ae3815fdSAdrian Chadd 	DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: called, npending=%d\n",
755ae3815fdSAdrian Chadd 	    __func__, npending);
75692e84e43SAdrian Chadd #endif
757ae3815fdSAdrian Chadd 	ath_edma_tx_processq(sc, 1);
758ae3815fdSAdrian Chadd }
759ae3815fdSAdrian Chadd 
760ae3815fdSAdrian Chadd /*
761ae3815fdSAdrian Chadd  * Process the TX status queue.
762ae3815fdSAdrian Chadd  */
763ae3815fdSAdrian Chadd static void
764ae3815fdSAdrian Chadd ath_edma_tx_processq(struct ath_softc *sc, int dosched)
765ae3815fdSAdrian Chadd {
7663ae723d4SAdrian Chadd 	struct ath_hal *ah = sc->sc_ah;
7673ae723d4SAdrian Chadd 	HAL_STATUS status;
7683ae723d4SAdrian Chadd 	struct ath_tx_status ts;
7693ae723d4SAdrian Chadd 	struct ath_txq *txq;
7704aa8818bSAdrian Chadd 	struct ath_buf *bf;
7714aa8818bSAdrian Chadd 	struct ieee80211_node *ni;
772208be709SAdrian Chadd 	int nacked = 0;
773d40c846aSAdrian Chadd 	int idx;
774*4f5ec72aSAdrian Chadd 	int i;
775d40c846aSAdrian Chadd 
776d40c846aSAdrian Chadd #ifdef	ATH_DEBUG
777d40c846aSAdrian Chadd 	/* XXX */
778d40c846aSAdrian Chadd 	uint32_t txstatus[32];
779d40c846aSAdrian Chadd #endif
780f8418db5SAdrian Chadd 
781d40c846aSAdrian Chadd 	for (idx = 0; ; idx++) {
7824aa8818bSAdrian Chadd 		bzero(&ts, sizeof(ts));
7834aa8818bSAdrian Chadd 
7843ae723d4SAdrian Chadd 		ATH_TXSTATUS_LOCK(sc);
7854c5038c7SAdrian Chadd #ifdef	ATH_DEBUG
786d40c846aSAdrian Chadd 		ath_hal_gettxrawtxdesc(ah, txstatus);
7874c5038c7SAdrian Chadd #endif
788ae3815fdSAdrian Chadd 		status = ath_hal_txprocdesc(ah, NULL, (void *) &ts);
7893ae723d4SAdrian Chadd 		ATH_TXSTATUS_UNLOCK(sc);
7903ae723d4SAdrian Chadd 
79192e84e43SAdrian Chadd 		if (status == HAL_EINPROGRESS)
79292e84e43SAdrian Chadd 			break;
79392e84e43SAdrian Chadd 
794d40c846aSAdrian Chadd #ifdef	ATH_DEBUG
795d40c846aSAdrian Chadd 		if (sc->sc_debug & ATH_DEBUG_TX_PROC)
79692e84e43SAdrian Chadd 			if (ts.ts_queue_id != sc->sc_bhalq)
797d40c846aSAdrian Chadd 			ath_printtxstatbuf(sc, NULL, txstatus, ts.ts_queue_id,
798d40c846aSAdrian Chadd 			    idx, (status == HAL_OK));
799d40c846aSAdrian Chadd #endif
800d40c846aSAdrian Chadd 
8013ae723d4SAdrian Chadd 		/*
8024aa8818bSAdrian Chadd 		 * If there is an error with this descriptor, continue
8034aa8818bSAdrian Chadd 		 * processing.
8044aa8818bSAdrian Chadd 		 *
8054aa8818bSAdrian Chadd 		 * XXX TBD: log some statistics?
8064aa8818bSAdrian Chadd 		 */
8074aa8818bSAdrian Chadd 		if (status == HAL_EIO) {
8084aa8818bSAdrian Chadd 			device_printf(sc->sc_dev, "%s: invalid TX status?\n",
8094aa8818bSAdrian Chadd 			    __func__);
810b92b5f6eSAdrian Chadd 			break;
8114aa8818bSAdrian Chadd 		}
8124aa8818bSAdrian Chadd 
81369cbcb21SAdrian Chadd #if defined(ATH_DEBUG_ALQ) && defined(ATH_DEBUG)
814b69b0dccSAdrian Chadd 		if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXSTATUS))
815b69b0dccSAdrian Chadd 			if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_TXSTATUS,
816b69b0dccSAdrian Chadd 			    sc->sc_tx_statuslen,
817b69b0dccSAdrian Chadd 			    (char *) txstatus);
818b69b0dccSAdrian Chadd #endif /* ATH_DEBUG_ALQ */
819b69b0dccSAdrian Chadd 
8204aa8818bSAdrian Chadd 		/*
8213ae723d4SAdrian Chadd 		 * At this point we have a valid status descriptor.
8223ae723d4SAdrian Chadd 		 * The QID and descriptor ID (which currently isn't set)
8233ae723d4SAdrian Chadd 		 * is part of the status.
8243ae723d4SAdrian Chadd 		 *
8253ae723d4SAdrian Chadd 		 * We then assume that the descriptor in question is the
8263ae723d4SAdrian Chadd 		 * -head- of the given QID.  Eventually we should verify
8273ae723d4SAdrian Chadd 		 * this by using the descriptor ID.
8283ae723d4SAdrian Chadd 		 */
8294aa8818bSAdrian Chadd 
8304aa8818bSAdrian Chadd 		/*
8314aa8818bSAdrian Chadd 		 * The beacon queue is not currently a "real" queue.
8324aa8818bSAdrian Chadd 		 * Frames aren't pushed onto it and the lock isn't setup.
8334aa8818bSAdrian Chadd 		 * So skip it for now; the beacon handling code will
8344aa8818bSAdrian Chadd 		 * free and alloc more beacon buffers as appropriate.
8354aa8818bSAdrian Chadd 		 */
8364aa8818bSAdrian Chadd 		if (ts.ts_queue_id == sc->sc_bhalq)
8374aa8818bSAdrian Chadd 			continue;
8383ae723d4SAdrian Chadd 
8393ae723d4SAdrian Chadd 		txq = &sc->sc_txq[ts.ts_queue_id];
8404aa8818bSAdrian Chadd 
841b837332dSAdrian Chadd 		ATH_TXQ_LOCK(txq);
84292e84e43SAdrian Chadd 		bf = ATH_TXQ_FIRST(&txq->fifo);
8434aa8818bSAdrian Chadd 
84492e84e43SAdrian Chadd 		/*
84592e84e43SAdrian Chadd 		 * Work around the situation where I'm seeing notifications
84692e84e43SAdrian Chadd 		 * for Q1 when no frames are available.  That needs to be
84792e84e43SAdrian Chadd 		 * debugged but not by crashing _here_.
84892e84e43SAdrian Chadd 		 */
84992e84e43SAdrian Chadd 		if (bf == NULL) {
85092e84e43SAdrian Chadd 			device_printf(sc->sc_dev, "%s: Q%d: empty?\n",
8514aa8818bSAdrian Chadd 			    __func__,
85292e84e43SAdrian Chadd 			    ts.ts_queue_id);
853b92b5f6eSAdrian Chadd 			ATH_TXQ_UNLOCK(txq);
85492e84e43SAdrian Chadd 			continue;
85592e84e43SAdrian Chadd 		}
85692e84e43SAdrian Chadd 
85792e84e43SAdrian Chadd 		DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d, bf=%p, start=%d, end=%d\n",
85892e84e43SAdrian Chadd 		    __func__,
85992e84e43SAdrian Chadd 		    ts.ts_queue_id, bf,
86092e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOPTR),
86192e84e43SAdrian Chadd 		    !! (bf->bf_flags & ATH_BUF_FIFOEND));
8624aa8818bSAdrian Chadd 
863d40c846aSAdrian Chadd 		/* XXX TODO: actually output debugging info about this */
864d40c846aSAdrian Chadd 
8654aa8818bSAdrian Chadd #if 0
8664aa8818bSAdrian Chadd 		/* XXX assert the buffer/descriptor matches the status descid */
8674aa8818bSAdrian Chadd 		if (ts.ts_desc_id != bf->bf_descid) {
8684aa8818bSAdrian Chadd 			device_printf(sc->sc_dev,
8694aa8818bSAdrian Chadd 			    "%s: mismatched descid (qid=%d, tsdescid=%d, "
8704aa8818bSAdrian Chadd 			    "bfdescid=%d\n",
8714aa8818bSAdrian Chadd 			    __func__,
8724aa8818bSAdrian Chadd 			    ts.ts_queue_id,
8734aa8818bSAdrian Chadd 			    ts.ts_desc_id,
8744aa8818bSAdrian Chadd 			    bf->bf_descid);
8753ae723d4SAdrian Chadd 		}
8764aa8818bSAdrian Chadd #endif
8774aa8818bSAdrian Chadd 
8784aa8818bSAdrian Chadd 		/* This removes the buffer and decrements the queue depth */
87992e84e43SAdrian Chadd 		ATH_TXQ_REMOVE(&txq->fifo, bf, bf_list);
8804aa8818bSAdrian Chadd 		if (bf->bf_state.bfs_aggr)
8814aa8818bSAdrian Chadd 			txq->axq_aggr_depth--;
88292e84e43SAdrian Chadd 
88392e84e43SAdrian Chadd 		/*
88492e84e43SAdrian Chadd 		 * If this was the end of a FIFO set, decrement FIFO depth
88592e84e43SAdrian Chadd 		 */
88692e84e43SAdrian Chadd 		if (bf->bf_flags & ATH_BUF_FIFOEND)
8874aa8818bSAdrian Chadd 			txq->axq_fifo_depth--;
88892e84e43SAdrian Chadd 
88992e84e43SAdrian Chadd 		/*
89092e84e43SAdrian Chadd 		 * If this isn't the final buffer in a FIFO set, mark
89192e84e43SAdrian Chadd 		 * the buffer as busy so it goes onto the holding queue.
89292e84e43SAdrian Chadd 		 */
89392e84e43SAdrian Chadd 		if (! (bf->bf_flags & ATH_BUF_FIFOEND))
89492e84e43SAdrian Chadd 			bf->bf_flags |= ATH_BUF_BUSY;
89592e84e43SAdrian Chadd 
89692e84e43SAdrian Chadd 		DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d: FIFO depth is now %d (%d)\n",
89792e84e43SAdrian Chadd 		    __func__,
89892e84e43SAdrian Chadd 		    txq->axq_qnum,
89992e84e43SAdrian Chadd 		    txq->axq_fifo_depth,
90092e84e43SAdrian Chadd 		    txq->fifo.axq_depth);
90192e84e43SAdrian Chadd 
9024aa8818bSAdrian Chadd 		/* XXX assert FIFO depth >= 0 */
903b837332dSAdrian Chadd 		ATH_TXQ_UNLOCK(txq);
9044aa8818bSAdrian Chadd 
9054aa8818bSAdrian Chadd 		/*
90692e84e43SAdrian Chadd 		 * Outside of the TX lock - if the buffer is end
90792e84e43SAdrian Chadd 		 * end buffer in this FIFO, we don't need a holding
90892e84e43SAdrian Chadd 		 * buffer any longer.
90992e84e43SAdrian Chadd 		 */
91092e84e43SAdrian Chadd 		if (bf->bf_flags & ATH_BUF_FIFOEND) {
911caedab2cSAdrian Chadd 			ATH_TXQ_LOCK(txq);
91292e84e43SAdrian Chadd 			ath_txq_freeholdingbuf(sc, txq);
913caedab2cSAdrian Chadd 			ATH_TXQ_UNLOCK(txq);
91492e84e43SAdrian Chadd 		}
91592e84e43SAdrian Chadd 
91692e84e43SAdrian Chadd 		/*
9174aa8818bSAdrian Chadd 		 * First we need to make sure ts_rate is valid.
9184aa8818bSAdrian Chadd 		 *
9194aa8818bSAdrian Chadd 		 * Pre-EDMA chips pass the whole TX descriptor to
9204aa8818bSAdrian Chadd 		 * the proctxdesc function which will then fill out
9214aa8818bSAdrian Chadd 		 * ts_rate based on the ts_finaltsi (final TX index)
9224aa8818bSAdrian Chadd 		 * in the TX descriptor.  However the TX completion
9234aa8818bSAdrian Chadd 		 * FIFO doesn't have this information.  So here we
9244aa8818bSAdrian Chadd 		 * do a separate HAL call to populate that information.
9253345c65bSAdrian Chadd 		 *
9263345c65bSAdrian Chadd 		 * The same problem exists with ts_longretry.
9273345c65bSAdrian Chadd 		 * The FreeBSD HAL corrects ts_longretry in the HAL layer;
9283345c65bSAdrian Chadd 		 * the AR9380 HAL currently doesn't.  So until the HAL
9293345c65bSAdrian Chadd 		 * is imported and this can be added, we correct for it
9303345c65bSAdrian Chadd 		 * here.
9314aa8818bSAdrian Chadd 		 */
9324aa8818bSAdrian Chadd 		/* XXX TODO */
9334aa8818bSAdrian Chadd 		/* XXX faked for now. Ew. */
9344aa8818bSAdrian Chadd 		if (ts.ts_finaltsi < 4) {
9354aa8818bSAdrian Chadd 			ts.ts_rate =
9364aa8818bSAdrian Chadd 			    bf->bf_state.bfs_rc[ts.ts_finaltsi].ratecode;
9373345c65bSAdrian Chadd 			switch (ts.ts_finaltsi) {
9383345c65bSAdrian Chadd 			case 3: ts.ts_longretry +=
9393345c65bSAdrian Chadd 			    bf->bf_state.bfs_rc[2].tries;
9403345c65bSAdrian Chadd 			case 2: ts.ts_longretry +=
9413345c65bSAdrian Chadd 			    bf->bf_state.bfs_rc[1].tries;
9423345c65bSAdrian Chadd 			case 1: ts.ts_longretry +=
9433345c65bSAdrian Chadd 			    bf->bf_state.bfs_rc[0].tries;
9443345c65bSAdrian Chadd 			}
9454aa8818bSAdrian Chadd 		} else {
9464aa8818bSAdrian Chadd 			device_printf(sc->sc_dev, "%s: finaltsi=%d\n",
9474aa8818bSAdrian Chadd 			    __func__,
9484aa8818bSAdrian Chadd 			    ts.ts_finaltsi);
9494aa8818bSAdrian Chadd 			ts.ts_rate = bf->bf_state.bfs_rc[0].ratecode;
9504aa8818bSAdrian Chadd 		}
9514aa8818bSAdrian Chadd 
9524aa8818bSAdrian Chadd 		/*
9534aa8818bSAdrian Chadd 		 * XXX This is terrible.
9544aa8818bSAdrian Chadd 		 *
9554aa8818bSAdrian Chadd 		 * Right now, some code uses the TX status that is
9564aa8818bSAdrian Chadd 		 * passed in here, but the completion handlers in the
9574aa8818bSAdrian Chadd 		 * software TX path also use bf_status.ds_txstat.
9584aa8818bSAdrian Chadd 		 * Ew.  That should all go away.
9594aa8818bSAdrian Chadd 		 *
9604aa8818bSAdrian Chadd 		 * XXX It's also possible the rate control completion
9614aa8818bSAdrian Chadd 		 * routine is called twice.
9624aa8818bSAdrian Chadd 		 */
9634aa8818bSAdrian Chadd 		memcpy(&bf->bf_status, &ts, sizeof(ts));
9644aa8818bSAdrian Chadd 
9654aa8818bSAdrian Chadd 		ni = bf->bf_node;
9664aa8818bSAdrian Chadd 
9674aa8818bSAdrian Chadd 		/* Update RSSI */
9684aa8818bSAdrian Chadd 		/* XXX duplicate from ath_tx_processq */
9694aa8818bSAdrian Chadd 		if (ni != NULL && ts.ts_status == 0 &&
9704aa8818bSAdrian Chadd 		    ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) {
9714aa8818bSAdrian Chadd 			nacked++;
9724aa8818bSAdrian Chadd 			sc->sc_stats.ast_tx_rssi = ts.ts_rssi;
9734aa8818bSAdrian Chadd 			ATH_RSSI_LPF(sc->sc_halstats.ns_avgtxrssi,
9744aa8818bSAdrian Chadd 			    ts.ts_rssi);
9754aa8818bSAdrian Chadd 		}
9764aa8818bSAdrian Chadd 
9774aa8818bSAdrian Chadd 		/* Handle frame completion and rate control update */
9784aa8818bSAdrian Chadd 		ath_tx_process_buf_completion(sc, txq, &ts, bf);
9794aa8818bSAdrian Chadd 
980*4f5ec72aSAdrian Chadd 		/* NB: bf is invalid at this point */
9814aa8818bSAdrian Chadd 	}
9824aa8818bSAdrian Chadd 
9834aa8818bSAdrian Chadd 	sc->sc_wd_timer = 0;
9844aa8818bSAdrian Chadd 
9854aa8818bSAdrian Chadd 	/*
9864aa8818bSAdrian Chadd 	 * XXX It's inefficient to do this if the FIFO queue is full,
9874aa8818bSAdrian Chadd 	 * but there's no easy way right now to only populate
9884aa8818bSAdrian Chadd 	 * the txq task for _one_ TXQ.  This should be fixed.
9894aa8818bSAdrian Chadd 	 */
990*4f5ec72aSAdrian Chadd 	if (dosched) {
991*4f5ec72aSAdrian Chadd 		/* Attempt to schedule more hardware frames to the TX FIFO */
992*4f5ec72aSAdrian Chadd 		for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
993*4f5ec72aSAdrian Chadd 			if (ATH_TXQ_SETUP(sc, i)) {
994*4f5ec72aSAdrian Chadd 				ATH_TXQ_LOCK(&sc->sc_txq[i]);
995*4f5ec72aSAdrian Chadd 				ath_edma_tx_fifo_fill(sc, &sc->sc_txq[i]);
996*4f5ec72aSAdrian Chadd 				ATH_TXQ_UNLOCK(&sc->sc_txq[i]);
997*4f5ec72aSAdrian Chadd 			}
998*4f5ec72aSAdrian Chadd 		}
999*4f5ec72aSAdrian Chadd 		/* Kick software scheduler */
100021bca442SAdrian Chadd 		ath_tx_swq_kick(sc);
1001f8418db5SAdrian Chadd 	}
1002*4f5ec72aSAdrian Chadd }
1003f8418db5SAdrian Chadd 
1004f8418db5SAdrian Chadd static void
1005f8418db5SAdrian Chadd ath_edma_attach_comp_func(struct ath_softc *sc)
1006f8418db5SAdrian Chadd {
1007f8418db5SAdrian Chadd 
1008f8418db5SAdrian Chadd 	TASK_INIT(&sc->sc_txtask, 0, ath_edma_tx_proc, sc);
1009f8418db5SAdrian Chadd }
1010f8418db5SAdrian Chadd 
10113fdfc330SAdrian Chadd void
10123fdfc330SAdrian Chadd ath_xmit_setup_edma(struct ath_softc *sc)
10133fdfc330SAdrian Chadd {
10143fdfc330SAdrian Chadd 
10153fdfc330SAdrian Chadd 	/* Fetch EDMA field and buffer sizes */
10163fdfc330SAdrian Chadd 	(void) ath_hal_gettxdesclen(sc->sc_ah, &sc->sc_tx_desclen);
10173fdfc330SAdrian Chadd 	(void) ath_hal_gettxstatuslen(sc->sc_ah, &sc->sc_tx_statuslen);
10183fdfc330SAdrian Chadd 	(void) ath_hal_getntxmaps(sc->sc_ah, &sc->sc_tx_nmaps);
10193fdfc330SAdrian Chadd 
1020516a0ac2SAdrian Chadd 	if (bootverbose) {
10213fdfc330SAdrian Chadd 		device_printf(sc->sc_dev, "TX descriptor length: %d\n",
10223fdfc330SAdrian Chadd 		    sc->sc_tx_desclen);
10233fdfc330SAdrian Chadd 		device_printf(sc->sc_dev, "TX status length: %d\n",
10243fdfc330SAdrian Chadd 		    sc->sc_tx_statuslen);
10253fdfc330SAdrian Chadd 		device_printf(sc->sc_dev, "TX buffers per descriptor: %d\n",
10263fdfc330SAdrian Chadd 		    sc->sc_tx_nmaps);
1027516a0ac2SAdrian Chadd 	}
10283fdfc330SAdrian Chadd 
10293fdfc330SAdrian Chadd 	sc->sc_tx.xmit_setup = ath_edma_dma_txsetup;
10303fdfc330SAdrian Chadd 	sc->sc_tx.xmit_teardown = ath_edma_dma_txteardown;
1031f8418db5SAdrian Chadd 	sc->sc_tx.xmit_attach_comp_func = ath_edma_attach_comp_func;
1032746bab5bSAdrian Chadd 
1033746bab5bSAdrian Chadd 	sc->sc_tx.xmit_dma_restart = ath_edma_dma_restart;
1034746bab5bSAdrian Chadd 	sc->sc_tx.xmit_handoff = ath_edma_xmit_handoff;
1035788e6aa9SAdrian Chadd 	sc->sc_tx.xmit_drain = ath_edma_tx_drain;
10363fdfc330SAdrian Chadd }
1037