ctl.c (288359) | ctl.c (288369) |
---|---|
1/*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * Copyright (c) 2015 Alexander Motin <mav@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 29 unchanged lines hidden (view full) --- 38 * CAM Target Layer, a SCSI device emulation subsystem. 39 * 40 * Author: Ken Merry <ken@FreeBSD.org> 41 */ 42 43#define _CTL_C 44 45#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * Copyright (c) 2015 Alexander Motin <mav@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 29 unchanged lines hidden (view full) --- 38 * CAM Target Layer, a SCSI device emulation subsystem. 39 * 40 * Author: Ken Merry <ken@FreeBSD.org> 41 */ 42 43#define _CTL_C 44 45#include <sys/cdefs.h> |
46__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 288359 2015-09-29 10:44:37Z mav $"); | 46__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 288369 2015-09-29 15:12:40Z mav $"); |
47 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/ctype.h> 51#include <sys/kernel.h> 52#include <sys/types.h> 53#include <sys/kthread.h> 54#include <sys/bio.h> --- 5069 unchanged lines hidden (view full) --- 5124 struct ctl_lun *lun; 5125 int retval; 5126 5127 CTL_DEBUG_PRINT(("ctl_start_stop\n")); 5128 5129 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 5130 cdb = (struct scsi_start_stop_unit *)ctsio->cdb; 5131 | 47 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/ctype.h> 51#include <sys/kernel.h> 52#include <sys/types.h> 53#include <sys/kthread.h> 54#include <sys/bio.h> --- 5069 unchanged lines hidden (view full) --- 5124 struct ctl_lun *lun; 5125 int retval; 5126 5127 CTL_DEBUG_PRINT(("ctl_start_stop\n")); 5128 5129 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 5130 cdb = (struct scsi_start_stop_unit *)ctsio->cdb; 5131 |
5132 if ((lun->flags & CTL_LUN_PR_RESERVED) 5133 && ((cdb->how & SSS_START)==0)) { 5134 uint32_t residx; | 5132 if ((cdb->how & SSS_PC_MASK) == 0) { 5133 if ((lun->flags & CTL_LUN_PR_RESERVED) && 5134 (cdb->how & SSS_START) == 0) { 5135 uint32_t residx; |
5135 | 5136 |
5136 residx = ctl_get_initindex(&ctsio->io_hdr.nexus); 5137 if (ctl_get_prkey(lun, residx) == 0 5138 || (lun->pr_res_idx!=residx && lun->res_type < 4)) { | 5137 residx = ctl_get_initindex(&ctsio->io_hdr.nexus); 5138 if (ctl_get_prkey(lun, residx) == 0 || 5139 (lun->pr_res_idx != residx && lun->res_type < 4)) { |
5139 | 5140 |
5140 ctl_set_reservation_conflict(ctsio); | 5141 ctl_set_reservation_conflict(ctsio); 5142 ctl_done((union ctl_io *)ctsio); 5143 return (CTL_RETVAL_COMPLETE); 5144 } 5145 } 5146 5147 if ((cdb->how & SSS_LOEJ) && 5148 (lun->flags & CTL_LUN_REMOVABLE) == 0) { 5149 ctl_set_invalid_field(ctsio, 5150 /*sks_valid*/ 1, 5151 /*command*/ 1, 5152 /*field*/ 4, 5153 /*bit_valid*/ 1, 5154 /*bit*/ 1); |
5141 ctl_done((union ctl_io *)ctsio); 5142 return (CTL_RETVAL_COMPLETE); 5143 } | 5155 ctl_done((union ctl_io *)ctsio); 5156 return (CTL_RETVAL_COMPLETE); 5157 } |
5144 } | |
5145 | 5158 |
5146 if ((cdb->how & SSS_LOEJ) && 5147 (lun->flags & CTL_LUN_REMOVABLE) == 0) { 5148 ctl_set_invalid_field(ctsio, 5149 /*sks_valid*/ 1, 5150 /*command*/ 1, 5151 /*field*/ 4, 5152 /*bit_valid*/ 1, 5153 /*bit*/ 1); 5154 ctl_done((union ctl_io *)ctsio); 5155 return (CTL_RETVAL_COMPLETE); | 5159 if ((cdb->how & SSS_START) == 0 && (cdb->how & SSS_LOEJ) && 5160 lun->prevent_count > 0) { 5161 /* "Medium removal prevented" */ 5162 ctl_set_sense(ctsio, /*current_error*/ 1, 5163 /*sense_key*/(lun->flags & CTL_LUN_NO_MEDIA) ? 5164 SSD_KEY_NOT_READY : SSD_KEY_ILLEGAL_REQUEST, 5165 /*asc*/ 0x53, /*ascq*/ 0x02, SSD_ELEM_NONE); 5166 ctl_done((union ctl_io *)ctsio); 5167 return (CTL_RETVAL_COMPLETE); 5168 } |
5156 } 5157 5158 retval = lun->backend->config_write((union ctl_io *)ctsio); 5159 return (retval); 5160} 5161 5162int 5163ctl_prevent_allow(struct ctl_scsiio *ctsio) 5164{ 5165 struct ctl_lun *lun; | 5169 } 5170 5171 retval = lun->backend->config_write((union ctl_io *)ctsio); 5172 return (retval); 5173} 5174 5175int 5176ctl_prevent_allow(struct ctl_scsiio *ctsio) 5177{ 5178 struct ctl_lun *lun; |
5179 struct scsi_prevent *cdb; |
|
5166 int retval; | 5180 int retval; |
5181 uint32_t initidx; |
|
5167 5168 CTL_DEBUG_PRINT(("ctl_prevent_allow\n")); 5169 5170 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; | 5182 5183 CTL_DEBUG_PRINT(("ctl_prevent_allow\n")); 5184 5185 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; |
5186 cdb = (struct scsi_prevent *)ctsio->cdb; |
|
5171 5172 if ((lun->flags & CTL_LUN_REMOVABLE) == 0) { 5173 ctl_set_invalid_opcode(ctsio); 5174 ctl_done((union ctl_io *)ctsio); 5175 return (CTL_RETVAL_COMPLETE); 5176 } 5177 | 5187 5188 if ((lun->flags & CTL_LUN_REMOVABLE) == 0) { 5189 ctl_set_invalid_opcode(ctsio); 5190 ctl_done((union ctl_io *)ctsio); 5191 return (CTL_RETVAL_COMPLETE); 5192 } 5193 |
5194 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus); 5195 mtx_lock(&lun->lun_lock); 5196 if ((cdb->how & PR_PREVENT) && 5197 ctl_is_set(lun->prevent, initidx) == 0) { 5198 ctl_set_mask(lun->prevent, initidx); 5199 lun->prevent_count++; 5200 } else if ((cdb->how & PR_PREVENT) == 0 && 5201 ctl_is_set(lun->prevent, initidx)) { 5202 ctl_clear_mask(lun->prevent, initidx); 5203 lun->prevent_count--; 5204 } 5205 mtx_unlock(&lun->lun_lock); |
|
5178 retval = lun->backend->config_write((union ctl_io *)ctsio); 5179 return (retval); 5180} 5181 5182/* 5183 * We support the SYNCHRONIZE CACHE command (10 and 16 byte versions), but 5184 * we don't really do anything with the LBA and length fields if the user 5185 * passes them in. Instead we'll just flush out the cache for the entire --- 6614 unchanged lines hidden (view full) --- 11800 */ 11801static int 11802ctl_do_lun_reset(struct ctl_lun *lun, union ctl_io *io, ctl_ua_type ua_type) 11803{ 11804 union ctl_io *xio; 11805#if 0 11806 uint32_t initidx; 11807#endif | 5206 retval = lun->backend->config_write((union ctl_io *)ctsio); 5207 return (retval); 5208} 5209 5210/* 5211 * We support the SYNCHRONIZE CACHE command (10 and 16 byte versions), but 5212 * we don't really do anything with the LBA and length fields if the user 5213 * passes them in. Instead we'll just flush out the cache for the entire --- 6614 unchanged lines hidden (view full) --- 11828 */ 11829static int 11830ctl_do_lun_reset(struct ctl_lun *lun, union ctl_io *io, ctl_ua_type ua_type) 11831{ 11832 union ctl_io *xio; 11833#if 0 11834 uint32_t initidx; 11835#endif |
11808#ifdef CTL_WITH_CA | |
11809 int i; | 11836 int i; |
11810#endif | |
11811 11812 mtx_lock(&lun->lun_lock); 11813 /* 11814 * Run through the OOA queue and abort each I/O. 11815 */ 11816 for (xio = (union ctl_io *)TAILQ_FIRST(&lun->ooa_queue); xio != NULL; 11817 xio = (union ctl_io *)TAILQ_NEXT(&xio->io_hdr, ooa_links)) { 11818 xio->io_hdr.flags |= CTL_FLAG_ABORT | CTL_FLAG_ABORT_STATUS; --- 18 unchanged lines hidden (view full) --- 11837 * those commands are obsolete in SPC-3. 11838 */ 11839 lun->flags &= ~CTL_LUN_RESERVED; 11840 11841#ifdef CTL_WITH_CA 11842 for (i = 0; i < CTL_MAX_INITIATORS; i++) 11843 ctl_clear_mask(lun->have_ca, i); 11844#endif | 11837 11838 mtx_lock(&lun->lun_lock); 11839 /* 11840 * Run through the OOA queue and abort each I/O. 11841 */ 11842 for (xio = (union ctl_io *)TAILQ_FIRST(&lun->ooa_queue); xio != NULL; 11843 xio = (union ctl_io *)TAILQ_NEXT(&xio->io_hdr, ooa_links)) { 11844 xio->io_hdr.flags |= CTL_FLAG_ABORT | CTL_FLAG_ABORT_STATUS; --- 18 unchanged lines hidden (view full) --- 11863 * those commands are obsolete in SPC-3. 11864 */ 11865 lun->flags &= ~CTL_LUN_RESERVED; 11866 11867#ifdef CTL_WITH_CA 11868 for (i = 0; i < CTL_MAX_INITIATORS; i++) 11869 ctl_clear_mask(lun->have_ca, i); 11870#endif |
11871 lun->prevent_count = 0; 11872 for (i = 0; i < CTL_MAX_INITIATORS; i++) 11873 ctl_clear_mask(lun->prevent, i); |
|
11845 mtx_unlock(&lun->lun_lock); 11846 11847 return (0); 11848} 11849 11850static int 11851ctl_lun_reset(struct ctl_softc *softc, union ctl_io *io) 11852{ --- 129 unchanged lines hidden (view full) --- 11982 mtx_lock(&lun->lun_lock); 11983 ctl_abort_tasks_lun(lun, io->io_hdr.nexus.targ_port, 11984 io->io_hdr.nexus.initid, 1); 11985#ifdef CTL_WITH_CA 11986 ctl_clear_mask(lun->have_ca, initidx); 11987#endif 11988 if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx == initidx)) 11989 lun->flags &= ~CTL_LUN_RESERVED; | 11874 mtx_unlock(&lun->lun_lock); 11875 11876 return (0); 11877} 11878 11879static int 11880ctl_lun_reset(struct ctl_softc *softc, union ctl_io *io) 11881{ --- 129 unchanged lines hidden (view full) --- 12011 mtx_lock(&lun->lun_lock); 12012 ctl_abort_tasks_lun(lun, io->io_hdr.nexus.targ_port, 12013 io->io_hdr.nexus.initid, 1); 12014#ifdef CTL_WITH_CA 12015 ctl_clear_mask(lun->have_ca, initidx); 12016#endif 12017 if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx == initidx)) 12018 lun->flags &= ~CTL_LUN_RESERVED; |
12019 if (ctl_is_set(lun->prevent, initidx)) { 12020 ctl_clear_mask(lun->prevent, initidx); 12021 lun->prevent_count--; 12022 } |
|
11990 ctl_est_ua(lun, initidx, CTL_UA_I_T_NEXUS_LOSS); 11991 mtx_unlock(&lun->lun_lock); 11992 } 11993 mtx_unlock(&softc->ctl_lock); 11994 io->taskio.task_status = CTL_TASK_FUNCTION_COMPLETE; 11995 return (0); 11996} 11997 --- 1648 unchanged lines hidden --- | 12023 ctl_est_ua(lun, initidx, CTL_UA_I_T_NEXUS_LOSS); 12024 mtx_unlock(&lun->lun_lock); 12025 } 12026 mtx_unlock(&softc->ctl_lock); 12027 io->taskio.task_status = CTL_TASK_FUNCTION_COMPLETE; 12028 return (0); 12029} 12030 --- 1648 unchanged lines hidden --- |