[SCSI] aacraid: do not set valid bit in sense information

Luben Tuikov [mailto:ltuikov@yahoo.com] sez:
> Just as in your case and Tony's case, which I presume
> uses the same RAID firmware vendor, it would've
> probably been better if the RAID firmware vendor
> fixed the firmware to not set the VALID bit if the
> INFORMATION field is not valid.

Point taken regarding the aacraid driver. Dropped the VALID bit, and
then did some cleanup/simplification of the set_sense procedure and
the associated parameters. Mike did some preliminary tests when the
VALID bit was dropped before the 'Re: [PATCH] [SCSI] sd: make error
handling more robust' patches came on the scene. The change in the
SCSI subsystem does make this enclosed aacraid patch unnecessary, so
this aacraid patch is merely post battle ground cleanup. If the
simplification is an issue, repugnant, too much for a back-port to the
stable trees or clouds the point, this patch could be happily
distilled down to:

diff -ru a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
--- a/drivers/scsi/aacraid/aachba.c 2008-02-06 16:26:45.834938955 -0500
+++ b/drivers/scsi/aacraid/aachba.c 2008-02-06 16:32:01.109035329 -0500
@@ -865,7 +865,7 @@
u32 residue)
{
- sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
+ sense_buf[0] = 0x70; /* Sense data invalid, err code 70h (current error) */
sense_buf[1] = 0; /* Segment number, always zero */

if (incorrect_length) {

Signed-off-by: Mark Salyzyn <aacraid@adaptec.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>

authored by Salyzyn, Mark and committed by James Bottomley 8e31e607 9927c688

+30 -51
+30 -51
drivers/scsi/aacraid/aachba.c
··· 859 le32_to_cpu(dev->adapter_info.serial[0]), cid); 860 } 861 862 - static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code, 863 - u8 a_sense_code, u8 incorrect_length, 864 - u8 bit_pointer, u16 field_pointer, 865 - u32 residue) 866 { 867 - sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */ 868 sense_buf[1] = 0; /* Segment number, always zero */ 869 870 - if (incorrect_length) { 871 - sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */ 872 - sense_buf[3] = BYTE3(residue); 873 - sense_buf[4] = BYTE2(residue); 874 - sense_buf[5] = BYTE1(residue); 875 - sense_buf[6] = BYTE0(residue); 876 - } else 877 - sense_buf[2] = sense_key; /* Sense key */ 878 - 879 - if (sense_key == ILLEGAL_REQUEST) 880 - sense_buf[7] = 10; /* Additional sense length */ 881 - else 882 - sense_buf[7] = 6; /* Additional sense length */ 883 884 sense_buf[12] = sense_code; /* Additional sense code */ 885 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */ 886 if (sense_key == ILLEGAL_REQUEST) { 887 - sense_buf[15] = 0; 888 889 - if (sense_code == SENCODE_INVALID_PARAM_FIELD) 890 - sense_buf[15] = 0x80;/* Std sense key specific field */ 891 /* Illegal parameter is in the parameter block */ 892 - 893 if (sense_code == SENCODE_INVALID_CDB_FIELD) 894 - sense_buf[15] = 0xc0;/* Std sense key specific field */ 895 /* Illegal parameter is in the CDB block */ 896 - sense_buf[15] |= bit_pointer; 897 sense_buf[16] = field_pointer >> 8; /* MSB */ 898 sense_buf[17] = field_pointer; /* LSB */ 899 - } 900 } 901 902 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) ··· 893 dprintk((KERN_DEBUG "aacraid: Illegal lba\n")); 894 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | 895 SAM_STAT_CHECK_CONDITION; 896 - set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 897 - HARDWARE_ERROR, 898 - SENCODE_INTERNAL_TARGET_FAILURE, 899 - ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 900 - 0, 0); 901 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 902 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 903 SCSI_SENSE_BUFFERSIZE)); ··· 1505 le32_to_cpu(readreply->status)); 1506 #endif 1507 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1508 - set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 1509 - HARDWARE_ERROR, 1510 - SENCODE_INTERNAL_TARGET_FAILURE, 1511 - ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 1512 - 0, 0); 1513 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1514 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1515 SCSI_SENSE_BUFFERSIZE)); ··· 1716 le32_to_cpu(synchronizereply->status)); 1717 cmd->result = DID_OK << 16 | 1718 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1719 - set_sense((u8 *)&dev->fsa_dev[cid].sense_data, 1720 - HARDWARE_ERROR, 1721 - SENCODE_INTERNAL_TARGET_FAILURE, 1722 - ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 1723 - 0, 0); 1724 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1725 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1726 SCSI_SENSE_BUFFERSIZE)); ··· 1926 { 1927 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0])); 1928 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1929 - set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 1930 - ILLEGAL_REQUEST, 1931 - SENCODE_INVALID_COMMAND, 1932 - ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 1933 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1934 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1935 SCSI_SENSE_BUFFERSIZE)); ··· 1975 scsicmd->result = DID_OK << 16 | 1976 COMMAND_COMPLETE << 8 | 1977 SAM_STAT_CHECK_CONDITION; 1978 - set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 1979 - ILLEGAL_REQUEST, 1980 - SENCODE_INVALID_CDB_FIELD, 1981 - ASENCODE_NO_SENSE, 0, 7, 2, 0); 1982 memcpy(scsicmd->sense_buffer, 1983 &dev->fsa_dev[cid].sense_data, 1984 min_t(size_t, ··· 2233 */ 2234 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0])); 2235 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 2236 - set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 2237 - ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, 2238 - ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 2239 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 2240 min_t(size_t, 2241 sizeof(dev->fsa_dev[cid].sense_data),
··· 859 le32_to_cpu(dev->adapter_info.serial[0]), cid); 860 } 861 862 + static inline void set_sense(struct sense_data *sense_data, u8 sense_key, 863 + u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer) 864 { 865 + u8 *sense_buf = (u8 *)sense_data; 866 + /* Sense data valid, err code 70h */ 867 + sense_buf[0] = 0x70; /* No info field */ 868 sense_buf[1] = 0; /* Segment number, always zero */ 869 870 + sense_buf[2] = sense_key; /* Sense key */ 871 872 sense_buf[12] = sense_code; /* Additional sense code */ 873 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */ 874 + 875 if (sense_key == ILLEGAL_REQUEST) { 876 + sense_buf[7] = 10; /* Additional sense length */ 877 878 + sense_buf[15] = bit_pointer; 879 /* Illegal parameter is in the parameter block */ 880 if (sense_code == SENCODE_INVALID_CDB_FIELD) 881 + sense_buf[15] |= 0xc0;/* Std sense key specific field */ 882 /* Illegal parameter is in the CDB block */ 883 sense_buf[16] = field_pointer >> 8; /* MSB */ 884 sense_buf[17] = field_pointer; /* LSB */ 885 + } else 886 + sense_buf[7] = 6; /* Additional sense length */ 887 } 888 889 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) ··· 906 dprintk((KERN_DEBUG "aacraid: Illegal lba\n")); 907 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | 908 SAM_STAT_CHECK_CONDITION; 909 + set_sense(&dev->fsa_dev[cid].sense_data, 910 + HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, 911 + ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); 912 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 913 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 914 SCSI_SENSE_BUFFERSIZE)); ··· 1520 le32_to_cpu(readreply->status)); 1521 #endif 1522 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1523 + set_sense(&dev->fsa_dev[cid].sense_data, 1524 + HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, 1525 + ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); 1526 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1527 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1528 SCSI_SENSE_BUFFERSIZE)); ··· 1733 le32_to_cpu(synchronizereply->status)); 1734 cmd->result = DID_OK << 16 | 1735 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1736 + set_sense(&dev->fsa_dev[cid].sense_data, 1737 + HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, 1738 + ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); 1739 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1740 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1741 SCSI_SENSE_BUFFERSIZE)); ··· 1945 { 1946 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0])); 1947 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1948 + set_sense(&dev->fsa_dev[cid].sense_data, 1949 + ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, 1950 + ASENCODE_INVALID_COMMAND, 0, 0); 1951 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1952 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1953 SCSI_SENSE_BUFFERSIZE)); ··· 1995 scsicmd->result = DID_OK << 16 | 1996 COMMAND_COMPLETE << 8 | 1997 SAM_STAT_CHECK_CONDITION; 1998 + set_sense(&dev->fsa_dev[cid].sense_data, 1999 + ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD, 2000 + ASENCODE_NO_SENSE, 7, 2); 2001 memcpy(scsicmd->sense_buffer, 2002 &dev->fsa_dev[cid].sense_data, 2003 min_t(size_t, ··· 2254 */ 2255 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0])); 2256 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 2257 + set_sense(&dev->fsa_dev[cid].sense_data, 2258 + ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, 2259 + ASENCODE_INVALID_COMMAND, 0, 0); 2260 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 2261 min_t(size_t, 2262 sizeof(dev->fsa_dev[cid].sense_data),