Deleted Added
full compact
ctl.c (275920) ctl.c (275942)
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * Copyright (c) 2012 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Edward Tomasz Napierala
7 * under sponsorship from the FreeBSD Foundation.
8 *

--- 28 unchanged lines hidden (view full) ---

37 * CAM Target Layer, a SCSI device emulation subsystem.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#define _CTL_C
43
44#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * Copyright (c) 2012 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Edward Tomasz Napierala
7 * under sponsorship from the FreeBSD Foundation.
8 *

--- 28 unchanged lines hidden (view full) ---

37 * CAM Target Layer, a SCSI device emulation subsystem.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#define _CTL_C
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 275920 2014-12-18 22:32:22Z mav $");
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 275942 2014-12-19 20:35:06Z mav $");
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/ctype.h>
50#include <sys/kernel.h>
51#include <sys/types.h>
52#include <sys/kthread.h>
53#include <sys/bio.h>

--- 339 unchanged lines hidden (view full) ---

393static void ctl_ioctl_hard_startstop_callback(void *arg,
394 struct cfi_metatask *metatask);
395static void ctl_ioctl_bbrread_callback(void *arg,struct cfi_metatask *metatask);
396static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
397 struct ctl_ooa *ooa_hdr,
398 struct ctl_ooa_entry *kern_entries);
399static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
400 struct thread *td);
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/ctype.h>
50#include <sys/kernel.h>
51#include <sys/types.h>
52#include <sys/kthread.h>
53#include <sys/bio.h>

--- 339 unchanged lines hidden (view full) ---

393static void ctl_ioctl_hard_startstop_callback(void *arg,
394 struct cfi_metatask *metatask);
395static void ctl_ioctl_bbrread_callback(void *arg,struct cfi_metatask *metatask);
396static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
397 struct ctl_ooa *ooa_hdr,
398 struct ctl_ooa_entry *kern_entries);
399static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
400 struct thread *td);
401static uint32_t ctl_map_lun(int port_num, uint32_t lun);
402static uint32_t ctl_map_lun_back(int port_num, uint32_t lun);
401static uint32_t ctl_map_lun(struct ctl_softc *softc, int port_num, uint32_t lun);
402static uint32_t ctl_map_lun_back(struct ctl_softc *softc, int port_num, uint32_t lun);
403static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
404 struct ctl_be_lun *be_lun, struct ctl_id target_id);
405static int ctl_free_lun(struct ctl_lun *lun);
406static void ctl_create_lun(struct ctl_be_lun *be_lun);
407/**
408static void ctl_failover_change_pages(struct ctl_softc *softc,
409 struct ctl_scsiio *ctsio, int master);
410**/

--- 25 unchanged lines hidden (view full) ---

436static ctl_action ctl_extent_check(union ctl_io *io1, union ctl_io *io2,
437 bool seq);
438static ctl_action ctl_extent_check_seq(union ctl_io *io1, union ctl_io *io2);
439static ctl_action ctl_check_for_blockage(struct ctl_lun *lun,
440 union ctl_io *pending_io, union ctl_io *ooa_io);
441static ctl_action ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io,
442 union ctl_io *starting_io);
443static int ctl_check_blocked(struct ctl_lun *lun);
403static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
404 struct ctl_be_lun *be_lun, struct ctl_id target_id);
405static int ctl_free_lun(struct ctl_lun *lun);
406static void ctl_create_lun(struct ctl_be_lun *be_lun);
407/**
408static void ctl_failover_change_pages(struct ctl_softc *softc,
409 struct ctl_scsiio *ctsio, int master);
410**/

--- 25 unchanged lines hidden (view full) ---

436static ctl_action ctl_extent_check(union ctl_io *io1, union ctl_io *io2,
437 bool seq);
438static ctl_action ctl_extent_check_seq(union ctl_io *io1, union ctl_io *io2);
439static ctl_action ctl_check_for_blockage(struct ctl_lun *lun,
440 union ctl_io *pending_io, union ctl_io *ooa_io);
441static ctl_action ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io,
442 union ctl_io *starting_io);
443static int ctl_check_blocked(struct ctl_lun *lun);
444static int ctl_scsiio_lun_check(struct ctl_softc *ctl_softc,
445 struct ctl_lun *lun,
444static int ctl_scsiio_lun_check(struct ctl_lun *lun,
446 const struct ctl_cmd_entry *entry,
447 struct ctl_scsiio *ctsio);
448//static int ctl_check_rtr(union ctl_io *pending_io, struct ctl_softc *softc);
449static void ctl_failover(void);
450static int ctl_scsiio_precheck(struct ctl_softc *ctl_softc,
451 struct ctl_scsiio *ctsio);
452static int ctl_scsiio(struct ctl_scsiio *ctsio);
453

--- 150 unchanged lines hidden (view full) ---

604
605/*
606 * ISC (Inter Shelf Communication) event handler. Events from the HA
607 * subsystem come in here.
608 */
609static void
610ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
611{
445 const struct ctl_cmd_entry *entry,
446 struct ctl_scsiio *ctsio);
447//static int ctl_check_rtr(union ctl_io *pending_io, struct ctl_softc *softc);
448static void ctl_failover(void);
449static int ctl_scsiio_precheck(struct ctl_softc *ctl_softc,
450 struct ctl_scsiio *ctsio);
451static int ctl_scsiio(struct ctl_scsiio *ctsio);
452

--- 150 unchanged lines hidden (view full) ---

603
604/*
605 * ISC (Inter Shelf Communication) event handler. Events from the HA
606 * subsystem come in here.
607 */
608static void
609ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
610{
612 struct ctl_softc *ctl_softc;
611 struct ctl_softc *softc;
613 union ctl_io *io;
614 struct ctl_prio *presio;
615 ctl_ha_status isc_status;
616
612 union ctl_io *io;
613 struct ctl_prio *presio;
614 ctl_ha_status isc_status;
615
617 ctl_softc = control_softc;
616 softc = control_softc;
618 io = NULL;
619
620
621#if 0
622 printf("CTL: Isc Msg event %d\n", event);
623#endif
624 if (event == CTL_HA_EVT_MSG_RECV) {
625 union ctl_ha_msg msg_info;

--- 9 unchanged lines hidden (view full) ---

635 return;
636 }
637
638 switch (msg_info.hdr.msg_type) {
639 case CTL_MSG_SERIALIZE:
640#if 0
641 printf("Serialize\n");
642#endif
617 io = NULL;
618
619
620#if 0
621 printf("CTL: Isc Msg event %d\n", event);
622#endif
623 if (event == CTL_HA_EVT_MSG_RECV) {
624 union ctl_ha_msg msg_info;

--- 9 unchanged lines hidden (view full) ---

634 return;
635 }
636
637 switch (msg_info.hdr.msg_type) {
638 case CTL_MSG_SERIALIZE:
639#if 0
640 printf("Serialize\n");
641#endif
643 io = ctl_alloc_io_nowait(ctl_softc->othersc_pool);
642 io = ctl_alloc_io_nowait(softc->othersc_pool);
644 if (io == NULL) {
645 printf("ctl_isc_event_handler: can't allocate "
646 "ctl_io!\n");
647 /* Bad Juju */
648 /* Need to set busy and send msg back */
649 msg_info.hdr.msg_type = CTL_MSG_BAD_JUJU;
650 msg_info.hdr.status = CTL_SCSI_ERROR;
651 msg_info.scsi.scsi_status = SCSI_STATUS_BUSY;

--- 15 unchanged lines hidden (view full) ---

667 CTL_FLAG_IO_ACTIVE;
668 /*
669 * If we're in serialization-only mode, we don't
670 * want to go through full done processing. Thus
671 * the COPY flag.
672 *
673 * XXX KDM add another flag that is more specific.
674 */
643 if (io == NULL) {
644 printf("ctl_isc_event_handler: can't allocate "
645 "ctl_io!\n");
646 /* Bad Juju */
647 /* Need to set busy and send msg back */
648 msg_info.hdr.msg_type = CTL_MSG_BAD_JUJU;
649 msg_info.hdr.status = CTL_SCSI_ERROR;
650 msg_info.scsi.scsi_status = SCSI_STATUS_BUSY;

--- 15 unchanged lines hidden (view full) ---

666 CTL_FLAG_IO_ACTIVE;
667 /*
668 * If we're in serialization-only mode, we don't
669 * want to go through full done processing. Thus
670 * the COPY flag.
671 *
672 * XXX KDM add another flag that is more specific.
673 */
675 if (ctl_softc->ha_mode == CTL_HA_MODE_SER_ONLY)
674 if (softc->ha_mode == CTL_HA_MODE_SER_ONLY)
676 io->io_hdr.flags |= CTL_FLAG_INT_COPY;
677 io->io_hdr.nexus = msg_info.hdr.nexus;
678#if 0
679 printf("targ %d, port %d, iid %d, lun %d\n",
680 io->io_hdr.nexus.targ_target.id,
681 io->io_hdr.nexus.targ_port,
682 io->io_hdr.nexus.initid.id,
683 io->io_hdr.nexus.targ_lun);
684#endif
685 io->scsiio.tag_num = msg_info.scsi.tag_num;
686 io->scsiio.tag_type = msg_info.scsi.tag_type;
687 memcpy(io->scsiio.cdb, msg_info.scsi.cdb,
688 CTL_MAX_CDBLEN);
675 io->io_hdr.flags |= CTL_FLAG_INT_COPY;
676 io->io_hdr.nexus = msg_info.hdr.nexus;
677#if 0
678 printf("targ %d, port %d, iid %d, lun %d\n",
679 io->io_hdr.nexus.targ_target.id,
680 io->io_hdr.nexus.targ_port,
681 io->io_hdr.nexus.initid.id,
682 io->io_hdr.nexus.targ_lun);
683#endif
684 io->scsiio.tag_num = msg_info.scsi.tag_num;
685 io->scsiio.tag_type = msg_info.scsi.tag_type;
686 memcpy(io->scsiio.cdb, msg_info.scsi.cdb,
687 CTL_MAX_CDBLEN);
689 if (ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
688 if (softc->ha_mode == CTL_HA_MODE_XFER) {
690 const struct ctl_cmd_entry *entry;
691
692 entry = ctl_get_cmd_entry(&io->scsiio, NULL);
693 io->io_hdr.flags &= ~CTL_FLAG_DATA_MASK;
694 io->io_hdr.flags |=
695 entry->flags & CTL_FLAG_DATA_MASK;
696 }
697 ctl_enqueue_isc(io);

--- 149 unchanged lines hidden (view full) ---

847
848 /*
849 * Performed on Serializing(i.e. primary SC) SC in SER_ONLY
850 * mode.
851 * Performed on the Originating (i.e. secondary) SC in XFER
852 * mode
853 */
854 case CTL_MSG_FINISH_IO:
689 const struct ctl_cmd_entry *entry;
690
691 entry = ctl_get_cmd_entry(&io->scsiio, NULL);
692 io->io_hdr.flags &= ~CTL_FLAG_DATA_MASK;
693 io->io_hdr.flags |=
694 entry->flags & CTL_FLAG_DATA_MASK;
695 }
696 ctl_enqueue_isc(io);

--- 149 unchanged lines hidden (view full) ---

846
847 /*
848 * Performed on Serializing(i.e. primary SC) SC in SER_ONLY
849 * mode.
850 * Performed on the Originating (i.e. secondary) SC in XFER
851 * mode
852 */
853 case CTL_MSG_FINISH_IO:
855 if (ctl_softc->ha_mode == CTL_HA_MODE_XFER)
856 ctl_isc_handler_finish_xfer(ctl_softc,
854 if (softc->ha_mode == CTL_HA_MODE_XFER)
855 ctl_isc_handler_finish_xfer(softc,
857 &msg_info);
858 else
856 &msg_info);
857 else
859 ctl_isc_handler_finish_ser_only(ctl_softc,
858 ctl_isc_handler_finish_ser_only(softc,
860 &msg_info);
861 break;
862
863 /* Preformed on Originating SC */
864 case CTL_MSG_BAD_JUJU:
865 io = msg_info.hdr.original_sc;
866 if (io == NULL) {
867 printf("%s: Bad JUJU!, original_sc is NULL!\n",

--- 13 unchanged lines hidden (view full) ---

881 io->io_hdr.msg_type = CTL_MSG_BAD_JUJU;
882 ctl_enqueue_isc(io);
883 break;
884
885 /* Handle resets sent from the other side */
886 case CTL_MSG_MANAGE_TASKS: {
887 struct ctl_taskio *taskio;
888 taskio = (struct ctl_taskio *)ctl_alloc_io_nowait(
859 &msg_info);
860 break;
861
862 /* Preformed on Originating SC */
863 case CTL_MSG_BAD_JUJU:
864 io = msg_info.hdr.original_sc;
865 if (io == NULL) {
866 printf("%s: Bad JUJU!, original_sc is NULL!\n",

--- 13 unchanged lines hidden (view full) ---

880 io->io_hdr.msg_type = CTL_MSG_BAD_JUJU;
881 ctl_enqueue_isc(io);
882 break;
883
884 /* Handle resets sent from the other side */
885 case CTL_MSG_MANAGE_TASKS: {
886 struct ctl_taskio *taskio;
887 taskio = (struct ctl_taskio *)ctl_alloc_io_nowait(
889 ctl_softc->othersc_pool);
888 softc->othersc_pool);
890 if (taskio == NULL) {
891 printf("ctl_isc_event_handler: can't allocate "
892 "ctl_io!\n");
893 /* Bad Juju */
894 /* should I just call the proper reset func
895 here??? */
896 goto bailout;
897 }

--- 12 unchanged lines hidden (view full) ---

910#endif
911#endif /* CTL_TIME_IO */
912 ctl_run_task((union ctl_io *)taskio);
913 break;
914 }
915 /* Persistent Reserve action which needs attention */
916 case CTL_MSG_PERS_ACTION:
917 presio = (struct ctl_prio *)ctl_alloc_io_nowait(
889 if (taskio == NULL) {
890 printf("ctl_isc_event_handler: can't allocate "
891 "ctl_io!\n");
892 /* Bad Juju */
893 /* should I just call the proper reset func
894 here??? */
895 goto bailout;
896 }

--- 12 unchanged lines hidden (view full) ---

909#endif
910#endif /* CTL_TIME_IO */
911 ctl_run_task((union ctl_io *)taskio);
912 break;
913 }
914 /* Persistent Reserve action which needs attention */
915 case CTL_MSG_PERS_ACTION:
916 presio = (struct ctl_prio *)ctl_alloc_io_nowait(
918 ctl_softc->othersc_pool);
917 softc->othersc_pool);
919 if (presio == NULL) {
920 printf("ctl_isc_event_handler: can't allocate "
921 "ctl_io!\n");
922 /* Bad Juju */
923 /* Need to set busy and send msg back */
924 goto bailout;
925 }
926 ctl_zero_io((union ctl_io *)presio);

--- 900 unchanged lines hidden (view full) ---

1827 * standard case in ctl_scsiio_precheck(). Errors in this case need to get
1828 * sent back to the other side, but in the success case, we execute the
1829 * command on this side (XFER mode) or tell the other side to execute it
1830 * (SER_ONLY mode).
1831 */
1832static int
1833ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio)
1834{
918 if (presio == NULL) {
919 printf("ctl_isc_event_handler: can't allocate "
920 "ctl_io!\n");
921 /* Bad Juju */
922 /* Need to set busy and send msg back */
923 goto bailout;
924 }
925 ctl_zero_io((union ctl_io *)presio);

--- 900 unchanged lines hidden (view full) ---

1826 * standard case in ctl_scsiio_precheck(). Errors in this case need to get
1827 * sent back to the other side, but in the success case, we execute the
1828 * command on this side (XFER mode) or tell the other side to execute it
1829 * (SER_ONLY mode).
1830 */
1831static int
1832ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio)
1833{
1835 struct ctl_softc *ctl_softc;
1834 struct ctl_softc *softc;
1836 union ctl_ha_msg msg_info;
1837 struct ctl_lun *lun;
1838 int retval = 0;
1839 uint32_t targ_lun;
1840
1835 union ctl_ha_msg msg_info;
1836 struct ctl_lun *lun;
1837 int retval = 0;
1838 uint32_t targ_lun;
1839
1841 ctl_softc = control_softc;
1840 softc = control_softc;
1842
1843 targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
1841
1842 targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
1844 lun = ctl_softc->ctl_luns[targ_lun];
1843 lun = softc->ctl_luns[targ_lun];
1845 if (lun==NULL)
1846 {
1847 /*
1848 * Why isn't LUN defined? The other side wouldn't
1849 * send a cmd if the LUN is undefined.
1850 */
1851 printf("%s: Bad JUJU!, LUN is NULL!\n", __func__);
1852

--- 28 unchanged lines hidden (view full) ---

1881 ooa_links))) {
1882 case CTL_ACTION_BLOCK:
1883 ctsio->io_hdr.flags |= CTL_FLAG_BLOCKED;
1884 TAILQ_INSERT_TAIL(&lun->blocked_queue, &ctsio->io_hdr,
1885 blocked_links);
1886 break;
1887 case CTL_ACTION_PASS:
1888 case CTL_ACTION_SKIP:
1844 if (lun==NULL)
1845 {
1846 /*
1847 * Why isn't LUN defined? The other side wouldn't
1848 * send a cmd if the LUN is undefined.
1849 */
1850 printf("%s: Bad JUJU!, LUN is NULL!\n", __func__);
1851

--- 28 unchanged lines hidden (view full) ---

1880 ooa_links))) {
1881 case CTL_ACTION_BLOCK:
1882 ctsio->io_hdr.flags |= CTL_FLAG_BLOCKED;
1883 TAILQ_INSERT_TAIL(&lun->blocked_queue, &ctsio->io_hdr,
1884 blocked_links);
1885 break;
1886 case CTL_ACTION_PASS:
1887 case CTL_ACTION_SKIP:
1889 if (ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
1888 if (softc->ha_mode == CTL_HA_MODE_XFER) {
1890 ctsio->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR;
1891 ctl_enqueue_rtr((union ctl_io *)ctsio);
1892 } else {
1893
1894 /* send msg back to other side */
1895 msg_info.hdr.original_sc = ctsio->io_hdr.original_sc;
1896 msg_info.hdr.serializing_sc = (union ctl_io *)ctsio;
1897 msg_info.hdr.msg_type = CTL_MSG_R2R;

--- 1699 unchanged lines hidden (view full) ---

3597{
3598 if (port_num < CTL_MAX_PORTS)
3599 return(port_num);
3600 else
3601 return(port_num - CTL_MAX_PORTS);
3602}
3603
3604static uint32_t
1889 ctsio->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR;
1890 ctl_enqueue_rtr((union ctl_io *)ctsio);
1891 } else {
1892
1893 /* send msg back to other side */
1894 msg_info.hdr.original_sc = ctsio->io_hdr.original_sc;
1895 msg_info.hdr.serializing_sc = (union ctl_io *)ctsio;
1896 msg_info.hdr.msg_type = CTL_MSG_R2R;

--- 1699 unchanged lines hidden (view full) ---

3596{
3597 if (port_num < CTL_MAX_PORTS)
3598 return(port_num);
3599 else
3600 return(port_num - CTL_MAX_PORTS);
3601}
3602
3603static uint32_t
3605ctl_map_lun(int port_num, uint32_t lun_id)
3604ctl_map_lun(struct ctl_softc *softc, int port_num, uint32_t lun_id)
3606{
3607 struct ctl_port *port;
3608
3605{
3606 struct ctl_port *port;
3607
3609 port = control_softc->ctl_ports[ctl_port_idx(port_num)];
3608 port = softc->ctl_ports[ctl_port_idx(port_num)];
3610 if (port == NULL)
3611 return (UINT32_MAX);
3612 if (port->lun_map == NULL)
3613 return (lun_id);
3614 return (port->lun_map(port->targ_lun_arg, lun_id));
3615}
3616
3617static uint32_t
3609 if (port == NULL)
3610 return (UINT32_MAX);
3611 if (port->lun_map == NULL)
3612 return (lun_id);
3613 return (port->lun_map(port->targ_lun_arg, lun_id));
3614}
3615
3616static uint32_t
3618ctl_map_lun_back(int port_num, uint32_t lun_id)
3617ctl_map_lun_back(struct ctl_softc *softc, int port_num, uint32_t lun_id)
3619{
3620 struct ctl_port *port;
3621 uint32_t i;
3622
3618{
3619 struct ctl_port *port;
3620 uint32_t i;
3621
3623 port = control_softc->ctl_ports[ctl_port_idx(port_num)];
3622 port = softc->ctl_ports[ctl_port_idx(port_num)];
3624 if (port->lun_map == NULL)
3625 return (lun_id);
3626 for (i = 0; i < CTL_MAX_LUNS; i++) {
3627 if (port->lun_map(port->targ_lun_arg, i) == lun_id)
3628 return (i);
3629 }
3630 return (UINT32_MAX);
3631}

--- 1140 unchanged lines hidden (view full) ---

4772 }
4773
4774 return (0);
4775}
4776
4777static void
4778ctl_create_lun(struct ctl_be_lun *be_lun)
4779{
3623 if (port->lun_map == NULL)
3624 return (lun_id);
3625 for (i = 0; i < CTL_MAX_LUNS; i++) {
3626 if (port->lun_map(port->targ_lun_arg, i) == lun_id)
3627 return (i);
3628 }
3629 return (UINT32_MAX);
3630}

--- 1140 unchanged lines hidden (view full) ---

4771 }
4772
4773 return (0);
4774}
4775
4776static void
4777ctl_create_lun(struct ctl_be_lun *be_lun)
4778{
4780 struct ctl_softc *ctl_softc;
4779 struct ctl_softc *softc;
4781
4780
4782 ctl_softc = control_softc;
4781 softc = control_softc;
4783
4784 /*
4785 * ctl_alloc_lun() should handle all potential failure cases.
4786 */
4782
4783 /*
4784 * ctl_alloc_lun() should handle all potential failure cases.
4785 */
4787 ctl_alloc_lun(ctl_softc, NULL, be_lun, ctl_softc->target);
4786 ctl_alloc_lun(softc, NULL, be_lun, softc->target);
4788}
4789
4790int
4791ctl_add_lun(struct ctl_be_lun *be_lun)
4792{
4787}
4788
4789int
4790ctl_add_lun(struct ctl_be_lun *be_lun)
4791{
4793 struct ctl_softc *ctl_softc = control_softc;
4792 struct ctl_softc *softc = control_softc;
4794
4793
4795 mtx_lock(&ctl_softc->ctl_lock);
4796 STAILQ_INSERT_TAIL(&ctl_softc->pending_lun_queue, be_lun, links);
4797 mtx_unlock(&ctl_softc->ctl_lock);
4798 wakeup(&ctl_softc->pending_lun_queue);
4794 mtx_lock(&softc->ctl_lock);
4795 STAILQ_INSERT_TAIL(&softc->pending_lun_queue, be_lun, links);
4796 mtx_unlock(&softc->ctl_lock);
4797 wakeup(&softc->pending_lun_queue);
4799
4800 return (0);
4801}
4802
4803int
4804ctl_enable_lun(struct ctl_be_lun *be_lun)
4805{
4798
4799 return (0);
4800}
4801
4802int
4803ctl_enable_lun(struct ctl_be_lun *be_lun)
4804{
4806 struct ctl_softc *ctl_softc;
4805 struct ctl_softc *softc;
4807 struct ctl_port *port, *nport;
4808 struct ctl_lun *lun;
4809 int retval;
4810
4806 struct ctl_port *port, *nport;
4807 struct ctl_lun *lun;
4808 int retval;
4809
4811 ctl_softc = control_softc;
4812
4813 lun = (struct ctl_lun *)be_lun->ctl_lun;
4810 lun = (struct ctl_lun *)be_lun->ctl_lun;
4811 softc = lun->ctl_softc;
4814
4812
4815 mtx_lock(&ctl_softc->ctl_lock);
4813 mtx_lock(&softc->ctl_lock);
4816 mtx_lock(&lun->lun_lock);
4817 if ((lun->flags & CTL_LUN_DISABLED) == 0) {
4818 /*
4819 * eh? Why did we get called if the LUN is already
4820 * enabled?
4821 */
4822 mtx_unlock(&lun->lun_lock);
4814 mtx_lock(&lun->lun_lock);
4815 if ((lun->flags & CTL_LUN_DISABLED) == 0) {
4816 /*
4817 * eh? Why did we get called if the LUN is already
4818 * enabled?
4819 */
4820 mtx_unlock(&lun->lun_lock);
4823 mtx_unlock(&ctl_softc->ctl_lock);
4821 mtx_unlock(&softc->ctl_lock);
4824 return (0);
4825 }
4826 lun->flags &= ~CTL_LUN_DISABLED;
4827 mtx_unlock(&lun->lun_lock);
4828
4822 return (0);
4823 }
4824 lun->flags &= ~CTL_LUN_DISABLED;
4825 mtx_unlock(&lun->lun_lock);
4826
4829 for (port = STAILQ_FIRST(&ctl_softc->port_list); port != NULL; port = nport) {
4827 for (port = STAILQ_FIRST(&softc->port_list); port != NULL; port = nport) {
4830 nport = STAILQ_NEXT(port, links);
4831
4832 /*
4833 * Drop the lock while we call the FETD's enable routine.
4834 * This can lead to a callback into CTL (at least in the
4835 * case of the internal initiator frontend.
4836 */
4828 nport = STAILQ_NEXT(port, links);
4829
4830 /*
4831 * Drop the lock while we call the FETD's enable routine.
4832 * This can lead to a callback into CTL (at least in the
4833 * case of the internal initiator frontend.
4834 */
4837 mtx_unlock(&ctl_softc->ctl_lock);
4835 mtx_unlock(&softc->ctl_lock);
4838 retval = port->lun_enable(port->targ_lun_arg, lun->target,lun->lun);
4836 retval = port->lun_enable(port->targ_lun_arg, lun->target,lun->lun);
4839 mtx_lock(&ctl_softc->ctl_lock);
4837 mtx_lock(&softc->ctl_lock);
4840 if (retval != 0) {
4841 printf("%s: FETD %s port %d returned error "
4842 "%d for lun_enable on target %ju lun %jd\n",
4843 __func__, port->port_name, port->targ_port, retval,
4844 (uintmax_t)lun->target.id, (intmax_t)lun->lun);
4845 }
4846#if 0
4847 else {
4848 /* NOTE: TODO: why does lun enable affect port status? */
4849 port->status |= CTL_PORT_STATUS_LUN_ONLINE;
4850 }
4851#endif
4852 }
4853
4838 if (retval != 0) {
4839 printf("%s: FETD %s port %d returned error "
4840 "%d for lun_enable on target %ju lun %jd\n",
4841 __func__, port->port_name, port->targ_port, retval,
4842 (uintmax_t)lun->target.id, (intmax_t)lun->lun);
4843 }
4844#if 0
4845 else {
4846 /* NOTE: TODO: why does lun enable affect port status? */
4847 port->status |= CTL_PORT_STATUS_LUN_ONLINE;
4848 }
4849#endif
4850 }
4851
4854 mtx_unlock(&ctl_softc->ctl_lock);
4852 mtx_unlock(&softc->ctl_lock);
4855
4856 return (0);
4857}
4858
4859int
4860ctl_disable_lun(struct ctl_be_lun *be_lun)
4861{
4853
4854 return (0);
4855}
4856
4857int
4858ctl_disable_lun(struct ctl_be_lun *be_lun)
4859{
4862 struct ctl_softc *ctl_softc;
4860 struct ctl_softc *softc;
4863 struct ctl_port *port;
4864 struct ctl_lun *lun;
4865 int retval;
4866
4861 struct ctl_port *port;
4862 struct ctl_lun *lun;
4863 int retval;
4864
4867 ctl_softc = control_softc;
4868
4869 lun = (struct ctl_lun *)be_lun->ctl_lun;
4865 lun = (struct ctl_lun *)be_lun->ctl_lun;
4866 softc = lun->ctl_softc;
4870
4867
4871 mtx_lock(&ctl_softc->ctl_lock);
4868 mtx_lock(&softc->ctl_lock);
4872 mtx_lock(&lun->lun_lock);
4873 if (lun->flags & CTL_LUN_DISABLED) {
4874 mtx_unlock(&lun->lun_lock);
4869 mtx_lock(&lun->lun_lock);
4870 if (lun->flags & CTL_LUN_DISABLED) {
4871 mtx_unlock(&lun->lun_lock);
4875 mtx_unlock(&ctl_softc->ctl_lock);
4872 mtx_unlock(&softc->ctl_lock);
4876 return (0);
4877 }
4878 lun->flags |= CTL_LUN_DISABLED;
4879 mtx_unlock(&lun->lun_lock);
4880
4873 return (0);
4874 }
4875 lun->flags |= CTL_LUN_DISABLED;
4876 mtx_unlock(&lun->lun_lock);
4877
4881 STAILQ_FOREACH(port, &ctl_softc->port_list, links) {
4882 mtx_unlock(&ctl_softc->ctl_lock);
4878 STAILQ_FOREACH(port, &softc->port_list, links) {
4879 mtx_unlock(&softc->ctl_lock);
4883 /*
4884 * Drop the lock before we call the frontend's disable
4885 * routine, to avoid lock order reversals.
4886 *
4887 * XXX KDM what happens if the frontend list changes while
4888 * we're traversing it? It's unlikely, but should be handled.
4889 */
4890 retval = port->lun_disable(port->targ_lun_arg, lun->target,
4891 lun->lun);
4880 /*
4881 * Drop the lock before we call the frontend's disable
4882 * routine, to avoid lock order reversals.
4883 *
4884 * XXX KDM what happens if the frontend list changes while
4885 * we're traversing it? It's unlikely, but should be handled.
4886 */
4887 retval = port->lun_disable(port->targ_lun_arg, lun->target,
4888 lun->lun);
4892 mtx_lock(&ctl_softc->ctl_lock);
4889 mtx_lock(&softc->ctl_lock);
4893 if (retval != 0) {
4894 printf("ctl_alloc_lun: FETD %s port %d returned error "
4895 "%d for lun_disable on target %ju lun %jd\n",
4896 port->port_name, port->targ_port, retval,
4897 (uintmax_t)lun->target.id, (intmax_t)lun->lun);
4898 }
4899 }
4900
4890 if (retval != 0) {
4891 printf("ctl_alloc_lun: FETD %s port %d returned error "
4892 "%d for lun_disable on target %ju lun %jd\n",
4893 port->port_name, port->targ_port, retval,
4894 (uintmax_t)lun->target.id, (intmax_t)lun->lun);
4895 }
4896 }
4897
4901 mtx_unlock(&ctl_softc->ctl_lock);
4898 mtx_unlock(&softc->ctl_lock);
4902
4903 return (0);
4904}
4905
4906int
4907ctl_start_lun(struct ctl_be_lun *be_lun)
4908{
4899
4900 return (0);
4901}
4902
4903int
4904ctl_start_lun(struct ctl_be_lun *be_lun)
4905{
4909 struct ctl_softc *ctl_softc;
4910 struct ctl_lun *lun;
4906 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
4911
4907
4912 ctl_softc = control_softc;
4913
4914 lun = (struct ctl_lun *)be_lun->ctl_lun;
4915
4916 mtx_lock(&lun->lun_lock);
4917 lun->flags &= ~CTL_LUN_STOPPED;
4918 mtx_unlock(&lun->lun_lock);
4908 mtx_lock(&lun->lun_lock);
4909 lun->flags &= ~CTL_LUN_STOPPED;
4910 mtx_unlock(&lun->lun_lock);
4919
4920 return (0);
4921}
4922
4923int
4924ctl_stop_lun(struct ctl_be_lun *be_lun)
4925{
4911 return (0);
4912}
4913
4914int
4915ctl_stop_lun(struct ctl_be_lun *be_lun)
4916{
4926 struct ctl_softc *ctl_softc;
4927 struct ctl_lun *lun;
4917 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
4928
4918
4929 ctl_softc = control_softc;
4930
4931 lun = (struct ctl_lun *)be_lun->ctl_lun;
4932
4933 mtx_lock(&lun->lun_lock);
4934 lun->flags |= CTL_LUN_STOPPED;
4935 mtx_unlock(&lun->lun_lock);
4919 mtx_lock(&lun->lun_lock);
4920 lun->flags |= CTL_LUN_STOPPED;
4921 mtx_unlock(&lun->lun_lock);
4936
4937 return (0);
4938}
4939
4940int
4941ctl_lun_offline(struct ctl_be_lun *be_lun)
4942{
4922 return (0);
4923}
4924
4925int
4926ctl_lun_offline(struct ctl_be_lun *be_lun)
4927{
4943 struct ctl_softc *ctl_softc;
4944 struct ctl_lun *lun;
4928 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
4945
4929
4946 ctl_softc = control_softc;
4947
4948 lun = (struct ctl_lun *)be_lun->ctl_lun;
4949
4950 mtx_lock(&lun->lun_lock);
4951 lun->flags |= CTL_LUN_OFFLINE;
4952 mtx_unlock(&lun->lun_lock);
4930 mtx_lock(&lun->lun_lock);
4931 lun->flags |= CTL_LUN_OFFLINE;
4932 mtx_unlock(&lun->lun_lock);
4953
4954 return (0);
4955}
4956
4957int
4958ctl_lun_online(struct ctl_be_lun *be_lun)
4959{
4933 return (0);
4934}
4935
4936int
4937ctl_lun_online(struct ctl_be_lun *be_lun)
4938{
4960 struct ctl_softc *ctl_softc;
4961 struct ctl_lun *lun;
4939 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
4962
4940
4963 ctl_softc = control_softc;
4964
4965 lun = (struct ctl_lun *)be_lun->ctl_lun;
4966
4967 mtx_lock(&lun->lun_lock);
4968 lun->flags &= ~CTL_LUN_OFFLINE;
4969 mtx_unlock(&lun->lun_lock);
4941 mtx_lock(&lun->lun_lock);
4942 lun->flags &= ~CTL_LUN_OFFLINE;
4943 mtx_unlock(&lun->lun_lock);
4970
4971 return (0);
4972}
4973
4974int
4975ctl_invalidate_lun(struct ctl_be_lun *be_lun)
4976{
4944 return (0);
4945}
4946
4947int
4948ctl_invalidate_lun(struct ctl_be_lun *be_lun)
4949{
4977 struct ctl_softc *ctl_softc;
4950 struct ctl_softc *softc;
4978 struct ctl_lun *lun;
4979
4951 struct ctl_lun *lun;
4952
4980 ctl_softc = control_softc;
4981
4982 lun = (struct ctl_lun *)be_lun->ctl_lun;
4953 lun = (struct ctl_lun *)be_lun->ctl_lun;
4954 softc = lun->ctl_softc;
4983
4984 mtx_lock(&lun->lun_lock);
4985
4986 /*
4987 * The LUN needs to be disabled before it can be marked invalid.
4988 */
4989 if ((lun->flags & CTL_LUN_DISABLED) == 0) {
4990 mtx_unlock(&lun->lun_lock);

--- 6 unchanged lines hidden (view full) ---

4997
4998 /*
4999 * If there is nothing in the OOA queue, go ahead and free the LUN.
5000 * If we have something in the OOA queue, we'll free it when the
5001 * last I/O completes.
5002 */
5003 if (TAILQ_EMPTY(&lun->ooa_queue)) {
5004 mtx_unlock(&lun->lun_lock);
4955
4956 mtx_lock(&lun->lun_lock);
4957
4958 /*
4959 * The LUN needs to be disabled before it can be marked invalid.
4960 */
4961 if ((lun->flags & CTL_LUN_DISABLED) == 0) {
4962 mtx_unlock(&lun->lun_lock);

--- 6 unchanged lines hidden (view full) ---

4969
4970 /*
4971 * If there is nothing in the OOA queue, go ahead and free the LUN.
4972 * If we have something in the OOA queue, we'll free it when the
4973 * last I/O completes.
4974 */
4975 if (TAILQ_EMPTY(&lun->ooa_queue)) {
4976 mtx_unlock(&lun->lun_lock);
5005 mtx_lock(&ctl_softc->ctl_lock);
4977 mtx_lock(&softc->ctl_lock);
5006 ctl_free_lun(lun);
4978 ctl_free_lun(lun);
5007 mtx_unlock(&ctl_softc->ctl_lock);
4979 mtx_unlock(&softc->ctl_lock);
5008 } else
5009 mtx_unlock(&lun->lun_lock);
5010
5011 return (0);
5012}
5013
5014int
5015ctl_lun_inoperable(struct ctl_be_lun *be_lun)
5016{
4980 } else
4981 mtx_unlock(&lun->lun_lock);
4982
4983 return (0);
4984}
4985
4986int
4987ctl_lun_inoperable(struct ctl_be_lun *be_lun)
4988{
5017 struct ctl_softc *ctl_softc;
5018 struct ctl_lun *lun;
4989 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
5019
4990
5020 ctl_softc = control_softc;
5021 lun = (struct ctl_lun *)be_lun->ctl_lun;
5022
5023 mtx_lock(&lun->lun_lock);
5024 lun->flags |= CTL_LUN_INOPERABLE;
5025 mtx_unlock(&lun->lun_lock);
4991 mtx_lock(&lun->lun_lock);
4992 lun->flags |= CTL_LUN_INOPERABLE;
4993 mtx_unlock(&lun->lun_lock);
5026
5027 return (0);
5028}
5029
5030int
5031ctl_lun_operable(struct ctl_be_lun *be_lun)
5032{
4994 return (0);
4995}
4996
4997int
4998ctl_lun_operable(struct ctl_be_lun *be_lun)
4999{
5033 struct ctl_softc *ctl_softc;
5034 struct ctl_lun *lun;
5000 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
5035
5001
5036 ctl_softc = control_softc;
5037 lun = (struct ctl_lun *)be_lun->ctl_lun;
5038
5039 mtx_lock(&lun->lun_lock);
5040 lun->flags &= ~CTL_LUN_INOPERABLE;
5041 mtx_unlock(&lun->lun_lock);
5002 mtx_lock(&lun->lun_lock);
5003 lun->flags &= ~CTL_LUN_INOPERABLE;
5004 mtx_unlock(&lun->lun_lock);
5042
5043 return (0);
5044}
5045
5046void
5047ctl_lun_capacity_changed(struct ctl_be_lun *be_lun)
5048{
5049 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
5050

--- 169 unchanged lines hidden (view full) ---

5220
5221/*
5222 * SCSI release command.
5223 */
5224int
5225ctl_scsi_release(struct ctl_scsiio *ctsio)
5226{
5227 int length, longid, thirdparty_id, resv_id;
5005 return (0);
5006}
5007
5008void
5009ctl_lun_capacity_changed(struct ctl_be_lun *be_lun)
5010{
5011 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
5012

--- 169 unchanged lines hidden (view full) ---

5182
5183/*
5184 * SCSI release command.
5185 */
5186int
5187ctl_scsi_release(struct ctl_scsiio *ctsio)
5188{
5189 int length, longid, thirdparty_id, resv_id;
5228 struct ctl_softc *ctl_softc;
5229 struct ctl_lun *lun;
5230 uint32_t residx;
5231
5232 length = 0;
5233 resv_id = 0;
5234
5235 CTL_DEBUG_PRINT(("ctl_scsi_release\n"));
5236
5237 residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
5238 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5190 struct ctl_lun *lun;
5191 uint32_t residx;
5192
5193 length = 0;
5194 resv_id = 0;
5195
5196 CTL_DEBUG_PRINT(("ctl_scsi_release\n"));
5197
5198 residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
5199 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5239 ctl_softc = control_softc;
5240
5241 switch (ctsio->cdb[0]) {
5242 case RELEASE_10: {
5243 struct scsi_release_10 *cdb;
5244
5245 cdb = (struct scsi_release_10 *)ctsio->cdb;
5246
5247 if (cdb->byte2 & SR10_LONGID)

--- 60 unchanged lines hidden (view full) ---

5308}
5309
5310int
5311ctl_scsi_reserve(struct ctl_scsiio *ctsio)
5312{
5313 int extent, thirdparty, longid;
5314 int resv_id, length;
5315 uint64_t thirdparty_id;
5200
5201 switch (ctsio->cdb[0]) {
5202 case RELEASE_10: {
5203 struct scsi_release_10 *cdb;
5204
5205 cdb = (struct scsi_release_10 *)ctsio->cdb;
5206
5207 if (cdb->byte2 & SR10_LONGID)

--- 60 unchanged lines hidden (view full) ---

5268}
5269
5270int
5271ctl_scsi_reserve(struct ctl_scsiio *ctsio)
5272{
5273 int extent, thirdparty, longid;
5274 int resv_id, length;
5275 uint64_t thirdparty_id;
5316 struct ctl_softc *ctl_softc;
5317 struct ctl_lun *lun;
5318 uint32_t residx;
5319
5320 extent = 0;
5321 thirdparty = 0;
5322 longid = 0;
5323 resv_id = 0;
5324 length = 0;
5325 thirdparty_id = 0;
5326
5327 CTL_DEBUG_PRINT(("ctl_reserve\n"));
5328
5329 residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
5330 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5276 struct ctl_lun *lun;
5277 uint32_t residx;
5278
5279 extent = 0;
5280 thirdparty = 0;
5281 longid = 0;
5282 resv_id = 0;
5283 length = 0;
5284 thirdparty_id = 0;
5285
5286 CTL_DEBUG_PRINT(("ctl_reserve\n"));
5287
5288 residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
5289 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5331 ctl_softc = control_softc;
5332
5333 switch (ctsio->cdb[0]) {
5334 case RESERVE_10: {
5335 struct scsi_reserve_10 *cdb;
5336
5337 cdb = (struct scsi_reserve_10 *)ctsio->cdb;
5338
5339 if (cdb->byte2 & SR10_LONGID)

--- 57 unchanged lines hidden (view full) ---

5397 return (CTL_RETVAL_COMPLETE);
5398}
5399
5400int
5401ctl_start_stop(struct ctl_scsiio *ctsio)
5402{
5403 struct scsi_start_stop_unit *cdb;
5404 struct ctl_lun *lun;
5290
5291 switch (ctsio->cdb[0]) {
5292 case RESERVE_10: {
5293 struct scsi_reserve_10 *cdb;
5294
5295 cdb = (struct scsi_reserve_10 *)ctsio->cdb;
5296
5297 if (cdb->byte2 & SR10_LONGID)

--- 57 unchanged lines hidden (view full) ---

5355 return (CTL_RETVAL_COMPLETE);
5356}
5357
5358int
5359ctl_start_stop(struct ctl_scsiio *ctsio)
5360{
5361 struct scsi_start_stop_unit *cdb;
5362 struct ctl_lun *lun;
5405 struct ctl_softc *ctl_softc;
5406 int retval;
5407
5408 CTL_DEBUG_PRINT(("ctl_start_stop\n"));
5409
5410 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5363 int retval;
5364
5365 CTL_DEBUG_PRINT(("ctl_start_stop\n"));
5366
5367 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5411 ctl_softc = control_softc;
5412 retval = 0;
5413
5414 cdb = (struct scsi_start_stop_unit *)ctsio->cdb;
5415
5416 /*
5417 * XXX KDM
5418 * We don't support the immediate bit on a stop unit. In order to
5419 * do that, we would need to code up a way to know that a stop is

--- 104 unchanged lines hidden (view full) ---

5524 * we don't really do anything with the LBA and length fields if the user
5525 * passes them in. Instead we'll just flush out the cache for the entire
5526 * LUN.
5527 */
5528int
5529ctl_sync_cache(struct ctl_scsiio *ctsio)
5530{
5531 struct ctl_lun *lun;
5368 retval = 0;
5369
5370 cdb = (struct scsi_start_stop_unit *)ctsio->cdb;
5371
5372 /*
5373 * XXX KDM
5374 * We don't support the immediate bit on a stop unit. In order to
5375 * do that, we would need to code up a way to know that a stop is

--- 104 unchanged lines hidden (view full) ---

5480 * we don't really do anything with the LBA and length fields if the user
5481 * passes them in. Instead we'll just flush out the cache for the entire
5482 * LUN.
5483 */
5484int
5485ctl_sync_cache(struct ctl_scsiio *ctsio)
5486{
5487 struct ctl_lun *lun;
5532 struct ctl_softc *ctl_softc;
5488 struct ctl_softc *softc;
5533 uint64_t starting_lba;
5534 uint32_t block_count;
5535 int retval;
5536
5537 CTL_DEBUG_PRINT(("ctl_sync_cache\n"));
5538
5539 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5489 uint64_t starting_lba;
5490 uint32_t block_count;
5491 int retval;
5492
5493 CTL_DEBUG_PRINT(("ctl_sync_cache\n"));
5494
5495 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5540 ctl_softc = control_softc;
5496 softc = lun->ctl_softc;
5541 retval = 0;
5542
5543 switch (ctsio->cdb[0]) {
5544 case SYNCHRONIZE_CACHE: {
5545 struct scsi_sync_cache *cdb;
5546 cdb = (struct scsi_sync_cache *)ctsio->cdb;
5547
5548 starting_lba = scsi_4btoul(cdb->begin_lba);

--- 36 unchanged lines hidden (view full) ---

5585 goto bailout;
5586 }
5587
5588 /*
5589 * Check to see whether we're configured to send the SYNCHRONIZE
5590 * CACHE command directly to the back end.
5591 */
5592 mtx_lock(&lun->lun_lock);
5497 retval = 0;
5498
5499 switch (ctsio->cdb[0]) {
5500 case SYNCHRONIZE_CACHE: {
5501 struct scsi_sync_cache *cdb;
5502 cdb = (struct scsi_sync_cache *)ctsio->cdb;
5503
5504 starting_lba = scsi_4btoul(cdb->begin_lba);

--- 36 unchanged lines hidden (view full) ---

5541 goto bailout;
5542 }
5543
5544 /*
5545 * Check to see whether we're configured to send the SYNCHRONIZE
5546 * CACHE command directly to the back end.
5547 */
5548 mtx_lock(&lun->lun_lock);
5593 if ((ctl_softc->flags & CTL_FLAG_REAL_SYNC)
5549 if ((softc->flags & CTL_FLAG_REAL_SYNC)
5594 && (++(lun->sync_count) >= lun->sync_interval)) {
5595 lun->sync_count = 0;
5596 mtx_unlock(&lun->lun_lock);
5597 retval = lun->backend->config_write((union ctl_io *)ctsio);
5598 } else {
5599 mtx_unlock(&lun->lun_lock);
5600 ctl_set_success(ctsio);
5601 ctl_done((union ctl_io *)ctsio);

--- 4 unchanged lines hidden (view full) ---

5606 return (retval);
5607}
5608
5609int
5610ctl_format(struct ctl_scsiio *ctsio)
5611{
5612 struct scsi_format *cdb;
5613 struct ctl_lun *lun;
5550 && (++(lun->sync_count) >= lun->sync_interval)) {
5551 lun->sync_count = 0;
5552 mtx_unlock(&lun->lun_lock);
5553 retval = lun->backend->config_write((union ctl_io *)ctsio);
5554 } else {
5555 mtx_unlock(&lun->lun_lock);
5556 ctl_set_success(ctsio);
5557 ctl_done((union ctl_io *)ctsio);

--- 4 unchanged lines hidden (view full) ---

5562 return (retval);
5563}
5564
5565int
5566ctl_format(struct ctl_scsiio *ctsio)
5567{
5568 struct scsi_format *cdb;
5569 struct ctl_lun *lun;
5614 struct ctl_softc *ctl_softc;
5615 int length, defect_list_len;
5616
5617 CTL_DEBUG_PRINT(("ctl_format\n"));
5618
5619 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5570 int length, defect_list_len;
5571
5572 CTL_DEBUG_PRINT(("ctl_format\n"));
5573
5574 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
5620 ctl_softc = control_softc;
5621
5622 cdb = (struct scsi_format *)ctsio->cdb;
5623
5624 length = 0;
5625 if (cdb->byte2 & SF_FMTDATA) {
5626 if (cdb->byte2 & SF_LONGLIST)
5627 length = sizeof(struct scsi_format_header_long);
5628 else

--- 441 unchanged lines hidden (view full) ---

6070 * descriptor sense on and off for a given LUN.
6071 */
6072int
6073ctl_control_page_handler(struct ctl_scsiio *ctsio,
6074 struct ctl_page_index *page_index, uint8_t *page_ptr)
6075{
6076 struct scsi_control_page *current_cp, *saved_cp, *user_cp;
6077 struct ctl_lun *lun;
5575
5576 cdb = (struct scsi_format *)ctsio->cdb;
5577
5578 length = 0;
5579 if (cdb->byte2 & SF_FMTDATA) {
5580 if (cdb->byte2 & SF_LONGLIST)
5581 length = sizeof(struct scsi_format_header_long);
5582 else

--- 441 unchanged lines hidden (view full) ---

6024 * descriptor sense on and off for a given LUN.
6025 */
6026int
6027ctl_control_page_handler(struct ctl_scsiio *ctsio,
6028 struct ctl_page_index *page_index, uint8_t *page_ptr)
6029{
6030 struct scsi_control_page *current_cp, *saved_cp, *user_cp;
6031 struct ctl_lun *lun;
6078 struct ctl_softc *softc;
6079 int set_ua;
6080 uint32_t initidx;
6081
6082 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
6083 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
6084 set_ua = 0;
6085
6086 user_cp = (struct scsi_control_page *)page_ptr;
6087 current_cp = (struct scsi_control_page *)
6088 (page_index->page_data + (page_index->page_len *
6089 CTL_PAGE_CURRENT));
6090 saved_cp = (struct scsi_control_page *)
6091 (page_index->page_data + (page_index->page_len *
6092 CTL_PAGE_SAVED));
6093
6032 int set_ua;
6033 uint32_t initidx;
6034
6035 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
6036 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
6037 set_ua = 0;
6038
6039 user_cp = (struct scsi_control_page *)page_ptr;
6040 current_cp = (struct scsi_control_page *)
6041 (page_index->page_data + (page_index->page_len *
6042 CTL_PAGE_CURRENT));
6043 saved_cp = (struct scsi_control_page *)
6044 (page_index->page_data + (page_index->page_len *
6045 CTL_PAGE_SAVED));
6046
6094 softc = control_softc;
6095
6096 mtx_lock(&lun->lun_lock);
6097 if (((current_cp->rlec & SCP_DSENSE) == 0)
6098 && ((user_cp->rlec & SCP_DSENSE) != 0)) {
6099 /*
6100 * Descriptor sense is currently turned off and the user
6101 * wants to turn it on.
6102 */
6103 current_cp->rlec |= SCP_DSENSE;

--- 1249 unchanged lines hidden (view full) ---

7353 struct ctl_port *port;
7354 struct scsi_target_group_data *rtg_ptr;
7355 struct scsi_target_group_data_extended *rtg_ext_ptr;
7356 struct scsi_target_port_group_descriptor *tpg_desc;
7357
7358 CTL_DEBUG_PRINT(("ctl_report_tagret_port_groups\n"));
7359
7360 cdb = (struct scsi_maintenance_in *)ctsio->cdb;
6047 mtx_lock(&lun->lun_lock);
6048 if (((current_cp->rlec & SCP_DSENSE) == 0)
6049 && ((user_cp->rlec & SCP_DSENSE) != 0)) {
6050 /*
6051 * Descriptor sense is currently turned off and the user
6052 * wants to turn it on.
6053 */
6054 current_cp->rlec |= SCP_DSENSE;

--- 1249 unchanged lines hidden (view full) ---

7304 struct ctl_port *port;
7305 struct scsi_target_group_data *rtg_ptr;
7306 struct scsi_target_group_data_extended *rtg_ext_ptr;
7307 struct scsi_target_port_group_descriptor *tpg_desc;
7308
7309 CTL_DEBUG_PRINT(("ctl_report_tagret_port_groups\n"));
7310
7311 cdb = (struct scsi_maintenance_in *)ctsio->cdb;
7361 softc = control_softc;
7362 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
7312 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
7313 softc = lun->ctl_softc;
7363
7364 retval = CTL_RETVAL_COMPLETE;
7365
7366 switch (cdb->byte2 & STG_PDF_MASK) {
7367 case STG_PDF_LENGTH:
7368 ext = 0;
7369 break;
7370 case STG_PDF_EXTENDED:

--- 14 unchanged lines hidden (view full) ---

7385 num_target_port_groups = 1;
7386 else
7387 num_target_port_groups = NUM_TARGET_PORT_GROUPS;
7388 num_target_ports = 0;
7389 mtx_lock(&softc->ctl_lock);
7390 STAILQ_FOREACH(port, &softc->port_list, links) {
7391 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
7392 continue;
7314
7315 retval = CTL_RETVAL_COMPLETE;
7316
7317 switch (cdb->byte2 & STG_PDF_MASK) {
7318 case STG_PDF_LENGTH:
7319 ext = 0;
7320 break;
7321 case STG_PDF_EXTENDED:

--- 14 unchanged lines hidden (view full) ---

7336 num_target_port_groups = 1;
7337 else
7338 num_target_port_groups = NUM_TARGET_PORT_GROUPS;
7339 num_target_ports = 0;
7340 mtx_lock(&softc->ctl_lock);
7341 STAILQ_FOREACH(port, &softc->port_list, links) {
7342 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
7343 continue;
7393 if (ctl_map_lun_back(port->targ_port, lun->lun) >= CTL_MAX_LUNS)
7344 if (ctl_map_lun_back(softc, port->targ_port, lun->lun) >=
7345 CTL_MAX_LUNS)
7394 continue;
7395 num_target_ports++;
7396 }
7397 mtx_unlock(&softc->ctl_lock);
7398
7399 if (ext)
7400 total_len = sizeof(struct scsi_target_group_data_extended);
7401 else

--- 56 unchanged lines hidden (view full) ---

7458 tpg_desc->pref_state = (g == pg) ? gs : os;
7459 tpg_desc->support = TPG_AO_SUP | TPG_AN_SUP | TPG_S_SUP;
7460 scsi_ulto2b(g + 1, tpg_desc->target_port_group);
7461 tpg_desc->status = TPG_IMPLICIT;
7462 pc = 0;
7463 STAILQ_FOREACH(port, &softc->port_list, links) {
7464 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
7465 continue;
7346 continue;
7347 num_target_ports++;
7348 }
7349 mtx_unlock(&softc->ctl_lock);
7350
7351 if (ext)
7352 total_len = sizeof(struct scsi_target_group_data_extended);
7353 else

--- 56 unchanged lines hidden (view full) ---

7410 tpg_desc->pref_state = (g == pg) ? gs : os;
7411 tpg_desc->support = TPG_AO_SUP | TPG_AN_SUP | TPG_S_SUP;
7412 scsi_ulto2b(g + 1, tpg_desc->target_port_group);
7413 tpg_desc->status = TPG_IMPLICIT;
7414 pc = 0;
7415 STAILQ_FOREACH(port, &softc->port_list, links) {
7416 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
7417 continue;
7466 if (ctl_map_lun_back(port->targ_port, lun->lun) >=
7467 CTL_MAX_LUNS)
7418 if (ctl_map_lun_back(softc, port->targ_port, lun->lun)
7419 >= CTL_MAX_LUNS)
7468 continue;
7469 p = port->targ_port % CTL_MAX_PORTS + g * CTL_MAX_PORTS;
7470 scsi_ulto2b(p, tpg_desc->descriptors[pc].
7471 relative_target_port_identifier);
7472 pc++;
7473 }
7474 tpg_desc->target_port_count = pc;
7475 tpg_desc = (struct scsi_target_port_group_descriptor *)

--- 275 unchanged lines hidden (view full) ---

7751 int alloc_len, total_len = 0;
7752 /* struct scsi_per_res_in_rsrv in_data; */
7753 struct ctl_lun *lun;
7754 struct ctl_softc *softc;
7755 uint64_t key;
7756
7757 CTL_DEBUG_PRINT(("ctl_persistent_reserve_in\n"));
7758
7420 continue;
7421 p = port->targ_port % CTL_MAX_PORTS + g * CTL_MAX_PORTS;
7422 scsi_ulto2b(p, tpg_desc->descriptors[pc].
7423 relative_target_port_identifier);
7424 pc++;
7425 }
7426 tpg_desc->target_port_count = pc;
7427 tpg_desc = (struct scsi_target_port_group_descriptor *)

--- 275 unchanged lines hidden (view full) ---

7703 int alloc_len, total_len = 0;
7704 /* struct scsi_per_res_in_rsrv in_data; */
7705 struct ctl_lun *lun;
7706 struct ctl_softc *softc;
7707 uint64_t key;
7708
7709 CTL_DEBUG_PRINT(("ctl_persistent_reserve_in\n"));
7710
7759 softc = control_softc;
7760
7761 cdb = (struct scsi_per_res_in *)ctsio->cdb;
7762
7763 alloc_len = scsi_2btoul(cdb->length);
7764
7765 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
7711 cdb = (struct scsi_per_res_in *)ctsio->cdb;
7712
7713 alloc_len = scsi_2btoul(cdb->length);
7714
7715 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
7716 softc = lun->ctl_softc;
7766
7767retry:
7768 mtx_lock(&lun->lun_lock);
7769 switch (cdb->action) {
7770 case SPRI_RK: /* read keys */
7771 total_len = sizeof(struct scsi_per_res_in_keys) +
7772 lun->pr_key_count *
7773 sizeof(struct scsi_per_res_key);

--- 606 unchanged lines hidden (view full) ---

8380 uint8_t type;
8381 union ctl_ha_msg persis_io;
8382 int i;
8383
8384 CTL_DEBUG_PRINT(("ctl_persistent_reserve_out\n"));
8385
8386 retval = CTL_RETVAL_COMPLETE;
8387
7717
7718retry:
7719 mtx_lock(&lun->lun_lock);
7720 switch (cdb->action) {
7721 case SPRI_RK: /* read keys */
7722 total_len = sizeof(struct scsi_per_res_in_keys) +
7723 lun->pr_key_count *
7724 sizeof(struct scsi_per_res_key);

--- 606 unchanged lines hidden (view full) ---

8331 uint8_t type;
8332 union ctl_ha_msg persis_io;
8333 int i;
8334
8335 CTL_DEBUG_PRINT(("ctl_persistent_reserve_out\n"));
8336
8337 retval = CTL_RETVAL_COMPLETE;
8338
8388 softc = control_softc;
8389
8390 cdb = (struct scsi_per_res_out *)ctsio->cdb;
8391 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
8339 cdb = (struct scsi_per_res_out *)ctsio->cdb;
8340 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
8341 softc = lun->ctl_softc;
8392
8393 /*
8394 * We only support whole-LUN scope. The scope & type are ignored for
8395 * register, register and ignore existing key and clear.
8396 * We sometimes ignore scope and type on preempts too!!
8397 * Verify reservation type here as well.
8398 */
8399 type = cdb->scope_type & SPR_TYPE_MASK;

--- 899 unchanged lines hidden (view full) ---

9299 CTL_DEBUG_PRINT(("ctl_verify: calling data_submit()\n"));
9300 retval = lun->backend->data_submit((union ctl_io *)ctsio);
9301 return (retval);
9302}
9303
9304int
9305ctl_report_luns(struct ctl_scsiio *ctsio)
9306{
8342
8343 /*
8344 * We only support whole-LUN scope. The scope & type are ignored for
8345 * register, register and ignore existing key and clear.
8346 * We sometimes ignore scope and type on preempts too!!
8347 * Verify reservation type here as well.
8348 */
8349 type = cdb->scope_type & SPR_TYPE_MASK;

--- 899 unchanged lines hidden (view full) ---

9249 CTL_DEBUG_PRINT(("ctl_verify: calling data_submit()\n"));
9250 retval = lun->backend->data_submit((union ctl_io *)ctsio);
9251 return (retval);
9252}
9253
9254int
9255ctl_report_luns(struct ctl_scsiio *ctsio)
9256{
9257 struct ctl_softc *softc = control_softc;
9307 struct scsi_report_luns *cdb;
9308 struct scsi_report_luns_data *lun_data;
9309 struct ctl_lun *lun, *request_lun;
9310 int num_luns, retval;
9311 uint32_t alloc_len, lun_datalen;
9312 int num_filled, well_known;
9313 uint32_t initidx, targ_lun_id, lun_id;
9314
9315 retval = CTL_RETVAL_COMPLETE;
9316 well_known = 0;
9317
9318 cdb = (struct scsi_report_luns *)ctsio->cdb;
9319
9320 CTL_DEBUG_PRINT(("ctl_report_luns\n"));
9321
9258 struct scsi_report_luns *cdb;
9259 struct scsi_report_luns_data *lun_data;
9260 struct ctl_lun *lun, *request_lun;
9261 int num_luns, retval;
9262 uint32_t alloc_len, lun_datalen;
9263 int num_filled, well_known;
9264 uint32_t initidx, targ_lun_id, lun_id;
9265
9266 retval = CTL_RETVAL_COMPLETE;
9267 well_known = 0;
9268
9269 cdb = (struct scsi_report_luns *)ctsio->cdb;
9270
9271 CTL_DEBUG_PRINT(("ctl_report_luns\n"));
9272
9322 mtx_lock(&control_softc->ctl_lock);
9323 num_luns = control_softc->num_luns;
9324 mtx_unlock(&control_softc->ctl_lock);
9273 mtx_lock(&softc->ctl_lock);
9274 num_luns = softc->num_luns;
9275 mtx_unlock(&softc->ctl_lock);
9325
9326 switch (cdb->select_report) {
9327 case RPL_REPORT_DEFAULT:
9328 case RPL_REPORT_ALL:
9329 break;
9330 case RPL_REPORT_WELLKNOWN:
9331 well_known = 1;
9332 num_luns = 0;

--- 35 unchanged lines hidden (view full) ---

9368 (num_luns * sizeof(struct scsi_report_luns_lundata));
9369
9370 ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK | M_ZERO);
9371 lun_data = (struct scsi_report_luns_data *)ctsio->kern_data_ptr;
9372 ctsio->kern_sg_entries = 0;
9373
9374 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
9375
9276
9277 switch (cdb->select_report) {
9278 case RPL_REPORT_DEFAULT:
9279 case RPL_REPORT_ALL:
9280 break;
9281 case RPL_REPORT_WELLKNOWN:
9282 well_known = 1;
9283 num_luns = 0;

--- 35 unchanged lines hidden (view full) ---

9319 (num_luns * sizeof(struct scsi_report_luns_lundata));
9320
9321 ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK | M_ZERO);
9322 lun_data = (struct scsi_report_luns_data *)ctsio->kern_data_ptr;
9323 ctsio->kern_sg_entries = 0;
9324
9325 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
9326
9376 mtx_lock(&control_softc->ctl_lock);
9327 mtx_lock(&softc->ctl_lock);
9377 for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) {
9328 for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) {
9378 lun_id = ctl_map_lun(ctsio->io_hdr.nexus.targ_port, targ_lun_id);
9329 lun_id = ctl_map_lun(softc, ctsio->io_hdr.nexus.targ_port,
9330 targ_lun_id);
9379 if (lun_id >= CTL_MAX_LUNS)
9380 continue;
9331 if (lun_id >= CTL_MAX_LUNS)
9332 continue;
9381 lun = control_softc->ctl_luns[lun_id];
9333 lun = softc->ctl_luns[lun_id];
9382 if (lun == NULL)
9383 continue;
9384
9385 if (targ_lun_id <= 0xff) {
9386 /*
9387 * Peripheral addressing method, bus number 0.
9388 */
9389 lun_data->luns[num_filled].lundata[0] =

--- 39 unchanged lines hidden (view full) ---

9429 * attention.
9430 */
9431 if (request_lun != NULL) {
9432 mtx_lock(&lun->lun_lock);
9433 ctl_clr_ua(lun, initidx, CTL_UA_RES_RELEASE);
9434 mtx_unlock(&lun->lun_lock);
9435 }
9436 }
9334 if (lun == NULL)
9335 continue;
9336
9337 if (targ_lun_id <= 0xff) {
9338 /*
9339 * Peripheral addressing method, bus number 0.
9340 */
9341 lun_data->luns[num_filled].lundata[0] =

--- 39 unchanged lines hidden (view full) ---

9381 * attention.
9382 */
9383 if (request_lun != NULL) {
9384 mtx_lock(&lun->lun_lock);
9385 ctl_clr_ua(lun, initidx, CTL_UA_RES_RELEASE);
9386 mtx_unlock(&lun->lun_lock);
9387 }
9388 }
9437 mtx_unlock(&control_softc->ctl_lock);
9389 mtx_unlock(&softc->ctl_lock);
9438
9439 /*
9440 * It's quite possible that we've returned fewer LUNs than we allocated
9441 * space for. Trim it.
9442 */
9443 lun_datalen = sizeof(*lun_data) +
9444 (num_filled * sizeof(struct scsi_report_luns_lundata));
9445

--- 418 unchanged lines hidden (view full) ---

9864 return (CTL_RETVAL_COMPLETE);
9865}
9866
9867static int
9868ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len)
9869{
9870 struct scsi_vpd_device_id *devid_ptr;
9871 struct scsi_vpd_id_descriptor *desc;
9390
9391 /*
9392 * It's quite possible that we've returned fewer LUNs than we allocated
9393 * space for. Trim it.
9394 */
9395 lun_datalen = sizeof(*lun_data) +
9396 (num_filled * sizeof(struct scsi_report_luns_lundata));
9397

--- 418 unchanged lines hidden (view full) ---

9816 return (CTL_RETVAL_COMPLETE);
9817}
9818
9819static int
9820ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len)
9821{
9822 struct scsi_vpd_device_id *devid_ptr;
9823 struct scsi_vpd_id_descriptor *desc;
9872 struct ctl_softc *ctl_softc;
9824 struct ctl_softc *softc;
9873 struct ctl_lun *lun;
9874 struct ctl_port *port;
9875 int data_len;
9876 uint8_t proto;
9877
9825 struct ctl_lun *lun;
9826 struct ctl_port *port;
9827 int data_len;
9828 uint8_t proto;
9829
9878 ctl_softc = control_softc;
9830 softc = control_softc;
9879
9831
9880 port = ctl_softc->ctl_ports[ctl_port_idx(ctsio->io_hdr.nexus.targ_port)];
9832 port = softc->ctl_ports[ctl_port_idx(ctsio->io_hdr.nexus.targ_port)];
9881 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
9882
9883 data_len = sizeof(struct scsi_vpd_device_id) +
9884 sizeof(struct scsi_vpd_id_descriptor) +
9885 sizeof(struct scsi_vpd_id_rel_trgt_port_id) +
9886 sizeof(struct scsi_vpd_id_descriptor) +
9887 sizeof(struct scsi_vpd_id_trgt_port_grp_id);
9888 if (lun && lun->lun_devid)

--- 117 unchanged lines hidden (view full) ---

10006 num_target_ports = 0;
10007 iid_len = 0;
10008 id_len = 0;
10009 mtx_lock(&softc->ctl_lock);
10010 STAILQ_FOREACH(port, &softc->port_list, links) {
10011 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
10012 continue;
10013 if (lun != NULL &&
9833 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
9834
9835 data_len = sizeof(struct scsi_vpd_device_id) +
9836 sizeof(struct scsi_vpd_id_descriptor) +
9837 sizeof(struct scsi_vpd_id_rel_trgt_port_id) +
9838 sizeof(struct scsi_vpd_id_descriptor) +
9839 sizeof(struct scsi_vpd_id_trgt_port_grp_id);
9840 if (lun && lun->lun_devid)

--- 117 unchanged lines hidden (view full) ---

9958 num_target_ports = 0;
9959 iid_len = 0;
9960 id_len = 0;
9961 mtx_lock(&softc->ctl_lock);
9962 STAILQ_FOREACH(port, &softc->port_list, links) {
9963 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
9964 continue;
9965 if (lun != NULL &&
10014 ctl_map_lun_back(port->targ_port, lun->lun) >=
9966 ctl_map_lun_back(softc, port->targ_port, lun->lun) >=
10015 CTL_MAX_LUNS)
10016 continue;
10017 num_target_ports++;
10018 if (port->init_devid)
10019 iid_len += port->init_devid->len;
10020 if (port->port_devid)
10021 id_len += port->port_devid->len;
10022 }

--- 37 unchanged lines hidden (view full) ---

10060
10061 mtx_lock(&softc->ctl_lock);
10062 pg = softc->port_offset / CTL_MAX_PORTS;
10063 for (g = 0; g < num_target_port_groups; g++) {
10064 STAILQ_FOREACH(port, &softc->port_list, links) {
10065 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
10066 continue;
10067 if (lun != NULL &&
9967 CTL_MAX_LUNS)
9968 continue;
9969 num_target_ports++;
9970 if (port->init_devid)
9971 iid_len += port->init_devid->len;
9972 if (port->port_devid)
9973 id_len += port->port_devid->len;
9974 }

--- 37 unchanged lines hidden (view full) ---

10012
10013 mtx_lock(&softc->ctl_lock);
10014 pg = softc->port_offset / CTL_MAX_PORTS;
10015 for (g = 0; g < num_target_port_groups; g++) {
10016 STAILQ_FOREACH(port, &softc->port_list, links) {
10017 if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
10018 continue;
10019 if (lun != NULL &&
10068 ctl_map_lun_back(port->targ_port, lun->lun) >=
10069 CTL_MAX_LUNS)
10020 ctl_map_lun_back(softc, port->targ_port, lun->lun)
10021 >= CTL_MAX_LUNS)
10070 continue;
10071 p = port->targ_port % CTL_MAX_PORTS + g * CTL_MAX_PORTS;
10072 scsi_ulto2b(p, pd->relative_port_id);
10073 if (port->init_devid && g == pg) {
10074 iid_len = port->init_devid->len;
10075 memcpy(pd->initiator_transportid,
10076 port->init_devid->data, port->init_devid->len);
10077 } else

--- 259 unchanged lines hidden (view full) ---

10337 return (retval);
10338}
10339
10340static int
10341ctl_inquiry_std(struct ctl_scsiio *ctsio)
10342{
10343 struct scsi_inquiry_data *inq_ptr;
10344 struct scsi_inquiry *cdb;
10022 continue;
10023 p = port->targ_port % CTL_MAX_PORTS + g * CTL_MAX_PORTS;
10024 scsi_ulto2b(p, pd->relative_port_id);
10025 if (port->init_devid && g == pg) {
10026 iid_len = port->init_devid->len;
10027 memcpy(pd->initiator_transportid,
10028 port->init_devid->data, port->init_devid->len);
10029 } else

--- 259 unchanged lines hidden (view full) ---

10289 return (retval);
10290}
10291
10292static int
10293ctl_inquiry_std(struct ctl_scsiio *ctsio)
10294{
10295 struct scsi_inquiry_data *inq_ptr;
10296 struct scsi_inquiry *cdb;
10345 struct ctl_softc *ctl_softc;
10297 struct ctl_softc *softc;
10346 struct ctl_lun *lun;
10347 char *val;
10348 uint32_t alloc_len, data_len;
10349 ctl_port_type port_type;
10350
10298 struct ctl_lun *lun;
10299 char *val;
10300 uint32_t alloc_len, data_len;
10301 ctl_port_type port_type;
10302
10351 ctl_softc = control_softc;
10303 softc = control_softc;
10352
10353 /*
10354 * Figure out whether we're talking to a Fibre Channel port or not.
10355 * We treat the ioctl front end, and any SCSI adapters, as packetized
10356 * SCSI front ends.
10357 */
10304
10305 /*
10306 * Figure out whether we're talking to a Fibre Channel port or not.
10307 * We treat the ioctl front end, and any SCSI adapters, as packetized
10308 * SCSI front ends.
10309 */
10358 port_type = ctl_softc->ctl_ports[
10310 port_type = softc->ctl_ports[
10359 ctl_port_idx(ctsio->io_hdr.nexus.targ_port)]->port_type;
10360 if (port_type == CTL_PORT_IOCTL || port_type == CTL_PORT_INTERNAL)
10361 port_type = CTL_PORT_SCSI;
10362
10363 lun = ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
10364 cdb = (struct scsi_inquiry *)ctsio->cdb;
10365 alloc_len = scsi_2btoul(cdb->length);
10366

--- 60 unchanged lines hidden (view full) ---

10427 *
10428 * So the solution is provide a hopefully reasonable default
10429 * (return bad/no LUN) and allow the user to change the behavior
10430 * with a tunable/sysctl variable.
10431 */
10432 if (lun != NULL)
10433 inq_ptr->device = (SID_QUAL_LU_CONNECTED << 5) |
10434 lun->be_lun->lun_type;
10311 ctl_port_idx(ctsio->io_hdr.nexus.targ_port)]->port_type;
10312 if (port_type == CTL_PORT_IOCTL || port_type == CTL_PORT_INTERNAL)
10313 port_type = CTL_PORT_SCSI;
10314
10315 lun = ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
10316 cdb = (struct scsi_inquiry *)ctsio->cdb;
10317 alloc_len = scsi_2btoul(cdb->length);
10318

--- 60 unchanged lines hidden (view full) ---

10379 *
10380 * So the solution is provide a hopefully reasonable default
10381 * (return bad/no LUN) and allow the user to change the behavior
10382 * with a tunable/sysctl variable.
10383 */
10384 if (lun != NULL)
10385 inq_ptr->device = (SID_QUAL_LU_CONNECTED << 5) |
10386 lun->be_lun->lun_type;
10435 else if (ctl_softc->inquiry_pq_no_lun == 0)
10387 else if (softc->inquiry_pq_no_lun == 0)
10436 inq_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT;
10437 else
10438 inq_ptr->device = (SID_QUAL_BAD_LU << 5) | T_NODEVICE;
10439
10440 /* RMB in byte 2 is 0 */
10441 inq_ptr->version = SCSI_REV_SPC4;
10442
10443 /*

--- 616 unchanged lines hidden (view full) ---

11060 case CTL_ACTION_OVERLAP_TAG:
11061 /*
11062 * This shouldn't happen! In theory we've already
11063 * checked this command for overlap...
11064 */
11065 break;
11066 case CTL_ACTION_PASS:
11067 case CTL_ACTION_SKIP: {
10388 inq_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT;
10389 else
10390 inq_ptr->device = (SID_QUAL_BAD_LU << 5) | T_NODEVICE;
10391
10392 /* RMB in byte 2 is 0 */
10393 inq_ptr->version = SCSI_REV_SPC4;
10394
10395 /*

--- 616 unchanged lines hidden (view full) ---

11012 case CTL_ACTION_OVERLAP_TAG:
11013 /*
11014 * This shouldn't happen! In theory we've already
11015 * checked this command for overlap...
11016 */
11017 break;
11018 case CTL_ACTION_PASS:
11019 case CTL_ACTION_SKIP: {
11068 struct ctl_softc *softc;
11069 const struct ctl_cmd_entry *entry;
11070 int isc_retval;
11071
11072 /*
11073 * The skip case shouldn't happen, this transaction
11074 * should have never made it onto the blocked queue.
11075 */
11076 /*

--- 22 unchanged lines hidden (view full) ---

11099 CTL_HA_STATUS_SUCCESS) {
11100 printf("CTL:Check Blocked error from "
11101 "ctl_ha_msg_send %d\n",
11102 isc_retval);
11103 }
11104 break;
11105 }
11106 entry = ctl_get_cmd_entry(&cur_blocked->scsiio, NULL);
11020 const struct ctl_cmd_entry *entry;
11021 int isc_retval;
11022
11023 /*
11024 * The skip case shouldn't happen, this transaction
11025 * should have never made it onto the blocked queue.
11026 */
11027 /*

--- 22 unchanged lines hidden (view full) ---

11050 CTL_HA_STATUS_SUCCESS) {
11051 printf("CTL:Check Blocked error from "
11052 "ctl_ha_msg_send %d\n",
11053 isc_retval);
11054 }
11055 break;
11056 }
11057 entry = ctl_get_cmd_entry(&cur_blocked->scsiio, NULL);
11107 softc = control_softc;
11108
11109 /*
11110 * Check this I/O for LUN state changes that may
11111 * have happened while this command was blocked.
11112 * The LUN state may have been changed by a command
11113 * ahead of us in the queue, so we need to re-check
11114 * for any states that can be caused by SCSI
11115 * commands.
11116 */
11058
11059 /*
11060 * Check this I/O for LUN state changes that may
11061 * have happened while this command was blocked.
11062 * The LUN state may have been changed by a command
11063 * ahead of us in the queue, so we need to re-check
11064 * for any states that can be caused by SCSI
11065 * commands.
11066 */
11117 if (ctl_scsiio_lun_check(softc, lun, entry,
11067 if (ctl_scsiio_lun_check(lun, entry,
11118 &cur_blocked->scsiio) == 0) {
11119 cur_blocked->io_hdr.flags |=
11120 CTL_FLAG_IS_WAS_ON_RTR;
11121 ctl_enqueue_rtr(cur_blocked);
11122 } else
11123 ctl_done(cur_blocked);
11124 break;
11125 }

--- 17 unchanged lines hidden (view full) ---

11143 * check these flags for commands on the blocked queue is that the LUN
11144 * state may have been changed by a command ahead of us while we're on the
11145 * blocked queue.
11146 *
11147 * Ordering is somewhat important with these checks, so please pay
11148 * careful attention to the placement of any new checks.
11149 */
11150static int
11068 &cur_blocked->scsiio) == 0) {
11069 cur_blocked->io_hdr.flags |=
11070 CTL_FLAG_IS_WAS_ON_RTR;
11071 ctl_enqueue_rtr(cur_blocked);
11072 } else
11073 ctl_done(cur_blocked);
11074 break;
11075 }

--- 17 unchanged lines hidden (view full) ---

11093 * check these flags for commands on the blocked queue is that the LUN
11094 * state may have been changed by a command ahead of us while we're on the
11095 * blocked queue.
11096 *
11097 * Ordering is somewhat important with these checks, so please pay
11098 * careful attention to the placement of any new checks.
11099 */
11100static int
11151ctl_scsiio_lun_check(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
11101ctl_scsiio_lun_check(struct ctl_lun *lun,
11152 const struct ctl_cmd_entry *entry, struct ctl_scsiio *ctsio)
11153{
11102 const struct ctl_cmd_entry *entry, struct ctl_scsiio *ctsio)
11103{
11104 struct ctl_softc *softc = lun->ctl_softc;
11154 int retval;
11155 uint32_t residx;
11156
11157 retval = 0;
11158
11159 mtx_assert(&lun->lun_lock, MA_OWNED);
11160
11161 /*
11162 * If this shelf is a secondary shelf controller, we have to reject
11163 * any media access commands.
11164 */
11105 int retval;
11106 uint32_t residx;
11107
11108 retval = 0;
11109
11110 mtx_assert(&lun->lun_lock, MA_OWNED);
11111
11112 /*
11113 * If this shelf is a secondary shelf controller, we have to reject
11114 * any media access commands.
11115 */
11165 if ((ctl_softc->flags & CTL_FLAG_ACTIVE_SHELF) == 0 &&
11116 if ((softc->flags & CTL_FLAG_ACTIVE_SHELF) == 0 &&
11166 (entry->flags & CTL_CMD_FLAG_OK_ON_SECONDARY) == 0) {
11167 ctl_set_lun_standby(ctsio);
11168 retval = 1;
11169 goto bailout;
11170 }
11171
11172 if (entry->pattern & CTL_LUN_PAT_WRITE) {
11173 if (lun->flags & CTL_LUN_READONLY) {

--- 89 unchanged lines hidden (view full) ---

11263 ctl_set_busy(&io->scsiio);
11264 ctl_done(io);
11265}
11266
11267static void
11268ctl_failover(void)
11269{
11270 struct ctl_lun *lun;
11117 (entry->flags & CTL_CMD_FLAG_OK_ON_SECONDARY) == 0) {
11118 ctl_set_lun_standby(ctsio);
11119 retval = 1;
11120 goto bailout;
11121 }
11122
11123 if (entry->pattern & CTL_LUN_PAT_WRITE) {
11124 if (lun->flags & CTL_LUN_READONLY) {

--- 89 unchanged lines hidden (view full) ---

11214 ctl_set_busy(&io->scsiio);
11215 ctl_done(io);
11216}
11217
11218static void
11219ctl_failover(void)
11220{
11221 struct ctl_lun *lun;
11271 struct ctl_softc *ctl_softc;
11222 struct ctl_softc *softc;
11272 union ctl_io *next_io, *pending_io;
11273 union ctl_io *io;
11274 int lun_idx;
11275
11223 union ctl_io *next_io, *pending_io;
11224 union ctl_io *io;
11225 int lun_idx;
11226
11276 ctl_softc = control_softc;
11227 softc = control_softc;
11277
11228
11278 mtx_lock(&ctl_softc->ctl_lock);
11229 mtx_lock(&softc->ctl_lock);
11279 /*
11280 * Remove any cmds from the other SC from the rtr queue. These
11281 * will obviously only be for LUNs for which we're the primary.
11282 * We can't send status or get/send data for these commands.
11283 * Since they haven't been executed yet, we can just remove them.
11284 * We'll either abort them or delete them below, depending on
11285 * which HA mode we're in.
11286 */
11287#ifdef notyet
11230 /*
11231 * Remove any cmds from the other SC from the rtr queue. These
11232 * will obviously only be for LUNs for which we're the primary.
11233 * We can't send status or get/send data for these commands.
11234 * Since they haven't been executed yet, we can just remove them.
11235 * We'll either abort them or delete them below, depending on
11236 * which HA mode we're in.
11237 */
11238#ifdef notyet
11288 mtx_lock(&ctl_softc->queue_lock);
11289 for (io = (union ctl_io *)STAILQ_FIRST(&ctl_softc->rtr_queue);
11239 mtx_lock(&softc->queue_lock);
11240 for (io = (union ctl_io *)STAILQ_FIRST(&softc->rtr_queue);
11290 io != NULL; io = next_io) {
11291 next_io = (union ctl_io *)STAILQ_NEXT(&io->io_hdr, links);
11292 if (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)
11241 io != NULL; io = next_io) {
11242 next_io = (union ctl_io *)STAILQ_NEXT(&io->io_hdr, links);
11243 if (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)
11293 STAILQ_REMOVE(&ctl_softc->rtr_queue, &io->io_hdr,
11244 STAILQ_REMOVE(&softc->rtr_queue, &io->io_hdr,
11294 ctl_io_hdr, links);
11295 }
11245 ctl_io_hdr, links);
11246 }
11296 mtx_unlock(&ctl_softc->queue_lock);
11247 mtx_unlock(&softc->queue_lock);
11297#endif
11298
11248#endif
11249
11299 for (lun_idx=0; lun_idx < ctl_softc->num_luns; lun_idx++) {
11300 lun = ctl_softc->ctl_luns[lun_idx];
11250 for (lun_idx=0; lun_idx < softc->num_luns; lun_idx++) {
11251 lun = softc->ctl_luns[lun_idx];
11301 if (lun==NULL)
11302 continue;
11303
11304 /*
11305 * Processor LUNs are primary on both sides.
11306 * XXX will this always be true?
11307 */
11308 if (lun->be_lun->lun_type == T_PROCESSOR)
11309 continue;
11310
11311 if ((lun->flags & CTL_LUN_PRIMARY_SC)
11252 if (lun==NULL)
11253 continue;
11254
11255 /*
11256 * Processor LUNs are primary on both sides.
11257 * XXX will this always be true?
11258 */
11259 if (lun->be_lun->lun_type == T_PROCESSOR)
11260 continue;
11261
11262 if ((lun->flags & CTL_LUN_PRIMARY_SC)
11312 && (ctl_softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
11263 && (softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
11313 printf("FAILOVER: primary lun %d\n", lun_idx);
11314 /*
11315 * Remove all commands from the other SC. First from the
11316 * blocked queue then from the ooa queue. Once we have
11317 * removed them. Call ctl_check_blocked to see if there
11318 * is anything that can run.
11319 */
11320 for (io = (union ctl_io *)TAILQ_FIRST(

--- 25 unchanged lines hidden (view full) ---

11346 &io->io_hdr,
11347 ooa_links);
11348
11349 ctl_free_io(io);
11350 }
11351 }
11352 ctl_check_blocked(lun);
11353 } else if ((lun->flags & CTL_LUN_PRIMARY_SC)
11264 printf("FAILOVER: primary lun %d\n", lun_idx);
11265 /*
11266 * Remove all commands from the other SC. First from the
11267 * blocked queue then from the ooa queue. Once we have
11268 * removed them. Call ctl_check_blocked to see if there
11269 * is anything that can run.
11270 */
11271 for (io = (union ctl_io *)TAILQ_FIRST(

--- 25 unchanged lines hidden (view full) ---

11297 &io->io_hdr,
11298 ooa_links);
11299
11300 ctl_free_io(io);
11301 }
11302 }
11303 ctl_check_blocked(lun);
11304 } else if ((lun->flags & CTL_LUN_PRIMARY_SC)
11354 && (ctl_softc->ha_mode == CTL_HA_MODE_XFER)) {
11305 && (softc->ha_mode == CTL_HA_MODE_XFER)) {
11355
11356 printf("FAILOVER: primary lun %d\n", lun_idx);
11357 /*
11358 * Abort all commands from the other SC. We can't
11359 * send status back for them now. These should get
11360 * cleaned up when they are completed or come out
11361 * for a datamove operation.
11362 */
11363 for (io = (union ctl_io *)TAILQ_FIRST(&lun->ooa_queue);
11364 io != NULL; io = next_io) {
11365 next_io = (union ctl_io *)TAILQ_NEXT(
11366 &io->io_hdr, ooa_links);
11367
11368 if (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)
11369 io->io_hdr.flags |= CTL_FLAG_ABORT;
11370 }
11371 } else if (((lun->flags & CTL_LUN_PRIMARY_SC) == 0)
11306
11307 printf("FAILOVER: primary lun %d\n", lun_idx);
11308 /*
11309 * Abort all commands from the other SC. We can't
11310 * send status back for them now. These should get
11311 * cleaned up when they are completed or come out
11312 * for a datamove operation.
11313 */
11314 for (io = (union ctl_io *)TAILQ_FIRST(&lun->ooa_queue);
11315 io != NULL; io = next_io) {
11316 next_io = (union ctl_io *)TAILQ_NEXT(
11317 &io->io_hdr, ooa_links);
11318
11319 if (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)
11320 io->io_hdr.flags |= CTL_FLAG_ABORT;
11321 }
11322 } else if (((lun->flags & CTL_LUN_PRIMARY_SC) == 0)
11372 && (ctl_softc->ha_mode == CTL_HA_MODE_XFER)) {
11323 && (softc->ha_mode == CTL_HA_MODE_XFER)) {
11373
11374 printf("FAILOVER: secondary lun %d\n", lun_idx);
11375
11376 lun->flags |= CTL_LUN_PRIMARY_SC;
11377
11378 /*
11379 * We send all I/O that was sent to this controller
11380 * and redirected to the other side back with

--- 22 unchanged lines hidden (view full) ---

11403 } else {
11404 ctl_set_busy(&pending_io->scsiio);
11405 ctl_done(pending_io);
11406 }
11407 }
11408
11409 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE);
11410 } else if (((lun->flags & CTL_LUN_PRIMARY_SC) == 0)
11324
11325 printf("FAILOVER: secondary lun %d\n", lun_idx);
11326
11327 lun->flags |= CTL_LUN_PRIMARY_SC;
11328
11329 /*
11330 * We send all I/O that was sent to this controller
11331 * and redirected to the other side back with

--- 22 unchanged lines hidden (view full) ---

11354 } else {
11355 ctl_set_busy(&pending_io->scsiio);
11356 ctl_done(pending_io);
11357 }
11358 }
11359
11360 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE);
11361 } else if (((lun->flags & CTL_LUN_PRIMARY_SC) == 0)
11411 && (ctl_softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
11362 && (softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
11412 printf("FAILOVER: secondary lun %d\n", lun_idx);
11413 /*
11414 * if the first io on the OOA is not on the RtR queue
11415 * add it.
11416 */
11417 lun->flags |= CTL_LUN_PRIMARY_SC;
11418
11419 pending_io = (union ctl_io *)TAILQ_FIRST(

--- 73 unchanged lines hidden (view full) ---

11493 ctl_done(pending_io);
11494 break;
11495 }
11496 }
11497
11498 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE);
11499 } else {
11500 panic("Unhandled HA mode failover, LUN flags = %#x, "
11363 printf("FAILOVER: secondary lun %d\n", lun_idx);
11364 /*
11365 * if the first io on the OOA is not on the RtR queue
11366 * add it.
11367 */
11368 lun->flags |= CTL_LUN_PRIMARY_SC;
11369
11370 pending_io = (union ctl_io *)TAILQ_FIRST(

--- 73 unchanged lines hidden (view full) ---

11444 ctl_done(pending_io);
11445 break;
11446 }
11447 }
11448
11449 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE);
11450 } else {
11451 panic("Unhandled HA mode failover, LUN flags = %#x, "
11501 "ha_mode = #%x", lun->flags, ctl_softc->ha_mode);
11452 "ha_mode = #%x", lun->flags, softc->ha_mode);
11502 }
11503 }
11504 ctl_pause_rtr = 0;
11453 }
11454 }
11455 ctl_pause_rtr = 0;
11505 mtx_unlock(&ctl_softc->ctl_lock);
11456 mtx_unlock(&softc->ctl_lock);
11506}
11507
11508static int
11457}
11458
11459static int
11509ctl_scsiio_precheck(struct ctl_softc *ctl_softc, struct ctl_scsiio *ctsio)
11460ctl_scsiio_precheck(struct ctl_softc *softc, struct ctl_scsiio *ctsio)
11510{
11511 struct ctl_lun *lun;
11512 const struct ctl_cmd_entry *entry;
11513 uint32_t initidx, targ_lun;
11514 int retval;
11515
11516 retval = 0;
11517
11518 lun = NULL;
11519
11520 targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
11521 if ((targ_lun < CTL_MAX_LUNS)
11461{
11462 struct ctl_lun *lun;
11463 const struct ctl_cmd_entry *entry;
11464 uint32_t initidx, targ_lun;
11465 int retval;
11466
11467 retval = 0;
11468
11469 lun = NULL;
11470
11471 targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
11472 if ((targ_lun < CTL_MAX_LUNS)
11522 && ((lun = ctl_softc->ctl_luns[targ_lun]) != NULL)) {
11473 && ((lun = softc->ctl_luns[targ_lun]) != NULL)) {
11523 /*
11524 * If the LUN is invalid, pretend that it doesn't exist.
11525 * It will go away as soon as all pending I/O has been
11526 * completed.
11527 */
11528 mtx_lock(&lun->lun_lock);
11529 if (lun->flags & CTL_LUN_DISABLED) {
11530 mtx_unlock(&lun->lun_lock);

--- 115 unchanged lines hidden (view full) ---

11646 ctsio->io_hdr.status = CTL_SCSI_ERROR | CTL_AUTOSENSE;
11647 ctsio->sense_len = SSD_FULL_SIZE;
11648 ctl_done((union ctl_io *)ctsio);
11649 return (retval);
11650 }
11651 }
11652
11653
11474 /*
11475 * If the LUN is invalid, pretend that it doesn't exist.
11476 * It will go away as soon as all pending I/O has been
11477 * completed.
11478 */
11479 mtx_lock(&lun->lun_lock);
11480 if (lun->flags & CTL_LUN_DISABLED) {
11481 mtx_unlock(&lun->lun_lock);

--- 115 unchanged lines hidden (view full) ---

11597 ctsio->io_hdr.status = CTL_SCSI_ERROR | CTL_AUTOSENSE;
11598 ctsio->sense_len = SSD_FULL_SIZE;
11599 ctl_done((union ctl_io *)ctsio);
11600 return (retval);
11601 }
11602 }
11603
11604
11654 if (ctl_scsiio_lun_check(ctl_softc, lun, entry, ctsio) != 0) {
11605 if (ctl_scsiio_lun_check(lun, entry, ctsio) != 0) {
11655 mtx_unlock(&lun->lun_lock);
11656 ctl_done((union ctl_io *)ctsio);
11657 return (retval);
11658 }
11659
11660 /*
11661 * XXX CHD this is where we want to send IO to other side if
11662 * this LUN is secondary on this SC. We will need to make a copy

--- 191 unchanged lines hidden (view full) ---

11854 return (retval);
11855}
11856
11857/*
11858 * Since we only implement one target right now, a bus reset simply resets
11859 * our single target.
11860 */
11861static int
11606 mtx_unlock(&lun->lun_lock);
11607 ctl_done((union ctl_io *)ctsio);
11608 return (retval);
11609 }
11610
11611 /*
11612 * XXX CHD this is where we want to send IO to other side if
11613 * this LUN is secondary on this SC. We will need to make a copy

--- 191 unchanged lines hidden (view full) ---

11805 return (retval);
11806}
11807
11808/*
11809 * Since we only implement one target right now, a bus reset simply resets
11810 * our single target.
11811 */
11812static int
11862ctl_bus_reset(struct ctl_softc *ctl_softc, union ctl_io *io)
11813ctl_bus_reset(struct ctl_softc *softc, union ctl_io *io)
11863{
11814{
11864 return(ctl_target_reset(ctl_softc, io, CTL_UA_BUS_RESET));
11815 return(ctl_target_reset(softc, io, CTL_UA_BUS_RESET));
11865}
11866
11867static int
11816}
11817
11818static int
11868ctl_target_reset(struct ctl_softc *ctl_softc, union ctl_io *io,
11819ctl_target_reset(struct ctl_softc *softc, union ctl_io *io,
11869 ctl_ua_type ua_type)
11870{
11871 struct ctl_lun *lun;
11872 int retval;
11873
11874 if (!(io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)) {
11875 union ctl_ha_msg msg_info;
11876

--- 7 unchanged lines hidden (view full) ---

11884 msg_info.hdr.original_sc = NULL;
11885 msg_info.hdr.serializing_sc = NULL;
11886 if (CTL_HA_STATUS_SUCCESS != ctl_ha_msg_send(CTL_HA_CHAN_CTL,
11887 (void *)&msg_info, sizeof(msg_info), 0)) {
11888 }
11889 }
11890 retval = 0;
11891
11820 ctl_ua_type ua_type)
11821{
11822 struct ctl_lun *lun;
11823 int retval;
11824
11825 if (!(io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)) {
11826 union ctl_ha_msg msg_info;
11827

--- 7 unchanged lines hidden (view full) ---

11835 msg_info.hdr.original_sc = NULL;
11836 msg_info.hdr.serializing_sc = NULL;
11837 if (CTL_HA_STATUS_SUCCESS != ctl_ha_msg_send(CTL_HA_CHAN_CTL,
11838 (void *)&msg_info, sizeof(msg_info), 0)) {
11839 }
11840 }
11841 retval = 0;
11842
11892 mtx_lock(&ctl_softc->ctl_lock);
11893 STAILQ_FOREACH(lun, &ctl_softc->lun_list, links)
11843 mtx_lock(&softc->ctl_lock);
11844 STAILQ_FOREACH(lun, &softc->lun_list, links)
11894 retval += ctl_lun_reset(lun, io, ua_type);
11845 retval += ctl_lun_reset(lun, io, ua_type);
11895 mtx_unlock(&ctl_softc->ctl_lock);
11846 mtx_unlock(&softc->ctl_lock);
11896
11897 return (retval);
11898}
11899
11900/*
11901 * The LUN should always be set. The I/O is optional, and is used to
11902 * distinguish between I/Os sent by this initiator, and by other
11903 * initiators. We set unit attention for initiators other than this one.

--- 169 unchanged lines hidden (view full) ---

12073 return (0);
12074}
12075
12076static int
12077ctl_abort_task(union ctl_io *io)
12078{
12079 union ctl_io *xio;
12080 struct ctl_lun *lun;
11847
11848 return (retval);
11849}
11850
11851/*
11852 * The LUN should always be set. The I/O is optional, and is used to
11853 * distinguish between I/Os sent by this initiator, and by other
11854 * initiators. We set unit attention for initiators other than this one.

--- 169 unchanged lines hidden (view full) ---

12024 return (0);
12025}
12026
12027static int
12028ctl_abort_task(union ctl_io *io)
12029{
12030 union ctl_io *xio;
12031 struct ctl_lun *lun;
12081 struct ctl_softc *ctl_softc;
12032 struct ctl_softc *softc;
12082#if 0
12083 struct sbuf sb;
12084 char printbuf[128];
12085#endif
12086 int found;
12087 uint32_t targ_lun;
12088
12033#if 0
12034 struct sbuf sb;
12035 char printbuf[128];
12036#endif
12037 int found;
12038 uint32_t targ_lun;
12039
12089 ctl_softc = control_softc;
12040 softc = control_softc;
12090 found = 0;
12091
12092 /*
12093 * Look up the LUN.
12094 */
12095 targ_lun = io->io_hdr.nexus.targ_mapped_lun;
12041 found = 0;
12042
12043 /*
12044 * Look up the LUN.
12045 */
12046 targ_lun = io->io_hdr.nexus.targ_mapped_lun;
12096 mtx_lock(&ctl_softc->ctl_lock);
12047 mtx_lock(&softc->ctl_lock);
12097 if ((targ_lun < CTL_MAX_LUNS)
12048 if ((targ_lun < CTL_MAX_LUNS)
12098 && (ctl_softc->ctl_luns[targ_lun] != NULL))
12099 lun = ctl_softc->ctl_luns[targ_lun];
12049 && (softc->ctl_luns[targ_lun] != NULL))
12050 lun = softc->ctl_luns[targ_lun];
12100 else {
12051 else {
12101 mtx_unlock(&ctl_softc->ctl_lock);
12052 mtx_unlock(&softc->ctl_lock);
12102 return (1);
12103 }
12104
12105#if 0
12106 printf("ctl_abort_task: called for lun %lld, tag %d type %d\n",
12107 lun->lun, io->taskio.tag_num, io->taskio.tag_type);
12108#endif
12109
12110 mtx_lock(&lun->lun_lock);
12053 return (1);
12054 }
12055
12056#if 0
12057 printf("ctl_abort_task: called for lun %lld, tag %d type %d\n",
12058 lun->lun, io->taskio.tag_num, io->taskio.tag_type);
12059#endif
12060
12061 mtx_lock(&lun->lun_lock);
12111 mtx_unlock(&ctl_softc->ctl_lock);
12062 mtx_unlock(&softc->ctl_lock);
12112 /*
12113 * Run through the OOA queue and attempt to find the given I/O.
12114 * The target port, initiator ID, tag type and tag number have to
12115 * match the values that we got from the initiator. If we have an
12116 * untagged command to abort, simply abort the first untagged command
12117 * we come to. We only allow one untagged command at a time of course.
12118 */
12119#if 0

--- 99 unchanged lines hidden (view full) ---

12219#endif
12220 }
12221 return (0);
12222}
12223
12224static void
12225ctl_run_task(union ctl_io *io)
12226{
12063 /*
12064 * Run through the OOA queue and attempt to find the given I/O.
12065 * The target port, initiator ID, tag type and tag number have to
12066 * match the values that we got from the initiator. If we have an
12067 * untagged command to abort, simply abort the first untagged command
12068 * we come to. We only allow one untagged command at a time of course.
12069 */
12070#if 0

--- 99 unchanged lines hidden (view full) ---

12170#endif
12171 }
12172 return (0);
12173}
12174
12175static void
12176ctl_run_task(union ctl_io *io)
12177{
12227 struct ctl_softc *ctl_softc = control_softc;
12178 struct ctl_softc *softc = control_softc;
12228 int retval = 1;
12229 const char *task_desc;
12230
12231 CTL_DEBUG_PRINT(("ctl_run_task\n"));
12232
12233 KASSERT(io->io_hdr.io_type == CTL_IO_TASK,
12234 ("ctl_run_task: Unextected io_type %d\n",
12235 io->io_hdr.io_type));

--- 38 unchanged lines hidden (view full) ---

12274 case CTL_TASK_I_T_NEXUS_RESET:
12275 retval = ctl_i_t_nexus_reset(io);
12276 break;
12277 case CTL_TASK_LUN_RESET: {
12278 struct ctl_lun *lun;
12279 uint32_t targ_lun;
12280
12281 targ_lun = io->io_hdr.nexus.targ_mapped_lun;
12179 int retval = 1;
12180 const char *task_desc;
12181
12182 CTL_DEBUG_PRINT(("ctl_run_task\n"));
12183
12184 KASSERT(io->io_hdr.io_type == CTL_IO_TASK,
12185 ("ctl_run_task: Unextected io_type %d\n",
12186 io->io_hdr.io_type));

--- 38 unchanged lines hidden (view full) ---

12225 case CTL_TASK_I_T_NEXUS_RESET:
12226 retval = ctl_i_t_nexus_reset(io);
12227 break;
12228 case CTL_TASK_LUN_RESET: {
12229 struct ctl_lun *lun;
12230 uint32_t targ_lun;
12231
12232 targ_lun = io->io_hdr.nexus.targ_mapped_lun;
12282 mtx_lock(&ctl_softc->ctl_lock);
12233 mtx_lock(&softc->ctl_lock);
12283 if ((targ_lun < CTL_MAX_LUNS)
12234 if ((targ_lun < CTL_MAX_LUNS)
12284 && (ctl_softc->ctl_luns[targ_lun] != NULL))
12285 lun = ctl_softc->ctl_luns[targ_lun];
12235 && (softc->ctl_luns[targ_lun] != NULL))
12236 lun = softc->ctl_luns[targ_lun];
12286 else {
12237 else {
12287 mtx_unlock(&ctl_softc->ctl_lock);
12238 mtx_unlock(&softc->ctl_lock);
12288 retval = 1;
12289 break;
12290 }
12291
12292 if (!(io->io_hdr.flags &
12293 CTL_FLAG_FROM_OTHER_SC)) {
12294 union ctl_ha_msg msg_info;
12295

--- 10 unchanged lines hidden (view full) ---

12306 ctl_ha_msg_send(CTL_HA_CHAN_CTL,
12307 (void *)&msg_info,
12308 sizeof(msg_info), 0)) {
12309 }
12310 }
12311
12312 retval = ctl_lun_reset(lun, io,
12313 CTL_UA_LUN_RESET);
12239 retval = 1;
12240 break;
12241 }
12242
12243 if (!(io->io_hdr.flags &
12244 CTL_FLAG_FROM_OTHER_SC)) {
12245 union ctl_ha_msg msg_info;
12246

--- 10 unchanged lines hidden (view full) ---

12257 ctl_ha_msg_send(CTL_HA_CHAN_CTL,
12258 (void *)&msg_info,
12259 sizeof(msg_info), 0)) {
12260 }
12261 }
12262
12263 retval = ctl_lun_reset(lun, io,
12264 CTL_UA_LUN_RESET);
12314 mtx_unlock(&ctl_softc->ctl_lock);
12265 mtx_unlock(&softc->ctl_lock);
12315 break;
12316 }
12317 case CTL_TASK_TARGET_RESET:
12266 break;
12267 }
12268 case CTL_TASK_TARGET_RESET:
12318 retval = ctl_target_reset(ctl_softc, io, CTL_UA_TARG_RESET);
12269 retval = ctl_target_reset(softc, io, CTL_UA_TARG_RESET);
12319 break;
12320 case CTL_TASK_BUS_RESET:
12270 break;
12271 case CTL_TASK_BUS_RESET:
12321 retval = ctl_bus_reset(ctl_softc, io);
12272 retval = ctl_bus_reset(softc, io);
12322 break;
12323 case CTL_TASK_PORT_LOGIN:
12324 break;
12325 case CTL_TASK_PORT_LOGOUT:
12326 break;
12327 default:
12328 printf("ctl_run_task: got unknown task management event %d\n",
12329 io->taskio.task_action);

--- 10 unchanged lines hidden (view full) ---

12340 * For HA operation. Handle commands that come in from the other
12341 * controller.
12342 */
12343static void
12344ctl_handle_isc(union ctl_io *io)
12345{
12346 int free_io;
12347 struct ctl_lun *lun;
12273 break;
12274 case CTL_TASK_PORT_LOGIN:
12275 break;
12276 case CTL_TASK_PORT_LOGOUT:
12277 break;
12278 default:
12279 printf("ctl_run_task: got unknown task management event %d\n",
12280 io->taskio.task_action);

--- 10 unchanged lines hidden (view full) ---

12291 * For HA operation. Handle commands that come in from the other
12292 * controller.
12293 */
12294static void
12295ctl_handle_isc(union ctl_io *io)
12296{
12297 int free_io;
12298 struct ctl_lun *lun;
12348 struct ctl_softc *ctl_softc;
12299 struct ctl_softc *softc;
12349 uint32_t targ_lun;
12350
12300 uint32_t targ_lun;
12301
12351 ctl_softc = control_softc;
12302 softc = control_softc;
12352
12353 targ_lun = io->io_hdr.nexus.targ_mapped_lun;
12303
12304 targ_lun = io->io_hdr.nexus.targ_mapped_lun;
12354 lun = ctl_softc->ctl_luns[targ_lun];
12305 lun = softc->ctl_luns[targ_lun];
12355
12356 switch (io->io_hdr.msg_type) {
12357 case CTL_MSG_SERIALIZE:
12358 free_io = ctl_serialize_other_sc_cmd(&io->scsiio);
12359 break;
12360 case CTL_MSG_R2R: {
12361 const struct ctl_cmd_entry *entry;
12362
12363 /*
12364 * This is only used in SER_ONLY mode.
12365 */
12366 free_io = 0;
12367 entry = ctl_get_cmd_entry(&io->scsiio, NULL);
12368 mtx_lock(&lun->lun_lock);
12306
12307 switch (io->io_hdr.msg_type) {
12308 case CTL_MSG_SERIALIZE:
12309 free_io = ctl_serialize_other_sc_cmd(&io->scsiio);
12310 break;
12311 case CTL_MSG_R2R: {
12312 const struct ctl_cmd_entry *entry;
12313
12314 /*
12315 * This is only used in SER_ONLY mode.
12316 */
12317 free_io = 0;
12318 entry = ctl_get_cmd_entry(&io->scsiio, NULL);
12319 mtx_lock(&lun->lun_lock);
12369 if (ctl_scsiio_lun_check(ctl_softc, lun,
12320 if (ctl_scsiio_lun_check(lun,
12370 entry, (struct ctl_scsiio *)io) != 0) {
12371 mtx_unlock(&lun->lun_lock);
12372 ctl_done(io);
12373 break;
12374 }
12375 io->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR;
12376 mtx_unlock(&lun->lun_lock);
12377 ctl_enqueue_rtr(io);
12378 break;
12379 }
12380 case CTL_MSG_FINISH_IO:
12321 entry, (struct ctl_scsiio *)io) != 0) {
12322 mtx_unlock(&lun->lun_lock);
12323 ctl_done(io);
12324 break;
12325 }
12326 io->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR;
12327 mtx_unlock(&lun->lun_lock);
12328 ctl_enqueue_rtr(io);
12329 break;
12330 }
12331 case CTL_MSG_FINISH_IO:
12381 if (ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
12332 if (softc->ha_mode == CTL_HA_MODE_XFER) {
12382 free_io = 0;
12383 ctl_done(io);
12384 } else {
12385 free_io = 1;
12386 mtx_lock(&lun->lun_lock);
12387 TAILQ_REMOVE(&lun->ooa_queue, &io->io_hdr,
12388 ooa_links);
12389 ctl_check_blocked(lun);

--- 1082 unchanged lines hidden (view full) ---

13472 }
13473
13474}
13475
13476static int
13477ctl_process_done(union ctl_io *io)
13478{
13479 struct ctl_lun *lun;
12333 free_io = 0;
12334 ctl_done(io);
12335 } else {
12336 free_io = 1;
12337 mtx_lock(&lun->lun_lock);
12338 TAILQ_REMOVE(&lun->ooa_queue, &io->io_hdr,
12339 ooa_links);
12340 ctl_check_blocked(lun);

--- 1082 unchanged lines hidden (view full) ---

13423 }
13424
13425}
13426
13427static int
13428ctl_process_done(union ctl_io *io)
13429{
13430 struct ctl_lun *lun;
13480 struct ctl_softc *ctl_softc = control_softc;
13431 struct ctl_softc *softc = control_softc;
13481 void (*fe_done)(union ctl_io *io);
13482 uint32_t targ_port = ctl_port_idx(io->io_hdr.nexus.targ_port);
13483
13484 CTL_DEBUG_PRINT(("ctl_process_done\n"));
13485
13432 void (*fe_done)(union ctl_io *io);
13433 uint32_t targ_port = ctl_port_idx(io->io_hdr.nexus.targ_port);
13434
13435 CTL_DEBUG_PRINT(("ctl_process_done\n"));
13436
13486 fe_done =
13487 control_softc->ctl_ports[targ_port]->fe_done;
13437 fe_done = softc->ctl_ports[targ_port]->fe_done;
13488
13489#ifdef CTL_TIME_IO
13490 if ((time_uptime - io->io_hdr.start_time) > ctl_time_io_secs) {
13491 char str[256];
13492 char path_str[64];
13493 struct sbuf sb;
13494
13495 ctl_scsi_path_string(io, path_str, sizeof(path_str));

--- 110 unchanged lines hidden (view full) ---

13606
13607 /*
13608 * If the LUN has been invalidated, free it if there is nothing
13609 * left on its OOA queue.
13610 */
13611 if ((lun->flags & CTL_LUN_INVALID)
13612 && TAILQ_EMPTY(&lun->ooa_queue)) {
13613 mtx_unlock(&lun->lun_lock);
13438
13439#ifdef CTL_TIME_IO
13440 if ((time_uptime - io->io_hdr.start_time) > ctl_time_io_secs) {
13441 char str[256];
13442 char path_str[64];
13443 struct sbuf sb;
13444
13445 ctl_scsi_path_string(io, path_str, sizeof(path_str));

--- 110 unchanged lines hidden (view full) ---

13556
13557 /*
13558 * If the LUN has been invalidated, free it if there is nothing
13559 * left on its OOA queue.
13560 */
13561 if ((lun->flags & CTL_LUN_INVALID)
13562 && TAILQ_EMPTY(&lun->ooa_queue)) {
13563 mtx_unlock(&lun->lun_lock);
13614 mtx_lock(&ctl_softc->ctl_lock);
13564 mtx_lock(&softc->ctl_lock);
13615 ctl_free_lun(lun);
13565 ctl_free_lun(lun);
13616 mtx_unlock(&ctl_softc->ctl_lock);
13566 mtx_unlock(&softc->ctl_lock);
13617 } else
13618 mtx_unlock(&lun->lun_lock);
13619
13620bailout:
13621
13622 /*
13623 * If this command has been aborted, make sure we set the status
13624 * properly. The FETD is responsible for freeing the I/O and doing

--- 35 unchanged lines hidden (view full) ---

13660 * mode. In SER_ONLY mode, the I/O is done on the controller that
13661 * received the I/O (from CTL's perspective), and so the status is
13662 * generated there.
13663 *
13664 * XXX KDM if we hold the lock here, we could cause a deadlock
13665 * if the frontend comes back in in this context to queue
13666 * something.
13667 */
13567 } else
13568 mtx_unlock(&lun->lun_lock);
13569
13570bailout:
13571
13572 /*
13573 * If this command has been aborted, make sure we set the status
13574 * properly. The FETD is responsible for freeing the I/O and doing

--- 35 unchanged lines hidden (view full) ---

13610 * mode. In SER_ONLY mode, the I/O is done on the controller that
13611 * received the I/O (from CTL's perspective), and so the status is
13612 * generated there.
13613 *
13614 * XXX KDM if we hold the lock here, we could cause a deadlock
13615 * if the frontend comes back in in this context to queue
13616 * something.
13617 */
13668 if ((ctl_softc->ha_mode == CTL_HA_MODE_XFER)
13618 if ((softc->ha_mode == CTL_HA_MODE_XFER)
13669 && (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)) {
13670 union ctl_ha_msg msg;
13671
13672 memset(&msg, 0, sizeof(msg));
13673 msg.hdr.msg_type = CTL_MSG_FINISH_IO;
13674 msg.hdr.original_sc = io->io_hdr.original_sc;
13675 msg.hdr.nexus = io->io_hdr.nexus;
13676 msg.hdr.status = io->io_hdr.status;

--- 31 unchanged lines hidden (view full) ---

13708/*
13709 * Front end should call this if it doesn't do autosense. When the request
13710 * sense comes back in from the initiator, we'll dequeue this and send it.
13711 */
13712int
13713ctl_queue_sense(union ctl_io *io)
13714{
13715 struct ctl_lun *lun;
13619 && (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)) {
13620 union ctl_ha_msg msg;
13621
13622 memset(&msg, 0, sizeof(msg));
13623 msg.hdr.msg_type = CTL_MSG_FINISH_IO;
13624 msg.hdr.original_sc = io->io_hdr.original_sc;
13625 msg.hdr.nexus = io->io_hdr.nexus;
13626 msg.hdr.status = io->io_hdr.status;

--- 31 unchanged lines hidden (view full) ---

13658/*
13659 * Front end should call this if it doesn't do autosense. When the request
13660 * sense comes back in from the initiator, we'll dequeue this and send it.
13661 */
13662int
13663ctl_queue_sense(union ctl_io *io)
13664{
13665 struct ctl_lun *lun;
13716 struct ctl_softc *ctl_softc;
13666 struct ctl_softc *softc;
13717 uint32_t initidx, targ_lun;
13718
13667 uint32_t initidx, targ_lun;
13668
13719 ctl_softc = control_softc;
13669 softc = control_softc;
13720
13721 CTL_DEBUG_PRINT(("ctl_queue_sense\n"));
13722
13723 /*
13724 * LUN lookup will likely move to the ctl_work_thread() once we
13725 * have our new queueing infrastructure (that doesn't put things on
13726 * a per-LUN queue initially). That is so that we can handle
13727 * things like an INQUIRY to a LUN that we don't have enabled. We
13728 * can't deal with that right now.
13729 */
13670
13671 CTL_DEBUG_PRINT(("ctl_queue_sense\n"));
13672
13673 /*
13674 * LUN lookup will likely move to the ctl_work_thread() once we
13675 * have our new queueing infrastructure (that doesn't put things on
13676 * a per-LUN queue initially). That is so that we can handle
13677 * things like an INQUIRY to a LUN that we don't have enabled. We
13678 * can't deal with that right now.
13679 */
13730 mtx_lock(&ctl_softc->ctl_lock);
13680 mtx_lock(&softc->ctl_lock);
13731
13732 /*
13733 * If we don't have a LUN for this, just toss the sense
13734 * information.
13735 */
13736 targ_lun = io->io_hdr.nexus.targ_lun;
13681
13682 /*
13683 * If we don't have a LUN for this, just toss the sense
13684 * information.
13685 */
13686 targ_lun = io->io_hdr.nexus.targ_lun;
13737 targ_lun = ctl_map_lun(io->io_hdr.nexus.targ_port, targ_lun);
13687 targ_lun = ctl_map_lun(softc, io->io_hdr.nexus.targ_port, targ_lun);
13738 if ((targ_lun < CTL_MAX_LUNS)
13688 if ((targ_lun < CTL_MAX_LUNS)
13739 && (ctl_softc->ctl_luns[targ_lun] != NULL))
13740 lun = ctl_softc->ctl_luns[targ_lun];
13689 && (softc->ctl_luns[targ_lun] != NULL))
13690 lun = softc->ctl_luns[targ_lun];
13741 else
13742 goto bailout;
13743
13744 initidx = ctl_get_initindex(&io->io_hdr.nexus);
13745
13746 mtx_lock(&lun->lun_lock);
13747 /*
13748 * Already have CA set for this LUN...toss the sense information.

--- 5 unchanged lines hidden (view full) ---

13754
13755 memcpy(&lun->pending_sense[initidx], &io->scsiio.sense_data,
13756 ctl_min(sizeof(lun->pending_sense[initidx]),
13757 sizeof(io->scsiio.sense_data)));
13758 ctl_set_mask(lun->have_ca, initidx);
13759 mtx_unlock(&lun->lun_lock);
13760
13761bailout:
13691 else
13692 goto bailout;
13693
13694 initidx = ctl_get_initindex(&io->io_hdr.nexus);
13695
13696 mtx_lock(&lun->lun_lock);
13697 /*
13698 * Already have CA set for this LUN...toss the sense information.

--- 5 unchanged lines hidden (view full) ---

13704
13705 memcpy(&lun->pending_sense[initidx], &io->scsiio.sense_data,
13706 ctl_min(sizeof(lun->pending_sense[initidx]),
13707 sizeof(io->scsiio.sense_data)));
13708 ctl_set_mask(lun->have_ca, initidx);
13709 mtx_unlock(&lun->lun_lock);
13710
13711bailout:
13762 mtx_unlock(&ctl_softc->ctl_lock);
13712 mtx_unlock(&softc->ctl_lock);
13763
13764 ctl_free_io(io);
13765
13766 return (CTL_RETVAL_COMPLETE);
13767}
13768#endif
13769
13770/*
13771 * Primary command inlet from frontend ports. All SCSI and task I/O
13772 * requests must go through this function.
13773 */
13774int
13775ctl_queue(union ctl_io *io)
13776{
13713
13714 ctl_free_io(io);
13715
13716 return (CTL_RETVAL_COMPLETE);
13717}
13718#endif
13719
13720/*
13721 * Primary command inlet from frontend ports. All SCSI and task I/O
13722 * requests must go through this function.
13723 */
13724int
13725ctl_queue(union ctl_io *io)
13726{
13777 struct ctl_softc *ctl_softc;
13778
13779 CTL_DEBUG_PRINT(("ctl_queue cdb[0]=%02X\n", io->scsiio.cdb[0]));
13780
13727
13728 CTL_DEBUG_PRINT(("ctl_queue cdb[0]=%02X\n", io->scsiio.cdb[0]));
13729
13781 ctl_softc = control_softc;
13782
13783#ifdef CTL_TIME_IO
13784 io->io_hdr.start_time = time_uptime;
13785 getbintime(&io->io_hdr.start_bt);
13786#endif /* CTL_TIME_IO */
13787
13788 /* Map FE-specific LUN ID into global one. */
13789 io->io_hdr.nexus.targ_mapped_lun =
13730#ifdef CTL_TIME_IO
13731 io->io_hdr.start_time = time_uptime;
13732 getbintime(&io->io_hdr.start_bt);
13733#endif /* CTL_TIME_IO */
13734
13735 /* Map FE-specific LUN ID into global one. */
13736 io->io_hdr.nexus.targ_mapped_lun =
13790 ctl_map_lun(io->io_hdr.nexus.targ_port, io->io_hdr.nexus.targ_lun);
13737 ctl_map_lun(control_softc, io->io_hdr.nexus.targ_port,
13738 io->io_hdr.nexus.targ_lun);
13791
13792 switch (io->io_hdr.io_type) {
13793 case CTL_IO_SCSI:
13794 case CTL_IO_TASK:
13795 if (ctl_debug & CTL_DEBUG_CDB)
13796 ctl_io_print(io);
13797 ctl_enqueue_incoming(io);
13798 break;

--- 14 unchanged lines hidden (view full) ---

13813 io = (union ctl_io *)arg;
13814 ctl_done(io);
13815}
13816#endif /* CTL_IO_DELAY */
13817
13818void
13819ctl_done(union ctl_io *io)
13820{
13739
13740 switch (io->io_hdr.io_type) {
13741 case CTL_IO_SCSI:
13742 case CTL_IO_TASK:
13743 if (ctl_debug & CTL_DEBUG_CDB)
13744 ctl_io_print(io);
13745 ctl_enqueue_incoming(io);
13746 break;

--- 14 unchanged lines hidden (view full) ---

13761 io = (union ctl_io *)arg;
13762 ctl_done(io);
13763}
13764#endif /* CTL_IO_DELAY */
13765
13766void
13767ctl_done(union ctl_io *io)
13768{
13821 struct ctl_softc *ctl_softc;
13822
13769
13823 ctl_softc = control_softc;
13824
13825 /*
13826 * Enable this to catch duplicate completion issues.
13827 */
13828#if 0
13829 if (io->io_hdr.flags & CTL_FLAG_ALREADY_DONE) {
13830 printf("%s: type %d msg %d cdb %x iptl: "
13831 "%d:%d:%d:%d tag 0x%04x "
13832 "flag %#x status %x\n",

--- 422 unchanged lines hidden ---
13770 /*
13771 * Enable this to catch duplicate completion issues.
13772 */
13773#if 0
13774 if (io->io_hdr.flags & CTL_FLAG_ALREADY_DONE) {
13775 printf("%s: type %d msg %d cdb %x iptl: "
13776 "%d:%d:%d:%d tag 0x%04x "
13777 "flag %#x status %x\n",

--- 422 unchanged lines hidden ---