linux-ide.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>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	Shaun Tancheff <shaun.tancheff@seagate.com>,
	Damien Le Moal <damien.lemoal@hgst.com>,
	linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
	Hannes Reinecke <hare@suse.com>
Subject: [PATCHv2 05/14] libata: NCQ Encapsulation for READ LOG DMA EXT
Date: Tue, 12 Apr 2016 08:47:49 +0200	[thread overview]
Message-ID: <1460443678-57934-6-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1460443678-57934-1-git-send-email-hare@suse.de>

Recent devices can use NCQ encapsulation for READ LOG DMA EXT,
so we should be using it if available.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/ata/libata-core.c |  5 ++---
 drivers/ata/libata-eh.c   | 30 +++++++++++++++++++++++++-----
 drivers/ata/libata.h      |  5 +++--
 include/linux/ata.h       |  5 +++++
 include/linux/libata.h    |  7 +++++++
 5 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index fa74b57..f48f152 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2085,7 +2085,7 @@ static void ata_dev_config_ncq_send_recv(struct ata_device *dev)
 	unsigned int err_mask;
 
 	err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV,
-				     0, ap->sector_buf, 1);
+				     0, ap->sector_buf, 1, true);
 	if (err_mask) {
 		ata_dev_dbg(dev,
 			    "failed to get NCQ Send/Recv Log Emask 0x%x\n",
@@ -2383,8 +2383,7 @@ int ata_dev_configure(struct ata_device *dev)
 			err_mask = ata_read_log_page(dev,
 						     ATA_LOG_SATA_ID_DEV_DATA,
 						     ATA_LOG_SATA_SETTINGS,
-						     sata_setting,
-						     1);
+						     sata_setting, 1, true);
 			if (err_mask)
 				ata_dev_dbg(dev,
 					    "failed to get Identify Device Data, Emask 0x%x\n",
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index e816619..dfe8fdc 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1493,6 +1493,7 @@ static const char *ata_err_string(unsigned int err_mask)
  *	@page: page to read
  *	@buf: buffer to store read page
  *	@sectors: number of sectors to read
+ *	@fpdma: flag if fpdma should be used
  *
  *	Read log page using READ_LOG_EXT command.
  *
@@ -1503,7 +1504,8 @@ static const char *ata_err_string(unsigned int err_mask)
  *	0 on success, AC_ERR_* mask otherwise.
  */
 unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
-			       u8 page, void *buf, unsigned int sectors)
+			       u8 page, void *buf, unsigned int sectors,
+			       bool fpdma)
 {
 	unsigned long ap_flags = dev->link->ap->flags;
 	struct ata_taskfile tf;
@@ -1521,25 +1523,43 @@ unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
 
 retry:
 	ata_tf_init(dev, &tf);
-	if (dev->dma_mode && ata_id_has_read_log_dma_ext(dev->id) &&
+	if (fpdma && ata_ncq_enabled(dev) &&
+	    ata_fpdma_read_log_supported(dev)) {
+		tf.command = ATA_CMD_FPDMA_RECV;
+		tf.protocol = ATA_PROT_NCQ;
+		tf.hob_nsect = ATA_SUBCMD_FPDMA_RECV_RD_LOG_DMA_EXT & 0x1f;
+		tf.nsect = ATA_TAG_INTERNAL << 3;
+		tf.feature = sectors;
+		tf.hob_feature = sectors >> 8;
+		dma = true;
+	} else if (dev->dma_mode && ata_id_has_read_log_dma_ext(dev->id) &&
 	    !(dev->horkage & ATA_HORKAGE_NO_NCQ_LOG)) {
 		tf.command = ATA_CMD_READ_LOG_DMA_EXT;
 		tf.protocol = ATA_PROT_DMA;
+		tf.nsect = sectors;
+		tf.hob_nsect = sectors >> 8;
 		dma = true;
 	} else {
 		tf.command = ATA_CMD_READ_LOG_EXT;
 		tf.protocol = ATA_PROT_PIO;
+		tf.nsect = sectors;
+		tf.hob_nsect = sectors >> 8;
 		dma = false;
 	}
 	tf.lbal = log;
 	tf.lbam = page;
-	tf.nsect = sectors;
-	tf.hob_nsect = sectors >> 8;
 	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE;
 
 	err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
 				     buf, sectors * ATA_SECT_SIZE, 0);
 
+	if (err_mask && fpdma) {
+		ata_dev_warn(dev,
+			     "RECEIVE FPDMA failed, trying READ LOG_DMA EXT\n");
+		dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &=
+		    ~ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED;
+		goto retry;
+	}
 	if (err_mask && dma) {
 		dev->horkage |= ATA_HORKAGE_NO_NCQ_LOG;
 		ata_dev_warn(dev, "READ LOG DMA EXT failed, trying unqueued\n");
@@ -1573,7 +1593,7 @@ static int ata_eh_read_log_10h(struct ata_device *dev,
 	u8 csum;
 	int i;
 
-	err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
+	err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1, false);
 	if (err_mask)
 		return -EIO;
 
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 3b301a4..5732f98 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -169,8 +169,9 @@ extern void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev,
 			       unsigned int action);
 extern void ata_eh_done(struct ata_link *link, struct ata_device *dev,
 			unsigned int action);
-extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
-				      u8 page, void *buf, unsigned int sectors);
+extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log, u8 page,
+				      void *buf, unsigned int sectors,
+				      bool fpdma);
 extern void ata_eh_autopsy(struct ata_port *ap);
 const char *ata_get_cmd_descript(u8 command);
 extern void ata_eh_report(struct ata_port *ap);
diff --git a/include/linux/ata.h b/include/linux/ata.h
index b84210a..94ccde5 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -306,6 +306,9 @@ enum {
 	/* marked obsolete in the ATA/ATAPI-7 spec */
 	ATA_CMD_RESTORE		= 0x10,
 
+	/* Subcmds for ATA_CMD_FPDMA_RECV */
+	ATA_SUBCMD_FPDMA_RECV_RD_LOG_DMA_EXT = 0x01,
+
 	/* Subcmds for ATA_CMD_FPDMA_SEND */
 	ATA_SUBCMD_FPDMA_SEND_DSM            = 0x00,
 	ATA_SUBCMD_FPDMA_SEND_WR_LOG_DMA_EXT = 0x02,
@@ -329,7 +332,9 @@ enum {
 	ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET	= 0x04,
 	ATA_LOG_NCQ_SEND_RECV_DSM_TRIM		= (1 << 0),
 	ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET	= 0x08,
+	ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED  = (1 << 0),
 	ATA_LOG_NCQ_SEND_RECV_WR_LOG_OFFSET	= 0x0C,
+	ATA_LOG_NCQ_SEND_RECV_WR_LOG_SUPPORTED  = (1 << 0),
 	ATA_LOG_NCQ_SEND_RECV_SIZE		= 0x10,
 
 	/* READ/WRITE LONG (obsolete) */
diff --git a/include/linux/libata.h b/include/linux/libata.h
index a418bca..09ddb5a 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1642,6 +1642,13 @@ static inline bool ata_fpdma_dsm_supported(struct ata_device *dev)
 		 ATA_LOG_NCQ_SEND_RECV_DSM_TRIM);
 }
 
+static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
+{
+	return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
+		(dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &
+		 ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
+}
+
 static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
 {
 	qc->tf.ctl |= ATA_NIEN;
-- 
1.8.5.6


  parent reply	other threads:[~2016-04-12  6:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-12  6:47 [PATCHv2 00/14] ZAC support Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 01/14] libata: do not attempt to retrieve sense code twice Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 02/14] libsas: enable FPDMA SEND/RECEIVE Hannes Reinecke
2016-04-12  7:10   ` kbuild test robot
2016-04-12  7:19   ` kbuild test robot
2016-04-12  7:25   ` Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 03/14] libsas: Define ATA_CMD_NCQ_NON_DATA Hannes Reinecke
2016-04-12 10:03   ` John Garry
2016-04-12 10:25     ` Hannes Reinecke
2016-04-14  9:06       ` John Garry
2016-04-14  9:39         ` Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 04/14] libata: Separate out ata_dev_config_ncq_send_recv() Hannes Reinecke
2016-04-12  6:47 ` Hannes Reinecke [this message]
2016-04-13 18:07   ` [PATCHv2 05/14] libata: NCQ Encapsulation for READ LOG DMA EXT Tejun Heo
2016-04-14  5:44     ` Hannes Reinecke
2016-04-14 15:43       ` Tejun Heo
2016-04-14 15:59         ` Hannes Reinecke
2016-04-14 16:07           ` Tejun Heo
2016-04-15 12:32             ` Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 06/14] libata: Check log page directory before accessing pages Hannes Reinecke
2016-04-13 18:08   ` Tejun Heo
2016-04-14  5:44     ` Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 07/14] libata-trace: decode subcommands Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 08/14] libata-scsi: Generate sense code for disabled devices Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 09/14] libata: fixup ZAC device disabling Hannes Reinecke
2016-04-13 18:09   ` Tejun Heo
2016-04-14  5:48     ` Hannes Reinecke
2016-04-14 15:43       ` Tejun Heo
2016-04-12  6:47 ` [PATCHv2 10/14] libata: implement ZBC IN translation Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 11/14] libata: Implement ZBC OUT translation Hannes Reinecke
2016-04-12 18:54   ` Shaun Tancheff
2016-04-12  6:47 ` [PATCHv2 12/14] libata: NCQ encapsulation for ZAC MANAGEMENT OUT Hannes Reinecke
2016-04-12  6:47 ` [PATCHv2 13/14] libata: support device-managed ZAC devices Hannes Reinecke
2016-04-13 20:50   ` Shaun Tancheff
2016-04-12  6:47 ` [PATCHv2 14/14] libata: support host-aware and host-managed " 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=1460443678-57934-6-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=damien.lemoal@hgst.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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).