Home | History | Annotate | Line # | Download | only in dev
sbc.c revision 1.32.2.3
      1  1.32.2.3   thorpej /*	$NetBSD: sbc.c,v 1.32.2.3 1997/12/09 20:17:33 thorpej Exp $	*/
      2       1.1    scottr 
      3       1.1    scottr /*
      4      1.19    scottr  * Copyright (C) 1996 Scott Reynolds.  All rights reserved.
      5       1.1    scottr  *
      6       1.1    scottr  * Redistribution and use in source and binary forms, with or without
      7       1.1    scottr  * modification, are permitted provided that the following conditions
      8       1.1    scottr  * are met:
      9       1.1    scottr  * 1. Redistributions of source code must retain the above copyright
     10       1.1    scottr  *    notice, this list of conditions and the following disclaimer.
     11       1.1    scottr  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1    scottr  *    notice, this list of conditions and the following disclaimer in the
     13       1.1    scottr  *    documentation and/or other materials provided with the distribution.
     14      1.32    scottr  * 3. The name of the author may not be used to endorse or promote products
     15      1.19    scottr  *    derived from this software without specific prior written permission
     16       1.1    scottr  *
     17      1.19    scottr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18       1.1    scottr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19       1.1    scottr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20      1.19    scottr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21       1.1    scottr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22       1.1    scottr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23       1.1    scottr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24       1.1    scottr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25       1.1    scottr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26       1.1    scottr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27       1.1    scottr  */
     28       1.1    scottr 
     29       1.1    scottr /*
     30       1.1    scottr  * This file contains only the machine-dependent parts of the mac68k
     31       1.1    scottr  * NCR 5380 SCSI driver.  (Autoconfig stuff and PDMA functions.)
     32       1.1    scottr  * The machine-independent parts are in ncr5380sbc.c
     33       1.1    scottr  *
     34       1.1    scottr  * Supported hardware includes:
     35       1.1    scottr  * Macintosh II family 5380-based controller
     36       1.1    scottr  *
     37       1.1    scottr  * Credits, history:
     38       1.1    scottr  *
     39       1.1    scottr  * Scott Reynolds wrote this module, based on work by Allen Briggs
     40       1.9    scottr  * (mac68k), Gordon W. Ross and David Jones (sun3), and Leo Weppelman
     41       1.9    scottr  * (atari).  Thanks to Allen for supplying crucial interpretation of the
     42       1.9    scottr  * NetBSD/mac68k 1.1 'ncrscsi' driver.  Also, Allen, Gordon, and Jason
     43       1.9    scottr  * Thorpe all helped to refine this code, and were considerable sources
     44       1.9    scottr  * of moral support.
     45       1.1    scottr  */
     46       1.1    scottr 
     47       1.1    scottr #include <sys/types.h>
     48       1.1    scottr #include <sys/param.h>
     49       1.1    scottr #include <sys/systm.h>
     50       1.1    scottr #include <sys/kernel.h>
     51       1.1    scottr #include <sys/errno.h>
     52       1.1    scottr #include <sys/device.h>
     53       1.1    scottr #include <sys/buf.h>
     54       1.1    scottr #include <sys/proc.h>
     55       1.1    scottr #include <sys/user.h>
     56       1.1    scottr 
     57      1.30    bouyer #include <dev/scsipi/scsi_all.h>
     58      1.30    bouyer #include <dev/scsipi/scsipi_all.h>
     59      1.30    bouyer #include <dev/scsipi/scsipi_debug.h>
     60      1.30    bouyer #include <dev/scsipi/scsiconf.h>
     61       1.1    scottr 
     62       1.1    scottr #include <dev/ic/ncr5380reg.h>
     63       1.1    scottr #include <dev/ic/ncr5380var.h>
     64       1.1    scottr 
     65       1.8    scottr #include <machine/cpu.h>
     66       1.1    scottr #include <machine/viareg.h>
     67       1.1    scottr 
     68      1.29    scottr #include <mac68k/dev/sbcreg.h>
     69      1.29    scottr #include <mac68k/dev/sbcvar.h>
     70       1.1    scottr 
     71      1.22    scottr int	sbc_debug = 0 /* | SBC_DB_INTR | SBC_DB_DMA */;
     72      1.22    scottr int	sbc_link_flags = 0 /* | SDEV_DB2 */;
     73      1.24    scottr int	sbc_options = 0 /* | SBC_PDMA */;
     74       1.1    scottr 
     75       1.1    scottr static	void	sbc_minphys __P((struct buf *bp));
     76       1.1    scottr 
     77      1.30    bouyer struct scsipi_adapter	sbc_ops = {
     78       1.1    scottr 	ncr5380_scsi_cmd,		/* scsi_cmd()		*/
     79       1.1    scottr 	sbc_minphys,			/* scsi_minphys()	*/
     80       1.1    scottr 	NULL,				/* open_target_lu()	*/
     81       1.1    scottr 	NULL,				/* close_target_lu()	*/
     82       1.1    scottr };
     83       1.1    scottr 
     84       1.1    scottr /* This is copied from julian's bt driver */
     85       1.1    scottr /* "so we have a default dev struct for our link struct." */
     86      1.30    bouyer struct scsipi_device sbc_dev = {
     87       1.1    scottr 	NULL,		/* Use default error handler.	    */
     88       1.1    scottr 	NULL,		/* Use default start handler.		*/
     89       1.1    scottr 	NULL,		/* Use default async handler.	    */
     90       1.1    scottr 	NULL,		/* Use default "done" routine.	    */
     91       1.1    scottr };
     92       1.1    scottr 
     93       1.1    scottr struct cfdriver sbc_cd = {
     94       1.1    scottr 	NULL, "sbc", DV_DULL
     95       1.1    scottr };
     96       1.1    scottr 
     97      1.31    scottr extern label_t	*nofault;
     98      1.31    scottr extern caddr_t	m68k_fault_addr;
     99      1.31    scottr 
    100      1.28    scottr static	int	sbc_wait_busy __P((struct ncr5380_softc *));
    101      1.22    scottr static	int	sbc_ready __P((struct ncr5380_softc *));
    102      1.28    scottr static	int	sbc_wait_dreq __P((struct ncr5380_softc *));
    103       1.1    scottr 
    104       1.1    scottr static void
    105       1.1    scottr sbc_minphys(struct buf *bp)
    106       1.1    scottr {
    107       1.1    scottr 	if (bp->b_bcount > MAX_DMA_LEN)
    108       1.1    scottr 		bp->b_bcount = MAX_DMA_LEN;
    109       1.1    scottr 	return (minphys(bp));
    110       1.1    scottr }
    111       1.1    scottr 
    112       1.1    scottr 
    113       1.1    scottr /***
    114       1.1    scottr  * General support for Mac-specific SCSI logic.
    115       1.1    scottr  ***/
    116       1.1    scottr 
    117      1.28    scottr /* These are used in the following inline functions. */
    118      1.28    scottr int sbc_wait_busy_timo = 1000 * 5000;	/* X2 = 10 S. */
    119      1.28    scottr int sbc_ready_timo = 1000 * 5000;	/* X2 = 10 S. */
    120      1.28    scottr int sbc_wait_dreq_timo = 1000 * 5000;	/* X2 = 10 S. */
    121      1.28    scottr 
    122      1.28    scottr /* Return zero on success. */
    123      1.28    scottr static __inline__ int
    124      1.28    scottr sbc_wait_busy(sc)
    125      1.28    scottr 	struct ncr5380_softc *sc;
    126      1.28    scottr {
    127      1.28    scottr 	int timo = sbc_wait_busy_timo;
    128      1.28    scottr 	for (;;) {
    129      1.28    scottr 		if (SCI_BUSY(sc)) {
    130      1.28    scottr 			timo = 0;	/* return 0 */
    131      1.28    scottr 			break;
    132      1.28    scottr 		}
    133      1.28    scottr 		if (--timo < 0)
    134      1.28    scottr 			break;	/* return -1 */
    135      1.28    scottr 		delay(2);
    136      1.28    scottr 	}
    137      1.28    scottr 	return (timo);
    138      1.28    scottr }
    139      1.28    scottr 
    140      1.28    scottr static __inline__ int
    141      1.28    scottr sbc_ready(sc)
    142      1.28    scottr 	struct ncr5380_softc *sc;
    143      1.28    scottr {
    144      1.28    scottr 	int timo = sbc_ready_timo;
    145      1.28    scottr 
    146      1.28    scottr 	for (;;) {
    147      1.28    scottr 		if ((*sc->sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH))
    148      1.28    scottr 		    == (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    149      1.28    scottr 			timo = 0;
    150      1.28    scottr 			break;
    151      1.28    scottr 		}
    152      1.28    scottr 		if (((*sc->sci_csr & SCI_CSR_PHASE_MATCH) == 0)
    153      1.28    scottr 		    || (SCI_BUSY(sc) == 0)) {
    154      1.28    scottr 			timo = -1;
    155      1.28    scottr 			break;
    156      1.28    scottr 		}
    157      1.28    scottr 		if (--timo < 0)
    158      1.28    scottr 			break;	/* return -1 */
    159      1.28    scottr 		delay(2);
    160      1.28    scottr 	}
    161      1.28    scottr 	return (timo);
    162      1.28    scottr }
    163      1.28    scottr 
    164      1.28    scottr static __inline__ int
    165      1.28    scottr sbc_wait_dreq(sc)
    166      1.28    scottr 	struct ncr5380_softc *sc;
    167      1.28    scottr {
    168      1.28    scottr 	int timo = sbc_wait_dreq_timo;
    169      1.28    scottr 
    170      1.28    scottr 	for (;;) {
    171      1.28    scottr 		if ((*sc->sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH))
    172      1.28    scottr 		    == (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    173      1.28    scottr 			timo = 0;
    174      1.28    scottr 			break;
    175      1.28    scottr 		}
    176      1.28    scottr 		if (--timo < 0)
    177      1.28    scottr 			break;	/* return -1 */
    178      1.28    scottr 		delay(2);
    179      1.28    scottr 	}
    180      1.28    scottr 	return (timo);
    181      1.28    scottr }
    182      1.28    scottr 
    183       1.1    scottr void
    184       1.1    scottr sbc_irq_intr(p)
    185       1.1    scottr 	void *p;
    186       1.1    scottr {
    187      1.23    scottr 	struct ncr5380_softc *ncr_sc = p;
    188  1.32.2.3   thorpej 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    189      1.23    scottr 	int claimed = 0;
    190  1.32.2.3   thorpej 	extern int cold;
    191       1.1    scottr 
    192       1.1    scottr 	/* How we ever arrive here without IRQ set is a mystery... */
    193       1.1    scottr 	if (*ncr_sc->sci_csr & SCI_CSR_INT) {
    194       1.3    scottr #ifdef SBC_DEBUG
    195       1.3    scottr 		if (sbc_debug & SBC_DB_INTR)
    196       1.3    scottr 			decode_5380_intr(ncr_sc);
    197       1.3    scottr #endif
    198  1.32.2.3   thorpej 		if (!cold)
    199  1.32.2.3   thorpej 			claimed = ncr5380_intr(ncr_sc);
    200       1.1    scottr 		if (!claimed) {
    201       1.1    scottr 			if (((*ncr_sc->sci_csr & ~SCI_CSR_PHASE_MATCH) == SCI_CSR_INT)
    202  1.32.2.3   thorpej 			    && ((*ncr_sc->sci_bus_csr & ~SCI_BUS_RST) == 0)) {
    203       1.1    scottr 				SCI_CLR_INTR(ncr_sc);	/* RST interrupt */
    204  1.32.2.3   thorpej 				if (sc->sc_clrintr)
    205  1.32.2.3   thorpej 					(*sc->sc_clrintr)(ncr_sc);
    206  1.32.2.3   thorpej 			}
    207       1.1    scottr #ifdef SBC_DEBUG
    208       1.1    scottr 			else {
    209      1.13  christos 				printf("%s: spurious intr\n",
    210       1.1    scottr 				    ncr_sc->sc_dev.dv_xname);
    211       1.3    scottr 				SBC_BREAK;
    212       1.1    scottr 			}
    213       1.1    scottr #endif
    214       1.1    scottr 		}
    215       1.1    scottr 	}
    216       1.1    scottr }
    217       1.1    scottr 
    218       1.3    scottr #ifdef SBC_DEBUG
    219       1.3    scottr void
    220       1.3    scottr decode_5380_intr(ncr_sc)
    221       1.3    scottr 	struct ncr5380_softc *ncr_sc;
    222       1.3    scottr {
    223  1.32.2.3   thorpej 	u_int8_t csr = *ncr_sc->sci_csr;
    224  1.32.2.3   thorpej 	u_int8_t bus_csr = *ncr_sc->sci_bus_csr;
    225       1.3    scottr 
    226       1.3    scottr 	if (((csr & ~(SCI_CSR_PHASE_MATCH | SCI_CSR_ATN)) == SCI_CSR_INT) &&
    227       1.3    scottr 	    ((bus_csr & ~(SCI_BUS_MSG | SCI_BUS_CD | SCI_BUS_IO | SCI_BUS_DBP)) == SCI_BUS_SEL)) {
    228       1.3    scottr 		if (csr & SCI_BUS_IO)
    229      1.13  christos 			printf("%s: reselect\n", ncr_sc->sc_dev.dv_xname);
    230       1.3    scottr 		else
    231      1.13  christos 			printf("%s: select\n", ncr_sc->sc_dev.dv_xname);
    232       1.3    scottr 	} else if (((csr & ~SCI_CSR_ACK) == (SCI_CSR_DONE | SCI_CSR_INT)) &&
    233       1.3    scottr 	    ((bus_csr & (SCI_BUS_RST | SCI_BUS_BSY | SCI_BUS_SEL)) == SCI_BUS_BSY))
    234      1.13  christos 		printf("%s: dma eop\n", ncr_sc->sc_dev.dv_xname);
    235       1.3    scottr 	else if (((csr & ~SCI_CSR_PHASE_MATCH) == SCI_CSR_INT) &&
    236       1.3    scottr 	    ((bus_csr & ~SCI_BUS_RST) == 0))
    237      1.13  christos 		printf("%s: bus reset\n", ncr_sc->sc_dev.dv_xname);
    238       1.3    scottr 	else if (((csr & ~(SCI_CSR_DREQ | SCI_CSR_ATN | SCI_CSR_ACK)) == (SCI_CSR_PERR | SCI_CSR_INT | SCI_CSR_PHASE_MATCH)) &&
    239       1.3    scottr 	    ((bus_csr & (SCI_BUS_RST | SCI_BUS_BSY | SCI_BUS_SEL)) == SCI_BUS_BSY))
    240      1.13  christos 		printf("%s: parity error\n", ncr_sc->sc_dev.dv_xname);
    241       1.3    scottr 	else if (((csr & ~SCI_CSR_ATN) == SCI_CSR_INT) &&
    242       1.3    scottr 	    ((bus_csr & (SCI_BUS_RST | SCI_BUS_BSY | SCI_BUS_REQ | SCI_BUS_SEL)) == (SCI_BUS_BSY | SCI_BUS_REQ)))
    243      1.13  christos 		printf("%s: phase mismatch\n", ncr_sc->sc_dev.dv_xname);
    244       1.3    scottr 	else if (((csr & ~SCI_CSR_PHASE_MATCH) == (SCI_CSR_INT | SCI_CSR_DISC)) &&
    245       1.3    scottr 	    (bus_csr == 0))
    246      1.13  christos 		printf("%s: disconnect\n", ncr_sc->sc_dev.dv_xname);
    247       1.3    scottr 	else
    248      1.13  christos 		printf("%s: unknown intr: csr=%x, bus_csr=%x\n",
    249       1.3    scottr 		    ncr_sc->sc_dev.dv_xname, csr, bus_csr);
    250       1.3    scottr }
    251       1.3    scottr #endif
    252       1.1    scottr 
    253       1.8    scottr 
    254       1.1    scottr /***
    255       1.1    scottr  * The following code implements polled PDMA.
    256       1.1    scottr  ***/
    257       1.1    scottr 
    258      1.23    scottr int
    259  1.32.2.3   thorpej sbc_pdma_in(ncr_sc, phase, datalen, data)
    260      1.23    scottr 	struct ncr5380_softc *ncr_sc;
    261      1.28    scottr 	int phase;
    262  1.32.2.3   thorpej 	int datalen;
    263      1.23    scottr 	u_char *data;
    264      1.23    scottr {
    265      1.23    scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    266  1.32.2.3   thorpej 	volatile u_int32_t *long_data = (u_int32_t *)sc->sc_drq_addr;
    267  1.32.2.3   thorpej 	volatile u_int8_t *byte_data = (u_int8_t *)sc->sc_nodrq_addr;
    268  1.32.2.3   thorpej 	int resid, s;
    269      1.23    scottr 
    270  1.32.2.3   thorpej 	if (datalen < ncr_sc->sc_min_dma_len ||
    271  1.32.2.3   thorpej 	    (sc->sc_options & SBC_PDMA) == 0)
    272  1.32.2.3   thorpej 		return ncr5380_pio_in(ncr_sc, phase, datalen, data);
    273      1.28    scottr 
    274      1.23    scottr 	s = splbio();
    275  1.32.2.3   thorpej 	if (sbc_wait_busy(ncr_sc)) {
    276  1.32.2.3   thorpej 		splx(s);
    277  1.32.2.3   thorpej 		return 0;
    278      1.28    scottr 	}
    279      1.28    scottr 
    280  1.32.2.3   thorpej 	*ncr_sc->sci_mode |= SCI_MODE_DMA;
    281  1.32.2.3   thorpej 	*ncr_sc->sci_irecv = 0;
    282  1.32.2.3   thorpej 
    283  1.32.2.3   thorpej #define R4	*((u_int32_t *)data)++ = *long_data
    284  1.32.2.3   thorpej #define R1	*((u_int8_t *)data)++ = *byte_data
    285  1.32.2.3   thorpej 	for (resid = datalen; resid >= 128; resid -= 128) {
    286  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    287  1.32.2.3   thorpej 			goto interrupt;
    288  1.32.2.3   thorpej 		R4; R4; R4; R4; R4; R4; R4; R4;
    289  1.32.2.3   thorpej 		R4; R4; R4; R4; R4; R4; R4; R4;
    290  1.32.2.3   thorpej 		R4; R4; R4; R4; R4; R4; R4; R4;
    291  1.32.2.3   thorpej 		R4; R4; R4; R4; R4; R4; R4; R4;		/* 128 */
    292       1.1    scottr 	}
    293  1.32.2.3   thorpej 	while (resid) {
    294  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    295  1.32.2.3   thorpej 			goto interrupt;
    296  1.32.2.3   thorpej 		R1;
    297  1.32.2.3   thorpej 		resid--;
    298  1.32.2.3   thorpej 	}
    299  1.32.2.3   thorpej #undef R4
    300  1.32.2.3   thorpej #undef R1
    301       1.1    scottr 
    302  1.32.2.3   thorpej interrupt:
    303       1.1    scottr 	SCI_CLR_INTR(ncr_sc);
    304       1.1    scottr 	*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    305      1.28    scottr 	*ncr_sc->sci_icmd = 0;
    306      1.23    scottr 	splx(s);
    307  1.32.2.3   thorpej 	return (datalen - resid);
    308       1.1    scottr }
    309       1.1    scottr 
    310      1.22    scottr int
    311  1.32.2.3   thorpej sbc_pdma_out(ncr_sc, phase, datalen, data)
    312       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    313      1.28    scottr 	int phase;
    314  1.32.2.3   thorpej 	int datalen;
    315       1.1    scottr 	u_char *data;
    316       1.1    scottr {
    317       1.1    scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    318      1.24    scottr 	volatile u_int32_t *long_data = (u_int32_t *)sc->sc_drq_addr;
    319      1.24    scottr 	volatile u_int8_t *byte_data = (u_int8_t *)sc->sc_nodrq_addr;
    320  1.32.2.3   thorpej 	label_t faultbuf;
    321  1.32.2.3   thorpej 	int resid, s;
    322  1.32.2.3   thorpej 	u_int8_t icmd;
    323  1.32.2.3   thorpej 
    324  1.32.2.3   thorpej #if 1
    325  1.32.2.3   thorpej 	/* Work around lame gcc initialization bug */
    326  1.32.2.3   thorpej 	(void)&data;
    327  1.32.2.3   thorpej #endif
    328      1.23    scottr 
    329  1.32.2.3   thorpej 	if (datalen < ncr_sc->sc_min_dma_len ||
    330  1.32.2.3   thorpej 	    (sc->sc_options & SBC_PDMA) == 0)
    331  1.32.2.3   thorpej 		return ncr5380_pio_out(ncr_sc, phase, datalen, data);
    332      1.24    scottr 
    333      1.23    scottr 	s = splbio();
    334  1.32.2.3   thorpej 	if (sbc_wait_busy(ncr_sc)) {
    335  1.32.2.3   thorpej 		splx(s);
    336  1.32.2.3   thorpej 		return 0;
    337  1.32.2.3   thorpej 	}
    338  1.32.2.3   thorpej 
    339  1.32.2.3   thorpej 	icmd = *(ncr_sc->sci_icmd) & SCI_ICMD_RMASK;
    340  1.32.2.3   thorpej 	*ncr_sc->sci_icmd = icmd | SCI_ICMD_DATA;
    341  1.32.2.3   thorpej 	*ncr_sc->sci_mode |= SCI_MODE_DMA;
    342  1.32.2.3   thorpej 	*ncr_sc->sci_dma_send = 0;
    343  1.32.2.3   thorpej 
    344  1.32.2.3   thorpej 	/*
    345  1.32.2.3   thorpej 	 * Setup for a possible bus error caused by SCSI controller
    346  1.32.2.3   thorpej 	 * switching out of DATA OUT before we're done with the
    347  1.32.2.3   thorpej 	 * current transfer.  (See comment before sbc_drq_intr().)
    348  1.32.2.3   thorpej 	 */
    349  1.32.2.3   thorpej 	nofault = &faultbuf;
    350  1.32.2.3   thorpej 
    351  1.32.2.3   thorpej 	if (setjmp(nofault)) {
    352  1.32.2.3   thorpej 		printf("buf = 0x%lx, fault = 0x%lx\n",
    353  1.32.2.3   thorpej 		    (u_long)sc->sc_drq_addr, (u_long)m68k_fault_addr);
    354  1.32.2.3   thorpej 		panic("Unexpected bus error in sbc_pdma_out()");
    355      1.23    scottr 	}
    356  1.32.2.3   thorpej 
    357  1.32.2.3   thorpej #define W1	*byte_data = *((u_int8_t *)data)++
    358  1.32.2.3   thorpej #define W4	*long_data = *((u_int32_t *)data)++
    359  1.32.2.3   thorpej 	for (resid = datalen; resid >= 64; resid -= 64) {
    360  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    361  1.32.2.3   thorpej 			goto interrupt;
    362  1.32.2.3   thorpej 		W1;
    363  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    364  1.32.2.3   thorpej 			goto interrupt;
    365  1.32.2.3   thorpej 		W1;
    366  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    367  1.32.2.3   thorpej 			goto interrupt;
    368  1.32.2.3   thorpej 		W1;
    369  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    370  1.32.2.3   thorpej 			goto interrupt;
    371  1.32.2.3   thorpej 		W1;
    372  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    373  1.32.2.3   thorpej 			goto interrupt;
    374  1.32.2.3   thorpej 		W4; W4; W4; W4;
    375  1.32.2.3   thorpej 		W4; W4; W4; W4;
    376  1.32.2.3   thorpej 		W4; W4; W4; W4;
    377  1.32.2.3   thorpej 		W4; W4; W4;
    378  1.32.2.3   thorpej 	}
    379  1.32.2.3   thorpej 	while (resid) {
    380  1.32.2.3   thorpej 		if (sbc_ready(ncr_sc))
    381  1.32.2.3   thorpej 			goto interrupt;
    382  1.32.2.3   thorpej 		W1;
    383  1.32.2.3   thorpej 		resid--;
    384  1.32.2.3   thorpej 	}
    385  1.32.2.3   thorpej #undef  W1
    386  1.32.2.3   thorpej #undef  W4
    387  1.32.2.3   thorpej 	if (sbc_wait_dreq(ncr_sc))
    388  1.32.2.3   thorpej 		printf("%s: timeout waiting for DREQ.\n",
    389  1.32.2.3   thorpej 		    ncr_sc->sc_dev.dv_xname);
    390  1.32.2.3   thorpej 
    391  1.32.2.3   thorpej 	*byte_data = 0;
    392      1.28    scottr 	goto done;
    393       1.1    scottr 
    394      1.28    scottr interrupt:
    395  1.32.2.3   thorpej 	if ((*ncr_sc->sci_csr & SCI_CSR_PHASE_MATCH) == 0) {
    396  1.32.2.3   thorpej 		*ncr_sc->sci_icmd = icmd & ~SCI_ICMD_DATA;
    397  1.32.2.3   thorpej 		--resid;
    398  1.32.2.3   thorpej 	}
    399  1.32.2.1    mellon 
    400  1.32.2.1    mellon done:
    401  1.32.2.3   thorpej 	SCI_CLR_INTR(ncr_sc);
    402  1.32.2.3   thorpej 	*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    403  1.32.2.3   thorpej 	*ncr_sc->sci_icmd = icmd;
    404      1.23    scottr 	splx(s);
    405  1.32.2.3   thorpej 	return (datalen - resid);
    406       1.1    scottr }
    407       1.1    scottr 
    408       1.1    scottr 
    409       1.1    scottr /***
    410       1.1    scottr  * The following code implements interrupt-driven PDMA.
    411       1.1    scottr  ***/
    412       1.1    scottr 
    413       1.1    scottr /*
    414       1.1    scottr  * This is the meat of the PDMA transfer.
    415       1.1    scottr  * When we get here, we shove data as fast as the mac can take it.
    416       1.1    scottr  * We depend on several things:
    417       1.1    scottr  *   * All macs after the Mac Plus that have a 5380 chip should have a general
    418       1.1    scottr  *     logic IC that handshakes data for blind transfers.
    419       1.1    scottr  *   * If the SCSI controller finishes sending/receiving data before we do,
    420       1.1    scottr  *     the same general logic IC will generate a /BERR for us in short order.
    421       1.1    scottr  *   * The fault address for said /BERR minus the base address for the
    422       1.1    scottr  *     transfer will be the amount of data that was actually written.
    423       1.1    scottr  *
    424       1.1    scottr  * We use the nofault flag and the setjmp/longjmp in locore.s so we can
    425       1.1    scottr  * detect and handle the bus error for early termination of a command.
    426       1.1    scottr  * This is usually caused by a disconnecting target.
    427       1.1    scottr  */
    428       1.1    scottr void
    429       1.1    scottr sbc_drq_intr(p)
    430       1.1    scottr 	void *p;
    431       1.1    scottr {
    432      1.24    scottr 	struct sbc_softc *sc = (struct sbc_softc *)p;
    433      1.24    scottr 	struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *)p;
    434      1.23    scottr 	struct sci_req *sr = ncr_sc->sc_current;
    435      1.23    scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
    436      1.23    scottr 	label_t faultbuf;
    437      1.23    scottr 	volatile u_int32_t *long_drq;
    438      1.23    scottr 	u_int32_t *long_data;
    439      1.23    scottr 	volatile u_int8_t *drq;
    440      1.23    scottr 	u_int8_t *data;
    441      1.23    scottr 	int count, dcount, resid;
    442      1.23    scottr 	u_int8_t tmp;
    443      1.26    scottr 
    444      1.26    scottr 	/* Work around lame gcc initialization bug */
    445      1.26    scottr 	(void)&drq;
    446       1.1    scottr 
    447       1.1    scottr 	/*
    448       1.1    scottr 	 * If we're not ready to xfer data, or have no more, just return.
    449       1.1    scottr 	 */
    450       1.3    scottr 	if ((*ncr_sc->sci_csr & SCI_CSR_DREQ) == 0 || dh->dh_len == 0)
    451       1.1    scottr 		return;
    452       1.1    scottr 
    453       1.1    scottr #ifdef SBC_DEBUG
    454       1.1    scottr 	if (sbc_debug & SBC_DB_INTR)
    455      1.13  christos 		printf("%s: drq intr, dh_len=0x%x, dh_flags=0x%x\n",
    456       1.1    scottr 		    ncr_sc->sc_dev.dv_xname, dh->dh_len, dh->dh_flags);
    457       1.1    scottr #endif
    458       1.1    scottr 
    459       1.1    scottr 	/*
    460       1.1    scottr 	 * Setup for a possible bus error caused by SCSI controller
    461       1.1    scottr 	 * switching out of DATA-IN/OUT before we're done with the
    462       1.1    scottr 	 * current transfer.
    463       1.1    scottr 	 */
    464      1.31    scottr 	nofault = &faultbuf;
    465       1.1    scottr 
    466  1.32.2.1    mellon 	if (setjmp(nofault)) {
    467      1.31    scottr 		nofault = (label_t *)0;
    468       1.8    scottr 		if ((dh->dh_flags & SBC_DH_DONE) == 0) {
    469      1.27    scottr 			count = ((  (u_long)m68k_fault_addr
    470      1.24    scottr 				  - (u_long)sc->sc_drq_addr));
    471       1.8    scottr 
    472       1.8    scottr 			if ((count < 0) || (count > dh->dh_len)) {
    473      1.13  christos 				printf("%s: complete=0x%x (pending 0x%x)\n",
    474       1.8    scottr 				    ncr_sc->sc_dev.dv_xname, count, dh->dh_len);
    475       1.8    scottr 				panic("something is wrong");
    476       1.8    scottr 			}
    477       1.1    scottr 
    478       1.8    scottr 			dh->dh_addr += count;
    479       1.8    scottr 			dh->dh_len -= count;
    480      1.18    scottr 		} else
    481      1.18    scottr 			count = 0;
    482       1.8    scottr 
    483       1.1    scottr #ifdef SBC_DEBUG
    484       1.1    scottr 		if (sbc_debug & SBC_DB_INTR)
    485      1.13  christos 			printf("%s: drq /berr, complete=0x%x (pending 0x%x)\n",
    486       1.8    scottr 			   ncr_sc->sc_dev.dv_xname, count, dh->dh_len);
    487       1.1    scottr #endif
    488      1.27    scottr 		m68k_fault_addr = 0;
    489       1.3    scottr 
    490       1.1    scottr 		return;
    491       1.1    scottr 	}
    492       1.1    scottr 
    493       1.1    scottr 	if (dh->dh_flags & SBC_DH_OUT) { /* Data Out */
    494      1.26    scottr 		dcount = 0;
    495      1.26    scottr 
    496       1.1    scottr 		/*
    497       1.1    scottr 		 * Get the source address aligned.
    498       1.1    scottr 		 */
    499       1.6    scottr 		resid =
    500      1.24    scottr 		    count = min(dh->dh_len, 4 - (((int)dh->dh_addr) & 0x3));
    501       1.1    scottr 		if (count && count < 4) {
    502      1.24    scottr 			drq = (volatile u_int8_t *)sc->sc_drq_addr;
    503      1.24    scottr 			data = (u_int8_t *)dh->dh_addr;
    504       1.8    scottr 
    505       1.1    scottr #define W1		*drq++ = *data++
    506       1.1    scottr 			while (count) {
    507       1.1    scottr 				W1; count--;
    508       1.1    scottr 			}
    509       1.1    scottr #undef W1
    510       1.1    scottr 			dh->dh_addr += resid;
    511       1.1    scottr 			dh->dh_len -= resid;
    512       1.1    scottr 		}
    513       1.1    scottr 
    514       1.1    scottr 		/*
    515       1.8    scottr 		 * Start the transfer.
    516       1.1    scottr 		 */
    517       1.1    scottr 		while (dh->dh_len) {
    518       1.1    scottr 			dcount = count = min(dh->dh_len, MAX_DMA_LEN);
    519      1.24    scottr 			long_drq = (volatile u_int32_t *)sc->sc_drq_addr;
    520      1.24    scottr 			long_data = (u_int32_t *)dh->dh_addr;
    521       1.1    scottr 
    522       1.1    scottr #define W4		*long_drq++ = *long_data++
    523       1.1    scottr 			while (count >= 64) {
    524       1.1    scottr 				W4; W4; W4; W4; W4; W4; W4; W4;
    525       1.1    scottr 				W4; W4; W4; W4; W4; W4; W4; W4; /*  64 */
    526       1.1    scottr 				count -= 64;
    527       1.1    scottr 			}
    528       1.1    scottr 			while (count >= 4) {
    529       1.1    scottr 				W4; count -= 4;
    530       1.1    scottr 			}
    531       1.1    scottr #undef W4
    532      1.24    scottr 			data = (u_int8_t *)long_data;
    533      1.24    scottr 			drq = (u_int8_t *)long_drq;
    534       1.8    scottr 
    535       1.7    scottr #define W1		*drq++ = *data++
    536       1.7    scottr 			while (count) {
    537       1.7    scottr 				W1; count--;
    538       1.7    scottr 			}
    539       1.7    scottr #undef W1
    540       1.7    scottr 			dh->dh_len -= dcount;
    541       1.7    scottr 			dh->dh_addr += dcount;
    542       1.7    scottr 		}
    543       1.8    scottr 		dh->dh_flags |= SBC_DH_DONE;
    544       1.7    scottr 
    545       1.7    scottr 		/*
    546       1.8    scottr 		 * XXX -- Read a byte from the SBC to trigger a /BERR.
    547       1.8    scottr 		 * This seems to be necessary for us to notice that
    548       1.8    scottr 		 * the target has disconnected.  Ick.  06 jun 1996 (sr)
    549       1.7    scottr 		 */
    550      1.26    scottr 		if (dcount >= MAX_DMA_LEN)
    551      1.24    scottr 			drq = (volatile u_int8_t *)sc->sc_drq_addr;
    552       1.8    scottr 		tmp = *drq;
    553       1.1    scottr 	} else {	/* Data In */
    554       1.1    scottr 		/*
    555       1.1    scottr 		 * Get the dest address aligned.
    556       1.1    scottr 		 */
    557       1.6    scottr 		resid =
    558      1.24    scottr 		    count = min(dh->dh_len, 4 - (((int)dh->dh_addr) & 0x3));
    559       1.1    scottr 		if (count && count < 4) {
    560      1.24    scottr 			data = (u_int8_t *)dh->dh_addr;
    561      1.24    scottr 			drq = (volatile u_int8_t *)sc->sc_drq_addr;
    562       1.8    scottr 
    563       1.1    scottr #define R1		*data++ = *drq++
    564       1.1    scottr 			while (count) {
    565       1.1    scottr 				R1; count--;
    566       1.1    scottr 			}
    567       1.1    scottr #undef R1
    568       1.1    scottr 			dh->dh_addr += resid;
    569       1.1    scottr 			dh->dh_len -= resid;
    570       1.1    scottr 		}
    571       1.1    scottr 
    572       1.1    scottr 		/*
    573       1.8    scottr 		 * Start the transfer.
    574       1.1    scottr 		 */
    575       1.1    scottr 		while (dh->dh_len) {
    576       1.1    scottr 			dcount = count = min(dh->dh_len, MAX_DMA_LEN);
    577      1.24    scottr 			long_data = (u_int32_t *)dh->dh_addr;
    578      1.24    scottr 			long_drq = (volatile u_int32_t *)sc->sc_drq_addr;
    579       1.1    scottr 
    580       1.1    scottr #define R4		*long_data++ = *long_drq++
    581       1.8    scottr 			while (count >= 64) {
    582       1.1    scottr 				R4; R4; R4; R4; R4; R4; R4; R4;
    583       1.1    scottr 				R4; R4; R4; R4; R4; R4; R4; R4;	/* 64 */
    584       1.8    scottr 				count -= 64;
    585       1.1    scottr 			}
    586       1.1    scottr 			while (count >= 4) {
    587       1.1    scottr 				R4; count -= 4;
    588       1.1    scottr 			}
    589       1.1    scottr #undef R4
    590      1.24    scottr 			data = (u_int8_t *)long_data;
    591      1.24    scottr 			drq = (volatile u_int8_t *)long_drq;
    592       1.8    scottr 
    593       1.1    scottr #define R1		*data++ = *drq++
    594       1.1    scottr 			while (count) {
    595       1.1    scottr 				R1; count--;
    596       1.1    scottr 			}
    597       1.1    scottr #undef R1
    598       1.1    scottr 			dh->dh_len -= dcount;
    599       1.1    scottr 			dh->dh_addr += dcount;
    600       1.1    scottr 		}
    601       1.8    scottr 		dh->dh_flags |= SBC_DH_DONE;
    602       1.1    scottr 	}
    603       1.1    scottr 
    604       1.1    scottr 	/*
    605       1.1    scottr 	 * OK.  No bus error occurred above.  Clear the nofault flag
    606       1.1    scottr 	 * so we no longer short-circuit bus errors.
    607       1.1    scottr 	 */
    608      1.31    scottr 	nofault = (label_t *)0;
    609       1.7    scottr 
    610       1.7    scottr #ifdef SBC_DEBUG
    611       1.7    scottr 	if (sbc_debug & (SBC_DB_REG | SBC_DB_INTR))
    612      1.13  christos 		printf("%s: drq intr complete: csr=0x%x, bus_csr=0x%x\n",
    613       1.7    scottr 		    ncr_sc->sc_dev.dv_xname, *ncr_sc->sci_csr,
    614       1.7    scottr 		    *ncr_sc->sci_bus_csr);
    615       1.7    scottr #endif
    616       1.1    scottr }
    617       1.1    scottr 
    618       1.1    scottr void
    619       1.1    scottr sbc_dma_alloc(ncr_sc)
    620       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    621       1.1    scottr {
    622      1.24    scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    623       1.1    scottr 	struct sci_req *sr = ncr_sc->sc_current;
    624      1.30    bouyer 	struct scsipi_xfer *xs = sr->sr_xs;
    625       1.1    scottr 	struct sbc_pdma_handle *dh;
    626       1.1    scottr 	int		i, xlen;
    627       1.1    scottr 
    628       1.6    scottr #ifdef DIAGNOSTIC
    629       1.1    scottr 	if (sr->sr_dma_hand != NULL)
    630       1.1    scottr 		panic("sbc_dma_alloc: already have PDMA handle");
    631       1.1    scottr #endif
    632       1.1    scottr 
    633       1.1    scottr 	/* Polled transfers shouldn't allocate a PDMA handle. */
    634       1.1    scottr 	if (sr->sr_flags & SR_IMMED)
    635       1.1    scottr 		return;
    636       1.1    scottr 
    637       1.1    scottr 	xlen = ncr_sc->sc_datalen;
    638       1.1    scottr 
    639       1.1    scottr 	/* Make sure our caller checked sc_min_dma_len. */
    640       1.1    scottr 	if (xlen < MIN_DMA_LEN)
    641       1.1    scottr 		panic("sbc_dma_alloc: len=0x%x\n", xlen);
    642       1.1    scottr 
    643       1.1    scottr 	/*
    644       1.1    scottr 	 * Find free PDMA handle.  Guaranteed to find one since we
    645       1.1    scottr 	 * have as many PDMA handles as the driver has processes.
    646       1.1    scottr 	 * (instances?)
    647       1.1    scottr 	 */
    648       1.1    scottr 	 for (i = 0; i < SCI_OPENINGS; i++) {
    649       1.1    scottr 		if ((sc->sc_pdma[i].dh_flags & SBC_DH_BUSY) == 0)
    650       1.1    scottr 			goto found;
    651       1.1    scottr 	}
    652       1.1    scottr 	panic("sbc: no free PDMA handles");
    653       1.1    scottr found:
    654       1.1    scottr 	dh = &sc->sc_pdma[i];
    655       1.1    scottr 	dh->dh_flags = SBC_DH_BUSY;
    656       1.1    scottr 	dh->dh_addr = ncr_sc->sc_dataptr;
    657       1.1    scottr 	dh->dh_len = xlen;
    658       1.1    scottr 
    659       1.1    scottr 	/* Copy the 'write' flag for convenience. */
    660       1.1    scottr 	if (xs->flags & SCSI_DATA_OUT)
    661       1.1    scottr 		dh->dh_flags |= SBC_DH_OUT;
    662       1.1    scottr 
    663       1.1    scottr 	sr->sr_dma_hand = dh;
    664       1.1    scottr }
    665       1.1    scottr 
    666       1.1    scottr void
    667       1.1    scottr sbc_dma_free(ncr_sc)
    668       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    669       1.1    scottr {
    670       1.1    scottr 	struct sci_req *sr = ncr_sc->sc_current;
    671       1.1    scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
    672       1.1    scottr 
    673       1.6    scottr #ifdef DIAGNOSTIC
    674       1.1    scottr 	if (sr->sr_dma_hand == NULL)
    675       1.1    scottr 		panic("sbc_dma_free: no DMA handle");
    676       1.1    scottr #endif
    677       1.1    scottr 
    678       1.1    scottr 	if (ncr_sc->sc_state & NCR_DOINGDMA)
    679       1.1    scottr 		panic("sbc_dma_free: free while in progress");
    680       1.1    scottr 
    681       1.1    scottr 	if (dh->dh_flags & SBC_DH_BUSY) {
    682       1.1    scottr 		dh->dh_flags = 0;
    683       1.1    scottr 		dh->dh_addr = NULL;
    684       1.1    scottr 		dh->dh_len = 0;
    685       1.1    scottr 	}
    686       1.1    scottr 	sr->sr_dma_hand = NULL;
    687       1.1    scottr }
    688       1.1    scottr 
    689       1.1    scottr void
    690       1.1    scottr sbc_dma_poll(ncr_sc)
    691       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    692       1.1    scottr {
    693       1.1    scottr 	struct sci_req *sr = ncr_sc->sc_current;
    694       1.1    scottr 
    695       1.3    scottr 	/*
    696       1.3    scottr 	 * We shouldn't arrive here; if SR_IMMED is set, then
    697       1.3    scottr 	 * dma_alloc() should have refused to allocate a handle
    698       1.3    scottr 	 * for the transfer.  This forces the polled PDMA code
    699       1.3    scottr 	 * to handle the request...
    700       1.3    scottr 	 */
    701       1.6    scottr #ifdef SBC_DEBUG
    702       1.1    scottr 	if (sbc_debug & SBC_DB_DMA)
    703      1.13  christos 		printf("%s: lost DRQ interrupt?\n", ncr_sc->sc_dev.dv_xname);
    704       1.1    scottr #endif
    705       1.3    scottr 	sr->sr_flags |= SR_OVERDUE;
    706       1.1    scottr }
    707       1.1    scottr 
    708       1.1    scottr void
    709       1.1    scottr sbc_dma_setup(ncr_sc)
    710       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    711       1.1    scottr {
    712       1.1    scottr 	/* Not needed; we don't have real DMA */
    713       1.1    scottr }
    714       1.1    scottr 
    715       1.1    scottr void
    716       1.1    scottr sbc_dma_start(ncr_sc)
    717       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    718       1.1    scottr {
    719      1.24    scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    720       1.1    scottr 	struct sci_req *sr = ncr_sc->sc_current;
    721       1.1    scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
    722       1.1    scottr 
    723       1.1    scottr 	/*
    724       1.7    scottr 	 * Match bus phase, clear pending interrupts, set DMA mode, and
    725       1.7    scottr 	 * assert data bus (for writing only), then start the transfer.
    726       1.1    scottr 	 */
    727       1.1    scottr 	if (dh->dh_flags & SBC_DH_OUT) {
    728       1.1    scottr 		*ncr_sc->sci_tcmd = PHASE_DATA_OUT;
    729       1.1    scottr 		SCI_CLR_INTR(ncr_sc);
    730      1.22    scottr 		if (sc->sc_clrintr)
    731      1.22    scottr 			(*sc->sc_clrintr)(ncr_sc);
    732       1.1    scottr 		*ncr_sc->sci_mode |= SCI_MODE_DMA;
    733       1.1    scottr 		*ncr_sc->sci_icmd = SCI_ICMD_DATA;
    734       1.1    scottr 		*ncr_sc->sci_dma_send = 0;
    735       1.1    scottr 	} else {
    736       1.1    scottr 		*ncr_sc->sci_tcmd = PHASE_DATA_IN;
    737       1.1    scottr 		SCI_CLR_INTR(ncr_sc);
    738      1.22    scottr 		if (sc->sc_clrintr)
    739      1.22    scottr 			(*sc->sc_clrintr)(ncr_sc);
    740       1.1    scottr 		*ncr_sc->sci_mode |= SCI_MODE_DMA;
    741       1.1    scottr 		*ncr_sc->sci_icmd = 0;
    742       1.1    scottr 		*ncr_sc->sci_irecv = 0;
    743       1.1    scottr 	}
    744       1.3    scottr 	ncr_sc->sc_state |= NCR_DOINGDMA;
    745       1.1    scottr 
    746       1.6    scottr #ifdef SBC_DEBUG
    747       1.1    scottr 	if (sbc_debug & SBC_DB_DMA)
    748      1.13  christos 		printf("%s: PDMA started, va=%p, len=0x%x\n",
    749       1.1    scottr 		    ncr_sc->sc_dev.dv_xname, dh->dh_addr, dh->dh_len);
    750       1.1    scottr #endif
    751       1.1    scottr }
    752       1.1    scottr 
    753       1.1    scottr void
    754       1.1    scottr sbc_dma_eop(ncr_sc)
    755       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    756       1.1    scottr {
    757       1.1    scottr 	/* Not used; the EOP pin is wired high (GMFH, pp. 389-390) */
    758       1.1    scottr }
    759       1.1    scottr 
    760       1.1    scottr void
    761       1.1    scottr sbc_dma_stop(ncr_sc)
    762       1.1    scottr 	struct ncr5380_softc *ncr_sc;
    763       1.1    scottr {
    764      1.24    scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    765       1.1    scottr 	struct sci_req *sr = ncr_sc->sc_current;
    766       1.1    scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
    767      1.23    scottr 	int ntrans;
    768       1.1    scottr 
    769       1.1    scottr 	if ((ncr_sc->sc_state & NCR_DOINGDMA) == 0) {
    770       1.1    scottr #ifdef SBC_DEBUG
    771       1.1    scottr 		if (sbc_debug & SBC_DB_DMA)
    772      1.13  christos 			printf("%s: dma_stop: DMA not running\n",
    773       1.1    scottr 			    ncr_sc->sc_dev.dv_xname);
    774       1.1    scottr #endif
    775       1.1    scottr 		return;
    776       1.1    scottr 	}
    777       1.1    scottr 	ncr_sc->sc_state &= ~NCR_DOINGDMA;
    778       1.1    scottr 
    779       1.3    scottr 	if ((ncr_sc->sc_state & NCR_ABORTING) == 0) {
    780       1.1    scottr 		ntrans = ncr_sc->sc_datalen - dh->dh_len;
    781       1.1    scottr 
    782       1.1    scottr #ifdef SBC_DEBUG
    783       1.1    scottr 		if (sbc_debug & SBC_DB_DMA)
    784      1.13  christos 			printf("%s: dma_stop: ntrans=0x%x\n",
    785       1.1    scottr 			    ncr_sc->sc_dev.dv_xname, ntrans);
    786       1.1    scottr #endif
    787       1.1    scottr 
    788       1.1    scottr 		if (ntrans > ncr_sc->sc_datalen)
    789       1.1    scottr 			panic("sbc_dma_stop: excess transfer\n");
    790       1.1    scottr 
    791       1.1    scottr 		/* Adjust data pointer */
    792       1.1    scottr 		ncr_sc->sc_dataptr += ntrans;
    793       1.1    scottr 		ncr_sc->sc_datalen -= ntrans;
    794       1.1    scottr 
    795       1.1    scottr 		/* Clear any pending interrupts. */
    796       1.1    scottr 		SCI_CLR_INTR(ncr_sc);
    797      1.22    scottr 		if (sc->sc_clrintr)
    798      1.22    scottr 			(*sc->sc_clrintr)(ncr_sc);
    799       1.1    scottr 	}
    800       1.1    scottr 
    801       1.1    scottr 	/* Put SBIC back into PIO mode. */
    802       1.1    scottr 	*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    803       1.1    scottr 	*ncr_sc->sci_icmd = 0;
    804       1.1    scottr 
    805       1.1    scottr #ifdef SBC_DEBUG
    806       1.3    scottr 	if (sbc_debug & SBC_DB_REG)
    807      1.13  christos 		printf("%s: dma_stop: csr=0x%x, bus_csr=0x%x\n",
    808       1.1    scottr 		    ncr_sc->sc_dev.dv_xname, *ncr_sc->sci_csr,
    809       1.1    scottr 		    *ncr_sc->sci_bus_csr);
    810       1.1    scottr #endif
    811       1.1    scottr }
    812