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