1 /*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Copyright (c) 2002 Eric Moore 28 * Copyright (c) 2002 LSI Logic Corporation 29 * All rights reserved. 30 * 31 * Redistribution and use in source and binary forms, with or without 32 * modification, are permitted provided that the following conditions 33 * are met: 34 * 1. Redistributions of source code must retain the above copyright 35 * notice, this list of conditions and the following disclaimer. 36 * 2. Redistributions in binary form must reproduce the above copyright 37 * notice, this list of conditions and the following disclaimer in the 38 * documentation and/or other materials provided with the distribution. 39 * 3. The party using or redistributing the source code and binary forms 40 * agrees to the disclaimer below and the terms and conditions set forth 41 * herein. 42 * 43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53 * SUCH DAMAGE. 54 * 55 * $FreeBSD: src/sys/dev/amr/amr_cam.c,v 1.1.2.3 2002/11/11 13:19:10 emoore Exp $ 56 * $DragonFly: src/sys/dev/raid/amr/amr_cam.c,v 1.6 2005/06/09 20:55:05 swildner Exp $ 57 */ 58 59 #include <sys/param.h> 60 #include <sys/systm.h> 61 #include <sys/malloc.h> 62 #include <sys/kernel.h> 63 64 #include "amr_compat.h" 65 #include <sys/bus.h> 66 #include <sys/conf.h> 67 #include <sys/devicestat.h> 68 #include <sys/disk.h> 69 #include <sys/stat.h> 70 71 #include <bus/cam/cam.h> 72 #include <bus/cam/cam_ccb.h> 73 #include <bus/cam/cam_sim.h> 74 #include <bus/cam/cam_xpt.h> 75 #include <bus/cam/cam_xpt_sim.h> 76 #include <bus/cam/cam_debug.h> 77 #include <bus/cam/scsi/scsi_all.h> 78 #include <bus/cam/scsi/scsi_message.h> 79 80 #include <machine/resource.h> 81 #include <machine/bus.h> 82 83 #include "amrreg.h" 84 #include "amrvar.h" 85 86 static void amr_cam_action(struct cam_sim *sim, union ccb *ccb); 87 static void amr_cam_poll(struct cam_sim *sim); 88 static void amr_cam_complete(struct amr_command *ac); 89 static void amr_cam_complete_extcdb(struct amr_command *ac); 90 91 92 /******************************************************************************** 93 * Enqueue/dequeue functions 94 */ 95 static __inline void 96 amr_enqueue_ccb(struct amr_softc *sc, union ccb *ccb) 97 { 98 crit_enter(); 99 TAILQ_INSERT_TAIL(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe); 100 crit_exit(); 101 } 102 103 static __inline void 104 amr_requeue_ccb(struct amr_softc *sc, union ccb *ccb) 105 { 106 crit_enter(); 107 TAILQ_INSERT_HEAD(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe); 108 crit_exit(); 109 } 110 111 static __inline union ccb * 112 amr_dequeue_ccb(struct amr_softc *sc) 113 { 114 union ccb *ccb; 115 116 crit_enter(); 117 if ((ccb = (union ccb *)TAILQ_FIRST(&sc->amr_cam_ccbq)) != NULL) 118 TAILQ_REMOVE(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe); 119 crit_exit(); 120 return(ccb); 121 } 122 123 /******************************************************************************** 124 * Attach our 'real' SCSI channels to CAM 125 */ 126 int 127 amr_cam_attach(struct amr_softc *sc) 128 { 129 struct cam_devq *devq; 130 int chn; 131 132 /* initialise the ccb queue */ 133 TAILQ_INIT(&sc->amr_cam_ccbq); 134 135 /* 136 * Allocate a devq for all our channels combined. This should 137 * allow for the maximum number of SCSI commands we will accept 138 * at one time. 139 */ 140 if ((devq = cam_simq_alloc(AMR_MAX_SCSI_CMDS)) == NULL) 141 return(ENOMEM); 142 143 /* 144 * Iterate over our channels, registering them with CAM 145 */ 146 for (chn = 0; chn < sc->amr_maxchan; chn++) { 147 148 /* allocate a sim */ 149 if ((sc->amr_cam_sim[chn] = cam_sim_alloc(amr_cam_action, 150 amr_cam_poll, 151 "amr", 152 sc, 153 device_get_unit(sc->amr_dev), 154 1, 155 AMR_MAX_SCSI_CMDS, 156 devq)) == NULL) { 157 device_printf(sc->amr_dev, "CAM SIM attach failed\n"); 158 return(ENOMEM); 159 } 160 161 /* register the bus ID so we can get it later */ 162 if (xpt_bus_register(sc->amr_cam_sim[chn], chn)) { 163 device_printf(sc->amr_dev, "CAM XPT bus registration failed\n"); 164 return(ENXIO); 165 } 166 } 167 cam_simq_release(devq); 168 /* 169 * XXX we should scan the config and work out which devices are actually 170 * protected. 171 */ 172 return(0); 173 } 174 175 /******************************************************************************** 176 * Disconnect ourselves from CAM 177 */ 178 void 179 amr_cam_detach(struct amr_softc *sc) 180 { 181 int chn; 182 183 /* 184 * If a sim was allocated for a channel, free it 185 */ 186 for (chn = 0; chn < sc->amr_maxchan; chn++) { 187 if (sc->amr_cam_sim[chn] != NULL) { 188 xpt_bus_deregister(cam_sim_path(sc->amr_cam_sim[chn])); 189 cam_sim_free(sc->amr_cam_sim[chn]); 190 } 191 } 192 } 193 194 /******************************************************************************** 195 ******************************************************************************** 196 CAM passthrough interface 197 ******************************************************************************** 198 ********************************************************************************/ 199 200 /******************************************************************************** 201 * Handle a request for action from CAM 202 */ 203 static void 204 amr_cam_action(struct cam_sim *sim, union ccb *ccb) 205 { 206 struct amr_softc *sc = cam_sim_softc(sim); 207 208 switch(ccb->ccb_h.func_code) { 209 210 /* 211 * Perform SCSI I/O to a physical device. 212 */ 213 case XPT_SCSI_IO: 214 { 215 struct ccb_hdr *ccbh = &ccb->ccb_h; 216 struct ccb_scsiio *csio = &ccb->csio; 217 218 /* Validate the CCB */ 219 ccbh->status = CAM_REQ_INPROG; 220 221 /* check the CDB length */ 222 if (csio->cdb_len > AMR_MAX_EXTCDB_LEN) 223 ccbh->status = CAM_REQ_CMP_ERR; 224 225 if ((csio->cdb_len > AMR_MAX_CDB_LEN) && (sc->support_ext_cdb == 0 )) 226 ccbh->status = CAM_REQ_CMP_ERR; 227 228 /* check that the CDB pointer is not to a physical address */ 229 if ((ccbh->flags & CAM_CDB_POINTER) && (ccbh->flags & CAM_CDB_PHYS)) 230 ccbh->status = CAM_REQ_CMP_ERR; 231 232 /* if there is data transfer, it must be to/from a virtual address */ 233 if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 234 if (ccbh->flags & CAM_DATA_PHYS) /* we can't map it */ 235 ccbh->status = CAM_REQ_CMP_ERR; 236 if (ccbh->flags & CAM_SCATTER_VALID) /* we want to do the s/g setup */ 237 ccbh->status = CAM_REQ_CMP_ERR; 238 } 239 240 /* 241 * If the command is to a LUN other than 0, fail it. 242 * This is probably incorrect, but during testing the firmware did not 243 * seem to respect the LUN field, and thus devices appear echoed. 244 */ 245 if (csio->ccb_h.target_lun != 0) 246 ccbh->status = CAM_REQ_CMP_ERR; 247 248 /* if we're happy with the request, queue it for attention */ 249 if (ccbh->status == CAM_REQ_INPROG) { 250 251 /* save the channel number in the ccb */ 252 csio->ccb_h.sim_priv.entries[0].field = cam_sim_bus(sim); 253 254 amr_enqueue_ccb(sc, ccb); 255 amr_startio(sc); 256 return; 257 } 258 break; 259 } 260 261 case XPT_CALC_GEOMETRY: 262 { 263 struct ccb_calc_geometry *ccg = &ccb->ccg; 264 u_int32_t size_in_mb; 265 u_int32_t secs_per_cylinder; 266 267 size_in_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size); 268 269 if (size_in_mb > 1024) { 270 ccg->heads = 255; 271 ccg->secs_per_track = 63; 272 } else { 273 ccg->heads = 64; 274 ccg->secs_per_track = 32; 275 } 276 secs_per_cylinder = ccg->heads * ccg->secs_per_track; 277 ccg->cylinders = ccg->volume_size / secs_per_cylinder; 278 ccb->ccb_h.status = CAM_REQ_CMP; 279 break; 280 } 281 282 /* 283 * Return path stats. Some of these should probably be 284 * amended. 285 */ 286 case XPT_PATH_INQ: 287 { 288 struct ccb_pathinq *cpi = & ccb->cpi; 289 290 debug(3, "XPT_PATH_INQ"); 291 cpi->version_num = 1; /* XXX??? */ 292 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16; 293 cpi->target_sprt = 0; 294 cpi->hba_misc = PIM_NOBUSRESET; 295 cpi->hba_eng_cnt = 0; 296 cpi->max_target = AMR_MAX_TARGETS; 297 cpi->max_lun = 0 /* AMR_MAX_LUNS*/; 298 cpi->initiator_id = 7; /* XXX variable? */ 299 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 300 strncpy(cpi->hba_vid, "LSI", HBA_IDLEN); 301 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 302 cpi->unit_number = cam_sim_unit(sim); 303 cpi->bus_id = cam_sim_bus(sim); 304 cpi->base_transfer_speed = 132 * 1024; /* XXX get from controller? */ 305 cpi->ccb_h.status = CAM_REQ_CMP; 306 307 break; 308 } 309 310 case XPT_RESET_BUS: 311 { 312 struct ccb_pathinq *cpi = & ccb->cpi; 313 314 debug(1, "XPT_RESET_BUS"); 315 cpi->ccb_h.status = CAM_REQ_CMP; 316 break; 317 } 318 319 case XPT_RESET_DEV: 320 { 321 debug(1, "XPT_RESET_DEV"); 322 ccb->ccb_h.status = CAM_REQ_CMP; 323 break; 324 } 325 326 case XPT_GET_TRAN_SETTINGS: 327 { 328 struct ccb_trans_settings *cts; 329 330 debug(3, "XPT_GET_TRAN_SETTINGS"); 331 332 cts = &(ccb->cts); 333 334 if ((cts->flags & CCB_TRANS_USER_SETTINGS) == 0) { 335 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 336 break; 337 } 338 339 cts->flags = CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB; 340 cts->bus_width = MSG_EXT_WDTR_BUS_32_BIT; 341 cts->sync_period = 6; /* 40MHz how wide is this bus? */ 342 cts->sync_offset = 31; /* How to extract this from board? */ 343 344 cts->valid = CCB_TRANS_SYNC_RATE_VALID 345 | CCB_TRANS_SYNC_OFFSET_VALID 346 | CCB_TRANS_BUS_WIDTH_VALID 347 | CCB_TRANS_DISC_VALID 348 | CCB_TRANS_TQ_VALID; 349 ccb->ccb_h.status = CAM_REQ_CMP; 350 break; 351 } 352 353 case XPT_SET_TRAN_SETTINGS: 354 debug(3, "XPT_SET_TRAN_SETTINGS"); 355 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 356 break; 357 358 359 /* 360 * Reject anything else as unsupported. 361 */ 362 default: 363 /* we can't do this */ 364 ccb->ccb_h.status = CAM_REQ_INVALID; 365 break; 366 } 367 xpt_done(ccb); 368 } 369 370 /******************************************************************************** 371 * Convert a CAM CCB off the top of the CCB queue to a passthrough SCSI command. 372 */ 373 int 374 amr_cam_command(struct amr_softc *sc, struct amr_command **acp) 375 { 376 struct amr_command *ac; 377 struct amr_passthrough *ap; 378 struct amr_ext_passthrough *aep; 379 struct ccb_scsiio *csio; 380 int bus, target, error; 381 382 error = 0; 383 ac = NULL; 384 ap = NULL; 385 aep = NULL; 386 387 /* check to see if there is a ccb for us to work with */ 388 if ((csio = (struct ccb_scsiio *)amr_dequeue_ccb(sc)) == NULL) 389 goto out; 390 391 /* get bus/target, XXX validate against protected devices? */ 392 bus = csio->ccb_h.sim_priv.entries[0].field; 393 target = csio->ccb_h.target_id; 394 395 /* 396 * Build a passthrough command. 397 */ 398 399 /* construct passthrough */ 400 if (sc->support_ext_cdb ) { 401 aep = malloc(sizeof(*aep), M_DEVBUF, M_INTWAIT | M_ZERO); 402 aep->ap_timeout = 2; 403 aep->ap_ars = 1; 404 aep->ap_request_sense_length = 14; 405 aep->ap_islogical = 0; 406 aep->ap_channel = bus; 407 aep->ap_scsi_id = target; 408 aep->ap_logical_drive_no = csio->ccb_h.target_lun; 409 aep->ap_cdb_length = csio->cdb_len; 410 aep->ap_data_transfer_length = csio->dxfer_len; 411 if (csio->ccb_h.flags & CAM_CDB_POINTER) { 412 bcopy(csio->cdb_io.cdb_ptr, aep->ap_cdb, csio->cdb_len); 413 } else { 414 bcopy(csio->cdb_io.cdb_bytes, aep->ap_cdb, csio->cdb_len); 415 } 416 /* we leave the data s/g list and s/g count to the map routine later */ 417 418 debug(2, " COMMAND %x/%d+%d to %d:%d:%d", aep->ap_cdb[0], aep->ap_cdb_length, csio->dxfer_len, 419 aep->ap_channel, aep->ap_scsi_id, aep->ap_logical_drive_no); 420 421 } else { 422 ap = malloc(sizeof(*ap), M_DEVBUF, M_INTWAIT | M_ZERO); 423 ap->ap_timeout = 0; 424 ap->ap_ars = 1; 425 ap->ap_request_sense_length = 14; 426 ap->ap_islogical = 0; 427 ap->ap_channel = bus; 428 ap->ap_scsi_id = target; 429 ap->ap_logical_drive_no = csio->ccb_h.target_lun; 430 ap->ap_cdb_length = csio->cdb_len; 431 ap->ap_data_transfer_length = csio->dxfer_len; 432 if (csio->ccb_h.flags & CAM_CDB_POINTER) { 433 bcopy(csio->cdb_io.cdb_ptr, ap->ap_cdb, csio->cdb_len); 434 } else { 435 bcopy(csio->cdb_io.cdb_bytes, ap->ap_cdb, csio->cdb_len); 436 } 437 /* we leave the data s/g list and s/g count to the map routine later */ 438 439 debug(2, " COMMAND %x/%d+%d to %d:%d:%d", ap->ap_cdb[0], ap->ap_cdb_length, csio->dxfer_len, 440 ap->ap_channel, ap->ap_scsi_id, ap->ap_logical_drive_no); 441 } 442 443 /* construct command */ 444 if ((ac = amr_alloccmd(sc)) == NULL) { 445 error = ENOMEM; 446 goto out; 447 } 448 449 ac->ac_flags |= AMR_CMD_DATAOUT; 450 451 ac->ac_ccb_data = csio->data_ptr; 452 ac->ac_ccb_length = csio->dxfer_len; 453 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) 454 ac->ac_flags |= AMR_CMD_CCB_DATAIN; 455 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) 456 ac->ac_flags |= AMR_CMD_CCB_DATAOUT; 457 458 ac->ac_private = csio; 459 if ( sc->support_ext_cdb ) { 460 ac->ac_data = aep; 461 ac->ac_length = sizeof(*aep); 462 ac->ac_complete = amr_cam_complete_extcdb; 463 ac->ac_mailbox.mb_command = AMR_CMD_EXTPASS; 464 } else { 465 ac->ac_data = ap; 466 ac->ac_length = sizeof(*ap); 467 ac->ac_complete = amr_cam_complete; 468 ac->ac_mailbox.mb_command = AMR_CMD_PASS; 469 } 470 471 out: 472 if (error != 0) { 473 if (ac != NULL) 474 amr_releasecmd(ac); 475 if (ap != NULL) 476 free(ap, M_DEVBUF); 477 if (aep != NULL) 478 free(aep, M_DEVBUF); 479 if (csio != NULL) /* put it back and try again later */ 480 amr_requeue_ccb(sc, (union ccb *)csio); 481 } 482 *acp = ac; 483 return(error); 484 } 485 486 /******************************************************************************** 487 * Check for interrupt status 488 */ 489 static void 490 amr_cam_poll(struct cam_sim *sim) 491 { 492 amr_done(cam_sim_softc(sim)); 493 } 494 495 /******************************************************************************** 496 * Handle completion of a command submitted via CAM. 497 */ 498 static void 499 amr_cam_complete(struct amr_command *ac) 500 { 501 struct amr_passthrough *ap = (struct amr_passthrough *)ac->ac_data; 502 struct ccb_scsiio *csio = (struct ccb_scsiio *)ac->ac_private; 503 struct scsi_inquiry_data *inq = (struct scsi_inquiry_data *)csio->data_ptr; 504 505 /* XXX note that we're ignoring ac->ac_status - good idea? */ 506 507 debug(1, "status 0x%x scsi_status 0x%x", ac->ac_status, ap->ap_scsi_status); 508 509 /* 510 * Hide disks from CAM so that they're not picked up and treated as 'normal' disks. 511 * 512 * If the configuration provides a mechanism to mark a disk a "not managed", we 513 * could add handling for that to allow disks to be selectively visible. 514 */ 515 516 if ((ap->ap_cdb[0] == INQUIRY) && (SID_TYPE(inq) == T_DIRECT)) { 517 bzero(csio->data_ptr, csio->dxfer_len); 518 if (ap->ap_scsi_status == 0xf0) { 519 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR; 520 } else { 521 csio->ccb_h.status = CAM_DEV_NOT_THERE; 522 } 523 } else { 524 525 /* handle passthrough SCSI status */ 526 switch(ap->ap_scsi_status) { 527 case 0: /* completed OK */ 528 csio->ccb_h.status = CAM_REQ_CMP; 529 break; 530 531 case 0x02: 532 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR; 533 csio->scsi_status = SCSI_STATUS_CHECK_COND; 534 bcopy(ap->ap_request_sense_area, &csio->sense_data, AMR_MAX_REQ_SENSE_LEN); 535 csio->sense_len = AMR_MAX_REQ_SENSE_LEN; 536 csio->ccb_h.status |= CAM_AUTOSNS_VALID; 537 break; 538 539 case 0x08: 540 csio->ccb_h.status = CAM_SCSI_BUSY; 541 break; 542 543 case 0xf0: 544 case 0xf4: 545 default: 546 csio->ccb_h.status = CAM_REQ_CMP_ERR; 547 break; 548 } 549 } 550 free(ap, M_DEVBUF); 551 if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) 552 debug(2, "%*D\n", imin(csio->dxfer_len, 16), csio->data_ptr, " "); 553 xpt_done((union ccb *)csio); 554 amr_releasecmd(ac); 555 } 556 557 /******************************************************************************** 558 * Handle completion of a command submitted via CAM. 559 * Completion for extended cdb 560 */ 561 static void 562 amr_cam_complete_extcdb(struct amr_command *ac) 563 { 564 struct amr_ext_passthrough *aep = (struct amr_ext_passthrough *)ac->ac_data; 565 struct ccb_scsiio *csio = (struct ccb_scsiio *)ac->ac_private; 566 struct scsi_inquiry_data *inq = (struct scsi_inquiry_data *)csio->data_ptr; 567 568 /* XXX note that we're ignoring ac->ac_status - good idea? */ 569 570 debug(1, "status 0x%x scsi_status 0x%x", ac->ac_status, aep->ap_scsi_status); 571 572 /* 573 * Hide disks from CAM so that they're not picked up and treated as 'normal' disks. 574 * 575 * If the configuration provides a mechanism to mark a disk a "not managed", we 576 * could add handling for that to allow disks to be selectively visible. 577 */ 578 579 if ((aep->ap_cdb[0] == INQUIRY) && (SID_TYPE(inq) == T_DIRECT)) { 580 bzero(csio->data_ptr, csio->dxfer_len); 581 if (aep->ap_scsi_status == 0xf0) { 582 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR; 583 } else { 584 csio->ccb_h.status = CAM_DEV_NOT_THERE; 585 } 586 } else { 587 588 /* handle passthrough SCSI status */ 589 switch(aep->ap_scsi_status) { 590 case 0: /* completed OK */ 591 csio->ccb_h.status = CAM_REQ_CMP; 592 break; 593 594 case 0x02: 595 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR; 596 csio->scsi_status = SCSI_STATUS_CHECK_COND; 597 bcopy(aep->ap_request_sense_area, &csio->sense_data, AMR_MAX_REQ_SENSE_LEN); 598 csio->sense_len = AMR_MAX_REQ_SENSE_LEN; 599 csio->ccb_h.status |= CAM_AUTOSNS_VALID; 600 break; 601 602 case 0x08: 603 csio->ccb_h.status = CAM_SCSI_BUSY; 604 break; 605 606 case 0xf0: 607 case 0xf4: 608 default: 609 csio->ccb_h.status = CAM_REQ_CMP_ERR; 610 break; 611 } 612 } 613 free(aep, M_DEVBUF); 614 if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) 615 debug(2, "%*D\n", imin(csio->dxfer_len, 16), csio->data_ptr, " "); 616 xpt_done((union ccb *)csio); 617 amr_releasecmd(ac); 618 } 619