All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: jgarzik@pobox.com, alan@lxorguk.ukuu.org.uk, albertcc@tw.ibm.com,
	axboe@suse.de, linux-ide@vger.kernel.org
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 10/14] libata: implement ata_ncq_complete()
Date: Mon, 3 Apr 2006 17:32:39 +0900	[thread overview]
Message-ID: <11440531593561-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <1144053158183-git-send-email-htejun@gmail.com>

Implement NCQ helper function ata_ncq_complete().  This function takes
the current value of SActive, compares it against ap->sactive and
invoke ata_qc_complete() on all finished commands.  This function is
to be used by interrupt handlers implementing NCQ.

Signed-off-by: Tejun Heo <htejun@gmail.com>

---

 drivers/scsi/libata-core.c |   47 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/libata.h     |    1 +
 2 files changed, 48 insertions(+), 0 deletions(-)

429f220dc61c1d67cedbbc7da9eb9f52b20c2271
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 56637f0..fa941cc 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -4574,6 +4574,52 @@ irqreturn_t ata_interrupt (int irq, void
 	return IRQ_RETVAL(handled);
 }
 
+/**
+ *	ata_ncq_complete - NCQ driver helper.  Complete requests normally.
+ *	@ap: port in question
+ *	@sactive: current SActive value
+ *
+ *	Complete in-flight commands.  One device per port is assumed.
+ *	This functions is meant to be called from low-level driver's
+ *	interrupt routine to complete requests normally.  On
+ *	invocation, if non-NCQ command was in-flight, it's completed
+ *	normally.  If NCQ commands were in-flight, cached ap->sactive
+ *	and new @sactive is compared and commands are completed
+ *	accordingly.
+ *
+ *	LOCKING:
+ *	spin_lock_irqsave(host_set lock)
+ *
+ *	RETURNS:
+ *	Number of completed commands on success, -errno otherwise.
+ */
+int ata_ncq_complete(struct ata_port *ap, u32 sactive)
+{
+	int nr_done = 0;
+	unsigned long done_mask = 0;
+	int i;
+
+	if (ap->sactive) {
+		done_mask = ap->sactive ^ sactive;
+
+		if (unlikely(done_mask & sactive)) {
+			printk(KERN_ERR "ata%u: illegal sactive transition "
+			       "(%08x->%08x)\n", ap->id, ap->sactive, sactive);
+			return -EINVAL;
+		}
+	} else if (ap->active_tag != ATA_TAG_POISON)
+		done_mask = 1 << ap->active_tag;
+
+	for (i = 0; i < ATA_MAX_QUEUE; i++) {
+		struct ata_queued_cmd *qc = ata_qc_from_tag(ap, i);
+		if (done_mask & (1 << i) && qc) {
+			ata_qc_complete(qc);
+			nr_done++;
+		}
+	}
+
+	return nr_done;
+}
 
 /*
  * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
@@ -5300,6 +5346,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_slave_config)
 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
 EXPORT_SYMBOL_GPL(ata_scsi_release);
 EXPORT_SYMBOL_GPL(ata_host_intr);
+EXPORT_SYMBOL_GPL(ata_ncq_complete);
 EXPORT_SYMBOL_GPL(ata_id_string);
 EXPORT_SYMBOL_GPL(ata_id_c_string);
 EXPORT_SYMBOL_GPL(ata_scsi_simulate);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 9ae1f03..b9abfb3 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -580,6 +580,7 @@ extern int ata_scsi_ioctl(struct scsi_de
 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
 extern int ata_scsi_release(struct Scsi_Host *host);
 extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
+extern int ata_ncq_complete(struct ata_port *ap, u32 sactive);
 extern int ata_scsi_device_resume(struct scsi_device *);
 extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state);
 extern int ata_device_resume(struct ata_port *, struct ata_device *);
-- 
1.2.4



  parent reply	other threads:[~2006-04-03  8:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-03  8:32 [PATCHSET] libata: add NCQ support Tejun Heo
2006-04-03  8:32 ` [PATCH 08/14] libata: update EH to handle NCQ Tejun Heo
2006-04-03  8:32 ` [PATCH 05/14] libata: implement command exclusion Tejun Heo
2006-04-03  8:32 ` [PATCH 03/14] libata: pass ata_scsi_translate() return value to SCSI midlayer Tejun Heo
2006-04-03  8:32 ` [PATCH 09/14] libata: implement NCQ device configuration Tejun Heo
2006-04-03  8:32 ` [PATCH 02/14] libata: add NCQ related libata flags Tejun Heo
2006-04-03  8:32 ` [PATCH 07/14] libata: implement ata_eh_read_log_10h() Tejun Heo
2006-04-03  8:32 ` [PATCH 01/14] libata: add NCQ related ATA constants and id macros Tejun Heo
2006-04-03  8:32 ` [PATCH 06/14] libata: implement NCQ command translation Tejun Heo
2006-04-03  8:32 ` [PATCH 04/14] libata: implement ap->sactive Tejun Heo
2006-04-03  8:32 ` Tejun Heo [this message]
2006-04-03  8:32 ` [PATCH 12/14] ahci: add HOST_CAP_NCQ constant Tejun Heo
2006-04-03  8:32 ` [PATCH 13/14] ahci: kill pp->cmd_tbl_sg Tejun Heo
2006-04-03  8:32 ` [PATCH 11/14] libata: clean up AHCI constants in preparation for NCQ Tejun Heo
2006-04-03  8:32 ` [PATCH 14/14] ahci: implement NCQ suppport Tejun Heo

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=11440531593561-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=albertcc@tw.ibm.com \
    --cc=axboe@suse.de \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.