From 6ec20a685c140625d763ab4bccdd0b0f7a2340dd Mon Sep 17 00:00:00 2001 From: Patrick Mackinlay Date: Thu, 10 Jan 2019 17:24:44 +0700 Subject: [PATCH] nscsi_bus: request sense fix (nw) * request sense returns minimum of allocated length or available data (or 4 bytes) * set the additional length properly * fix some magic numbers --- src/devices/machine/nscsi_bus.cpp | 15 +++++---------- src/devices/machine/nscsi_bus.h | 4 +++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/devices/machine/nscsi_bus.cpp b/src/devices/machine/nscsi_bus.cpp index 328dd7239bd..c408a6a6839 100644 --- a/src/devices/machine/nscsi_bus.cpp +++ b/src/devices/machine/nscsi_bus.cpp @@ -583,6 +583,7 @@ void nscsi_full_device::sense(bool deferred, uint8_t key, uint8_t asc, uint8_t a memset(scsi_sense_buffer, 0, sizeof(scsi_sense_buffer)); scsi_sense_buffer[0] = deferred ? 0x71 : 0x70; scsi_sense_buffer[2] = key; + scsi_sense_buffer[7] = sizeof(scsi_sense_buffer) - 8; scsi_sense_buffer[12] = asc; scsi_sense_buffer[13] = ascq; } @@ -595,19 +596,15 @@ void nscsi_full_device::scsi_unknown_command() logerror("\n"); scsi_status_complete(SS_CHECK_CONDITION); - sense(false, 5); + sense(false, SK_ILLEGAL_REQUEST); } void nscsi_full_device::scsi_command() { switch(scsi_cmdbuf[0]) { case SC_REQUEST_SENSE: - LOG("command REQUEST SENSE\n"); - /* - * Targets shall be capable of returning eighteen bytes of data in - * response to a REQUEST SENSE command. - */ - scsi_data_in(SBUF_SENSE, 18); + LOG("command REQUEST SENSE alloc=%d\n", scsi_cmdbuf[4]); + scsi_data_in(SBUF_SENSE, scsi_cmdbuf[4] ? std::min(scsi_cmdbuf[4], u8(sizeof(scsi_sense_buffer))) : 4); scsi_status_complete(SS_GOOD); break; default: @@ -640,9 +637,7 @@ int nscsi_full_device::get_lun(int def) void nscsi_full_device::bad_lun() { scsi_status_complete(SS_CHECK_CONDITION); - - // key:illegal request, asc:logical unit not supported - sense(false, 5, 0x25); + sense(false, SK_ILLEGAL_REQUEST, SK_ASC_LOGICAL_UNIT_NOT_SUPPORTED); } // Arbitration delay (2.4us) diff --git a/src/devices/machine/nscsi_bus.h b/src/devices/machine/nscsi_bus.h index 0eadd51de7f..2180e2f67b7 100644 --- a/src/devices/machine/nscsi_bus.h +++ b/src/devices/machine/nscsi_bus.h @@ -176,7 +176,9 @@ protected: // SCSI addtional sense code qualifiers enum { - SK_ASC_MEDIUM_NOT_PRESENT = 0x3a + SK_ASC_INVALID_FIELD_IN_CDB = 0x24, + SK_ASC_LOGICAL_UNIT_NOT_SUPPORTED = 0x25, + SK_ASC_MEDIUM_NOT_PRESENT = 0x3a }; // SCSI commands