Home | History | Annotate | Line # | Download | only in vsa
ncr.c revision 1.16
      1  1.16    ragge /*	$NetBSD: ncr.c,v 1.16 1998/12/06 13:55:09 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.1    ragge };
     91   1.1    ragge 
     92   1.1    ragge /* This is copied from julian's bt driver */
     93   1.1    ragge /* "so we have a default dev struct for our link struct." */
     94   1.9   bouyer static struct scsipi_device si_dev = {
     95  1.16    ragge 	NULL,	/* Use default error handler. */
     96  1.16    ragge 	NULL,	/* Use default start handler. */
     97  1.16    ragge 	NULL,	/* Use default async handler. */
     98  1.16    ragge 	NULL,	/* Use default "done" routine. */
     99   1.1    ragge };
    100   1.1    ragge 
    101  1.16    ragge static int si_match(struct device *, struct cfdata *, void *);
    102  1.16    ragge static void si_attach(struct device *, struct device *, void *);
    103  1.16    ragge static void si_minphys(struct buf *);
    104  1.16    ragge static void si_intr(int);
    105  1.16    ragge void dk_establish(void);
    106   1.1    ragge 
    107   1.1    ragge struct cfattach ncr_ca = {
    108  1.16    ragge 	sizeof(struct si_softc), si_match, si_attach
    109   1.1    ragge };
    110   1.1    ragge 
    111   1.1    ragge void
    112  1.16    ragge dk_establish(void)
    113   1.1    ragge {
    114   1.1    ragge #if 0
    115  1.16    ragge 	printf("faking dk_establish()...\n");
    116   1.1    ragge #endif
    117   1.1    ragge }
    118   1.1    ragge 
    119  1.16    ragge static int
    120  1.16    ragge si_match(parent, cf, aux)
    121  1.16    ragge 	struct device *parent;
    122  1.16    ragge 	struct cfdata *cf;
    123  1.16    ragge 	void *aux;
    124   1.1    ragge {
    125  1.16    ragge 	struct vsbus_attach_args *va = aux;
    126   1.1    ragge 
    127  1.16    ragge 	if (va->va_type == 0x200C0080)
    128  1.16    ragge 		return 1;
    129  1.16    ragge 	return 0;
    130   1.1    ragge }
    131   1.1    ragge 
    132  1.16    ragge static void
    133  1.16    ragge si_attach(parent, self, args)
    134   1.1    ragge 	struct device	*parent, *self;
    135  1.16    ragge 	void		*args;
    136   1.1    ragge {
    137   1.1    ragge 	struct si_softc *sc = (struct si_softc *) self;
    138  1.16    ragge 	struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
    139  1.16    ragge #ifdef notyet
    140  1.16    ragge 	struct confargs *ca = args;
    141  1.16    ragge #endif
    142   1.1    ragge 
    143  1.16    ragge 	printf("\n");
    144   1.1    ragge 	/*
    145  1.16    ragge 	 * MD function pointers used by the MI code.
    146   1.1    ragge 	 */
    147  1.16    ragge 	ncr_sc->sc_pio_out = ncr5380_pio_out;
    148  1.16    ragge 	ncr_sc->sc_pio_in =  ncr5380_pio_in;
    149  1.16    ragge 
    150  1.16    ragge #ifdef notyet
    151  1.16    ragge 	ncr_sc->sc_dma_alloc = si_dma_alloc;
    152  1.16    ragge 	ncr_sc->sc_dma_free  = si_dma_free;
    153  1.16    ragge 	ncr_sc->sc_dma_setup = si_dma_setup;
    154  1.16    ragge 	ncr_sc->sc_dma_start = si_dma_start;
    155  1.16    ragge 	ncr_sc->sc_dma_poll  = si_dma_poll;
    156  1.16    ragge 	ncr_sc->sc_dma_eop   = si_dma_eop;
    157  1.16    ragge 	ncr_sc->sc_dma_stop  = si_dma_stop;
    158   1.1    ragge #endif
    159  1.16    ragge 	ncr_sc->sc_intr_on   = NULL /*si_intr_on*/;
    160  1.16    ragge 	ncr_sc->sc_intr_off  = NULL /*si_intr_off*/;
    161   1.1    ragge 
    162  1.16    ragge 	ncr_sc->sc_dma_alloc = NULL;
    163  1.16    ragge 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    164  1.15  thorpej 
    165  1.15  thorpej 	/*
    166  1.15  thorpej 	 * Fill in the adapter.
    167  1.15  thorpej 	 */
    168  1.15  thorpej 	ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
    169  1.15  thorpej 	ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
    170  1.15  thorpej 
    171   1.1    ragge 	/*
    172   1.1    ragge 	 * Fill in the prototype scsi_link.
    173   1.1    ragge 	 */
    174   1.9   bouyer 	ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
    175   1.1    ragge 	ncr_sc->sc_link.adapter_softc = sc;
    176  1.16    ragge 	ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
    177  1.15  thorpej 	ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
    178   1.1    ragge 	ncr_sc->sc_link.device = &si_dev;
    179   1.9   bouyer 	ncr_sc->sc_link.type = BUS_SCSI;
    180  1.16    ragge 
    181   1.1    ragge 	/*
    182  1.16    ragge 	 * Initialize fields used by the MI code.
    183   1.1    ragge 	 */
    184  1.16    ragge 	ncr_sc->sci_r0 = sca_regs + 0x80; /* CUR_DATA/OUT_DATA (rw) */
    185  1.16    ragge 	ncr_sc->sci_r1 = sca_regs + 0x84; /* INI_CMD           (rw) */
    186  1.16    ragge 	ncr_sc->sci_r2 = sca_regs + 0x88; /* MODE              (rw) */
    187  1.16    ragge 	ncr_sc->sci_r3 = sca_regs + 0x8c; /* TAR_CMD           (rw) */
    188  1.16    ragge 	ncr_sc->sci_r4 = sca_regs + 0x90; /* CUR_STAT/SEL_ENA  (rw) */
    189  1.16    ragge 	ncr_sc->sci_r5 = sca_regs + 0x94; /* STATUS/DMA_SEND   (rw) */
    190  1.16    ragge 	ncr_sc->sci_r6 = sca_regs + 0x98; /* IN_DATA/DMA_TRCV  (rw) */
    191  1.16    ragge 	ncr_sc->sci_r7 = sca_regs + 0x9c; /* RESET/DMA_IRCV    (rw) */
    192   1.1    ragge 
    193   1.1    ragge 	/*
    194  1.16    ragge 	 * Initialize si board itself.
    195   1.1    ragge 	 */
    196   1.1    ragge 	ncr5380_init(ncr_sc);
    197   1.1    ragge 	ncr5380_reset_scsibus(ncr_sc);
    198   1.1    ragge 
    199  1.16    ragge 	vsbus_intr_attach(1, si_intr, 0); /* 0 is arg for si_intr */
    200  1.16    ragge 	vsbus_intr_enable(1);
    201  1.16    ragge 
    202  1.16    ragge 	config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
    203   1.1    ragge }
    204   1.1    ragge 
    205  1.16    ragge static void
    206   1.1    ragge si_minphys(struct buf *bp)
    207   1.1    ragge {
    208   1.1    ragge #if 0
    209  1.16    ragge 	printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
    210  1.16    ragge 			bp->b_blkno, (int) bp->b_bcount,
    211  1.16    ragge 			(unsigned) bp->b_data, (unsigned) bp->b_flags);
    212   1.1    ragge #endif
    213   1.1    ragge }
    214   1.1    ragge 
    215  1.16    ragge static void
    216  1.16    ragge si_intr(int arg)
    217   1.1    ragge {
    218   1.1    ragge #if 0
    219  1.16    ragge 	printf("si_intr: arg=%d\n", arg);
    220   1.1    ragge #endif
    221  1.16    ragge 	ncr5380_intr(ncr_cd.cd_devs[arg]);
    222   1.1    ragge }
    223   1.1    ragge 
    224