Home | History | Annotate | Line # | Download | only in sbus
esp_sbus.c revision 1.12.2.5
      1  1.12.2.5   nathanw /*	$NetBSD: esp_sbus.c,v 1.12.2.5 2001/11/14 19:15:57 nathanw Exp $	*/
      2       1.1        pk 
      3       1.1        pk /*-
      4       1.1        pk  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5       1.1        pk  * All rights reserved.
      6       1.1        pk  *
      7       1.1        pk  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1        pk  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9       1.1        pk  * Simulation Facility, NASA Ames Research Center; Paul Kranenburg.
     10       1.1        pk  *
     11       1.1        pk  * Redistribution and use in source and binary forms, with or without
     12       1.1        pk  * modification, are permitted provided that the following conditions
     13       1.1        pk  * are met:
     14       1.1        pk  * 1. Redistributions of source code must retain the above copyright
     15       1.1        pk  *    notice, this list of conditions and the following disclaimer.
     16       1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     18       1.1        pk  *    documentation and/or other materials provided with the distribution.
     19       1.1        pk  * 3. All advertising materials mentioning features or use of this software
     20       1.1        pk  *    must display the following acknowledgement:
     21       1.1        pk  *	This product includes software developed by the NetBSD
     22       1.1        pk  *	Foundation, Inc. and its contributors.
     23       1.1        pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1        pk  *    contributors may be used to endorse or promote products derived
     25       1.1        pk  *    from this software without specific prior written permission.
     26       1.1        pk  *
     27       1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1        pk  */
     39  1.12.2.5   nathanw 
     40  1.12.2.5   nathanw #include <sys/cdefs.h>
     41  1.12.2.5   nathanw __KERNEL_RCSID(0, "$NetBSD: esp_sbus.c,v 1.12.2.5 2001/11/14 19:15:57 nathanw Exp $");
     42       1.1        pk 
     43       1.1        pk #include <sys/types.h>
     44       1.1        pk #include <sys/param.h>
     45       1.1        pk #include <sys/systm.h>
     46       1.1        pk #include <sys/device.h>
     47       1.1        pk #include <sys/buf.h>
     48  1.12.2.1   nathanw #include <sys/malloc.h>
     49       1.1        pk 
     50       1.1        pk #include <dev/scsipi/scsi_all.h>
     51       1.1        pk #include <dev/scsipi/scsipi_all.h>
     52       1.1        pk #include <dev/scsipi/scsiconf.h>
     53       1.1        pk #include <dev/scsipi/scsi_message.h>
     54       1.1        pk 
     55       1.1        pk #include <machine/bus.h>
     56      1.11        pk #include <machine/intr.h>
     57       1.1        pk #include <machine/autoconf.h>
     58       1.1        pk 
     59       1.1        pk #include <dev/ic/lsi64854reg.h>
     60       1.1        pk #include <dev/ic/lsi64854var.h>
     61       1.1        pk 
     62       1.1        pk #include <dev/ic/ncr53c9xreg.h>
     63       1.1        pk #include <dev/ic/ncr53c9xvar.h>
     64       1.1        pk 
     65       1.1        pk #include <dev/sbus/sbusvar.h>
     66       1.1        pk 
     67  1.12.2.1   nathanw /* #define ESP_SBUS_DEBUG */
     68  1.12.2.1   nathanw 
     69       1.1        pk struct esp_softc {
     70       1.1        pk 	struct ncr53c9x_softc sc_ncr53c9x;	/* glue to MI code */
     71       1.1        pk 	struct sbusdev	sc_sd;			/* sbus device */
     72       1.1        pk 
     73       1.1        pk 	bus_space_tag_t	sc_bustag;
     74       1.1        pk 	bus_dma_tag_t	sc_dmatag;
     75       1.1        pk 
     76       1.1        pk 	bus_space_handle_t sc_reg;		/* the registers */
     77       1.1        pk 	struct lsi64854_softc *sc_dma;		/* pointer to my dma */
     78       1.1        pk 
     79       1.1        pk 	int	sc_pri;				/* SBUS priority */
     80       1.1        pk };
     81       1.1        pk 
     82       1.1        pk void	espattach_sbus	__P((struct device *, struct device *, void *));
     83       1.1        pk void	espattach_dma	__P((struct device *, struct device *, void *));
     84       1.1        pk int	espmatch_sbus	__P((struct device *, struct cfdata *, void *));
     85       1.1        pk 
     86       1.1        pk 
     87       1.1        pk /* Linkup to the rest of the kernel */
     88       1.1        pk struct cfattach esp_sbus_ca = {
     89       1.1        pk 	sizeof(struct esp_softc), espmatch_sbus, espattach_sbus
     90       1.1        pk };
     91       1.1        pk struct cfattach esp_dma_ca = {
     92       1.1        pk 	sizeof(struct esp_softc), espmatch_sbus, espattach_dma
     93       1.1        pk };
     94       1.1        pk 
     95       1.1        pk /*
     96       1.1        pk  * Functions and the switch for the MI code.
     97       1.1        pk  */
     98       1.1        pk static u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
     99       1.1        pk static void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    100       1.6    mjacob static u_char	esp_rdreg1 __P((struct ncr53c9x_softc *, int));
    101       1.6    mjacob static void	esp_wrreg1 __P((struct ncr53c9x_softc *, int, u_char));
    102       1.1        pk static int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    103       1.1        pk static void	esp_dma_reset __P((struct ncr53c9x_softc *));
    104       1.1        pk static int	esp_dma_intr __P((struct ncr53c9x_softc *));
    105       1.1        pk static int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    106       1.1        pk 				    size_t *, int, size_t *));
    107       1.1        pk static void	esp_dma_go __P((struct ncr53c9x_softc *));
    108       1.1        pk static void	esp_dma_stop __P((struct ncr53c9x_softc *));
    109       1.1        pk static int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    110       1.1        pk 
    111       1.1        pk static struct ncr53c9x_glue esp_sbus_glue = {
    112       1.1        pk 	esp_read_reg,
    113       1.1        pk 	esp_write_reg,
    114       1.1        pk 	esp_dma_isintr,
    115       1.1        pk 	esp_dma_reset,
    116       1.1        pk 	esp_dma_intr,
    117       1.1        pk 	esp_dma_setup,
    118       1.1        pk 	esp_dma_go,
    119       1.1        pk 	esp_dma_stop,
    120       1.1        pk 	esp_dma_isactive,
    121       1.1        pk 	NULL,			/* gl_clear_latched_intr */
    122       1.1        pk };
    123       1.1        pk 
    124       1.6    mjacob static struct ncr53c9x_glue esp_sbus_glue1 = {
    125       1.6    mjacob 	esp_rdreg1,
    126       1.6    mjacob 	esp_wrreg1,
    127       1.6    mjacob 	esp_dma_isintr,
    128       1.6    mjacob 	esp_dma_reset,
    129       1.6    mjacob 	esp_dma_intr,
    130       1.6    mjacob 	esp_dma_setup,
    131       1.6    mjacob 	esp_dma_go,
    132       1.6    mjacob 	esp_dma_stop,
    133       1.6    mjacob 	esp_dma_isactive,
    134       1.6    mjacob 	NULL,			/* gl_clear_latched_intr */
    135       1.6    mjacob };
    136       1.6    mjacob 
    137       1.6    mjacob static void	espattach __P((struct esp_softc *, struct ncr53c9x_glue *));
    138       1.6    mjacob 
    139       1.1        pk int
    140       1.1        pk espmatch_sbus(parent, cf, aux)
    141       1.1        pk 	struct device *parent;
    142       1.1        pk 	struct cfdata *cf;
    143       1.1        pk 	void *aux;
    144       1.1        pk {
    145       1.6    mjacob 	int rv;
    146       1.1        pk 	struct sbus_attach_args *sa = aux;
    147       1.1        pk 
    148  1.12.2.1   nathanw 	if (strcmp("SUNW,fas", sa->sa_name) == 0)
    149  1.12.2.1   nathanw 	        return 1;
    150  1.12.2.1   nathanw 
    151       1.6    mjacob 	rv = (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
    152       1.6    mjacob 	    strcmp("ptscII", sa->sa_name) == 0);
    153       1.6    mjacob 	return (rv);
    154       1.1        pk }
    155       1.1        pk 
    156       1.1        pk void
    157       1.1        pk espattach_sbus(parent, self, aux)
    158       1.1        pk 	struct device *parent, *self;
    159       1.1        pk 	void *aux;
    160       1.1        pk {
    161       1.1        pk 	struct esp_softc *esc = (void *)self;
    162       1.1        pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    163       1.1        pk 	struct sbus_attach_args *sa = aux;
    164  1.12.2.1   nathanw 	struct lsi64854_softc *lsc;
    165  1.12.2.1   nathanw 	int burst, sbusburst;
    166       1.1        pk 
    167       1.1        pk 	esc->sc_bustag = sa->sa_bustag;
    168       1.1        pk 	esc->sc_dmatag = sa->sa_dmatag;
    169       1.1        pk 
    170  1.12.2.4   nathanw 	sc->sc_id = PROM_getpropint(sa->sa_node, "initiator-id", 7);
    171  1.12.2.4   nathanw 	sc->sc_freq = PROM_getpropint(sa->sa_node, "clock-frequency", -1);
    172       1.1        pk 	if (sc->sc_freq < 0)
    173       1.1        pk 		sc->sc_freq = ((struct sbus_softc *)
    174       1.1        pk 		    sc->sc_dev.dv_parent)->sc_clockfreq;
    175       1.1        pk 
    176  1.12.2.1   nathanw #ifdef ESP_SBUS_DEBUG
    177  1.12.2.1   nathanw 	printf("%s: espattach_sbus: sc_id %d, freq %d\n",
    178  1.12.2.1   nathanw 	       self->dv_xname, sc->sc_id, sc->sc_freq);
    179  1.12.2.1   nathanw #endif
    180  1.12.2.1   nathanw 
    181  1.12.2.1   nathanw 	if (strcmp("SUNW,fas", sa->sa_name) == 0) {
    182  1.12.2.1   nathanw 
    183  1.12.2.1   nathanw 		/*
    184  1.12.2.1   nathanw 		 * fas has 2 register spaces: dma(lsi64854) and SCSI core (ncr53c9x)
    185  1.12.2.1   nathanw 		 */
    186  1.12.2.1   nathanw 		if (sa->sa_nreg != 2) {
    187  1.12.2.1   nathanw 			printf("%s: %d register spaces\n", self->dv_xname, sa->sa_nreg);
    188  1.12.2.1   nathanw 			return;
    189  1.12.2.1   nathanw 		}
    190  1.12.2.1   nathanw 
    191  1.12.2.1   nathanw 		/*
    192  1.12.2.1   nathanw 		 * allocate space for dma, in SUNW,fas there are no separate
    193  1.12.2.1   nathanw 		 * dma device
    194  1.12.2.1   nathanw 		 */
    195  1.12.2.1   nathanw 		lsc = malloc(sizeof (struct lsi64854_softc), M_DEVBUF, M_NOWAIT);
    196  1.12.2.1   nathanw 
    197  1.12.2.1   nathanw 		if (lsc == NULL) {
    198  1.12.2.1   nathanw 			printf("%s: out of memory (lsi64854_softc)\n",
    199  1.12.2.1   nathanw 			       self->dv_xname);
    200  1.12.2.1   nathanw 			return;
    201  1.12.2.1   nathanw 		}
    202  1.12.2.1   nathanw 		esc->sc_dma = lsc;
    203  1.12.2.1   nathanw 
    204  1.12.2.1   nathanw 		lsc->sc_bustag = sa->sa_bustag;
    205  1.12.2.1   nathanw 		lsc->sc_dmatag = sa->sa_dmatag;
    206  1.12.2.1   nathanw 
    207  1.12.2.1   nathanw 		bcopy(sc->sc_dev.dv_xname, lsc->sc_dev.dv_xname,
    208  1.12.2.1   nathanw 		      sizeof (lsc->sc_dev.dv_xname));
    209  1.12.2.1   nathanw 
    210  1.12.2.1   nathanw 		/* Map dma registers */
    211  1.12.2.1   nathanw 		if (bus_space_map2(sa->sa_bustag,
    212  1.12.2.1   nathanw 		                   sa->sa_reg[0].sbr_slot,
    213  1.12.2.1   nathanw 			           sa->sa_reg[0].sbr_offset,
    214  1.12.2.1   nathanw 			           sa->sa_reg[0].sbr_size,
    215  1.12.2.1   nathanw 			           BUS_SPACE_MAP_LINEAR,
    216  1.12.2.1   nathanw 			           0, &lsc->sc_regs) != 0) {
    217  1.12.2.1   nathanw 			printf("%s: cannot map dma registers\n", self->dv_xname);
    218  1.12.2.1   nathanw 			return;
    219  1.12.2.1   nathanw 		}
    220  1.12.2.1   nathanw 
    221  1.12.2.1   nathanw 		/*
    222  1.12.2.1   nathanw 		 * XXX is this common(from bpp.c), the same in dma_sbus...etc.
    223  1.12.2.1   nathanw 		 *
    224  1.12.2.1   nathanw 		 * Get transfer burst size from PROM and plug it into the
    225  1.12.2.1   nathanw 		 * controller registers. This is needed on the Sun4m; do
    226  1.12.2.1   nathanw 		 * others need it too?
    227  1.12.2.1   nathanw 		 */
    228  1.12.2.1   nathanw 		sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    229  1.12.2.1   nathanw 		if (sbusburst == 0)
    230  1.12.2.1   nathanw 			sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    231  1.12.2.1   nathanw 
    232  1.12.2.4   nathanw 		burst = PROM_getpropint(sa->sa_node, "burst-sizes", -1);
    233  1.12.2.1   nathanw 
    234  1.12.2.1   nathanw #if ESP_SBUS_DEBUG
    235  1.12.2.1   nathanw 		printf("espattach_sbus: burst 0x%x, sbus 0x%x\n",
    236  1.12.2.1   nathanw 		    burst, sbusburst);
    237  1.12.2.1   nathanw #endif
    238  1.12.2.1   nathanw 
    239  1.12.2.1   nathanw 		if (burst == -1)
    240  1.12.2.1   nathanw 			/* take SBus burst sizes */
    241  1.12.2.1   nathanw 			burst = sbusburst;
    242  1.12.2.1   nathanw 
    243  1.12.2.1   nathanw 		/* Clamp at parent's burst sizes */
    244  1.12.2.1   nathanw 		burst &= sbusburst;
    245  1.12.2.1   nathanw 		lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
    246  1.12.2.1   nathanw 		    (burst & SBUS_BURST_16) ? 16 : 0;
    247  1.12.2.1   nathanw 
    248  1.12.2.1   nathanw 		lsc->sc_channel = L64854_CHANNEL_SCSI;
    249  1.12.2.1   nathanw 		lsc->sc_client = sc;
    250  1.12.2.1   nathanw 
    251  1.12.2.1   nathanw 		lsi64854_attach(lsc);
    252  1.12.2.1   nathanw 
    253  1.12.2.1   nathanw 		/*
    254  1.12.2.1   nathanw 		 * map SCSI core registers
    255  1.12.2.1   nathanw 		 */
    256  1.12.2.1   nathanw 		if (sbus_bus_map(sa->sa_bustag,
    257  1.12.2.1   nathanw 				 sa->sa_reg[1].sbr_slot,
    258  1.12.2.1   nathanw 				 sa->sa_reg[1].sbr_offset,
    259  1.12.2.1   nathanw 				 sa->sa_reg[1].sbr_size,
    260  1.12.2.1   nathanw 				 BUS_SPACE_MAP_LINEAR,
    261  1.12.2.1   nathanw 				 0, &esc->sc_reg) != 0) {
    262  1.12.2.1   nathanw 			printf("%s @ sbus: cannot map scsi core registers\n",
    263  1.12.2.1   nathanw 			       self->dv_xname);
    264  1.12.2.1   nathanw 			return;
    265  1.12.2.1   nathanw 		}
    266  1.12.2.1   nathanw 
    267  1.12.2.1   nathanw 		if (sa->sa_nintr == 0) {
    268  1.12.2.1   nathanw 			printf("\n%s: no interrupt property\n", self->dv_xname);
    269  1.12.2.1   nathanw 			return;
    270  1.12.2.1   nathanw 		}
    271  1.12.2.1   nathanw 
    272  1.12.2.1   nathanw 		esc->sc_pri = sa->sa_pri;
    273  1.12.2.1   nathanw 
    274  1.12.2.1   nathanw 		/* add me to the sbus structures */
    275  1.12.2.1   nathanw 		esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
    276  1.12.2.1   nathanw 		sbus_establish(&esc->sc_sd, &sc->sc_dev);
    277  1.12.2.1   nathanw 
    278  1.12.2.1   nathanw 		espattach(esc, &esp_sbus_glue);
    279  1.12.2.1   nathanw 
    280  1.12.2.1   nathanw 		return;
    281  1.12.2.1   nathanw 	}
    282  1.12.2.1   nathanw 
    283       1.1        pk 	/*
    284       1.1        pk 	 * Find the DMA by poking around the dma device structures
    285       1.1        pk 	 *
    286       1.1        pk 	 * What happens here is that if the dma driver has not been
    287       1.1        pk 	 * configured, then this returns a NULL pointer. Then when the
    288       1.1        pk 	 * dma actually gets configured, it does the opposing test, and
    289       1.1        pk 	 * if the sc->sc_esp field in it's softc is NULL, then tries to
    290       1.1        pk 	 * find the matching esp driver.
    291       1.1        pk 	 */
    292       1.1        pk 	esc->sc_dma = (struct lsi64854_softc *)
    293       1.1        pk 				getdevunit("dma", sc->sc_dev.dv_unit);
    294       1.1        pk 
    295       1.1        pk 	/*
    296       1.1        pk 	 * and a back pointer to us, for DMA
    297       1.1        pk 	 */
    298       1.1        pk 	if (esc->sc_dma)
    299       1.2        pk 		esc->sc_dma->sc_client = sc;
    300       1.1        pk 	else {
    301       1.1        pk 		printf("\n");
    302       1.1        pk 		panic("espattach: no dma found");
    303       1.1        pk 	}
    304  1.12.2.3   nathanw 
    305  1.12.2.3   nathanw 	/*
    306  1.12.2.3   nathanw 	 * The `ESC' DMA chip must be reset before we can access
    307  1.12.2.3   nathanw 	 * the esp registers.
    308  1.12.2.3   nathanw 	 */
    309  1.12.2.3   nathanw 	if (esc->sc_dma->sc_rev == DMAREV_ESC)
    310  1.12.2.3   nathanw 		DMA_RESET(esc->sc_dma);
    311       1.1        pk 
    312       1.1        pk 	/*
    313       1.1        pk 	 * Map my registers in, if they aren't already in virtual
    314       1.1        pk 	 * address space.
    315       1.1        pk 	 */
    316       1.1        pk 	if (sa->sa_npromvaddrs)
    317       1.1        pk 		esc->sc_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
    318       1.1        pk 	else {
    319       1.1        pk 		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    320       1.1        pk 				 sa->sa_offset,
    321       1.1        pk 				 sa->sa_size,
    322       1.1        pk 				 BUS_SPACE_MAP_LINEAR,
    323       1.2        pk 				 0, &esc->sc_reg) != 0) {
    324       1.1        pk 			printf("%s @ sbus: cannot map registers\n",
    325       1.1        pk 				self->dv_xname);
    326       1.1        pk 			return;
    327       1.1        pk 		}
    328       1.1        pk 	}
    329       1.1        pk 
    330       1.7        pk 	if (sa->sa_nintr == 0) {
    331       1.7        pk 		/*
    332       1.7        pk 		 * No interrupt properties: we quit; this might
    333       1.7        pk 		 * happen on e.g. a Sparc X terminal.
    334       1.7        pk 		 */
    335       1.7        pk 		printf("\n%s: no interrupt property\n", self->dv_xname);
    336       1.7        pk 		return;
    337       1.7        pk 	}
    338       1.7        pk 
    339       1.1        pk 	esc->sc_pri = sa->sa_pri;
    340       1.1        pk 
    341       1.1        pk 	/* add me to the sbus structures */
    342       1.1        pk 	esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
    343       1.1        pk 	sbus_establish(&esc->sc_sd, &sc->sc_dev);
    344       1.1        pk 
    345       1.6    mjacob 	if (strcmp("ptscII", sa->sa_name) == 0) {
    346       1.6    mjacob 		espattach(esc, &esp_sbus_glue1);
    347       1.6    mjacob 	} else {
    348       1.6    mjacob 		espattach(esc, &esp_sbus_glue);
    349       1.6    mjacob 	}
    350       1.1        pk }
    351       1.1        pk 
    352       1.1        pk void
    353       1.1        pk espattach_dma(parent, self, aux)
    354       1.1        pk 	struct device *parent, *self;
    355       1.1        pk 	void *aux;
    356       1.1        pk {
    357       1.1        pk 	struct esp_softc *esc = (void *)self;
    358       1.1        pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    359       1.1        pk 	struct sbus_attach_args *sa = aux;
    360       1.1        pk 
    361       1.6    mjacob 	if (strcmp("ptscII", sa->sa_name) == 0) {
    362       1.6    mjacob 		return;
    363       1.6    mjacob 	}
    364       1.6    mjacob 
    365       1.1        pk 	esc->sc_bustag = sa->sa_bustag;
    366       1.1        pk 	esc->sc_dmatag = sa->sa_dmatag;
    367       1.1        pk 
    368  1.12.2.4   nathanw 	sc->sc_id = PROM_getpropint(sa->sa_node, "initiator-id", 7);
    369  1.12.2.4   nathanw 	sc->sc_freq = PROM_getpropint(sa->sa_node, "clock-frequency", -1);
    370       1.1        pk 
    371       1.1        pk 	esc->sc_dma = (struct lsi64854_softc *)parent;
    372       1.2        pk 	esc->sc_dma->sc_client = sc;
    373       1.1        pk 
    374       1.1        pk 	/*
    375       1.1        pk 	 * Map my registers in, if they aren't already in virtual
    376       1.1        pk 	 * address space.
    377       1.1        pk 	 */
    378       1.1        pk 	if (sa->sa_npromvaddrs)
    379       1.1        pk 		esc->sc_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
    380       1.1        pk 	else {
    381       1.1        pk 		if (bus_space_map2(sa->sa_bustag,
    382       1.1        pk 				   sa->sa_slot,
    383       1.1        pk 				   sa->sa_offset,
    384       1.1        pk 				   sa->sa_size,
    385       1.1        pk 				   BUS_SPACE_MAP_LINEAR,
    386       1.2        pk 				   0, &esc->sc_reg) != 0) {
    387       1.1        pk 			printf("%s @ dma: cannot map registers\n",
    388       1.1        pk 				self->dv_xname);
    389       1.1        pk 			return;
    390       1.1        pk 		}
    391       1.1        pk 	}
    392       1.1        pk 
    393       1.7        pk 	if (sa->sa_nintr == 0) {
    394       1.7        pk 		/*
    395       1.7        pk 		 * No interrupt properties: we quit; this might
    396       1.7        pk 		 * happen on e.g. a Sparc X terminal.
    397       1.7        pk 		 */
    398       1.7        pk 		printf("\n%s: no interrupt property\n", self->dv_xname);
    399       1.7        pk 		return;
    400       1.7        pk 	}
    401       1.7        pk 
    402       1.1        pk 	esc->sc_pri = sa->sa_pri;
    403       1.1        pk 
    404       1.1        pk 	/* Assume SBus is grandparent */
    405       1.1        pk 	esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
    406       1.1        pk 	sbus_establish(&esc->sc_sd, parent);
    407       1.1        pk 
    408       1.6    mjacob 	espattach(esc, &esp_sbus_glue);
    409       1.1        pk }
    410       1.1        pk 
    411       1.1        pk 
    412       1.1        pk /*
    413       1.1        pk  * Attach this instance, and then all the sub-devices
    414       1.1        pk  */
    415       1.1        pk void
    416       1.6    mjacob espattach(esc, gluep)
    417       1.1        pk 	struct esp_softc *esc;
    418       1.6    mjacob 	struct ncr53c9x_glue *gluep;
    419       1.1        pk {
    420       1.1        pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    421       1.1        pk 	void *icookie;
    422  1.12.2.1   nathanw 	unsigned int uid = 0;
    423       1.1        pk 
    424       1.1        pk 	/*
    425       1.1        pk 	 * Set up glue for MI code early; we use some of it here.
    426       1.1        pk 	 */
    427       1.6    mjacob 	sc->sc_glue = gluep;
    428       1.1        pk 
    429       1.1        pk 	/* gimme Mhz */
    430       1.1        pk 	sc->sc_freq /= 1000000;
    431       1.1        pk 
    432       1.1        pk 	/*
    433       1.1        pk 	 * XXX More of this should be in ncr53c9x_attach(), but
    434       1.1        pk 	 * XXX should we really poke around the chip that much in
    435       1.1        pk 	 * XXX the MI code?  Think about this more...
    436       1.1        pk 	 */
    437       1.1        pk 
    438       1.1        pk 	/*
    439       1.1        pk 	 * It is necessary to try to load the 2nd config register here,
    440       1.1        pk 	 * to find out what rev the esp chip is, else the ncr53c9x_reset
    441       1.1        pk 	 * will not set up the defaults correctly.
    442       1.1        pk 	 */
    443       1.1        pk 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
    444       1.1        pk 	sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE;
    445  1.12.2.1   nathanw 	sc->sc_cfg3 = NCRCFG3_CDB;
    446       1.1        pk 	NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
    447       1.1        pk 
    448       1.1        pk 	if ((NCR_READ_REG(sc, NCR_CFG2) & ~NCRCFG2_RSVD) !=
    449       1.1        pk 	    (NCRCFG2_SCSI2 | NCRCFG2_RPE)) {
    450       1.1        pk 		sc->sc_rev = NCR_VARIANT_ESP100;
    451       1.1        pk 	} else {
    452       1.1        pk 		sc->sc_cfg2 = NCRCFG2_SCSI2;
    453       1.1        pk 		NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
    454       1.1        pk 		sc->sc_cfg3 = 0;
    455       1.1        pk 		NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
    456  1.12.2.1   nathanw 		sc->sc_cfg3 = (NCRCFG3_CDB | NCRCFG3_FCLK);
    457       1.1        pk 		NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
    458       1.1        pk 		if (NCR_READ_REG(sc, NCR_CFG3) !=
    459       1.1        pk 		    (NCRCFG3_CDB | NCRCFG3_FCLK)) {
    460       1.1        pk 			sc->sc_rev = NCR_VARIANT_ESP100A;
    461       1.1        pk 		} else {
    462       1.1        pk 			/* NCRCFG2_FE enables > 64K transfers */
    463       1.1        pk 			sc->sc_cfg2 |= NCRCFG2_FE;
    464  1.12.2.1   nathanw 			sc->sc_cfg3 = 0;
    465       1.1        pk 			NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
    466       1.1        pk 			sc->sc_rev = NCR_VARIANT_ESP200;
    467  1.12.2.1   nathanw 
    468  1.12.2.1   nathanw 			/* XXX spec says it's valid after power up or chip reset */
    469  1.12.2.1   nathanw 			uid = NCR_READ_REG(sc, NCR_UID);
    470  1.12.2.1   nathanw 			if (((uid & 0xf8) >> 3) == 0x0a) /* XXX */
    471  1.12.2.1   nathanw 				sc->sc_rev = NCR_VARIANT_FAS366;
    472       1.1        pk 		}
    473       1.1        pk 	}
    474       1.1        pk 
    475  1.12.2.1   nathanw #ifdef ESP_SBUS_DEBUG
    476  1.12.2.1   nathanw 	printf("espattach: revision %d, uid 0x%x\n", sc->sc_rev, uid);
    477  1.12.2.1   nathanw #endif
    478  1.12.2.1   nathanw 
    479       1.1        pk 	/*
    480       1.1        pk 	 * XXX minsync and maxxfer _should_ be set up in MI code,
    481       1.1        pk 	 * XXX but it appears to have some dependency on what sort
    482       1.1        pk 	 * XXX of DMA we're hooked up to, etc.
    483       1.1        pk 	 */
    484       1.1        pk 
    485       1.1        pk 	/*
    486       1.1        pk 	 * This is the value used to start sync negotiations
    487       1.1        pk 	 * Note that the NCR register "SYNCTP" is programmed
    488       1.1        pk 	 * in "clocks per byte", and has a minimum value of 4.
    489       1.1        pk 	 * The SCSI period used in negotiation is one-fourth
    490       1.1        pk 	 * of the time (in nanoseconds) needed to transfer one byte.
    491       1.1        pk 	 * Since the chip's clock is given in MHz, we have the following
    492       1.1        pk 	 * formula: 4 * period = (1000 / freq) * 4
    493       1.1        pk 	 */
    494       1.1        pk 	sc->sc_minsync = 1000 / sc->sc_freq;
    495       1.1        pk 
    496       1.1        pk 	/*
    497       1.1        pk 	 * Alas, we must now modify the value a bit, because it's
    498       1.1        pk 	 * only valid when can switch on FASTCLK and FASTSCSI bits
    499       1.1        pk 	 * in config register 3...
    500       1.1        pk 	 */
    501       1.1        pk 	switch (sc->sc_rev) {
    502       1.1        pk 	case NCR_VARIANT_ESP100:
    503       1.1        pk 		sc->sc_maxxfer = 64 * 1024;
    504       1.1        pk 		sc->sc_minsync = 0;	/* No synch on old chip? */
    505       1.1        pk 		break;
    506       1.1        pk 
    507       1.1        pk 	case NCR_VARIANT_ESP100A:
    508       1.1        pk 		sc->sc_maxxfer = 64 * 1024;
    509       1.1        pk 		/* Min clocks/byte is 5 */
    510       1.1        pk 		sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5);
    511       1.1        pk 		break;
    512       1.1        pk 
    513       1.1        pk 	case NCR_VARIANT_ESP200:
    514  1.12.2.1   nathanw 	case NCR_VARIANT_FAS366:
    515       1.1        pk 		sc->sc_maxxfer = 16 * 1024 * 1024;
    516       1.1        pk 		/* XXX - do actually set FAST* bits */
    517       1.1        pk 		break;
    518       1.1        pk 	}
    519       1.1        pk 
    520       1.1        pk 	/* Establish interrupt channel */
    521      1.11        pk 	icookie = bus_intr_establish(esc->sc_bustag, esc->sc_pri, IPL_BIO, 0,
    522      1.10  nisimura 				     ncr53c9x_intr, sc);
    523       1.1        pk 
    524       1.1        pk 	/* register interrupt stats */
    525       1.9       cgd 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    526       1.9       cgd 	    sc->sc_dev.dv_xname, "intr");
    527       1.1        pk 
    528  1.12.2.1   nathanw 	/* Turn on target selection using the `dma' method */
    529  1.12.2.1   nathanw 	if (sc->sc_rev != NCR_VARIANT_FAS366)
    530  1.12.2.1   nathanw 		sc->sc_features |= NCR_F_DMASELECT;
    531  1.12.2.1   nathanw 
    532       1.1        pk 	/* Do the common parts of attachment. */
    533  1.12.2.2   nathanw 	sc->sc_adapter.adapt_minphys = minphys;
    534  1.12.2.2   nathanw 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    535  1.12.2.2   nathanw 	ncr53c9x_attach(sc);
    536  1.12.2.2   nathanw 
    537       1.1        pk }
    538       1.1        pk 
    539       1.1        pk /*
    540       1.1        pk  * Glue functions.
    541       1.1        pk  */
    542       1.1        pk 
    543  1.12.2.1   nathanw #ifdef ESP_SBUS_DEBUG
    544  1.12.2.1   nathanw int esp_sbus_debug = 0;
    545  1.12.2.1   nathanw 
    546  1.12.2.1   nathanw static struct {
    547  1.12.2.1   nathanw 	char *r_name;
    548  1.12.2.1   nathanw 	int   r_flag;
    549  1.12.2.1   nathanw } esp__read_regnames [] = {
    550  1.12.2.1   nathanw 	{ "TCL", 0},			/* 0/00 */
    551  1.12.2.1   nathanw 	{ "TCM", 0},			/* 1/04 */
    552  1.12.2.1   nathanw 	{ "FIFO", 0},			/* 2/08 */
    553  1.12.2.1   nathanw 	{ "CMD", 0},			/* 3/0c */
    554  1.12.2.1   nathanw 	{ "STAT", 0},			/* 4/10 */
    555  1.12.2.1   nathanw 	{ "INTR", 0},			/* 5/14 */
    556  1.12.2.1   nathanw 	{ "STEP", 0},			/* 6/18 */
    557  1.12.2.1   nathanw 	{ "FFLAGS", 1},			/* 7/1c */
    558  1.12.2.1   nathanw 	{ "CFG1", 1},			/* 8/20 */
    559  1.12.2.1   nathanw 	{ "STAT2", 0},			/* 9/24 */
    560  1.12.2.1   nathanw 	{ "CFG4", 1},			/* a/28 */
    561  1.12.2.1   nathanw 	{ "CFG2", 1},			/* b/2c */
    562  1.12.2.1   nathanw 	{ "CFG3", 1},			/* c/30 */
    563  1.12.2.1   nathanw 	{ "-none", 1},			/* d/34 */
    564  1.12.2.1   nathanw 	{ "TCH", 1},			/* e/38 */
    565  1.12.2.1   nathanw 	{ "TCX", 1},			/* f/3c */
    566  1.12.2.1   nathanw };
    567  1.12.2.1   nathanw 
    568  1.12.2.1   nathanw static struct {
    569  1.12.2.1   nathanw 	char *r_name;
    570  1.12.2.1   nathanw 	int   r_flag;
    571  1.12.2.1   nathanw } esp__write_regnames[] = {
    572  1.12.2.1   nathanw 	{ "TCL", 1},			/* 0/00 */
    573  1.12.2.1   nathanw 	{ "TCM", 1},			/* 1/04 */
    574  1.12.2.1   nathanw 	{ "FIFO", 0},			/* 2/08 */
    575  1.12.2.1   nathanw 	{ "CMD", 0},			/* 3/0c */
    576  1.12.2.1   nathanw 	{ "SELID", 1},			/* 4/10 */
    577  1.12.2.1   nathanw 	{ "TIMEOUT", 1},		/* 5/14 */
    578  1.12.2.1   nathanw 	{ "SYNCTP", 1},			/* 6/18 */
    579  1.12.2.1   nathanw 	{ "SYNCOFF", 1},		/* 7/1c */
    580  1.12.2.1   nathanw 	{ "CFG1", 1},			/* 8/20 */
    581  1.12.2.1   nathanw 	{ "CCF", 1},			/* 9/24 */
    582  1.12.2.1   nathanw 	{ "TEST", 1},			/* a/28 */
    583  1.12.2.1   nathanw 	{ "CFG2", 1},			/* b/2c */
    584  1.12.2.1   nathanw 	{ "CFG3", 1},			/* c/30 */
    585  1.12.2.1   nathanw 	{ "-none", 1},			/* d/34 */
    586  1.12.2.1   nathanw 	{ "TCH", 1},			/* e/38 */
    587  1.12.2.1   nathanw 	{ "TCX", 1},			/* f/3c */
    588  1.12.2.1   nathanw };
    589  1.12.2.1   nathanw #endif
    590  1.12.2.1   nathanw 
    591       1.1        pk u_char
    592       1.1        pk esp_read_reg(sc, reg)
    593       1.1        pk 	struct ncr53c9x_softc *sc;
    594       1.1        pk 	int reg;
    595       1.1        pk {
    596       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    597  1.12.2.1   nathanw 	u_char v;
    598       1.1        pk 
    599  1.12.2.1   nathanw 	v = bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg * 4);
    600  1.12.2.1   nathanw #ifdef ESP_SBUS_DEBUG
    601  1.12.2.1   nathanw 	if (esp_sbus_debug && (reg < 0x10) && esp__read_regnames[reg].r_flag)
    602  1.12.2.1   nathanw 		printf("RD:%x <%s> %x\n", reg * 4,
    603  1.12.2.1   nathanw 		    ((unsigned)reg < 0x10) ? esp__read_regnames[reg].r_name : "<***>", v);
    604  1.12.2.1   nathanw #endif
    605  1.12.2.1   nathanw 	return v;
    606       1.1        pk }
    607       1.1        pk 
    608       1.1        pk void
    609       1.1        pk esp_write_reg(sc, reg, v)
    610       1.1        pk 	struct ncr53c9x_softc *sc;
    611       1.1        pk 	int reg;
    612       1.1        pk 	u_char v;
    613       1.1        pk {
    614       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    615       1.1        pk 
    616  1.12.2.1   nathanw #ifdef ESP_SBUS_DEBUG
    617  1.12.2.1   nathanw 	if (esp_sbus_debug && (reg < 0x10) && esp__write_regnames[reg].r_flag)
    618  1.12.2.1   nathanw 		printf("WR:%x <%s> %x\n", reg * 4,
    619  1.12.2.1   nathanw 		    ((unsigned)reg < 0x10) ? esp__write_regnames[reg].r_name : "<***>", v);
    620  1.12.2.1   nathanw #endif
    621       1.1        pk 	bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg * 4, v);
    622       1.6    mjacob }
    623       1.6    mjacob 
    624       1.6    mjacob u_char
    625       1.6    mjacob esp_rdreg1(sc, reg)
    626       1.6    mjacob 	struct ncr53c9x_softc *sc;
    627       1.6    mjacob 	int reg;
    628       1.6    mjacob {
    629       1.6    mjacob 	struct esp_softc *esc = (struct esp_softc *)sc;
    630       1.6    mjacob 
    631       1.6    mjacob 	return (bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg));
    632       1.6    mjacob }
    633       1.6    mjacob 
    634       1.6    mjacob void
    635       1.6    mjacob esp_wrreg1(sc, reg, v)
    636       1.6    mjacob 	struct ncr53c9x_softc *sc;
    637       1.6    mjacob 	int reg;
    638       1.6    mjacob 	u_char v;
    639       1.6    mjacob {
    640       1.6    mjacob 	struct esp_softc *esc = (struct esp_softc *)sc;
    641       1.6    mjacob 
    642       1.6    mjacob 	bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg, v);
    643       1.1        pk }
    644       1.1        pk 
    645       1.1        pk int
    646       1.1        pk esp_dma_isintr(sc)
    647       1.1        pk 	struct ncr53c9x_softc *sc;
    648       1.1        pk {
    649       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    650       1.1        pk 
    651       1.1        pk 	return (DMA_ISINTR(esc->sc_dma));
    652       1.1        pk }
    653       1.1        pk 
    654       1.1        pk void
    655       1.1        pk esp_dma_reset(sc)
    656       1.1        pk 	struct ncr53c9x_softc *sc;
    657       1.1        pk {
    658       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    659       1.1        pk 
    660       1.1        pk 	DMA_RESET(esc->sc_dma);
    661       1.1        pk }
    662       1.1        pk 
    663       1.1        pk int
    664       1.1        pk esp_dma_intr(sc)
    665       1.1        pk 	struct ncr53c9x_softc *sc;
    666       1.1        pk {
    667       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    668       1.1        pk 
    669       1.1        pk 	return (DMA_INTR(esc->sc_dma));
    670       1.1        pk }
    671       1.1        pk 
    672       1.1        pk int
    673       1.1        pk esp_dma_setup(sc, addr, len, datain, dmasize)
    674       1.1        pk 	struct ncr53c9x_softc *sc;
    675       1.1        pk 	caddr_t *addr;
    676       1.1        pk 	size_t *len;
    677       1.1        pk 	int datain;
    678       1.1        pk 	size_t *dmasize;
    679       1.1        pk {
    680       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    681       1.1        pk 
    682       1.1        pk 	return (DMA_SETUP(esc->sc_dma, addr, len, datain, dmasize));
    683       1.1        pk }
    684       1.1        pk 
    685       1.1        pk void
    686       1.1        pk esp_dma_go(sc)
    687       1.1        pk 	struct ncr53c9x_softc *sc;
    688       1.1        pk {
    689       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    690       1.1        pk 
    691       1.1        pk 	DMA_GO(esc->sc_dma);
    692       1.1        pk }
    693       1.1        pk 
    694       1.1        pk void
    695       1.1        pk esp_dma_stop(sc)
    696       1.1        pk 	struct ncr53c9x_softc *sc;
    697       1.1        pk {
    698       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    699       1.1        pk 	u_int32_t csr;
    700       1.1        pk 
    701       1.1        pk 	csr = L64854_GCSR(esc->sc_dma);
    702       1.1        pk 	csr &= ~D_EN_DMA;
    703       1.1        pk 	L64854_SCSR(esc->sc_dma, csr);
    704       1.1        pk }
    705       1.1        pk 
    706       1.1        pk int
    707       1.1        pk esp_dma_isactive(sc)
    708       1.1        pk 	struct ncr53c9x_softc *sc;
    709       1.1        pk {
    710       1.1        pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    711       1.1        pk 
    712       1.1        pk 	return (DMA_ISACTIVE(esc->sc_dma));
    713       1.1        pk }
    714      1.12       eeh 
    715      1.12       eeh #include "opt_ddb.h"
    716      1.12       eeh #ifdef DDB
    717      1.12       eeh #include <machine/db_machdep.h>
    718      1.12       eeh #include <ddb/db_output.h>
    719      1.12       eeh 
    720      1.12       eeh void db_esp __P((db_expr_t, int, db_expr_t, char*));
    721      1.12       eeh 
    722      1.12       eeh void
    723      1.12       eeh db_esp(addr, have_addr, count, modif)
    724      1.12       eeh 	db_expr_t addr;
    725      1.12       eeh 	int have_addr;
    726      1.12       eeh 	db_expr_t count;
    727      1.12       eeh 	char *modif;
    728      1.12       eeh {
    729      1.12       eeh 	struct ncr53c9x_softc *sc;
    730      1.12       eeh 	struct ncr53c9x_ecb *ecb;
    731      1.12       eeh 	struct ncr53c9x_linfo *li;
    732      1.12       eeh 	int u, t, i;
    733      1.12       eeh 
    734      1.12       eeh 	for (u=0; u<10; u++) {
    735      1.12       eeh 		sc = (struct ncr53c9x_softc *)
    736      1.12       eeh 			getdevunit("esp", u);
    737      1.12       eeh 		if (!sc) continue;
    738      1.12       eeh 
    739      1.12       eeh 		db_printf("esp%d: nexus %p phase %x prev %x dp %p dleft %lx ify %x\n",
    740      1.12       eeh 			  u, sc->sc_nexus, sc->sc_phase, sc->sc_prevphase,
    741      1.12       eeh 			  sc->sc_dp, sc->sc_dleft, sc->sc_msgify);
    742      1.12       eeh 		db_printf("\tmsgout %x msgpriq %x msgin %x:%x:%x:%x:%x\n",
    743      1.12       eeh 			  sc->sc_msgout, sc->sc_msgpriq, sc->sc_imess[0],
    744      1.12       eeh 			  sc->sc_imess[1], sc->sc_imess[2], sc->sc_imess[3],
    745      1.12       eeh 			  sc->sc_imess[0]);
    746      1.12       eeh 		db_printf("ready: ");
    747      1.12       eeh 		for (ecb = sc->ready_list.tqh_first; ecb; ecb = ecb->chain.tqe_next) {
    748      1.12       eeh 			db_printf("ecb %p ", ecb);
    749      1.12       eeh 			if (ecb == ecb->chain.tqe_next) {
    750      1.12       eeh 				db_printf("\nWARNING: tailq loop on ecb %p", ecb);
    751      1.12       eeh 				break;
    752      1.12       eeh 			}
    753      1.12       eeh 		}
    754      1.12       eeh 		db_printf("\n");
    755      1.12       eeh 
    756      1.12       eeh 		for (t=0; t<NCR_NTARG; t++) {
    757      1.12       eeh 			LIST_FOREACH(li, &sc->sc_tinfo[t].luns, link) {
    758      1.12       eeh 				db_printf("t%d lun %d untagged %p busy %d used %x\n",
    759      1.12       eeh 					  t, (int)li->lun, li->untagged, li->busy,
    760      1.12       eeh 					  li->used);
    761      1.12       eeh 				for (i=0; i<256; i++)
    762      1.12       eeh 					if ((ecb = li->queued[i])) {
    763      1.12       eeh 						db_printf("ecb %p tag %x\n", ecb, i);
    764      1.12       eeh 					}
    765      1.12       eeh 			}
    766      1.12       eeh 		}
    767      1.12       eeh 	}
    768      1.12       eeh }
    769      1.12       eeh #endif
    770  1.12.2.1   nathanw 
    771