Home | History | Annotate | Line # | Download | only in vsa
ncr.c revision 1.22
      1  1.22    ragge /*	$NetBSD: ncr.c,v 1.22 1999/09/21 18:07:54 ragge Exp $	*/
      2   1.1    ragge 
      3  1.16    ragge /*-
      4  1.16    ragge  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5   1.1    ragge  * All rights reserved.
      6   1.1    ragge  *
      7  1.16    ragge  * This code is derived from software contributed to The NetBSD Foundation
      8  1.16    ragge  * by Adam Glass, David Jones, Gordon W. Ross, and Jens A. Nilsson.
      9  1.16    ragge  *
     10   1.1    ragge  * Redistribution and use in source and binary forms, with or without
     11   1.1    ragge  * modification, are permitted provided that the following conditions
     12   1.1    ragge  * are met:
     13   1.1    ragge  * 1. Redistributions of source code must retain the above copyright
     14   1.1    ragge  *    notice, this list of conditions and the following disclaimer.
     15   1.1    ragge  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    ragge  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    ragge  *    documentation and/or other materials provided with the distribution.
     18  1.16    ragge  * 3. All advertising materials mentioning features or use of this software
     19   1.1    ragge  *    must display the following acknowledgement:
     20  1.16    ragge  *        This product includes software developed by the NetBSD
     21  1.16    ragge  *        Foundation, Inc. and its contributors.
     22  1.16    ragge  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.16    ragge  *    contributors may be used to endorse or promote products derived
     24  1.16    ragge  *    from this software without specific prior written permission.
     25  1.16    ragge  *
     26  1.16    ragge  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.16    ragge  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.16    ragge  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.16    ragge  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.16    ragge  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.16    ragge  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.16    ragge  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.16    ragge  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.16    ragge  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.16    ragge  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.16    ragge  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    ragge  */
     38   1.1    ragge 
     39   1.1    ragge /*
     40  1.16    ragge  * This file contains the machine-dependent parts of the NCR-5380
     41  1.16    ragge  * controller. The machine-independent parts are in ncr5380sbc.c.
     42  1.16    ragge  *
     43  1.16    ragge  * Note: Only PIO transfers for now which implicates very bad
     44  1.16    ragge  * performance. DMA support will come soon.
     45  1.16    ragge  *
     46  1.16    ragge  * Jens A. Nilsson.
     47  1.16    ragge  *
     48  1.16    ragge  * Credits:
     49  1.16    ragge  *
     50  1.16    ragge  * This code is based on arch/sun3/dev/si*
     51  1.16    ragge  * Written by David Jones, Gordon Ross, and Adam Glass.
     52   1.1    ragge  */
     53   1.1    ragge 
     54   1.1    ragge #include <sys/param.h>
     55   1.1    ragge #include <sys/systm.h>
     56  1.16    ragge #include <sys/errno.h>
     57   1.1    ragge #include <sys/kernel.h>
     58  1.16    ragge #include <sys/malloc.h>
     59  1.16    ragge #include <sys/device.h>
     60   1.1    ragge #include <sys/buf.h>
     61   1.1    ragge #include <sys/proc.h>
     62   1.1    ragge #include <sys/user.h>
     63   1.1    ragge 
     64   1.9   bouyer #include <dev/scsipi/scsi_all.h>
     65   1.9   bouyer #include <dev/scsipi/scsipi_all.h>
     66   1.9   bouyer #include <dev/scsipi/scsipi_debug.h>
     67   1.9   bouyer #include <dev/scsipi/scsiconf.h>
     68   1.1    ragge 
     69   1.1    ragge #include <dev/ic/ncr5380reg.h>
     70   1.1    ragge #include <dev/ic/ncr5380var.h>
     71   1.1    ragge 
     72  1.16    ragge #include <machine/vsbus.h>
     73  1.16    ragge #include <machine/bus.h>
     74  1.21    ragge #include <machine/sid.h>
     75   1.1    ragge 
     76  1.16    ragge #include "ioconf.h"
     77   1.1    ragge 
     78  1.16    ragge #define MIN_DMA_LEN 128
     79   1.1    ragge 
     80  1.16    ragge #ifdef notyet
     81   1.1    ragge struct si_dma_handle {
     82  1.16    ragge 	int	dh_flags;
     83  1.16    ragge #define SIDH_BUSY	1
     84  1.16    ragge #define SIDH_OUT	2
     85  1.16    ragge 	u_char	*dh_addr;
     86   1.1    ragge };
     87  1.16    ragge #endif
     88   1.1    ragge 
     89   1.1    ragge struct si_softc {
     90   1.1    ragge 	struct ncr5380_softc	ncr_sc;
     91   1.1    ragge };
     92   1.1    ragge 
     93   1.1    ragge /* This is copied from julian's bt driver */
     94   1.1    ragge /* "so we have a default dev struct for our link struct." */
     95   1.9   bouyer static struct scsipi_device si_dev = {
     96  1.16    ragge 	NULL,	/* Use default error handler. */
     97  1.16    ragge 	NULL,	/* Use default start handler. */
     98  1.16    ragge 	NULL,	/* Use default async handler. */
     99  1.16    ragge 	NULL,	/* Use default "done" routine. */
    100   1.1    ragge };
    101   1.1    ragge 
    102  1.16    ragge static int si_match(struct device *, struct cfdata *, void *);
    103  1.16    ragge static void si_attach(struct device *, struct device *, void *);
    104  1.16    ragge static void si_minphys(struct buf *);
    105  1.16    ragge static void si_intr(int);
    106  1.16    ragge void dk_establish(void);
    107   1.1    ragge 
    108   1.1    ragge struct cfattach ncr_ca = {
    109  1.16    ragge 	sizeof(struct si_softc), si_match, si_attach
    110   1.1    ragge };
    111   1.1    ragge 
    112   1.1    ragge void
    113  1.16    ragge dk_establish(void)
    114   1.1    ragge {
    115   1.1    ragge #if 0
    116  1.16    ragge 	printf("faking dk_establish()...\n");
    117   1.1    ragge #endif
    118   1.1    ragge }
    119   1.1    ragge 
    120  1.16    ragge static int
    121  1.16    ragge si_match(parent, cf, aux)
    122  1.16    ragge 	struct device *parent;
    123  1.16    ragge 	struct cfdata *cf;
    124  1.16    ragge 	void *aux;
    125   1.1    ragge {
    126  1.16    ragge 	struct vsbus_attach_args *va = aux;
    127  1.18    ragge 	volatile char *si_csr = (char *) va->va_addr;
    128   1.1    ragge 
    129  1.21    ragge 	if (vax_boardtype == VAX_BTYP_49)
    130  1.21    ragge 		return 0;
    131  1.19    ragge 	/* This is the way Linux autoprobes the interrupt MK-990321 */
    132  1.19    ragge 	si_csr[12] = 0;
    133  1.19    ragge 	si_csr[16] = 0x80;
    134  1.19    ragge 	si_csr[0] = 0x80;
    135  1.19    ragge 	si_csr[4] = 5; /* 0xcf */
    136  1.18    ragge 	DELAY(100000);
    137  1.18    ragge 	va->va_ivec = si_intr;
    138  1.18    ragge 	return 1;
    139   1.1    ragge }
    140   1.1    ragge 
    141  1.16    ragge static void
    142  1.18    ragge si_attach(parent, self, aux)
    143   1.1    ragge 	struct device	*parent, *self;
    144  1.18    ragge 	void		*aux;
    145   1.1    ragge {
    146  1.18    ragge 	struct vsbus_attach_args *va = aux;
    147   1.1    ragge 	struct si_softc *sc = (struct si_softc *) self;
    148  1.16    ragge 	struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
    149   1.1    ragge 
    150  1.16    ragge 	printf("\n");
    151   1.1    ragge 	/*
    152  1.16    ragge 	 * MD function pointers used by the MI code.
    153   1.1    ragge 	 */
    154  1.16    ragge 	ncr_sc->sc_pio_out = ncr5380_pio_out;
    155  1.16    ragge 	ncr_sc->sc_pio_in =  ncr5380_pio_in;
    156  1.16    ragge 
    157  1.16    ragge #ifdef notyet
    158  1.16    ragge 	ncr_sc->sc_dma_alloc = si_dma_alloc;
    159  1.16    ragge 	ncr_sc->sc_dma_free  = si_dma_free;
    160  1.16    ragge 	ncr_sc->sc_dma_setup = si_dma_setup;
    161  1.16    ragge 	ncr_sc->sc_dma_start = si_dma_start;
    162  1.16    ragge 	ncr_sc->sc_dma_poll  = si_dma_poll;
    163  1.16    ragge 	ncr_sc->sc_dma_eop   = si_dma_eop;
    164  1.16    ragge 	ncr_sc->sc_dma_stop  = si_dma_stop;
    165   1.1    ragge #endif
    166  1.16    ragge 	ncr_sc->sc_intr_on   = NULL /*si_intr_on*/;
    167  1.16    ragge 	ncr_sc->sc_intr_off  = NULL /*si_intr_off*/;
    168   1.1    ragge 
    169  1.16    ragge 	ncr_sc->sc_dma_alloc = NULL;
    170  1.16    ragge 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    171  1.15  thorpej 
    172  1.15  thorpej 	/*
    173  1.15  thorpej 	 * Fill in the adapter.
    174  1.15  thorpej 	 */
    175  1.15  thorpej 	ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
    176  1.15  thorpej 	ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
    177  1.15  thorpej 
    178   1.1    ragge 	/*
    179   1.1    ragge 	 * Fill in the prototype scsi_link.
    180   1.1    ragge 	 */
    181   1.9   bouyer 	ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
    182   1.1    ragge 	ncr_sc->sc_link.adapter_softc = sc;
    183  1.16    ragge 	ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
    184  1.15  thorpej 	ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
    185   1.1    ragge 	ncr_sc->sc_link.device = &si_dev;
    186   1.9   bouyer 	ncr_sc->sc_link.type = BUS_SCSI;
    187  1.16    ragge 
    188   1.1    ragge 	/*
    189  1.16    ragge 	 * Initialize fields used by the MI code.
    190   1.1    ragge 	 */
    191  1.22    ragge /*	ncr_sc->sc_regt =  Unused on VAX */
    192  1.22    ragge 	ncr_sc->sc_regh = vax_map_physmem(va->va_paddr, 1);
    193  1.22    ragge 
    194  1.22    ragge 	/* Register offsets */
    195  1.22    ragge 	ncr_sc->sci_r0 = 0;
    196  1.22    ragge 	ncr_sc->sci_r1 = 4;
    197  1.22    ragge 	ncr_sc->sci_r2 = 8;
    198  1.22    ragge 	ncr_sc->sci_r3 = 12;
    199  1.22    ragge 	ncr_sc->sci_r4 = 16;
    200  1.22    ragge 	ncr_sc->sci_r5 = 20;
    201  1.22    ragge 	ncr_sc->sci_r6 = 24;
    202  1.22    ragge 	ncr_sc->sci_r7 = 28;
    203   1.1    ragge 
    204  1.20    ragge 	ncr_sc->sc_no_disconnect = 0xff;
    205   1.1    ragge 	/*
    206  1.16    ragge 	 * Initialize si board itself.
    207   1.1    ragge 	 */
    208   1.1    ragge 	ncr5380_init(ncr_sc);
    209   1.1    ragge 	ncr5380_reset_scsibus(ncr_sc);
    210   1.1    ragge 
    211  1.16    ragge 	config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
    212   1.1    ragge }
    213   1.1    ragge 
    214  1.22    ragge /*
    215  1.22    ragge  * Adjust the max transfer size. The DMA buffer is only 16k on VS2000.
    216  1.22    ragge  */
    217  1.16    ragge static void
    218   1.1    ragge si_minphys(struct buf *bp)
    219   1.1    ragge {
    220  1.22    ragge 	if ((vax_boardtype == VAX_BTYP_410) && (bp->b_bcount > (16*1024)))
    221  1.22    ragge 		bp->b_bcount = (16*1024);
    222  1.22    ragge 	else if (bp->b_bcount > MAXPHYS)
    223  1.22    ragge 		bp->b_bcount = MAXPHYS;
    224   1.1    ragge }
    225   1.1    ragge 
    226  1.16    ragge static void
    227  1.16    ragge si_intr(int arg)
    228   1.1    ragge {
    229  1.16    ragge 	ncr5380_intr(ncr_cd.cd_devs[arg]);
    230   1.1    ragge }
    231