aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/Kconfig35
-rw-r--r--drivers/ide/Makefile4
-rw-r--r--drivers/ide/aec62xx.c4
-rw-r--r--drivers/ide/alim15x3.c10
-rw-r--r--drivers/ide/amd74xx.c4
-rw-r--r--drivers/ide/au1xxx-ide.c11
-rw-r--r--drivers/ide/cmd640.c5
-rw-r--r--drivers/ide/cmd64x.c27
-rw-r--r--drivers/ide/cs5520.c2
-rw-r--r--drivers/ide/cy82c693.c3
-rw-r--r--drivers/ide/falconide.c1
-rw-r--r--drivers/ide/gayle.c6
-rw-r--r--drivers/ide/hpt366.c31
-rw-r--r--drivers/ide/icside.c12
-rw-r--r--drivers/ide/ide-acpi.c26
-rw-r--r--drivers/ide/ide-atapi.c257
-rw-r--r--drivers/ide/ide-cd.c313
-rw-r--r--drivers/ide/ide-cd.h48
-rw-r--r--drivers/ide/ide-disk.c4
-rw-r--r--drivers/ide/ide-dma-sff.c105
-rw-r--r--drivers/ide/ide-dma.c2
-rw-r--r--drivers/ide/ide-floppy.c30
-rw-r--r--drivers/ide/ide-floppy_ioctl.c58
-rw-r--r--drivers/ide/ide-gd.c3
-rw-r--r--drivers/ide/ide-gd.h10
-rw-r--r--drivers/ide/ide-h8300.c1
-rw-r--r--drivers/ide/ide-io.c856
-rw-r--r--drivers/ide/ide-ioctls.c6
-rw-r--r--drivers/ide/ide-iops.c114
-rw-r--r--drivers/ide/ide-legacy.c58
-rw-r--r--drivers/ide/ide-lib.c112
-rw-r--r--drivers/ide/ide-park.c27
-rw-r--r--drivers/ide/ide-pm.c235
-rw-r--r--drivers/ide/ide-probe.c799
-rw-r--r--drivers/ide/ide-proc.c52
-rw-r--r--drivers/ide/ide-sysfs.c125
-rw-r--r--drivers/ide/ide-tape.c22
-rw-r--r--drivers/ide/ide-taskfile.c14
-rw-r--r--drivers/ide/ide.c342
-rw-r--r--drivers/ide/ide_arm.c11
-rw-r--r--drivers/ide/it8172.c166
-rw-r--r--drivers/ide/it8213.c4
-rw-r--r--drivers/ide/it821x.c13
-rw-r--r--drivers/ide/macide.c1
-rw-r--r--drivers/ide/ns87415.c14
-rw-r--r--drivers/ide/palm_bk3710.c3
-rw-r--r--drivers/ide/pdc202xx_new.c4
-rw-r--r--drivers/ide/pdc202xx_old.c23
-rw-r--r--drivers/ide/piix.c8
-rw-r--r--drivers/ide/pmac.c7
-rw-r--r--drivers/ide/q40ide.c1
-rw-r--r--drivers/ide/qd65xx.c7
-rw-r--r--drivers/ide/qd65xx.h4
-rw-r--r--drivers/ide/rz1000.c36
-rw-r--r--drivers/ide/sc1200.c9
-rw-r--r--drivers/ide/scc_pata.c33
-rw-r--r--drivers/ide/serverworks.c2
-rw-r--r--drivers/ide/setup-pci.c12
-rw-r--r--drivers/ide/sgiioc4.c15
-rw-r--r--drivers/ide/siimage.c11
-rw-r--r--drivers/ide/sis5513.c2
-rw-r--r--drivers/ide/sl82c105.c5
-rw-r--r--drivers/ide/slc90e66.c4
-rw-r--r--drivers/ide/tc86c001.c17
-rw-r--r--drivers/ide/triflex.c2
-rw-r--r--drivers/ide/trm290.c14
-rw-r--r--drivers/ide/tx4938ide.c15
-rw-r--r--drivers/ide/tx4939ide.c76
-rw-r--r--drivers/ide/umc8672.c12
-rw-r--r--drivers/ide/via82cxxx.c2
70 files changed, 1938 insertions, 2369 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index e6857e01d1ba..3f9503867e6b 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -62,6 +62,9 @@ config IDE_TIMINGS
62config IDE_ATAPI 62config IDE_ATAPI
63 bool 63 bool
64 64
65config IDE_LEGACY
66 bool
67
65config BLK_DEV_IDE_SATA 68config BLK_DEV_IDE_SATA
66 bool "Support for SATA (deprecated; conflicts with libata SATA driver)" 69 bool "Support for SATA (deprecated; conflicts with libata SATA driver)"
67 default n 70 default n
@@ -134,6 +137,7 @@ config BLK_DEV_DELKIN
134 137
135config BLK_DEV_IDECD 138config BLK_DEV_IDECD
136 tristate "Include IDE/ATAPI CDROM support" 139 tristate "Include IDE/ATAPI CDROM support"
140 select IDE_ATAPI
137 ---help--- 141 ---help---
138 If you have a CD-ROM drive using the ATAPI protocol, say Y. ATAPI is 142 If you have a CD-ROM drive using the ATAPI protocol, say Y. ATAPI is
139 a newer protocol used by IDE CD-ROM and TAPE drives, similar to the 143 a newer protocol used by IDE CD-ROM and TAPE drives, similar to the
@@ -182,23 +186,6 @@ config BLK_DEV_IDETAPE
182 To compile this driver as a module, choose M here: the 186 To compile this driver as a module, choose M here: the
183 module will be called ide-tape. 187 module will be called ide-tape.
184 188
185config BLK_DEV_IDESCSI
186 tristate "SCSI emulation support (DEPRECATED)"
187 depends on SCSI
188 select IDE_ATAPI
189 ---help---
190 WARNING: ide-scsi is no longer needed for cd writing applications!
191 The 2.6 kernel supports direct writing to ide-cd, which eliminates
192 the need for ide-scsi + the entire scsi stack just for writing a
193 cd. The new method is more efficient in every way.
194
195 This will provide SCSI host adapter emulation for IDE ATAPI devices,
196 and will allow you to use a SCSI device driver instead of a native
197 ATAPI driver.
198
199 If both this SCSI emulation and native ATAPI support are compiled
200 into the kernel, the native support will be used.
201
202config BLK_DEV_IDEACPI 189config BLK_DEV_IDEACPI
203 bool "IDE ACPI support" 190 bool "IDE ACPI support"
204 depends on ACPI 191 depends on ACPI
@@ -524,6 +511,13 @@ config BLK_DEV_PIIX
524 This allows the kernel to change PIO, DMA and UDMA speeds and to 511 This allows the kernel to change PIO, DMA and UDMA speeds and to
525 configure the chip to optimum performance. 512 configure the chip to optimum performance.
526 513
514config BLK_DEV_IT8172
515 tristate "IT8172 IDE support"
516 select BLK_DEV_IDEDMA_PCI
517 help
518 This driver adds support for the IDE controller on the
519 IT8172 System Controller.
520
527config BLK_DEV_IT8213 521config BLK_DEV_IT8213
528 tristate "IT8213 IDE support" 522 tristate "IT8213 IDE support"
529 select BLK_DEV_IDEDMA_PCI 523 select BLK_DEV_IDEDMA_PCI
@@ -724,7 +718,7 @@ config BLK_DEV_IDE_TX4939
724 718
725config IDE_ARM 719config IDE_ARM
726 tristate "ARM IDE support" 720 tristate "ARM IDE support"
727 depends on ARM && (ARCH_CLPS7500 || ARCH_RPC || ARCH_SHARK) 721 depends on ARM && (ARCH_RPC || ARCH_SHARK)
728 default y 722 default y
729 723
730config BLK_DEV_IDE_ICSIDE 724config BLK_DEV_IDE_ICSIDE
@@ -856,6 +850,7 @@ config BLK_DEV_4DRIVES
856config BLK_DEV_ALI14XX 850config BLK_DEV_ALI14XX
857 tristate "ALI M14xx support" 851 tristate "ALI M14xx support"
858 select IDE_TIMINGS 852 select IDE_TIMINGS
853 select IDE_LEGACY
859 help 854 help
860 This driver is enabled at runtime using the "ali14xx.probe" kernel 855 This driver is enabled at runtime using the "ali14xx.probe" kernel
861 boot parameter. It enables support for the secondary IDE interface 856 boot parameter. It enables support for the secondary IDE interface
@@ -866,6 +861,7 @@ config BLK_DEV_ALI14XX
866 861
867config BLK_DEV_DTC2278 862config BLK_DEV_DTC2278
868 tristate "DTC-2278 support" 863 tristate "DTC-2278 support"
864 select IDE_LEGACY
869 help 865 help
870 This driver is enabled at runtime using the "dtc2278.probe" kernel 866 This driver is enabled at runtime using the "dtc2278.probe" kernel
871 boot parameter. It enables support for the secondary IDE interface 867 boot parameter. It enables support for the secondary IDE interface
@@ -876,6 +872,7 @@ config BLK_DEV_DTC2278
876config BLK_DEV_HT6560B 872config BLK_DEV_HT6560B
877 tristate "Holtek HT6560B support" 873 tristate "Holtek HT6560B support"
878 select IDE_TIMINGS 874 select IDE_TIMINGS
875 select IDE_LEGACY
879 help 876 help
880 This driver is enabled at runtime using the "ht6560b.probe" kernel 877 This driver is enabled at runtime using the "ht6560b.probe" kernel
881 boot parameter. It enables support for the secondary IDE interface 878 boot parameter. It enables support for the secondary IDE interface
@@ -886,6 +883,7 @@ config BLK_DEV_HT6560B
886config BLK_DEV_QD65XX 883config BLK_DEV_QD65XX
887 tristate "QDI QD65xx support" 884 tristate "QDI QD65xx support"
888 select IDE_TIMINGS 885 select IDE_TIMINGS
886 select IDE_LEGACY
889 help 887 help
890 This driver is enabled at runtime using the "qd65xx.probe" kernel 888 This driver is enabled at runtime using the "qd65xx.probe" kernel
891 boot parameter. It permits faster I/O speeds to be set. See the 889 boot parameter. It permits faster I/O speeds to be set. See the
@@ -894,6 +892,7 @@ config BLK_DEV_QD65XX
894 892
895config BLK_DEV_UMC8672 893config BLK_DEV_UMC8672
896 tristate "UMC-8672 support" 894 tristate "UMC-8672 support"
895 select IDE_LEGACY
897 help 896 help
898 This driver is enabled at runtime using the "umc8672.probe" kernel 897 This driver is enabled at runtime using the "umc8672.probe" kernel
899 boot parameter. It enables support for the secondary IDE interface 898 boot parameter. It enables support for the secondary IDE interface
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 7818d402b188..c2b9c93f0095 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -5,7 +5,7 @@
5EXTRA_CFLAGS += -Idrivers/ide 5EXTRA_CFLAGS += -Idrivers/ide
6 6
7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ 7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8 ide-taskfile.o ide-park.o ide-pio-blacklist.o 8 ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o ide-sysfs.o
9 9
10# core IDE code 10# core IDE code
11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o 11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o
@@ -15,6 +15,7 @@ ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o
15ide-core-$(CONFIG_BLK_DEV_IDEDMA_SFF) += ide-dma-sff.o 15ide-core-$(CONFIG_BLK_DEV_IDEDMA_SFF) += ide-dma-sff.o
16ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o 16ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o
17ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o 17ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o
18ide-core-$(CONFIG_IDE_LEGACY) += ide-legacy.o
18 19
19obj-$(CONFIG_IDE) += ide-core.o 20obj-$(CONFIG_IDE) += ide-core.o
20 21
@@ -46,6 +47,7 @@ obj-$(CONFIG_BLK_DEV_SC1200) += sc1200.o
46obj-$(CONFIG_BLK_DEV_CY82C693) += cy82c693.o 47obj-$(CONFIG_BLK_DEV_CY82C693) += cy82c693.o
47obj-$(CONFIG_BLK_DEV_DELKIN) += delkin_cb.o 48obj-$(CONFIG_BLK_DEV_DELKIN) += delkin_cb.o
48obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o 49obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o
50obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o
49obj-$(CONFIG_BLK_DEV_IT8213) += it8213.o 51obj-$(CONFIG_BLK_DEV_IT8213) += it8213.o
50obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o 52obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o
51obj-$(CONFIG_BLK_DEV_JMICRON) += jmicron.o 53obj-$(CONFIG_BLK_DEV_JMICRON) += jmicron.o
diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
index 4142c698e0d3..4485b9c6f0e6 100644
--- a/drivers/ide/aec62xx.c
+++ b/drivers/ide/aec62xx.c
@@ -83,7 +83,7 @@ static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entr
83 83
84static void aec6210_set_mode(ide_drive_t *drive, const u8 speed) 84static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
85{ 85{
86 ide_hwif_t *hwif = HWIF(drive); 86 ide_hwif_t *hwif = drive->hwif;
87 struct pci_dev *dev = to_pci_dev(hwif->dev); 87 struct pci_dev *dev = to_pci_dev(hwif->dev);
88 struct ide_host *host = pci_get_drvdata(dev); 88 struct ide_host *host = pci_get_drvdata(dev);
89 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv; 89 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
@@ -111,7 +111,7 @@ static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
111 111
112static void aec6260_set_mode(ide_drive_t *drive, const u8 speed) 112static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
113{ 113{
114 ide_hwif_t *hwif = HWIF(drive); 114 ide_hwif_t *hwif = drive->hwif;
115 struct pci_dev *dev = to_pci_dev(hwif->dev); 115 struct pci_dev *dev = to_pci_dev(hwif->dev);
116 struct ide_host *host = pci_get_drvdata(dev); 116 struct ide_host *host = pci_get_drvdata(dev);
117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv; 117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
index 45d2356bb725..66f43083408b 100644
--- a/drivers/ide/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -68,7 +68,7 @@ static struct pci_dev *isa_dev;
68 68
69static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio) 69static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
70{ 70{
71 ide_hwif_t *hwif = HWIF(drive); 71 ide_hwif_t *hwif = drive->hwif;
72 struct pci_dev *dev = to_pci_dev(hwif->dev); 72 struct pci_dev *dev = to_pci_dev(hwif->dev);
73 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); 73 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
74 int s_time = t->setup, a_time = t->active, c_time = t->cycle; 74 int s_time = t->setup, a_time = t->active, c_time = t->cycle;
@@ -150,7 +150,7 @@ static u8 ali_udma_filter(ide_drive_t *drive)
150 150
151static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed) 151static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
152{ 152{
153 ide_hwif_t *hwif = HWIF(drive); 153 ide_hwif_t *hwif = drive->hwif;
154 struct pci_dev *dev = to_pci_dev(hwif->dev); 154 struct pci_dev *dev = to_pci_dev(hwif->dev);
155 u8 speed1 = speed; 155 u8 speed1 = speed;
156 u8 unit = drive->dn & 1; 156 u8 unit = drive->dn & 1;
@@ -198,7 +198,7 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
198static int ali15x3_dma_setup(ide_drive_t *drive) 198static int ali15x3_dma_setup(ide_drive_t *drive)
199{ 199{
200 if (m5229_revision < 0xC2 && drive->media != ide_disk) { 200 if (m5229_revision < 0xC2 && drive->media != ide_disk) {
201 if (rq_data_dir(drive->hwif->hwgroup->rq)) 201 if (rq_data_dir(drive->hwif->rq))
202 return 1; /* try PIO instead of DMA */ 202 return 1; /* try PIO instead of DMA */
203 } 203 }
204 return ide_dma_setup(drive); 204 return ide_dma_setup(drive);
@@ -490,8 +490,6 @@ static int __devinit init_dma_ali15x3(ide_hwif_t *hwif,
490 if (ide_allocate_dma_engine(hwif)) 490 if (ide_allocate_dma_engine(hwif))
491 return -1; 491 return -1;
492 492
493 hwif->dma_ops = &sff_dma_ops;
494
495 return 0; 493 return 0;
496} 494}
497 495
@@ -511,6 +509,7 @@ static const struct ide_dma_ops ali_dma_ops = {
511 .dma_test_irq = ide_dma_test_irq, 509 .dma_test_irq = ide_dma_test_irq,
512 .dma_lost_irq = ide_dma_lost_irq, 510 .dma_lost_irq = ide_dma_lost_irq,
513 .dma_timeout = ide_dma_timeout, 511 .dma_timeout = ide_dma_timeout,
512 .dma_sff_read_status = ide_dma_sff_read_status,
514}; 513};
515 514
516static const struct ide_port_info ali15x3_chipset __devinitdata = { 515static const struct ide_port_info ali15x3_chipset __devinitdata = {
@@ -519,6 +518,7 @@ static const struct ide_port_info ali15x3_chipset __devinitdata = {
519 .init_hwif = init_hwif_ali15x3, 518 .init_hwif = init_hwif_ali15x3,
520 .init_dma = init_dma_ali15x3, 519 .init_dma = init_dma_ali15x3,
521 .port_ops = &ali_port_ops, 520 .port_ops = &ali_port_ops,
521 .dma_ops = &sff_dma_ops,
522 .pio_mask = ATA_PIO5, 522 .pio_mask = ATA_PIO5,
523 .swdma_mask = ATA_SWDMA2, 523 .swdma_mask = ATA_SWDMA2,
524 .mwdma_mask = ATA_MWDMA2, 524 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
index c6bcd3014a29..69660a431cd9 100644
--- a/drivers/ide/amd74xx.c
+++ b/drivers/ide/amd74xx.c
@@ -82,7 +82,7 @@ static void amd_set_drive(ide_drive_t *drive, const u8 speed)
82{ 82{
83 ide_hwif_t *hwif = drive->hwif; 83 ide_hwif_t *hwif = drive->hwif;
84 struct pci_dev *dev = to_pci_dev(hwif->dev); 84 struct pci_dev *dev = to_pci_dev(hwif->dev);
85 ide_drive_t *peer = hwif->drives + (~drive->dn & 1); 85 ide_drive_t *peer = ide_get_pair_dev(drive);
86 struct ide_timing t, p; 86 struct ide_timing t, p;
87 int T, UT; 87 int T, UT;
88 u8 udma_mask = hwif->ultra_mask; 88 u8 udma_mask = hwif->ultra_mask;
@@ -92,7 +92,7 @@ static void amd_set_drive(ide_drive_t *drive, const u8 speed)
92 92
93 ide_timing_compute(drive, speed, &t, T, UT); 93 ide_timing_compute(drive, speed, &t, T, UT);
94 94
95 if (peer->dev_flags & IDE_DFLAG_PRESENT) { 95 if (peer) {
96 ide_timing_compute(peer, peer->current_speed, &p, T, UT); 96 ide_timing_compute(peer, peer->current_speed, &p, T, UT);
97 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); 97 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
98 } 98 }
diff --git a/drivers/ide/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index 0ec8fd1e4dcb..79a2dfed8eb7 100644
--- a/drivers/ide/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -212,8 +212,8 @@ static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
212static int auide_build_dmatable(ide_drive_t *drive) 212static int auide_build_dmatable(ide_drive_t *drive)
213{ 213{
214 int i, iswrite, count = 0; 214 int i, iswrite, count = 0;
215 ide_hwif_t *hwif = HWIF(drive); 215 ide_hwif_t *hwif = drive->hwif;
216 struct request *rq = HWGROUP(drive)->rq; 216 struct request *rq = hwif->rq;
217 _auide_hwif *ahwif = &auide_hwif; 217 _auide_hwif *ahwif = &auide_hwif;
218 struct scatterlist *sg; 218 struct scatterlist *sg;
219 219
@@ -286,7 +286,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
286 286
287static int auide_dma_end(ide_drive_t *drive) 287static int auide_dma_end(ide_drive_t *drive)
288{ 288{
289 ide_hwif_t *hwif = HWIF(drive); 289 ide_hwif_t *hwif = drive->hwif;
290 290
291 if (hwif->sg_nents) { 291 if (hwif->sg_nents) {
292 ide_destroy_dmatable(drive); 292 ide_destroy_dmatable(drive);
@@ -309,8 +309,8 @@ static void auide_dma_exec_cmd(ide_drive_t *drive, u8 command)
309} 309}
310 310
311static int auide_dma_setup(ide_drive_t *drive) 311static int auide_dma_setup(ide_drive_t *drive)
312{ 312{
313 struct request *rq = HWGROUP(drive)->rq; 313 struct request *rq = drive->hwif->rq;
314 314
315 if (!auide_build_dmatable(drive)) { 315 if (!auide_build_dmatable(drive)) {
316 ide_map_sg(drive, rq); 316 ide_map_sg(drive, rq);
@@ -502,7 +502,6 @@ static const struct ide_tp_ops au1xxx_tp_ops = {
502 .exec_command = ide_exec_command, 502 .exec_command = ide_exec_command,
503 .read_status = ide_read_status, 503 .read_status = ide_read_status,
504 .read_altstatus = ide_read_altstatus, 504 .read_altstatus = ide_read_altstatus,
505 .read_sff_dma_status = ide_read_sff_dma_status,
506 505
507 .set_irq = ide_set_irq, 506 .set_irq = ide_set_irq,
508 507
diff --git a/drivers/ide/cmd640.c b/drivers/ide/cmd640.c
index e4306647d00d..8890276fef7f 100644
--- a/drivers/ide/cmd640.c
+++ b/drivers/ide/cmd640.c
@@ -467,11 +467,10 @@ static void program_drive_counts(ide_drive_t *drive, unsigned int index)
467 * so we merge the timings, using the slowest value for each timing. 467 * so we merge the timings, using the slowest value for each timing.
468 */ 468 */
469 if (index > 1) { 469 if (index > 1) {
470 ide_hwif_t *hwif = drive->hwif; 470 ide_drive_t *peer = ide_get_pair_dev(drive);
471 ide_drive_t *peer = &hwif->drives[!(drive->dn & 1)];
472 unsigned int mate = index ^ 1; 471 unsigned int mate = index ^ 1;
473 472
474 if (peer->dev_flags & IDE_DFLAG_PRESENT) { 473 if (peer) {
475 if (setup_count < setup_counts[mate]) 474 if (setup_count < setup_counts[mate])
476 setup_count = setup_counts[mate]; 475 setup_count = setup_counts[mate];
477 if (active_count < active_counts[mate]) 476 if (active_count < active_counts[mate])
diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
index 935385c77e06..2f9688d87ecd 100644
--- a/drivers/ide/cmd64x.c
+++ b/drivers/ide/cmd64x.c
@@ -115,7 +115,7 @@ static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_
115 */ 115 */
116static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio) 116static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
117{ 117{
118 ide_hwif_t *hwif = HWIF(drive); 118 ide_hwif_t *hwif = drive->hwif;
119 struct pci_dev *dev = to_pci_dev(hwif->dev); 119 struct pci_dev *dev = to_pci_dev(hwif->dev);
120 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); 120 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
121 unsigned int cycle_time; 121 unsigned int cycle_time;
@@ -138,10 +138,12 @@ static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
138 * the slowest address setup timing ourselves. 138 * the slowest address setup timing ourselves.
139 */ 139 */
140 if (hwif->channel) { 140 if (hwif->channel) {
141 ide_drive_t *drives = hwif->drives; 141 ide_drive_t *pair = ide_get_pair_dev(drive);
142 142
143 drive->drive_data = setup_count; 143 drive->drive_data = setup_count;
144 setup_count = max(drives[0].drive_data, drives[1].drive_data); 144
145 if (pair)
146 setup_count = max_t(u8, setup_count, pair->drive_data);
145 } 147 }
146 148
147 if (setup_count > 5) /* shouldn't actually happen... */ 149 if (setup_count > 5) /* shouldn't actually happen... */
@@ -180,7 +182,7 @@ static void cmd64x_set_pio_mode(ide_drive_t *drive, const u8 pio)
180 182
181static void cmd64x_set_dma_mode(ide_drive_t *drive, const u8 speed) 183static void cmd64x_set_dma_mode(ide_drive_t *drive, const u8 speed)
182{ 184{
183 ide_hwif_t *hwif = HWIF(drive); 185 ide_hwif_t *hwif = drive->hwif;
184 struct pci_dev *dev = to_pci_dev(hwif->dev); 186 struct pci_dev *dev = to_pci_dev(hwif->dev);
185 u8 unit = drive->dn & 0x01; 187 u8 unit = drive->dn & 0x01;
186 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0; 188 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0;
@@ -226,7 +228,7 @@ static void cmd64x_set_dma_mode(ide_drive_t *drive, const u8 speed)
226 228
227static int cmd648_dma_end(ide_drive_t *drive) 229static int cmd648_dma_end(ide_drive_t *drive)
228{ 230{
229 ide_hwif_t *hwif = HWIF(drive); 231 ide_hwif_t *hwif = drive->hwif;
230 unsigned long base = hwif->dma_base - (hwif->channel * 8); 232 unsigned long base = hwif->dma_base - (hwif->channel * 8);
231 int err = ide_dma_end(drive); 233 int err = ide_dma_end(drive);
232 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 234 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
@@ -242,7 +244,7 @@ static int cmd648_dma_end(ide_drive_t *drive)
242 244
243static int cmd64x_dma_end(ide_drive_t *drive) 245static int cmd64x_dma_end(ide_drive_t *drive)
244{ 246{
245 ide_hwif_t *hwif = HWIF(drive); 247 ide_hwif_t *hwif = drive->hwif;
246 struct pci_dev *dev = to_pci_dev(hwif->dev); 248 struct pci_dev *dev = to_pci_dev(hwif->dev);
247 int irq_reg = hwif->channel ? ARTTIM23 : CFR; 249 int irq_reg = hwif->channel ? ARTTIM23 : CFR;
248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 250 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
@@ -259,7 +261,7 @@ static int cmd64x_dma_end(ide_drive_t *drive)
259 261
260static int cmd648_dma_test_irq(ide_drive_t *drive) 262static int cmd648_dma_test_irq(ide_drive_t *drive)
261{ 263{
262 ide_hwif_t *hwif = HWIF(drive); 264 ide_hwif_t *hwif = drive->hwif;
263 unsigned long base = hwif->dma_base - (hwif->channel * 8); 265 unsigned long base = hwif->dma_base - (hwif->channel * 8);
264 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 266 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
265 MRDMODE_INTR_CH0; 267 MRDMODE_INTR_CH0;
@@ -282,7 +284,7 @@ static int cmd648_dma_test_irq(ide_drive_t *drive)
282 284
283static int cmd64x_dma_test_irq(ide_drive_t *drive) 285static int cmd64x_dma_test_irq(ide_drive_t *drive)
284{ 286{
285 ide_hwif_t *hwif = HWIF(drive); 287 ide_hwif_t *hwif = drive->hwif;
286 struct pci_dev *dev = to_pci_dev(hwif->dev); 288 struct pci_dev *dev = to_pci_dev(hwif->dev);
287 int irq_reg = hwif->channel ? ARTTIM23 : CFR; 289 int irq_reg = hwif->channel ? ARTTIM23 : CFR;
288 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 290 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
@@ -313,7 +315,7 @@ static int cmd64x_dma_test_irq(ide_drive_t *drive)
313 315
314static int cmd646_1_dma_end(ide_drive_t *drive) 316static int cmd646_1_dma_end(ide_drive_t *drive)
315{ 317{
316 ide_hwif_t *hwif = HWIF(drive); 318 ide_hwif_t *hwif = drive->hwif;
317 u8 dma_stat = 0, dma_cmd = 0; 319 u8 dma_stat = 0, dma_cmd = 0;
318 320
319 drive->waiting_for_dma = 0; 321 drive->waiting_for_dma = 0;
@@ -383,6 +385,7 @@ static const struct ide_dma_ops cmd64x_dma_ops = {
383 .dma_test_irq = cmd64x_dma_test_irq, 385 .dma_test_irq = cmd64x_dma_test_irq,
384 .dma_lost_irq = ide_dma_lost_irq, 386 .dma_lost_irq = ide_dma_lost_irq,
385 .dma_timeout = ide_dma_timeout, 387 .dma_timeout = ide_dma_timeout,
388 .dma_sff_read_status = ide_dma_sff_read_status,
386}; 389};
387 390
388static const struct ide_dma_ops cmd646_rev1_dma_ops = { 391static const struct ide_dma_ops cmd646_rev1_dma_ops = {
@@ -394,6 +397,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
394 .dma_test_irq = ide_dma_test_irq, 397 .dma_test_irq = ide_dma_test_irq,
395 .dma_lost_irq = ide_dma_lost_irq, 398 .dma_lost_irq = ide_dma_lost_irq,
396 .dma_timeout = ide_dma_timeout, 399 .dma_timeout = ide_dma_timeout,
400 .dma_sff_read_status = ide_dma_sff_read_status,
397}; 401};
398 402
399static const struct ide_dma_ops cmd648_dma_ops = { 403static const struct ide_dma_ops cmd648_dma_ops = {
@@ -405,6 +409,7 @@ static const struct ide_dma_ops cmd648_dma_ops = {
405 .dma_test_irq = cmd648_dma_test_irq, 409 .dma_test_irq = cmd648_dma_test_irq,
406 .dma_lost_irq = ide_dma_lost_irq, 410 .dma_lost_irq = ide_dma_lost_irq,
407 .dma_timeout = ide_dma_timeout, 411 .dma_timeout = ide_dma_timeout,
412 .dma_sff_read_status = ide_dma_sff_read_status,
408}; 413};
409 414
410static const struct ide_port_info cmd64x_chipsets[] __devinitdata = { 415static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
@@ -424,10 +429,10 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
424 .name = DRV_NAME, 429 .name = DRV_NAME,
425 .init_chipset = init_chipset_cmd64x, 430 .init_chipset = init_chipset_cmd64x,
426 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 431 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
427 .chipset = ide_cmd646,
428 .port_ops = &cmd64x_port_ops, 432 .port_ops = &cmd64x_port_ops,
429 .dma_ops = &cmd648_dma_ops, 433 .dma_ops = &cmd648_dma_ops,
430 .host_flags = IDE_HFLAG_ABUSE_PREFETCH, 434 .host_flags = IDE_HFLAG_SERIALIZE |
435 IDE_HFLAG_ABUSE_PREFETCH,
431 .pio_mask = ATA_PIO5, 436 .pio_mask = ATA_PIO5,
432 .mwdma_mask = ATA_MWDMA2, 437 .mwdma_mask = ATA_MWDMA2,
433 .udma_mask = ATA_UDMA2, 438 .udma_mask = ATA_UDMA2,
diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
index 5efb467f8fa0..d003bec56ff9 100644
--- a/drivers/ide/cs5520.c
+++ b/drivers/ide/cs5520.c
@@ -59,7 +59,7 @@ static struct pio_clocks cs5520_pio_clocks[]={
59 59
60static void cs5520_set_pio_mode(ide_drive_t *drive, const u8 pio) 60static void cs5520_set_pio_mode(ide_drive_t *drive, const u8 pio)
61{ 61{
62 ide_hwif_t *hwif = HWIF(drive); 62 ide_hwif_t *hwif = drive->hwif;
63 struct pci_dev *pdev = to_pci_dev(hwif->dev); 63 struct pci_dev *pdev = to_pci_dev(hwif->dev);
64 int controller = drive->dn > 1 ? 1 : 0; 64 int controller = drive->dn > 1 ? 1 : 0;
65 65
diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
index 5297f07d2933..74fc5401f407 100644
--- a/drivers/ide/cy82c693.c
+++ b/drivers/ide/cy82c693.c
@@ -203,7 +203,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
203 203
204static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio) 204static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
205{ 205{
206 ide_hwif_t *hwif = HWIF(drive); 206 ide_hwif_t *hwif = drive->hwif;
207 struct pci_dev *dev = to_pci_dev(hwif->dev); 207 struct pci_dev *dev = to_pci_dev(hwif->dev);
208 pio_clocks_t pclk; 208 pio_clocks_t pclk;
209 unsigned int addrCtrl; 209 unsigned int addrCtrl;
@@ -292,7 +292,6 @@ static const struct ide_port_info cy82c693_chipset __devinitdata = {
292 .name = DRV_NAME, 292 .name = DRV_NAME,
293 .init_iops = init_iops_cy82c693, 293 .init_iops = init_iops_cy82c693,
294 .port_ops = &cy82c693_port_ops, 294 .port_ops = &cy82c693_port_ops,
295 .chipset = ide_cy82c693,
296 .host_flags = IDE_HFLAG_SINGLE, 295 .host_flags = IDE_HFLAG_SINGLE,
297 .pio_mask = ATA_PIO4, 296 .pio_mask = ATA_PIO4,
298 .swdma_mask = ATA_SWDMA2, 297 .swdma_mask = ATA_SWDMA2,
diff --git a/drivers/ide/falconide.c b/drivers/ide/falconide.c
index 39d500d84b07..a5ba820d69bb 100644
--- a/drivers/ide/falconide.c
+++ b/drivers/ide/falconide.c
@@ -70,7 +70,6 @@ static const struct ide_tp_ops falconide_tp_ops = {
70 .exec_command = ide_exec_command, 70 .exec_command = ide_exec_command,
71 .read_status = ide_read_status, 71 .read_status = ide_read_status,
72 .read_altstatus = ide_read_altstatus, 72 .read_altstatus = ide_read_altstatus,
73 .read_sff_dma_status = ide_read_sff_dma_status,
74 73
75 .set_irq = ide_set_irq, 74 .set_irq = ide_set_irq,
76 75
diff --git a/drivers/ide/gayle.c b/drivers/ide/gayle.c
index 691506886561..59bd0be9dcb3 100644
--- a/drivers/ide/gayle.c
+++ b/drivers/ide/gayle.c
@@ -117,6 +117,10 @@ static void __init gayle_setup_ports(hw_regs_t *hw, unsigned long base,
117 hw->chipset = ide_generic; 117 hw->chipset = ide_generic;
118} 118}
119 119
120static const struct ide_port_info gayle_port_info = {
121 .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_NO_DMA,
122};
123
120 /* 124 /*
121 * Probe for a Gayle IDE interface (and optionally for an IDE doubler) 125 * Probe for a Gayle IDE interface (and optionally for an IDE doubler)
122 */ 126 */
@@ -178,7 +182,7 @@ found:
178 hws[i] = &hw[i]; 182 hws[i] = &hw[i];
179 } 183 }
180 184
181 rc = ide_host_add(NULL, hws, NULL); 185 rc = ide_host_add(&gayle_port_info, hws, NULL);
182 if (rc) 186 if (rc)
183 release_mem_region(res_start, res_n); 187 release_mem_region(res_start, res_n);
184 188
diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
index f5afd46ed51c..3eb9b5c63a0f 100644
--- a/drivers/ide/hpt366.c
+++ b/drivers/ide/hpt366.c
@@ -135,7 +135,6 @@
135/* various tuning parameters */ 135/* various tuning parameters */
136#define HPT_RESET_STATE_ENGINE 136#define HPT_RESET_STATE_ENGINE
137#undef HPT_DELAY_INTERRUPT 137#undef HPT_DELAY_INTERRUPT
138#define HPT_SERIALIZE_IO 0
139 138
140static const char *quirk_drives[] = { 139static const char *quirk_drives[] = {
141 "QUANTUM FIREBALLlct08 08", 140 "QUANTUM FIREBALLlct08 08",
@@ -627,7 +626,7 @@ static struct hpt_info *hpt3xx_get_info(struct device *dev)
627 626
628static u8 hpt3xx_udma_filter(ide_drive_t *drive) 627static u8 hpt3xx_udma_filter(ide_drive_t *drive)
629{ 628{
630 ide_hwif_t *hwif = HWIF(drive); 629 ide_hwif_t *hwif = drive->hwif;
631 struct hpt_info *info = hpt3xx_get_info(hwif->dev); 630 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
632 u8 mask = hwif->ultra_mask; 631 u8 mask = hwif->ultra_mask;
633 632
@@ -666,7 +665,7 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
666 665
667static u8 hpt3xx_mdma_filter(ide_drive_t *drive) 666static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
668{ 667{
669 ide_hwif_t *hwif = HWIF(drive); 668 ide_hwif_t *hwif = drive->hwif;
670 struct hpt_info *info = hpt3xx_get_info(hwif->dev); 669 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
671 670
672 switch (info->chip_type) { 671 switch (info->chip_type) {
@@ -744,7 +743,7 @@ static void hpt3xx_quirkproc(ide_drive_t *drive)
744 743
745static void hpt3xx_maskproc(ide_drive_t *drive, int mask) 744static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
746{ 745{
747 ide_hwif_t *hwif = HWIF(drive); 746 ide_hwif_t *hwif = drive->hwif;
748 struct pci_dev *dev = to_pci_dev(hwif->dev); 747 struct pci_dev *dev = to_pci_dev(hwif->dev);
749 struct hpt_info *info = hpt3xx_get_info(hwif->dev); 748 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
750 749
@@ -789,7 +788,7 @@ static void hpt366_dma_lost_irq(ide_drive_t *drive)
789 788
790static void hpt370_clear_engine(ide_drive_t *drive) 789static void hpt370_clear_engine(ide_drive_t *drive)
791{ 790{
792 ide_hwif_t *hwif = HWIF(drive); 791 ide_hwif_t *hwif = drive->hwif;
793 struct pci_dev *dev = to_pci_dev(hwif->dev); 792 struct pci_dev *dev = to_pci_dev(hwif->dev);
794 793
795 pci_write_config_byte(dev, hwif->select_data, 0x37); 794 pci_write_config_byte(dev, hwif->select_data, 0x37);
@@ -798,7 +797,7 @@ static void hpt370_clear_engine(ide_drive_t *drive)
798 797
799static void hpt370_irq_timeout(ide_drive_t *drive) 798static void hpt370_irq_timeout(ide_drive_t *drive)
800{ 799{
801 ide_hwif_t *hwif = HWIF(drive); 800 ide_hwif_t *hwif = drive->hwif;
802 struct pci_dev *dev = to_pci_dev(hwif->dev); 801 struct pci_dev *dev = to_pci_dev(hwif->dev);
803 u16 bfifo = 0; 802 u16 bfifo = 0;
804 u8 dma_cmd; 803 u8 dma_cmd;
@@ -823,7 +822,7 @@ static void hpt370_dma_start(ide_drive_t *drive)
823 822
824static int hpt370_dma_end(ide_drive_t *drive) 823static int hpt370_dma_end(ide_drive_t *drive)
825{ 824{
826 ide_hwif_t *hwif = HWIF(drive); 825 ide_hwif_t *hwif = drive->hwif;
827 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 826 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
828 827
829 if (dma_stat & 0x01) { 828 if (dma_stat & 0x01) {
@@ -845,7 +844,7 @@ static void hpt370_dma_timeout(ide_drive_t *drive)
845/* returns 1 if DMA IRQ issued, 0 otherwise */ 844/* returns 1 if DMA IRQ issued, 0 otherwise */
846static int hpt374_dma_test_irq(ide_drive_t *drive) 845static int hpt374_dma_test_irq(ide_drive_t *drive)
847{ 846{
848 ide_hwif_t *hwif = HWIF(drive); 847 ide_hwif_t *hwif = drive->hwif;
849 struct pci_dev *dev = to_pci_dev(hwif->dev); 848 struct pci_dev *dev = to_pci_dev(hwif->dev);
850 u16 bfifo = 0; 849 u16 bfifo = 0;
851 u8 dma_stat; 850 u8 dma_stat;
@@ -866,7 +865,7 @@ static int hpt374_dma_test_irq(ide_drive_t *drive)
866 865
867static int hpt374_dma_end(ide_drive_t *drive) 866static int hpt374_dma_end(ide_drive_t *drive)
868{ 867{
869 ide_hwif_t *hwif = HWIF(drive); 868 ide_hwif_t *hwif = drive->hwif;
870 struct pci_dev *dev = to_pci_dev(hwif->dev); 869 struct pci_dev *dev = to_pci_dev(hwif->dev);
871 u8 mcr = 0, mcr_addr = hwif->select_data; 870 u8 mcr = 0, mcr_addr = hwif->select_data;
872 u8 bwsr = 0, mask = hwif->channel ? 0x02 : 0x01; 871 u8 bwsr = 0, mask = hwif->channel ? 0x02 : 0x01;
@@ -928,7 +927,7 @@ static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode)
928 927
929static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq) 928static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq)
930{ 929{
931 hpt3xxn_set_clock(HWIF(drive), rq_data_dir(rq) ? 0x23 : 0x21); 930 hpt3xxn_set_clock(drive->hwif, rq_data_dir(rq) ? 0x23 : 0x21);
932} 931}
933 932
934/** 933/**
@@ -1288,7 +1287,6 @@ static u8 hpt3xx_cable_detect(ide_hwif_t *hwif)
1288static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1287static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1289{ 1288{
1290 struct hpt_info *info = hpt3xx_get_info(hwif->dev); 1289 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
1291 int serialize = HPT_SERIALIZE_IO;
1292 u8 chip_type = info->chip_type; 1290 u8 chip_type = info->chip_type;
1293 1291
1294 /* Cache the channel's MISC. control registers' offset */ 1292 /* Cache the channel's MISC. control registers' offset */
@@ -1305,13 +1303,9 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1305 * Clock is shared between the channels, 1303 * Clock is shared between the channels,
1306 * so we'll have to serialize them... :-( 1304 * so we'll have to serialize them... :-(
1307 */ 1305 */
1308 serialize = 1; 1306 hwif->host->host_flags |= IDE_HFLAG_SERIALIZE;
1309 hwif->rw_disk = &hpt3xxn_rw_disk; 1307 hwif->rw_disk = &hpt3xxn_rw_disk;
1310 } 1308 }
1311
1312 /* Serialize access to this device if needed */
1313 if (serialize && hwif->mate)
1314 hwif->serialized = hwif->mate->serialized = 1;
1315} 1309}
1316 1310
1317static int __devinit init_dma_hpt366(ide_hwif_t *hwif, 1311static int __devinit init_dma_hpt366(ide_hwif_t *hwif,
@@ -1355,8 +1349,6 @@ static int __devinit init_dma_hpt366(ide_hwif_t *hwif,
1355 if (ide_allocate_dma_engine(hwif)) 1349 if (ide_allocate_dma_engine(hwif))
1356 return -1; 1350 return -1;
1357 1351
1358 hwif->dma_ops = &sff_dma_ops;
1359
1360 return 0; 1352 return 0;
1361} 1353}
1362 1354
@@ -1432,6 +1424,7 @@ static const struct ide_dma_ops hpt37x_dma_ops = {
1432 .dma_test_irq = hpt374_dma_test_irq, 1424 .dma_test_irq = hpt374_dma_test_irq,
1433 .dma_lost_irq = ide_dma_lost_irq, 1425 .dma_lost_irq = ide_dma_lost_irq,
1434 .dma_timeout = ide_dma_timeout, 1426 .dma_timeout = ide_dma_timeout,
1427 .dma_sff_read_status = ide_dma_sff_read_status,
1435}; 1428};
1436 1429
1437static const struct ide_dma_ops hpt370_dma_ops = { 1430static const struct ide_dma_ops hpt370_dma_ops = {
@@ -1443,6 +1436,7 @@ static const struct ide_dma_ops hpt370_dma_ops = {
1443 .dma_test_irq = ide_dma_test_irq, 1436 .dma_test_irq = ide_dma_test_irq,
1444 .dma_lost_irq = ide_dma_lost_irq, 1437 .dma_lost_irq = ide_dma_lost_irq,
1445 .dma_timeout = hpt370_dma_timeout, 1438 .dma_timeout = hpt370_dma_timeout,
1439 .dma_sff_read_status = ide_dma_sff_read_status,
1446}; 1440};
1447 1441
1448static const struct ide_dma_ops hpt36x_dma_ops = { 1442static const struct ide_dma_ops hpt36x_dma_ops = {
@@ -1454,6 +1448,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1454 .dma_test_irq = ide_dma_test_irq, 1448 .dma_test_irq = ide_dma_test_irq,
1455 .dma_lost_irq = hpt366_dma_lost_irq, 1449 .dma_lost_irq = hpt366_dma_lost_irq,
1456 .dma_timeout = ide_dma_timeout, 1450 .dma_timeout = ide_dma_timeout,
1451 .dma_sff_read_status = ide_dma_sff_read_status,
1457}; 1452};
1458 1453
1459static const struct ide_port_info hpt366_chipsets[] __devinitdata = { 1454static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
diff --git a/drivers/ide/icside.c b/drivers/ide/icside.c
index 81f70caeb40f..97a35c667aee 100644
--- a/drivers/ide/icside.c
+++ b/drivers/ide/icside.c
@@ -166,7 +166,7 @@ static const expansioncard_ops_t icside_ops_arcin_v6 = {
166 */ 166 */
167static void icside_maskproc(ide_drive_t *drive, int mask) 167static void icside_maskproc(ide_drive_t *drive, int mask)
168{ 168{
169 ide_hwif_t *hwif = HWIF(drive); 169 ide_hwif_t *hwif = drive->hwif;
170 struct expansion_card *ec = ECARD_DEV(hwif->dev); 170 struct expansion_card *ec = ECARD_DEV(hwif->dev);
171 struct icside_state *state = ecard_get_drvdata(ec); 171 struct icside_state *state = ecard_get_drvdata(ec);
172 unsigned long flags; 172 unsigned long flags;
@@ -284,7 +284,7 @@ static void icside_dma_host_set(ide_drive_t *drive, int on)
284 284
285static int icside_dma_end(ide_drive_t *drive) 285static int icside_dma_end(ide_drive_t *drive)
286{ 286{
287 ide_hwif_t *hwif = HWIF(drive); 287 ide_hwif_t *hwif = drive->hwif;
288 struct expansion_card *ec = ECARD_DEV(hwif->dev); 288 struct expansion_card *ec = ECARD_DEV(hwif->dev);
289 289
290 drive->waiting_for_dma = 0; 290 drive->waiting_for_dma = 0;
@@ -299,7 +299,7 @@ static int icside_dma_end(ide_drive_t *drive)
299 299
300static void icside_dma_start(ide_drive_t *drive) 300static void icside_dma_start(ide_drive_t *drive)
301{ 301{
302 ide_hwif_t *hwif = HWIF(drive); 302 ide_hwif_t *hwif = drive->hwif;
303 struct expansion_card *ec = ECARD_DEV(hwif->dev); 303 struct expansion_card *ec = ECARD_DEV(hwif->dev);
304 304
305 /* We can not enable DMA on both channels simultaneously. */ 305 /* We can not enable DMA on both channels simultaneously. */
@@ -309,10 +309,10 @@ static void icside_dma_start(ide_drive_t *drive)
309 309
310static int icside_dma_setup(ide_drive_t *drive) 310static int icside_dma_setup(ide_drive_t *drive)
311{ 311{
312 ide_hwif_t *hwif = HWIF(drive); 312 ide_hwif_t *hwif = drive->hwif;
313 struct expansion_card *ec = ECARD_DEV(hwif->dev); 313 struct expansion_card *ec = ECARD_DEV(hwif->dev);
314 struct icside_state *state = ecard_get_drvdata(ec); 314 struct icside_state *state = ecard_get_drvdata(ec);
315 struct request *rq = hwif->hwgroup->rq; 315 struct request *rq = hwif->rq;
316 unsigned int dma_mode; 316 unsigned int dma_mode;
317 317
318 if (rq_data_dir(rq)) 318 if (rq_data_dir(rq))
@@ -362,7 +362,7 @@ static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
362 362
363static int icside_dma_test_irq(ide_drive_t *drive) 363static int icside_dma_test_irq(ide_drive_t *drive)
364{ 364{
365 ide_hwif_t *hwif = HWIF(drive); 365 ide_hwif_t *hwif = drive->hwif;
366 struct expansion_card *ec = ECARD_DEV(hwif->dev); 366 struct expansion_card *ec = ECARD_DEV(hwif->dev);
367 struct icside_state *state = ecard_get_drvdata(ec); 367 struct icside_state *state = ecard_get_drvdata(ec);
368 368
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 9e8d52a4f306..d8f295bdad76 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -212,7 +212,7 @@ static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
212 */ 212 */
213static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive) 213static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
214{ 214{
215 ide_hwif_t *hwif = HWIF(drive); 215 ide_hwif_t *hwif = drive->hwif;
216 int port; 216 int port;
217 acpi_handle drive_handle; 217 acpi_handle drive_handle;
218 218
@@ -257,7 +257,7 @@ static int do_drive_get_GTF(ide_drive_t *drive,
257 acpi_status status; 257 acpi_status status;
258 struct acpi_buffer output; 258 struct acpi_buffer output;
259 union acpi_object *out_obj; 259 union acpi_object *out_obj;
260 ide_hwif_t *hwif = HWIF(drive); 260 ide_hwif_t *hwif = drive->hwif;
261 struct device *dev = hwif->gendev.parent; 261 struct device *dev = hwif->gendev.parent;
262 int err = -ENODEV; 262 int err = -ENODEV;
263 int port; 263 int port;
@@ -609,10 +609,10 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
609 in_params[0].buffer.length = sizeof(struct GTM_buffer); 609 in_params[0].buffer.length = sizeof(struct GTM_buffer);
610 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm; 610 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
611 in_params[1].type = ACPI_TYPE_BUFFER; 611 in_params[1].type = ACPI_TYPE_BUFFER;
612 in_params[1].buffer.length = sizeof(ATA_ID_WORDS * 2); 612 in_params[1].buffer.length = ATA_ID_WORDS * 2;
613 in_params[1].buffer.pointer = (u8 *)&master->idbuff; 613 in_params[1].buffer.pointer = (u8 *)&master->idbuff;
614 in_params[2].type = ACPI_TYPE_BUFFER; 614 in_params[2].type = ACPI_TYPE_BUFFER;
615 in_params[2].buffer.length = sizeof(ATA_ID_WORDS * 2); 615 in_params[2].buffer.length = ATA_ID_WORDS * 2;
616 in_params[2].buffer.pointer = (u8 *)&slave->idbuff; 616 in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
617 /* Output buffer: _STM has no output */ 617 /* Output buffer: _STM has no output */
618 618
@@ -635,7 +635,8 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
635 */ 635 */
636void ide_acpi_set_state(ide_hwif_t *hwif, int on) 636void ide_acpi_set_state(ide_hwif_t *hwif, int on)
637{ 637{
638 int unit; 638 ide_drive_t *drive;
639 int i;
639 640
640 if (ide_noacpi || ide_noacpi_psx) 641 if (ide_noacpi || ide_noacpi_psx)
641 return; 642 return;
@@ -649,9 +650,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
649 /* channel first and then drives for power on and verse versa for power off */ 650 /* channel first and then drives for power on and verse versa for power off */
650 if (on) 651 if (on)
651 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0); 652 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
652 for (unit = 0; unit < MAX_DRIVES; ++unit) {
653 ide_drive_t *drive = &hwif->drives[unit];
654 653
654 ide_port_for_each_dev(i, drive, hwif) {
655 if (!drive->acpidata->obj_handle) 655 if (!drive->acpidata->obj_handle)
656 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); 656 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
657 657
@@ -705,15 +705,13 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
705 * for both drives, regardless whether they are connected 705 * for both drives, regardless whether they are connected
706 * or not. 706 * or not.
707 */ 707 */
708 hwif->drives[0].acpidata = &hwif->acpidata->master; 708 hwif->devices[0]->acpidata = &hwif->acpidata->master;
709 hwif->drives[1].acpidata = &hwif->acpidata->slave; 709 hwif->devices[1]->acpidata = &hwif->acpidata->slave;
710 710
711 /* 711 /*
712 * Send IDENTIFY for each drive 712 * Send IDENTIFY for each drive
713 */ 713 */
714 for (i = 0; i < MAX_DRIVES; i++) { 714 ide_port_for_each_dev(i, drive, hwif) {
715 drive = &hwif->drives[i];
716
717 memset(drive->acpidata, 0, sizeof(*drive->acpidata)); 715 memset(drive->acpidata, 0, sizeof(*drive->acpidata));
718 716
719 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 717 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
@@ -738,9 +736,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
738 ide_acpi_get_timing(hwif); 736 ide_acpi_get_timing(hwif);
739 ide_acpi_push_timing(hwif); 737 ide_acpi_push_timing(hwif);
740 738
741 for (i = 0; i < MAX_DRIVES; i++) { 739 ide_port_for_each_dev(i, drive, hwif) {
742 drive = &hwif->drives[i];
743
744 if (drive->dev_flags & IDE_DFLAG_PRESENT) 740 if (drive->dev_flags & IDE_DFLAG_PRESENT)
745 /* Execute ACPI startup code */ 741 /* Execute ACPI startup code */
746 ide_acpi_exec_tfs(drive); 742 ide_acpi_exec_tfs(drive);
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 4e58b9e7a58a..e96c01260598 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -3,6 +3,7 @@
3 */ 3 */
4 4
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/cdrom.h>
6#include <linux/delay.h> 7#include <linux/delay.h>
7#include <linux/ide.h> 8#include <linux/ide.h>
8#include <scsi/scsi.h> 9#include <scsi/scsi.h>
@@ -14,6 +15,13 @@
14#define debug_log(fmt, args...) do {} while (0) 15#define debug_log(fmt, args...) do {} while (0)
15#endif 16#endif
16 17
18#define ATAPI_MIN_CDB_BYTES 12
19
20static inline int dev_is_idecd(ide_drive_t *drive)
21{
22 return drive->media == ide_cdrom || drive->media == ide_optical;
23}
24
17/* 25/*
18 * Check whether we can support a device, 26 * Check whether we can support a device,
19 * based on the ATAPI IDENTIFY command results. 27 * based on the ATAPI IDENTIFY command results.
@@ -233,18 +241,49 @@ void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
233} 241}
234EXPORT_SYMBOL_GPL(ide_retry_pc); 242EXPORT_SYMBOL_GPL(ide_retry_pc);
235 243
236int ide_scsi_expiry(ide_drive_t *drive) 244int ide_cd_expiry(ide_drive_t *drive)
237{ 245{
238 struct ide_atapi_pc *pc = drive->pc; 246 struct request *rq = drive->hwif->rq;
247 unsigned long wait = 0;
239 248
240 debug_log("%s called for %lu at %lu\n", __func__, 249 debug_log("%s: rq->cmd[0]: 0x%x\n", __func__, rq->cmd[0]);
241 pc->scsi_cmd->serial_number, jiffies);
242 250
243 pc->flags |= PC_FLAG_TIMEDOUT; 251 /*
252 * Some commands are *slow* and normally take a long time to complete.
253 * Usually we can use the ATAPI "disconnect" to bypass this, but not all
254 * commands/drives support that. Let ide_timer_expiry keep polling us
255 * for these.
256 */
257 switch (rq->cmd[0]) {
258 case GPCMD_BLANK:
259 case GPCMD_FORMAT_UNIT:
260 case GPCMD_RESERVE_RZONE_TRACK:
261 case GPCMD_CLOSE_TRACK:
262 case GPCMD_FLUSH_CACHE:
263 wait = ATAPI_WAIT_PC;
264 break;
265 default:
266 if (!(rq->cmd_flags & REQ_QUIET))
267 printk(KERN_INFO "cmd 0x%x timed out\n",
268 rq->cmd[0]);
269 wait = 0;
270 break;
271 }
272 return wait;
273}
274EXPORT_SYMBOL_GPL(ide_cd_expiry);
244 275
245 return 0; /* we do not want the IDE subsystem to retry */ 276int ide_cd_get_xferlen(struct request *rq)
277{
278 if (blk_fs_request(rq))
279 return 32768;
280 else if (blk_sense_request(rq) || blk_pc_request(rq) ||
281 rq->cmd_type == REQ_TYPE_ATA_PC)
282 return rq->data_len;
283 else
284 return 0;
246} 285}
247EXPORT_SYMBOL_GPL(ide_scsi_expiry); 286EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
248 287
249/* 288/*
250 * This is the usual interrupt handler which will be called during a packet 289 * This is the usual interrupt handler which will be called during a packet
@@ -255,24 +294,17 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
255{ 294{
256 struct ide_atapi_pc *pc = drive->pc; 295 struct ide_atapi_pc *pc = drive->pc;
257 ide_hwif_t *hwif = drive->hwif; 296 ide_hwif_t *hwif = drive->hwif;
258 struct request *rq = hwif->hwgroup->rq; 297 struct request *rq = hwif->rq;
259 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 298 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
260 xfer_func_t *xferfunc; 299 xfer_func_t *xferfunc;
261 ide_expiry_t *expiry;
262 unsigned int timeout, temp; 300 unsigned int timeout, temp;
263 u16 bcount; 301 u16 bcount;
264 u8 stat, ireason, scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI), dsc = 0; 302 u8 stat, ireason, dsc = 0;
265 303
266 debug_log("Enter %s - interrupt handler\n", __func__); 304 debug_log("Enter %s - interrupt handler\n", __func__);
267 305
268 if (scsi) { 306 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
269 timeout = ide_scsi_get_timeout(pc); 307 : WAIT_TAPE_CMD;
270 expiry = ide_scsi_expiry;
271 } else {
272 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
273 : WAIT_TAPE_CMD;
274 expiry = NULL;
275 }
276 308
277 if (pc->flags & PC_FLAG_TIMEDOUT) { 309 if (pc->flags & PC_FLAG_TIMEDOUT) {
278 drive->pc_callback(drive, 0); 310 drive->pc_callback(drive, 0);
@@ -284,8 +316,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
284 316
285 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { 317 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
286 if (hwif->dma_ops->dma_end(drive) || 318 if (hwif->dma_ops->dma_end(drive) ||
287 (drive->media == ide_tape && !scsi && (stat & ATA_ERR))) { 319 (drive->media == ide_tape && (stat & ATA_ERR))) {
288 if (drive->media == ide_floppy && !scsi) 320 if (drive->media == ide_floppy)
289 printk(KERN_ERR "%s: DMA %s error\n", 321 printk(KERN_ERR "%s: DMA %s error\n",
290 drive->name, rq_data_dir(pc->rq) 322 drive->name, rq_data_dir(pc->rq)
291 ? "write" : "read"); 323 ? "write" : "read");
@@ -307,7 +339,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
307 339
308 local_irq_enable_in_hardirq(); 340 local_irq_enable_in_hardirq();
309 341
310 if (drive->media == ide_tape && !scsi && 342 if (drive->media == ide_tape &&
311 (stat & ATA_ERR) && rq->cmd[0] == REQUEST_SENSE) 343 (stat & ATA_ERR) && rq->cmd[0] == REQUEST_SENSE)
312 stat &= ~ATA_ERR; 344 stat &= ~ATA_ERR;
313 345
@@ -315,11 +347,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
315 /* Error detected */ 347 /* Error detected */
316 debug_log("%s: I/O error\n", drive->name); 348 debug_log("%s: I/O error\n", drive->name);
317 349
318 if (drive->media != ide_tape || scsi) { 350 if (drive->media != ide_tape)
319 pc->rq->errors++; 351 pc->rq->errors++;
320 if (scsi)
321 goto cmd_finished;
322 }
323 352
324 if (rq->cmd[0] == REQUEST_SENSE) { 353 if (rq->cmd[0] == REQUEST_SENSE) {
325 printk(KERN_ERR "%s: I/O error in request sense" 354 printk(KERN_ERR "%s: I/O error in request sense"
@@ -335,7 +364,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
335 /* queued, but not started */ 364 /* queued, but not started */
336 return ide_stopped; 365 return ide_stopped;
337 } 366 }
338cmd_finished:
339 pc->error = 0; 367 pc->error = 0;
340 368
341 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) 369 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
@@ -382,25 +410,8 @@ cmd_finished:
382 "us more data than expected - " 410 "us more data than expected - "
383 "discarding data\n", 411 "discarding data\n",
384 drive->name); 412 drive->name);
385 if (scsi) 413
386 temp = pc->buf_size - pc->xferred; 414 ide_pad_transfer(drive, 0, bcount);
387 else
388 temp = 0;
389 if (temp) {
390 if (pc->sg)
391 drive->pc_io_buffers(drive, pc,
392 temp, 0);
393 else
394 tp_ops->input_data(drive, NULL,
395 pc->cur_pos, temp);
396 printk(KERN_ERR "%s: transferred %d of "
397 "%d bytes\n",
398 drive->name,
399 temp, bcount);
400 }
401 pc->xferred += temp;
402 pc->cur_pos += temp;
403 ide_pad_transfer(drive, 0, bcount - temp);
404 goto next_irq; 415 goto next_irq;
405 } 416 }
406 debug_log("The device wants to send us more data than " 417 debug_log("The device wants to send us more data than "
@@ -410,14 +421,13 @@ cmd_finished:
410 } else 421 } else
411 xferfunc = tp_ops->output_data; 422 xferfunc = tp_ops->output_data;
412 423
413 if ((drive->media == ide_floppy && !scsi && !pc->buf) || 424 if ((drive->media == ide_floppy && !pc->buf) ||
414 (drive->media == ide_tape && !scsi && pc->bh) || 425 (drive->media == ide_tape && pc->bh)) {
415 (scsi && pc->sg)) {
416 int done = drive->pc_io_buffers(drive, pc, bcount, 426 int done = drive->pc_io_buffers(drive, pc, bcount,
417 !!(pc->flags & PC_FLAG_WRITING)); 427 !!(pc->flags & PC_FLAG_WRITING));
418 428
419 /* FIXME: don't do partial completions */ 429 /* FIXME: don't do partial completions */
420 if (drive->media == ide_floppy && !scsi) 430 if (drive->media == ide_floppy)
421 ide_end_request(drive, 1, done >> 9); 431 ide_end_request(drive, 1, done >> 9);
422 } else 432 } else
423 xferfunc(drive, NULL, pc->cur_pos, bcount); 433 xferfunc(drive, NULL, pc->cur_pos, bcount);
@@ -430,7 +440,7 @@ cmd_finished:
430 rq->cmd[0], bcount); 440 rq->cmd[0], bcount);
431next_irq: 441next_irq:
432 /* And set the interrupt handler again */ 442 /* And set the interrupt handler again */
433 ide_set_handler(drive, ide_pc_intr, timeout, expiry); 443 ide_set_handler(drive, ide_pc_intr, timeout, NULL);
434 return ide_started; 444 return ide_started;
435} 445}
436 446
@@ -479,11 +489,12 @@ static int ide_delayed_transfer_pc(ide_drive_t *drive)
479 489
480static ide_startstop_t ide_transfer_pc(ide_drive_t *drive) 490static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
481{ 491{
482 struct ide_atapi_pc *pc = drive->pc; 492 struct ide_atapi_pc *uninitialized_var(pc);
483 ide_hwif_t *hwif = drive->hwif; 493 ide_hwif_t *hwif = drive->hwif;
484 struct request *rq = hwif->hwgroup->rq; 494 struct request *rq = hwif->rq;
485 ide_expiry_t *expiry; 495 ide_expiry_t *expiry;
486 unsigned int timeout; 496 unsigned int timeout;
497 int cmd_len;
487 ide_startstop_t startstop; 498 ide_startstop_t startstop;
488 u8 ireason; 499 u8 ireason;
489 500
@@ -493,101 +504,127 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
493 return startstop; 504 return startstop;
494 } 505 }
495 506
496 ireason = ide_read_ireason(drive); 507 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
497 if (drive->media == ide_tape && 508 if (drive->dma)
498 (drive->dev_flags & IDE_DFLAG_SCSI) == 0) 509 drive->waiting_for_dma = 1;
499 ireason = ide_wait_ireason(drive, ireason);
500
501 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
502 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
503 "a packet command\n", drive->name);
504 return ide_do_reset(drive);
505 } 510 }
506 511
507 /* 512 if (dev_is_idecd(drive)) {
508 * If necessary schedule the packet transfer to occur 'timeout' 513 /* ATAPI commands get padded out to 12 bytes minimum */
509 * miliseconds later in ide_delayed_transfer_pc() after the device 514 cmd_len = COMMAND_SIZE(rq->cmd[0]);
510 * says it's ready for a packet. 515 if (cmd_len < ATAPI_MIN_CDB_BYTES)
511 */ 516 cmd_len = ATAPI_MIN_CDB_BYTES;
512 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) { 517
513 timeout = drive->pc_delay; 518 timeout = rq->timeout;
514 expiry = &ide_delayed_transfer_pc; 519 expiry = ide_cd_expiry;
515 } else { 520 } else {
516 if (drive->dev_flags & IDE_DFLAG_SCSI) { 521 pc = drive->pc;
517 timeout = ide_scsi_get_timeout(pc); 522
518 expiry = ide_scsi_expiry; 523 cmd_len = ATAPI_MIN_CDB_BYTES;
524
525 /*
526 * If necessary schedule the packet transfer to occur 'timeout'
527 * miliseconds later in ide_delayed_transfer_pc() after the
528 * device says it's ready for a packet.
529 */
530 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
531 timeout = drive->pc_delay;
532 expiry = &ide_delayed_transfer_pc;
519 } else { 533 } else {
520 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD 534 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
521 : WAIT_TAPE_CMD; 535 : WAIT_TAPE_CMD;
522 expiry = NULL; 536 expiry = NULL;
523 } 537 }
538
539 ireason = ide_read_ireason(drive);
540 if (drive->media == ide_tape)
541 ireason = ide_wait_ireason(drive, ireason);
542
543 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
544 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
545 "a packet command\n", drive->name);
546
547 return ide_do_reset(drive);
548 }
524 } 549 }
525 550
526 /* Set the interrupt routine */ 551 /* Set the interrupt routine */
527 ide_set_handler(drive, ide_pc_intr, timeout, expiry); 552 ide_set_handler(drive,
553 (dev_is_idecd(drive) ? drive->irq_handler
554 : ide_pc_intr),
555 timeout, expiry);
528 556
529 /* Begin DMA, if necessary */ 557 /* Begin DMA, if necessary */
530 if (pc->flags & PC_FLAG_DMA_OK) { 558 if (dev_is_idecd(drive)) {
531 pc->flags |= PC_FLAG_DMA_IN_PROGRESS; 559 if (drive->dma)
532 hwif->dma_ops->dma_start(drive); 560 hwif->dma_ops->dma_start(drive);
561 } else {
562 if (pc->flags & PC_FLAG_DMA_OK) {
563 pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
564 hwif->dma_ops->dma_start(drive);
565 }
533 } 566 }
534 567
535 /* Send the actual packet */ 568 /* Send the actual packet */
536 if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0) 569 if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0)
537 hwif->tp_ops->output_data(drive, NULL, rq->cmd, 12); 570 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
538 571
539 return ide_started; 572 return ide_started;
540} 573}
541 574
542ide_startstop_t ide_issue_pc(ide_drive_t *drive, unsigned int timeout, 575ide_startstop_t ide_issue_pc(ide_drive_t *drive)
543 ide_expiry_t *expiry)
544{ 576{
545 struct ide_atapi_pc *pc = drive->pc; 577 struct ide_atapi_pc *pc;
546 ide_hwif_t *hwif = drive->hwif; 578 ide_hwif_t *hwif = drive->hwif;
579 ide_expiry_t *expiry = NULL;
580 unsigned int timeout;
547 u32 tf_flags; 581 u32 tf_flags;
548 u16 bcount; 582 u16 bcount;
549 u8 scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI);
550 583
551 /* We haven't transferred any data yet */ 584 if (dev_is_idecd(drive)) {
552 pc->xferred = 0; 585 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
553 pc->cur_pos = pc->buf; 586 bcount = ide_cd_get_xferlen(hwif->rq);
587 expiry = ide_cd_expiry;
588 timeout = ATAPI_WAIT_PC;
554 589
555 /* Request to transfer the entire buffer at once */ 590 if (drive->dma)
556 if (drive->media == ide_tape && scsi == 0) 591 drive->dma = !hwif->dma_ops->dma_setup(drive);
557 bcount = pc->req_xfer; 592 } else {
558 else 593 pc = drive->pc;
559 bcount = min(pc->req_xfer, 63 * 1024);
560 594
561 if (pc->flags & PC_FLAG_DMA_ERROR) { 595 /* We haven't transferred any data yet */
562 pc->flags &= ~PC_FLAG_DMA_ERROR; 596 pc->xferred = 0;
563 ide_dma_off(drive); 597 pc->cur_pos = pc->buf;
564 }
565 598
566 if ((pc->flags & PC_FLAG_DMA_OK) && 599 tf_flags = IDE_TFLAG_OUT_DEVICE;
567 (drive->dev_flags & IDE_DFLAG_USING_DMA)) { 600 bcount = ((drive->media == ide_tape) ?
568 if (scsi) 601 pc->req_xfer :
569 hwif->sg_mapped = 1; 602 min(pc->req_xfer, 63 * 1024));
570 drive->dma = !hwif->dma_ops->dma_setup(drive);
571 if (scsi)
572 hwif->sg_mapped = 0;
573 }
574 603
575 if (!drive->dma) 604 if (pc->flags & PC_FLAG_DMA_ERROR) {
576 pc->flags &= ~PC_FLAG_DMA_OK; 605 pc->flags &= ~PC_FLAG_DMA_ERROR;
606 ide_dma_off(drive);
607 }
577 608
578 if (scsi) 609 if ((pc->flags & PC_FLAG_DMA_OK) &&
579 tf_flags = 0; 610 (drive->dev_flags & IDE_DFLAG_USING_DMA))
580 else if (drive->media == ide_cdrom || drive->media == ide_optical) 611 drive->dma = !hwif->dma_ops->dma_setup(drive);
581 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL; 612
582 else 613 if (!drive->dma)
583 tf_flags = IDE_TFLAG_OUT_DEVICE; 614 pc->flags &= ~PC_FLAG_DMA_OK;
615
616 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
617 : WAIT_TAPE_CMD;
618 }
584 619
585 ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma); 620 ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);
586 621
587 /* Issue the packet command */ 622 /* Issue the packet command */
588 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 623 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
624 if (drive->dma)
625 drive->waiting_for_dma = 0;
589 ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc, 626 ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc,
590 timeout, NULL); 627 timeout, expiry);
591 return ide_started; 628 return ide_started;
592 } else { 629 } else {
593 ide_execute_pkt_cmd(drive); 630 ide_execute_pkt_cmd(drive);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 42ab6d8715f2..cae69372cf45 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -53,14 +53,6 @@
53 53
54#include "ide-cd.h" 54#include "ide-cd.h"
55 55
56#define IDECD_DEBUG_LOG 1
57
58#if IDECD_DEBUG_LOG
59#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
60#else
61#define ide_debug_log(lvl, fmt, args...) do {} while (0)
62#endif
63
64static DEFINE_MUTEX(idecd_ref_mutex); 56static DEFINE_MUTEX(idecd_ref_mutex);
65 57
66static void ide_cd_release(struct kref *); 58static void ide_cd_release(struct kref *);
@@ -247,7 +239,7 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
247 239
248static void cdrom_end_request(ide_drive_t *drive, int uptodate) 240static void cdrom_end_request(ide_drive_t *drive, int uptodate)
249{ 241{
250 struct request *rq = HWGROUP(drive)->rq; 242 struct request *rq = drive->hwif->rq;
251 int nsectors = rq->hard_cur_sectors; 243 int nsectors = rq->hard_cur_sectors;
252 244
253 ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, " 245 ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, "
@@ -262,7 +254,6 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
262 struct request *failed = (struct request *) rq->buffer; 254 struct request *failed = (struct request *) rq->buffer;
263 struct cdrom_info *info = drive->driver_data; 255 struct cdrom_info *info = drive->driver_data;
264 void *sense = &info->sense_data; 256 void *sense = &info->sense_data;
265 unsigned long flags;
266 257
267 if (failed) { 258 if (failed) {
268 if (failed->sense) { 259 if (failed->sense) {
@@ -278,11 +269,9 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
278 failed->hard_nr_sectors)) 269 failed->hard_nr_sectors))
279 BUG(); 270 BUG();
280 } else { 271 } else {
281 spin_lock_irqsave(&ide_lock, flags); 272 if (blk_end_request(failed, -EIO,
282 if (__blk_end_request(failed, -EIO, 273 failed->data_len))
283 failed->data_len))
284 BUG(); 274 BUG();
285 spin_unlock_irqrestore(&ide_lock, flags);
286 } 275 }
287 } else 276 } else
288 cdrom_analyze_sense_data(drive, NULL, sense); 277 cdrom_analyze_sense_data(drive, NULL, sense);
@@ -317,7 +306,7 @@ static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st)
317static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) 306static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
318{ 307{
319 ide_hwif_t *hwif = drive->hwif; 308 ide_hwif_t *hwif = drive->hwif;
320 struct request *rq = hwif->hwgroup->rq; 309 struct request *rq = hwif->rq;
321 int stat, err, sense_key; 310 int stat, err, sense_key;
322 311
323 /* check for errors */ 312 /* check for errors */
@@ -426,16 +415,17 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
426 if (time_after(jiffies, info->write_timeout)) 415 if (time_after(jiffies, info->write_timeout))
427 do_end_request = 1; 416 do_end_request = 1;
428 else { 417 else {
418 struct request_queue *q = drive->queue;
429 unsigned long flags; 419 unsigned long flags;
430 420
431 /* 421 /*
432 * take a breather relying on the unplug 422 * take a breather relying on the unplug
433 * timer to kick us again 423 * timer to kick us again
434 */ 424 */
435 spin_lock_irqsave(&ide_lock, flags); 425 spin_lock_irqsave(q->queue_lock, flags);
436 blk_plug_device(drive->queue); 426 blk_plug_device(q);
437 spin_unlock_irqrestore(&ide_lock, 427 spin_unlock_irqrestore(q->queue_lock, flags);
438 flags); 428
439 return 1; 429 return 1;
440 } 430 }
441 } 431 }
@@ -504,12 +494,14 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
504 494
505end_request: 495end_request:
506 if (stat & ATA_ERR) { 496 if (stat & ATA_ERR) {
497 struct request_queue *q = drive->queue;
507 unsigned long flags; 498 unsigned long flags;
508 499
509 spin_lock_irqsave(&ide_lock, flags); 500 spin_lock_irqsave(q->queue_lock, flags);
510 blkdev_dequeue_request(rq); 501 blkdev_dequeue_request(rq);
511 HWGROUP(drive)->rq = NULL; 502 spin_unlock_irqrestore(q->queue_lock, flags);
512 spin_unlock_irqrestore(&ide_lock, flags); 503
504 hwif->rq = NULL;
513 505
514 cdrom_queue_request_sense(drive, rq->sense, rq); 506 cdrom_queue_request_sense(drive, rq->sense, rq);
515 } else 507 } else
@@ -518,133 +510,6 @@ end_request:
518 return 1; 510 return 1;
519} 511}
520 512
521static int cdrom_timer_expiry(ide_drive_t *drive)
522{
523 struct request *rq = HWGROUP(drive)->rq;
524 unsigned long wait = 0;
525
526 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd[0]: 0x%x\n", __func__,
527 rq->cmd[0]);
528
529 /*
530 * Some commands are *slow* and normally take a long time to complete.
531 * Usually we can use the ATAPI "disconnect" to bypass this, but not all
532 * commands/drives support that. Let ide_timer_expiry keep polling us
533 * for these.
534 */
535 switch (rq->cmd[0]) {
536 case GPCMD_BLANK:
537 case GPCMD_FORMAT_UNIT:
538 case GPCMD_RESERVE_RZONE_TRACK:
539 case GPCMD_CLOSE_TRACK:
540 case GPCMD_FLUSH_CACHE:
541 wait = ATAPI_WAIT_PC;
542 break;
543 default:
544 if (!(rq->cmd_flags & REQ_QUIET))
545 printk(KERN_INFO PFX "cmd 0x%x timed out\n",
546 rq->cmd[0]);
547 wait = 0;
548 break;
549 }
550 return wait;
551}
552
553/*
554 * Set up the device registers for transferring a packet command on DEV,
555 * expecting to later transfer XFERLEN bytes. HANDLER is the routine
556 * which actually transfers the command to the drive. If this is a
557 * drq_interrupt device, this routine will arrange for HANDLER to be
558 * called when the interrupt from the drive arrives. Otherwise, HANDLER
559 * will be called immediately after the drive is prepared for the transfer.
560 */
561static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
562 int xferlen,
563 ide_handler_t *handler)
564{
565 ide_hwif_t *hwif = drive->hwif;
566
567 ide_debug_log(IDE_DBG_PC, "Call %s, xferlen: %d\n", __func__, xferlen);
568
569 /* FIXME: for Virtual DMA we must check harder */
570 if (drive->dma)
571 drive->dma = !hwif->dma_ops->dma_setup(drive);
572
573 /* set up the controller registers */
574 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL,
575 xferlen, drive->dma);
576
577 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
578 /* waiting for CDB interrupt, not DMA yet. */
579 if (drive->dma)
580 drive->waiting_for_dma = 0;
581
582 /* packet command */
583 ide_execute_command(drive, ATA_CMD_PACKET, handler,
584 ATAPI_WAIT_PC, cdrom_timer_expiry);
585 return ide_started;
586 } else {
587 ide_execute_pkt_cmd(drive);
588
589 return (*handler) (drive);
590 }
591}
592
593/*
594 * Send a packet command to DRIVE described by CMD_BUF and CMD_LEN. The device
595 * registers must have already been prepared by cdrom_start_packet_command.
596 * HANDLER is the interrupt handler to call when the command completes or
597 * there's data ready.
598 */
599#define ATAPI_MIN_CDB_BYTES 12
600static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
601 struct request *rq,
602 ide_handler_t *handler)
603{
604 ide_hwif_t *hwif = drive->hwif;
605 int cmd_len;
606 ide_startstop_t startstop;
607
608 ide_debug_log(IDE_DBG_PC, "Call %s\n", __func__);
609
610 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
611 /*
612 * Here we should have been called after receiving an interrupt
613 * from the device. DRQ should how be set.
614 */
615
616 /* check for errors */
617 if (cdrom_decode_status(drive, ATA_DRQ, NULL))
618 return ide_stopped;
619
620 /* ok, next interrupt will be DMA interrupt */
621 if (drive->dma)
622 drive->waiting_for_dma = 1;
623 } else {
624 /* otherwise, we must wait for DRQ to get set */
625 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
626 ATA_BUSY, WAIT_READY))
627 return startstop;
628 }
629
630 /* arm the interrupt handler */
631 ide_set_handler(drive, handler, rq->timeout, cdrom_timer_expiry);
632
633 /* ATAPI commands get padded out to 12 bytes minimum */
634 cmd_len = COMMAND_SIZE(rq->cmd[0]);
635 if (cmd_len < ATAPI_MIN_CDB_BYTES)
636 cmd_len = ATAPI_MIN_CDB_BYTES;
637
638 /* send the command to the device */
639 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
640
641 /* start the DMA if need be */
642 if (drive->dma)
643 hwif->dma_ops->dma_start(drive);
644
645 return ide_started;
646}
647
648/* 513/*
649 * Check the contents of the interrupt reason register from the cdrom 514 * Check the contents of the interrupt reason register from the cdrom
650 * and attempt to recover if there are problems. Returns 0 if everything's 515 * and attempt to recover if there are problems. Returns 0 if everything's
@@ -716,8 +581,6 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
716 return 1; 581 return 1;
717} 582}
718 583
719static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
720
721static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, 584static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
722 struct request *rq) 585 struct request *rq)
723{ 586{
@@ -760,66 +623,6 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
760} 623}
761 624
762/* 625/*
763 * Routine to send a read/write packet command to the drive. This is usually
764 * called directly from cdrom_start_{read,write}(). However, for drq_interrupt
765 * devices, it is called from an interrupt when the drive is ready to accept
766 * the command.
767 */
768static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
769{
770 struct request *rq = drive->hwif->hwgroup->rq;
771
772 /* send the command to the drive and return */
773 return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr);
774}
775
776#define IDECD_SEEK_THRESHOLD (1000) /* 1000 blocks */
777#define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */
778#define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */
779
780static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
781{
782 struct cdrom_info *info = drive->driver_data;
783 int stat;
784 static int retry = 10;
785
786 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
787
788 if (cdrom_decode_status(drive, 0, &stat))
789 return ide_stopped;
790
791 drive->atapi_flags |= IDE_AFLAG_SEEKING;
792
793 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) {
794 if (--retry == 0)
795 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
796 }
797 return ide_stopped;
798}
799
800static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq)
801{
802 sector_t frame = rq->sector;
803
804 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
805
806 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
807
808 memset(rq->cmd, 0, BLK_MAX_CDB);
809 rq->cmd[0] = GPCMD_SEEK;
810 put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]);
811
812 rq->timeout = ATAPI_WAIT_PC;
813}
814
815static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
816{
817 struct request *rq = drive->hwif->hwgroup->rq;
818
819 return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr);
820}
821
822/*
823 * Fix up a possibly partially-processed request so that we can start it over 626 * Fix up a possibly partially-processed request so that we can start it over
824 * entirely, or even put it back on the request queue. 627 * entirely, or even put it back on the request queue.
825 */ 628 */
@@ -950,7 +753,7 @@ static int cdrom_newpc_intr_dummy_cb(struct request *rq)
950static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 753static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
951{ 754{
952 ide_hwif_t *hwif = drive->hwif; 755 ide_hwif_t *hwif = drive->hwif;
953 struct request *rq = HWGROUP(drive)->rq; 756 struct request *rq = hwif->rq;
954 xfer_func_t *xferfunc; 757 xfer_func_t *xferfunc;
955 ide_expiry_t *expiry = NULL; 758 ide_expiry_t *expiry = NULL;
956 int dma_error = 0, dma, stat, thislen, uptodate = 0; 759 int dma_error = 0, dma, stat, thislen, uptodate = 0;
@@ -1140,7 +943,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1140 } else { 943 } else {
1141 timeout = ATAPI_WAIT_PC; 944 timeout = ATAPI_WAIT_PC;
1142 if (!blk_fs_request(rq)) 945 if (!blk_fs_request(rq))
1143 expiry = cdrom_timer_expiry; 946 expiry = ide_cd_expiry;
1144 } 947 }
1145 948
1146 ide_set_handler(drive, cdrom_newpc_intr, timeout, expiry); 949 ide_set_handler(drive, cdrom_newpc_intr, timeout, expiry);
@@ -1148,17 +951,15 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1148 951
1149end_request: 952end_request:
1150 if (blk_pc_request(rq)) { 953 if (blk_pc_request(rq)) {
1151 unsigned long flags;
1152 unsigned int dlen = rq->data_len; 954 unsigned int dlen = rq->data_len;
1153 955
1154 if (dma) 956 if (dma)
1155 rq->data_len = 0; 957 rq->data_len = 0;
1156 958
1157 spin_lock_irqsave(&ide_lock, flags); 959 if (blk_end_request(rq, 0, dlen))
1158 if (__blk_end_request(rq, 0, dlen))
1159 BUG(); 960 BUG();
1160 HWGROUP(drive)->rq = NULL; 961
1161 spin_unlock_irqrestore(&ide_lock, flags); 962 hwif->rq = NULL;
1162 } else { 963 } else {
1163 if (!uptodate) 964 if (!uptodate)
1164 rq->cmd_flags |= REQ_FAILED; 965 rq->cmd_flags |= REQ_FAILED;
@@ -1209,13 +1010,6 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1209 return ide_started; 1010 return ide_started;
1210} 1011}
1211 1012
1212static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
1213{
1214 struct request *rq = HWGROUP(drive)->rq;
1215
1216 return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr);
1217}
1218
1219static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) 1013static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1220{ 1014{
1221 1015
@@ -1260,59 +1054,19 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1260static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq, 1054static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1261 sector_t block) 1055 sector_t block)
1262{ 1056{
1263 struct cdrom_info *info = drive->driver_data;
1264 ide_handler_t *fn;
1265 int xferlen;
1266
1267 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd[0]: 0x%x, " 1057 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd[0]: 0x%x, "
1268 "rq->cmd_type: 0x%x, block: %llu\n", 1058 "rq->cmd_type: 0x%x, block: %llu\n",
1269 __func__, rq->cmd[0], rq->cmd_type, 1059 __func__, rq->cmd[0], rq->cmd_type,
1270 (unsigned long long)block); 1060 (unsigned long long)block);
1271 1061
1272 if (blk_fs_request(rq)) { 1062 if (blk_fs_request(rq)) {
1273 if (drive->atapi_flags & IDE_AFLAG_SEEKING) { 1063 if (cdrom_start_rw(drive, rq) == ide_stopped)
1274 ide_hwif_t *hwif = drive->hwif; 1064 return ide_stopped;
1275 unsigned long elapsed = jiffies - info->start_seek;
1276 int stat = hwif->tp_ops->read_status(hwif);
1277
1278 if ((stat & ATA_DSC) != ATA_DSC) {
1279 if (elapsed < IDECD_SEEK_TIMEOUT) {
1280 ide_stall_queue(drive,
1281 IDECD_SEEK_TIMER);
1282 return ide_stopped;
1283 }
1284 printk(KERN_ERR PFX "%s: DSC timeout\n",
1285 drive->name);
1286 }
1287 drive->atapi_flags &= ~IDE_AFLAG_SEEKING;
1288 }
1289 if (rq_data_dir(rq) == READ &&
1290 IDE_LARGE_SEEK(info->last_block, block,
1291 IDECD_SEEK_THRESHOLD) &&
1292 (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)) {
1293 xferlen = 0;
1294 fn = cdrom_start_seek_continuation;
1295
1296 drive->dma = 0;
1297 info->start_seek = jiffies;
1298
1299 ide_cd_prepare_seek_request(drive, rq);
1300 } else {
1301 xferlen = 32768;
1302 fn = cdrom_start_rw_cont;
1303
1304 if (cdrom_start_rw(drive, rq) == ide_stopped)
1305 return ide_stopped;
1306 1065
1307 if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped) 1066 if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped)
1308 return ide_stopped; 1067 return ide_stopped;
1309 }
1310 info->last_block = block;
1311 } else if (blk_sense_request(rq) || blk_pc_request(rq) || 1068 } else if (blk_sense_request(rq) || blk_pc_request(rq) ||
1312 rq->cmd_type == REQ_TYPE_ATA_PC) { 1069 rq->cmd_type == REQ_TYPE_ATA_PC) {
1313 xferlen = rq->data_len;
1314 fn = cdrom_do_newpc_cont;
1315
1316 if (!rq->timeout) 1070 if (!rq->timeout)
1317 rq->timeout = ATAPI_WAIT_PC; 1071 rq->timeout = ATAPI_WAIT_PC;
1318 1072
@@ -1327,7 +1081,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1327 return ide_stopped; 1081 return ide_stopped;
1328 } 1082 }
1329 1083
1330 return cdrom_start_packet_command(drive, xferlen, fn); 1084 return ide_issue_pc(drive);
1331} 1085}
1332 1086
1333/* 1087/*
@@ -1908,13 +1662,6 @@ static ide_proc_entry_t idecd_proc[] = {
1908 { NULL, 0, NULL, NULL } 1662 { NULL, 0, NULL, NULL }
1909}; 1663};
1910 1664
1911ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
1912
1913static const struct ide_proc_devset idecd_settings[] = {
1914 IDE_PROC_DEVSET(dsc_overlap, 0, 1),
1915 { 0 },
1916};
1917
1918static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive) 1665static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
1919{ 1666{
1920 return idecd_proc; 1667 return idecd_proc;
@@ -1922,7 +1669,7 @@ static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
1922 1669
1923static const struct ide_proc_devset *ide_cd_proc_devsets(ide_drive_t *drive) 1670static const struct ide_proc_devset *ide_cd_proc_devsets(ide_drive_t *drive)
1924{ 1671{
1925 return idecd_settings; 1672 return NULL;
1926} 1673}
1927#endif 1674#endif
1928 1675
@@ -2022,11 +1769,6 @@ static int ide_cdrom_setup(ide_drive_t *drive)
2022 /* set correct block size */ 1769 /* set correct block size */
2023 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); 1770 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
2024 1771
2025 if (drive->next != drive)
2026 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2027 else
2028 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2029
2030 if (ide_cdrom_register(drive, nslots)) { 1772 if (ide_cdrom_register(drive, nslots)) {
2031 printk(KERN_ERR PFX "%s: %s failed to register device with the" 1773 printk(KERN_ERR PFX "%s: %s failed to register device with the"
2032 " cdrom driver.\n", drive->name, __func__); 1774 " cdrom driver.\n", drive->name, __func__);
@@ -2063,7 +1805,6 @@ static void ide_cd_release(struct kref *kref)
2063 kfree(info->toc); 1805 kfree(info->toc);
2064 if (devinfo->handle == drive) 1806 if (devinfo->handle == drive)
2065 unregister_cdrom(devinfo); 1807 unregister_cdrom(devinfo);
2066 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2067 drive->driver_data = NULL; 1808 drive->driver_data = NULL;
2068 blk_queue_prep_rq(drive->queue, NULL); 1809 blk_queue_prep_rq(drive->queue, NULL);
2069 g->private_data = NULL; 1810 g->private_data = NULL;
@@ -2073,7 +1814,7 @@ static void ide_cd_release(struct kref *kref)
2073 1814
2074static int ide_cd_probe(ide_drive_t *); 1815static int ide_cd_probe(ide_drive_t *);
2075 1816
2076static ide_driver_t ide_cdrom_driver = { 1817static struct ide_driver ide_cdrom_driver = {
2077 .gen_driver = { 1818 .gen_driver = {
2078 .owner = THIS_MODULE, 1819 .owner = THIS_MODULE,
2079 .name = "ide-cdrom", 1820 .name = "ide-cdrom",
@@ -2084,7 +1825,6 @@ static ide_driver_t ide_cdrom_driver = {
2084 .version = IDECD_VERSION, 1825 .version = IDECD_VERSION,
2085 .do_request = ide_cd_do_request, 1826 .do_request = ide_cd_do_request,
2086 .end_request = ide_end_request, 1827 .end_request = ide_end_request,
2087 .error = __ide_error,
2088#ifdef CONFIG_IDE_PROC_FS 1828#ifdef CONFIG_IDE_PROC_FS
2089 .proc_entries = ide_cd_proc_entries, 1829 .proc_entries = ide_cd_proc_entries,
2090 .proc_devsets = ide_cd_proc_devsets, 1830 .proc_devsets = ide_cd_proc_devsets,
@@ -2239,6 +1979,7 @@ static int ide_cd_probe(ide_drive_t *drive)
2239 } 1979 }
2240 1980
2241 drive->debug_mask = debug_mask; 1981 drive->debug_mask = debug_mask;
1982 drive->irq_handler = cdrom_newpc_intr;
2242 1983
2243 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); 1984 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
2244 if (info == NULL) { 1985 if (info == NULL) {
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 5882b9a9ea8b..ac40d6cb90a2 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -8,10 +8,14 @@
8#include <linux/cdrom.h> 8#include <linux/cdrom.h>
9#include <asm/byteorder.h> 9#include <asm/byteorder.h>
10 10
11/* 11#define IDECD_DEBUG_LOG 0
12 * typical timeout for packet command 12
13 */ 13#if IDECD_DEBUG_LOG
14#define ATAPI_WAIT_PC (60 * HZ) 14#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
15#else
16#define ide_debug_log(lvl, fmt, args...) do {} while (0)
17#endif
18
15#define ATAPI_WAIT_WRITE_BUSY (10 * HZ) 19#define ATAPI_WAIT_WRITE_BUSY (10 * HZ)
16 20
17/************************************************************************/ 21/************************************************************************/
@@ -29,33 +33,33 @@
29 33
30/* Structure of a MSF cdrom address. */ 34/* Structure of a MSF cdrom address. */
31struct atapi_msf { 35struct atapi_msf {
32 byte reserved; 36 u8 reserved;
33 byte minute; 37 u8 minute;
34 byte second; 38 u8 second;
35 byte frame; 39 u8 frame;
36}; 40};
37 41
38/* Space to hold the disk TOC. */ 42/* Space to hold the disk TOC. */
39#define MAX_TRACKS 99 43#define MAX_TRACKS 99
40struct atapi_toc_header { 44struct atapi_toc_header {
41 unsigned short toc_length; 45 unsigned short toc_length;
42 byte first_track; 46 u8 first_track;
43 byte last_track; 47 u8 last_track;
44}; 48};
45 49
46struct atapi_toc_entry { 50struct atapi_toc_entry {
47 byte reserved1; 51 u8 reserved1;
48#if defined(__BIG_ENDIAN_BITFIELD) 52#if defined(__BIG_ENDIAN_BITFIELD)
49 __u8 adr : 4; 53 u8 adr : 4;
50 __u8 control : 4; 54 u8 control : 4;
51#elif defined(__LITTLE_ENDIAN_BITFIELD) 55#elif defined(__LITTLE_ENDIAN_BITFIELD)
52 __u8 control : 4; 56 u8 control : 4;
53 __u8 adr : 4; 57 u8 adr : 4;
54#else 58#else
55#error "Please fix <asm/byteorder.h>" 59#error "Please fix <asm/byteorder.h>"
56#endif 60#endif
57 byte track; 61 u8 track;
58 byte reserved2; 62 u8 reserved2;
59 union { 63 union {
60 unsigned lba; 64 unsigned lba;
61 struct atapi_msf msf; 65 struct atapi_msf msf;
@@ -73,10 +77,10 @@ struct atapi_toc {
73 77
74/* Extra per-device info for cdrom drives. */ 78/* Extra per-device info for cdrom drives. */
75struct cdrom_info { 79struct cdrom_info {
76 ide_drive_t *drive; 80 ide_drive_t *drive;
77 ide_driver_t *driver; 81 struct ide_driver *driver;
78 struct gendisk *disk; 82 struct gendisk *disk;
79 struct kref kref; 83 struct kref kref;
80 84
81 /* Buffer for table of contents. NULL if we haven't allocated 85 /* Buffer for table of contents. NULL if we haven't allocated
82 a TOC buffer for this device yet. */ 86 a TOC buffer for this device yet. */
@@ -88,8 +92,6 @@ struct cdrom_info {
88 struct request_sense sense_data; 92 struct request_sense sense_data;
89 93
90 struct request request_sense_request; 94 struct request request_sense_request;
91 unsigned long last_block;
92 unsigned long start_seek;
93 95
94 u8 max_speed; /* Max speed of the drive. */ 96 u8 max_speed; /* Max speed of the drive. */
95 u8 current_speed; /* Current speed of the drive. */ 97 u8 current_speed; /* Current speed of the drive. */
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index eb9fac4d0f0c..4088a622873e 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -89,7 +89,7 @@ static void ide_tf_set_cmd(ide_drive_t *drive, ide_task_t *task, u8 dma)
89static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, 89static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
90 sector_t block) 90 sector_t block)
91{ 91{
92 ide_hwif_t *hwif = HWIF(drive); 92 ide_hwif_t *hwif = drive->hwif;
93 u16 nsectors = (u16)rq->nr_sectors; 93 u16 nsectors = (u16)rq->nr_sectors;
94 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); 94 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
95 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); 95 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
@@ -187,7 +187,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
187static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq, 187static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
188 sector_t block) 188 sector_t block)
189{ 189{
190 ide_hwif_t *hwif = HWIF(drive); 190 ide_hwif_t *hwif = drive->hwif;
191 191
192 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED); 192 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
193 193
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
index cac431f0df17..123d393658af 100644
--- a/drivers/ide/ide-dma-sff.c
+++ b/drivers/ide/ide-dma-sff.c
@@ -50,6 +50,27 @@ int config_drive_for_dma(ide_drive_t *drive)
50 return 0; 50 return 0;
51} 51}
52 52
53u8 ide_dma_sff_read_status(ide_hwif_t *hwif)
54{
55 unsigned long addr = hwif->dma_base + ATA_DMA_STATUS;
56
57 if (hwif->host_flags & IDE_HFLAG_MMIO)
58 return readb((void __iomem *)addr);
59 else
60 return inb(addr);
61}
62EXPORT_SYMBOL_GPL(ide_dma_sff_read_status);
63
64static void ide_dma_sff_write_status(ide_hwif_t *hwif, u8 val)
65{
66 unsigned long addr = hwif->dma_base + ATA_DMA_STATUS;
67
68 if (hwif->host_flags & IDE_HFLAG_MMIO)
69 writeb(val, (void __iomem *)addr);
70 else
71 outb(val, addr);
72}
73
53/** 74/**
54 * ide_dma_host_set - Enable/disable DMA on a host 75 * ide_dma_host_set - Enable/disable DMA on a host
55 * @drive: drive to control 76 * @drive: drive to control
@@ -62,18 +83,14 @@ void ide_dma_host_set(ide_drive_t *drive, int on)
62{ 83{
63 ide_hwif_t *hwif = drive->hwif; 84 ide_hwif_t *hwif = drive->hwif;
64 u8 unit = drive->dn & 1; 85 u8 unit = drive->dn & 1;
65 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 86 u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
66 87
67 if (on) 88 if (on)
68 dma_stat |= (1 << (5 + unit)); 89 dma_stat |= (1 << (5 + unit));
69 else 90 else
70 dma_stat &= ~(1 << (5 + unit)); 91 dma_stat &= ~(1 << (5 + unit));
71 92
72 if (hwif->host_flags & IDE_HFLAG_MMIO) 93 ide_dma_sff_write_status(hwif, dma_stat);
73 writeb(dma_stat,
74 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
75 else
76 outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
77} 94}
78EXPORT_SYMBOL_GPL(ide_dma_host_set); 95EXPORT_SYMBOL_GPL(ide_dma_host_set);
79 96
@@ -98,10 +115,10 @@ int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
98{ 115{
99 ide_hwif_t *hwif = drive->hwif; 116 ide_hwif_t *hwif = drive->hwif;
100 __le32 *table = (__le32 *)hwif->dmatable_cpu; 117 __le32 *table = (__le32 *)hwif->dmatable_cpu;
101 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
102 unsigned int count = 0; 118 unsigned int count = 0;
103 int i; 119 int i;
104 struct scatterlist *sg; 120 struct scatterlist *sg;
121 u8 is_trm290 = !!(hwif->host_flags & IDE_HFLAG_TRM290);
105 122
106 hwif->sg_nents = ide_build_sglist(drive, rq); 123 hwif->sg_nents = ide_build_sglist(drive, rq);
107 if (hwif->sg_nents == 0) 124 if (hwif->sg_nents == 0)
@@ -175,16 +192,11 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
175int ide_dma_setup(ide_drive_t *drive) 192int ide_dma_setup(ide_drive_t *drive)
176{ 193{
177 ide_hwif_t *hwif = drive->hwif; 194 ide_hwif_t *hwif = drive->hwif;
178 struct request *rq = hwif->hwgroup->rq; 195 struct request *rq = hwif->rq;
179 unsigned int reading; 196 unsigned int reading = rq_data_dir(rq) ? 0 : ATA_DMA_WR;
180 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 197 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
181 u8 dma_stat; 198 u8 dma_stat;
182 199
183 if (rq_data_dir(rq))
184 reading = 0;
185 else
186 reading = 1 << 3;
187
188 /* fall back to pio! */ 200 /* fall back to pio! */
189 if (!ide_build_dmatable(drive, rq)) { 201 if (!ide_build_dmatable(drive, rq)) {
190 ide_map_sg(drive, rq); 202 ide_map_sg(drive, rq);
@@ -192,7 +204,7 @@ int ide_dma_setup(ide_drive_t *drive)
192 } 204 }
193 205
194 /* PRD table */ 206 /* PRD table */
195 if (hwif->host_flags & IDE_HFLAG_MMIO) 207 if (mmio)
196 writel(hwif->dmatable_dma, 208 writel(hwif->dmatable_dma,
197 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS)); 209 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
198 else 210 else
@@ -205,14 +217,10 @@ int ide_dma_setup(ide_drive_t *drive)
205 outb(reading, hwif->dma_base + ATA_DMA_CMD); 217 outb(reading, hwif->dma_base + ATA_DMA_CMD);
206 218
207 /* read DMA status for INTR & ERROR flags */ 219 /* read DMA status for INTR & ERROR flags */
208 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 220 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
209 221
210 /* clear INTR & ERROR flags */ 222 /* clear INTR & ERROR flags */
211 if (mmio) 223 ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR);
212 writeb(dma_stat | 6,
213 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
214 else
215 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
216 224
217 drive->waiting_for_dma = 1; 225 drive->waiting_for_dma = 1;
218 return 0; 226 return 0;
@@ -236,7 +244,7 @@ EXPORT_SYMBOL_GPL(ide_dma_setup);
236static int dma_timer_expiry(ide_drive_t *drive) 244static int dma_timer_expiry(ide_drive_t *drive)
237{ 245{
238 ide_hwif_t *hwif = drive->hwif; 246 ide_hwif_t *hwif = drive->hwif;
239 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 247 u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
240 248
241 printk(KERN_WARNING "%s: %s: DMA status (0x%02x)\n", 249 printk(KERN_WARNING "%s: %s: DMA status (0x%02x)\n",
242 drive->name, __func__, dma_stat); 250 drive->name, __func__, dma_stat);
@@ -244,16 +252,15 @@ static int dma_timer_expiry(ide_drive_t *drive)
244 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */ 252 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
245 return WAIT_CMD; 253 return WAIT_CMD;
246 254
247 hwif->hwgroup->expiry = NULL; /* one free ride for now */ 255 hwif->expiry = NULL; /* one free ride for now */
248 256
249 /* 1 dmaing, 2 error, 4 intr */ 257 if (dma_stat & ATA_DMA_ERR) /* ERROR */
250 if (dma_stat & 2) /* ERROR */
251 return -1; 258 return -1;
252 259
253 if (dma_stat & 1) /* DMAing */ 260 if (dma_stat & ATA_DMA_ACTIVE) /* DMAing */
254 return WAIT_CMD; 261 return WAIT_CMD;
255 262
256 if (dma_stat & 4) /* Got an Interrupt */ 263 if (dma_stat & ATA_DMA_INTR) /* Got an Interrupt */
257 return WAIT_CMD; 264 return WAIT_CMD;
258 265
259 return 0; /* Status is unknown -- reset the bus */ 266 return 0; /* Status is unknown -- reset the bus */
@@ -279,12 +286,11 @@ void ide_dma_start(ide_drive_t *drive)
279 */ 286 */
280 if (hwif->host_flags & IDE_HFLAG_MMIO) { 287 if (hwif->host_flags & IDE_HFLAG_MMIO) {
281 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); 288 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
282 /* start DMA */ 289 writeb(dma_cmd | ATA_DMA_START,
283 writeb(dma_cmd | 1,
284 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); 290 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
285 } else { 291 } else {
286 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); 292 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
287 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD); 293 outb(dma_cmd | ATA_DMA_START, hwif->dma_base + ATA_DMA_CMD);
288 } 294 }
289 295
290 wmb(); 296 wmb();
@@ -295,37 +301,35 @@ EXPORT_SYMBOL_GPL(ide_dma_start);
295int ide_dma_end(ide_drive_t *drive) 301int ide_dma_end(ide_drive_t *drive)
296{ 302{
297 ide_hwif_t *hwif = drive->hwif; 303 ide_hwif_t *hwif = drive->hwif;
298 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 304 u8 dma_stat = 0, dma_cmd = 0, mask;
299 u8 dma_stat = 0, dma_cmd = 0;
300 305
301 drive->waiting_for_dma = 0; 306 drive->waiting_for_dma = 0;
302 307
303 if (mmio) { 308 /* stop DMA */
304 /* get DMA command mode */ 309 if (hwif->host_flags & IDE_HFLAG_MMIO) {
305 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); 310 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
306 /* stop DMA */ 311 writeb(dma_cmd & ~ATA_DMA_START,
307 writeb(dma_cmd & ~1,
308 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); 312 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
309 } else { 313 } else {
310 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); 314 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
311 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD); 315 outb(dma_cmd & ~ATA_DMA_START, hwif->dma_base + ATA_DMA_CMD);
312 } 316 }
313 317
314 /* get DMA status */ 318 /* get DMA status */
315 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 319 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
316 320
317 if (mmio) 321 /* clear INTR & ERROR bits */
318 /* clear the INTR & ERROR bits */ 322 ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR);
319 writeb(dma_stat | 6,
320 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
321 else
322 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
323 323
324 /* purge DMA mappings */ 324 /* purge DMA mappings */
325 ide_destroy_dmatable(drive); 325 ide_destroy_dmatable(drive);
326 /* verify good DMA status */
327 wmb(); 326 wmb();
328 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; 327
328 /* verify good DMA status */
329 mask = ATA_DMA_ACTIVE | ATA_DMA_ERR | ATA_DMA_INTR;
330 if ((dma_stat & mask) != ATA_DMA_INTR)
331 return 0x10 | dma_stat;
332 return 0;
329} 333}
330EXPORT_SYMBOL_GPL(ide_dma_end); 334EXPORT_SYMBOL_GPL(ide_dma_end);
331 335
@@ -333,13 +337,9 @@ EXPORT_SYMBOL_GPL(ide_dma_end);
333int ide_dma_test_irq(ide_drive_t *drive) 337int ide_dma_test_irq(ide_drive_t *drive)
334{ 338{
335 ide_hwif_t *hwif = drive->hwif; 339 ide_hwif_t *hwif = drive->hwif;
336 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 340 u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
337 341
338 /* return 1 if INTR asserted */ 342 return (dma_stat & ATA_DMA_INTR) ? 1 : 0;
339 if ((dma_stat & 4) == 4)
340 return 1;
341
342 return 0;
343} 343}
344EXPORT_SYMBOL_GPL(ide_dma_test_irq); 344EXPORT_SYMBOL_GPL(ide_dma_test_irq);
345 345
@@ -352,5 +352,6 @@ const struct ide_dma_ops sff_dma_ops = {
352 .dma_test_irq = ide_dma_test_irq, 352 .dma_test_irq = ide_dma_test_irq,
353 .dma_timeout = ide_dma_timeout, 353 .dma_timeout = ide_dma_timeout,
354 .dma_lost_irq = ide_dma_lost_irq, 354 .dma_lost_irq = ide_dma_lost_irq,
355 .dma_sff_read_status = ide_dma_sff_read_status,
355}; 356};
356EXPORT_SYMBOL_GPL(sff_dma_ops); 357EXPORT_SYMBOL_GPL(sff_dma_ops);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index fffd11717b2d..72ebab0bc755 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -96,7 +96,7 @@ ide_startstop_t ide_dma_intr(ide_drive_t *drive)
96 96
97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) { 97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
98 if (!dma_stat) { 98 if (!dma_stat) {
99 struct request *rq = hwif->hwgroup->rq; 99 struct request *rq = hwif->rq;
100 100
101 task_end_request(drive, rq, stat); 101 task_end_request(drive, rq, stat);
102 return ide_stopped; 102 return ide_stopped;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index aeb1ad782f54..3eab1c6c9b31 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -71,7 +71,7 @@
71static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs) 71static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
72{ 72{
73 struct ide_disk_obj *floppy = drive->driver_data; 73 struct ide_disk_obj *floppy = drive->driver_data;
74 struct request *rq = HWGROUP(drive)->rq; 74 struct request *rq = drive->hwif->rq;
75 int error; 75 int error;
76 76
77 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 77 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
@@ -197,7 +197,7 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
197 197
198 pc->retries++; 198 pc->retries++;
199 199
200 return ide_issue_pc(drive, WAIT_FLOPPY_CMD, NULL); 200 return ide_issue_pc(drive);
201} 201}
202 202
203void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 203void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
@@ -342,38 +342,38 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
342 * Look at the flexible disk page parameters. We ignore the CHS capacity 342 * Look at the flexible disk page parameters. We ignore the CHS capacity
343 * parameters and use the LBA parameters instead. 343 * parameters and use the LBA parameters instead.
344 */ 344 */
345static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) 345static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive,
346 struct ide_atapi_pc *pc)
346{ 347{
347 struct ide_disk_obj *floppy = drive->driver_data; 348 struct ide_disk_obj *floppy = drive->driver_data;
348 struct gendisk *disk = floppy->disk; 349 struct gendisk *disk = floppy->disk;
349 struct ide_atapi_pc pc;
350 u8 *page; 350 u8 *page;
351 int capacity, lba_capacity; 351 int capacity, lba_capacity;
352 u16 transfer_rate, sector_size, cyls, rpm; 352 u16 transfer_rate, sector_size, cyls, rpm;
353 u8 heads, sectors; 353 u8 heads, sectors;
354 354
355 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE); 355 ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
356 356
357 if (ide_queue_pc_tail(drive, disk, &pc)) { 357 if (ide_queue_pc_tail(drive, disk, pc)) {
358 printk(KERN_ERR PFX "Can't get flexible disk page params\n"); 358 printk(KERN_ERR PFX "Can't get flexible disk page params\n");
359 return 1; 359 return 1;
360 } 360 }
361 361
362 if (pc.buf[3] & 0x80) 362 if (pc->buf[3] & 0x80)
363 drive->dev_flags |= IDE_DFLAG_WP; 363 drive->dev_flags |= IDE_DFLAG_WP;
364 else 364 else
365 drive->dev_flags &= ~IDE_DFLAG_WP; 365 drive->dev_flags &= ~IDE_DFLAG_WP;
366 366
367 set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP)); 367 set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP));
368 368
369 page = &pc.buf[8]; 369 page = &pc->buf[8];
370 370
371 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); 371 transfer_rate = be16_to_cpup((__be16 *)&pc->buf[8 + 2]);
372 sector_size = be16_to_cpup((__be16 *)&pc.buf[8 + 6]); 372 sector_size = be16_to_cpup((__be16 *)&pc->buf[8 + 6]);
373 cyls = be16_to_cpup((__be16 *)&pc.buf[8 + 8]); 373 cyls = be16_to_cpup((__be16 *)&pc->buf[8 + 8]);
374 rpm = be16_to_cpup((__be16 *)&pc.buf[8 + 28]); 374 rpm = be16_to_cpup((__be16 *)&pc->buf[8 + 28]);
375 heads = pc.buf[8 + 4]; 375 heads = pc->buf[8 + 4];
376 sectors = pc.buf[8 + 5]; 376 sectors = pc->buf[8 + 5];
377 377
378 capacity = cyls * heads * sectors * sector_size; 378 capacity = cyls * heads * sectors * sector_size;
379 379
@@ -499,7 +499,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
499 499
500 /* Clik! disk does not support get_flexible_disk_page */ 500 /* Clik! disk does not support get_flexible_disk_page */
501 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) 501 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
502 (void) ide_floppy_get_flexible_disk_page(drive); 502 (void) ide_floppy_get_flexible_disk_page(drive, &pc);
503 503
504 return rc; 504 return rc;
505} 505}
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index 2bc51ff73fee..8f8be8546038 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -31,10 +31,11 @@
31 * On exit we set nformats to the number of records we've actually initialized. 31 * On exit we set nformats to the number of records we've actually initialized.
32 */ 32 */
33 33
34static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg) 34static int ide_floppy_get_format_capacities(ide_drive_t *drive,
35 struct ide_atapi_pc *pc,
36 int __user *arg)
35{ 37{
36 struct ide_disk_obj *floppy = drive->driver_data; 38 struct ide_disk_obj *floppy = drive->driver_data;
37 struct ide_atapi_pc pc;
38 u8 header_len, desc_cnt; 39 u8 header_len, desc_cnt;
39 int i, blocks, length, u_array_size, u_index; 40 int i, blocks, length, u_array_size, u_index;
40 int __user *argp; 41 int __user *argp;
@@ -45,13 +46,13 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
45 if (u_array_size <= 0) 46 if (u_array_size <= 0)
46 return -EINVAL; 47 return -EINVAL;
47 48
48 ide_floppy_create_read_capacity_cmd(&pc); 49 ide_floppy_create_read_capacity_cmd(pc);
49 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) { 50 if (ide_queue_pc_tail(drive, floppy->disk, pc)) {
50 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 51 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
51 return -EIO; 52 return -EIO;
52 } 53 }
53 54
54 header_len = pc.buf[3]; 55 header_len = pc->buf[3];
55 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ 56 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
56 57
57 u_index = 0; 58 u_index = 0;
@@ -68,8 +69,8 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
68 if (u_index >= u_array_size) 69 if (u_index >= u_array_size)
69 break; /* User-supplied buffer too small */ 70 break; /* User-supplied buffer too small */
70 71
71 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); 72 blocks = be32_to_cpup((__be32 *)&pc->buf[desc_start]);
72 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); 73 length = be16_to_cpup((__be16 *)&pc->buf[desc_start + 6]);
73 74
74 if (put_user(blocks, argp)) 75 if (put_user(blocks, argp))
75 return -EFAULT; 76 return -EFAULT;
@@ -111,29 +112,28 @@ static void ide_floppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
111 pc->flags |= PC_FLAG_WRITING; 112 pc->flags |= PC_FLAG_WRITING;
112} 113}
113 114
114static int ide_floppy_get_sfrp_bit(ide_drive_t *drive) 115static int ide_floppy_get_sfrp_bit(ide_drive_t *drive, struct ide_atapi_pc *pc)
115{ 116{
116 struct ide_disk_obj *floppy = drive->driver_data; 117 struct ide_disk_obj *floppy = drive->driver_data;
117 struct ide_atapi_pc pc;
118 118
119 drive->atapi_flags &= ~IDE_AFLAG_SRFP; 119 drive->atapi_flags &= ~IDE_AFLAG_SRFP;
120 120
121 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE); 121 ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_CAPABILITIES_PAGE);
122 pc.flags |= PC_FLAG_SUPPRESS_ERROR; 122 pc->flags |= PC_FLAG_SUPPRESS_ERROR;
123 123
124 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) 124 if (ide_queue_pc_tail(drive, floppy->disk, pc))
125 return 1; 125 return 1;
126 126
127 if (pc.buf[8 + 2] & 0x40) 127 if (pc->buf[8 + 2] & 0x40)
128 drive->atapi_flags |= IDE_AFLAG_SRFP; 128 drive->atapi_flags |= IDE_AFLAG_SRFP;
129 129
130 return 0; 130 return 0;
131} 131}
132 132
133static int ide_floppy_format_unit(ide_drive_t *drive, int __user *arg) 133static int ide_floppy_format_unit(ide_drive_t *drive, struct ide_atapi_pc *pc,
134 int __user *arg)
134{ 135{
135 struct ide_disk_obj *floppy = drive->driver_data; 136 struct ide_disk_obj *floppy = drive->driver_data;
136 struct ide_atapi_pc pc;
137 int blocks, length, flags, err = 0; 137 int blocks, length, flags, err = 0;
138 138
139 if (floppy->openers > 1) { 139 if (floppy->openers > 1) {
@@ -166,10 +166,10 @@ static int ide_floppy_format_unit(ide_drive_t *drive, int __user *arg)
166 goto out; 166 goto out;
167 } 167 }
168 168
169 (void)ide_floppy_get_sfrp_bit(drive); 169 ide_floppy_get_sfrp_bit(drive, pc);
170 ide_floppy_create_format_unit_cmd(&pc, blocks, length, flags); 170 ide_floppy_create_format_unit_cmd(pc, blocks, length, flags);
171 171
172 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) 172 if (ide_queue_pc_tail(drive, floppy->disk, pc))
173 err = -EIO; 173 err = -EIO;
174 174
175out: 175out:
@@ -188,15 +188,16 @@ out:
188 * the dsc bit, and return either 0 or 65536. 188 * the dsc bit, and return either 0 or 65536.
189 */ 189 */
190 190
191static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg) 191static int ide_floppy_get_format_progress(ide_drive_t *drive,
192 struct ide_atapi_pc *pc,
193 int __user *arg)
192{ 194{
193 struct ide_disk_obj *floppy = drive->driver_data; 195 struct ide_disk_obj *floppy = drive->driver_data;
194 struct ide_atapi_pc pc;
195 int progress_indication = 0x10000; 196 int progress_indication = 0x10000;
196 197
197 if (drive->atapi_flags & IDE_AFLAG_SRFP) { 198 if (drive->atapi_flags & IDE_AFLAG_SRFP) {
198 ide_create_request_sense_cmd(drive, &pc); 199 ide_create_request_sense_cmd(drive, pc);
199 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) 200 if (ide_queue_pc_tail(drive, floppy->disk, pc))
200 return -EIO; 201 return -EIO;
201 202
202 if (floppy->sense_key == 2 && 203 if (floppy->sense_key == 2 &&
@@ -241,20 +242,21 @@ static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
241 return 0; 242 return 0;
242} 243}
243 244
244static int ide_floppy_format_ioctl(ide_drive_t *drive, fmode_t mode, 245static int ide_floppy_format_ioctl(ide_drive_t *drive, struct ide_atapi_pc *pc,
245 unsigned int cmd, void __user *argp) 246 fmode_t mode, unsigned int cmd,
247 void __user *argp)
246{ 248{
247 switch (cmd) { 249 switch (cmd) {
248 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: 250 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
249 return 0; 251 return 0;
250 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: 252 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
251 return ide_floppy_get_format_capacities(drive, argp); 253 return ide_floppy_get_format_capacities(drive, pc, argp);
252 case IDEFLOPPY_IOCTL_FORMAT_START: 254 case IDEFLOPPY_IOCTL_FORMAT_START:
253 if (!(mode & FMODE_WRITE)) 255 if (!(mode & FMODE_WRITE))
254 return -EPERM; 256 return -EPERM;
255 return ide_floppy_format_unit(drive, (int __user *)argp); 257 return ide_floppy_format_unit(drive, pc, (int __user *)argp);
256 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: 258 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
257 return ide_floppy_get_format_progress(drive, argp); 259 return ide_floppy_get_format_progress(drive, pc, argp);
258 default: 260 default:
259 return -ENOTTY; 261 return -ENOTTY;
260 } 262 }
@@ -270,7 +272,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
270 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) 272 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
271 return ide_floppy_lockdoor(drive, &pc, arg, cmd); 273 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
272 274
273 err = ide_floppy_format_ioctl(drive, mode, cmd, argp); 275 err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp);
274 if (err != -ENOTTY) 276 if (err != -ENOTTY)
275 return err; 277 return err;
276 278
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index b8078b3231f7..7857b209c6df 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -149,7 +149,7 @@ static int ide_gd_end_request(ide_drive_t *drive, int uptodate, int nrsecs)
149 return drive->disk_ops->end_request(drive, uptodate, nrsecs); 149 return drive->disk_ops->end_request(drive, uptodate, nrsecs);
150} 150}
151 151
152static ide_driver_t ide_gd_driver = { 152static struct ide_driver ide_gd_driver = {
153 .gen_driver = { 153 .gen_driver = {
154 .owner = THIS_MODULE, 154 .owner = THIS_MODULE,
155 .name = "ide-gd", 155 .name = "ide-gd",
@@ -162,7 +162,6 @@ static ide_driver_t ide_gd_driver = {
162 .version = IDE_GD_VERSION, 162 .version = IDE_GD_VERSION,
163 .do_request = ide_gd_do_request, 163 .do_request = ide_gd_do_request,
164 .end_request = ide_gd_end_request, 164 .end_request = ide_gd_end_request,
165 .error = __ide_error,
166#ifdef CONFIG_IDE_PROC_FS 165#ifdef CONFIG_IDE_PROC_FS
167 .proc_entries = ide_disk_proc_entries, 166 .proc_entries = ide_disk_proc_entries,
168 .proc_devsets = ide_disk_proc_devsets, 167 .proc_devsets = ide_disk_proc_devsets,
diff --git a/drivers/ide/ide-gd.h b/drivers/ide/ide-gd.h
index 7d3d101713e0..a86779f0756b 100644
--- a/drivers/ide/ide-gd.h
+++ b/drivers/ide/ide-gd.h
@@ -14,11 +14,11 @@
14#endif 14#endif
15 15
16struct ide_disk_obj { 16struct ide_disk_obj {
17 ide_drive_t *drive; 17 ide_drive_t *drive;
18 ide_driver_t *driver; 18 struct ide_driver *driver;
19 struct gendisk *disk; 19 struct gendisk *disk;
20 struct kref kref; 20 struct kref kref;
21 unsigned int openers; /* protected by BKL for now */ 21 unsigned int openers; /* protected by BKL for now */
22 22
23 /* Last failed packet command */ 23 /* Last failed packet command */
24 struct ide_atapi_pc *failed_pc; 24 struct ide_atapi_pc *failed_pc;
diff --git a/drivers/ide/ide-h8300.c b/drivers/ide/ide-h8300.c
index e2cdd2e9cdec..9270d3255ee0 100644
--- a/drivers/ide/ide-h8300.c
+++ b/drivers/ide/ide-h8300.c
@@ -159,7 +159,6 @@ static const struct ide_tp_ops h8300_tp_ops = {
159 .exec_command = ide_exec_command, 159 .exec_command = ide_exec_command,
160 .read_status = ide_read_status, 160 .read_status = ide_read_status,
161 .read_altstatus = ide_read_altstatus, 161 .read_altstatus = ide_read_altstatus,
162 .read_sff_dma_status = ide_read_sff_dma_status,
163 162
164 .set_irq = ide_set_irq, 163 .set_irq = ide_set_irq,
165 164
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index cc35d6dbd410..cc163319dfbd 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -84,11 +84,11 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
84 ide_dma_on(drive); 84 ide_dma_on(drive);
85 } 85 }
86 86
87 if (!__blk_end_request(rq, error, nr_bytes)) { 87 if (!blk_end_request(rq, error, nr_bytes))
88 if (dequeue)
89 HWGROUP(drive)->rq = NULL;
90 ret = 0; 88 ret = 0;
91 } 89
90 if (ret == 0 && dequeue)
91 drive->hwif->rq = NULL;
92 92
93 return ret; 93 return ret;
94} 94}
@@ -107,16 +107,7 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
107int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors) 107int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
108{ 108{
109 unsigned int nr_bytes = nr_sectors << 9; 109 unsigned int nr_bytes = nr_sectors << 9;
110 struct request *rq; 110 struct request *rq = drive->hwif->rq;
111 unsigned long flags;
112 int ret = 1;
113
114 /*
115 * room for locking improvements here, the calls below don't
116 * need the queue lock held at all
117 */
118 spin_lock_irqsave(&ide_lock, flags);
119 rq = HWGROUP(drive)->rq;
120 111
121 if (!nr_bytes) { 112 if (!nr_bytes) {
122 if (blk_pc_request(rq)) 113 if (blk_pc_request(rq))
@@ -125,105 +116,10 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
125 nr_bytes = rq->hard_cur_sectors << 9; 116 nr_bytes = rq->hard_cur_sectors << 9;
126 } 117 }
127 118
128 ret = __ide_end_request(drive, rq, uptodate, nr_bytes, 1); 119 return __ide_end_request(drive, rq, uptodate, nr_bytes, 1);
129
130 spin_unlock_irqrestore(&ide_lock, flags);
131 return ret;
132} 120}
133EXPORT_SYMBOL(ide_end_request); 121EXPORT_SYMBOL(ide_end_request);
134 122
135static void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
136{
137 struct request_pm_state *pm = rq->data;
138
139#ifdef DEBUG_PM
140 printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
141 drive->name, pm->pm_step);
142#endif
143 if (drive->media != ide_disk)
144 return;
145
146 switch (pm->pm_step) {
147 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
148 if (pm->pm_state == PM_EVENT_FREEZE)
149 pm->pm_step = IDE_PM_COMPLETED;
150 else
151 pm->pm_step = IDE_PM_STANDBY;
152 break;
153 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
154 pm->pm_step = IDE_PM_COMPLETED;
155 break;
156 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
157 pm->pm_step = IDE_PM_IDLE;
158 break;
159 case IDE_PM_IDLE: /* Resume step 2 (idle)*/
160 pm->pm_step = IDE_PM_RESTORE_DMA;
161 break;
162 }
163}
164
165static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
166{
167 struct request_pm_state *pm = rq->data;
168 ide_task_t *args = rq->special;
169
170 memset(args, 0, sizeof(*args));
171
172 switch (pm->pm_step) {
173 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
174 if (drive->media != ide_disk)
175 break;
176 /* Not supported? Switch to next step now. */
177 if (ata_id_flush_enabled(drive->id) == 0 ||
178 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
179 ide_complete_power_step(drive, rq);
180 return ide_stopped;
181 }
182 if (ata_id_flush_ext_enabled(drive->id))
183 args->tf.command = ATA_CMD_FLUSH_EXT;
184 else
185 args->tf.command = ATA_CMD_FLUSH;
186 goto out_do_tf;
187 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
188 args->tf.command = ATA_CMD_STANDBYNOW1;
189 goto out_do_tf;
190 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
191 ide_set_max_pio(drive);
192 /*
193 * skip IDE_PM_IDLE for ATAPI devices
194 */
195 if (drive->media != ide_disk)
196 pm->pm_step = IDE_PM_RESTORE_DMA;
197 else
198 ide_complete_power_step(drive, rq);
199 return ide_stopped;
200 case IDE_PM_IDLE: /* Resume step 2 (idle) */
201 args->tf.command = ATA_CMD_IDLEIMMEDIATE;
202 goto out_do_tf;
203 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
204 /*
205 * Right now, all we do is call ide_set_dma(drive),
206 * we could be smarter and check for current xfer_speed
207 * in struct drive etc...
208 */
209 if (drive->hwif->dma_ops == NULL)
210 break;
211 /*
212 * TODO: respect IDE_DFLAG_USING_DMA
213 */
214 ide_set_dma(drive);
215 break;
216 }
217
218 pm->pm_step = IDE_PM_COMPLETED;
219 return ide_stopped;
220
221out_do_tf:
222 args->tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
223 args->data_phase = TASKFILE_NO_DATA;
224 return do_rw_taskfile(drive, args);
225}
226
227/** 123/**
228 * ide_end_dequeued_request - complete an IDE I/O 124 * ide_end_dequeued_request - complete an IDE I/O
229 * @drive: IDE device for the I/O 125 * @drive: IDE device for the I/O
@@ -242,48 +138,12 @@ out_do_tf:
242int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq, 138int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
243 int uptodate, int nr_sectors) 139 int uptodate, int nr_sectors)
244{ 140{
245 unsigned long flags;
246 int ret;
247
248 spin_lock_irqsave(&ide_lock, flags);
249 BUG_ON(!blk_rq_started(rq)); 141 BUG_ON(!blk_rq_started(rq));
250 ret = __ide_end_request(drive, rq, uptodate, nr_sectors << 9, 0);
251 spin_unlock_irqrestore(&ide_lock, flags);
252 142
253 return ret; 143 return __ide_end_request(drive, rq, uptodate, nr_sectors << 9, 0);
254} 144}
255EXPORT_SYMBOL_GPL(ide_end_dequeued_request); 145EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
256 146
257
258/**
259 * ide_complete_pm_request - end the current Power Management request
260 * @drive: target drive
261 * @rq: request
262 *
263 * This function cleans up the current PM request and stops the queue
264 * if necessary.
265 */
266static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
267{
268 unsigned long flags;
269
270#ifdef DEBUG_PM
271 printk("%s: completing PM request, %s\n", drive->name,
272 blk_pm_suspend_request(rq) ? "suspend" : "resume");
273#endif
274 spin_lock_irqsave(&ide_lock, flags);
275 if (blk_pm_suspend_request(rq)) {
276 blk_stop_queue(drive->queue);
277 } else {
278 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
279 blk_start_queue(drive->queue);
280 }
281 HWGROUP(drive)->rq = NULL;
282 if (__blk_end_request(rq, 0, 0))
283 BUG();
284 spin_unlock_irqrestore(&ide_lock, flags);
285}
286
287/** 147/**
288 * ide_end_drive_cmd - end an explicit drive command 148 * ide_end_drive_cmd - end an explicit drive command
289 * @drive: command 149 * @drive: command
@@ -300,19 +160,12 @@ static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
300 160
301void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err) 161void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
302{ 162{
303 unsigned long flags; 163 ide_hwif_t *hwif = drive->hwif;
304 struct request *rq; 164 struct request *rq = hwif->rq;
305
306 spin_lock_irqsave(&ide_lock, flags);
307 rq = HWGROUP(drive)->rq;
308 spin_unlock_irqrestore(&ide_lock, flags);
309 165
310 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 166 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
311 ide_task_t *task = (ide_task_t *)rq->special; 167 ide_task_t *task = (ide_task_t *)rq->special;
312 168
313 if (rq->errors == 0)
314 rq->errors = !OK_STAT(stat, ATA_DRDY, BAD_STAT);
315
316 if (task) { 169 if (task) {
317 struct ide_taskfile *tf = &task->tf; 170 struct ide_taskfile *tf = &task->tf;
318 171
@@ -333,23 +186,22 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
333 return; 186 return;
334 } 187 }
335 188
336 spin_lock_irqsave(&ide_lock, flags); 189 hwif->rq = NULL;
337 HWGROUP(drive)->rq = NULL; 190
338 rq->errors = err; 191 rq->errors = err;
339 if (unlikely(__blk_end_request(rq, (rq->errors ? -EIO : 0), 192
340 blk_rq_bytes(rq)))) 193 if (unlikely(blk_end_request(rq, (rq->errors ? -EIO : 0),
194 blk_rq_bytes(rq))))
341 BUG(); 195 BUG();
342 spin_unlock_irqrestore(&ide_lock, flags);
343} 196}
344
345EXPORT_SYMBOL(ide_end_drive_cmd); 197EXPORT_SYMBOL(ide_end_drive_cmd);
346 198
347static void ide_kill_rq(ide_drive_t *drive, struct request *rq) 199static void ide_kill_rq(ide_drive_t *drive, struct request *rq)
348{ 200{
349 if (rq->rq_disk) { 201 if (rq->rq_disk) {
350 ide_driver_t *drv; 202 struct ide_driver *drv;
351 203
352 drv = *(ide_driver_t **)rq->rq_disk->private_data; 204 drv = *(struct ide_driver **)rq->rq_disk->private_data;
353 drv->end_request(drive, 0, 0); 205 drv->end_request(drive, 0, 0);
354 } else 206 } else
355 ide_end_request(drive, 0, 0); 207 ide_end_request(drive, 0, 0);
@@ -439,7 +291,7 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
439 return ide_stopped; 291 return ide_stopped;
440} 292}
441 293
442ide_startstop_t 294static ide_startstop_t
443__ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) 295__ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
444{ 296{
445 if (drive->media == ide_disk) 297 if (drive->media == ide_disk)
@@ -447,8 +299,6 @@ __ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
447 return ide_atapi_error(drive, rq, stat, err); 299 return ide_atapi_error(drive, rq, stat, err);
448} 300}
449 301
450EXPORT_SYMBOL_GPL(__ide_error);
451
452/** 302/**
453 * ide_error - handle an error on the IDE 303 * ide_error - handle an error on the IDE
454 * @drive: drive the error occurred on 304 * @drive: drive the error occurred on
@@ -469,7 +319,8 @@ ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
469 319
470 err = ide_dump_status(drive, msg, stat); 320 err = ide_dump_status(drive, msg, stat);
471 321
472 if ((rq = HWGROUP(drive)->rq) == NULL) 322 rq = drive->hwif->rq;
323 if (rq == NULL)
473 return ide_stopped; 324 return ide_stopped;
474 325
475 /* retry only "normal" I/O: */ 326 /* retry only "normal" I/O: */
@@ -479,15 +330,8 @@ ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
479 return ide_stopped; 330 return ide_stopped;
480 } 331 }
481 332
482 if (rq->rq_disk) { 333 return __ide_error(drive, rq, stat, err);
483 ide_driver_t *drv;
484
485 drv = *(ide_driver_t **)rq->rq_disk->private_data;
486 return drv->error(drive, rq, stat, err);
487 } else
488 return __ide_error(drive, rq, stat, err);
489} 334}
490
491EXPORT_SYMBOL_GPL(ide_error); 335EXPORT_SYMBOL_GPL(ide_error);
492 336
493static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 337static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
@@ -574,9 +418,6 @@ void ide_map_sg(ide_drive_t *drive, struct request *rq)
574 ide_hwif_t *hwif = drive->hwif; 418 ide_hwif_t *hwif = drive->hwif;
575 struct scatterlist *sg = hwif->sg_table; 419 struct scatterlist *sg = hwif->sg_table;
576 420
577 if (hwif->sg_mapped) /* needed by ide-scsi */
578 return;
579
580 if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) { 421 if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) {
581 hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg); 422 hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
582 } else { 423 } else {
@@ -613,7 +454,7 @@ EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
613static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, 454static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
614 struct request *rq) 455 struct request *rq)
615{ 456{
616 ide_hwif_t *hwif = HWIF(drive); 457 ide_hwif_t *hwif = drive->hwif;
617 ide_task_t *task = rq->special; 458 ide_task_t *task = rq->special;
618 459
619 if (task) { 460 if (task) {
@@ -720,40 +561,6 @@ static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
720 } 561 }
721} 562}
722 563
723static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
724{
725 struct request_pm_state *pm = rq->data;
726
727 if (blk_pm_suspend_request(rq) &&
728 pm->pm_step == IDE_PM_START_SUSPEND)
729 /* Mark drive blocked when starting the suspend sequence. */
730 drive->dev_flags |= IDE_DFLAG_BLOCKED;
731 else if (blk_pm_resume_request(rq) &&
732 pm->pm_step == IDE_PM_START_RESUME) {
733 /*
734 * The first thing we do on wakeup is to wait for BSY bit to
735 * go away (with a looong timeout) as a drive on this hwif may
736 * just be POSTing itself.
737 * We do that before even selecting as the "other" device on
738 * the bus may be broken enough to walk on our toes at this
739 * point.
740 */
741 ide_hwif_t *hwif = drive->hwif;
742 int rc;
743#ifdef DEBUG_PM
744 printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
745#endif
746 rc = ide_wait_not_busy(hwif, 35000);
747 if (rc)
748 printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
749 SELECT_DRIVE(drive);
750 hwif->tp_ops->set_irq(hwif, 1);
751 rc = ide_wait_not_busy(hwif, 100000);
752 if (rc)
753 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
754 }
755}
756
757/** 564/**
758 * start_request - start of I/O and command issuing for IDE 565 * start_request - start of I/O and command issuing for IDE
759 * 566 *
@@ -771,7 +578,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
771 578
772#ifdef DEBUG 579#ifdef DEBUG
773 printk("%s: start_request: current=0x%08lx\n", 580 printk("%s: start_request: current=0x%08lx\n",
774 HWIF(drive)->name, (unsigned long) rq); 581 drive->hwif->name, (unsigned long) rq);
775#endif 582#endif
776 583
777 /* bail early if we've exceeded max_failures */ 584 /* bail early if we've exceeded max_failures */
@@ -790,7 +597,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
790 return startstop; 597 return startstop;
791 } 598 }
792 if (!drive->special.all) { 599 if (!drive->special.all) {
793 ide_driver_t *drv; 600 struct ide_driver *drv;
794 601
795 /* 602 /*
796 * We reset the drive so we need to issue a SETFEATURES. 603 * We reset the drive so we need to issue a SETFEATURES.
@@ -823,7 +630,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
823 */ 630 */
824 return ide_special_rq(drive, rq); 631 return ide_special_rq(drive, rq);
825 632
826 drv = *(ide_driver_t **)rq->rq_disk->private_data; 633 drv = *(struct ide_driver **)rq->rq_disk->private_data;
827 634
828 return drv->do_request(drive, rq, rq->sector); 635 return drv->do_request(drive, rq, rq->sector);
829 } 636 }
@@ -839,7 +646,7 @@ kill_rq:
839 * @timeout: time to stall for (jiffies) 646 * @timeout: time to stall for (jiffies)
840 * 647 *
841 * ide_stall_queue() can be used by a drive to give excess bandwidth back 648 * ide_stall_queue() can be used by a drive to give excess bandwidth back
842 * to the hwgroup by sleeping for timeout jiffies. 649 * to the port by sleeping for timeout jiffies.
843 */ 650 */
844 651
845void ide_stall_queue (ide_drive_t *drive, unsigned long timeout) 652void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
@@ -849,206 +656,117 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
849 drive->sleep = timeout + jiffies; 656 drive->sleep = timeout + jiffies;
850 drive->dev_flags |= IDE_DFLAG_SLEEPING; 657 drive->dev_flags |= IDE_DFLAG_SLEEPING;
851} 658}
852
853EXPORT_SYMBOL(ide_stall_queue); 659EXPORT_SYMBOL(ide_stall_queue);
854 660
855#define WAKEUP(drive) ((drive)->service_start + 2 * (drive)->service_time) 661static inline int ide_lock_port(ide_hwif_t *hwif)
662{
663 if (hwif->busy)
664 return 1;
856 665
857/** 666 hwif->busy = 1;
858 * choose_drive - select a drive to service 667
859 * @hwgroup: hardware group to select on 668 return 0;
860 * 669}
861 * choose_drive() selects the next drive which will be serviced. 670
862 * This is necessary because the IDE layer can't issue commands 671static inline void ide_unlock_port(ide_hwif_t *hwif)
863 * to both drives on the same cable, unlike SCSI. 672{
864 */ 673 hwif->busy = 0;
865 674}
866static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup) 675
676static inline int ide_lock_host(struct ide_host *host, ide_hwif_t *hwif)
867{ 677{
868 ide_drive_t *drive, *best; 678 int rc = 0;
869 679
870repeat: 680 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
871 best = NULL; 681 rc = test_and_set_bit_lock(IDE_HOST_BUSY, &host->host_busy);
872 drive = hwgroup->drive; 682 if (rc == 0) {
683 /* for atari only */
684 ide_get_lock(ide_intr, hwif);
685 }
686 }
687 return rc;
688}
689
690static inline void ide_unlock_host(struct ide_host *host)
691{
692 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
693 /* for atari only */
694 ide_release_lock();
695 clear_bit_unlock(IDE_HOST_BUSY, &host->host_busy);
696 }
697}
698
699/*
700 * Issue a new request to a device.
701 */
702void do_ide_request(struct request_queue *q)
703{
704 ide_drive_t *drive = q->queuedata;
705 ide_hwif_t *hwif = drive->hwif;
706 struct ide_host *host = hwif->host;
707 struct request *rq = NULL;
708 ide_startstop_t startstop;
873 709
874 /* 710 /*
875 * drive is doing pre-flush, ordered write, post-flush sequence. even 711 * drive is doing pre-flush, ordered write, post-flush sequence. even
876 * though that is 3 requests, it must be seen as a single transaction. 712 * though that is 3 requests, it must be seen as a single transaction.
877 * we must not preempt this drive until that is complete 713 * we must not preempt this drive until that is complete
878 */ 714 */
879 if (blk_queue_flushing(drive->queue)) { 715 if (blk_queue_flushing(q))
880 /* 716 /*
881 * small race where queue could get replugged during 717 * small race where queue could get replugged during
882 * the 3-request flush cycle, just yank the plug since 718 * the 3-request flush cycle, just yank the plug since
883 * we want it to finish asap 719 * we want it to finish asap
884 */ 720 */
885 blk_remove_plug(drive->queue); 721 blk_remove_plug(q);
886 return drive;
887 }
888 722
889 do { 723 spin_unlock_irq(q->queue_lock);
890 u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING);
891 u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING));
892
893 if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) &&
894 !elv_queue_empty(drive->queue)) {
895 if (best == NULL ||
896 (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) ||
897 (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) {
898 if (!blk_queue_plugged(drive->queue))
899 best = drive;
900 }
901 }
902 } while ((drive = drive->next) != hwgroup->drive);
903 724
904 if (best && (best->dev_flags & IDE_DFLAG_NICE1) && 725 if (ide_lock_host(host, hwif))
905 (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 && 726 goto plug_device_2;
906 best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
907 long t = (signed long)(WAKEUP(best) - jiffies);
908 if (t >= WAIT_MIN_SLEEP) {
909 /*
910 * We *may* have some time to spare, but first let's see if
911 * someone can potentially benefit from our nice mood today..
912 */
913 drive = best->next;
914 do {
915 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0
916 && time_before(jiffies - best->service_time, WAKEUP(drive))
917 && time_before(WAKEUP(drive), jiffies + t))
918 {
919 ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP));
920 goto repeat;
921 }
922 } while ((drive = drive->next) != best);
923 }
924 }
925 return best;
926}
927 727
928/* 728 spin_lock_irq(&hwif->lock);
929 * Issue a new request to a drive from hwgroup
930 * Caller must have already done spin_lock_irqsave(&ide_lock, ..);
931 *
932 * A hwgroup is a serialized group of IDE interfaces. Usually there is
933 * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640)
934 * may have both interfaces in a single hwgroup to "serialize" access.
935 * Or possibly multiple ISA interfaces can share a common IRQ by being grouped
936 * together into one hwgroup for serialized access.
937 *
938 * Note also that several hwgroups can end up sharing a single IRQ,
939 * possibly along with many other devices. This is especially common in
940 * PCI-based systems with off-board IDE controller cards.
941 *
942 * The IDE driver uses the single global ide_lock spinlock to protect
943 * access to the request queues, and to protect the hwgroup->busy flag.
944 *
945 * The first thread into the driver for a particular hwgroup sets the
946 * hwgroup->busy flag to indicate that this hwgroup is now active,
947 * and then initiates processing of the top request from the request queue.
948 *
949 * Other threads attempting entry notice the busy setting, and will simply
950 * queue their new requests and exit immediately. Note that hwgroup->busy
951 * remains set even when the driver is merely awaiting the next interrupt.
952 * Thus, the meaning is "this hwgroup is busy processing a request".
953 *
954 * When processing of a request completes, the completing thread or IRQ-handler
955 * will start the next request from the queue. If no more work remains,
956 * the driver will clear the hwgroup->busy flag and exit.
957 *
958 * The ide_lock (spinlock) is used to protect all access to the
959 * hwgroup->busy flag, but is otherwise not needed for most processing in
960 * the driver. This makes the driver much more friendlier to shared IRQs
961 * than previous designs, while remaining 100% (?) SMP safe and capable.
962 */
963static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
964{
965 ide_drive_t *drive;
966 ide_hwif_t *hwif;
967 struct request *rq;
968 ide_startstop_t startstop;
969 int loops = 0;
970 729
971 /* caller must own ide_lock */ 730 if (!ide_lock_port(hwif)) {
972 BUG_ON(!irqs_disabled()); 731 ide_hwif_t *prev_port;
732repeat:
733 prev_port = hwif->host->cur_port;
734 hwif->rq = NULL;
973 735
974 while (!hwgroup->busy) { 736 if (drive->dev_flags & IDE_DFLAG_SLEEPING) {
975 hwgroup->busy = 1; 737 if (time_before(drive->sleep, jiffies)) {
976 /* for atari only */ 738 ide_unlock_port(hwif);
977 ide_get_lock(ide_intr, hwgroup); 739 goto plug_device;
978 drive = choose_drive(hwgroup);
979 if (drive == NULL) {
980 int sleeping = 0;
981 unsigned long sleep = 0; /* shut up, gcc */
982 hwgroup->rq = NULL;
983 drive = hwgroup->drive;
984 do {
985 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) &&
986 (sleeping == 0 ||
987 time_before(drive->sleep, sleep))) {
988 sleeping = 1;
989 sleep = drive->sleep;
990 }
991 } while ((drive = drive->next) != hwgroup->drive);
992 if (sleeping) {
993 /*
994 * Take a short snooze, and then wake up this hwgroup again.
995 * This gives other hwgroups on the same a chance to
996 * play fairly with us, just in case there are big differences
997 * in relative throughputs.. don't want to hog the cpu too much.
998 */
999 if (time_before(sleep, jiffies + WAIT_MIN_SLEEP))
1000 sleep = jiffies + WAIT_MIN_SLEEP;
1001#if 1
1002 if (timer_pending(&hwgroup->timer))
1003 printk(KERN_CRIT "ide_set_handler: timer already active\n");
1004#endif
1005 /* so that ide_timer_expiry knows what to do */
1006 hwgroup->sleeping = 1;
1007 hwgroup->req_gen_timer = hwgroup->req_gen;
1008 mod_timer(&hwgroup->timer, sleep);
1009 /* we purposely leave hwgroup->busy==1
1010 * while sleeping */
1011 } else {
1012 /* Ugly, but how can we sleep for the lock
1013 * otherwise? perhaps from tq_disk?
1014 */
1015
1016 /* for atari only */
1017 ide_release_lock();
1018 hwgroup->busy = 0;
1019 } 740 }
1020
1021 /* no more work for this hwgroup (for now) */
1022 return;
1023 } 741 }
1024 again: 742
1025 hwif = HWIF(drive); 743 if ((hwif->host->host_flags & IDE_HFLAG_SERIALIZE) &&
1026 if (hwgroup->hwif->sharing_irq && hwif != hwgroup->hwif) { 744 hwif != prev_port) {
1027 /* 745 /*
1028 * set nIEN for previous hwif, drives in the 746 * set nIEN for previous port, drives in the
1029 * quirk_list may not like intr setups/cleanups 747 * quirk_list may not like intr setups/cleanups
1030 */ 748 */
1031 if (drive->quirk_list != 1) 749 if (prev_port && prev_port->cur_dev->quirk_list == 0)
1032 hwif->tp_ops->set_irq(hwif, 0); 750 prev_port->tp_ops->set_irq(prev_port, 0);
1033 }
1034 hwgroup->hwif = hwif;
1035 hwgroup->drive = drive;
1036 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
1037 drive->service_start = jiffies;
1038 751
1039 if (blk_queue_plugged(drive->queue)) { 752 hwif->host->cur_port = hwif;
1040 printk(KERN_ERR "ide: huh? queue was plugged!\n");
1041 break;
1042 } 753 }
754 hwif->cur_dev = drive;
755 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
1043 756
757 spin_unlock_irq(&hwif->lock);
758 spin_lock_irq(q->queue_lock);
1044 /* 759 /*
1045 * we know that the queue isn't empty, but this can happen 760 * we know that the queue isn't empty, but this can happen
1046 * if the q->prep_rq_fn() decides to kill a request 761 * if the q->prep_rq_fn() decides to kill a request
1047 */ 762 */
1048 rq = elv_next_request(drive->queue); 763 rq = elv_next_request(drive->queue);
764 spin_unlock_irq(q->queue_lock);
765 spin_lock_irq(&hwif->lock);
766
1049 if (!rq) { 767 if (!rq) {
1050 hwgroup->busy = 0; 768 ide_unlock_port(hwif);
1051 break; 769 goto out;
1052 } 770 }
1053 771
1054 /* 772 /*
@@ -1063,63 +781,50 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1063 * though. I hope that doesn't happen too much, hopefully not 781 * though. I hope that doesn't happen too much, hopefully not
1064 * unless the subdriver triggers such a thing in its own PM 782 * unless the subdriver triggers such a thing in its own PM
1065 * state machine. 783 * state machine.
1066 *
1067 * We count how many times we loop here to make sure we service
1068 * all drives in the hwgroup without looping for ever
1069 */ 784 */
1070 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && 785 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
1071 blk_pm_request(rq) == 0 && 786 blk_pm_request(rq) == 0 &&
1072 (rq->cmd_flags & REQ_PREEMPT) == 0) { 787 (rq->cmd_flags & REQ_PREEMPT) == 0) {
1073 drive = drive->next ? drive->next : hwgroup->drive; 788 /* there should be no pending command at this point */
1074 if (loops++ < 4 && !blk_queue_plugged(drive->queue)) 789 ide_unlock_port(hwif);
1075 goto again; 790 goto plug_device;
1076 /* We clear busy, there should be no pending ATA command at this point. */
1077 hwgroup->busy = 0;
1078 break;
1079 } 791 }
1080 792
1081 hwgroup->rq = rq; 793 hwif->rq = rq;
1082 794
1083 /* 795 spin_unlock_irq(&hwif->lock);
1084 * Some systems have trouble with IDE IRQs arriving while
1085 * the driver is still setting things up. So, here we disable
1086 * the IRQ used by this interface while the request is being started.
1087 * This may look bad at first, but pretty much the same thing
1088 * happens anyway when any interrupt comes in, IDE or otherwise
1089 * -- the kernel masks the IRQ while it is being handled.
1090 */
1091 if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
1092 disable_irq_nosync(hwif->irq);
1093 spin_unlock(&ide_lock);
1094 local_irq_enable_in_hardirq();
1095 /* allow other IRQs while we start this request */
1096 startstop = start_request(drive, rq); 796 startstop = start_request(drive, rq);
1097 spin_lock_irq(&ide_lock); 797 spin_lock_irq(&hwif->lock);
1098 if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
1099 enable_irq(hwif->irq);
1100 if (startstop == ide_stopped)
1101 hwgroup->busy = 0;
1102 }
1103}
1104 798
1105/* 799 if (startstop == ide_stopped)
1106 * Passes the stuff to ide_do_request 800 goto repeat;
1107 */ 801 } else
1108void do_ide_request(struct request_queue *q) 802 goto plug_device;
1109{ 803out:
1110 ide_drive_t *drive = q->queuedata; 804 spin_unlock_irq(&hwif->lock);
1111 805 if (rq == NULL)
1112 ide_do_request(HWGROUP(drive), IDE_NO_IRQ); 806 ide_unlock_host(host);
807 spin_lock_irq(q->queue_lock);
808 return;
809
810plug_device:
811 spin_unlock_irq(&hwif->lock);
812 ide_unlock_host(host);
813plug_device_2:
814 spin_lock_irq(q->queue_lock);
815
816 if (!elv_queue_empty(q))
817 blk_plug_device(q);
1113} 818}
1114 819
1115/* 820/*
1116 * un-busy the hwgroup etc, and clear any pending DMA status. we want to 821 * un-busy the port etc, and clear any pending DMA status. we want to
1117 * retry the current request in pio mode instead of risking tossing it 822 * retry the current request in pio mode instead of risking tossing it
1118 * all away 823 * all away
1119 */ 824 */
1120static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) 825static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1121{ 826{
1122 ide_hwif_t *hwif = HWIF(drive); 827 ide_hwif_t *hwif = drive->hwif;
1123 struct request *rq; 828 struct request *rq;
1124 ide_startstop_t ret = ide_stopped; 829 ide_startstop_t ret = ide_stopped;
1125 830
@@ -1147,15 +852,14 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1147 ide_dma_off_quietly(drive); 852 ide_dma_off_quietly(drive);
1148 853
1149 /* 854 /*
1150 * un-busy drive etc (hwgroup->busy is cleared on return) and 855 * un-busy drive etc and make sure request is sane
1151 * make sure request is sane
1152 */ 856 */
1153 rq = HWGROUP(drive)->rq;
1154 857
858 rq = hwif->rq;
1155 if (!rq) 859 if (!rq)
1156 goto out; 860 goto out;
1157 861
1158 HWGROUP(drive)->rq = NULL; 862 hwif->rq = NULL;
1159 863
1160 rq->errors = 0; 864 rq->errors = 0;
1161 865
@@ -1170,9 +874,20 @@ out:
1170 return ret; 874 return ret;
1171} 875}
1172 876
877static void ide_plug_device(ide_drive_t *drive)
878{
879 struct request_queue *q = drive->queue;
880 unsigned long flags;
881
882 spin_lock_irqsave(q->queue_lock, flags);
883 if (!elv_queue_empty(q))
884 blk_plug_device(q);
885 spin_unlock_irqrestore(q->queue_lock, flags);
886}
887
1173/** 888/**
1174 * ide_timer_expiry - handle lack of an IDE interrupt 889 * ide_timer_expiry - handle lack of an IDE interrupt
1175 * @data: timer callback magic (hwgroup) 890 * @data: timer callback magic (hwif)
1176 * 891 *
1177 * An IDE command has timed out before the expected drive return 892 * An IDE command has timed out before the expected drive return
1178 * occurred. At this point we attempt to clean up the current 893 * occurred. At this point we attempt to clean up the current
@@ -1186,93 +901,87 @@ out:
1186 901
1187void ide_timer_expiry (unsigned long data) 902void ide_timer_expiry (unsigned long data)
1188{ 903{
1189 ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data; 904 ide_hwif_t *hwif = (ide_hwif_t *)data;
905 ide_drive_t *uninitialized_var(drive);
1190 ide_handler_t *handler; 906 ide_handler_t *handler;
1191 ide_expiry_t *expiry;
1192 unsigned long flags; 907 unsigned long flags;
1193 unsigned long wait = -1; 908 unsigned long wait = -1;
909 int plug_device = 0;
1194 910
1195 spin_lock_irqsave(&ide_lock, flags); 911 spin_lock_irqsave(&hwif->lock, flags);
1196 912
1197 if (((handler = hwgroup->handler) == NULL) || 913 handler = hwif->handler;
1198 (hwgroup->req_gen != hwgroup->req_gen_timer)) { 914
915 if (handler == NULL || hwif->req_gen != hwif->req_gen_timer) {
1199 /* 916 /*
1200 * Either a marginal timeout occurred 917 * Either a marginal timeout occurred
1201 * (got the interrupt just as timer expired), 918 * (got the interrupt just as timer expired),
1202 * or we were "sleeping" to give other devices a chance. 919 * or we were "sleeping" to give other devices a chance.
1203 * Either way, we don't really want to complain about anything. 920 * Either way, we don't really want to complain about anything.
1204 */ 921 */
1205 if (hwgroup->sleeping) {
1206 hwgroup->sleeping = 0;
1207 hwgroup->busy = 0;
1208 }
1209 } else { 922 } else {
1210 ide_drive_t *drive = hwgroup->drive; 923 ide_expiry_t *expiry = hwif->expiry;
1211 if (!drive) { 924 ide_startstop_t startstop = ide_stopped;
1212 printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n"); 925
1213 hwgroup->handler = NULL; 926 drive = hwif->cur_dev;
1214 } else { 927
1215 ide_hwif_t *hwif; 928 if (expiry) {
1216 ide_startstop_t startstop = ide_stopped; 929 wait = expiry(drive);
1217 if (!hwgroup->busy) { 930 if (wait > 0) { /* continue */
1218 hwgroup->busy = 1; /* paranoia */ 931 /* reset timer */
1219 printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name); 932 hwif->timer.expires = jiffies + wait;
1220 } 933 hwif->req_gen_timer = hwif->req_gen;
1221 if ((expiry = hwgroup->expiry) != NULL) { 934 add_timer(&hwif->timer);
1222 /* continue */ 935 spin_unlock_irqrestore(&hwif->lock, flags);
1223 if ((wait = expiry(drive)) > 0) { 936 return;
1224 /* reset timer */
1225 hwgroup->timer.expires = jiffies + wait;
1226 hwgroup->req_gen_timer = hwgroup->req_gen;
1227 add_timer(&hwgroup->timer);
1228 spin_unlock_irqrestore(&ide_lock, flags);
1229 return;
1230 }
1231 } 937 }
1232 hwgroup->handler = NULL;
1233 /*
1234 * We need to simulate a real interrupt when invoking
1235 * the handler() function, which means we need to
1236 * globally mask the specific IRQ:
1237 */
1238 spin_unlock(&ide_lock);
1239 hwif = HWIF(drive);
1240 /* disable_irq_nosync ?? */
1241 disable_irq(hwif->irq);
1242 /* local CPU only,
1243 * as if we were handling an interrupt */
1244 local_irq_disable();
1245 if (hwgroup->polling) {
1246 startstop = handler(drive);
1247 } else if (drive_is_ready(drive)) {
1248 if (drive->waiting_for_dma)
1249 hwif->dma_ops->dma_lost_irq(drive);
1250 (void)ide_ack_intr(hwif);
1251 printk(KERN_WARNING "%s: lost interrupt\n", drive->name);
1252 startstop = handler(drive);
1253 } else {
1254 if (drive->waiting_for_dma) {
1255 startstop = ide_dma_timeout_retry(drive, wait);
1256 } else
1257 startstop =
1258 ide_error(drive, "irq timeout",
1259 hwif->tp_ops->read_status(hwif));
1260 }
1261 drive->service_time = jiffies - drive->service_start;
1262 spin_lock_irq(&ide_lock);
1263 enable_irq(hwif->irq);
1264 if (startstop == ide_stopped)
1265 hwgroup->busy = 0;
1266 } 938 }
939 hwif->handler = NULL;
940 /*
941 * We need to simulate a real interrupt when invoking
942 * the handler() function, which means we need to
943 * globally mask the specific IRQ:
944 */
945 spin_unlock(&hwif->lock);
946 /* disable_irq_nosync ?? */
947 disable_irq(hwif->irq);
948 /* local CPU only, as if we were handling an interrupt */
949 local_irq_disable();
950 if (hwif->polling) {
951 startstop = handler(drive);
952 } else if (drive_is_ready(drive)) {
953 if (drive->waiting_for_dma)
954 hwif->dma_ops->dma_lost_irq(drive);
955 (void)ide_ack_intr(hwif);
956 printk(KERN_WARNING "%s: lost interrupt\n",
957 drive->name);
958 startstop = handler(drive);
959 } else {
960 if (drive->waiting_for_dma)
961 startstop = ide_dma_timeout_retry(drive, wait);
962 else
963 startstop = ide_error(drive, "irq timeout",
964 hwif->tp_ops->read_status(hwif));
965 }
966 spin_lock_irq(&hwif->lock);
967 enable_irq(hwif->irq);
968 if (startstop == ide_stopped) {
969 ide_unlock_port(hwif);
970 plug_device = 1;
971 }
972 }
973 spin_unlock_irqrestore(&hwif->lock, flags);
974
975 if (plug_device) {
976 ide_unlock_host(hwif->host);
977 ide_plug_device(drive);
1267 } 978 }
1268 ide_do_request(hwgroup, IDE_NO_IRQ);
1269 spin_unlock_irqrestore(&ide_lock, flags);
1270} 979}
1271 980
1272/** 981/**
1273 * unexpected_intr - handle an unexpected IDE interrupt 982 * unexpected_intr - handle an unexpected IDE interrupt
1274 * @irq: interrupt line 983 * @irq: interrupt line
1275 * @hwgroup: hwgroup being processed 984 * @hwif: port being processed
1276 * 985 *
1277 * There's nothing really useful we can do with an unexpected interrupt, 986 * There's nothing really useful we can do with an unexpected interrupt,
1278 * other than reading the status register (to clear it), and logging it. 987 * other than reading the status register (to clear it), and logging it.
@@ -1296,52 +1005,38 @@ void ide_timer_expiry (unsigned long data)
1296 * before completing the issuance of any new drive command, so we will not 1005 * before completing the issuance of any new drive command, so we will not
1297 * be accidentally invoked as a result of any valid command completion 1006 * be accidentally invoked as a result of any valid command completion
1298 * interrupt. 1007 * interrupt.
1299 *
1300 * Note that we must walk the entire hwgroup here. We know which hwif
1301 * is doing the current command, but we don't know which hwif burped
1302 * mysteriously.
1303 */ 1008 */
1304
1305static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
1306{
1307 u8 stat;
1308 ide_hwif_t *hwif = hwgroup->hwif;
1309 1009
1310 /* 1010static void unexpected_intr(int irq, ide_hwif_t *hwif)
1311 * handle the unexpected interrupt 1011{
1312 */ 1012 u8 stat = hwif->tp_ops->read_status(hwif);
1313 do { 1013
1314 if (hwif->irq == irq) { 1014 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
1315 stat = hwif->tp_ops->read_status(hwif); 1015 /* Try to not flood the console with msgs */
1316 1016 static unsigned long last_msgtime, count;
1317 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) { 1017 ++count;
1318 /* Try to not flood the console with msgs */ 1018
1319 static unsigned long last_msgtime, count; 1019 if (time_after(jiffies, last_msgtime + HZ)) {
1320 ++count; 1020 last_msgtime = jiffies;
1321 if (time_after(jiffies, last_msgtime + HZ)) { 1021 printk(KERN_ERR "%s: unexpected interrupt, "
1322 last_msgtime = jiffies; 1022 "status=0x%02x, count=%ld\n",
1323 printk(KERN_ERR "%s%s: unexpected interrupt, " 1023 hwif->name, stat, count);
1324 "status=0x%02x, count=%ld\n",
1325 hwif->name,
1326 (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count);
1327 }
1328 }
1329 } 1024 }
1330 } while ((hwif = hwif->next) != hwgroup->hwif); 1025 }
1331} 1026}
1332 1027
1333/** 1028/**
1334 * ide_intr - default IDE interrupt handler 1029 * ide_intr - default IDE interrupt handler
1335 * @irq: interrupt number 1030 * @irq: interrupt number
1336 * @dev_id: hwif group 1031 * @dev_id: hwif
1337 * @regs: unused weirdness from the kernel irq layer 1032 * @regs: unused weirdness from the kernel irq layer
1338 * 1033 *
1339 * This is the default IRQ handler for the IDE layer. You should 1034 * This is the default IRQ handler for the IDE layer. You should
1340 * not need to override it. If you do be aware it is subtle in 1035 * not need to override it. If you do be aware it is subtle in
1341 * places 1036 * places
1342 * 1037 *
1343 * hwgroup->hwif is the interface in the group currently performing 1038 * hwif is the interface in the group currently performing
1344 * a command. hwgroup->drive is the drive and hwgroup->handler is 1039 * a command. hwif->cur_dev is the drive and hwif->handler is
1345 * the IRQ handler to call. As we issue a command the handlers 1040 * the IRQ handler to call. As we issue a command the handlers
1346 * step through multiple states, reassigning the handler to the 1041 * step through multiple states, reassigning the handler to the
1347 * next step in the process. Unlike a smart SCSI controller IDE 1042 * next step in the process. Unlike a smart SCSI controller IDE
@@ -1352,27 +1047,32 @@ static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
1352 * 1047 *
1353 * The handler eventually returns ide_stopped to indicate the 1048 * The handler eventually returns ide_stopped to indicate the
1354 * request completed. At this point we issue the next request 1049 * request completed. At this point we issue the next request
1355 * on the hwgroup and the process begins again. 1050 * on the port and the process begins again.
1356 */ 1051 */
1357 1052
1358irqreturn_t ide_intr (int irq, void *dev_id) 1053irqreturn_t ide_intr (int irq, void *dev_id)
1359{ 1054{
1360 unsigned long flags; 1055 ide_hwif_t *hwif = (ide_hwif_t *)dev_id;
1361 ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id; 1056 ide_drive_t *uninitialized_var(drive);
1362 ide_hwif_t *hwif;
1363 ide_drive_t *drive;
1364 ide_handler_t *handler; 1057 ide_handler_t *handler;
1058 unsigned long flags;
1365 ide_startstop_t startstop; 1059 ide_startstop_t startstop;
1060 irqreturn_t irq_ret = IRQ_NONE;
1061 int plug_device = 0;
1366 1062
1367 spin_lock_irqsave(&ide_lock, flags); 1063 if (hwif->host->host_flags & IDE_HFLAG_SERIALIZE) {
1368 hwif = hwgroup->hwif; 1064 if (hwif != hwif->host->cur_port)
1369 1065 goto out_early;
1370 if (!ide_ack_intr(hwif)) {
1371 spin_unlock_irqrestore(&ide_lock, flags);
1372 return IRQ_NONE;
1373 } 1066 }
1374 1067
1375 if ((handler = hwgroup->handler) == NULL || hwgroup->polling) { 1068 spin_lock_irqsave(&hwif->lock, flags);
1069
1070 if (!ide_ack_intr(hwif))
1071 goto out;
1072
1073 handler = hwif->handler;
1074
1075 if (handler == NULL || hwif->polling) {
1376 /* 1076 /*
1377 * Not expecting an interrupt from this drive. 1077 * Not expecting an interrupt from this drive.
1378 * That means this could be: 1078 * That means this could be:
@@ -1396,7 +1096,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1396 * Probably not a shared PCI interrupt, 1096 * Probably not a shared PCI interrupt,
1397 * so we can safely try to do something about it: 1097 * so we can safely try to do something about it:
1398 */ 1098 */
1399 unexpected_intr(irq, hwgroup); 1099 unexpected_intr(irq, hwif);
1400#ifdef CONFIG_BLK_DEV_IDEPCI 1100#ifdef CONFIG_BLK_DEV_IDEPCI
1401 } else { 1101 } else {
1402 /* 1102 /*
@@ -1406,21 +1106,12 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1406 (void)hwif->tp_ops->read_status(hwif); 1106 (void)hwif->tp_ops->read_status(hwif);
1407#endif /* CONFIG_BLK_DEV_IDEPCI */ 1107#endif /* CONFIG_BLK_DEV_IDEPCI */
1408 } 1108 }
1409 spin_unlock_irqrestore(&ide_lock, flags); 1109 goto out;
1410 return IRQ_NONE;
1411 }
1412 drive = hwgroup->drive;
1413 if (!drive) {
1414 /*
1415 * This should NEVER happen, and there isn't much
1416 * we could do about it here.
1417 *
1418 * [Note - this can occur if the drive is hot unplugged]
1419 */
1420 spin_unlock_irqrestore(&ide_lock, flags);
1421 return IRQ_HANDLED;
1422 } 1110 }
1423 if (!drive_is_ready(drive)) { 1111
1112 drive = hwif->cur_dev;
1113
1114 if (!drive_is_ready(drive))
1424 /* 1115 /*
1425 * This happens regularly when we share a PCI IRQ with 1116 * This happens regularly when we share a PCI IRQ with
1426 * another device. Unfortunately, it can also happen 1117 * another device. Unfortunately, it can also happen
@@ -1428,17 +1119,12 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1428 * their status register is up to date. Hopefully we have 1119 * their status register is up to date. Hopefully we have
1429 * enough advance overhead that the latter isn't a problem. 1120 * enough advance overhead that the latter isn't a problem.
1430 */ 1121 */
1431 spin_unlock_irqrestore(&ide_lock, flags); 1122 goto out;
1432 return IRQ_NONE; 1123
1433 } 1124 hwif->handler = NULL;
1434 if (!hwgroup->busy) { 1125 hwif->req_gen++;
1435 hwgroup->busy = 1; /* paranoia */ 1126 del_timer(&hwif->timer);
1436 printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name); 1127 spin_unlock(&hwif->lock);
1437 }
1438 hwgroup->handler = NULL;
1439 hwgroup->req_gen++;
1440 del_timer(&hwgroup->timer);
1441 spin_unlock(&ide_lock);
1442 1128
1443 if (hwif->port_ops && hwif->port_ops->clear_irq) 1129 if (hwif->port_ops && hwif->port_ops->clear_irq)
1444 hwif->port_ops->clear_irq(drive); 1130 hwif->port_ops->clear_irq(drive);
@@ -1449,7 +1135,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1449 /* service this interrupt, may set handler for next interrupt */ 1135 /* service this interrupt, may set handler for next interrupt */
1450 startstop = handler(drive); 1136 startstop = handler(drive);
1451 1137
1452 spin_lock_irq(&ide_lock); 1138 spin_lock_irq(&hwif->lock);
1453 /* 1139 /*
1454 * Note that handler() may have set things up for another 1140 * Note that handler() may have set things up for another
1455 * interrupt to occur soon, but it cannot happen until 1141 * interrupt to occur soon, but it cannot happen until
@@ -1457,18 +1143,21 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1457 * same irq as is currently being serviced here, and Linux 1143 * same irq as is currently being serviced here, and Linux
1458 * won't allow another of the same (on any CPU) until we return. 1144 * won't allow another of the same (on any CPU) until we return.
1459 */ 1145 */
1460 drive->service_time = jiffies - drive->service_start;
1461 if (startstop == ide_stopped) { 1146 if (startstop == ide_stopped) {
1462 if (hwgroup->handler == NULL) { /* paranoia */ 1147 BUG_ON(hwif->handler);
1463 hwgroup->busy = 0; 1148 ide_unlock_port(hwif);
1464 ide_do_request(hwgroup, hwif->irq); 1149 plug_device = 1;
1465 } else {
1466 printk(KERN_ERR "%s: ide_intr: huh? expected NULL handler "
1467 "on exit\n", drive->name);
1468 }
1469 } 1150 }
1470 spin_unlock_irqrestore(&ide_lock, flags); 1151 irq_ret = IRQ_HANDLED;
1471 return IRQ_HANDLED; 1152out:
1153 spin_unlock_irqrestore(&hwif->lock, flags);
1154out_early:
1155 if (plug_device) {
1156 ide_unlock_host(hwif->host);
1157 ide_plug_device(drive);
1158 }
1159
1160 return irq_ret;
1472} 1161}
1473 1162
1474/** 1163/**
@@ -1488,16 +1177,15 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1488 1177
1489void ide_do_drive_cmd(ide_drive_t *drive, struct request *rq) 1178void ide_do_drive_cmd(ide_drive_t *drive, struct request *rq)
1490{ 1179{
1180 struct request_queue *q = drive->queue;
1491 unsigned long flags; 1181 unsigned long flags;
1492 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1493 1182
1494 spin_lock_irqsave(&ide_lock, flags); 1183 drive->hwif->rq = NULL;
1495 hwgroup->rq = NULL;
1496 __elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
1497 blk_start_queueing(drive->queue);
1498 spin_unlock_irqrestore(&ide_lock, flags);
1499}
1500 1184
1185 spin_lock_irqsave(q->queue_lock, flags);
1186 __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 0);
1187 spin_unlock_irqrestore(q->queue_lock, flags);
1188}
1501EXPORT_SYMBOL(ide_do_drive_cmd); 1189EXPORT_SYMBOL(ide_do_drive_cmd);
1502 1190
1503void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount, u8 dma) 1191void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount, u8 dma)
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index fcde16bb53a7..1be263eb9c07 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -19,7 +19,6 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,
19 const struct ide_ioctl_devset *s) 19 const struct ide_ioctl_devset *s)
20{ 20{
21 const struct ide_devset *ds; 21 const struct ide_devset *ds;
22 unsigned long flags;
23 int err = -EOPNOTSUPP; 22 int err = -EOPNOTSUPP;
24 23
25 for (; (ds = s->setting); s++) { 24 for (; (ds = s->setting); s++) {
@@ -33,9 +32,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,
33 32
34read_val: 33read_val:
35 mutex_lock(&ide_setting_mtx); 34 mutex_lock(&ide_setting_mtx);
36 spin_lock_irqsave(&ide_lock, flags);
37 err = ds->get(drive); 35 err = ds->get(drive);
38 spin_unlock_irqrestore(&ide_lock, flags);
39 mutex_unlock(&ide_setting_mtx); 36 mutex_unlock(&ide_setting_mtx);
40 return err >= 0 ? put_user(err, (long __user *)arg) : err; 37 return err >= 0 ? put_user(err, (long __user *)arg) : err;
41 38
@@ -98,8 +95,7 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
98 return -EPERM; 95 return -EPERM;
99 96
100 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) && 97 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
101 (drive->media == ide_disk || drive->media == ide_floppy || 98 (drive->media != ide_tape))
102 (drive->dev_flags & IDE_DFLAG_SCSI)))
103 return -EPERM; 99 return -EPERM;
104 100
105 if ((arg >> IDE_NICE_DSC_OVERLAP) & 1) 101 if ((arg >> IDE_NICE_DSC_OVERLAP) & 1)
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index c41c3b9b6f02..e728cfe7273f 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -105,15 +105,6 @@ u8 ide_read_altstatus(ide_hwif_t *hwif)
105} 105}
106EXPORT_SYMBOL_GPL(ide_read_altstatus); 106EXPORT_SYMBOL_GPL(ide_read_altstatus);
107 107
108u8 ide_read_sff_dma_status(ide_hwif_t *hwif)
109{
110 if (hwif->host_flags & IDE_HFLAG_MMIO)
111 return readb((void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
112 else
113 return inb(hwif->dma_base + ATA_DMA_STATUS);
114}
115EXPORT_SYMBOL_GPL(ide_read_sff_dma_status);
116
117void ide_set_irq(ide_hwif_t *hwif, int on) 108void ide_set_irq(ide_hwif_t *hwif, int on)
118{ 109{
119 u8 ctl = ATA_DEVCTL_OBS; 110 u8 ctl = ATA_DEVCTL_OBS;
@@ -388,7 +379,6 @@ const struct ide_tp_ops default_tp_ops = {
388 .exec_command = ide_exec_command, 379 .exec_command = ide_exec_command,
389 .read_status = ide_read_status, 380 .read_status = ide_read_status,
390 .read_altstatus = ide_read_altstatus, 381 .read_altstatus = ide_read_altstatus,
391 .read_sff_dma_status = ide_read_sff_dma_status,
392 382
393 .set_irq = ide_set_irq, 383 .set_irq = ide_set_irq,
394 384
@@ -451,7 +441,7 @@ EXPORT_SYMBOL(ide_fixstring);
451 */ 441 */
452int drive_is_ready (ide_drive_t *drive) 442int drive_is_ready (ide_drive_t *drive)
453{ 443{
454 ide_hwif_t *hwif = HWIF(drive); 444 ide_hwif_t *hwif = drive->hwif;
455 u8 stat = 0; 445 u8 stat = 0;
456 446
457 if (drive->waiting_for_dma) 447 if (drive->waiting_for_dma)
@@ -503,7 +493,8 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti
503 stat = tp_ops->read_status(hwif); 493 stat = tp_ops->read_status(hwif);
504 494
505 if (stat & ATA_BUSY) { 495 if (stat & ATA_BUSY) {
506 local_irq_set(flags); 496 local_irq_save(flags);
497 local_irq_enable_in_hardirq();
507 timeout += jiffies; 498 timeout += jiffies;
508 while ((stat = tp_ops->read_status(hwif)) & ATA_BUSY) { 499 while ((stat = tp_ops->read_status(hwif)) & ATA_BUSY) {
509 if (time_after(jiffies, timeout)) { 500 if (time_after(jiffies, timeout)) {
@@ -822,23 +813,25 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
822static void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, 813static void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
823 unsigned int timeout, ide_expiry_t *expiry) 814 unsigned int timeout, ide_expiry_t *expiry)
824{ 815{
825 ide_hwgroup_t *hwgroup = HWGROUP(drive); 816 ide_hwif_t *hwif = drive->hwif;
826 817
827 BUG_ON(hwgroup->handler); 818 BUG_ON(hwif->handler);
828 hwgroup->handler = handler; 819 hwif->handler = handler;
829 hwgroup->expiry = expiry; 820 hwif->expiry = expiry;
830 hwgroup->timer.expires = jiffies + timeout; 821 hwif->timer.expires = jiffies + timeout;
831 hwgroup->req_gen_timer = hwgroup->req_gen; 822 hwif->req_gen_timer = hwif->req_gen;
832 add_timer(&hwgroup->timer); 823 add_timer(&hwif->timer);
833} 824}
834 825
835void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, 826void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
836 unsigned int timeout, ide_expiry_t *expiry) 827 unsigned int timeout, ide_expiry_t *expiry)
837{ 828{
829 ide_hwif_t *hwif = drive->hwif;
838 unsigned long flags; 830 unsigned long flags;
839 spin_lock_irqsave(&ide_lock, flags); 831
832 spin_lock_irqsave(&hwif->lock, flags);
840 __ide_set_handler(drive, handler, timeout, expiry); 833 __ide_set_handler(drive, handler, timeout, expiry);
841 spin_unlock_irqrestore(&ide_lock, flags); 834 spin_unlock_irqrestore(&hwif->lock, flags);
842} 835}
843 836
844EXPORT_SYMBOL(ide_set_handler); 837EXPORT_SYMBOL(ide_set_handler);
@@ -860,10 +853,10 @@ EXPORT_SYMBOL(ide_set_handler);
860void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler, 853void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler,
861 unsigned timeout, ide_expiry_t *expiry) 854 unsigned timeout, ide_expiry_t *expiry)
862{ 855{
856 ide_hwif_t *hwif = drive->hwif;
863 unsigned long flags; 857 unsigned long flags;
864 ide_hwif_t *hwif = HWIF(drive);
865 858
866 spin_lock_irqsave(&ide_lock, flags); 859 spin_lock_irqsave(&hwif->lock, flags);
867 __ide_set_handler(drive, handler, timeout, expiry); 860 __ide_set_handler(drive, handler, timeout, expiry);
868 hwif->tp_ops->exec_command(hwif, cmd); 861 hwif->tp_ops->exec_command(hwif, cmd);
869 /* 862 /*
@@ -873,7 +866,7 @@ void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler,
873 * FIXME: we could skip this delay with care on non shared devices 866 * FIXME: we could skip this delay with care on non shared devices
874 */ 867 */
875 ndelay(400); 868 ndelay(400);
876 spin_unlock_irqrestore(&ide_lock, flags); 869 spin_unlock_irqrestore(&hwif->lock, flags);
877} 870}
878EXPORT_SYMBOL(ide_execute_command); 871EXPORT_SYMBOL(ide_execute_command);
879 872
@@ -882,16 +875,16 @@ void ide_execute_pkt_cmd(ide_drive_t *drive)
882 ide_hwif_t *hwif = drive->hwif; 875 ide_hwif_t *hwif = drive->hwif;
883 unsigned long flags; 876 unsigned long flags;
884 877
885 spin_lock_irqsave(&ide_lock, flags); 878 spin_lock_irqsave(&hwif->lock, flags);
886 hwif->tp_ops->exec_command(hwif, ATA_CMD_PACKET); 879 hwif->tp_ops->exec_command(hwif, ATA_CMD_PACKET);
887 ndelay(400); 880 ndelay(400);
888 spin_unlock_irqrestore(&ide_lock, flags); 881 spin_unlock_irqrestore(&hwif->lock, flags);
889} 882}
890EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd); 883EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd);
891 884
892static inline void ide_complete_drive_reset(ide_drive_t *drive, int err) 885static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
893{ 886{
894 struct request *rq = drive->hwif->hwgroup->rq; 887 struct request *rq = drive->hwif->rq;
895 888
896 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) 889 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET)
897 ide_end_request(drive, err ? err : 1, 0); 890 ide_end_request(drive, err ? err : 1, 0);
@@ -909,7 +902,6 @@ static ide_startstop_t do_reset1 (ide_drive_t *, int);
909static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive) 902static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
910{ 903{
911 ide_hwif_t *hwif = drive->hwif; 904 ide_hwif_t *hwif = drive->hwif;
912 ide_hwgroup_t *hwgroup = hwif->hwgroup;
913 u8 stat; 905 u8 stat;
914 906
915 SELECT_DRIVE(drive); 907 SELECT_DRIVE(drive);
@@ -919,20 +911,20 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
919 if (OK_STAT(stat, 0, ATA_BUSY)) 911 if (OK_STAT(stat, 0, ATA_BUSY))
920 printk("%s: ATAPI reset complete\n", drive->name); 912 printk("%s: ATAPI reset complete\n", drive->name);
921 else { 913 else {
922 if (time_before(jiffies, hwgroup->poll_timeout)) { 914 if (time_before(jiffies, hwif->poll_timeout)) {
923 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); 915 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
924 /* continue polling */ 916 /* continue polling */
925 return ide_started; 917 return ide_started;
926 } 918 }
927 /* end of polling */ 919 /* end of polling */
928 hwgroup->polling = 0; 920 hwif->polling = 0;
929 printk("%s: ATAPI reset timed-out, status=0x%02x\n", 921 printk("%s: ATAPI reset timed-out, status=0x%02x\n",
930 drive->name, stat); 922 drive->name, stat);
931 /* do it the old fashioned way */ 923 /* do it the old fashioned way */
932 return do_reset1(drive, 1); 924 return do_reset1(drive, 1);
933 } 925 }
934 /* done polling */ 926 /* done polling */
935 hwgroup->polling = 0; 927 hwif->polling = 0;
936 ide_complete_drive_reset(drive, 0); 928 ide_complete_drive_reset(drive, 0);
937 return ide_stopped; 929 return ide_stopped;
938} 930}
@@ -964,8 +956,7 @@ static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
964 */ 956 */
965static ide_startstop_t reset_pollfunc (ide_drive_t *drive) 957static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
966{ 958{
967 ide_hwgroup_t *hwgroup = HWGROUP(drive); 959 ide_hwif_t *hwif = drive->hwif;
968 ide_hwif_t *hwif = HWIF(drive);
969 const struct ide_port_ops *port_ops = hwif->port_ops; 960 const struct ide_port_ops *port_ops = hwif->port_ops;
970 u8 tmp; 961 u8 tmp;
971 int err = 0; 962 int err = 0;
@@ -982,7 +973,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
982 tmp = hwif->tp_ops->read_status(hwif); 973 tmp = hwif->tp_ops->read_status(hwif);
983 974
984 if (!OK_STAT(tmp, 0, ATA_BUSY)) { 975 if (!OK_STAT(tmp, 0, ATA_BUSY)) {
985 if (time_before(jiffies, hwgroup->poll_timeout)) { 976 if (time_before(jiffies, hwif->poll_timeout)) {
986 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 977 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
987 /* continue polling */ 978 /* continue polling */
988 return ide_started; 979 return ide_started;
@@ -1003,7 +994,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
1003 } 994 }
1004 } 995 }
1005out: 996out:
1006 hwgroup->polling = 0; /* done polling */ 997 hwif->polling = 0; /* done polling */
1007 ide_complete_drive_reset(drive, err); 998 ide_complete_drive_reset(drive, err);
1008 return ide_stopped; 999 return ide_stopped;
1009} 1000}
@@ -1076,25 +1067,19 @@ static void pre_reset(ide_drive_t *drive)
1076 */ 1067 */
1077static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) 1068static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1078{ 1069{
1079 unsigned int unit; 1070 ide_hwif_t *hwif = drive->hwif;
1080 unsigned long flags, timeout; 1071 struct ide_io_ports *io_ports = &hwif->io_ports;
1081 ide_hwif_t *hwif; 1072 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
1082 ide_hwgroup_t *hwgroup;
1083 struct ide_io_ports *io_ports;
1084 const struct ide_tp_ops *tp_ops;
1085 const struct ide_port_ops *port_ops; 1073 const struct ide_port_ops *port_ops;
1074 ide_drive_t *tdrive;
1075 unsigned long flags, timeout;
1076 int i;
1086 DEFINE_WAIT(wait); 1077 DEFINE_WAIT(wait);
1087 1078
1088 spin_lock_irqsave(&ide_lock, flags); 1079 spin_lock_irqsave(&hwif->lock, flags);
1089 hwif = HWIF(drive);
1090 hwgroup = HWGROUP(drive);
1091
1092 io_ports = &hwif->io_ports;
1093
1094 tp_ops = hwif->tp_ops;
1095 1080
1096 /* We must not reset with running handlers */ 1081 /* We must not reset with running handlers */
1097 BUG_ON(hwgroup->handler != NULL); 1082 BUG_ON(hwif->handler != NULL);
1098 1083
1099 /* For an ATAPI device, first try an ATAPI SRST. */ 1084 /* For an ATAPI device, first try an ATAPI SRST. */
1100 if (drive->media != ide_disk && !do_not_try_atapi) { 1085 if (drive->media != ide_disk && !do_not_try_atapi) {
@@ -1103,10 +1088,10 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1103 udelay (20); 1088 udelay (20);
1104 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 1089 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
1105 ndelay(400); 1090 ndelay(400);
1106 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; 1091 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
1107 hwgroup->polling = 1; 1092 hwif->polling = 1;
1108 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); 1093 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
1109 spin_unlock_irqrestore(&ide_lock, flags); 1094 spin_unlock_irqrestore(&hwif->lock, flags);
1110 return ide_started; 1095 return ide_started;
1111 } 1096 }
1112 1097
@@ -1116,9 +1101,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1116 1101
1117 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE); 1102 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
1118 timeout = jiffies; 1103 timeout = jiffies;
1119 for (unit = 0; unit < MAX_DRIVES; unit++) { 1104 ide_port_for_each_dev(i, tdrive, hwif) {
1120 ide_drive_t *tdrive = &hwif->drives[unit];
1121
1122 if (tdrive->dev_flags & IDE_DFLAG_PRESENT && 1105 if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
1123 tdrive->dev_flags & IDE_DFLAG_PARKED && 1106 tdrive->dev_flags & IDE_DFLAG_PARKED &&
1124 time_after(tdrive->sleep, timeout)) 1107 time_after(tdrive->sleep, timeout))
@@ -1129,9 +1112,9 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1129 if (time_before_eq(timeout, now)) 1112 if (time_before_eq(timeout, now))
1130 break; 1113 break;
1131 1114
1132 spin_unlock_irqrestore(&ide_lock, flags); 1115 spin_unlock_irqrestore(&hwif->lock, flags);
1133 timeout = schedule_timeout_uninterruptible(timeout - now); 1116 timeout = schedule_timeout_uninterruptible(timeout - now);
1134 spin_lock_irqsave(&ide_lock, flags); 1117 spin_lock_irqsave(&hwif->lock, flags);
1135 } while (timeout); 1118 } while (timeout);
1136 finish_wait(&ide_park_wq, &wait); 1119 finish_wait(&ide_park_wq, &wait);
1137 1120
@@ -1139,11 +1122,11 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1139 * First, reset any device state data we were maintaining 1122 * First, reset any device state data we were maintaining
1140 * for any of the drives on this interface. 1123 * for any of the drives on this interface.
1141 */ 1124 */
1142 for (unit = 0; unit < MAX_DRIVES; ++unit) 1125 ide_port_for_each_dev(i, tdrive, hwif)
1143 pre_reset(&hwif->drives[unit]); 1126 pre_reset(tdrive);
1144 1127
1145 if (io_ports->ctl_addr == 0) { 1128 if (io_ports->ctl_addr == 0) {
1146 spin_unlock_irqrestore(&ide_lock, flags); 1129 spin_unlock_irqrestore(&hwif->lock, flags);
1147 ide_complete_drive_reset(drive, -ENXIO); 1130 ide_complete_drive_reset(drive, -ENXIO);
1148 return ide_stopped; 1131 return ide_stopped;
1149 } 1132 }
@@ -1166,8 +1149,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1166 tp_ops->set_irq(hwif, drive->quirk_list == 2); 1149 tp_ops->set_irq(hwif, drive->quirk_list == 2);
1167 /* more than enough time */ 1150 /* more than enough time */
1168 udelay(10); 1151 udelay(10);
1169 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; 1152 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
1170 hwgroup->polling = 1; 1153 hwif->polling = 1;
1171 __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 1154 __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
1172 1155
1173 /* 1156 /*
@@ -1179,7 +1162,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1179 if (port_ops && port_ops->resetproc) 1162 if (port_ops && port_ops->resetproc)
1180 port_ops->resetproc(drive); 1163 port_ops->resetproc(drive);
1181 1164
1182 spin_unlock_irqrestore(&ide_lock, flags); 1165 spin_unlock_irqrestore(&hwif->lock, flags);
1183 return ide_started; 1166 return ide_started;
1184} 1167}
1185 1168
@@ -1223,6 +1206,3 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
1223 } 1206 }
1224 return -EBUSY; 1207 return -EBUSY;
1225} 1208}
1226
1227EXPORT_SYMBOL_GPL(ide_wait_not_busy);
1228
diff --git a/drivers/ide/ide-legacy.c b/drivers/ide/ide-legacy.c
new file mode 100644
index 000000000000..8c5dcbf22547
--- /dev/null
+++ b/drivers/ide/ide-legacy.c
@@ -0,0 +1,58 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3
4static void ide_legacy_init_one(hw_regs_t **hws, hw_regs_t *hw,
5 u8 port_no, const struct ide_port_info *d,
6 unsigned long config)
7{
8 unsigned long base, ctl;
9 int irq;
10
11 if (port_no == 0) {
12 base = 0x1f0;
13 ctl = 0x3f6;
14 irq = 14;
15 } else {
16 base = 0x170;
17 ctl = 0x376;
18 irq = 15;
19 }
20
21 if (!request_region(base, 8, d->name)) {
22 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
23 d->name, base, base + 7);
24 return;
25 }
26
27 if (!request_region(ctl, 1, d->name)) {
28 printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
29 d->name, ctl);
30 release_region(base, 8);
31 return;
32 }
33
34 ide_std_init_ports(hw, base, ctl);
35 hw->irq = irq;
36 hw->chipset = d->chipset;
37 hw->config = config;
38
39 hws[port_no] = hw;
40}
41
42int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config)
43{
44 hw_regs_t hw[2], *hws[] = { NULL, NULL, NULL, NULL };
45
46 memset(&hw, 0, sizeof(hw));
47
48 if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0)
49 ide_legacy_init_one(hws, &hw[0], 0, d, config);
50 ide_legacy_init_one(hws, &hw[1], 1, d, config);
51
52 if (hws[0] == NULL && hws[1] == NULL &&
53 (d->host_flags & IDE_HFLAG_SINGLE))
54 return -ENOENT;
55
56 return ide_host_add(d, hws, NULL);
57}
58EXPORT_SYMBOL_GPL(ide_legacy_device_add);
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 9fc4cfb2a272..09526a0de734 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -43,7 +43,6 @@ const char *ide_xfer_verbose(u8 mode)
43 43
44 return s; 44 return s;
45} 45}
46
47EXPORT_SYMBOL(ide_xfer_verbose); 46EXPORT_SYMBOL(ide_xfer_verbose);
48 47
49/** 48/**
@@ -87,7 +86,7 @@ static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
87 * This is used by most chipset support modules when "auto-tuning". 86 * This is used by most chipset support modules when "auto-tuning".
88 */ 87 */
89 88
90u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode) 89u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
91{ 90{
92 u16 *id = drive->id; 91 u16 *id = drive->id;
93 int pio_mode = -1, overridden = 0; 92 int pio_mode = -1, overridden = 0;
@@ -131,7 +130,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
131 130
132 return pio_mode; 131 return pio_mode;
133} 132}
134
135EXPORT_SYMBOL_GPL(ide_get_best_pio_mode); 133EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
136 134
137/* req_pio == "255" for auto-tune */ 135/* req_pio == "255" for auto-tune */
@@ -162,7 +160,6 @@ void ide_set_pio(ide_drive_t *drive, u8 req_pio)
162 160
163 (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio); 161 (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio);
164} 162}
165
166EXPORT_SYMBOL_GPL(ide_set_pio); 163EXPORT_SYMBOL_GPL(ide_set_pio);
167 164
168/** 165/**
@@ -173,7 +170,7 @@ EXPORT_SYMBOL_GPL(ide_set_pio);
173 * Enable or disable bounce buffering for the device. Drives move 170 * Enable or disable bounce buffering for the device. Drives move
174 * between PIO and DMA and that changes the rules we need. 171 * between PIO and DMA and that changes the rules we need.
175 */ 172 */
176 173
177void ide_toggle_bounce(ide_drive_t *drive, int on) 174void ide_toggle_bounce(ide_drive_t *drive, int on)
178{ 175{
179 u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */ 176 u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
@@ -243,14 +240,13 @@ int ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
243 return ide_config_drive_speed(drive, mode); 240 return ide_config_drive_speed(drive, mode);
244 } 241 }
245} 242}
246
247EXPORT_SYMBOL_GPL(ide_set_dma_mode); 243EXPORT_SYMBOL_GPL(ide_set_dma_mode);
248 244
249/** 245/**
250 * ide_set_xfer_rate - set transfer rate 246 * ide_set_xfer_rate - set transfer rate
251 * @drive: drive to set 247 * @drive: drive to set
252 * @rate: speed to attempt to set 248 * @rate: speed to attempt to set
253 * 249 *
254 * General helper for setting the speed of an IDE device. This 250 * General helper for setting the speed of an IDE device. This
255 * function knows about user enforced limits from the configuration 251 * function knows about user enforced limits from the configuration
256 * which ->set_pio_mode/->set_dma_mode does not. 252 * which ->set_pio_mode/->set_dma_mode does not.
@@ -277,21 +273,16 @@ int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
277 273
278static void ide_dump_opcode(ide_drive_t *drive) 274static void ide_dump_opcode(ide_drive_t *drive)
279{ 275{
280 struct request *rq; 276 struct request *rq = drive->hwif->rq;
281 ide_task_t *task = NULL; 277 ide_task_t *task = NULL;
282 278
283 spin_lock(&ide_lock);
284 rq = NULL;
285 if (HWGROUP(drive))
286 rq = HWGROUP(drive)->rq;
287 spin_unlock(&ide_lock);
288 if (!rq) 279 if (!rq)
289 return; 280 return;
290 281
291 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) 282 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
292 task = rq->special; 283 task = rq->special;
293 284
294 printk("ide: failed opcode was: "); 285 printk(KERN_ERR "ide: failed opcode was: ");
295 if (task == NULL) 286 if (task == NULL)
296 printk(KERN_CONT "unknown\n"); 287 printk(KERN_CONT "unknown\n");
297 else 288 else
@@ -329,44 +320,58 @@ static void ide_dump_sector(ide_drive_t *drive)
329 drive->hwif->tp_ops->tf_read(drive, &task); 320 drive->hwif->tp_ops->tf_read(drive, &task);
330 321
331 if (lba48 || (tf->device & ATA_LBA)) 322 if (lba48 || (tf->device & ATA_LBA))
332 printk(", LBAsect=%llu", 323 printk(KERN_CONT ", LBAsect=%llu",
333 (unsigned long long)ide_get_lba_addr(tf, lba48)); 324 (unsigned long long)ide_get_lba_addr(tf, lba48));
334 else 325 else
335 printk(", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, 326 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
336 tf->device & 0xf, tf->lbal); 327 tf->device & 0xf, tf->lbal);
337} 328}
338 329
339static void ide_dump_ata_error(ide_drive_t *drive, u8 err) 330static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
340{ 331{
341 printk("{ "); 332 printk(KERN_ERR "{ ");
342 if (err & ATA_ABORTED) printk("DriveStatusError "); 333 if (err & ATA_ABORTED)
334 printk(KERN_CONT "DriveStatusError ");
343 if (err & ATA_ICRC) 335 if (err & ATA_ICRC)
344 printk((err & ATA_ABORTED) ? "BadCRC " : "BadSector "); 336 printk(KERN_CONT "%s",
345 if (err & ATA_UNC) printk("UncorrectableError "); 337 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
346 if (err & ATA_IDNF) printk("SectorIdNotFound "); 338 if (err & ATA_UNC)
347 if (err & ATA_TRK0NF) printk("TrackZeroNotFound "); 339 printk(KERN_CONT "UncorrectableError ");
348 if (err & ATA_AMNF) printk("AddrMarkNotFound "); 340 if (err & ATA_IDNF)
349 printk("}"); 341 printk(KERN_CONT "SectorIdNotFound ");
342 if (err & ATA_TRK0NF)
343 printk(KERN_CONT "TrackZeroNotFound ");
344 if (err & ATA_AMNF)
345 printk(KERN_CONT "AddrMarkNotFound ");
346 printk(KERN_CONT "}");
350 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || 347 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
351 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { 348 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
349 struct request *rq = drive->hwif->rq;
350
352 ide_dump_sector(drive); 351 ide_dump_sector(drive);
353 if (HWGROUP(drive) && HWGROUP(drive)->rq) 352
354 printk(", sector=%llu", 353 if (rq)
355 (unsigned long long)HWGROUP(drive)->rq->sector); 354 printk(KERN_CONT ", sector=%llu",
355 (unsigned long long)rq->sector);
356 } 356 }
357 printk("\n"); 357 printk(KERN_CONT "\n");
358} 358}
359 359
360static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) 360static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
361{ 361{
362 printk("{ "); 362 printk(KERN_ERR "{ ");
363 if (err & ATAPI_ILI) printk("IllegalLengthIndication "); 363 if (err & ATAPI_ILI)
364 if (err & ATAPI_EOM) printk("EndOfMedia "); 364 printk(KERN_CONT "IllegalLengthIndication ");
365 if (err & ATA_ABORTED) printk("AbortedCommand "); 365 if (err & ATAPI_EOM)
366 if (err & ATA_MCR) printk("MediaChangeRequested "); 366 printk(KERN_CONT "EndOfMedia ");
367 if (err & ATAPI_LFS) printk("LastFailedSense=0x%02x ", 367 if (err & ATA_ABORTED)
368 (err & ATAPI_LFS) >> 4); 368 printk(KERN_CONT "AbortedCommand ");
369 printk("}\n"); 369 if (err & ATA_MCR)
370 printk(KERN_CONT "MediaChangeRequested ");
371 if (err & ATAPI_LFS)
372 printk(KERN_CONT "LastFailedSense=0x%02x ",
373 (err & ATAPI_LFS) >> 4);
374 printk(KERN_CONT "}\n");
370} 375}
371 376
372/** 377/**
@@ -382,34 +387,37 @@ static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
382 387
383u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) 388u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
384{ 389{
385 unsigned long flags;
386 u8 err = 0; 390 u8 err = 0;
387 391
388 local_irq_save(flags); 392 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
389 printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
390 if (stat & ATA_BUSY) 393 if (stat & ATA_BUSY)
391 printk("Busy "); 394 printk(KERN_CONT "Busy ");
392 else { 395 else {
393 if (stat & ATA_DRDY) printk("DriveReady "); 396 if (stat & ATA_DRDY)
394 if (stat & ATA_DF) printk("DeviceFault "); 397 printk(KERN_CONT "DriveReady ");
395 if (stat & ATA_DSC) printk("SeekComplete "); 398 if (stat & ATA_DF)
396 if (stat & ATA_DRQ) printk("DataRequest "); 399 printk(KERN_CONT "DeviceFault ");
397 if (stat & ATA_CORR) printk("CorrectedError "); 400 if (stat & ATA_DSC)
398 if (stat & ATA_IDX) printk("Index "); 401 printk(KERN_CONT "SeekComplete ");
399 if (stat & ATA_ERR) printk("Error "); 402 if (stat & ATA_DRQ)
403 printk(KERN_CONT "DataRequest ");
404 if (stat & ATA_CORR)
405 printk(KERN_CONT "CorrectedError ");
406 if (stat & ATA_IDX)
407 printk(KERN_CONT "Index ");
408 if (stat & ATA_ERR)
409 printk(KERN_CONT "Error ");
400 } 410 }
401 printk("}\n"); 411 printk(KERN_CONT "}\n");
402 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { 412 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
403 err = ide_read_error(drive); 413 err = ide_read_error(drive);
404 printk("%s: %s: error=0x%02x ", drive->name, msg, err); 414 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
405 if (drive->media == ide_disk) 415 if (drive->media == ide_disk)
406 ide_dump_ata_error(drive, err); 416 ide_dump_ata_error(drive, err);
407 else 417 else
408 ide_dump_atapi_error(drive, err); 418 ide_dump_atapi_error(drive, err);
409 } 419 }
410 ide_dump_opcode(drive); 420 ide_dump_opcode(drive);
411 local_irq_restore(flags);
412 return err; 421 return err;
413} 422}
414
415EXPORT_SYMBOL(ide_dump_status); 423EXPORT_SYMBOL(ide_dump_status);
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index 03b00e57e93f..c875a957596c 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -7,29 +7,31 @@ DECLARE_WAIT_QUEUE_HEAD(ide_park_wq);
7 7
8static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout) 8static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
9{ 9{
10 ide_hwif_t *hwif = drive->hwif;
10 struct request_queue *q = drive->queue; 11 struct request_queue *q = drive->queue;
11 struct request *rq; 12 struct request *rq;
12 int rc; 13 int rc;
13 14
14 timeout += jiffies; 15 timeout += jiffies;
15 spin_lock_irq(&ide_lock); 16 spin_lock_irq(&hwif->lock);
16 if (drive->dev_flags & IDE_DFLAG_PARKED) { 17 if (drive->dev_flags & IDE_DFLAG_PARKED) {
17 ide_hwgroup_t *hwgroup = drive->hwif->hwgroup; 18 int reset_timer = time_before(timeout, drive->sleep);
18 int reset_timer; 19 int start_queue = 0;
19 20
20 reset_timer = time_before(timeout, drive->sleep);
21 drive->sleep = timeout; 21 drive->sleep = timeout;
22 wake_up_all(&ide_park_wq); 22 wake_up_all(&ide_park_wq);
23 if (reset_timer && hwgroup->sleeping && 23 if (reset_timer && del_timer(&hwif->timer))
24 del_timer(&hwgroup->timer)) { 24 start_queue = 1;
25 hwgroup->sleeping = 0; 25 spin_unlock_irq(&hwif->lock);
26 hwgroup->busy = 0; 26
27 if (start_queue) {
28 spin_lock_irq(q->queue_lock);
27 blk_start_queueing(q); 29 blk_start_queueing(q);
30 spin_unlock_irq(q->queue_lock);
28 } 31 }
29 spin_unlock_irq(&ide_lock);
30 return; 32 return;
31 } 33 }
32 spin_unlock_irq(&ide_lock); 34 spin_unlock_irq(&hwif->lock);
33 35
34 rq = blk_get_request(q, READ, __GFP_WAIT); 36 rq = blk_get_request(q, READ, __GFP_WAIT);
35 rq->cmd[0] = REQ_PARK_HEADS; 37 rq->cmd[0] = REQ_PARK_HEADS;
@@ -62,20 +64,21 @@ ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
62 char *buf) 64 char *buf)
63{ 65{
64 ide_drive_t *drive = to_ide_device(dev); 66 ide_drive_t *drive = to_ide_device(dev);
67 ide_hwif_t *hwif = drive->hwif;
65 unsigned long now; 68 unsigned long now;
66 unsigned int msecs; 69 unsigned int msecs;
67 70
68 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD) 71 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
69 return -EOPNOTSUPP; 72 return -EOPNOTSUPP;
70 73
71 spin_lock_irq(&ide_lock); 74 spin_lock_irq(&hwif->lock);
72 now = jiffies; 75 now = jiffies;
73 if (drive->dev_flags & IDE_DFLAG_PARKED && 76 if (drive->dev_flags & IDE_DFLAG_PARKED &&
74 time_after(drive->sleep, now)) 77 time_after(drive->sleep, now))
75 msecs = jiffies_to_msecs(drive->sleep - now); 78 msecs = jiffies_to_msecs(drive->sleep - now);
76 else 79 else
77 msecs = 0; 80 msecs = 0;
78 spin_unlock_irq(&ide_lock); 81 spin_unlock_irq(&hwif->lock);
79 82
80 return snprintf(buf, 20, "%u\n", msecs); 83 return snprintf(buf, 20, "%u\n", msecs);
81} 84}
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
new file mode 100644
index 000000000000..4b3bf6a06b70
--- /dev/null
+++ b/drivers/ide/ide-pm.c
@@ -0,0 +1,235 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5int generic_ide_suspend(struct device *dev, pm_message_t mesg)
6{
7 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
8 ide_hwif_t *hwif = drive->hwif;
9 struct request *rq;
10 struct request_pm_state rqpm;
11 ide_task_t args;
12 int ret;
13
14 /* call ACPI _GTM only once */
15 if ((drive->dn & 1) == 0 || pair == NULL)
16 ide_acpi_get_timing(hwif);
17
18 memset(&rqpm, 0, sizeof(rqpm));
19 memset(&args, 0, sizeof(args));
20 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
21 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
22 rq->special = &args;
23 rq->data = &rqpm;
24 rqpm.pm_step = IDE_PM_START_SUSPEND;
25 if (mesg.event == PM_EVENT_PRETHAW)
26 mesg.event = PM_EVENT_FREEZE;
27 rqpm.pm_state = mesg.event;
28
29 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
30 blk_put_request(rq);
31
32 /* call ACPI _PS3 only after both devices are suspended */
33 if (ret == 0 && ((drive->dn & 1) || pair == NULL))
34 ide_acpi_set_state(hwif, 0);
35
36 return ret;
37}
38
39int generic_ide_resume(struct device *dev)
40{
41 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
42 ide_hwif_t *hwif = drive->hwif;
43 struct request *rq;
44 struct request_pm_state rqpm;
45 ide_task_t args;
46 int err;
47
48 /* call ACPI _PS0 / _STM only once */
49 if ((drive->dn & 1) == 0 || pair == NULL) {
50 ide_acpi_set_state(hwif, 1);
51 ide_acpi_push_timing(hwif);
52 }
53
54 ide_acpi_exec_tfs(drive);
55
56 memset(&rqpm, 0, sizeof(rqpm));
57 memset(&args, 0, sizeof(args));
58 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
59 rq->cmd_type = REQ_TYPE_PM_RESUME;
60 rq->cmd_flags |= REQ_PREEMPT;
61 rq->special = &args;
62 rq->data = &rqpm;
63 rqpm.pm_step = IDE_PM_START_RESUME;
64 rqpm.pm_state = PM_EVENT_ON;
65
66 err = blk_execute_rq(drive->queue, NULL, rq, 1);
67 blk_put_request(rq);
68
69 if (err == 0 && dev->driver) {
70 struct ide_driver *drv = to_ide_driver(dev->driver);
71
72 if (drv->resume)
73 drv->resume(drive);
74 }
75
76 return err;
77}
78
79void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
80{
81 struct request_pm_state *pm = rq->data;
82
83#ifdef DEBUG_PM
84 printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
85 drive->name, pm->pm_step);
86#endif
87 if (drive->media != ide_disk)
88 return;
89
90 switch (pm->pm_step) {
91 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
92 if (pm->pm_state == PM_EVENT_FREEZE)
93 pm->pm_step = IDE_PM_COMPLETED;
94 else
95 pm->pm_step = IDE_PM_STANDBY;
96 break;
97 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
98 pm->pm_step = IDE_PM_COMPLETED;
99 break;
100 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
101 pm->pm_step = IDE_PM_IDLE;
102 break;
103 case IDE_PM_IDLE: /* Resume step 2 (idle)*/
104 pm->pm_step = IDE_PM_RESTORE_DMA;
105 break;
106 }
107}
108
109ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
110{
111 struct request_pm_state *pm = rq->data;
112 ide_task_t *args = rq->special;
113
114 memset(args, 0, sizeof(*args));
115
116 switch (pm->pm_step) {
117 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
118 if (drive->media != ide_disk)
119 break;
120 /* Not supported? Switch to next step now. */
121 if (ata_id_flush_enabled(drive->id) == 0 ||
122 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
123 ide_complete_power_step(drive, rq);
124 return ide_stopped;
125 }
126 if (ata_id_flush_ext_enabled(drive->id))
127 args->tf.command = ATA_CMD_FLUSH_EXT;
128 else
129 args->tf.command = ATA_CMD_FLUSH;
130 goto out_do_tf;
131 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
132 args->tf.command = ATA_CMD_STANDBYNOW1;
133 goto out_do_tf;
134 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
135 ide_set_max_pio(drive);
136 /*
137 * skip IDE_PM_IDLE for ATAPI devices
138 */
139 if (drive->media != ide_disk)
140 pm->pm_step = IDE_PM_RESTORE_DMA;
141 else
142 ide_complete_power_step(drive, rq);
143 return ide_stopped;
144 case IDE_PM_IDLE: /* Resume step 2 (idle) */
145 args->tf.command = ATA_CMD_IDLEIMMEDIATE;
146 goto out_do_tf;
147 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
148 /*
149 * Right now, all we do is call ide_set_dma(drive),
150 * we could be smarter and check for current xfer_speed
151 * in struct drive etc...
152 */
153 if (drive->hwif->dma_ops == NULL)
154 break;
155 /*
156 * TODO: respect IDE_DFLAG_USING_DMA
157 */
158 ide_set_dma(drive);
159 break;
160 }
161
162 pm->pm_step = IDE_PM_COMPLETED;
163 return ide_stopped;
164
165out_do_tf:
166 args->tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
167 args->data_phase = TASKFILE_NO_DATA;
168 return do_rw_taskfile(drive, args);
169}
170
171/**
172 * ide_complete_pm_request - end the current Power Management request
173 * @drive: target drive
174 * @rq: request
175 *
176 * This function cleans up the current PM request and stops the queue
177 * if necessary.
178 */
179void ide_complete_pm_request(ide_drive_t *drive, struct request *rq)
180{
181 struct request_queue *q = drive->queue;
182 unsigned long flags;
183
184#ifdef DEBUG_PM
185 printk("%s: completing PM request, %s\n", drive->name,
186 blk_pm_suspend_request(rq) ? "suspend" : "resume");
187#endif
188 spin_lock_irqsave(q->queue_lock, flags);
189 if (blk_pm_suspend_request(rq)) {
190 blk_stop_queue(q);
191 } else {
192 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
193 blk_start_queue(q);
194 }
195 spin_unlock_irqrestore(q->queue_lock, flags);
196
197 drive->hwif->rq = NULL;
198
199 if (blk_end_request(rq, 0, 0))
200 BUG();
201}
202
203void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
204{
205 struct request_pm_state *pm = rq->data;
206
207 if (blk_pm_suspend_request(rq) &&
208 pm->pm_step == IDE_PM_START_SUSPEND)
209 /* Mark drive blocked when starting the suspend sequence. */
210 drive->dev_flags |= IDE_DFLAG_BLOCKED;
211 else if (blk_pm_resume_request(rq) &&
212 pm->pm_step == IDE_PM_START_RESUME) {
213 /*
214 * The first thing we do on wakeup is to wait for BSY bit to
215 * go away (with a looong timeout) as a drive on this hwif may
216 * just be POSTing itself.
217 * We do that before even selecting as the "other" device on
218 * the bus may be broken enough to walk on our toes at this
219 * point.
220 */
221 ide_hwif_t *hwif = drive->hwif;
222 int rc;
223#ifdef DEBUG_PM
224 printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
225#endif
226 rc = ide_wait_not_busy(hwif, 35000);
227 if (rc)
228 printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
229 SELECT_DRIVE(drive);
230 hwif->tp_ops->set_irq(hwif, 1);
231 rc = ide_wait_not_busy(hwif, 100000);
232 if (rc)
233 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
234 }
235}
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index c55bdbd22314..0ccbb4459fb9 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -101,6 +101,82 @@ static void ide_disk_init_mult_count(ide_drive_t *drive)
101 } 101 }
102} 102}
103 103
104static void ide_classify_ata_dev(ide_drive_t *drive)
105{
106 u16 *id = drive->id;
107 char *m = (char *)&id[ATA_ID_PROD];
108 int is_cfa = ata_id_is_cfa(id);
109
110 /* CF devices are *not* removable in Linux definition of the term */
111 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
112 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
113
114 drive->media = ide_disk;
115
116 if (!ata_id_has_unload(drive->id))
117 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
118
119 printk(KERN_INFO "%s: %s, %s DISK drive\n", drive->name, m,
120 is_cfa ? "CFA" : "ATA");
121}
122
123static void ide_classify_atapi_dev(ide_drive_t *drive)
124{
125 u16 *id = drive->id;
126 char *m = (char *)&id[ATA_ID_PROD];
127 u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f;
128
129 printk(KERN_INFO "%s: %s, ATAPI ", drive->name, m);
130 switch (type) {
131 case ide_floppy:
132 if (!strstr(m, "CD-ROM")) {
133 if (!strstr(m, "oppy") &&
134 !strstr(m, "poyp") &&
135 !strstr(m, "ZIP"))
136 printk(KERN_CONT "cdrom or floppy?, assuming ");
137 if (drive->media != ide_cdrom) {
138 printk(KERN_CONT "FLOPPY");
139 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
140 break;
141 }
142 }
143 /* Early cdrom models used zero */
144 type = ide_cdrom;
145 case ide_cdrom:
146 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
147#ifdef CONFIG_PPC
148 /* kludge for Apple PowerBook internal zip */
149 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
150 printk(KERN_CONT "FLOPPY");
151 type = ide_floppy;
152 break;
153 }
154#endif
155 printk(KERN_CONT "CD/DVD-ROM");
156 break;
157 case ide_tape:
158 printk(KERN_CONT "TAPE");
159 break;
160 case ide_optical:
161 printk(KERN_CONT "OPTICAL");
162 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
163 break;
164 default:
165 printk(KERN_CONT "UNKNOWN (type %d)", type);
166 break;
167 }
168
169 printk(KERN_CONT " drive\n");
170 drive->media = type;
171 /* an ATAPI device ignores DRDY */
172 drive->ready_stat = 0;
173 if (ata_id_cdb_intr(id))
174 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
175 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
176 /* we don't do head unloading on ATAPI devices */
177 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
178}
179
104/** 180/**
105 * do_identify - identify a drive 181 * do_identify - identify a drive
106 * @drive: drive to identify 182 * @drive: drive to identify
@@ -110,20 +186,22 @@ static void ide_disk_init_mult_count(ide_drive_t *drive)
110 * read and parse the results. This function is run with 186 * read and parse the results. This function is run with
111 * interrupts disabled. 187 * interrupts disabled.
112 */ 188 */
113 189
114static inline void do_identify (ide_drive_t *drive, u8 cmd) 190static void do_identify(ide_drive_t *drive, u8 cmd)
115{ 191{
116 ide_hwif_t *hwif = HWIF(drive); 192 ide_hwif_t *hwif = drive->hwif;
117 u16 *id = drive->id; 193 u16 *id = drive->id;
118 char *m = (char *)&id[ATA_ID_PROD]; 194 char *m = (char *)&id[ATA_ID_PROD];
119 int bswap = 1, is_cfa; 195 unsigned long flags;
196 int bswap = 1;
120 197
198 /* local CPU only; some systems need this */
199 local_irq_save(flags);
121 /* read 512 bytes of id info */ 200 /* read 512 bytes of id info */
122 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE); 201 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
202 local_irq_restore(flags);
123 203
124 drive->dev_flags |= IDE_DFLAG_ID_READ; 204 drive->dev_flags |= IDE_DFLAG_ID_READ;
125
126 local_irq_enable();
127#ifdef DEBUG 205#ifdef DEBUG
128 printk(KERN_INFO "%s: dumping identify data\n", drive->name); 206 printk(KERN_INFO "%s: dumping identify data\n", drive->name);
129 ide_dump_identify((u8 *)id); 207 ide_dump_identify((u8 *)id);
@@ -152,91 +230,23 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
152 if (strstr(m, "E X A B Y T E N E S T")) 230 if (strstr(m, "E X A B Y T E N E S T"))
153 goto err_misc; 231 goto err_misc;
154 232
155 printk(KERN_INFO "%s: %s, ", drive->name, m);
156
157 drive->dev_flags |= IDE_DFLAG_PRESENT; 233 drive->dev_flags |= IDE_DFLAG_PRESENT;
158 drive->dev_flags &= ~IDE_DFLAG_DEAD; 234 drive->dev_flags &= ~IDE_DFLAG_DEAD;
159 235
160 /* 236 /*
161 * Check for an ATAPI device 237 * Check for an ATAPI device
162 */ 238 */
163 if (cmd == ATA_CMD_ID_ATAPI) { 239 if (cmd == ATA_CMD_ID_ATAPI)
164 u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f; 240 ide_classify_atapi_dev(drive);
165 241 else
166 printk(KERN_CONT "ATAPI ");
167 switch (type) {
168 case ide_floppy:
169 if (!strstr(m, "CD-ROM")) {
170 if (!strstr(m, "oppy") &&
171 !strstr(m, "poyp") &&
172 !strstr(m, "ZIP"))
173 printk(KERN_CONT "cdrom or floppy?, assuming ");
174 if (drive->media != ide_cdrom) {
175 printk(KERN_CONT "FLOPPY");
176 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
177 break;
178 }
179 }
180 /* Early cdrom models used zero */
181 type = ide_cdrom;
182 case ide_cdrom:
183 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
184#ifdef CONFIG_PPC
185 /* kludge for Apple PowerBook internal zip */
186 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
187 printk(KERN_CONT "FLOPPY");
188 type = ide_floppy;
189 break;
190 }
191#endif
192 printk(KERN_CONT "CD/DVD-ROM");
193 break;
194 case ide_tape:
195 printk(KERN_CONT "TAPE");
196 break;
197 case ide_optical:
198 printk(KERN_CONT "OPTICAL");
199 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
200 break;
201 default:
202 printk(KERN_CONT "UNKNOWN (type %d)", type);
203 break;
204 }
205 printk(KERN_CONT " drive\n");
206 drive->media = type;
207 /* an ATAPI device ignores DRDY */
208 drive->ready_stat = 0;
209 if (ata_id_cdb_intr(id))
210 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
211 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
212 /* we don't do head unloading on ATAPI devices */
213 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
214 return;
215 }
216
217 /* 242 /*
218 * Not an ATAPI device: looks like a "regular" hard disk 243 * Not an ATAPI device: looks like a "regular" hard disk
219 */ 244 */
220 245 ide_classify_ata_dev(drive);
221 is_cfa = ata_id_is_cfa(id);
222
223 /* CF devices are *not* removable in Linux definition of the term */
224 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
225 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
226
227 drive->media = ide_disk;
228
229 if (!ata_id_has_unload(drive->id))
230 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
231
232 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
233
234 return; 246 return;
235
236err_misc: 247err_misc:
237 kfree(id); 248 kfree(id);
238 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 249 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
239 return;
240} 250}
241 251
242/** 252/**
@@ -256,7 +266,7 @@ err_misc:
256 266
257static int actual_try_to_identify (ide_drive_t *drive, u8 cmd) 267static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
258{ 268{
259 ide_hwif_t *hwif = HWIF(drive); 269 ide_hwif_t *hwif = drive->hwif;
260 struct ide_io_ports *io_ports = &hwif->io_ports; 270 struct ide_io_ports *io_ports = &hwif->io_ports;
261 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 271 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
262 int use_altstatus = 0, rc; 272 int use_altstatus = 0, rc;
@@ -306,17 +316,12 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
306 s = tp_ops->read_status(hwif); 316 s = tp_ops->read_status(hwif);
307 317
308 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) { 318 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
309 unsigned long flags;
310
311 /* local CPU only; some systems need this */
312 local_irq_save(flags);
313 /* drive returned ID */ 319 /* drive returned ID */
314 do_identify(drive, cmd); 320 do_identify(drive, cmd);
315 /* drive responded with ID */ 321 /* drive responded with ID */
316 rc = 0; 322 rc = 0;
317 /* clear drive IRQ */ 323 /* clear drive IRQ */
318 (void)tp_ops->read_status(hwif); 324 (void)tp_ops->read_status(hwif);
319 local_irq_restore(flags);
320 } else { 325 } else {
321 /* drive refused ID */ 326 /* drive refused ID */
322 rc = 2; 327 rc = 2;
@@ -336,7 +341,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
336 341
337static int try_to_identify (ide_drive_t *drive, u8 cmd) 342static int try_to_identify (ide_drive_t *drive, u8 cmd)
338{ 343{
339 ide_hwif_t *hwif = HWIF(drive); 344 ide_hwif_t *hwif = drive->hwif;
340 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 345 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
341 int retval; 346 int retval;
342 int autoprobe = 0; 347 int autoprobe = 0;
@@ -433,7 +438,7 @@ static u8 ide_read_device(ide_drive_t *drive)
433 438
434static int do_probe (ide_drive_t *drive, u8 cmd) 439static int do_probe (ide_drive_t *drive, u8 cmd)
435{ 440{
436 ide_hwif_t *hwif = HWIF(drive); 441 ide_hwif_t *hwif = drive->hwif;
437 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 442 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
438 int rc; 443 int rc;
439 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat; 444 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
@@ -458,7 +463,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
458 if (ide_read_device(drive) != drive->select && present == 0) { 463 if (ide_read_device(drive) != drive->select && present == 0) {
459 if (drive->dn & 1) { 464 if (drive->dn & 1) {
460 /* exit with drive0 selected */ 465 /* exit with drive0 selected */
461 SELECT_DRIVE(&hwif->drives[0]); 466 SELECT_DRIVE(hwif->devices[0]);
462 /* allow ATA_BUSY to assert & clear */ 467 /* allow ATA_BUSY to assert & clear */
463 msleep(50); 468 msleep(50);
464 } 469 }
@@ -504,7 +509,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
504 } 509 }
505 if (drive->dn & 1) { 510 if (drive->dn & 1) {
506 /* exit with drive0 selected */ 511 /* exit with drive0 selected */
507 SELECT_DRIVE(&hwif->drives[0]); 512 SELECT_DRIVE(hwif->devices[0]);
508 msleep(50); 513 msleep(50);
509 /* ensure drive irq is clear */ 514 /* ensure drive irq is clear */
510 (void)tp_ops->read_status(hwif); 515 (void)tp_ops->read_status(hwif);
@@ -517,7 +522,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
517 */ 522 */
518static void enable_nest (ide_drive_t *drive) 523static void enable_nest (ide_drive_t *drive)
519{ 524{
520 ide_hwif_t *hwif = HWIF(drive); 525 ide_hwif_t *hwif = drive->hwif;
521 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 526 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
522 u8 stat; 527 u8 stat;
523 528
@@ -554,8 +559,8 @@ static void enable_nest (ide_drive_t *drive)
554 * 1 device was found 559 * 1 device was found
555 * (note: IDE_DFLAG_PRESENT might still be not set) 560 * (note: IDE_DFLAG_PRESENT might still be not set)
556 */ 561 */
557 562
558static inline u8 probe_for_drive (ide_drive_t *drive) 563static u8 probe_for_drive(ide_drive_t *drive)
559{ 564{
560 char *m; 565 char *m;
561 566
@@ -642,16 +647,11 @@ static int ide_register_port(ide_hwif_t *hwif)
642 int ret; 647 int ret;
643 648
644 /* register with global device tree */ 649 /* register with global device tree */
645 strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); 650 dev_set_name(&hwif->gendev, hwif->name);
646 hwif->gendev.driver_data = hwif; 651 hwif->gendev.driver_data = hwif;
647 if (hwif->gendev.parent == NULL) { 652 hwif->gendev.parent = hwif->dev;
648 if (hwif->dev)
649 hwif->gendev.parent = hwif->dev;
650 else
651 /* Would like to do = &device_legacy */
652 hwif->gendev.parent = NULL;
653 }
654 hwif->gendev.release = hwif_release_dev; 653 hwif->gendev.release = hwif_release_dev;
654
655 ret = device_register(&hwif->gendev); 655 ret = device_register(&hwif->gendev);
656 if (ret < 0) { 656 if (ret < 0) {
657 printk(KERN_WARNING "IDE: %s: device_register error: %d\n", 657 printk(KERN_WARNING "IDE: %s: device_register error: %d\n",
@@ -697,7 +697,8 @@ out:
697 697
698static int ide_port_wait_ready(ide_hwif_t *hwif) 698static int ide_port_wait_ready(ide_hwif_t *hwif)
699{ 699{
700 int unit, rc; 700 ide_drive_t *drive;
701 int i, rc;
701 702
702 printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name); 703 printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name);
703 704
@@ -714,9 +715,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
714 return rc; 715 return rc;
715 716
716 /* Now make sure both master & slave are ready */ 717 /* Now make sure both master & slave are ready */
717 for (unit = 0; unit < MAX_DRIVES; unit++) { 718 ide_port_for_each_dev(i, drive, hwif) {
718 ide_drive_t *drive = &hwif->drives[unit];
719
720 /* Ignore disks that we will not probe for later. */ 719 /* Ignore disks that we will not probe for later. */
721 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 || 720 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
722 (drive->dev_flags & IDE_DFLAG_PRESENT)) { 721 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
@@ -732,8 +731,8 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
732 } 731 }
733out: 732out:
734 /* Exit function with master reselected (let's be sane) */ 733 /* Exit function with master reselected (let's be sane) */
735 if (unit) 734 if (i)
736 SELECT_DRIVE(&hwif->drives[0]); 735 SELECT_DRIVE(hwif->devices[0]);
737 736
738 return rc; 737 return rc;
739} 738}
@@ -749,7 +748,7 @@ out:
749 748
750void ide_undecoded_slave(ide_drive_t *dev1) 749void ide_undecoded_slave(ide_drive_t *dev1)
751{ 750{
752 ide_drive_t *dev0 = &dev1->hwif->drives[0]; 751 ide_drive_t *dev0 = dev1->hwif->devices[0];
753 752
754 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0) 753 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
755 return; 754 return;
@@ -778,14 +777,15 @@ EXPORT_SYMBOL_GPL(ide_undecoded_slave);
778 777
779static int ide_probe_port(ide_hwif_t *hwif) 778static int ide_probe_port(ide_hwif_t *hwif)
780{ 779{
780 ide_drive_t *drive;
781 unsigned long flags; 781 unsigned long flags;
782 unsigned int irqd; 782 unsigned int irqd;
783 int unit, rc = -ENODEV; 783 int i, rc = -ENODEV;
784 784
785 BUG_ON(hwif->present); 785 BUG_ON(hwif->present);
786 786
787 if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) && 787 if ((hwif->devices[0]->dev_flags & IDE_DFLAG_NOPROBE) &&
788 (hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE)) 788 (hwif->devices[1]->dev_flags & IDE_DFLAG_NOPROBE))
789 return -EACCES; 789 return -EACCES;
790 790
791 /* 791 /*
@@ -796,7 +796,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
796 if (irqd) 796 if (irqd)
797 disable_irq(hwif->irq); 797 disable_irq(hwif->irq);
798 798
799 local_irq_set(flags); 799 local_irq_save(flags);
800 local_irq_enable_in_hardirq();
800 801
801 if (ide_port_wait_ready(hwif) == -EBUSY) 802 if (ide_port_wait_ready(hwif) == -EBUSY)
802 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); 803 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name);
@@ -805,9 +806,7 @@ static int ide_probe_port(ide_hwif_t *hwif)
805 * Second drive should only exist if first drive was found, 806 * Second drive should only exist if first drive was found,
806 * but a lot of cdrom drives are configured as single slaves. 807 * but a lot of cdrom drives are configured as single slaves.
807 */ 808 */
808 for (unit = 0; unit < MAX_DRIVES; ++unit) { 809 ide_port_for_each_dev(i, drive, hwif) {
809 ide_drive_t *drive = &hwif->drives[unit];
810
811 (void) probe_for_drive(drive); 810 (void) probe_for_drive(drive);
812 if (drive->dev_flags & IDE_DFLAG_PRESENT) 811 if (drive->dev_flags & IDE_DFLAG_PRESENT)
813 rc = 0; 812 rc = 0;
@@ -828,20 +827,17 @@ static int ide_probe_port(ide_hwif_t *hwif)
828static void ide_port_tune_devices(ide_hwif_t *hwif) 827static void ide_port_tune_devices(ide_hwif_t *hwif)
829{ 828{
830 const struct ide_port_ops *port_ops = hwif->port_ops; 829 const struct ide_port_ops *port_ops = hwif->port_ops;
831 int unit; 830 ide_drive_t *drive;
832 831 int i;
833 for (unit = 0; unit < MAX_DRIVES; unit++) {
834 ide_drive_t *drive = &hwif->drives[unit];
835 832
833 ide_port_for_each_dev(i, drive, hwif) {
836 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 834 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
837 if (port_ops && port_ops->quirkproc) 835 if (port_ops && port_ops->quirkproc)
838 port_ops->quirkproc(drive); 836 port_ops->quirkproc(drive);
839 } 837 }
840 } 838 }
841 839
842 for (unit = 0; unit < MAX_DRIVES; ++unit) { 840 ide_port_for_each_dev(i, drive, hwif) {
843 ide_drive_t *drive = &hwif->drives[unit];
844
845 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 841 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
846 ide_set_max_pio(drive); 842 ide_set_max_pio(drive);
847 843
@@ -852,11 +848,8 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
852 } 848 }
853 } 849 }
854 850
855 for (unit = 0; unit < MAX_DRIVES; ++unit) { 851 ide_port_for_each_dev(i, drive, hwif) {
856 ide_drive_t *drive = &hwif->drives[unit]; 852 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
857
858 if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
859 drive->id[ATA_ID_DWORD_IO])
860 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT; 853 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
861 else 854 else
862 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT; 855 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
@@ -864,37 +857,12 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
864} 857}
865 858
866/* 859/*
867 * save_match() is used to simplify logic in init_irq() below.
868 *
869 * A loophole here is that we may not know about a particular
870 * hwif's irq until after that hwif is actually probed/initialized..
871 * This could be a problem for the case where an hwif is on a
872 * dual interface that requires serialization (eg. cmd640) and another
873 * hwif using one of the same irqs is initialized beforehand.
874 *
875 * This routine detects and reports such situations, but does not fix them.
876 */
877static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
878{
879 ide_hwif_t *m = *match;
880
881 if (m && m->hwgroup && m->hwgroup != new->hwgroup) {
882 if (!new->hwgroup)
883 return;
884 printk(KERN_WARNING "%s: potential IRQ problem with %s and %s\n",
885 hwif->name, new->name, m->name);
886 }
887 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
888 *match = new;
889}
890
891/*
892 * init request queue 860 * init request queue
893 */ 861 */
894static int ide_init_queue(ide_drive_t *drive) 862static int ide_init_queue(ide_drive_t *drive)
895{ 863{
896 struct request_queue *q; 864 struct request_queue *q;
897 ide_hwif_t *hwif = HWIF(drive); 865 ide_hwif_t *hwif = drive->hwif;
898 int max_sectors = 256; 866 int max_sectors = 256;
899 int max_sg_entries = PRD_ENTRIES; 867 int max_sg_entries = PRD_ENTRIES;
900 868
@@ -906,7 +874,7 @@ static int ide_init_queue(ide_drive_t *drive)
906 * do not. 874 * do not.
907 */ 875 */
908 876
909 q = blk_init_queue_node(do_ide_request, &ide_lock, hwif_to_node(hwif)); 877 q = blk_init_queue_node(do_ide_request, NULL, hwif_to_node(hwif));
910 if (!q) 878 if (!q)
911 return 1; 879 return 1;
912 880
@@ -943,36 +911,19 @@ static int ide_init_queue(ide_drive_t *drive)
943 return 0; 911 return 0;
944} 912}
945 913
946static void ide_add_drive_to_hwgroup(ide_drive_t *drive) 914static DEFINE_MUTEX(ide_cfg_mtx);
947{
948 ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
949
950 spin_lock_irq(&ide_lock);
951 if (!hwgroup->drive) {
952 /* first drive for hwgroup. */
953 drive->next = drive;
954 hwgroup->drive = drive;
955 hwgroup->hwif = HWIF(hwgroup->drive);
956 } else {
957 drive->next = hwgroup->drive->next;
958 hwgroup->drive->next = drive;
959 }
960 spin_unlock_irq(&ide_lock);
961}
962 915
963/* 916/*
964 * For any present drive: 917 * For any present drive:
965 * - allocate the block device queue 918 * - allocate the block device queue
966 * - link drive into the hwgroup
967 */ 919 */
968static int ide_port_setup_devices(ide_hwif_t *hwif) 920static int ide_port_setup_devices(ide_hwif_t *hwif)
969{ 921{
922 ide_drive_t *drive;
970 int i, j = 0; 923 int i, j = 0;
971 924
972 mutex_lock(&ide_cfg_mtx); 925 mutex_lock(&ide_cfg_mtx);
973 for (i = 0; i < MAX_DRIVES; i++) { 926 ide_port_for_each_dev(i, drive, hwif) {
974 ide_drive_t *drive = &hwif->drives[i];
975
976 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 927 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
977 continue; 928 continue;
978 929
@@ -986,152 +937,39 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
986 } 937 }
987 938
988 j++; 939 j++;
989
990 ide_add_drive_to_hwgroup(drive);
991 } 940 }
992 mutex_unlock(&ide_cfg_mtx); 941 mutex_unlock(&ide_cfg_mtx);
993 942
994 return j; 943 return j;
995} 944}
996 945
997static ide_hwif_t *ide_ports[MAX_HWIFS];
998
999void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
1000{
1001 ide_hwgroup_t *hwgroup = hwif->hwgroup;
1002
1003 ide_ports[hwif->index] = NULL;
1004
1005 spin_lock_irq(&ide_lock);
1006 /*
1007 * Remove us from the hwgroup, and free
1008 * the hwgroup if we were the only member
1009 */
1010 if (hwif->next == hwif) {
1011 BUG_ON(hwgroup->hwif != hwif);
1012 kfree(hwgroup);
1013 } else {
1014 /* There is another interface in hwgroup.
1015 * Unlink us, and set hwgroup->drive and ->hwif to
1016 * something sane.
1017 */
1018 ide_hwif_t *g = hwgroup->hwif;
1019
1020 while (g->next != hwif)
1021 g = g->next;
1022 g->next = hwif->next;
1023 if (hwgroup->hwif == hwif) {
1024 /* Chose a random hwif for hwgroup->hwif.
1025 * It's guaranteed that there are no drives
1026 * left in the hwgroup.
1027 */
1028 BUG_ON(hwgroup->drive != NULL);
1029 hwgroup->hwif = g;
1030 }
1031 BUG_ON(hwgroup->hwif == hwif);
1032 }
1033 spin_unlock_irq(&ide_lock);
1034}
1035
1036/* 946/*
1037 * This routine sets up the irq for an ide interface, and creates a new 947 * This routine sets up the IRQ for an IDE interface.
1038 * hwgroup for the irq/hwif if none was previously assigned.
1039 *
1040 * Much of the code is for correctly detecting/handling irq sharing
1041 * and irq serialization situations. This is somewhat complex because
1042 * it handles static as well as dynamic (PCMCIA) IDE interfaces.
1043 */ 948 */
1044static int init_irq (ide_hwif_t *hwif) 949static int init_irq (ide_hwif_t *hwif)
1045{ 950{
1046 struct ide_io_ports *io_ports = &hwif->io_ports; 951 struct ide_io_ports *io_ports = &hwif->io_ports;
1047 unsigned int index; 952 int sa = 0;
1048 ide_hwgroup_t *hwgroup;
1049 ide_hwif_t *match = NULL;
1050 953
1051 mutex_lock(&ide_cfg_mtx); 954 mutex_lock(&ide_cfg_mtx);
1052 hwif->hwgroup = NULL; 955 spin_lock_init(&hwif->lock);
1053 956
1054 /* 957 init_timer(&hwif->timer);
1055 * Group up with any other hwifs that share our irq(s). 958 hwif->timer.function = &ide_timer_expiry;
1056 */ 959 hwif->timer.data = (unsigned long)hwif;
1057 for (index = 0; index < MAX_HWIFS; index++) {
1058 ide_hwif_t *h = ide_ports[index];
1059
1060 if (h && h->hwgroup) { /* scan only initialized ports */
1061 if (hwif->irq == h->irq) {
1062 hwif->sharing_irq = h->sharing_irq = 1;
1063 if (hwif->chipset != ide_pci ||
1064 h->chipset != ide_pci) {
1065 save_match(hwif, h, &match);
1066 }
1067 }
1068 if (hwif->serialized) {
1069 if (hwif->mate && hwif->mate->irq == h->irq)
1070 save_match(hwif, h, &match);
1071 }
1072 if (h->serialized) {
1073 if (h->mate && hwif->irq == h->mate->irq)
1074 save_match(hwif, h, &match);
1075 }
1076 }
1077 }
1078
1079 /*
1080 * If we are still without a hwgroup, then form a new one
1081 */
1082 if (match) {
1083 hwgroup = match->hwgroup;
1084 hwif->hwgroup = hwgroup;
1085 /*
1086 * Link us into the hwgroup.
1087 * This must be done early, do ensure that unexpected_intr
1088 * can find the hwif and prevent irq storms.
1089 * No drives are attached to the new hwif, choose_drive
1090 * can't do anything stupid (yet).
1091 * Add ourself as the 2nd entry to the hwgroup->hwif
1092 * linked list, the first entry is the hwif that owns
1093 * hwgroup->handler - do not change that.
1094 */
1095 spin_lock_irq(&ide_lock);
1096 hwif->next = hwgroup->hwif->next;
1097 hwgroup->hwif->next = hwif;
1098 BUG_ON(hwif->next == hwif);
1099 spin_unlock_irq(&ide_lock);
1100 } else {
1101 hwgroup = kmalloc_node(sizeof(*hwgroup), GFP_KERNEL|__GFP_ZERO,
1102 hwif_to_node(hwif));
1103 if (hwgroup == NULL)
1104 goto out_up;
1105
1106 hwif->hwgroup = hwgroup;
1107 hwgroup->hwif = hwif->next = hwif;
1108 960
1109 init_timer(&hwgroup->timer);
1110 hwgroup->timer.function = &ide_timer_expiry;
1111 hwgroup->timer.data = (unsigned long) hwgroup;
1112 }
1113
1114 ide_ports[hwif->index] = hwif;
1115
1116 /*
1117 * Allocate the irq, if not already obtained for another hwif
1118 */
1119 if (!match || match->irq != hwif->irq) {
1120 int sa = 0;
1121#if defined(__mc68000__) 961#if defined(__mc68000__)
1122 sa = IRQF_SHARED; 962 sa = IRQF_SHARED;
1123#endif /* __mc68000__ */ 963#endif /* __mc68000__ */
1124 964
1125 if (hwif->chipset == ide_pci || hwif->chipset == ide_cmd646 || 965 if (hwif->chipset == ide_pci)
1126 hwif->chipset == ide_ali14xx) 966 sa = IRQF_SHARED;
1127 sa = IRQF_SHARED;
1128 967
1129 if (io_ports->ctl_addr) 968 if (io_ports->ctl_addr)
1130 hwif->tp_ops->set_irq(hwif, 1); 969 hwif->tp_ops->set_irq(hwif, 1);
1131 970
1132 if (request_irq(hwif->irq,&ide_intr,sa,hwif->name,hwgroup)) 971 if (request_irq(hwif->irq, &ide_intr, sa, hwif->name, hwif))
1133 goto out_unlink; 972 goto out_up;
1134 }
1135 973
1136 if (!hwif->rqsize) { 974 if (!hwif->rqsize) {
1137 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) || 975 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
@@ -1149,15 +987,12 @@ static int init_irq (ide_hwif_t *hwif)
1149 printk(KERN_INFO "%s at 0x%08lx on irq %d", hwif->name, 987 printk(KERN_INFO "%s at 0x%08lx on irq %d", hwif->name,
1150 io_ports->data_addr, hwif->irq); 988 io_ports->data_addr, hwif->irq);
1151#endif /* __mc68000__ */ 989#endif /* __mc68000__ */
1152 if (match) 990 if (hwif->host->host_flags & IDE_HFLAG_SERIALIZE)
1153 printk(KERN_CONT " (%sed with %s)", 991 printk(KERN_CONT " (serialized)");
1154 hwif->sharing_irq ? "shar" : "serializ", match->name);
1155 printk(KERN_CONT "\n"); 992 printk(KERN_CONT "\n");
1156 993
1157 mutex_unlock(&ide_cfg_mtx); 994 mutex_unlock(&ide_cfg_mtx);
1158 return 0; 995 return 0;
1159out_unlink:
1160 ide_remove_port_from_hwgroup(hwif);
1161out_up: 996out_up:
1162 mutex_unlock(&ide_cfg_mtx); 997 mutex_unlock(&ide_cfg_mtx);
1163 return 1; 998 return 1;
@@ -1173,15 +1008,13 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
1173{ 1008{
1174 ide_hwif_t *hwif = data; 1009 ide_hwif_t *hwif = data;
1175 int unit = *part >> PARTN_BITS; 1010 int unit = *part >> PARTN_BITS;
1176 ide_drive_t *drive = &hwif->drives[unit]; 1011 ide_drive_t *drive = hwif->devices[unit];
1177 1012
1178 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 1013 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1179 return NULL; 1014 return NULL;
1180 1015
1181 if (drive->media == ide_disk) 1016 if (drive->media == ide_disk)
1182 request_module("ide-disk"); 1017 request_module("ide-disk");
1183 if (drive->dev_flags & IDE_DFLAG_SCSI)
1184 request_module("ide-scsi");
1185 if (drive->media == ide_cdrom || drive->media == ide_optical) 1018 if (drive->media == ide_cdrom || drive->media == ide_optical)
1186 request_module("ide-cd"); 1019 request_module("ide-cd");
1187 if (drive->media == ide_tape) 1020 if (drive->media == ide_tape)
@@ -1237,46 +1070,23 @@ void ide_init_disk(struct gendisk *disk, ide_drive_t *drive)
1237 1070
1238EXPORT_SYMBOL_GPL(ide_init_disk); 1071EXPORT_SYMBOL_GPL(ide_init_disk);
1239 1072
1240static void ide_remove_drive_from_hwgroup(ide_drive_t *drive)
1241{
1242 ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
1243
1244 if (drive == drive->next) {
1245 /* special case: last drive from hwgroup. */
1246 BUG_ON(hwgroup->drive != drive);
1247 hwgroup->drive = NULL;
1248 } else {
1249 ide_drive_t *walk;
1250
1251 walk = hwgroup->drive;
1252 while (walk->next != drive)
1253 walk = walk->next;
1254 walk->next = drive->next;
1255 if (hwgroup->drive == drive) {
1256 hwgroup->drive = drive->next;
1257 hwgroup->hwif = hwgroup->drive->hwif;
1258 }
1259 }
1260 BUG_ON(hwgroup->drive == drive);
1261}
1262
1263static void drive_release_dev (struct device *dev) 1073static void drive_release_dev (struct device *dev)
1264{ 1074{
1265 ide_drive_t *drive = container_of(dev, ide_drive_t, gendev); 1075 ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
1076 ide_hwif_t *hwif = drive->hwif;
1266 1077
1267 ide_proc_unregister_device(drive); 1078 ide_proc_unregister_device(drive);
1268 1079
1269 spin_lock_irq(&ide_lock); 1080 spin_lock_irq(&hwif->lock);
1270 ide_remove_drive_from_hwgroup(drive);
1271 kfree(drive->id); 1081 kfree(drive->id);
1272 drive->id = NULL; 1082 drive->id = NULL;
1273 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 1083 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
1274 /* Messed up locking ... */ 1084 /* Messed up locking ... */
1275 spin_unlock_irq(&ide_lock); 1085 spin_unlock_irq(&hwif->lock);
1276 blk_cleanup_queue(drive->queue); 1086 blk_cleanup_queue(drive->queue);
1277 spin_lock_irq(&ide_lock); 1087 spin_lock_irq(&hwif->lock);
1278 drive->queue = NULL; 1088 drive->queue = NULL;
1279 spin_unlock_irq(&ide_lock); 1089 spin_unlock_irq(&hwif->lock);
1280 1090
1281 complete(&drive->gendev_rel_comp); 1091 complete(&drive->gendev_rel_comp);
1282} 1092}
@@ -1342,17 +1152,17 @@ out:
1342 1152
1343static void hwif_register_devices(ide_hwif_t *hwif) 1153static void hwif_register_devices(ide_hwif_t *hwif)
1344{ 1154{
1155 ide_drive_t *drive;
1345 unsigned int i; 1156 unsigned int i;
1346 1157
1347 for (i = 0; i < MAX_DRIVES; i++) { 1158 ide_port_for_each_dev(i, drive, hwif) {
1348 ide_drive_t *drive = &hwif->drives[i];
1349 struct device *dev = &drive->gendev; 1159 struct device *dev = &drive->gendev;
1350 int ret; 1160 int ret;
1351 1161
1352 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 1162 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1353 continue; 1163 continue;
1354 1164
1355 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i); 1165 dev_set_name(dev, "%u.%u", hwif->index, i);
1356 dev->parent = &hwif->gendev; 1166 dev->parent = &hwif->gendev;
1357 dev->bus = &ide_bus_type; 1167 dev->bus = &ide_bus_type;
1358 dev->driver_data = drive; 1168 dev->driver_data = drive;
@@ -1368,11 +1178,10 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1368static void ide_port_init_devices(ide_hwif_t *hwif) 1178static void ide_port_init_devices(ide_hwif_t *hwif)
1369{ 1179{
1370 const struct ide_port_ops *port_ops = hwif->port_ops; 1180 const struct ide_port_ops *port_ops = hwif->port_ops;
1181 ide_drive_t *drive;
1371 int i; 1182 int i;
1372 1183
1373 for (i = 0; i < MAX_DRIVES; i++) { 1184 ide_port_for_each_dev(i, drive, hwif) {
1374 ide_drive_t *drive = &hwif->drives[i];
1375
1376 drive->dn = i + hwif->channel * 2; 1185 drive->dn = i + hwif->channel * 2;
1377 1186
1378 if (hwif->host_flags & IDE_HFLAG_IO_32BIT) 1187 if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
@@ -1420,6 +1229,8 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1420 if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) { 1229 if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
1421 int rc; 1230 int rc;
1422 1231
1232 hwif->dma_ops = d->dma_ops;
1233
1423 if (d->init_dma) 1234 if (d->init_dma)
1424 rc = d->init_dma(hwif, d); 1235 rc = d->init_dma(hwif, d);
1425 else 1236 else
@@ -1427,22 +1238,21 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1427 1238
1428 if (rc < 0) { 1239 if (rc < 0) {
1429 printk(KERN_INFO "%s: DMA disabled\n", hwif->name); 1240 printk(KERN_INFO "%s: DMA disabled\n", hwif->name);
1241
1242 hwif->dma_ops = NULL;
1430 hwif->dma_base = 0; 1243 hwif->dma_base = 0;
1431 hwif->swdma_mask = 0; 1244 hwif->swdma_mask = 0;
1432 hwif->mwdma_mask = 0; 1245 hwif->mwdma_mask = 0;
1433 hwif->ultra_mask = 0; 1246 hwif->ultra_mask = 0;
1434 } else if (d->dma_ops) 1247 }
1435 hwif->dma_ops = d->dma_ops;
1436 } 1248 }
1437 1249
1438 if ((d->host_flags & IDE_HFLAG_SERIALIZE) || 1250 if ((d->host_flags & IDE_HFLAG_SERIALIZE) ||
1439 ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base)) { 1251 ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base))
1440 if (hwif->mate) 1252 hwif->host->host_flags |= IDE_HFLAG_SERIALIZE;
1441 hwif->mate->serialized = hwif->serialized = 1;
1442 }
1443 1253
1444 if (d->host_flags & IDE_HFLAG_RQSIZE_256) 1254 if (d->max_sectors)
1445 hwif->rqsize = 256; 1255 hwif->rqsize = d->max_sectors;
1446 1256
1447 /* call chipset specific routine for each enabled port */ 1257 /* call chipset specific routine for each enabled port */
1448 if (d->init_hwif) 1258 if (d->init_hwif)
@@ -1459,56 +1269,64 @@ static void ide_port_cable_detect(ide_hwif_t *hwif)
1459 } 1269 }
1460} 1270}
1461 1271
1462static ssize_t store_delete_devices(struct device *portdev, 1272static const u8 ide_hwif_to_major[] =
1463 struct device_attribute *attr, 1273 { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, IDE4_MAJOR,
1464 const char *buf, size_t n) 1274 IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR, IDE8_MAJOR, IDE9_MAJOR };
1465{
1466 ide_hwif_t *hwif = dev_get_drvdata(portdev);
1467
1468 if (strncmp(buf, "1", n))
1469 return -EINVAL;
1470 1275
1471 ide_port_unregister_devices(hwif); 1276static void ide_port_init_devices_data(ide_hwif_t *hwif)
1472 1277{
1473 return n; 1278 ide_drive_t *drive;
1474}; 1279 int i;
1475 1280
1476static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices); 1281 ide_port_for_each_dev(i, drive, hwif) {
1282 u8 j = (hwif->index * MAX_DRIVES) + i;
1283
1284 memset(drive, 0, sizeof(*drive));
1285
1286 drive->media = ide_disk;
1287 drive->select = (i << 4) | ATA_DEVICE_OBS;
1288 drive->hwif = hwif;
1289 drive->ready_stat = ATA_DRDY;
1290 drive->bad_wstat = BAD_W_STAT;
1291 drive->special.b.recalibrate = 1;
1292 drive->special.b.set_geometry = 1;
1293 drive->name[0] = 'h';
1294 drive->name[1] = 'd';
1295 drive->name[2] = 'a' + j;
1296 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
1297
1298 INIT_LIST_HEAD(&drive->list);
1299 init_completion(&drive->gendev_rel_comp);
1300 }
1301}
1477 1302
1478static ssize_t store_scan(struct device *portdev, 1303static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
1479 struct device_attribute *attr,
1480 const char *buf, size_t n)
1481{ 1304{
1482 ide_hwif_t *hwif = dev_get_drvdata(portdev); 1305 /* fill in any non-zero initial values */
1483 1306 hwif->index = index;
1484 if (strncmp(buf, "1", n)) 1307 hwif->major = ide_hwif_to_major[index];
1485 return -EINVAL;
1486 1308
1487 ide_port_unregister_devices(hwif); 1309 hwif->name[0] = 'i';
1488 ide_port_scan(hwif); 1310 hwif->name[1] = 'd';
1311 hwif->name[2] = 'e';
1312 hwif->name[3] = '0' + index;
1489 1313
1490 return n; 1314 init_completion(&hwif->gendev_rel_comp);
1491};
1492 1315
1493static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan); 1316 hwif->tp_ops = &default_tp_ops;
1494 1317
1495static struct device_attribute *ide_port_attrs[] = { 1318 ide_port_init_devices_data(hwif);
1496 &dev_attr_delete_devices, 1319}
1497 &dev_attr_scan,
1498 NULL
1499};
1500 1320
1501static int ide_sysfs_register_port(ide_hwif_t *hwif) 1321static void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
1502{ 1322{
1503 int i, uninitialized_var(rc); 1323 memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
1504 1324 hwif->irq = hw->irq;
1505 for (i = 0; ide_port_attrs[i]; i++) { 1325 hwif->chipset = hw->chipset;
1506 rc = device_create_file(hwif->portdev, ide_port_attrs[i]); 1326 hwif->dev = hw->dev;
1507 if (rc) 1327 hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
1508 break; 1328 hwif->ack_intr = hw->ack_intr;
1509 } 1329 hwif->config_data = hw->config;
1510
1511 return rc;
1512} 1330}
1513 1331
1514static unsigned int ide_indexes; 1332static unsigned int ide_indexes;
@@ -1560,12 +1378,43 @@ static void ide_free_port_slot(int idx)
1560 mutex_unlock(&ide_cfg_mtx); 1378 mutex_unlock(&ide_cfg_mtx);
1561} 1379}
1562 1380
1381static void ide_port_free_devices(ide_hwif_t *hwif)
1382{
1383 ide_drive_t *drive;
1384 int i;
1385
1386 ide_port_for_each_dev(i, drive, hwif)
1387 kfree(drive);
1388}
1389
1390static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
1391{
1392 int i;
1393
1394 for (i = 0; i < MAX_DRIVES; i++) {
1395 ide_drive_t *drive;
1396
1397 drive = kzalloc_node(sizeof(*drive), GFP_KERNEL, node);
1398 if (drive == NULL)
1399 goto out_nomem;
1400
1401 hwif->devices[i] = drive;
1402 }
1403 return 0;
1404
1405out_nomem:
1406 ide_port_free_devices(hwif);
1407 return -ENOMEM;
1408}
1409
1563struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws) 1410struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1564{ 1411{
1565 struct ide_host *host; 1412 struct ide_host *host;
1413 struct device *dev = hws[0] ? hws[0]->dev : NULL;
1414 int node = dev ? dev_to_node(dev) : -1;
1566 int i; 1415 int i;
1567 1416
1568 host = kzalloc(sizeof(*host), GFP_KERNEL); 1417 host = kzalloc_node(sizeof(*host), GFP_KERNEL, node);
1569 if (host == NULL) 1418 if (host == NULL)
1570 return NULL; 1419 return NULL;
1571 1420
@@ -1576,10 +1425,15 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1576 if (hws[i] == NULL) 1425 if (hws[i] == NULL)
1577 continue; 1426 continue;
1578 1427
1579 hwif = kzalloc(sizeof(*hwif), GFP_KERNEL); 1428 hwif = kzalloc_node(sizeof(*hwif), GFP_KERNEL, node);
1580 if (hwif == NULL) 1429 if (hwif == NULL)
1581 continue; 1430 continue;
1582 1431
1432 if (ide_port_alloc_devices(hwif, node) < 0) {
1433 kfree(hwif);
1434 continue;
1435 }
1436
1583 idx = ide_find_port_slot(d); 1437 idx = ide_find_port_slot(d);
1584 if (idx < 0) { 1438 if (idx < 0) {
1585 printk(KERN_ERR "%s: no free slot for interface\n", 1439 printk(KERN_ERR "%s: no free slot for interface\n",
@@ -1601,8 +1455,7 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1601 return NULL; 1455 return NULL;
1602 } 1456 }
1603 1457
1604 if (hws[0]) 1458 host->dev[0] = dev;
1605 host->dev[0] = hws[0]->dev;
1606 1459
1607 if (d) { 1460 if (d) {
1608 host->init_chipset = d->init_chipset; 1461 host->init_chipset = d->init_chipset;
@@ -1619,9 +1472,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1619 ide_hwif_t *hwif, *mate = NULL; 1472 ide_hwif_t *hwif, *mate = NULL;
1620 int i, j = 0; 1473 int i, j = 0;
1621 1474
1622 for (i = 0; i < MAX_HOST_PORTS; i++) { 1475 ide_host_for_each_port(i, hwif, host) {
1623 hwif = host->ports[i];
1624
1625 if (hwif == NULL) { 1476 if (hwif == NULL) {
1626 mate = NULL; 1477 mate = NULL;
1627 continue; 1478 continue;
@@ -1647,9 +1498,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1647 ide_port_init_devices(hwif); 1498 ide_port_init_devices(hwif);
1648 } 1499 }
1649 1500
1650 for (i = 0; i < MAX_HOST_PORTS; i++) { 1501 ide_host_for_each_port(i, hwif, host) {
1651 hwif = host->ports[i];
1652
1653 if (hwif == NULL) 1502 if (hwif == NULL)
1654 continue; 1503 continue;
1655 1504
@@ -1664,9 +1513,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1664 ide_port_tune_devices(hwif); 1513 ide_port_tune_devices(hwif);
1665 } 1514 }
1666 1515
1667 for (i = 0; i < MAX_HOST_PORTS; i++) { 1516 ide_host_for_each_port(i, hwif, host) {
1668 hwif = host->ports[i];
1669
1670 if (hwif == NULL) 1517 if (hwif == NULL)
1671 continue; 1518 continue;
1672 1519
@@ -1691,22 +1538,15 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1691 ide_acpi_port_init_devices(hwif); 1538 ide_acpi_port_init_devices(hwif);
1692 } 1539 }
1693 1540
1694 for (i = 0; i < MAX_HOST_PORTS; i++) { 1541 ide_host_for_each_port(i, hwif, host) {
1695 hwif = host->ports[i];
1696
1697 if (hwif == NULL) 1542 if (hwif == NULL)
1698 continue; 1543 continue;
1699 1544
1700 if (hwif->chipset == ide_unknown)
1701 hwif->chipset = ide_generic;
1702
1703 if (hwif->present) 1545 if (hwif->present)
1704 hwif_register_devices(hwif); 1546 hwif_register_devices(hwif);
1705 } 1547 }
1706 1548
1707 for (i = 0; i < MAX_HOST_PORTS; i++) { 1549 ide_host_for_each_port(i, hwif, host) {
1708 hwif = host->ports[i];
1709
1710 if (hwif == NULL) 1550 if (hwif == NULL)
1711 continue; 1551 continue;
1712 1552
@@ -1744,17 +1584,85 @@ int ide_host_add(const struct ide_port_info *d, hw_regs_t **hws,
1744} 1584}
1745EXPORT_SYMBOL_GPL(ide_host_add); 1585EXPORT_SYMBOL_GPL(ide_host_add);
1746 1586
1587static void __ide_port_unregister_devices(ide_hwif_t *hwif)
1588{
1589 ide_drive_t *drive;
1590 int i;
1591
1592 ide_port_for_each_dev(i, drive, hwif) {
1593 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
1594 device_unregister(&drive->gendev);
1595 wait_for_completion(&drive->gendev_rel_comp);
1596 }
1597 }
1598}
1599
1600void ide_port_unregister_devices(ide_hwif_t *hwif)
1601{
1602 mutex_lock(&ide_cfg_mtx);
1603 __ide_port_unregister_devices(hwif);
1604 hwif->present = 0;
1605 ide_port_init_devices_data(hwif);
1606 mutex_unlock(&ide_cfg_mtx);
1607}
1608EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
1609
1610/**
1611 * ide_unregister - free an IDE interface
1612 * @hwif: IDE interface
1613 *
1614 * Perform the final unregister of an IDE interface.
1615 *
1616 * Locking:
1617 * The caller must not hold the IDE locks.
1618 *
1619 * It is up to the caller to be sure there is no pending I/O here,
1620 * and that the interface will not be reopened (present/vanishing
1621 * locking isn't yet done BTW).
1622 */
1623
1624static void ide_unregister(ide_hwif_t *hwif)
1625{
1626 BUG_ON(in_interrupt());
1627 BUG_ON(irqs_disabled());
1628
1629 mutex_lock(&ide_cfg_mtx);
1630
1631 if (hwif->present) {
1632 __ide_port_unregister_devices(hwif);
1633 hwif->present = 0;
1634 }
1635
1636 ide_proc_unregister_port(hwif);
1637
1638 free_irq(hwif->irq, hwif);
1639
1640 device_unregister(hwif->portdev);
1641 device_unregister(&hwif->gendev);
1642 wait_for_completion(&hwif->gendev_rel_comp);
1643
1644 /*
1645 * Remove us from the kernel's knowledge
1646 */
1647 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
1648 kfree(hwif->sg_table);
1649 unregister_blkdev(hwif->major, hwif->name);
1650
1651 ide_release_dma_engine(hwif);
1652
1653 mutex_unlock(&ide_cfg_mtx);
1654}
1655
1747void ide_host_free(struct ide_host *host) 1656void ide_host_free(struct ide_host *host)
1748{ 1657{
1749 ide_hwif_t *hwif; 1658 ide_hwif_t *hwif;
1750 int i; 1659 int i;
1751 1660
1752 for (i = 0; i < MAX_HOST_PORTS; i++) { 1661 ide_host_for_each_port(i, hwif, host) {
1753 hwif = host->ports[i];
1754
1755 if (hwif == NULL) 1662 if (hwif == NULL)
1756 continue; 1663 continue;
1757 1664
1665 ide_port_free_devices(hwif);
1758 ide_free_port_slot(hwif->index); 1666 ide_free_port_slot(hwif->index);
1759 kfree(hwif); 1667 kfree(hwif);
1760 } 1668 }
@@ -1765,11 +1673,12 @@ EXPORT_SYMBOL_GPL(ide_host_free);
1765 1673
1766void ide_host_remove(struct ide_host *host) 1674void ide_host_remove(struct ide_host *host)
1767{ 1675{
1676 ide_hwif_t *hwif;
1768 int i; 1677 int i;
1769 1678
1770 for (i = 0; i < MAX_HOST_PORTS; i++) { 1679 ide_host_for_each_port(i, hwif, host) {
1771 if (host->ports[i]) 1680 if (hwif)
1772 ide_unregister(host->ports[i]); 1681 ide_unregister(hwif);
1773 } 1682 }
1774 1683
1775 ide_host_free(host); 1684 ide_host_free(host);
@@ -1788,65 +1697,9 @@ void ide_port_scan(ide_hwif_t *hwif)
1788 hwif->present = 1; 1697 hwif->present = 1;
1789 1698
1790 ide_port_tune_devices(hwif); 1699 ide_port_tune_devices(hwif);
1791 ide_acpi_port_init_devices(hwif);
1792 ide_port_setup_devices(hwif); 1700 ide_port_setup_devices(hwif);
1701 ide_acpi_port_init_devices(hwif);
1793 hwif_register_devices(hwif); 1702 hwif_register_devices(hwif);
1794 ide_proc_port_register_devices(hwif); 1703 ide_proc_port_register_devices(hwif);
1795} 1704}
1796EXPORT_SYMBOL_GPL(ide_port_scan); 1705EXPORT_SYMBOL_GPL(ide_port_scan);
1797
1798static void ide_legacy_init_one(hw_regs_t **hws, hw_regs_t *hw,
1799 u8 port_no, const struct ide_port_info *d,
1800 unsigned long config)
1801{
1802 unsigned long base, ctl;
1803 int irq;
1804
1805 if (port_no == 0) {
1806 base = 0x1f0;
1807 ctl = 0x3f6;
1808 irq = 14;
1809 } else {
1810 base = 0x170;
1811 ctl = 0x376;
1812 irq = 15;
1813 }
1814
1815 if (!request_region(base, 8, d->name)) {
1816 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
1817 d->name, base, base + 7);
1818 return;
1819 }
1820
1821 if (!request_region(ctl, 1, d->name)) {
1822 printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
1823 d->name, ctl);
1824 release_region(base, 8);
1825 return;
1826 }
1827
1828 ide_std_init_ports(hw, base, ctl);
1829 hw->irq = irq;
1830 hw->chipset = d->chipset;
1831 hw->config = config;
1832
1833 hws[port_no] = hw;
1834}
1835
1836int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config)
1837{
1838 hw_regs_t hw[2], *hws[] = { NULL, NULL, NULL, NULL };
1839
1840 memset(&hw, 0, sizeof(hw));
1841
1842 if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0)
1843 ide_legacy_init_one(hws, &hw[0], 0, d, config);
1844 ide_legacy_init_one(hws, &hw[1], 1, d, config);
1845
1846 if (hws[0] == NULL && hws[1] == NULL &&
1847 (d->host_flags & IDE_HFLAG_SINGLE))
1848 return -ENOENT;
1849
1850 return ide_host_add(d, hws, NULL);
1851}
1852EXPORT_SYMBOL_GPL(ide_legacy_device_add);
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index f3cddd1b2f8f..1d8978b3314a 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -46,10 +46,6 @@ static int proc_ide_read_imodel
46 case ide_qd65xx: name = "qd65xx"; break; 46 case ide_qd65xx: name = "qd65xx"; break;
47 case ide_umc8672: name = "umc8672"; break; 47 case ide_umc8672: name = "umc8672"; break;
48 case ide_ht6560b: name = "ht6560b"; break; 48 case ide_ht6560b: name = "ht6560b"; break;
49 case ide_rz1000: name = "rz1000"; break;
50 case ide_trm290: name = "trm290"; break;
51 case ide_cmd646: name = "cmd646"; break;
52 case ide_cy82c693: name = "cy82c693"; break;
53 case ide_4drives: name = "4drives"; break; 49 case ide_4drives: name = "4drives"; break;
54 case ide_pmac: name = "mac-io"; break; 50 case ide_pmac: name = "mac-io"; break;
55 case ide_au1xxx: name = "au1xxx"; break; 51 case ide_au1xxx: name = "au1xxx"; break;
@@ -155,13 +151,8 @@ static int ide_read_setting(ide_drive_t *drive,
155 const struct ide_devset *ds = setting->setting; 151 const struct ide_devset *ds = setting->setting;
156 int val = -EINVAL; 152 int val = -EINVAL;
157 153
158 if (ds->get) { 154 if (ds->get)
159 unsigned long flags;
160
161 spin_lock_irqsave(&ide_lock, flags);
162 val = ds->get(drive); 155 val = ds->get(drive);
163 spin_unlock_irqrestore(&ide_lock, flags);
164 }
165 156
166 return val; 157 return val;
167} 158}
@@ -448,13 +439,13 @@ static int proc_ide_read_dmodel
448static int proc_ide_read_driver 439static int proc_ide_read_driver
449 (char *page, char **start, off_t off, int count, int *eof, void *data) 440 (char *page, char **start, off_t off, int count, int *eof, void *data)
450{ 441{
451 ide_drive_t *drive = (ide_drive_t *) data; 442 ide_drive_t *drive = (ide_drive_t *)data;
452 struct device *dev = &drive->gendev; 443 struct device *dev = &drive->gendev;
453 ide_driver_t *ide_drv; 444 struct ide_driver *ide_drv;
454 int len; 445 int len;
455 446
456 if (dev->driver) { 447 if (dev->driver) {
457 ide_drv = container_of(dev->driver, ide_driver_t, gen_driver); 448 ide_drv = to_ide_driver(dev->driver);
458 len = sprintf(page, "%s version %s\n", 449 len = sprintf(page, "%s version %s\n",
459 dev->driver->name, ide_drv->version); 450 dev->driver->name, ide_drv->version);
460 } else 451 } else
@@ -564,7 +555,7 @@ static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t
564 } 555 }
565} 556}
566 557
567void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver) 558void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver)
568{ 559{
569 mutex_lock(&ide_setting_mtx); 560 mutex_lock(&ide_setting_mtx);
570 drive->settings = driver->proc_devsets(drive); 561 drive->settings = driver->proc_devsets(drive);
@@ -583,45 +574,32 @@ EXPORT_SYMBOL(ide_proc_register_driver);
583 * Clean up the driver specific /proc files and IDE settings 574 * Clean up the driver specific /proc files and IDE settings
584 * for a given drive. 575 * for a given drive.
585 * 576 *
586 * Takes ide_setting_mtx and ide_lock. 577 * Takes ide_setting_mtx.
587 * Caller must hold none of the locks.
588 */ 578 */
589 579
590void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver) 580void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver)
591{ 581{
592 unsigned long flags;
593
594 ide_remove_proc_entries(drive->proc, driver->proc_entries(drive)); 582 ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
595 583
596 mutex_lock(&ide_setting_mtx); 584 mutex_lock(&ide_setting_mtx);
597 spin_lock_irqsave(&ide_lock, flags);
598 /* 585 /*
599 * ide_setting_mtx protects the settings list 586 * ide_setting_mtx protects both the settings list and the use
600 * ide_lock protects the use of settings 587 * of settings (we cannot take a setting out that is being used).
601 *
602 * so we need to hold both, ide_settings_sem because we want to
603 * modify the settings list, and ide_lock because we cannot take
604 * a setting out that is being used.
605 *
606 * OTOH both ide_{read,write}_setting are only ever used under
607 * ide_setting_mtx.
608 */ 588 */
609 drive->settings = NULL; 589 drive->settings = NULL;
610 spin_unlock_irqrestore(&ide_lock, flags);
611 mutex_unlock(&ide_setting_mtx); 590 mutex_unlock(&ide_setting_mtx);
612} 591}
613EXPORT_SYMBOL(ide_proc_unregister_driver); 592EXPORT_SYMBOL(ide_proc_unregister_driver);
614 593
615void ide_proc_port_register_devices(ide_hwif_t *hwif) 594void ide_proc_port_register_devices(ide_hwif_t *hwif)
616{ 595{
617 int d;
618 struct proc_dir_entry *ent; 596 struct proc_dir_entry *ent;
619 struct proc_dir_entry *parent = hwif->proc; 597 struct proc_dir_entry *parent = hwif->proc;
598 ide_drive_t *drive;
620 char name[64]; 599 char name[64];
600 int i;
621 601
622 for (d = 0; d < MAX_DRIVES; d++) { 602 ide_port_for_each_dev(i, drive, hwif) {
623 ide_drive_t *drive = &hwif->drives[d];
624
625 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc) 603 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
626 continue; 604 continue;
627 605
@@ -674,7 +652,7 @@ void ide_proc_unregister_port(ide_hwif_t *hwif)
674 652
675static int proc_print_driver(struct device_driver *drv, void *data) 653static int proc_print_driver(struct device_driver *drv, void *data)
676{ 654{
677 ide_driver_t *ide_drv = container_of(drv, ide_driver_t, gen_driver); 655 struct ide_driver *ide_drv = to_ide_driver(drv);
678 struct seq_file *s = data; 656 struct seq_file *s = data;
679 657
680 seq_printf(s, "%s version %s\n", drv->name, ide_drv->version); 658 seq_printf(s, "%s version %s\n", drv->name, ide_drv->version);
diff --git a/drivers/ide/ide-sysfs.c b/drivers/ide/ide-sysfs.c
new file mode 100644
index 000000000000..883ffacaf45a
--- /dev/null
+++ b/drivers/ide/ide-sysfs.c
@@ -0,0 +1,125 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3
4char *ide_media_string(ide_drive_t *drive)
5{
6 switch (drive->media) {
7 case ide_disk:
8 return "disk";
9 case ide_cdrom:
10 return "cdrom";
11 case ide_tape:
12 return "tape";
13 case ide_floppy:
14 return "floppy";
15 case ide_optical:
16 return "optical";
17 default:
18 return "UNKNOWN";
19 }
20}
21
22static ssize_t media_show(struct device *dev, struct device_attribute *attr,
23 char *buf)
24{
25 ide_drive_t *drive = to_ide_device(dev);
26 return sprintf(buf, "%s\n", ide_media_string(drive));
27}
28
29static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
30 char *buf)
31{
32 ide_drive_t *drive = to_ide_device(dev);
33 return sprintf(buf, "%s\n", drive->name);
34}
35
36static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
37 char *buf)
38{
39 ide_drive_t *drive = to_ide_device(dev);
40 return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
41}
42
43static ssize_t model_show(struct device *dev, struct device_attribute *attr,
44 char *buf)
45{
46 ide_drive_t *drive = to_ide_device(dev);
47 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
48}
49
50static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
51 char *buf)
52{
53 ide_drive_t *drive = to_ide_device(dev);
54 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
55}
56
57static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
58 char *buf)
59{
60 ide_drive_t *drive = to_ide_device(dev);
61 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
62}
63
64struct device_attribute ide_dev_attrs[] = {
65 __ATTR_RO(media),
66 __ATTR_RO(drivename),
67 __ATTR_RO(modalias),
68 __ATTR_RO(model),
69 __ATTR_RO(firmware),
70 __ATTR(serial, 0400, serial_show, NULL),
71 __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
72 __ATTR_NULL
73};
74
75static ssize_t store_delete_devices(struct device *portdev,
76 struct device_attribute *attr,
77 const char *buf, size_t n)
78{
79 ide_hwif_t *hwif = dev_get_drvdata(portdev);
80
81 if (strncmp(buf, "1", n))
82 return -EINVAL;
83
84 ide_port_unregister_devices(hwif);
85
86 return n;
87};
88
89static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
90
91static ssize_t store_scan(struct device *portdev,
92 struct device_attribute *attr,
93 const char *buf, size_t n)
94{
95 ide_hwif_t *hwif = dev_get_drvdata(portdev);
96
97 if (strncmp(buf, "1", n))
98 return -EINVAL;
99
100 ide_port_unregister_devices(hwif);
101 ide_port_scan(hwif);
102
103 return n;
104};
105
106static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
107
108static struct device_attribute *ide_port_attrs[] = {
109 &dev_attr_delete_devices,
110 &dev_attr_scan,
111 NULL
112};
113
114int ide_sysfs_register_port(ide_hwif_t *hwif)
115{
116 int i, uninitialized_var(rc);
117
118 for (i = 0; ide_port_attrs[i]; i++) {
119 rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
120 if (rc)
121 break;
122 }
123
124 return rc;
125}
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index a2d470eb2b55..d7ecd3c79757 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -166,10 +166,10 @@ struct idetape_bh {
166 * to an interrupt or a timer event is stored in the struct defined below. 166 * to an interrupt or a timer event is stored in the struct defined below.
167 */ 167 */
168typedef struct ide_tape_obj { 168typedef struct ide_tape_obj {
169 ide_drive_t *drive; 169 ide_drive_t *drive;
170 ide_driver_t *driver; 170 struct ide_driver *driver;
171 struct gendisk *disk; 171 struct gendisk *disk;
172 struct kref kref; 172 struct kref kref;
173 173
174 /* 174 /*
175 * failed_pc points to the last failed packet command, or contains 175 * failed_pc points to the last failed packet command, or contains
@@ -479,7 +479,7 @@ static void ide_tape_kfree_buffer(idetape_tape_t *tape)
479 479
480static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) 480static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
481{ 481{
482 struct request *rq = HWGROUP(drive)->rq; 482 struct request *rq = drive->hwif->rq;
483 idetape_tape_t *tape = drive->driver_data; 483 idetape_tape_t *tape = drive->driver_data;
484 unsigned long flags; 484 unsigned long flags;
485 int error; 485 int error;
@@ -531,7 +531,7 @@ static void ide_tape_callback(ide_drive_t *drive, int dsc)
531 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE " 531 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
532 "itself - Aborting request!\n"); 532 "itself - Aborting request!\n");
533 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { 533 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
534 struct request *rq = drive->hwif->hwgroup->rq; 534 struct request *rq = drive->hwif->rq;
535 int blocks = pc->xferred / tape->blk_size; 535 int blocks = pc->xferred / tape->blk_size;
536 536
537 tape->avg_size += blocks * tape->blk_size; 537 tape->avg_size += blocks * tape->blk_size;
@@ -576,7 +576,7 @@ static void ide_tape_callback(ide_drive_t *drive, int dsc)
576 576
577/* 577/*
578 * Postpone the current request so that ide.c will be able to service requests 578 * Postpone the current request so that ide.c will be able to service requests
579 * from another device on the same hwgroup while we are polling for DSC. 579 * from another device on the same port while we are polling for DSC.
580 */ 580 */
581static void idetape_postpone_request(ide_drive_t *drive) 581static void idetape_postpone_request(ide_drive_t *drive)
582{ 582{
@@ -584,7 +584,8 @@ static void idetape_postpone_request(ide_drive_t *drive)
584 584
585 debug_log(DBG_PROCS, "Enter %s\n", __func__); 585 debug_log(DBG_PROCS, "Enter %s\n", __func__);
586 586
587 tape->postponed_rq = HWGROUP(drive)->rq; 587 tape->postponed_rq = drive->hwif->rq;
588
588 ide_stall_queue(drive, tape->dsc_poll_freq); 589 ide_stall_queue(drive, tape->dsc_poll_freq);
589} 590}
590 591
@@ -694,7 +695,7 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
694 695
695 pc->retries++; 696 pc->retries++;
696 697
697 return ide_issue_pc(drive, WAIT_TAPE_CMD, NULL); 698 return ide_issue_pc(drive);
698} 699}
699 700
700/* A mode sense command is used to "sense" tape parameters. */ 701/* A mode sense command is used to "sense" tape parameters. */
@@ -2312,7 +2313,7 @@ static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive)
2312 2313
2313static int ide_tape_probe(ide_drive_t *); 2314static int ide_tape_probe(ide_drive_t *);
2314 2315
2315static ide_driver_t idetape_driver = { 2316static struct ide_driver idetape_driver = {
2316 .gen_driver = { 2317 .gen_driver = {
2317 .owner = THIS_MODULE, 2318 .owner = THIS_MODULE,
2318 .name = "ide-tape", 2319 .name = "ide-tape",
@@ -2323,7 +2324,6 @@ static ide_driver_t idetape_driver = {
2323 .version = IDETAPE_VERSION, 2324 .version = IDETAPE_VERSION,
2324 .do_request = idetape_do_request, 2325 .do_request = idetape_do_request,
2325 .end_request = idetape_end_request, 2326 .end_request = idetape_end_request,
2326 .error = __ide_error,
2327#ifdef CONFIG_IDE_PROC_FS 2327#ifdef CONFIG_IDE_PROC_FS
2328 .proc_entries = ide_tape_proc_entries, 2328 .proc_entries = ide_tape_proc_entries,
2329 .proc_devsets = ide_tape_proc_devsets, 2329 .proc_devsets = ide_tape_proc_devsets,
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index bf4fb9d8d176..16138bce84a7 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -58,7 +58,7 @@ static ide_startstop_t task_in_intr(ide_drive_t *);
58 58
59ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task) 59ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
60{ 60{
61 ide_hwif_t *hwif = HWIF(drive); 61 ide_hwif_t *hwif = drive->hwif;
62 struct ide_taskfile *tf = &task->tf; 62 struct ide_taskfile *tf = &task->tf;
63 ide_handler_t *handler = NULL; 63 ide_handler_t *handler = NULL;
64 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 64 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
@@ -309,9 +309,9 @@ static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
309 } 309 }
310 310
311 if (sectors > 0) { 311 if (sectors > 0) {
312 ide_driver_t *drv; 312 struct ide_driver *drv;
313 313
314 drv = *(ide_driver_t **)rq->rq_disk->private_data; 314 drv = *(struct ide_driver **)rq->rq_disk->private_data;
315 drv->end_request(drive, 1, sectors); 315 drv->end_request(drive, 1, sectors);
316 } 316 }
317 } 317 }
@@ -328,9 +328,9 @@ void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
328 } 328 }
329 329
330 if (rq->rq_disk) { 330 if (rq->rq_disk) {
331 ide_driver_t *drv; 331 struct ide_driver *drv;
332 332
333 drv = *(ide_driver_t **)rq->rq_disk->private_data;; 333 drv = *(struct ide_driver **)rq->rq_disk->private_data;;
334 drv->end_request(drive, 1, rq->nr_sectors); 334 drv->end_request(drive, 1, rq->nr_sectors);
335 } else 335 } else
336 ide_end_request(drive, 1, rq->nr_sectors); 336 ide_end_request(drive, 1, rq->nr_sectors);
@@ -361,7 +361,7 @@ static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq
361static ide_startstop_t task_in_intr(ide_drive_t *drive) 361static ide_startstop_t task_in_intr(ide_drive_t *drive)
362{ 362{
363 ide_hwif_t *hwif = drive->hwif; 363 ide_hwif_t *hwif = drive->hwif;
364 struct request *rq = hwif->hwgroup->rq; 364 struct request *rq = hwif->rq;
365 u8 stat = hwif->tp_ops->read_status(hwif); 365 u8 stat = hwif->tp_ops->read_status(hwif);
366 366
367 /* Error? */ 367 /* Error? */
@@ -395,7 +395,7 @@ static ide_startstop_t task_in_intr(ide_drive_t *drive)
395static ide_startstop_t task_out_intr (ide_drive_t *drive) 395static ide_startstop_t task_out_intr (ide_drive_t *drive)
396{ 396{
397 ide_hwif_t *hwif = drive->hwif; 397 ide_hwif_t *hwif = drive->hwif;
398 struct request *rq = HWGROUP(drive)->rq; 398 struct request *rq = hwif->rq;
399 u8 stat = hwif->tp_ops->read_status(hwif); 399 u8 stat = hwif->tp_ops->read_status(hwif);
400 400
401 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) 401 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 04f8f13cb9d7..258805da15c3 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -60,189 +60,8 @@
60#include <linux/completion.h> 60#include <linux/completion.h>
61#include <linux/device.h> 61#include <linux/device.h>
62 62
63
64/* default maximum number of failures */
65#define IDE_DEFAULT_MAX_FAILURES 1
66
67struct class *ide_port_class; 63struct class *ide_port_class;
68 64
69static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
70 IDE2_MAJOR, IDE3_MAJOR,
71 IDE4_MAJOR, IDE5_MAJOR,
72 IDE6_MAJOR, IDE7_MAJOR,
73 IDE8_MAJOR, IDE9_MAJOR };
74
75DEFINE_MUTEX(ide_cfg_mtx);
76
77__cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
78EXPORT_SYMBOL(ide_lock);
79
80static void ide_port_init_devices_data(ide_hwif_t *);
81
82/*
83 * Do not even *think* about calling this!
84 */
85void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
86{
87 /* bulk initialize hwif & drive info with zeros */
88 memset(hwif, 0, sizeof(ide_hwif_t));
89
90 /* fill in any non-zero initial values */
91 hwif->index = index;
92 hwif->major = ide_hwif_to_major[index];
93
94 hwif->name[0] = 'i';
95 hwif->name[1] = 'd';
96 hwif->name[2] = 'e';
97 hwif->name[3] = '0' + index;
98
99 init_completion(&hwif->gendev_rel_comp);
100
101 hwif->tp_ops = &default_tp_ops;
102
103 ide_port_init_devices_data(hwif);
104}
105
106static void ide_port_init_devices_data(ide_hwif_t *hwif)
107{
108 int unit;
109
110 for (unit = 0; unit < MAX_DRIVES; ++unit) {
111 ide_drive_t *drive = &hwif->drives[unit];
112 u8 j = (hwif->index * MAX_DRIVES) + unit;
113
114 memset(drive, 0, sizeof(*drive));
115
116 drive->media = ide_disk;
117 drive->select = (unit << 4) | ATA_DEVICE_OBS;
118 drive->hwif = hwif;
119 drive->ready_stat = ATA_DRDY;
120 drive->bad_wstat = BAD_W_STAT;
121 drive->special.b.recalibrate = 1;
122 drive->special.b.set_geometry = 1;
123 drive->name[0] = 'h';
124 drive->name[1] = 'd';
125 drive->name[2] = 'a' + j;
126 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
127
128 INIT_LIST_HEAD(&drive->list);
129 init_completion(&drive->gendev_rel_comp);
130 }
131}
132
133/* Called with ide_lock held. */
134static void __ide_port_unregister_devices(ide_hwif_t *hwif)
135{
136 int i;
137
138 for (i = 0; i < MAX_DRIVES; i++) {
139 ide_drive_t *drive = &hwif->drives[i];
140
141 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
142 spin_unlock_irq(&ide_lock);
143 device_unregister(&drive->gendev);
144 wait_for_completion(&drive->gendev_rel_comp);
145 spin_lock_irq(&ide_lock);
146 }
147 }
148}
149
150void ide_port_unregister_devices(ide_hwif_t *hwif)
151{
152 mutex_lock(&ide_cfg_mtx);
153 spin_lock_irq(&ide_lock);
154 __ide_port_unregister_devices(hwif);
155 hwif->present = 0;
156 ide_port_init_devices_data(hwif);
157 spin_unlock_irq(&ide_lock);
158 mutex_unlock(&ide_cfg_mtx);
159}
160EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
161
162/**
163 * ide_unregister - free an IDE interface
164 * @hwif: IDE interface
165 *
166 * Perform the final unregister of an IDE interface. At the moment
167 * we don't refcount interfaces so this will also get split up.
168 *
169 * Locking:
170 * The caller must not hold the IDE locks
171 * The drive present/vanishing is not yet properly locked
172 * Take care with the callbacks. These have been split to avoid
173 * deadlocking the IDE layer. The shutdown callback is called
174 * before we take the lock and free resources. It is up to the
175 * caller to be sure there is no pending I/O here, and that
176 * the interface will not be reopened (present/vanishing locking
177 * isn't yet done BTW). After we commit to the final kill we
178 * call the cleanup callback with the ide locks held.
179 *
180 * Unregister restores the hwif structures to the default state.
181 * This is raving bonkers.
182 */
183
184void ide_unregister(ide_hwif_t *hwif)
185{
186 ide_hwif_t *g;
187 ide_hwgroup_t *hwgroup;
188 int irq_count = 0;
189
190 BUG_ON(in_interrupt());
191 BUG_ON(irqs_disabled());
192
193 mutex_lock(&ide_cfg_mtx);
194
195 spin_lock_irq(&ide_lock);
196 if (hwif->present) {
197 __ide_port_unregister_devices(hwif);
198 hwif->present = 0;
199 }
200 spin_unlock_irq(&ide_lock);
201
202 ide_proc_unregister_port(hwif);
203
204 hwgroup = hwif->hwgroup;
205 /*
206 * free the irq if we were the only hwif using it
207 */
208 g = hwgroup->hwif;
209 do {
210 if (g->irq == hwif->irq)
211 ++irq_count;
212 g = g->next;
213 } while (g != hwgroup->hwif);
214 if (irq_count == 1)
215 free_irq(hwif->irq, hwgroup);
216
217 ide_remove_port_from_hwgroup(hwif);
218
219 device_unregister(hwif->portdev);
220 device_unregister(&hwif->gendev);
221 wait_for_completion(&hwif->gendev_rel_comp);
222
223 /*
224 * Remove us from the kernel's knowledge
225 */
226 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
227 kfree(hwif->sg_table);
228 unregister_blkdev(hwif->major, hwif->name);
229
230 ide_release_dma_engine(hwif);
231
232 mutex_unlock(&ide_cfg_mtx);
233}
234
235void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
236{
237 memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
238 hwif->irq = hw->irq;
239 hwif->chipset = hw->chipset;
240 hwif->dev = hw->dev;
241 hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
242 hwif->ack_intr = hw->ack_intr;
243 hwif->config_data = hw->config;
244}
245
246/* 65/*
247 * Locks for IDE setting functionality 66 * Locks for IDE setting functionality
248 */ 67 */
@@ -354,9 +173,9 @@ static int set_pio_mode(ide_drive_t *drive, int arg)
354 unsigned long flags; 173 unsigned long flags;
355 174
356 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */ 175 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
357 spin_lock_irqsave(&ide_lock, flags); 176 spin_lock_irqsave(&hwif->lock, flags);
358 port_ops->set_pio_mode(drive, arg); 177 port_ops->set_pio_mode(drive, arg);
359 spin_unlock_irqrestore(&ide_lock, flags); 178 spin_unlock_irqrestore(&hwif->lock, flags);
360 } else 179 } else
361 port_ops->set_pio_mode(drive, arg); 180 port_ops->set_pio_mode(drive, arg);
362 } else { 181 } else {
@@ -397,80 +216,6 @@ ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
397ide_ext_devset_rw_sync(using_dma, using_dma); 216ide_ext_devset_rw_sync(using_dma, using_dma);
398__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode); 217__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
399 218
400static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
401{
402 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
403 ide_hwif_t *hwif = HWIF(drive);
404 struct request *rq;
405 struct request_pm_state rqpm;
406 ide_task_t args;
407 int ret;
408
409 /* call ACPI _GTM only once */
410 if ((drive->dn & 1) == 0 || pair == NULL)
411 ide_acpi_get_timing(hwif);
412
413 memset(&rqpm, 0, sizeof(rqpm));
414 memset(&args, 0, sizeof(args));
415 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
416 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
417 rq->special = &args;
418 rq->data = &rqpm;
419 rqpm.pm_step = IDE_PM_START_SUSPEND;
420 if (mesg.event == PM_EVENT_PRETHAW)
421 mesg.event = PM_EVENT_FREEZE;
422 rqpm.pm_state = mesg.event;
423
424 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
425 blk_put_request(rq);
426
427 /* call ACPI _PS3 only after both devices are suspended */
428 if (ret == 0 && ((drive->dn & 1) || pair == NULL))
429 ide_acpi_set_state(hwif, 0);
430
431 return ret;
432}
433
434static int generic_ide_resume(struct device *dev)
435{
436 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
437 ide_hwif_t *hwif = HWIF(drive);
438 struct request *rq;
439 struct request_pm_state rqpm;
440 ide_task_t args;
441 int err;
442
443 /* call ACPI _PS0 / _STM only once */
444 if ((drive->dn & 1) == 0 || pair == NULL) {
445 ide_acpi_set_state(hwif, 1);
446 ide_acpi_push_timing(hwif);
447 }
448
449 ide_acpi_exec_tfs(drive);
450
451 memset(&rqpm, 0, sizeof(rqpm));
452 memset(&args, 0, sizeof(args));
453 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
454 rq->cmd_type = REQ_TYPE_PM_RESUME;
455 rq->cmd_flags |= REQ_PREEMPT;
456 rq->special = &args;
457 rq->data = &rqpm;
458 rqpm.pm_step = IDE_PM_START_RESUME;
459 rqpm.pm_state = PM_EVENT_ON;
460
461 err = blk_execute_rq(drive->queue, NULL, rq, 1);
462 blk_put_request(rq);
463
464 if (err == 0 && dev->driver) {
465 ide_driver_t *drv = to_ide_driver(dev->driver);
466
467 if (drv->resume)
468 drv->resume(drive);
469 }
470
471 return err;
472}
473
474/** 219/**
475 * ide_device_get - get an additional reference to a ide_drive_t 220 * ide_device_get - get an additional reference to a ide_drive_t
476 * @drive: device to get a reference to 221 * @drive: device to get a reference to
@@ -523,88 +268,20 @@ static int ide_bus_match(struct device *dev, struct device_driver *drv)
523 return 1; 268 return 1;
524} 269}
525 270
526static char *media_string(ide_drive_t *drive)
527{
528 switch (drive->media) {
529 case ide_disk:
530 return "disk";
531 case ide_cdrom:
532 return "cdrom";
533 case ide_tape:
534 return "tape";
535 case ide_floppy:
536 return "floppy";
537 case ide_optical:
538 return "optical";
539 default:
540 return "UNKNOWN";
541 }
542}
543
544static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
545{
546 ide_drive_t *drive = to_ide_device(dev);
547 return sprintf(buf, "%s\n", media_string(drive));
548}
549
550static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
551{
552 ide_drive_t *drive = to_ide_device(dev);
553 return sprintf(buf, "%s\n", drive->name);
554}
555
556static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
557{
558 ide_drive_t *drive = to_ide_device(dev);
559 return sprintf(buf, "ide:m-%s\n", media_string(drive));
560}
561
562static ssize_t model_show(struct device *dev, struct device_attribute *attr,
563 char *buf)
564{
565 ide_drive_t *drive = to_ide_device(dev);
566 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
567}
568
569static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
570 char *buf)
571{
572 ide_drive_t *drive = to_ide_device(dev);
573 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
574}
575
576static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
577 char *buf)
578{
579 ide_drive_t *drive = to_ide_device(dev);
580 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
581}
582
583static struct device_attribute ide_dev_attrs[] = {
584 __ATTR_RO(media),
585 __ATTR_RO(drivename),
586 __ATTR_RO(modalias),
587 __ATTR_RO(model),
588 __ATTR_RO(firmware),
589 __ATTR(serial, 0400, serial_show, NULL),
590 __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
591 __ATTR_NULL
592};
593
594static int ide_uevent(struct device *dev, struct kobj_uevent_env *env) 271static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
595{ 272{
596 ide_drive_t *drive = to_ide_device(dev); 273 ide_drive_t *drive = to_ide_device(dev);
597 274
598 add_uevent_var(env, "MEDIA=%s", media_string(drive)); 275 add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
599 add_uevent_var(env, "DRIVENAME=%s", drive->name); 276 add_uevent_var(env, "DRIVENAME=%s", drive->name);
600 add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive)); 277 add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
601 return 0; 278 return 0;
602} 279}
603 280
604static int generic_ide_probe(struct device *dev) 281static int generic_ide_probe(struct device *dev)
605{ 282{
606 ide_drive_t *drive = to_ide_device(dev); 283 ide_drive_t *drive = to_ide_device(dev);
607 ide_driver_t *drv = to_ide_driver(dev->driver); 284 struct ide_driver *drv = to_ide_driver(dev->driver);
608 285
609 return drv->probe ? drv->probe(drive) : -ENODEV; 286 return drv->probe ? drv->probe(drive) : -ENODEV;
610} 287}
@@ -612,7 +289,7 @@ static int generic_ide_probe(struct device *dev)
612static int generic_ide_remove(struct device *dev) 289static int generic_ide_remove(struct device *dev)
613{ 290{
614 ide_drive_t *drive = to_ide_device(dev); 291 ide_drive_t *drive = to_ide_device(dev);
615 ide_driver_t *drv = to_ide_driver(dev->driver); 292 struct ide_driver *drv = to_ide_driver(dev->driver);
616 293
617 if (drv->remove) 294 if (drv->remove)
618 drv->remove(drive); 295 drv->remove(drive);
@@ -623,7 +300,7 @@ static int generic_ide_remove(struct device *dev)
623static void generic_ide_shutdown(struct device *dev) 300static void generic_ide_shutdown(struct device *dev)
624{ 301{
625 ide_drive_t *drive = to_ide_device(dev); 302 ide_drive_t *drive = to_ide_device(dev);
626 ide_driver_t *drv = to_ide_driver(dev->driver); 303 struct ide_driver *drv = to_ide_driver(dev->driver);
627 304
628 if (dev->driver && drv->shutdown) 305 if (dev->driver && drv->shutdown)
629 drv->shutdown(drive); 306 drv->shutdown(drive);
@@ -811,6 +488,7 @@ MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
811 488
812void ide_port_apply_params(ide_hwif_t *hwif) 489void ide_port_apply_params(ide_hwif_t *hwif)
813{ 490{
491 ide_drive_t *drive;
814 int i; 492 int i;
815 493
816 if (ide_ignore_cable & (1 << hwif->index)) { 494 if (ide_ignore_cable & (1 << hwif->index)) {
@@ -819,8 +497,8 @@ void ide_port_apply_params(ide_hwif_t *hwif)
819 hwif->cbl = ATA_CBL_PATA40_SHORT; 497 hwif->cbl = ATA_CBL_PATA40_SHORT;
820 } 498 }
821 499
822 for (i = 0; i < MAX_DRIVES; i++) 500 ide_port_for_each_dev(i, drive, hwif)
823 ide_dev_apply_params(&hwif->drives[i], i); 501 ide_dev_apply_params(drive, i);
824} 502}
825 503
826/* 504/*
diff --git a/drivers/ide/ide_arm.c b/drivers/ide/ide_arm.c
index f728f2927b5a..bdcac94d7c1f 100644
--- a/drivers/ide/ide_arm.c
+++ b/drivers/ide/ide_arm.c
@@ -15,15 +15,8 @@
15 15
16#define DRV_NAME "ide_arm" 16#define DRV_NAME "ide_arm"
17 17
18#ifdef CONFIG_ARCH_CLPS7500 18#define IDE_ARM_IO 0x1f0
19# include <mach/hardware.h> 19#define IDE_ARM_IRQ IRQ_HARDDISK
20#
21# define IDE_ARM_IO (ISASLOT_IO + 0x1f0)
22# define IDE_ARM_IRQ IRQ_ISA_14
23#else
24# define IDE_ARM_IO 0x1f0
25# define IDE_ARM_IRQ IRQ_HARDDISK
26#endif
27 20
28static int __init ide_arm_init(void) 21static int __init ide_arm_init(void)
29{ 22{
diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
new file mode 100644
index 000000000000..e021078cd06b
--- /dev/null
+++ b/drivers/ide/it8172.c
@@ -0,0 +1,166 @@
1/*
2 *
3 * BRIEF MODULE DESCRIPTION
4 * IT8172 IDE controller support
5 *
6 * Copyright (C) 2000 MontaVista Software Inc.
7 * Copyright (C) 2008 Shane McDonald
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#include <linux/module.h>
31#include <linux/types.h>
32#include <linux/kernel.h>
33#include <linux/ioport.h>
34#include <linux/pci.h>
35#include <linux/ide.h>
36#include <linux/init.h>
37
38#define DRV_NAME "IT8172"
39
40static void it8172_set_pio_mode(ide_drive_t *drive, const u8 pio)
41{
42 ide_hwif_t *hwif = drive->hwif;
43 struct pci_dev *dev = to_pci_dev(hwif->dev);
44 u16 drive_enables;
45 u32 drive_timing;
46
47 /*
48 * The highest value of DIOR/DIOW pulse width and recovery time
49 * that can be set in the IT8172 is 8 PCI clock cycles. As a result,
50 * it cannot be configured for PIO mode 0. This table sets these
51 * parameters to the maximum supported by the IT8172.
52 */
53 static const u8 timings[] = { 0x3f, 0x3c, 0x1b, 0x12, 0x0a };
54
55 pci_read_config_word(dev, 0x40, &drive_enables);
56 pci_read_config_dword(dev, 0x44, &drive_timing);
57
58 /*
59 * Enable port 0x44. The IT8172 spec is confused; it calls
60 * this register the "Slave IDE Timing Register", but in fact,
61 * it controls timing for both master and slave drives.
62 */
63 drive_enables |= 0x4000;
64
65 drive_enables &= drive->dn ? 0xc006 : 0xc060;
66 if (drive->media == ide_disk)
67 /* enable prefetch */
68 drive_enables |= 0x0004 << (drive->dn * 4);
69 if (ata_id_has_iordy(drive->id))
70 /* enable IORDY sample-point */
71 drive_enables |= 0x0002 << (drive->dn * 4);
72
73 drive_timing &= drive->dn ? 0x00003f00 : 0x000fc000;
74 drive_timing |= timings[pio] << (drive->dn * 6 + 8);
75
76 pci_write_config_word(dev, 0x40, drive_enables);
77 pci_write_config_dword(dev, 0x44, drive_timing);
78}
79
80static void it8172_set_dma_mode(ide_drive_t *drive, const u8 speed)
81{
82 ide_hwif_t *hwif = drive->hwif;
83 struct pci_dev *dev = to_pci_dev(hwif->dev);
84 int a_speed = 3 << (drive->dn * 4);
85 int u_flag = 1 << drive->dn;
86 int u_speed = 0;
87 u8 reg48, reg4a;
88
89 pci_read_config_byte(dev, 0x48, &reg48);
90 pci_read_config_byte(dev, 0x4a, &reg4a);
91
92 if (speed >= XFER_UDMA_0) {
93 u8 udma = speed - XFER_UDMA_0;
94 u_speed = udma << (drive->dn * 4);
95
96 pci_write_config_byte(dev, 0x48, reg48 | u_flag);
97 reg4a &= ~a_speed;
98 pci_write_config_byte(dev, 0x4a, reg4a | u_speed);
99 } else {
100 const u8 mwdma_to_pio[] = { 0, 3, 4 };
101 u8 pio;
102
103 pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
104 pci_write_config_byte(dev, 0x4a, reg4a & ~a_speed);
105
106 pio = mwdma_to_pio[speed - XFER_MW_DMA_0];
107
108 it8172_set_pio_mode(drive, pio);
109 }
110}
111
112
113static const struct ide_port_ops it8172_port_ops = {
114 .set_pio_mode = it8172_set_pio_mode,
115 .set_dma_mode = it8172_set_dma_mode,
116};
117
118static const struct ide_port_info it8172_port_info __devinitdata = {
119 .name = DRV_NAME,
120 .port_ops = &it8172_port_ops,
121 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
122 .host_flags = IDE_HFLAG_SINGLE,
123 .pio_mask = ATA_PIO4 & ~ATA_PIO0,
124 .mwdma_mask = ATA_MWDMA2,
125 .udma_mask = ATA_UDMA2,
126};
127
128static int __devinit it8172_init_one(struct pci_dev *dev,
129 const struct pci_device_id *id)
130{
131 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
132 return -ENODEV; /* IT8172 is more than an IDE controller */
133 return ide_pci_init_one(dev, &it8172_port_info, NULL);
134}
135
136static struct pci_device_id it8172_pci_tbl[] = {
137 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8172), 0 },
138 { 0, },
139};
140MODULE_DEVICE_TABLE(pci, it8172_pci_tbl);
141
142static struct pci_driver it8172_pci_driver = {
143 .name = "IT8172_IDE",
144 .id_table = it8172_pci_tbl,
145 .probe = it8172_init_one,
146 .remove = ide_pci_remove,
147 .suspend = ide_pci_suspend,
148 .resume = ide_pci_resume,
149};
150
151static int __init it8172_ide_init(void)
152{
153 return ide_pci_register_driver(&it8172_pci_driver);
154}
155
156static void __exit it8172_ide_exit(void)
157{
158 pci_unregister_driver(&it8172_pci_driver);
159}
160
161module_init(it8172_ide_init);
162module_exit(it8172_ide_exit);
163
164MODULE_AUTHOR("Steve Longerbeam");
165MODULE_DESCRIPTION("PCI driver module for ITE 8172 IDE");
166MODULE_LICENSE("GPL");
diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
index 7c2feeb3c5ec..d7969b6d139e 100644
--- a/drivers/ide/it8213.c
+++ b/drivers/ide/it8213.c
@@ -25,7 +25,7 @@
25 25
26static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio) 26static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
27{ 27{
28 ide_hwif_t *hwif = HWIF(drive); 28 ide_hwif_t *hwif = drive->hwif;
29 struct pci_dev *dev = to_pci_dev(hwif->dev); 29 struct pci_dev *dev = to_pci_dev(hwif->dev);
30 int is_slave = drive->dn & 1; 30 int is_slave = drive->dn & 1;
31 int master_port = 0x40; 31 int master_port = 0x40;
@@ -82,7 +82,7 @@ static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
82 82
83static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed) 83static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
84{ 84{
85 ide_hwif_t *hwif = HWIF(drive); 85 ide_hwif_t *hwif = drive->hwif;
86 struct pci_dev *dev = to_pci_dev(hwif->dev); 86 struct pci_dev *dev = to_pci_dev(hwif->dev);
87 u8 maslave = 0x40; 87 u8 maslave = 0x40;
88 int a_speed = 3 << (drive->dn * 4); 88 int a_speed = 3 << (drive->dn * 4);
diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
index ef004089761b..0be27ac1f077 100644
--- a/drivers/ide/it821x.c
+++ b/drivers/ide/it821x.c
@@ -167,12 +167,10 @@ static void it821x_clock_strategy(ide_drive_t *drive)
167 ide_hwif_t *hwif = drive->hwif; 167 ide_hwif_t *hwif = drive->hwif;
168 struct pci_dev *dev = to_pci_dev(hwif->dev); 168 struct pci_dev *dev = to_pci_dev(hwif->dev);
169 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 169 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
170 ide_drive_t *pair; 170 ide_drive_t *pair = ide_get_pair_dev(drive);
171 int clock, altclock, sel = 0; 171 int clock, altclock, sel = 0;
172 u8 unit = drive->dn & 1, v; 172 u8 unit = drive->dn & 1, v;
173 173
174 pair = &hwif->drives[1 - unit];
175
176 if(itdev->want[0][0] > itdev->want[1][0]) { 174 if(itdev->want[0][0] > itdev->want[1][0]) {
177 clock = itdev->want[0][1]; 175 clock = itdev->want[0][1];
178 altclock = itdev->want[1][1]; 176 altclock = itdev->want[1][1];
@@ -239,15 +237,13 @@ static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
239{ 237{
240 ide_hwif_t *hwif = drive->hwif; 238 ide_hwif_t *hwif = drive->hwif;
241 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 239 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
242 ide_drive_t *pair; 240 ide_drive_t *pair = ide_get_pair_dev(drive);
243 u8 unit = drive->dn & 1, set_pio = pio; 241 u8 unit = drive->dn & 1, set_pio = pio;
244 242
245 /* Spec says 89 ref driver uses 88 */ 243 /* Spec says 89 ref driver uses 88 */
246 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 }; 244 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
247 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY }; 245 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
248 246
249 pair = &hwif->drives[1 - unit];
250
251 /* 247 /*
252 * Compute the best PIO mode we can for a given device. We must 248 * Compute the best PIO mode we can for a given device. We must
253 * pick a speed that does not cause problems with the other device 249 * pick a speed that does not cause problems with the other device
@@ -279,7 +275,7 @@ static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
279 * the shared MWDMA/PIO timing register. 275 * the shared MWDMA/PIO timing register.
280 */ 276 */
281 277
282static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted) 278static void it821x_tune_mwdma(ide_drive_t *drive, u8 mode_wanted)
283{ 279{
284 ide_hwif_t *hwif = drive->hwif; 280 ide_hwif_t *hwif = drive->hwif;
285 struct pci_dev *dev = to_pci_dev(hwif->dev); 281 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -316,7 +312,7 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
316 * controller when doing UDMA modes in pass through. 312 * controller when doing UDMA modes in pass through.
317 */ 313 */
318 314
319static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted) 315static void it821x_tune_udma(ide_drive_t *drive, u8 mode_wanted)
320{ 316{
321 ide_hwif_t *hwif = drive->hwif; 317 ide_hwif_t *hwif = drive->hwif;
322 struct pci_dev *dev = to_pci_dev(hwif->dev); 318 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -516,6 +512,7 @@ static struct ide_dma_ops it821x_pass_through_dma_ops = {
516 .dma_test_irq = ide_dma_test_irq, 512 .dma_test_irq = ide_dma_test_irq,
517 .dma_timeout = ide_dma_timeout, 513 .dma_timeout = ide_dma_timeout,
518 .dma_lost_irq = ide_dma_lost_irq, 514 .dma_lost_irq = ide_dma_lost_irq,
515 .dma_sff_read_status = ide_dma_sff_read_status,
519}; 516};
520 517
521/** 518/**
diff --git a/drivers/ide/macide.c b/drivers/ide/macide.c
index 43f97cc1d30e..3c60064f1d4f 100644
--- a/drivers/ide/macide.c
+++ b/drivers/ide/macide.c
@@ -18,7 +18,6 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/ide.h> 19#include <linux/ide.h>
20 20
21#include <asm/machw.h>
22#include <asm/macintosh.h> 21#include <asm/macintosh.h>
23#include <asm/macints.h> 22#include <asm/macints.h>
24#include <asm/mac_baboon.h> 23#include <asm/mac_baboon.h>
diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
index 13789060f407..83643ed9a426 100644
--- a/drivers/ide/ns87415.c
+++ b/drivers/ide/ns87415.c
@@ -56,7 +56,7 @@ static u8 superio_read_status(ide_hwif_t *hwif)
56 return superio_ide_inb(hwif->io_ports.status_addr); 56 return superio_ide_inb(hwif->io_ports.status_addr);
57} 57}
58 58
59static u8 superio_read_sff_dma_status(ide_hwif_t *hwif) 59static u8 superio_dma_sff_read_status(ide_hwif_t *hwif)
60{ 60{
61 return superio_ide_inb(hwif->dma_base + ATA_DMA_STATUS); 61 return superio_ide_inb(hwif->dma_base + ATA_DMA_STATUS);
62} 62}
@@ -109,7 +109,6 @@ static const struct ide_tp_ops superio_tp_ops = {
109 .exec_command = ide_exec_command, 109 .exec_command = ide_exec_command,
110 .read_status = superio_read_status, 110 .read_status = superio_read_status,
111 .read_altstatus = ide_read_altstatus, 111 .read_altstatus = ide_read_altstatus,
112 .read_sff_dma_status = superio_read_sff_dma_status,
113 112
114 .set_irq = ide_set_irq, 113 .set_irq = ide_set_irq,
115 114
@@ -132,18 +131,20 @@ static void __devinit superio_init_iops(struct hwif_s *hwif)
132 tmp = superio_ide_inb(dma_stat); 131 tmp = superio_ide_inb(dma_stat);
133 outb(tmp | 0x66, dma_stat); 132 outb(tmp | 0x66, dma_stat);
134} 133}
134#else
135#define superio_dma_sff_read_status ide_dma_sff_read_status
135#endif 136#endif
136 137
137static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 }; 138static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 };
138 139
139/* 140/*
140 * This routine either enables/disables (according to IDE_DFLAG_PRESENT) 141 * This routine either enables/disables (according to IDE_DFLAG_PRESENT)
141 * the IRQ associated with the port (HWIF(drive)), 142 * the IRQ associated with the port,
142 * and selects either PIO or DMA handshaking for the next I/O operation. 143 * and selects either PIO or DMA handshaking for the next I/O operation.
143 */ 144 */
144static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma) 145static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
145{ 146{
146 ide_hwif_t *hwif = HWIF(drive); 147 ide_hwif_t *hwif = drive->hwif;
147 struct pci_dev *dev = to_pci_dev(hwif->dev); 148 struct pci_dev *dev = to_pci_dev(hwif->dev);
148 unsigned int bit, other, new, *old = (unsigned int *) hwif->select_data; 149 unsigned int bit, other, new, *old = (unsigned int *) hwif->select_data;
149 unsigned long flags; 150 unsigned long flags;
@@ -197,11 +198,11 @@ static void ns87415_selectproc (ide_drive_t *drive)
197 198
198static int ns87415_dma_end(ide_drive_t *drive) 199static int ns87415_dma_end(ide_drive_t *drive)
199{ 200{
200 ide_hwif_t *hwif = HWIF(drive); 201 ide_hwif_t *hwif = drive->hwif;
201 u8 dma_stat = 0, dma_cmd = 0; 202 u8 dma_stat = 0, dma_cmd = 0;
202 203
203 drive->waiting_for_dma = 0; 204 drive->waiting_for_dma = 0;
204 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 205 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
205 /* get DMA command mode */ 206 /* get DMA command mode */
206 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); 207 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
207 /* stop DMA */ 208 /* stop DMA */
@@ -308,6 +309,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
308 .dma_test_irq = ide_dma_test_irq, 309 .dma_test_irq = ide_dma_test_irq,
309 .dma_lost_irq = ide_dma_lost_irq, 310 .dma_lost_irq = ide_dma_lost_irq,
310 .dma_timeout = ide_dma_timeout, 311 .dma_timeout = ide_dma_timeout,
312 .dma_sff_read_status = superio_dma_sff_read_status,
311}; 313};
312 314
313static const struct ide_port_info ns87415_chipset __devinitdata = { 315static const struct ide_port_info ns87415_chipset __devinitdata = {
diff --git a/drivers/ide/palm_bk3710.c b/drivers/ide/palm_bk3710.c
index 122ed3c072fd..a7ac490c9ae3 100644
--- a/drivers/ide/palm_bk3710.c
+++ b/drivers/ide/palm_bk3710.c
@@ -324,8 +324,6 @@ static int __devinit palm_bk3710_init_dma(ide_hwif_t *hwif,
324 324
325 hwif->dma_base = hwif->io_ports.data_addr - IDE_PALM_ATA_PRI_REG_OFFSET; 325 hwif->dma_base = hwif->io_ports.data_addr - IDE_PALM_ATA_PRI_REG_OFFSET;
326 326
327 hwif->dma_ops = &sff_dma_ops;
328
329 return 0; 327 return 0;
330} 328}
331 329
@@ -338,6 +336,7 @@ static const struct ide_port_ops palm_bk3710_ports_ops = {
338static struct ide_port_info __devinitdata palm_bk3710_port_info = { 336static struct ide_port_info __devinitdata palm_bk3710_port_info = {
339 .init_dma = palm_bk3710_init_dma, 337 .init_dma = palm_bk3710_init_dma,
340 .port_ops = &palm_bk3710_ports_ops, 338 .port_ops = &palm_bk3710_ports_ops,
339 .dma_ops = &sff_dma_ops,
341 .host_flags = IDE_HFLAG_MMIO, 340 .host_flags = IDE_HFLAG_MMIO,
342 .pio_mask = ATA_PIO4, 341 .pio_mask = ATA_PIO4,
343 .mwdma_mask = ATA_MWDMA2, 342 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
index 211ae46e3e0c..f21290c4b447 100644
--- a/drivers/ide/pdc202xx_new.c
+++ b/drivers/ide/pdc202xx_new.c
@@ -143,7 +143,7 @@ static struct udma_timing {
143 143
144static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed) 144static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed)
145{ 145{
146 ide_hwif_t *hwif = HWIF(drive); 146 ide_hwif_t *hwif = drive->hwif;
147 struct pci_dev *dev = to_pci_dev(hwif->dev); 147 struct pci_dev *dev = to_pci_dev(hwif->dev);
148 u8 adj = (drive->dn & 1) ? 0x08 : 0x00; 148 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
149 149
@@ -219,7 +219,7 @@ static void pdcnew_reset(ide_drive_t *drive)
219 * Deleted this because it is redundant from the caller. 219 * Deleted this because it is redundant from the caller.
220 */ 220 */
221 printk(KERN_WARNING "pdc202xx_new: %s channel reset.\n", 221 printk(KERN_WARNING "pdc202xx_new: %s channel reset.\n",
222 HWIF(drive)->channel ? "Secondary" : "Primary"); 222 drive->hwif->channel ? "Secondary" : "Primary");
223} 223}
224 224
225/** 225/**
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index 799557c25eef..97193323aebf 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -39,7 +39,7 @@ static void pdc_old_disable_66MHz_clock(ide_hwif_t *);
39 39
40static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed) 40static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed)
41{ 41{
42 ide_hwif_t *hwif = HWIF(drive); 42 ide_hwif_t *hwif = drive->hwif;
43 struct pci_dev *dev = to_pci_dev(hwif->dev); 43 struct pci_dev *dev = to_pci_dev(hwif->dev);
44 u8 drive_pci = 0x60 + (drive->dn << 2); 44 u8 drive_pci = 0x60 + (drive->dn << 2);
45 45
@@ -169,8 +169,8 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
169 if (drive->current_speed > XFER_UDMA_2) 169 if (drive->current_speed > XFER_UDMA_2)
170 pdc_old_enable_66MHz_clock(drive->hwif); 170 pdc_old_enable_66MHz_clock(drive->hwif);
171 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) { 171 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
172 struct request *rq = HWGROUP(drive)->rq; 172 ide_hwif_t *hwif = drive->hwif;
173 ide_hwif_t *hwif = HWIF(drive); 173 struct request *rq = hwif->rq;
174 unsigned long high_16 = hwif->extra_base - 16; 174 unsigned long high_16 = hwif->extra_base - 16;
175 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 175 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
176 u32 word_count = 0; 176 u32 word_count = 0;
@@ -189,7 +189,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
189static int pdc202xx_dma_end(ide_drive_t *drive) 189static int pdc202xx_dma_end(ide_drive_t *drive)
190{ 190{
191 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) { 191 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
192 ide_hwif_t *hwif = HWIF(drive); 192 ide_hwif_t *hwif = drive->hwif;
193 unsigned long high_16 = hwif->extra_base - 16; 193 unsigned long high_16 = hwif->extra_base - 16;
194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
195 u8 clock = 0; 195 u8 clock = 0;
@@ -205,7 +205,7 @@ static int pdc202xx_dma_end(ide_drive_t *drive)
205 205
206static int pdc202xx_dma_test_irq(ide_drive_t *drive) 206static int pdc202xx_dma_test_irq(ide_drive_t *drive)
207{ 207{
208 ide_hwif_t *hwif = HWIF(drive); 208 ide_hwif_t *hwif = drive->hwif;
209 unsigned long high_16 = hwif->extra_base - 16; 209 unsigned long high_16 = hwif->extra_base - 16;
210 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 210 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
211 u8 sc1d = inb(high_16 + 0x001d); 211 u8 sc1d = inb(high_16 + 0x001d);
@@ -243,7 +243,7 @@ static void pdc202xx_reset_host (ide_hwif_t *hwif)
243 243
244static void pdc202xx_reset (ide_drive_t *drive) 244static void pdc202xx_reset (ide_drive_t *drive)
245{ 245{
246 ide_hwif_t *hwif = HWIF(drive); 246 ide_hwif_t *hwif = drive->hwif;
247 ide_hwif_t *mate = hwif->mate; 247 ide_hwif_t *mate = hwif->mate;
248 248
249 pdc202xx_reset_host(hwif); 249 pdc202xx_reset_host(hwif);
@@ -337,6 +337,7 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
337 .dma_test_irq = pdc202xx_dma_test_irq, 337 .dma_test_irq = pdc202xx_dma_test_irq,
338 .dma_lost_irq = pdc202xx_dma_lost_irq, 338 .dma_lost_irq = pdc202xx_dma_lost_irq,
339 .dma_timeout = pdc202xx_dma_timeout, 339 .dma_timeout = pdc202xx_dma_timeout,
340 .dma_sff_read_status = ide_dma_sff_read_status,
340}; 341};
341 342
342static const struct ide_dma_ops pdc2026x_dma_ops = { 343static const struct ide_dma_ops pdc2026x_dma_ops = {
@@ -348,18 +349,20 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
348 .dma_test_irq = pdc202xx_dma_test_irq, 349 .dma_test_irq = pdc202xx_dma_test_irq,
349 .dma_lost_irq = pdc202xx_dma_lost_irq, 350 .dma_lost_irq = pdc202xx_dma_lost_irq,
350 .dma_timeout = pdc202xx_dma_timeout, 351 .dma_timeout = pdc202xx_dma_timeout,
352 .dma_sff_read_status = ide_dma_sff_read_status,
351}; 353};
352 354
353#define DECLARE_PDC2026X_DEV(udma, extra_flags) \ 355#define DECLARE_PDC2026X_DEV(udma, sectors) \
354 { \ 356 { \
355 .name = DRV_NAME, \ 357 .name = DRV_NAME, \
356 .init_chipset = init_chipset_pdc202xx, \ 358 .init_chipset = init_chipset_pdc202xx, \
357 .port_ops = &pdc2026x_port_ops, \ 359 .port_ops = &pdc2026x_port_ops, \
358 .dma_ops = &pdc2026x_dma_ops, \ 360 .dma_ops = &pdc2026x_dma_ops, \
359 .host_flags = IDE_HFLAGS_PDC202XX | extra_flags, \ 361 .host_flags = IDE_HFLAGS_PDC202XX, \
360 .pio_mask = ATA_PIO4, \ 362 .pio_mask = ATA_PIO4, \
361 .mwdma_mask = ATA_MWDMA2, \ 363 .mwdma_mask = ATA_MWDMA2, \
362 .udma_mask = udma, \ 364 .udma_mask = udma, \
365 .max_sectors = sectors, \
363 } 366 }
364 367
365static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = { 368static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
@@ -376,8 +379,8 @@ static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
376 379
377 /* 1: PDC2026{2,3} */ 380 /* 1: PDC2026{2,3} */
378 DECLARE_PDC2026X_DEV(ATA_UDMA4, 0), 381 DECLARE_PDC2026X_DEV(ATA_UDMA4, 0),
379 /* 2: PDC2026{5,7} */ 382 /* 2: PDC2026{5,7}: UDMA5, limit LBA48 requests to 256 sectors */
380 DECLARE_PDC2026X_DEV(ATA_UDMA5, IDE_HFLAG_RQSIZE_256), 383 DECLARE_PDC2026X_DEV(ATA_UDMA5, 256),
381}; 384};
382 385
383/** 386/**
diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
index 61d2d920a5cd..f1e2e4ef0d71 100644
--- a/drivers/ide/piix.c
+++ b/drivers/ide/piix.c
@@ -67,7 +67,7 @@ static int no_piix_dma;
67 67
68static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio) 68static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio)
69{ 69{
70 ide_hwif_t *hwif = HWIF(drive); 70 ide_hwif_t *hwif = drive->hwif;
71 struct pci_dev *dev = to_pci_dev(hwif->dev); 71 struct pci_dev *dev = to_pci_dev(hwif->dev);
72 int is_slave = drive->dn & 1; 72 int is_slave = drive->dn & 1;
73 int master_port = hwif->channel ? 0x42 : 0x40; 73 int master_port = hwif->channel ? 0x42 : 0x40;
@@ -136,7 +136,7 @@ static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio)
136 136
137static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed) 137static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed)
138{ 138{
139 ide_hwif_t *hwif = HWIF(drive); 139 ide_hwif_t *hwif = drive->hwif;
140 struct pci_dev *dev = to_pci_dev(hwif->dev); 140 struct pci_dev *dev = to_pci_dev(hwif->dev);
141 u8 maslave = hwif->channel ? 0x42 : 0x40; 141 u8 maslave = hwif->channel ? 0x42 : 0x40;
142 int a_speed = 3 << (drive->dn * 4); 142 int a_speed = 3 << (drive->dn * 4);
@@ -224,7 +224,7 @@ static unsigned int init_chipset_ich(struct pci_dev *dev)
224 */ 224 */
225static void ich_clear_irq(ide_drive_t *drive) 225static void ich_clear_irq(ide_drive_t *drive)
226{ 226{
227 ide_hwif_t *hwif = HWIF(drive); 227 ide_hwif_t *hwif = drive->hwif;
228 u8 dma_stat; 228 u8 dma_stat;
229 229
230 /* 230 /*
@@ -260,6 +260,8 @@ static const struct ich_laptop ich_laptop[] = {
260 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 260 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
261 { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */ 261 { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */
262 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */ 262 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */
263 { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */
264 { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
263 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 265 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
264 /* end marker */ 266 /* end marker */
265 { 0, } 267 { 0, }
diff --git a/drivers/ide/pmac.c b/drivers/ide/pmac.c
index 7c481bb56fab..74625e821a43 100644
--- a/drivers/ide/pmac.c
+++ b/drivers/ide/pmac.c
@@ -955,7 +955,6 @@ static const struct ide_tp_ops pmac_tp_ops = {
955 .exec_command = pmac_exec_command, 955 .exec_command = pmac_exec_command,
956 .read_status = ide_read_status, 956 .read_status = ide_read_status,
957 .read_altstatus = ide_read_altstatus, 957 .read_altstatus = ide_read_altstatus,
958 .read_sff_dma_status = ide_read_sff_dma_status,
959 958
960 .set_irq = pmac_set_irq, 959 .set_irq = pmac_set_irq,
961 960
@@ -1513,10 +1512,10 @@ use_pio_instead:
1513static int 1512static int
1514pmac_ide_dma_setup(ide_drive_t *drive) 1513pmac_ide_dma_setup(ide_drive_t *drive)
1515{ 1514{
1516 ide_hwif_t *hwif = HWIF(drive); 1515 ide_hwif_t *hwif = drive->hwif;
1517 pmac_ide_hwif_t *pmif = 1516 pmac_ide_hwif_t *pmif =
1518 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1517 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1519 struct request *rq = HWGROUP(drive)->rq; 1518 struct request *rq = hwif->rq;
1520 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4); 1519 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
1521 1520
1522 if (!pmac_ide_build_dmatable(drive, rq)) { 1521 if (!pmac_ide_build_dmatable(drive, rq)) {
@@ -1637,7 +1636,7 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1637 break; 1636 break;
1638 if (++timeout > 100) { 1637 if (++timeout > 100) {
1639 printk(KERN_WARNING "ide%d, ide_dma_test_irq \ 1638 printk(KERN_WARNING "ide%d, ide_dma_test_irq \
1640 timeout flushing channel\n", HWIF(drive)->index); 1639 timeout flushing channel\n", hwif->index);
1641 break; 1640 break;
1642 } 1641 }
1643 } 1642 }
diff --git a/drivers/ide/q40ide.c b/drivers/ide/q40ide.c
index 4af4a8ce4cdf..9f9c0b3cc3a3 100644
--- a/drivers/ide/q40ide.c
+++ b/drivers/ide/q40ide.c
@@ -99,7 +99,6 @@ static const struct ide_tp_ops q40ide_tp_ops = {
99 .exec_command = ide_exec_command, 99 .exec_command = ide_exec_command,
100 .read_status = ide_read_status, 100 .read_status = ide_read_status,
101 .read_altstatus = ide_read_altstatus, 101 .read_altstatus = ide_read_altstatus,
102 .read_sff_dma_status = ide_read_sff_dma_status,
103 102
104 .set_irq = ide_set_irq, 103 .set_irq = ide_set_irq,
105 104
diff --git a/drivers/ide/qd65xx.c b/drivers/ide/qd65xx.c
index bc27c7aba936..5b2e3af43c4b 100644
--- a/drivers/ide/qd65xx.c
+++ b/drivers/ide/qd65xx.c
@@ -202,7 +202,8 @@ static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio)
202 recovery_time = drive->id[ATA_ID_EIDE_PIO] - 120; 202 recovery_time = drive->id[ATA_ID_EIDE_PIO] - 120;
203 } 203 }
204 204
205 qd_set_timing(drive, qd6500_compute_timing(HWIF(drive), active_time, recovery_time)); 205 qd_set_timing(drive, qd6500_compute_timing(drive->hwif,
206 active_time, recovery_time));
206} 207}
207 208
208static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio) 209static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio)
@@ -245,11 +246,11 @@ static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio)
245 printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio); 246 printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio);
246 } 247 }
247 248
248 if (!HWIF(drive)->channel && drive->media != ide_disk) { 249 if (!hwif->channel && drive->media != ide_disk) {
249 outb(0x5f, QD_CONTROL_PORT); 250 outb(0x5f, QD_CONTROL_PORT);
250 printk(KERN_WARNING "%s: ATAPI: disabled read-ahead FIFO " 251 printk(KERN_WARNING "%s: ATAPI: disabled read-ahead FIFO "
251 "and post-write buffer on %s.\n", 252 "and post-write buffer on %s.\n",
252 drive->name, HWIF(drive)->name); 253 drive->name, hwif->name);
253 } 254 }
254 255
255 qd_set_timing(drive, qd6580_compute_timing(active_time, recovery_time)); 256 qd_set_timing(drive, qd6580_compute_timing(active_time, recovery_time));
diff --git a/drivers/ide/qd65xx.h b/drivers/ide/qd65xx.h
index c83dea85e621..6636f9665d16 100644
--- a/drivers/ide/qd65xx.h
+++ b/drivers/ide/qd65xx.h
@@ -31,8 +31,8 @@
31 31
32#define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff) 32#define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff)
33 33
34#define QD_TIMING(drive) (byte)(((drive)->drive_data) & 0x00ff) 34#define QD_TIMING(drive) (u8)(((drive)->drive_data) & 0x00ff)
35#define QD_TIMREG(drive) (byte)((((drive)->drive_data) & 0xff00) >> 8) 35#define QD_TIMREG(drive) (u8)((((drive)->drive_data) & 0xff00) >> 8)
36 36
37#define QD6500_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0c : 0x08)) 37#define QD6500_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0c : 0x08))
38#define QD6580_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0a : 0x00)) 38#define QD6580_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0a : 0x00))
diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
index 7daf0135cbac..a6414a884eb1 100644
--- a/drivers/ide/rz1000.c
+++ b/drivers/ide/rz1000.c
@@ -22,34 +22,48 @@
22 22
23#define DRV_NAME "rz1000" 23#define DRV_NAME "rz1000"
24 24
25static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif) 25static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
26{ 26{
27 struct pci_dev *dev = to_pci_dev(hwif->dev);
28 u16 reg; 27 u16 reg;
29 28
30 if (!pci_read_config_word (dev, 0x40, &reg) && 29 if (!pci_read_config_word (dev, 0x40, &reg) &&
31 !pci_write_config_word(dev, 0x40, reg & 0xdfff)) { 30 !pci_write_config_word(dev, 0x40, reg & 0xdfff)) {
32 printk(KERN_INFO "%s: disabled chipset read-ahead " 31 printk(KERN_INFO "%s: disabled chipset read-ahead "
33 "(buggy RZ1000/RZ1001)\n", hwif->name); 32 "(buggy RZ1000/RZ1001)\n", pci_name(dev));
33 return 0;
34 } else { 34 } else {
35 if (hwif->mate)
36 hwif->mate->serialized = hwif->serialized = 1;
37 hwif->host_flags |= IDE_HFLAG_NO_UNMASK_IRQS;
38 printk(KERN_INFO "%s: serialized, disabled unmasking " 35 printk(KERN_INFO "%s: serialized, disabled unmasking "
39 "(buggy RZ1000/RZ1001)\n", hwif->name); 36 "(buggy RZ1000/RZ1001)\n", pci_name(dev));
37 return 1;
40 } 38 }
41} 39}
42 40
43static const struct ide_port_info rz1000_chipset __devinitdata = { 41static const struct ide_port_info rz1000_chipset __devinitdata = {
44 .name = DRV_NAME, 42 .name = DRV_NAME,
45 .init_hwif = init_hwif_rz1000,
46 .chipset = ide_rz1000,
47 .host_flags = IDE_HFLAG_NO_DMA, 43 .host_flags = IDE_HFLAG_NO_DMA,
48}; 44};
49 45
50static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id) 46static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id)
51{ 47{
52 return ide_pci_init_one(dev, &rz1000_chipset, NULL); 48 struct ide_port_info d = rz1000_chipset;
49 int rc;
50
51 rc = pci_enable_device(dev);
52 if (rc)
53 return rc;
54
55 if (rz1000_disable_readahead(dev)) {
56 d.host_flags |= IDE_HFLAG_SERIALIZE;
57 d.host_flags |= IDE_HFLAG_NO_UNMASK_IRQS;
58 }
59
60 return ide_pci_init_one(dev, &d, NULL);
61}
62
63static void rz1000_remove(struct pci_dev *dev)
64{
65 ide_pci_remove(dev);
66 pci_disable_device(dev);
53} 67}
54 68
55static const struct pci_device_id rz1000_pci_tbl[] = { 69static const struct pci_device_id rz1000_pci_tbl[] = {
@@ -63,7 +77,7 @@ static struct pci_driver rz1000_pci_driver = {
63 .name = "RZ1000_IDE", 77 .name = "RZ1000_IDE",
64 .id_table = rz1000_pci_tbl, 78 .id_table = rz1000_pci_tbl,
65 .probe = rz1000_init_one, 79 .probe = rz1000_init_one,
66 .remove = ide_pci_remove, 80 .remove = rz1000_remove,
67}; 81};
68 82
69static int __init rz1000_ide_init(void) 83static int __init rz1000_ide_init(void)
diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
index ec7f766ef5e4..dbdd2985a0d8 100644
--- a/drivers/ide/sc1200.c
+++ b/drivers/ide/sc1200.c
@@ -125,7 +125,7 @@ out:
125 125
126static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode) 126static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
127{ 127{
128 ide_hwif_t *hwif = HWIF(drive); 128 ide_hwif_t *hwif = drive->hwif;
129 struct pci_dev *dev = to_pci_dev(hwif->dev); 129 struct pci_dev *dev = to_pci_dev(hwif->dev);
130 unsigned int reg, timings; 130 unsigned int reg, timings;
131 unsigned short pci_clock; 131 unsigned short pci_clock;
@@ -170,9 +170,9 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
170 */ 170 */
171static int sc1200_dma_end(ide_drive_t *drive) 171static int sc1200_dma_end(ide_drive_t *drive)
172{ 172{
173 ide_hwif_t *hwif = HWIF(drive); 173 ide_hwif_t *hwif = drive->hwif;
174 unsigned long dma_base = hwif->dma_base; 174 unsigned long dma_base = hwif->dma_base;
175 byte dma_stat; 175 u8 dma_stat;
176 176
177 dma_stat = inb(dma_base+2); /* get DMA status */ 177 dma_stat = inb(dma_base+2); /* get DMA status */
178 178
@@ -199,7 +199,7 @@ static int sc1200_dma_end(ide_drive_t *drive)
199 199
200static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio) 200static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
201{ 201{
202 ide_hwif_t *hwif = HWIF(drive); 202 ide_hwif_t *hwif = drive->hwif;
203 int mode = -1; 203 int mode = -1;
204 204
205 /* 205 /*
@@ -292,6 +292,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
292 .dma_test_irq = ide_dma_test_irq, 292 .dma_test_irq = ide_dma_test_irq,
293 .dma_lost_irq = ide_dma_lost_irq, 293 .dma_lost_irq = ide_dma_lost_irq,
294 .dma_timeout = ide_dma_timeout, 294 .dma_timeout = ide_dma_timeout,
295 .dma_sff_read_status = ide_dma_sff_read_status,
295}; 296};
296 297
297static const struct ide_port_info sc1200_chipset __devinitdata = { 298static const struct ide_port_info sc1200_chipset __devinitdata = {
diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
index 0f48f9dacfa5..8d2314b6327c 100644
--- a/drivers/ide/scc_pata.c
+++ b/drivers/ide/scc_pata.c
@@ -143,7 +143,7 @@ static u8 scc_read_altstatus(ide_hwif_t *hwif)
143 return (u8)in_be32((void *)hwif->io_ports.ctl_addr); 143 return (u8)in_be32((void *)hwif->io_ports.ctl_addr);
144} 144}
145 145
146static u8 scc_read_sff_dma_status(ide_hwif_t *hwif) 146static u8 scc_dma_sff_read_status(ide_hwif_t *hwif)
147{ 147{
148 return (u8)in_be32((void *)(hwif->dma_base + 4)); 148 return (u8)in_be32((void *)(hwif->dma_base + 4));
149} 149}
@@ -217,7 +217,7 @@ scc_ide_outsl(unsigned long port, void *addr, u32 count)
217 217
218static void scc_set_pio_mode(ide_drive_t *drive, const u8 pio) 218static void scc_set_pio_mode(ide_drive_t *drive, const u8 pio)
219{ 219{
220 ide_hwif_t *hwif = HWIF(drive); 220 ide_hwif_t *hwif = drive->hwif;
221 struct scc_ports *ports = ide_get_hwifdata(hwif); 221 struct scc_ports *ports = ide_get_hwifdata(hwif);
222 unsigned long ctl_base = ports->ctl; 222 unsigned long ctl_base = ports->ctl;
223 unsigned long cckctrl_port = ctl_base + 0xff0; 223 unsigned long cckctrl_port = ctl_base + 0xff0;
@@ -249,7 +249,7 @@ static void scc_set_pio_mode(ide_drive_t *drive, const u8 pio)
249 249
250static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed) 250static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
251{ 251{
252 ide_hwif_t *hwif = HWIF(drive); 252 ide_hwif_t *hwif = drive->hwif;
253 struct scc_ports *ports = ide_get_hwifdata(hwif); 253 struct scc_ports *ports = ide_get_hwifdata(hwif);
254 unsigned long ctl_base = ports->ctl; 254 unsigned long ctl_base = ports->ctl;
255 unsigned long cckctrl_port = ctl_base + 0xff0; 255 unsigned long cckctrl_port = ctl_base + 0xff0;
@@ -259,7 +259,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
259 unsigned long scrcst_port = ctl_base + 0x014; 259 unsigned long scrcst_port = ctl_base + 0x014;
260 unsigned long udenvt_port = ctl_base + 0x018; 260 unsigned long udenvt_port = ctl_base + 0x018;
261 unsigned long tdvhsel_port = ctl_base + 0x020; 261 unsigned long tdvhsel_port = ctl_base + 0x020;
262 int is_slave = (&hwif->drives[1] == drive); 262 int is_slave = drive->dn & 1;
263 int offset, idx; 263 int offset, idx;
264 unsigned long reg; 264 unsigned long reg;
265 unsigned long jcactsel; 265 unsigned long jcactsel;
@@ -292,7 +292,7 @@ static void scc_dma_host_set(ide_drive_t *drive, int on)
292{ 292{
293 ide_hwif_t *hwif = drive->hwif; 293 ide_hwif_t *hwif = drive->hwif;
294 u8 unit = drive->dn & 1; 294 u8 unit = drive->dn & 1;
295 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4); 295 u8 dma_stat = scc_dma_sff_read_status(hwif);
296 296
297 if (on) 297 if (on)
298 dma_stat |= (1 << (5 + unit)); 298 dma_stat |= (1 << (5 + unit));
@@ -316,7 +316,7 @@ static void scc_dma_host_set(ide_drive_t *drive, int on)
316static int scc_dma_setup(ide_drive_t *drive) 316static int scc_dma_setup(ide_drive_t *drive)
317{ 317{
318 ide_hwif_t *hwif = drive->hwif; 318 ide_hwif_t *hwif = drive->hwif;
319 struct request *rq = HWGROUP(drive)->rq; 319 struct request *rq = hwif->rq;
320 unsigned int reading; 320 unsigned int reading;
321 u8 dma_stat; 321 u8 dma_stat;
322 322
@@ -338,7 +338,7 @@ static int scc_dma_setup(ide_drive_t *drive)
338 out_be32((void __iomem *)hwif->dma_base, reading); 338 out_be32((void __iomem *)hwif->dma_base, reading);
339 339
340 /* read DMA status for INTR & ERROR flags */ 340 /* read DMA status for INTR & ERROR flags */
341 dma_stat = in_be32((void __iomem *)(hwif->dma_base + 4)); 341 dma_stat = scc_dma_sff_read_status(hwif);
342 342
343 /* clear INTR & ERROR flags */ 343 /* clear INTR & ERROR flags */
344 out_be32((void __iomem *)(hwif->dma_base + 4), dma_stat | 6); 344 out_be32((void __iomem *)(hwif->dma_base + 4), dma_stat | 6);
@@ -367,7 +367,7 @@ static int __scc_dma_end(ide_drive_t *drive)
367 /* stop DMA */ 367 /* stop DMA */
368 scc_ide_outb(dma_cmd & ~1, hwif->dma_base); 368 scc_ide_outb(dma_cmd & ~1, hwif->dma_base);
369 /* get DMA status */ 369 /* get DMA status */
370 dma_stat = scc_ide_inb(hwif->dma_base + 4); 370 dma_stat = scc_dma_sff_read_status(hwif);
371 /* clear the INTR & ERROR bits */ 371 /* clear the INTR & ERROR bits */
372 scc_ide_outb(dma_stat | 6, hwif->dma_base + 4); 372 scc_ide_outb(dma_stat | 6, hwif->dma_base + 4);
373 /* purge DMA mappings */ 373 /* purge DMA mappings */
@@ -387,7 +387,7 @@ static int __scc_dma_end(ide_drive_t *drive)
387 387
388static int scc_dma_end(ide_drive_t *drive) 388static int scc_dma_end(ide_drive_t *drive)
389{ 389{
390 ide_hwif_t *hwif = HWIF(drive); 390 ide_hwif_t *hwif = drive->hwif;
391 void __iomem *dma_base = (void __iomem *)hwif->dma_base; 391 void __iomem *dma_base = (void __iomem *)hwif->dma_base;
392 unsigned long intsts_port = hwif->dma_base + 0x014; 392 unsigned long intsts_port = hwif->dma_base + 0x014;
393 u32 reg; 393 u32 reg;
@@ -405,17 +405,18 @@ static int scc_dma_end(ide_drive_t *drive)
405 drive->name); 405 drive->name);
406 data_loss = 1; 406 data_loss = 1;
407 if (retry++) { 407 if (retry++) {
408 struct request *rq = HWGROUP(drive)->rq; 408 struct request *rq = hwif->rq;
409 int unit; 409 ide_drive_t *drive;
410 int i;
411
410 /* ERROR_RESET and drive->crc_count are needed 412 /* ERROR_RESET and drive->crc_count are needed
411 * to reduce DMA transfer mode in retry process. 413 * to reduce DMA transfer mode in retry process.
412 */ 414 */
413 if (rq) 415 if (rq)
414 rq->errors |= ERROR_RESET; 416 rq->errors |= ERROR_RESET;
415 for (unit = 0; unit < MAX_DRIVES; unit++) { 417
416 ide_drive_t *drive = &hwif->drives[unit]; 418 ide_port_for_each_dev(i, drive, hwif)
417 drive->crc_count++; 419 drive->crc_count++;
418 }
419 } 420 }
420 } 421 }
421 } 422 }
@@ -496,7 +497,7 @@ static int scc_dma_end(ide_drive_t *drive)
496/* returns 1 if dma irq issued, 0 otherwise */ 497/* returns 1 if dma irq issued, 0 otherwise */
497static int scc_dma_test_irq(ide_drive_t *drive) 498static int scc_dma_test_irq(ide_drive_t *drive)
498{ 499{
499 ide_hwif_t *hwif = HWIF(drive); 500 ide_hwif_t *hwif = drive->hwif;
500 u32 int_stat = in_be32((void __iomem *)hwif->dma_base + 0x014); 501 u32 int_stat = in_be32((void __iomem *)hwif->dma_base + 0x014);
501 502
502 /* SCC errata A252,A308 workaround: Step4 */ 503 /* SCC errata A252,A308 workaround: Step4 */
@@ -852,7 +853,6 @@ static const struct ide_tp_ops scc_tp_ops = {
852 .exec_command = scc_exec_command, 853 .exec_command = scc_exec_command,
853 .read_status = scc_read_status, 854 .read_status = scc_read_status,
854 .read_altstatus = scc_read_altstatus, 855 .read_altstatus = scc_read_altstatus,
855 .read_sff_dma_status = scc_read_sff_dma_status,
856 856
857 .set_irq = scc_set_irq, 857 .set_irq = scc_set_irq,
858 858
@@ -879,6 +879,7 @@ static const struct ide_dma_ops scc_dma_ops = {
879 .dma_test_irq = scc_dma_test_irq, 879 .dma_test_irq = scc_dma_test_irq,
880 .dma_lost_irq = ide_dma_lost_irq, 880 .dma_lost_irq = ide_dma_lost_irq,
881 .dma_timeout = ide_dma_timeout, 881 .dma_timeout = ide_dma_timeout,
882 .dma_sff_read_status = scc_dma_sff_read_status,
882}; 883};
883 884
884#define DECLARE_SCC_DEV(name_str) \ 885#define DECLARE_SCC_DEV(name_str) \
diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
index 437bc919dafd..382102ba467b 100644
--- a/drivers/ide/serverworks.c
+++ b/drivers/ide/serverworks.c
@@ -151,7 +151,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
151 static const u8 dma_modes[] = { 0x77, 0x21, 0x20 }; 151 static const u8 dma_modes[] = { 0x77, 0x21, 0x20 };
152 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; 152 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
153 153
154 ide_hwif_t *hwif = HWIF(drive); 154 ide_hwif_t *hwif = drive->hwif;
155 struct pci_dev *dev = to_pci_dev(hwif->dev); 155 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 u8 unit = drive->dn & 1; 156 u8 unit = drive->dn & 1;
157 157
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 9f1f9163a136..e85d1ed29c2a 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -130,7 +130,7 @@ int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
130 * we tune the drive then try to grab DMA ownership if we want to be 130 * we tune the drive then try to grab DMA ownership if we want to be
131 * the DMA end. This has to be become dynamic to handle hot-plug. 131 * the DMA end. This has to be become dynamic to handle hot-plug.
132 */ 132 */
133 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 133 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
134 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) { 134 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
135 printk(KERN_INFO "%s %s: simplex device: DMA disabled\n", 135 printk(KERN_INFO "%s %s: simplex device: DMA disabled\n",
136 d->name, pci_name(dev)); 136 d->name, pci_name(dev));
@@ -377,6 +377,9 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
377 377
378 hwif->dma_base = base; 378 hwif->dma_base = base;
379 379
380 if (hwif->dma_ops == NULL)
381 hwif->dma_ops = &sff_dma_ops;
382
380 if (ide_pci_check_simplex(hwif, d) < 0) 383 if (ide_pci_check_simplex(hwif, d) < 0)
381 return -1; 384 return -1;
382 385
@@ -393,8 +396,6 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
393 396
394 if (ide_allocate_dma_engine(hwif)) 397 if (ide_allocate_dma_engine(hwif))
395 return -1; 398 return -1;
396
397 hwif->dma_ops = &sff_dma_ops;
398 } 399 }
399 400
400 return 0; 401 return 0;
@@ -471,7 +472,7 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
471 */ 472 */
472 473
473 for (port = 0; port < channels; ++port) { 474 for (port = 0; port < channels; ++port) {
474 const ide_pci_enablebit_t *e = &(d->enablebits[port]); 475 const struct ide_pci_enablebit *e = &d->enablebits[port];
475 476
476 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || 477 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
477 (tmp & e->mask) != e->val)) { 478 (tmp & e->mask) != e->val)) {
@@ -519,8 +520,7 @@ static int do_ide_setup_pci_device(struct pci_dev *dev,
519 if (ret < 0) 520 if (ret < 0)
520 goto out; 521 goto out;
521 522
522 /* Is it an "IDE storage" device in non-PCI mode? */ 523 if (ide_pci_is_in_compatibility_mode(dev)) {
523 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
524 if (noisy) 524 if (noisy)
525 printk(KERN_INFO "%s %s: not 100%% native mode: will " 525 printk(KERN_INFO "%s %s: not 100%% native mode: will "
526 "probe irqs later\n", d->name, pci_name(dev)); 526 "probe irqs later\n", d->name, pci_name(dev));
diff --git a/drivers/ide/sgiioc4.c b/drivers/ide/sgiioc4.c
index a687a7dfea6f..fdb9d7037694 100644
--- a/drivers/ide/sgiioc4.c
+++ b/drivers/ide/sgiioc4.c
@@ -123,7 +123,7 @@ static int
123sgiioc4_clearirq(ide_drive_t * drive) 123sgiioc4_clearirq(ide_drive_t * drive)
124{ 124{
125 u32 intr_reg; 125 u32 intr_reg;
126 ide_hwif_t *hwif = HWIF(drive); 126 ide_hwif_t *hwif = drive->hwif;
127 struct ide_io_ports *io_ports = &hwif->io_ports; 127 struct ide_io_ports *io_ports = &hwif->io_ports;
128 unsigned long other_ir = io_ports->irq_addr + (IOC4_INTR_REG << 2); 128 unsigned long other_ir = io_ports->irq_addr + (IOC4_INTR_REG << 2);
129 129
@@ -181,7 +181,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
181 181
182static void sgiioc4_dma_start(ide_drive_t *drive) 182static void sgiioc4_dma_start(ide_drive_t *drive)
183{ 183{
184 ide_hwif_t *hwif = HWIF(drive); 184 ide_hwif_t *hwif = drive->hwif;
185 unsigned long ioc4_dma_addr = hwif->dma_base + IOC4_DMA_CTRL * 4; 185 unsigned long ioc4_dma_addr = hwif->dma_base + IOC4_DMA_CTRL * 4;
186 unsigned int reg = readl((void __iomem *)ioc4_dma_addr); 186 unsigned int reg = readl((void __iomem *)ioc4_dma_addr);
187 unsigned int temp_reg = reg | IOC4_S_DMA_START; 187 unsigned int temp_reg = reg | IOC4_S_DMA_START;
@@ -209,7 +209,7 @@ sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
209static int sgiioc4_dma_end(ide_drive_t *drive) 209static int sgiioc4_dma_end(ide_drive_t *drive)
210{ 210{
211 u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0; 211 u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0;
212 ide_hwif_t *hwif = HWIF(drive); 212 ide_hwif_t *hwif = drive->hwif;
213 unsigned long dma_base = hwif->dma_base; 213 unsigned long dma_base = hwif->dma_base;
214 int dma_stat = 0; 214 int dma_stat = 0;
215 unsigned long *ending_dma = ide_get_hwifdata(hwif); 215 unsigned long *ending_dma = ide_get_hwifdata(hwif);
@@ -271,7 +271,7 @@ static void sgiioc4_set_dma_mode(ide_drive_t *drive, const u8 speed)
271/* returns 1 if dma irq issued, 0 otherwise */ 271/* returns 1 if dma irq issued, 0 otherwise */
272static int sgiioc4_dma_test_irq(ide_drive_t *drive) 272static int sgiioc4_dma_test_irq(ide_drive_t *drive)
273{ 273{
274 return sgiioc4_checkirq(HWIF(drive)); 274 return sgiioc4_checkirq(drive->hwif);
275} 275}
276 276
277static void sgiioc4_dma_host_set(ide_drive_t *drive, int on) 277static void sgiioc4_dma_host_set(ide_drive_t *drive, int on)
@@ -367,7 +367,7 @@ static void
367sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive) 367sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
368{ 368{
369 u32 ioc4_dma; 369 u32 ioc4_dma;
370 ide_hwif_t *hwif = HWIF(drive); 370 ide_hwif_t *hwif = drive->hwif;
371 unsigned long dma_base = hwif->dma_base; 371 unsigned long dma_base = hwif->dma_base;
372 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4; 372 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
373 u32 dma_addr, ending_dma_addr; 373 u32 dma_addr, ending_dma_addr;
@@ -427,7 +427,7 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
427static unsigned int 427static unsigned int
428sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir) 428sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir)
429{ 429{
430 ide_hwif_t *hwif = HWIF(drive); 430 ide_hwif_t *hwif = drive->hwif;
431 unsigned int *table = hwif->dmatable_cpu; 431 unsigned int *table = hwif->dmatable_cpu;
432 unsigned int count = 0, i = 1; 432 unsigned int count = 0, i = 1;
433 struct scatterlist *sg; 433 struct scatterlist *sg;
@@ -492,7 +492,7 @@ use_pio_instead:
492 492
493static int sgiioc4_dma_setup(ide_drive_t *drive) 493static int sgiioc4_dma_setup(ide_drive_t *drive)
494{ 494{
495 struct request *rq = HWGROUP(drive)->rq; 495 struct request *rq = drive->hwif->rq;
496 unsigned int count = 0; 496 unsigned int count = 0;
497 int ddir; 497 int ddir;
498 498
@@ -523,7 +523,6 @@ static const struct ide_tp_ops sgiioc4_tp_ops = {
523 .exec_command = ide_exec_command, 523 .exec_command = ide_exec_command,
524 .read_status = sgiioc4_read_status, 524 .read_status = sgiioc4_read_status,
525 .read_altstatus = ide_read_altstatus, 525 .read_altstatus = ide_read_altstatus,
526 .read_sff_dma_status = ide_read_sff_dma_status,
527 526
528 .set_irq = ide_set_irq, 527 .set_irq = ide_set_irq,
529 528
diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
index 7d622d20bc4c..cb2b352b876b 100644
--- a/drivers/ide/siimage.c
+++ b/drivers/ide/siimage.c
@@ -114,7 +114,7 @@ static unsigned long siimage_selreg(ide_hwif_t *hwif, int r)
114 114
115static inline unsigned long siimage_seldev(ide_drive_t *drive, int r) 115static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
116{ 116{
117 ide_hwif_t *hwif = HWIF(drive); 117 ide_hwif_t *hwif = drive->hwif;
118 unsigned long base = (unsigned long)hwif->hwif_data; 118 unsigned long base = (unsigned long)hwif->hwif_data;
119 u8 unit = drive->dn & 1; 119 u8 unit = drive->dn & 1;
120 120
@@ -243,7 +243,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
243 static const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 }; 243 static const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 };
244 static const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 }; 244 static const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 };
245 245
246 ide_hwif_t *hwif = HWIF(drive); 246 ide_hwif_t *hwif = drive->hwif;
247 struct pci_dev *dev = to_pci_dev(hwif->dev); 247 struct pci_dev *dev = to_pci_dev(hwif->dev);
248 ide_drive_t *pair = ide_get_pair_dev(drive); 248 ide_drive_t *pair = ide_get_pair_dev(drive);
249 u32 speedt = 0; 249 u32 speedt = 0;
@@ -300,7 +300,7 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
300 static const u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 }; 300 static const u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 };
301 static const u16 dma[] = { 0x2208, 0x10C2, 0x10C1 }; 301 static const u16 dma[] = { 0x2208, 0x10C2, 0x10C1 };
302 302
303 ide_hwif_t *hwif = HWIF(drive); 303 ide_hwif_t *hwif = drive->hwif;
304 struct pci_dev *dev = to_pci_dev(hwif->dev); 304 struct pci_dev *dev = to_pci_dev(hwif->dev);
305 unsigned long base = (unsigned long)hwif->hwif_data; 305 unsigned long base = (unsigned long)hwif->hwif_data;
306 u16 ultra = 0, multi = 0; 306 u16 ultra = 0, multi = 0;
@@ -340,7 +340,7 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
340/* returns 1 if dma irq issued, 0 otherwise */ 340/* returns 1 if dma irq issued, 0 otherwise */
341static int siimage_io_dma_test_irq(ide_drive_t *drive) 341static int siimage_io_dma_test_irq(ide_drive_t *drive)
342{ 342{
343 ide_hwif_t *hwif = HWIF(drive); 343 ide_hwif_t *hwif = drive->hwif;
344 struct pci_dev *dev = to_pci_dev(hwif->dev); 344 struct pci_dev *dev = to_pci_dev(hwif->dev);
345 u8 dma_altstat = 0; 345 u8 dma_altstat = 0;
346 unsigned long addr = siimage_selreg(hwif, 1); 346 unsigned long addr = siimage_selreg(hwif, 1);
@@ -367,7 +367,7 @@ static int siimage_io_dma_test_irq(ide_drive_t *drive)
367 367
368static int siimage_mmio_dma_test_irq(ide_drive_t *drive) 368static int siimage_mmio_dma_test_irq(ide_drive_t *drive)
369{ 369{
370 ide_hwif_t *hwif = HWIF(drive); 370 ide_hwif_t *hwif = drive->hwif;
371 unsigned long addr = siimage_selreg(hwif, 0x1); 371 unsigned long addr = siimage_selreg(hwif, 0x1);
372 void __iomem *sata_error_addr 372 void __iomem *sata_error_addr
373 = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET]; 373 = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET];
@@ -717,6 +717,7 @@ static const struct ide_dma_ops sil_dma_ops = {
717 .dma_test_irq = siimage_dma_test_irq, 717 .dma_test_irq = siimage_dma_test_irq,
718 .dma_timeout = ide_dma_timeout, 718 .dma_timeout = ide_dma_timeout,
719 .dma_lost_irq = ide_dma_lost_irq, 719 .dma_lost_irq = ide_dma_lost_irq,
720 .dma_sff_read_status = ide_dma_sff_read_status,
720}; 721};
721 722
722#define DECLARE_SII_DEV(p_ops) \ 723#define DECLARE_SII_DEV(p_ops) \
diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
index ad32e18c5ba3..9ec1a4a4432c 100644
--- a/drivers/ide/sis5513.c
+++ b/drivers/ide/sis5513.c
@@ -274,7 +274,7 @@ static void sis_program_timings(ide_drive_t *drive, const u8 mode)
274 274
275static void config_drive_art_rwp(ide_drive_t *drive) 275static void config_drive_art_rwp(ide_drive_t *drive)
276{ 276{
277 ide_hwif_t *hwif = HWIF(drive); 277 ide_hwif_t *hwif = drive->hwif;
278 struct pci_dev *dev = to_pci_dev(hwif->dev); 278 struct pci_dev *dev = to_pci_dev(hwif->dev);
279 u8 reg4bh = 0; 279 u8 reg4bh = 0;
280 u8 rw_prefetch = 0; 280 u8 rw_prefetch = 0;
diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
index 84dc33602ff8..48cc748c5043 100644
--- a/drivers/ide/sl82c105.c
+++ b/drivers/ide/sl82c105.c
@@ -140,7 +140,7 @@ static inline void sl82c105_reset_host(struct pci_dev *dev)
140 */ 140 */
141static void sl82c105_dma_lost_irq(ide_drive_t *drive) 141static void sl82c105_dma_lost_irq(ide_drive_t *drive)
142{ 142{
143 ide_hwif_t *hwif = HWIF(drive); 143 ide_hwif_t *hwif = drive->hwif;
144 struct pci_dev *dev = to_pci_dev(hwif->dev); 144 struct pci_dev *dev = to_pci_dev(hwif->dev);
145 u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA; 145 u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA;
146 u8 dma_cmd; 146 u8 dma_cmd;
@@ -177,7 +177,7 @@ static void sl82c105_dma_lost_irq(ide_drive_t *drive)
177 */ 177 */
178static void sl82c105_dma_start(ide_drive_t *drive) 178static void sl82c105_dma_start(ide_drive_t *drive)
179{ 179{
180 ide_hwif_t *hwif = HWIF(drive); 180 ide_hwif_t *hwif = drive->hwif;
181 struct pci_dev *dev = to_pci_dev(hwif->dev); 181 struct pci_dev *dev = to_pci_dev(hwif->dev);
182 int reg = 0x44 + drive->dn * 4; 182 int reg = 0x44 + drive->dn * 4;
183 183
@@ -299,6 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
299 .dma_test_irq = ide_dma_test_irq, 299 .dma_test_irq = ide_dma_test_irq,
300 .dma_lost_irq = sl82c105_dma_lost_irq, 300 .dma_lost_irq = sl82c105_dma_lost_irq,
301 .dma_timeout = sl82c105_dma_timeout, 301 .dma_timeout = sl82c105_dma_timeout,
302 .dma_sff_read_status = ide_dma_sff_read_status,
302}; 303};
303 304
304static const struct ide_port_info sl82c105_chipset __devinitdata = { 305static const struct ide_port_info sl82c105_chipset __devinitdata = {
diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
index 0f759e4ed779..40b4b94a4288 100644
--- a/drivers/ide/slc90e66.c
+++ b/drivers/ide/slc90e66.c
@@ -20,7 +20,7 @@ static DEFINE_SPINLOCK(slc90e66_lock);
20 20
21static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio) 21static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
22{ 22{
23 ide_hwif_t *hwif = HWIF(drive); 23 ide_hwif_t *hwif = drive->hwif;
24 struct pci_dev *dev = to_pci_dev(hwif->dev); 24 struct pci_dev *dev = to_pci_dev(hwif->dev);
25 int is_slave = drive->dn & 1; 25 int is_slave = drive->dn & 1;
26 int master_port = hwif->channel ? 0x42 : 0x40; 26 int master_port = hwif->channel ? 0x42 : 0x40;
@@ -73,7 +73,7 @@ static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
73 73
74static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed) 74static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
75{ 75{
76 ide_hwif_t *hwif = HWIF(drive); 76 ide_hwif_t *hwif = drive->hwif;
77 struct pci_dev *dev = to_pci_dev(hwif->dev); 77 struct pci_dev *dev = to_pci_dev(hwif->dev);
78 u8 maslave = hwif->channel ? 0x42 : 0x40; 78 u8 maslave = hwif->channel ? 0x42 : 0x40;
79 int sitre = 0, a_speed = 7 << (drive->dn * 4); 79 int sitre = 0, a_speed = 7 << (drive->dn * 4);
diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
index 93e2cce4b296..84109f5a1632 100644
--- a/drivers/ide/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -15,7 +15,7 @@
15 15
16static void tc86c001_set_mode(ide_drive_t *drive, const u8 speed) 16static void tc86c001_set_mode(ide_drive_t *drive, const u8 speed)
17{ 17{
18 ide_hwif_t *hwif = HWIF(drive); 18 ide_hwif_t *hwif = drive->hwif;
19 unsigned long scr_port = hwif->config_data + (drive->dn ? 0x02 : 0x00); 19 unsigned long scr_port = hwif->config_data + (drive->dn ? 0x02 : 0x00);
20 u16 mode, scr = inw(scr_port); 20 u16 mode, scr = inw(scr_port);
21 21
@@ -62,13 +62,12 @@ static void tc86c001_set_pio_mode(ide_drive_t *drive, const u8 pio)
62 */ 62 */
63static int tc86c001_timer_expiry(ide_drive_t *drive) 63static int tc86c001_timer_expiry(ide_drive_t *drive)
64{ 64{
65 ide_hwif_t *hwif = HWIF(drive); 65 ide_hwif_t *hwif = drive->hwif;
66 ide_expiry_t *expiry = ide_get_hwifdata(hwif); 66 ide_expiry_t *expiry = ide_get_hwifdata(hwif);
67 ide_hwgroup_t *hwgroup = HWGROUP(drive);
68 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 67 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
69 68
70 /* Restore a higher level driver's expiry handler first. */ 69 /* Restore a higher level driver's expiry handler first. */
71 hwgroup->expiry = expiry; 70 hwif->expiry = expiry;
72 71
73 if ((dma_stat & 5) == 1) { /* DMA active and no interrupt */ 72 if ((dma_stat & 5) == 1) { /* DMA active and no interrupt */
74 unsigned long sc_base = hwif->config_data; 73 unsigned long sc_base = hwif->config_data;
@@ -110,11 +109,10 @@ static int tc86c001_timer_expiry(ide_drive_t *drive)
110 109
111static void tc86c001_dma_start(ide_drive_t *drive) 110static void tc86c001_dma_start(ide_drive_t *drive)
112{ 111{
113 ide_hwif_t *hwif = HWIF(drive); 112 ide_hwif_t *hwif = drive->hwif;
114 ide_hwgroup_t *hwgroup = HWGROUP(drive);
115 unsigned long sc_base = hwif->config_data; 113 unsigned long sc_base = hwif->config_data;
116 unsigned long twcr_port = sc_base + (drive->dn ? 0x06 : 0x04); 114 unsigned long twcr_port = sc_base + (drive->dn ? 0x06 : 0x04);
117 unsigned long nsectors = hwgroup->rq->nr_sectors; 115 unsigned long nsectors = hwif->rq->nr_sectors;
118 116
119 /* 117 /*
120 * We have to manually load the sector count and size into 118 * We have to manually load the sector count and size into
@@ -125,8 +123,8 @@ static void tc86c001_dma_start(ide_drive_t *drive)
125 outw(SECTOR_SIZE / 2, twcr_port); /* Transfer Word Count 1/2 */ 123 outw(SECTOR_SIZE / 2, twcr_port); /* Transfer Word Count 1/2 */
126 124
127 /* Install our timeout expiry hook, saving the current handler... */ 125 /* Install our timeout expiry hook, saving the current handler... */
128 ide_set_hwifdata(hwif, hwgroup->expiry); 126 ide_set_hwifdata(hwif, hwif->expiry);
129 hwgroup->expiry = &tc86c001_timer_expiry; 127 hwif->expiry = &tc86c001_timer_expiry;
130 128
131 ide_dma_start(drive); 129 ide_dma_start(drive);
132} 130}
@@ -190,6 +188,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
190 .dma_test_irq = ide_dma_test_irq, 188 .dma_test_irq = ide_dma_test_irq,
191 .dma_lost_irq = ide_dma_lost_irq, 189 .dma_lost_irq = ide_dma_lost_irq,
192 .dma_timeout = ide_dma_timeout, 190 .dma_timeout = ide_dma_timeout,
191 .dma_sff_read_status = ide_dma_sff_read_status,
193}; 192};
194 193
195static const struct ide_port_info tc86c001_chipset __devinitdata = { 194static const struct ide_port_info tc86c001_chipset __devinitdata = {
diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
index b6ff40336aa9..8773c3ba7462 100644
--- a/drivers/ide/triflex.c
+++ b/drivers/ide/triflex.c
@@ -36,7 +36,7 @@
36 36
37static void triflex_set_mode(ide_drive_t *drive, const u8 speed) 37static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
38{ 38{
39 ide_hwif_t *hwif = HWIF(drive); 39 ide_hwif_t *hwif = drive->hwif;
40 struct pci_dev *dev = to_pci_dev(hwif->dev); 40 struct pci_dev *dev = to_pci_dev(hwif->dev);
41 u32 triflex_timings = 0; 41 u32 triflex_timings = 0;
42 u16 timing = 0; 42 u16 timing = 0;
diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
index 75ea61526566..b6a1285a4021 100644
--- a/drivers/ide/trm290.c
+++ b/drivers/ide/trm290.c
@@ -144,7 +144,7 @@
144 144
145static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma) 145static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
146{ 146{
147 ide_hwif_t *hwif = HWIF(drive); 147 ide_hwif_t *hwif = drive->hwif;
148 u16 reg = 0; 148 u16 reg = 0;
149 unsigned long flags; 149 unsigned long flags;
150 150
@@ -184,7 +184,7 @@ static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command)
184static int trm290_dma_setup(ide_drive_t *drive) 184static int trm290_dma_setup(ide_drive_t *drive)
185{ 185{
186 ide_hwif_t *hwif = drive->hwif; 186 ide_hwif_t *hwif = drive->hwif;
187 struct request *rq = hwif->hwgroup->rq; 187 struct request *rq = hwif->rq;
188 unsigned int count, rw; 188 unsigned int count, rw;
189 189
190 if (rq_data_dir(rq)) { 190 if (rq_data_dir(rq)) {
@@ -222,15 +222,15 @@ static int trm290_dma_end(ide_drive_t *drive)
222 drive->waiting_for_dma = 0; 222 drive->waiting_for_dma = 0;
223 /* purge DMA mappings */ 223 /* purge DMA mappings */
224 ide_destroy_dmatable(drive); 224 ide_destroy_dmatable(drive);
225 status = inw(HWIF(drive)->dma_base + 2); 225 status = inw(drive->hwif->dma_base + 2);
226
226 return status != 0x00ff; 227 return status != 0x00ff;
227} 228}
228 229
229static int trm290_dma_test_irq(ide_drive_t *drive) 230static int trm290_dma_test_irq(ide_drive_t *drive)
230{ 231{
231 u16 status; 232 u16 status = inw(drive->hwif->dma_base + 2);
232 233
233 status = inw(HWIF(drive)->dma_base + 2);
234 return status == 0x00ff; 234 return status == 0x00ff;
235} 235}
236 236
@@ -328,10 +328,10 @@ static struct ide_dma_ops trm290_dma_ops = {
328static const struct ide_port_info trm290_chipset __devinitdata = { 328static const struct ide_port_info trm290_chipset __devinitdata = {
329 .name = DRV_NAME, 329 .name = DRV_NAME,
330 .init_hwif = init_hwif_trm290, 330 .init_hwif = init_hwif_trm290,
331 .chipset = ide_trm290,
332 .port_ops = &trm290_port_ops, 331 .port_ops = &trm290_port_ops,
333 .dma_ops = &trm290_dma_ops, 332 .dma_ops = &trm290_dma_ops,
334 .host_flags = IDE_HFLAG_NO_ATAPI_DMA | 333 .host_flags = IDE_HFLAG_TRM290 |
334 IDE_HFLAG_NO_ATAPI_DMA |
335#if 0 /* play it safe for now */ 335#if 0 /* play it safe for now */
336 IDE_HFLAG_TRUST_BIOS_FOR_DMA | 336 IDE_HFLAG_TRUST_BIOS_FOR_DMA |
337#endif 337#endif
diff --git a/drivers/ide/tx4938ide.c b/drivers/ide/tx4938ide.c
index 9120063e8f87..b4ef218072cd 100644
--- a/drivers/ide/tx4938ide.c
+++ b/drivers/ide/tx4938ide.c
@@ -181,7 +181,7 @@ static void tx4938ide_input_data_swap(ide_drive_t *drive, struct request *rq,
181 181
182 while (count--) 182 while (count--)
183 *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port)); 183 *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port));
184 __ide_flush_dcache_range((unsigned long)buf, count * 2); 184 __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
185} 185}
186 186
187static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq, 187static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq,
@@ -195,7 +195,7 @@ static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq,
195 __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port); 195 __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port);
196 ptr++; 196 ptr++;
197 } 197 }
198 __ide_flush_dcache_range((unsigned long)buf, count * 2); 198 __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
199} 199}
200 200
201static const struct ide_tp_ops tx4938ide_tp_ops = { 201static const struct ide_tp_ops tx4938ide_tp_ops = {
@@ -216,16 +216,17 @@ static const struct ide_tp_ops tx4938ide_tp_ops = {
216#endif /* __BIG_ENDIAN */ 216#endif /* __BIG_ENDIAN */
217 217
218static const struct ide_port_ops tx4938ide_port_ops = { 218static const struct ide_port_ops tx4938ide_port_ops = {
219 .set_pio_mode = tx4938ide_set_pio_mode, 219 .set_pio_mode = tx4938ide_set_pio_mode,
220}; 220};
221 221
222static const struct ide_port_info tx4938ide_port_info __initdata = { 222static const struct ide_port_info tx4938ide_port_info __initdata = {
223 .port_ops = &tx4938ide_port_ops, 223 .port_ops = &tx4938ide_port_ops,
224#ifdef __BIG_ENDIAN 224#ifdef __BIG_ENDIAN
225 .tp_ops = &tx4938ide_tp_ops, 225 .tp_ops = &tx4938ide_tp_ops,
226#endif 226#endif
227 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, 227 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
228 .pio_mask = ATA_PIO5, 228 .pio_mask = ATA_PIO5,
229 .chipset = ide_generic,
229}; 230};
230 231
231static int __init tx4938ide_probe(struct platform_device *pdev) 232static int __init tx4938ide_probe(struct platform_device *pdev)
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
index bafb7d1a22e2..882f6f07c476 100644
--- a/drivers/ide/tx4939ide.c
+++ b/drivers/ide/tx4939ide.c
@@ -259,6 +259,12 @@ static int tx4939ide_build_dmatable(ide_drive_t *drive, struct request *rq)
259 bcount = 0x10000 - (cur_addr & 0xffff); 259 bcount = 0x10000 - (cur_addr & 0xffff);
260 if (bcount > cur_len) 260 if (bcount > cur_len)
261 bcount = cur_len; 261 bcount = cur_len;
262 /*
263 * This workaround for zero count seems required.
264 * (standard ide_build_dmatable do it too)
265 */
266 if ((bcount & 0xffff) == 0x0000)
267 bcount = 0x8000;
262 *table++ = bcount & 0xffff; 268 *table++ = bcount & 0xffff;
263 *table++ = cur_addr; 269 *table++ = cur_addr;
264 cur_addr += bcount; 270 cur_addr += bcount;
@@ -287,7 +293,7 @@ static int tx4939ide_dma_setup(ide_drive_t *drive)
287{ 293{
288 ide_hwif_t *hwif = drive->hwif; 294 ide_hwif_t *hwif = drive->hwif;
289 void __iomem *base = TX4939IDE_BASE(hwif); 295 void __iomem *base = TX4939IDE_BASE(hwif);
290 struct request *rq = hwif->hwgroup->rq; 296 struct request *rq = hwif->rq;
291 u8 reading; 297 u8 reading;
292 int nent; 298 int nent;
293 299
@@ -391,6 +397,17 @@ static int tx4939ide_dma_test_irq(ide_drive_t *drive)
391 return found; 397 return found;
392} 398}
393 399
400#ifdef __BIG_ENDIAN
401static u8 tx4939ide_dma_sff_read_status(ide_hwif_t *hwif)
402{
403 void __iomem *base = TX4939IDE_BASE(hwif);
404
405 return tx4939ide_readb(base, TX4939IDE_DMA_Stat);
406}
407#else
408#define tx4939ide_dma_sff_read_status ide_dma_sff_read_status
409#endif
410
394static void tx4939ide_init_hwif(ide_hwif_t *hwif) 411static void tx4939ide_init_hwif(ide_hwif_t *hwif)
395{ 412{
396 void __iomem *base = TX4939IDE_BASE(hwif); 413 void __iomem *base = TX4939IDE_BASE(hwif);
@@ -437,13 +454,6 @@ static void tx4939ide_tf_load_fixup(ide_drive_t *drive, ide_task_t *task)
437 454
438#ifdef __BIG_ENDIAN 455#ifdef __BIG_ENDIAN
439 456
440static u8 tx4939ide_read_sff_dma_status(ide_hwif_t *hwif)
441{
442 void __iomem *base = TX4939IDE_BASE(hwif);
443
444 return tx4939ide_readb(base, TX4939IDE_DMA_Stat);
445}
446
447/* custom iops (independent from SWAP_IO_SPACE) */ 457/* custom iops (independent from SWAP_IO_SPACE) */
448static u8 tx4939ide_inb(unsigned long port) 458static u8 tx4939ide_inb(unsigned long port)
449{ 459{
@@ -558,7 +568,7 @@ static void tx4939ide_input_data_swap(ide_drive_t *drive, struct request *rq,
558 568
559 while (count--) 569 while (count--)
560 *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port)); 570 *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port));
561 __ide_flush_dcache_range((unsigned long)buf, count * 2); 571 __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
562} 572}
563 573
564static void tx4939ide_output_data_swap(ide_drive_t *drive, struct request *rq, 574static void tx4939ide_output_data_swap(ide_drive_t *drive, struct request *rq,
@@ -572,14 +582,13 @@ static void tx4939ide_output_data_swap(ide_drive_t *drive, struct request *rq,
572 __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port); 582 __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port);
573 ptr++; 583 ptr++;
574 } 584 }
575 __ide_flush_dcache_range((unsigned long)buf, count * 2); 585 __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
576} 586}
577 587
578static const struct ide_tp_ops tx4939ide_tp_ops = { 588static const struct ide_tp_ops tx4939ide_tp_ops = {
579 .exec_command = ide_exec_command, 589 .exec_command = ide_exec_command,
580 .read_status = ide_read_status, 590 .read_status = ide_read_status,
581 .read_altstatus = ide_read_altstatus, 591 .read_altstatus = ide_read_altstatus,
582 .read_sff_dma_status = tx4939ide_read_sff_dma_status,
583 592
584 .set_irq = ide_set_irq, 593 .set_irq = ide_set_irq,
585 594
@@ -603,7 +612,6 @@ static const struct ide_tp_ops tx4939ide_tp_ops = {
603 .exec_command = ide_exec_command, 612 .exec_command = ide_exec_command,
604 .read_status = ide_read_status, 613 .read_status = ide_read_status,
605 .read_altstatus = ide_read_altstatus, 614 .read_altstatus = ide_read_altstatus,
606 .read_sff_dma_status = ide_read_sff_dma_status,
607 615
608 .set_irq = ide_set_irq, 616 .set_irq = ide_set_irq,
609 617
@@ -617,33 +625,35 @@ static const struct ide_tp_ops tx4939ide_tp_ops = {
617#endif /* __LITTLE_ENDIAN */ 625#endif /* __LITTLE_ENDIAN */
618 626
619static const struct ide_port_ops tx4939ide_port_ops = { 627static const struct ide_port_ops tx4939ide_port_ops = {
620 .set_pio_mode = tx4939ide_set_pio_mode, 628 .set_pio_mode = tx4939ide_set_pio_mode,
621 .set_dma_mode = tx4939ide_set_dma_mode, 629 .set_dma_mode = tx4939ide_set_dma_mode,
622 .clear_irq = tx4939ide_clear_irq, 630 .clear_irq = tx4939ide_clear_irq,
623 .cable_detect = tx4939ide_cable_detect, 631 .cable_detect = tx4939ide_cable_detect,
624}; 632};
625 633
626static const struct ide_dma_ops tx4939ide_dma_ops = { 634static const struct ide_dma_ops tx4939ide_dma_ops = {
627 .dma_host_set = tx4939ide_dma_host_set, 635 .dma_host_set = tx4939ide_dma_host_set,
628 .dma_setup = tx4939ide_dma_setup, 636 .dma_setup = tx4939ide_dma_setup,
629 .dma_exec_cmd = ide_dma_exec_cmd, 637 .dma_exec_cmd = ide_dma_exec_cmd,
630 .dma_start = ide_dma_start, 638 .dma_start = ide_dma_start,
631 .dma_end = tx4939ide_dma_end, 639 .dma_end = tx4939ide_dma_end,
632 .dma_test_irq = tx4939ide_dma_test_irq, 640 .dma_test_irq = tx4939ide_dma_test_irq,
633 .dma_lost_irq = ide_dma_lost_irq, 641 .dma_lost_irq = ide_dma_lost_irq,
634 .dma_timeout = ide_dma_timeout, 642 .dma_timeout = ide_dma_timeout,
643 .dma_sff_read_status = tx4939ide_dma_sff_read_status,
635}; 644};
636 645
637static const struct ide_port_info tx4939ide_port_info __initdata = { 646static const struct ide_port_info tx4939ide_port_info __initdata = {
638 .init_hwif = tx4939ide_init_hwif, 647 .init_hwif = tx4939ide_init_hwif,
639 .init_dma = tx4939ide_init_dma, 648 .init_dma = tx4939ide_init_dma,
640 .port_ops = &tx4939ide_port_ops, 649 .port_ops = &tx4939ide_port_ops,
641 .dma_ops = &tx4939ide_dma_ops, 650 .dma_ops = &tx4939ide_dma_ops,
642 .tp_ops = &tx4939ide_tp_ops, 651 .tp_ops = &tx4939ide_tp_ops,
643 .host_flags = IDE_HFLAG_MMIO, 652 .host_flags = IDE_HFLAG_MMIO,
644 .pio_mask = ATA_PIO4, 653 .pio_mask = ATA_PIO4,
645 .mwdma_mask = ATA_MWDMA2, 654 .mwdma_mask = ATA_MWDMA2,
646 .udma_mask = ATA_UDMA5, 655 .udma_mask = ATA_UDMA5,
656 .chipset = ide_generic,
647}; 657};
648 658
649static int __init tx4939ide_probe(struct platform_device *pdev) 659static int __init tx4939ide_probe(struct platform_device *pdev)
diff --git a/drivers/ide/umc8672.c b/drivers/ide/umc8672.c
index 1da076e0c917..0608d41fb6d0 100644
--- a/drivers/ide/umc8672.c
+++ b/drivers/ide/umc8672.c
@@ -106,19 +106,21 @@ static void umc_set_speeds(u8 speeds[])
106 106
107static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio) 107static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio)
108{ 108{
109 ide_hwif_t *hwif = drive->hwif; 109 ide_hwif_t *hwif = drive->hwif, *mate = hwif->mate;
110 unsigned long flags; 110 unsigned long uninitialized_var(flags);
111 111
112 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", 112 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n",
113 drive->name, pio, pio_to_umc[pio]); 113 drive->name, pio, pio_to_umc[pio]);
114 spin_lock_irqsave(&ide_lock, flags); 114 if (mate)
115 if (hwif->mate && hwif->mate->hwgroup->handler) { 115 spin_lock_irqsave(&mate->lock, flags);
116 if (mate && mate->handler) {
116 printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n"); 117 printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n");
117 } else { 118 } else {
118 current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio]; 119 current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio];
119 umc_set_speeds(current_speeds); 120 umc_set_speeds(current_speeds);
120 } 121 }
121 spin_unlock_irqrestore(&ide_lock, flags); 122 if (mate)
123 spin_unlock_irqrestore(&mate->lock, flags);
122} 124}
123 125
124static const struct ide_port_ops umc8672_port_ops = { 126static const struct ide_port_ops umc8672_port_ops = {
diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
index 2a812d3207e9..fecc0e03c3fc 100644
--- a/drivers/ide/via82cxxx.c
+++ b/drivers/ide/via82cxxx.c
@@ -178,7 +178,7 @@ static void via_set_drive(ide_drive_t *drive, const u8 speed)
178 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); 178 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
179 } 179 }
180 180
181 via_set_speed(HWIF(drive), drive->dn, &t); 181 via_set_speed(hwif, drive->dn, &t);
182} 182}
183 183
184/** 184/**