ctl_frontend_cam_sim.c revision 288732
1/*- 2 * Copyright (c) 2009 Silicon Graphics International Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions, and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * substantially similar to the "NO WARRANTY" disclaimer below 13 * ("Disclaimer") and any redistribution must be conditioned upon 14 * including a substantially similar Disclaimer requirement for further 15 * binary redistribution. 16 * 17 * NO WARRANTY 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGES. 29 * 30 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend_cam_sim.c#4 $ 31 */ 32/* 33 * CTL frontend to CAM SIM interface. This allows access to CTL LUNs via 34 * the da(4) and pass(4) drivers from inside the system. 35 * 36 * Author: Ken Merry <ken@FreeBSD.org> 37 */ 38 39#include <sys/cdefs.h> 40__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_cam_sim.c 288732 2015-10-05 08:57:16Z mav $"); 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/types.h> 46#include <sys/malloc.h> 47#include <sys/lock.h> 48#include <sys/mutex.h> 49#include <sys/condvar.h> 50#include <sys/queue.h> 51#include <sys/bus.h> 52#include <sys/sysctl.h> 53#include <machine/bus.h> 54#include <sys/sbuf.h> 55 56#include <cam/cam.h> 57#include <cam/cam_ccb.h> 58#include <cam/cam_sim.h> 59#include <cam/cam_xpt_sim.h> 60#include <cam/cam_xpt.h> 61#include <cam/cam_periph.h> 62#include <cam/scsi/scsi_all.h> 63#include <cam/scsi/scsi_message.h> 64#include <cam/ctl/ctl_io.h> 65#include <cam/ctl/ctl.h> 66#include <cam/ctl/ctl_frontend.h> 67#include <cam/ctl/ctl_debug.h> 68 69#define io_ptr spriv_ptr1 70 71struct cfcs_io { 72 union ccb *ccb; 73}; 74 75struct cfcs_softc { 76 struct ctl_port port; 77 char port_name[32]; 78 struct cam_sim *sim; 79 struct cam_devq *devq; 80 struct cam_path *path; 81 struct mtx lock; 82 uint64_t wwnn; 83 uint64_t wwpn; 84 uint32_t cur_tag_num; 85 int online; 86}; 87 88/* 89 * We can't handle CCBs with these flags. For the most part, we just don't 90 * handle physical addresses yet. That would require mapping things in 91 * order to do the copy. 92 */ 93#define CFCS_BAD_CCB_FLAGS (CAM_DATA_ISPHYS | CAM_MSG_BUF_PHYS | \ 94 CAM_SNS_BUF_PHYS | CAM_CDB_PHYS | CAM_SENSE_PTR | \ 95 CAM_SENSE_PHYS) 96 97int cfcs_init(void); 98static void cfcs_poll(struct cam_sim *sim); 99static void cfcs_online(void *arg); 100static void cfcs_offline(void *arg); 101static void cfcs_datamove(union ctl_io *io); 102static void cfcs_done(union ctl_io *io); 103void cfcs_action(struct cam_sim *sim, union ccb *ccb); 104static void cfcs_async(void *callback_arg, uint32_t code, 105 struct cam_path *path, void *arg); 106 107struct cfcs_softc cfcs_softc; 108/* 109 * This is primarly intended to allow for error injection to test the CAM 110 * sense data and sense residual handling code. This sets the maximum 111 * amount of SCSI sense data that we will report to CAM. 112 */ 113static int cfcs_max_sense = sizeof(struct scsi_sense_data); 114 115SYSCTL_NODE(_kern_cam, OID_AUTO, ctl2cam, CTLFLAG_RD, 0, 116 "CAM Target Layer SIM frontend"); 117SYSCTL_INT(_kern_cam_ctl2cam, OID_AUTO, max_sense, CTLFLAG_RW, 118 &cfcs_max_sense, 0, "Maximum sense data size"); 119 120static struct ctl_frontend cfcs_frontend = 121{ 122 .name = "camsim", 123 .init = cfcs_init, 124}; 125CTL_FRONTEND_DECLARE(ctlcfcs, cfcs_frontend); 126 127int 128cfcs_init(void) 129{ 130 struct cfcs_softc *softc; 131 struct ccb_setasync csa; 132 struct ctl_port *port; 133#ifdef NEEDTOPORT 134 char wwnn[8]; 135#endif 136 int retval; 137 138 softc = &cfcs_softc; 139 retval = 0; 140 bzero(softc, sizeof(*softc)); 141 mtx_init(&softc->lock, "ctl2cam", NULL, MTX_DEF); 142 port = &softc->port; 143 144 port->frontend = &cfcs_frontend; 145 port->port_type = CTL_PORT_INTERNAL; 146 /* XXX KDM what should the real number be here? */ 147 port->num_requested_ctl_io = 4096; 148 snprintf(softc->port_name, sizeof(softc->port_name), "camsim"); 149 port->port_name = softc->port_name; 150 port->port_online = cfcs_online; 151 port->port_offline = cfcs_offline; 152 port->onoff_arg = softc; 153 port->fe_datamove = cfcs_datamove; 154 port->fe_done = cfcs_done; 155 156 /* XXX KDM what should we report here? */ 157 /* XXX These should probably be fetched from CTL. */ 158 port->max_targets = 1; 159 port->max_target_id = 15; 160 port->targ_port = -1; 161 162 retval = ctl_port_register(port); 163 if (retval != 0) { 164 printf("%s: ctl_port_register() failed with error %d!\n", 165 __func__, retval); 166 mtx_destroy(&softc->lock); 167 return (retval); 168 } 169 170 /* 171 * Get the WWNN out of the database, and create a WWPN as well. 172 */ 173#ifdef NEEDTOPORT 174 ddb_GetWWNN((char *)wwnn); 175 softc->wwnn = be64dec(wwnn); 176 softc->wwpn = softc->wwnn + (softc->port.targ_port & 0xff); 177#endif 178 179 /* 180 * If the CTL frontend didn't tell us what our WWNN/WWPN is, go 181 * ahead and set something random. 182 */ 183 if (port->wwnn == 0) { 184 uint64_t random_bits; 185 186 arc4rand(&random_bits, sizeof(random_bits), 0); 187 softc->wwnn = (random_bits & 0x0000000fffffff00ULL) | 188 /* Company ID */ 0x5000000000000000ULL | 189 /* NL-Port */ 0x0300; 190 softc->wwpn = softc->wwnn + port->targ_port + 1; 191 ctl_port_set_wwns(port, true, softc->wwnn, true, softc->wwpn); 192 } else { 193 softc->wwnn = port->wwnn; 194 softc->wwpn = port->wwpn; 195 } 196 197 mtx_lock(&softc->lock); 198 softc->devq = cam_simq_alloc(port->num_requested_ctl_io); 199 if (softc->devq == NULL) { 200 printf("%s: error allocating devq\n", __func__); 201 retval = ENOMEM; 202 goto bailout; 203 } 204 205 softc->sim = cam_sim_alloc(cfcs_action, cfcs_poll, softc->port_name, 206 softc, /*unit*/ 0, &softc->lock, 1, 207 port->num_requested_ctl_io, softc->devq); 208 if (softc->sim == NULL) { 209 printf("%s: error allocating SIM\n", __func__); 210 retval = ENOMEM; 211 goto bailout; 212 } 213 214 if (xpt_bus_register(softc->sim, NULL, 0) != CAM_SUCCESS) { 215 printf("%s: error registering SIM\n", __func__); 216 retval = ENOMEM; 217 goto bailout; 218 } 219 220 if (xpt_create_path(&softc->path, /*periph*/NULL, 221 cam_sim_path(softc->sim), 222 CAM_TARGET_WILDCARD, 223 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 224 printf("%s: error creating path\n", __func__); 225 xpt_bus_deregister(cam_sim_path(softc->sim)); 226 retval = EINVAL; 227 goto bailout; 228 } 229 230 xpt_setup_ccb(&csa.ccb_h, softc->path, CAM_PRIORITY_NONE); 231 csa.ccb_h.func_code = XPT_SASYNC_CB; 232 csa.event_enable = AC_LOST_DEVICE; 233 csa.callback = cfcs_async; 234 csa.callback_arg = softc->sim; 235 xpt_action((union ccb *)&csa); 236 237 mtx_unlock(&softc->lock); 238 239 return (retval); 240 241bailout: 242 if (softc->sim) 243 cam_sim_free(softc->sim, /*free_devq*/ TRUE); 244 else if (softc->devq) 245 cam_simq_free(softc->devq); 246 mtx_unlock(&softc->lock); 247 mtx_destroy(&softc->lock); 248 249 return (retval); 250} 251 252static void 253cfcs_poll(struct cam_sim *sim) 254{ 255 256} 257 258static void 259cfcs_onoffline(void *arg, int online) 260{ 261 struct cfcs_softc *softc; 262 union ccb *ccb; 263 264 softc = (struct cfcs_softc *)arg; 265 266 mtx_lock(&softc->lock); 267 softc->online = online; 268 269 ccb = xpt_alloc_ccb_nowait(); 270 if (ccb == NULL) { 271 printf("%s: unable to allocate CCB for rescan\n", __func__); 272 goto bailout; 273 } 274 275 if (xpt_create_path(&ccb->ccb_h.path, NULL, 276 cam_sim_path(softc->sim), CAM_TARGET_WILDCARD, 277 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 278 printf("%s: can't allocate path for rescan\n", __func__); 279 xpt_free_ccb(ccb); 280 goto bailout; 281 } 282 xpt_rescan(ccb); 283 284bailout: 285 mtx_unlock(&softc->lock); 286} 287 288static void 289cfcs_online(void *arg) 290{ 291 cfcs_onoffline(arg, /*online*/ 1); 292} 293 294static void 295cfcs_offline(void *arg) 296{ 297 cfcs_onoffline(arg, /*online*/ 0); 298} 299 300/* 301 * This function is very similar to ctl_ioctl_do_datamove(). Is there a 302 * way to combine the functionality? 303 * 304 * XXX KDM may need to move this into a thread. We're doing a bcopy in the 305 * caller's context, which will usually be the backend. That may not be a 306 * good thing. 307 */ 308static void 309cfcs_datamove(union ctl_io *io) 310{ 311 union ccb *ccb; 312 bus_dma_segment_t cam_sg_entry, *cam_sglist; 313 struct ctl_sg_entry ctl_sg_entry, *ctl_sglist; 314 int cam_sg_count, ctl_sg_count, cam_sg_start; 315 int cam_sg_offset; 316 int len_to_copy, len_copied; 317 int ctl_watermark, cam_watermark; 318 int i, j; 319 320 321 cam_sg_offset = 0; 322 cam_sg_start = 0; 323 324 ccb = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; 325 326 /* 327 * Note that we have a check in cfcs_action() to make sure that any 328 * CCBs with "bad" flags are returned with CAM_REQ_INVALID. This 329 * is just to make sure no one removes that check without updating 330 * this code to provide the additional functionality necessary to 331 * support those modes of operation. 332 */ 333 KASSERT(((ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS) == 0), ("invalid " 334 "CAM flags %#x", (ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS))); 335 336 /* 337 * Simplify things on both sides by putting single buffers into a 338 * single entry S/G list. 339 */ 340 switch ((ccb->ccb_h.flags & CAM_DATA_MASK)) { 341 case CAM_DATA_SG: { 342 int len_seen; 343 344 cam_sglist = (bus_dma_segment_t *)ccb->csio.data_ptr; 345 cam_sg_count = ccb->csio.sglist_cnt; 346 347 for (i = 0, len_seen = 0; i < cam_sg_count; i++) { 348 if ((len_seen + cam_sglist[i].ds_len) >= 349 io->scsiio.kern_rel_offset) { 350 cam_sg_start = i; 351 cam_sg_offset = io->scsiio.kern_rel_offset - 352 len_seen; 353 break; 354 } 355 len_seen += cam_sglist[i].ds_len; 356 } 357 break; 358 } 359 case CAM_DATA_VADDR: 360 cam_sglist = &cam_sg_entry; 361 cam_sglist[0].ds_len = ccb->csio.dxfer_len; 362 cam_sglist[0].ds_addr = (bus_addr_t)ccb->csio.data_ptr; 363 cam_sg_count = 1; 364 cam_sg_start = 0; 365 cam_sg_offset = io->scsiio.kern_rel_offset; 366 break; 367 default: 368 panic("Invalid CAM flags %#x", ccb->ccb_h.flags); 369 } 370 371 if (io->scsiio.kern_sg_entries > 0) { 372 ctl_sglist = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr; 373 ctl_sg_count = io->scsiio.kern_sg_entries; 374 } else { 375 ctl_sglist = &ctl_sg_entry; 376 ctl_sglist->addr = io->scsiio.kern_data_ptr; 377 ctl_sglist->len = io->scsiio.kern_data_len; 378 ctl_sg_count = 1; 379 } 380 381 ctl_watermark = 0; 382 cam_watermark = cam_sg_offset; 383 len_copied = 0; 384 for (i = cam_sg_start, j = 0; 385 i < cam_sg_count && j < ctl_sg_count;) { 386 uint8_t *cam_ptr, *ctl_ptr; 387 388 len_to_copy = MIN(cam_sglist[i].ds_len - cam_watermark, 389 ctl_sglist[j].len - ctl_watermark); 390 391 cam_ptr = (uint8_t *)cam_sglist[i].ds_addr; 392 cam_ptr = cam_ptr + cam_watermark; 393 if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) { 394 /* 395 * XXX KDM fix this! 396 */ 397 panic("need to implement bus address support"); 398#if 0 399 kern_ptr = bus_to_virt(kern_sglist[j].addr); 400#endif 401 } else 402 ctl_ptr = (uint8_t *)ctl_sglist[j].addr; 403 ctl_ptr = ctl_ptr + ctl_watermark; 404 405 ctl_watermark += len_to_copy; 406 cam_watermark += len_to_copy; 407 408 if ((io->io_hdr.flags & CTL_FLAG_DATA_MASK) == 409 CTL_FLAG_DATA_IN) { 410 CTL_DEBUG_PRINT(("%s: copying %d bytes to CAM\n", 411 __func__, len_to_copy)); 412 CTL_DEBUG_PRINT(("%s: from %p to %p\n", ctl_ptr, 413 __func__, cam_ptr)); 414 bcopy(ctl_ptr, cam_ptr, len_to_copy); 415 } else { 416 CTL_DEBUG_PRINT(("%s: copying %d bytes from CAM\n", 417 __func__, len_to_copy)); 418 CTL_DEBUG_PRINT(("%s: from %p to %p\n", cam_ptr, 419 __func__, ctl_ptr)); 420 bcopy(cam_ptr, ctl_ptr, len_to_copy); 421 } 422 423 len_copied += len_to_copy; 424 425 if (cam_sglist[i].ds_len == cam_watermark) { 426 i++; 427 cam_watermark = 0; 428 } 429 430 if (ctl_sglist[j].len == ctl_watermark) { 431 j++; 432 ctl_watermark = 0; 433 } 434 } 435 436 io->scsiio.ext_data_filled += len_copied; 437 438 io->scsiio.be_move_done(io); 439} 440 441static void 442cfcs_done(union ctl_io *io) 443{ 444 union ccb *ccb; 445 446 ccb = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; 447 if (ccb == NULL) { 448 ctl_free_io(io); 449 return; 450 } 451 452 /* 453 * At this point we should have status. If we don't, that's a bug. 454 */ 455 KASSERT(((io->io_hdr.status & CTL_STATUS_MASK) != CTL_STATUS_NONE), 456 ("invalid CTL status %#x", io->io_hdr.status)); 457 458 /* 459 * Translate CTL status to CAM status. 460 */ 461 switch (io->io_hdr.status & CTL_STATUS_MASK) { 462 case CTL_SUCCESS: 463 ccb->ccb_h.status = CAM_REQ_CMP; 464 break; 465 case CTL_SCSI_ERROR: 466 ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; 467 ccb->csio.scsi_status = io->scsiio.scsi_status; 468 bcopy(&io->scsiio.sense_data, &ccb->csio.sense_data, 469 min(io->scsiio.sense_len, ccb->csio.sense_len)); 470 if (ccb->csio.sense_len > io->scsiio.sense_len) 471 ccb->csio.sense_resid = ccb->csio.sense_len - 472 io->scsiio.sense_len; 473 else 474 ccb->csio.sense_resid = 0; 475 if ((ccb->csio.sense_len - ccb->csio.sense_resid) > 476 cfcs_max_sense) { 477 ccb->csio.sense_resid = ccb->csio.sense_len - 478 cfcs_max_sense; 479 } 480 break; 481 case CTL_CMD_ABORTED: 482 ccb->ccb_h.status = CAM_REQ_ABORTED; 483 break; 484 case CTL_ERROR: 485 default: 486 ccb->ccb_h.status = CAM_REQ_CMP_ERR; 487 break; 488 } 489 490 xpt_done(ccb); 491 ctl_free_io(io); 492} 493 494void 495cfcs_action(struct cam_sim *sim, union ccb *ccb) 496{ 497 struct cfcs_softc *softc; 498 int err; 499 500 softc = (struct cfcs_softc *)cam_sim_softc(sim); 501 mtx_assert(&softc->lock, MA_OWNED); 502 503 switch (ccb->ccb_h.func_code) { 504 case XPT_SCSI_IO: { 505 union ctl_io *io; 506 struct ccb_scsiio *csio; 507 508 csio = &ccb->csio; 509 510 /* 511 * Catch CCB flags, like physical address flags, that 512 * indicate situations we currently can't handle. 513 */ 514 if (ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS) { 515 ccb->ccb_h.status = CAM_REQ_INVALID; 516 printf("%s: bad CCB flags %#x (all flags %#x)\n", 517 __func__, ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS, 518 ccb->ccb_h.flags); 519 xpt_done(ccb); 520 return; 521 } 522 523 /* 524 * If we aren't online, there are no devices to see. 525 */ 526 if (softc->online == 0) { 527 ccb->ccb_h.status = CAM_DEV_NOT_THERE; 528 xpt_done(ccb); 529 return; 530 } 531 532 io = ctl_alloc_io_nowait(softc->port.ctl_pool_ref); 533 if (io == NULL) { 534 printf("%s: can't allocate ctl_io\n", __func__); 535 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN; 536 xpt_freeze_devq(ccb->ccb_h.path, 1); 537 xpt_done(ccb); 538 return; 539 } 540 ctl_zero_io(io); 541 /* Save pointers on both sides */ 542 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb; 543 ccb->ccb_h.io_ptr = io; 544 545 /* 546 * Only SCSI I/O comes down this path, resets, etc. come 547 * down via the XPT_RESET_BUS/LUN CCBs below. 548 */ 549 io->io_hdr.io_type = CTL_IO_SCSI; 550 io->io_hdr.nexus.initid = 1; 551 io->io_hdr.nexus.targ_port = softc->port.targ_port; 552 io->io_hdr.nexus.targ_lun = ccb->ccb_h.target_lun; 553 /* 554 * This tag scheme isn't the best, since we could in theory 555 * have a very long-lived I/O and tag collision, especially 556 * in a high I/O environment. But it should work well 557 * enough for now. Since we're using unsigned ints, 558 * they'll just wrap around. 559 */ 560 io->scsiio.tag_num = softc->cur_tag_num++; 561 csio->tag_id = io->scsiio.tag_num; 562 switch (csio->tag_action) { 563 case CAM_TAG_ACTION_NONE: 564 io->scsiio.tag_type = CTL_TAG_UNTAGGED; 565 break; 566 case MSG_SIMPLE_TASK: 567 io->scsiio.tag_type = CTL_TAG_SIMPLE; 568 break; 569 case MSG_HEAD_OF_QUEUE_TASK: 570 io->scsiio.tag_type = CTL_TAG_HEAD_OF_QUEUE; 571 break; 572 case MSG_ORDERED_TASK: 573 io->scsiio.tag_type = CTL_TAG_ORDERED; 574 break; 575 case MSG_ACA_TASK: 576 io->scsiio.tag_type = CTL_TAG_ACA; 577 break; 578 default: 579 io->scsiio.tag_type = CTL_TAG_UNTAGGED; 580 printf("%s: unhandled tag type %#x!!\n", __func__, 581 csio->tag_action); 582 break; 583 } 584 if (csio->cdb_len > sizeof(io->scsiio.cdb)) { 585 printf("%s: WARNING: CDB len %d > ctl_io space %zd\n", 586 __func__, csio->cdb_len, sizeof(io->scsiio.cdb)); 587 } 588 io->scsiio.cdb_len = min(csio->cdb_len, sizeof(io->scsiio.cdb)); 589 bcopy(csio->cdb_io.cdb_bytes, io->scsiio.cdb, 590 io->scsiio.cdb_len); 591 592 ccb->ccb_h.status |= CAM_SIM_QUEUED; 593 err = ctl_queue(io); 594 if (err != CTL_RETVAL_COMPLETE) { 595 printf("%s: func %d: error %d returned by " 596 "ctl_queue()!\n", __func__, 597 ccb->ccb_h.func_code, err); 598 ctl_free_io(io); 599 ccb->ccb_h.status = CAM_REQ_INVALID; 600 xpt_done(ccb); 601 return; 602 } 603 break; 604 } 605 case XPT_ABORT: { 606 union ctl_io *io; 607 union ccb *abort_ccb; 608 609 abort_ccb = ccb->cab.abort_ccb; 610 611 if (abort_ccb->ccb_h.func_code != XPT_SCSI_IO) { 612 ccb->ccb_h.status = CAM_REQ_INVALID; 613 xpt_done(ccb); 614 } 615 616 /* 617 * If we aren't online, there are no devices to talk to. 618 */ 619 if (softc->online == 0) { 620 ccb->ccb_h.status = CAM_DEV_NOT_THERE; 621 xpt_done(ccb); 622 return; 623 } 624 625 io = ctl_alloc_io_nowait(softc->port.ctl_pool_ref); 626 if (io == NULL) { 627 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN; 628 xpt_freeze_devq(ccb->ccb_h.path, 1); 629 xpt_done(ccb); 630 return; 631 } 632 633 ctl_zero_io(io); 634 /* Save pointers on both sides */ 635 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb; 636 ccb->ccb_h.io_ptr = io; 637 638 io->io_hdr.io_type = CTL_IO_TASK; 639 io->io_hdr.nexus.initid = 1; 640 io->io_hdr.nexus.targ_port = softc->port.targ_port; 641 io->io_hdr.nexus.targ_lun = ccb->ccb_h.target_lun; 642 io->taskio.task_action = CTL_TASK_ABORT_TASK; 643 io->taskio.tag_num = abort_ccb->csio.tag_id; 644 switch (abort_ccb->csio.tag_action) { 645 case CAM_TAG_ACTION_NONE: 646 io->taskio.tag_type = CTL_TAG_UNTAGGED; 647 break; 648 case MSG_SIMPLE_TASK: 649 io->taskio.tag_type = CTL_TAG_SIMPLE; 650 break; 651 case MSG_HEAD_OF_QUEUE_TASK: 652 io->taskio.tag_type = CTL_TAG_HEAD_OF_QUEUE; 653 break; 654 case MSG_ORDERED_TASK: 655 io->taskio.tag_type = CTL_TAG_ORDERED; 656 break; 657 case MSG_ACA_TASK: 658 io->taskio.tag_type = CTL_TAG_ACA; 659 break; 660 default: 661 io->taskio.tag_type = CTL_TAG_UNTAGGED; 662 printf("%s: unhandled tag type %#x!!\n", __func__, 663 abort_ccb->csio.tag_action); 664 break; 665 } 666 err = ctl_queue(io); 667 if (err != CTL_RETVAL_COMPLETE) { 668 printf("%s func %d: error %d returned by " 669 "ctl_queue()!\n", __func__, 670 ccb->ccb_h.func_code, err); 671 ctl_free_io(io); 672 } 673 break; 674 } 675 case XPT_GET_TRAN_SETTINGS: { 676 struct ccb_trans_settings *cts; 677 struct ccb_trans_settings_scsi *scsi; 678 struct ccb_trans_settings_fc *fc; 679 680 cts = &ccb->cts; 681 scsi = &cts->proto_specific.scsi; 682 fc = &cts->xport_specific.fc; 683 684 685 cts->protocol = PROTO_SCSI; 686 cts->protocol_version = SCSI_REV_SPC2; 687 cts->transport = XPORT_FC; 688 cts->transport_version = 0; 689 690 scsi->valid = CTS_SCSI_VALID_TQ; 691 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; 692 fc->valid = CTS_FC_VALID_SPEED; 693 fc->bitrate = 800000; 694 fc->wwnn = softc->wwnn; 695 fc->wwpn = softc->wwpn; 696 fc->port = softc->port.targ_port; 697 fc->valid |= CTS_FC_VALID_WWNN | CTS_FC_VALID_WWPN | 698 CTS_FC_VALID_PORT; 699 ccb->ccb_h.status = CAM_REQ_CMP; 700 break; 701 } 702 case XPT_SET_TRAN_SETTINGS: 703 /* XXX KDM should we actually do something here? */ 704 ccb->ccb_h.status = CAM_REQ_CMP; 705 break; 706 case XPT_RESET_BUS: 707 case XPT_RESET_DEV: { 708 union ctl_io *io; 709 710 /* 711 * If we aren't online, there are no devices to talk to. 712 */ 713 if (softc->online == 0) { 714 ccb->ccb_h.status = CAM_DEV_NOT_THERE; 715 xpt_done(ccb); 716 return; 717 } 718 719 io = ctl_alloc_io_nowait(softc->port.ctl_pool_ref); 720 if (io == NULL) { 721 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN; 722 xpt_freeze_devq(ccb->ccb_h.path, 1); 723 xpt_done(ccb); 724 return; 725 } 726 727 ctl_zero_io(io); 728 /* Save pointers on both sides */ 729 if (ccb->ccb_h.func_code == XPT_RESET_DEV) 730 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb; 731 ccb->ccb_h.io_ptr = io; 732 733 io->io_hdr.io_type = CTL_IO_TASK; 734 io->io_hdr.nexus.initid = 1; 735 io->io_hdr.nexus.targ_port = softc->port.targ_port; 736 io->io_hdr.nexus.targ_lun = ccb->ccb_h.target_lun; 737 if (ccb->ccb_h.func_code == XPT_RESET_BUS) 738 io->taskio.task_action = CTL_TASK_BUS_RESET; 739 else 740 io->taskio.task_action = CTL_TASK_LUN_RESET; 741 742 err = ctl_queue(io); 743 if (err != CTL_RETVAL_COMPLETE) { 744 printf("%s func %d: error %d returned by " 745 "ctl_queue()!\n", __func__, 746 ccb->ccb_h.func_code, err); 747 ctl_free_io(io); 748 } 749 break; 750 } 751 case XPT_CALC_GEOMETRY: 752 cam_calc_geometry(&ccb->ccg, 1); 753 xpt_done(ccb); 754 break; 755 case XPT_PATH_INQ: { 756 struct ccb_pathinq *cpi; 757 758 cpi = &ccb->cpi; 759 760 cpi->version_num = 0; 761 cpi->hba_inquiry = PI_TAG_ABLE; 762 cpi->target_sprt = 0; 763 cpi->hba_misc = 0; 764 cpi->hba_eng_cnt = 0; 765 cpi->max_target = 1; 766 cpi->max_lun = 1024; 767 /* Do we really have a limit? */ 768 cpi->maxio = 1024 * 1024; 769 cpi->async_flags = 0; 770 cpi->hpath_id = 0; 771 cpi->initiator_id = 0; 772 773 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 774 strncpy(cpi->hba_vid, "FreeBSD", HBA_IDLEN); 775 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 776 cpi->unit_number = 0; 777 cpi->bus_id = 0; 778 cpi->base_transfer_speed = 800000; 779 cpi->protocol = PROTO_SCSI; 780 cpi->protocol_version = SCSI_REV_SPC2; 781 /* 782 * Pretend to be Fibre Channel. 783 */ 784 cpi->transport = XPORT_FC; 785 cpi->transport_version = 0; 786 cpi->xport_specific.fc.wwnn = softc->wwnn; 787 cpi->xport_specific.fc.wwpn = softc->wwpn; 788 cpi->xport_specific.fc.port = softc->port.targ_port; 789 cpi->xport_specific.fc.bitrate = 8 * 1000 * 1000; 790 cpi->ccb_h.status = CAM_REQ_CMP; 791 break; 792 } 793 default: 794 ccb->ccb_h.status = CAM_PROVIDE_FAIL; 795 printf("%s: unsupported CCB type %#x\n", __func__, 796 ccb->ccb_h.func_code); 797 xpt_done(ccb); 798 break; 799 } 800} 801 802static void 803cfcs_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg) 804{ 805 806} 807