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
This commit is contained in:
Patrick Mackinlay 2019-01-10 17:24:44 +07:00
parent b999de69a5
commit 6ec20a685c
2 changed files with 8 additions and 11 deletions

View File

@ -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)

View File

@ -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