Track start/stop status per virtual scsi device.
authorMichael McMaster <michael@codesrc.com>
Sat, 15 Jan 2022 10:03:02 +0000 (20:03 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 15 Jan 2022 10:03:02 +0000 (20:03 +1000)
src/firmware/disk.c
src/firmware/disk.h
src/firmware/scsi.c
src/firmware/scsi.h
src/firmware/sd.c

index af802f10d3a8dc96517e01ead43eca92d4e3ebd6..f68cb2427188623938dce231e9858d87475c563e 100755 (executable)
@@ -310,11 +310,12 @@ static void doSeek(uint32_t lba)
 static int doTestUnitReady()\r
 {\r
     int ready = 1;\r
-    if (likely(blockDev.state == (DISK_STARTED | DISK_PRESENT | DISK_INITIALISED)))\r
+    if (likely(blockDev.state == (DISK_PRESENT | DISK_INITIALISED) &&\r
+               scsiDev.target->started))\r
     {\r
         // nothing to do.\r
     }\r
-    else if (unlikely(!(blockDev.state & DISK_STARTED)))\r
+    else if (unlikely(!scsiDev.target->started))\r
     {\r
         ready = 0;\r
         scsiDev.status = CHECK_CONDITION;\r
@@ -361,7 +362,7 @@ int scsiDiskCommand()
         }\r
         else if (start)\r
         {\r
-            blockDev.state = blockDev.state | DISK_STARTED;\r
+            scsiDev.target->started = 1;\r
             if (!(blockDev.state & DISK_INITIALISED))\r
             {\r
                 doSdInit();\r
@@ -369,7 +370,7 @@ int scsiDiskCommand()
         }\r
         else\r
         {\r
-            blockDev.state &= ~DISK_STARTED;\r
+            scsiDev.target->started = 0;\r
         }\r
     }\r
     else if (unlikely(command == 0x00))\r
@@ -988,8 +989,5 @@ void scsiDiskReset()
 void scsiDiskInit()\r
 {\r
     scsiDiskReset();\r
-\r
-    // Don't require the host to send us a START STOP UNIT command\r
-    blockDev.state = DISK_STARTED;\r
 }\r
 \r
index b1f958fb9352e8f91d9ebf6b6cf5cc02355a2844..e2003bf0a27d070d2fb983fe22fdbba9bc99362e 100755 (executable)
@@ -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.
index d4077b9f0a3d600d5b4ac4a1448157c83cf8a78f..930e87d93217d63f6a4c80b260c83fa03c547f46 100755 (executable)
@@ -1164,6 +1164,12 @@ void scsiInit()
 \r
                scsiDev.targets[i].syncOffset = 0;\r
                scsiDev.targets[i].syncPeriod = 0;\r
+\r
+               // Always "start" the device. Many systems (eg. Apple System 7)\r
+               // won't respond properly to\r
+               // LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED sense\r
+               // code\r
+               scsiDev.targets[i].started = 1;\r
        }\r
        firstInit = 0;\r
 }\r
index 64353ada8d845688ec080251ecc81294750e9d7c..77d67fc0a50f08d487eee94400aefbf6b284e0e6 100755 (executable)
@@ -101,6 +101,8 @@ typedef struct
 
        uint8_t syncOffset;
        uint8_t syncPeriod;
+
+       uint8_t started; // Controlled by START STOP UNIT
 } TargetState;
 
 typedef struct
index 78a94fe86f789ff66bf5e146a6c7eacaccc368a0..e24672111968975ed72ebd93617deccc373c90c7 100755 (executable)
@@ -171,13 +171,6 @@ int sdInit()
                                        blockDev.state &= ~DISK_WP;\r
                                }\r
 \r
-                               // Always "start" the device. Many systems (eg. Apple System 7)\r
-                               // won't respond properly to\r
-                               // LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED sense\r
-                               // code, even if they stopped it first with\r
-                               // START STOP UNIT command.\r
-                               blockDev.state |= DISK_STARTED;\r
-\r
                                result = 1;\r
 \r
                                s2s_ledOff();\r