From 3dfb6ab8c07bd8b539a15af413e79518f506c2ba Mon Sep 17 00:00:00 2001 From: pk Date: Mon, 3 Jun 1996 23:48:41 +0000 Subject: [PATCH] Code the residual computation a bit differently. --- sys/arch/sparc/dev/dma.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/sys/arch/sparc/dev/dma.c b/sys/arch/sparc/dev/dma.c index e87f0bc923ae..f5fb6f588dd5 100644 --- a/sys/arch/sparc/dev/dma.c +++ b/sys/arch/sparc/dev/dma.c @@ -1,4 +1,4 @@ -/* $NetBSD: dma.c,v 1.28 1996/05/21 19:07:30 pk Exp $ */ +/* $NetBSD: dma.c,v 1.29 1996/06/03 23:48:41 pk Exp $ */ /* * Copyright (c) 1994 Paul Kranenburg. All rights reserved. @@ -394,7 +394,7 @@ int espdmaintr(sc) struct dma_softc *sc; { - int trans = 0, resid = 0; + int trans, resid; u_long csr; csr = DMACSR(sc); @@ -434,20 +434,35 @@ espdmaintr(sc) return 0; } + resid = 0; + /* + * If a transfer onto the SCSI bus gets interrupted by the device + * (e.g. for a SAVEPOINTER message), the data in the FIFO counts + * as residual since the ESP counter registers get decremented as + * bytes are clocked into the FIFO. + */ if (!(csr & D_WRITE) && (resid = (ESP_READ_REG(sc->sc_esp, ESP_FFLAG) & ESPFIFO_FF)) != 0) { ESP_DMA(("dmaintr: empty esp FIFO of %d ", resid)); ESPCMD(sc->sc_esp, ESPCMD_FLUSH); } - resid += ESP_READ_REG(sc->sc_esp, ESP_TCL) | - (ESP_READ_REG(sc->sc_esp, ESP_TCM) << 8) | - (sc->sc_esp->sc_rev > ESP100A - ? (ESP_READ_REG(sc->sc_esp, ESP_TCH) << 16) : 0); + if ((sc->sc_esp->sc_espstat & ESPSTAT_TC) == 0) { + /* + * `Terminal count' is off, so read the residue + * out of the ESP counter registers. + */ + resid += ( ESP_READ_REG(sc->sc_esp, ESP_TCL) | + (ESP_READ_REG(sc->sc_esp, ESP_TCM) << 8) | + (sc->sc_esp->sc_rev > ESP100A + ? (ESP_READ_REG(sc->sc_esp, ESP_TCH) << 16) + : 0)); - if (resid == 0 && (sc->sc_esp->sc_rev <= ESP100A) && - (sc->sc_esp->sc_espstat & ESPSTAT_TC) == 0) - resid = 65536; + if (resid == 0 && sc->sc_dmasize == 65536 && + sc->sc_esp->sc_rev <= ESP100A) + /* A transfer of 64K is encoded as `TCL=TCM=0' */ + resid = 65536; + } trans = sc->sc_dmasize - resid; if (trans < 0) { /* transferred < 0 ? */