ctl_frontend_iscsi.c (268684) | ctl_frontend_iscsi.c (268685) |
---|---|
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268684 2014-07-15 17:07:07Z mav $ | 29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268685 2014-07-15 17:08:04Z mav $ |
30 */ 31 32/* 33 * CTL frontend for the iSCSI protocol. 34 */ 35 36#include <sys/cdefs.h> | 30 */ 31 32/* 33 * CTL frontend for the iSCSI protocol. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268684 2014-07-15 17:07:07Z mav $"); | 37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268685 2014-07-15 17:08:04Z mav $"); |
38 39#include <sys/param.h> 40#include <sys/capability.h> 41#include <sys/condvar.h> 42#include <sys/file.h> 43#include <sys/kernel.h> 44#include <sys/kthread.h> 45#include <sys/lock.h> --- 102 unchanged lines hidden (view full) --- 148 149int cfiscsi_init(void); 150static void cfiscsi_online(void *arg); 151static void cfiscsi_offline(void *arg); 152static int cfiscsi_lun_enable(void *arg, 153 struct ctl_id target_id, int lun_id); 154static int cfiscsi_lun_disable(void *arg, 155 struct ctl_id target_id, int lun_id); | 38 39#include <sys/param.h> 40#include <sys/capability.h> 41#include <sys/condvar.h> 42#include <sys/file.h> 43#include <sys/kernel.h> 44#include <sys/kthread.h> 45#include <sys/lock.h> --- 102 unchanged lines hidden (view full) --- 148 149int cfiscsi_init(void); 150static void cfiscsi_online(void *arg); 151static void cfiscsi_offline(void *arg); 152static int cfiscsi_lun_enable(void *arg, 153 struct ctl_id target_id, int lun_id); 154static int cfiscsi_lun_disable(void *arg, 155 struct ctl_id target_id, int lun_id); |
156static uint32_t cfiscsi_lun_map(void *arg, uint32_t lun); |
|
156static int cfiscsi_ioctl(struct cdev *dev, 157 u_long cmd, caddr_t addr, int flag, struct thread *td); 158static void cfiscsi_datamove(union ctl_io *io); 159static void cfiscsi_done(union ctl_io *io); | 157static int cfiscsi_ioctl(struct cdev *dev, 158 u_long cmd, caddr_t addr, int flag, struct thread *td); 159static void cfiscsi_datamove(union ctl_io *io); 160static void cfiscsi_done(union ctl_io *io); |
160static uint32_t cfiscsi_map_lun(void *arg, uint32_t lun); | |
161static bool cfiscsi_pdu_update_cmdsn(const struct icl_pdu *request); 162static void cfiscsi_pdu_handle_nop_out(struct icl_pdu *request); 163static void cfiscsi_pdu_handle_scsi_command(struct icl_pdu *request); 164static void cfiscsi_pdu_handle_task_request(struct icl_pdu *request); 165static void cfiscsi_pdu_handle_data_out(struct icl_pdu *request); 166static void cfiscsi_pdu_handle_logout_request(struct icl_pdu *request); 167static void cfiscsi_session_terminate(struct cfiscsi_session *cs); 168static struct cfiscsi_target *cfiscsi_target_find(struct cfiscsi_softc --- 382 unchanged lines hidden (view full) --- 551 } 552 ctl_zero_io(io); 553 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = request; 554 io->io_hdr.io_type = CTL_IO_SCSI; 555 io->io_hdr.nexus.initid.id = cs->cs_ctl_initid; 556 io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; 557 io->io_hdr.nexus.targ_target.id = 0; 558 io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhssc->bhssc_lun); | 161static bool cfiscsi_pdu_update_cmdsn(const struct icl_pdu *request); 162static void cfiscsi_pdu_handle_nop_out(struct icl_pdu *request); 163static void cfiscsi_pdu_handle_scsi_command(struct icl_pdu *request); 164static void cfiscsi_pdu_handle_task_request(struct icl_pdu *request); 165static void cfiscsi_pdu_handle_data_out(struct icl_pdu *request); 166static void cfiscsi_pdu_handle_logout_request(struct icl_pdu *request); 167static void cfiscsi_session_terminate(struct cfiscsi_session *cs); 168static struct cfiscsi_target *cfiscsi_target_find(struct cfiscsi_softc --- 382 unchanged lines hidden (view full) --- 551 } 552 ctl_zero_io(io); 553 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = request; 554 io->io_hdr.io_type = CTL_IO_SCSI; 555 io->io_hdr.nexus.initid.id = cs->cs_ctl_initid; 556 io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; 557 io->io_hdr.nexus.targ_target.id = 0; 558 io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhssc->bhssc_lun); |
559 io->io_hdr.nexus.lun_map_fn = cfiscsi_map_lun; 560 io->io_hdr.nexus.lun_map_arg = cs; | |
561 io->scsiio.tag_num = bhssc->bhssc_initiator_task_tag; 562 switch ((bhssc->bhssc_flags & BHSSC_FLAGS_ATTR)) { 563 case BHSSC_FLAGS_ATTR_UNTAGGED: 564 io->scsiio.tag_type = CTL_TAG_UNTAGGED; 565 break; 566 case BHSSC_FLAGS_ATTR_SIMPLE: 567 io->scsiio.tag_type = CTL_TAG_SIMPLE; 568 break; --- 48 unchanged lines hidden (view full) --- 617 } 618 ctl_zero_io(io); 619 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = request; 620 io->io_hdr.io_type = CTL_IO_TASK; 621 io->io_hdr.nexus.initid.id = cs->cs_ctl_initid; 622 io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; 623 io->io_hdr.nexus.targ_target.id = 0; 624 io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhstmr->bhstmr_lun); | 559 io->scsiio.tag_num = bhssc->bhssc_initiator_task_tag; 560 switch ((bhssc->bhssc_flags & BHSSC_FLAGS_ATTR)) { 561 case BHSSC_FLAGS_ATTR_UNTAGGED: 562 io->scsiio.tag_type = CTL_TAG_UNTAGGED; 563 break; 564 case BHSSC_FLAGS_ATTR_SIMPLE: 565 io->scsiio.tag_type = CTL_TAG_SIMPLE; 566 break; --- 48 unchanged lines hidden (view full) --- 615 } 616 ctl_zero_io(io); 617 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = request; 618 io->io_hdr.io_type = CTL_IO_TASK; 619 io->io_hdr.nexus.initid.id = cs->cs_ctl_initid; 620 io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; 621 io->io_hdr.nexus.targ_target.id = 0; 622 io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhstmr->bhstmr_lun); |
625 io->io_hdr.nexus.lun_map_fn = cfiscsi_map_lun; 626 io->io_hdr.nexus.lun_map_arg = cs; | |
627 io->taskio.tag_type = CTL_TAG_SIMPLE; /* XXX */ 628 629 switch (bhstmr->bhstmr_function & ~0x80) { 630 case BHSTMR_FUNCTION_ABORT_TASK: 631#if 0 632 CFISCSI_SESSION_DEBUG(cs, "BHSTMR_FUNCTION_ABORT_TASK"); 633#endif 634 io->taskio.task_action = CTL_TASK_ABORT_TASK; --- 1364 unchanged lines hidden (view full) --- 1999 port->num_requested_ctl_io = 4096; 2000 port->port_name = "iscsi"; 2001 port->virtual_port = strtoul(tag, NULL, 0); 2002 port->port_online = cfiscsi_online; 2003 port->port_offline = cfiscsi_offline; 2004 port->onoff_arg = ct; 2005 port->lun_enable = cfiscsi_lun_enable; 2006 port->lun_disable = cfiscsi_lun_disable; | 623 io->taskio.tag_type = CTL_TAG_SIMPLE; /* XXX */ 624 625 switch (bhstmr->bhstmr_function & ~0x80) { 626 case BHSTMR_FUNCTION_ABORT_TASK: 627#if 0 628 CFISCSI_SESSION_DEBUG(cs, "BHSTMR_FUNCTION_ABORT_TASK"); 629#endif 630 io->taskio.task_action = CTL_TASK_ABORT_TASK; --- 1364 unchanged lines hidden (view full) --- 1995 port->num_requested_ctl_io = 4096; 1996 port->port_name = "iscsi"; 1997 port->virtual_port = strtoul(tag, NULL, 0); 1998 port->port_online = cfiscsi_online; 1999 port->port_offline = cfiscsi_offline; 2000 port->onoff_arg = ct; 2001 port->lun_enable = cfiscsi_lun_enable; 2002 port->lun_disable = cfiscsi_lun_disable; |
2003 port->lun_map = cfiscsi_lun_map; |
|
2007 port->targ_lun_arg = ct; 2008 port->fe_datamove = cfiscsi_datamove; 2009 port->fe_done = cfiscsi_done; 2010 2011 /* XXX KDM what should we report here? */ 2012 /* XXX These should probably be fetched from CTL. */ 2013 port->max_targets = 1; 2014 port->max_target_id = 15; --- 230 unchanged lines hidden (view full) --- 2245 continue; 2246 cfiscsi_target_hold(ct); 2247 mtx_unlock(&softc->lock); 2248 free(newct, M_CFISCSI); 2249 return (ct); 2250 } 2251 2252 for (i = 0; i < CTL_MAX_LUNS; i++) | 2004 port->targ_lun_arg = ct; 2005 port->fe_datamove = cfiscsi_datamove; 2006 port->fe_done = cfiscsi_done; 2007 2008 /* XXX KDM what should we report here? */ 2009 /* XXX These should probably be fetched from CTL. */ 2010 port->max_targets = 1; 2011 port->max_target_id = 15; --- 230 unchanged lines hidden (view full) --- 2242 continue; 2243 cfiscsi_target_hold(ct); 2244 mtx_unlock(&softc->lock); 2245 free(newct, M_CFISCSI); 2246 return (ct); 2247 } 2248 2249 for (i = 0; i < CTL_MAX_LUNS; i++) |
2253 newct->ct_luns[i] = -1; | 2250 newct->ct_luns[i] = UINT32_MAX; |
2254 2255 strlcpy(newct->ct_name, name, sizeof(newct->ct_name)); 2256 if (alias != NULL) 2257 strlcpy(newct->ct_alias, alias, sizeof(newct->ct_alias)); 2258 refcount_init(&newct->ct_refcount, 1); 2259 newct->ct_softc = softc; 2260 TAILQ_INSERT_TAIL(&softc->targets, newct, ct_next); 2261 mtx_unlock(&softc->lock); 2262 2263 return (newct); 2264} 2265 2266/* 2267 * Takes LUN from the target space and returns LUN from the CTL space. 2268 */ 2269static uint32_t | 2251 2252 strlcpy(newct->ct_name, name, sizeof(newct->ct_name)); 2253 if (alias != NULL) 2254 strlcpy(newct->ct_alias, alias, sizeof(newct->ct_alias)); 2255 refcount_init(&newct->ct_refcount, 1); 2256 newct->ct_softc = softc; 2257 TAILQ_INSERT_TAIL(&softc->targets, newct, ct_next); 2258 mtx_unlock(&softc->lock); 2259 2260 return (newct); 2261} 2262 2263/* 2264 * Takes LUN from the target space and returns LUN from the CTL space. 2265 */ 2266static uint32_t |
2270cfiscsi_map_lun(void *arg, uint32_t lun) | 2267cfiscsi_lun_map(void *arg, uint32_t lun) |
2271{ | 2268{ |
2272 struct cfiscsi_session *cs; | 2269 struct cfiscsi_target *ct = arg; |
2273 | 2270 |
2274 cs = arg; 2275 | |
2276 if (lun >= CTL_MAX_LUNS) { 2277 CFISCSI_DEBUG("requested lun number %d is higher " 2278 "than maximum %d", lun, CTL_MAX_LUNS - 1); | 2271 if (lun >= CTL_MAX_LUNS) { 2272 CFISCSI_DEBUG("requested lun number %d is higher " 2273 "than maximum %d", lun, CTL_MAX_LUNS - 1); |
2279 return (0xffffffff); | 2274 return (UINT32_MAX); |
2280 } | 2275 } |
2281 2282 if (cs->cs_target->ct_luns[lun] < 0) 2283 return (0xffffffff); 2284 2285 return (cs->cs_target->ct_luns[lun]); | 2276 return (ct->ct_luns[lun]); |
2286} 2287 2288static int 2289cfiscsi_target_set_lun(struct cfiscsi_target *ct, 2290 unsigned long lun_id, unsigned long ctl_lun_id) 2291{ 2292 2293 if (lun_id >= CTL_MAX_LUNS) { 2294 CFISCSI_WARN("requested lun number %ld is higher " 2295 "than maximum %d", lun_id, CTL_MAX_LUNS - 1); 2296 return (-1); 2297 } 2298 | 2277} 2278 2279static int 2280cfiscsi_target_set_lun(struct cfiscsi_target *ct, 2281 unsigned long lun_id, unsigned long ctl_lun_id) 2282{ 2283 2284 if (lun_id >= CTL_MAX_LUNS) { 2285 CFISCSI_WARN("requested lun number %ld is higher " 2286 "than maximum %d", lun_id, CTL_MAX_LUNS - 1); 2287 return (-1); 2288 } 2289 |
2299 if (ct->ct_luns[lun_id] >= 0) { | 2290 if (ct->ct_luns[lun_id] < CTL_MAX_LUNS) { |
2300 /* 2301 * CTL calls cfiscsi_lun_enable() twice for each LUN - once 2302 * when the LUN is created, and a second time just before 2303 * the port is brought online; don't emit warnings 2304 * for that case. 2305 */ 2306 if (ct->ct_luns[lun_id] == ctl_lun_id) 2307 return (0); --- 52 unchanged lines hidden (view full) --- 2360 struct cfiscsi_target *ct; 2361 int i; 2362 2363 ct = (struct cfiscsi_target *)arg; 2364 softc = ct->ct_softc; 2365 2366 mtx_lock(&softc->lock); 2367 for (i = 0; i < CTL_MAX_LUNS; i++) { | 2291 /* 2292 * CTL calls cfiscsi_lun_enable() twice for each LUN - once 2293 * when the LUN is created, and a second time just before 2294 * the port is brought online; don't emit warnings 2295 * for that case. 2296 */ 2297 if (ct->ct_luns[lun_id] == ctl_lun_id) 2298 return (0); --- 52 unchanged lines hidden (view full) --- 2351 struct cfiscsi_target *ct; 2352 int i; 2353 2354 ct = (struct cfiscsi_target *)arg; 2355 softc = ct->ct_softc; 2356 2357 mtx_lock(&softc->lock); 2358 for (i = 0; i < CTL_MAX_LUNS; i++) { |
2368 if (ct->ct_luns[i] < 0) 2369 continue; | |
2370 if (ct->ct_luns[i] != lun_id) 2371 continue; | 2359 if (ct->ct_luns[i] != lun_id) 2360 continue; |
2372 ct->ct_luns[lun_id] = -1; | 2361 ct->ct_luns[i] = UINT32_MAX; |
2373 break; 2374 } 2375 mtx_unlock(&softc->lock); 2376 return (0); 2377} 2378 2379static void 2380cfiscsi_datamove_in(union ctl_io *io) --- 507 unchanged lines hidden --- | 2362 break; 2363 } 2364 mtx_unlock(&softc->lock); 2365 return (0); 2366} 2367 2368static void 2369cfiscsi_datamove_in(union ctl_io *io) --- 507 unchanged lines hidden --- |