Reserve one descriptor at the end of the ring as a termination point,

to prevent the producer index from getting confused.
This commit is contained in:
thorpej 2001-10-21 20:45:15 +00:00
parent 74c571e033
commit d1e191d848

View File

@ -1,4 +1,4 @@
/* $NetBSD: gem.c,v 1.8 2001/10/20 18:25:52 thorpej Exp $ */ /* $NetBSD: gem.c,v 1.9 2001/10/21 20:45:15 thorpej Exp $ */
/* /*
* *
@ -923,8 +923,7 @@ gem_start(ifp)
* until we drain the queue, or use up all available transmit * until we drain the queue, or use up all available transmit
* descriptors. * descriptors.
*/ */
while ((txs = SIMPLEQ_FIRST(&sc->sc_txfreeq)) != NULL && for (;;) {
sc->sc_txfree != 0) {
/* /*
* Grab a packet off the queue. * Grab a packet off the queue.
*/ */
@ -933,6 +932,12 @@ gem_start(ifp)
break; break;
m = NULL; m = NULL;
/* Get a work queue entry. */
if ((txs = SIMPLEQ_FIRST(&sc->sc_txfreeq)) == NULL) {
/* We've run out. */
break;
}
dmamap = txs->txs_dmamap; dmamap = txs->txs_dmamap;
/* /*
@ -971,9 +976,11 @@ gem_start(ifp)
/* /*
* Ensure we have enough descriptors free to describe * Ensure we have enough descriptors free to describe
* the packet. * the packet. Note, we always reserve one descriptor
* at the end of the ring as a termination point, to
* prevent wrap-around.
*/ */
if (dmamap->dm_nsegs > sc->sc_txfree) { if (dmamap->dm_nsegs > (sc->sc_txfree - 1)) {
/* /*
* Not enough free descriptors to transmit this * Not enough free descriptors to transmit this
* packet. We haven't committed to anything yet, * packet. We haven't committed to anything yet,