Add scsi mode page 0 support
authorMichael McMaster <michael@codesrc.com>
Wed, 22 May 2019 10:01:44 +0000 (20:01 +1000)
committerMichael McMaster <michael@codesrc.com>
Wed, 22 May 2019 10:01:44 +0000 (20:01 +1000)
software/SCSI2SD/src/inquiry.c
software/SCSI2SD/src/inquiry.h
software/SCSI2SD/src/mode.c

index 5e006ca..463b8ea 100755 (executable)
@@ -157,6 +157,7 @@ void scsiInquiry()
                        memcpy(&scsiDev.data[8], config->vendor, sizeof(config->vendor));
                        memcpy(&scsiDev.data[16], config->prodId, sizeof(config->prodId));
                        memcpy(&scsiDev.data[32], config->revision, sizeof(config->revision));
+
                        scsiDev.dataLen = sizeof(StandardResponse) +
                                sizeof(config->vendor) +
                                sizeof(config->prodId) +
@@ -229,20 +230,19 @@ void scsiInquiry()
                scsiDev.dataLen = allocationLength;
 
                // Set the device type as needed.
+               scsiDev.data[0] = getDeviceTypeQualifier();
+
                switch (scsiDev.target->cfg->deviceType)
                {
                case CONFIG_OPTICAL:
-                       scsiDev.data[0] = 0x05; // device type
                        scsiDev.data[1] |= 0x80; // Removable bit.
                        break;
 
                case CONFIG_SEQUENTIAL:
-                       scsiDev.data[0] = 0x01; // device type
                        scsiDev.data[1] |= 0x80; // Removable bit.
                        break;
                        
                case CONFIG_MO:
-                       scsiDev.data[0] = 0x07; // device type
                        scsiDev.data[1] |= 0x80; // Removable bit.
                        break;
 
@@ -254,6 +254,7 @@ void scsiInquiry()
                        // Accept defaults for a fixed disk.
                        break;
                }
+
        }
 
        // Set the first byte to indicate LUN presence.
@@ -263,3 +264,31 @@ void scsiInquiry()
        }
 }
 
+uint8_t getDeviceTypeQualifier()
+{
+       // Set the device type as needed.
+       switch (scsiDev.target->cfg->deviceType)
+       {
+       case CONFIG_OPTICAL:
+               return 0x05;
+               break;
+
+       case CONFIG_SEQUENTIAL:
+               return 0x01;
+               break;
+
+       case CONFIG_MO:
+               return 0x07;
+               break;
+
+       case CONFIG_FLOPPY_14MB:
+       case CONFIG_REMOVEABLE:
+               return 0;
+               break;
+
+       default:
+               // Accept defaults for a fixed disk.
+               return 0;
+       }
+}
+
index c707b27..0e0909c 100755 (executable)
@@ -19,4 +19,6 @@
 
 void scsiInquiry(void);
 
+uint8_t getDeviceTypeQualifier(void);
+
 #endif
index 95d00e9..bd9ccc2 100755 (executable)
 #include "scsi.h"\r
 #include "mode.h"\r
 #include "disk.h"\r
+#include "inquiry.h"\r
 \r
 #include <string.h>\r
 \r
+// "Vendor" defined page which was included by Seagate, and required for\r
+// Amiga 500 using DKB SpitFire controller.\r
+static const uint8 OperatingPage[] =\r
+{\r
+0x00, // Page code\r
+0x02, // Page length\r
+\r
+// Bit 4 = unit attension (0 = on, 1 = off).\r
+// Bit 7 = usage bit, EEPROM life exceeded warning = 1.\r
+0x80, \r
+\r
+// Bit 7 = reserved.\r
+// Bits 0:6: Device type qualifier, as per Inquiry data\r
+0x00\r
+};\r
+\r
 static const uint8 ReadWriteErrorRecoveryPage[] =\r
 {\r
 0x01, // Page code\r
@@ -518,6 +535,21 @@ static void doModeSense(
                idx += sizeof(AppleVendorPage);\r
        }\r
 \r
+       // SCSI 2 standard says page 0 is always last.\r
+       if (pageCode == 0x00 || pageCode == 0x3F)\r
+       {\r
+               pageFound = 1;\r
+               pageIn(pc, idx, OperatingPage, sizeof(OperatingPage));\r
+\r
+               // Note inverted logic for the flag.\r
+               scsiDev.data[idx+2] =\r
+                       (scsiDev.boardCfg.flags & CONFIG_ENABLE_UNIT_ATTENTION) ? 0x80 : 0x90;\r
+\r
+               scsiDev.data[idx+3] = getDeviceTypeQualifier();\r
+\r
+               idx += sizeof(OperatingPage);\r
+       }\r
+\r
        if (!pageFound)\r
        {\r
                // Unknown Page Code\r