Skip to content

Commit cf3fc03

Browse files
committed
ata: libata-scsi: Fix ata_to_sense_error() status handling
Commit 8ae7204 ("libata: whitespace fixes in ata_to_sense_error()") inadvertantly added the entry 0x40 (ATA_DRDY) to the stat_table array in the function ata_to_sense_error(). This entry ties a failed qc which has a status filed equal to ATA_DRDY to the sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND. This entry will be used to generate a failed qc sense key and sense code when the qc is missing sense data and there is no match for the qc error field in the sense_table array of ata_to_sense_error(). As a result, for a failed qc for which we failed to get sense data (e.g. read log 10h failed if qc is an NCQ command, or REQUEST SENSE EXT command failed for the non-ncq case, the user very often end up seeing the completely misleading "unaligned write command" error, even if qc was not a write command. E.g.: sd 0:0:0:0: [sda] tag#12 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 0:0:0:0: [sda] tag#12 Sense Key : Illegal Request [current] sd 0:0:0:0: [sda] tag#12 Add. Sense: Unaligned write command sd 0:0:0:0: [sda] tag#12 CDB: Read(10) 28 00 00 00 10 00 00 00 08 00 I/O error, dev sda, sector 4096 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0 Fix this by removing the ATA_DRDY entry from the stat_table array so that we default to always returning ABORTED COMMAND without any additional sense code, since we do not know any better. The entry 0x08 (ATA_DRQ) is also removed since signaling ABORTED COMMAND with a parity error is also misleading (as a parity error would likely be signaled through a bus error). So for this case, also default to returning ABORTED COMMAND without any additional sense code. With this, the previous example error case becomes: sd 0:0:0:0: [sda] tag#17 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 0:0:0:0: [sda] tag#17 Sense Key : Aborted Command [current] sd 0:0:0:0: [sda] tag#17 Add. Sense: No additional sense information sd 0:0:0:0: [sda] tag#17 CDB: Read(10) 28 00 00 00 10 00 00 00 08 00 I/O error, dev sda, sector 4096 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0 Together with these fixes, refactor stat_table to make it more readable by putting the entries comments in front of the entries and using the defined status bits macros instead of hardcoded values. Reported-by: Lorenz Brun <[email protected]> Reported-by: Brandon Schwartz <[email protected]> Fixes: 8ae7204 ("libata: whitespace fixes in ata_to_sense_error()") Cc: [email protected] Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]>
1 parent 260f6f4 commit cf3fc03

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

drivers/ata/libata-scsi.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -859,18 +859,14 @@ static void ata_to_sense_error(u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
859859
{0xFF, 0xFF, 0xFF, 0xFF}, // END mark
860860
};
861861
static const unsigned char stat_table[][4] = {
862-
/* Must be first because BUSY means no other bits valid */
863-
{0x80, ABORTED_COMMAND, 0x47, 0x00},
864-
// Busy, fake parity for now
865-
{0x40, ILLEGAL_REQUEST, 0x21, 0x04},
866-
// Device ready, unaligned write command
867-
{0x20, HARDWARE_ERROR, 0x44, 0x00},
868-
// Device fault, internal target failure
869-
{0x08, ABORTED_COMMAND, 0x47, 0x00},
870-
// Timed out in xfer, fake parity for now
871-
{0x04, RECOVERED_ERROR, 0x11, 0x00},
872-
// Recovered ECC error Medium error, recovered
873-
{0xFF, 0xFF, 0xFF, 0xFF}, // END mark
862+
/* Busy: must be first because BUSY means no other bits valid */
863+
{ ATA_BUSY, ABORTED_COMMAND, 0x00, 0x00 },
864+
/* Device fault: INTERNAL TARGET FAILURE */
865+
{ ATA_DF, HARDWARE_ERROR, 0x44, 0x00 },
866+
/* Corrected data error */
867+
{ ATA_CORR, RECOVERED_ERROR, 0x00, 0x00 },
868+
869+
{ 0xFF, 0xFF, 0xFF, 0xFF }, /* END mark */
874870
};
875871

876872
/*

0 commit comments

Comments
 (0)