commit bc8bab676c0a34899baa2384e8c073118c4df5ec
Author: Andreas Eversberg <jolly@eversberg.eu>
Date:   Sat Nov 11 15:43:10 2023 +0100

    EWSD patch for ZuluSCSI

diff --git a/lib/SCSI2SD/include/scsi2sd.h b/lib/SCSI2SD/include/scsi2sd.h
index d94f089..f0d4daf 100755
--- a/lib/SCSI2SD/include/scsi2sd.h
+++ b/lib/SCSI2SD/include/scsi2sd.h
@@ -84,7 +84,8 @@ typedef enum
 	S2S_CFG_QUIRKS_OMTI = 2,
 	S2S_CFG_QUIRKS_XEBEC = 4,
 	S2S_CFG_QUIRKS_VMS = 8,
-	S2S_CFG_QUIRKS_EMU = 9
+	S2S_CFG_QUIRKS_EMU = 9,
+	S2S_CFG_QUIRKS_EWSD = 10
 } S2S_CFG_QUIRKS;
 
 typedef enum
diff --git a/lib/SCSI2SD/src/firmware/scsi.c b/lib/SCSI2SD/src/firmware/scsi.c
index 4ee01b9..9cad854 100755
--- a/lib/SCSI2SD/src/firmware/scsi.c
+++ b/lib/SCSI2SD/src/firmware/scsi.c
@@ -139,6 +139,11 @@ void process_Status()
 {
 	scsiEnterPhase(STATUS);
 
+	if (scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_EWSD)
+	{
+		s2s_delay_ms(1);
+	}
+
 	uint8_t message;
 
 	uint8_t control = scsiDev.cdb[scsiDev.cdbLen - 1];
@@ -517,6 +522,12 @@ static void process_Command()
 			scsiDev.data[7] = 10; // additional length
 			scsiDev.data[12] = scsiDev.target->sense.asc >> 8;
 			scsiDev.data[13] = scsiDev.target->sense.asc;
+			if ((scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_EWSD))
+			{
+				/* EWSD seems not to want something behind additional length. (8 + 0x0e = 22) */
+				allocLength=22;
+				scsiDev.data[7] = 0x0e;
+			}
 		}
 
 		// Silently truncate results. SCSI-2 spec 8.2.14.
@@ -531,8 +542,15 @@ static void process_Command()
 	// on receiving the unit attention response on boot, thus
 	// triggering another unit attention condition.
 	else if (scsiDev.target->unitAttention &&
-		(scsiDev.boardCfg.flags & S2S_CFG_ENABLE_UNIT_ATTENTION))
+		scsiDev.target->unitAttention_stop == 0 &&
+		((scsiDev.boardCfg.flags & S2S_CFG_ENABLE_UNIT_ATTENTION) ||
+		(scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_EWSD)))
 	{
+		/* EWSD requires unitAttention to be sent only once. */
+		if (scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_EWSD)
+		{
+			scsiDev.target->unitAttention_stop = 1;
+		}
 		scsiDev.target->sense.code = UNIT_ATTENTION;
 		scsiDev.target->sense.asc = scsiDev.target->unitAttention;
 
@@ -1257,7 +1275,13 @@ void scsiInit()
 		scsiDev.targets[i].reserverId = -1;
 		if (firstInit)
 		{
-			scsiDev.targets[i].unitAttention = POWER_ON_RESET;
+			if ((cfg->deviceType == S2S_CFG_MO) && (scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_EWSD))
+			{
+				scsiDev.targets[i].unitAttention = POWER_ON_RESET_OR_BUS_DEVICE_RESET_OCCURRED;
+			} else
+			{
+				scsiDev.targets[i].unitAttention = POWER_ON_RESET;
+			}
 		}
 		else
 		{
diff --git a/lib/SCSI2SD/src/firmware/scsi.h b/lib/SCSI2SD/src/firmware/scsi.h
index 8c466bc..14c772b 100755
--- a/lib/SCSI2SD/src/firmware/scsi.h
+++ b/lib/SCSI2SD/src/firmware/scsi.h
@@ -102,6 +102,7 @@ typedef struct
 	ScsiSense sense;
 
 	uint16_t unitAttention; // Set to the sense qualifier key to be returned.
+	uint8_t unitAttention_stop; // Indicates if unit attention has to be stopped.
 
 	// Only let the reserved initiator talk to us.
 	// A 3rd party may be sending the RESERVE/RELEASE commands
diff --git a/src/ZuluSCSI_disk.cpp b/src/ZuluSCSI_disk.cpp
index 7163ef9..6eda692 100644
--- a/src/ZuluSCSI_disk.cpp
+++ b/src/ZuluSCSI_disk.cpp
@@ -1200,6 +1200,10 @@ static void doReadCapacity()
     {
         uint32_t highestBlock = capacity - 1;
 
+	if (pmi && scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_EWSD)
+	{
+		highestBlock = 0x00001053;
+	}
         scsiDev.data[0] = highestBlock >> 24;
         scsiDev.data[1] = highestBlock >> 16;
         scsiDev.data[2] = highestBlock >> 8;
diff --git a/zuluscsi.ini b/zuluscsi.ini
index a369603..d6c6d4f 100644
--- a/zuluscsi.ini
+++ b/zuluscsi.ini
@@ -17,7 +17,7 @@
 # The PhyMode parameter has no effect on ZuluSCSI RP2040-based platforms, as there is only one PHY mode.
 
 # Settings that can be needed for compatibility with some hosts
-#Quirks = 0   # 0: Standard, 1: Apple, 2: OMTI, 4: Xebec, 8: VMS
+#Quirks = 0   # 0: Standard, 1: Apple, 2: OMTI, 4: Xebec, 8: VMS, 9: EMU, 10: EWSD
 #EnableUnitAttention = 0 # Post UNIT_ATTENTION status on power-on or SD card hotplug
 #EnableSCSI2 = 1 # Enable faster speeds of SCSI2
 #EnableSelLatch = 0 # For Philips P2000C and other devices that release SEL signal before BSY
