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