diff mbox series

[v1,4/4] ata: libata-scsi: Fix offsets for the fixed format sense data

Message ID 20240614191835.3056153-5-ipylypiv@google.com
State New
Headers show
Series ATA PASS-THROUGH sense data fixes | expand

Commit Message

Igor Pylypiv June 14, 2024, 7:18 p.m. UTC
Correct the ATA PASS-THROUGH fixed format sense data offsets to conform
to SPC-6 and SAT-5 specifications. Additionally, set the VALID bit to
indicate that the INFORMATION field contains valid information.

INFORMATION
===========

SAT-5 Table 212 — "Fixed format sense data INFORMATION field for the ATA
PASS-THROUGH commands" defines the following format:

+------+------------+
| Byte |   Field    |
+------+------------+
|    0 | ERROR      |
|    1 | STATUS     |
|    2 | DEVICE     |
|    3 | COUNT(7:0) |
+------+------------+

SPC-6 Table 48 - "Fixed format sense data" specifies that the INFORMATION
field starts at byte 3 in sense buffer resulting in the following offsets
for the ATA PASS-THROUGH commands:

+------------+-------------------------+
|   Field    |  Offset in sense buffer |
+------------+-------------------------+
| ERROR      |  3                      |
| STATUS     |  4                      |
| DEVICE     |  5                      |
| COUNT(7:0) |  6                      |
+------------+-------------------------+

COMMAND-SPECIFIC INFORMATION
============================

SAT-5 Table 213 - "Fixed format sense data COMMAND-SPECIFIC INFORMATION
field for ATA PASS-THROUGH" defines the following format:

+------+-------------------+
| Byte |        Field      |
+------+-------------------+
|    0 | FLAGS | LOG INDEX |
|    1 | LBA (7:0)         |
|    2 | LBA (15:8)        |
|    3 | LBA (23:16)       |
+------+-------------------+

SPC-6 Table 48 - "Fixed format sense data" specifies that
the COMMAND-SPECIFIC-INFORMATION field starts at byte 8
in sense buffer resulting in the following offsets for
the ATA PASS-THROUGH commands:

Offsets of these fields in the fixed sense format are as follows:

+-------------------+-------------------------+
|       Field       |  Offset in sense buffer |
+-------------------+-------------------------+
| FLAGS | LOG INDEX |  8                      |
| LBA (7:0)         |  9                      |
| LBA (15:8)        |  10                     |
| LBA (23:16)       |  11                     |
+-------------------+-------------------------+

Reported-by: Akshat Jain <akshatzen@google.com>
Fixes: 11093cb1ef56 ("libata-scsi: generate correct ATA pass-through sense")
Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
---
 drivers/ata/libata-scsi.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

Comments

Damien Le Moal June 16, 2024, 11:37 p.m. UTC | #1
On 6/15/24 04:18, Igor Pylypiv wrote:
> Correct the ATA PASS-THROUGH fixed format sense data offsets to conform
> to SPC-6 and SAT-5 specifications. Additionally, set the VALID bit to
> indicate that the INFORMATION field contains valid information.
> 
> INFORMATION
> ===========
> 
> SAT-5 Table 212 — "Fixed format sense data INFORMATION field for the ATA
> PASS-THROUGH commands" defines the following format:
> 
> +------+------------+
> | Byte |   Field    |
> +------+------------+
> |    0 | ERROR      |
> |    1 | STATUS     |
> |    2 | DEVICE     |
> |    3 | COUNT(7:0) |
> +------+------------+
> 
> SPC-6 Table 48 - "Fixed format sense data" specifies that the INFORMATION
> field starts at byte 3 in sense buffer resulting in the following offsets
> for the ATA PASS-THROUGH commands:
> 
> +------------+-------------------------+
> |   Field    |  Offset in sense buffer |
> +------------+-------------------------+
> | ERROR      |  3                      |
> | STATUS     |  4                      |
> | DEVICE     |  5                      |
> | COUNT(7:0) |  6                      |
> +------------+-------------------------+
> 
> COMMAND-SPECIFIC INFORMATION
> ============================
> 
> SAT-5 Table 213 - "Fixed format sense data COMMAND-SPECIFIC INFORMATION
> field for ATA PASS-THROUGH" defines the following format:
> 
> +------+-------------------+
> | Byte |        Field      |
> +------+-------------------+
> |    0 | FLAGS | LOG INDEX |
> |    1 | LBA (7:0)         |
> |    2 | LBA (15:8)        |
> |    3 | LBA (23:16)       |
> +------+-------------------+
> 
> SPC-6 Table 48 - "Fixed format sense data" specifies that
> the COMMAND-SPECIFIC-INFORMATION field starts at byte 8
> in sense buffer resulting in the following offsets for
> the ATA PASS-THROUGH commands:
> 
> Offsets of these fields in the fixed sense format are as follows:
> 
> +-------------------+-------------------------+
> |       Field       |  Offset in sense buffer |
> +-------------------+-------------------------+
> | FLAGS | LOG INDEX |  8                      |
> | LBA (7:0)         |  9                      |
> | LBA (15:8)        |  10                     |
> | LBA (23:16)       |  11                     |
> +-------------------+-------------------------+
> 
> Reported-by: Akshat Jain <akshatzen@google.com>
> Fixes: 11093cb1ef56 ("libata-scsi: generate correct ATA pass-through sense")
> Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
> ---
>  drivers/ata/libata-scsi.c | 26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 4bfe47e7d266..8588512f5975 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -855,7 +855,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
>  	struct scsi_cmnd *cmd = qc->scsicmd;
>  	struct ata_taskfile *tf = &qc->result_tf;
>  	unsigned char *sb = cmd->sense_buffer;
> -	unsigned char *desc = sb + 8;
>  	u8 sense_key, asc, ascq;
>  
>  	if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
> @@ -880,8 +879,9 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
>  		scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D);
>  	}
>  
> -	if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {
> +	if ((sb[0] & 0x7f) >= 0x72) {
>  		u8 len;
> +		unsigned char *desc;

Please move this declaration before the "u8 len" one.
Otherwise, this seems OK but needs a Cc: stable@vger.kernel.org tag added.

>  
>  		/* descriptor format */
>  		len = sb[7];
> @@ -919,21 +919,21 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
>  		}
>  	} else {
>  		/* Fixed sense format */
> -		desc[0] = tf->error;
> -		desc[1] = tf->status;
> -		desc[2] = tf->device;
> -		desc[3] = tf->nsect;
> -		desc[7] = 0;
> +		sb[0] |= 0x80;
> +		sb[3] = tf->error;
> +		sb[4] = tf->status;
> +		sb[5] = tf->device;
> +		sb[6] = tf->nsect;
>  		if (tf->flags & ATA_TFLAG_LBA48)  {
> -			desc[8] |= 0x80;
> +			sb[8] |= 0x80;
>  			if (tf->hob_nsect)
> -				desc[8] |= 0x40;
> +				sb[8] |= 0x40;>  			if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah)
> -				desc[8] |= 0x20;
> +				sb[8] |= 0x20;
>  		}
> -		desc[9] = tf->lbal;
> -		desc[10] = tf->lbam;
> -		desc[11] = tf->lbah;
> +		sb[9] = tf->lbal;
> +		sb[10] = tf->lbam;
> +		sb[11] = tf->lbah;
>  	}
>  }
>
Igor Pylypiv June 18, 2024, 1:51 a.m. UTC | #2
On Mon, Jun 17, 2024 at 08:37:09AM +0900, Damien Le Moal wrote:
> On 6/15/24 04:18, Igor Pylypiv wrote:
> > Correct the ATA PASS-THROUGH fixed format sense data offsets to conform
> > to SPC-6 and SAT-5 specifications. Additionally, set the VALID bit to
> > indicate that the INFORMATION field contains valid information.
> > 
> > INFORMATION
> > ===========
> > 
> > SAT-5 Table 212 — "Fixed format sense data INFORMATION field for the ATA
> > PASS-THROUGH commands" defines the following format:
> > 
> > +------+------------+
> > | Byte |   Field    |
> > +------+------------+
> > |    0 | ERROR      |
> > |    1 | STATUS     |
> > |    2 | DEVICE     |
> > |    3 | COUNT(7:0) |
> > +------+------------+
> > 
> > SPC-6 Table 48 - "Fixed format sense data" specifies that the INFORMATION
> > field starts at byte 3 in sense buffer resulting in the following offsets
> > for the ATA PASS-THROUGH commands:
> > 
> > +------------+-------------------------+
> > |   Field    |  Offset in sense buffer |
> > +------------+-------------------------+
> > | ERROR      |  3                      |
> > | STATUS     |  4                      |
> > | DEVICE     |  5                      |
> > | COUNT(7:0) |  6                      |
> > +------------+-------------------------+
> > 
> > COMMAND-SPECIFIC INFORMATION
> > ============================
> > 
> > SAT-5 Table 213 - "Fixed format sense data COMMAND-SPECIFIC INFORMATION
> > field for ATA PASS-THROUGH" defines the following format:
> > 
> > +------+-------------------+
> > | Byte |        Field      |
> > +------+-------------------+
> > |    0 | FLAGS | LOG INDEX |
> > |    1 | LBA (7:0)         |
> > |    2 | LBA (15:8)        |
> > |    3 | LBA (23:16)       |
> > +------+-------------------+
> > 
> > SPC-6 Table 48 - "Fixed format sense data" specifies that
> > the COMMAND-SPECIFIC-INFORMATION field starts at byte 8
> > in sense buffer resulting in the following offsets for
> > the ATA PASS-THROUGH commands:
> > 
> > Offsets of these fields in the fixed sense format are as follows:
> > 
> > +-------------------+-------------------------+
> > |       Field       |  Offset in sense buffer |
> > +-------------------+-------------------------+
> > | FLAGS | LOG INDEX |  8                      |
> > | LBA (7:0)         |  9                      |
> > | LBA (15:8)        |  10                     |
> > | LBA (23:16)       |  11                     |
> > +-------------------+-------------------------+
> > 
> > Reported-by: Akshat Jain <akshatzen@google.com>
> > Fixes: 11093cb1ef56 ("libata-scsi: generate correct ATA pass-through sense")
> > Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
> > ---
> >  drivers/ata/libata-scsi.c | 26 +++++++++++++-------------
> >  1 file changed, 13 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> > index 4bfe47e7d266..8588512f5975 100644
> > --- a/drivers/ata/libata-scsi.c
> > +++ b/drivers/ata/libata-scsi.c
> > @@ -855,7 +855,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
> >  	struct scsi_cmnd *cmd = qc->scsicmd;
> >  	struct ata_taskfile *tf = &qc->result_tf;
> >  	unsigned char *sb = cmd->sense_buffer;
> > -	unsigned char *desc = sb + 8;
> >  	u8 sense_key, asc, ascq;
> >  
> >  	if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
> > @@ -880,8 +879,9 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
> >  		scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D);
> >  	}
> >  
> > -	if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {
> > +	if ((sb[0] & 0x7f) >= 0x72) {
> >  		u8 len;
> > +		unsigned char *desc;
> 
> Please move this declaration before the "u8 len" one.

Will do in v2. Could you please explain why this declaration order is preferred?

> Otherwise, this seems OK but needs a Cc: stable@vger.kernel.org tag added.

Ack, will add in v2.
> 
> >  
> >  		/* descriptor format */
> >  		len = sb[7];
> > @@ -919,21 +919,21 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
> >  		}
> >  	} else {
> >  		/* Fixed sense format */
> > -		desc[0] = tf->error;
> > -		desc[1] = tf->status;
> > -		desc[2] = tf->device;
> > -		desc[3] = tf->nsect;
> > -		desc[7] = 0;
> > +		sb[0] |= 0x80;
> > +		sb[3] = tf->error;
> > +		sb[4] = tf->status;
> > +		sb[5] = tf->device;
> > +		sb[6] = tf->nsect;
> >  		if (tf->flags & ATA_TFLAG_LBA48)  {
> > -			desc[8] |= 0x80;
> > +			sb[8] |= 0x80;
> >  			if (tf->hob_nsect)
> > -				desc[8] |= 0x40;
> > +				sb[8] |= 0x40;>  			if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah)
> > -				desc[8] |= 0x20;
> > +				sb[8] |= 0x20;
> >  		}
> > -		desc[9] = tf->lbal;
> > -		desc[10] = tf->lbam;
> > -		desc[11] = tf->lbah;
> > +		sb[9] = tf->lbal;
> > +		sb[10] = tf->lbam;
> > +		sb[11] = tf->lbah;
> >  	}
> >  }
> >  
> 
> -- 
> Damien Le Moal
> Western Digital Research
>

Thank you,
Igor
diff mbox series

Patch

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 4bfe47e7d266..8588512f5975 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -855,7 +855,6 @@  static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
 	struct scsi_cmnd *cmd = qc->scsicmd;
 	struct ata_taskfile *tf = &qc->result_tf;
 	unsigned char *sb = cmd->sense_buffer;
-	unsigned char *desc = sb + 8;
 	u8 sense_key, asc, ascq;
 
 	if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
@@ -880,8 +879,9 @@  static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
 		scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D);
 	}
 
-	if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {
+	if ((sb[0] & 0x7f) >= 0x72) {
 		u8 len;
+		unsigned char *desc;
 
 		/* descriptor format */
 		len = sb[7];
@@ -919,21 +919,21 @@  static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
 		}
 	} else {
 		/* Fixed sense format */
-		desc[0] = tf->error;
-		desc[1] = tf->status;
-		desc[2] = tf->device;
-		desc[3] = tf->nsect;
-		desc[7] = 0;
+		sb[0] |= 0x80;
+		sb[3] = tf->error;
+		sb[4] = tf->status;
+		sb[5] = tf->device;
+		sb[6] = tf->nsect;
 		if (tf->flags & ATA_TFLAG_LBA48)  {
-			desc[8] |= 0x80;
+			sb[8] |= 0x80;
 			if (tf->hob_nsect)
-				desc[8] |= 0x40;
+				sb[8] |= 0x40;
 			if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah)
-				desc[8] |= 0x20;
+				sb[8] |= 0x20;
 		}
-		desc[9] = tf->lbal;
-		desc[10] = tf->lbam;
-		desc[11] = tf->lbah;
+		sb[9] = tf->lbal;
+		sb[10] = tf->lbam;
+		sb[11] = tf->lbah;
 	}
 }