Lines Matching +full:test2 +full:. +full:good

4  * Copyright (c) 2009 Silicon Graphics International Corp.
5 * All rights reserved.
10 * 1. Redistributions of source code must retain the above copyright
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
17 * binary redistribution.
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * POSSIBILITY OF SUCH DAMAGES.
32 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend_cam_sim.c#4 $
35 * CTL frontend to CAM SIM interface. This allows access to CTL LUNs via
36 * the da(4) and pass(4) drivers from inside the system.
38 * Author: Ken Merry <ken@FreeBSD.org>
41 #include <sys/cdefs.h>
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/types.h>
48 #include <sys/malloc.h>
49 #include <sys/lock.h>
50 #include <sys/mutex.h>
51 #include <sys/condvar.h>
52 #include <sys/queue.h>
53 #include <sys/bus.h>
54 #include <sys/sysctl.h>
55 #include <machine/bus.h>
56 #include <sys/sbuf.h>
58 #include <cam/cam.h>
59 #include <cam/cam_ccb.h>
60 #include <cam/cam_sim.h>
61 #include <cam/cam_xpt_sim.h>
62 #include <cam/cam_xpt.h>
63 #include <cam/cam_periph.h>
64 #include <cam/scsi/scsi_all.h>
65 #include <cam/scsi/scsi_message.h>
66 #include <cam/ctl/ctl_io.h>
67 #include <cam/ctl/ctl.h>
68 #include <cam/ctl/ctl_frontend.h>
69 #include <cam/ctl/ctl_debug.h>
91 * We can't handle CCBs with these flags. For the most part, we just don't
92 * handle physical addresses yet. That would require mapping things in
93 * order to do the copy.
111 * sense data and sense residual handling code. This sets the maximum
112 * amount of SCSI sense data that we will report to CAM.
123 .name = "camsim",
124 .init = cfcs_init,
125 .shutdown = cfcs_shutdown,
164 * ahead and set something random. in cfcs_init()
272 if (xpt_create_path(&ccb->ccb_h.path, NULL, in cfcs_onoffline()
298 * This function is very similar to ctl_ioctl_do_datamove(). Is there a
301 * XXX KDM may need to move this into a thread. We're doing a bcopy in the
302 * caller's context, which will usually be the backend. That may not be a
303 * good thing.
317 ccb = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; in cfcs_datamove()
321 * CCBs with "bad" flags are returned with CAM_REQ_INVALID. This in cfcs_datamove()
324 * support those modes of operation. in cfcs_datamove()
326 KASSERT(((ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS) == 0), ("invalid " in cfcs_datamove()
327 "CAM flags %#x", (ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS))); in cfcs_datamove()
331 * single entry S/G list. in cfcs_datamove()
333 switch ((ccb->ccb_h.flags & CAM_DATA_MASK)) { in cfcs_datamove()
337 cam_sglist = (bus_dma_segment_t *)ccb->csio.data_ptr; in cfcs_datamove()
338 cam_sg_count = ccb->csio.sglist_cnt; in cfcs_datamove()
343 if ((len_seen + cam_sglist[i].ds_len) >= in cfcs_datamove()
344 io->scsiio.kern_rel_offset) { in cfcs_datamove()
346 cam_sg_offset = io->scsiio.kern_rel_offset - in cfcs_datamove()
350 len_seen += cam_sglist[i].ds_len; in cfcs_datamove()
356 cam_sglist[0].ds_len = ccb->csio.dxfer_len; in cfcs_datamove()
357 cam_sglist[0].ds_addr = (bus_addr_t)(uintptr_t)ccb->csio.data_ptr; in cfcs_datamove()
360 cam_sg_offset = io->scsiio.kern_rel_offset; in cfcs_datamove()
363 panic("Invalid CAM flags %#x", ccb->ccb_h.flags); in cfcs_datamove()
366 if (io->scsiio.kern_sg_entries > 0) { in cfcs_datamove()
367 ctl_sglist = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr; in cfcs_datamove()
368 ctl_sg_count = io->scsiio.kern_sg_entries; in cfcs_datamove()
371 ctl_sglist->addr = io->scsiio.kern_data_ptr; in cfcs_datamove()
372 ctl_sglist->len = io->scsiio.kern_data_len; in cfcs_datamove()
382 len_to_copy = MIN(cam_sglist[i].ds_len - cam_watermark, in cfcs_datamove()
383 ctl_sglist[j].len - ctl_watermark); in cfcs_datamove()
385 cam_ptr = (uint8_t *)(uintptr_t)cam_sglist[i].ds_addr; in cfcs_datamove()
387 if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) { in cfcs_datamove()
393 kern_ptr = bus_to_virt(kern_sglist[j].addr); in cfcs_datamove()
396 ctl_ptr = (uint8_t *)ctl_sglist[j].addr; in cfcs_datamove()
399 if ((io->io_hdr.flags & CTL_FLAG_DATA_MASK) == in cfcs_datamove()
414 io->scsiio.ext_data_filled += len_to_copy; in cfcs_datamove()
415 io->scsiio.kern_data_resid -= len_to_copy; in cfcs_datamove()
418 if (cam_sglist[i].ds_len == cam_watermark) { in cfcs_datamove()
424 if (ctl_sglist[j].len == ctl_watermark) { in cfcs_datamove()
430 if ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS) { in cfcs_datamove()
431 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = NULL; in cfcs_datamove()
432 io->io_hdr.flags |= CTL_FLAG_STATUS_SENT; in cfcs_datamove()
433 ccb->csio.resid = ccb->csio.dxfer_len - in cfcs_datamove()
434 io->scsiio.ext_data_filled; in cfcs_datamove()
435 ccb->ccb_h.status &= ~CAM_STATUS_MASK; in cfcs_datamove()
436 ccb->ccb_h.status |= CAM_REQ_CMP; in cfcs_datamove()
440 io->scsiio.be_move_done(io); in cfcs_datamove()
448 ccb = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; in cfcs_done()
455 * At this point we should have status. If we don't, that's a bug. in cfcs_done()
457 KASSERT(((io->io_hdr.status & CTL_STATUS_MASK) != CTL_STATUS_NONE), in cfcs_done()
458 ("invalid CTL status %#x", io->io_hdr.status)); in cfcs_done()
461 * Translate CTL status to CAM status. in cfcs_done()
463 if (ccb->ccb_h.func_code == XPT_SCSI_IO) { in cfcs_done()
464 ccb->csio.resid = ccb->csio.dxfer_len - in cfcs_done()
465 io->scsiio.ext_data_filled; in cfcs_done()
467 ccb->ccb_h.status &= ~CAM_STATUS_MASK; in cfcs_done()
468 switch (io->io_hdr.status & CTL_STATUS_MASK) { in cfcs_done()
470 ccb->ccb_h.status |= CAM_REQ_CMP; in cfcs_done()
473 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; in cfcs_done()
474 ccb->csio.scsi_status = io->scsiio.scsi_status; in cfcs_done()
475 bcopy(&io->scsiio.sense_data, &ccb->csio.sense_data, in cfcs_done()
476 min(io->scsiio.sense_len, ccb->csio.sense_len)); in cfcs_done()
477 if (ccb->csio.sense_len > io->scsiio.sense_len) in cfcs_done()
478 ccb->csio.sense_resid = ccb->csio.sense_len - in cfcs_done()
479 io->scsiio.sense_len; in cfcs_done()
481 ccb->csio.sense_resid = 0; in cfcs_done()
482 if ((ccb->csio.sense_len - ccb->csio.sense_resid) > in cfcs_done()
484 ccb->csio.sense_resid = ccb->csio.sense_len - in cfcs_done()
489 ccb->ccb_h.status |= CAM_REQ_ABORTED; in cfcs_done()
493 ccb->ccb_h.status |= CAM_REQ_CMP_ERR; in cfcs_done()
496 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP && in cfcs_done()
497 (ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { in cfcs_done()
498 xpt_freeze_devq(ccb->ccb_h.path, 1); in cfcs_done()
499 ccb->ccb_h.status |= CAM_DEV_QFRZN; in cfcs_done()
514 switch (ccb->ccb_h.func_code) { in cfcs_action()
523 * indicate situations we currently can't handle. in cfcs_action()
525 if (ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS) { in cfcs_action()
526 ccb->ccb_h.status = CAM_REQ_INVALID; in cfcs_action()
528 __func__, ccb->ccb_h.flags & CFCS_BAD_CCB_FLAGS, in cfcs_action()
529 ccb->ccb_h.flags); in cfcs_action()
535 * If we aren't online, there are no devices to see. in cfcs_action()
538 ccb->ccb_h.status = CAM_DEV_NOT_THERE; in cfcs_action()
543 io = ctl_alloc_io_nowait(softc->port.ctl_pool_ref); in cfcs_action()
546 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN; in cfcs_action()
547 xpt_freeze_devq(ccb->ccb_h.path, 1); in cfcs_action()
553 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb; in cfcs_action()
554 ccb->ccb_h.io_ptr = io; in cfcs_action()
557 * Only SCSI I/O comes down this path, resets, etc. come in cfcs_action()
558 * down via the XPT_RESET_BUS/LUN CCBs below. in cfcs_action()
560 io->io_hdr.io_type = CTL_IO_SCSI; in cfcs_action()
561 io->io_hdr.nexus.initid = 1; in cfcs_action()
562 io->io_hdr.nexus.targ_port = softc->port.targ_port; in cfcs_action()
563 io->io_hdr.nexus.targ_lun = ctl_decode_lun( in cfcs_action()
564 CAM_EXTLUN_BYTE_SWIZZLE(ccb->ccb_h.target_lun)); in cfcs_action()
568 * in a high I/O environment. But it should work well in cfcs_action()
569 * enough for now. Since we're using unsigned ints, in cfcs_action()
570 * they'll just wrap around. in cfcs_action()
572 io->scsiio.tag_num = softc->cur_tag_num++; in cfcs_action()
573 csio->tag_id = io->scsiio.tag_num; in cfcs_action()
576 io->scsiio.tag_type = CTL_TAG_UNTAGGED; in cfcs_action()
579 io->scsiio.tag_type = CTL_TAG_SIMPLE; in cfcs_action()
582 io->scsiio.tag_type = CTL_TAG_HEAD_OF_QUEUE; in cfcs_action()
585 io->scsiio.tag_type = CTL_TAG_ORDERED; in cfcs_action()
588 io->scsiio.tag_type = CTL_TAG_ACA; in cfcs_action()
591 io->scsiio.tag_type = CTL_TAG_UNTAGGED; in cfcs_action()
596 if (csio->cdb_len > sizeof(io->scsiio.cdb)) { in cfcs_action()
598 __func__, csio->cdb_len, sizeof(io->scsiio.cdb)); in cfcs_action()
600 io->scsiio.cdb_len = min(csio->cdb_len, sizeof(io->scsiio.cdb)); in cfcs_action()
601 bcopy(scsiio_cdb_ptr(csio), io->scsiio.cdb, io->scsiio.cdb_len); in cfcs_action()
603 ccb->ccb_h.status |= CAM_SIM_QUEUED; in cfcs_action()
608 ccb->ccb_h.func_code, err); in cfcs_action()
610 ccb->ccb_h.status = CAM_REQ_INVALID; in cfcs_action()
620 abort_ccb = ccb->cab.abort_ccb; in cfcs_action()
622 if (abort_ccb->ccb_h.func_code != XPT_SCSI_IO) { in cfcs_action()
623 ccb->ccb_h.status = CAM_REQ_INVALID; in cfcs_action()
628 * If we aren't online, there are no devices to talk to. in cfcs_action()
631 ccb->ccb_h.status = CAM_DEV_NOT_THERE; in cfcs_action()
636 io = ctl_alloc_io_nowait(softc->port.ctl_pool_ref); in cfcs_action()
638 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN; in cfcs_action()
639 xpt_freeze_devq(ccb->ccb_h.path, 1); in cfcs_action()
646 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb; in cfcs_action()
647 ccb->ccb_h.io_ptr = io; in cfcs_action()
649 io->io_hdr.io_type = CTL_IO_TASK; in cfcs_action()
650 io->io_hdr.nexus.initid = 1; in cfcs_action()
651 io->io_hdr.nexus.targ_port = softc->port.targ_port; in cfcs_action()
652 io->io_hdr.nexus.targ_lun = ctl_decode_lun( in cfcs_action()
653 CAM_EXTLUN_BYTE_SWIZZLE(ccb->ccb_h.target_lun)); in cfcs_action()
654 io->taskio.task_action = CTL_TASK_ABORT_TASK; in cfcs_action()
655 io->taskio.tag_num = abort_ccb->csio.tag_id; in cfcs_action()
656 switch (abort_ccb->csio.tag_action) { in cfcs_action()
658 io->taskio.tag_type = CTL_TAG_UNTAGGED; in cfcs_action()
661 io->taskio.tag_type = CTL_TAG_SIMPLE; in cfcs_action()
664 io->taskio.tag_type = CTL_TAG_HEAD_OF_QUEUE; in cfcs_action()
667 io->taskio.tag_type = CTL_TAG_ORDERED; in cfcs_action()
670 io->taskio.tag_type = CTL_TAG_ACA; in cfcs_action()
673 io->taskio.tag_type = CTL_TAG_UNTAGGED; in cfcs_action()
675 abort_ccb->csio.tag_action); in cfcs_action()
682 ccb->ccb_h.func_code, err); in cfcs_action()
693 scsi = &cts->proto_specific.scsi; in cfcs_action()
694 fc = &cts->xport_specific.fc; in cfcs_action()
708 fc->port = softc->port.targ_port; in cfcs_action()
711 ccb->ccb_h.status = CAM_REQ_CMP; in cfcs_action()
716 ccb->ccb_h.status = CAM_REQ_CMP; in cfcs_action()
723 * If we aren't online, there are no devices to talk to. in cfcs_action()
726 ccb->ccb_h.status = CAM_DEV_NOT_THERE; in cfcs_action()
731 io = ctl_alloc_io_nowait(softc->port.ctl_pool_ref); in cfcs_action()
733 ccb->ccb_h.status = CAM_BUSY | CAM_DEV_QFRZN; in cfcs_action()
734 xpt_freeze_devq(ccb->ccb_h.path, 1); in cfcs_action()
741 if (ccb->ccb_h.func_code == XPT_RESET_DEV) in cfcs_action()
742 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = ccb; in cfcs_action()
743 ccb->ccb_h.io_ptr = io; in cfcs_action()
745 io->io_hdr.io_type = CTL_IO_TASK; in cfcs_action()
746 io->io_hdr.nexus.initid = 1; in cfcs_action()
747 io->io_hdr.nexus.targ_port = softc->port.targ_port; in cfcs_action()
748 io->io_hdr.nexus.targ_lun = ctl_decode_lun( in cfcs_action()
749 CAM_EXTLUN_BYTE_SWIZZLE(ccb->ccb_h.target_lun)); in cfcs_action()
750 if (ccb->ccb_h.func_code == XPT_RESET_BUS) in cfcs_action()
751 io->taskio.task_action = CTL_TASK_BUS_RESET; in cfcs_action()
753 io->taskio.task_action = CTL_TASK_LUN_RESET; in cfcs_action()
759 ccb->ccb_h.func_code, err); in cfcs_action()
795 * Pretend to be Fibre Channel. in cfcs_action()
799 cpi->xport_specific.fc.wwnn = softc->wwnn; in cfcs_action()
800 cpi->xport_specific.fc.wwpn = softc->wwpn; in cfcs_action()
801 cpi->xport_specific.fc.port = softc->port.targ_port; in cfcs_action()
802 cpi->xport_specific.fc.bitrate = 8 * 1000 * 1000; in cfcs_action()
803 cpi->ccb_h.status = CAM_REQ_CMP; in cfcs_action()
807 ccb->ccb_h.status = CAM_PROVIDE_FAIL; in cfcs_action()
809 ccb->ccb_h.func_code); in cfcs_action()