Browse Source

Track start/stop status per virtual scsi device.

Michael McMaster 3 năm trước cách đây
mục cha
commit
cc24654f8b

+ 5 - 7
lib/SCSI2SD/src/firmware/disk.c

@@ -310,11 +310,12 @@ static void doSeek(uint32_t lba)
 static int doTestUnitReady()
 {
     int ready = 1;
-    if (likely(blockDev.state == (DISK_STARTED | DISK_PRESENT | DISK_INITIALISED)))
+    if (likely(blockDev.state == (DISK_PRESENT | DISK_INITIALISED) &&
+		scsiDev.target->started))
     {
         // nothing to do.
     }
-    else if (unlikely(!(blockDev.state & DISK_STARTED)))
+    else if (unlikely(!scsiDev.target->started))
     {
         ready = 0;
         scsiDev.status = CHECK_CONDITION;
@@ -361,7 +362,7 @@ int scsiDiskCommand()
         }
         else if (start)
         {
-            blockDev.state = blockDev.state | DISK_STARTED;
+            scsiDev.target->started = 1;
             if (!(blockDev.state & DISK_INITIALISED))
             {
                 doSdInit();
@@ -369,7 +370,7 @@ int scsiDiskCommand()
         }
         else
         {
-            blockDev.state &= ~DISK_STARTED;
+            scsiDev.target->started = 0;
         }
     }
     else if (unlikely(command == 0x00))
@@ -988,8 +989,5 @@ void scsiDiskReset()
 void scsiDiskInit()
 {
     scsiDiskReset();
-
-    // Don't require the host to send us a START STOP UNIT command
-    blockDev.state = DISK_STARTED;
 }
 

+ 3 - 1
lib/SCSI2SD/src/firmware/disk.h

@@ -19,7 +19,9 @@
 
 typedef enum
 {
-	DISK_STARTED = 1,     // Controlled via START STOP UNIT
+	// DISK_STARTED is stored per-target now as it's controlled by the
+	// START STOP UNIT command
+	OBSOLETE_DISK_STARTED = 1,
 	DISK_PRESENT = 2,     // SD card is physically present
 	DISK_INITIALISED = 4, // SD card responded to init sequence
 	DISK_WP = 8           // Write-protect.

+ 6 - 0
lib/SCSI2SD/src/firmware/scsi.c

@@ -1164,6 +1164,12 @@ void scsiInit()
 
 		scsiDev.targets[i].syncOffset = 0;
 		scsiDev.targets[i].syncPeriod = 0;
+
+		// Always "start" the device. Many systems (eg. Apple System 7)
+		// won't respond properly to
+		// LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED sense
+		// code
+		scsiDev.targets[i].started = 1;
 	}
 	firstInit = 0;
 }

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

@@ -101,6 +101,8 @@ typedef struct
 
 	uint8_t syncOffset;
 	uint8_t syncPeriod;
+
+	uint8_t started; // Controlled by START STOP UNIT
 } TargetState;
 
 typedef struct

+ 0 - 7
lib/SCSI2SD/src/firmware/sd.c

@@ -171,13 +171,6 @@ int sdInit()
 					blockDev.state &= ~DISK_WP;
 				}
 
-				// Always "start" the device. Many systems (eg. Apple System 7)
-				// won't respond properly to
-				// LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED sense
-				// code, even if they stopped it first with
-				// START STOP UNIT command.
-				blockDev.state |= DISK_STARTED;
-
 				result = 1;
 
 				s2s_ledOff();