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