1 /* $NetBSD: siop2.c,v 1.19 2002/02/24 15:20:06 is Exp $ */ 2 3 /* 4 * Copyright (c) 1994,1998 Michael L. Hitch 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Van Jacobson of Lawrence Berkeley Laboratory. 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 University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)siop.c 7.5 (Berkeley) 5/4/91 40 */ 41 42 /* 43 * AMIGA 53C720/770 scsi adaptor driver 44 */ 45 46 #include "opt_ddb.h" 47 48 #include <sys/cdefs.h> 49 __KERNEL_RCSID(0, "$NetBSD: siop2.c,v 1.19 2002/02/24 15:20:06 is Exp $"); 50 51 #include <sys/param.h> 52 #include <sys/systm.h> 53 #include <sys/device.h> 54 #include <sys/disklabel.h> 55 #include <sys/dkstat.h> 56 #include <sys/buf.h> 57 #include <sys/malloc.h> 58 #include <dev/scsipi/scsi_all.h> 59 #include <dev/scsipi/scsipi_all.h> 60 #include <dev/scsipi/scsiconf.h> 61 #include <machine/cpu.h> 62 #ifdef __m68k__ 63 #include <m68k/include/cacheops.h> 64 #endif 65 #include <amiga/amiga/custom.h> 66 #include <amiga/amiga/isr.h> 67 68 #define ARCH_720 69 70 #include <amiga/dev/siopreg.h> 71 #include <amiga/dev/siopvar.h> 72 73 /* 74 * SCSI delays 75 * In u-seconds, primarily for state changes on the SPC. 76 */ 77 #define SCSI_CMD_WAIT 500000 /* wait per step of 'immediate' cmds */ 78 #define SCSI_DATA_WAIT 500000 /* wait per data in/out step */ 79 #define SCSI_INIT_WAIT 500000 /* wait per step (both) during init */ 80 81 void siopng_select(struct siop_softc *); 82 void siopngabort(struct siop_softc *, siop_regmap_p, char *); 83 void siopngerror(struct siop_softc *, siop_regmap_p, u_char); 84 int siopng_checkintr(struct siop_softc *, u_char, u_char, u_short, int *); 85 void siopngreset(struct siop_softc *); 86 void siopngsetdelay(int); 87 void siopng_scsidone(struct siop_acb *, int); 88 void siopng_sched(struct siop_softc *); 89 void siopng_poll(struct siop_softc *, struct siop_acb *); 90 void siopngintr(struct siop_softc *); 91 void scsi_period_to_siopng(struct siop_softc *, int); 92 void siopng_start(struct siop_softc *, int, int, u_char *, int, u_char *, int); 93 void siopng_dump_acb(struct siop_acb *); 94 95 /* 53C720/770 script */ 96 97 #include <amiga/dev/siop2_script.out> 98 99 /* default to not inhibit sync negotiation on any drive */ 100 u_char siopng_inhibit_sync[16] = { 101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 102 }; /* initialize, so patchable */ 103 104 u_char siopng_inhibit_wide[16] = { 105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 106 }; /* initialize, so patchable */ 107 108 u_char siopng_allow_disc[16] = { 109 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 110 }; 111 112 int siopng_no_dma = 0; 113 114 int siopng_reset_delay = 250; /* delay after reset, in milleseconds */ 115 116 int siopng_cmd_wait = SCSI_CMD_WAIT; 117 int siopng_data_wait = SCSI_DATA_WAIT; 118 int siopng_init_wait = SCSI_INIT_WAIT; 119 120 #define DEBUG_SYNC 121 122 #ifdef DEBUG 123 /* 124 * 0x01 - full debug 125 * 0x02 - DMA chaining 126 * 0x04 - siopngintr 127 * 0x08 - phase mismatch 128 * 0x10 - <not used> 129 * 0x20 - panic on unhandled exceptions 130 * 0x100 - disconnect/reselect 131 */ 132 int siopng_debug = 0; 133 int siopngsync_debug = 0; 134 int siopngdma_hits = 0; 135 int siopngdma_misses = 0; 136 int siopngchain_ints = 0; 137 int siopngstarts = 0; 138 int siopngints = 0; 139 int siopngphmm = 0; 140 #define SIOP_TRACE_SIZE 128 141 #define SIOP_TRACE(a,b,c,d) \ 142 siopng_trbuf[siopng_trix] = (a); \ 143 siopng_trbuf[siopng_trix+1] = (b); \ 144 siopng_trbuf[siopng_trix+2] = (c); \ 145 siopng_trbuf[siopng_trix+3] = (d); \ 146 siopng_trix = (siopng_trix + 4) & (SIOP_TRACE_SIZE - 1); 147 u_char siopng_trbuf[SIOP_TRACE_SIZE]; 148 int siopng_trix; 149 void siopng_dump(struct siop_softc *); 150 void siopng_dump_trace(void); 151 #else 152 #define SIOP_TRACE(a,b,c,d) 153 #endif 154 155 156 static char *siopng_chips[] = { 157 "720", "720SE", "770", "0x3", 158 "810A", "0x5", "0x6", "0x7", 159 "0x8", "0x9", "0xA", "0xB", 160 "0xC", "0xD", "0xE", "0xF", 161 }; 162 163 /* 164 * default minphys routine for siopng based controllers 165 */ 166 void 167 siopng_minphys(struct buf *bp) 168 { 169 170 /* 171 * No max transfer at this level. 172 */ 173 minphys(bp); 174 } 175 176 /* 177 * used by specific siopng controller 178 * 179 */ 180 void 181 siopng_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req, 182 void *arg) 183 { 184 struct scsipi_xfer *xs; 185 struct scsipi_periph *periph; 186 struct siop_acb *acb; 187 struct siop_softc *sc = (void *)chan->chan_adapter->adapt_dev; 188 int flags, s; 189 190 switch (req) { 191 case ADAPTER_REQ_RUN_XFER: 192 xs = arg; 193 periph = xs->xs_periph; 194 flags = xs->xs_control; 195 196 /* XXXX ?? */ 197 if (flags & XS_CTL_DATA_UIO) 198 panic("siopng: scsi data uio requested"); 199 200 /* XXXX ?? */ 201 if (sc->sc_nexus && flags & XS_CTL_POLL) 202 /* panic("siopng_scsicmd: busy");*/ 203 printf("siopng_scsicmd: busy\n"); 204 205 s = splbio(); 206 acb = sc->free_list.tqh_first; 207 if (acb) { 208 TAILQ_REMOVE(&sc->free_list, acb, chain); 209 } 210 splx(s); 211 212 #ifdef DIAGNOSTIC 213 /* 214 * This should never happen as we track the resources 215 * in the mid-layer. 216 */ 217 if (acb == NULL) { 218 scsipi_printaddr(periph); 219 printf("unable to allocate acb\n"); 220 panic("siopng_scsipi_request"); 221 } 222 #endif 223 acb->flags = ACB_ACTIVE; 224 acb->xs = xs; 225 bcopy(xs->cmd, &acb->cmd, xs->cmdlen); 226 acb->clen = xs->cmdlen; 227 acb->daddr = xs->data; 228 acb->dleft = xs->datalen; 229 230 s = splbio(); 231 TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain); 232 233 if (sc->sc_nexus == NULL) 234 siopng_sched(sc); 235 236 splx(s); 237 238 if (flags & XS_CTL_POLL || siopng_no_dma) 239 siopng_poll(sc, acb); 240 return; 241 242 case ADAPTER_REQ_GROW_RESOURCES: 243 return; 244 245 case ADAPTER_REQ_SET_XFER_MODE: 246 return; 247 } 248 } 249 250 void 251 siopng_poll(struct siop_softc *sc, struct siop_acb *acb) 252 { 253 siop_regmap_p rp = sc->sc_siopp; 254 struct scsipi_xfer *xs = acb->xs; 255 int i; 256 int status; 257 u_char istat; 258 u_char dstat; 259 u_short sist; 260 int s; 261 int to; 262 263 s = splbio(); 264 to = xs->timeout / 1000; 265 if (sc->nexus_list.tqh_first) 266 printf("%s: siopng_poll called with disconnected device\n", 267 sc->sc_dev.dv_xname); 268 for (;;) { 269 /* use cmd_wait values? */ 270 i = 50000; 271 /* XXX spl0(); */ 272 while (((istat = rp->siop_istat) & 273 (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) { 274 if (--i <= 0) { 275 #ifdef DEBUG 276 printf ("waiting: tgt %d cmd %02x sbcl %02x istat %02x sbdl %04x\n dsp %lx (+%lx) dcmd %lx ds %p timeout %d\n", 277 xs->xs_periph->periph_target, acb->cmd.opcode, 278 rp->siop_sbcl, istat, rp->siop_sbdl, rp->siop_dsp, 279 rp->siop_dsp - sc->sc_scriptspa, 280 *((long *)&rp->siop_dcmd), &acb->ds, acb->xs->timeout); 281 #endif 282 i = 50000; 283 --to; 284 if (to <= 0) { 285 siopngreset(sc); 286 return; 287 } 288 } 289 delay(20); 290 } 291 sist = rp->siop_sist; 292 dstat = rp->siop_dstat; 293 if (siopng_checkintr(sc, istat, dstat, sist, &status)) { 294 if (acb != sc->sc_nexus) 295 printf("%s: siopng_poll disconnected device completed\n", 296 sc->sc_dev.dv_xname); 297 else if ((sc->sc_flags & SIOP_INTDEFER) == 0) { 298 sc->sc_flags &= ~SIOP_INTSOFF; 299 rp->siop_sien = sc->sc_sien; 300 rp->siop_dien = sc->sc_dien; 301 } 302 siopng_scsidone(sc->sc_nexus, status); 303 } 304 if (xs->xs_status & XS_STS_DONE) 305 break; 306 } 307 splx(s); 308 } 309 310 /* 311 * start next command that's ready 312 */ 313 void 314 siopng_sched(struct siop_softc *sc) 315 { 316 struct scsipi_periph *periph; 317 struct siop_acb *acb; 318 int i; 319 320 #ifdef DEBUG 321 if (sc->sc_nexus) { 322 printf("%s: siopng_sched- nexus %p/%d ready %p/%d\n", 323 sc->sc_dev.dv_xname, sc->sc_nexus, 324 sc->sc_nexus->xs->xs_periph->periph_target, 325 sc->ready_list.tqh_first, 326 sc->ready_list.tqh_first->xs->xs_periph->periph_target); 327 return; 328 } 329 #endif 330 for (acb = sc->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) { 331 periph = acb->xs->xs_periph; 332 i = periph->periph_target; 333 if(!(sc->sc_tinfo[i].lubusy & (1 << periph->periph_lun))) { 334 struct siop_tinfo *ti = &sc->sc_tinfo[i]; 335 336 TAILQ_REMOVE(&sc->ready_list, acb, chain); 337 sc->sc_nexus = acb; 338 periph = acb->xs->xs_periph; 339 ti = &sc->sc_tinfo[periph->periph_target]; 340 ti->lubusy |= (1 << periph->periph_lun); 341 break; 342 } 343 } 344 345 if (acb == NULL) { 346 #ifdef DEBUGXXX 347 printf("%s: siopng_sched didn't find ready command\n", 348 sc->sc_dev.dv_xname); 349 #endif 350 return; 351 } 352 353 if (acb->xs->xs_control & XS_CTL_RESET) 354 siopngreset(sc); 355 356 #if 0 357 acb->cmd.bytes[0] |= periph->periph_lun << 5; /* XXXX */ 358 #endif 359 ++sc->sc_active; 360 siopng_select(sc); 361 } 362 363 void 364 siopng_scsidone(struct siop_acb *acb, int stat) 365 { 366 struct scsipi_xfer *xs; 367 struct scsipi_periph *periph; 368 struct siop_softc *sc; 369 int dosched = 0; 370 371 if (acb == NULL || (xs = acb->xs) == NULL) { 372 #ifdef DIAGNOSTIC 373 printf("siopng_scsidone: NULL acb or scsipi_xfer\n"); 374 #if defined(DEBUG) && defined(DDB) 375 Debugger(); 376 #endif 377 #endif 378 return; 379 } 380 periph = xs->xs_periph; 381 sc = (void *)periph->periph_channel->chan_adapter->adapt_dev; 382 383 xs->status = stat; 384 xs->resid = 0; /* XXXX */ 385 386 if (xs->error == XS_NOERROR) { 387 if (stat == SCSI_CHECK || stat == SCSI_BUSY) 388 xs->error = XS_BUSY; 389 } 390 391 /* 392 * Remove the ACB from whatever queue it's on. We have to do a bit of 393 * a hack to figure out which queue it's on. Note that it is *not* 394 * necessary to cdr down the ready queue, but we must cdr down the 395 * nexus queue and see if it's there, so we can mark the unit as no 396 * longer busy. This code is sickening, but it works. 397 */ 398 if (acb == sc->sc_nexus) { 399 sc->sc_nexus = NULL; 400 sc->sc_tinfo[periph->periph_target].lubusy &= 401 ~(1<<periph->periph_lun); 402 if (sc->ready_list.tqh_first) 403 dosched = 1; /* start next command */ 404 --sc->sc_active; 405 SIOP_TRACE('d','a',stat,0) 406 } else if (sc->ready_list.tqh_last == &acb->chain.tqe_next) { 407 TAILQ_REMOVE(&sc->ready_list, acb, chain); 408 SIOP_TRACE('d','r',stat,0) 409 } else { 410 register struct siop_acb *acb2; 411 for (acb2 = sc->nexus_list.tqh_first; acb2; 412 acb2 = acb2->chain.tqe_next) 413 if (acb2 == acb) { 414 TAILQ_REMOVE(&sc->nexus_list, acb, chain); 415 sc->sc_tinfo[periph->periph_target].lubusy 416 &= ~(1<<periph->periph_lun); 417 --sc->sc_active; 418 break; 419 } 420 if (acb2) 421 ; 422 else if (acb->chain.tqe_next) { 423 TAILQ_REMOVE(&sc->ready_list, acb, chain); 424 --sc->sc_active; 425 } else { 426 printf("%s: can't find matching acb\n", 427 sc->sc_dev.dv_xname); 428 #ifdef DDB 429 /* Debugger(); */ 430 #endif 431 } 432 SIOP_TRACE('d','n',stat,0); 433 } 434 /* Put it on the free list. */ 435 acb->flags = ACB_FREE; 436 TAILQ_INSERT_HEAD(&sc->free_list, acb, chain); 437 438 sc->sc_tinfo[periph->periph_target].cmds++; 439 440 scsipi_done(xs); 441 442 if (dosched && sc->sc_nexus == NULL) 443 siopng_sched(sc); 444 } 445 446 void 447 siopngabort(register struct siop_softc *sc, siop_regmap_p rp, char *where) 448 { 449 #ifdef fix_this 450 int i; 451 #endif 452 453 printf ("%s: abort %s: dstat %02x, istat %02x sist %04x sien %04x sbcl %02x\n", 454 sc->sc_dev.dv_xname, 455 where, rp->siop_dstat, rp->siop_istat, rp->siop_sist, 456 rp->siop_sien, rp->siop_sbcl); 457 siopng_dump_registers(sc); 458 459 if (sc->sc_active > 0) { 460 #ifdef TODO 461 SET_SBIC_cmd (rp, SBIC_CMD_ABORT); 462 WAIT_CIP (rp); 463 464 GET_SBIC_asr (rp, asr); 465 if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI)) 466 { 467 /* ok, get more drastic.. */ 468 469 SET_SBIC_cmd (rp, SBIC_CMD_RESET); 470 delay(25); 471 SBIC_WAIT(rp, SBIC_ASR_INT, 0); 472 GET_SBIC_csr (rp, csr); /* clears interrupt also */ 473 474 return; 475 } 476 477 do 478 { 479 SBIC_WAIT (rp, SBIC_ASR_INT, 0); 480 GET_SBIC_csr (rp, csr); 481 } 482 while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1) 483 && (csr != SBIC_CSR_CMD_INVALID)); 484 #endif 485 486 /* lets just hope it worked.. */ 487 #ifdef fix_this 488 for (i = 0; i < 2; ++i) { 489 if (sc->sc_iob[i].sc_xs && &sc->sc_iob[i] != 490 sc->sc_cur) { 491 printf ("siopngabort: cleanup!\n"); 492 sc->sc_iob[i].sc_xs = NULL; 493 } 494 } 495 #endif /* fix_this */ 496 /* sc->sc_active = 0; */ 497 } 498 } 499 500 void 501 siopnginitialize(struct siop_softc *sc) 502 { 503 int i; 504 u_int inhibit_sync; 505 extern u_long scsi_nosync; 506 extern int shift_nosync; 507 508 /* 509 * Need to check that scripts is on a long word boundary 510 * Also should verify that dev doesn't span non-contiguous 511 * physical pages. 512 */ 513 sc->sc_scriptspa = kvtop((caddr_t)siopng_scripts); 514 515 /* 516 * malloc sc_acb to ensure that DS is on a long word boundary. 517 */ 518 519 MALLOC(sc->sc_acb, struct siop_acb *, 520 sizeof(struct siop_acb) * SIOP_NACB, M_DEVBUF, M_NOWAIT); 521 if (sc->sc_acb == NULL) 522 panic("siopnginitialize: ACB malloc failed!"); 523 524 sc->sc_tcp[1] = 1000 / sc->sc_clock_freq; 525 sc->sc_tcp[2] = 1500 / sc->sc_clock_freq; 526 sc->sc_tcp[3] = 2000 / sc->sc_clock_freq; 527 sc->sc_minsync = sc->sc_tcp[1]; /* in 4ns units */ 528 if (sc->sc_minsync < 25) 529 sc->sc_minsync = 25; 530 sc->sc_minsync >>= 1; /* Using clock doubler, allow Ultra */ 531 if (sc->sc_clock_freq <= 25) { 532 sc->sc_dcntl |= 0x80; /* SCLK/1 */ 533 sc->sc_tcp[0] = sc->sc_tcp[1]; 534 } else if (sc->sc_clock_freq <= 37) { 535 sc->sc_dcntl |= 0x40; /* SCLK/1.5 */ 536 sc->sc_tcp[0] = sc->sc_tcp[2]; 537 } else if (sc->sc_clock_freq <= 50) { 538 sc->sc_dcntl |= 0x00; /* SCLK/2 */ 539 sc->sc_tcp[0] = sc->sc_tcp[3]; 540 } else { 541 sc->sc_dcntl |= 0xc0; /* SCLK/3 */ 542 sc->sc_tcp[0] = 3000 / sc->sc_clock_freq; 543 } 544 545 if (scsi_nosync) { 546 inhibit_sync = (scsi_nosync >> shift_nosync) & 0xffff; 547 shift_nosync += 16; /* XXX maxtarget */ 548 #ifdef DEBUG 549 if (inhibit_sync) 550 printf("%s: Inhibiting synchronous transfer %02x\n", 551 sc->sc_dev.dv_xname, inhibit_sync); 552 #endif 553 for (i = 0; i < 16; ++i) /* XXX maxtarget */ 554 if (inhibit_sync & (1 << i)) 555 siopng_inhibit_sync[i] = 1; 556 } 557 558 siopngreset (sc); 559 } 560 561 void 562 siopngreset(struct siop_softc *sc) 563 { 564 siop_regmap_p rp; 565 u_int i, s; 566 u_short dummy; 567 struct siop_acb *acb; 568 569 rp = sc->sc_siopp; 570 571 if (sc->sc_flags & SIOP_ALIVE) 572 siopngabort(sc, rp, "reset"); 573 574 printf("%s: ", sc->sc_dev.dv_xname); /* XXXX */ 575 576 s = splbio(); 577 578 /* 579 * Reset the chip 580 * XXX - is this really needed? 581 */ 582 rp->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */ 583 rp->siop_istat |= SIOP_ISTAT_RST; /* reset chip */ 584 rp->siop_istat &= ~SIOP_ISTAT_RST; 585 /* 586 * Reset SCSI bus (do we really want this?) 587 */ 588 rp->siop_sien = 0; 589 rp->siop_scntl1 |= SIOP_SCNTL1_RST; 590 delay(1); 591 rp->siop_scntl1 &= ~SIOP_SCNTL1_RST; 592 593 /* 594 * Set up various chip parameters 595 */ 596 rp->siop_stest1 |= SIOP_STEST1_DBLEN; /* SCLK doubler enable */ 597 delay(20); 598 rp->siop_stest3 |= SIOP_STEST3_HSC; /* Halt SCSI clock */ 599 rp->siop_scntl3 = 0x15; /* SCF/CCF*/ 600 rp->siop_stest1 |= SIOP_STEST1_DBLSEL; /* SCLK doubler select */ 601 rp->siop_stest3 &= ~SIOP_STEST3_HSC; /* Clear Halt SCSI clock */ 602 rp->siop_scntl0 = SIOP_ARB_FULL | /*SIOP_SCNTL0_EPC |*/ SIOP_SCNTL0_EPG; 603 rp->siop_dcntl = sc->sc_dcntl; 604 rp->siop_dmode = 0xc0; /* XXX burst length */ 605 rp->siop_sien = 0x00; /* don't enable interrupts yet */ 606 rp->siop_dien = 0x00; /* don't enable interrupts yet */ 607 rp->siop_scid = sc->sc_channel.chan_id | 608 SIOP_SCID_RRE | SIOP_SCID_SRE; 609 rp->siop_respid = 1 << sc->sc_channel.chan_id; 610 rp->siop_dwt = 0x00; 611 rp->siop_stime0 = 0x0c; /* XXXXX check */ 612 613 /* will need to re-negotiate sync xfers */ 614 bzero(&sc->sc_sync, sizeof (sc->sc_sync)); 615 616 i = rp->siop_istat; 617 if (i & SIOP_ISTAT_SIP) 618 dummy = rp->siop_sist; 619 if (i & SIOP_ISTAT_DIP) 620 dummy = rp->siop_dstat; 621 622 splx (s); 623 624 delay (siopng_reset_delay * 1000); 625 626 /* 627 * is lower half unterminated? 628 */ 629 if ((rp->siop_sbdl & 0x00ff) == 0x00ff) { 630 printf(" no SCSI termination, host adapter deactivated.\n"); 631 sc->sc_channel.chan_ntargets = 0; /* XXX */ 632 sc->sc_flags &= ~(SIOP_ALIVE|SIOP_INTDEFER|SIOP_INTSOFF); 633 /* disable SCSI and DMA interrupts */ 634 sc->sc_sien = 0; 635 sc->sc_dien = 0; 636 rp->siop_sien = sc->sc_sien; 637 rp->siop_dien = sc->sc_dien; 638 639 return; 640 } 641 642 /* 643 * Check if upper half of SCSI bus is unterminated, and disallow 644 * disconnections if it appears to be unterminated. 645 */ 646 if ((rp->siop_sbdl & 0xff00) == 0xff00) { 647 printf(" NO WIDE TERM"); 648 /* XXX need to restrict maximum target ID as well? */ 649 sc->sc_channel.chan_ntargets = 8; 650 for (i = 0; i < 16; ++i) { 651 siopng_allow_disc[i] = 0; 652 siopng_inhibit_wide[i] |= 0x80; 653 } 654 } 655 656 printf("siopng type %s id %d reset V%d\n", 657 siopng_chips[rp->siop_macntl>>4], 658 sc->sc_channel.chan_ntargets, 659 rp->siop_ctest3 >> 4); 660 661 if ((sc->sc_flags & SIOP_ALIVE) == 0) { 662 TAILQ_INIT(&sc->ready_list); 663 TAILQ_INIT(&sc->nexus_list); 664 TAILQ_INIT(&sc->free_list); 665 sc->sc_nexus = NULL; 666 acb = sc->sc_acb; 667 bzero(acb, sizeof(struct siop_acb) * SIOP_NACB); 668 for (i = 0; i < SIOP_NACB; i++) { 669 TAILQ_INSERT_TAIL(&sc->free_list, acb, chain); 670 acb++; 671 } 672 bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo)); 673 } else { 674 if (sc->sc_nexus != NULL) { 675 sc->sc_nexus->xs->error = XS_RESET; 676 siopng_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]); 677 } 678 while ((acb = sc->nexus_list.tqh_first) > 0) { 679 acb->xs->error = XS_RESET; 680 siopng_scsidone(acb, acb->stat[0]); 681 } 682 } 683 684 sc->sc_flags |= SIOP_ALIVE; 685 sc->sc_flags &= ~(SIOP_INTDEFER|SIOP_INTSOFF); 686 /* enable SCSI and DMA interrupts */ 687 sc->sc_sien = SIOP_SIEN_MA | SIOP_SIEN_STO | /*SIOP_SIEN_GEN |*/ 688 /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE | SIOP_SIEN_UDC | 689 SIOP_SIEN_RST | SIOP_SIEN_PAR; 690 sc->sc_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR | 691 /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID; 692 rp->siop_sien = sc->sc_sien; 693 rp->siop_dien = sc->sc_dien; 694 /*siopng_dump_registers(sc);*/ 695 } 696 697 /* 698 * Setup Data Storage for 53C720/770 and start SCRIPTS processing 699 */ 700 701 void 702 siopng_start(struct siop_softc *sc, int target, int lun, u_char *cbuf, 703 int clen, u_char *buf, int len) 704 { 705 siop_regmap_p rp = sc->sc_siopp; 706 int nchain; 707 int count, tcount; 708 char *addr, *dmaend; 709 struct siop_acb *acb = sc->sc_nexus; 710 #ifdef DEBUG 711 int i; 712 #endif 713 714 #ifdef DEBUG 715 if (siopng_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) { 716 printf ("ACK! siopng was busy: rp %p script %p dsa %p active %ld\n", 717 rp, &siopng_scripts, &acb->ds, sc->sc_active); 718 printf ("istat %02x sfbr %02x respid %02x sien %04x dien %02x\n", 719 rp->siop_istat, rp->siop_sfbr, rp->siop_respid, 720 rp->siop_sien, rp->siop_dien); 721 #ifdef DDB 722 /*Debugger();*/ 723 #endif 724 } 725 #endif 726 acb->msgout[0] = MSG_IDENTIFY | lun; 727 if (siopng_allow_disc[target] & 2 || 728 (siopng_allow_disc[target] && len == 0)) 729 acb->msgout[0] = MSG_IDENTIFY_DR | lun; 730 acb->status = 0; 731 acb->stat[0] = -1; 732 acb->msg[0] = -1; 733 acb->ds.scsi_addr = (target << 16) | (sc->sc_sync[target].sxfer << 8) | 734 (sc->sc_sync[target].scntl3 << 24); 735 acb->ds.idlen = 1; 736 acb->ds.idbuf = (char *) kvtop(&acb->msgout[0]); 737 acb->ds.cmdlen = clen; 738 acb->ds.cmdbuf = (char *) kvtop(cbuf); 739 acb->ds.stslen = 1; 740 acb->ds.stsbuf = (char *) kvtop(&acb->stat[0]); 741 acb->ds.msglen = 1; 742 acb->ds.msgbuf = (char *) kvtop(&acb->msg[0]); 743 acb->msg[1] = -1; 744 acb->ds.msginlen = 1; 745 acb->ds.extmsglen = 1; 746 acb->ds.synmsglen = 3; 747 acb->ds.msginbuf = acb->ds.msgbuf + 1; 748 acb->ds.extmsgbuf = acb->ds.msginbuf + 1; 749 acb->ds.synmsgbuf = acb->ds.extmsgbuf + 1; 750 bzero(&acb->ds.chain, sizeof (acb->ds.chain)); 751 752 if (sc->sc_sync[target].state == NEG_WIDE) { 753 if (siopng_inhibit_wide[target]) { 754 sc->sc_sync[target].state = NEG_SYNC; 755 sc->sc_sync[target].scntl3 &= ~SIOP_SCNTL3_EWS; 756 #ifdef DEBUG 757 if (siopngsync_debug) 758 printf ("Forcing target %d narrow\n", target); 759 #endif 760 } 761 else { 762 sc->sc_sync[target].scntl3 = 0x15 | /* XXX */ 763 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */ 764 acb->msg[2] = -1; 765 acb->msgout[1] = MSG_EXT_MESSAGE; 766 acb->msgout[2] = 2; 767 acb->msgout[3] = MSG_WIDE_REQ; 768 acb->msgout[4] = 1; 769 acb->ds.idlen = 5; 770 acb->ds.synmsglen = 2; 771 sc->sc_sync[target].state = NEG_WAITW; 772 #ifdef DEBUG 773 if (siopngsync_debug) 774 printf("Sending wide request to target %d\n", target); 775 #endif 776 } 777 } 778 if (sc->sc_sync[target].state == NEG_SYNC) { 779 if (siopng_inhibit_sync[target]) { 780 sc->sc_sync[target].state = NEG_DONE; 781 sc->sc_sync[target].scntl3 = 5 | /* XXX */ 782 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */ 783 sc->sc_sync[target].sxfer = 0; 784 #ifdef DEBUG 785 if (siopngsync_debug) 786 printf ("Forcing target %d asynchronous\n", target); 787 #endif 788 } 789 else { 790 sc->sc_sync[target].scntl3 = 0x15 | /* XXX */ 791 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */ 792 acb->msg[2] = -1; 793 acb->msgout[1] = MSG_EXT_MESSAGE; 794 acb->msgout[2] = 3; 795 acb->msgout[3] = MSG_SYNC_REQ; 796 #ifdef MAXTOR_SYNC_KLUDGE 797 acb->msgout[4] = 50 / 4; /* ask for ridiculous period */ 798 #else 799 acb->msgout[4] = sc->sc_minsync; 800 #endif 801 acb->msgout[5] = SIOP_MAX_OFFSET; 802 acb->ds.idlen = 6; 803 sc->sc_sync[target].state = NEG_WAITS; 804 #ifdef DEBUG 805 if (siopngsync_debug) 806 printf ("Sending sync request to target %d\n", target); 807 #endif 808 } 809 } 810 811 /* 812 * Build physical DMA addresses for scatter/gather I/O 813 */ 814 acb->iob_buf = buf; 815 acb->iob_len = len; 816 acb->iob_curbuf = acb->iob_curlen = 0; 817 nchain = 0; 818 count = len; 819 addr = buf; 820 dmaend = NULL; 821 while (count > 0) { 822 acb->ds.chain[nchain].databuf = (char *) kvtop (addr); 823 if (count < (tcount = NBPG - ((int) addr & PGOFSET))) 824 tcount = count; 825 826 #if DEBUG_ONLY_IF_DESPERATE 827 printf("chain[%d]: count %d tcount %d vaddr %p paddr %p\n", 828 nchain, count, tcount, addr, 829 acb->ds.chain[nchain].databuf); 830 #endif 831 acb->ds.chain[nchain].datalen = tcount; 832 addr += tcount; 833 count -= tcount; 834 if (acb->ds.chain[nchain].databuf == dmaend) { 835 dmaend += acb->ds.chain[nchain].datalen; 836 acb->ds.chain[nchain].datalen = 0; 837 acb->ds.chain[--nchain].datalen += tcount; 838 #ifdef DEBUG 839 ++siopngdma_hits; 840 #endif 841 } 842 else { 843 dmaend = acb->ds.chain[nchain].databuf + 844 acb->ds.chain[nchain].datalen; 845 acb->ds.chain[nchain].datalen = tcount; 846 #ifdef DEBUG 847 if (nchain) /* Don't count miss on first one */ 848 ++siopngdma_misses; 849 #endif 850 } 851 ++nchain; 852 } 853 #ifdef DEBUG 854 if (nchain != 1 && len != 0 && siopng_debug & 3) { 855 printf ("DMA chaining set: %d\n", nchain); 856 for (i = 0; i < nchain; ++i) { 857 printf (" [%d] %8p %lx\n", i, acb->ds.chain[i].databuf, 858 acb->ds.chain[i].datalen); 859 } 860 } 861 #endif 862 863 /* push data cache for all data the 53c720/770 needs to access */ 864 dma_cachectl ((caddr_t)acb, sizeof (struct siop_acb)); 865 dma_cachectl (cbuf, clen); 866 if (buf != NULL && len != 0) 867 dma_cachectl (buf, len); 868 #ifdef DEBUG 869 if (siopng_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) { 870 printf ("ACK! siopng was busy at start: rp %p script %p dsa %p active %ld\n", 871 rp, &siopng_scripts, &acb->ds, sc->sc_active); 872 #ifdef DDB 873 /*Debugger();*/ 874 #endif 875 } 876 #endif 877 if (sc->nexus_list.tqh_first == NULL) { 878 if (rp->siop_istat & SIOP_ISTAT_CON) 879 printf("%s: siopng_select while connected?\n", 880 sc->sc_dev.dv_xname); 881 rp->siop_temp = 0; 882 #ifndef FIXME 883 rp->siop_scntl3 = sc->sc_sync[target].scntl3; 884 #endif 885 rp->siop_dsa = kvtop((caddr_t)&acb->ds); 886 rp->siop_dsp = sc->sc_scriptspa; 887 SIOP_TRACE('s',1,0,0) 888 } else { 889 if ((rp->siop_istat & SIOP_ISTAT_CON) == 0) { 890 rp->siop_istat = SIOP_ISTAT_SIGP; 891 SIOP_TRACE('s',2,0,0); 892 } 893 else { 894 SIOP_TRACE('s',3,rp->siop_istat,0); 895 } 896 } 897 #ifdef DEBUG 898 ++siopngstarts; 899 #endif 900 } 901 902 /* 903 * Process a DMA or SCSI interrupt from the 53C720/770 SIOP 904 */ 905 906 int 907 siopng_checkintr(struct siop_softc *sc, u_char istat, u_char dstat, 908 u_short sist, int *status) 909 { 910 siop_regmap_p rp = sc->sc_siopp; 911 struct siop_acb *acb = sc->sc_nexus; 912 int target = 0; 913 int dfifo, dbc, sstat0, sstat1, sstat2; 914 915 dfifo = rp->siop_dfifo; 916 dbc = rp->siop_dbc0; 917 sstat0 = rp->siop_sstat0; 918 sstat1 = rp->siop_sstat1; 919 sstat2 = rp->siop_sstat2; 920 rp->siop_ctest3 |= SIOP_CTEST8_CLF; 921 while ((rp->siop_ctest1 & SIOP_CTEST1_FMT) != SIOP_CTEST1_FMT) 922 ; 923 rp->siop_ctest3 &= ~SIOP_CTEST8_CLF; 924 #ifdef DEBUG 925 ++siopngints; 926 #if 0 927 if (siopng_debug & 0x100) { 928 DCIAS(&acb->stat[0]); /* XXX */ 929 printf ("siopngchkintr: istat %x dstat %x sist %x dsps %x sbcl %x sts %x msg %x\n", 930 istat, dstat, sist, rp->siop_dsps, rp->siop_sbcl, acb->stat[0], acb->msg[0]); 931 printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n", 932 acb->msg[0], acb->msg[1], acb->msg[2], 933 acb->msg[3], acb->msg[4], acb->msg[5]); 934 } 935 #endif 936 if (rp->siop_dsp && (rp->siop_dsp < sc->sc_scriptspa || 937 rp->siop_dsp >= sc->sc_scriptspa + sizeof(siopng_scripts))) { 938 printf ("%s: dsp not within script dsp %lx scripts %lx:%lx", 939 sc->sc_dev.dv_xname, rp->siop_dsp, sc->sc_scriptspa, 940 sc->sc_scriptspa + sizeof(siopng_scripts)); 941 printf(" istat %x dstat %x sist %x\n", 942 istat, dstat, sist); 943 #ifdef DDB 944 Debugger(); 945 #endif 946 } 947 #endif 948 SIOP_TRACE('i',dstat,istat,(istat&SIOP_ISTAT_DIP)?rp->siop_dsps&0xff:sist); 949 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff00) { 950 /* Normal completion status, or check condition */ 951 #ifdef DEBUG 952 if (rp->siop_dsa != kvtop((caddr_t)&acb->ds)) { 953 printf ("siopng: invalid dsa: %lx %x\n", rp->siop_dsa, 954 kvtop((caddr_t)&acb->ds)); 955 panic("*** siopng DSA invalid ***"); 956 } 957 #endif 958 target = acb->xs->xs_periph->periph_target; 959 if (sc->sc_sync[target].state == NEG_WAITW) { 960 if (acb->msg[1] == 0xff) 961 printf ("%s: target %d ignored wide request\n", 962 sc->sc_dev.dv_xname, target); 963 else if (acb->msg[1] == MSG_REJECT) 964 printf ("%s: target %d rejected wide request\n", 965 sc->sc_dev.dv_xname, target); 966 else { 967 printf("%s: target %d (wide) %02x %02x %02x %02x\n", 968 sc->sc_dev.dv_xname, target, acb->msg[1], 969 acb->msg[2], acb->msg[3], acb->msg[4]); 970 if (acb->msg[1] == MSG_EXT_MESSAGE && 971 acb->msg[2] == 2 && 972 acb->msg[3] == MSG_WIDE_REQ) 973 sc->sc_sync[target].scntl3 = acb->msg[4] ? 974 sc->sc_sync[target].scntl3 | SIOP_SCNTL3_EWS : 975 sc->sc_sync[target].scntl3 & ~SIOP_SCNTL3_EWS; 976 } 977 sc->sc_sync[target].state = NEG_SYNC; 978 } 979 if (sc->sc_sync[target].state == NEG_WAITS) { 980 if (acb->msg[1] == 0xff) 981 printf ("%s: target %d ignored sync request\n", 982 sc->sc_dev.dv_xname, target); 983 else if (acb->msg[1] == MSG_REJECT) 984 printf ("%s: target %d rejected sync request\n", 985 sc->sc_dev.dv_xname, target); 986 else 987 /* XXX - need to set sync transfer parameters */ 988 printf("%s: target %d (sync) %02x %02x %02x\n", 989 sc->sc_dev.dv_xname, target, acb->msg[1], 990 acb->msg[2], acb->msg[3]); 991 sc->sc_sync[target].state = NEG_DONE; 992 } 993 dma_cachectl(&acb->stat[0], 1); 994 *status = acb->stat[0]; 995 #ifdef DEBUG 996 if (rp->siop_sbcl & SIOP_BSY) { 997 /*printf ("ACK! siop was busy at end: rp %x script %x dsa %x\n", 998 rp, &siopng_scripts, &acb->ds);*/ 999 #ifdef DDB 1000 /*Debugger();*/ 1001 #endif 1002 } 1003 if (acb->msg[0] != 0x00) 1004 printf("%s: message was not COMMAND COMPLETE: %x\n", 1005 sc->sc_dev.dv_xname, acb->msg[0]); 1006 #endif 1007 if (sc->nexus_list.tqh_first) 1008 rp->siop_dcntl |= SIOP_DCNTL_STD; 1009 return 1; 1010 } 1011 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0b) { 1012 target = acb->xs->xs_periph->periph_target; 1013 if (acb->msg[1] == MSG_EXT_MESSAGE && acb->msg[2] == 2 && 1014 acb->msg[3] == MSG_WIDE_REQ) { 1015 #ifdef DEBUG 1016 if (siopngsync_debug) 1017 printf ("wide msg in: %02x %02x %02x %02x %02x %02x\n", 1018 acb->msg[0], acb->msg[1], acb->msg[2], 1019 acb->msg[3], acb->msg[4], acb->msg[5]); 1020 #endif 1021 sc->sc_sync[target].scntl3 &= ~(SIOP_SCNTL3_EWS); 1022 if (acb->msg[2] == 2 && 1023 acb->msg[3] == MSG_WIDE_REQ && 1024 acb->msg[4] != 0) { 1025 sc->sc_sync[target].scntl3 |= SIOP_SCNTL3_EWS; 1026 printf ("%s: target %d now wide %d\n", 1027 sc->sc_dev.dv_xname, target, 1028 acb->msg[4]); 1029 } 1030 rp->siop_scntl3 = sc->sc_sync[target].scntl3; 1031 if (sc->sc_sync[target].state == NEG_WAITW) { 1032 sc->sc_sync[target].state = NEG_SYNC; 1033 rp->siop_dsp = sc->sc_scriptspa + Ent_clear_ack; 1034 return(0); 1035 } 1036 rp->siop_dcntl |= SIOP_DCNTL_STD; 1037 sc->sc_sync[target].state = NEG_SYNC; 1038 return (0); 1039 } 1040 if (acb->msg[1] == MSG_EXT_MESSAGE && acb->msg[2] == 3 && 1041 acb->msg[3] == MSG_SYNC_REQ) { 1042 #ifdef DEBUG 1043 if (siopngsync_debug) 1044 printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n", 1045 acb->msg[0], acb->msg[1], acb->msg[2], 1046 acb->msg[3], acb->msg[4], acb->msg[5]); 1047 #endif 1048 sc->sc_sync[target].sxfer = 0; 1049 sc->sc_sync[target].scntl3 = 5 | /* XXX */ 1050 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */ 1051 if (acb->msg[2] == 3 && 1052 acb->msg[3] == MSG_SYNC_REQ && 1053 acb->msg[5] != 0) { 1054 #ifdef MAXTOR_KLUDGE 1055 /* 1056 * Kludge for my Maxtor XT8580S 1057 * It accepts whatever we request, even 1058 * though it won't work. So we ask for 1059 * a short period than we can handle. If 1060 * the device says it can do it, use 208ns. 1061 * If the device says it can do less than 1062 * 100ns, then we limit it to 100ns. 1063 */ 1064 if (acb->msg[4] && acb->msg[4] < 100 / 4) { 1065 #ifdef DEBUG 1066 printf ("%d: target %d wanted %dns period\n", 1067 sc->sc_dev.dv_xname, target, 1068 acb->msg[4] * 4); 1069 #endif 1070 if (acb->msg[4] == 50 / 4) 1071 acb->msg[4] = 208 / 4; 1072 else 1073 acb->msg[4] = 100 / 4; 1074 } 1075 #endif /* MAXTOR_KLUDGE */ 1076 printf ("%s: target %d now synchronous, period=%dns, offset=%d\n", 1077 sc->sc_dev.dv_xname, target, 1078 (acb->msg[4] == 12) ? 50 : acb->msg[4] * 4, 1079 acb->msg[5]); 1080 scsi_period_to_siopng (sc, target); 1081 } 1082 rp->siop_sxfer = sc->sc_sync[target].sxfer; 1083 rp->siop_scntl3 = sc->sc_sync[target].scntl3; 1084 if (sc->sc_sync[target].state == NEG_WAITS) { 1085 sc->sc_sync[target].state = NEG_DONE; 1086 rp->siop_dsp = sc->sc_scriptspa + Ent_clear_ack; 1087 return(0); 1088 } 1089 rp->siop_dcntl |= SIOP_DCNTL_STD; 1090 sc->sc_sync[target].state = NEG_DONE; 1091 return (0); 1092 } 1093 /* XXX - not SDTR message */ 1094 } 1095 if (sist & SIOP_SIST_MA) { /* Phase mismatch */ 1096 #ifdef DEBUG 1097 ++siopngphmm; 1098 if (acb == NULL) 1099 printf("%s: Phase mismatch with no active command?\n", 1100 sc->sc_dev.dv_xname); 1101 #endif 1102 if (acb->iob_len) { 1103 int adjust; 1104 adjust = ((dfifo - (dbc & 0x7f)) & 0x7f); 1105 if (sstat0 & SIOP_SSTAT0_OLF) /* sstat0 SODL lsb */ 1106 ++adjust; 1107 if (sstat0 & SIOP_SSTAT0_ORF) /* sstat0 SODR lsb */ 1108 ++adjust; 1109 if (sstat2 & SIOP_SSTAT2_OLF1) /* sstat2 SODL msb */ 1110 ++adjust; 1111 if (sstat2 & SIOP_SSTAT2_ORF1) /* sstat2 SODR msb */ 1112 ++adjust; 1113 acb->iob_curlen = *((long *)&rp->siop_dcmd) & 0xffffff; 1114 acb->iob_curlen += adjust; 1115 acb->iob_curbuf = *((long *)&rp->siop_dnad) - adjust; 1116 #ifdef DEBUG 1117 if (siopng_debug & 0x100) { 1118 int i; 1119 printf ("Phase mismatch: curbuf %lx curlen %lx dfifo %x dbc %x sstat1 %x adjust %x sbcl %x starts %d acb %p\n", 1120 acb->iob_curbuf, acb->iob_curlen, dfifo, 1121 dbc, sstat1, adjust, rp->siop_sbcl, siopngstarts, acb); 1122 if (acb->ds.chain[1].datalen) { 1123 for (i = 0; acb->ds.chain[i].datalen; ++i) 1124 printf("chain[%d] addr %p len %lx\n", 1125 i, acb->ds.chain[i].databuf, 1126 acb->ds.chain[i].datalen); 1127 } 1128 } 1129 #endif 1130 dma_cachectl ((caddr_t)acb, sizeof(*acb)); 1131 } 1132 #ifdef DEBUG 1133 SIOP_TRACE('m',rp->siop_sbcl,(rp->siop_dsp>>8),rp->siop_dsp); 1134 if (siopng_debug & 9) 1135 printf ("Phase mismatch: %x dsp +%lx dcmd %lx\n", 1136 rp->siop_sbcl, 1137 rp->siop_dsp - sc->sc_scriptspa, 1138 *((long *)&rp->siop_dcmd)); 1139 #endif 1140 if ((rp->siop_sbcl & SIOP_REQ) == 0) { 1141 printf ("Phase mismatch: REQ not asserted! %02x dsp %lx\n", 1142 rp->siop_sbcl, rp->siop_dsp); 1143 #if defined(DEBUG) && defined(DDB) 1144 Debugger(); 1145 #endif 1146 } 1147 switch (rp->siop_sbcl & 7) { 1148 case 0: /* data out */ 1149 case 1: /* data in */ 1150 case 2: /* status */ 1151 case 3: /* command */ 1152 case 6: /* message in */ 1153 case 7: /* message out */ 1154 rp->siop_dsp = sc->sc_scriptspa + Ent_switch; 1155 break; 1156 default: 1157 goto bad_phase; 1158 } 1159 return 0; 1160 } 1161 if (sist & SIOP_SIST_STO) { /* Select timed out */ 1162 #ifdef DEBUG 1163 if (acb == NULL) 1164 printf("%s: Select timeout with no active command?\n", 1165 sc->sc_dev.dv_xname); 1166 if (rp->siop_sbcl & SIOP_BSY) { 1167 printf ("ACK! siop was busy at timeout: rp %p script %p dsa %p\n", 1168 rp, &siopng_scripts, &acb->ds); 1169 printf(" sbcl %x sdid %x istat %x dstat %x sist %x\n", 1170 rp->siop_sbcl, rp->siop_sdid, istat, dstat, sist); 1171 if (!(rp->siop_sbcl & SIOP_BSY)) { 1172 printf ("Yikes, it's not busy now!\n"); 1173 #if 0 1174 *status = -1; 1175 if (sc->nexus_list.tqh_first) 1176 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect; 1177 return 1; 1178 #endif 1179 } 1180 /* rp->siop_dcntl |= SIOP_DCNTL_STD;*/ 1181 return (0); 1182 #ifdef DDB 1183 Debugger(); 1184 #endif 1185 } 1186 #endif 1187 *status = -1; 1188 acb->xs->error = XS_SELTIMEOUT; 1189 if (sc->nexus_list.tqh_first) 1190 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect; 1191 return 1; 1192 } 1193 if (acb) 1194 target = acb->xs->xs_periph->periph_target; 1195 else 1196 target = 7; 1197 if (sist & SIOP_SIST_UDC) { 1198 #ifdef DEBUG 1199 if (acb == NULL) 1200 printf("%s: Unexpected disconnect with no active command?\n", 1201 sc->sc_dev.dv_xname); 1202 printf ("%s: target %d disconnected unexpectedly\n", 1203 sc->sc_dev.dv_xname, target); 1204 siopng_dump_registers(sc); 1205 siopng_dump(sc); 1206 #endif 1207 #if 0 1208 siopngabort (sc, rp, "siopngchkintr"); 1209 #endif 1210 *status = STS_BUSY; 1211 if (sc->nexus_list.tqh_first) 1212 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect; 1213 return (acb != NULL); 1214 } 1215 if (dstat & SIOP_DSTAT_SIR && (rp->siop_dsps == 0xff01 || 1216 rp->siop_dsps == 0xff02)) { 1217 #ifdef DEBUG 1218 if (siopng_debug & 0x100) 1219 printf ("%s: ID %02x disconnected TEMP %lx (+%lx) curbuf %lx curlen %lx buf %p len %lx dfifo %x dbc %x sstat1 %x starts %d acb %p\n", 1220 sc->sc_dev.dv_xname, 1 << target, rp->siop_temp, 1221 rp->siop_temp ? rp->siop_temp - sc->sc_scriptspa : 0, 1222 acb->iob_curbuf, acb->iob_curlen, 1223 acb->ds.chain[0].databuf, acb->ds.chain[0].datalen, dfifo, dbc, sstat1, siopngstarts, acb); 1224 #endif 1225 if (acb == NULL) { 1226 printf("%s: Disconnect with no active command?\n", 1227 sc->sc_dev.dv_xname); 1228 return (0); 1229 } 1230 /* 1231 * XXXX need to update iob_curbuf/iob_curlen to reflect 1232 * current data transferred. If device disconnected in 1233 * the middle of a DMA block, they should already be set 1234 * by the phase change interrupt. If the disconnect 1235 * occurs on a DMA block boundary, we have to figure out 1236 * which DMA block it was. 1237 */ 1238 if (acb->iob_len && rp->siop_temp) { 1239 int n = rp->siop_temp - sc->sc_scriptspa; 1240 1241 if (acb->iob_curlen && acb->iob_curlen != acb->ds.chain[0].datalen) 1242 printf("%s: iob_curbuf/len already set? n %x iob %lx/%lx chain[0] %p/%lx\n", 1243 sc->sc_dev.dv_xname, n, acb->iob_curbuf, acb->iob_curlen, 1244 acb->ds.chain[0].databuf, acb->ds.chain[0].datalen); 1245 if (n < Ent_datain) 1246 n = (n - Ent_dataout) / 16; 1247 else 1248 n = (n - Ent_datain) / 16; 1249 if (n <= 0 && n > DMAMAXIO) 1250 printf("TEMP invalid %d\n", n); 1251 else { 1252 acb->iob_curbuf = (u_long)acb->ds.chain[n].databuf; 1253 acb->iob_curlen = acb->ds.chain[n].datalen; 1254 } 1255 #ifdef DEBUG 1256 if (siopng_debug & 0x100) { 1257 printf("%s: TEMP offset %d", sc->sc_dev.dv_xname, n); 1258 printf(" curbuf %lx curlen %lx\n", acb->iob_curbuf, 1259 acb->iob_curlen); 1260 } 1261 #endif 1262 } 1263 /* 1264 * If data transfer was interrupted by disconnect, iob_curbuf 1265 * and iob_curlen should reflect the point of interruption. 1266 * Adjust the DMA chain so that the data transfer begins 1267 * at the appropriate place upon reselection. 1268 * XXX This should only be done on save data pointer message? 1269 */ 1270 if (acb->iob_curlen) { 1271 int i, j; 1272 1273 #ifdef DEBUG 1274 if (siopng_debug & 0x100) 1275 printf ("%s: adjusting DMA chain\n", 1276 sc->sc_dev.dv_xname); 1277 if (rp->siop_dsps == 0xff02) 1278 printf ("%s: ID %02x disconnected without Save Data Pointers\n", 1279 sc->sc_dev.dv_xname, 1 << target); 1280 #endif 1281 for (i = 0; i < DMAMAXIO; ++i) { 1282 if (acb->ds.chain[i].datalen == 0) 1283 break; 1284 if (acb->iob_curbuf >= (long)acb->ds.chain[i].databuf && 1285 acb->iob_curbuf < (long)(acb->ds.chain[i].databuf + 1286 acb->ds.chain[i].datalen)) 1287 break; 1288 } 1289 if (i >= DMAMAXIO || acb->ds.chain[i].datalen == 0) { 1290 printf("couldn't find saved data pointer: "); 1291 printf("curbuf %lx curlen %lx i %d\n", 1292 acb->iob_curbuf, acb->iob_curlen, i); 1293 #ifdef DDB 1294 Debugger(); 1295 #endif 1296 } 1297 #ifdef DEBUG 1298 if (siopng_debug & 0x100) 1299 printf(" chain[0]: %p/%lx -> %lx/%lx\n", 1300 acb->ds.chain[0].databuf, 1301 acb->ds.chain[0].datalen, 1302 acb->iob_curbuf, 1303 acb->iob_curlen); 1304 #endif 1305 acb->ds.chain[0].databuf = (char *)acb->iob_curbuf; 1306 acb->ds.chain[0].datalen = acb->iob_curlen; 1307 for (j = 1, ++i; i < DMAMAXIO && acb->ds.chain[i].datalen; ++i, ++j) { 1308 #ifdef DEBUG 1309 if (siopng_debug & 0x100) 1310 printf(" chain[%d]: %p/%lx -> %p/%lx\n", j, 1311 acb->ds.chain[j].databuf, 1312 acb->ds.chain[j].datalen, 1313 acb->ds.chain[i].databuf, 1314 acb->ds.chain[i].datalen); 1315 #endif 1316 acb->ds.chain[j].databuf = acb->ds.chain[i].databuf; 1317 acb->ds.chain[j].datalen = acb->ds.chain[i].datalen; 1318 } 1319 if (j < DMAMAXIO) 1320 acb->ds.chain[j].datalen = 0; 1321 DCIAS(kvtop((caddr_t)&acb->ds.chain)); 1322 } 1323 ++sc->sc_tinfo[target].dconns; 1324 /* 1325 * add nexus to waiting list 1326 * clear nexus 1327 * try to start another command for another target/lun 1328 */ 1329 acb->status = sc->sc_flags & SIOP_INTSOFF; 1330 TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain); 1331 sc->sc_nexus = NULL; /* no current device */ 1332 /* start script to wait for reselect */ 1333 if (sc->sc_nexus == NULL) 1334 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect; 1335 /* XXXX start another command ? */ 1336 if (sc->ready_list.tqh_first) 1337 siopng_sched(sc); 1338 #if 0 1339 else 1340 rp->siop_dcntl |= SIOP_DCNTL_STD; 1341 #endif 1342 return (0); 1343 } 1344 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff03) { 1345 int reselid = rp->siop_scratcha & 0x7f; 1346 int reselun = rp->siop_sfbr & 0x07; 1347 1348 sc->sc_sstat1 = rp->siop_sbcl; /* XXXX save current SBCL */ 1349 #ifdef DEBUG 1350 if (siopng_debug & 0x100) 1351 printf ("%s: target ID %02x reselected dsps %lx\n", 1352 sc->sc_dev.dv_xname, reselid, 1353 rp->siop_dsps); 1354 if ((rp->siop_sfbr & 0x80) == 0) 1355 printf("%s: Reselect message in was not identify: %x\n", 1356 sc->sc_dev.dv_xname, rp->siop_sfbr); 1357 #endif 1358 if (sc->sc_nexus) { 1359 #ifdef DEBUG 1360 if (siopng_debug & 0x100) 1361 printf ("%s: reselect ID %02x w/active\n", 1362 sc->sc_dev.dv_xname, reselid); 1363 #endif 1364 TAILQ_INSERT_HEAD(&sc->ready_list, sc->sc_nexus, chain); 1365 sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target].lubusy 1366 &= ~(1 << sc->sc_nexus->xs->xs_periph->periph_lun); 1367 --sc->sc_active; 1368 } 1369 /* 1370 * locate acb of reselecting device 1371 * set sc->sc_nexus to acb 1372 */ 1373 for (acb = sc->nexus_list.tqh_first; acb; 1374 acb = acb->chain.tqe_next) { 1375 if (reselid != ((acb->ds.scsi_addr >> 16) & 0xff) || 1376 reselun != (acb->msgout[0] & 0x07)) 1377 continue; 1378 TAILQ_REMOVE(&sc->nexus_list, acb, chain); 1379 sc->sc_nexus = acb; 1380 sc->sc_flags |= acb->status; 1381 acb->status = 0; 1382 DCIAS(kvtop(&acb->stat[0])); 1383 rp->siop_dsa = kvtop((caddr_t)&acb->ds); 1384 rp->siop_sxfer = 1385 sc->sc_sync[acb->xs->xs_periph->periph_target].sxfer; 1386 #ifndef FIXME 1387 rp->siop_scntl3 = 1388 sc->sc_sync[acb->xs->xs_periph->periph_target].scntl3; 1389 #endif 1390 break; 1391 } 1392 if (acb == NULL) { 1393 printf("%s: target ID %02x reselect nexus_list %p\n", 1394 sc->sc_dev.dv_xname, reselid, 1395 sc->nexus_list.tqh_first); 1396 panic("unable to find reselecting device"); 1397 } 1398 dma_cachectl ((caddr_t)acb, sizeof(*acb)); 1399 rp->siop_temp = 0; 1400 rp->siop_dcntl |= SIOP_DCNTL_STD; 1401 return (0); 1402 } 1403 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff04) { 1404 #ifdef DEBUG 1405 u_short ctest2 = rp->siop_ctest2; 1406 1407 /* reselect was interrupted (by Sig_P or select) */ 1408 if (siopng_debug & 0x100 || 1409 (ctest2 & SIOP_CTEST2_SIGP) == 0) 1410 printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x istat %x/%x\n", 1411 sc->sc_dev.dv_xname, rp->siop_scntl1, 1412 ctest2, rp->siop_sfbr, istat, rp->siop_istat); 1413 #endif 1414 /* XXX assumes it was not select */ 1415 if (sc->sc_nexus == NULL) { 1416 #ifdef DEBUG 1417 printf("%s: reselect interrupted, sc_nexus == NULL\n", 1418 sc->sc_dev.dv_xname); 1419 #if 0 1420 siopng_dump(sc); 1421 #ifdef DDB 1422 Debugger(); 1423 #endif 1424 #endif 1425 #endif 1426 rp->siop_dcntl |= SIOP_DCNTL_STD; 1427 return(0); 1428 } 1429 target = sc->sc_nexus->xs->xs_periph->periph_target; 1430 rp->siop_temp = 0; 1431 rp->siop_dsa = kvtop((caddr_t)&sc->sc_nexus->ds); 1432 rp->siop_sxfer = sc->sc_sync[target].sxfer; 1433 #ifndef FIXME 1434 rp->siop_scntl3 = sc->sc_sync[target].scntl3; 1435 #endif 1436 rp->siop_dsp = sc->sc_scriptspa; 1437 return (0); 1438 } 1439 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff06) { 1440 if (acb == NULL) 1441 printf("%s: Bad message-in with no active command?\n", 1442 sc->sc_dev.dv_xname); 1443 /* Unrecognized message in byte */ 1444 dma_cachectl (&acb->msg[1],1); 1445 printf ("%s: Unrecognized message in data sfbr %x msg %x sbcl %x\n", 1446 sc->sc_dev.dv_xname, rp->siop_sfbr, acb->msg[1], rp->siop_sbcl); 1447 /* what should be done here? */ 1448 DCIAS(kvtop(&acb->msg[1])); 1449 rp->siop_dsp = sc->sc_scriptspa + Ent_switch; 1450 return (0); 1451 } 1452 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0a) { 1453 /* Status phase wasn't followed by message in phase? */ 1454 printf ("%s: Status phase not followed by message in phase? sbcl %x sbdl %x\n", 1455 sc->sc_dev.dv_xname, rp->siop_sbcl, rp->siop_sbdl); 1456 if (rp->siop_sbcl == 0xa7) { 1457 /* It is now, just continue the script? */ 1458 rp->siop_dcntl |= SIOP_DCNTL_STD; 1459 return (0); 1460 } 1461 } 1462 if (sist == 0 && dstat & SIOP_DSTAT_SIR) { 1463 dma_cachectl (&acb->stat[0], 1); 1464 dma_cachectl (&acb->msg[0], 1); 1465 printf ("SIOP interrupt: %lx sts %x msg %x %x sbcl %x\n", 1466 rp->siop_dsps, acb->stat[0], acb->msg[0], acb->msg[1], 1467 rp->siop_sbcl); 1468 siopngreset (sc); 1469 *status = -1; 1470 return 0; /* siopngreset has cleaned up */ 1471 } 1472 if (sist & SIOP_SIST_SGE) 1473 printf ("SIOP: SCSI Gross Error\n"); 1474 if (sist & SIOP_SIST_PAR) 1475 printf ("SIOP: Parity Error\n"); 1476 if (dstat & SIOP_DSTAT_IID) 1477 printf ("SIOP: Invalid instruction detected\n"); 1478 bad_phase: 1479 /* 1480 * temporary panic for unhandled conditions 1481 * displays various things about the 53C720/770 status and registers 1482 * then panics. 1483 * XXXX need to clean this up to print out the info, reset, and continue 1484 */ 1485 printf ("siopngchkintr: target %x ds %p\n", target, &acb->ds); 1486 printf ("scripts %lx ds %x rp %x dsp %lx dcmd %lx\n", sc->sc_scriptspa, 1487 kvtop((caddr_t)&acb->ds), kvtop((caddr_t)rp), rp->siop_dsp, 1488 *((long *)&rp->siop_dcmd)); 1489 printf ("siopngchkintr: istat %x dstat %x sist %x dsps %lx dsa %lx sbcl %x sts %x msg %x %x sfbr %x\n", 1490 istat, dstat, sist, rp->siop_dsps, rp->siop_dsa, 1491 rp->siop_sbcl, acb->stat[0], acb->msg[0], acb->msg[1], rp->siop_sfbr); 1492 #ifdef DEBUG 1493 if (siopng_debug & 0x20) 1494 panic("siopngchkintr: **** temp ****"); 1495 #endif 1496 #ifdef DDB 1497 Debugger (); 1498 #endif 1499 siopngreset (sc); /* hard reset */ 1500 *status = -1; 1501 return 0; /* siopngreset cleaned up */ 1502 } 1503 1504 void 1505 siopng_select(struct siop_softc *sc) 1506 { 1507 siop_regmap_p rp; 1508 struct siop_acb *acb = sc->sc_nexus; 1509 1510 #ifdef DEBUG 1511 if (siopng_debug & 1) 1512 printf ("%s: select ", sc->sc_dev.dv_xname); 1513 #endif 1514 1515 rp = sc->sc_siopp; 1516 if (acb->xs->xs_control & XS_CTL_POLL || siopng_no_dma) { 1517 sc->sc_flags |= SIOP_INTSOFF; 1518 sc->sc_flags &= ~SIOP_INTDEFER; 1519 if ((rp->siop_istat & 0x08) == 0) { 1520 rp->siop_sien = 0; 1521 rp->siop_dien = 0; 1522 } 1523 #if 0 1524 } else if ((sc->sc_flags & SIOP_INTDEFER) == 0) { 1525 sc->sc_flags &= ~SIOP_INTSOFF; 1526 if ((rp->siop_istat & 0x08) == 0) { 1527 rp->siop_sien = sc->sc_sien; 1528 rp->siop_dien = sc->sc_dien; 1529 } 1530 #endif 1531 } 1532 #ifdef DEBUG 1533 if (siopng_debug & 1) 1534 printf ("siopng_select: target %x cmd %02x ds %p\n", 1535 acb->xs->xs_periph->periph_target, acb->cmd.opcode, 1536 &sc->sc_nexus->ds); 1537 #endif 1538 1539 siopng_start(sc, acb->xs->xs_periph->periph_target, 1540 acb->xs->xs_periph->periph_lun, 1541 (u_char *)&acb->cmd, acb->clen, acb->daddr, acb->dleft); 1542 1543 return; 1544 } 1545 1546 /* 1547 * 53C720/770 interrupt handler 1548 */ 1549 1550 void 1551 siopngintr(register struct siop_softc *sc) 1552 { 1553 siop_regmap_p rp; 1554 u_char istat, dstat; 1555 u_short sist; 1556 int status; 1557 int s = splbio(); 1558 1559 istat = sc->sc_istat; 1560 if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) { 1561 splx(s); 1562 return; 1563 } 1564 1565 /* Got a valid interrupt on this device */ 1566 rp = sc->sc_siopp; 1567 dstat = sc->sc_dstat; 1568 sist = sc->sc_sist; 1569 if (dstat & SIOP_DSTAT_SIR) 1570 sc->sc_intcode = rp->siop_dsps; 1571 sc->sc_istat = 0; 1572 #ifdef DEBUG 1573 if (siopng_debug & 1) 1574 printf ("%s: intr istat %x dstat %x sist %x\n", 1575 sc->sc_dev.dv_xname, istat, dstat, sist); 1576 if (!sc->sc_active) { 1577 printf ("%s: spurious interrupt? istat %x dstat %x sist %x nexus %p status %x\n", 1578 sc->sc_dev.dv_xname, istat, dstat, sist, 1579 sc->sc_nexus, sc->sc_nexus ? sc->sc_nexus->stat[0] : 0); 1580 } 1581 #endif 1582 1583 #ifdef DEBUG 1584 if (siopng_debug & 5) { 1585 DCIAS(kvtop(&sc->sc_nexus->stat[0])); 1586 printf ("%s: intr istat %x dstat %x sist %x dsps %lx sbcl %x sts %x msg %x\n", 1587 sc->sc_dev.dv_xname, istat, dstat, sist, 1588 rp->siop_dsps, rp->siop_sbcl, 1589 sc->sc_nexus->stat[0], sc->sc_nexus->msg[0]); 1590 } 1591 #endif 1592 if (sc->sc_flags & SIOP_INTDEFER) { 1593 sc->sc_flags &= ~(SIOP_INTDEFER | SIOP_INTSOFF); 1594 rp->siop_sien = sc->sc_sien; 1595 rp->siop_dien = sc->sc_dien; 1596 } 1597 if (siopng_checkintr (sc, istat, dstat, sist, &status)) { 1598 #if 1 1599 if (status == 0xff) 1600 printf ("siopngintr: status == 0xff\n"); 1601 #endif 1602 if ((sc->sc_flags & (SIOP_INTSOFF | SIOP_INTDEFER)) != SIOP_INTSOFF) { 1603 #if 0 1604 if (rp->siop_sbcl & SIOP_BSY) { 1605 printf ("%s: SCSI bus busy at completion", 1606 sc->sc_dev.dv_xname); 1607 printf(" targ %d sbcl %02x sfbr %x respid %02x dsp +%x\n", 1608 sc->sc_nexus->xs->xs_periph->periph_target, 1609 rp->siop_sbcl, rp->siop_sfbr, rp->siop_respid, 1610 rp->siop_dsp - sc->sc_scriptspa); 1611 } 1612 #endif 1613 siopng_scsidone(sc->sc_nexus, sc->sc_nexus ? 1614 sc->sc_nexus->stat[0] : -1); 1615 } 1616 } 1617 splx(s); 1618 } 1619 1620 /* 1621 * This is based on the Progressive Peripherals 33Mhz Zeus driver and will 1622 * not be correct for other 53c710 boards. 1623 * 1624 */ 1625 void 1626 scsi_period_to_siopng(struct siop_softc *sc, int target) 1627 { 1628 int period, offset, sxfer, scntl3 = 0; 1629 1630 period = sc->sc_nexus->msg[4]; 1631 offset = sc->sc_nexus->msg[5]; 1632 #ifdef FIXME 1633 for (scntl3 = 1; scntl3 < 4; ++scntl3) { 1634 sxfer = (period * 4 - 1) / sc->sc_tcp[scntl3] - 3; 1635 if (sxfer >= 0 && sxfer <= 7) 1636 break; 1637 } 1638 if (scntl3 > 3) { 1639 printf("siopng sync: unable to compute sync params for period %dns\n", 1640 period * 4); 1641 /* 1642 * XXX need to pick a value we can do and renegotiate 1643 */ 1644 sxfer = scntl3 = 0; 1645 } else { 1646 sxfer = (sxfer << 4) | ((offset <= SIOP_MAX_OFFSET) ? 1647 offset : SIOP_MAX_OFFSET); 1648 #ifdef DEBUG_SYNC 1649 printf("siopng sync: params for period %dns: sxfer %x scntl3 %x", 1650 period * 4, sxfer, scntl3); 1651 printf(" actual period %dns\n", 1652 sc->sc_tcp[scntl3] * ((sxfer >> 4) + 4)); 1653 #endif /* DEBUG_SYNC */ 1654 } 1655 #else /* FIXME */ 1656 sxfer = offset <= SIOP_MAX_OFFSET ? offset : SIOP_MAX_OFFSET; 1657 sxfer |= 0x20; /* XXX XFERP: 5 */ 1658 #ifndef FIXME 1659 if (period <= (50 / 4)) /* XXX */ 1660 scntl3 = 0x95; /* Ultra, SCF: /1, CCF: /4 */ 1661 else if (period <= (100 / 4)) 1662 scntl3 = 0x35; /* SCF: /2, CCF: /4 */ 1663 else if (period <= (200 / 4)) 1664 scntl3 = 0x55; /* SCF: /4, CCF: /4 */ 1665 else 1666 scntl3 = 0xff; /* XXX ??? */ 1667 #else 1668 scntl3 = 5; 1669 #endif 1670 #endif 1671 sc->sc_sync[target].sxfer = sxfer; 1672 sc->sc_sync[target].scntl3 = scntl3 | 1673 (sc->sc_sync[target].scntl3 & SIOP_SCNTL3_EWS); 1674 #ifdef DEBUG_SYNC 1675 printf ("siopng sync: siop_sxfr %02x, siop_scntl3 %02x\n", sxfer, scntl3); 1676 #endif 1677 } 1678 1679 void 1680 siopng_dump_registers(struct siop_softc *sc) 1681 { 1682 siop_regmap_p rp = sc->sc_siopp; 1683 1684 printf(" scntl0 %02x scntl1 %02x scntl2 %02x scntl3 %02x\n", 1685 rp->siop_scntl0, rp->siop_scntl1, rp->siop_scntl2, rp->siop_scntl3); 1686 printf(" scid %02x sxfer %02x sdid %02x gpreg %02x\n", 1687 rp->siop_scid, rp->siop_sxfer, rp->siop_sdid, rp->siop_gpreg); 1688 printf(" sfbr %02x socl %02x ssid %02x sbcl %02x\n", 1689 rp->siop_sfbr, rp->siop_socl, rp->siop_ssid, rp->siop_sbcl); 1690 printf(" dstat %02x sstat0 %02x sstat1 %02x sstat2 %02x\n", 1691 rp->siop_dstat, rp->siop_sstat0, rp->siop_sstat1, rp->siop_sstat2); 1692 printf(" ctest0 %02x ctest1 %02x ctest2 %02x ctest3 %02x\n", 1693 rp->siop_ctest0, rp->siop_ctest1, rp->siop_ctest2, rp->siop_ctest3); 1694 printf(" dfifo %02x ctest4 %02x ctest5 %02x ctest6 %02x\n", 1695 0, rp->siop_ctest4, rp->siop_ctest5, rp->siop_ctest6); 1696 printf(" dcmd %02x dbc2 %02x dbc1 %02x dbc0 %02x\n", 1697 rp->siop_dcmd, rp->siop_dbc2, rp->siop_dbc1, rp->siop_dbc0); 1698 printf(" dmode %02x dien %02x dwt %02x dcntl %02x\n", 1699 rp->siop_dmode, rp->siop_dien, rp->siop_dwt, rp->siop_dcntl); 1700 printf(" stest0 %02x stest1 %02x stest2 %02x stest3 %02x\n", 1701 rp->siop_stest0, rp->siop_stest1, rp->siop_stest2, rp->siop_stest3); 1702 printf(" istat %02x sien %04x sist %04x respid %04x\n", 1703 rp->siop_istat, rp->siop_sien, rp->siop_sist, rp->siop_respid); 1704 printf(" sidl %04x sodl %04x sbdl %04x\n", 1705 rp->siop_sidl, rp->siop_sodl, rp->siop_sbdl); 1706 printf(" dsps %08lx dsp %08lx (+%lx)\n", 1707 rp->siop_dsps, rp->siop_dsp, rp->siop_dsp > sc->sc_scriptspa ? 1708 rp->siop_dsp - sc->sc_scriptspa : 0); 1709 printf(" dsa %08lx temp %08lx dnad %08lx\n", 1710 rp->siop_dsa, rp->siop_temp, rp->siop_dnad); 1711 printf(" scratcha %08lx scratchb %08lx adder %08lx\n", 1712 rp->siop_scratcha, rp->siop_scratchb, rp->siop_adder); 1713 } 1714 1715 #ifdef DEBUG 1716 1717 #if SIOP_TRACE_SIZE 1718 void 1719 siopng_dump_trace(void) 1720 { 1721 int i; 1722 1723 printf("siopng trace: next index %d\n", siopng_trix); 1724 i = siopng_trix; 1725 do { 1726 printf("%3d: '%c' %02x %02x %02x\n", i, siopng_trbuf[i], 1727 siopng_trbuf[i + 1], siopng_trbuf[i + 2], siopng_trbuf[i + 3]); 1728 i = (i + 4) & (SIOP_TRACE_SIZE - 1); 1729 } while (i != siopng_trix); 1730 } 1731 #endif 1732 1733 void 1734 siopng_dump_acb(struct siop_acb *acb) 1735 { 1736 u_char *b = (u_char *) &acb->cmd; 1737 int i; 1738 1739 printf("acb@%p ", acb); 1740 if (acb->xs == NULL) { 1741 printf("<unused>\n"); 1742 return; 1743 } 1744 printf("(%d:%d) flags %2x clen %2d cmd ", 1745 acb->xs->xs_periph->periph_target, 1746 acb->xs->xs_periph->periph_lun, acb->flags, acb->clen); 1747 for (i = acb->clen; i; --i) 1748 printf(" %02x", *b++); 1749 printf("\n"); 1750 printf(" xs: %p data %p:%04x ", acb->xs, acb->xs->data, 1751 acb->xs->datalen); 1752 printf("va %p:%lx ", acb->iob_buf, acb->iob_len); 1753 printf("cur %lx:%lx\n", acb->iob_curbuf, acb->iob_curlen); 1754 } 1755 1756 void 1757 siopng_dump(struct siop_softc *sc) 1758 { 1759 struct siop_acb *acb; 1760 siop_regmap_p rp = sc->sc_siopp; 1761 int s; 1762 int i; 1763 1764 s = splbio(); 1765 #if SIOP_TRACE_SIZE 1766 siopng_dump_trace(); 1767 #endif 1768 printf("%s@%p regs %p istat %x\n", 1769 sc->sc_dev.dv_xname, sc, rp, rp->siop_istat); 1770 if ((acb = sc->free_list.tqh_first) > 0) { 1771 printf("Free list:\n"); 1772 while (acb) { 1773 siopng_dump_acb(acb); 1774 acb = acb->chain.tqe_next; 1775 } 1776 } 1777 if ((acb = sc->ready_list.tqh_first) > 0) { 1778 printf("Ready list:\n"); 1779 while (acb) { 1780 siopng_dump_acb(acb); 1781 acb = acb->chain.tqe_next; 1782 } 1783 } 1784 if ((acb = sc->nexus_list.tqh_first) > 0) { 1785 printf("Nexus list:\n"); 1786 while (acb) { 1787 siopng_dump_acb(acb); 1788 acb = acb->chain.tqe_next; 1789 } 1790 } 1791 if (sc->sc_nexus) { 1792 printf("Nexus:\n"); 1793 siopng_dump_acb(sc->sc_nexus); 1794 } 1795 for (i = 0; i < 8; ++i) { 1796 if (sc->sc_tinfo[i].cmds > 2) { 1797 printf("tgt %d: cmds %d disc %d lubusy %x\n", 1798 i, sc->sc_tinfo[i].cmds, 1799 sc->sc_tinfo[i].dconns, 1800 sc->sc_tinfo[i].lubusy); 1801 } 1802 } 1803 splx(s); 1804 } 1805 #endif 1806