Home | History | Annotate | Line # | Download | only in dev
sbc.c revision 1.6.4.1
      1  1.6.4.1  scottr /*	$NetBSD: sbc.c,v 1.6.4.1 1996/06/11 13:45:33 scottr Exp $	*/
      2      1.1  scottr 
      3      1.1  scottr /*
      4      1.1  scottr  * Copyright (c) 1996 Scott Reynolds
      5      1.1  scottr  * Copyright (c) 1995 Allen Briggs
      6      1.1  scottr  * All rights reserved.
      7      1.1  scottr  *
      8      1.1  scottr  * Redistribution and use in source and binary forms, with or without
      9      1.1  scottr  * modification, are permitted provided that the following conditions
     10      1.1  scottr  * are met:
     11      1.1  scottr  * 1. Redistributions of source code must retain the above copyright
     12      1.1  scottr  *    notice, this list of conditions and the following disclaimer.
     13      1.1  scottr  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  scottr  *    notice, this list of conditions and the following disclaimer in the
     15      1.1  scottr  *    documentation and/or other materials provided with the distribution.
     16      1.1  scottr  * 3. The name of the authors may not be used to endorse or promote products
     17      1.1  scottr  *    derived from this software without specific prior written permission.
     18      1.1  scottr  * 4. All advertising materials mentioning features or use of this software
     19      1.1  scottr  *    must display the following acknowledgement:
     20  1.6.4.1  scottr  *      This product includes software developed by Allen Briggs and
     21  1.6.4.1  scottr  *      Scott Reynolds.
     22      1.1  scottr  *
     23      1.1  scottr  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     24      1.1  scottr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25      1.1  scottr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26      1.1  scottr  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     27      1.1  scottr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28      1.1  scottr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29      1.1  scottr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30      1.1  scottr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31      1.1  scottr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32      1.1  scottr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33      1.1  scottr  */
     34      1.1  scottr 
     35      1.1  scottr /*
     36      1.1  scottr  * This file contains only the machine-dependent parts of the mac68k
     37      1.1  scottr  * NCR 5380 SCSI driver.  (Autoconfig stuff and PDMA functions.)
     38      1.1  scottr  * The machine-independent parts are in ncr5380sbc.c
     39      1.1  scottr  *
     40      1.1  scottr  * Supported hardware includes:
     41      1.1  scottr  * Macintosh II family 5380-based controller
     42      1.1  scottr  *
     43      1.1  scottr  * Credits, history:
     44      1.1  scottr  *
     45      1.1  scottr  * Scott Reynolds wrote this module, based on work by Allen Briggs
     46      1.1  scottr  * (mac68k), David Jones (sun3), and Leo Weppelman (atari).  Allen
     47      1.1  scottr  * supplied some crucial interpretation of the NetBSD 1.1 'ncrscsi'
     48      1.1  scottr  * driver.  Allen, Gordon W. Ross, and Jason Thorpe all helped to
     49      1.1  scottr  * refine this code, and were considerable sources of moral support.
     50      1.1  scottr  *
     51      1.1  scottr  * The sbc_options code is based on similar code in Jason's modified
     52      1.1  scottr  * NetBSD/sparc 'si' driver.
     53      1.1  scottr  */
     54      1.1  scottr 
     55      1.1  scottr #include <sys/types.h>
     56      1.1  scottr #include <sys/param.h>
     57      1.1  scottr #include <sys/systm.h>
     58      1.1  scottr #include <sys/kernel.h>
     59      1.1  scottr #include <sys/errno.h>
     60      1.1  scottr #include <sys/device.h>
     61      1.1  scottr #include <sys/buf.h>
     62      1.1  scottr #include <sys/proc.h>
     63      1.1  scottr #include <sys/user.h>
     64      1.1  scottr 
     65      1.1  scottr #include <scsi/scsi_all.h>
     66      1.1  scottr #include <scsi/scsi_debug.h>
     67      1.1  scottr #include <scsi/scsiconf.h>
     68      1.1  scottr 
     69      1.1  scottr #include <dev/ic/ncr5380reg.h>
     70      1.1  scottr #include <dev/ic/ncr5380var.h>
     71      1.1  scottr 
     72  1.6.4.1  scottr #include <machine/cpu.h>
     73      1.1  scottr #include <machine/viareg.h>
     74      1.1  scottr 
     75      1.2  scottr #include "sbcreg.h"
     76      1.1  scottr 
     77      1.1  scottr /*
     78      1.1  scottr  * Transfers smaller than this are done using PIO
     79      1.1  scottr  * (on assumption they're not worth PDMA overhead)
     80      1.1  scottr  */
     81      1.1  scottr #define	MIN_DMA_LEN 128
     82      1.1  scottr 
     83      1.1  scottr /*
     84      1.1  scottr  * Transfers larger than 8192 bytes need to be split up
     85      1.1  scottr  * due to the size of the PDMA space.
     86      1.1  scottr  */
     87      1.1  scottr #define	MAX_DMA_LEN 0x2000
     88      1.1  scottr 
     89      1.1  scottr /*
     90  1.6.4.1  scottr  * From Guide to the Macintosh Family Hardware, pp. 137-143
     91      1.1  scottr  * These are offsets from SCSIBase (see pmap_bootstrap.c)
     92      1.1  scottr  */
     93  1.6.4.1  scottr #define	SBC_REG_OFS		0x10000
     94  1.6.4.1  scottr #define	SBC_HSK_OFS		0x06000
     95  1.6.4.1  scottr #define	SBC_DMA_OFS		0x12000
     96  1.6.4.1  scottr 
     97  1.6.4.1  scottr #define	SBC_DMA_OFS_PB500	0x06000
     98  1.6.4.1  scottr 
     99  1.6.4.1  scottr #define	SBC_REG_OFS_IIFX	0x08000		/* Just guessing... */
    100  1.6.4.1  scottr #define	SBC_HSK_OFS_IIFX	0x0e000
    101  1.6.4.1  scottr #define	SBC_DMA_OFS_IIFX	0x0c000
    102      1.1  scottr 
    103      1.3  scottr #ifdef SBC_DEBUG
    104      1.3  scottr # define	SBC_DB_INTR	0x01
    105      1.3  scottr # define	SBC_DB_DMA	0x02
    106      1.3  scottr # define	SBC_DB_REG	0x04
    107      1.3  scottr # define	SBC_DB_BREAK	0x08
    108      1.3  scottr 
    109      1.3  scottr 	int	sbc_debug = 0 /* | SBC_DB_INTR | SBC_DB_DMA */;
    110      1.3  scottr 	int	sbc_link_flags = 0 /* | SDEV_DB2 */;
    111      1.1  scottr 
    112      1.3  scottr # ifndef DDB
    113      1.3  scottr #  define	Debugger()	printf("Debug: sbc.c:%d\n", __LINE__)
    114      1.3  scottr # endif
    115      1.3  scottr # define	SBC_BREAK \
    116      1.3  scottr 		do { if (sbc_debug & SBC_DB_BREAK) Debugger(); } while (0)
    117      1.3  scottr #else
    118      1.3  scottr # define	SBC_BREAK
    119      1.1  scottr #endif
    120      1.1  scottr 
    121      1.1  scottr /*
    122      1.1  scottr  * This structure is used to keep track of PDMA requests.
    123      1.1  scottr  */
    124      1.1  scottr struct sbc_pdma_handle {
    125      1.1  scottr 	int	dh_flags;	/* flags */
    126      1.3  scottr #define	SBC_DH_BUSY	0x01	/* This handle is in use */
    127      1.3  scottr #define	SBC_DH_OUT	0x02	/* PDMA data out (write) */
    128  1.6.4.1  scottr #define	SBC_DH_DONE	0x04	/* PDMA transfer is complete */
    129      1.1  scottr 	u_char	*dh_addr;	/* data buffer */
    130      1.1  scottr 	int	dh_len;		/* length of data buffer */
    131      1.1  scottr };
    132      1.1  scottr 
    133      1.1  scottr /*
    134      1.1  scottr  * The first structure member has to be the ncr5380_softc
    135      1.1  scottr  * so we can just cast to go back and forth between them.
    136      1.1  scottr  */
    137      1.1  scottr struct sbc_softc {
    138      1.1  scottr 	struct ncr5380_softc ncr_sc;
    139      1.1  scottr 	volatile struct sbc_regs *sc_regs;
    140  1.6.4.1  scottr 	volatile vm_offset_t	sc_drq_addr;
    141  1.6.4.1  scottr 	volatile vm_offset_t	sc_nodrq_addr;
    142  1.6.4.1  scottr 	volatile u_int8_t	*sc_ienable;
    143  1.6.4.1  scottr 	volatile u_int8_t	*sc_iflag;
    144  1.6.4.1  scottr 	int			sc_options;	/* options for this instance. */
    145      1.1  scottr 	struct sbc_pdma_handle sc_pdma[SCI_OPENINGS];
    146      1.1  scottr };
    147      1.1  scottr 
    148      1.1  scottr /*
    149      1.1  scottr  * Options.  By default, SCSI interrupts and reselect are disabled.
    150      1.1  scottr  * You may enable either of these features with the `flags' directive
    151      1.1  scottr  * in your kernel's configuration file.
    152      1.1  scottr  *
    153      1.1  scottr  * Alternatively, you can patch your kernel with DDB or some other
    154      1.1  scottr  * mechanism.  The sc_options member of the softc is OR'd with
    155      1.1  scottr  * the value in sbc_options.
    156      1.1  scottr  */
    157      1.6  scottr #define	SBC_PDMA	0x01	/* Use PDMA for polled transfers */
    158      1.6  scottr #define	SBC_INTR	0x02	/* Allow SCSI IRQ/DRQ interrupts */
    159      1.6  scottr #define	SBC_RESELECT	0x04	/* Allow disconnect/reselect */
    160      1.6  scottr #define	SBC_OPTIONS_MASK	(SBC_RESELECT|SBC_INTR|SBC_PDMA)
    161      1.6  scottr #define	SBC_OPTIONS_BITS	"\10\3RESELECT\2INTR\1PDMA"
    162      1.6  scottr int sbc_options = SBC_PDMA;
    163      1.1  scottr 
    164      1.4  scottr static	int	sbc_match __P((struct device *, void *, void *));
    165      1.4  scottr static	void	sbc_attach __P((struct device *, struct device *, void *));
    166      1.6  scottr static	int	sbc_print __P((void *, char *));
    167      1.1  scottr static	void	sbc_minphys __P((struct buf *bp));
    168      1.1  scottr 
    169      1.1  scottr static	int	sbc_wait_busy __P((struct ncr5380_softc *));
    170      1.1  scottr static	int	sbc_ready __P((struct ncr5380_softc *));
    171      1.1  scottr static	int	sbc_wait_dreq __P((struct ncr5380_softc *));
    172      1.1  scottr static	int	sbc_pdma_in __P((struct ncr5380_softc *, int, int, u_char *));
    173      1.1  scottr static	int	sbc_pdma_out __P((struct ncr5380_softc *, int, int, u_char *));
    174      1.3  scottr #ifdef SBC_DEBUG
    175      1.3  scottr static	void	decode_5380_intr __P((struct ncr5380_softc *));
    176      1.3  scottr #endif
    177      1.1  scottr 
    178      1.1  scottr 	void	sbc_intr_enable __P((struct ncr5380_softc *));
    179      1.1  scottr 	void	sbc_intr_disable __P((struct ncr5380_softc *));
    180      1.1  scottr 	void	sbc_irq_intr __P((void *));
    181      1.1  scottr 	void	sbc_drq_intr __P((void *));
    182      1.1  scottr 	void	sbc_dma_alloc __P((struct ncr5380_softc *));
    183      1.1  scottr 	void	sbc_dma_free __P((struct ncr5380_softc *));
    184      1.1  scottr 	void	sbc_dma_poll __P((struct ncr5380_softc *));
    185      1.1  scottr 	void	sbc_dma_setup __P((struct ncr5380_softc *));
    186      1.1  scottr 	void	sbc_dma_start __P((struct ncr5380_softc *));
    187      1.1  scottr 	void	sbc_dma_eop __P((struct ncr5380_softc *));
    188      1.1  scottr 	void	sbc_dma_stop __P((struct ncr5380_softc *));
    189      1.1  scottr 
    190      1.1  scottr static struct scsi_adapter	sbc_ops = {
    191      1.1  scottr 	ncr5380_scsi_cmd,		/* scsi_cmd()		*/
    192      1.1  scottr 	sbc_minphys,			/* scsi_minphys()	*/
    193      1.1  scottr 	NULL,				/* open_target_lu()	*/
    194      1.1  scottr 	NULL,				/* close_target_lu()	*/
    195      1.1  scottr };
    196      1.1  scottr 
    197      1.1  scottr /* This is copied from julian's bt driver */
    198      1.1  scottr /* "so we have a default dev struct for our link struct." */
    199      1.1  scottr static struct scsi_device sbc_dev = {
    200      1.1  scottr 	NULL,		/* Use default error handler.	    */
    201      1.1  scottr 	NULL,		/* Use default start handler.		*/
    202      1.1  scottr 	NULL,		/* Use default async handler.	    */
    203      1.1  scottr 	NULL,		/* Use default "done" routine.	    */
    204      1.1  scottr };
    205      1.1  scottr 
    206      1.1  scottr struct cfattach sbc_ca = {
    207      1.1  scottr 	sizeof(struct sbc_softc), sbc_match, sbc_attach
    208      1.1  scottr };
    209      1.1  scottr 
    210      1.1  scottr struct cfdriver sbc_cd = {
    211      1.1  scottr 	NULL, "sbc", DV_DULL
    212      1.1  scottr };
    213      1.1  scottr 
    214      1.1  scottr 
    215      1.1  scottr static int
    216      1.1  scottr sbc_match(parent, match, args)
    217      1.6  scottr 	struct device *parent;
    218      1.6  scottr 	void *match, *args;
    219      1.1  scottr {
    220      1.1  scottr 	if (!mac68k_machine.scsi80)
    221      1.1  scottr 		return 0;
    222      1.1  scottr 	return 1;
    223      1.1  scottr }
    224      1.1  scottr 
    225      1.1  scottr static void
    226      1.1  scottr sbc_attach(parent, self, args)
    227      1.6  scottr 	struct device *parent, *self;
    228      1.6  scottr 	void *args;
    229      1.1  scottr {
    230      1.1  scottr 	struct sbc_softc *sc = (struct sbc_softc *) self;
    231      1.1  scottr 	struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *) sc;
    232      1.1  scottr 	extern vm_offset_t SCSIBase;
    233      1.1  scottr 
    234      1.1  scottr 	/* Pull in the options flags. */
    235      1.6  scottr 	sc->sc_options = ((ncr_sc->sc_dev.dv_cfdata->cf_flags | sbc_options)
    236      1.6  scottr 	    & SBC_OPTIONS_MASK);
    237      1.1  scottr 
    238      1.1  scottr 	/*
    239  1.6.4.1  scottr 	 * Set up offsets to 5380 registers and GLUE I/O space, and turn
    240  1.6.4.1  scottr 	 * off options we know we can't support on certain models.
    241      1.1  scottr 	 */
    242  1.6.4.1  scottr 	switch (current_mac_model->machineid) {
    243  1.6.4.1  scottr 	case MACH_MACIIFX:	/* Note: the IIfx isn't (yet) supported. */
    244  1.6.4.1  scottr 		sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS_IIFX);
    245  1.6.4.1  scottr 		sc->sc_drq_addr = (vm_offset_t)(SCSIBase + SBC_HSK_OFS_IIFX);
    246  1.6.4.1  scottr 		sc->sc_nodrq_addr = (vm_offset_t)(SCSIBase + SBC_DMA_OFS_IIFX);
    247  1.6.4.1  scottr 		sc->sc_options &= ~(SBC_INTR | SBC_RESELECT);
    248  1.6.4.1  scottr 		break;
    249  1.6.4.1  scottr 	case MACH_MACPB500:
    250  1.6.4.1  scottr 		sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS);
    251  1.6.4.1  scottr 		sc->sc_drq_addr = (vm_offset_t)(SCSIBase + SBC_HSK_OFS); /*??*/
    252  1.6.4.1  scottr 		sc->sc_nodrq_addr = (vm_offset_t)(SCSIBase + SBC_DMA_OFS_PB500);
    253  1.6.4.1  scottr 		sc->sc_options &= ~(SBC_INTR | SBC_RESELECT);
    254  1.6.4.1  scottr 		break;
    255  1.6.4.1  scottr 	default:
    256  1.6.4.1  scottr 		sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS);
    257  1.6.4.1  scottr 		sc->sc_drq_addr = (vm_offset_t)(SCSIBase + SBC_HSK_OFS);
    258  1.6.4.1  scottr 		sc->sc_nodrq_addr = (vm_offset_t)(SCSIBase + SBC_DMA_OFS);
    259  1.6.4.1  scottr 		break;
    260  1.6.4.1  scottr 	}
    261      1.1  scottr 
    262      1.1  scottr 	/*
    263      1.1  scottr 	 * Fill in the prototype scsi_link.
    264      1.1  scottr 	 */
    265      1.1  scottr 	ncr_sc->sc_link.adapter_softc = sc;
    266      1.1  scottr 	ncr_sc->sc_link.adapter_target = 7;
    267      1.1  scottr 	ncr_sc->sc_link.adapter = &sbc_ops;
    268      1.1  scottr 	ncr_sc->sc_link.device = &sbc_dev;
    269      1.1  scottr 
    270      1.1  scottr 	/*
    271      1.1  scottr 	 * Initialize fields used by the MI code
    272      1.1  scottr 	 */
    273      1.1  scottr 	ncr_sc->sci_r0 = &sc->sc_regs->sci_pr0.sci_reg;
    274      1.1  scottr 	ncr_sc->sci_r1 = &sc->sc_regs->sci_pr1.sci_reg;
    275      1.1  scottr 	ncr_sc->sci_r2 = &sc->sc_regs->sci_pr2.sci_reg;
    276      1.1  scottr 	ncr_sc->sci_r3 = &sc->sc_regs->sci_pr3.sci_reg;
    277      1.1  scottr 	ncr_sc->sci_r4 = &sc->sc_regs->sci_pr4.sci_reg;
    278      1.1  scottr 	ncr_sc->sci_r5 = &sc->sc_regs->sci_pr5.sci_reg;
    279      1.1  scottr 	ncr_sc->sci_r6 = &sc->sc_regs->sci_pr6.sci_reg;
    280      1.1  scottr 	ncr_sc->sci_r7 = &sc->sc_regs->sci_pr7.sci_reg;
    281      1.1  scottr 
    282      1.1  scottr 	/*
    283      1.1  scottr 	 * MD function pointers used by the MI code.
    284      1.1  scottr 	 */
    285  1.6.4.1  scottr 	if (sc->sc_options & SBC_PDMA) {
    286  1.6.4.1  scottr 		ncr_sc->sc_pio_out   = sbc_pdma_out;
    287  1.6.4.1  scottr 		ncr_sc->sc_pio_in    = sbc_pdma_in;
    288  1.6.4.1  scottr 	} else {
    289  1.6.4.1  scottr 		ncr_sc->sc_pio_out   = ncr5380_pio_out;
    290  1.6.4.1  scottr 		ncr_sc->sc_pio_in    = ncr5380_pio_in;
    291  1.6.4.1  scottr 	}
    292      1.1  scottr 	ncr_sc->sc_dma_alloc = NULL;
    293      1.1  scottr 	ncr_sc->sc_dma_free  = NULL;
    294      1.1  scottr 	ncr_sc->sc_dma_poll  = NULL;
    295      1.1  scottr 	ncr_sc->sc_intr_on   = NULL;
    296      1.1  scottr 	ncr_sc->sc_intr_off  = NULL;
    297      1.1  scottr 	ncr_sc->sc_dma_setup = NULL;
    298      1.1  scottr 	ncr_sc->sc_dma_start = NULL;
    299      1.1  scottr 	ncr_sc->sc_dma_eop   = NULL;
    300      1.1  scottr 	ncr_sc->sc_dma_stop  = NULL;
    301      1.1  scottr 	ncr_sc->sc_flags = 0;
    302      1.1  scottr 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    303      1.1  scottr 
    304  1.6.4.1  scottr 	if (sc->sc_options & SBC_INTR) {
    305      1.1  scottr 		if (sc->sc_options & SBC_RESELECT)
    306      1.1  scottr 			ncr_sc->sc_flags |= NCR5380_PERMIT_RESELECT;
    307      1.1  scottr 		ncr_sc->sc_dma_alloc = sbc_dma_alloc;
    308      1.1  scottr 		ncr_sc->sc_dma_free  = sbc_dma_free;
    309      1.1  scottr 		ncr_sc->sc_dma_poll  = sbc_dma_poll;
    310      1.1  scottr 		ncr_sc->sc_dma_setup = sbc_dma_setup;
    311      1.1  scottr 		ncr_sc->sc_dma_start = sbc_dma_start;
    312      1.1  scottr 		ncr_sc->sc_dma_eop   = sbc_dma_eop;
    313      1.1  scottr 		ncr_sc->sc_dma_stop  = sbc_dma_stop;
    314      1.1  scottr 		mac68k_register_scsi_drq(sbc_drq_intr, ncr_sc);
    315      1.1  scottr 		mac68k_register_scsi_irq(sbc_irq_intr, ncr_sc);
    316  1.6.4.1  scottr 	} else
    317  1.6.4.1  scottr 		ncr_sc->sc_flags |= NCR5380_FORCE_POLLING;
    318      1.1  scottr 
    319      1.1  scottr 	/*
    320      1.1  scottr 	 * Initialize fields used only here in the MD code.
    321      1.1  scottr 	 */
    322      1.1  scottr 	if (VIA2 == VIA2OFF) {
    323      1.1  scottr 		sc->sc_ienable = Via1Base + VIA2 * 0x2000 + vIER;
    324      1.1  scottr 		sc->sc_iflag   = Via1Base + VIA2 * 0x2000 + vIFR;
    325      1.1  scottr 	} else {
    326      1.1  scottr 		sc->sc_ienable = Via1Base + VIA2 * 0x2000 + rIER;
    327      1.1  scottr 		sc->sc_iflag   = Via1Base + VIA2 * 0x2000 + rIFR;
    328      1.1  scottr 	}
    329      1.1  scottr 
    330      1.1  scottr 	if (sc->sc_options)
    331      1.1  scottr 		printf(": options=%b", sc->sc_options, SBC_OPTIONS_BITS);
    332      1.1  scottr 	printf("\n");
    333      1.1  scottr 
    334      1.1  scottr 	/* Now enable SCSI interrupts through VIA2, if appropriate */
    335      1.1  scottr 	if (sc->sc_options & SBC_INTR)
    336      1.1  scottr 		sbc_intr_enable(ncr_sc);
    337      1.1  scottr 
    338      1.6  scottr #ifdef SBC_DEBUG
    339      1.1  scottr 	if (sbc_debug)
    340      1.4  scottr 		printf("%s: softc=%p regs=%p\n", ncr_sc->sc_dev.dv_xname,
    341      1.1  scottr 		    sc, sc->sc_regs);
    342      1.1  scottr 	ncr_sc->sc_link.flags |= sbc_link_flags;
    343      1.1  scottr #endif
    344      1.1  scottr 
    345      1.1  scottr 	/*
    346      1.1  scottr 	 *  Initialize the SCSI controller itself.
    347      1.1  scottr 	 */
    348      1.1  scottr 	ncr5380_init(ncr_sc);
    349      1.1  scottr 	ncr5380_reset_scsibus(ncr_sc);
    350      1.1  scottr 	config_found(self, &(ncr_sc->sc_link), sbc_print);
    351      1.1  scottr }
    352      1.1  scottr 
    353      1.6  scottr static int
    354      1.6  scottr sbc_print(aux, name)
    355      1.6  scottr 	void *aux;
    356      1.6  scottr 	char *name;
    357      1.6  scottr {
    358      1.6  scottr 	if (name != NULL)
    359      1.6  scottr 		printf("%s: scsibus ", name);
    360      1.6  scottr 	return UNCONF;
    361      1.6  scottr }
    362      1.1  scottr 
    363      1.1  scottr static void
    364      1.1  scottr sbc_minphys(struct buf *bp)
    365      1.1  scottr {
    366      1.1  scottr 	if (bp->b_bcount > MAX_DMA_LEN)
    367      1.1  scottr 		bp->b_bcount = MAX_DMA_LEN;
    368      1.1  scottr 	return (minphys(bp));
    369      1.1  scottr }
    370      1.1  scottr 
    371      1.1  scottr 
    372      1.1  scottr /***
    373      1.1  scottr  * General support for Mac-specific SCSI logic.
    374      1.1  scottr  ***/
    375      1.1  scottr 
    376      1.1  scottr /* These are used in the following inline functions. */
    377      1.1  scottr int sbc_wait_busy_timo = 1000 * 5000;	/* X2 = 10 S. */
    378      1.1  scottr int sbc_ready_timo = 1000 * 5000;	/* X2 = 10 S. */
    379      1.1  scottr int sbc_wait_dreq_timo = 1000 * 5000;	/* X2 = 10 S. */
    380      1.1  scottr 
    381      1.1  scottr /* Return zero on success. */
    382      1.1  scottr static __inline__ int
    383      1.1  scottr sbc_wait_busy(sc)
    384      1.1  scottr 	struct ncr5380_softc *sc;
    385      1.1  scottr {
    386      1.1  scottr 	register int timo = sbc_wait_busy_timo;
    387      1.1  scottr 	for (;;) {
    388      1.1  scottr 		if (SCI_BUSY(sc)) {
    389      1.1  scottr 			timo = 0;	/* return 0 */
    390      1.1  scottr 			break;
    391      1.1  scottr 		}
    392      1.1  scottr 		if (--timo < 0)
    393      1.1  scottr 			break;	/* return -1 */
    394      1.1  scottr 		delay(2);
    395      1.1  scottr 	}
    396      1.1  scottr 	return (timo);
    397      1.1  scottr }
    398      1.1  scottr 
    399      1.1  scottr static __inline__ int
    400      1.1  scottr sbc_ready(sc)
    401      1.1  scottr 	struct ncr5380_softc *sc;
    402      1.1  scottr {
    403      1.1  scottr 	register int timo = sbc_ready_timo;
    404      1.1  scottr 
    405      1.1  scottr 	for (;;) {
    406      1.1  scottr 		if ((*sc->sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH))
    407      1.1  scottr 		    == (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    408      1.1  scottr 			timo = 0;
    409      1.1  scottr 			break;
    410      1.1  scottr 		}
    411      1.1  scottr 		if (((*sc->sci_csr & SCI_CSR_PHASE_MATCH) == 0)
    412      1.1  scottr 		    || (SCI_BUSY(sc) == 0)) {
    413      1.1  scottr 			timo = -1;
    414      1.1  scottr 			break;
    415      1.1  scottr 		}
    416      1.1  scottr 		if (--timo < 0)
    417      1.1  scottr 			break;	/* return -1 */
    418      1.1  scottr 		delay(2);
    419      1.1  scottr 	}
    420      1.1  scottr 	return (timo);
    421      1.1  scottr }
    422      1.1  scottr 
    423      1.1  scottr static __inline__ int
    424      1.1  scottr sbc_wait_dreq(sc)
    425      1.1  scottr 	struct ncr5380_softc *sc;
    426      1.1  scottr {
    427      1.1  scottr 	register int timo = sbc_wait_dreq_timo;
    428      1.1  scottr 
    429      1.1  scottr 	for (;;) {
    430      1.1  scottr 		if ((*sc->sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH))
    431      1.1  scottr 		    == (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
    432      1.1  scottr 			timo = 0;
    433      1.1  scottr 			break;
    434      1.1  scottr 		}
    435      1.1  scottr 		if (--timo < 0)
    436      1.1  scottr 			break;	/* return -1 */
    437      1.1  scottr 		delay(2);
    438      1.1  scottr 	}
    439      1.1  scottr 	return (timo);
    440      1.1  scottr }
    441      1.1  scottr 
    442      1.1  scottr 
    443      1.1  scottr /***
    444      1.1  scottr  * Macintosh SCSI interrupt support routines.
    445      1.1  scottr  ***/
    446      1.1  scottr 
    447      1.1  scottr void
    448      1.1  scottr sbc_intr_enable(ncr_sc)
    449      1.1  scottr 	struct ncr5380_softc *ncr_sc;
    450      1.1  scottr {
    451      1.1  scottr 	register struct sbc_softc *sc = (struct sbc_softc *) ncr_sc;
    452      1.1  scottr 	int s;
    453      1.1  scottr 
    454      1.1  scottr 	s = splhigh();
    455      1.1  scottr 	*sc->sc_ienable = 0x80 | (V2IF_SCSIIRQ | V2IF_SCSIDRQ);
    456      1.1  scottr 	splx(s);
    457      1.1  scottr }
    458      1.1  scottr 
    459      1.1  scottr void
    460      1.1  scottr sbc_intr_disable(ncr_sc)
    461      1.1  scottr 	struct ncr5380_softc *ncr_sc;
    462      1.1  scottr {
    463      1.1  scottr 	register struct sbc_softc *sc = (struct sbc_softc *) ncr_sc;
    464      1.1  scottr 	int s;
    465      1.1  scottr 
    466      1.1  scottr 	s = splhigh();
    467      1.1  scottr 	*sc->sc_ienable = (V2IF_SCSIIRQ | V2IF_SCSIDRQ);
    468      1.1  scottr 	splx(s);
    469      1.1  scottr }
    470      1.1  scottr 
    471      1.1  scottr void
    472      1.1  scottr sbc_irq_intr(p)
    473      1.1  scottr 	void *p;
    474      1.1  scottr {
    475      1.1  scottr 	register struct ncr5380_softc *ncr_sc = p;
    476      1.1  scottr 	register int claimed = 0;
    477      1.1  scottr 
    478      1.1  scottr 	/* How we ever arrive here without IRQ set is a mystery... */
    479      1.1  scottr 	if (*ncr_sc->sci_csr & SCI_CSR_INT) {
    480      1.3  scottr #ifdef SBC_DEBUG
    481      1.3  scottr 		if (sbc_debug & SBC_DB_INTR)
    482      1.3  scottr 			decode_5380_intr(ncr_sc);
    483      1.3  scottr #endif
    484      1.1  scottr 		claimed = ncr5380_intr(ncr_sc);
    485      1.1  scottr 		if (!claimed) {
    486      1.1  scottr 			if (((*ncr_sc->sci_csr & ~SCI_CSR_PHASE_MATCH) == SCI_CSR_INT)
    487      1.3  scottr 			    && ((*ncr_sc->sci_bus_csr & ~SCI_BUS_RST) == 0))
    488      1.1  scottr 				SCI_CLR_INTR(ncr_sc);	/* RST interrupt */
    489      1.1  scottr #ifdef SBC_DEBUG
    490      1.1  scottr 			else {
    491      1.1  scottr 				printf("%s: spurious intr\n",
    492      1.1  scottr 				    ncr_sc->sc_dev.dv_xname);
    493      1.3  scottr 				SBC_BREAK;
    494      1.1  scottr 			}
    495      1.1  scottr #endif
    496      1.1  scottr 		}
    497      1.1  scottr 	}
    498      1.1  scottr }
    499      1.1  scottr 
    500      1.3  scottr #ifdef SBC_DEBUG
    501      1.3  scottr void
    502      1.3  scottr decode_5380_intr(ncr_sc)
    503      1.3  scottr 	struct ncr5380_softc *ncr_sc;
    504      1.3  scottr {
    505      1.3  scottr 	register u_char csr = *ncr_sc->sci_csr;
    506      1.3  scottr 	register u_char bus_csr = *ncr_sc->sci_bus_csr;
    507      1.3  scottr 
    508      1.3  scottr 	if (((csr & ~(SCI_CSR_PHASE_MATCH | SCI_CSR_ATN)) == SCI_CSR_INT) &&
    509      1.3  scottr 	    ((bus_csr & ~(SCI_BUS_MSG | SCI_BUS_CD | SCI_BUS_IO | SCI_BUS_DBP)) == SCI_BUS_SEL)) {
    510      1.3  scottr 		if (csr & SCI_BUS_IO)
    511      1.3  scottr 			printf("%s: reselect\n", ncr_sc->sc_dev.dv_xname);
    512      1.3  scottr 		else
    513      1.3  scottr 			printf("%s: select\n", ncr_sc->sc_dev.dv_xname);
    514      1.3  scottr 	} else if (((csr & ~SCI_CSR_ACK) == (SCI_CSR_DONE | SCI_CSR_INT)) &&
    515      1.3  scottr 	    ((bus_csr & (SCI_BUS_RST | SCI_BUS_BSY | SCI_BUS_SEL)) == SCI_BUS_BSY))
    516      1.3  scottr 		printf("%s: dma eop\n", ncr_sc->sc_dev.dv_xname);
    517      1.3  scottr 	else if (((csr & ~SCI_CSR_PHASE_MATCH) == SCI_CSR_INT) &&
    518      1.3  scottr 	    ((bus_csr & ~SCI_BUS_RST) == 0))
    519      1.3  scottr 		printf("%s: bus reset\n", ncr_sc->sc_dev.dv_xname);
    520      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)) &&
    521      1.3  scottr 	    ((bus_csr & (SCI_BUS_RST | SCI_BUS_BSY | SCI_BUS_SEL)) == SCI_BUS_BSY))
    522      1.3  scottr 		printf("%s: parity error\n", ncr_sc->sc_dev.dv_xname);
    523      1.3  scottr 	else if (((csr & ~SCI_CSR_ATN) == SCI_CSR_INT) &&
    524      1.3  scottr 	    ((bus_csr & (SCI_BUS_RST | SCI_BUS_BSY | SCI_BUS_REQ | SCI_BUS_SEL)) == (SCI_BUS_BSY | SCI_BUS_REQ)))
    525      1.3  scottr 		printf("%s: phase mismatch\n", ncr_sc->sc_dev.dv_xname);
    526      1.3  scottr 	else if (((csr & ~SCI_CSR_PHASE_MATCH) == (SCI_CSR_INT | SCI_CSR_DISC)) &&
    527      1.3  scottr 	    (bus_csr == 0))
    528      1.3  scottr 		printf("%s: disconnect\n", ncr_sc->sc_dev.dv_xname);
    529      1.3  scottr 	else
    530      1.3  scottr 		printf("%s: unknown intr: csr=%x, bus_csr=%x\n",
    531      1.3  scottr 		    ncr_sc->sc_dev.dv_xname, csr, bus_csr);
    532      1.3  scottr }
    533      1.3  scottr #endif
    534      1.1  scottr 
    535  1.6.4.1  scottr 
    536      1.1  scottr /***
    537      1.1  scottr  * The following code implements polled PDMA.
    538      1.1  scottr  ***/
    539      1.1  scottr 
    540      1.1  scottr static	int
    541      1.1  scottr sbc_pdma_out(ncr_sc, phase, count, data)
    542      1.1  scottr 	struct ncr5380_softc *ncr_sc;
    543      1.1  scottr 	int phase;
    544      1.1  scottr 	int count;
    545      1.1  scottr 	u_char *data;
    546      1.1  scottr {
    547      1.1  scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    548  1.6.4.1  scottr 	register volatile long *long_data = (long *) sc->sc_drq_addr;
    549  1.6.4.1  scottr 	register volatile u_char *byte_data = (u_char *) sc->sc_nodrq_addr;
    550      1.1  scottr 	register int len = count;
    551      1.1  scottr 
    552      1.6  scottr 	if (count < ncr_sc->sc_min_dma_len || (sc->sc_options & SBC_PDMA) == 0)
    553      1.1  scottr 		return ncr5380_pio_out(ncr_sc, phase, count, data);
    554      1.1  scottr 
    555      1.1  scottr 	if (sbc_wait_busy(ncr_sc) == 0) {
    556      1.1  scottr 		*ncr_sc->sci_mode |= SCI_MODE_DMA;
    557      1.1  scottr 		*ncr_sc->sci_icmd |= SCI_ICMD_DATA;
    558      1.1  scottr 		*ncr_sc->sci_dma_send = 0;
    559      1.1  scottr 
    560      1.1  scottr #define W1	*byte_data = *data++
    561      1.1  scottr #define W4	*long_data = *((long*)data)++
    562      1.1  scottr 		while (len >= 64) {
    563      1.1  scottr 			if (sbc_ready(ncr_sc))
    564      1.1  scottr 				goto timeout;
    565      1.1  scottr 			W1;
    566      1.1  scottr 			if (sbc_ready(ncr_sc))
    567      1.1  scottr 				goto timeout;
    568      1.1  scottr 			W1;
    569      1.1  scottr 			if (sbc_ready(ncr_sc))
    570      1.1  scottr 				goto timeout;
    571      1.1  scottr 			W1;
    572      1.1  scottr 			if (sbc_ready(ncr_sc))
    573      1.1  scottr 				goto timeout;
    574      1.1  scottr 			W1;
    575      1.1  scottr 			if (sbc_ready(ncr_sc))
    576      1.1  scottr 				goto timeout;
    577      1.1  scottr 			W4; W4; W4; W4;
    578      1.1  scottr 			W4; W4; W4; W4;
    579      1.1  scottr 			W4; W4; W4; W4;
    580      1.1  scottr 			W4; W4; W4;
    581      1.1  scottr 			len -= 64;
    582      1.1  scottr 		}
    583      1.1  scottr 		while (len) {
    584      1.1  scottr 			if (sbc_ready(ncr_sc))
    585      1.1  scottr 				goto timeout;
    586      1.1  scottr 			W1;
    587      1.1  scottr 			len--;
    588      1.1  scottr 		}
    589      1.1  scottr #undef  W1
    590      1.1  scottr #undef  W4
    591      1.1  scottr 		if (sbc_wait_dreq(ncr_sc))
    592      1.1  scottr 			printf("%s: timeout waiting for DREQ.\n",
    593      1.1  scottr 			    ncr_sc->sc_dev.dv_xname);
    594      1.1  scottr 
    595      1.1  scottr 		*byte_data = 0;
    596      1.1  scottr 
    597      1.1  scottr 		SCI_CLR_INTR(ncr_sc);
    598      1.1  scottr 		*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    599      1.1  scottr 		*ncr_sc->sci_icmd = 0;
    600      1.1  scottr 	}
    601      1.1  scottr 	return count - len;
    602      1.1  scottr 
    603      1.1  scottr timeout:
    604      1.1  scottr 	printf("%s: pdma_out: timeout len=%d count=%d\n",
    605      1.1  scottr 	    ncr_sc->sc_dev.dv_xname, len, count);
    606      1.1  scottr 	if ((*ncr_sc->sci_csr & SCI_CSR_PHASE_MATCH) == 0) {
    607      1.1  scottr 		*ncr_sc->sci_icmd &= ~SCI_ICMD_DATA;
    608      1.1  scottr 		--len;
    609      1.1  scottr 	}
    610      1.1  scottr 
    611      1.1  scottr 	SCI_CLR_INTR(ncr_sc);
    612      1.1  scottr 	*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    613      1.1  scottr 	*ncr_sc->sci_icmd = 0;
    614      1.1  scottr 	return count - len;
    615      1.1  scottr }
    616      1.1  scottr 
    617      1.1  scottr static	int
    618      1.1  scottr sbc_pdma_in(ncr_sc, phase, count, data)
    619      1.1  scottr 	struct ncr5380_softc *ncr_sc;
    620      1.1  scottr 	int phase;
    621      1.1  scottr 	int count;
    622      1.1  scottr 	u_char *data;
    623      1.1  scottr {
    624      1.1  scottr 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    625  1.6.4.1  scottr 	register volatile long *long_data = (long *) sc->sc_drq_addr;
    626  1.6.4.1  scottr 	register volatile u_char *byte_data = (u_char *) sc->sc_nodrq_addr;
    627      1.1  scottr 	register int len = count;
    628      1.1  scottr 
    629      1.6  scottr 	if (count < ncr_sc->sc_min_dma_len || (sc->sc_options & SBC_PDMA) == 0)
    630      1.1  scottr 		return ncr5380_pio_in(ncr_sc, phase, count, data);
    631      1.1  scottr 
    632      1.1  scottr 	if (sbc_wait_busy(ncr_sc) == 0) {
    633      1.1  scottr 		*ncr_sc->sci_mode |= SCI_MODE_DMA;
    634      1.1  scottr 		*ncr_sc->sci_icmd |= SCI_ICMD_DATA;
    635      1.1  scottr 		*ncr_sc->sci_irecv = 0;
    636      1.1  scottr 
    637      1.1  scottr #define R4	*((long *)data)++ = *long_data
    638      1.1  scottr #define R1	*data++ = *byte_data
    639      1.1  scottr 		while (len >= 1024) {
    640      1.1  scottr 			if (sbc_ready(ncr_sc))
    641      1.1  scottr 				goto timeout;
    642      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    643      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    644      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    645      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 128 */
    646      1.1  scottr 			if (sbc_ready(ncr_sc))
    647      1.1  scottr 				goto timeout;
    648      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    649      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    650      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    651      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 256 */
    652      1.1  scottr 			if (sbc_ready(ncr_sc))
    653      1.1  scottr 				goto timeout;
    654      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    655      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    656      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    657      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 384 */
    658      1.1  scottr 			if (sbc_ready(ncr_sc))
    659      1.1  scottr 				goto timeout;
    660      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    661      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    662      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    663      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 512 */
    664      1.1  scottr 			if (sbc_ready(ncr_sc))
    665      1.1  scottr 				goto timeout;
    666      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    667      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    668      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    669      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 640 */
    670      1.1  scottr 			if (sbc_ready(ncr_sc))
    671      1.1  scottr 				goto timeout;
    672      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    673      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    674      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    675      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 768 */
    676      1.1  scottr 			if (sbc_ready(ncr_sc))
    677      1.1  scottr 				goto timeout;
    678      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    679      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    680      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    681      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 896 */
    682      1.1  scottr 			if (sbc_ready(ncr_sc))
    683      1.1  scottr 				goto timeout;
    684      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    685      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    686      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    687      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 1024 */
    688      1.1  scottr 			len -= 1024;
    689      1.1  scottr 		}
    690      1.1  scottr 		while (len >= 128) {
    691      1.1  scottr 			if (sbc_ready(ncr_sc))
    692      1.1  scottr 				goto timeout;
    693      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    694      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    695      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;
    696      1.1  scottr 			R4; R4; R4; R4; R4; R4; R4; R4;		/* 128 */
    697      1.1  scottr 			len -= 128;
    698      1.1  scottr 		}
    699      1.1  scottr 		while (len) {
    700      1.1  scottr 			if (sbc_ready(ncr_sc))
    701      1.1  scottr 				goto timeout;
    702      1.1  scottr 			R1;
    703      1.1  scottr 			len--;
    704      1.1  scottr 		}
    705      1.1  scottr #undef R4
    706      1.1  scottr #undef R1
    707      1.1  scottr 		SCI_CLR_INTR(ncr_sc);
    708      1.1  scottr 		*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    709      1.1  scottr 		*ncr_sc->sci_icmd = 0;
    710      1.1  scottr 	}
    711      1.1  scottr 	return count - len;
    712      1.1  scottr 
    713      1.1  scottr timeout:
    714      1.1  scottr 	printf("%s: pdma_in: timeout len=%d count=%d\n",
    715      1.1  scottr 	    ncr_sc->sc_dev.dv_xname, len, count);
    716      1.1  scottr 
    717      1.1  scottr 	SCI_CLR_INTR(ncr_sc);
    718      1.1  scottr 	*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
    719      1.1  scottr 	*ncr_sc->sci_icmd = 0;
    720      1.1  scottr 	return count - len;
    721      1.1  scottr }
    722      1.1  scottr 
    723      1.1  scottr 
    724      1.1  scottr /***
    725      1.1  scottr  * The following code implements interrupt-driven PDMA.
    726      1.1  scottr  ***/
    727      1.1  scottr 
    728      1.1  scottr /*
    729      1.1  scottr  * This is the meat of the PDMA transfer.
    730      1.1  scottr  * When we get here, we shove data as fast as the mac can take it.
    731      1.1  scottr  * We depend on several things:
    732      1.1  scottr  *   * All macs after the Mac Plus that have a 5380 chip should have a general
    733      1.1  scottr  *     logic IC that handshakes data for blind transfers.
    734      1.1  scottr  *   * If the SCSI controller finishes sending/receiving data before we do,
    735      1.1  scottr  *     the same general logic IC will generate a /BERR for us in short order.
    736      1.1  scottr  *   * The fault address for said /BERR minus the base address for the
    737      1.1  scottr  *     transfer will be the amount of data that was actually written.
    738      1.1  scottr  *
    739      1.1  scottr  * We use the nofault flag and the setjmp/longjmp in locore.s so we can
    740      1.1  scottr  * detect and handle the bus error for early termination of a command.
    741      1.1  scottr  * This is usually caused by a disconnecting target.
    742      1.1  scottr  */
    743      1.1  scottr void
    744      1.1  scottr sbc_drq_intr(p)
    745      1.1  scottr 	void *p;
    746      1.1  scottr {
    747      1.1  scottr 	extern	int		*nofault, mac68k_buserr_addr;
    748      1.1  scottr 	register struct sbc_softc *sc = (struct sbc_softc *) p;
    749      1.1  scottr 	register struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *) p;
    750      1.1  scottr 	register struct sci_req *sr = ncr_sc->sc_current;
    751      1.1  scottr 	register struct sbc_pdma_handle *dh = sr->sr_dma_hand;
    752      1.1  scottr 	label_t			faultbuf;
    753      1.1  scottr 	volatile u_int32_t	*long_drq;
    754      1.1  scottr 	u_int32_t		*long_data;
    755      1.1  scottr 	volatile u_int8_t	*drq;
    756      1.1  scottr 	u_int8_t		*data;
    757      1.1  scottr 	register int		count;
    758      1.1  scottr 	int			dcount, resid;
    759  1.6.4.1  scottr 	u_int8_t		tmp;
    760      1.1  scottr 
    761      1.1  scottr 	/*
    762      1.1  scottr 	 * If we're not ready to xfer data, or have no more, just return.
    763      1.1  scottr 	 */
    764      1.3  scottr 	if ((*ncr_sc->sci_csr & SCI_CSR_DREQ) == 0 || dh->dh_len == 0)
    765      1.1  scottr 		return;
    766      1.1  scottr 
    767      1.1  scottr #ifdef SBC_DEBUG
    768      1.1  scottr 	if (sbc_debug & SBC_DB_INTR)
    769      1.1  scottr 		printf("%s: drq intr, dh_len=0x%x, dh_flags=0x%x\n",
    770      1.1  scottr 		    ncr_sc->sc_dev.dv_xname, dh->dh_len, dh->dh_flags);
    771      1.1  scottr #endif
    772      1.1  scottr 
    773      1.1  scottr 	/*
    774      1.1  scottr 	 * Setup for a possible bus error caused by SCSI controller
    775      1.1  scottr 	 * switching out of DATA-IN/OUT before we're done with the
    776      1.1  scottr 	 * current transfer.
    777      1.1  scottr 	 */
    778      1.1  scottr 	nofault = (int *) &faultbuf;
    779      1.1  scottr 
    780      1.1  scottr 	if (setjmp((label_t *) nofault)) {
    781      1.1  scottr 		nofault = (int *) 0;
    782  1.6.4.1  scottr 		if ((dh->dh_flags & SBC_DH_DONE) == 0) {
    783  1.6.4.1  scottr 			count = ((  (u_long) mac68k_buserr_addr
    784  1.6.4.1  scottr 				  - (u_long) sc->sc_drq_addr));
    785  1.6.4.1  scottr 
    786  1.6.4.1  scottr 			if ((count < 0) || (count > dh->dh_len)) {
    787  1.6.4.1  scottr 				printf("%s: complete=0x%x (pending 0x%x)\n",
    788  1.6.4.1  scottr 				    ncr_sc->sc_dev.dv_xname, count, dh->dh_len);
    789  1.6.4.1  scottr 				panic("something is wrong");
    790  1.6.4.1  scottr 			}
    791      1.1  scottr 
    792  1.6.4.1  scottr 			dh->dh_addr += count;
    793  1.6.4.1  scottr 			dh->dh_len -= count;
    794      1.1  scottr 		}
    795  1.6.4.1  scottr 
    796      1.1  scottr #ifdef SBC_DEBUG
    797      1.1  scottr 		if (sbc_debug & SBC_DB_INTR)
    798  1.6.4.1  scottr 			printf("%s: drq /berr, complete=0x%x (pending 0x%x)\n",
    799  1.6.4.1  scottr 			   ncr_sc->sc_dev.dv_xname, count, dh->dh_len);
    800      1.1  scottr #endif
    801      1.1  scottr 		mac68k_buserr_addr = 0;
    802      1.3  scottr 
    803      1.1  scottr 		return;
    804      1.1  scottr 	}
    805      1.1  scottr 
    806      1.1  scottr 	if (dh->dh_flags & SBC_DH_OUT) { /* Data Out */
    807  1.6.4.1  scottr #if notyet /* XXX */
    808      1.1  scottr 		/*
    809      1.1  scottr 		 * Get the source address aligned.
    810      1.1  scottr 		 */
    811      1.6  scottr 		resid =
    812      1.6  scottr 		    count = min(dh->dh_len, 4 - (((int) dh->dh_addr) & 0x3));
    813      1.1  scottr 		if (count && count < 4) {
    814  1.6.4.1  scottr 			drq = (volatile u_int8_t *) sc->sc_drq_addr;
    815      1.1  scottr 			data = (u_int8_t *) dh->dh_addr;
    816  1.6.4.1  scottr 
    817      1.1  scottr #define W1		*drq++ = *data++
    818      1.1  scottr 			while (count) {
    819      1.1  scottr 				W1; count--;
    820      1.1  scottr 			}
    821      1.1  scottr #undef W1
    822      1.1  scottr 			dh->dh_addr += resid;
    823      1.1  scottr 			dh->dh_len -= resid;
    824      1.1  scottr 		}
    825      1.1  scottr 
    826      1.1  scottr 		/*
    827  1.6.4.1  scottr 		 * Start the transfer.
    828      1.1  scottr 		 */
    829      1.1  scottr 		while (dh->dh_len) {
    830      1.1  scottr 			dcount = count = min(dh->dh_len, MAX_DMA_LEN);
    831      1.1  scottr 			long_drq = (volatile u_int32_t *) sc->sc_drq_addr;
    832      1.1  scottr 			long_data = (u_int32_t *) dh->dh_addr;
    833      1.1  scottr 
    834      1.1  scottr #define W4		*long_drq++ = *long_data++
    835      1.1  scottr 			while (count >= 64) {
    836      1.1  scottr 				W4; W4; W4; W4; W4; W4; W4; W4;
    837      1.1  scottr 				W4; W4; W4; W4; W4; W4; W4; W4; /*  64 */
    838      1.1  scottr 				count -= 64;
    839      1.1  scottr 			}
    840      1.1  scottr 			while (count >= 4) {
    841      1.1  scottr 				W4; count -= 4;
    842      1.1  scottr 			}
    843      1.1  scottr #undef W4
    844      1.1  scottr 			data = (u_int8_t *) long_data;
    845      1.1  scottr 			drq = (u_int8_t *) long_drq;
    846  1.6.4.1  scottr #else /* notyet */
    847  1.6.4.1  scottr 		/*
    848  1.6.4.1  scottr 		 * Start the transfer.
    849  1.6.4.1  scottr 		 */
    850  1.6.4.1  scottr 		while (dh->dh_len) {
    851  1.6.4.1  scottr 			dcount = count = min(dh->dh_len, MAX_DMA_LEN);
    852  1.6.4.1  scottr 			drq = (volatile u_int8_t *) sc->sc_drq_addr;
    853  1.6.4.1  scottr 			data = (u_int8_t *) dh->dh_addr;
    854  1.6.4.1  scottr #endif /* notyet */
    855  1.6.4.1  scottr 
    856      1.1  scottr #define W1		*drq++ = *data++
    857      1.1  scottr 			while (count) {
    858      1.1  scottr 				W1; count--;
    859      1.1  scottr 			}
    860      1.1  scottr #undef W1
    861      1.1  scottr 			dh->dh_len -= dcount;
    862      1.1  scottr 			dh->dh_addr += dcount;
    863      1.1  scottr 		}
    864  1.6.4.1  scottr 		dh->dh_flags |= SBC_DH_DONE;
    865  1.6.4.1  scottr 
    866  1.6.4.1  scottr 		/*
    867  1.6.4.1  scottr 		 * XXX -- Read a byte from the SBC to trigger a /BERR.
    868  1.6.4.1  scottr 		 * This seems to be necessary for us to notice that
    869  1.6.4.1  scottr 		 * the target has disconnected.  Ick.  06 jun 1996 (sr)
    870  1.6.4.1  scottr 		 */
    871  1.6.4.1  scottr 		if (dcount >= MAX_DMA_LEN) {
    872  1.6.4.1  scottr #if 0
    873  1.6.4.1  scottr 			while ((*ncr_sc->sci_csr & SCI_CSR_ACK) == 0)
    874  1.6.4.1  scottr 				;
    875  1.6.4.1  scottr #endif
    876  1.6.4.1  scottr 			drq = (volatile u_int8_t *) sc->sc_drq_addr;
    877  1.6.4.1  scottr 		}
    878  1.6.4.1  scottr 		tmp = *drq;
    879      1.1  scottr 	} else {	/* Data In */
    880      1.1  scottr 		/*
    881      1.1  scottr 		 * Get the dest address aligned.
    882      1.1  scottr 		 */
    883      1.6  scottr 		resid =
    884      1.6  scottr 		    count = min(dh->dh_len, 4 - (((int) dh->dh_addr) & 0x3));
    885      1.1  scottr 		if (count && count < 4) {
    886      1.1  scottr 			data = (u_int8_t *) dh->dh_addr;
    887  1.6.4.1  scottr 			drq = (volatile u_int8_t *) sc->sc_drq_addr;
    888  1.6.4.1  scottr 
    889      1.1  scottr #define R1		*data++ = *drq++
    890      1.1  scottr 			while (count) {
    891      1.1  scottr 				R1; count--;
    892      1.1  scottr 			}
    893      1.1  scottr #undef R1
    894      1.1  scottr 			dh->dh_addr += resid;
    895      1.1  scottr 			dh->dh_len -= resid;
    896      1.1  scottr 		}
    897      1.1  scottr 
    898      1.1  scottr 		/*
    899  1.6.4.1  scottr 		 * Start the transfer.
    900      1.1  scottr 		 */
    901      1.1  scottr 		while (dh->dh_len) {
    902      1.1  scottr 			dcount = count = min(dh->dh_len, MAX_DMA_LEN);
    903      1.1  scottr 			long_data = (u_int32_t *) dh->dh_addr;
    904  1.6.4.1  scottr 			long_drq = (volatile u_int32_t *) sc->sc_drq_addr;
    905      1.1  scottr 
    906      1.1  scottr #define R4		*long_data++ = *long_drq++
    907  1.6.4.1  scottr 			while (count >= 64) {
    908      1.1  scottr 				R4; R4; R4; R4; R4; R4; R4; R4;
    909      1.1  scottr 				R4; R4; R4; R4; R4; R4; R4; R4;	/* 64 */
    910  1.6.4.1  scottr 				count -= 64;
    911      1.1  scottr 			}
    912      1.1  scottr 			while (count >= 4) {
    913      1.1  scottr 				R4; count -= 4;
    914      1.1  scottr 			}
    915      1.1  scottr #undef R4
    916      1.1  scottr 			data = (u_int8_t *) long_data;
    917  1.6.4.1  scottr 			drq = (volatile u_int8_t *) long_drq;
    918  1.6.4.1  scottr 
    919      1.1  scottr #define R1		*data++ = *drq++
    920      1.1  scottr 			while (count) {
    921      1.1  scottr 				R1; count--;
    922      1.1  scottr 			}
    923      1.1  scottr #undef R1
    924      1.1  scottr 			dh->dh_len -= dcount;
    925      1.1  scottr 			dh->dh_addr += dcount;
    926      1.1  scottr 		}
    927  1.6.4.1  scottr 		dh->dh_flags |= SBC_DH_DONE;
    928      1.1  scottr 	}
    929      1.1  scottr 
    930      1.1  scottr 	/*
    931      1.1  scottr 	 * OK.  No bus error occurred above.  Clear the nofault flag
    932      1.1  scottr 	 * so we no longer short-circuit bus errors.
    933      1.1  scottr 	 */
    934      1.1  scottr 	nofault = (int *) 0;
    935  1.6.4.1  scottr 
    936  1.6.4.1  scottr #ifdef SBC_DEBUG
    937  1.6.4.1  scottr 	if (sbc_debug & (SBC_DB_REG | SBC_DB_INTR))
    938  1.6.4.1  scottr 		printf("%s: drq intr complete: csr=0x%x, bus_csr=0x%x\n",
    939  1.6.4.1  scottr 		    ncr_sc->sc_dev.dv_xname, *ncr_sc->sci_csr,
    940  1.6.4.1  scottr 		    *ncr_sc->sci_bus_csr);
    941  1.6.4.1  scottr #endif
    942      1.1  scottr }
    943      1.1  scottr 
    944      1.1  scottr void
    945      1.1  scottr sbc_dma_alloc(ncr_sc)
    946      1.1  scottr 	struct ncr5380_softc *ncr_sc;
    947      1.1  scottr {
    948      1.1  scottr 	struct sbc_softc *sc = (struct sbc_softc *) ncr_sc;
    949      1.1  scottr 	struct sci_req *sr = ncr_sc->sc_current;
    950      1.1  scottr 	struct scsi_xfer *xs = sr->sr_xs;
    951      1.1  scottr 	struct sbc_pdma_handle *dh;
    952      1.1  scottr 	int		i, xlen;
    953      1.1  scottr 
    954      1.6  scottr #ifdef DIAGNOSTIC
    955      1.1  scottr 	if (sr->sr_dma_hand != NULL)
    956      1.1  scottr 		panic("sbc_dma_alloc: already have PDMA handle");
    957      1.1  scottr #endif
    958      1.1  scottr 
    959      1.1  scottr 	/* Polled transfers shouldn't allocate a PDMA handle. */
    960      1.1  scottr 	if (sr->sr_flags & SR_IMMED)
    961      1.1  scottr 		return;
    962      1.1  scottr 
    963      1.1  scottr 	xlen = ncr_sc->sc_datalen;
    964      1.1  scottr 
    965      1.1  scottr 	/* Make sure our caller checked sc_min_dma_len. */
    966      1.1  scottr 	if (xlen < MIN_DMA_LEN)
    967      1.1  scottr 		panic("sbc_dma_alloc: len=0x%x\n", xlen);
    968      1.1  scottr 
    969      1.1  scottr 	/*
    970      1.1  scottr 	 * Find free PDMA handle.  Guaranteed to find one since we
    971      1.1  scottr 	 * have as many PDMA handles as the driver has processes.
    972      1.1  scottr 	 * (instances?)
    973      1.1  scottr 	 */
    974      1.1  scottr 	 for (i = 0; i < SCI_OPENINGS; i++) {
    975      1.1  scottr 		if ((sc->sc_pdma[i].dh_flags & SBC_DH_BUSY) == 0)
    976      1.1  scottr 			goto found;
    977      1.1  scottr 	}
    978      1.1  scottr 	panic("sbc: no free PDMA handles");
    979      1.1  scottr found:
    980      1.1  scottr 	dh = &sc->sc_pdma[i];
    981      1.1  scottr 	dh->dh_flags = SBC_DH_BUSY;
    982      1.1  scottr 	dh->dh_addr = ncr_sc->sc_dataptr;
    983      1.1  scottr 	dh->dh_len = xlen;
    984      1.1  scottr 
    985      1.1  scottr 	/* Copy the 'write' flag for convenience. */
    986      1.1  scottr 	if (xs->flags & SCSI_DATA_OUT)
    987      1.1  scottr 		dh->dh_flags |= SBC_DH_OUT;
    988      1.1  scottr 
    989      1.1  scottr 	sr->sr_dma_hand = dh;
    990      1.1  scottr }
    991      1.1  scottr 
    992      1.1  scottr void
    993      1.1  scottr sbc_dma_free(ncr_sc)
    994      1.1  scottr 	struct ncr5380_softc *ncr_sc;
    995      1.1  scottr {
    996      1.1  scottr 	struct sci_req *sr = ncr_sc->sc_current;
    997      1.1  scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
    998      1.1  scottr 
    999      1.6  scottr #ifdef DIAGNOSTIC
   1000      1.1  scottr 	if (sr->sr_dma_hand == NULL)
   1001      1.1  scottr 		panic("sbc_dma_free: no DMA handle");
   1002      1.1  scottr #endif
   1003      1.1  scottr 
   1004      1.1  scottr 	if (ncr_sc->sc_state & NCR_DOINGDMA)
   1005      1.1  scottr 		panic("sbc_dma_free: free while in progress");
   1006      1.1  scottr 
   1007      1.1  scottr 	if (dh->dh_flags & SBC_DH_BUSY) {
   1008      1.1  scottr 		dh->dh_flags = 0;
   1009      1.1  scottr 		dh->dh_addr = NULL;
   1010      1.1  scottr 		dh->dh_len = 0;
   1011      1.1  scottr 	}
   1012      1.1  scottr 	sr->sr_dma_hand = NULL;
   1013      1.1  scottr }
   1014      1.1  scottr 
   1015      1.1  scottr void
   1016      1.1  scottr sbc_dma_poll(ncr_sc)
   1017      1.1  scottr 	struct ncr5380_softc *ncr_sc;
   1018      1.1  scottr {
   1019      1.1  scottr 	struct sci_req *sr = ncr_sc->sc_current;
   1020      1.1  scottr 
   1021      1.3  scottr 	/*
   1022      1.3  scottr 	 * We shouldn't arrive here; if SR_IMMED is set, then
   1023      1.3  scottr 	 * dma_alloc() should have refused to allocate a handle
   1024      1.3  scottr 	 * for the transfer.  This forces the polled PDMA code
   1025      1.3  scottr 	 * to handle the request...
   1026      1.3  scottr 	 */
   1027      1.6  scottr #ifdef SBC_DEBUG
   1028      1.1  scottr 	if (sbc_debug & SBC_DB_DMA)
   1029      1.3  scottr 		printf("%s: lost DRQ interrupt?\n", ncr_sc->sc_dev.dv_xname);
   1030      1.1  scottr #endif
   1031      1.3  scottr 	sr->sr_flags |= SR_OVERDUE;
   1032      1.1  scottr }
   1033      1.1  scottr 
   1034      1.1  scottr void
   1035      1.1  scottr sbc_dma_setup(ncr_sc)
   1036      1.1  scottr 	struct ncr5380_softc *ncr_sc;
   1037      1.1  scottr {
   1038      1.1  scottr 	/* Not needed; we don't have real DMA */
   1039      1.1  scottr }
   1040      1.1  scottr 
   1041      1.1  scottr void
   1042      1.1  scottr sbc_dma_start(ncr_sc)
   1043      1.1  scottr 	struct ncr5380_softc *ncr_sc;
   1044      1.1  scottr {
   1045  1.6.4.1  scottr 	register struct sbc_softc *sc = (struct sbc_softc *) ncr_sc;
   1046      1.1  scottr 	struct sci_req *sr = ncr_sc->sc_current;
   1047      1.1  scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
   1048      1.1  scottr 
   1049      1.1  scottr 	/*
   1050  1.6.4.1  scottr 	 * Match bus phase, clear pending interrupts, set DMA mode, and
   1051  1.6.4.1  scottr 	 * assert data bus (for writing only), then start the transfer.
   1052      1.1  scottr 	 */
   1053      1.1  scottr 	if (dh->dh_flags & SBC_DH_OUT) {
   1054      1.1  scottr 		*ncr_sc->sci_tcmd = PHASE_DATA_OUT;
   1055      1.1  scottr 		SCI_CLR_INTR(ncr_sc);
   1056  1.6.4.1  scottr 		*sc->sc_iflag = 0x80 | (V2IF_SCSIIRQ | V2IF_SCSIDRQ);
   1057      1.1  scottr 		*ncr_sc->sci_mode |= SCI_MODE_DMA;
   1058      1.1  scottr 		*ncr_sc->sci_icmd = SCI_ICMD_DATA;
   1059      1.1  scottr 		*ncr_sc->sci_dma_send = 0;
   1060      1.1  scottr 	} else {
   1061      1.1  scottr 		*ncr_sc->sci_tcmd = PHASE_DATA_IN;
   1062      1.1  scottr 		SCI_CLR_INTR(ncr_sc);
   1063  1.6.4.1  scottr 		*sc->sc_iflag = 0x80 | (V2IF_SCSIIRQ | V2IF_SCSIDRQ);
   1064      1.1  scottr 		*ncr_sc->sci_mode |= SCI_MODE_DMA;
   1065      1.1  scottr 		*ncr_sc->sci_icmd = 0;
   1066      1.1  scottr 		*ncr_sc->sci_irecv = 0;
   1067      1.1  scottr 	}
   1068      1.3  scottr 	ncr_sc->sc_state |= NCR_DOINGDMA;
   1069      1.1  scottr 
   1070      1.6  scottr #ifdef SBC_DEBUG
   1071      1.1  scottr 	if (sbc_debug & SBC_DB_DMA)
   1072      1.1  scottr 		printf("%s: PDMA started, va=%p, len=0x%x\n",
   1073      1.1  scottr 		    ncr_sc->sc_dev.dv_xname, dh->dh_addr, dh->dh_len);
   1074      1.1  scottr #endif
   1075      1.1  scottr }
   1076      1.1  scottr 
   1077      1.1  scottr void
   1078      1.1  scottr sbc_dma_eop(ncr_sc)
   1079      1.1  scottr 	struct ncr5380_softc *ncr_sc;
   1080      1.1  scottr {
   1081      1.1  scottr 	/* Not used; the EOP pin is wired high (GMFH, pp. 389-390) */
   1082      1.1  scottr }
   1083      1.1  scottr 
   1084      1.1  scottr void
   1085      1.1  scottr sbc_dma_stop(ncr_sc)
   1086      1.1  scottr 	struct ncr5380_softc *ncr_sc;
   1087      1.1  scottr {
   1088  1.6.4.1  scottr 	register struct sbc_softc *sc = (struct sbc_softc *) ncr_sc;
   1089      1.1  scottr 	struct sci_req *sr = ncr_sc->sc_current;
   1090      1.1  scottr 	struct sbc_pdma_handle *dh = sr->sr_dma_hand;
   1091      1.1  scottr 	register int ntrans;
   1092      1.1  scottr 
   1093      1.1  scottr 	if ((ncr_sc->sc_state & NCR_DOINGDMA) == 0) {
   1094      1.1  scottr #ifdef SBC_DEBUG
   1095      1.1  scottr 		if (sbc_debug & SBC_DB_DMA)
   1096      1.1  scottr 			printf("%s: dma_stop: DMA not running\n",
   1097      1.1  scottr 			    ncr_sc->sc_dev.dv_xname);
   1098      1.1  scottr #endif
   1099      1.1  scottr 		return;
   1100      1.1  scottr 	}
   1101      1.1  scottr 	ncr_sc->sc_state &= ~NCR_DOINGDMA;
   1102      1.1  scottr 
   1103      1.3  scottr 	if ((ncr_sc->sc_state & NCR_ABORTING) == 0) {
   1104      1.1  scottr 		ntrans = ncr_sc->sc_datalen - dh->dh_len;
   1105      1.1  scottr 
   1106      1.1  scottr #ifdef SBC_DEBUG
   1107      1.1  scottr 		if (sbc_debug & SBC_DB_DMA)
   1108      1.1  scottr 			printf("%s: dma_stop: ntrans=0x%x\n",
   1109      1.1  scottr 			    ncr_sc->sc_dev.dv_xname, ntrans);
   1110      1.1  scottr #endif
   1111      1.1  scottr 
   1112      1.1  scottr 		if (ntrans > ncr_sc->sc_datalen)
   1113      1.1  scottr 			panic("sbc_dma_stop: excess transfer\n");
   1114      1.1  scottr 
   1115      1.1  scottr 		/* Adjust data pointer */
   1116      1.1  scottr 		ncr_sc->sc_dataptr += ntrans;
   1117      1.1  scottr 		ncr_sc->sc_datalen -= ntrans;
   1118      1.1  scottr 
   1119      1.1  scottr 		/* Clear any pending interrupts. */
   1120      1.1  scottr 		SCI_CLR_INTR(ncr_sc);
   1121  1.6.4.1  scottr 		*sc->sc_iflag = 0x80 | V2IF_SCSIIRQ;
   1122      1.1  scottr 	}
   1123      1.1  scottr 
   1124      1.1  scottr 	/* Put SBIC back into PIO mode. */
   1125      1.1  scottr 	*ncr_sc->sci_mode &= ~SCI_MODE_DMA;
   1126      1.1  scottr 	*ncr_sc->sci_icmd = 0;
   1127      1.1  scottr 
   1128      1.1  scottr #ifdef SBC_DEBUG
   1129      1.3  scottr 	if (sbc_debug & SBC_DB_REG)
   1130      1.3  scottr 		printf("%s: dma_stop: csr=0x%x, bus_csr=0x%x\n",
   1131      1.1  scottr 		    ncr_sc->sc_dev.dv_xname, *ncr_sc->sci_csr,
   1132      1.1  scottr 		    *ncr_sc->sci_bus_csr);
   1133      1.1  scottr #endif
   1134      1.1  scottr }
   1135