Use the LUN provided in IDENTIFY messages in preference to the CDB.
authorMichael McMaster <michael@codesrc.com>
Wed, 23 Jul 2014 20:52:34 +0000 (06:52 +1000)
committerMichael McMaster <michael@codesrc.com>
Wed, 23 Jul 2014 20:52:34 +0000 (06:52 +1000)
This fixes extra LUNS being seen by VMS.

CHANGELOG
software/SCSI2SD/src/config.c
software/SCSI2SD/src/diagnostic.c
software/SCSI2SD/src/inquiry.c
software/SCSI2SD/src/scsi.c
software/SCSI2SD/src/scsi.h

index 3a4442a..5e6bc72 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+201407XX               3.6
+       - Fix handling requests for LUNs other than 0 from SCSI-2 hosts.
+
 20140718               3.5.2
        - Fix blank SCSI ID in scsi2sd-config output.
 
index 81fdef0..12600de 100755 (executable)
@@ -28,7 +28,7 @@
 \r
 // CYDEV_EEPROM_ROW_SIZE == 16.\r
 static const char magic[CYDEV_EEPROM_ROW_SIZE] = "codesrc_00000002";\r
-static const uint16_t FIRMWARE_VERSION = 0x0352;\r
+static const uint16_t FIRMWARE_VERSION = 0x0360;\r
 \r
 // Config shadow RAM (copy of EEPROM)\r
 static Config shadow =\r
@@ -36,7 +36,7 @@ static Config shadow =
        0, // SCSI ID\r
        " codesrc", // vendor  (68k Apple Drive Setup: Set to " SEAGATE")\r
        "         SCSI2SD", //prodId (68k Apple Drive Setup: Set to "          ST225N")\r
-       " 3.5", // revision (68k Apple Drive Setup: Set to "1.0 ")\r
+       " 3.6", // revision (68k Apple Drive Setup: Set to "1.0 ")\r
        1, // enable parity\r
        1, // enable unit attention,\r
        0, // RESERVED\r
index 17721c2..45f5a0b 100755 (executable)
@@ -123,9 +123,8 @@ void scsiReceiveDiagnostic()
        }\r
 \r
        {\r
-               uint8 lun = scsiDev.cdb[1] >> 5;\r
                // Set the first byte to indicate LUN presence.\r
-               if (lun) // We only support lun 0\r
+               if (scsiDev.lun) // We only support lun 0\r
                {\r
                        scsiDev.data[0] = 0x7F;\r
                }\r
index da03eba..b90eb71 100755 (executable)
@@ -95,7 +95,6 @@ void scsiInquiry()
 {\r
        uint8 evpd = scsiDev.cdb[1] & 1; // enable vital product data.\r
        uint8 pageCode = scsiDev.cdb[2];\r
-       uint8 lun = scsiDev.cdb[1] >> 5;\r
        uint32 allocationLength = scsiDev.cdb[4];\r
        if (allocationLength == 0) allocationLength = 256;\r
        \r
@@ -180,7 +179,7 @@ void scsiInquiry()
        }\r
 \r
        // Set the first byte to indicate LUN presence.\r
-       if (lun) // We only support lun 0\r
+       if (scsiDev.lun) // We only support lun 0\r
        {\r
                scsiDev.data[0] = 0x7F;\r
        }\r
index d66099c..5be5a84 100755 (executable)
@@ -225,7 +225,6 @@ static void process_Command()
 {\r
        int group;\r
        uint8 command;\r
-       uint8 lun;\r
        uint8 control;\r
 \r
        scsiEnterPhase(COMMAND);\r
@@ -239,7 +238,13 @@ static void process_Command()
        scsiRead(scsiDev.cdb + 1, scsiDev.cdbLen - 1);\r
 \r
        command = scsiDev.cdb[0];\r
-       lun = scsiDev.cdb[1] >> 5;\r
+\r
+       // Prefer LUN's set by IDENTIFY messages for newer hosts.\r
+       if (scsiDev.lun < 0)\r
+       {\r
+               scsiDev.lun = scsiDev.cdb[1] >> 5;\r
+       }\r
+\r
        control = scsiDev.cdb[scsiDev.cdbLen - 1];\r
 \r
        scsiDev.cmdCount++;\r
@@ -313,7 +318,7 @@ static void process_Command()
 \r
                enter_Status(CHECK_CONDITION);\r
        }\r
-       else if (lun)\r
+       else if (scsiDev.lun)\r
        {\r
                scsiDev.sense.code = ILLEGAL_REQUEST;\r
                scsiDev.sense.asc = LOGICAL_UNIT_NOT_SUPPORTED;\r
@@ -424,6 +429,7 @@ static void scsiReset()
        scsiDev.phase = BUS_FREE;\r
        scsiDev.atnFlag = 0;\r
        scsiDev.resetFlag = 0;\r
+       scsiDev.lun = -1;\r
 \r
        if (scsiDev.unitAttention != POWER_ON_RESET)\r
        {\r
@@ -458,6 +464,7 @@ static void enter_SelectionPhase()
        scsiDev.dataLen = 0;\r
        scsiDev.status = GOOD;\r
        scsiDev.phase = SELECTION;\r
+       scsiDev.lun = -1;\r
 \r
        transfer.blocks = 0;\r
        transfer.currentBlock = 0;\r
@@ -626,15 +633,12 @@ static void process_MessageOut()
                // IDENTIFY\r
                // We don't disconnect, so ignore disconnect privilege.\r
                if ((scsiDev.msgOut & 0x18) || // Reserved bits set.\r
-                       (scsiDev.msgOut & 0x20)  || // We don't have any target routines!\r
-                       (scsiDev.msgOut & 0x7) // We only support LUN 0!\r
-                       )\r
+                       (scsiDev.msgOut & 0x20))  // We don't have any target routines!\r
                {\r
-                       //scsiDev.sense.code = ILLEGAL_REQUEST;\r
-                       //scsiDev.sense.asc = INVALID_BITS_IN_IDENTIFY_MESSAGE;\r
-                       //enter_Status(CHECK_CONDITION);\r
                        messageReject();\r
                }\r
+\r
+               scsiDev.lun = scsiDev.msgOut & 0x7;\r
                //scsiDev.allowDisconnect = scsiDev.msgOut & 0x40;\r
        }\r
        else if (scsiDev.msgOut >= 0x20 && scsiDev.msgOut <= 0x2F)\r
index 59ba02e..b0f5b84 100755 (executable)
@@ -84,6 +84,7 @@ typedef struct
 
        uint8 cdb[12]; // command descriptor block
        uint8 cdbLen; // 6, 10, or 12 byte message.
+       int8 lun; // Target lun, set by IDENTIFY message.
 
        // Only let the reserved initiator talk to us.
        // A 3rd party may be sending the RESERVE/RELEASE commands