From d88371b5adc31773bd3f034bc7fbe1e38e58bc5a Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Sat, 15 Jan 2022 20:03:02 +1000 Subject: [PATCH] Track start/stop status per virtual scsi device. --- src/firmware/disk.c | 12 +++++------- src/firmware/disk.h | 4 +++- src/firmware/scsi.c | 6 ++++++ src/firmware/scsi.h | 2 ++ src/firmware/sd.c | 7 ------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/firmware/disk.c b/src/firmware/disk.c index af802f10..f68cb242 100755 --- a/src/firmware/disk.c +++ b/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; } diff --git a/src/firmware/disk.h b/src/firmware/disk.h index b1f958fb..e2003bf0 100755 --- a/src/firmware/disk.h +++ b/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. diff --git a/src/firmware/scsi.c b/src/firmware/scsi.c index d4077b9f..930e87d9 100755 --- a/src/firmware/scsi.c +++ b/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; } diff --git a/src/firmware/scsi.h b/src/firmware/scsi.h index 64353ada..77d67fc0 100755 --- a/src/firmware/scsi.h +++ b/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 diff --git a/src/firmware/sd.c b/src/firmware/sd.c index 78a94fe8..e2467211 100755 --- a/src/firmware/sd.c +++ b/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(); -- 2.38.5