Sense Data

24 Mar

Sense Data
On experiencing a problem in executing a command or on receiving an unsupported command, a device fills a structure with status information and sets bCSWStatus in the CSW to 01h (command failed). The status information is called the sense data. A REQUEST SENSE command can request the sense data, which the device returns in the data-transport phase.

A device can also use sense data to announce other events that require attention by the host, such as the inserting of removable media. To signal the event, the device sets the SENSE KEY field in the sense data to 06h (UNIT ATTENTION).

The contents of the returned sense-data structure vary with the command, the device type, and whether the DESC bit in the REQUEST SENSE command block requests fixed-format sense data (0) or descriptor-format sense data (1). Fixed-format sense data uses a single defined structure to return status information (Table 6-2). The format of descriptor-format sense data varies with the descriptors being sent. Each descriptor is a structure with a type of status information such as command-specific information, information relating to an exception condition, or information relating to block commands.

(In true SCSI communications, the device returns a status code after each command, and a status of CHECK CONDITION indicates that the SCSI host should issue a REQUEST SENSE command. USB communications use the status code in the CSW instead.)

Table 6-2: Fixed-format Sense Data has a defined structure.

Fixed-format Sense Data
The RequestSenseResponse union enables accessing fixed-format sense data as 18 generic bytes or as a structure with a series of named members:

typedef union {
struct
{
byte _byte[18];
};
struct
{
unsigned ResponseCode:7;
unsigned VALID:1;
byte Obsolete;
unsigned SenseKey:4;
unsigned Resv:1;
unsigned ILI:1;
unsigned EOM:1;
unsigned FILEMARK:1;
DWORD Information;
byte AddSenseLen;
DWORD CmdSpecificInfo;
byte ASC;
byte ASCQ;
byte FRUC;
byte SenseKeySpecific[3];
};
} RequestSenseResponse;

Setting Default Values
The ResetSenseData function sets the values in the RequestSenseResponse structure gblSenseData to default values:

RequestSenseResponse gblSenseData;
void ResetSenseData(void)
{
gblSenseData.ResponseCode = 0×70;
gblSenseData.VALID = 0×0;
gblSenseData.Obsolete = 0×0;
gblSenseData.SenseKey = 0×0;
gblSenseData.Resv = 0×0;
gblSenseData.ILI = 0×0;
gblSenseData.EOM = 0×0;
gblSenseData.FILEMARK = 0×0;
gblSenseData.Information._dword = 0×0;
gblSenseData.AddSenseLen = 0×0a;
gblSenseData.CmdSpecificInfo._dword = 0×0;
gblSenseData.ASC = 0×0;
gblSenseData.ASCQ = 0×0;
gblSenseData.FRUC = 0×0;
gblSenseData.SenseKeySpecific[0] = 0×0;
gblSenseData.SenseKeySpecific[1] = 0×0;
gblSenseData.SenseKeySpecific[2] = 0×0;
}
The sense codes can have assigned friendly names:
#define S_NOT_READY 0×2
#define S_MEDIUM_ERROR 0×3
#define S_ILLEGAL_REQUEST 0×5
#define S_UNIT_ATTENTION 0×6
#define ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0×21
#define ASCQ_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0×00
#define ASC_MEDIUM_NOT_PRESENT 0×3a
#define ASCQ_MEDIUM_NOT_PRESENT 0×00
#define ASC_PERIPHERAL_DEVICE_WRITE_FAULT 0×03
#define ASCQ_PERIPHERAL_DEVICE_WRITE_FAULT 0×00
#define ASC_UNRECOVERED_READ_ERROR 0×11
#define ASCQ_UNRECOVERED_READ_ERROR 0×00
#define ASC_WRITE_PROTECTED 0×27
#define ASCQ_WRITE_PROTECTED 0×00

NEXT: Primary Commands

Random Posts

No comments yet

Leave a Reply

You must be logged in to post a comment.