ata: libata-sata: Save all fields from sense data descriptor
authorNiklas Cassel <cassel@kernel.org>
Tue, 15 Apr 2025 07:30:15 +0000 (09:30 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:42 +0000 (10:45 +0200)
[ Upstream commit 399eab7f92fb73ffe621294a2d6bec8fc9f3b36b ]

When filling the taskfile result for a successful NCQ command, we use
the SDB FIS from the FIS Receive Area, see e.g. ahci_qc_ncq_fill_rtf().

However, the SDB FIS only has fields STATUS and ERROR.

For a successful NCQ command that has sense data, we will have a
successful sense data descriptor, in the Sense Data for Successful NCQ
Commands log.

Since we have access to additional taskfile result fields, fill in these
additional fields in qc->result_tf.

This matches how for failing/aborted NCQ commands, we will use e.g.
ahci_qc_fill_rtf() to fill in some fields, but then for the command that
actually caused the NCQ error, we will use ata_eh_read_log_10h(), which
provides additional fields, saving additional fields/overriding the
qc->result_tf that was fetched using ahci_qc_fill_rtf().

Fixes: 18bd7718b5c4 ("scsi: ata: libata: Handle completion of CDL commands using policy 0xD")
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Igor Pylypiv <ipylypiv@google.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/ata/libata-sata.c

index a701e1538482f09eb5960a606edad01f34920401..be72030a500d44ba65527d9cc98527b78d268d57 100644 (file)
@@ -1365,6 +1365,8 @@ int ata_eh_read_sense_success_ncq_log(struct ata_link *link)
        unsigned int err_mask, tag;
        u8 *sense, sk = 0, asc = 0, ascq = 0;
        u64 sense_valid, val;
+       u16 extended_sense;
+       bool aux_icc_valid;
        int ret = 0;
 
        err_mask = ata_read_log_page(dev, ATA_LOG_SENSE_NCQ, 0, buf, 2);
@@ -1384,6 +1386,8 @@ int ata_eh_read_sense_success_ncq_log(struct ata_link *link)
 
        sense_valid = (u64)buf[8] | ((u64)buf[9] << 8) |
                ((u64)buf[10] << 16) | ((u64)buf[11] << 24);
+       extended_sense = get_unaligned_le16(&buf[14]);
+       aux_icc_valid = extended_sense & BIT(15);
 
        ata_qc_for_each_raw(ap, qc, tag) {
                if (!(qc->flags & ATA_QCFLAG_EH) ||
@@ -1411,6 +1415,17 @@ int ata_eh_read_sense_success_ncq_log(struct ata_link *link)
                        continue;
                }
 
+               qc->result_tf.nsect = sense[6];
+               qc->result_tf.hob_nsect = sense[7];
+               qc->result_tf.lbal = sense[8];
+               qc->result_tf.lbam = sense[9];
+               qc->result_tf.lbah = sense[10];
+               qc->result_tf.hob_lbal = sense[11];
+               qc->result_tf.hob_lbam = sense[12];
+               qc->result_tf.hob_lbah = sense[13];
+               if (aux_icc_valid)
+                       qc->result_tf.auxiliary = get_unaligned_le32(&sense[16]);
+
                /* Set sense without also setting scsicmd->result */
                scsi_build_sense_buffer(dev->flags & ATA_DFLAG_D_SENSE,
                                        qc->scsicmd->sense_buffer, sk,