1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2002 Adaptec, Inc. 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 AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR 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 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 /* 33 * CAM front-end for communicating with non-DASD devices 34 */ 35 36 #include "opt_aac.h" 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/sysctl.h> 42 #include <sys/lock.h> 43 #include <sys/malloc.h> 44 #include <sys/module.h> 45 #include <sys/mutex.h> 46 47 #include <cam/cam.h> 48 #include <cam/cam_ccb.h> 49 #include <cam/cam_debug.h> 50 #include <cam/cam_periph.h> 51 #include <cam/cam_sim.h> 52 #include <cam/cam_xpt_sim.h> 53 #include <cam/scsi/scsi_all.h> 54 #include <cam/scsi/scsi_message.h> 55 56 #include <sys/bus.h> 57 #include <sys/conf.h> 58 #include <sys/disk.h> 59 60 #include <machine/md_var.h> 61 #include <machine/bus.h> 62 #include <sys/rman.h> 63 64 #include <vm/vm.h> 65 #include <vm/pmap.h> 66 67 #include <dev/aac/aacreg.h> 68 #include <sys/aac_ioctl.h> 69 #include <dev/aac/aacvar.h> 70 71 struct aac_cam { 72 device_t dev; 73 struct aac_sim *inf; 74 struct cam_sim *sim; 75 struct cam_path *path; 76 }; 77 78 static int aac_cam_probe(device_t dev); 79 static int aac_cam_attach(device_t dev); 80 static int aac_cam_detach(device_t dev); 81 static void aac_cam_action(struct cam_sim *, union ccb *); 82 static void aac_cam_poll(struct cam_sim *); 83 static void aac_cam_complete(struct aac_command *); 84 static void aac_cam_rescan(struct aac_softc *sc, uint32_t channel, 85 uint32_t target_id); 86 87 static u_int32_t aac_cam_reset_bus(struct cam_sim *, union ccb *); 88 static u_int32_t aac_cam_abort_ccb(struct cam_sim *, union ccb *); 89 static u_int32_t aac_cam_term_io(struct cam_sim *, union ccb *); 90 91 static devclass_t aac_pass_devclass; 92 93 static device_method_t aac_pass_methods[] = { 94 DEVMETHOD(device_probe, aac_cam_probe), 95 DEVMETHOD(device_attach, aac_cam_attach), 96 DEVMETHOD(device_detach, aac_cam_detach), 97 DEVMETHOD_END 98 }; 99 100 static driver_t aac_pass_driver = { 101 "aacp", 102 aac_pass_methods, 103 sizeof(struct aac_cam) 104 }; 105 106 DRIVER_MODULE(aacp, aac, aac_pass_driver, aac_pass_devclass, NULL, NULL); 107 MODULE_DEPEND(aacp, cam, 1, 1, 1); 108 109 static MALLOC_DEFINE(M_AACCAM, "aaccam", "AAC CAM info"); 110 111 static void 112 aac_cam_rescan(struct aac_softc *sc, uint32_t channel, uint32_t target_id) 113 { 114 union ccb *ccb; 115 struct aac_sim *sim; 116 struct aac_cam *camsc; 117 118 if (target_id == AAC_CAM_TARGET_WILDCARD) 119 target_id = CAM_TARGET_WILDCARD; 120 121 TAILQ_FOREACH(sim, &sc->aac_sim_tqh, sim_link) { 122 camsc = sim->aac_cam; 123 if (camsc == NULL || camsc->inf == NULL || 124 camsc->inf->BusNumber != channel) 125 continue; 126 127 ccb = xpt_alloc_ccb_nowait(); 128 if (ccb == NULL) { 129 device_printf(sc->aac_dev, 130 "Cannot allocate ccb for bus rescan.\n"); 131 return; 132 } 133 134 if (xpt_create_path(&ccb->ccb_h.path, NULL, 135 cam_sim_path(camsc->sim), 136 target_id, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 137 xpt_free_ccb(ccb); 138 device_printf(sc->aac_dev, 139 "Cannot create path for bus rescan.\n"); 140 return; 141 } 142 xpt_rescan(ccb); 143 break; 144 } 145 } 146 147 static void 148 aac_cam_event(struct aac_softc *sc, struct aac_event *event, void *arg) 149 { 150 union ccb *ccb; 151 struct aac_cam *camsc; 152 153 switch (event->ev_type) { 154 case AAC_EVENT_CMFREE: 155 ccb = arg; 156 camsc = ccb->ccb_h.sim_priv.entries[0].ptr; 157 free(event, M_AACCAM); 158 xpt_release_simq(camsc->sim, 1); 159 ccb->ccb_h.status = CAM_REQUEUE_REQ; 160 xpt_done(ccb); 161 break; 162 default: 163 device_printf(sc->aac_dev, "unknown event %d in aac_cam\n", 164 event->ev_type); 165 break; 166 } 167 } 168 169 static int 170 aac_cam_probe(device_t dev) 171 { 172 fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); 173 174 return (0); 175 } 176 177 static int 178 aac_cam_detach(device_t dev) 179 { 180 struct aac_softc *sc; 181 struct aac_cam *camsc; 182 fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); 183 184 camsc = (struct aac_cam *)device_get_softc(dev); 185 sc = camsc->inf->aac_sc; 186 camsc->inf->aac_cam = NULL; 187 188 mtx_lock(&sc->aac_io_lock); 189 190 xpt_async(AC_LOST_DEVICE, camsc->path, NULL); 191 xpt_free_path(camsc->path); 192 xpt_bus_deregister(cam_sim_path(camsc->sim)); 193 cam_sim_free(camsc->sim, /*free_devq*/TRUE); 194 195 sc->cam_rescan_cb = NULL; 196 197 mtx_unlock(&sc->aac_io_lock); 198 199 return (0); 200 } 201 202 /* 203 * Register the driver as a CAM SIM 204 */ 205 static int 206 aac_cam_attach(device_t dev) 207 { 208 struct cam_devq *devq; 209 struct cam_sim *sim; 210 struct cam_path *path; 211 struct aac_cam *camsc; 212 struct aac_sim *inf; 213 214 fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); 215 216 camsc = (struct aac_cam *)device_get_softc(dev); 217 inf = (struct aac_sim *)device_get_ivars(dev); 218 camsc->inf = inf; 219 camsc->inf->aac_cam = camsc; 220 221 devq = cam_simq_alloc(inf->TargetsPerBus); 222 if (devq == NULL) 223 return (EIO); 224 225 sim = cam_sim_alloc(aac_cam_action, aac_cam_poll, "aacp", camsc, 226 device_get_unit(dev), &inf->aac_sc->aac_io_lock, 1, 1, devq); 227 if (sim == NULL) { 228 cam_simq_free(devq); 229 return (EIO); 230 } 231 232 /* Since every bus has it's own sim, every bus 'appears' as bus 0 */ 233 mtx_lock(&inf->aac_sc->aac_io_lock); 234 if (xpt_bus_register(sim, dev, 0) != CAM_SUCCESS) { 235 cam_sim_free(sim, TRUE); 236 mtx_unlock(&inf->aac_sc->aac_io_lock); 237 return (EIO); 238 } 239 240 if (xpt_create_path(&path, NULL, cam_sim_path(sim), 241 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 242 xpt_bus_deregister(cam_sim_path(sim)); 243 cam_sim_free(sim, TRUE); 244 mtx_unlock(&inf->aac_sc->aac_io_lock); 245 return (EIO); 246 } 247 inf->aac_sc->cam_rescan_cb = aac_cam_rescan; 248 mtx_unlock(&inf->aac_sc->aac_io_lock); 249 250 camsc->sim = sim; 251 camsc->path = path; 252 253 return (0); 254 } 255 256 static void 257 aac_cam_action(struct cam_sim *sim, union ccb *ccb) 258 { 259 struct aac_cam *camsc; 260 struct aac_softc *sc; 261 struct aac_srb *srb; 262 struct aac_fib *fib; 263 struct aac_command *cm; 264 265 camsc = (struct aac_cam *)cam_sim_softc(sim); 266 sc = camsc->inf->aac_sc; 267 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); 268 269 /* Synchronous ops, and ops that don't require communication with the 270 * controller */ 271 switch(ccb->ccb_h.func_code) { 272 case XPT_SCSI_IO: 273 case XPT_RESET_DEV: 274 /* These are handled down below */ 275 break; 276 case XPT_CALC_GEOMETRY: 277 { 278 struct ccb_calc_geometry *ccg; 279 u_int32_t size_mb; 280 u_int32_t secs_per_cylinder; 281 282 ccg = &ccb->ccg; 283 size_mb = ccg->volume_size / 284 ((1024L * 1024L) / ccg->block_size); 285 if (size_mb >= (2 * 1024)) { /* 2GB */ 286 ccg->heads = 255; 287 ccg->secs_per_track = 63; 288 } else if (size_mb >= (1 * 1024)) { /* 1GB */ 289 ccg->heads = 128; 290 ccg->secs_per_track = 32; 291 } else { 292 ccg->heads = 64; 293 ccg->secs_per_track = 32; 294 } 295 secs_per_cylinder = ccg->heads * ccg->secs_per_track; 296 ccg->cylinders = ccg->volume_size / secs_per_cylinder; 297 298 ccb->ccb_h.status = CAM_REQ_CMP; 299 xpt_done(ccb); 300 return; 301 } 302 case XPT_PATH_INQ: 303 { 304 struct ccb_pathinq *cpi = &ccb->cpi; 305 306 cpi->version_num = 1; 307 cpi->hba_inquiry = PI_WIDE_16; 308 cpi->target_sprt = 0; 309 310 /* 311 * Resetting via the passthrough or parallel bus scan 312 * causes problems. 313 */ 314 cpi->hba_misc = PIM_NOBUSRESET | PIM_SEQSCAN; 315 cpi->hba_eng_cnt = 0; 316 cpi->max_target = camsc->inf->TargetsPerBus; 317 cpi->max_lun = 8; /* Per the controller spec */ 318 cpi->initiator_id = camsc->inf->InitiatorBusId; 319 cpi->bus_id = camsc->inf->BusNumber; 320 cpi->base_transfer_speed = 3300; 321 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 322 strlcpy(cpi->hba_vid, "Adaptec", HBA_IDLEN); 323 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 324 cpi->unit_number = cam_sim_unit(sim); 325 cpi->transport = XPORT_SPI; 326 cpi->transport_version = 2; 327 cpi->protocol = PROTO_SCSI; 328 cpi->protocol_version = SCSI_REV_2; 329 ccb->ccb_h.status = CAM_REQ_CMP; 330 xpt_done(ccb); 331 return; 332 } 333 case XPT_GET_TRAN_SETTINGS: 334 { 335 struct ccb_trans_settings_scsi *scsi = 336 &ccb->cts.proto_specific.scsi; 337 struct ccb_trans_settings_spi *spi = 338 &ccb->cts.xport_specific.spi; 339 ccb->cts.protocol = PROTO_SCSI; 340 ccb->cts.protocol_version = SCSI_REV_2; 341 ccb->cts.transport = XPORT_SPI; 342 ccb->cts.transport_version = 2; 343 if (ccb->ccb_h.target_lun != CAM_LUN_WILDCARD) { 344 scsi->valid = CTS_SCSI_VALID_TQ; 345 spi->valid |= CTS_SPI_VALID_DISC; 346 } else { 347 scsi->valid = 0; 348 } 349 ccb->ccb_h.status = CAM_REQ_CMP; 350 xpt_done(ccb); 351 return; 352 } 353 case XPT_SET_TRAN_SETTINGS: 354 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 355 xpt_done(ccb); 356 return; 357 case XPT_RESET_BUS: 358 if (!(sc->flags & AAC_FLAGS_CAM_NORESET)) { 359 ccb->ccb_h.status = aac_cam_reset_bus(sim, ccb); 360 } else { 361 ccb->ccb_h.status = CAM_REQ_CMP; 362 } 363 xpt_done(ccb); 364 return; 365 case XPT_ABORT: 366 ccb->ccb_h.status = aac_cam_abort_ccb(sim, ccb); 367 xpt_done(ccb); 368 return; 369 case XPT_TERM_IO: 370 ccb->ccb_h.status = aac_cam_term_io(sim, ccb); 371 xpt_done(ccb); 372 return; 373 default: 374 device_printf(sc->aac_dev, "Unsupported command 0x%x\n", 375 ccb->ccb_h.func_code); 376 ccb->ccb_h.status = CAM_PROVIDE_FAIL; 377 xpt_done(ccb); 378 return; 379 } 380 381 /* Async ops that require communcation with the controller */ 382 383 if (aac_alloc_command(sc, &cm)) { 384 struct aac_event *event; 385 386 xpt_freeze_simq(sim, 1); 387 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 388 ccb->ccb_h.sim_priv.entries[0].ptr = camsc; 389 event = malloc(sizeof(struct aac_event), M_AACCAM, 390 M_NOWAIT | M_ZERO); 391 if (event == NULL) { 392 device_printf(sc->aac_dev, 393 "Warning, out of memory for event\n"); 394 return; 395 } 396 event->ev_callback = aac_cam_event; 397 event->ev_arg = ccb; 398 event->ev_type = AAC_EVENT_CMFREE; 399 aac_add_event(sc, event); 400 return; 401 } 402 403 fib = cm->cm_fib; 404 srb = (struct aac_srb *)&fib->data[0]; 405 cm->cm_datalen = 0; 406 407 switch (ccb->ccb_h.flags & CAM_DIR_MASK) { 408 case CAM_DIR_IN: 409 srb->flags = AAC_SRB_FLAGS_DATA_IN; 410 cm->cm_flags |= AAC_CMD_DATAIN; 411 break; 412 case CAM_DIR_OUT: 413 srb->flags = AAC_SRB_FLAGS_DATA_OUT; 414 cm->cm_flags |= AAC_CMD_DATAOUT; 415 break; 416 case CAM_DIR_NONE: 417 srb->flags = AAC_SRB_FLAGS_NO_DATA_XFER; 418 break; 419 default: 420 srb->flags = AAC_SRB_FLAGS_UNSPECIFIED_DIRECTION; 421 cm->cm_flags |= AAC_CMD_DATAIN | AAC_CMD_DATAOUT; 422 break; 423 } 424 425 switch(ccb->ccb_h.func_code) { 426 case XPT_SCSI_IO: 427 { 428 struct ccb_scsiio *csio = &ccb->csio; 429 430 srb->function = AAC_SRB_FUNC_EXECUTE_SCSI; 431 432 /* 433 * Copy the CDB into the SRB. It's only 6-16 bytes, 434 * so a copy is not too expensive. 435 */ 436 srb->cdb_len = csio->cdb_len; 437 if (ccb->ccb_h.flags & CAM_CDB_POINTER) 438 bcopy(csio->cdb_io.cdb_ptr, (u_int8_t *)&srb->cdb[0], 439 srb->cdb_len); 440 else 441 bcopy(csio->cdb_io.cdb_bytes, (u_int8_t *)&srb->cdb[0], 442 srb->cdb_len); 443 444 /* Set command */ 445 fib->Header.Command = (sc->flags & AAC_FLAGS_SG_64BIT) ? 446 ScsiPortCommandU64 : ScsiPortCommand; 447 448 /* Map the s/g list. XXX 32bit addresses only! */ 449 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 450 switch ((ccb->ccb_h.flags & CAM_DATA_MASK)) { 451 case CAM_DATA_VADDR: 452 srb->data_len = csio->dxfer_len; 453 /* 454 * Arrange things so that the S/G 455 * map will get set up automagically 456 */ 457 cm->cm_data = (void *)csio->data_ptr; 458 cm->cm_datalen = csio->dxfer_len; 459 cm->cm_sgtable = &srb->sg_map; 460 break; 461 case CAM_DATA_PADDR: 462 /* Send a 32bit command */ 463 fib->Header.Command = ScsiPortCommand; 464 srb->sg_map.SgCount = 1; 465 srb->sg_map.SgEntry[0].SgAddress = 466 (uint32_t)(uintptr_t)csio->data_ptr; 467 srb->sg_map.SgEntry[0].SgByteCount = 468 csio->dxfer_len; 469 srb->data_len = csio->dxfer_len; 470 break; 471 default: 472 /* XXX Need to handle multiple s/g elements */ 473 panic("aac_cam: multiple s/g elements"); 474 } 475 } else { 476 srb->sg_map.SgCount = 0; 477 srb->sg_map.SgEntry[0].SgByteCount = 0; 478 srb->data_len = 0; 479 } 480 481 break; 482 } 483 case XPT_RESET_DEV: 484 if (!(sc->flags & AAC_FLAGS_CAM_NORESET)) { 485 srb->function = AAC_SRB_FUNC_RESET_DEVICE; 486 break; 487 } else { 488 ccb->ccb_h.status = CAM_REQ_CMP; 489 xpt_done(ccb); 490 return; 491 } 492 default: 493 break; 494 } 495 496 srb->bus = camsc->inf->BusNumber; /* Bus number relative to the card */ 497 srb->target = ccb->ccb_h.target_id; 498 srb->lun = ccb->ccb_h.target_lun; 499 srb->timeout = ccb->ccb_h.timeout; /* XXX */ 500 srb->retry_limit = 0; 501 502 cm->cm_complete = aac_cam_complete; 503 cm->cm_private = ccb; 504 cm->cm_timestamp = time_uptime; 505 506 fib->Header.XferState = 507 AAC_FIBSTATE_HOSTOWNED | 508 AAC_FIBSTATE_INITIALISED | 509 AAC_FIBSTATE_FROMHOST | 510 AAC_FIBSTATE_REXPECTED | 511 AAC_FIBSTATE_NORM; 512 fib->Header.Size = sizeof(struct aac_fib_header) + 513 sizeof(struct aac_srb); 514 515 aac_enqueue_ready(cm); 516 aac_startio(cm->cm_sc); 517 } 518 519 static void 520 aac_cam_poll(struct cam_sim *sim) 521 { 522 /* 523 * Pinging the interrupt routine isn't very safe, nor is it 524 * really necessary. Do nothing. 525 */ 526 } 527 528 static void 529 aac_cam_fix_inquiry(struct aac_softc *sc, union ccb *ccb) 530 { 531 struct scsi_inquiry_data *inq; 532 uint8_t *data; 533 uint8_t device, qual; 534 535 /* If this is an inquiry command, fake things out */ 536 if (ccb->ccb_h.flags & CAM_CDB_POINTER) 537 data = ccb->csio.cdb_io.cdb_ptr; 538 else 539 data = ccb->csio.cdb_io.cdb_bytes; 540 541 if (data[0] != INQUIRY) 542 return; 543 544 if (ccb->ccb_h.status == CAM_REQ_CMP) { 545 inq = (struct scsi_inquiry_data *)ccb->csio.data_ptr; 546 device = SID_TYPE(inq); 547 qual = SID_QUAL(inq); 548 549 /* 550 * We want DASD and PROC devices to only be 551 * visible through the pass device. 552 */ 553 if (((device == T_DIRECT) || 554 (device == T_PROCESSOR) || 555 (sc->flags & AAC_FLAGS_CAM_PASSONLY))) { 556 /* 557 * Some aac(4) adapters will always report that a direct 558 * access device is offline in response to a INQUIRY 559 * command that does not retrieve vital product data. 560 * Force the qualifier to connected so that upper layers 561 * correctly recognize that a disk is present. 562 */ 563 if ((data[1] & SI_EVPD) == 0 && device == T_DIRECT && 564 qual == SID_QUAL_LU_OFFLINE) 565 qual = SID_QUAL_LU_CONNECTED; 566 ccb->csio.data_ptr[0] = (qual << 5) | T_NODEVICE; 567 } 568 } else if (ccb->ccb_h.status == CAM_SEL_TIMEOUT && 569 ccb->ccb_h.target_lun != 0) { 570 /* fix for INQUIRYs on Lun>0 */ 571 ccb->ccb_h.status = CAM_DEV_NOT_THERE; 572 } 573 } 574 575 static void 576 aac_cam_complete(struct aac_command *cm) 577 { 578 union ccb *ccb; 579 struct aac_srb_response *srbr; 580 struct aac_softc *sc; 581 int sense_returned; 582 583 sc = cm->cm_sc; 584 fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); 585 ccb = cm->cm_private; 586 srbr = (struct aac_srb_response *)&cm->cm_fib->data[0]; 587 588 if (srbr->fib_status != 0) { 589 device_printf(sc->aac_dev, "Passthru FIB failed!\n"); 590 ccb->ccb_h.status = CAM_REQ_ABORTED; 591 } else { 592 /* 593 * The SRB error codes just happen to match the CAM error 594 * codes. How convenient! 595 */ 596 ccb->ccb_h.status = srbr->srb_status; 597 598 /* Take care of SCSI_IO ops. */ 599 if (ccb->ccb_h.func_code == XPT_SCSI_IO) { 600 ccb->csio.scsi_status = srbr->scsi_status; 601 602 /* Take care of autosense */ 603 if (srbr->sense_len) { 604 sense_returned = srbr->sense_len; 605 if (sense_returned < ccb->csio.sense_len) 606 ccb->csio.sense_resid = 607 ccb->csio.sense_len - 608 sense_returned; 609 else 610 ccb->csio.sense_resid = 0; 611 bzero(&ccb->csio.sense_data, 612 sizeof(struct scsi_sense_data)); 613 bcopy(&srbr->sense[0], &ccb->csio.sense_data, 614 min(ccb->csio.sense_len, sense_returned)); 615 ccb->ccb_h.status |= CAM_AUTOSNS_VALID; 616 // scsi_sense_print(&ccb->csio); 617 } 618 619 aac_cam_fix_inquiry(sc, ccb); 620 } 621 } 622 623 aac_release_command(cm); 624 xpt_done(ccb); 625 } 626 627 static u_int32_t 628 aac_cam_reset_bus(struct cam_sim *sim, union ccb *ccb) 629 { 630 struct aac_fib *fib; 631 struct aac_softc *sc; 632 struct aac_cam *camsc; 633 struct aac_vmioctl *vmi; 634 struct aac_resetbus *rbc; 635 int e; 636 637 camsc = (struct aac_cam *)cam_sim_softc(sim); 638 sc = camsc->inf->aac_sc; 639 640 if (sc == NULL) { 641 printf("aac: Null sc?\n"); 642 return (CAM_REQ_ABORTED); 643 } 644 645 aac_alloc_sync_fib(sc, &fib); 646 647 vmi = (struct aac_vmioctl *)&fib->data[0]; 648 bzero(vmi, sizeof(struct aac_vmioctl)); 649 650 vmi->Command = VM_Ioctl; 651 vmi->ObjType = FT_DRIVE; 652 vmi->MethId = sc->scsi_method_id; 653 vmi->ObjId = 0; 654 vmi->IoctlCmd = ResetBus; 655 656 rbc = (struct aac_resetbus *)&vmi->IoctlBuf[0]; 657 rbc->BusNumber = camsc->inf->BusNumber; 658 659 e = aac_sync_fib(sc, ContainerCommand, 0, fib, 660 sizeof(struct aac_vmioctl)); 661 if (e) { 662 device_printf(sc->aac_dev,"Error %d sending ResetBus command\n", 663 e); 664 aac_release_sync_fib(sc); 665 return (CAM_REQ_ABORTED); 666 } 667 668 aac_release_sync_fib(sc); 669 return (CAM_REQ_CMP); 670 } 671 672 static u_int32_t 673 aac_cam_abort_ccb(struct cam_sim *sim, union ccb *ccb) 674 { 675 return (CAM_UA_ABORT); 676 } 677 678 static u_int32_t 679 aac_cam_term_io(struct cam_sim *sim, union ccb *ccb) 680 { 681 return (CAM_UA_TERMIO); 682 } 683