2 * The following is from the linux kernel scsi_error.c
4 * scsi_error.c Copyright (C) 1997 Eric Youngdale
6 * SCSI error/timeout handling
7 * Initial versions: Eric Youngdale. Based upon conversations with
8 * Leonard Zubkoff and David Miller at Linux Expo,
9 * ideas originating from all over the place.
11 * Restructured scsi_unjam_host and associated functions.
12 * September 04, 2002 Mike Anderson (andmike@us.ibm.com)
14 * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and
16 * September 30, 2002 Mike Anderson (andmike@us.ibm.com)
23 * scsi_normalize_sense - normalize main elements from either fixed or
24 * descriptor sense data format into a common format.
26 * @sense_buffer: byte array containing sense data returned by device
27 * @sb_len: number of valid bytes in sense_buffer
28 * @sshdr: pointer to instance of structure that common
29 * elements are written to.
32 * The "main elements" from sense data are: response_code, sense_key,
33 * asc, ascq and additional_length (only for descriptor format).
35 * Typically this function can be called after a device has
36 * responded to a SCSI command with the CHECK_CONDITION status.
39 * 1 if valid sense data information found, else 0;
41 int scsi_normalize_sense(const uint8_t *sense_buffer
, int sb_len
,
42 struct scsi_sense_hdr
*sshdr
)
44 if (!sense_buffer
|| !sb_len
)
47 memset(sshdr
, 0, sizeof(struct scsi_sense_hdr
));
49 sshdr
->response_code
= (sense_buffer
[0] & 0x7f);
51 if (!scsi_sense_valid(sshdr
))
54 if (sshdr
->response_code
>= 0x72) {
59 sshdr
->sense_key
= (sense_buffer
[1] & 0xf);
61 sshdr
->asc
= sense_buffer
[2];
63 sshdr
->ascq
= sense_buffer
[3];
65 sshdr
->additional_length
= sense_buffer
[7];
71 sshdr
->sense_key
= (sense_buffer
[2] & 0xf);
73 sb_len
= (sb_len
< (sense_buffer
[7] + 8)) ?
74 sb_len
: (sense_buffer
[7] + 8);
76 sshdr
->asc
= sense_buffer
[12];
78 sshdr
->ascq
= sense_buffer
[13];