Home | History | Annotate | Line # | Download | only in vsa
ncr.c revision 1.20
      1  1.20    ragge /*	$NetBSD: ncr.c,v 1.20 1999/06/19 15:46:05 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.1    ragge 
     75  1.16    ragge #include "ioconf.h"
     76   1.1    ragge 
     77  1.16    ragge #define MIN_DMA_LEN 128
     78   1.1    ragge 
     79  1.16    ragge #ifdef notyet
     80   1.1    ragge struct si_dma_handle {
     81  1.16    ragge 	int	dh_flags;
     82  1.16    ragge #define SIDH_BUSY	1
     83  1.16    ragge #define SIDH_OUT	2
     84  1.16    ragge 	u_char	*dh_addr;
     85   1.1    ragge };
     86  1.16    ragge #endif
     87   1.1    ragge 
     88   1.1    ragge struct si_softc {
     89   1.1    ragge 	struct ncr5380_softc	ncr_sc;
     90  1.18    ragge 	caddr_t sca_regs;
     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.19    ragge 	/* This is the way Linux autoprobes the interrupt MK-990321 */
    130  1.19    ragge 	si_csr[12] = 0;
    131  1.19    ragge 	si_csr[16] = 0x80;
    132  1.19    ragge 	si_csr[0] = 0x80;
    133  1.19    ragge 	si_csr[4] = 5; /* 0xcf */
    134  1.18    ragge 	DELAY(100000);
    135  1.18    ragge 	va->va_ivec = si_intr;
    136  1.18    ragge 	return 1;
    137   1.1    ragge }
    138   1.1    ragge 
    139  1.16    ragge static void
    140  1.18    ragge si_attach(parent, self, aux)
    141   1.1    ragge 	struct device	*parent, *self;
    142  1.18    ragge 	void		*aux;
    143   1.1    ragge {
    144  1.18    ragge 	struct vsbus_attach_args *va = aux;
    145   1.1    ragge 	struct si_softc *sc = (struct si_softc *) self;
    146  1.16    ragge 	struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
    147   1.1    ragge 
    148  1.16    ragge 	printf("\n");
    149  1.18    ragge 	sc->sca_regs = (caddr_t)vax_map_physmem(va->va_paddr, 1);
    150   1.1    ragge 	/*
    151  1.16    ragge 	 * MD function pointers used by the MI code.
    152   1.1    ragge 	 */
    153  1.16    ragge 	ncr_sc->sc_pio_out = ncr5380_pio_out;
    154  1.16    ragge 	ncr_sc->sc_pio_in =  ncr5380_pio_in;
    155  1.16    ragge 
    156  1.16    ragge #ifdef notyet
    157  1.16    ragge 	ncr_sc->sc_dma_alloc = si_dma_alloc;
    158  1.16    ragge 	ncr_sc->sc_dma_free  = si_dma_free;
    159  1.16    ragge 	ncr_sc->sc_dma_setup = si_dma_setup;
    160  1.16    ragge 	ncr_sc->sc_dma_start = si_dma_start;
    161  1.16    ragge 	ncr_sc->sc_dma_poll  = si_dma_poll;
    162  1.16    ragge 	ncr_sc->sc_dma_eop   = si_dma_eop;
    163  1.16    ragge 	ncr_sc->sc_dma_stop  = si_dma_stop;
    164   1.1    ragge #endif
    165  1.16    ragge 	ncr_sc->sc_intr_on   = NULL /*si_intr_on*/;
    166  1.16    ragge 	ncr_sc->sc_intr_off  = NULL /*si_intr_off*/;
    167   1.1    ragge 
    168  1.16    ragge 	ncr_sc->sc_dma_alloc = NULL;
    169  1.16    ragge 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    170  1.15  thorpej 
    171  1.15  thorpej 	/*
    172  1.15  thorpej 	 * Fill in the adapter.
    173  1.15  thorpej 	 */
    174  1.15  thorpej 	ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
    175  1.15  thorpej 	ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
    176  1.15  thorpej 
    177   1.1    ragge 	/*
    178   1.1    ragge 	 * Fill in the prototype scsi_link.
    179   1.1    ragge 	 */
    180   1.9   bouyer 	ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
    181   1.1    ragge 	ncr_sc->sc_link.adapter_softc = sc;
    182  1.16    ragge 	ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
    183  1.15  thorpej 	ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
    184   1.1    ragge 	ncr_sc->sc_link.device = &si_dev;
    185   1.9   bouyer 	ncr_sc->sc_link.type = BUS_SCSI;
    186  1.16    ragge 
    187   1.1    ragge 	/*
    188  1.16    ragge 	 * Initialize fields used by the MI code.
    189   1.1    ragge 	 */
    190  1.18    ragge 	ncr_sc->sci_r0 = sc->sca_regs; /* CUR_DATA/OUT_DATA (rw) */
    191  1.18    ragge 	ncr_sc->sci_r1 = sc->sca_regs + 4; /* INI_CMD           (rw) */
    192  1.18    ragge 	ncr_sc->sci_r2 = sc->sca_regs + 8; /* MODE              (rw) */
    193  1.18    ragge 	ncr_sc->sci_r3 = sc->sca_regs + 12; /* TAR_CMD           (rw) */
    194  1.18    ragge 	ncr_sc->sci_r4 = sc->sca_regs + 16; /* CUR_STAT/SEL_ENA  (rw) */
    195  1.18    ragge 	ncr_sc->sci_r5 = sc->sca_regs + 20; /* STATUS/DMA_SEND   (rw) */
    196  1.18    ragge 	ncr_sc->sci_r6 = sc->sca_regs + 24; /* IN_DATA/DMA_TRCV  (rw) */
    197  1.18    ragge 	ncr_sc->sci_r7 = sc->sca_regs + 28; /* RESET/DMA_IRCV    (rw) */
    198   1.1    ragge 
    199  1.20    ragge 	ncr_sc->sc_no_disconnect = 0xff;
    200   1.1    ragge 	/*
    201  1.16    ragge 	 * Initialize si board itself.
    202   1.1    ragge 	 */
    203   1.1    ragge 	ncr5380_init(ncr_sc);
    204   1.1    ragge 	ncr5380_reset_scsibus(ncr_sc);
    205   1.1    ragge 
    206  1.16    ragge 	config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
    207   1.1    ragge }
    208   1.1    ragge 
    209  1.16    ragge static void
    210   1.1    ragge si_minphys(struct buf *bp)
    211   1.1    ragge {
    212   1.1    ragge #if 0
    213  1.16    ragge 	printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
    214  1.16    ragge 			bp->b_blkno, (int) bp->b_bcount,
    215  1.16    ragge 			(unsigned) bp->b_data, (unsigned) bp->b_flags);
    216   1.1    ragge #endif
    217   1.1    ragge }
    218   1.1    ragge 
    219  1.16    ragge static void
    220  1.16    ragge si_intr(int arg)
    221   1.1    ragge {
    222  1.16    ragge 	ncr5380_intr(ncr_cd.cd_devs[arg]);
    223   1.1    ragge }
    224   1.1    ragge 
    225