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