aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ide/ide-io.c105
-rw-r--r--include/linux/ide.h35
2 files changed, 69 insertions, 71 deletions
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 4ce793c05629..8f371821c614 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -666,45 +666,54 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
666} 666}
667EXPORT_SYMBOL(ide_stall_queue); 667EXPORT_SYMBOL(ide_stall_queue);
668 668
669static inline int ide_lock_port(ide_hwif_t *hwif)
670{
671 if (hwif->busy)
672 return 1;
673
674 hwif->busy = 1;
675
676 return 0;
677}
678
679static inline void ide_unlock_port(ide_hwif_t *hwif)
680{
681 hwif->busy = 0;
682}
683
684static inline int ide_lock_host(struct ide_host *host, ide_hwif_t *hwif)
685{
686 int rc = 0;
687
688 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
689 rc = test_and_set_bit_lock(IDE_HOST_BUSY, &host->host_busy);
690 if (rc == 0) {
691 /* for atari only */
692 ide_get_lock(ide_intr, hwif);
693 }
694 }
695 return rc;
696}
697
698static inline void ide_unlock_host(struct ide_host *host)
699{
700 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
701 /* for atari only */
702 ide_release_lock();
703 clear_bit_unlock(IDE_HOST_BUSY, &host->host_busy);
704 }
705}
706
669/* 707/*
670 * Issue a new request to a drive from hwgroup 708 * Issue a new request to a drive from hwgroup
671 *
672 * A hwgroup is a serialized group of IDE interfaces. Usually there is
673 * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640)
674 * may have both interfaces in a single hwgroup to "serialize" access.
675 * Or possibly multiple ISA interfaces can share a common IRQ by being grouped
676 * together into one hwgroup for serialized access.
677 *
678 * Note also that several hwgroups can end up sharing a single IRQ,
679 * possibly along with many other devices. This is especially common in
680 * PCI-based systems with off-board IDE controller cards.
681 *
682 * The IDE driver uses a per-hwgroup lock to protect the hwgroup->busy flag.
683 *
684 * The first thread into the driver for a particular hwgroup sets the
685 * hwgroup->busy flag to indicate that this hwgroup is now active,
686 * and then initiates processing of the top request from the request queue.
687 *
688 * Other threads attempting entry notice the busy setting, and will simply
689 * queue their new requests and exit immediately. Note that hwgroup->busy
690 * remains set even when the driver is merely awaiting the next interrupt.
691 * Thus, the meaning is "this hwgroup is busy processing a request".
692 *
693 * When processing of a request completes, the completing thread or IRQ-handler
694 * will start the next request from the queue. If no more work remains,
695 * the driver will clear the hwgroup->busy flag and exit.
696 *
697 * The per-hwgroup spinlock is used to protect all access to the
698 * hwgroup->busy flag, but is otherwise not needed for most processing in
699 * the driver. This makes the driver much more friendlier to shared IRQs
700 * than previous designs, while remaining 100% (?) SMP safe and capable.
701 */ 709 */
702void do_ide_request(struct request_queue *q) 710void do_ide_request(struct request_queue *q)
703{ 711{
704 ide_drive_t *drive = q->queuedata; 712 ide_drive_t *drive = q->queuedata;
705 ide_hwif_t *hwif = drive->hwif; 713 ide_hwif_t *hwif = drive->hwif;
714 struct ide_host *host = hwif->host;
706 ide_hwgroup_t *hwgroup = hwif->hwgroup; 715 ide_hwgroup_t *hwgroup = hwif->hwgroup;
707 struct request *rq; 716 struct request *rq = NULL;
708 ide_startstop_t startstop; 717 ide_startstop_t startstop;
709 718
710 /* 719 /*
@@ -721,9 +730,13 @@ void do_ide_request(struct request_queue *q)
721 blk_remove_plug(q); 730 blk_remove_plug(q);
722 731
723 spin_unlock_irq(q->queue_lock); 732 spin_unlock_irq(q->queue_lock);
733
734 if (ide_lock_host(host, hwif))
735 goto plug_device_2;
736
724 spin_lock_irq(&hwgroup->lock); 737 spin_lock_irq(&hwgroup->lock);
725 738
726 if (!ide_lock_hwgroup(hwgroup, hwif)) { 739 if (!ide_lock_port(hwif)) {
727 ide_hwif_t *prev_port; 740 ide_hwif_t *prev_port;
728repeat: 741repeat:
729 prev_port = hwif->host->cur_port; 742 prev_port = hwif->host->cur_port;
@@ -731,7 +744,7 @@ repeat:
731 744
732 if (drive->dev_flags & IDE_DFLAG_SLEEPING) { 745 if (drive->dev_flags & IDE_DFLAG_SLEEPING) {
733 if (time_before(drive->sleep, jiffies)) { 746 if (time_before(drive->sleep, jiffies)) {
734 ide_unlock_hwgroup(hwgroup); 747 ide_unlock_port(hwif);
735 goto plug_device; 748 goto plug_device;
736 } 749 }
737 } 750 }
@@ -761,7 +774,7 @@ repeat:
761 spin_lock_irq(&hwgroup->lock); 774 spin_lock_irq(&hwgroup->lock);
762 775
763 if (!rq) { 776 if (!rq) {
764 ide_unlock_hwgroup(hwgroup); 777 ide_unlock_port(hwif);
765 goto out; 778 goto out;
766 } 779 }
767 780
@@ -782,7 +795,7 @@ repeat:
782 blk_pm_request(rq) == 0 && 795 blk_pm_request(rq) == 0 &&
783 (rq->cmd_flags & REQ_PREEMPT) == 0) { 796 (rq->cmd_flags & REQ_PREEMPT) == 0) {
784 /* there should be no pending command at this point */ 797 /* there should be no pending command at this point */
785 ide_unlock_hwgroup(hwgroup); 798 ide_unlock_port(hwif);
786 goto plug_device; 799 goto plug_device;
787 } 800 }
788 801
@@ -798,11 +811,15 @@ repeat:
798 goto plug_device; 811 goto plug_device;
799out: 812out:
800 spin_unlock_irq(&hwgroup->lock); 813 spin_unlock_irq(&hwgroup->lock);
814 if (rq == NULL)
815 ide_unlock_host(host);
801 spin_lock_irq(q->queue_lock); 816 spin_lock_irq(q->queue_lock);
802 return; 817 return;
803 818
804plug_device: 819plug_device:
805 spin_unlock_irq(&hwgroup->lock); 820 spin_unlock_irq(&hwgroup->lock);
821 ide_unlock_host(host);
822plug_device_2:
806 spin_lock_irq(q->queue_lock); 823 spin_lock_irq(q->queue_lock);
807 824
808 if (!elv_queue_empty(q)) 825 if (!elv_queue_empty(q))
@@ -844,9 +861,9 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
844 ide_dma_off_quietly(drive); 861 ide_dma_off_quietly(drive);
845 862
846 /* 863 /*
847 * un-busy drive etc (hwgroup->busy is cleared on return) and 864 * un-busy drive etc and make sure request is sane
848 * make sure request is sane
849 */ 865 */
866
850 rq = HWGROUP(drive)->rq; 867 rq = HWGROUP(drive)->rq;
851 868
852 if (!rq) 869 if (!rq)
@@ -895,6 +912,7 @@ static void ide_plug_device(ide_drive_t *drive)
895void ide_timer_expiry (unsigned long data) 912void ide_timer_expiry (unsigned long data)
896{ 913{
897 ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data; 914 ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data;
915 ide_hwif_t *uninitialized_var(hwif);
898 ide_drive_t *uninitialized_var(drive); 916 ide_drive_t *uninitialized_var(drive);
899 ide_handler_t *handler; 917 ide_handler_t *handler;
900 ide_expiry_t *expiry; 918 ide_expiry_t *expiry;
@@ -918,7 +936,6 @@ void ide_timer_expiry (unsigned long data)
918 printk(KERN_ERR "%s: ->cur_dev was NULL\n", __func__); 936 printk(KERN_ERR "%s: ->cur_dev was NULL\n", __func__);
919 hwgroup->handler = NULL; 937 hwgroup->handler = NULL;
920 } else { 938 } else {
921 ide_hwif_t *hwif;
922 ide_startstop_t startstop = ide_stopped; 939 ide_startstop_t startstop = ide_stopped;
923 940
924 if ((expiry = hwgroup->expiry) != NULL) { 941 if ((expiry = hwgroup->expiry) != NULL) {
@@ -964,15 +981,17 @@ void ide_timer_expiry (unsigned long data)
964 spin_lock_irq(&hwgroup->lock); 981 spin_lock_irq(&hwgroup->lock);
965 enable_irq(hwif->irq); 982 enable_irq(hwif->irq);
966 if (startstop == ide_stopped) { 983 if (startstop == ide_stopped) {
967 ide_unlock_hwgroup(hwgroup); 984 ide_unlock_port(hwif);
968 plug_device = 1; 985 plug_device = 1;
969 } 986 }
970 } 987 }
971 } 988 }
972 spin_unlock_irqrestore(&hwgroup->lock, flags); 989 spin_unlock_irqrestore(&hwgroup->lock, flags);
973 990
974 if (plug_device) 991 if (plug_device) {
992 ide_unlock_host(hwif->host);
975 ide_plug_device(drive); 993 ide_plug_device(drive);
994 }
976} 995}
977 996
978/** 997/**
@@ -1150,7 +1169,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1150 */ 1169 */
1151 if (startstop == ide_stopped) { 1170 if (startstop == ide_stopped) {
1152 if (hwgroup->handler == NULL) { /* paranoia */ 1171 if (hwgroup->handler == NULL) { /* paranoia */
1153 ide_unlock_hwgroup(hwgroup); 1172 ide_unlock_port(hwif);
1154 plug_device = 1; 1173 plug_device = 1;
1155 } else 1174 } else
1156 printk(KERN_ERR "%s: %s: huh? expected NULL handler " 1175 printk(KERN_ERR "%s: %s: huh? expected NULL handler "
@@ -1161,8 +1180,10 @@ out_handled:
1161out: 1180out:
1162 spin_unlock_irqrestore(&hwgroup->lock, flags); 1181 spin_unlock_irqrestore(&hwgroup->lock, flags);
1163out_early: 1182out_early:
1164 if (plug_device) 1183 if (plug_device) {
1184 ide_unlock_host(hwif->host);
1165 ide_plug_device(drive); 1185 ide_plug_device(drive);
1186 }
1166 1187
1167 return irq_ret; 1188 return irq_ret;
1168} 1189}
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 8b74ccdd221c..00df155b5a02 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -828,6 +828,7 @@ typedef struct hwif_s {
828 828
829 unsigned present : 1; /* this interface exists */ 829 unsigned present : 1; /* this interface exists */
830 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */ 830 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */
831 unsigned busy : 1; /* serializes devices on a port */
831 832
832 struct device gendev; 833 struct device gendev;
833 struct device *portdev; 834 struct device *portdev;
@@ -851,8 +852,13 @@ struct ide_host {
851 unsigned long host_flags; 852 unsigned long host_flags;
852 void *host_priv; 853 void *host_priv;
853 ide_hwif_t *cur_port; /* for hosts requiring serialization */ 854 ide_hwif_t *cur_port; /* for hosts requiring serialization */
855
856 /* used for hosts requiring serialization */
857 volatile long host_busy;
854}; 858};
855 859
860#define IDE_HOST_BUSY 0
861
856/* 862/*
857 * internal ide interrupt handler type 863 * internal ide interrupt handler type
858 */ 864 */
@@ -866,8 +872,6 @@ typedef struct hwgroup_s {
866 /* irq handler, if active */ 872 /* irq handler, if active */
867 ide_startstop_t (*handler)(ide_drive_t *); 873 ide_startstop_t (*handler)(ide_drive_t *);
868 874
869 /* BOOL: protects all fields below */
870 volatile int busy;
871 /* BOOL: polling active & poll_timeout field valid */ 875 /* BOOL: polling active & poll_timeout field valid */
872 unsigned int polling : 1; 876 unsigned int polling : 1;
873 877
@@ -1271,26 +1275,6 @@ extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout);
1271 1275
1272extern void ide_timer_expiry(unsigned long); 1276extern void ide_timer_expiry(unsigned long);
1273extern irqreturn_t ide_intr(int irq, void *dev_id); 1277extern irqreturn_t ide_intr(int irq, void *dev_id);
1274
1275static inline int ide_lock_hwgroup(ide_hwgroup_t *hwgroup, ide_hwif_t *hwif)
1276{
1277 if (hwgroup->busy)
1278 return 1;
1279
1280 hwgroup->busy = 1;
1281 /* for atari only */
1282 ide_get_lock(ide_intr, hwif);
1283
1284 return 0;
1285}
1286
1287static inline void ide_unlock_hwgroup(ide_hwgroup_t *hwgroup)
1288{
1289 /* for atari only */
1290 ide_release_lock();
1291 hwgroup->busy = 0;
1292}
1293
1294extern void do_ide_request(struct request_queue *); 1278extern void do_ide_request(struct request_queue *);
1295 1279
1296void ide_init_disk(struct gendisk *, ide_drive_t *); 1280void ide_init_disk(struct gendisk *, ide_drive_t *);
@@ -1617,13 +1601,6 @@ static inline void ide_set_max_pio(ide_drive_t *drive)
1617 1601
1618extern spinlock_t ide_lock; 1602extern spinlock_t ide_lock;
1619extern struct mutex ide_cfg_mtx; 1603extern struct mutex ide_cfg_mtx;
1620/*
1621 * Structure locking:
1622 *
1623 * ide_hwgroup_t->busy: hwgroup->lock
1624 * ide_hwif_t->{hwgroup,mate}: constant, no locking
1625 * ide_drive_t->hwif: constant, no locking
1626 */
1627 1604
1628#define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0) 1605#define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0)
1629 1606