aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2006-03-05 01:29:09 -0500
committerJeff Garzik <jeff@garzik.org>2006-03-11 17:57:20 -0500
commit86e45b6bd6900c4a0b3666fb18b46e215f775c4f (patch)
tree5b86ebd0b0b17d05bdfdd07b7683f7348577b52a
parentd7fc3ca1cd0ecce82263299c6b1631fc83b0ec79 (diff)
[PATCH] libata: implement port_task
Implement port_task. LLDD's can schedule a function to be executed with context after specified delay. libata core takes care of synchronization against EH. This is generalized form of pio_task and packet_task which are tied to PIO hsm implementation. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
-rw-r--r--drivers/scsi/libata-core.c77
-rw-r--r--drivers/scsi/libata-scsi.c2
-rw-r--r--drivers/scsi/libata.h1
-rw-r--r--include/linux/libata.h4
4 files changed, 84 insertions, 0 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 5dbcf0cf4a10..d59d462130c1 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -721,6 +721,81 @@ static unsigned int ata_pio_modes(const struct ata_device *adev)
721 timing API will get this right anyway */ 721 timing API will get this right anyway */
722} 722}
723 723
724/**
725 * ata_port_queue_task - Queue port_task
726 * @ap: The ata_port to queue port_task for
727 *
728 * Schedule @fn(@data) for execution after @delay jiffies using
729 * port_task. There is one port_task per port and it's the
730 * user(low level driver)'s responsibility to make sure that only
731 * one task is active at any given time.
732 *
733 * libata core layer takes care of synchronization between
734 * port_task and EH. ata_port_queue_task() may be ignored for EH
735 * synchronization.
736 *
737 * LOCKING:
738 * Inherited from caller.
739 */
740void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
741 unsigned long delay)
742{
743 int rc;
744
745 if (ap->flags & ATA_FLAG_FLUSH_PIO_TASK)
746 return;
747
748 PREPARE_WORK(&ap->port_task, fn, data);
749
750 if (!delay)
751 rc = queue_work(ata_wq, &ap->port_task);
752 else
753 rc = queue_delayed_work(ata_wq, &ap->port_task, delay);
754
755 /* rc == 0 means that another user is using port task */
756 WARN_ON(rc == 0);
757}
758
759/**
760 * ata_port_flush_task - Flush port_task
761 * @ap: The ata_port to flush port_task for
762 *
763 * After this function completes, port_task is guranteed not to
764 * be running or scheduled.
765 *
766 * LOCKING:
767 * Kernel thread context (may sleep)
768 */
769void ata_port_flush_task(struct ata_port *ap)
770{
771 unsigned long flags;
772
773 DPRINTK("ENTER\n");
774
775 spin_lock_irqsave(&ap->host_set->lock, flags);
776 ap->flags |= ATA_FLAG_FLUSH_PIO_TASK;
777 spin_unlock_irqrestore(&ap->host_set->lock, flags);
778
779 DPRINTK("flush #1\n");
780 flush_workqueue(ata_wq);
781
782 /*
783 * At this point, if a task is running, it's guaranteed to see
784 * the FLUSH flag; thus, it will never queue pio tasks again.
785 * Cancel and flush.
786 */
787 if (!cancel_delayed_work(&ap->port_task)) {
788 DPRINTK("flush #2\n");
789 flush_workqueue(ata_wq);
790 }
791
792 spin_lock_irqsave(&ap->host_set->lock, flags);
793 ap->flags &= ~ATA_FLAG_FLUSH_PIO_TASK;
794 spin_unlock_irqrestore(&ap->host_set->lock, flags);
795
796 DPRINTK("EXIT\n");
797}
798
724static inline void 799static inline void
725ata_queue_packet_task(struct ata_port *ap) 800ata_queue_packet_task(struct ata_port *ap)
726{ 801{
@@ -4617,6 +4692,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4617 ap->active_tag = ATA_TAG_POISON; 4692 ap->active_tag = ATA_TAG_POISON;
4618 ap->last_ctl = 0xFF; 4693 ap->last_ctl = 0xFF;
4619 4694
4695 INIT_WORK(&ap->port_task, NULL, NULL);
4620 INIT_WORK(&ap->packet_task, atapi_packet_task, ap); 4696 INIT_WORK(&ap->packet_task, atapi_packet_task, ap);
4621 INIT_WORK(&ap->pio_task, ata_pio_task, ap); 4697 INIT_WORK(&ap->pio_task, ata_pio_task, ap);
4622 INIT_LIST_HEAD(&ap->eh_done_q); 4698 INIT_LIST_HEAD(&ap->eh_done_q);
@@ -5088,6 +5164,7 @@ EXPORT_SYMBOL_GPL(ata_dev_revalidate);
5088EXPORT_SYMBOL_GPL(ata_port_disable); 5164EXPORT_SYMBOL_GPL(ata_port_disable);
5089EXPORT_SYMBOL_GPL(ata_ratelimit); 5165EXPORT_SYMBOL_GPL(ata_ratelimit);
5090EXPORT_SYMBOL_GPL(ata_busy_sleep); 5166EXPORT_SYMBOL_GPL(ata_busy_sleep);
5167EXPORT_SYMBOL_GPL(ata_port_queue_task);
5091EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 5168EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
5092EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 5169EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
5093EXPORT_SYMBOL_GPL(ata_scsi_timed_out); 5170EXPORT_SYMBOL_GPL(ata_scsi_timed_out);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index d0bd94abb413..ccedb4536977 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -785,6 +785,8 @@ int ata_scsi_error(struct Scsi_Host *host)
785 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); 785 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
786 spin_unlock_irqrestore(&ap->host_set->lock, flags); 786 spin_unlock_irqrestore(&ap->host_set->lock, flags);
787 787
788 ata_port_flush_task(ap);
789
788 ap->ops->eng_timeout(ap); 790 ap->ops->eng_timeout(ap);
789 791
790 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q)); 792 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index d822eba05f3c..f4c48c91b63d 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -45,6 +45,7 @@ extern int libata_fua;
45extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 45extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
46 struct ata_device *dev); 46 struct ata_device *dev);
47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); 47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc);
48extern void ata_port_flush_task(struct ata_port *ap);
48extern void ata_qc_free(struct ata_queued_cmd *qc); 49extern void ata_qc_free(struct ata_queued_cmd *qc);
49extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc); 50extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc);
50extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); 51extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 66dce58f1941..3ad2570f663b 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -388,6 +388,8 @@ struct ata_port {
388 struct ata_host_stats stats; 388 struct ata_host_stats stats;
389 struct ata_host_set *host_set; 389 struct ata_host_set *host_set;
390 390
391 struct work_struct port_task;
392
391 struct work_struct packet_task; 393 struct work_struct packet_task;
392 394
393 struct work_struct pio_task; 395 struct work_struct pio_task;
@@ -515,6 +517,8 @@ extern int ata_ratelimit(void);
515extern unsigned int ata_busy_sleep(struct ata_port *ap, 517extern unsigned int ata_busy_sleep(struct ata_port *ap,
516 unsigned long timeout_pat, 518 unsigned long timeout_pat,
517 unsigned long timeout); 519 unsigned long timeout);
520extern void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *),
521 void *data, unsigned long delay);
518 522
519/* 523/*
520 * Default driver ops implementations 524 * Default driver ops implementations