1 /* $OpenBSD: aic79xx_openbsd.c,v 1.28 2007/10/20 00:21:49 krw Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29 30 /* 31 * Bus independent OpenBSD shim for the aic79xx based Adaptec SCSI controllers 32 * 33 * Copyright (c) 1994-2002 Justin T. Gibbs. 34 * Copyright (c) 2001-2002 Adaptec Inc. 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions, and the following disclaimer, 42 * without modification. 43 * 2. The name of the author may not be used to endorse or promote products 44 * derived from this software without specific prior written permission. 45 * 46 * Alternatively, this software may be distributed under the terms of the 47 * GNU Public License ("GPL"). 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 53 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 */ 62 63 #include <sys/cdefs.h> 64 /* 65 __FBSDID("$FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.c,v 1.16 2003/12/17 00:02:09 gibbs Exp $"); 66 */ 67 68 #include <dev/ic/aic79xx_openbsd.h> 69 #include <dev/ic/aic79xx_inline.h> 70 #include <dev/ic/aic79xx.h> 71 72 #ifndef AHD_TMODE_ENABLE 73 #define AHD_TMODE_ENABLE 0 74 #endif 75 76 /* XXX milos add ahd_ioctl */ 77 int ahd_action(struct scsi_xfer *); 78 int ahd_execute_scb(void *, bus_dma_segment_t *, int); 79 int ahd_poll(struct ahd_softc *, int); 80 int ahd_setup_data(struct ahd_softc *, struct scsi_xfer *, 81 struct scb *); 82 83 void ahd_adapter_req_set_xfer_mode(struct ahd_softc *, struct scb *); 84 void ahd_minphys(struct buf *); 85 86 struct cfdriver ahd_cd = { 87 NULL, "ahd", DV_DULL 88 }; 89 90 static struct scsi_adapter ahd_switch = 91 { 92 ahd_action, 93 ahd_minphys, 94 0, 95 0, 96 }; 97 98 /* the below structure is so we have a default dev struct for our link struct */ 99 static struct scsi_device ahd_dev = 100 { 101 NULL, /* Use default error handler */ 102 NULL, /* have a queue, served by this */ 103 NULL, /* have no async handler */ 104 NULL, /* Use default 'done' routine */ 105 }; 106 107 /* 108 * Attach all the sub-devices we can find 109 */ 110 int 111 ahd_attach(struct ahd_softc *ahd) 112 { 113 struct scsibus_attach_args saa; 114 char ahd_info[256]; 115 int s; 116 117 ahd_controller_info(ahd, ahd_info, sizeof ahd_info); 118 printf("%s\n", ahd_info); 119 ahd_lock(ahd, &s); 120 121 /* 122 * fill in the prototype scsi_links. 123 */ 124 ahd->sc_channel.adapter_target = ahd->our_id; 125 if (ahd->features & AHD_WIDE) 126 ahd->sc_channel.adapter_buswidth = 16; 127 ahd->sc_channel.adapter_softc = ahd; 128 ahd->sc_channel.adapter = &ahd_switch; 129 ahd->sc_channel.openings = 16; 130 ahd->sc_channel.device = &ahd_dev; 131 132 if (bootverbose) { 133 ahd_controller_info(ahd, ahd_info, sizeof ahd_info); 134 printf("%s: %s\n", ahd->sc_dev.dv_xname, ahd_info); 135 } 136 137 ahd_intr_enable(ahd, TRUE); 138 139 if (ahd->flags & AHD_RESET_BUS_A) 140 ahd_reset_channel(ahd, 'A', TRUE); 141 142 bzero(&saa, sizeof(saa)); 143 saa.saa_sc_link = &ahd->sc_channel; 144 145 ahd->sc_child = config_found((void *)&ahd->sc_dev, &saa, scsiprint); 146 147 ahd_unlock(ahd, &s); 148 149 return (1); 150 151 } 152 153 /* 154 * Catch an interrupt from the adapter 155 */ 156 int 157 ahd_platform_intr(void *arg) 158 { 159 struct ahd_softc *ahd; 160 161 /* XXX in ahc there is some bus_dmamap_sync(PREREAD|PREWRITE); */ 162 163 ahd = (struct ahd_softc *)arg; 164 return ahd_intr(ahd); 165 } 166 167 /* 168 * We have an scb which has been processed by the 169 * adaptor, now we look to see how the operation 170 * went. 171 */ 172 void 173 ahd_done(struct ahd_softc *ahd, struct scb *scb) 174 { 175 struct scsi_xfer *xs = scb->xs; 176 int s; 177 178 /* XXX in ahc there is some bus_dmamap_sync(PREREAD|PREWRITE); */ 179 180 LIST_REMOVE(scb, pending_links); 181 182 timeout_del(&xs->stimeout); 183 184 if (xs->datalen) { 185 int op; 186 187 if ((xs->flags & SCSI_DATA_IN) != 0) 188 op = BUS_DMASYNC_POSTREAD; 189 else 190 op = BUS_DMASYNC_POSTWRITE; 191 bus_dmamap_sync(ahd->parent_dmat, scb->dmamap, 0, 192 scb->dmamap->dm_mapsize, op); 193 bus_dmamap_unload(ahd->parent_dmat, scb->dmamap); 194 } 195 196 /* Translate the CAM status code to a SCSI error code. */ 197 switch (xs->error) { 198 case CAM_SCSI_STATUS_ERROR: 199 case CAM_REQ_INPROG: 200 case CAM_REQ_CMP: 201 switch (xs->status) { 202 case SCSI_TASKSET_FULL: 203 /* SCSI Layer won't requeue, so we force infinite 204 * retries until queue space is available. XS_BUSY 205 * is dangerous because if the NOSLEEP flag is set 206 * it can cause the I/O to return EIO. XS_BUSY code 207 * falls through to XS_TIMEOUT anyway. 208 */ 209 xs->error = XS_TIMEOUT; 210 xs->retries++; 211 break; 212 case SCSI_BUSY: 213 xs->error = XS_BUSY; 214 break; 215 case SCSI_CHECK: 216 case SCSI_TERMINATED: 217 if ((scb->flags & SCB_SENSE) == 0) { 218 /* CHECK on CHECK? */ 219 xs->error = XS_DRIVER_STUFFUP; 220 } else 221 xs->error = XS_NOERROR; 222 break; 223 default: 224 xs->error = XS_NOERROR; 225 break; 226 } 227 break; 228 case CAM_BUSY: 229 xs->error = XS_BUSY; 230 break; 231 case CAM_CMD_TIMEOUT: 232 xs->error = XS_TIMEOUT; 233 break; 234 case CAM_BDR_SENT: 235 case CAM_SCSI_BUS_RESET: 236 xs->error = XS_RESET; 237 break; 238 case CAM_REQUEUE_REQ: 239 xs->error = XS_TIMEOUT; 240 xs->retries++; 241 break; 242 case CAM_SEL_TIMEOUT: 243 xs->error = XS_SELTIMEOUT; 244 break; 245 default: 246 xs->error = XS_DRIVER_STUFFUP; 247 break; 248 } 249 250 if (xs->error != XS_NOERROR) { 251 /* Don't clobber any existing error state */ 252 } else if ((scb->flags & SCB_SENSE) != 0) { 253 /* 254 * We performed autosense retrieval. 255 * 256 * Zero any sense not transferred by the 257 * device. The SCSI spec mandates that any 258 * untransfered data should be assumed to be 259 * zero. Complete the 'bounce' of sense information 260 * through buffers accessible via bus-space by 261 * copying it into the clients csio. 262 */ 263 memset(&xs->sense, 0, sizeof(struct scsi_sense_data)); 264 memcpy(&xs->sense, ahd_get_sense_buf(ahd, scb), 265 sizeof(struct scsi_sense_data)); 266 xs->error = XS_SENSE; 267 } else if ((scb->flags & SCB_PKT_SENSE) != 0) { 268 struct scsi_status_iu_header *siu; 269 u_int32_t len; 270 271 siu = (struct scsi_status_iu_header *)scb->sense_data; 272 len = SIU_SENSE_LENGTH(siu); 273 memset(&xs->sense, 0, sizeof(xs->sense)); 274 memcpy(&xs->sense, SIU_SENSE_DATA(siu), 275 ulmin(len, sizeof(xs->sense))); 276 xs->error = XS_SENSE; 277 } 278 279 ahd_lock(ahd, &s); 280 ahd_free_scb(ahd, scb); 281 xs->flags |= ITSDONE; 282 scsi_done(xs); 283 ahd_unlock(ahd, &s); 284 } 285 286 void 287 ahd_minphys(struct buf *bp) 288 { 289 /* 290 * Even though the card can transfer up to 16megs per command 291 * we are limited by the number of segments in the dma segment 292 * list that we can hold. The worst case is that all pages are 293 * discontinuous physically, hence the "page per segment" limit 294 * enforced here. 295 */ 296 if (bp->b_bcount > ((AHD_NSEG - 1) * PAGE_SIZE)) { 297 bp->b_bcount = ((AHD_NSEG - 1) * PAGE_SIZE); 298 } 299 minphys(bp); 300 } 301 302 int32_t 303 ahd_action(struct scsi_xfer *xs) 304 { 305 struct ahd_softc *ahd; 306 struct scb *scb; 307 struct hardware_scb *hscb; 308 u_int target_id; 309 u_int our_id; 310 int s; 311 int dontqueue = 0; 312 struct ahd_initiator_tinfo *tinfo; 313 struct ahd_tmode_tstate *tstate; 314 u_int col_idx; 315 u_int16_t quirks; 316 317 SC_DEBUG(xs->sc_link, SDEV_DB3, ("ahd_action\n")); 318 ahd = (struct ahd_softc *)xs->sc_link->adapter_softc; 319 320 /* determine safety of software queueing */ 321 dontqueue = xs->flags & SCSI_POLL; 322 323 target_id = xs->sc_link->target; 324 our_id = SCSI_SCSI_ID(ahd, xs->sc_link); 325 326 ahd_lock(ahd, &s); 327 if ((ahd->flags & AHD_INITIATORROLE) == 0) { 328 xs->error = XS_DRIVER_STUFFUP; 329 xs->flags |= ITSDONE; 330 scsi_done(xs); 331 ahd_unlock(ahd, &s); 332 return (COMPLETE); 333 } 334 /* 335 * get an scb to use. 336 */ 337 tinfo = ahd_fetch_transinfo(ahd, 'A', our_id, target_id, &tstate); 338 339 quirks = xs->sc_link->quirks; 340 341 if ((quirks & SDEV_NOTAGS) != 0 || 342 (tinfo->curr.ppr_options & MSG_EXT_PPR_PROT_IUS) != 0) 343 col_idx = AHD_NEVER_COL_IDX; 344 else 345 col_idx = AHD_BUILD_COL_IDX(target_id, xs->sc_link->lun); 346 347 if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) { 348 ahd->flags |= AHD_RESOURCE_SHORTAGE; 349 ahd_unlock(ahd, &s); 350 return (TRY_AGAIN_LATER); 351 } 352 ahd_unlock(ahd, &s); 353 354 hscb = scb->hscb; 355 356 SC_DEBUG(xs->sc_link, SDEV_DB3, ("start scb(%p)\n", scb)); 357 358 scb->xs = xs; 359 timeout_set(&xs->stimeout, ahd_timeout, scb); 360 361 /* 362 * Put all the arguments for the xfer in the scb 363 */ 364 hscb->control = 0; 365 hscb->scsiid = BUILD_SCSIID(ahd, xs->sc_link, target_id, our_id); 366 hscb->lun = xs->sc_link->lun; 367 if (xs->xs_control & XS_CTL_RESET) { 368 hscb->cdb_len = 0; 369 scb->flags |= SCB_DEVICE_RESET; 370 hscb->control |= MK_MESSAGE; 371 hscb->task_management = SIU_TASKMGMT_LUN_RESET; 372 return (ahd_execute_scb(scb, NULL, 0)); 373 } else { 374 hscb->task_management = 0; 375 return (ahd_setup_data(ahd, xs, scb)); 376 } 377 } 378 379 int 380 ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments) 381 { 382 struct scb *scb; 383 struct scsi_xfer *xs; 384 struct ahd_softc *ahd; 385 struct ahd_initiator_tinfo *tinfo; 386 struct ahd_tmode_tstate *tstate; 387 u_int mask; 388 int s; 389 390 scb = (struct scb *)arg; 391 xs = scb->xs; 392 xs->error = CAM_REQ_INPROG; 393 xs->status = 0; 394 ahd = (struct ahd_softc *)xs->sc_link->adapter_softc; 395 396 if (nsegments != 0) { 397 void *sg; 398 int op; 399 u_int i; 400 401 ahd_setup_data_scb(ahd, scb); 402 403 /* Copy the segments into our SG list */ 404 for (i = nsegments, sg = scb->sg_list; i > 0; i--) { 405 406 sg = ahd_sg_setup(ahd, scb, sg, dm_segs->ds_addr, 407 dm_segs->ds_len, 408 /*last*/i == 1); 409 dm_segs++; 410 } 411 412 if ((xs->flags & SCSI_DATA_IN) != 0) 413 op = BUS_DMASYNC_PREREAD; 414 else 415 op = BUS_DMASYNC_PREWRITE; 416 417 bus_dmamap_sync(ahd->parent_dmat, scb->dmamap, 0, 418 scb->dmamap->dm_mapsize, op); 419 420 } 421 422 ahd_lock(ahd, &s); 423 424 /* 425 * Last time we need to check if this SCB needs to 426 * be aborted. 427 */ 428 if (xs->flags & ITSDONE) { 429 if (nsegments != 0) 430 bus_dmamap_unload(ahd->parent_dmat, 431 scb->dmamap); 432 ahd_free_scb(ahd, scb); 433 ahd_unlock(ahd, &s); 434 return (COMPLETE); 435 } 436 437 tinfo = ahd_fetch_transinfo(ahd, SCSIID_CHANNEL(ahd, scb->hscb->scsiid), 438 SCSIID_OUR_ID(scb->hscb->scsiid), 439 SCSIID_TARGET(ahd, scb->hscb->scsiid), 440 &tstate); 441 442 mask = SCB_GET_TARGET_MASK(ahd, scb); 443 444 if ((tstate->discenable & mask) != 0) 445 scb->hscb->control |= DISCENB; 446 447 if ((tstate->tagenable & mask) != 0) 448 scb->hscb->control |= TAG_ENB; 449 450 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_PROT_IUS) != 0) { 451 scb->flags |= SCB_PACKETIZED; 452 if (scb->hscb->task_management != 0) 453 scb->hscb->control &= ~MK_MESSAGE; 454 } 455 456 if ((tstate->auto_negotiate & mask) != 0) { 457 scb->flags |= SCB_AUTO_NEGOTIATE; 458 scb->hscb->control |= MK_MESSAGE; 459 } 460 461 /* XXX with ahc there was some bus_dmamap_sync(PREREAD|PREWRITE); */ 462 463 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links); 464 465 if (!(xs->flags & SCSI_POLL)) 466 timeout_add(&xs->stimeout, (xs->timeout * hz) / 1000); 467 468 scb->flags |= SCB_ACTIVE; 469 470 if ((scb->flags & SCB_TARGET_IMMEDIATE) != 0) { 471 /* Define a mapping from our tag to the SCB. */ 472 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb; 473 ahd_pause(ahd); 474 ahd_set_scbptr(ahd, SCB_GET_TAG(scb)); 475 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG); 476 ahd_unpause(ahd); 477 } else { 478 ahd_queue_scb(ahd, scb); 479 } 480 481 if (!(xs->flags & SCSI_POLL)) { 482 int target = xs->sc_link->target; 483 int lun = SCB_GET_LUN(scb); 484 485 if (ahd->inited_target[target] == 0) { 486 struct ahd_devinfo devinfo; 487 488 ahd_adapter_req_set_xfer_mode(ahd, scb); 489 ahd_compile_devinfo(&devinfo, ahd->our_id, target, lun, 490 'A', /*XXX milos*/ROLE_UNKNOWN); 491 ahd_scb_devinfo(ahd, &devinfo, scb); 492 ahd_update_neg_request(ahd, &devinfo, tstate, tinfo, 493 AHD_NEG_IF_NON_ASYNC); 494 ahd->inited_target[target] = 1; 495 } 496 497 ahd_unlock(ahd, &s); 498 return (SUCCESSFULLY_QUEUED); 499 } 500 501 /* 502 * If we can't use interrupts, poll for completion 503 */ 504 SC_DEBUG(xs->sc_link, SDEV_DB3, ("cmd_poll\n")); 505 506 do { 507 if (ahd_poll(ahd, xs->timeout)) { 508 if (!(xs->flags & SCSI_SILENT)) 509 printf("cmd fail\n"); 510 ahd_timeout(scb); 511 break; 512 } 513 } while (!(xs->flags & ITSDONE)); 514 515 ahd_unlock(ahd, &s); 516 return (COMPLETE); 517 } 518 519 int 520 ahd_poll(struct ahd_softc *ahd, int wait) 521 { 522 while (--wait) { 523 DELAY(1000); 524 if (ahd_inb(ahd, INTSTAT) & INT_PEND) 525 break; 526 } 527 528 if (wait == 0) { 529 printf("%s: board is not responding\n", ahd_name(ahd)); 530 return (EIO); 531 } 532 533 ahd_intr((void *)ahd); 534 return (0); 535 } 536 537 int 538 ahd_setup_data(struct ahd_softc *ahd, struct scsi_xfer *xs, 539 struct scb *scb) 540 { 541 struct hardware_scb *hscb; 542 int s; 543 544 hscb = scb->hscb; 545 xs->resid = xs->status = 0; 546 xs->error = CAM_REQ_INPROG; 547 548 hscb->cdb_len = xs->cmdlen; 549 if (hscb->cdb_len > MAX_CDB_LEN) { 550 ahd_lock(ahd, &s); 551 ahd_free_scb(ahd, scb); 552 xs->error = XS_DRIVER_STUFFUP; 553 xs->flags |= ITSDONE; 554 scsi_done(xs); 555 ahd_unlock(ahd, &s); 556 return (COMPLETE); 557 } 558 559 memcpy(hscb->shared_data.idata.cdb, xs->cmd, hscb->cdb_len); 560 561 /* Only use S/G if there is a transfer */ 562 if (xs->datalen) { 563 int error; 564 565 error = bus_dmamap_load(ahd->parent_dmat, 566 scb->dmamap, xs->data, 567 xs->datalen, NULL, 568 ((xs->flags & SCSI_NOSLEEP) ? 569 BUS_DMA_NOWAIT : BUS_DMA_WAITOK) | 570 BUS_DMA_STREAMING | 571 ((xs->flags & XS_CTL_DATA_IN) ? 572 BUS_DMA_READ : BUS_DMA_WRITE)); 573 if (error) { 574 #ifdef AHD_DEBUG 575 printf("%s: in ahd_setup_data(): bus_dmamap_load() " 576 "= %d\n", ahd_name(ahd), error); 577 #endif 578 ahd_lock(ahd, &s); 579 ahd_free_scb(ahd, scb); 580 ahd_unlock(ahd, &s); 581 return (TRY_AGAIN_LATER); /* XXX fvdl */ 582 } 583 error = ahd_execute_scb(scb, scb->dmamap->dm_segs, 584 scb->dmamap->dm_nsegs); 585 return error; 586 } else { 587 return ahd_execute_scb(scb, NULL, 0); 588 } 589 } 590 591 void 592 ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, 593 ahd_queue_alg alg) 594 { 595 struct ahd_tmode_tstate *tstate; 596 597 ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid, 598 devinfo->target, &tstate); 599 600 if (alg != AHD_QUEUE_NONE) 601 tstate->tagenable |= devinfo->target_mask; 602 else 603 tstate->tagenable &= ~devinfo->target_mask; 604 } 605 606 int 607 ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg) 608 { 609 if (sizeof(struct ahd_platform_data) > 0) { 610 ahd->platform_data = malloc(sizeof(struct ahd_platform_data), 611 M_DEVBUF, M_NOWAIT | M_ZERO); 612 if (ahd->platform_data == NULL) 613 return (ENOMEM); 614 } 615 616 return (0); 617 } 618 619 void 620 ahd_platform_free(struct ahd_softc *ahd) 621 { 622 if (sizeof(struct ahd_platform_data) > 0) 623 free(ahd->platform_data, M_DEVBUF); 624 } 625 626 int 627 ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd) 628 { 629 /* We don't sort softcs under OpenBSD so report equal always */ 630 return (0); 631 } 632 633 int 634 ahd_detach(struct device *self, int flags) 635 { 636 int rv = 0; 637 638 struct ahd_softc *ahd = (struct ahd_softc*)self; 639 640 if (ahd->sc_child != NULL) 641 rv = config_detach((void *)ahd->sc_child, flags); 642 643 if (ahd->shutdown_hook != NULL) 644 shutdownhook_disestablish(ahd->shutdown_hook); 645 646 ahd_free(ahd); 647 648 return rv; 649 } 650 651 void 652 ahd_adapter_req_set_xfer_mode(struct ahd_softc *ahd, struct scb *scb) 653 { 654 struct ahd_initiator_tinfo *tinfo; 655 struct ahd_tmode_tstate *tstate; 656 int target_id, our_id; 657 struct ahd_devinfo devinfo; 658 u_int16_t quirks; 659 u_int width, ppr_options, period, offset; 660 int s; 661 662 target_id = scb->xs->sc_link->target; 663 our_id = SCSI_SCSI_ID(ahd, scb->xs->sc_link); 664 665 s = splbio(); 666 667 quirks = scb->xs->sc_link->quirks; 668 tinfo = ahd_fetch_transinfo(ahd, 'A', our_id, target_id, &tstate); 669 ahd_compile_devinfo(&devinfo, our_id, target_id, 0, 'A', 670 ROLE_INITIATOR); 671 672 tstate->discenable |= (ahd->user_discenable & devinfo.target_mask); 673 674 if (quirks & SDEV_NOTAGS) 675 tstate->tagenable &= ~devinfo.target_mask; 676 else if (ahd->user_tagenable & devinfo.target_mask) 677 tstate->tagenable |= devinfo.target_mask; 678 679 if (quirks & SDEV_NOWIDE) 680 width = MSG_EXT_WDTR_BUS_8_BIT; 681 else 682 width = MSG_EXT_WDTR_BUS_16_BIT; 683 684 ahd_validate_width(ahd, NULL, &width, ROLE_UNKNOWN); 685 if (width > tinfo->user.width) 686 width = tinfo->user.width; 687 ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE); 688 689 if (quirks & SDEV_NOSYNC) { 690 period = 0; 691 offset = 0; 692 } else { 693 period = tinfo->user.period; 694 offset = tinfo->user.offset; 695 } 696 697 /* XXX Look at saved INQUIRY flags for PPR capabilities XXX */ 698 ppr_options = tinfo->user.ppr_options; 699 /* XXX Other reasons to avoid ppr? XXX */ 700 if (width < MSG_EXT_WDTR_BUS_16_BIT) 701 ppr_options = 0; 702 703 if ((tstate->discenable & devinfo.target_mask) == 0 || 704 (tstate->tagenable & devinfo.target_mask) == 0) 705 ppr_options &= ~MSG_EXT_PPR_PROT_IUS; 706 707 ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX); 708 ahd_validate_offset(ahd, NULL, period, &offset, width, ROLE_UNKNOWN); 709 710 if (offset == 0) { 711 period = 0; 712 ppr_options = 0; 713 } 714 715 if (ppr_options != 0 && tinfo->user.transport_version >= 3) { 716 tinfo->goal.transport_version = tinfo->user.transport_version; 717 tinfo->curr.transport_version = tinfo->user.transport_version; 718 } 719 720 ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options, 721 AHD_TRANS_GOAL, FALSE); 722 723 splx(s); 724 } 725 726 void 727 aic_timer_reset(aic_timer_t *timer, u_int msec, ahd_callback_t *func, 728 void *arg) 729 { 730 uint64_t ticks; 731 732 ticks = msec; 733 ticks *= hz; 734 ticks /= 1000; 735 callout_reset(timer, ticks, func, arg); 736 } 737 738 void 739 aic_scb_timer_reset(struct scb *scb, u_int msec) 740 { 741 uint64_t ticks; 742 743 ticks = msec; 744 ticks *= hz; 745 ticks /= 1000; 746 if (!(scb->xs->xs_control & XS_CTL_POLL)) 747 callout_reset(&scb->xs->xs_callout, ticks, ahd_timeout, scb); 748 } 749 750 void 751 ahd_flush_device_writes(struct ahd_softc *ahd) 752 { 753 /* XXX Is this sufficient for all architectures??? */ 754 ahd_inb(ahd, INTSTAT); 755 } 756 757 void 758 aic_platform_scb_free(struct ahd_softc *ahd, struct scb *scb) 759 { 760 int s; 761 762 ahd_lock(ahd, &s); 763 764 if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0) { 765 ahd->flags &= ~AHD_RESOURCE_SHORTAGE; 766 } 767 768 if (!cold) { 769 /* we are no longer in autoconf */ 770 timeout_del(&scb->xs->stimeout); 771 } 772 773 ahd_unlock(ahd, &s); 774 } 775 776 void 777 ahd_print_path(struct ahd_softc *ahd, struct scb *scb) 778 { 779 sc_print_addr(scb->xs->sc_link); 780 } 781 782 void 783 ahd_platform_dump_card_state(struct ahd_softc *ahd) 784 { 785 /* Nothing to do here for OpenBSD */ 786 printf("FEATURES = 0x%x, FLAGS = 0x%x, CHIP = 0x%x BUGS =0x%x\n", 787 ahd->features, ahd->flags, ahd->chip, ahd->bugs); 788 } 789 790 void 791 ahd_platform_flushwork(struct ahd_softc *ahd) 792 { 793 } 794