linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Tejun Heo <tj@kernel.org>
Cc: linux-ide@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Christoph Hellwig <hch@lst.de>,
	Shaun Tancheff <shaun.tancheff@seagate.com>,
	Damien Le Moal <damien.lemoal@hgst.com>,
	linux-scsi@vger.kernel.org,
	Sathya Prakash <sathya.prakash@broadcom.com>,
	Hannes Reinecke <hare@suse.de>, Hannes Reinecke <hare@suse.com>
Subject: [PATCH 09/14] libata-scsi: generate correct ATA pass-through sense
Date: Mon,  4 Apr 2016 11:44:02 +0200	[thread overview]
Message-ID: <1459763047-125551-10-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1459763047-125551-1-git-send-email-hare@suse.de>

Generate ATA pass-through sense for both fixed and descriptor
format sense.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/ata/libata-scsi.c | 93 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index c69186b..84c5e13 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1016,43 +1016,68 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
 				   &sense_key, &asc, &ascq, verbose);
 		ata_scsi_set_sense(cmd, sense_key, asc, ascq);
 	} else {
-		/* ATA PASS-THROUGH INFORMATION AVAILABLE */
-		ata_scsi_set_sense(cmd, RECOVERED_ERROR, 0, 0x1D);
+		/*
+		 * ATA PASS-THROUGH INFORMATION AVAILABLE
+		 * Always in descriptor format sense.
+		 */
+		scsi_build_sense_buffer(1, cmd->sense_buffer,
+					RECOVERED_ERROR, 0, 0x1D);
 	}
 
-	/*
-	 * Sense data is current and format is descriptor.
-	 */
-	sb[0] = 0x72;
-
-	desc[0] = 0x09;
-
-	/* set length of additional sense data */
-	sb[7] = 14;
-	desc[1] = 12;
-
-	/*
-	 * Copy registers into sense buffer.
-	 */
-	desc[2] = 0x00;
-	desc[3] = tf->feature;	/* == error reg */
-	desc[5] = tf->nsect;
-	desc[7] = tf->lbal;
-	desc[9] = tf->lbam;
-	desc[11] = tf->lbah;
-	desc[12] = tf->device;
-	desc[13] = tf->command; /* == status reg */
+	if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {
+		u8 len;
+
+		/* descriptor format */
+		len = sb[7];
+		desc = (char *)scsi_sense_desc_find(sb, len + 8, 9);
+		if (!desc) {
+			if (SCSI_SENSE_BUFFERSIZE < len + 14)
+				return;
+			sb[7] = len + 14;
+			desc = sb + 8 + len;
+		}
+		desc[0] = 9;
+		desc[1] = 12;
+		/*
+		 * Copy registers into sense buffer.
+		 */
+		desc[2] = 0x00;
+		desc[3] = tf->feature;	/* == error reg */
+		desc[5] = tf->nsect;
+		desc[7] = tf->lbal;
+		desc[9] = tf->lbam;
+		desc[11] = tf->lbah;
+		desc[12] = tf->device;
+		desc[13] = tf->command; /* == status reg */
 
-	/*
-	 * Fill in Extend bit, and the high order bytes
-	 * if applicable.
-	 */
-	if (tf->flags & ATA_TFLAG_LBA48) {
-		desc[2] |= 0x01;
-		desc[4] = tf->hob_nsect;
-		desc[6] = tf->hob_lbal;
-		desc[8] = tf->hob_lbam;
-		desc[10] = tf->hob_lbah;
+		/*
+		 * Fill in Extend bit, and the high order bytes
+		 * if applicable.
+		 */
+		if (tf->flags & ATA_TFLAG_LBA48) {
+			desc[2] |= 0x01;
+			desc[4] = tf->hob_nsect;
+			desc[6] = tf->hob_lbal;
+			desc[8] = tf->hob_lbam;
+			desc[10] = tf->hob_lbah;
+		}
+	} else {
+		/* Fixed sense format */
+		desc[0] = tf->feature;
+		desc[1] = tf->command; /* status */
+		desc[2] = tf->device;
+		desc[3] = tf->nsect;
+		desc[0] = 0;
+		if (tf->flags & ATA_TFLAG_LBA48)  {
+			desc[8] |= 0x80;
+			if (tf->hob_nsect)
+				desc[8] |= 0x40;
+			if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah)
+				desc[8] |= 0x20;
+		}
+		desc[9] = tf->lbal;
+		desc[10] = tf->lbam;
+		desc[11] = tf->lbah;
 	}
 }
 
-- 
1.8.5.6


  parent reply	other threads:[~2016-04-04  9:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-04  9:43 [PATCH 00/14] libata: SATL update Hannes Reinecke
2016-04-04  9:43 ` [PATCH 01/14] libata: Implement NCQ autosense Hannes Reinecke
2016-04-04  9:43 ` [PATCH 02/14] libata: Implement support for sense data reporting Hannes Reinecke
2016-04-04  9:43 ` [PATCH 03/14] libata-scsi: sanitize ata_gen_ata_sense() Hannes Reinecke
2016-04-04 11:26   ` Sergei Shtylyov
2016-04-04 16:22     ` Tejun Heo
2016-04-04 17:33       ` Sergei Shtylyov
2016-04-04  9:43 ` [PATCH 04/14] libata: sanitize ata_tf_read_block() Hannes Reinecke
2016-04-04  9:43 ` [PATCH 05/14] libata-scsi: use scsi_set_sense_information() Hannes Reinecke
2016-04-04  9:43 ` [PATCH 06/14] libata-eh: Set 'information' field for autosense Hannes Reinecke
2016-04-04  9:44 ` [PATCH 07/14] libata-scsi: use ata_scsi_set_sense() Hannes Reinecke
2016-04-04  9:44 ` [PATCH 08/14] libata: evaluate SCSI sense code Hannes Reinecke
2016-04-04 11:21   ` Sergei Shtylyov
2016-04-04  9:44 ` Hannes Reinecke [this message]
2016-04-04  9:44 ` [PATCH 10/14] libata: Implement control mode page to select sense format Hannes Reinecke
2016-04-04 12:53   ` kbuild test robot
2016-04-04  9:44 ` [PATCH 11/14] scsi: add scsi_set_sense_field_pointer() Hannes Reinecke
2016-04-04  9:44 ` [PATCH 12/14] libata-scsi: Set field pointer in sense code Hannes Reinecke
2016-04-04  9:44 ` [PATCH 13/14] libata-scsi: set bit pointer for sense code information Hannes Reinecke
2016-04-04  9:44 ` [PATCH 14/14] libata-scsi: Set information sense field for invalid parameter Hannes Reinecke
2016-04-04 15:22   ` kbuild test robot
2016-04-04 15:46 ` [PATCH 00/14] libata: SATL update Tejun Heo
2016-04-04 19:54   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459763047-125551-10-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=damien.lemoal@hgst.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=sathya.prakash@broadcom.com \
    --cc=shaun.tancheff@seagate.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).