2 * Copyright (c) 2009 Silicon Graphics International Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend_cam_sim.c#4 $
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.
36 * Author: Ken Merry <ken@FreeBSD.org>
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
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>
48 #include <sys/mutex.h>
49 #include <sys/condvar.h>
50 #include <sys/queue.h>
52 #include <sys/sysctl.h>
53 #include <machine/bus.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_frontend_internal.h>
68 #include <cam/ctl/ctl_mem_pool.h>
69 #include <cam/ctl/ctl_debug.h>
71 #define io_ptr spriv_ptr1
78 struct ctl_frontend fe;
81 struct cam_devq *devq;
82 struct cam_path *path;
92 * We can't handle CCBs with these flags. For the most part, we just don't
93 * handle physical addresses yet. That would require mapping things in
94 * order to do the copy.
96 #define CFCS_BAD_CCB_FLAGS (CAM_DATA_PHYS | CAM_SG_LIST_PHYS | \
97 CAM_MSG_BUF_PHYS | CAM_SNS_BUF_PHYS | CAM_CDB_PHYS | CAM_SENSE_PTR |\
101 void cfcs_shutdown(void);
102 static void cfcs_poll(struct cam_sim *sim);
103 static void cfcs_online(void *arg);
104 static void cfcs_offline(void *arg);
105 static int cfcs_targ_enable(void *arg, struct ctl_id targ_id);
106 static int cfcs_targ_disable(void *arg, struct ctl_id targ_id);
107 static int cfcs_lun_enable(void *arg, struct ctl_id target_id, int lun_id);
108 static int cfcs_lun_disable(void *arg, struct ctl_id target_id, int lun_id);
109 static void cfcs_datamove(union ctl_io *io);
110 static void cfcs_done(union ctl_io *io);
111 void cfcs_action(struct cam_sim *sim, union ccb *ccb);
112 static void cfcs_async(void *callback_arg, uint32_t code,
113 struct cam_path *path, void *arg);
115 struct cfcs_softc cfcs_softc;
117 * This is primarly intended to allow for error injection to test the CAM
118 * sense data and sense residual handling code. This sets the maximum
119 * amount of SCSI sense data that we will report to CAM.
121 static int cfcs_max_sense = sizeof(struct scsi_sense_data);
122 extern int ctl_disable;
124 SYSCTL_NODE(_kern_cam, OID_AUTO, ctl2cam, CTLFLAG_RD, 0,
125 "CAM Target Layer SIM frontend");
126 SYSCTL_INT(_kern_cam_ctl2cam, OID_AUTO, max_sense, CTLFLAG_RW,
127 &cfcs_max_sense, 0, "Maximum sense data size");
129 static int cfcs_module_event_handler(module_t, int /*modeventtype_t*/, void *);
131 static moduledata_t cfcs_moduledata = {
133 cfcs_module_event_handler,
137 DECLARE_MODULE(ctlcfcs, cfcs_moduledata, SI_SUB_CONFIGURE, SI_ORDER_FOURTH);
138 MODULE_VERSION(ctlcfcs, 1);
139 MODULE_DEPEND(ctlcfi, ctl, 1, 1, 1);
140 MODULE_DEPEND(ctlcfi, cam, 1, 1, 1);
145 struct cfcs_softc *softc;
146 struct ccb_setasync csa;
147 struct ctl_frontend *fe;
153 /* Don't continue if CTL is disabled */
154 if (ctl_disable != 0)
159 bzero(softc, sizeof(*softc));
160 sprintf(softc->lock_desc, "ctl2cam");
161 mtx_init(&softc->lock, softc->lock_desc, NULL, MTX_DEF);
164 fe->port_type = CTL_PORT_INTERNAL;
165 /* XXX KDM what should the real number be here? */
166 fe->num_requested_ctl_io = 4096;
167 snprintf(softc->port_name, sizeof(softc->port_name), "ctl2cam");
168 fe->port_name = softc->port_name;
169 fe->port_online = cfcs_online;
170 fe->port_offline = cfcs_offline;
171 fe->onoff_arg = softc;
172 fe->targ_enable = cfcs_targ_enable;
173 fe->targ_disable = cfcs_targ_disable;
174 fe->lun_enable = cfcs_lun_enable;
175 fe->lun_disable = cfcs_lun_disable;
176 fe->targ_lun_arg = softc;
177 fe->fe_datamove = cfcs_datamove;
178 fe->fe_done = cfcs_done;
180 /* XXX KDM what should we report here? */
181 /* XXX These should probably be fetched from CTL. */
183 fe->max_target_id = 15;
185 retval = ctl_frontend_register(fe, /*master_SC*/ 1);
187 printf("%s: ctl_frontend_register() failed with error %d!\n",
189 mtx_destroy(&softc->lock);
194 * Get the WWNN out of the database, and create a WWPN as well.
197 ddb_GetWWNN((char *)wwnn);
198 softc->wwnn = be64dec(wwnn);
199 softc->wwpn = softc->wwnn + (softc->fe.targ_port & 0xff);
203 * If the CTL frontend didn't tell us what our WWNN/WWPN is, go
204 * ahead and set something random.
207 uint64_t random_bits;
209 arc4rand(&random_bits, sizeof(random_bits), 0);
210 softc->wwnn = (random_bits & 0x0000000fffffff00ULL) |
211 /* Company ID */ 0x5000000000000000ULL |
212 /* NL-Port */ 0x0300;
213 softc->wwpn = softc->wwnn + fe->targ_port + 1;
214 fe->wwnn = softc->wwnn;
215 fe->wwpn = softc->wwpn;
217 softc->wwnn = fe->wwnn;
218 softc->wwpn = fe->wwpn;
221 mtx_lock(&softc->lock);
222 softc->devq = cam_simq_alloc(fe->num_requested_ctl_io);
223 if (softc->devq == NULL) {
224 printf("%s: error allocating devq\n", __func__);
229 softc->sim = cam_sim_alloc(cfcs_action, cfcs_poll, softc->port_name,
230 softc, /*unit*/ 0, &softc->lock, 1,
231 fe->num_requested_ctl_io, softc->devq);
232 if (softc->sim == NULL) {
233 printf("%s: error allocating SIM\n", __func__);
238 if (xpt_bus_register(softc->sim, NULL, 0) != CAM_SUCCESS) {
239 printf("%s: error registering SIM\n", __func__);
244 if (xpt_create_path(&softc->path, /*periph*/NULL,
245 cam_sim_path(softc->sim),
247 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
248 printf("%s: error creating path\n", __func__);
249 xpt_bus_deregister(cam_sim_path(softc->sim));
254 xpt_setup_ccb(&csa.ccb_h, softc->path, CAM_PRIORITY_NONE);
255 csa.ccb_h.func_code = XPT_SASYNC_CB;
256 csa.event_enable = AC_LOST_DEVICE;
257 csa.callback = cfcs_async;
258 csa.callback_arg = softc->sim;
259 xpt_action((union ccb *)&csa);
261 mtx_unlock(&softc->lock);
267 cam_sim_free(softc->sim, /*free_devq*/ TRUE);
268 else if (softc->devq)
269 cam_simq_free(softc->devq);
270 mtx_unlock(&softc->lock);
271 mtx_destroy(&softc->lock);
277 cfcs_poll(struct cam_sim *sim)
289 cfcs_module_event_handler(module_t mod, int what, void *arg)
294 return (cfcs_init());
303 cfcs_onoffline(void *arg, int online)
305 struct cfcs_softc *softc;
308 softc = (struct cfcs_softc *)arg;
310 mtx_lock(&softc->lock);
311 softc->online = online;
313 ccb = xpt_alloc_ccb_nowait();
315 printf("%s: unable to allocate CCB for rescan\n", __func__);
319 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
320 cam_sim_path(softc->sim), CAM_TARGET_WILDCARD,
321 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
322 printf("%s: can't allocate path for rescan\n", __func__);
329 mtx_unlock(&softc->lock);
333 cfcs_online(void *arg)
335 cfcs_onoffline(arg, /*online*/ 1);
339 cfcs_offline(void *arg)
341 cfcs_onoffline(arg, /*online*/ 0);
345 cfcs_targ_enable(void *arg, struct ctl_id targ_id)
351 cfcs_targ_disable(void *arg, struct ctl_id targ_id)
357 cfcs_lun_enable(void *arg, struct ctl_id target_id, int lun_id)
362 cfcs_lun_disable(void *arg, struct ctl_id target_id, int lun_id)
368 * This function is very similar to ctl_ioctl_do_datamove(). Is there a
369 * way to combine the functionality?
371 * XXX KDM may need to move this into a thread. We're doing a bcopy in the
372 * caller's context, which will usually be the backend. That may not be a
376 cfcs_datamove(union ctl_io *io)
379 bus_dma_segment_t cam_sg_entry, *cam_sglist;
380 struct ctl_sg_entry ctl_sg_entry, *ctl_sglist;
381 int cam_sg_count, ctl_sg_count, cam_sg_start;
383 int len_to_copy, len_copied;
384 int ctl_watermark, cam_watermark;
391 ccb = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
394 * Note that we have a check in cfcs_action() to make sure that any
395 * CCBs with "bad" flags are returned with CAM_REQ_INVALID. This
396 * is just to make sure no one removes that check without updating
397 * this code to provide the additional functionality necessary to
398 * support those modes of operation.
400 KASSERT(((ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS) == 0), ("invalid "
401 "CAM flags %#x", (ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS)));
404 * Simplify things on both sides by putting single buffers into a
405 * single entry S/G list.
407 if (ccb->ccb_h.flags & CAM_SCATTER_VALID) {
408 if (ccb->ccb_h.flags & CAM_SG_LIST_PHYS) {
409 /* We should filter this out on entry */
410 panic("%s: physical S/G list, should not get here",
415 cam_sglist = (bus_dma_segment_t *)ccb->csio.data_ptr;
416 cam_sg_count = ccb->csio.sglist_cnt;
418 for (i = 0, len_seen = 0; i < cam_sg_count; i++) {
419 if ((len_seen + cam_sglist[i].ds_len) >=
420 io->scsiio.kern_rel_offset) {
423 io->scsiio.kern_rel_offset -
427 len_seen += cam_sglist[i].ds_len;
431 cam_sglist = &cam_sg_entry;
432 cam_sglist[0].ds_len = ccb->csio.dxfer_len;
433 cam_sglist[0].ds_addr = (bus_addr_t)ccb->csio.data_ptr;
436 cam_sg_offset = io->scsiio.kern_rel_offset;
439 if (io->scsiio.kern_sg_entries > 0) {
440 ctl_sglist = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr;
441 ctl_sg_count = io->scsiio.kern_sg_entries;
443 ctl_sglist = &ctl_sg_entry;
444 ctl_sglist->addr = io->scsiio.kern_data_ptr;
445 ctl_sglist->len = io->scsiio.kern_data_len;
450 cam_watermark = cam_sg_offset;
452 for (i = cam_sg_start, j = 0;
453 i < cam_sg_count && j < ctl_sg_count;) {
454 uint8_t *cam_ptr, *ctl_ptr;
456 len_to_copy = ctl_min(cam_sglist[i].ds_len - cam_watermark,
457 ctl_sglist[j].len - ctl_watermark);
459 cam_ptr = (uint8_t *)cam_sglist[i].ds_addr;
460 cam_ptr = cam_ptr + cam_watermark;
461 if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) {
465 panic("need to implement bus address support");
467 kern_ptr = bus_to_virt(kern_sglist[j].addr);
470 ctl_ptr = (uint8_t *)ctl_sglist[j].addr;
471 ctl_ptr = ctl_ptr + ctl_watermark;
473 ctl_watermark += len_to_copy;
474 cam_watermark += len_to_copy;
476 if ((io->io_hdr.flags & CTL_FLAG_DATA_MASK) ==
478 CTL_DEBUG_PRINT(("%s: copying %d bytes to CAM\n",
479 __func__, len_to_copy));
480 CTL_DEBUG_PRINT(("%s: from %p to %p\n", ctl_ptr,
482 bcopy(ctl_ptr, cam_ptr, len_to_copy);
484 CTL_DEBUG_PRINT(("%s: copying %d bytes from CAM\n",
485 __func__, len_to_copy));
486 CTL_DEBUG_PRINT(("%s: from %p to %p\n", cam_ptr,
488 bcopy(cam_ptr, ctl_ptr, len_to_copy);
491 len_copied += len_to_copy;
493 if (cam_sglist[i].ds_len == cam_watermark) {
498 if (ctl_sglist[j].len == ctl_watermark) {
504 io->scsiio.ext_data_filled += len_copied;
506 io->scsiio.be_move_done(io);
510 cfcs_done(union ctl_io *io)
513 struct cfcs_softc *softc;
516 ccb = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
518 sim = xpt_path_sim(ccb->ccb_h.path);
519 softc = (struct cfcs_softc *)cam_sim_softc(sim);
522 * At this point we should have status. If we don't, that's a bug.
524 KASSERT(((io->io_hdr.status & CTL_STATUS_MASK) != CTL_STATUS_NONE),
525 ("invalid CTL status %#x", io->io_hdr.status));
528 * Translate CTL status to CAM status.
530 switch (io->io_hdr.status & CTL_STATUS_MASK) {
532 ccb->ccb_h.status = CAM_REQ_CMP;
535 ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID;
536 ccb->csio.scsi_status = io->scsiio.scsi_status;
537 bcopy(&io->scsiio.sense_data, &ccb->csio.sense_data,
538 min(io->scsiio.sense_len, ccb->csio.sense_len));
539 if (ccb->csio.sense_len > io->scsiio.sense_len)
540 ccb->csio.sense_resid = ccb->csio.sense_len -
541 io->scsiio.sense_len;
543 ccb->csio.sense_resid = 0;
544 if ((ccb->csio.sense_len - ccb->csio.sense_resid) >
546 ccb->csio.sense_resid = ccb->csio.sense_len -
550 case CTL_CMD_ABORTED:
551 ccb->ccb_h.status = CAM_REQ_ABORTED;
555 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
561 mtx_unlock(sim->mtx);
567 cfcs_action(struct cam_sim *sim, union ccb *ccb)
569 struct cfcs_softc *softc;
572 softc = (struct cfcs_softc *)cam_sim_softc(sim);
573 mtx_assert(&softc->lock, MA_OWNED);
575 switch (ccb->ccb_h.func_code) {
578 struct ccb_scsiio *csio;
583 * Catch CCB flags, like physical address flags, that
584 * indicate situations we currently can't handle.
586 if (ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS) {
587 ccb->ccb_h.status = CAM_REQ_INVALID;
588 printf("%s: bad CCB flags %#x (all flags %#x)\n",
589 __func__, ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS,
596 * If we aren't online, there are no devices to see.
598 if (softc->online == 0) {
599 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
604 io = ctl_alloc_io(softc->fe.ctl_pool_ref);
606 printf("%s: can't allocate ctl_io\n", __func__);
607 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN;
608 xpt_freeze_devq(ccb->ccb_h.path, 1);
613 /* Save pointers on both sides */
614 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb;
615 ccb->ccb_h.io_ptr = io;
618 * Only SCSI I/O comes down this path, resets, etc. come
619 * down via the XPT_RESET_BUS/LUN CCBs below.
621 io->io_hdr.io_type = CTL_IO_SCSI;
622 io->io_hdr.nexus.initid.id = 1;
623 io->io_hdr.nexus.targ_port = softc->fe.targ_port;
625 * XXX KDM how do we handle target IDs?
627 io->io_hdr.nexus.targ_target.id = ccb->ccb_h.target_id;
628 io->io_hdr.nexus.targ_lun = ccb->ccb_h.target_lun;
630 * This tag scheme isn't the best, since we could in theory
631 * have a very long-lived I/O and tag collision, especially
632 * in a high I/O environment. But it should work well
633 * enough for now. Since we're using unsigned ints,
634 * they'll just wrap around.
636 io->scsiio.tag_num = softc->cur_tag_num++;
637 csio->tag_id = io->scsiio.tag_num;
638 switch (csio->tag_action) {
639 case CAM_TAG_ACTION_NONE:
640 io->scsiio.tag_type = CTL_TAG_UNTAGGED;
642 case MSG_SIMPLE_TASK:
643 io->scsiio.tag_type = CTL_TAG_SIMPLE;
645 case MSG_HEAD_OF_QUEUE_TASK:
646 io->scsiio.tag_type = CTL_TAG_HEAD_OF_QUEUE;
648 case MSG_ORDERED_TASK:
649 io->scsiio.tag_type = CTL_TAG_ORDERED;
652 io->scsiio.tag_type = CTL_TAG_ACA;
655 io->scsiio.tag_type = CTL_TAG_UNTAGGED;
656 printf("%s: unhandled tag type %#x!!\n", __func__,
660 if (csio->cdb_len > sizeof(io->scsiio.cdb)) {
661 printf("%s: WARNING: CDB len %d > ctl_io space %zd\n",
662 __func__, csio->cdb_len, sizeof(io->scsiio.cdb));
664 io->scsiio.cdb_len = min(csio->cdb_len, sizeof(io->scsiio.cdb));
665 bcopy(csio->cdb_io.cdb_bytes, io->scsiio.cdb,
669 if (err != CTL_RETVAL_COMPLETE) {
670 printf("%s: func %d: error %d returned by "
671 "ctl_queue()!\n", __func__,
672 ccb->ccb_h.func_code, err);
675 ccb->ccb_h.status |= CAM_SIM_QUEUED;
681 union ccb *abort_ccb;
683 abort_ccb = ccb->cab.abort_ccb;
685 if (abort_ccb->ccb_h.func_code != XPT_SCSI_IO) {
686 ccb->ccb_h.status = CAM_REQ_INVALID;
691 * If we aren't online, there are no devices to talk to.
693 if (softc->online == 0) {
694 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
699 io = ctl_alloc_io(softc->fe.ctl_pool_ref);
701 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN;
702 xpt_freeze_devq(ccb->ccb_h.path, 1);
708 /* Save pointers on both sides */
709 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb;
710 ccb->ccb_h.io_ptr = io;
712 io->io_hdr.io_type = CTL_IO_TASK;
713 io->io_hdr.nexus.initid.id = 1;
714 io->io_hdr.nexus.targ_port = softc->fe.targ_port;
715 io->io_hdr.nexus.targ_target.id = ccb->ccb_h.target_id;
716 io->io_hdr.nexus.targ_lun = ccb->ccb_h.target_lun;
717 io->taskio.task_action = CTL_TASK_ABORT_TASK;
718 io->taskio.tag_num = abort_ccb->csio.tag_id;
719 switch (abort_ccb->csio.tag_action) {
720 case CAM_TAG_ACTION_NONE:
721 io->taskio.tag_type = CTL_TAG_UNTAGGED;
723 case MSG_SIMPLE_TASK:
724 io->taskio.tag_type = CTL_TAG_SIMPLE;
726 case MSG_HEAD_OF_QUEUE_TASK:
727 io->taskio.tag_type = CTL_TAG_HEAD_OF_QUEUE;
729 case MSG_ORDERED_TASK:
730 io->taskio.tag_type = CTL_TAG_ORDERED;
733 io->taskio.tag_type = CTL_TAG_ACA;
736 io->taskio.tag_type = CTL_TAG_UNTAGGED;
737 printf("%s: unhandled tag type %#x!!\n", __func__,
738 abort_ccb->csio.tag_action);
742 if (err != CTL_RETVAL_COMPLETE) {
743 printf("%s func %d: error %d returned by "
744 "ctl_queue()!\n", __func__,
745 ccb->ccb_h.func_code, err);
750 case XPT_GET_TRAN_SETTINGS: {
751 struct ccb_trans_settings *cts;
752 struct ccb_trans_settings_scsi *scsi;
753 struct ccb_trans_settings_fc *fc;
756 scsi = &cts->proto_specific.scsi;
757 fc = &cts->xport_specific.fc;
760 cts->protocol = PROTO_SCSI;
761 cts->protocol_version = SCSI_REV_SPC2;
762 cts->transport = XPORT_FC;
763 cts->transport_version = 0;
765 scsi->valid = CTS_SCSI_VALID_TQ;
766 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
767 fc->valid = CTS_FC_VALID_SPEED;
768 fc->bitrate = 800000;
769 fc->wwnn = softc->wwnn;
770 fc->wwpn = softc->wwpn;
771 fc->port = softc->fe.targ_port;
772 fc->valid |= CTS_FC_VALID_WWNN | CTS_FC_VALID_WWPN |
774 ccb->ccb_h.status = CAM_REQ_CMP;
777 case XPT_SET_TRAN_SETTINGS:
778 /* XXX KDM should we actually do something here? */
779 ccb->ccb_h.status = CAM_REQ_CMP;
782 case XPT_RESET_DEV: {
786 * If we aren't online, there are no devices to talk to.
788 if (softc->online == 0) {
789 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
794 io = ctl_alloc_io(softc->fe.ctl_pool_ref);
796 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN;
797 xpt_freeze_devq(ccb->ccb_h.path, 1);
803 /* Save pointers on both sides */
804 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb;
805 ccb->ccb_h.io_ptr = io;
807 io->io_hdr.io_type = CTL_IO_TASK;
808 io->io_hdr.nexus.initid.id = 0;
809 io->io_hdr.nexus.targ_port = softc->fe.targ_port;
810 io->io_hdr.nexus.targ_target.id = ccb->ccb_h.target_id;
811 io->io_hdr.nexus.targ_lun = ccb->ccb_h.target_lun;
812 if (ccb->ccb_h.func_code == XPT_RESET_BUS)
813 io->taskio.task_action = CTL_TASK_BUS_RESET;
815 io->taskio.task_action = CTL_TASK_LUN_RESET;
818 if (err != CTL_RETVAL_COMPLETE) {
819 printf("%s func %d: error %d returned by "
820 "ctl_queue()!\n", __func__,
821 ccb->ccb_h.func_code, err);
826 case XPT_CALC_GEOMETRY:
827 cam_calc_geometry(&ccb->ccg, 1);
831 struct ccb_pathinq *cpi;
835 cpi->version_num = 0;
836 cpi->hba_inquiry = PI_TAG_ABLE;
837 cpi->target_sprt = 0;
839 cpi->hba_eng_cnt = 0;
842 /* Do we really have a limit? */
843 cpi->maxio = 1024 * 1024;
844 cpi->async_flags = 0;
846 cpi->initiator_id = 0;
848 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
849 strncpy(cpi->hba_vid, "FreeBSD", HBA_IDLEN);
850 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
851 cpi->unit_number = 0;
853 cpi->base_transfer_speed = 800000;
854 cpi->protocol = PROTO_SCSI;
855 cpi->protocol_version = SCSI_REV_SPC2;
857 * Pretend to be Fibre Channel.
859 cpi->transport = XPORT_FC;
860 cpi->transport_version = 0;
861 cpi->xport_specific.fc.wwnn = softc->wwnn;
862 cpi->xport_specific.fc.wwpn = softc->wwpn;
863 cpi->xport_specific.fc.port = softc->fe.targ_port;
864 cpi->xport_specific.fc.bitrate = 8 * 1000 * 1000;
865 cpi->ccb_h.status = CAM_REQ_CMP;
869 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
870 printf("%s: unsupported CCB type %#x\n", __func__,
871 ccb->ccb_h.func_code);
878 cfcs_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)