Parcourir la source

Add scsi mode page 0 support (merge from v5)

Michael McMaster il y a 6 ans
Parent
commit
2b2a04d89c

+ 31 - 3
lib/SCSI2SD/src/firmware/inquiry.c

@@ -171,20 +171,19 @@ void s2s_scsiInquiry()
 		scsiDev.dataLen = allocationLength;
 
 		// Set the device type as needed.
+		scsiDev.data[0] = getDeviceTypeQualifier();
+
 		switch (scsiDev.target->cfg->deviceType)
 		{
 		case S2S_CFG_OPTICAL:
-			scsiDev.data[0] = 0x05; // device type
 			scsiDev.data[1] |= 0x80; // Removable bit.
 			break;
 
 		case S2S_CFG_SEQUENTIAL:
-			scsiDev.data[0] = 0x01; // device type
 			scsiDev.data[1] |= 0x80; // Removable bit.
 			break;
 
 		case S2S_CFG_MO:
-			scsiDev.data[0] = 0x07; // device type
 			scsiDev.data[1] |= 0x80; // Removable bit.
 			break;
 
@@ -227,3 +226,32 @@ uint32_t s2s_getStandardInquiry(
 		sizeof(cfg->prodId) +
 		sizeof(cfg->revision);
 }
+
+uint8_t getDeviceTypeQualifier()
+{
+	// Set the device type as needed.
+	switch (scsiDev.target->cfg->deviceType)
+	{
+	case S2S_CFG_OPTICAL:
+		return 0x05;
+		break;
+
+	case S2S_CFG_SEQUENTIAL:
+		return 0x01;
+		break;
+
+	case S2S_CFG_MO:
+		return 0x07;
+		break;
+
+	case S2S_CFG_FLOPPY_14MB:
+	case S2S_CFG_REMOVEABLE:
+		return 0;
+		break;
+
+	default:
+		// Accept defaults for a fixed disk.
+		return 0;
+	}
+}
+

+ 2 - 0
lib/SCSI2SD/src/firmware/inquiry.h

@@ -19,5 +19,7 @@
 
 void s2s_scsiInquiry(void);
 uint32_t s2s_getStandardInquiry(const S2S_TargetCfg* cfg, uint8_t* out, uint32_t maxlen);
+uint8_t getDeviceTypeQualifier(void);
+
 
 #endif

+ 32 - 0
lib/SCSI2SD/src/firmware/mode.c

@@ -19,9 +19,26 @@
 #include "scsi.h"
 #include "mode.h"
 #include "disk.h"
+#include "inquiry.h"
 
 #include <string.h>
 
+// "Vendor" defined page which was included by Seagate, and required for\r
+// Amiga 500 using DKB SpitFire controller.\r
+static const uint8_t OperatingPage[] =
+{
+0x00, // Page code
+0x02, // Page length
+
+// Bit 4 = unit attension (0 = on, 1 = off).
+// Bit 7 = usage bit, EEPROM life exceeded warning = 1.
+0x80, 
+
+// Bit 7 = reserved.
+// Bits 0:6: Device type qualifier, as per Inquiry data
+0x00
+};
+
 static const uint8_t ReadWriteErrorRecoveryPage[] =
 {
 0x01, // Page code
@@ -508,6 +525,21 @@ static void doModeSense(
 		idx += sizeof(CCSCachingPage);
 	}
 
+	// SCSI 2 standard says page 0 is always last.
+	if (pageCode == 0x00 || pageCode == 0x3F)
+	{
+		pageFound = 1;
+		pageIn(pc, idx, OperatingPage, sizeof(OperatingPage));
+
+		// Note inverted logic for the flag.
+		scsiDev.data[idx+2] =
+			(scsiDev.boardCfg.flags & S2S_CFG_ENABLE_UNIT_ATTENTION) ? 0x80 : 0x90;
+
+		scsiDev.data[idx+3] = getDeviceTypeQualifier();
+
+		idx += sizeof(OperatingPage);
+	}
+
 	if (!pageFound)
 	{
 		// Unknown Page Code