aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/ctl/ctl_frontend_iscsi.c
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2015-10-24 17:24:19 +0000
committerAlexander Motin <mav@FreeBSD.org>2015-10-24 17:24:19 +0000
commit59f063d549d6d372d4deed9042f27cc8cf93d68a (patch)
tree583839f3d95703c929d533134d89691d48b24213 /sys/cam/ctl/ctl_frontend_iscsi.c
parentc91d99bf1c4eba7fc355823e33376a05cf420b8c (diff)
downloadsrc-59f063d549d6d372d4deed9042f27cc8cf93d68a.tar.gz
src-59f063d549d6d372d4deed9042f27cc8cf93d68a.zip
Give CTL support for PIM_EXTLUNS when talking to CAM.
CTL itself still lives in flat LUN space, but it can generate extended numbers if CAM SIM reports such capability.
Notes
Notes: svn path=/head/; revision=289881
Diffstat (limited to 'sys/cam/ctl/ctl_frontend_iscsi.c')
-rw-r--r--sys/cam/ctl/ctl_frontend_iscsi.c61
1 files changed, 3 insertions, 58 deletions
diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c
index 30cca91efca9..07b9687b82a6 100644
--- a/sys/cam/ctl/ctl_frontend_iscsi.c
+++ b/sys/cam/ctl/ctl_frontend_iscsi.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/condvar.h>
+#include <sys/endian.h>
#include <sys/file.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
@@ -416,62 +417,6 @@ cfiscsi_pdu_queue(struct icl_pdu *response)
CFISCSI_SESSION_UNLOCK(cs);
}
-static uint32_t
-cfiscsi_decode_lun(uint64_t encoded)
-{
- uint8_t lun[8];
- uint32_t result;
-
- /*
- * The LUN field in iSCSI PDUs may look like an ordinary 64 bit number,
- * but is in fact an evil, multidimensional structure defined
- * in SCSI Architecture Model 5 (SAM-5), section 4.6.
- */
- memcpy(lun, &encoded, sizeof(lun));
- switch (lun[0] & 0xC0) {
- case 0x00:
- if ((lun[0] & 0x3f) != 0 || lun[2] != 0 || lun[3] != 0 ||
- lun[4] != 0 || lun[5] != 0 || lun[6] != 0 || lun[7] != 0) {
- CFISCSI_WARN("malformed LUN "
- "(peripheral device addressing method): 0x%jx",
- (uintmax_t)encoded);
- result = 0xffffffff;
- break;
- }
- result = lun[1];
- break;
- case 0x40:
- if (lun[2] != 0 || lun[3] != 0 || lun[4] != 0 || lun[5] != 0 ||
- lun[6] != 0 || lun[7] != 0) {
- CFISCSI_WARN("malformed LUN "
- "(flat address space addressing method): 0x%jx",
- (uintmax_t)encoded);
- result = 0xffffffff;
- break;
- }
- result = ((lun[0] & 0x3f) << 8) + lun[1];
- break;
- case 0xC0:
- if (lun[0] != 0xD2 || lun[4] != 0 || lun[5] != 0 ||
- lun[6] != 0 || lun[7] != 0) {
- CFISCSI_WARN("malformed LUN (extended flat "
- "address space addressing method): 0x%jx",
- (uintmax_t)encoded);
- result = 0xffffffff;
- break;
- }
- result = (lun[1] << 16) + (lun[2] << 8) + lun[3];
- break;
- default:
- CFISCSI_WARN("unsupported LUN format 0x%jx",
- (uintmax_t)encoded);
- result = 0xffffffff;
- break;
- }
-
- return (result);
-}
-
static void
cfiscsi_pdu_handle_nop_out(struct icl_pdu *request)
{
@@ -566,7 +511,7 @@ cfiscsi_pdu_handle_scsi_command(struct icl_pdu *request)
io->io_hdr.io_type = CTL_IO_SCSI;
io->io_hdr.nexus.initid = cs->cs_ctl_initid;
io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port;
- io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhssc->bhssc_lun);
+ io->io_hdr.nexus.targ_lun = ctl_decode_lun(be64toh(bhssc->bhssc_lun));
io->scsiio.tag_num = bhssc->bhssc_initiator_task_tag;
switch ((bhssc->bhssc_flags & BHSSC_FLAGS_ATTR)) {
case BHSSC_FLAGS_ATTR_UNTAGGED:
@@ -622,7 +567,7 @@ cfiscsi_pdu_handle_task_request(struct icl_pdu *request)
io->io_hdr.io_type = CTL_IO_TASK;
io->io_hdr.nexus.initid = cs->cs_ctl_initid;
io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port;
- io->io_hdr.nexus.targ_lun = cfiscsi_decode_lun(bhstmr->bhstmr_lun);
+ io->io_hdr.nexus.targ_lun = ctl_decode_lun(be64toh(bhstmr->bhstmr_lun));
io->taskio.tag_type = CTL_TAG_SIMPLE; /* XXX */
switch (bhstmr->bhstmr_function & ~0x80) {