Home | History | Annotate | Line # | Download | only in vme
sc_vme.c revision 1.7
      1 /*	$NetBSD: sc_vme.c,v 1.7 2002/10/01 01:28:03 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996,2000,2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Adam Glass, David Jones, Gordon W. Ross, Jason R. Thorpe,
      9  * Paul Kranenburg, and Matt Fredette.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * This file contains VME bus-dependent of the `sc' SCSI adapter.
     42  * This hardware is frequently found on Sun 2, Sun 3, and Sun 4 machines.
     43  *
     44  * The SCSI machinery on this adapter is implemented by an Sun custom
     45  * chipset, which is handled by the chipset driver in /sys/dev/ic/sunscpal.c
     46  */
     47 
     48 /*
     49  * This driver originated as an MD implementation for the `si' VME driver.
     50  * The notes pertaining to that history are included below.
     51  *
     52  * David Jones wrote the initial version of this module for NetBSD/sun3,
     53  * which included support for the VME adapter only. (no reselection).
     54  *
     55  * Gordon Ross added support for the Sun 3 OBIO adapter, and re-worked
     56  * both the VME and OBIO code to support disconnect/reselect.
     57  * (Required figuring out the hardware "features" noted above.)
     58  *
     59  * The autoconfiguration boilerplate came from Adam Glass.
     60  *
     61  * Jason R. Thorpe ported the autoconfiguration and VME portions to
     62  * NetBSD/sparc, and added initial support for the 4/100 "SCSI Weird",
     63  * a wacky OBIO variant of the VME SCSI-3.  Many thanks to Chuck Cranor
     64  * for lots of helpful tips and suggestions.  Thanks also to Paul Kranenburg
     65  * and Chris Torek for bits of insight needed along the way.  Thanks to
     66  * David Gilbert and Andrew Gillham who risked filesystem life-and-limb
     67  * for the sake of testing.  Andrew Gillham helped work out the bugs
     68  * the 4/100 DMA code.
     69  */
     70 
     71 #include <sys/cdefs.h>
     72 __KERNEL_RCSID(0, "$NetBSD: sc_vme.c,v 1.7 2002/10/01 01:28:03 thorpej Exp $");
     73 
     74 #include "opt_ddb.h"
     75 
     76 #include <sys/param.h>
     77 #include <sys/systm.h>
     78 #include <sys/kernel.h>
     79 #include <sys/malloc.h>
     80 #include <sys/errno.h>
     81 #include <sys/device.h>
     82 #include <sys/buf.h>
     83 
     84 #include <machine/bus.h>
     85 #include <machine/intr.h>
     86 
     87 #include <dev/vme/vmereg.h>
     88 #include <dev/vme/vmevar.h>
     89 
     90 #include <dev/scsipi/scsi_all.h>
     91 #include <dev/scsipi/scsipi_all.h>
     92 #include <dev/scsipi/scsipi_debug.h>
     93 #include <dev/scsipi/scsiconf.h>
     94 
     95 #if !defined(DDB) && !defined(Debugger)
     96 #define	Debugger()
     97 #endif
     98 
     99 #ifndef DEBUG
    100 #define DEBUG XXX
    101 #endif
    102 
    103 #include <dev/ic/sunscpalvar.h>
    104 
    105 #include <dev/vme/screg.h>
    106 
    107 /*
    108  * Transfers smaller than this are done using PIO
    109  * (on assumption they're not worth DMA overhead)
    110  */
    111 #define	MIN_DMA_LEN 128
    112 
    113 int sunsc_vme_options = 0;
    114 
    115 static int	sc_vme_match __P((struct device *, struct cfdata *, void *));
    116 static void	sc_vme_attach __P((struct device *, struct device *, void *));
    117 static int	sc_vme_intr __P((void *));
    118 
    119 /* Auto-configuration glue. */
    120 CFATTACH_DECL(sc_vme, sizeof(struct sunscpal_softc),
    121     sc_vme_match, sc_vme_attach, NULL, NULL)
    122 
    123 static int
    124 sc_vme_match(parent, cf, aux)
    125 	struct device	*parent;
    126 	struct cfdata *cf;
    127 	void *aux;
    128 {
    129 	struct vme_attach_args	*va = aux;
    130 	vme_chipset_tag_t	ct = va->va_vct;
    131         vme_am_t		mod;
    132         vme_addr_t		vme_addr;
    133 
    134 	/* Make sure there is something there... */
    135 	mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
    136 	vme_addr = va->r[0].offset;
    137 
    138 	if (vme_probe(ct, vme_addr, 1, mod, VME_D8, NULL, 0) != 0)
    139 		return (0);
    140 
    141 	/*
    142 	 * If this is a VME SCSI board, we have to determine whether
    143 	 * it is an "sc" (Sun2) or "si" (Sun3) SCSI board.  This can
    144 	 * be determined using the fact that the "sc" board occupies
    145 	 * 4K bytes in VME space but the "si" board occupies 2K bytes.
    146 	 */
    147 	return (vme_probe(ct, vme_addr + 0x801, 1, mod, VME_D8, NULL, 0) == 0);
    148 }
    149 
    150 static void
    151 sc_vme_attach(parent, self, aux)
    152 	struct device	*parent, *self;
    153 	void		*aux;
    154 {
    155 	struct sunscpal_softc	*sc = (struct sunscpal_softc *) self;
    156 	struct vme_attach_args	*va = aux;
    157 	vme_chipset_tag_t	ct = va->va_vct;
    158 	bus_space_tag_t		bt;
    159 	bus_space_handle_t	bh;
    160 	vme_mapresc_t resc;
    161 	vme_intr_handle_t	ih;
    162 	vme_am_t		mod;
    163 	int i;
    164 
    165 	sc->sunscpal_dmat = va->va_bdt;
    166 
    167 	mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
    168 
    169 	if (vme_space_map(ct, va->r[0].offset, SCREG_BANK_SZ,
    170 			  mod, VME_D8, 0, &bt, &bh, &resc) != 0)
    171 		panic("%s: vme_space_map", sc->sc_dev.dv_xname);
    172 
    173 	sc->sunscpal_regt = bt;
    174 	sc->sunscpal_regh = bh;
    175 
    176 	vme_intr_map(ct, va->ilevel, va->ivector, &ih);
    177 	vme_intr_establish(ct, ih, IPL_BIO, sc_vme_intr, sc);
    178 
    179 	printf("\n");
    180 
    181 	/*
    182 	 * Initialize fields used by the MI code
    183 	 */
    184 
    185 	/* PAL register bank offsets */
    186 	sc->sunscpal_data = SCREG_DATA;
    187 	sc->sunscpal_cmd_stat = SCREG_CMD_STAT;
    188 	sc->sunscpal_icr = SCREG_ICR;
    189 	sc->sunscpal_dma_addr_h = SCREG_DMA_ADDR_H;
    190 	sc->sunscpal_dma_addr_l = SCREG_DMA_ADDR_L;
    191 	sc->sunscpal_dma_count = SCREG_DMA_COUNT;
    192 	sc->sunscpal_intvec = SCREG_INTVEC;
    193 
    194 	/* Miscellaneous. */
    195 	sc->sc_min_dma_len = MIN_DMA_LEN;
    196 	sc->sc_rev = SUNSCPAL_VARIANT_501_1045;
    197 
    198 	/*
    199 	 * Allocate DMA handles.
    200 	 */
    201 	i = SUNSCPAL_OPENINGS * sizeof(struct sunscpal_dma_handle);
    202 	sc->sc_dma_handles = (struct sunscpal_dma_handle *)malloc(i, M_DEVBUF, M_NOWAIT);
    203 	if (sc->sc_dma_handles == NULL)
    204 		panic("sc: dma handle malloc failed");
    205 
    206 	for (i = 0; i < SUNSCPAL_OPENINGS; i++) {
    207 		sc->sc_dma_handles[i].dh_flags = 0;
    208 
    209 		/* Allocate a DMA handle */
    210 		if (vme_dmamap_create(
    211 				ct,		/* VME chip tag */
    212 				SUNSCPAL_MAX_DMA_LEN,	/* size */
    213 				VME_AM_A24,	/* address modifier */
    214 				VME_D16,	/* data size */
    215 				0,		/* swap */
    216 				1,		/* nsegments */
    217 				SUNSCPAL_MAX_DMA_LEN,	/* maxsegsz */
    218 				0,		/* boundary */
    219 				BUS_DMA_NOWAIT,
    220 				&sc->sc_dma_handles[i].dh_dmamap) != 0) {
    221 
    222 			printf("%s: DMA buffer map create error\n",
    223 				sc->sc_dev.dv_xname);
    224 			return;
    225 		}
    226 	}
    227 
    228 	/*
    229 	 * Set up interrupts on the board.
    230 	 */
    231 	SUNSCPAL_WRITE_1(sc, sunscpal_intvec, va->ivector & 0xFF);
    232 
    233 	/* Do the common attach stuff. */
    234 	printf("%s", sc->sc_dev.dv_xname);
    235 	sunscpal_attach(sc, (sc->sc_dev.dv_cfdata->cf_flags ? sc->sc_dev.dv_cfdata->cf_flags : sunsc_vme_options));
    236 }
    237 
    238 static int
    239 sc_vme_intr(void *arg)
    240 {
    241 	struct sunscpal_softc *sc = arg;
    242 	int claimed;
    243 
    244 	claimed = sunscpal_intr(sc);
    245 #ifdef  DEBUG
    246 	if (!claimed) {
    247         	printf("sc_vme_intr: spurious from SBC\n");
    248 	}
    249 #endif
    250 	/* Yes, we DID cause this interrupt. */
    251 	claimed = 1;
    252 
    253 	return (claimed);
    254 }
    255 
    256