* [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes
@ 2025-04-16 9:31 Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 1/3] ata: libata-sata: Save all fields from sense data descriptor Niklas Cassel
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Niklas Cassel @ 2025-04-16 9:31 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-ide, Igor Pylypiv, Hannes Reinecke, Niklas Cassel
Hello all,
Here comes some minor cleanups/fixes related to the sense_valid field in
the Successful NCQ commands log.
Kind regards,
Niklas
Changes since v2:
-Picked up tags.
-Changed "1ULL << tag" to "1 << tag" in patch 2/3 (Damien).
-Improved subject in patch 3/3.
Niklas Cassel (3):
ata: libata-sata: Save all fields from sense data descriptor
ata: libata-sata: Simplify sense_valid fetching
ata: libata-sata: Use BIT() macro to convert tag to bit field
drivers/ata/libata-sata.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/3] ata: libata-sata: Save all fields from sense data descriptor
2025-04-16 9:31 [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Niklas Cassel
@ 2025-04-16 9:31 ` Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 2/3] ata: libata-sata: Simplify sense_valid fetching Niklas Cassel
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2025-04-16 9:31 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-ide, Igor Pylypiv, Hannes Reinecke, Niklas Cassel
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>
---
drivers/ata/libata-sata.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index ba300cc0a3a3..2e4463d3a356 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -1510,6 +1510,8 @@ int ata_eh_get_ncq_success_sense(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);
@@ -1529,6 +1531,8 @@ int ata_eh_get_ncq_success_sense(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) ||
@@ -1556,6 +1560,17 @@ int ata_eh_get_ncq_success_sense(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,
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/3] ata: libata-sata: Simplify sense_valid fetching
2025-04-16 9:31 [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 1/3] ata: libata-sata: Save all fields from sense data descriptor Niklas Cassel
@ 2025-04-16 9:31 ` Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 3/3] ata: libata-sata: Use BIT() macro to convert tag to bit field Niklas Cassel
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2025-04-16 9:31 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-ide, Igor Pylypiv, Hannes Reinecke, Niklas Cassel
While the SENSE DATA VALID field in the ACS-6 specification is 47 bits,
we are currently only fetching 32 bits, because these are the only bits
that we care about (these bits represent the tags (which can be 0-31)).
Thus, replace the existing logic with a simple get_unaligned_le32().
While at it, change the type of sense_valid to u32.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Igor Pylypiv <ipylypiv@google.com>
---
drivers/ata/libata-sata.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 2e4463d3a356..89d3b784706b 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -1509,9 +1509,10 @@ int ata_eh_get_ncq_success_sense(struct ata_link *link)
struct ata_queued_cmd *qc;
unsigned int err_mask, tag;
u8 *sense, sk = 0, asc = 0, ascq = 0;
- u64 sense_valid, val;
u16 extended_sense;
bool aux_icc_valid;
+ u32 sense_valid;
+ u64 val;
int ret = 0;
err_mask = ata_read_log_page(dev, ATA_LOG_SENSE_NCQ, 0, buf, 2);
@@ -1529,8 +1530,7 @@ int ata_eh_get_ncq_success_sense(struct ata_link *link)
return -EIO;
}
- sense_valid = (u64)buf[8] | ((u64)buf[9] << 8) |
- ((u64)buf[10] << 16) | ((u64)buf[11] << 24);
+ sense_valid = get_unaligned_le32(&buf[8]);
extended_sense = get_unaligned_le16(&buf[14]);
aux_icc_valid = extended_sense & BIT(15);
@@ -1545,7 +1545,7 @@ int ata_eh_get_ncq_success_sense(struct ata_link *link)
* If the command does not have any sense data, clear ATA_SENSE.
* Keep ATA_QCFLAG_EH_SUCCESS_CMD so that command is finished.
*/
- if (!(sense_valid & (1ULL << tag))) {
+ if (!(sense_valid & (1 << tag))) {
qc->result_tf.status &= ~ATA_SENSE;
continue;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 3/3] ata: libata-sata: Use BIT() macro to convert tag to bit field
2025-04-16 9:31 [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 1/3] ata: libata-sata: Save all fields from sense data descriptor Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 2/3] ata: libata-sata: Simplify sense_valid fetching Niklas Cassel
@ 2025-04-16 9:31 ` Niklas Cassel
2025-04-16 9:50 ` [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Damien Le Moal
2025-04-21 0:06 ` Damien Le Moal
4 siblings, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2025-04-16 9:31 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-ide, Igor Pylypiv, Hannes Reinecke, Niklas Cassel
The BIT() macro is commonly used in the kernel.
Make use of it when converting a tag, fetched from the Successful NCQ
Commands log or the NCQ Command Error log, to a bit field.
This makes the code easier to read.
Suggested-by: Igor Pylypiv <ipylypiv@google.com>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Igor Pylypiv <ipylypiv@google.com>
---
drivers/ata/libata-sata.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 89d3b784706b..4e3034af285e 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -1545,7 +1545,7 @@ int ata_eh_get_ncq_success_sense(struct ata_link *link)
* If the command does not have any sense data, clear ATA_SENSE.
* Keep ATA_QCFLAG_EH_SUCCESS_CMD so that command is finished.
*/
- if (!(sense_valid & (1 << tag))) {
+ if (!(sense_valid & BIT(tag))) {
qc->result_tf.status &= ~ATA_SENSE;
continue;
}
@@ -1634,7 +1634,7 @@ void ata_eh_analyze_ncq_error(struct ata_link *link)
return;
}
- if (!(link->sactive & (1 << tag))) {
+ if (!(link->sactive & BIT(tag))) {
ata_link_err(link, "log page 10h reported inactive tag %d\n",
tag);
return;
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes
2025-04-16 9:31 [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Niklas Cassel
` (2 preceding siblings ...)
2025-04-16 9:31 ` [PATCH v3 3/3] ata: libata-sata: Use BIT() macro to convert tag to bit field Niklas Cassel
@ 2025-04-16 9:50 ` Damien Le Moal
2025-04-21 0:06 ` Damien Le Moal
4 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-04-16 9:50 UTC (permalink / raw)
To: Niklas Cassel; +Cc: linux-ide, Igor Pylypiv, Hannes Reinecke
On 4/16/25 6:31 PM, Niklas Cassel wrote:
> Hello all,
>
> Here comes some minor cleanups/fixes related to the sense_valid field in
> the Successful NCQ commands log.
>
>
> Kind regards,
> Niklas
>
>
> Changes since v2:
> -Picked up tags.
> -Changed "1ULL << tag" to "1 << tag" in patch 2/3 (Damien).
> -Improved subject in patch 3/3.
>
>
> Niklas Cassel (3):
> ata: libata-sata: Save all fields from sense data descriptor
> ata: libata-sata: Simplify sense_valid fetching
> ata: libata-sata: Use BIT() macro to convert tag to bit field
Looks good. I will rebase for-6.16 on rc3 next Monday and apply 2/3 and 3/3.
Thanks !
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes
2025-04-16 9:31 [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Niklas Cassel
` (3 preceding siblings ...)
2025-04-16 9:50 ` [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Damien Le Moal
@ 2025-04-21 0:06 ` Damien Le Moal
4 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-04-21 0:06 UTC (permalink / raw)
To: Niklas Cassel; +Cc: linux-ide, Igor Pylypiv, Hannes Reinecke
On 4/16/25 6:31 PM, Niklas Cassel wrote:
> Hello all,
>
> Here comes some minor cleanups/fixes related to the sense_valid field in
> the Successful NCQ commands log.
>
>
> Kind regards,
> Niklas
>
>
> Changes since v2:
> -Picked up tags.
> -Changed "1ULL << tag" to "1 << tag" in patch 2/3 (Damien).
> -Improved subject in patch 3/3.
>
>
> Niklas Cassel (3):
> ata: libata-sata: Save all fields from sense data descriptor
> ata: libata-sata: Simplify sense_valid fetching
> ata: libata-sata: Use BIT() macro to convert tag to bit field
Applied 2/3 and 3/3 to for-6.16. Thanks !
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-21 0:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 9:31 [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 1/3] ata: libata-sata: Save all fields from sense data descriptor Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 2/3] ata: libata-sata: Simplify sense_valid fetching Niklas Cassel
2025-04-16 9:31 ` [PATCH v3 3/3] ata: libata-sata: Use BIT() macro to convert tag to bit field Niklas Cassel
2025-04-16 9:50 ` [PATCH v3 0/3] Successful NCQ commands sense_valid cleanups/fixes Damien Le Moal
2025-04-21 0:06 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).