2 * Copyright (c) 2012 Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 * Driver for the Atheros Wireless LAN controller.
36 * This software is derived from work of Atsushi Onoe; his contribution
37 * is greatly appreciated.
43 * This is needed for register operations which are performed
44 * by the driver - eg, calls to ath_hal_gettsf32().
46 * It's also required for any AH_DEBUG checks in here, eg the
47 * module dependencies.
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/sysctl.h>
56 #include <sys/malloc.h>
58 #include <sys/mutex.h>
59 #include <sys/kernel.h>
60 #include <sys/socket.h>
61 #include <sys/sockio.h>
62 #include <sys/errno.h>
63 #include <sys/callout.h>
65 #include <sys/endian.h>
66 #include <sys/kthread.h>
67 #include <sys/taskqueue.h>
69 #include <sys/module.h>
71 #include <sys/smp.h> /* for mp_ncpus */
73 #include <machine/bus.h>
76 #include <net/if_var.h>
77 #include <net/if_dl.h>
78 #include <net/if_media.h>
79 #include <net/if_types.h>
80 #include <net/if_arp.h>
81 #include <net/ethernet.h>
82 #include <net/if_llc.h>
84 #include <net80211/ieee80211_var.h>
85 #include <net80211/ieee80211_regdomain.h>
86 #ifdef IEEE80211_SUPPORT_SUPERG
87 #include <net80211/ieee80211_superg.h>
89 #ifdef IEEE80211_SUPPORT_TDMA
90 #include <net80211/ieee80211_tdma.h>
96 #include <netinet/in.h>
97 #include <netinet/if_ether.h>
100 #include <dev/ath/if_athvar.h>
101 #include <dev/ath/ath_hal/ah_devid.h> /* XXX for softled */
102 #include <dev/ath/ath_hal/ah_diagcodes.h>
104 #include <dev/ath/if_ath_debug.h>
105 #include <dev/ath/if_ath_misc.h>
106 #include <dev/ath/if_ath_tsf.h>
107 #include <dev/ath/if_ath_tx.h>
108 #include <dev/ath/if_ath_sysctl.h>
109 #include <dev/ath/if_ath_led.h>
110 #include <dev/ath/if_ath_keycache.h>
111 #include <dev/ath/if_ath_rx.h>
112 #include <dev/ath/if_ath_beacon.h>
113 #include <dev/ath/if_athdfs.h>
114 #include <dev/ath/if_ath_descdma.h>
117 #include <dev/ath/ath_tx99/ath_tx99.h>
120 #include <dev/ath/if_ath_tx_edma.h>
123 #include <dev/ath/if_ath_alq.h>
127 * some general macros
129 #define INCR(_l, _sz) (_l) ++; (_l) &= ((_sz) - 1)
130 #define DECR(_l, _sz) (_l) --; (_l) &= ((_sz) - 1)
133 * XXX doesn't belong here, and should be tunable
135 #define ATH_TXSTATUS_RING_SIZE 512
137 MALLOC_DECLARE(M_ATHDEV);
139 static void ath_edma_tx_processq(struct ath_softc *sc, int dosched);
143 ath_tx_alq_edma_push(struct ath_softc *sc, int txq, int nframes,
144 int fifo_depth, int frame_cnt)
146 struct if_ath_alq_tx_fifo_push aq;
148 aq.txq = htobe32(txq);
149 aq.nframes = htobe32(nframes);
150 aq.fifo_depth = htobe32(fifo_depth);
151 aq.frame_cnt = htobe32(frame_cnt);
153 if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TX_FIFO_PUSH,
157 #endif /* ATH_DEBUG_ALQ */
160 * XXX TODO: push an aggregate as a single FIFO slot, even though
161 * it may not meet the TXOP for say, DBA-gated traffic in TDMA mode.
163 * The TX completion code handles a TX FIFO slot having multiple frames,
164 * aggregate or otherwise, but it may just make things easier to deal
167 * XXX TODO: track the number of aggregate subframes and put that in the
171 ath_tx_edma_push_staging_list(struct ath_softc *sc, struct ath_txq *txq,
174 struct ath_buf *bf, *bf_last;
175 struct ath_buf *bfi, *bfp;
177 TAILQ_HEAD(axq_q_f_s, ath_buf) sq;
179 ATH_TXQ_LOCK_ASSERT(txq);
182 * Don't bother doing any work if it's full.
184 if (txq->axq_fifo_depth >= HAL_TXFIFO_DEPTH)
187 if (TAILQ_EMPTY(&txq->axq_q))
193 * First pass - walk sq, queue up to 'limit' entries,
194 * subtract them from the staging queue.
197 for (i = 0; i < limit; i++) {
198 /* Grab the head entry */
199 bf = ATH_TXQ_FIRST(txq);
202 ATH_TXQ_REMOVE(txq, bf, bf_list);
204 /* Queue it into our staging list */
205 TAILQ_INSERT_TAIL(&sq, bf, bf_list);
207 /* Ensure the flags are cleared */
208 bf->bf_flags &= ~(ATH_BUF_FIFOPTR | ATH_BUF_FIFOEND);
213 * Ok, so now we have a staging list of up to 'limit'
214 * frames from the txq. Now let's wrap that up
215 * into its own list and pass that to the hardware
219 bf = TAILQ_FIRST(&sq);
220 bf_last = TAILQ_LAST(&sq, axq_q_s);
223 * Ok, so here's the gymnastics reqiured to make this
228 * Tag the first/last buffer appropriately.
230 bf->bf_flags |= ATH_BUF_FIFOPTR;
231 bf_last->bf_flags |= ATH_BUF_FIFOEND;
234 * Walk the descriptor list and link them appropriately.
237 TAILQ_FOREACH(bfi, &sq, bf_list) {
239 ath_hal_settxdesclink(sc->sc_ah, bfp->bf_lastds,
246 TAILQ_FOREACH(bfi, &sq, bf_list) {
248 if (sc->sc_debug & ATH_DEBUG_XMIT_DESC)
249 ath_printtxbuf(sc, bfi, txq->axq_qnum, i, 0);
250 #endif/* ATH_DEBUG */
252 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
253 ath_tx_alq_post(sc, bfi);
254 #endif /* ATH_DEBUG_ALQ */
259 * We now need to push this set of frames onto the tail
260 * of the FIFO queue. We don't adjust the aggregate
261 * count, only the queue depth counter(s).
262 * We also need to blank the link pointer now.
265 TAILQ_CONCAT(&txq->fifo.axq_q, &sq, bf_list);
266 /* Bump total queue tracking in FIFO queue */
267 txq->fifo.axq_depth += sqdepth;
269 /* Bump FIFO queue */
270 txq->axq_fifo_depth++;
271 DPRINTF(sc, ATH_DEBUG_XMIT,
272 "%s: queued %d packets; depth=%d, fifo depth=%d\n",
273 __func__, sqdepth, txq->fifo.axq_depth, txq->axq_fifo_depth);
275 /* Push the first entry into the hardware */
276 ath_hal_puttxbuf(sc->sc_ah, txq->axq_qnum, bf->bf_daddr);
278 /* Push start on the DMA if it's not already started */
279 ath_hal_txstart(sc->sc_ah, txq->axq_qnum);
282 ath_tx_alq_edma_push(sc, txq->axq_qnum, sqdepth,
284 txq->fifo.axq_depth);
285 #endif /* ATH_DEBUG_ALQ */
288 #define TX_BATCH_SIZE 32
291 * Push some frames into the TX FIFO if we have space.
294 ath_edma_tx_fifo_fill(struct ath_softc *sc, struct ath_txq *txq)
297 ATH_TXQ_LOCK_ASSERT(txq);
299 DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d: called\n",
304 * For now, push up to 4 frames per TX FIFO slot.
305 * If more are in the hardware queue then they'll
306 * get populated when we try to send another frame
307 * or complete a frame - so at most there'll be
308 * 32 non-AMPDU frames per TXQ.
310 * Note that the hardware staging queue will limit
311 * how many frames in total we will have pushed into
314 * Later on, we'll want to push less frames into
315 * the TX FIFO since we don't want to necessarily
316 * fill tens or hundreds of milliseconds of potential
319 * However, we need more frames right now because of
320 * how the MAC implements the frame scheduling policy.
321 * It only ungates a single FIFO entry at a time,
322 * and will run that until CHNTIME expires or the
323 * end of that FIFO entry descriptor list is reached.
324 * So for TDMA we suffer a big performance penalty -
325 * single TX FIFO entries mean the MAC only sends out
326 * one frame per DBA event, which turned out on average
329 * So, for aggregates it's okay - it'll push two at a
330 * time and this will just do them more efficiently.
331 * For non-aggregates it'll do 4 at a time, up to the
332 * non-aggr limit (non_aggr, which is 32.) They should
333 * be time based rather than a hard count, but I also
338 * Do some basic, basic batching to the hardware
341 * If we have TX_BATCH_SIZE entries in the staging
342 * queue, then let's try to send them all in one hit.
344 * Ensure we don't push more than TX_BATCH_SIZE worth
345 * in, otherwise we end up draining 8 slots worth of
346 * 32 frames into the hardware queue and then we don't
347 * attempt to push more frames in until we empty the
350 if (txq->axq_depth >= TX_BATCH_SIZE / 2 &&
351 txq->fifo.axq_depth <= TX_BATCH_SIZE) {
352 ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
356 * Aggregate check: if we have less than two FIFO slots
357 * busy and we have some aggregate frames, queue it.
359 * Now, ideally we'd just check to see if the scheduler
360 * has given us aggregate frames and push them into the FIFO
361 * as individual slots, as honestly we should just be pushing
362 * a single aggregate in as one FIFO slot.
364 * Let's do that next once I know this works.
366 else if (txq->axq_aggr_depth > 0 && txq->axq_fifo_depth < 2)
367 ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
371 * If we have less, and the TXFIFO isn't empty, let's
372 * wait until we've finished sending the FIFO.
374 * If we have less, and the TXFIFO is empty, then
377 else if (txq->axq_fifo_depth == 0) {
378 ath_tx_edma_push_staging_list(sc, txq, TX_BATCH_SIZE);
383 * Re-initialise the DMA FIFO with the current contents of
386 * This should only be called as part of the chip reset path, as it
387 * assumes the FIFO is currently empty.
390 ath_edma_dma_restart(struct ath_softc *sc, struct ath_txq *txq)
397 DPRINTF(sc, ATH_DEBUG_RESET, "%s: Q%d: called\n",
401 ATH_TXQ_LOCK_ASSERT(txq);
404 * Let's log if the tracked FIFO depth doesn't match
405 * what we actually push in.
407 old_fifo_depth = txq->axq_fifo_depth;
408 txq->axq_fifo_depth = 0;
411 * Walk the FIFO staging list, looking for "head" entries.
412 * Since we may have a partially completed list of frames,
413 * we push the first frame we see into the FIFO and re-mark
414 * it as the head entry. We then skip entries until we see
415 * FIFO end, at which point we get ready to push another
416 * entry into the FIFO.
418 TAILQ_FOREACH(bf, &txq->fifo.axq_q, bf_list) {
420 * If we're looking for FIFOEND and we haven't found
423 * If we're looking for FIFOEND and we've found it,
424 * reset for another descriptor.
427 if (sc->sc_debug & ATH_DEBUG_XMIT_DESC)
428 ath_printtxbuf(sc, bf, txq->axq_qnum, i, 0);
429 #endif/* ATH_DEBUG */
431 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
432 ath_tx_alq_post(sc, bf);
433 #endif /* ATH_DEBUG_ALQ */
435 if (fifostart == 0) {
436 if (bf->bf_flags & ATH_BUF_FIFOEND)
441 /* Make sure we're not overflowing the FIFO! */
442 if (txq->axq_fifo_depth >= HAL_TXFIFO_DEPTH) {
443 device_printf(sc->sc_dev,
444 "%s: Q%d: more frames in the queue; FIFO depth=%d?!\n",
447 txq->axq_fifo_depth);
451 DPRINTF(sc, ATH_DEBUG_RESET,
452 "%s: Q%d: depth=%d: pushing bf=%p; start=%d, end=%d\n",
457 !! (bf->bf_flags & ATH_BUF_FIFOPTR),
458 !! (bf->bf_flags & ATH_BUF_FIFOEND));
462 * Set this to be the first buffer in the FIFO
463 * list - even if it's also the last buffer in
466 bf->bf_flags |= ATH_BUF_FIFOPTR;
468 /* Push it into the FIFO and bump the FIFO count */
469 ath_hal_puttxbuf(sc->sc_ah, txq->axq_qnum, bf->bf_daddr);
470 txq->axq_fifo_depth++;
473 * If this isn't the last entry either, let's
474 * clear fifostart so we continue looking for
477 if (! (bf->bf_flags & ATH_BUF_FIFOEND))
482 /* Only bother starting the queue if there's something in it */
484 ath_hal_txstart(sc->sc_ah, txq->axq_qnum);
486 DPRINTF(sc, ATH_DEBUG_RESET, "%s: Q%d: FIFO depth was %d, is %d\n",
490 txq->axq_fifo_depth);
492 /* And now, let's check! */
493 if (txq->axq_fifo_depth != old_fifo_depth) {
494 device_printf(sc->sc_dev,
495 "%s: Q%d: FIFO depth should be %d, is %d\n",
499 txq->axq_fifo_depth);
504 * Hand off this frame to a hardware queue.
506 * Things are a bit hairy in the EDMA world. The TX FIFO is only
507 * 8 entries deep, so we need to keep track of exactly what we've
508 * pushed into the FIFO and what's just sitting in the TX queue,
511 * So this is split into two halves - frames get appended to the
512 * TXQ; then a scheduler is called to push some frames into the
516 ath_edma_xmit_handoff_hw(struct ath_softc *sc, struct ath_txq *txq,
522 KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
523 ("%s: busy status 0x%x", __func__, bf->bf_flags));
526 * XXX TODO: write a hard-coded check to ensure that
527 * the queue id in the TX descriptor matches txq->axq_qnum.
530 /* Update aggr stats */
531 if (bf->bf_state.bfs_aggr)
532 txq->axq_aggr_depth++;
534 /* Push and update frame stats */
535 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
538 * Finally, call the FIFO schedule routine to schedule some
539 * frames to the FIFO.
541 ath_edma_tx_fifo_fill(sc, txq);
546 * Hand off this frame to a multicast software queue.
548 * The EDMA TX CABQ will get a list of chained frames, chained
549 * together using the next pointer. The single head of that
550 * particular queue is pushed to the hardware CABQ.
553 ath_edma_xmit_handoff_mcast(struct ath_softc *sc, struct ath_txq *txq,
557 ATH_TX_LOCK_ASSERT(sc);
558 KASSERT((bf->bf_flags & ATH_BUF_BUSY) == 0,
559 ("%s: busy status 0x%x", __func__, bf->bf_flags));
563 * XXX this is mostly duplicated in ath_tx_handoff_mcast().
565 if (ATH_TXQ_LAST(txq, axq_q_s) != NULL) {
566 struct ath_buf *bf_last = ATH_TXQ_LAST(txq, axq_q_s);
567 struct ieee80211_frame *wh;
569 /* mark previous frame */
570 wh = mtod(bf_last->bf_m, struct ieee80211_frame *);
571 wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
573 /* re-sync buffer to memory */
574 bus_dmamap_sync(sc->sc_dmat, bf_last->bf_dmamap,
575 BUS_DMASYNC_PREWRITE);
577 /* link descriptor */
578 ath_hal_settxdesclink(sc->sc_ah,
583 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXDESC))
584 ath_tx_alq_post(sc, bf);
585 #endif /* ATH_DEBUG_ALQ */
586 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
591 * Handoff this frame to the hardware.
593 * For the multicast queue, this will treat it as a software queue
594 * and append it to the list, after updating the MORE_DATA flag
595 * in the previous frame. The cabq processing code will ensure
596 * that the queue contents gets transferred over.
598 * For the hardware queues, this will queue a frame to the queue
599 * like before, then populate the FIFO from that. Since the
600 * EDMA hardware has 8 FIFO slots per TXQ, this ensures that
601 * frames such as management frames don't get prematurely dropped.
603 * This does imply that a similar flush-hwq-to-fifoq method will
604 * need to be called from the processq function, before the
605 * per-node software scheduler is called.
608 ath_edma_xmit_handoff(struct ath_softc *sc, struct ath_txq *txq,
612 DPRINTF(sc, ATH_DEBUG_XMIT_DESC,
613 "%s: called; bf=%p, txq=%p, qnum=%d\n",
619 if (txq->axq_qnum == ATH_TXQ_SWQ)
620 ath_edma_xmit_handoff_mcast(sc, txq, bf);
622 ath_edma_xmit_handoff_hw(sc, txq, bf);
626 ath_edma_setup_txfifo(struct ath_softc *sc, int qnum)
628 struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
630 te->m_fifo = malloc(sizeof(struct ath_buf *) * HAL_TXFIFO_DEPTH,
633 if (te->m_fifo == NULL) {
634 device_printf(sc->sc_dev, "%s: malloc failed\n",
640 * Set initial "empty" state.
642 te->m_fifo_head = te->m_fifo_tail = te->m_fifo_depth = 0;
648 ath_edma_free_txfifo(struct ath_softc *sc, int qnum)
650 struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
652 /* XXX TODO: actually deref the ath_buf entries? */
653 free(te->m_fifo, M_ATHDEV);
658 ath_edma_dma_txsetup(struct ath_softc *sc)
663 error = ath_descdma_alloc_desc(sc, &sc->sc_txsdma,
664 NULL, "txcomp", sc->sc_tx_statuslen, ATH_TXSTATUS_RING_SIZE);
668 ath_hal_setuptxstatusring(sc->sc_ah,
669 (void *) sc->sc_txsdma.dd_desc,
670 sc->sc_txsdma.dd_desc_paddr,
671 ATH_TXSTATUS_RING_SIZE);
673 for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
674 ath_edma_setup_txfifo(sc, i);
681 ath_edma_dma_txteardown(struct ath_softc *sc)
685 for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
686 ath_edma_free_txfifo(sc, i);
689 ath_descdma_cleanup(sc, &sc->sc_txsdma, NULL);
694 * Drain all TXQs, potentially after completing the existing completed
698 ath_edma_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
702 DPRINTF(sc, ATH_DEBUG_RESET, "%s: called\n", __func__);
704 (void) ath_stoptxdma(sc);
707 * If reset type is noloss, the TX FIFO needs to be serviced
708 * and those frames need to be handled.
710 * Otherwise, just toss everything in each TX queue.
712 if (reset_type == ATH_RESET_NOLOSS) {
713 ath_edma_tx_processq(sc, 0);
714 for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
715 if (ATH_TXQ_SETUP(sc, i)) {
716 ATH_TXQ_LOCK(&sc->sc_txq[i]);
718 * Free the holding buffer; DMA is now
721 ath_txq_freeholdingbuf(sc, &sc->sc_txq[i]);
723 * Reset the link pointer to NULL; there's
724 * no frames to chain DMA to.
726 sc->sc_txq[i].axq_link = NULL;
727 ATH_TXQ_UNLOCK(&sc->sc_txq[i]);
731 for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
732 if (ATH_TXQ_SETUP(sc, i))
733 ath_tx_draintxq(sc, &sc->sc_txq[i]);
737 /* XXX dump out the TX completion FIFO contents */
739 /* XXX dump out the frames */
745 * TX completion tasklet.
749 ath_edma_tx_proc(void *arg, int npending)
751 struct ath_softc *sc = (struct ath_softc *) arg;
754 DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: called, npending=%d\n",
757 ath_edma_tx_processq(sc, 1);
761 * Process the TX status queue.
764 ath_edma_tx_processq(struct ath_softc *sc, int dosched)
766 struct ath_hal *ah = sc->sc_ah;
768 struct ath_tx_status ts;
771 struct ieee80211_node *ni;
778 uint32_t txstatus[32];
781 for (idx = 0; ; idx++) {
782 bzero(&ts, sizeof(ts));
784 ATH_TXSTATUS_LOCK(sc);
786 ath_hal_gettxrawtxdesc(ah, txstatus);
788 status = ath_hal_txprocdesc(ah, NULL, (void *) &ts);
789 ATH_TXSTATUS_UNLOCK(sc);
791 if (status == HAL_EINPROGRESS)
795 if (sc->sc_debug & ATH_DEBUG_TX_PROC)
796 if (ts.ts_queue_id != sc->sc_bhalq)
797 ath_printtxstatbuf(sc, NULL, txstatus, ts.ts_queue_id,
798 idx, (status == HAL_OK));
802 * If there is an error with this descriptor, continue
805 * XXX TBD: log some statistics?
807 if (status == HAL_EIO) {
808 device_printf(sc->sc_dev, "%s: invalid TX status?\n",
813 #if defined(ATH_DEBUG_ALQ) && defined(ATH_DEBUG)
814 if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_EDMA_TXSTATUS))
815 if_ath_alq_post(&sc->sc_alq, ATH_ALQ_EDMA_TXSTATUS,
818 #endif /* ATH_DEBUG_ALQ */
821 * At this point we have a valid status descriptor.
822 * The QID and descriptor ID (which currently isn't set)
823 * is part of the status.
825 * We then assume that the descriptor in question is the
826 * -head- of the given QID. Eventually we should verify
827 * this by using the descriptor ID.
831 * The beacon queue is not currently a "real" queue.
832 * Frames aren't pushed onto it and the lock isn't setup.
833 * So skip it for now; the beacon handling code will
834 * free and alloc more beacon buffers as appropriate.
836 if (ts.ts_queue_id == sc->sc_bhalq)
839 txq = &sc->sc_txq[ts.ts_queue_id];
842 bf = ATH_TXQ_FIRST(&txq->fifo);
845 * Work around the situation where I'm seeing notifications
846 * for Q1 when no frames are available. That needs to be
847 * debugged but not by crashing _here_.
850 device_printf(sc->sc_dev, "%s: Q%d: empty?\n",
857 DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d, bf=%p, start=%d, end=%d\n",
860 !! (bf->bf_flags & ATH_BUF_FIFOPTR),
861 !! (bf->bf_flags & ATH_BUF_FIFOEND));
863 /* XXX TODO: actually output debugging info about this */
866 /* XXX assert the buffer/descriptor matches the status descid */
867 if (ts.ts_desc_id != bf->bf_descid) {
868 device_printf(sc->sc_dev,
869 "%s: mismatched descid (qid=%d, tsdescid=%d, "
878 /* This removes the buffer and decrements the queue depth */
879 ATH_TXQ_REMOVE(&txq->fifo, bf, bf_list);
880 if (bf->bf_state.bfs_aggr)
881 txq->axq_aggr_depth--;
884 * If this was the end of a FIFO set, decrement FIFO depth
886 if (bf->bf_flags & ATH_BUF_FIFOEND)
887 txq->axq_fifo_depth--;
890 * If this isn't the final buffer in a FIFO set, mark
891 * the buffer as busy so it goes onto the holding queue.
893 if (! (bf->bf_flags & ATH_BUF_FIFOEND))
894 bf->bf_flags |= ATH_BUF_BUSY;
896 DPRINTF(sc, ATH_DEBUG_TX_PROC, "%s: Q%d: FIFO depth is now %d (%d)\n",
900 txq->fifo.axq_depth);
902 /* XXX assert FIFO depth >= 0 */
906 * Outside of the TX lock - if the buffer is end
907 * end buffer in this FIFO, we don't need a holding
910 if (bf->bf_flags & ATH_BUF_FIFOEND) {
912 ath_txq_freeholdingbuf(sc, txq);
917 * First we need to make sure ts_rate is valid.
919 * Pre-EDMA chips pass the whole TX descriptor to
920 * the proctxdesc function which will then fill out
921 * ts_rate based on the ts_finaltsi (final TX index)
922 * in the TX descriptor. However the TX completion
923 * FIFO doesn't have this information. So here we
924 * do a separate HAL call to populate that information.
926 * The same problem exists with ts_longretry.
927 * The FreeBSD HAL corrects ts_longretry in the HAL layer;
928 * the AR9380 HAL currently doesn't. So until the HAL
929 * is imported and this can be added, we correct for it
933 /* XXX faked for now. Ew. */
934 if (ts.ts_finaltsi < 4) {
936 bf->bf_state.bfs_rc[ts.ts_finaltsi].ratecode;
937 switch (ts.ts_finaltsi) {
938 case 3: ts.ts_longretry +=
939 bf->bf_state.bfs_rc[2].tries;
940 case 2: ts.ts_longretry +=
941 bf->bf_state.bfs_rc[1].tries;
942 case 1: ts.ts_longretry +=
943 bf->bf_state.bfs_rc[0].tries;
946 device_printf(sc->sc_dev, "%s: finaltsi=%d\n",
949 ts.ts_rate = bf->bf_state.bfs_rc[0].ratecode;
953 * XXX This is terrible.
955 * Right now, some code uses the TX status that is
956 * passed in here, but the completion handlers in the
957 * software TX path also use bf_status.ds_txstat.
958 * Ew. That should all go away.
960 * XXX It's also possible the rate control completion
961 * routine is called twice.
963 memcpy(&bf->bf_status, &ts, sizeof(ts));
968 /* XXX duplicate from ath_tx_processq */
969 if (ni != NULL && ts.ts_status == 0 &&
970 ((bf->bf_state.bfs_txflags & HAL_TXDESC_NOACK) == 0)) {
972 sc->sc_stats.ast_tx_rssi = ts.ts_rssi;
973 ATH_RSSI_LPF(sc->sc_halstats.ns_avgtxrssi,
977 /* Handle frame completion and rate control update */
978 ath_tx_process_buf_completion(sc, txq, &ts, bf);
980 /* NB: bf is invalid at this point */
986 * XXX It's inefficient to do this if the FIFO queue is full,
987 * but there's no easy way right now to only populate
988 * the txq task for _one_ TXQ. This should be fixed.
991 /* Attempt to schedule more hardware frames to the TX FIFO */
992 for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
993 if (ATH_TXQ_SETUP(sc, i)) {
994 ATH_TXQ_LOCK(&sc->sc_txq[i]);
995 ath_edma_tx_fifo_fill(sc, &sc->sc_txq[i]);
996 ATH_TXQ_UNLOCK(&sc->sc_txq[i]);
999 /* Kick software scheduler */
1000 ath_tx_swq_kick(sc);
1005 ath_edma_attach_comp_func(struct ath_softc *sc)
1008 TASK_INIT(&sc->sc_txtask, 0, ath_edma_tx_proc, sc);
1012 ath_xmit_setup_edma(struct ath_softc *sc)
1015 /* Fetch EDMA field and buffer sizes */
1016 (void) ath_hal_gettxdesclen(sc->sc_ah, &sc->sc_tx_desclen);
1017 (void) ath_hal_gettxstatuslen(sc->sc_ah, &sc->sc_tx_statuslen);
1018 (void) ath_hal_getntxmaps(sc->sc_ah, &sc->sc_tx_nmaps);
1021 device_printf(sc->sc_dev, "TX descriptor length: %d\n",
1023 device_printf(sc->sc_dev, "TX status length: %d\n",
1024 sc->sc_tx_statuslen);
1025 device_printf(sc->sc_dev, "TX buffers per descriptor: %d\n",
1029 sc->sc_tx.xmit_setup = ath_edma_dma_txsetup;
1030 sc->sc_tx.xmit_teardown = ath_edma_dma_txteardown;
1031 sc->sc_tx.xmit_attach_comp_func = ath_edma_attach_comp_func;
1033 sc->sc_tx.xmit_dma_restart = ath_edma_dma_restart;
1034 sc->sc_tx.xmit_handoff = ath_edma_xmit_handoff;
1035 sc->sc_tx.xmit_drain = ath_edma_tx_drain;