Skip to content

Commit

Permalink
Improve XEBEC vendor Request Sense responses
Browse files Browse the repository at this point in the history
Handle all sense codes that the current code can produce.
Xebec has more possible sense codes but they currently aren't needed.

Since there is no direct mapping from SCSI sense data to the Xebec
proprietary sense data, the codes were matched as closely as possible.

Signed-off-by: Jernej Jakob <jernej.jakob@gmail.com>
  • Loading branch information
jjakob committed Aug 27, 2023
1 parent 97da331 commit 3216668
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions lib/SCSI2SD/src/firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,57 @@ static void process_Command()
{
// Completely non-standard
allocLength = 4;
if (scsiDev.target->sense.code == NO_SENSE)
scsiDev.data[0] = 0;
else if (scsiDev.target->sense.code == ILLEGAL_REQUEST)
scsiDev.data[0] = 0x20; // Illegal command
else if (scsiDev.target->sense.code == NOT_READY)
scsiDev.data[0] = 0x04; // Drive not ready
else
scsiDev.data[0] = 0x11; // Uncorrectable data error

switch (scsiDev.target->sense.code)
{
case NO_SENSE:
scsiDev.data[0] = 0;
break;
case MEDIUM_ERROR:
switch (scsiDev.target->sense.asc)
{
case NO_SEEK_COMPLETE:
scsiDev.data[0] = 0x15; // Seek Error
break;
case WRITE_ERROR_AUTO_REALLOCATION_FAILED:
scsiDev.data[0] = 0x03; // Write fault
break;
default:
case UNRECOVERED_READ_ERROR:
scsiDev.data[0] = 0x11; // Uncorrectable read error
break;
}
break;
case ILLEGAL_REQUEST:
switch (scsiDev.target->sense.asc)
{
case LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE:
scsiDev.data[0] = 0x14; // Target sector not found
break;
case WRITE_PROTECTED:
scsiDev.data[0] = 0x03; // Write fault
break;
default:
scsiDev.data[0] = 0x20; // Invalid command
break;
}
break;
case NOT_READY:
switch (scsiDev.target->sense.asc)
{
default:
case MEDIUM_NOT_PRESENT:
scsiDev.data[0] = 0x04; // Drive not ready
break;
case LOGICAL_UNIT_NOT_READY_INITIALIZING_COMMAND_REQUIRED:
scsiDev.data[0] = 0x1A; // Format Error
break;
}
break;
default:
scsiDev.data[0] = 0x11; // Uncorrectable data error
break;
}

scsiDev.data[1] = (scsiDev.cdb[1] & 0x20) | ((transfer.lba >> 16) & 0x1F);
scsiDev.data[2] = transfer.lba >> 8;
Expand Down

0 comments on commit 3216668

Please sign in to comment.