1 /* $OpenBSD: wds.c,v 1.33 2010/03/23 01:57:20 krw Exp $ */ 2 /* $NetBSD: wds.c,v 1.13 1996/11/03 16:20:31 mycroft Exp $ */ 3 4 #undef WDSDIAG 5 #ifdef DDB 6 #define integrate 7 #else 8 #define integrate static inline 9 #endif 10 11 /* 12 * XXX 13 * sense data 14 * aborts 15 * resets 16 */ 17 18 /* 19 * Copyright (c) 1994, 1995 Julian Highfield. All rights reserved. 20 * Portions copyright (c) 1994, 1996 Charles M. Hannum. All rights reserved. 21 * 22 * Redistribution and use in source and binary forms, with or without 23 * modification, are permitted provided that the following conditions 24 * are met: 25 * 1. Redistributions of source code must retain the above copyright 26 * notice, this list of conditions and the following disclaimer. 27 * 2. Redistributions in binary form must reproduce the above copyright 28 * notice, this list of conditions and the following disclaimer in the 29 * documentation and/or other materials provided with the distribution. 30 * 3. All advertising materials mentioning features or use of this software 31 * must display the following acknowledgement: 32 * This product includes software developed by Julian Highfield. 33 * 4. The name of the author may not be used to endorse or promote products 34 * derived from this software without specific prior written permission. 35 * 36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 37 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 45 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 */ 47 48 /* 49 * This driver is for the WD7000 family of SCSI controllers: 50 * the WD7000-ASC, a bus-mastering DMA controller, 51 * the WD7000-FASST2, an -ASC with new firmware and scatter-gather, 52 * and the WD7000-ASE, which was custom manufactured for Apollo 53 * workstations and seems to include an -ASC as well as floppy 54 * and ESDI interfaces. 55 * 56 * Loosely based on Theo Deraadt's unfinished attempt says the NetBSD group 57 * so they decided to delete the copyright that file had on it. 58 */ 59 60 #include <sys/types.h> 61 #include <sys/param.h> 62 #include <sys/systm.h> 63 #include <sys/kernel.h> 64 #include <sys/errno.h> 65 #include <sys/ioctl.h> 66 #include <sys/device.h> 67 #include <sys/malloc.h> 68 #include <sys/buf.h> 69 #include <sys/proc.h> 70 #include <sys/user.h> 71 72 #include <machine/bus.h> 73 #include <machine/intr.h> 74 75 #include <scsi/scsi_all.h> 76 #include <scsi/scsiconf.h> 77 78 #include <dev/isa/isavar.h> 79 #include <dev/isa/isadmavar.h> 80 #include <dev/isa/wdsreg.h> 81 82 #define WDS_MBX_SIZE 16 83 84 #define WDS_SCB_MAX 32 85 #define SCB_HASH_SIZE 32 /* hash table size for phystokv */ 86 #define SCB_HASH_SHIFT 9 87 #define SCB_HASH(x) ((((long)(x))>>SCB_HASH_SHIFT) & (SCB_HASH_SIZE - 1)) 88 89 #define wds_nextmbx(wmb, mbx, mbio) \ 90 if ((wmb) == &(mbx)->mbio[WDS_MBX_SIZE - 1]) \ 91 (wmb) = &(mbx)->mbio[0]; \ 92 else \ 93 (wmb)++; 94 95 struct wds_mbx { 96 struct wds_mbx_out mbo[WDS_MBX_SIZE]; 97 struct wds_mbx_in mbi[WDS_MBX_SIZE]; 98 struct wds_mbx_out *cmbo; /* Collection Mail Box out */ 99 struct wds_mbx_out *tmbo; /* Target Mail Box out */ 100 struct wds_mbx_in *tmbi; /* Target Mail Box in */ 101 }; 102 103 #define KVTOPHYS(x) vtophys((vaddr_t)(x)) 104 105 struct wds_softc { 106 struct device sc_dev; 107 struct isadev sc_id; 108 void *sc_ih; 109 110 bus_space_tag_t sc_iot; /* bus identifier */ 111 bus_space_handle_t sc_ioh; /* io handle */ 112 int sc_irq, sc_drq; 113 114 int sc_revision; 115 116 struct wds_mbx sc_mbx; 117 #define wmbx (&sc->sc_mbx) 118 struct wds_scb *sc_scbhash[SCB_HASH_SIZE]; 119 TAILQ_HEAD(, wds_scb) sc_free_scb, sc_waiting_scb; 120 int sc_numscbs, sc_mbofull; 121 int sc_scsi_dev; 122 struct scsi_link sc_link; /* prototype for subdevs */ 123 }; 124 125 /* Define the bounce buffer length... */ 126 #define BUFLEN (64*1024) 127 /* ..and how many there are. One per device! Non-FASST boards need these. */ 128 #define BUFCNT 8 129 /* The macro for deciding whether the board needs a buffer. */ 130 #define NEEDBUFFER(sc) (sc->sc_revision < 0x800) 131 132 struct wds_buf { 133 u_char data[BUFLEN]; 134 int busy; 135 TAILQ_ENTRY(wds_buf) chain; 136 } wds_buffer[BUFCNT]; 137 138 TAILQ_HEAD(, wds_buf) wds_free_buffer; 139 140 #ifdef WDSDEBUG 141 int wds_debug = WDSDEBUG; 142 #endif 143 144 integrate void wds_wait(bus_space_tag_t, bus_space_handle_t, int, int, int); 145 int wds_cmd(struct wds_softc *, u_char *, int); 146 integrate void wds_finish_scbs(struct wds_softc *); 147 int wdsintr(void *); 148 integrate void wds_reset_scb(struct wds_softc *, struct wds_scb *); 149 void wds_free_scb(struct wds_softc *, struct wds_scb *); 150 void wds_free_buf(struct wds_softc *, struct wds_buf *); 151 integrate void wds_init_scb(struct wds_softc *, struct wds_scb *); 152 struct wds_scb *wds_get_scb(struct wds_softc *, int, int); 153 struct wds_buf *wds_get_buf(struct wds_softc *, int); 154 struct wds_scb *wds_scb_phys_kv(struct wds_softc *, u_long); 155 void wds_queue_scb(struct wds_softc *, struct wds_scb *); 156 void wds_collect_mbo(struct wds_softc *); 157 void wds_start_scbs(struct wds_softc *); 158 void wds_done(struct wds_softc *, struct wds_scb *, u_char); 159 int wds_find(struct isa_attach_args *, struct wds_softc *); 160 void wds_init(struct wds_softc *); 161 void wds_inquire_setup_information(struct wds_softc *); 162 void wdsminphys(struct buf *, struct scsi_link *); 163 void wds_scsi_cmd(struct scsi_xfer *); 164 void wds_sense(struct wds_softc *, struct wds_scb *); 165 int wds_poll(struct wds_softc *, struct scsi_xfer *, int); 166 int wds_ipoll(struct wds_softc *, struct wds_scb *, int); 167 void wds_timeout(void *); 168 int wdsprint(void *, const char *); 169 170 struct scsi_adapter wds_switch = { 171 wds_scsi_cmd, 172 wdsminphys, 173 0, 174 0, 175 }; 176 177 /* the below structure is so we have a default dev struct for our link struct */ 178 struct scsi_device wds_dev = { 179 NULL, /* Use default error handler */ 180 NULL, /* have a queue, served by this */ 181 NULL, /* have no async handler */ 182 NULL, /* Use default 'done' routine */ 183 }; 184 185 int wdsprobe(struct device *, void *, void *); 186 void wdsattach(struct device *, struct device *, void *); 187 188 struct cfattach wds_ca = { 189 sizeof(struct wds_softc), wdsprobe, wdsattach 190 }; 191 192 struct cfdriver wds_cd = { 193 NULL, "wds", DV_DULL 194 }; 195 196 #define WDS_ABORT_TIMEOUT 2000 /* time to wait for abort (mSec) */ 197 198 integrate void 199 wds_wait(iot, ioh, port, mask, val) 200 bus_space_tag_t iot; 201 bus_space_handle_t ioh; 202 int port; 203 int mask; 204 int val; 205 { 206 while ((bus_space_read_1(iot, ioh, port) & mask) != val) 207 ; 208 } 209 210 /* 211 * Write a command to the board's I/O ports. 212 */ 213 int 214 wds_cmd(sc, ibuf, icnt) 215 struct wds_softc *sc; 216 u_int8_t *ibuf; 217 int icnt; 218 { 219 bus_space_tag_t iot = sc->sc_iot; 220 bus_space_handle_t ioh = sc->sc_ioh; 221 u_int8_t c; 222 223 wds_wait(iot, ioh, WDS_STAT, WDSS_RDY, WDSS_RDY); 224 225 while (icnt--) { 226 bus_space_write_1(iot, ioh, WDS_CMD, *ibuf++); 227 wds_wait(iot, ioh, WDS_STAT, WDSS_RDY, WDSS_RDY); 228 c = bus_space_read_1(iot, ioh, WDS_STAT); 229 if (c & WDSS_REJ) 230 return 1; 231 } 232 233 return 0; 234 } 235 236 /* 237 * Check for the presence of a WD7000 SCSI controller. 238 */ 239 int 240 wdsprobe(parent, match, aux) 241 struct device *parent; 242 void *match, *aux; 243 { 244 register struct isa_attach_args *ia = aux; 245 bus_space_tag_t iot = ia->ia_iot; 246 bus_space_handle_t ioh; 247 int rv; 248 249 if (bus_space_map(iot, ia->ia_iobase, WDS_IO_PORTS, 0, &ioh)) 250 return (0); 251 252 /* See if there is a unit at this location. */ 253 rv = wds_find(ia, NULL); 254 255 bus_space_unmap(iot, ioh, WDS_IO_PORTS); 256 257 if (rv) { 258 ia->ia_msize = 0; 259 ia->ia_iosize = WDS_IO_PORTS; 260 } 261 262 return (rv); 263 } 264 265 int 266 wdsprint(aux, name) 267 void *aux; 268 const char *name; 269 { 270 271 if (name != NULL) 272 printf("%s: scsibus ", name); 273 return UNCONF; 274 } 275 276 /* 277 * Attach all available units. 278 */ 279 void 280 wdsattach(parent, self, aux) 281 struct device *parent, *self; 282 void *aux; 283 { 284 struct isa_attach_args *ia = aux; 285 struct wds_softc *sc = (void *)self; 286 struct scsibus_attach_args saa; 287 bus_space_tag_t iot = ia->ia_iot; 288 bus_space_handle_t ioh; 289 290 if (bus_space_map(iot, ia->ia_iobase, WDS_IO_PORTS, 0, &ioh)) { 291 printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname); 292 return; 293 } 294 295 if (!wds_find(ia, sc)) 296 panic("wdsattach: wds_find of %s failed", self->dv_xname); 297 wds_init(sc); 298 299 if (sc->sc_drq != DRQUNK) 300 isadma_cascade(sc->sc_drq); 301 302 TAILQ_INIT(&sc->sc_free_scb); 303 TAILQ_INIT(&sc->sc_waiting_scb); 304 wds_inquire_setup_information(sc); 305 306 /* 307 * fill in the prototype scsi_link. 308 */ 309 #ifdef notyet 310 sc->sc_link.channel = SCSI_CHANNEL_ONLY_ONE; 311 #endif 312 sc->sc_link.adapter_softc = sc; 313 sc->sc_link.adapter_target = sc->sc_scsi_dev; 314 sc->sc_link.adapter = &wds_switch; 315 sc->sc_link.device = &wds_dev; 316 /* XXX */ 317 /* I don't think the -ASE can handle openings > 1. */ 318 /* It gives Vendor Error 26 whenever I try it. */ 319 sc->sc_link.openings = 1; 320 321 sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE, 322 IPL_BIO, wdsintr, sc, sc->sc_dev.dv_xname); 323 324 bzero(&saa, sizeof(saa)); 325 saa.saa_sc_link = &sc->sc_link; 326 327 /* 328 * ask the adapter what subunits are present 329 */ 330 config_found(self, &saa, wdsprint); 331 } 332 333 integrate void 334 wds_finish_scbs(sc) 335 struct wds_softc *sc; 336 { 337 struct wds_mbx_in *wmbi; 338 struct wds_scb *scb; 339 int i; 340 341 wmbi = wmbx->tmbi; 342 343 if (wmbi->stat == WDS_MBI_FREE) { 344 for (i = 0; i < WDS_MBX_SIZE; i++) { 345 if (wmbi->stat != WDS_MBI_FREE) { 346 printf("%s: mbi not in round-robin order\n", 347 sc->sc_dev.dv_xname); 348 goto AGAIN; 349 } 350 wds_nextmbx(wmbi, wmbx, mbi); 351 } 352 #ifdef WDSDIAGnot 353 printf("%s: mbi interrupt with no full mailboxes\n", 354 sc->sc_dev.dv_xname); 355 #endif 356 return; 357 } 358 359 AGAIN: 360 do { 361 scb = wds_scb_phys_kv(sc, phystol(wmbi->scb_addr)); 362 if (!scb) { 363 printf("%s: bad mbi scb pointer; skipping\n", 364 sc->sc_dev.dv_xname); 365 goto next; 366 } 367 368 #ifdef WDSDEBUG 369 if (wds_debug) { 370 u_int8_t *cp = (u_int8_t *)&scb->cmd.scb; 371 printf("op=%x %x %x %x %x %x\n", 372 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]); 373 printf("stat %x for mbi addr = 0x%08x, ", 374 wmbi->stat, wmbi); 375 printf("scb addr = 0x%x\n", scb); 376 } 377 #endif /* WDSDEBUG */ 378 379 timeout_del(&scb->xs->stimeout); 380 #ifdef notyet 381 isadma_copyfrombuf((caddr_t)scb, SCB_PHYS_SIZE, 382 1, scb->scb_phys); 383 #endif 384 wds_done(sc, scb, wmbi->stat); 385 386 next: 387 wmbi->stat = WDS_MBI_FREE; 388 wds_nextmbx(wmbi, wmbx, mbi); 389 } while (wmbi->stat != WDS_MBI_FREE); 390 391 wmbx->tmbi = wmbi; 392 } 393 394 /* 395 * Process an interrupt. 396 */ 397 int 398 wdsintr(arg) 399 void *arg; 400 { 401 struct wds_softc *sc = arg; 402 bus_space_tag_t iot = sc->sc_iot; 403 bus_space_handle_t ioh = sc->sc_ioh; 404 u_char c; 405 406 /* Was it really an interrupt from the board? */ 407 if ((bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_IRQ) == 0) 408 return 0; 409 410 /* Get the interrupt status byte. */ 411 c = bus_space_read_1(iot, ioh, WDS_IRQSTAT) & WDSI_MASK; 412 413 /* Acknowledge (which resets) the interrupt. */ 414 bus_space_write_1(iot, ioh, WDS_IRQACK, 0x00); 415 416 switch (c) { 417 case WDSI_MSVC: 418 wds_finish_scbs(sc); 419 break; 420 421 case WDSI_MFREE: 422 wds_start_scbs(sc); 423 break; 424 425 default: 426 printf("%s: unrecognized interrupt type %02x", 427 sc->sc_dev.dv_xname, c); 428 break; 429 } 430 431 return 1; 432 } 433 434 integrate void 435 wds_reset_scb(sc, scb) 436 struct wds_softc *sc; 437 struct wds_scb *scb; 438 { 439 440 scb->flags = 0; 441 } 442 443 /* 444 * Free the command structure, the outgoing mailbox and the data buffer. 445 */ 446 void 447 wds_free_scb(sc, scb) 448 struct wds_softc *sc; 449 struct wds_scb *scb; 450 { 451 int s; 452 453 if (scb->buf != 0) { 454 wds_free_buf(sc, scb->buf); 455 scb->buf = 0; 456 } 457 458 s = splbio(); 459 460 #ifdef notyet 461 if (scb->scb_phys[0].addr) 462 isadma_unmap((caddr_t)scb, SCB_PHYS_SIZE, 1, scb->scb_phys); 463 #endif 464 465 wds_reset_scb(sc, scb); 466 TAILQ_INSERT_HEAD(&sc->sc_free_scb, scb, chain); 467 468 /* 469 * If there were none, wake anybody waiting for one to come free, 470 * starting with queued entries. 471 */ 472 if (TAILQ_NEXT(scb, chain) == NULL) 473 wakeup(&sc->sc_free_scb); 474 475 splx(s); 476 } 477 478 void 479 wds_free_buf(sc, buf) 480 struct wds_softc *sc; 481 struct wds_buf *buf; 482 { 483 int s; 484 485 s = splbio(); 486 487 buf->busy = 0; 488 TAILQ_INSERT_HEAD(&wds_free_buffer, buf, chain); 489 490 /* 491 * If there were none, wake anybody waiting for one to come free, 492 * starting with queued entries. 493 */ 494 if (TAILQ_NEXT(buf, chain) == NULL) 495 wakeup(&wds_free_buffer); 496 497 splx(s); 498 } 499 500 integrate void 501 wds_init_scb(sc, scb) 502 struct wds_softc *sc; 503 struct wds_scb *scb; 504 { 505 int hashnum; 506 507 bzero(scb, sizeof(struct wds_scb)); 508 /* 509 * put in the phystokv hash table 510 * Never gets taken out. 511 */ 512 scb->hashkey = KVTOPHYS(scb); 513 hashnum = SCB_HASH(scb->hashkey); 514 scb->nexthash = sc->sc_scbhash[hashnum]; 515 sc->sc_scbhash[hashnum] = scb; 516 wds_reset_scb(sc, scb); 517 } 518 519 /* 520 * Get a free scb 521 * 522 * If there are none, see if we can allocate a new one. If so, put it in 523 * the hash table too otherwise either return an error or sleep. 524 */ 525 struct wds_scb * 526 wds_get_scb(sc, flags, needbuffer) 527 struct wds_softc *sc; 528 int flags; 529 int needbuffer; 530 { 531 struct wds_scb *scb; 532 int s; 533 #ifdef notyet 534 int mflags, hashnum; 535 #endif 536 537 s = splbio(); 538 539 #ifdef notyet 540 if (flags & SCSI_NOSLEEP) 541 mflags = ISADMA_MAP_BOUNCE; 542 else 543 mflags = ISADMA_MAP_BOUNCE | ISADMA_MAP_WAITOK; 544 #endif 545 546 /* 547 * If we can and have to, sleep waiting for one to come free 548 * but only if we can't allocate a new one. 549 */ 550 for (;;) { 551 scb = TAILQ_FIRST(&sc->sc_free_scb); 552 if (scb) { 553 TAILQ_REMOVE(&sc->sc_free_scb, scb, chain); 554 break; 555 } 556 if (sc->sc_numscbs < WDS_SCB_MAX) { 557 scb = (struct wds_scb *) malloc(sizeof(struct wds_scb), 558 M_TEMP, M_NOWAIT); 559 if (!scb) { 560 printf("%s: can't malloc scb\n", 561 sc->sc_dev.dv_xname); 562 goto out; 563 } 564 wds_init_scb(sc, scb); 565 sc->sc_numscbs++; 566 break; 567 } 568 if ((flags & SCSI_NOSLEEP) != 0) 569 goto out; 570 tsleep(&sc->sc_free_scb, PRIBIO, "wdsscb", 0); 571 } 572 573 scb->flags |= SCB_ALLOC; 574 575 #ifdef notyet 576 if (isadma_map((caddr_t)scb, SCB_PHYS_SIZE, scb->scb_phys, 577 mflags | ISADMA_MAP_CONTIG) == 1) { 578 hashnum = SCB_HASH(scb->scb_phys[0].addr); 579 scb->nexthash = sc->sc_scbhash[hashnum]; 580 sc->sc_scbhash[hashnum] = ccb; 581 } else { 582 scb->scb_phys[0].addr = 0; 583 wds_free_scb(sc, scb); 584 scb = 0; 585 } 586 #else 587 if (needbuffer) { 588 scb->buf = wds_get_buf(sc, flags); 589 if (scb->buf == 0) { 590 wds_free_scb(sc, scb); 591 scb = 0; 592 } 593 } 594 #endif 595 596 597 out: 598 splx(s); 599 return (scb); 600 } 601 602 struct wds_buf * 603 wds_get_buf(sc, flags) 604 struct wds_softc *sc; 605 int flags; 606 { 607 struct wds_buf *buf; 608 int s; 609 610 s = splbio(); 611 612 for (;;) { 613 buf = TAILQ_FIRST(&wds_free_buffer); 614 if (buf) { 615 TAILQ_REMOVE(&wds_free_buffer, buf, chain); 616 break; 617 } 618 if ((flags & SCSI_NOSLEEP) != 0) 619 goto out; 620 tsleep(&wds_free_buffer, PRIBIO, "wdsbuf", 0); 621 } 622 623 buf->busy = 1; 624 625 out: 626 splx(s); 627 return (buf); 628 } 629 630 struct wds_scb * 631 wds_scb_phys_kv(sc, scb_phys) 632 struct wds_softc *sc; 633 u_long scb_phys; 634 { 635 int hashnum = SCB_HASH(scb_phys); 636 struct wds_scb *scb = sc->sc_scbhash[hashnum]; 637 638 while (scb) { 639 if (scb->hashkey == scb_phys) 640 break; 641 /* XXX Check to see if it matches the sense command block. */ 642 if (scb->hashkey == (scb_phys - sizeof(struct wds_cmd))) 643 break; 644 scb = scb->nexthash; 645 } 646 return scb; 647 } 648 649 /* 650 * Queue a SCB to be sent to the controller, and send it if possible. 651 */ 652 void 653 wds_queue_scb(sc, scb) 654 struct wds_softc *sc; 655 struct wds_scb *scb; 656 { 657 658 TAILQ_INSERT_TAIL(&sc->sc_waiting_scb, scb, chain); 659 wds_start_scbs(sc); 660 } 661 662 /* 663 * Garbage collect mailboxes that are no longer in use. 664 */ 665 void 666 wds_collect_mbo(sc) 667 struct wds_softc *sc; 668 { 669 struct wds_mbx_out *wmbo; /* Mail Box Out pointer */ 670 #ifdef WDSDIAG 671 struct wds_scb *scb; 672 #endif 673 674 wmbo = wmbx->cmbo; 675 676 while (sc->sc_mbofull > 0) { 677 if (wmbo->cmd != WDS_MBO_FREE) 678 break; 679 680 #ifdef WDSDIAG 681 scb = wds_scb_phys_kv(sc, phystol(wmbo->scb_addr)); 682 scb->flags &= ~SCB_SENDING; 683 #endif 684 685 --sc->sc_mbofull; 686 wds_nextmbx(wmbo, wmbx, mbo); 687 } 688 689 wmbx->cmbo = wmbo; 690 } 691 692 /* 693 * Send as many SCBs as we have empty mailboxes for. 694 */ 695 void 696 wds_start_scbs(sc) 697 struct wds_softc *sc; 698 { 699 struct wds_mbx_out *wmbo; /* Mail Box Out pointer */ 700 struct wds_scb *scb; 701 u_char c; 702 703 wmbo = wmbx->tmbo; 704 705 while ((scb = TAILQ_FIRST(&sc->sc_waiting_scb)) != NULL) { 706 if (sc->sc_mbofull >= WDS_MBX_SIZE) { 707 wds_collect_mbo(sc); 708 if (sc->sc_mbofull >= WDS_MBX_SIZE) { 709 c = WDSC_IRQMFREE; 710 wds_cmd(sc, &c, sizeof c); 711 break; 712 } 713 } 714 715 TAILQ_REMOVE(&sc->sc_waiting_scb, scb, chain); 716 #ifdef WDSDIAG 717 scb->flags |= SCB_SENDING; 718 #endif 719 timeout_set(&scb->xs->stimeout, wds_timeout, scb); 720 721 /* Link scb to mbo. */ 722 #ifdef notyet 723 isadma_copytobuf((caddr_t)scb, SCB_PHYS_SIZE, 724 1, scb->scb_phys); 725 ltophys(scb->scb_phys[0].addr, wmbo->scb_addr); 726 #else 727 if (scb->flags & SCB_SENSE) 728 ltophys(KVTOPHYS(&scb->sense), wmbo->scb_addr); 729 else 730 ltophys(KVTOPHYS(&scb->cmd), wmbo->scb_addr); 731 #endif 732 /* XXX What about aborts? */ 733 wmbo->cmd = WDS_MBO_START; 734 735 /* Tell the card to poll immediately. */ 736 c = WDSC_MSTART(wmbo - wmbx->mbo); 737 wds_cmd(sc, &c, sizeof c); 738 739 if ((scb->flags & SCB_POLLED) == 0) 740 timeout_add_msec(&scb->xs->stimeout, scb->timeout); 741 742 ++sc->sc_mbofull; 743 wds_nextmbx(wmbo, wmbx, mbo); 744 } 745 746 wmbx->tmbo = wmbo; 747 } 748 749 /* 750 * Process the result of a SCSI command. 751 */ 752 void 753 wds_done(sc, scb, stat) 754 struct wds_softc *sc; 755 struct wds_scb *scb; 756 u_int8_t stat; 757 { 758 struct scsi_xfer *xs = scb->xs; 759 760 /* XXXXX */ 761 762 /* Don't release the SCB if it was an internal command. */ 763 if (xs == 0) { 764 scb->flags |= SCB_DONE; 765 return; 766 } 767 768 /* Sense handling. */ 769 if (xs->error == XS_SENSE) { 770 bcopy(&scb->sense_data, &xs->sense, sizeof (struct scsi_sense_data)); 771 } else { 772 if (xs->error == XS_NOERROR) { 773 /* If all went well, or an error is acceptable. */ 774 if (stat == WDS_MBI_OK) { 775 /* OK, set the result */ 776 xs->resid = 0; 777 } else { 778 /* Check the mailbox status. */ 779 switch (stat) { 780 case WDS_MBI_OKERR: 781 /* SCSI error recorded in scb, counts as WDS_MBI_OK */ 782 switch (scb->cmd.venderr) { 783 case 0x00: 784 printf("%s: Is this an error?\n", sc->sc_dev.dv_xname); 785 xs->error = XS_DRIVER_STUFFUP; /* Experiment */ 786 break; 787 case 0x01: 788 /*printf("%s: OK, see SCSI error field.\n", sc->sc_dev.dv_xname);*/ 789 if (scb->cmd.stat == SCSI_CHECK) { 790 /* Do sense. */ 791 wds_sense (sc, scb); 792 return; 793 } else if (scb->cmd.stat == SCSI_BUSY) { 794 xs->error = XS_BUSY; 795 } 796 break; 797 case 0x40: 798 /*printf("%s: DMA underrun!\n", sc->sc_dev.dv_xname);*/ 799 /* Hits this if the target returns fewer that datalen bytes (eg my CD-ROM, 800 which returns a short version string, or if DMA is turned off etc. */ 801 xs->resid = 0; 802 break; 803 default: 804 printf("%s: VENDOR ERROR %02x, scsi %02x\n", sc->sc_dev.dv_xname, scb->cmd.venderr, scb->cmd.stat); 805 xs->error = XS_DRIVER_STUFFUP; /* Experiment */ 806 break; 807 } 808 break; 809 case WDS_MBI_ETIME: 810 /* 811 * The documentation isn't clear on 812 * what conditions might generate this, 813 * but selection timeouts are the only 814 * one I can think of. 815 */ 816 xs->error = XS_SELTIMEOUT; 817 break; 818 case WDS_MBI_ERESET: 819 case WDS_MBI_ETARCMD: 820 case WDS_MBI_ERESEL: 821 case WDS_MBI_ESEL: 822 case WDS_MBI_EABORT: 823 case WDS_MBI_ESRESET: 824 case WDS_MBI_EHRESET: 825 xs->error = XS_DRIVER_STUFFUP; 826 break; 827 } 828 } 829 } /* else sense */ 830 831 if (NEEDBUFFER(sc) && xs->datalen) { 832 if (xs->flags & SCSI_DATA_IN) 833 bcopy(scb->buf->data, xs->data, xs->datalen); 834 } 835 } /* XS_NOERROR */ 836 837 #ifdef notyet 838 if (scb->data_nseg) { 839 if (xs->flags & SCSI_DATA_IN) 840 isadma_copyfrombuf(xs->data, xs->datalen, 841 scb->data_nseg, scb->data_phys); 842 isadma_unmap(xs->data, xs->datalen, 843 scb->data_nseg, scb->data_phys); 844 } 845 #endif 846 wds_free_scb(sc, scb); 847 scsi_done(xs); 848 } 849 850 int 851 wds_find(ia, sc) 852 struct isa_attach_args *ia; 853 struct wds_softc *sc; 854 { 855 bus_space_tag_t iot = ia->ia_iot; 856 bus_space_handle_t ioh; 857 u_char c; 858 int i; 859 860 /* 861 * Sending a command causes the CMDRDY bit to clear. 862 */ 863 c = bus_space_read_1(iot, ioh, WDS_STAT); 864 for (i = 0; i < 4; i++) 865 if ((bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_RDY) != 0) { 866 goto ready; 867 delay(10); 868 } 869 return (0); 870 871 ready: 872 bus_space_write_1(iot, ioh, WDS_CMD, WDSC_NOOP); 873 if (bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_RDY) 874 return (0); 875 876 bus_space_write_1(iot, ioh, WDS_HCR, WDSH_SCSIRESET|WDSH_ASCRESET); 877 delay(10000); 878 bus_space_write_1(iot, ioh, WDS_HCR, 0x00); 879 delay(500000); 880 wds_wait(iot, ioh, WDS_STAT, WDSS_RDY, WDSS_RDY); 881 if (bus_space_read_1(iot, ioh, WDS_IRQSTAT) != 1) 882 if (bus_space_read_1(iot, ioh, WDS_IRQSTAT) != 7) 883 printf("%s: failed reset!!! %2x\n", 884 sc ? sc->sc_dev.dv_xname : "wds?", 885 bus_space_read_1(iot, ioh, WDS_IRQSTAT)); 886 887 if ((bus_space_read_1(iot, ioh, WDS_STAT) & (WDSS_RDY)) != WDSS_RDY) { 888 printf("%s: waiting for controller to become ready.", 889 sc ? sc->sc_dev.dv_xname : "wds?"); 890 for (i = 0; i < 20; i++) { 891 if ((bus_space_read_1(iot, ioh, WDS_STAT) & 892 (WDSS_RDY)) == WDSS_RDY) 893 break; 894 printf("."); 895 delay(10000); 896 } 897 if ((bus_space_read_1(iot, ioh, WDS_STAT) & (WDSS_RDY)) != 898 WDSS_RDY) { 899 printf(" failed\n"); 900 return (0); 901 } 902 printf("\n"); 903 } 904 905 if (sc != NULL) { 906 /* XXX Can we do this better? */ 907 /* who are we on the scsi bus? */ 908 sc->sc_scsi_dev = 7; 909 910 sc->sc_iot = iot; 911 sc->sc_ioh = ioh; 912 sc->sc_irq = ia->ia_irq; 913 sc->sc_drq = ia->ia_drq; 914 } 915 916 return (1); 917 } 918 919 /* 920 * Initialise the board and driver. 921 */ 922 void 923 wds_init(sc) 924 struct wds_softc *sc; 925 { 926 bus_space_tag_t iot = sc->sc_iot; 927 bus_space_handle_t ioh = sc->sc_ioh; 928 struct wds_setup init; 929 u_char c; 930 int i; 931 #ifdef notyet 932 struct isadma_seg mbx_phys[1]; 933 #endif 934 935 /* 936 * Set up initial mail box for round-robin operation. 937 */ 938 for (i = 0; i < WDS_MBX_SIZE; i++) { 939 wmbx->mbo[i].cmd = WDS_MBO_FREE; 940 wmbx->mbi[i].stat = WDS_MBI_FREE; 941 } 942 wmbx->cmbo = wmbx->tmbo = &wmbx->mbo[0]; 943 wmbx->tmbi = &wmbx->mbi[0]; 944 sc->sc_mbofull = 0; 945 946 /* Clear the buffers. */ 947 TAILQ_INIT(&wds_free_buffer); 948 for (i = 0; i < BUFCNT; i++) { 949 wds_buffer[i].busy = 0; 950 TAILQ_INSERT_HEAD(&wds_free_buffer, &wds_buffer[i], chain); 951 } 952 953 init.opcode = WDSC_INIT; 954 init.scsi_id = sc->sc_scsi_dev; 955 /* Record scsi id of controller for use in scsi_attach */ 956 sc->sc_scsi_dev = init.scsi_id; 957 init.buson_t = 48; 958 init.busoff_t = 24; 959 init.xx = 0; 960 #ifdef notyet 961 if (isadma_map((caddr_t)(wmbx), sizeof(struct wds_mbx), 962 mbx_phys, ISADMA_MAP_CONTIG) != 1) 963 panic("wds_init: cannot map mail box"); 964 ltophys(mbx_phys[0].addr, init.mbaddr); 965 #else 966 ltophys(KVTOPHYS(wmbx), init.mbaddr); 967 #endif 968 init.nomb = init.nimb = WDS_MBX_SIZE; 969 wds_cmd(sc, (u_char *)&init, sizeof init); 970 971 wds_wait(iot, ioh, WDS_STAT, WDSS_INIT, WDSS_INIT); 972 973 c = WDSC_DISUNSOL; 974 wds_cmd(sc, &c, sizeof c); 975 976 bus_space_write_1(iot, ioh, WDS_HCR, WDSH_DRQEN); 977 } 978 979 /* 980 * Read the board's firmware revision information. 981 */ 982 void 983 wds_inquire_setup_information(sc) 984 struct wds_softc *sc; 985 { 986 struct wds_scb *scb; 987 u_char *j; 988 int s; 989 990 if ((scb = wds_get_scb(sc, SCSI_NOSLEEP, 0)) == NULL) { 991 printf("%s: no request slot available in getvers()!\n", 992 sc->sc_dev.dv_xname); 993 return; 994 } 995 scb->xs = NULL; 996 scb->timeout = 40; 997 998 bzero(&scb->cmd, sizeof scb->cmd); 999 scb->cmd.write = 0x80; 1000 scb->cmd.opcode = WDSX_GETFIRMREV; 1001 1002 /* Will poll card, await result. */ 1003 bus_space_write_1(sc->sc_iot, sc->sc_ioh, WDS_HCR, WDSH_DRQEN); 1004 scb->flags |= SCB_POLLED; 1005 1006 s = splbio(); 1007 wds_queue_scb(sc, scb); 1008 splx(s); 1009 1010 if (wds_ipoll(sc, scb, scb->timeout)) 1011 goto out; 1012 1013 /* Print the version number. */ 1014 printf(": version %x.%02x ", scb->cmd.targ, scb->cmd.scb.opcode); 1015 sc->sc_revision = (scb->cmd.targ << 8) | scb->cmd.scb.opcode; 1016 /* Print out the version string. */ 1017 j = 2 + &(scb->cmd.targ); 1018 while ((*j >= 32) && (*j < 128)) { 1019 printf("%c", *j); 1020 j++; 1021 } 1022 1023 out: 1024 printf("\n"); 1025 wds_free_scb(sc, scb); 1026 } 1027 1028 void 1029 wdsminphys(struct buf *bp, struct scsi_link *sl) 1030 { 1031 if (bp->b_bcount > ((WDS_NSEG - 1) << PGSHIFT)) 1032 bp->b_bcount = ((WDS_NSEG - 1) << PGSHIFT); 1033 minphys(bp); 1034 } 1035 1036 /* 1037 * Send a SCSI command. 1038 */ 1039 void 1040 wds_scsi_cmd(xs) 1041 struct scsi_xfer *xs; 1042 { 1043 struct scsi_link *sc_link = xs->sc_link; 1044 struct wds_softc *sc = sc_link->adapter_softc; 1045 bus_space_tag_t iot = sc->sc_iot; 1046 bus_space_handle_t ioh = sc->sc_ioh; 1047 struct wds_scb *scb; 1048 struct wds_scat_gath *sg; 1049 int seg; 1050 u_long thiskv, thisphys, nextphys; 1051 int bytes_this_seg, bytes_this_page, datalen, flags; 1052 int s; 1053 #ifdef notyet 1054 int mflags; 1055 #endif 1056 1057 if (xs->flags & SCSI_RESET) { 1058 /* XXX Fix me! */ 1059 printf("%s: reset!\n", sc->sc_dev.dv_xname); 1060 wds_init(sc); 1061 s = splbio(); 1062 scsi_done(xs); 1063 splx(s); 1064 return; 1065 } 1066 1067 flags = xs->flags; 1068 #ifdef notyet 1069 if (flags & SCSI_NOSLEEP) 1070 mflags = ISADMA_MAP_BOUNCE; 1071 else 1072 mflags = ISADMA_MAP_BOUNCE | ISADMA_MAP_WAITOK; 1073 #endif 1074 if ((scb = wds_get_scb(sc, flags, NEEDBUFFER(sc))) == NULL) { 1075 xs->error = XS_NO_CCB; 1076 s = splbio(); 1077 scsi_done(xs); 1078 splx(s); 1079 return; 1080 } 1081 scb->xs = xs; 1082 scb->timeout = xs->timeout; 1083 1084 /* Zero out the command structure. */ 1085 bzero(&scb->cmd, sizeof scb->cmd); 1086 bcopy(xs->cmd, &scb->cmd.scb, xs->cmdlen < 12 ? xs->cmdlen : 12); 1087 1088 /* Set up some of the command fields. */ 1089 scb->cmd.targ = (xs->sc_link->target << 5) | xs->sc_link->lun; 1090 1091 /* NOTE: cmd.write may be OK as 0x40 (disable direction checking) 1092 * on boards other than the WD-7000V-ASE. Need this for the ASE: 1093 */ 1094 scb->cmd.write = (xs->flags & SCSI_DATA_IN) ? 0x80 : 0x00; 1095 1096 if (!NEEDBUFFER(sc) && xs->datalen) { 1097 sg = scb->scat_gath; 1098 seg = 0; 1099 1100 /* 1101 * Set up the scatter-gather block. 1102 */ 1103 SC_DEBUG(sc_link, SDEV_DB4, 1104 ("%d @0x%x:- ", xs->datalen, xs->data)); 1105 1106 #ifdef notyet 1107 scb->data_nseg = isadma_map(xs->data, xs->datalen, 1108 scb->data_phys, mflags); 1109 for (seg = 0; seg < scb->data_nseg; seg++) { 1110 ltophys(scb->data_phys[seg].addr, 1111 sg[seg].seg_addr); 1112 ltophys(scb->data_phys[seg].length, 1113 sg[seg].seg_len); 1114 } 1115 #else 1116 datalen = xs->datalen; 1117 thiskv = (int)xs->data; 1118 thisphys = KVTOPHYS(xs->data); 1119 1120 while (datalen && seg < WDS_NSEG) { 1121 bytes_this_seg = 0; 1122 1123 /* put in the base address */ 1124 ltophys(thisphys, sg->seg_addr); 1125 1126 SC_DEBUGN(sc_link, SDEV_DB4, ("0x%x", thisphys)); 1127 1128 /* do it at least once */ 1129 nextphys = thisphys; 1130 while (datalen && thisphys == nextphys) { 1131 /* 1132 * This page is contiguous (physically) 1133 * with the last, just extend the 1134 * length 1135 */ 1136 /* check it fits on the ISA bus */ 1137 if (thisphys > 0xFFFFFF) { 1138 printf("%s: DMA beyond" 1139 " end of ISA\n", 1140 sc->sc_dev.dv_xname); 1141 goto bad; 1142 } 1143 /* how far to the end of the page */ 1144 nextphys = (thisphys & ~PGOFSET) + NBPG; 1145 bytes_this_page = nextphys - thisphys; 1146 /**** or the data ****/ 1147 bytes_this_page = min(bytes_this_page, 1148 datalen); 1149 bytes_this_seg += bytes_this_page; 1150 datalen -= bytes_this_page; 1151 1152 /* get more ready for the next page */ 1153 thiskv = (thiskv & ~PGOFSET) + NBPG; 1154 if (datalen) 1155 thisphys = KVTOPHYS(thiskv); 1156 } 1157 /* 1158 * next page isn't contiguous, finish the seg 1159 */ 1160 SC_DEBUGN(sc_link, SDEV_DB4, 1161 ("(0x%x)", bytes_this_seg)); 1162 ltophys(bytes_this_seg, sg->seg_len); 1163 sg++; 1164 seg++; 1165 #endif 1166 } 1167 1168 SC_DEBUGN(sc_link, SDEV_DB4, ("\n")); 1169 if (datalen) { 1170 /* 1171 * there's still data, must have run out of segs! 1172 */ 1173 printf("%s: wds_scsi_cmd, more than %d dma segs\n", 1174 sc->sc_dev.dv_xname, WDS_NSEG); 1175 goto bad; 1176 } 1177 #ifdef notyet 1178 if (scb->data_nseg == 0) { 1179 printf("%s: wds_scsi_cmd, cannot map\n", 1180 sc->sc_dev.dv_xname); 1181 goto bad; 1182 } else if (flags & SCSI_DATA_OUT) 1183 isadma_copytobuf(xs->data, xs->datalen, 1184 scb->data_nseg, scb->data_phys); 1185 ltophys((unsigned)((struct wds_scb *)(scb->scb_phys[0].addr))->scat_gath, 1186 scb->data_addr); 1187 ltophys(scb->data_nseg * sizeof(struct wds_scat_gath), 1188 scb->data_length); 1189 #else 1190 scb->cmd.opcode = WDSX_SCSISG; 1191 ltophys(KVTOPHYS(scb->scat_gath), scb->cmd.data); 1192 ltophys(seg * sizeof(struct wds_scat_gath), scb->cmd.len); 1193 #endif 1194 } else if (xs->datalen > 0) { 1195 /* The board is an ASC or ASE. Do not use scatter/gather. */ 1196 if (xs->datalen > BUFLEN) { 1197 printf("%s: wds_scsi_cmd, I/O too large for bounce buffer\n", 1198 sc->sc_dev.dv_xname); 1199 goto bad; 1200 } 1201 if (xs->flags & SCSI_DATA_OUT) 1202 bcopy(xs->data, scb->buf->data, xs->datalen); 1203 else 1204 bzero(scb->buf->data, xs->datalen); 1205 scb->cmd.opcode = WDSX_SCSICMD; 1206 ltophys(KVTOPHYS(scb->buf->data), scb->cmd.data); 1207 ltophys(xs->datalen, scb->cmd.len); 1208 } else { 1209 scb->cmd.opcode = WDSX_SCSICMD; 1210 ltophys(0, scb->cmd.data); 1211 ltophys(0, scb->cmd.len); 1212 } 1213 1214 scb->cmd.stat = 0x00; 1215 scb->cmd.venderr = 0x00; 1216 ltophys(0, scb->cmd.link); 1217 1218 /* XXX Do we really want to do this? */ 1219 if (flags & SCSI_POLL) { 1220 /* Will poll card, await result. */ 1221 bus_space_write_1(iot, ioh, WDS_HCR, WDSH_DRQEN); 1222 scb->flags |= SCB_POLLED; 1223 } else { 1224 /* Will send command, let interrupt routine handle result. */ 1225 bus_space_write_1(iot, ioh, WDS_HCR, WDSH_IRQEN | WDSH_DRQEN); 1226 } 1227 1228 s = splbio(); 1229 wds_queue_scb(sc, scb); 1230 1231 #ifdef notyet 1232 if (VOLATILE_XS(xs)) { 1233 while ((scb->xs->flags & ITSDONE) == 0) { 1234 tsleep(scb, PRIBIO, "wdswait", 0); 1235 } 1236 if (scb->data_nseg) { 1237 if (flags & SCSI_DATA_IN) 1238 isadma_copyfrombuf(xs->data, xs->datalen, 1239 scb->data_nseg, scb->data_phys); 1240 isadma_unmap(xs->data, xs->datalen, 1241 scb->data_nseg, scb->data_phys); 1242 } 1243 wds_free_scb(sc, scb); 1244 scsi_done(xs); 1245 splx(s); 1246 return; 1247 } 1248 #endif 1249 splx(s); 1250 1251 if ((flags & SCSI_POLL) == 0) 1252 return; 1253 1254 if (wds_poll(sc, xs, scb->timeout)) { 1255 wds_timeout(scb); 1256 if (wds_poll(sc, xs, scb->timeout)) 1257 wds_timeout(scb); 1258 } 1259 return; 1260 1261 bad: 1262 xs->error = XS_DRIVER_STUFFUP; 1263 wds_free_scb(sc, scb); 1264 } 1265 1266 /* 1267 * Send a sense request. 1268 */ 1269 void 1270 wds_sense(sc, scb) 1271 struct wds_softc *sc; 1272 struct wds_scb *scb; 1273 { 1274 struct scsi_xfer *xs = scb->xs; 1275 struct scsi_sense *ss = (void *)&scb->sense.scb; 1276 int s; 1277 1278 /* XXXXX */ 1279 1280 /* Send sense request SCSI command. */ 1281 xs->error = XS_SENSE; 1282 scb->flags |= SCB_SENSE; 1283 1284 /* First, save the return values */ 1285 if (NEEDBUFFER(sc) && xs->datalen) { 1286 if (xs->flags & SCSI_DATA_IN) 1287 bcopy(scb->buf->data, xs->data, xs->datalen); 1288 } 1289 1290 /* Next, setup a request sense command block */ 1291 bzero(ss, sizeof(*ss)); 1292 ss->opcode = REQUEST_SENSE; 1293 ss->byte2 = xs->sc_link->lun << 5; 1294 ss->length = sizeof(struct scsi_sense_data); 1295 1296 /* Set up some of the command fields. */ 1297 scb->sense.targ = scb->cmd.targ; 1298 scb->sense.write = 0x80; 1299 scb->sense.opcode = WDSX_SCSICMD; 1300 ltophys(KVTOPHYS(&scb->sense_data), scb->sense.data); 1301 ltophys(sizeof(struct scsi_sense_data), scb->sense.len); 1302 1303 s = splbio(); 1304 wds_queue_scb(sc, scb); 1305 splx(s); 1306 1307 /* 1308 * There's no reason for us to poll here. There are two cases: 1309 * 1) If it's a polling operation, then we're called from the interrupt 1310 * handler, and we return and continue polling. 1311 * 2) If it's an interrupt-driven operation, then it gets completed 1312 * later on when the REQUEST SENSE finishes. 1313 */ 1314 } 1315 1316 /* 1317 * Poll a particular unit, looking for a particular scb 1318 */ 1319 int 1320 wds_poll(sc, xs, count) 1321 struct wds_softc *sc; 1322 struct scsi_xfer *xs; 1323 int count; 1324 { 1325 bus_space_tag_t iot = sc->sc_iot; 1326 bus_space_handle_t ioh = sc->sc_ioh; 1327 int s; 1328 1329 /* timeouts are in msec, so we loop in 1000 usec cycles */ 1330 while (count) { 1331 /* 1332 * If we had interrupts enabled, would we 1333 * have got an interrupt? 1334 */ 1335 if (bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_IRQ) { 1336 s = splbio(); 1337 wdsintr(sc); 1338 splx(s); 1339 } 1340 if (xs->flags & ITSDONE) 1341 return 0; 1342 delay(1000); /* only happens in boot so ok */ 1343 count--; 1344 } 1345 return 1; 1346 } 1347 1348 /* 1349 * Poll a particular unit, looking for a particular scb 1350 */ 1351 int 1352 wds_ipoll(sc, scb, count) 1353 struct wds_softc *sc; 1354 struct wds_scb *scb; 1355 int count; 1356 { 1357 bus_space_tag_t iot = sc->sc_iot; 1358 bus_space_handle_t ioh = sc->sc_ioh; 1359 int s; 1360 1361 /* timeouts are in msec, so we loop in 1000 usec cycles */ 1362 while (count) { 1363 /* 1364 * If we had interrupts enabled, would we 1365 * have got an interrupt? 1366 */ 1367 if (bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_IRQ) { 1368 s = splbio(); 1369 wdsintr(sc); 1370 splx(s); 1371 } 1372 if (scb->flags & SCB_DONE) 1373 return 0; 1374 delay(1000); /* only happens in boot so ok */ 1375 count--; 1376 } 1377 return 1; 1378 } 1379 1380 void 1381 wds_timeout(arg) 1382 void *arg; 1383 { 1384 struct wds_scb *scb = arg; 1385 struct scsi_xfer *xs; 1386 struct scsi_link *sc_link; 1387 struct wds_softc *sc; 1388 int s; 1389 1390 s = splbio(); 1391 #ifdef notyet 1392 isadma_copyfrombuf((caddr_t)scb, SCB_PHYS_SIZE, 1, scb->scb_phys); 1393 #endif 1394 xs = scb->xs; 1395 sc_link = xs->sc_link; 1396 sc = sc_link->adapter_softc; 1397 1398 sc_print_addr(sc_link); 1399 printf("timed out"); 1400 1401 #ifdef WDSDIAG 1402 /* 1403 * If The scb's mbx is not free, then the board has gone south? 1404 */ 1405 wds_collect_mbo(sc); 1406 if (scb->flags & SCB_SENDING) 1407 panic("%s: not taking commands!", sc->sc_dev.dv_xname); 1408 #endif 1409 1410 /* 1411 * If it has been through before, then 1412 * a previous abort has failed, don't 1413 * try abort again 1414 */ 1415 if (scb->flags & SCB_ABORT) { 1416 /* abort timed out */ 1417 printf(" AGAIN\n"); 1418 /* XXX Must reset! */ 1419 } else { 1420 /* abort the operation that has timed out */ 1421 printf("\n"); 1422 scb->xs->error = XS_TIMEOUT; 1423 scb->timeout = WDS_ABORT_TIMEOUT; 1424 scb->flags |= SCB_ABORT; 1425 wds_queue_scb(sc, scb); 1426 } 1427 1428 splx(s); 1429 } 1430