From 754e8ff88fa1aae235a6e36032410283007027b1 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 21 Jan 2017 06:21:46 +0100 Subject: [PATCH] SCSI incoming mailbox now correctly also rewrites the CCB up to the CDB even if the status is CHECK CONDITION, fixes CD-ROM disc changes when using SCSI; Previous CD-ROM sense is now correctly cleared when a REQUEST SENSE command is performed, fixes detection of disc change after setting the drive to empty first regardless of what bus is used for the CD-ROM. --- src/buslogic.c | 23 +++++++++++++---------- src/cdrom.c | 26 ++++++++++---------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/buslogic.c b/src/buslogic.c index b21b17e08..182765cd5 100644 --- a/src/buslogic.c +++ b/src/buslogic.c @@ -521,7 +521,7 @@ int scsi_base = 0x330; int scsi_dma = 6; int scsi_irq = 11; -int buslogic_do_log = 1; +int buslogic_do_log = 0; int BuslogicCallback = 0; @@ -711,11 +711,8 @@ static void BuslogicMailboxIn(Buslogic_t *Buslogic, uint32_t CCBPointer, CCBU *C CmdBlock->common.TargetStatus = TargetStatus; //Rewrite the CCB up to the CDB. - if ((CmdBlock->common.TargetStatus != 0x02) && (CCBPointer != 0)) - { - BuslogicLog("CCB rewritten to the CDB (pointer %08X, length %i)\n", CCBPointer, offsetof(CCBC, Cdb)); - DMAPageWrite(CCBPointer, CmdBlock, offsetof(CCBC, Cdb)); - } + BuslogicLog("CCB rewritten to the CDB (pointer %08X, length %i)\n", CCBPointer, offsetof(CCBC, Cdb)); + DMAPageWrite(CCBPointer, CmdBlock, offsetof(CCBC, Cdb)); } else { @@ -806,7 +803,7 @@ void BuslogicDataBufferAllocate(BuslogicRequests_t *BuslogicRequests, int Is24bi BuslogicLog("Data Buffer write: length %d, pointer 0x%04X\n", DataLength, DataPointer); if ((BuslogicRequests->CmdBlock.common.ControlByte != 0x03) && DataLength) - { + { if (BuslogicRequests->CmdBlock.common.Opcode == SCATTER_GATHER_COMMAND || BuslogicRequests->CmdBlock.common.Opcode == SCATTER_GATHER_COMMAND_RES) { @@ -1595,10 +1592,16 @@ void BuslogicWrite(uint16_t Port, uint8_t Val, void *p) static uint8_t BuslogicConvertSenseLength(uint8_t RequestSenseLength) { + BuslogicLog("Unconverted Request Sense length %i\n", RequestSenseLength); + if (RequestSenseLength == 0) RequestSenseLength = 14; - else if ((RequestSenseLength >= 1) && (RequestSenseLength < 8)) + else if (RequestSenseLength == 1) RequestSenseLength = 0; + /* else if ((RequestSenseLength > 1) && (RequestSenseLength < 8)) + { + if (!scsi_model) RequestSenseLength = 0; + } */ BuslogicLog("Request Sense length %i\n", RequestSenseLength); @@ -1607,7 +1610,7 @@ static uint8_t BuslogicConvertSenseLength(uint8_t RequestSenseLength) static void BuslogicSenseBufferFree(BuslogicRequests_t *BuslogicRequests, int Copy) { - uint8_t SenseLength = BuslogicConvertSenseLength(BuslogicRequests->CmdBlock.common.RequestSenseLength); + uint8_t SenseLength = BuslogicConvertSenseLength(BuslogicRequests->CmdBlock.common.RequestSenseLength); uint8_t cdrom_id = scsi_cdrom_drives[BuslogicRequests->TargetID][BuslogicRequests->LUN]; uint8_t temp_sense[256]; @@ -1873,7 +1876,7 @@ static int BuslogicProcessMailbox(Buslogic_t *Buslogic) /* Check if the mailbox is actually loaded. */ if (Mailbox32.u.out.ActionCode == MBO_FREE) { - BuslogicLog("No loaded mailbox left\n"); + // BuslogicLog("No loaded mailbox left\n"); if (Buslogic->MailboxOutInterrupts) { diff --git a/src/cdrom.c b/src/cdrom.c index 9612bad08..03671d5a0 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -909,13 +909,10 @@ static void cdrom_data_command_finish(uint8_t id, int len, int block_len, int al cdrom_log("CD-ROM %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", id, cdrom[id].packet_status, cdrom[id].request_length, cdrom[id].packet_len, cdrom[id].pos, cdrom[id].phase); } -static void cdrom_sense_clear(int id, int command, int ignore_ua) +static void cdrom_sense_clear(int id, int command) { - if ((cdrom_sense_key == SENSE_UNIT_ATTENTION) || ignore_ua) - { - cdrom[id].previous_command = command; - cdrom_sense_key = cdrom_asc = cdrom_ascq = 0; - } + cdrom[id].previous_command = command; + cdrom_sense_key = cdrom_asc = cdrom_ascq = 0; } static void cdrom_cmd_error(uint8_t id) @@ -1469,15 +1466,16 @@ int cdrom_pre_execution_check(uint8_t id, uint8_t *cdb) disc changes. */ cdrom[id].unit_attention = 0; } - + /* If the UNIT ATTENTION condition is set and the command does not allow execution under it, error out and report the condition. */ if (cdrom[id].unit_attention == 1) { - // cdrom_log("CD-ROM %i: Unit attention now 2\n", id); - cdrom[id].unit_attention = 2; + /* Only increment the unit attention phase if the command can not pass through it. */ if (!(cdrom_command_flags[cdb[0]] & ALLOW_UA)) { + // cdrom_log("CD-ROM %i: Unit attention now 2\n", id); + cdrom[id].unit_attention = 2; cdrom_log("CD-ROM %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", id, cdb[0]); cdrom_unit_attention(id); return 0; @@ -1496,7 +1494,7 @@ int cdrom_pre_execution_check(uint8_t id, uint8_t *cdb) the UNIT ATTENTION condition if it's set. */ if (cdb[0] != GPCMD_REQUEST_SENSE) { - cdrom_sense_clear(id, cdb[0], 1); + cdrom_sense_clear(id, cdb[0]); } /* Next it's time for NOT READY. */ @@ -1608,7 +1606,7 @@ void cdrom_request_sense(uint8_t id, uint8_t *buffer, uint8_t alloc_length) } /* Clear the sense stuff as per the spec. */ - cdrom_sense_clear(id, GPCMD_REQUEST_SENSE, 0); + cdrom_sense_clear(id, GPCMD_REQUEST_SENSE); } void cdrom_request_sense_for_scsi(uint8_t id, uint8_t *buffer, uint8_t alloc_length) @@ -1630,7 +1628,7 @@ void cdrom_request_sense_for_scsi(uint8_t id, uint8_t *buffer, uint8_t alloc_len disc changes. */ cdrom[id].unit_attention = 0; } - + /* Do *NOT* advance the unit attention phase. */ cdrom_request_sense(id, buffer, alloc_length); @@ -1732,10 +1730,6 @@ void cdrom_command(uint8_t id, uint8_t *cdb) case GPCMD_REQUEST_SENSE: /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE should forget about the not ready, and report unit attention straight away. */ - if (cdrom[id].unit_attention && (cdrom_sense_key == 2)) - { - cdrom_sense_key = cdrom_asc = cdrom_ascq = 0; - } cdrom_request_sense(id, cdbufferb, cdb[4]); cdrom_data_command_finish(id, 18, 18, cdb[4], 0); break;