aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/Kconfig151
-rw-r--r--drivers/ide/Makefile109
-rw-r--r--drivers/ide/aec62xx.c (renamed from drivers/ide/pci/aec62xx.c)13
-rw-r--r--drivers/ide/ali14xx.c (renamed from drivers/ide/legacy/ali14xx.c)3
-rw-r--r--drivers/ide/alim15x3.c (renamed from drivers/ide/pci/alim15x3.c)26
-rw-r--r--drivers/ide/amd74xx.c (renamed from drivers/ide/pci/amd74xx.c)16
-rw-r--r--drivers/ide/arm/Makefile10
-rw-r--r--drivers/ide/atiixp.c (renamed from drivers/ide/pci/atiixp.c)9
-rw-r--r--drivers/ide/au1xxx-ide.c (renamed from drivers/ide/mips/au1xxx-ide.c)34
-rw-r--r--drivers/ide/buddha.c (renamed from drivers/ide/legacy/buddha.c)1
-rw-r--r--drivers/ide/cmd640.c (renamed from drivers/ide/pci/cmd640.c)51
-rw-r--r--drivers/ide/cmd64x.c (renamed from drivers/ide/pci/cmd64x.c)15
-rw-r--r--drivers/ide/cs5520.c (renamed from drivers/ide/pci/cs5520.c)7
-rw-r--r--drivers/ide/cs5530.c (renamed from drivers/ide/pci/cs5530.c)25
-rw-r--r--drivers/ide/cs5535.c (renamed from drivers/ide/pci/cs5535.c)22
-rw-r--r--drivers/ide/cy82c693.c (renamed from drivers/ide/pci/cy82c693.c)126
-rw-r--r--drivers/ide/delkin_cb.c (renamed from drivers/ide/pci/delkin_cb.c)70
-rw-r--r--drivers/ide/dtc2278.c (renamed from drivers/ide/legacy/dtc2278.c)1
-rw-r--r--drivers/ide/falconide.c (renamed from drivers/ide/legacy/falconide.c)1
-rw-r--r--drivers/ide/gayle.c (renamed from drivers/ide/legacy/gayle.c)1
-rw-r--r--drivers/ide/h8300/Makefile2
-rw-r--r--drivers/ide/hpt366.c (renamed from drivers/ide/pci/hpt366.c)129
-rw-r--r--drivers/ide/ht6560b.c (renamed from drivers/ide/legacy/ht6560b.c)10
-rw-r--r--drivers/ide/icside.c (renamed from drivers/ide/arm/icside.c)32
-rw-r--r--drivers/ide/ide-4drives.c (renamed from drivers/ide/legacy/ide-4drives.c)2
-rw-r--r--drivers/ide/ide-acpi.c18
-rw-r--r--drivers/ide/ide-atapi.c405
-rw-r--r--drivers/ide/ide-cd.c390
-rw-r--r--drivers/ide/ide-cd.h1
-rw-r--r--drivers/ide/ide-cd_ioctl.c8
-rw-r--r--drivers/ide/ide-cs.c (renamed from drivers/ide/legacy/ide-cs.c)160
-rw-r--r--drivers/ide/ide-disk.c868
-rw-r--r--drivers/ide/ide-disk.h29
-rw-r--r--drivers/ide/ide-disk_ioctl.c26
-rw-r--r--drivers/ide/ide-disk_proc.c129
-rw-r--r--drivers/ide/ide-dma-sff.c356
-rw-r--r--drivers/ide/ide-dma.c519
-rw-r--r--drivers/ide/ide-floppy.c1197
-rw-r--r--drivers/ide/ide-floppy.h39
-rw-r--r--drivers/ide/ide-floppy_ioctl.c289
-rw-r--r--drivers/ide/ide-floppy_proc.c33
-rw-r--r--drivers/ide/ide-gd.c401
-rw-r--r--drivers/ide/ide-gd.h44
-rw-r--r--drivers/ide/ide-generic.c102
-rw-r--r--drivers/ide/ide-h8300.c (renamed from drivers/ide/h8300/ide-h8300.c)2
-rw-r--r--drivers/ide/ide-io.c344
-rw-r--r--drivers/ide/ide-ioctls.c298
-rw-r--r--drivers/ide/ide-iops.c322
-rw-r--r--drivers/ide/ide-lib.c75
-rw-r--r--drivers/ide/ide-park.c121
-rw-r--r--drivers/ide/ide-pci-generic.c (renamed from drivers/ide/pci/generic.c)11
-rw-r--r--drivers/ide/ide-probe.c462
-rw-r--r--drivers/ide/ide-proc.c316
-rw-r--r--drivers/ide/ide-tape.c641
-rw-r--r--drivers/ide/ide-taskfile.c250
-rw-r--r--drivers/ide/ide-timings.c22
-rw-r--r--drivers/ide/ide.c351
-rw-r--r--drivers/ide/ide_arm.c (renamed from drivers/ide/arm/ide_arm.c)0
-rw-r--r--drivers/ide/ide_platform.c (renamed from drivers/ide/legacy/ide_platform.c)0
-rw-r--r--drivers/ide/it8213.c (renamed from drivers/ide/pci/it8213.c)9
-rw-r--r--drivers/ide/it821x.c (renamed from drivers/ide/pci/it821x.c)106
-rw-r--r--drivers/ide/jmicron.c (renamed from drivers/ide/pci/jmicron.c)11
-rw-r--r--drivers/ide/legacy/Makefile25
-rw-r--r--drivers/ide/macide.c (renamed from drivers/ide/legacy/macide.c)1
-rw-r--r--drivers/ide/mips/Makefile3
-rw-r--r--drivers/ide/ns87415.c (renamed from drivers/ide/pci/ns87415.c)30
-rw-r--r--drivers/ide/opti621.c (renamed from drivers/ide/pci/opti621.c)15
-rw-r--r--drivers/ide/palm_bk3710.c (renamed from drivers/ide/arm/palm_bk3710.c)8
-rw-r--r--drivers/ide/pci/Makefile44
-rw-r--r--drivers/ide/pci/hpt34x.c192
-rw-r--r--drivers/ide/pdc202xx_new.c (renamed from drivers/ide/pci/pdc202xx_new.c)21
-rw-r--r--drivers/ide/pdc202xx_old.c (renamed from drivers/ide/pci/pdc202xx_old.c)25
-rw-r--r--drivers/ide/piix.c (renamed from drivers/ide/pci/piix.c)53
-rw-r--r--drivers/ide/pmac.c (renamed from drivers/ide/ppc/pmac.c)77
-rw-r--r--drivers/ide/ppc/Makefile2
-rw-r--r--drivers/ide/q40ide.c (renamed from drivers/ide/legacy/q40ide.c)2
-rw-r--r--drivers/ide/qd65xx.c (renamed from drivers/ide/legacy/qd65xx.c)25
-rw-r--r--drivers/ide/qd65xx.h (renamed from drivers/ide/legacy/qd65xx.h)0
-rw-r--r--drivers/ide/rapide.c (renamed from drivers/ide/arm/rapide.c)4
-rw-r--r--drivers/ide/rz1000.c (renamed from drivers/ide/pci/rz1000.c)7
-rw-r--r--drivers/ide/sc1200.c (renamed from drivers/ide/pci/sc1200.c)27
-rw-r--r--drivers/ide/scc_pata.c (renamed from drivers/ide/pci/scc_pata.c)50
-rw-r--r--drivers/ide/serverworks.c (renamed from drivers/ide/pci/serverworks.c)17
-rw-r--r--drivers/ide/setup-pci.c33
-rw-r--r--drivers/ide/sgiioc4.c (renamed from drivers/ide/pci/sgiioc4.c)123
-rw-r--r--drivers/ide/siimage.c (renamed from drivers/ide/pci/siimage.c)38
-rw-r--r--drivers/ide/sis5513.c (renamed from drivers/ide/pci/sis5513.c)11
-rw-r--r--drivers/ide/sl82c105.c (renamed from drivers/ide/pci/sl82c105.c)15
-rw-r--r--drivers/ide/slc90e66.c (renamed from drivers/ide/pci/slc90e66.c)9
-rw-r--r--drivers/ide/tc86c001.c (renamed from drivers/ide/pci/tc86c001.c)8
-rw-r--r--drivers/ide/triflex.c (renamed from drivers/ide/pci/triflex.c)18
-rw-r--r--drivers/ide/trm290.c (renamed from drivers/ide/pci/trm290.c)11
-rw-r--r--drivers/ide/tx4938ide.c323
-rw-r--r--drivers/ide/tx4939ide.c754
-rw-r--r--drivers/ide/umc8672.c (renamed from drivers/ide/legacy/umc8672.c)1
-rw-r--r--drivers/ide/via82cxxx.c (renamed from drivers/ide/pci/via82cxxx.c)16
96 files changed, 5767 insertions, 5442 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 052879a6f853..6d7401772a8f 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -4,7 +4,7 @@
4 4
5# Select HAVE_IDE if IDE is supported 5# Select HAVE_IDE if IDE is supported
6config HAVE_IDE 6config HAVE_IDE
7 def_bool n 7 bool
8 8
9menuconfig IDE 9menuconfig IDE
10 tristate "ATA/ATAPI/MFM/RLL support" 10 tristate "ATA/ATAPI/MFM/RLL support"
@@ -54,38 +54,6 @@ menuconfig IDE
54 54
55if IDE 55if IDE
56 56
57config BLK_DEV_IDE
58 tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support"
59 ---help---
60 If you say Y here, you will use the full-featured IDE driver to
61 control up to ten ATA/IDE interfaces, each being able to serve a
62 "master" and a "slave" device, for a total of up to twenty ATA/IDE
63 disk/cdrom/tape/floppy drives.
64
65 Useful information about large (>540 MB) IDE disks, multiple
66 interfaces, what to do if ATA/IDE devices are not automatically
67 detected, sound card ATA/IDE ports, module support, and other
68 topics, is contained in <file:Documentation/ide/ide.txt>. For detailed
69 information about hard drives, consult the Disk-HOWTO and the
70 Multi-Disk-HOWTO, available from
71 <http://www.tldp.org/docs.html#howto>.
72
73 To fine-tune ATA/IDE drive/interface parameters for improved
74 performance, look for the hdparm package at
75 <ftp://ibiblio.org/pub/Linux/system/hardware/>.
76
77 To compile this driver as a module, choose M here and read
78 <file:Documentation/ide/ide.txt>. The module will be called ide-mod.
79 Do not compile this driver as a module if your root file system (the
80 one containing the directory /) is located on an IDE device.
81
82 If you have one or more IDE drives, say Y or M here. If your system
83 has no IDE drives, or if memory requirements are really tight, you
84 could say N here, and select the "Old hard disk driver" below
85 instead to save about 13 KB of memory in the kernel.
86
87if BLK_DEV_IDE
88
89comment "Please see Documentation/ide/ide.txt for help/info on IDE drives" 57comment "Please see Documentation/ide/ide.txt for help/info on IDE drives"
90 58
91config IDE_TIMINGS 59config IDE_TIMINGS
@@ -116,43 +84,39 @@ config BLK_DEV_IDE_SATA
116 84
117 If unsure, say N. 85 If unsure, say N.
118 86
119config BLK_DEV_IDEDISK 87config IDE_GD
120 tristate "Include IDE/ATA-2 DISK support" 88 tristate "generic ATA/ATAPI disk support"
121 ---help--- 89 default y
122 This will include enhanced support for MFM/RLL/IDE hard disks. If 90 help
123 you have a MFM/RLL/IDE disk, and there is no special reason to use 91 Support for ATA/ATAPI disks (including ATAPI floppy drives).
124 the old hard disk driver instead, say Y. If you have an SCSI-only
125 system, you can say N here.
126 92
127 To compile this driver as a module, choose M here: the 93 To compile this driver as a module, choose M here.
128 module will be called ide-disk. 94 The module will be called ide-gd_mod.
129 Do not compile this driver as a module if your root file system
130 (the one containing the directory /) is located on the IDE disk.
131 95
132 If unsure, say Y. 96 If unsure, say Y.
133 97
134config IDEDISK_MULTI_MODE 98config IDE_GD_ATA
135 bool "Use multiple sector mode for Programmed Input/Output by default" 99 bool "ATA disk support"
100 depends on IDE_GD
101 default y
136 help 102 help
137 This setting is irrelevant for most IDE disks, with direct memory 103 This will include support for ATA hard disks.
138 access, to which multiple sector mode does not apply. Multiple sector 104
139 mode is a feature of most modern IDE hard drives, permitting the 105 If unsure, say Y.
140 transfer of multiple sectors per Programmed Input/Output interrupt,
141 rather than the usual one sector per interrupt. When this feature is
142 enabled, it can reduce operating system overhead for disk Programmed
143 Input/Output. On some systems, it also can increase the data
144 throughput of Programmed Input/Output. Some drives, however, seemed
145 to run slower with multiple sector mode enabled. Some drives claimed
146 to support multiple sector mode, but lost data at some settings.
147 Under rare circumstances, such failures could result in massive
148 filesystem corruption.
149 106
150 If you get the following error, try to say Y here: 107config IDE_GD_ATAPI
108 bool "ATAPI floppy support"
109 depends on IDE_GD
110 select IDE_ATAPI
111 help
112 This will include support for ATAPI floppy drives
113 (i.e. Iomega ZIP or MKE LS-120).
151 114
152 hda: set_multmode: status=0x51 { DriveReady SeekComplete Error } 115 For information about jumper settings and the question
153 hda: set_multmode: error=0x04 { DriveStatusError } 116 of when a ZIP drive uses a partition table, see
117 <http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>.
154 118
155 If in doubt, say N. 119 If unsure, say N.
156 120
157config BLK_DEV_IDECS 121config BLK_DEV_IDECS
158 tristate "PCMCIA IDE support" 122 tristate "PCMCIA IDE support"
@@ -218,29 +182,6 @@ config BLK_DEV_IDETAPE
218 To compile this driver as a module, choose M here: the 182 To compile this driver as a module, choose M here: the
219 module will be called ide-tape. 183 module will be called ide-tape.
220 184
221config BLK_DEV_IDEFLOPPY
222 tristate "Include IDE/ATAPI FLOPPY support"
223 select IDE_ATAPI
224 ---help---
225 If you have an IDE floppy drive which uses the ATAPI protocol,
226 answer Y. ATAPI is a newer protocol used by IDE CD-ROM/tape/floppy
227 drives, similar to the SCSI protocol.
228
229 The LS-120 and the IDE/ATAPI Iomega ZIP drive are also supported by
230 this driver. For information about jumper settings and the question
231 of when a ZIP drive uses a partition table, see
232 <http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>.
233 (ATAPI PD-CD/CDR drives are not supported by this driver; support
234 for PD-CD/CDR drives is available if you answer Y to
235 "SCSI emulation support", below).
236
237 If you say Y here, the FLOPPY drive will be identified along with
238 other IDE devices, as "hdb" or "hdc", or something similar (check
239 the boot messages with dmesg).
240
241 To compile this driver as a module, choose M here: the
242 module will be called ide-floppy.
243
244config BLK_DEV_IDESCSI 185config BLK_DEV_IDESCSI
245 tristate "SCSI emulation support (DEPRECATED)" 186 tristate "SCSI emulation support (DEPRECATED)"
246 depends on SCSI 187 depends on SCSI
@@ -371,7 +312,7 @@ config BLK_DEV_IDEPCI
371 312
372config IDEPCI_PCIBUS_ORDER 313config IDEPCI_PCIBUS_ORDER
373 bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)" 314 bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)"
374 depends on BLK_DEV_IDE=y && BLK_DEV_IDEPCI 315 depends on IDE=y && BLK_DEV_IDEPCI
375 default y 316 default y
376 help 317 help
377 Probe IDE PCI devices in the order in which they appear on the 318 Probe IDE PCI devices in the order in which they appear on the
@@ -387,7 +328,7 @@ config IDEPCI_PCIBUS_ORDER
387# TODO: split it on per host driver config options (or module parameters) 328# TODO: split it on per host driver config options (or module parameters)
388config BLK_DEV_OFFBOARD 329config BLK_DEV_OFFBOARD
389 bool "Boot off-board chipsets first support (DEPRECATED)" 330 bool "Boot off-board chipsets first support (DEPRECATED)"
390 depends on BLK_DEV_IDEPCI && (BLK_DEV_AEC62XX || BLK_DEV_GENERIC || BLK_DEV_HPT34X || BLK_DEV_HPT366 || BLK_DEV_PDC202XX_NEW || BLK_DEV_PDC202XX_OLD || BLK_DEV_TC86C001) 331 depends on BLK_DEV_IDEPCI && (BLK_DEV_AEC62XX || BLK_DEV_GENERIC || BLK_DEV_HPT366 || BLK_DEV_PDC202XX_NEW || BLK_DEV_PDC202XX_OLD || BLK_DEV_TC86C001)
391 help 332 help
392 Normally, IDE controllers built into the motherboard (on-board 333 Normally, IDE controllers built into the motherboard (on-board
393 controllers) are assigned to ide0 and ide1 while those on add-in PCI 334 controllers) are assigned to ide0 and ide1 while those on add-in PCI
@@ -537,28 +478,6 @@ config BLK_DEV_CS5535
537 478
538 It is safe to say Y to this question. 479 It is safe to say Y to this question.
539 480
540config BLK_DEV_HPT34X
541 tristate "HPT34X chipset support"
542 depends on BROKEN
543 select BLK_DEV_IDEDMA_PCI
544 help
545 This driver adds up to 4 more EIDE devices sharing a single
546 interrupt. The HPT343 chipset in its current form is a non-bootable
547 controller; the HPT345/HPT363 chipset is a bootable (needs BIOS FIX)
548 PCI UDMA controllers. This driver requires dynamic tuning of the
549 chipset during the ide-probe at boot time. It is reported to support
550 DVD II drives, by the manufacturer.
551
552config HPT34X_AUTODMA
553 bool "HPT34X AUTODMA support (EXPERIMENTAL)"
554 depends on BLK_DEV_HPT34X && EXPERIMENTAL
555 help
556 This is a dangerous thing to attempt currently! Please read the
557 comments at the top of <file:drivers/ide/pci/hpt34x.c>. If you say Y
558 here, then say Y to "Use DMA by default when available" as well.
559
560 If unsure, say N.
561
562config BLK_DEV_HPT366 481config BLK_DEV_HPT366
563 tristate "HPT36X/37X chipset support" 482 tristate "HPT36X/37X chipset support"
564 select BLK_DEV_IDEDMA_PCI 483 select BLK_DEV_IDEDMA_PCI
@@ -752,7 +671,7 @@ endif
752 671
753config BLK_DEV_IDE_PMAC 672config BLK_DEV_IDE_PMAC
754 tristate "PowerMac on-board IDE support" 673 tristate "PowerMac on-board IDE support"
755 depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y 674 depends on PPC_PMAC && IDE=y
756 select IDE_TIMINGS 675 select IDE_TIMINGS
757 help 676 help
758 This driver provides support for the on-board IDE controller on 677 This driver provides support for the on-board IDE controller on
@@ -801,6 +720,16 @@ config BLK_DEV_IDE_AU1XXX_SEQTS_PER_RQ
801 default "128" 720 default "128"
802 depends on BLK_DEV_IDE_AU1XXX 721 depends on BLK_DEV_IDE_AU1XXX
803 722
723config BLK_DEV_IDE_TX4938
724 tristate "TX4938 internal IDE support"
725 depends on SOC_TX4938
726 select IDE_TIMINGS
727
728config BLK_DEV_IDE_TX4939
729 tristate "TX4939 internal IDE support"
730 depends on SOC_TX4939
731 select BLK_DEV_IDEDMA_SFF
732
804config IDE_ARM 733config IDE_ARM
805 tristate "ARM IDE support" 734 tristate "ARM IDE support"
806 depends on ARM && (ARCH_CLPS7500 || ARCH_RPC || ARCH_SHARK) 735 depends on ARM && (ARCH_CLPS7500 || ARCH_RPC || ARCH_SHARK)
@@ -986,6 +915,4 @@ config BLK_DEV_IDEDMA
986 def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \ 915 def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \
987 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 916 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
988 917
989endif
990
991endif # IDE 918endif # IDE
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 64e0ecdc4ed5..7818d402b188 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -4,53 +4,112 @@
4 4
5EXTRA_CFLAGS += -Idrivers/ide 5EXTRA_CFLAGS += -Idrivers/ide
6 6
7ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o \ 7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8 ide-pio-blacklist.o 8 ide-taskfile.o ide-park.o ide-pio-blacklist.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
12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o 12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o
13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o 13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o
14ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o 14ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o
15ide-core-$(CONFIG_BLK_DEV_IDEDMA_SFF) += ide-dma-sff.o
15ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o 16ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o
16ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o 17ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o
17 18
18obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o 19obj-$(CONFIG_IDE) += ide-core.o
19 20
20ifeq ($(CONFIG_IDE_ARM), y) 21obj-$(CONFIG_IDE_ARM) += ide_arm.o
21 ide-arm-core-y += arm/ide_arm.o 22
22 obj-y += ide-arm-core.o 23obj-$(CONFIG_BLK_DEV_ALI14XX) += ali14xx.o
23endif 24obj-$(CONFIG_BLK_DEV_UMC8672) += umc8672.o
25obj-$(CONFIG_BLK_DEV_DTC2278) += dtc2278.o
26obj-$(CONFIG_BLK_DEV_HT6560B) += ht6560b.o
27obj-$(CONFIG_BLK_DEV_QD65XX) += qd65xx.o
28obj-$(CONFIG_BLK_DEV_4DRIVES) += ide-4drives.o
29
30obj-$(CONFIG_BLK_DEV_GAYLE) += gayle.o
31obj-$(CONFIG_BLK_DEV_FALCON_IDE) += falconide.o
32obj-$(CONFIG_BLK_DEV_MAC_IDE) += macide.o
33obj-$(CONFIG_BLK_DEV_Q40IDE) += q40ide.o
34obj-$(CONFIG_BLK_DEV_BUDDHA) += buddha.o
24 35
25obj-$(CONFIG_BLK_DEV_IDE) += legacy/ pci/ 36obj-$(CONFIG_BLK_DEV_AEC62XX) += aec62xx.o
37obj-$(CONFIG_BLK_DEV_ALI15X3) += alim15x3.o
38obj-$(CONFIG_BLK_DEV_AMD74XX) += amd74xx.o
39obj-$(CONFIG_BLK_DEV_ATIIXP) += atiixp.o
40obj-$(CONFIG_BLK_DEV_CELLEB) += scc_pata.o
41obj-$(CONFIG_BLK_DEV_CMD64X) += cmd64x.o
42obj-$(CONFIG_BLK_DEV_CS5520) += cs5520.o
43obj-$(CONFIG_BLK_DEV_CS5530) += cs5530.o
44obj-$(CONFIG_BLK_DEV_CS5535) += cs5535.o
45obj-$(CONFIG_BLK_DEV_SC1200) += sc1200.o
46obj-$(CONFIG_BLK_DEV_CY82C693) += cy82c693.o
47obj-$(CONFIG_BLK_DEV_DELKIN) += delkin_cb.o
48obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o
49obj-$(CONFIG_BLK_DEV_IT8213) += it8213.o
50obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o
51obj-$(CONFIG_BLK_DEV_JMICRON) += jmicron.o
52obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o
53obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o
54obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o
55obj-$(CONFIG_BLK_DEV_PDC202XX_NEW) += pdc202xx_new.o
56obj-$(CONFIG_BLK_DEV_PIIX) += piix.o
57obj-$(CONFIG_BLK_DEV_RZ1000) += rz1000.o
58obj-$(CONFIG_BLK_DEV_SVWKS) += serverworks.o
59obj-$(CONFIG_BLK_DEV_SGIIOC4) += sgiioc4.o
60obj-$(CONFIG_BLK_DEV_SIIMAGE) += siimage.o
61obj-$(CONFIG_BLK_DEV_SIS5513) += sis5513.o
62obj-$(CONFIG_BLK_DEV_SL82C105) += sl82c105.o
63obj-$(CONFIG_BLK_DEV_SLC90E66) += slc90e66.o
64obj-$(CONFIG_BLK_DEV_TC86C001) += tc86c001.o
65obj-$(CONFIG_BLK_DEV_TRIFLEX) += triflex.o
66obj-$(CONFIG_BLK_DEV_TRM290) += trm290.o
67obj-$(CONFIG_BLK_DEV_VIA82CXXX) += via82cxxx.o
68
69# Must appear at the end of the block
70obj-$(CONFIG_BLK_DEV_GENERIC) += ide-pci-generic.o
26 71
27obj-$(CONFIG_IDEPCI_PCIBUS_ORDER) += ide-scan-pci.o 72obj-$(CONFIG_IDEPCI_PCIBUS_ORDER) += ide-scan-pci.o
28 73
29ifeq ($(CONFIG_BLK_DEV_CMD640), y) 74obj-$(CONFIG_BLK_DEV_CMD640) += cmd640.o
30 cmd640-core-y += pci/cmd640.o 75
31 obj-y += cmd640-core.o 76obj-$(CONFIG_BLK_DEV_IDE_PMAC) += pmac.o
32endif 77
78obj-$(CONFIG_IDE_H8300) += ide-h8300.o
33 79
34obj-$(CONFIG_BLK_DEV_IDE) += ppc/
35obj-$(CONFIG_IDE_H8300) += h8300/
36obj-$(CONFIG_IDE_GENERIC) += ide-generic.o 80obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
37obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 81obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
38 82
83ide-gd_mod-y += ide-gd.o
39ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o 84ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
40 85
41obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o 86ifeq ($(CONFIG_IDE_GD_ATA), y)
87 ide-gd_mod-y += ide-disk.o ide-disk_ioctl.o
88ifeq ($(CONFIG_IDE_PROC_FS), y)
89 ide-gd_mod-y += ide-disk_proc.o
90endif
91endif
92
93ifeq ($(CONFIG_IDE_GD_ATAPI), y)
94 ide-gd_mod-y += ide-floppy.o ide-floppy_ioctl.o
95ifeq ($(CONFIG_IDE_PROC_FS), y)
96 ide-gd_mod-y += ide-floppy_proc.o
97endif
98endif
99
100obj-$(CONFIG_IDE_GD) += ide-gd_mod.o
42obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o 101obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
43obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o 102obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o
44obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy.o
45 103
46ifeq ($(CONFIG_BLK_DEV_IDECS), y) 104obj-$(CONFIG_BLK_DEV_IDECS) += ide-cs.o
47 ide-cs-core-y += legacy/ide-cs.o
48 obj-y += ide-cs-core.o
49endif
50 105
51ifeq ($(CONFIG_BLK_DEV_PLATFORM), y) 106obj-$(CONFIG_BLK_DEV_PLATFORM) += ide_platform.o
52 ide-platform-core-y += legacy/ide_platform.o 107
53 obj-y += ide-platform-core.o 108obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o
54endif 109obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o
110obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o
111
112obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o
55 113
56obj-$(CONFIG_BLK_DEV_IDE) += arm/ mips/ 114obj-$(CONFIG_BLK_DEV_IDE_TX4938) += tx4938ide.o
115obj-$(CONFIG_BLK_DEV_IDE_TX4939) += tx4939ide.o
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/aec62xx.c
index 3187215e8f89..4142c698e0d3 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/aec62xx.c
@@ -7,7 +7,6 @@
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <linux/hdreg.h>
11#include <linux/ide.h> 10#include <linux/ide.h>
12#include <linux/init.h> 11#include <linux/init.h>
13 12
@@ -116,7 +115,7 @@ static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
116 struct pci_dev *dev = to_pci_dev(hwif->dev); 115 struct pci_dev *dev = to_pci_dev(hwif->dev);
117 struct ide_host *host = pci_get_drvdata(dev); 116 struct ide_host *host = pci_get_drvdata(dev);
118 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv; 117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
119 u8 unit = (drive->select.b.unit & 0x01); 118 u8 unit = drive->dn & 1;
120 u8 tmp1 = 0, tmp2 = 0; 119 u8 tmp1 = 0, tmp2 = 0;
121 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 120 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
122 unsigned long flags; 121 unsigned long flags;
@@ -140,7 +139,7 @@ static void aec_set_pio_mode(ide_drive_t *drive, const u8 pio)
140 drive->hwif->port_ops->set_dma_mode(drive, pio + XFER_PIO_0); 139 drive->hwif->port_ops->set_dma_mode(drive, pio + XFER_PIO_0);
141} 140}
142 141
143static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev) 142static unsigned int init_chipset_aec62xx(struct pci_dev *dev)
144{ 143{
145 /* These are necessary to get AEC6280 Macintosh cards to work */ 144 /* These are necessary to get AEC6280 Macintosh cards to work */
146 if ((dev->device == PCI_DEVICE_ID_ARTOP_ATP865) || 145 if ((dev->device == PCI_DEVICE_ID_ARTOP_ATP865) ||
@@ -303,21 +302,23 @@ static const struct pci_device_id aec62xx_pci_tbl[] = {
303}; 302};
304MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl); 303MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);
305 304
306static struct pci_driver driver = { 305static struct pci_driver aec62xx_pci_driver = {
307 .name = "AEC62xx_IDE", 306 .name = "AEC62xx_IDE",
308 .id_table = aec62xx_pci_tbl, 307 .id_table = aec62xx_pci_tbl,
309 .probe = aec62xx_init_one, 308 .probe = aec62xx_init_one,
310 .remove = __devexit_p(aec62xx_remove), 309 .remove = __devexit_p(aec62xx_remove),
310 .suspend = ide_pci_suspend,
311 .resume = ide_pci_resume,
311}; 312};
312 313
313static int __init aec62xx_ide_init(void) 314static int __init aec62xx_ide_init(void)
314{ 315{
315 return ide_pci_register_driver(&driver); 316 return ide_pci_register_driver(&aec62xx_pci_driver);
316} 317}
317 318
318static void __exit aec62xx_ide_exit(void) 319static void __exit aec62xx_ide_exit(void)
319{ 320{
320 pci_unregister_driver(&driver); 321 pci_unregister_driver(&aec62xx_pci_driver);
321} 322}
322 323
323module_init(aec62xx_ide_init); 324module_init(aec62xx_ide_init);
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/ali14xx.c
index 4ec19737f3c5..90da1f953ed0 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/ali14xx.c
@@ -43,7 +43,6 @@
43#include <linux/mm.h> 43#include <linux/mm.h>
44#include <linux/ioport.h> 44#include <linux/ioport.h>
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/hdreg.h>
47#include <linux/ide.h> 46#include <linux/ide.h>
48#include <linux/init.h> 47#include <linux/init.h>
49 48
@@ -132,7 +131,7 @@ static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
132 drive->name, pio, time1, time2, param1, param2, param3, param4); 131 drive->name, pio, time1, time2, param1, param2, param3, param4);
133 132
134 /* stuff timing parameters into controller registers */ 133 /* stuff timing parameters into controller registers */
135 driveNum = (HWIF(drive)->index << 1) + drive->select.b.unit; 134 driveNum = (drive->hwif->index << 1) + (drive->dn & 1);
136 spin_lock_irqsave(&ali14xx_lock, flags); 135 spin_lock_irqsave(&ali14xx_lock, flags);
137 outb_p(regOn, basePort); 136 outb_p(regOn, basePort);
138 outReg(param1, regTab[driveNum].reg1); 137 outReg(param1, regTab[driveNum].reg1);
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/alim15x3.c
index d647526af557..e56c7b72f9e2 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org) 6 * Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org)
7 * May be copied or modified under the terms of the GNU General Public License 7 * May be copied or modified under the terms of the GNU General Public License
8 * Copyright (C) 2002 Alan Cox <alan@redhat.com> 8 * Copyright (C) 2002 Alan Cox
9 * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw> 9 * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw>
10 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com> 10 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
11 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> 11 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
@@ -31,7 +31,6 @@
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/hdreg.h>
35#include <linux/ide.h> 34#include <linux/ide.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/dmi.h> 36#include <linux/dmi.h>
@@ -78,8 +77,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
78 int bus_speed = ide_pci_clk ? ide_pci_clk : 33; 77 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
79 int port = hwif->channel ? 0x5c : 0x58; 78 int port = hwif->channel ? 0x5c : 0x58;
80 int portFIFO = hwif->channel ? 0x55 : 0x54; 79 int portFIFO = hwif->channel ? 0x55 : 0x54;
81 u8 cd_dma_fifo = 0; 80 u8 cd_dma_fifo = 0, unit = drive->dn & 1;
82 int unit = drive->select.b.unit & 1;
83 81
84 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) 82 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
85 s_clc = 0; 83 s_clc = 0;
@@ -113,7 +111,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
113 } 111 }
114 112
115 pci_write_config_byte(dev, port, s_clc); 113 pci_write_config_byte(dev, port, s_clc);
116 pci_write_config_byte(dev, port+drive->select.b.unit+2, (a_clc << 4) | r_clc); 114 pci_write_config_byte(dev, port + unit + 2, (a_clc << 4) | r_clc);
117 local_irq_restore(flags); 115 local_irq_restore(flags);
118} 116}
119 117
@@ -134,8 +132,8 @@ static u8 ali_udma_filter(ide_drive_t *drive)
134 if (m5229_revision > 0x20 && m5229_revision < 0xC2) { 132 if (m5229_revision > 0x20 && m5229_revision < 0xC2) {
135 if (drive->media != ide_disk) 133 if (drive->media != ide_disk)
136 return 0; 134 return 0;
137 if (chip_is_1543c_e && strstr(drive->id->model, "WDC ") && 135 if (wdc_udma == 0 && chip_is_1543c_e &&
138 wdc_udma == 0) 136 strstr((char *)&drive->id[ATA_ID_PROD], "WDC "))
139 return 0; 137 return 0;
140 } 138 }
141 139
@@ -155,7 +153,7 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
155 ide_hwif_t *hwif = HWIF(drive); 153 ide_hwif_t *hwif = HWIF(drive);
156 struct pci_dev *dev = to_pci_dev(hwif->dev); 154 struct pci_dev *dev = to_pci_dev(hwif->dev);
157 u8 speed1 = speed; 155 u8 speed1 = speed;
158 u8 unit = (drive->select.b.unit & 0x01); 156 u8 unit = drive->dn & 1;
159 u8 tmpbyte = 0x00; 157 u8 tmpbyte = 0x00;
160 int m5229_udma = (hwif->channel) ? 0x57 : 0x56; 158 int m5229_udma = (hwif->channel) ? 0x57 : 0x56;
161 159
@@ -214,7 +212,7 @@ static int ali15x3_dma_setup(ide_drive_t *drive)
214 * appropriate also sets up the 1533 southbridge. 212 * appropriate also sets up the 1533 southbridge.
215 */ 213 */
216 214
217static unsigned int __devinit init_chipset_ali15x3(struct pci_dev *dev) 215static unsigned int init_chipset_ali15x3(struct pci_dev *dev)
218{ 216{
219 unsigned long flags; 217 unsigned long flags;
220 u8 tmpbyte; 218 u8 tmpbyte;
@@ -509,7 +507,7 @@ static const struct ide_dma_ops ali_dma_ops = {
509 .dma_setup = ali15x3_dma_setup, 507 .dma_setup = ali15x3_dma_setup,
510 .dma_exec_cmd = ide_dma_exec_cmd, 508 .dma_exec_cmd = ide_dma_exec_cmd,
511 .dma_start = ide_dma_start, 509 .dma_start = ide_dma_start,
512 .dma_end = __ide_dma_end, 510 .dma_end = ide_dma_end,
513 .dma_test_irq = ide_dma_test_irq, 511 .dma_test_irq = ide_dma_test_irq,
514 .dma_lost_irq = ide_dma_lost_irq, 512 .dma_lost_irq = ide_dma_lost_irq,
515 .dma_timeout = ide_dma_timeout, 513 .dma_timeout = ide_dma_timeout,
@@ -577,21 +575,23 @@ static const struct pci_device_id alim15x3_pci_tbl[] = {
577}; 575};
578MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl); 576MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
579 577
580static struct pci_driver driver = { 578static struct pci_driver alim15x3_pci_driver = {
581 .name = "ALI15x3_IDE", 579 .name = "ALI15x3_IDE",
582 .id_table = alim15x3_pci_tbl, 580 .id_table = alim15x3_pci_tbl,
583 .probe = alim15x3_init_one, 581 .probe = alim15x3_init_one,
584 .remove = ide_pci_remove, 582 .remove = ide_pci_remove,
583 .suspend = ide_pci_suspend,
584 .resume = ide_pci_resume,
585}; 585};
586 586
587static int __init ali15x3_ide_init(void) 587static int __init ali15x3_ide_init(void)
588{ 588{
589 return ide_pci_register_driver(&driver); 589 return ide_pci_register_driver(&alim15x3_pci_driver);
590} 590}
591 591
592static void __exit ali15x3_ide_exit(void) 592static void __exit ali15x3_ide_exit(void)
593{ 593{
594 return pci_unregister_driver(&driver); 594 return pci_unregister_driver(&alim15x3_pci_driver);
595} 595}
596 596
597module_init(ali15x3_ide_init); 597module_init(ali15x3_ide_init);
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/amd74xx.c
index 1e66a960a96a..81ec73134eda 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/amd74xx.c
@@ -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->present) { 95 if (peer->dev_flags & IDE_DFLAG_PRESENT) {
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 }
@@ -112,13 +112,13 @@ static void amd_set_pio_mode(ide_drive_t *drive, const u8 pio)
112 amd_set_drive(drive, XFER_PIO_0 + pio); 112 amd_set_drive(drive, XFER_PIO_0 + pio);
113} 113}
114 114
115static void __devinit amd7409_cable_detect(struct pci_dev *dev) 115static void amd7409_cable_detect(struct pci_dev *dev)
116{ 116{
117 /* no host side cable detection */ 117 /* no host side cable detection */
118 amd_80w = 0x03; 118 amd_80w = 0x03;
119} 119}
120 120
121static void __devinit amd7411_cable_detect(struct pci_dev *dev) 121static void amd7411_cable_detect(struct pci_dev *dev)
122{ 122{
123 int i; 123 int i;
124 u32 u = 0; 124 u32 u = 0;
@@ -140,7 +140,7 @@ static void __devinit amd7411_cable_detect(struct pci_dev *dev)
140 * The initialization callback. Initialize drive independent registers. 140 * The initialization callback. Initialize drive independent registers.
141 */ 141 */
142 142
143static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev) 143static unsigned int init_chipset_amd74xx(struct pci_dev *dev)
144{ 144{
145 u8 t = 0, offset = amd_offset(dev); 145 u8 t = 0, offset = amd_offset(dev);
146 146
@@ -319,21 +319,23 @@ static const struct pci_device_id amd74xx_pci_tbl[] = {
319}; 319};
320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); 320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);
321 321
322static struct pci_driver driver = { 322static struct pci_driver amd74xx_pci_driver = {
323 .name = "AMD_IDE", 323 .name = "AMD_IDE",
324 .id_table = amd74xx_pci_tbl, 324 .id_table = amd74xx_pci_tbl,
325 .probe = amd74xx_probe, 325 .probe = amd74xx_probe,
326 .remove = ide_pci_remove, 326 .remove = ide_pci_remove,
327 .suspend = ide_pci_suspend,
328 .resume = ide_pci_resume,
327}; 329};
328 330
329static int __init amd74xx_ide_init(void) 331static int __init amd74xx_ide_init(void)
330{ 332{
331 return ide_pci_register_driver(&driver); 333 return ide_pci_register_driver(&amd74xx_pci_driver);
332} 334}
333 335
334static void __exit amd74xx_ide_exit(void) 336static void __exit amd74xx_ide_exit(void)
335{ 337{
336 pci_unregister_driver(&driver); 338 pci_unregister_driver(&amd74xx_pci_driver);
337} 339}
338 340
339module_init(amd74xx_ide_init); 341module_init(amd74xx_ide_init);
diff --git a/drivers/ide/arm/Makefile b/drivers/ide/arm/Makefile
deleted file mode 100644
index 5bc26053afa6..000000000000
--- a/drivers/ide/arm/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1
2obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o
3obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o
4obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o
5
6ifeq ($(CONFIG_IDE_ARM), m)
7 obj-m += ide_arm.o
8endif
9
10EXTRA_CFLAGS := -Idrivers/ide
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/atiixp.c
index 41f6cb6c163a..b2735d28f5cc 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/atiixp.c
@@ -7,7 +7,6 @@
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <linux/hdreg.h>
11#include <linux/ide.h> 10#include <linux/ide.h>
12#include <linux/init.h> 11#include <linux/init.h>
13 12
@@ -183,21 +182,23 @@ static const struct pci_device_id atiixp_pci_tbl[] = {
183}; 182};
184MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 183MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
185 184
186static struct pci_driver driver = { 185static struct pci_driver atiixp_pci_driver = {
187 .name = "ATIIXP_IDE", 186 .name = "ATIIXP_IDE",
188 .id_table = atiixp_pci_tbl, 187 .id_table = atiixp_pci_tbl,
189 .probe = atiixp_init_one, 188 .probe = atiixp_init_one,
190 .remove = ide_pci_remove, 189 .remove = ide_pci_remove,
190 .suspend = ide_pci_suspend,
191 .resume = ide_pci_resume,
191}; 192};
192 193
193static int __init atiixp_ide_init(void) 194static int __init atiixp_ide_init(void)
194{ 195{
195 return ide_pci_register_driver(&driver); 196 return ide_pci_register_driver(&atiixp_pci_driver);
196} 197}
197 198
198static void __exit atiixp_ide_exit(void) 199static void __exit atiixp_ide_exit(void)
199{ 200{
200 pci_unregister_driver(&driver); 201 pci_unregister_driver(&atiixp_pci_driver);
201} 202}
202 203
203module_init(atiixp_ide_init); 204module_init(atiixp_ide_init);
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index 11b7f61aae40..0ec8fd1e4dcb 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -322,11 +322,7 @@ static int auide_dma_setup(ide_drive_t *drive)
322} 322}
323 323
324static int auide_dma_test_irq(ide_drive_t *drive) 324static int auide_dma_test_irq(ide_drive_t *drive)
325{ 325{
326 if (drive->waiting_for_dma == 0)
327 printk(KERN_WARNING "%s: ide_dma_test_irq \
328 called while not waiting\n", drive->name);
329
330 /* If dbdma didn't execute the STOP command yet, the 326 /* If dbdma didn't execute the STOP command yet, the
331 * active bit is still set 327 * active bit is still set
332 */ 328 */
@@ -344,11 +340,6 @@ static void auide_dma_host_set(ide_drive_t *drive, int on)
344{ 340{
345} 341}
346 342
347static void auide_dma_lost_irq(ide_drive_t *drive)
348{
349 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
350}
351
352static void auide_ddma_tx_callback(int irq, void *param) 343static void auide_ddma_tx_callback(int irq, void *param)
353{ 344{
354 _auide_hwif *ahwif = (_auide_hwif*)param; 345 _auide_hwif *ahwif = (_auide_hwif*)param;
@@ -375,18 +366,6 @@ static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 de
375} 366}
376 367
377#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 368#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
378static void auide_dma_timeout(ide_drive_t *drive)
379{
380 ide_hwif_t *hwif = HWIF(drive);
381
382 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
383
384 if (auide_dma_test_irq(drive))
385 return;
386
387 auide_dma_end(drive);
388}
389
390static const struct ide_dma_ops au1xxx_dma_ops = { 369static const struct ide_dma_ops au1xxx_dma_ops = {
391 .dma_host_set = auide_dma_host_set, 370 .dma_host_set = auide_dma_host_set,
392 .dma_setup = auide_dma_setup, 371 .dma_setup = auide_dma_setup,
@@ -394,8 +373,8 @@ static const struct ide_dma_ops au1xxx_dma_ops = {
394 .dma_start = auide_dma_start, 373 .dma_start = auide_dma_start,
395 .dma_end = auide_dma_end, 374 .dma_end = auide_dma_end,
396 .dma_test_irq = auide_dma_test_irq, 375 .dma_test_irq = auide_dma_test_irq,
397 .dma_lost_irq = auide_dma_lost_irq, 376 .dma_lost_irq = ide_dma_lost_irq,
398 .dma_timeout = auide_dma_timeout, 377 .dma_timeout = ide_dma_timeout,
399}; 378};
400 379
401static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 380static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
@@ -448,10 +427,9 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
448 NUM_DESCRIPTORS); 427 NUM_DESCRIPTORS);
449 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan, 428 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
450 NUM_DESCRIPTORS); 429 NUM_DESCRIPTORS);
451 430
452 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, 431 /* FIXME: check return value */
453 PRD_ENTRIES * PRD_BYTES, /* 1 Page */ 432 (void)ide_allocate_dma_engine(hwif);
454 &hwif->dmatable_dma, GFP_KERNEL);
455 433
456 au1xxx_dbdma_start( auide->tx_chan ); 434 au1xxx_dbdma_start( auide->tx_chan );
457 au1xxx_dbdma_start( auide->rx_chan ); 435 au1xxx_dbdma_start( auide->rx_chan );
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/buddha.c
index 7c2afa97f417..c5a3c9ef6a5d 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/buddha.c
@@ -20,7 +20,6 @@
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/hdreg.h>
24#include <linux/zorro.h> 23#include <linux/zorro.h>
25#include <linux/ide.h> 24#include <linux/ide.h>
26#include <linux/init.h> 25#include <linux/init.h>
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/cmd640.c
index e6c62006ca1a..e4306647d00d 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/cmd640.c
@@ -103,7 +103,6 @@
103#include <linux/types.h> 103#include <linux/types.h>
104#include <linux/kernel.h> 104#include <linux/kernel.h>
105#include <linux/delay.h> 105#include <linux/delay.h>
106#include <linux/hdreg.h>
107#include <linux/ide.h> 106#include <linux/ide.h>
108#include <linux/init.h> 107#include <linux/init.h>
109 108
@@ -375,6 +374,21 @@ static void cmd640_dump_regs(void)
375} 374}
376#endif 375#endif
377 376
377static void __set_prefetch_mode(ide_drive_t *drive, int mode)
378{
379 if (mode) { /* want prefetch on? */
380#if CMD640_PREFETCH_MASKS
381 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
382 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
383#endif
384 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
385 } else {
386 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
387 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
388 drive->io_32bit = 0;
389 }
390}
391
378#ifndef CONFIG_BLK_DEV_CMD640_ENHANCED 392#ifndef CONFIG_BLK_DEV_CMD640_ENHANCED
379/* 393/*
380 * Check whether prefetch is on for a drive, 394 * Check whether prefetch is on for a drive,
@@ -384,19 +398,10 @@ static void __init check_prefetch(ide_drive_t *drive, unsigned int index)
384{ 398{
385 u8 b = get_cmd640_reg(prefetch_regs[index]); 399 u8 b = get_cmd640_reg(prefetch_regs[index]);
386 400
387 if (b & prefetch_masks[index]) { /* is prefetch off? */ 401 __set_prefetch_mode(drive, (b & prefetch_masks[index]) ? 0 : 1);
388 drive->no_unmask = 0;
389 drive->no_io_32bit = 1;
390 drive->io_32bit = 0;
391 } else {
392#if CMD640_PREFETCH_MASKS
393 drive->no_unmask = 1;
394 drive->unmask = 0;
395#endif
396 drive->no_io_32bit = 0;
397 }
398} 402}
399#else 403#else
404
400/* 405/*
401 * Sets prefetch mode for a drive. 406 * Sets prefetch mode for a drive.
402 */ 407 */
@@ -408,19 +413,11 @@ static void set_prefetch_mode(ide_drive_t *drive, unsigned int index, int mode)
408 413
409 spin_lock_irqsave(&cmd640_lock, flags); 414 spin_lock_irqsave(&cmd640_lock, flags);
410 b = __get_cmd640_reg(reg); 415 b = __get_cmd640_reg(reg);
411 if (mode) { /* want prefetch on? */ 416 __set_prefetch_mode(drive, mode);
412#if CMD640_PREFETCH_MASKS 417 if (mode)
413 drive->no_unmask = 1;
414 drive->unmask = 0;
415#endif
416 drive->no_io_32bit = 0;
417 b &= ~prefetch_masks[index]; /* enable prefetch */ 418 b &= ~prefetch_masks[index]; /* enable prefetch */
418 } else { 419 else
419 drive->no_unmask = 0;
420 drive->no_io_32bit = 1;
421 drive->io_32bit = 0;
422 b |= prefetch_masks[index]; /* disable prefetch */ 420 b |= prefetch_masks[index]; /* disable prefetch */
423 }
424 __put_cmd640_reg(reg, b); 421 __put_cmd640_reg(reg, b);
425 spin_unlock_irqrestore(&cmd640_lock, flags); 422 spin_unlock_irqrestore(&cmd640_lock, flags);
426} 423}
@@ -471,10 +468,10 @@ static void program_drive_counts(ide_drive_t *drive, unsigned int index)
471 */ 468 */
472 if (index > 1) { 469 if (index > 1) {
473 ide_hwif_t *hwif = drive->hwif; 470 ide_hwif_t *hwif = drive->hwif;
474 ide_drive_t *peer = &hwif->drives[!drive->select.b.unit]; 471 ide_drive_t *peer = &hwif->drives[!(drive->dn & 1)];
475 unsigned int mate = index ^ 1; 472 unsigned int mate = index ^ 1;
476 473
477 if (peer->present) { 474 if (peer->dev_flags & IDE_DFLAG_PRESENT) {
478 if (setup_count < setup_counts[mate]) 475 if (setup_count < setup_counts[mate])
479 setup_count = setup_counts[mate]; 476 setup_count = setup_counts[mate];
480 if (active_count < active_counts[mate]) 477 if (active_count < active_counts[mate])
@@ -610,7 +607,7 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
610 607
611static void cmd640_init_dev(ide_drive_t *drive) 608static void cmd640_init_dev(ide_drive_t *drive)
612{ 609{
613 unsigned int i = drive->hwif->channel * 2 + drive->select.b.unit; 610 unsigned int i = drive->hwif->channel * 2 + (drive->dn & 1);
614 611
615#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 612#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
616 /* 613 /*
@@ -629,7 +626,7 @@ static void cmd640_init_dev(ide_drive_t *drive)
629 */ 626 */
630 check_prefetch(drive, i); 627 check_prefetch(drive, i);
631 printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n", 628 printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n",
632 i, drive->no_io_32bit ? "off" : "on"); 629 i, (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT) ? "off" : "on");
633#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 630#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
634} 631}
635 632
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/cmd64x.c
index e064398e03b4..935385c77e06 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/cmd64x.c
@@ -13,7 +13,6 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/hdreg.h>
17#include <linux/ide.h> 16#include <linux/ide.h>
18#include <linux/init.h> 17#include <linux/init.h>
19 18
@@ -229,7 +228,7 @@ static int cmd648_dma_end(ide_drive_t *drive)
229{ 228{
230 ide_hwif_t *hwif = HWIF(drive); 229 ide_hwif_t *hwif = HWIF(drive);
231 unsigned long base = hwif->dma_base - (hwif->channel * 8); 230 unsigned long base = hwif->dma_base - (hwif->channel * 8);
232 int err = __ide_dma_end(drive); 231 int err = ide_dma_end(drive);
233 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 232 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
234 MRDMODE_INTR_CH0; 233 MRDMODE_INTR_CH0;
235 u8 mrdmode = inb(base + 1); 234 u8 mrdmode = inb(base + 1);
@@ -249,7 +248,7 @@ static int cmd64x_dma_end(ide_drive_t *drive)
249 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
250 CFR_INTR_CH0; 249 CFR_INTR_CH0;
251 u8 irq_stat = 0; 250 u8 irq_stat = 0;
252 int err = __ide_dma_end(drive); 251 int err = ide_dma_end(drive);
253 252
254 (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 253 (void) pci_read_config_byte(dev, irq_reg, &irq_stat);
255 /* clear the interrupt bit */ 254 /* clear the interrupt bit */
@@ -332,7 +331,7 @@ static int cmd646_1_dma_end(ide_drive_t *drive)
332 return (dma_stat & 7) != 4; 331 return (dma_stat & 7) != 4;
333} 332}
334 333
335static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev) 334static unsigned int init_chipset_cmd64x(struct pci_dev *dev)
336{ 335{
337 u8 mrdmode = 0; 336 u8 mrdmode = 0;
338 337
@@ -506,21 +505,23 @@ static const struct pci_device_id cmd64x_pci_tbl[] = {
506}; 505};
507MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl); 506MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl);
508 507
509static struct pci_driver driver = { 508static struct pci_driver cmd64x_pci_driver = {
510 .name = "CMD64x_IDE", 509 .name = "CMD64x_IDE",
511 .id_table = cmd64x_pci_tbl, 510 .id_table = cmd64x_pci_tbl,
512 .probe = cmd64x_init_one, 511 .probe = cmd64x_init_one,
513 .remove = ide_pci_remove, 512 .remove = ide_pci_remove,
513 .suspend = ide_pci_suspend,
514 .resume = ide_pci_resume,
514}; 515};
515 516
516static int __init cmd64x_ide_init(void) 517static int __init cmd64x_ide_init(void)
517{ 518{
518 return ide_pci_register_driver(&driver); 519 return ide_pci_register_driver(&cmd64x_pci_driver);
519} 520}
520 521
521static void __exit cmd64x_ide_exit(void) 522static void __exit cmd64x_ide_exit(void)
522{ 523{
523 pci_unregister_driver(&driver); 524 pci_unregister_driver(&cmd64x_pci_driver);
524} 525}
525 526
526module_init(cmd64x_ide_init); 527module_init(cmd64x_ide_init);
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/cs5520.c
index 151844fcbb07..5efb467f8fa0 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/cs5520.c
@@ -35,7 +35,6 @@
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/hdreg.h>
39#include <linux/init.h> 38#include <linux/init.h>
40#include <linux/pci.h> 39#include <linux/pci.h>
41#include <linux/ide.h> 40#include <linux/ide.h>
@@ -146,15 +145,17 @@ static const struct pci_device_id cs5520_pci_tbl[] = {
146}; 145};
147MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl); 146MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl);
148 147
149static struct pci_driver driver = { 148static struct pci_driver cs5520_pci_driver = {
150 .name = "Cyrix_IDE", 149 .name = "Cyrix_IDE",
151 .id_table = cs5520_pci_tbl, 150 .id_table = cs5520_pci_tbl,
152 .probe = cs5520_init_one, 151 .probe = cs5520_init_one,
152 .suspend = ide_pci_suspend,
153 .resume = ide_pci_resume,
153}; 154};
154 155
155static int __init cs5520_ide_init(void) 156static int __init cs5520_ide_init(void)
156{ 157{
157 return ide_pci_register_driver(&driver); 158 return ide_pci_register_driver(&cs5520_pci_driver);
158} 159}
159 160
160module_init(cs5520_ide_init); 161module_init(cs5520_ide_init);
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/cs5530.c
index f235db8c678b..53f079cc00af 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/cs5530.c
@@ -15,7 +15,6 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/hdreg.h>
19#include <linux/pci.h> 18#include <linux/pci.h>
20#include <linux/init.h> 19#include <linux/init.h>
21#include <linux/ide.h> 20#include <linux/ide.h>
@@ -81,17 +80,19 @@ static void cs5530_set_pio_mode(ide_drive_t *drive, const u8 pio)
81static u8 cs5530_udma_filter(ide_drive_t *drive) 80static u8 cs5530_udma_filter(ide_drive_t *drive)
82{ 81{
83 ide_hwif_t *hwif = drive->hwif; 82 ide_hwif_t *hwif = drive->hwif;
84 ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1]; 83 ide_drive_t *mate = ide_get_pair_dev(drive);
85 struct hd_driveid *mateid = mate->id; 84 u16 *mateid = mate->id;
86 u8 mask = hwif->ultra_mask; 85 u8 mask = hwif->ultra_mask;
87 86
88 if (mate->present == 0) 87 if (mate == NULL)
89 goto out; 88 goto out;
90 89
91 if ((mateid->capability & 1) && __ide_dma_bad_drive(mate) == 0) { 90 if (ata_id_has_dma(mateid) && __ide_dma_bad_drive(mate) == 0) {
92 if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7)) 91 if ((mateid[ATA_ID_FIELD_VALID] & 4) &&
92 (mateid[ATA_ID_UDMA_MODES] & 7))
93 goto out; 93 goto out;
94 if ((mateid->field_valid & 2) && (mateid->dma_mword & 7)) 94 if ((mateid[ATA_ID_FIELD_VALID] & 2) &&
95 (mateid[ATA_ID_MWDMA_MODES] & 7))
95 mask = 0; 96 mask = 0;
96 } 97 }
97out: 98out:
@@ -133,7 +134,7 @@ static void cs5530_set_dma_mode(ide_drive_t *drive, const u8 mode)
133 * Initialize the cs5530 bridge for reliable IDE DMA operation. 134 * Initialize the cs5530 bridge for reliable IDE DMA operation.
134 */ 135 */
135 136
136static unsigned int __devinit init_chipset_cs5530(struct pci_dev *dev) 137static unsigned int init_chipset_cs5530(struct pci_dev *dev)
137{ 138{
138 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL; 139 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL;
139 140
@@ -266,21 +267,23 @@ static const struct pci_device_id cs5530_pci_tbl[] = {
266}; 267};
267MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl); 268MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl);
268 269
269static struct pci_driver driver = { 270static struct pci_driver cs5530_pci_driver = {
270 .name = "CS5530 IDE", 271 .name = "CS5530 IDE",
271 .id_table = cs5530_pci_tbl, 272 .id_table = cs5530_pci_tbl,
272 .probe = cs5530_init_one, 273 .probe = cs5530_init_one,
273 .remove = ide_pci_remove, 274 .remove = ide_pci_remove,
275 .suspend = ide_pci_suspend,
276 .resume = ide_pci_resume,
274}; 277};
275 278
276static int __init cs5530_ide_init(void) 279static int __init cs5530_ide_init(void)
277{ 280{
278 return ide_pci_register_driver(&driver); 281 return ide_pci_register_driver(&cs5530_pci_driver);
279} 282}
280 283
281static void __exit cs5530_ide_exit(void) 284static void __exit cs5530_ide_exit(void)
282{ 285{
283 pci_unregister_driver(&driver); 286 pci_unregister_driver(&cs5530_pci_driver);
284} 287}
285 288
286module_init(cs5530_ide_init); 289module_init(cs5530_ide_init);
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/cs5535.c
index dd3dc23af995..983d957a0189 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/cs5535.c
@@ -76,16 +76,16 @@ static unsigned int cs5535_udma_timings[5] =
76static void cs5535_set_speed(ide_drive_t *drive, const u8 speed) 76static void cs5535_set_speed(ide_drive_t *drive, const u8 speed)
77{ 77{
78 u32 reg = 0, dummy; 78 u32 reg = 0, dummy;
79 int unit = drive->select.b.unit; 79 u8 unit = drive->dn & 1;
80 80
81 /* Set the PIO timings */ 81 /* Set the PIO timings */
82 if (speed < XFER_SW_DMA_0) { 82 if (speed < XFER_SW_DMA_0) {
83 ide_drive_t *pair = ide_get_paired_drive(drive); 83 ide_drive_t *pair = ide_get_pair_dev(drive);
84 u8 cmd, pioa; 84 u8 cmd, pioa;
85 85
86 cmd = pioa = speed - XFER_PIO_0; 86 cmd = pioa = speed - XFER_PIO_0;
87 87
88 if (pair->present) { 88 if (pair) {
89 u8 piob = ide_get_best_pio_mode(pair, 255, 4); 89 u8 piob = ide_get_best_pio_mode(pair, 255, 4);
90 90
91 if (piob < cmd) 91 if (piob < cmd)
@@ -192,21 +192,23 @@ static const struct pci_device_id cs5535_pci_tbl[] = {
192 192
193MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl); 193MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl);
194 194
195static struct pci_driver driver = { 195static struct pci_driver cs5535_pci_driver = {
196 .name = "CS5535_IDE", 196 .name = "CS5535_IDE",
197 .id_table = cs5535_pci_tbl, 197 .id_table = cs5535_pci_tbl,
198 .probe = cs5535_init_one, 198 .probe = cs5535_init_one,
199 .remove = ide_pci_remove, 199 .remove = ide_pci_remove,
200 .suspend = ide_pci_suspend,
201 .resume = ide_pci_resume,
200}; 202};
201 203
202static int __init cs5535_ide_init(void) 204static int __init cs5535_ide_init(void)
203{ 205{
204 return ide_pci_register_driver(&driver); 206 return ide_pci_register_driver(&cs5535_pci_driver);
205} 207}
206 208
207static void __exit cs5535_ide_exit(void) 209static void __exit cs5535_ide_exit(void)
208{ 210{
209 pci_unregister_driver(&driver); 211 pci_unregister_driver(&cs5535_pci_driver);
210} 212}
211 213
212module_init(cs5535_ide_init); 214module_init(cs5535_ide_init);
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/cy82c693.c
index e6d8ee88d56d..5297f07d2933 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/cy82c693.c
@@ -50,18 +50,11 @@
50 50
51#define DRV_NAME "cy82c693" 51#define DRV_NAME "cy82c693"
52 52
53/* the current version */
54#define CY82_VERSION "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)"
55
56/* 53/*
57 * The following are used to debug the driver. 54 * The following are used to debug the driver.
58 */ 55 */
59#define CY82C693_DEBUG_LOGS 0
60#define CY82C693_DEBUG_INFO 0 56#define CY82C693_DEBUG_INFO 0
61 57
62/* define CY82C693_SETDMA_CLOCK to set DMA Controller Clock Speed to ATCLK */
63#undef CY82C693_SETDMA_CLOCK
64
65/* 58/*
66 * NOTE: the value for busmaster timeout is tricky and I got it by 59 * NOTE: the value for busmaster timeout is tricky and I got it by
67 * trial and error! By using a to low value will cause DMA timeouts 60 * trial and error! By using a to low value will cause DMA timeouts
@@ -89,7 +82,6 @@
89#define CY82_INDEX_PORT 0x22 82#define CY82_INDEX_PORT 0x22
90#define CY82_DATA_PORT 0x23 83#define CY82_DATA_PORT 0x23
91 84
92#define CY82_INDEX_CTRLREG1 0x01
93#define CY82_INDEX_CHANNEL0 0x30 85#define CY82_INDEX_CHANNEL0 0x30
94#define CY82_INDEX_CHANNEL1 0x31 86#define CY82_INDEX_CHANNEL1 0x31
95#define CY82_INDEX_TIMEOUT 0x32 87#define CY82_INDEX_TIMEOUT 0x32
@@ -179,17 +171,6 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
179 171
180 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0; 172 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0;
181 173
182#if CY82C693_DEBUG_LOGS
183 /* for debug let's show the previous values */
184
185 outb(index, CY82_INDEX_PORT);
186 data = inb(CY82_DATA_PORT);
187
188 printk(KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
189 drive->name, HWIF(drive)->channel, drive->select.b.unit,
190 (data&0x3), ((data>>2)&1));
191#endif /* CY82C693_DEBUG_LOGS */
192
193 data = (mode & 3) | (single << 2); 174 data = (mode & 3) | (single << 2);
194 175
195 outb(index, CY82_INDEX_PORT); 176 outb(index, CY82_INDEX_PORT);
@@ -197,8 +178,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
197 178
198#if CY82C693_DEBUG_INFO 179#if CY82C693_DEBUG_INFO
199 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n", 180 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
200 drive->name, HWIF(drive)->channel, drive->select.b.unit, 181 drive->name, hwif->channel, drive->dn & 1, mode & 3, single);
201 mode & 3, single);
202#endif /* CY82C693_DEBUG_INFO */ 182#endif /* CY82C693_DEBUG_INFO */
203 183
204 /* 184 /*
@@ -239,50 +219,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
239 } 219 }
240 } 220 }
241 221
242#if CY82C693_DEBUG_LOGS
243 /* for debug let's show the register values */
244
245 if (drive->select.b.unit == 0) {
246 /*
247 * get master drive registers
248 * address setup control register
249 * is 32 bit !!!
250 */
251 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
252 addrCtrl &= 0x0F;
253
254 /* now let's get the remaining registers */
255 pci_read_config_byte(dev, CY82_IDE_MASTER_IOR, &pclk.time_16r);
256 pci_read_config_byte(dev, CY82_IDE_MASTER_IOW, &pclk.time_16w);
257 pci_read_config_byte(dev, CY82_IDE_MASTER_8BIT, &pclk.time_8);
258 } else {
259 /*
260 * set slave drive registers
261 * address setup control register
262 * is 32 bit !!!
263 */
264 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
265
266 addrCtrl &= 0xF0;
267 addrCtrl >>= 4;
268
269 /* now let's get the remaining registers */
270 pci_read_config_byte(dev, CY82_IDE_SLAVE_IOR, &pclk.time_16r);
271 pci_read_config_byte(dev, CY82_IDE_SLAVE_IOW, &pclk.time_16w);
272 pci_read_config_byte(dev, CY82_IDE_SLAVE_8BIT, &pclk.time_8);
273 }
274
275 printk(KERN_INFO "%s (ch=%d, dev=%d): PIO timing is "
276 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
277 drive->name, hwif->channel, drive->select.b.unit,
278 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
279#endif /* CY82C693_DEBUG_LOGS */
280
281 /* let's calc the values for this PIO mode */ 222 /* let's calc the values for this PIO mode */
282 compute_clocks(pio, &pclk); 223 compute_clocks(pio, &pclk);
283 224
284 /* now let's write the clocks registers */ 225 /* now let's write the clocks registers */
285 if (drive->select.b.unit == 0) { 226 if ((drive->dn & 1) == 0) {
286 /* 227 /*
287 * set master drive 228 * set master drive
288 * address setup control register 229 * address setup control register
@@ -324,63 +265,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
324#if CY82C693_DEBUG_INFO 265#if CY82C693_DEBUG_INFO
325 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to " 266 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to "
326 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n", 267 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
327 drive->name, hwif->channel, drive->select.b.unit, 268 drive->name, hwif->channel, drive->dn & 1,
328 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8); 269 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
329#endif /* CY82C693_DEBUG_INFO */ 270#endif /* CY82C693_DEBUG_INFO */
330} 271}
331 272
332/*
333 * this function is called during init and is used to setup the cy82c693 chip
334 */
335static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev)
336{
337 if (PCI_FUNC(dev->devfn) != 1)
338 return 0;
339
340#ifdef CY82C693_SETDMA_CLOCK
341 u8 data = 0;
342#endif /* CY82C693_SETDMA_CLOCK */
343
344 /* write info about this verion of the driver */
345 printk(KERN_INFO CY82_VERSION "\n");
346
347#ifdef CY82C693_SETDMA_CLOCK
348 /* okay let's set the DMA clock speed */
349
350 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
351 data = inb(CY82_DATA_PORT);
352
353#if CY82C693_DEBUG_INFO
354 printk(KERN_INFO DRV_NAME ": Peripheral Configuration Register: 0x%X\n",
355 data);
356#endif /* CY82C693_DEBUG_INFO */
357
358 /*
359 * for some reason sometimes the DMA controller
360 * speed is set to ATCLK/2 ???? - we fix this here
361 *
362 * note: i don't know what causes this strange behaviour,
363 * but even changing the dma speed doesn't solve it :-(
364 * the ide performance is still only half the normal speed
365 *
366 * if anybody knows what goes wrong with my machine, please
367 * let me know - ASK
368 */
369
370 data |= 0x03;
371
372 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
373 outb(data, CY82_DATA_PORT);
374
375#if CY82C693_DEBUG_INFO
376 printk(KERN_INFO ": New Peripheral Configuration Register: 0x%X\n",
377 data);
378#endif /* CY82C693_DEBUG_INFO */
379
380#endif /* CY82C693_SETDMA_CLOCK */
381 return 0;
382}
383
384static void __devinit init_iops_cy82c693(ide_hwif_t *hwif) 273static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
385{ 274{
386 static ide_hwif_t *primary; 275 static ide_hwif_t *primary;
@@ -401,7 +290,6 @@ static const struct ide_port_ops cy82c693_port_ops = {
401 290
402static const struct ide_port_info cy82c693_chipset __devinitdata = { 291static const struct ide_port_info cy82c693_chipset __devinitdata = {
403 .name = DRV_NAME, 292 .name = DRV_NAME,
404 .init_chipset = init_chipset_cy82c693,
405 .init_iops = init_iops_cy82c693, 293 .init_iops = init_iops_cy82c693,
406 .port_ops = &cy82c693_port_ops, 294 .port_ops = &cy82c693_port_ops,
407 .chipset = ide_cy82c693, 295 .chipset = ide_cy82c693,
@@ -443,21 +331,23 @@ static const struct pci_device_id cy82c693_pci_tbl[] = {
443}; 331};
444MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl); 332MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl);
445 333
446static struct pci_driver driver = { 334static struct pci_driver cy82c693_pci_driver = {
447 .name = "Cypress_IDE", 335 .name = "Cypress_IDE",
448 .id_table = cy82c693_pci_tbl, 336 .id_table = cy82c693_pci_tbl,
449 .probe = cy82c693_init_one, 337 .probe = cy82c693_init_one,
450 .remove = __devexit_p(cy82c693_remove), 338 .remove = __devexit_p(cy82c693_remove),
339 .suspend = ide_pci_suspend,
340 .resume = ide_pci_resume,
451}; 341};
452 342
453static int __init cy82c693_ide_init(void) 343static int __init cy82c693_ide_init(void)
454{ 344{
455 return ide_pci_register_driver(&driver); 345 return ide_pci_register_driver(&cy82c693_pci_driver);
456} 346}
457 347
458static void __exit cy82c693_ide_exit(void) 348static void __exit cy82c693_ide_exit(void)
459{ 349{
460 pci_unregister_driver(&driver); 350 pci_unregister_driver(&cy82c693_pci_driver);
461} 351}
462 352
463module_init(cy82c693_ide_init); 353module_init(cy82c693_ide_init);
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/delkin_cb.c
index f84bfb4f600f..8f1b2d9f0513 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/delkin_cb.c
@@ -19,7 +19,6 @@
19 19
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/hdreg.h>
23#include <linux/ide.h> 22#include <linux/ide.h>
24#include <linux/init.h> 23#include <linux/init.h>
25#include <linux/pci.h> 24#include <linux/pci.h>
@@ -47,10 +46,27 @@ static const struct ide_port_ops delkin_cb_port_ops = {
47 .quirkproc = ide_undecoded_slave, 46 .quirkproc = ide_undecoded_slave,
48}; 47};
49 48
49static unsigned int delkin_cb_init_chipset(struct pci_dev *dev)
50{
51 unsigned long base = pci_resource_start(dev, 0);
52 int i;
53
54 outb(0x02, base + 0x1e); /* set nIEN to block interrupts */
55 inb(base + 0x17); /* read status to clear interrupts */
56
57 for (i = 0; i < sizeof(setup); ++i) {
58 if (setup[i])
59 outb(setup[i], base + i);
60 }
61
62 return 0;
63}
64
50static const struct ide_port_info delkin_cb_port_info = { 65static const struct ide_port_info delkin_cb_port_info = {
51 .port_ops = &delkin_cb_port_ops, 66 .port_ops = &delkin_cb_port_ops,
52 .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS | 67 .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS |
53 IDE_HFLAG_NO_DMA, 68 IDE_HFLAG_NO_DMA,
69 .init_chipset = delkin_cb_init_chipset,
54}; 70};
55 71
56static int __devinit 72static int __devinit
@@ -58,7 +74,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
58{ 74{
59 struct ide_host *host; 75 struct ide_host *host;
60 unsigned long base; 76 unsigned long base;
61 int i, rc; 77 int rc;
62 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 78 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
63 79
64 rc = pci_enable_device(dev); 80 rc = pci_enable_device(dev);
@@ -73,12 +89,8 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
73 return rc; 89 return rc;
74 } 90 }
75 base = pci_resource_start(dev, 0); 91 base = pci_resource_start(dev, 0);
76 outb(0x02, base + 0x1e); /* set nIEN to block interrupts */ 92
77 inb(base + 0x17); /* read status to clear interrupts */ 93 delkin_cb_init_chipset(dev);
78 for (i = 0; i < sizeof(setup); ++i) {
79 if (setup[i])
80 outb(setup[i], base + i);
81 }
82 94
83 memset(&hw, 0, sizeof(hw)); 95 memset(&hw, 0, sizeof(hw));
84 ide_std_init_ports(&hw, base + 0x10, base + 0x1e); 96 ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
@@ -111,6 +123,40 @@ delkin_cb_remove (struct pci_dev *dev)
111 pci_disable_device(dev); 123 pci_disable_device(dev);
112} 124}
113 125
126#ifdef CONFIG_PM
127static int delkin_cb_suspend(struct pci_dev *dev, pm_message_t state)
128{
129 pci_save_state(dev);
130 pci_disable_device(dev);
131 pci_set_power_state(dev, pci_choose_state(dev, state));
132
133 return 0;
134}
135
136static int delkin_cb_resume(struct pci_dev *dev)
137{
138 struct ide_host *host = pci_get_drvdata(dev);
139 int rc;
140
141 pci_set_power_state(dev, PCI_D0);
142
143 rc = pci_enable_device(dev);
144 if (rc)
145 return rc;
146
147 pci_restore_state(dev);
148 pci_set_master(dev);
149
150 if (host->init_chipset)
151 host->init_chipset(dev);
152
153 return 0;
154}
155#else
156#define delkin_cb_suspend NULL
157#define delkin_cb_resume NULL
158#endif
159
114static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = { 160static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
115 { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 161 { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
116 { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 162 { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@@ -118,21 +164,23 @@ static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
118}; 164};
119MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl); 165MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
120 166
121static struct pci_driver driver = { 167static struct pci_driver delkin_cb_pci_driver = {
122 .name = "Delkin-ASKA-Workbit Cardbus IDE", 168 .name = "Delkin-ASKA-Workbit Cardbus IDE",
123 .id_table = delkin_cb_pci_tbl, 169 .id_table = delkin_cb_pci_tbl,
124 .probe = delkin_cb_probe, 170 .probe = delkin_cb_probe,
125 .remove = delkin_cb_remove, 171 .remove = delkin_cb_remove,
172 .suspend = delkin_cb_suspend,
173 .resume = delkin_cb_resume,
126}; 174};
127 175
128static int __init delkin_cb_init(void) 176static int __init delkin_cb_init(void)
129{ 177{
130 return pci_register_driver(&driver); 178 return pci_register_driver(&delkin_cb_pci_driver);
131} 179}
132 180
133static void __exit delkin_cb_exit(void) 181static void __exit delkin_cb_exit(void)
134{ 182{
135 pci_unregister_driver(&driver); 183 pci_unregister_driver(&delkin_cb_pci_driver);
136} 184}
137 185
138module_init(delkin_cb_init); 186module_init(delkin_cb_init);
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/dtc2278.c
index af791a02a120..689b2e493413 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/dtc2278.c
@@ -10,7 +10,6 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/ioport.h> 11#include <linux/ioport.h>
12#include <linux/blkdev.h> 12#include <linux/blkdev.h>
13#include <linux/hdreg.h>
14#include <linux/ide.h> 13#include <linux/ide.h>
15#include <linux/init.h> 14#include <linux/init.h>
16 15
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/falconide.c
index 724f95073d80..39d500d84b07 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/falconide.c
@@ -13,7 +13,6 @@
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/hdreg.h>
17#include <linux/ide.h> 16#include <linux/ide.h>
18#include <linux/init.h> 17#include <linux/init.h>
19 18
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/gayle.c
index 51ba085d7aa8..691506886561 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/gayle.c
@@ -12,7 +12,6 @@
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/blkdev.h> 14#include <linux/blkdev.h>
15#include <linux/hdreg.h>
16#include <linux/ide.h> 15#include <linux/ide.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/zorro.h> 17#include <linux/zorro.h>
diff --git a/drivers/ide/h8300/Makefile b/drivers/ide/h8300/Makefile
deleted file mode 100644
index 5eba16f423f4..000000000000
--- a/drivers/ide/h8300/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
1
2obj-$(CONFIG_IDE_H8300) += ide-h8300.o
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/hpt366.c
index c37ab1743819..f5afd46ed51c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/hpt366.c
@@ -3,7 +3,7 @@
3 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 3 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
4 * Portions Copyright (C) 2003 Red Hat Inc 4 * Portions Copyright (C) 2003 Red Hat Inc
5 * Portions Copyright (C) 2007 Bartlomiej Zolnierkiewicz 5 * Portions Copyright (C) 2007 Bartlomiej Zolnierkiewicz
6 * Portions Copyright (C) 2005-2007 MontaVista Software, Inc. 6 * Portions Copyright (C) 2005-2008 MontaVista Software, Inc.
7 * 7 *
8 * Thanks to HighPoint Technologies for their assistance, and hardware. 8 * Thanks to HighPoint Technologies for their assistance, and hardware.
9 * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his 9 * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his
@@ -52,7 +52,7 @@
52 * different clocks on read/write. This requires overloading rw_disk and 52 * different clocks on read/write. This requires overloading rw_disk and
53 * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for 53 * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for
54 * keeping me sane. 54 * keeping me sane.
55 * Alan Cox <alan@redhat.com> 55 * Alan Cox <alan@lxorguk.ukuu.org.uk>
56 * 56 *
57 * - fix the clock turnaround code: it was writing to the wrong ports when 57 * - fix the clock turnaround code: it was writing to the wrong ports when
58 * called for the secondary channel, caching the current clock mode per- 58 * called for the secondary channel, caching the current clock mode per-
@@ -122,7 +122,6 @@
122#include <linux/kernel.h> 122#include <linux/kernel.h>
123#include <linux/delay.h> 123#include <linux/delay.h>
124#include <linux/blkdev.h> 124#include <linux/blkdev.h>
125#include <linux/hdreg.h>
126#include <linux/interrupt.h> 125#include <linux/interrupt.h>
127#include <linux/pci.h> 126#include <linux/pci.h>
128#include <linux/init.h> 127#include <linux/init.h>
@@ -605,10 +604,10 @@ static const struct hpt_info hpt371n __devinitdata = {
605 604
606static int check_in_drive_list(ide_drive_t *drive, const char **list) 605static int check_in_drive_list(ide_drive_t *drive, const char **list)
607{ 606{
608 struct hd_driveid *id = drive->id; 607 char *m = (char *)&drive->id[ATA_ID_PROD];
609 608
610 while (*list) 609 while (*list)
611 if (!strcmp(*list++,id->model)) 610 if (!strcmp(*list++, m))
612 return 1; 611 return 1;
613 return 0; 612 return 0;
614} 613}
@@ -655,7 +654,7 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
655 case HPT372A: 654 case HPT372A:
656 case HPT372N: 655 case HPT372N:
657 case HPT374 : 656 case HPT374 :
658 if (ide_dev_is_sata(drive->id)) 657 if (ata_id_is_sata(drive->id))
659 mask &= ~0x0e; 658 mask &= ~0x0e;
660 /* Fall thru */ 659 /* Fall thru */
661 default: 660 default:
@@ -675,7 +674,7 @@ static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
675 case HPT372A: 674 case HPT372A:
676 case HPT372N: 675 case HPT372N:
677 case HPT374 : 676 case HPT374 :
678 if (ide_dev_is_sata(drive->id)) 677 if (ata_id_is_sata(drive->id))
679 return 0x00; 678 return 0x00;
680 /* Fall thru */ 679 /* Fall thru */
681 default: 680 default:
@@ -731,11 +730,11 @@ static void hpt3xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
731 730
732static void hpt3xx_quirkproc(ide_drive_t *drive) 731static void hpt3xx_quirkproc(ide_drive_t *drive)
733{ 732{
734 struct hd_driveid *id = drive->id; 733 char *m = (char *)&drive->id[ATA_ID_PROD];
735 const char **list = quirk_drives; 734 const char **list = quirk_drives;
736 735
737 while (*list) 736 while (*list)
738 if (strstr(id->model, *list++)) { 737 if (strstr(m, *list++)) {
739 drive->quirk_list = 1; 738 drive->quirk_list = 1;
740 return; 739 return;
741 } 740 }
@@ -749,26 +748,24 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
749 struct pci_dev *dev = to_pci_dev(hwif->dev); 748 struct pci_dev *dev = to_pci_dev(hwif->dev);
750 struct hpt_info *info = hpt3xx_get_info(hwif->dev); 749 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
751 750
752 if (drive->quirk_list) { 751 if (drive->quirk_list == 0)
753 if (info->chip_type >= HPT370) { 752 return;
754 u8 scr1 = 0; 753
755 754 if (info->chip_type >= HPT370) {
756 pci_read_config_byte(dev, 0x5a, &scr1); 755 u8 scr1 = 0;
757 if (((scr1 & 0x10) >> 4) != mask) { 756
758 if (mask) 757 pci_read_config_byte(dev, 0x5a, &scr1);
759 scr1 |= 0x10; 758 if (((scr1 & 0x10) >> 4) != mask) {
760 else
761 scr1 &= ~0x10;
762 pci_write_config_byte(dev, 0x5a, scr1);
763 }
764 } else {
765 if (mask) 759 if (mask)
766 disable_irq(hwif->irq); 760 scr1 |= 0x10;
767 else 761 else
768 enable_irq (hwif->irq); 762 scr1 &= ~0x10;
763 pci_write_config_byte(dev, 0x5a, scr1);
769 } 764 }
770 } else 765 } else if (mask)
771 outb(ATA_DEVCTL_OBS | (mask ? 2 : 0), hwif->io_ports.ctl_addr); 766 disable_irq(hwif->irq);
767 else
768 enable_irq(hwif->irq);
772} 769}
773 770
774/* 771/*
@@ -836,7 +833,7 @@ static int hpt370_dma_end(ide_drive_t *drive)
836 if (dma_stat & 0x01) 833 if (dma_stat & 0x01)
837 hpt370_irq_timeout(drive); 834 hpt370_irq_timeout(drive);
838 } 835 }
839 return __ide_dma_end(drive); 836 return ide_dma_end(drive);
840} 837}
841 838
842static void hpt370_dma_timeout(ide_drive_t *drive) 839static void hpt370_dma_timeout(ide_drive_t *drive)
@@ -864,9 +861,6 @@ static int hpt374_dma_test_irq(ide_drive_t *drive)
864 if (dma_stat & 4) 861 if (dma_stat & 4)
865 return 1; 862 return 1;
866 863
867 if (!drive->waiting_for_dma)
868 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
869 drive->name, __func__);
870 return 0; 864 return 0;
871} 865}
872 866
@@ -881,7 +875,7 @@ static int hpt374_dma_end(ide_drive_t *drive)
881 pci_read_config_byte(dev, mcr_addr, &mcr); 875 pci_read_config_byte(dev, mcr_addr, &mcr);
882 if (bwsr & mask) 876 if (bwsr & mask)
883 pci_write_config_byte(dev, mcr_addr, mcr | 0x30); 877 pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
884 return __ide_dma_end(drive); 878 return ide_dma_end(drive);
885} 879}
886 880
887/** 881/**
@@ -944,7 +938,7 @@ static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq)
944 * Perform a calibration cycle on the DPLL. 938 * Perform a calibration cycle on the DPLL.
945 * Returns 1 if this succeeds 939 * Returns 1 if this succeeds
946 */ 940 */
947static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high) 941static int hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high)
948{ 942{
949 u32 dpll = (f_high << 16) | f_low | 0x100; 943 u32 dpll = (f_high << 16) | f_low | 0x100;
950 u8 scr2; 944 u8 scr2;
@@ -972,7 +966,37 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f
972 return 1; 966 return 1;
973} 967}
974 968
975static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev) 969static void hpt3xx_disable_fast_irq(struct pci_dev *dev, u8 mcr_addr)
970{
971 struct ide_host *host = pci_get_drvdata(dev);
972 struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]);
973 u8 chip_type = info->chip_type;
974 u8 new_mcr, old_mcr = 0;
975
976 /*
977 * Disable the "fast interrupt" prediction. Don't hold off
978 * on interrupts. (== 0x01 despite what the docs say)
979 */
980 pci_read_config_byte(dev, mcr_addr + 1, &old_mcr);
981
982 if (chip_type >= HPT374)
983 new_mcr = old_mcr & ~0x07;
984 else if (chip_type >= HPT370) {
985 new_mcr = old_mcr;
986 new_mcr &= ~0x02;
987#ifdef HPT_DELAY_INTERRUPT
988 new_mcr &= ~0x01;
989#else
990 new_mcr |= 0x01;
991#endif
992 } else /* HPT366 and HPT368 */
993 new_mcr = old_mcr & ~0x80;
994
995 if (new_mcr != old_mcr)
996 pci_write_config_byte(dev, mcr_addr + 1, new_mcr);
997}
998
999static unsigned int init_chipset_hpt366(struct pci_dev *dev)
976{ 1000{
977 unsigned long io_base = pci_resource_start(dev, 4); 1001 unsigned long io_base = pci_resource_start(dev, 4);
978 struct hpt_info *info = hpt3xx_get_info(&dev->dev); 1002 struct hpt_info *info = hpt3xx_get_info(&dev->dev);
@@ -1209,9 +1233,11 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev)
1209 * NOTE: This register is only writeable via I/O space. 1233 * NOTE: This register is only writeable via I/O space.
1210 */ 1234 */
1211 if (chip_type == HPT371N && clock == ATA_CLOCK_66MHZ) 1235 if (chip_type == HPT371N && clock == ATA_CLOCK_66MHZ)
1212
1213 outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c); 1236 outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c);
1214 1237
1238 hpt3xx_disable_fast_irq(dev, 0x50);
1239 hpt3xx_disable_fast_irq(dev, 0x54);
1240
1215 return dev->irq; 1241 return dev->irq;
1216} 1242}
1217 1243
@@ -1261,11 +1287,9 @@ static u8 hpt3xx_cable_detect(ide_hwif_t *hwif)
1261 1287
1262static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1288static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1263{ 1289{
1264 struct pci_dev *dev = to_pci_dev(hwif->dev);
1265 struct hpt_info *info = hpt3xx_get_info(hwif->dev); 1290 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
1266 int serialize = HPT_SERIALIZE_IO; 1291 int serialize = HPT_SERIALIZE_IO;
1267 u8 chip_type = info->chip_type; 1292 u8 chip_type = info->chip_type;
1268 u8 new_mcr, old_mcr = 0;
1269 1293
1270 /* Cache the channel's MISC. control registers' offset */ 1294 /* Cache the channel's MISC. control registers' offset */
1271 hwif->select_data = hwif->channel ? 0x54 : 0x50; 1295 hwif->select_data = hwif->channel ? 0x54 : 0x50;
@@ -1288,29 +1312,6 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1288 /* Serialize access to this device if needed */ 1312 /* Serialize access to this device if needed */
1289 if (serialize && hwif->mate) 1313 if (serialize && hwif->mate)
1290 hwif->serialized = hwif->mate->serialized = 1; 1314 hwif->serialized = hwif->mate->serialized = 1;
1291
1292 /*
1293 * Disable the "fast interrupt" prediction. Don't hold off
1294 * on interrupts. (== 0x01 despite what the docs say)
1295 */
1296 pci_read_config_byte(dev, hwif->select_data + 1, &old_mcr);
1297
1298 if (info->chip_type >= HPT374)
1299 new_mcr = old_mcr & ~0x07;
1300 else if (info->chip_type >= HPT370) {
1301 new_mcr = old_mcr;
1302 new_mcr &= ~0x02;
1303
1304#ifdef HPT_DELAY_INTERRUPT
1305 new_mcr &= ~0x01;
1306#else
1307 new_mcr |= 0x01;
1308#endif
1309 } else /* HPT366 and HPT368 */
1310 new_mcr = old_mcr & ~0x80;
1311
1312 if (new_mcr != old_mcr)
1313 pci_write_config_byte(dev, hwif->select_data + 1, new_mcr);
1314} 1315}
1315 1316
1316static int __devinit init_dma_hpt366(ide_hwif_t *hwif, 1317static int __devinit init_dma_hpt366(ide_hwif_t *hwif,
@@ -1449,7 +1450,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1449 .dma_setup = ide_dma_setup, 1450 .dma_setup = ide_dma_setup,
1450 .dma_exec_cmd = ide_dma_exec_cmd, 1451 .dma_exec_cmd = ide_dma_exec_cmd,
1451 .dma_start = ide_dma_start, 1452 .dma_start = ide_dma_start,
1452 .dma_end = __ide_dma_end, 1453 .dma_end = ide_dma_end,
1453 .dma_test_irq = ide_dma_test_irq, 1454 .dma_test_irq = ide_dma_test_irq,
1454 .dma_lost_irq = hpt366_dma_lost_irq, 1455 .dma_lost_irq = hpt366_dma_lost_irq,
1455 .dma_timeout = ide_dma_timeout, 1456 .dma_timeout = ide_dma_timeout,
@@ -1615,21 +1616,23 @@ static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
1615}; 1616};
1616MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl); 1617MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
1617 1618
1618static struct pci_driver driver = { 1619static struct pci_driver hpt366_pci_driver = {
1619 .name = "HPT366_IDE", 1620 .name = "HPT366_IDE",
1620 .id_table = hpt366_pci_tbl, 1621 .id_table = hpt366_pci_tbl,
1621 .probe = hpt366_init_one, 1622 .probe = hpt366_init_one,
1622 .remove = __devexit_p(hpt366_remove), 1623 .remove = __devexit_p(hpt366_remove),
1624 .suspend = ide_pci_suspend,
1625 .resume = ide_pci_resume,
1623}; 1626};
1624 1627
1625static int __init hpt366_ide_init(void) 1628static int __init hpt366_ide_init(void)
1626{ 1629{
1627 return ide_pci_register_driver(&driver); 1630 return ide_pci_register_driver(&hpt366_pci_driver);
1628} 1631}
1629 1632
1630static void __exit hpt366_ide_exit(void) 1633static void __exit hpt366_ide_exit(void)
1631{ 1634{
1632 pci_unregister_driver(&driver); 1635 pci_unregister_driver(&hpt366_pci_driver);
1633} 1636}
1634 1637
1635module_init(hpt366_ide_init); 1638module_init(hpt366_ide_init);
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/ht6560b.c
index 98f7c95e39ed..c7e5c2246b79 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/ht6560b.c
@@ -24,7 +24,6 @@
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/ioport.h> 25#include <linux/ioport.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/hdreg.h>
28#include <linux/ide.h> 27#include <linux/ide.h>
29#include <linux/init.h> 28#include <linux/init.h>
30 29
@@ -121,7 +120,8 @@ static void ht6560b_selectproc (ide_drive_t *drive)
121 * Need to enforce prefetch sometimes because otherwise 120 * Need to enforce prefetch sometimes because otherwise
122 * it'll hang (hard). 121 * it'll hang (hard).
123 */ 122 */
124 if (drive->media != ide_disk || !drive->present) 123 if (drive->media != ide_disk ||
124 (drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
125 select |= HT_PREFETCH_MODE; 125 select |= HT_PREFETCH_MODE;
126 126
127 if (select != current_select || timing != current_timing) { 127 if (select != current_select || timing != current_timing) {
@@ -250,11 +250,11 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
250 */ 250 */
251 if (state) { 251 if (state) {
252 drive->drive_data |= t; /* enable prefetch mode */ 252 drive->drive_data |= t; /* enable prefetch mode */
253 drive->no_unmask = 1; 253 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
254 drive->unmask = 0; 254 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
255 } else { 255 } else {
256 drive->drive_data &= ~t; /* disable prefetch mode */ 256 drive->drive_data &= ~t; /* disable prefetch mode */
257 drive->no_unmask = 0; 257 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
258 } 258 }
259 259
260 spin_unlock_irqrestore(&ht6560b_lock, flags); 260 spin_unlock_irqrestore(&ht6560b_lock, flags);
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/icside.c
index df4af4083954..2d848010499d 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/icside.c
@@ -10,7 +10,6 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/blkdev.h> 11#include <linux/blkdev.h>
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/hdreg.h>
14#include <linux/ide.h> 13#include <linux/ide.h>
15#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
16#include <linux/device.h> 15#include <linux/device.h>
@@ -265,8 +264,8 @@ static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
265 * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should 264 * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
266 * take care to note the values in the ID... 265 * take care to note the values in the ID...
267 */ 266 */
268 if (use_dma_info && drive->id->eide_dma_time > cycle_time) 267 if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time)
269 cycle_time = drive->id->eide_dma_time; 268 cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME];
270 269
271 drive->drive_data = cycle_time; 270 drive->drive_data = cycle_time;
272 271
@@ -373,25 +372,6 @@ static int icside_dma_test_irq(ide_drive_t *drive)
373 ICS_ARCIN_V6_INTRSTAT_1)) & 1; 372 ICS_ARCIN_V6_INTRSTAT_1)) & 1;
374} 373}
375 374
376static void icside_dma_timeout(ide_drive_t *drive)
377{
378 ide_hwif_t *hwif = drive->hwif;
379
380 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
381
382 if (icside_dma_test_irq(drive))
383 return;
384
385 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
386
387 icside_dma_end(drive);
388}
389
390static void icside_dma_lost_irq(ide_drive_t *drive)
391{
392 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
393}
394
395static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 375static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
396{ 376{
397 hwif->dmatable_cpu = NULL; 377 hwif->dmatable_cpu = NULL;
@@ -407,8 +387,8 @@ static const struct ide_dma_ops icside_v6_dma_ops = {
407 .dma_start = icside_dma_start, 387 .dma_start = icside_dma_start,
408 .dma_end = icside_dma_end, 388 .dma_end = icside_dma_end,
409 .dma_test_irq = icside_dma_test_irq, 389 .dma_test_irq = icside_dma_test_irq,
410 .dma_timeout = icside_dma_timeout, 390 .dma_timeout = ide_dma_timeout,
411 .dma_lost_irq = icside_dma_lost_irq, 391 .dma_lost_irq = ide_dma_lost_irq,
412}; 392};
413#else 393#else
414#define icside_v6_dma_ops NULL 394#define icside_v6_dma_ops NULL
@@ -710,9 +690,9 @@ static int __init icside_init(void)
710 return ecard_register_driver(&icside_driver); 690 return ecard_register_driver(&icside_driver);
711} 691}
712 692
713static void __exit icside_exit(void); 693static void __exit icside_exit(void)
714{ 694{
715 ecard_unregister_driver(&icside_driver); 695 ecard_remove_driver(&icside_driver);
716} 696}
717 697
718MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); 698MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
diff --git a/drivers/ide/legacy/ide-4drives.c b/drivers/ide/ide-4drives.c
index c76d55de6996..9e85b1ec9607 100644
--- a/drivers/ide/legacy/ide-4drives.c
+++ b/drivers/ide/ide-4drives.c
@@ -14,7 +14,7 @@ MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port");
14static void ide_4drives_init_dev(ide_drive_t *drive) 14static void ide_4drives_init_dev(ide_drive_t *drive)
15{ 15{
16 if (drive->hwif->channel) 16 if (drive->hwif->channel)
17 drive->select.all ^= 0x20; 17 drive->select ^= 0x20;
18} 18}
19 19
20static const struct ide_port_ops ide_4drives_port_ops = { 20static const struct ide_port_ops ide_4drives_port_ops = {
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 6f704628c27d..244a8a052ce8 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -290,7 +290,7 @@ static int do_drive_get_GTF(ide_drive_t *drive,
290 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n", 290 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
291 hwif->name, dev->bus_id, port, hwif->channel); 291 hwif->name, dev->bus_id, port, hwif->channel);
292 292
293 if (!drive->present) { 293 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) {
294 DEBPRINT("%s drive %d:%d not present\n", 294 DEBPRINT("%s drive %d:%d not present\n",
295 hwif->name, hwif->channel, port); 295 hwif->name, hwif->channel, port);
296 goto out; 296 goto out;
@@ -420,8 +420,9 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
420 420
421 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn); 421 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
422 422
423 if (!drive->present) 423 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
424 goto out; 424 goto out;
425
425 if (!gtf_count) /* shouldn't be here */ 426 if (!gtf_count) /* shouldn't be here */
426 goto out; 427 goto out;
427 428
@@ -584,7 +585,7 @@ void ide_acpi_get_timing(ide_hwif_t *hwif)
584 * This function executes the _STM ACPI method for the target channel. 585 * This function executes the _STM ACPI method for the target channel.
585 * 586 *
586 * _STM requires Identify Drive data, which has to passed as an argument. 587 * _STM requires Identify Drive data, which has to passed as an argument.
587 * Unfortunately hd_driveid is a mangled version which we can't readily 588 * Unfortunately drive->id is a mangled version which we can't readily
588 * use; hence we'll get the information afresh. 589 * use; hence we'll get the information afresh.
589 */ 590 */
590void ide_acpi_push_timing(ide_hwif_t *hwif) 591void ide_acpi_push_timing(ide_hwif_t *hwif)
@@ -614,10 +615,10 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
614 in_params[0].buffer.length = sizeof(struct GTM_buffer); 615 in_params[0].buffer.length = sizeof(struct GTM_buffer);
615 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm; 616 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
616 in_params[1].type = ACPI_TYPE_BUFFER; 617 in_params[1].type = ACPI_TYPE_BUFFER;
617 in_params[1].buffer.length = sizeof(struct hd_driveid); 618 in_params[1].buffer.length = sizeof(ATA_ID_WORDS * 2);
618 in_params[1].buffer.pointer = (u8 *)&master->idbuff; 619 in_params[1].buffer.pointer = (u8 *)&master->idbuff;
619 in_params[2].type = ACPI_TYPE_BUFFER; 620 in_params[2].type = ACPI_TYPE_BUFFER;
620 in_params[2].buffer.length = sizeof(struct hd_driveid); 621 in_params[2].buffer.length = sizeof(ATA_ID_WORDS * 2);
621 in_params[2].buffer.pointer = (u8 *)&slave->idbuff; 622 in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
622 /* Output buffer: _STM has no output */ 623 /* Output buffer: _STM has no output */
623 624
@@ -660,7 +661,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
660 if (!drive->acpidata->obj_handle) 661 if (!drive->acpidata->obj_handle)
661 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); 662 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
662 663
663 if (drive->acpidata->obj_handle && drive->present) { 664 if (drive->acpidata->obj_handle &&
665 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
664 acpi_bus_set_power(drive->acpidata->obj_handle, 666 acpi_bus_set_power(drive->acpidata->obj_handle,
665 on? ACPI_STATE_D0: ACPI_STATE_D3); 667 on? ACPI_STATE_D0: ACPI_STATE_D3);
666 } 668 }
@@ -720,7 +722,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
720 722
721 memset(drive->acpidata, 0, sizeof(*drive->acpidata)); 723 memset(drive->acpidata, 0, sizeof(*drive->acpidata));
722 724
723 if (!drive->present) 725 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
724 continue; 726 continue;
725 727
726 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff); 728 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
@@ -745,7 +747,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
745 for (i = 0; i < MAX_DRIVES; i++) { 747 for (i = 0; i < MAX_DRIVES; i++) {
746 drive = &hwif->drives[i]; 748 drive = &hwif->drives[i];
747 749
748 if (drive->present) 750 if (drive->dev_flags & IDE_DFLAG_PRESENT)
749 /* Execute ACPI startup code */ 751 /* Execute ACPI startup code */
750 ide_acpi_exec_tfs(drive); 752 ide_acpi_exec_tfs(drive);
751 } 753 }
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index adf04f99cdeb..4e58b9e7a58a 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -14,25 +14,268 @@
14#define debug_log(fmt, args...) do {} while (0) 14#define debug_log(fmt, args...) do {} while (0)
15#endif 15#endif
16 16
17/* TODO: unify the code thus making some arguments go away */ 17/*
18ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, 18 * Check whether we can support a device,
19 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, 19 * based on the ATAPI IDENTIFY command results.
20 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), 20 */
21 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), 21int ide_check_atapi_device(ide_drive_t *drive, const char *s)
22 void (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int)) 22{
23 u16 *id = drive->id;
24 u8 gcw[2], protocol, device_type, removable, drq_type, packet_size;
25
26 *((u16 *)&gcw) = id[ATA_ID_CONFIG];
27
28 protocol = (gcw[1] & 0xC0) >> 6;
29 device_type = gcw[1] & 0x1F;
30 removable = (gcw[0] & 0x80) >> 7;
31 drq_type = (gcw[0] & 0x60) >> 5;
32 packet_size = gcw[0] & 0x03;
33
34#ifdef CONFIG_PPC
35 /* kludge for Apple PowerBook internal zip */
36 if (drive->media == ide_floppy && device_type == 5 &&
37 !strstr((char *)&id[ATA_ID_PROD], "CD-ROM") &&
38 strstr((char *)&id[ATA_ID_PROD], "ZIP"))
39 device_type = 0;
40#endif
41
42 if (protocol != 2)
43 printk(KERN_ERR "%s: %s: protocol (0x%02x) is not ATAPI\n",
44 s, drive->name, protocol);
45 else if ((drive->media == ide_floppy && device_type != 0) ||
46 (drive->media == ide_tape && device_type != 1))
47 printk(KERN_ERR "%s: %s: invalid device type (0x%02x)\n",
48 s, drive->name, device_type);
49 else if (removable == 0)
50 printk(KERN_ERR "%s: %s: the removable flag is not set\n",
51 s, drive->name);
52 else if (drive->media == ide_floppy && drq_type == 3)
53 printk(KERN_ERR "%s: %s: sorry, DRQ type (0x%02x) not "
54 "supported\n", s, drive->name, drq_type);
55 else if (packet_size != 0)
56 printk(KERN_ERR "%s: %s: packet size (0x%02x) is not 12 "
57 "bytes\n", s, drive->name, packet_size);
58 else
59 return 1;
60 return 0;
61}
62EXPORT_SYMBOL_GPL(ide_check_atapi_device);
63
64/* PIO data transfer routine using the scatter gather table. */
65int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
66 unsigned int bcount, int write)
67{
68 ide_hwif_t *hwif = drive->hwif;
69 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
70 xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data;
71 struct scatterlist *sg = pc->sg;
72 char *buf;
73 int count, done = 0;
74
75 while (bcount) {
76 count = min(sg->length - pc->b_count, bcount);
77
78 if (PageHighMem(sg_page(sg))) {
79 unsigned long flags;
80
81 local_irq_save(flags);
82 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
83 xf(drive, NULL, buf + pc->b_count, count);
84 kunmap_atomic(buf - sg->offset, KM_IRQ0);
85 local_irq_restore(flags);
86 } else {
87 buf = sg_virt(sg);
88 xf(drive, NULL, buf + pc->b_count, count);
89 }
90
91 bcount -= count;
92 pc->b_count += count;
93 done += count;
94
95 if (pc->b_count == sg->length) {
96 if (!--pc->sg_cnt)
97 break;
98 pc->sg = sg = sg_next(sg);
99 pc->b_count = 0;
100 }
101 }
102
103 if (bcount) {
104 printk(KERN_ERR "%s: %d leftover bytes, %s\n", drive->name,
105 bcount, write ? "padding with zeros"
106 : "discarding data");
107 ide_pad_transfer(drive, write, bcount);
108 }
109
110 return done;
111}
112EXPORT_SYMBOL_GPL(ide_io_buffers);
113
114void ide_init_pc(struct ide_atapi_pc *pc)
115{
116 memset(pc, 0, sizeof(*pc));
117 pc->buf = pc->pc_buf;
118 pc->buf_size = IDE_PC_BUFFER_SIZE;
119}
120EXPORT_SYMBOL_GPL(ide_init_pc);
121
122/*
123 * Generate a new packet command request in front of the request queue, before
124 * the current request, so that it will be processed immediately, on the next
125 * pass through the driver.
126 */
127static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
128 struct ide_atapi_pc *pc, struct request *rq)
129{
130 blk_rq_init(NULL, rq);
131 rq->cmd_type = REQ_TYPE_SPECIAL;
132 rq->cmd_flags |= REQ_PREEMPT;
133 rq->buffer = (char *)pc;
134 rq->rq_disk = disk;
135 memcpy(rq->cmd, pc->c, 12);
136 if (drive->media == ide_tape)
137 rq->cmd[13] = REQ_IDETAPE_PC1;
138 ide_do_drive_cmd(drive, rq);
139}
140
141/*
142 * Add a special packet command request to the tail of the request queue,
143 * and wait for it to be serviced.
144 */
145int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
146 struct ide_atapi_pc *pc)
147{
148 struct request *rq;
149 int error;
150
151 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
152 rq->cmd_type = REQ_TYPE_SPECIAL;
153 rq->buffer = (char *)pc;
154 memcpy(rq->cmd, pc->c, 12);
155 if (drive->media == ide_tape)
156 rq->cmd[13] = REQ_IDETAPE_PC1;
157 error = blk_execute_rq(drive->queue, disk, rq, 0);
158 blk_put_request(rq);
159
160 return error;
161}
162EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
163
164int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
165{
166 struct ide_atapi_pc pc;
167
168 ide_init_pc(&pc);
169 pc.c[0] = TEST_UNIT_READY;
170
171 return ide_queue_pc_tail(drive, disk, &pc);
172}
173EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
174
175int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
176{
177 struct ide_atapi_pc pc;
178
179 ide_init_pc(&pc);
180 pc.c[0] = START_STOP;
181 pc.c[4] = start;
182
183 if (drive->media == ide_tape)
184 pc.flags |= PC_FLAG_WAIT_FOR_DSC;
185
186 return ide_queue_pc_tail(drive, disk, &pc);
187}
188EXPORT_SYMBOL_GPL(ide_do_start_stop);
189
190int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
23{ 191{
192 struct ide_atapi_pc pc;
193
194 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
195 return 0;
196
197 ide_init_pc(&pc);
198 pc.c[0] = ALLOW_MEDIUM_REMOVAL;
199 pc.c[4] = on;
200
201 return ide_queue_pc_tail(drive, disk, &pc);
202}
203EXPORT_SYMBOL_GPL(ide_set_media_lock);
204
205void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
206{
207 ide_init_pc(pc);
208 pc->c[0] = REQUEST_SENSE;
209 if (drive->media == ide_floppy) {
210 pc->c[4] = 255;
211 pc->req_xfer = 18;
212 } else {
213 pc->c[4] = 20;
214 pc->req_xfer = 20;
215 }
216}
217EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
218
219/*
220 * Called when an error was detected during the last packet command.
221 * We queue a request sense packet command in the head of the request list.
222 */
223void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
224{
225 struct request *rq = &drive->request_sense_rq;
226 struct ide_atapi_pc *pc = &drive->request_sense_pc;
227
228 (void)ide_read_error(drive);
229 ide_create_request_sense_cmd(drive, pc);
230 if (drive->media == ide_tape)
231 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
232 ide_queue_pc_head(drive, disk, pc, rq);
233}
234EXPORT_SYMBOL_GPL(ide_retry_pc);
235
236int ide_scsi_expiry(ide_drive_t *drive)
237{
238 struct ide_atapi_pc *pc = drive->pc;
239
240 debug_log("%s called for %lu at %lu\n", __func__,
241 pc->scsi_cmd->serial_number, jiffies);
242
243 pc->flags |= PC_FLAG_TIMEDOUT;
244
245 return 0; /* we do not want the IDE subsystem to retry */
246}
247EXPORT_SYMBOL_GPL(ide_scsi_expiry);
248
249/*
250 * This is the usual interrupt handler which will be called during a packet
251 * command. We will transfer some of the data (as requested by the drive)
252 * and will re-point interrupt handler to us.
253 */
254static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
255{
256 struct ide_atapi_pc *pc = drive->pc;
24 ide_hwif_t *hwif = drive->hwif; 257 ide_hwif_t *hwif = drive->hwif;
25 struct request *rq = hwif->hwgroup->rq; 258 struct request *rq = hwif->hwgroup->rq;
26 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 259 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
27 xfer_func_t *xferfunc; 260 xfer_func_t *xferfunc;
28 unsigned int temp; 261 ide_expiry_t *expiry;
262 unsigned int timeout, temp;
29 u16 bcount; 263 u16 bcount;
30 u8 stat, ireason, scsi = drive->scsi; 264 u8 stat, ireason, scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI), dsc = 0;
31 265
32 debug_log("Enter %s - interrupt handler\n", __func__); 266 debug_log("Enter %s - interrupt handler\n", __func__);
33 267
268 if (scsi) {
269 timeout = ide_scsi_get_timeout(pc);
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
34 if (pc->flags & PC_FLAG_TIMEDOUT) { 277 if (pc->flags & PC_FLAG_TIMEDOUT) {
35 drive->pc_callback(drive); 278 drive->pc_callback(drive, 0);
36 return ide_stopped; 279 return ide_stopped;
37 } 280 }
38 281
@@ -41,7 +284,7 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
41 284
42 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { 285 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
43 if (hwif->dma_ops->dma_end(drive) || 286 if (hwif->dma_ops->dma_end(drive) ||
44 (drive->media == ide_tape && !scsi && (stat & ERR_STAT))) { 287 (drive->media == ide_tape && !scsi && (stat & ATA_ERR))) {
45 if (drive->media == ide_floppy && !scsi) 288 if (drive->media == ide_floppy && !scsi)
46 printk(KERN_ERR "%s: DMA %s error\n", 289 printk(KERN_ERR "%s: DMA %s error\n",
47 drive->name, rq_data_dir(pc->rq) 290 drive->name, rq_data_dir(pc->rq)
@@ -49,14 +292,14 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
49 pc->flags |= PC_FLAG_DMA_ERROR; 292 pc->flags |= PC_FLAG_DMA_ERROR;
50 } else { 293 } else {
51 pc->xferred = pc->req_xfer; 294 pc->xferred = pc->req_xfer;
52 if (update_buffers) 295 if (drive->pc_update_buffers)
53 update_buffers(drive, pc); 296 drive->pc_update_buffers(drive, pc);
54 } 297 }
55 debug_log("%s: DMA finished\n", drive->name); 298 debug_log("%s: DMA finished\n", drive->name);
56 } 299 }
57 300
58 /* No more interrupts */ 301 /* No more interrupts */
59 if ((stat & DRQ_STAT) == 0) { 302 if ((stat & ATA_DRQ) == 0) {
60 debug_log("Packet command completed, %d bytes transferred\n", 303 debug_log("Packet command completed, %d bytes transferred\n",
61 pc->xferred); 304 pc->xferred);
62 305
@@ -65,10 +308,10 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
65 local_irq_enable_in_hardirq(); 308 local_irq_enable_in_hardirq();
66 309
67 if (drive->media == ide_tape && !scsi && 310 if (drive->media == ide_tape && !scsi &&
68 (stat & ERR_STAT) && rq->cmd[0] == REQUEST_SENSE) 311 (stat & ATA_ERR) && rq->cmd[0] == REQUEST_SENSE)
69 stat &= ~ERR_STAT; 312 stat &= ~ATA_ERR;
70 313
71 if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) { 314 if ((stat & ATA_ERR) || (pc->flags & PC_FLAG_DMA_ERROR)) {
72 /* Error detected */ 315 /* Error detected */
73 debug_log("%s: I/O error\n", drive->name); 316 debug_log("%s: I/O error\n", drive->name);
74 317
@@ -87,21 +330,19 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
87 debug_log("[cmd %x]: check condition\n", rq->cmd[0]); 330 debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
88 331
89 /* Retry operation */ 332 /* Retry operation */
90 retry_pc(drive); 333 ide_retry_pc(drive, rq->rq_disk);
91 334
92 /* queued, but not started */ 335 /* queued, but not started */
93 return ide_stopped; 336 return ide_stopped;
94 } 337 }
95cmd_finished: 338cmd_finished:
96 pc->error = 0; 339 pc->error = 0;
97 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && 340
98 (stat & SEEK_STAT) == 0) { 341 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
99 dsc_handle(drive); 342 dsc = 1;
100 return ide_stopped;
101 }
102 343
103 /* Command finished - Call the callback function */ 344 /* Command finished - Call the callback function */
104 drive->pc_callback(drive); 345 drive->pc_callback(drive, dsc);
105 346
106 return ide_stopped; 347 return ide_stopped;
107 } 348 }
@@ -117,17 +358,18 @@ cmd_finished:
117 /* Get the number of bytes to transfer on this interrupt. */ 358 /* Get the number of bytes to transfer on this interrupt. */
118 ide_read_bcount_and_ireason(drive, &bcount, &ireason); 359 ide_read_bcount_and_ireason(drive, &bcount, &ireason);
119 360
120 if (ireason & CD) { 361 if (ireason & ATAPI_COD) {
121 printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__); 362 printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__);
122 return ide_do_reset(drive); 363 return ide_do_reset(drive);
123 } 364 }
124 365
125 if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) { 366 if (((ireason & ATAPI_IO) == ATAPI_IO) ==
367 !!(pc->flags & PC_FLAG_WRITING)) {
126 /* Hopefully, we will never get here */ 368 /* Hopefully, we will never get here */
127 printk(KERN_ERR "%s: We wanted to %s, but the device wants us " 369 printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
128 "to %s!\n", drive->name, 370 "to %s!\n", drive->name,
129 (ireason & IO) ? "Write" : "Read", 371 (ireason & ATAPI_IO) ? "Write" : "Read",
130 (ireason & IO) ? "Read" : "Write"); 372 (ireason & ATAPI_IO) ? "Read" : "Write");
131 return ide_do_reset(drive); 373 return ide_do_reset(drive);
132 } 374 }
133 375
@@ -146,7 +388,8 @@ cmd_finished:
146 temp = 0; 388 temp = 0;
147 if (temp) { 389 if (temp) {
148 if (pc->sg) 390 if (pc->sg)
149 io_buffers(drive, pc, temp, 0); 391 drive->pc_io_buffers(drive, pc,
392 temp, 0);
150 else 393 else
151 tp_ops->input_data(drive, NULL, 394 tp_ops->input_data(drive, NULL,
152 pc->cur_pos, temp); 395 pc->cur_pos, temp);
@@ -158,9 +401,7 @@ cmd_finished:
158 pc->xferred += temp; 401 pc->xferred += temp;
159 pc->cur_pos += temp; 402 pc->cur_pos += temp;
160 ide_pad_transfer(drive, 0, bcount - temp); 403 ide_pad_transfer(drive, 0, bcount - temp);
161 ide_set_handler(drive, handler, timeout, 404 goto next_irq;
162 expiry);
163 return ide_started;
164 } 405 }
165 debug_log("The device wants to send us more data than " 406 debug_log("The device wants to send us more data than "
166 "expected - allowing transfer\n"); 407 "expected - allowing transfer\n");
@@ -171,9 +412,14 @@ cmd_finished:
171 412
172 if ((drive->media == ide_floppy && !scsi && !pc->buf) || 413 if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
173 (drive->media == ide_tape && !scsi && pc->bh) || 414 (drive->media == ide_tape && !scsi && pc->bh) ||
174 (scsi && pc->sg)) 415 (scsi && pc->sg)) {
175 io_buffers(drive, pc, bcount, !!(pc->flags & PC_FLAG_WRITING)); 416 int done = drive->pc_io_buffers(drive, pc, bcount,
176 else 417 !!(pc->flags & PC_FLAG_WRITING));
418
419 /* FIXME: don't do partial completions */
420 if (drive->media == ide_floppy && !scsi)
421 ide_end_request(drive, 1, done >> 9);
422 } else
177 xferfunc(drive, NULL, pc->cur_pos, bcount); 423 xferfunc(drive, NULL, pc->cur_pos, bcount);
178 424
179 /* Update the current position */ 425 /* Update the current position */
@@ -182,12 +428,11 @@ cmd_finished:
182 428
183 debug_log("[cmd %x] transferred %d bytes on that intr.\n", 429 debug_log("[cmd %x] transferred %d bytes on that intr.\n",
184 rq->cmd[0], bcount); 430 rq->cmd[0], bcount);
185 431next_irq:
186 /* And set the interrupt handler again */ 432 /* And set the interrupt handler again */
187 ide_set_handler(drive, handler, timeout, expiry); 433 ide_set_handler(drive, ide_pc_intr, timeout, expiry);
188 return ide_started; 434 return ide_started;
189} 435}
190EXPORT_SYMBOL_GPL(ide_pc_intr);
191 436
192static u8 ide_read_ireason(ide_drive_t *drive) 437static u8 ide_read_ireason(ide_drive_t *drive)
193{ 438{
@@ -205,7 +450,8 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
205{ 450{
206 int retries = 100; 451 int retries = 100;
207 452
208 while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) { 453 while (retries-- && ((ireason & ATAPI_COD) == 0 ||
454 (ireason & ATAPI_IO))) {
209 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " 455 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
210 "a packet command, retrying\n", drive->name); 456 "a packet command, retrying\n", drive->name);
211 udelay(100); 457 udelay(100);
@@ -214,41 +460,71 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
214 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " 460 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
215 "a packet command, ignoring\n", 461 "a packet command, ignoring\n",
216 drive->name); 462 drive->name);
217 ireason |= CD; 463 ireason |= ATAPI_COD;
218 ireason &= ~IO; 464 ireason &= ~ATAPI_IO;
219 } 465 }
220 } 466 }
221 467
222 return ireason; 468 return ireason;
223} 469}
224 470
225ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc, 471static int ide_delayed_transfer_pc(ide_drive_t *drive)
226 ide_handler_t *handler, unsigned int timeout,
227 ide_expiry_t *expiry)
228{ 472{
473 /* Send the actual packet */
474 drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
475
476 /* Timeout for the packet command */
477 return WAIT_FLOPPY_CMD;
478}
479
480static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
481{
482 struct ide_atapi_pc *pc = drive->pc;
229 ide_hwif_t *hwif = drive->hwif; 483 ide_hwif_t *hwif = drive->hwif;
230 struct request *rq = hwif->hwgroup->rq; 484 struct request *rq = hwif->hwgroup->rq;
485 ide_expiry_t *expiry;
486 unsigned int timeout;
231 ide_startstop_t startstop; 487 ide_startstop_t startstop;
232 u8 ireason; 488 u8 ireason;
233 489
234 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { 490 if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) {
235 printk(KERN_ERR "%s: Strange, packet command initiated yet " 491 printk(KERN_ERR "%s: Strange, packet command initiated yet "
236 "DRQ isn't asserted\n", drive->name); 492 "DRQ isn't asserted\n", drive->name);
237 return startstop; 493 return startstop;
238 } 494 }
239 495
240 ireason = ide_read_ireason(drive); 496 ireason = ide_read_ireason(drive);
241 if (drive->media == ide_tape && !drive->scsi) 497 if (drive->media == ide_tape &&
498 (drive->dev_flags & IDE_DFLAG_SCSI) == 0)
242 ireason = ide_wait_ireason(drive, ireason); 499 ireason = ide_wait_ireason(drive, ireason);
243 500
244 if ((ireason & CD) == 0 || (ireason & IO)) { 501 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
245 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing " 502 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
246 "a packet command\n", drive->name); 503 "a packet command\n", drive->name);
247 return ide_do_reset(drive); 504 return ide_do_reset(drive);
248 } 505 }
249 506
507 /*
508 * If necessary schedule the packet transfer to occur 'timeout'
509 * miliseconds later in ide_delayed_transfer_pc() after the device
510 * says it's ready for a packet.
511 */
512 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
513 timeout = drive->pc_delay;
514 expiry = &ide_delayed_transfer_pc;
515 } else {
516 if (drive->dev_flags & IDE_DFLAG_SCSI) {
517 timeout = ide_scsi_get_timeout(pc);
518 expiry = ide_scsi_expiry;
519 } else {
520 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
521 : WAIT_TAPE_CMD;
522 expiry = NULL;
523 }
524 }
525
250 /* Set the interrupt routine */ 526 /* Set the interrupt routine */
251 ide_set_handler(drive, handler, timeout, expiry); 527 ide_set_handler(drive, ide_pc_intr, timeout, expiry);
252 528
253 /* Begin DMA, if necessary */ 529 /* Begin DMA, if necessary */
254 if (pc->flags & PC_FLAG_DMA_OK) { 530 if (pc->flags & PC_FLAG_DMA_OK) {
@@ -262,22 +538,22 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
262 538
263 return ide_started; 539 return ide_started;
264} 540}
265EXPORT_SYMBOL_GPL(ide_transfer_pc);
266 541
267ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc, 542ide_startstop_t ide_issue_pc(ide_drive_t *drive, unsigned int timeout,
268 ide_handler_t *handler, unsigned int timeout,
269 ide_expiry_t *expiry) 543 ide_expiry_t *expiry)
270{ 544{
545 struct ide_atapi_pc *pc = drive->pc;
271 ide_hwif_t *hwif = drive->hwif; 546 ide_hwif_t *hwif = drive->hwif;
547 u32 tf_flags;
272 u16 bcount; 548 u16 bcount;
273 u8 dma = 0; 549 u8 scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI);
274 550
275 /* We haven't transferred any data yet */ 551 /* We haven't transferred any data yet */
276 pc->xferred = 0; 552 pc->xferred = 0;
277 pc->cur_pos = pc->buf; 553 pc->cur_pos = pc->buf;
278 554
279 /* Request to transfer the entire buffer at once */ 555 /* Request to transfer the entire buffer at once */
280 if (drive->media == ide_tape && !drive->scsi) 556 if (drive->media == ide_tape && scsi == 0)
281 bcount = pc->req_xfer; 557 bcount = pc->req_xfer;
282 else 558 else
283 bcount = min(pc->req_xfer, 63 * 1024); 559 bcount = min(pc->req_xfer, 63 * 1024);
@@ -287,28 +563,35 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
287 ide_dma_off(drive); 563 ide_dma_off(drive);
288 } 564 }
289 565
290 if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma) { 566 if ((pc->flags & PC_FLAG_DMA_OK) &&
291 if (drive->scsi) 567 (drive->dev_flags & IDE_DFLAG_USING_DMA)) {
568 if (scsi)
292 hwif->sg_mapped = 1; 569 hwif->sg_mapped = 1;
293 dma = !hwif->dma_ops->dma_setup(drive); 570 drive->dma = !hwif->dma_ops->dma_setup(drive);
294 if (drive->scsi) 571 if (scsi)
295 hwif->sg_mapped = 0; 572 hwif->sg_mapped = 0;
296 } 573 }
297 574
298 if (!dma) 575 if (!drive->dma)
299 pc->flags &= ~PC_FLAG_DMA_OK; 576 pc->flags &= ~PC_FLAG_DMA_OK;
300 577
301 ide_pktcmd_tf_load(drive, drive->scsi ? 0 : IDE_TFLAG_OUT_DEVICE, 578 if (scsi)
302 bcount, dma); 579 tf_flags = 0;
580 else if (drive->media == ide_cdrom || drive->media == ide_optical)
581 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
582 else
583 tf_flags = IDE_TFLAG_OUT_DEVICE;
584
585 ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);
303 586
304 /* Issue the packet command */ 587 /* Issue the packet command */
305 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 588 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
306 ide_execute_command(drive, WIN_PACKETCMD, handler, 589 ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc,
307 timeout, NULL); 590 timeout, NULL);
308 return ide_started; 591 return ide_started;
309 } else { 592 } else {
310 ide_execute_pkt_cmd(drive); 593 ide_execute_pkt_cmd(drive);
311 return (*handler)(drive); 594 return ide_transfer_pc(drive);
312 } 595 }
313} 596}
314EXPORT_SYMBOL_GPL(ide_issue_pc); 597EXPORT_SYMBOL_GPL(ide_issue_pc);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index f16bb4667238..42ab6d8715f2 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -23,6 +23,9 @@
23 * Documentation/ide/ChangeLog.ide-cd.1994-2004 23 * Documentation/ide/ChangeLog.ide-cd.1994-2004
24 */ 24 */
25 25
26#define DRV_NAME "ide-cd"
27#define PFX DRV_NAME ": "
28
26#define IDECD_VERSION "5.00" 29#define IDECD_VERSION "5.00"
27 30
28#include <linux/module.h> 31#include <linux/module.h>
@@ -50,12 +53,15 @@
50 53
51#include "ide-cd.h" 54#include "ide-cd.h"
52 55
53static DEFINE_MUTEX(idecd_ref_mutex); 56#define IDECD_DEBUG_LOG 1
54 57
55#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) 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
56 63
57#define ide_cd_g(disk) \ 64static DEFINE_MUTEX(idecd_ref_mutex);
58 container_of((disk)->private_data, struct cdrom_info, driver)
59 65
60static void ide_cd_release(struct kref *); 66static void ide_cd_release(struct kref *);
61 67
@@ -64,7 +70,7 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
64 struct cdrom_info *cd = NULL; 70 struct cdrom_info *cd = NULL;
65 71
66 mutex_lock(&idecd_ref_mutex); 72 mutex_lock(&idecd_ref_mutex);
67 cd = ide_cd_g(disk); 73 cd = ide_drv_g(disk, cdrom_info);
68 if (cd) { 74 if (cd) {
69 if (ide_device_get(cd->drive)) 75 if (ide_device_get(cd->drive))
70 cd = NULL; 76 cd = NULL;
@@ -93,7 +99,7 @@ static void ide_cd_put(struct cdrom_info *cd)
93/* Mark that we've seen a media change and invalidate our internal buffers. */ 99/* Mark that we've seen a media change and invalidate our internal buffers. */
94static void cdrom_saw_media_change(ide_drive_t *drive) 100static void cdrom_saw_media_change(ide_drive_t *drive)
95{ 101{
96 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; 102 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
97 drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID; 103 drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID;
98} 104}
99 105
@@ -102,6 +108,9 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
102{ 108{
103 int log = 0; 109 int log = 0;
104 110
111 ide_debug_log(IDE_DBG_SENSE, "Call %s, sense_key: 0x%x\n", __func__,
112 sense->sense_key);
113
105 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) 114 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
106 return 0; 115 return 0;
107 116
@@ -150,6 +159,14 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
150 unsigned long bio_sectors; 159 unsigned long bio_sectors;
151 struct cdrom_info *info = drive->driver_data; 160 struct cdrom_info *info = drive->driver_data;
152 161
162 ide_debug_log(IDE_DBG_SENSE, "Call %s, error_code: 0x%x, "
163 "sense_key: 0x%x\n", __func__, sense->error_code,
164 sense->sense_key);
165
166 if (failed_command)
167 ide_debug_log(IDE_DBG_SENSE, "%s: failed cmd: 0x%x\n",
168 __func__, failed_command->cmd[0]);
169
153 if (!cdrom_log_sense(drive, failed_command, sense)) 170 if (!cdrom_log_sense(drive, failed_command, sense))
154 return; 171 return;
155 172
@@ -200,6 +217,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
200 struct cdrom_info *info = drive->driver_data; 217 struct cdrom_info *info = drive->driver_data;
201 struct request *rq = &info->request_sense_request; 218 struct request *rq = &info->request_sense_request;
202 219
220 ide_debug_log(IDE_DBG_SENSE, "Call %s\n", __func__);
221
203 if (sense == NULL) 222 if (sense == NULL)
204 sense = &info->sense_data; 223 sense = &info->sense_data;
205 224
@@ -219,6 +238,10 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
219 /* NOTE! Save the failed command in "rq->buffer" */ 238 /* NOTE! Save the failed command in "rq->buffer" */
220 rq->buffer = (void *) failed_command; 239 rq->buffer = (void *) failed_command;
221 240
241 if (failed_command)
242 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n",
243 failed_command->cmd[0]);
244
222 ide_do_drive_cmd(drive, rq); 245 ide_do_drive_cmd(drive, rq);
223} 246}
224 247
@@ -227,6 +250,10 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
227 struct request *rq = HWGROUP(drive)->rq; 250 struct request *rq = HWGROUP(drive)->rq;
228 int nsectors = rq->hard_cur_sectors; 251 int nsectors = rq->hard_cur_sectors;
229 252
253 ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, "
254 "nsectors: %d\n", __func__, rq->cmd[0], uptodate,
255 nsectors);
256
230 if (blk_sense_request(rq) && uptodate) { 257 if (blk_sense_request(rq) && uptodate) {
231 /* 258 /*
232 * For REQ_TYPE_SENSE, "rq->buffer" points to the original 259 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
@@ -269,6 +296,9 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
269 if (!nsectors) 296 if (!nsectors)
270 nsectors = 1; 297 nsectors = 1;
271 298
299 ide_debug_log(IDE_DBG_FUNC, "Exit %s, uptodate: 0x%x, nsectors: %d\n",
300 __func__, uptodate, nsectors);
301
272 ide_end_request(drive, uptodate, nsectors); 302 ide_end_request(drive, uptodate, nsectors);
273} 303}
274 304
@@ -304,11 +334,15 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
304 sense_key = err >> 4; 334 sense_key = err >> 4;
305 335
306 if (rq == NULL) { 336 if (rq == NULL) {
307 printk(KERN_ERR "%s: missing rq in %s\n", 337 printk(KERN_ERR PFX "%s: missing rq in %s\n",
308 drive->name, __func__); 338 drive->name, __func__);
309 return 1; 339 return 1;
310 } 340 }
311 341
342 ide_debug_log(IDE_DBG_RQ, "%s: stat: 0x%x, good_stat: 0x%x, "
343 "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x, err: 0x%x\n",
344 __func__, stat, good_stat, rq->cmd[0], rq->cmd_type, err);
345
312 if (blk_sense_request(rq)) { 346 if (blk_sense_request(rq)) {
313 /* 347 /*
314 * We got an error trying to get sense info from the drive 348 * We got an error trying to get sense info from the drive
@@ -374,7 +408,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
374 cdrom_saw_media_change(drive); 408 cdrom_saw_media_change(drive);
375 409
376 /* fail the request */ 410 /* fail the request */
377 printk(KERN_ERR "%s: tray open\n", drive->name); 411 printk(KERN_ERR PFX "%s: tray open\n",
412 drive->name);
378 do_end_request = 1; 413 do_end_request = 1;
379 } else { 414 } else {
380 struct cdrom_info *info = drive->driver_data; 415 struct cdrom_info *info = drive->driver_data;
@@ -436,7 +471,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
436 ide_dump_status_no_sense(drive, "media error (blank)", 471 ide_dump_status_no_sense(drive, "media error (blank)",
437 stat); 472 stat);
438 do_end_request = 1; 473 do_end_request = 1;
439 } else if ((err & ~ABRT_ERR) != 0) { 474 } else if ((err & ~ATA_ABORTED) != 0) {
440 /* go to the default handler for other errors */ 475 /* go to the default handler for other errors */
441 ide_error(drive, "cdrom_decode_status", stat); 476 ide_error(drive, "cdrom_decode_status", stat);
442 return 1; 477 return 1;
@@ -457,10 +492,10 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
457 * If we got a CHECK_CONDITION status, queue 492 * If we got a CHECK_CONDITION status, queue
458 * a request sense command. 493 * a request sense command.
459 */ 494 */
460 if (stat & ERR_STAT) 495 if (stat & ATA_ERR)
461 cdrom_queue_request_sense(drive, NULL, NULL); 496 cdrom_queue_request_sense(drive, NULL, NULL);
462 } else { 497 } else {
463 blk_dump_rq_flags(rq, "ide-cd: bad rq"); 498 blk_dump_rq_flags(rq, PFX "bad rq");
464 cdrom_end_request(drive, 0); 499 cdrom_end_request(drive, 0);
465 } 500 }
466 501
@@ -468,7 +503,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
468 return 1; 503 return 1;
469 504
470end_request: 505end_request:
471 if (stat & ERR_STAT) { 506 if (stat & ATA_ERR) {
472 unsigned long flags; 507 unsigned long flags;
473 508
474 spin_lock_irqsave(&ide_lock, flags); 509 spin_lock_irqsave(&ide_lock, flags);
@@ -488,6 +523,9 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
488 struct request *rq = HWGROUP(drive)->rq; 523 struct request *rq = HWGROUP(drive)->rq;
489 unsigned long wait = 0; 524 unsigned long wait = 0;
490 525
526 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd[0]: 0x%x\n", __func__,
527 rq->cmd[0]);
528
491 /* 529 /*
492 * Some commands are *slow* and normally take a long time to complete. 530 * Some commands are *slow* and normally take a long time to complete.
493 * Usually we can use the ATAPI "disconnect" to bypass this, but not all 531 * Usually we can use the ATAPI "disconnect" to bypass this, but not all
@@ -504,7 +542,7 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
504 break; 542 break;
505 default: 543 default:
506 if (!(rq->cmd_flags & REQ_QUIET)) 544 if (!(rq->cmd_flags & REQ_QUIET))
507 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", 545 printk(KERN_INFO PFX "cmd 0x%x timed out\n",
508 rq->cmd[0]); 546 rq->cmd[0]);
509 wait = 0; 547 wait = 0;
510 break; 548 break;
@@ -524,24 +562,25 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
524 int xferlen, 562 int xferlen,
525 ide_handler_t *handler) 563 ide_handler_t *handler)
526{ 564{
527 struct cdrom_info *info = drive->driver_data;
528 ide_hwif_t *hwif = drive->hwif; 565 ide_hwif_t *hwif = drive->hwif;
529 566
567 ide_debug_log(IDE_DBG_PC, "Call %s, xferlen: %d\n", __func__, xferlen);
568
530 /* FIXME: for Virtual DMA we must check harder */ 569 /* FIXME: for Virtual DMA we must check harder */
531 if (info->dma) 570 if (drive->dma)
532 info->dma = !hwif->dma_ops->dma_setup(drive); 571 drive->dma = !hwif->dma_ops->dma_setup(drive);
533 572
534 /* set up the controller registers */ 573 /* set up the controller registers */
535 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL, 574 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL,
536 xferlen, info->dma); 575 xferlen, drive->dma);
537 576
538 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 577 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
539 /* waiting for CDB interrupt, not DMA yet. */ 578 /* waiting for CDB interrupt, not DMA yet. */
540 if (info->dma) 579 if (drive->dma)
541 drive->waiting_for_dma = 0; 580 drive->waiting_for_dma = 0;
542 581
543 /* packet command */ 582 /* packet command */
544 ide_execute_command(drive, WIN_PACKETCMD, handler, 583 ide_execute_command(drive, ATA_CMD_PACKET, handler,
545 ATAPI_WAIT_PC, cdrom_timer_expiry); 584 ATAPI_WAIT_PC, cdrom_timer_expiry);
546 return ide_started; 585 return ide_started;
547 } else { 586 } else {
@@ -564,9 +603,10 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
564{ 603{
565 ide_hwif_t *hwif = drive->hwif; 604 ide_hwif_t *hwif = drive->hwif;
566 int cmd_len; 605 int cmd_len;
567 struct cdrom_info *info = drive->driver_data;
568 ide_startstop_t startstop; 606 ide_startstop_t startstop;
569 607
608 ide_debug_log(IDE_DBG_PC, "Call %s\n", __func__);
609
570 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 610 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
571 /* 611 /*
572 * Here we should have been called after receiving an interrupt 612 * Here we should have been called after receiving an interrupt
@@ -574,16 +614,16 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
574 */ 614 */
575 615
576 /* check for errors */ 616 /* check for errors */
577 if (cdrom_decode_status(drive, DRQ_STAT, NULL)) 617 if (cdrom_decode_status(drive, ATA_DRQ, NULL))
578 return ide_stopped; 618 return ide_stopped;
579 619
580 /* ok, next interrupt will be DMA interrupt */ 620 /* ok, next interrupt will be DMA interrupt */
581 if (info->dma) 621 if (drive->dma)
582 drive->waiting_for_dma = 1; 622 drive->waiting_for_dma = 1;
583 } else { 623 } else {
584 /* otherwise, we must wait for DRQ to get set */ 624 /* otherwise, we must wait for DRQ to get set */
585 if (ide_wait_stat(&startstop, drive, DRQ_STAT, 625 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
586 BUSY_STAT, WAIT_READY)) 626 ATA_BUSY, WAIT_READY))
587 return startstop; 627 return startstop;
588 } 628 }
589 629
@@ -599,7 +639,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
599 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len); 639 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
600 640
601 /* start the DMA if need be */ 641 /* start the DMA if need be */
602 if (info->dma) 642 if (drive->dma)
603 hwif->dma_ops->dma_start(drive); 643 hwif->dma_ops->dma_start(drive);
604 644
605 return ide_started; 645 return ide_started;
@@ -615,6 +655,9 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
615{ 655{
616 ide_hwif_t *hwif = drive->hwif; 656 ide_hwif_t *hwif = drive->hwif;
617 657
658 ide_debug_log(IDE_DBG_FUNC, "Call %s, ireason: 0x%x, rw: 0x%x\n",
659 __func__, ireason, rw);
660
618 /* 661 /*
619 * ireason == 0: the drive wants to receive data from us 662 * ireason == 0: the drive wants to receive data from us
620 * ireason == 2: the drive is expecting to transfer data to us 663 * ireason == 2: the drive is expecting to transfer data to us
@@ -624,7 +667,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
624 else if (ireason == (rw << 1)) { 667 else if (ireason == (rw << 1)) {
625 668
626 /* whoops... */ 669 /* whoops... */
627 printk(KERN_ERR "%s: %s: wrong transfer direction!\n", 670 printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
628 drive->name, __func__); 671 drive->name, __func__);
629 672
630 ide_pad_transfer(drive, rw, len); 673 ide_pad_transfer(drive, rw, len);
@@ -637,7 +680,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
637 return 0; 680 return 0;
638 } else { 681 } else {
639 /* drive wants a command packet, or invalid ireason... */ 682 /* drive wants a command packet, or invalid ireason... */
640 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", 683 printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
641 drive->name, __func__, ireason); 684 drive->name, __func__, ireason);
642 } 685 }
643 686
@@ -654,17 +697,19 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
654 */ 697 */
655static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) 698static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
656{ 699{
700 ide_debug_log(IDE_DBG_FUNC, "Call %s, len: %d\n", __func__, len);
701
657 if ((len % SECTOR_SIZE) == 0) 702 if ((len % SECTOR_SIZE) == 0)
658 return 0; 703 return 0;
659 704
660 printk(KERN_ERR "%s: %s: Bad transfer size %d\n", 705 printk(KERN_ERR PFX "%s: %s: Bad transfer size %d\n", drive->name,
661 drive->name, __func__, len); 706 __func__, len);
662 707
663 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES) 708 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES)
664 printk(KERN_ERR " This drive is not supported by " 709 printk(KERN_ERR PFX "This drive is not supported by this "
665 "this version of the driver\n"); 710 "version of the driver\n");
666 else { 711 else {
667 printk(KERN_ERR " Trying to limit transfer sizes\n"); 712 printk(KERN_ERR PFX "Trying to limit transfer sizes\n");
668 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES; 713 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES;
669 } 714 }
670 715
@@ -676,6 +721,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
676static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, 721static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
677 struct request *rq) 722 struct request *rq)
678{ 723{
724 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd_flags: 0x%x\n", __func__,
725 rq->cmd_flags);
726
679 if (rq_data_dir(rq) == READ) { 727 if (rq_data_dir(rq) == READ) {
680 unsigned short sectors_per_frame = 728 unsigned short sectors_per_frame =
681 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 729 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
@@ -695,7 +743,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
695 /* sanity check... */ 743 /* sanity check... */
696 if (rq->current_nr_sectors != 744 if (rq->current_nr_sectors !=
697 bio_cur_sectors(rq->bio)) { 745 bio_cur_sectors(rq->bio)) {
698 printk(KERN_ERR "%s: %s: buffer botch (%u)\n", 746 printk(KERN_ERR PFX "%s: %s: buffer botch (%u)\n",
699 drive->name, __func__, 747 drive->name, __func__,
700 rq->current_nr_sectors); 748 rq->current_nr_sectors);
701 cdrom_end_request(drive, 0); 749 cdrom_end_request(drive, 0);
@@ -704,11 +752,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
704 rq->current_nr_sectors += nskip; 752 rq->current_nr_sectors += nskip;
705 } 753 }
706 } 754 }
707#if 0 755
708 else
709 /* the immediate bit */
710 rq->cmd[1] = 1 << 3;
711#endif
712 /* set up the command */ 756 /* set up the command */
713 rq->timeout = ATAPI_WAIT_PC; 757 rq->timeout = ATAPI_WAIT_PC;
714 758
@@ -739,6 +783,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
739 int stat; 783 int stat;
740 static int retry = 10; 784 static int retry = 10;
741 785
786 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
787
742 if (cdrom_decode_status(drive, 0, &stat)) 788 if (cdrom_decode_status(drive, 0, &stat))
743 return ide_stopped; 789 return ide_stopped;
744 790
@@ -746,7 +792,7 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
746 792
747 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { 793 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) {
748 if (--retry == 0) 794 if (--retry == 0)
749 drive->dsc_overlap = 0; 795 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
750 } 796 }
751 return ide_stopped; 797 return ide_stopped;
752} 798}
@@ -755,6 +801,8 @@ static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq)
755{ 801{
756 sector_t frame = rq->sector; 802 sector_t frame = rq->sector;
757 803
804 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
805
758 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); 806 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
759 807
760 memset(rq->cmd, 0, BLK_MAX_CDB); 808 memset(rq->cmd, 0, BLK_MAX_CDB);
@@ -775,8 +823,11 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
775 * Fix up a possibly partially-processed request so that we can start it over 823 * Fix up a possibly partially-processed request so that we can start it over
776 * entirely, or even put it back on the request queue. 824 * entirely, or even put it back on the request queue.
777 */ 825 */
778static void restore_request(struct request *rq) 826static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
779{ 827{
828
829 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
830
780 if (rq->buffer != bio_data(rq->bio)) { 831 if (rq->buffer != bio_data(rq->bio)) {
781 sector_t n = 832 sector_t n =
782 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE; 833 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE;
@@ -792,11 +843,11 @@ static void restore_request(struct request *rq)
792 rq->q->prep_rq_fn(rq->q, rq); 843 rq->q->prep_rq_fn(rq->q, rq);
793} 844}
794 845
795/* 846static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
796 * All other packet commands.
797 */
798static void ide_cd_request_sense_fixup(struct request *rq)
799{ 847{
848 ide_debug_log(IDE_DBG_FUNC, "Call %s, rq->cmd[0]: 0x%x\n",
849 __func__, rq->cmd[0]);
850
800 /* 851 /*
801 * Some of the trailing request sense fields are optional, 852 * Some of the trailing request sense fields are optional,
802 * and some drives don't send them. Sigh. 853 * and some drives don't send them. Sigh.
@@ -822,6 +873,10 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
822 if (!sense) 873 if (!sense)
823 sense = &local_sense; 874 sense = &local_sense;
824 875
876 ide_debug_log(IDE_DBG_PC, "Call %s, cmd[0]: 0x%x, write: 0x%x, "
877 "timeout: %d, cmd_flags: 0x%x\n", __func__, cmd[0], write,
878 timeout, cmd_flags);
879
825 /* start of retry loop */ 880 /* start of retry loop */
826 do { 881 do {
827 struct request *rq; 882 struct request *rq;
@@ -895,7 +950,6 @@ static int cdrom_newpc_intr_dummy_cb(struct request *rq)
895static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 950static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
896{ 951{
897 ide_hwif_t *hwif = drive->hwif; 952 ide_hwif_t *hwif = drive->hwif;
898 struct cdrom_info *info = drive->driver_data;
899 struct request *rq = HWGROUP(drive)->rq; 953 struct request *rq = HWGROUP(drive)->rq;
900 xfer_func_t *xferfunc; 954 xfer_func_t *xferfunc;
901 ide_expiry_t *expiry = NULL; 955 ide_expiry_t *expiry = NULL;
@@ -905,13 +959,16 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
905 u16 len; 959 u16 len;
906 u8 ireason; 960 u8 ireason;
907 961
962 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x\n",
963 __func__, rq->cmd[0], write);
964
908 /* check for errors */ 965 /* check for errors */
909 dma = info->dma; 966 dma = drive->dma;
910 if (dma) { 967 if (dma) {
911 info->dma = 0; 968 drive->dma = 0;
912 dma_error = hwif->dma_ops->dma_end(drive); 969 dma_error = hwif->dma_ops->dma_end(drive);
913 if (dma_error) { 970 if (dma_error) {
914 printk(KERN_ERR "%s: DMA %s error\n", drive->name, 971 printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name,
915 write ? "write" : "read"); 972 write ? "write" : "read");
916 ide_dma_off(drive); 973 ide_dma_off(drive);
917 } 974 }
@@ -937,8 +994,11 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
937 if (thislen > len) 994 if (thislen > len)
938 thislen = len; 995 thislen = len;
939 996
997 ide_debug_log(IDE_DBG_PC, "%s: DRQ: stat: 0x%x, thislen: %d\n",
998 __func__, stat, thislen);
999
940 /* If DRQ is clear, the command has completed. */ 1000 /* If DRQ is clear, the command has completed. */
941 if ((stat & DRQ_STAT) == 0) { 1001 if ((stat & ATA_DRQ) == 0) {
942 if (blk_fs_request(rq)) { 1002 if (blk_fs_request(rq)) {
943 /* 1003 /*
944 * If we're not done reading/writing, complain. 1004 * If we're not done reading/writing, complain.
@@ -946,7 +1006,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
946 */ 1006 */
947 uptodate = 1; 1007 uptodate = 1;
948 if (rq->current_nr_sectors > 0) { 1008 if (rq->current_nr_sectors > 0) {
949 printk(KERN_ERR "%s: %s: data underrun " 1009 printk(KERN_ERR PFX "%s: %s: data underrun "
950 "(%d blocks)\n", 1010 "(%d blocks)\n",
951 drive->name, __func__, 1011 drive->name, __func__,
952 rq->current_nr_sectors); 1012 rq->current_nr_sectors);
@@ -957,7 +1017,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
957 cdrom_end_request(drive, uptodate); 1017 cdrom_end_request(drive, uptodate);
958 return ide_stopped; 1018 return ide_stopped;
959 } else if (!blk_pc_request(rq)) { 1019 } else if (!blk_pc_request(rq)) {
960 ide_cd_request_sense_fixup(rq); 1020 ide_cd_request_sense_fixup(drive, rq);
961 /* complain if we still have data left to transfer */ 1021 /* complain if we still have data left to transfer */
962 uptodate = rq->data_len ? 0 : 1; 1022 uptodate = rq->data_len ? 0 : 1;
963 } 1023 }
@@ -1000,6 +1060,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1000 xferfunc = hwif->tp_ops->input_data; 1060 xferfunc = hwif->tp_ops->input_data;
1001 } 1061 }
1002 1062
1063 ide_debug_log(IDE_DBG_PC, "%s: data transfer, rq->cmd_type: 0x%x, "
1064 "ireason: 0x%x\n", __func__, rq->cmd_type, ireason);
1065
1003 /* transfer data */ 1066 /* transfer data */
1004 while (thislen > 0) { 1067 while (thislen > 0) {
1005 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; 1068 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data;
@@ -1024,7 +1087,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1024 */ 1087 */
1025 ide_pad_transfer(drive, 0, thislen); 1088 ide_pad_transfer(drive, 0, thislen);
1026 else { 1089 else {
1027 printk(KERN_ERR "%s: confused, missing data\n", 1090 printk(KERN_ERR PFX "%s: confused, missing data\n",
1028 drive->name); 1091 drive->name);
1029 blk_dump_rq_flags(rq, rq_data_dir(rq) 1092 blk_dump_rq_flags(rq, rq_data_dir(rq)
1030 ? "cdrom_newpc_intr, write" 1093 ? "cdrom_newpc_intr, write"
@@ -1111,9 +1174,13 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1111 unsigned short sectors_per_frame = 1174 unsigned short sectors_per_frame =
1112 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 1175 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
1113 1176
1177 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x, "
1178 "secs_per_frame: %u\n",
1179 __func__, rq->cmd[0], write, sectors_per_frame);
1180
1114 if (write) { 1181 if (write) {
1115 /* disk has become write protected */ 1182 /* disk has become write protected */
1116 if (cd->disk->policy) { 1183 if (get_disk_ro(cd->disk)) {
1117 cdrom_end_request(drive, 0); 1184 cdrom_end_request(drive, 0);
1118 return ide_stopped; 1185 return ide_stopped;
1119 } 1186 }
@@ -1122,7 +1189,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1122 * We may be retrying this request after an error. Fix up any 1189 * We may be retrying this request after an error. Fix up any
1123 * weirdness which might be present in the request packet. 1190 * weirdness which might be present in the request packet.
1124 */ 1191 */
1125 restore_request(rq); 1192 ide_cd_restore_request(drive, rq);
1126 } 1193 }
1127 1194
1128 /* use DMA, if possible / writes *must* be hardware frame aligned */ 1195 /* use DMA, if possible / writes *must* be hardware frame aligned */
@@ -1132,9 +1199,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1132 cdrom_end_request(drive, 0); 1199 cdrom_end_request(drive, 0);
1133 return ide_stopped; 1200 return ide_stopped;
1134 } 1201 }
1135 cd->dma = 0; 1202 drive->dma = 0;
1136 } else 1203 } else
1137 cd->dma = drive->using_dma; 1204 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1138 1205
1139 if (write) 1206 if (write)
1140 cd->devinfo.media_written = 1; 1207 cd->devinfo.media_written = 1;
@@ -1151,28 +1218,30 @@ static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
1151 1218
1152static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) 1219static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1153{ 1220{
1154 struct cdrom_info *info = drive->driver_data; 1221
1222 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, "
1223 "rq->cmd_type: 0x%x\n", __func__, rq->cmd[0],
1224 rq->cmd_type);
1155 1225
1156 if (blk_pc_request(rq)) 1226 if (blk_pc_request(rq))
1157 rq->cmd_flags |= REQ_QUIET; 1227 rq->cmd_flags |= REQ_QUIET;
1158 else 1228 else
1159 rq->cmd_flags &= ~REQ_FAILED; 1229 rq->cmd_flags &= ~REQ_FAILED;
1160 1230
1161 info->dma = 0; 1231 drive->dma = 0;
1162 1232
1163 /* sg request */ 1233 /* sg request */
1164 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { 1234 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) {
1165 struct request_queue *q = drive->queue; 1235 struct request_queue *q = drive->queue;
1166 unsigned int alignment; 1236 unsigned int alignment;
1167 unsigned long addr; 1237 char *buf;
1168 unsigned long stack_mask = ~(THREAD_SIZE - 1);
1169 1238
1170 if (rq->bio) 1239 if (rq->bio)
1171 addr = (unsigned long)bio_data(rq->bio); 1240 buf = bio_data(rq->bio);
1172 else 1241 else
1173 addr = (unsigned long)rq->data; 1242 buf = rq->data;
1174 1243
1175 info->dma = drive->using_dma; 1244 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1176 1245
1177 /* 1246 /*
1178 * check if dma is safe 1247 * check if dma is safe
@@ -1181,18 +1250,13 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1181 * separate masks. 1250 * separate masks.
1182 */ 1251 */
1183 alignment = queue_dma_alignment(q) | q->dma_pad_mask; 1252 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1184 if (addr & alignment || rq->data_len & alignment) 1253 if ((unsigned long)buf & alignment
1185 info->dma = 0; 1254 || rq->data_len & q->dma_pad_mask
1186 1255 || object_is_on_stack(buf))
1187 if (!((addr & stack_mask) ^ 1256 drive->dma = 0;
1188 ((unsigned long)current->stack & stack_mask)))
1189 info->dma = 0;
1190 } 1257 }
1191} 1258}
1192 1259
1193/*
1194 * cdrom driver request routine.
1195 */
1196static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq, 1260static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1197 sector_t block) 1261 sector_t block)
1198{ 1262{
@@ -1200,19 +1264,24 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1200 ide_handler_t *fn; 1264 ide_handler_t *fn;
1201 int xferlen; 1265 int xferlen;
1202 1266
1267 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd[0]: 0x%x, "
1268 "rq->cmd_type: 0x%x, block: %llu\n",
1269 __func__, rq->cmd[0], rq->cmd_type,
1270 (unsigned long long)block);
1271
1203 if (blk_fs_request(rq)) { 1272 if (blk_fs_request(rq)) {
1204 if (drive->atapi_flags & IDE_AFLAG_SEEKING) { 1273 if (drive->atapi_flags & IDE_AFLAG_SEEKING) {
1205 ide_hwif_t *hwif = drive->hwif; 1274 ide_hwif_t *hwif = drive->hwif;
1206 unsigned long elapsed = jiffies - info->start_seek; 1275 unsigned long elapsed = jiffies - info->start_seek;
1207 int stat = hwif->tp_ops->read_status(hwif); 1276 int stat = hwif->tp_ops->read_status(hwif);
1208 1277
1209 if ((stat & SEEK_STAT) != SEEK_STAT) { 1278 if ((stat & ATA_DSC) != ATA_DSC) {
1210 if (elapsed < IDECD_SEEK_TIMEOUT) { 1279 if (elapsed < IDECD_SEEK_TIMEOUT) {
1211 ide_stall_queue(drive, 1280 ide_stall_queue(drive,
1212 IDECD_SEEK_TIMER); 1281 IDECD_SEEK_TIMER);
1213 return ide_stopped; 1282 return ide_stopped;
1214 } 1283 }
1215 printk(KERN_ERR "%s: DSC timeout\n", 1284 printk(KERN_ERR PFX "%s: DSC timeout\n",
1216 drive->name); 1285 drive->name);
1217 } 1286 }
1218 drive->atapi_flags &= ~IDE_AFLAG_SEEKING; 1287 drive->atapi_flags &= ~IDE_AFLAG_SEEKING;
@@ -1220,11 +1289,11 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1220 if (rq_data_dir(rq) == READ && 1289 if (rq_data_dir(rq) == READ &&
1221 IDE_LARGE_SEEK(info->last_block, block, 1290 IDE_LARGE_SEEK(info->last_block, block,
1222 IDECD_SEEK_THRESHOLD) && 1291 IDECD_SEEK_THRESHOLD) &&
1223 drive->dsc_overlap) { 1292 (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)) {
1224 xferlen = 0; 1293 xferlen = 0;
1225 fn = cdrom_start_seek_continuation; 1294 fn = cdrom_start_seek_continuation;
1226 1295
1227 info->dma = 0; 1296 drive->dma = 0;
1228 info->start_seek = jiffies; 1297 info->start_seek = jiffies;
1229 1298
1230 ide_cd_prepare_seek_request(drive, rq); 1299 ide_cd_prepare_seek_request(drive, rq);
@@ -1253,7 +1322,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1253 cdrom_end_request(drive, 1); 1322 cdrom_end_request(drive, 1);
1254 return ide_stopped; 1323 return ide_stopped;
1255 } else { 1324 } else {
1256 blk_dump_rq_flags(rq, "ide-cd bad flags"); 1325 blk_dump_rq_flags(rq, DRV_NAME " bad flags");
1257 cdrom_end_request(drive, 0); 1326 cdrom_end_request(drive, 0);
1258 return ide_stopped; 1327 return ide_stopped;
1259 } 1328 }
@@ -1283,6 +1352,8 @@ int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
1283 struct cdrom_device_info *cdi = &info->devinfo; 1352 struct cdrom_device_info *cdi = &info->devinfo;
1284 unsigned char cmd[BLK_MAX_CDB]; 1353 unsigned char cmd[BLK_MAX_CDB];
1285 1354
1355 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1356
1286 memset(cmd, 0, BLK_MAX_CDB); 1357 memset(cmd, 0, BLK_MAX_CDB);
1287 cmd[0] = GPCMD_TEST_UNIT_READY; 1358 cmd[0] = GPCMD_TEST_UNIT_READY;
1288 1359
@@ -1309,6 +1380,8 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1309 unsigned len = sizeof(capbuf); 1380 unsigned len = sizeof(capbuf);
1310 u32 blocklen; 1381 u32 blocklen;
1311 1382
1383 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1384
1312 memset(cmd, 0, BLK_MAX_CDB); 1385 memset(cmd, 0, BLK_MAX_CDB);
1313 cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1386 cmd[0] = GPCMD_READ_CDVD_CAPACITY;
1314 1387
@@ -1328,16 +1401,20 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1328 case 4096: 1401 case 4096:
1329 break; 1402 break;
1330 default: 1403 default:
1331 printk(KERN_ERR "%s: weird block size %u\n", 1404 printk(KERN_ERR PFX "%s: weird block size %u\n",
1332 drive->name, blocklen); 1405 drive->name, blocklen);
1333 printk(KERN_ERR "%s: default to 2kb block size\n", 1406 printk(KERN_ERR PFX "%s: default to 2kb block size\n",
1334 drive->name); 1407 drive->name);
1335 blocklen = 2048; 1408 blocklen = 2048;
1336 break; 1409 break;
1337 } 1410 }
1338 1411
1339 *capacity = 1 + be32_to_cpu(capbuf.lba); 1412 *capacity = 1 + be32_to_cpu(capbuf.lba);
1340 *sectors_per_frame = blocklen >> SECTOR_BITS; 1413 *sectors_per_frame = blocklen >> SECTOR_BITS;
1414
1415 ide_debug_log(IDE_DBG_PROBE, "%s: cap: %lu, sectors_per_frame: %lu\n",
1416 __func__, *capacity, *sectors_per_frame);
1417
1341 return 0; 1418 return 0;
1342} 1419}
1343 1420
@@ -1347,6 +1424,8 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
1347{ 1424{
1348 unsigned char cmd[BLK_MAX_CDB]; 1425 unsigned char cmd[BLK_MAX_CDB];
1349 1426
1427 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1428
1350 memset(cmd, 0, BLK_MAX_CDB); 1429 memset(cmd, 0, BLK_MAX_CDB);
1351 1430
1352 cmd[0] = GPCMD_READ_TOC_PMA_ATIP; 1431 cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
@@ -1375,11 +1454,13 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1375 long last_written; 1454 long last_written;
1376 unsigned long sectors_per_frame = SECTORS_PER_FRAME; 1455 unsigned long sectors_per_frame = SECTORS_PER_FRAME;
1377 1456
1457 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1458
1378 if (toc == NULL) { 1459 if (toc == NULL) {
1379 /* try to allocate space */ 1460 /* try to allocate space */
1380 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); 1461 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
1381 if (toc == NULL) { 1462 if (toc == NULL) {
1382 printk(KERN_ERR "%s: No cdrom TOC buffer!\n", 1463 printk(KERN_ERR PFX "%s: No cdrom TOC buffer!\n",
1383 drive->name); 1464 drive->name);
1384 return -ENOMEM; 1465 return -ENOMEM;
1385 } 1466 }
@@ -1535,6 +1616,8 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
1535 struct packet_command cgc; 1616 struct packet_command cgc;
1536 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE; 1617 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
1537 1618
1619 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1620
1538 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) 1621 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0)
1539 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; 1622 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
1540 1623
@@ -1553,6 +1636,8 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1553 struct cdrom_info *cd = drive->driver_data; 1636 struct cdrom_info *cd = drive->driver_data;
1554 u16 curspeed, maxspeed; 1637 u16 curspeed, maxspeed;
1555 1638
1639 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1640
1556 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { 1641 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) {
1557 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]); 1642 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]);
1558 maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]); 1643 maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]);
@@ -1561,6 +1646,9 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1561 maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]); 1646 maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]);
1562 } 1647 }
1563 1648
1649 ide_debug_log(IDE_DBG_PROBE, "%s: curspeed: %u, maxspeed: %u\n",
1650 __func__, curspeed, maxspeed);
1651
1564 cd->current_speed = (curspeed + (176/2)) / 176; 1652 cd->current_speed = (curspeed + (176/2)) / 176;
1565 cd->max_speed = (maxspeed + (176/2)) / 176; 1653 cd->max_speed = (maxspeed + (176/2)) / 176;
1566} 1654}
@@ -1593,6 +1681,8 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
1593 struct cdrom_info *info = drive->driver_data; 1681 struct cdrom_info *info = drive->driver_data;
1594 struct cdrom_device_info *devinfo = &info->devinfo; 1682 struct cdrom_device_info *devinfo = &info->devinfo;
1595 1683
1684 ide_debug_log(IDE_DBG_PROBE, "Call %s, nslots: %d\n", __func__, nslots);
1685
1596 devinfo->ops = &ide_cdrom_dops; 1686 devinfo->ops = &ide_cdrom_dops;
1597 devinfo->speed = info->current_speed; 1687 devinfo->speed = info->current_speed;
1598 devinfo->capacity = nslots; 1688 devinfo->capacity = nslots;
@@ -1614,13 +1704,17 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1614 mechtype_t mechtype; 1704 mechtype_t mechtype;
1615 int nslots = 1; 1705 int nslots = 1;
1616 1706
1707 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->media: 0x%x, "
1708 "drive->atapi_flags: 0x%lx\n", __func__, drive->media,
1709 drive->atapi_flags);
1710
1617 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | 1711 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
1618 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO | 1712 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
1619 CDC_MO_DRIVE | CDC_RAM); 1713 CDC_MO_DRIVE | CDC_RAM);
1620 1714
1621 if (drive->media == ide_optical) { 1715 if (drive->media == ide_optical) {
1622 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); 1716 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
1623 printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", 1717 printk(KERN_ERR PFX "%s: ATAPI magneto-optical drive\n",
1624 drive->name); 1718 drive->name);
1625 return nslots; 1719 return nslots;
1626 } 1720 }
@@ -1644,7 +1738,7 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1644 return 0; 1738 return 0;
1645 1739
1646 if ((buf[8 + 6] & 0x01) == 0) 1740 if ((buf[8 + 6] & 0x01) == 0)
1647 drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK; 1741 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
1648 if (buf[8 + 6] & 0x08) 1742 if (buf[8 + 6] & 0x08)
1649 drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; 1743 drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT;
1650 if (buf[8 + 3] & 0x01) 1744 if (buf[8 + 3] & 0x01)
@@ -1678,7 +1772,7 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1678 1772
1679 ide_cdrom_update_speed(drive, buf); 1773 ide_cdrom_update_speed(drive, buf);
1680 1774
1681 printk(KERN_INFO "%s: ATAPI", drive->name); 1775 printk(KERN_INFO PFX "%s: ATAPI", drive->name);
1682 1776
1683 /* don't print speed if the drive reported 0 */ 1777 /* don't print speed if the drive reported 0 */
1684 if (cd->max_speed) 1778 if (cd->max_speed)
@@ -1689,7 +1783,7 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1689 if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0) 1783 if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0)
1690 printk(KERN_CONT " DVD%s%s", 1784 printk(KERN_CONT " DVD%s%s",
1691 (cdi->mask & CDC_DVD_R) ? "" : "-R", 1785 (cdi->mask & CDC_DVD_R) ? "" : "-R",
1692 (cdi->mask & CDC_DVD_RAM) ? "" : "-RAM"); 1786 (cdi->mask & CDC_DVD_RAM) ? "" : "/RAM");
1693 1787
1694 if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0) 1788 if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0)
1695 printk(KERN_CONT " CD%s%s", 1789 printk(KERN_CONT " CD%s%s",
@@ -1701,7 +1795,8 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1701 else 1795 else
1702 printk(KERN_CONT " drive"); 1796 printk(KERN_CONT " drive");
1703 1797
1704 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpup((__be16 *)&buf[8 + 12])); 1798 printk(KERN_CONT ", %dkB Cache\n",
1799 be16_to_cpup((__be16 *)&buf[8 + 12]));
1705 1800
1706 return nslots; 1801 return nslots;
1707} 1802}
@@ -1813,13 +1908,22 @@ static ide_proc_entry_t idecd_proc[] = {
1813 { NULL, 0, NULL, NULL } 1908 { NULL, 0, NULL, NULL }
1814}; 1909};
1815 1910
1816static void ide_cdrom_add_settings(ide_drive_t *drive) 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)
1817{ 1919{
1818 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, 1920 return idecd_proc;
1819 &drive->dsc_overlap, NULL); 1921}
1922
1923static const struct ide_proc_devset *ide_cd_proc_devsets(ide_drive_t *drive)
1924{
1925 return idecd_settings;
1820} 1926}
1821#else
1822static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; }
1823#endif 1927#endif
1824 1928
1825static const struct cd_list_entry ide_cd_quirks_list[] = { 1929static const struct cd_list_entry ide_cd_quirks_list[] = {
@@ -1863,17 +1967,18 @@ static const struct cd_list_entry ide_cd_quirks_list[] = {
1863 { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, 1967 { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1864 { "Optiarc DVD RW AD-7200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, 1968 { "Optiarc DVD RW AD-7200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1865 { "Optiarc DVD RW AD-7543A", NULL, IDE_AFLAG_NO_AUTOCLOSE }, 1969 { "Optiarc DVD RW AD-7543A", NULL, IDE_AFLAG_NO_AUTOCLOSE },
1970 { "TEAC CD-ROM CD-224E", NULL, IDE_AFLAG_NO_AUTOCLOSE },
1866 { NULL, NULL, 0 } 1971 { NULL, NULL, 0 }
1867}; 1972};
1868 1973
1869static unsigned int ide_cd_flags(struct hd_driveid *id) 1974static unsigned int ide_cd_flags(u16 *id)
1870{ 1975{
1871 const struct cd_list_entry *cle = ide_cd_quirks_list; 1976 const struct cd_list_entry *cle = ide_cd_quirks_list;
1872 1977
1873 while (cle->id_model) { 1978 while (cle->id_model) {
1874 if (strcmp(cle->id_model, id->model) == 0 && 1979 if (strcmp(cle->id_model, (char *)&id[ATA_ID_PROD]) == 0 &&
1875 (cle->id_firmware == NULL || 1980 (cle->id_firmware == NULL ||
1876 strstr(id->fw_rev, cle->id_firmware))) 1981 strstr((char *)&id[ATA_ID_FW_REV], cle->id_firmware)))
1877 return cle->cd_flags; 1982 return cle->cd_flags;
1878 cle++; 1983 cle++;
1879 } 1984 }
@@ -1885,9 +1990,12 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1885{ 1990{
1886 struct cdrom_info *cd = drive->driver_data; 1991 struct cdrom_info *cd = drive->driver_data;
1887 struct cdrom_device_info *cdi = &cd->devinfo; 1992 struct cdrom_device_info *cdi = &cd->devinfo;
1888 struct hd_driveid *id = drive->id; 1993 u16 *id = drive->id;
1994 char *fw_rev = (char *)&id[ATA_ID_FW_REV];
1889 int nslots; 1995 int nslots;
1890 1996
1997 ide_debug_log(IDE_DBG_PROBE, "Call %s\n", __func__);
1998
1891 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1999 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
1892 blk_queue_dma_alignment(drive->queue, 31); 2000 blk_queue_dma_alignment(drive->queue, 31);
1893 blk_queue_update_dma_pad(drive->queue, 15); 2001 blk_queue_update_dma_pad(drive->queue, 15);
@@ -1895,20 +2003,15 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1895 if (!drive->queue->unplug_delay) 2003 if (!drive->queue->unplug_delay)
1896 drive->queue->unplug_delay = 1; 2004 drive->queue->unplug_delay = 1;
1897 2005
1898 drive->special.all = 0; 2006 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
1899 2007 drive->atapi_flags = IDE_AFLAG_NO_EJECT | ide_cd_flags(id);
1900 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
1901 ide_cd_flags(id);
1902
1903 if ((id->config & 0x0060) == 0x20)
1904 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
1905 2008
1906 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && 2009 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
1907 id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') 2010 fw_rev[4] == '1' && fw_rev[6] <= '2')
1908 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | 2011 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
1909 IDE_AFLAG_TOCADDR_AS_BCD); 2012 IDE_AFLAG_TOCADDR_AS_BCD);
1910 else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) && 2013 else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) &&
1911 id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') 2014 fw_rev[4] == '1' && fw_rev[6] <= '2')
1912 drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD; 2015 drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD;
1913 else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD) 2016 else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD)
1914 /* 3 => use CD in slot 0 */ 2017 /* 3 => use CD in slot 0 */
@@ -1919,15 +2022,19 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1919 /* set correct block size */ 2022 /* set correct block size */
1920 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); 2023 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
1921 2024
1922 drive->dsc_overlap = (drive->next != drive); 2025 if (drive->next != drive)
2026 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2027 else
2028 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1923 2029
1924 if (ide_cdrom_register(drive, nslots)) { 2030 if (ide_cdrom_register(drive, nslots)) {
1925 printk(KERN_ERR "%s: %s failed to register device with the" 2031 printk(KERN_ERR PFX "%s: %s failed to register device with the"
1926 " cdrom driver.\n", drive->name, __func__); 2032 " cdrom driver.\n", drive->name, __func__);
1927 cd->devinfo.handle = NULL; 2033 cd->devinfo.handle = NULL;
1928 return 1; 2034 return 1;
1929 } 2035 }
1930 ide_cdrom_add_settings(drive); 2036
2037 ide_proc_register_driver(drive, cd->driver);
1931 return 0; 2038 return 0;
1932} 2039}
1933 2040
@@ -1935,6 +2042,8 @@ static void ide_cd_remove(ide_drive_t *drive)
1935{ 2042{
1936 struct cdrom_info *info = drive->driver_data; 2043 struct cdrom_info *info = drive->driver_data;
1937 2044
2045 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
2046
1938 ide_proc_unregister_driver(drive, info->driver); 2047 ide_proc_unregister_driver(drive, info->driver);
1939 2048
1940 del_gendisk(info->disk); 2049 del_gendisk(info->disk);
@@ -1944,15 +2053,17 @@ static void ide_cd_remove(ide_drive_t *drive)
1944 2053
1945static void ide_cd_release(struct kref *kref) 2054static void ide_cd_release(struct kref *kref)
1946{ 2055{
1947 struct cdrom_info *info = to_ide_cd(kref); 2056 struct cdrom_info *info = to_ide_drv(kref, cdrom_info);
1948 struct cdrom_device_info *devinfo = &info->devinfo; 2057 struct cdrom_device_info *devinfo = &info->devinfo;
1949 ide_drive_t *drive = info->drive; 2058 ide_drive_t *drive = info->drive;
1950 struct gendisk *g = info->disk; 2059 struct gendisk *g = info->disk;
1951 2060
2061 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
2062
1952 kfree(info->toc); 2063 kfree(info->toc);
1953 if (devinfo->handle == drive) 2064 if (devinfo->handle == drive)
1954 unregister_cdrom(devinfo); 2065 unregister_cdrom(devinfo);
1955 drive->dsc_overlap = 0; 2066 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1956 drive->driver_data = NULL; 2067 drive->driver_data = NULL;
1957 blk_queue_prep_rq(drive->queue, NULL); 2068 blk_queue_prep_rq(drive->queue, NULL);
1958 g->private_data = NULL; 2069 g->private_data = NULL;
@@ -1971,27 +2082,24 @@ static ide_driver_t ide_cdrom_driver = {
1971 .probe = ide_cd_probe, 2082 .probe = ide_cd_probe,
1972 .remove = ide_cd_remove, 2083 .remove = ide_cd_remove,
1973 .version = IDECD_VERSION, 2084 .version = IDECD_VERSION,
1974 .media = ide_cdrom,
1975 .supports_dsc_overlap = 1,
1976 .do_request = ide_cd_do_request, 2085 .do_request = ide_cd_do_request,
1977 .end_request = ide_end_request, 2086 .end_request = ide_end_request,
1978 .error = __ide_error, 2087 .error = __ide_error,
1979#ifdef CONFIG_IDE_PROC_FS 2088#ifdef CONFIG_IDE_PROC_FS
1980 .proc = idecd_proc, 2089 .proc_entries = ide_cd_proc_entries,
2090 .proc_devsets = ide_cd_proc_devsets,
1981#endif 2091#endif
1982}; 2092};
1983 2093
1984static int idecd_open(struct inode *inode, struct file *file) 2094static int idecd_open(struct block_device *bdev, fmode_t mode)
1985{ 2095{
1986 struct gendisk *disk = inode->i_bdev->bd_disk; 2096 struct cdrom_info *info = ide_cd_get(bdev->bd_disk);
1987 struct cdrom_info *info;
1988 int rc = -ENOMEM; 2097 int rc = -ENOMEM;
1989 2098
1990 info = ide_cd_get(disk);
1991 if (!info) 2099 if (!info)
1992 return -ENXIO; 2100 return -ENXIO;
1993 2101
1994 rc = cdrom_open(&info->devinfo, inode, file); 2102 rc = cdrom_open(&info->devinfo, bdev, mode);
1995 2103
1996 if (rc < 0) 2104 if (rc < 0)
1997 ide_cd_put(info); 2105 ide_cd_put(info);
@@ -1999,12 +2107,11 @@ static int idecd_open(struct inode *inode, struct file *file)
1999 return rc; 2107 return rc;
2000} 2108}
2001 2109
2002static int idecd_release(struct inode *inode, struct file *file) 2110static int idecd_release(struct gendisk *disk, fmode_t mode)
2003{ 2111{
2004 struct gendisk *disk = inode->i_bdev->bd_disk; 2112 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2005 struct cdrom_info *info = ide_cd_g(disk);
2006 2113
2007 cdrom_release(&info->devinfo, file); 2114 cdrom_release(&info->devinfo, mode);
2008 2115
2009 ide_cd_put(info); 2116 ide_cd_put(info);
2010 2117
@@ -2050,11 +2157,10 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
2050 return 0; 2157 return 0;
2051} 2158}
2052 2159
2053static int idecd_ioctl(struct inode *inode, struct file *file, 2160static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
2054 unsigned int cmd, unsigned long arg) 2161 unsigned int cmd, unsigned long arg)
2055{ 2162{
2056 struct block_device *bdev = inode->i_bdev; 2163 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
2057 struct cdrom_info *info = ide_cd_g(bdev->bd_disk);
2058 int err; 2164 int err;
2059 2165
2060 switch (cmd) { 2166 switch (cmd) {
@@ -2066,22 +2172,22 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
2066 break; 2172 break;
2067 } 2173 }
2068 2174
2069 err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); 2175 err = generic_ide_ioctl(info->drive, bdev, cmd, arg);
2070 if (err == -EINVAL) 2176 if (err == -EINVAL)
2071 err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg); 2177 err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, arg);
2072 2178
2073 return err; 2179 return err;
2074} 2180}
2075 2181
2076static int idecd_media_changed(struct gendisk *disk) 2182static int idecd_media_changed(struct gendisk *disk)
2077{ 2183{
2078 struct cdrom_info *info = ide_cd_g(disk); 2184 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2079 return cdrom_media_changed(&info->devinfo); 2185 return cdrom_media_changed(&info->devinfo);
2080} 2186}
2081 2187
2082static int idecd_revalidate_disk(struct gendisk *disk) 2188static int idecd_revalidate_disk(struct gendisk *disk)
2083{ 2189{
2084 struct cdrom_info *info = ide_cd_g(disk); 2190 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2085 struct request_sense sense; 2191 struct request_sense sense;
2086 2192
2087 ide_cd_read_toc(info->drive, &sense); 2193 ide_cd_read_toc(info->drive, &sense);
@@ -2093,15 +2199,18 @@ static struct block_device_operations idecd_ops = {
2093 .owner = THIS_MODULE, 2199 .owner = THIS_MODULE,
2094 .open = idecd_open, 2200 .open = idecd_open,
2095 .release = idecd_release, 2201 .release = idecd_release,
2096 .ioctl = idecd_ioctl, 2202 .locked_ioctl = idecd_ioctl,
2097 .media_changed = idecd_media_changed, 2203 .media_changed = idecd_media_changed,
2098 .revalidate_disk = idecd_revalidate_disk 2204 .revalidate_disk = idecd_revalidate_disk
2099}; 2205};
2100 2206
2101/* module options */ 2207/* module options */
2102static char *ignore; 2208static char *ignore;
2103
2104module_param(ignore, charp, 0400); 2209module_param(ignore, charp, 0400);
2210
2211static unsigned long debug_mask;
2212module_param(debug_mask, ulong, 0644);
2213
2105MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); 2214MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
2106 2215
2107static int ide_cd_probe(ide_drive_t *drive) 2216static int ide_cd_probe(ide_drive_t *drive)
@@ -2110,23 +2219,30 @@ static int ide_cd_probe(ide_drive_t *drive)
2110 struct gendisk *g; 2219 struct gendisk *g;
2111 struct request_sense sense; 2220 struct request_sense sense;
2112 2221
2222 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->driver_req: %s, "
2223 "drive->media: 0x%x\n", __func__, drive->driver_req,
2224 drive->media);
2225
2113 if (!strstr("ide-cdrom", drive->driver_req)) 2226 if (!strstr("ide-cdrom", drive->driver_req))
2114 goto failed; 2227 goto failed;
2115 if (!drive->present) 2228
2116 goto failed;
2117 if (drive->media != ide_cdrom && drive->media != ide_optical) 2229 if (drive->media != ide_cdrom && drive->media != ide_optical)
2118 goto failed; 2230 goto failed;
2231
2119 /* skip drives that we were told to ignore */ 2232 /* skip drives that we were told to ignore */
2120 if (ignore != NULL) { 2233 if (ignore != NULL) {
2121 if (strstr(ignore, drive->name)) { 2234 if (strstr(ignore, drive->name)) {
2122 printk(KERN_INFO "ide-cd: ignoring drive %s\n", 2235 printk(KERN_INFO PFX "ignoring drive %s\n",
2123 drive->name); 2236 drive->name);
2124 goto failed; 2237 goto failed;
2125 } 2238 }
2126 } 2239 }
2240
2241 drive->debug_mask = debug_mask;
2242
2127 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); 2243 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
2128 if (info == NULL) { 2244 if (info == NULL) {
2129 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", 2245 printk(KERN_ERR PFX "%s: Can't allocate a cdrom structure\n",
2130 drive->name); 2246 drive->name);
2131 goto failed; 2247 goto failed;
2132 } 2248 }
@@ -2137,8 +2253,6 @@ static int ide_cd_probe(ide_drive_t *drive)
2137 2253
2138 ide_init_disk(g, drive); 2254 ide_init_disk(g, drive);
2139 2255
2140 ide_proc_register_driver(drive, &ide_cdrom_driver);
2141
2142 kref_init(&info->kref); 2256 kref_init(&info->kref);
2143 2257
2144 info->drive = drive; 2258 info->drive = drive;
@@ -2153,7 +2267,6 @@ static int ide_cd_probe(ide_drive_t *drive)
2153 g->driverfs_dev = &drive->gendev; 2267 g->driverfs_dev = &drive->gendev;
2154 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; 2268 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE;
2155 if (ide_cdrom_setup(drive)) { 2269 if (ide_cdrom_setup(drive)) {
2156 ide_proc_unregister_driver(drive, &ide_cdrom_driver);
2157 ide_cd_release(&info->kref); 2270 ide_cd_release(&info->kref);
2158 goto failed; 2271 goto failed;
2159 } 2272 }
@@ -2177,6 +2290,7 @@ static void __exit ide_cdrom_exit(void)
2177 2290
2178static int __init ide_cdrom_init(void) 2291static int __init ide_cdrom_init(void)
2179{ 2292{
2293 printk(KERN_INFO DRV_NAME " driver " IDECD_VERSION "\n");
2180 return driver_register(&ide_cdrom_driver.gen_driver); 2294 return driver_register(&ide_cdrom_driver.gen_driver);
2181} 2295}
2182 2296
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 61a4599b77db..5882b9a9ea8b 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -88,7 +88,6 @@ struct cdrom_info {
88 struct request_sense sense_data; 88 struct request_sense sense_data;
89 89
90 struct request request_sense_request; 90 struct request request_sense_request;
91 int dma;
92 unsigned long last_block; 91 unsigned long last_block;
93 unsigned long start_seek; 92 unsigned long start_seek;
94 93
diff --git a/drivers/ide/ide-cd_ioctl.c b/drivers/ide/ide-cd_ioctl.c
index 74231b41f611..df3df0041eb6 100644
--- a/drivers/ide/ide-cd_ioctl.c
+++ b/drivers/ide/ide-cd_ioctl.c
@@ -86,8 +86,8 @@ int ide_cdrom_check_media_change_real(struct cdrom_device_info *cdi,
86 86
87 if (slot_nr == CDSL_CURRENT) { 87 if (slot_nr == CDSL_CURRENT) {
88 (void) cdrom_check_status(drive, NULL); 88 (void) cdrom_check_status(drive, NULL);
89 retval = (drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED) ? 1 : 0; 89 retval = (drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED) ? 1 : 0;
90 drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED; 90 drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
91 return retval; 91 return retval;
92 } else { 92 } else {
93 return -EINVAL; 93 return -EINVAL;
@@ -136,7 +136,7 @@ int ide_cd_lockdoor(ide_drive_t *drive, int lockflag,
136 sense = &my_sense; 136 sense = &my_sense;
137 137
138 /* If the drive cannot lock the door, just pretend. */ 138 /* If the drive cannot lock the door, just pretend. */
139 if (drive->atapi_flags & IDE_AFLAG_NO_DOORLOCK) { 139 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0) {
140 stat = 0; 140 stat = 0;
141 } else { 141 } else {
142 unsigned char cmd[BLK_MAX_CDB]; 142 unsigned char cmd[BLK_MAX_CDB];
@@ -157,7 +157,7 @@ int ide_cd_lockdoor(ide_drive_t *drive, int lockflag,
157 (sense->asc == 0x24 || sense->asc == 0x20)) { 157 (sense->asc == 0x24 || sense->asc == 0x20)) {
158 printk(KERN_ERR "%s: door locking not supported\n", 158 printk(KERN_ERR "%s: door locking not supported\n",
159 drive->name); 159 drive->name);
160 drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK; 160 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
161 stat = 0; 161 stat = 0;
162 } 162 }
163 163
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/ide-cs.c
index 21bfac137844..f50210fe558f 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/ide-cs.c
@@ -38,7 +38,6 @@
38#include <linux/timer.h> 38#include <linux/timer.h>
39#include <linux/ioport.h> 39#include <linux/ioport.h>
40#include <linux/ide.h> 40#include <linux/ide.h>
41#include <linux/hdreg.h>
42#include <linux/major.h> 41#include <linux/major.h>
43#include <linux/delay.h> 42#include <linux/delay.h>
44#include <asm/io.h> 43#include <asm/io.h>
@@ -220,103 +219,91 @@ out_release:
220#define CS_CHECK(fn, ret) \ 219#define CS_CHECK(fn, ret) \
221do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 220do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
222 221
222struct pcmcia_config_check {
223 unsigned long ctl_base;
224 int skip_vcc;
225 int is_kme;
226};
227
228static int pcmcia_check_one_config(struct pcmcia_device *pdev,
229 cistpl_cftable_entry_t *cfg,
230 cistpl_cftable_entry_t *dflt,
231 unsigned int vcc,
232 void *priv_data)
233{
234 struct pcmcia_config_check *stk = priv_data;
235
236 /* Check for matching Vcc, unless we're desperate */
237 if (!stk->skip_vcc) {
238 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
239 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
240 return -ENODEV;
241 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
242 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
243 return -ENODEV;
244 }
245 }
246
247 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
248 pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
249 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
250 pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
251
252 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
253 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
254 pdev->conf.ConfigIndex = cfg->index;
255 pdev->io.BasePort1 = io->win[0].base;
256 pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
257 if (!(io->flags & CISTPL_IO_16BIT))
258 pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
259 if (io->nwin == 2) {
260 pdev->io.NumPorts1 = 8;
261 pdev->io.BasePort2 = io->win[1].base;
262 pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
263 if (pcmcia_request_io(pdev, &pdev->io) != 0)
264 return -ENODEV;
265 stk->ctl_base = pdev->io.BasePort2;
266 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
267 pdev->io.NumPorts1 = io->win[0].len;
268 pdev->io.NumPorts2 = 0;
269 if (pcmcia_request_io(pdev, &pdev->io) != 0)
270 return -ENODEV;
271 stk->ctl_base = pdev->io.BasePort1 + 0x0e;
272 } else
273 return -ENODEV;
274 /* If we've got this far, we're done */
275 return 0;
276 }
277 return -ENODEV;
278}
279
223static int ide_config(struct pcmcia_device *link) 280static int ide_config(struct pcmcia_device *link)
224{ 281{
225 ide_info_t *info = link->priv; 282 ide_info_t *info = link->priv;
226 tuple_t tuple; 283 struct pcmcia_config_check *stk = NULL;
227 struct { 284 int last_ret = 0, last_fn = 0, is_kme = 0;
228 u_short buf[128];
229 cisparse_t parse;
230 config_info_t conf;
231 cistpl_cftable_entry_t dflt;
232 } *stk = NULL;
233 cistpl_cftable_entry_t *cfg;
234 int pass, last_ret = 0, last_fn = 0, is_kme = 0;
235 unsigned long io_base, ctl_base; 285 unsigned long io_base, ctl_base;
236 struct ide_host *host; 286 struct ide_host *host;
237 287
238 DEBUG(0, "ide_config(0x%p)\n", link); 288 DEBUG(0, "ide_config(0x%p)\n", link);
239 289
240 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
241 if (!stk) goto err_mem;
242 cfg = &stk->parse.cftable_entry;
243
244 tuple.TupleData = (cisdata_t *)&stk->buf;
245 tuple.TupleOffset = 0;
246 tuple.TupleDataMax = 255;
247 tuple.Attributes = 0;
248
249 is_kme = ((link->manf_id == MANFID_KME) && 290 is_kme = ((link->manf_id == MANFID_KME) &&
250 ((link->card_id == PRODID_KME_KXLC005_A) || 291 ((link->card_id == PRODID_KME_KXLC005_A) ||
251 (link->card_id == PRODID_KME_KXLC005_B))); 292 (link->card_id == PRODID_KME_KXLC005_B)));
252 293
253 /* Not sure if this is right... look up the current Vcc */ 294 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
254 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf)); 295 if (!stk)
255 296 goto err_mem;
256 pass = io_base = ctl_base = 0; 297 stk->is_kme = is_kme;
257 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 298 stk->skip_vcc = io_base = ctl_base = 0;
258 tuple.Attributes = 0; 299
259 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 300 if (pcmcia_loop_config(link, pcmcia_check_one_config, stk)) {
260 while (1) { 301 stk->skip_vcc = 1;
261 if (pcmcia_get_tuple_data(link, &tuple) != 0) goto next_entry; 302 if (pcmcia_loop_config(link, pcmcia_check_one_config, stk))
262 if (pcmcia_parse_tuple(link, &tuple, &stk->parse) != 0) goto next_entry; 303 goto failed; /* No suitable config found */
263
264 /* Check for matching Vcc, unless we're desperate */
265 if (!pass) {
266 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
267 if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
268 goto next_entry;
269 } else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
270 if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
271 goto next_entry;
272 }
273 }
274
275 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
276 link->conf.Vpp =
277 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
278 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
279 link->conf.Vpp =
280 stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
281
282 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
283 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
284 link->conf.ConfigIndex = cfg->index;
285 link->io.BasePort1 = io->win[0].base;
286 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
287 if (!(io->flags & CISTPL_IO_16BIT))
288 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
289 if (io->nwin == 2) {
290 link->io.NumPorts1 = 8;
291 link->io.BasePort2 = io->win[1].base;
292 link->io.NumPorts2 = (is_kme) ? 2 : 1;
293 if (pcmcia_request_io(link, &link->io) != 0)
294 goto next_entry;
295 io_base = link->io.BasePort1;
296 ctl_base = link->io.BasePort2;
297 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
298 link->io.NumPorts1 = io->win[0].len;
299 link->io.NumPorts2 = 0;
300 if (pcmcia_request_io(link, &link->io) != 0)
301 goto next_entry;
302 io_base = link->io.BasePort1;
303 ctl_base = link->io.BasePort1 + 0x0e;
304 } else goto next_entry;
305 /* If we've got this far, we're done */
306 break;
307 }
308
309 next_entry:
310 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
311 memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
312 if (pass) {
313 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
314 } else if (pcmcia_get_next_tuple(link, &tuple) != 0) {
315 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
316 memset(&stk->dflt, 0, sizeof(stk->dflt));
317 pass++;
318 }
319 } 304 }
305 io_base = link->io.BasePort1;
306 ctl_base = stk->ctl_base;
320 307
321 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 308 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
322 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 309 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
@@ -404,8 +391,10 @@ static struct pcmcia_device_id ide_ids[] = {
404 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */ 391 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
405 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */ 392 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
406 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 393 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
394 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
407 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */ 395 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
408 PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */ 396 PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */
397 PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620), /* TI emulated */
409 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ 398 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
410 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 399 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
411 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */ 400 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
@@ -455,6 +444,7 @@ static struct pcmcia_device_id ide_ids[] = {
455 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209), 444 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
456 PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e), 445 PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e),
457 PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6), 446 PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6),
447 PCMCIA_DEVICE_PROD_ID2("Flash Card", 0x5a362506),
458 PCMCIA_DEVICE_NULL, 448 PCMCIA_DEVICE_NULL,
459}; 449};
460MODULE_DEVICE_TABLE(pcmcia, ide_ids); 450MODULE_DEVICE_TABLE(pcmcia, ide_ids);
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 07ef88bd109b..eb9fac4d0f0c 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -2,7 +2,7 @@
2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) 2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
3 * Copyright (C) 1998-2002 Linux ATA Development 3 * Copyright (C) 1998-2002 Linux ATA Development
4 * Andre Hedrick <andre@linux-ide.org> 4 * Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 5 * Copyright (C) 2003 Red Hat
6 * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz 6 * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
7 */ 7 */
8 8
@@ -14,9 +14,6 @@
14 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c. 14 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
15 */ 15 */
16 16
17#define IDEDISK_VERSION "1.18"
18
19#include <linux/module.h>
20#include <linux/types.h> 17#include <linux/types.h>
21#include <linux/string.h> 18#include <linux/string.h>
22#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -30,10 +27,8 @@
30#include <linux/delay.h> 27#include <linux/delay.h>
31#include <linux/mutex.h> 28#include <linux/mutex.h>
32#include <linux/leds.h> 29#include <linux/leds.h>
33
34#define _IDE_DISK
35
36#include <linux/ide.h> 30#include <linux/ide.h>
31#include <linux/hdreg.h>
37 32
38#include <asm/byteorder.h> 33#include <asm/byteorder.h>
39#include <asm/irq.h> 34#include <asm/irq.h>
@@ -41,111 +36,21 @@
41#include <asm/io.h> 36#include <asm/io.h>
42#include <asm/div64.h> 37#include <asm/div64.h>
43 38
44struct ide_disk_obj { 39#include "ide-disk.h"
45 ide_drive_t *drive;
46 ide_driver_t *driver;
47 struct gendisk *disk;
48 struct kref kref;
49 unsigned int openers; /* protected by BKL for now */
50};
51
52static DEFINE_MUTEX(idedisk_ref_mutex);
53
54#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
55
56#define ide_disk_g(disk) \
57 container_of((disk)->private_data, struct ide_disk_obj, driver)
58
59static void ide_disk_release(struct kref *);
60
61static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
62{
63 struct ide_disk_obj *idkp = NULL;
64
65 mutex_lock(&idedisk_ref_mutex);
66 idkp = ide_disk_g(disk);
67 if (idkp) {
68 if (ide_device_get(idkp->drive))
69 idkp = NULL;
70 else
71 kref_get(&idkp->kref);
72 }
73 mutex_unlock(&idedisk_ref_mutex);
74 return idkp;
75}
76
77static void ide_disk_put(struct ide_disk_obj *idkp)
78{
79 ide_drive_t *drive = idkp->drive;
80
81 mutex_lock(&idedisk_ref_mutex);
82 kref_put(&idkp->kref, ide_disk_release);
83 ide_device_put(drive);
84 mutex_unlock(&idedisk_ref_mutex);
85}
86
87/*
88 * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity"
89 * value for this drive (from its reported identification information).
90 *
91 * Returns: 1 if lba_capacity looks sensible
92 * 0 otherwise
93 *
94 * It is called only once for each drive.
95 */
96static int lba_capacity_is_ok(struct hd_driveid *id)
97{
98 unsigned long lba_sects, chs_sects, head, tail;
99
100 /* No non-LBA info .. so valid! */
101 if (id->cyls == 0)
102 return 1;
103
104 /*
105 * The ATA spec tells large drives to return
106 * C/H/S = 16383/16/63 independent of their size.
107 * Some drives can be jumpered to use 15 heads instead of 16.
108 * Some drives can be jumpered to use 4092 cyls instead of 16383.
109 */
110 if ((id->cyls == 16383
111 || (id->cyls == 4092 && id->cur_cyls == 16383)) &&
112 id->sectors == 63 &&
113 (id->heads == 15 || id->heads == 16) &&
114 (id->lba_capacity >= 16383*63*id->heads))
115 return 1;
116
117 lba_sects = id->lba_capacity;
118 chs_sects = id->cyls * id->heads * id->sectors;
119
120 /* perform a rough sanity check on lba_sects: within 10% is OK */
121 if ((lba_sects - chs_sects) < chs_sects/10)
122 return 1;
123
124 /* some drives have the word order reversed */
125 head = ((lba_sects >> 16) & 0xffff);
126 tail = (lba_sects & 0xffff);
127 lba_sects = (head | (tail << 16));
128 if ((lba_sects - chs_sects) < chs_sects/10) {
129 id->lba_capacity = lba_sects;
130 return 1; /* lba_capacity is (now) good */
131 }
132
133 return 0; /* lba_capacity value may be bad */
134}
135 40
136static const u8 ide_rw_cmds[] = { 41static const u8 ide_rw_cmds[] = {
137 WIN_MULTREAD, 42 ATA_CMD_READ_MULTI,
138 WIN_MULTWRITE, 43 ATA_CMD_WRITE_MULTI,
139 WIN_MULTREAD_EXT, 44 ATA_CMD_READ_MULTI_EXT,
140 WIN_MULTWRITE_EXT, 45 ATA_CMD_WRITE_MULTI_EXT,
141 WIN_READ, 46 ATA_CMD_PIO_READ,
142 WIN_WRITE, 47 ATA_CMD_PIO_WRITE,
143 WIN_READ_EXT, 48 ATA_CMD_PIO_READ_EXT,
144 WIN_WRITE_EXT, 49 ATA_CMD_PIO_WRITE_EXT,
145 WIN_READDMA, 50 ATA_CMD_READ,
146 WIN_WRITEDMA, 51 ATA_CMD_WRITE,
147 WIN_READDMA_EXT, 52 ATA_CMD_READ_EXT,
148 WIN_WRITEDMA_EXT, 53 ATA_CMD_WRITE_EXT,
149}; 54};
150 55
151static const u8 ide_data_phases[] = { 56static const u8 ide_data_phases[] = {
@@ -185,9 +90,9 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
185 sector_t block) 90 sector_t block)
186{ 91{
187 ide_hwif_t *hwif = HWIF(drive); 92 ide_hwif_t *hwif = HWIF(drive);
188 unsigned int dma = drive->using_dma;
189 u16 nsectors = (u16)rq->nr_sectors; 93 u16 nsectors = (u16)rq->nr_sectors;
190 u8 lba48 = (drive->addressing == 1) ? 1 : 0; 94 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
95 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
191 ide_task_t task; 96 ide_task_t task;
192 struct ide_taskfile *tf = &task.tf; 97 struct ide_taskfile *tf = &task.tf;
193 ide_startstop_t rc; 98 ide_startstop_t rc;
@@ -207,7 +112,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
207 memset(&task, 0, sizeof(task)); 112 memset(&task, 0, sizeof(task));
208 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 113 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
209 114
210 if (drive->select.b.lba) { 115 if (drive->dev_flags & IDE_DFLAG_LBA) {
211 if (lba48) { 116 if (lba48) {
212 pr_debug("%s: LBA=0x%012llx\n", drive->name, 117 pr_debug("%s: LBA=0x%012llx\n", drive->name,
213 (unsigned long long)block); 118 (unsigned long long)block);
@@ -232,6 +137,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
232 tf->lbah = block >>= 8; 137 tf->lbah = block >>= 8;
233 tf->device = (block >> 8) & 0xf; 138 tf->device = (block >> 8) & 0xf;
234 } 139 }
140
141 tf->device |= ATA_LBA;
235 } else { 142 } else {
236 unsigned int sect, head, cyl, track; 143 unsigned int sect, head, cyl, track;
237 144
@@ -282,7 +189,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
282{ 189{
283 ide_hwif_t *hwif = HWIF(drive); 190 ide_hwif_t *hwif = HWIF(drive);
284 191
285 BUG_ON(drive->blocked); 192 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
286 193
287 if (!blk_fs_request(rq)) { 194 if (!blk_fs_request(rq)) {
288 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); 195 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
@@ -316,9 +223,9 @@ static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
316 /* Create IDE/ATA command request structure */ 223 /* Create IDE/ATA command request structure */
317 memset(&args, 0, sizeof(ide_task_t)); 224 memset(&args, 0, sizeof(ide_task_t));
318 if (lba48) 225 if (lba48)
319 tf->command = WIN_READ_NATIVE_MAX_EXT; 226 tf->command = ATA_CMD_READ_NATIVE_MAX_EXT;
320 else 227 else
321 tf->command = WIN_READ_NATIVE_MAX; 228 tf->command = ATA_CMD_READ_NATIVE_MAX;
322 tf->device = ATA_LBA; 229 tf->device = ATA_LBA;
323 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 230 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
324 if (lba48) 231 if (lba48)
@@ -353,10 +260,10 @@ static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
353 tf->hob_lbal = (addr_req >>= 8) & 0xff; 260 tf->hob_lbal = (addr_req >>= 8) & 0xff;
354 tf->hob_lbam = (addr_req >>= 8) & 0xff; 261 tf->hob_lbam = (addr_req >>= 8) & 0xff;
355 tf->hob_lbah = (addr_req >>= 8) & 0xff; 262 tf->hob_lbah = (addr_req >>= 8) & 0xff;
356 tf->command = WIN_SET_MAX_EXT; 263 tf->command = ATA_CMD_SET_MAX_EXT;
357 } else { 264 } else {
358 tf->device = (addr_req >>= 8) & 0x0f; 265 tf->device = (addr_req >>= 8) & 0x0f;
359 tf->command = WIN_SET_MAX; 266 tf->command = ATA_CMD_SET_MAX;
360 } 267 }
361 tf->device |= ATA_LBA; 268 tf->device |= ATA_LBA;
362 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 269 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
@@ -379,25 +286,6 @@ static unsigned long long sectors_to_MB(unsigned long long n)
379} 286}
380 287
381/* 288/*
382 * Bits 10 of command_set_1 and cfs_enable_1 must be equal,
383 * so on non-buggy drives we need test only one.
384 * However, we should also check whether these fields are valid.
385 */
386static inline int idedisk_supports_hpa(const struct hd_driveid *id)
387{
388 return (id->command_set_1 & 0x0400) && (id->cfs_enable_1 & 0x0400);
389}
390
391/*
392 * The same here.
393 */
394static inline int idedisk_supports_lba48(const struct hd_driveid *id)
395{
396 return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400)
397 && id->lba_capacity_2;
398}
399
400/*
401 * Some disks report total number of sectors instead of 289 * Some disks report total number of sectors instead of
402 * maximum sector address. We list them here. 290 * maximum sector address. We list them here.
403 */ 291 */
@@ -411,7 +299,7 @@ static const struct drive_list_entry hpa_list[] = {
411static void idedisk_check_hpa(ide_drive_t *drive) 299static void idedisk_check_hpa(ide_drive_t *drive)
412{ 300{
413 unsigned long long capacity, set_max; 301 unsigned long long capacity, set_max;
414 int lba48 = idedisk_supports_lba48(drive->id); 302 int lba48 = ata_id_lba48_enabled(drive->id);
415 303
416 capacity = drive->capacity64; 304 capacity = drive->capacity64;
417 305
@@ -445,141 +333,59 @@ static void idedisk_check_hpa(ide_drive_t *drive)
445 } 333 }
446} 334}
447 335
448static void init_idedisk_capacity(ide_drive_t *drive) 336static int ide_disk_get_capacity(ide_drive_t *drive)
449{ 337{
450 struct hd_driveid *id = drive->id; 338 u16 *id = drive->id;
451 /* 339 int lba;
452 * If this drive supports the Host Protected Area feature set,
453 * then we may need to change our opinion about the drive's capacity.
454 */
455 int hpa = idedisk_supports_hpa(id);
456 340
457 if (idedisk_supports_lba48(id)) { 341 if (ata_id_lba48_enabled(id)) {
458 /* drive speaks 48-bit LBA */ 342 /* drive speaks 48-bit LBA */
459 drive->select.b.lba = 1; 343 lba = 1;
460 drive->capacity64 = id->lba_capacity_2; 344 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
461 if (hpa) 345 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
462 idedisk_check_hpa(drive);
463 } else if ((id->capability & 2) && lba_capacity_is_ok(id)) {
464 /* drive speaks 28-bit LBA */ 346 /* drive speaks 28-bit LBA */
465 drive->select.b.lba = 1; 347 lba = 1;
466 drive->capacity64 = id->lba_capacity; 348 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
467 if (hpa)
468 idedisk_check_hpa(drive);
469 } else { 349 } else {
470 /* drive speaks boring old 28-bit CHS */ 350 /* drive speaks boring old 28-bit CHS */
351 lba = 0;
471 drive->capacity64 = drive->cyl * drive->head * drive->sect; 352 drive->capacity64 = drive->cyl * drive->head * drive->sect;
472 } 353 }
473}
474
475static sector_t idedisk_capacity(ide_drive_t *drive)
476{
477 return drive->capacity64 - drive->sect0;
478}
479
480#ifdef CONFIG_IDE_PROC_FS
481static int smart_enable(ide_drive_t *drive)
482{
483 ide_task_t args;
484 struct ide_taskfile *tf = &args.tf;
485
486 memset(&args, 0, sizeof(ide_task_t));
487 tf->feature = SMART_ENABLE;
488 tf->lbam = SMART_LCYL_PASS;
489 tf->lbah = SMART_HCYL_PASS;
490 tf->command = WIN_SMART;
491 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
492 return ide_no_data_taskfile(drive, &args);
493}
494
495static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
496{
497 ide_task_t args;
498 struct ide_taskfile *tf = &args.tf;
499
500 memset(&args, 0, sizeof(ide_task_t));
501 tf->feature = sub_cmd;
502 tf->nsect = 0x01;
503 tf->lbam = SMART_LCYL_PASS;
504 tf->lbah = SMART_HCYL_PASS;
505 tf->command = WIN_SMART;
506 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
507 args.data_phase = TASKFILE_IN;
508 (void) smart_enable(drive);
509 return ide_raw_taskfile(drive, &args, buf, 1);
510}
511
512static int proc_idedisk_read_cache
513 (char *page, char **start, off_t off, int count, int *eof, void *data)
514{
515 ide_drive_t *drive = (ide_drive_t *) data;
516 char *out = page;
517 int len;
518
519 if (drive->id_read)
520 len = sprintf(out, "%i\n", drive->id->buf_size / 2);
521 else
522 len = sprintf(out, "(none)\n");
523 354
524 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 355 if (lba) {
525} 356 drive->dev_flags |= IDE_DFLAG_LBA;
526
527static int proc_idedisk_read_capacity
528 (char *page, char **start, off_t off, int count, int *eof, void *data)
529{
530 ide_drive_t*drive = (ide_drive_t *)data;
531 int len;
532
533 len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive));
534 357
535 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 358 /*
536} 359 * If this device supports the Host Protected Area feature set,
537 360 * then we may need to change our opinion about its capacity.
538static int proc_idedisk_read_smart(char *page, char **start, off_t off, 361 */
539 int count, int *eof, void *data, u8 sub_cmd) 362 if (ata_id_hpa_enabled(id))
540{ 363 idedisk_check_hpa(drive);
541 ide_drive_t *drive = (ide_drive_t *)data;
542 int len = 0, i = 0;
543
544 if (get_smart_data(drive, page, sub_cmd) == 0) {
545 unsigned short *val = (unsigned short *) page;
546 char *out = ((char *)val) + (SECTOR_WORDS * 4);
547 page = out;
548 do {
549 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
550 (++i & 7) ? ' ' : '\n');
551 val += 1;
552 } while (i < (SECTOR_WORDS * 2));
553 len = out - page;
554 } 364 }
555 365
556 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 366 /* limit drive capacity to 137GB if LBA48 cannot be used */
557} 367 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
368 drive->capacity64 > 1ULL << 28) {
369 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
370 "%llu sectors (%llu MB)\n",
371 drive->name, (unsigned long long)drive->capacity64,
372 sectors_to_MB(drive->capacity64));
373 drive->capacity64 = 1ULL << 28;
374 }
558 375
559static int proc_idedisk_read_sv 376 if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
560 (char *page, char **start, off_t off, int count, int *eof, void *data) 377 (drive->dev_flags & IDE_DFLAG_LBA48)) {
561{ 378 if (drive->capacity64 > 1ULL << 28) {
562 return proc_idedisk_read_smart(page, start, off, count, eof, data, 379 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
563 SMART_READ_VALUES); 380 " will be used for accessing sectors "
564} 381 "> %u\n", drive->name, 1 << 28);
382 } else
383 drive->dev_flags &= ~IDE_DFLAG_LBA48;
384 }
565 385
566static int proc_idedisk_read_st 386 return 0;
567 (char *page, char **start, off_t off, int count, int *eof, void *data)
568{
569 return proc_idedisk_read_smart(page, start, off, count, eof, data,
570 SMART_READ_THRESHOLDS);
571} 387}
572 388
573static ide_proc_entry_t idedisk_proc[] = {
574 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
575 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
576 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
577 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
578 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
579 { NULL, 0, NULL, NULL }
580};
581#endif /* CONFIG_IDE_PROC_FS */
582
583static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 389static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
584{ 390{
585 ide_drive_t *drive = q->queuedata; 391 ide_drive_t *drive = q->queuedata;
@@ -589,11 +395,11 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
589 BUG_ON(task == NULL); 395 BUG_ON(task == NULL);
590 396
591 memset(task, 0, sizeof(*task)); 397 memset(task, 0, sizeof(*task));
592 if (ide_id_has_flush_cache_ext(drive->id) && 398 if (ata_id_flush_ext_enabled(drive->id) &&
593 (drive->capacity64 >= (1UL << 28))) 399 (drive->capacity64 >= (1UL << 28)))
594 task->tf.command = WIN_FLUSH_CACHE_EXT; 400 task->tf.command = ATA_CMD_FLUSH_EXT;
595 else 401 else
596 task->tf.command = WIN_FLUSH_CACHE; 402 task->tf.command = ATA_CMD_FLUSH;
597 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE | 403 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE |
598 IDE_TFLAG_DYN; 404 IDE_TFLAG_DYN;
599 task->data_phase = TASKFILE_NO_DATA; 405 task->data_phase = TASKFILE_NO_DATA;
@@ -603,6 +409,8 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
603 rq->special = task; 409 rq->special = task;
604} 410}
605 411
412ide_devset_get(multcount, mult_count);
413
606/* 414/*
607 * This is tightly woven into the driver->do_special can not touch. 415 * This is tightly woven into the driver->do_special can not touch.
608 * DON'T do it again until a total personality rewrite is committed. 416 * DON'T do it again until a total personality rewrite is committed.
@@ -612,7 +420,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
612 struct request *rq; 420 struct request *rq;
613 int error; 421 int error;
614 422
615 if (arg < 0 || arg > drive->id->max_multsect) 423 if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff))
616 return -EINVAL; 424 return -EINVAL;
617 425
618 if (drive->special.b.set_multmode) 426 if (drive->special.b.set_multmode)
@@ -629,26 +437,43 @@ static int set_multcount(ide_drive_t *drive, int arg)
629 return (drive->mult_count == arg) ? 0 : -EIO; 437 return (drive->mult_count == arg) ? 0 : -EIO;
630} 438}
631 439
440ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR);
441
632static int set_nowerr(ide_drive_t *drive, int arg) 442static int set_nowerr(ide_drive_t *drive, int arg)
633{ 443{
634 if (arg < 0 || arg > 1) 444 if (arg < 0 || arg > 1)
635 return -EINVAL; 445 return -EINVAL;
636 446
637 if (ide_spin_wait_hwgroup(drive)) 447 if (arg)
638 return -EBUSY; 448 drive->dev_flags |= IDE_DFLAG_NOWERR;
639 drive->nowerr = arg; 449 else
450 drive->dev_flags &= ~IDE_DFLAG_NOWERR;
451
640 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; 452 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
641 spin_unlock_irq(&ide_lock); 453
642 return 0; 454 return 0;
643} 455}
644 456
457static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
458{
459 ide_task_t task;
460
461 memset(&task, 0, sizeof(task));
462 task.tf.feature = feature;
463 task.tf.nsect = nsect;
464 task.tf.command = ATA_CMD_SET_FEATURES;
465 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
466
467 return ide_no_data_taskfile(drive, &task);
468}
469
645static void update_ordered(ide_drive_t *drive) 470static void update_ordered(ide_drive_t *drive)
646{ 471{
647 struct hd_driveid *id = drive->id; 472 u16 *id = drive->id;
648 unsigned ordered = QUEUE_ORDERED_NONE; 473 unsigned ordered = QUEUE_ORDERED_NONE;
649 prepare_flush_fn *prep_fn = NULL; 474 prepare_flush_fn *prep_fn = NULL;
650 475
651 if (drive->wcache) { 476 if (drive->dev_flags & IDE_DFLAG_WCACHE) {
652 unsigned long long capacity; 477 unsigned long long capacity;
653 int barrier; 478 int barrier;
654 /* 479 /*
@@ -659,10 +484,12 @@ static void update_ordered(ide_drive_t *drive)
659 * time we have trimmed the drive capacity if LBA48 is 484 * time we have trimmed the drive capacity if LBA48 is
660 * not available so we don't need to recheck that. 485 * not available so we don't need to recheck that.
661 */ 486 */
662 capacity = idedisk_capacity(drive); 487 capacity = ide_gd_capacity(drive);
663 barrier = ide_id_has_flush_cache(id) && !drive->noflush && 488 barrier = ata_id_flush_enabled(id) &&
664 (drive->addressing == 0 || capacity <= (1ULL << 28) || 489 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
665 ide_id_has_flush_cache_ext(id)); 490 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
491 capacity <= (1ULL << 28) ||
492 ata_id_flush_ext_enabled(id));
666 493
667 printk(KERN_INFO "%s: cache flushes %ssupported\n", 494 printk(KERN_INFO "%s: cache flushes %ssupported\n",
668 drive->name, barrier ? "" : "not "); 495 drive->name, barrier ? "" : "not ");
@@ -677,23 +504,24 @@ static void update_ordered(ide_drive_t *drive)
677 blk_queue_ordered(drive->queue, ordered, prep_fn); 504 blk_queue_ordered(drive->queue, ordered, prep_fn);
678} 505}
679 506
680static int write_cache(ide_drive_t *drive, int arg) 507ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
508
509static int set_wcache(ide_drive_t *drive, int arg)
681{ 510{
682 ide_task_t args;
683 int err = 1; 511 int err = 1;
684 512
685 if (arg < 0 || arg > 1) 513 if (arg < 0 || arg > 1)
686 return -EINVAL; 514 return -EINVAL;
687 515
688 if (ide_id_has_flush_cache(drive->id)) { 516 if (ata_id_flush_enabled(drive->id)) {
689 memset(&args, 0, sizeof(ide_task_t)); 517 err = ide_do_setfeature(drive,
690 args.tf.feature = arg ? 518 arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
691 SETFEATURES_EN_WCACHE : SETFEATURES_DIS_WCACHE; 519 if (err == 0) {
692 args.tf.command = WIN_SETFEATURES; 520 if (arg)
693 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 521 drive->dev_flags |= IDE_DFLAG_WCACHE;
694 err = ide_no_data_taskfile(drive, &args); 522 else
695 if (err == 0) 523 drive->dev_flags &= ~IDE_DFLAG_WCACHE;
696 drive->wcache = arg; 524 }
697 } 525 }
698 526
699 update_ordered(drive); 527 update_ordered(drive);
@@ -706,149 +534,119 @@ static int do_idedisk_flushcache(ide_drive_t *drive)
706 ide_task_t args; 534 ide_task_t args;
707 535
708 memset(&args, 0, sizeof(ide_task_t)); 536 memset(&args, 0, sizeof(ide_task_t));
709 if (ide_id_has_flush_cache_ext(drive->id)) 537 if (ata_id_flush_ext_enabled(drive->id))
710 args.tf.command = WIN_FLUSH_CACHE_EXT; 538 args.tf.command = ATA_CMD_FLUSH_EXT;
711 else 539 else
712 args.tf.command = WIN_FLUSH_CACHE; 540 args.tf.command = ATA_CMD_FLUSH;
713 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 541 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
714 return ide_no_data_taskfile(drive, &args); 542 return ide_no_data_taskfile(drive, &args);
715} 543}
716 544
545ide_devset_get(acoustic, acoustic);
546
717static int set_acoustic(ide_drive_t *drive, int arg) 547static int set_acoustic(ide_drive_t *drive, int arg)
718{ 548{
719 ide_task_t args;
720
721 if (arg < 0 || arg > 254) 549 if (arg < 0 || arg > 254)
722 return -EINVAL; 550 return -EINVAL;
723 551
724 memset(&args, 0, sizeof(ide_task_t)); 552 ide_do_setfeature(drive,
725 args.tf.feature = arg ? SETFEATURES_EN_AAM : SETFEATURES_DIS_AAM; 553 arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
726 args.tf.nsect = arg; 554
727 args.tf.command = WIN_SETFEATURES;
728 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
729 ide_no_data_taskfile(drive, &args);
730 drive->acoustic = arg; 555 drive->acoustic = arg;
556
731 return 0; 557 return 0;
732} 558}
733 559
560ide_devset_get_flag(addressing, IDE_DFLAG_LBA48);
561
734/* 562/*
735 * drive->addressing: 563 * drive->addressing:
736 * 0: 28-bit 564 * 0: 28-bit
737 * 1: 48-bit 565 * 1: 48-bit
738 * 2: 48-bit capable doing 28-bit 566 * 2: 48-bit capable doing 28-bit
739 */ 567 */
740static int set_lba_addressing(ide_drive_t *drive, int arg) 568static int set_addressing(ide_drive_t *drive, int arg)
741{ 569{
742 if (arg < 0 || arg > 2) 570 if (arg < 0 || arg > 2)
743 return -EINVAL; 571 return -EINVAL;
744 572
745 drive->addressing = 0; 573 if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
574 ata_id_lba48_enabled(drive->id) == 0))
575 return -EIO;
746 576
747 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) 577 if (arg == 2)
748 return 0; 578 arg = 0;
579
580 if (arg)
581 drive->dev_flags |= IDE_DFLAG_LBA48;
582 else
583 drive->dev_flags &= ~IDE_DFLAG_LBA48;
749 584
750 if (!idedisk_supports_lba48(drive->id))
751 return -EIO;
752 drive->addressing = arg;
753 return 0; 585 return 0;
754} 586}
755 587
756#ifdef CONFIG_IDE_PROC_FS 588ide_ext_devset_rw(acoustic, acoustic);
757static void idedisk_add_settings(ide_drive_t *drive) 589ide_ext_devset_rw(address, addressing);
590ide_ext_devset_rw(multcount, multcount);
591ide_ext_devset_rw(wcache, wcache);
592
593ide_ext_devset_rw_sync(nowerr, nowerr);
594
595static int ide_disk_check(ide_drive_t *drive, const char *s)
758{ 596{
759 struct hd_driveid *id = drive->id; 597 return 1;
760
761 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
762 &drive->bios_cyl, NULL);
763 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
764 &drive->bios_head, NULL);
765 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1,
766 &drive->bios_sect, NULL);
767 ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1,
768 &drive->addressing, set_lba_addressing);
769 ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0,
770 id->max_multsect, 1, 1, &drive->mult_count,
771 set_multcount);
772 ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
773 &drive->nowerr, set_nowerr);
774 ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1,
775 &drive->lun, NULL);
776 ide_add_setting(drive, "wcache", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
777 &drive->wcache, write_cache);
778 ide_add_setting(drive, "acoustic", SETTING_RW, TYPE_BYTE, 0, 254, 1, 1,
779 &drive->acoustic, set_acoustic);
780 ide_add_setting(drive, "failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
781 &drive->failures, NULL);
782 ide_add_setting(drive, "max_failures", SETTING_RW, TYPE_INT, 0, 65535,
783 1, 1, &drive->max_failures, NULL);
784} 598}
785#else
786static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
787#endif
788 599
789static void idedisk_setup(ide_drive_t *drive) 600static void ide_disk_setup(ide_drive_t *drive)
790{ 601{
602 struct ide_disk_obj *idkp = drive->driver_data;
603 struct request_queue *q = drive->queue;
791 ide_hwif_t *hwif = drive->hwif; 604 ide_hwif_t *hwif = drive->hwif;
792 struct hd_driveid *id = drive->id; 605 u16 *id = drive->id;
606 char *m = (char *)&id[ATA_ID_PROD];
793 unsigned long long capacity; 607 unsigned long long capacity;
794 608
795 idedisk_add_settings(drive); 609 ide_proc_register_driver(drive, idkp->driver);
796 610
797 if (drive->id_read == 0) 611 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
798 return; 612 return;
799 613
800 if (drive->removable) { 614 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
801 /* 615 /*
802 * Removable disks (eg. SYQUEST); ignore 'WD' drives 616 * Removable disks (eg. SYQUEST); ignore 'WD' drives
803 */ 617 */
804 if (id->model[0] != 'W' || id->model[1] != 'D') 618 if (m[0] != 'W' || m[1] != 'D')
805 drive->doorlocking = 1; 619 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
806 } 620 }
807 621
808 (void)set_lba_addressing(drive, 1); 622 (void)set_addressing(drive, 1);
809 623
810 if (drive->addressing == 1) { 624 if (drive->dev_flags & IDE_DFLAG_LBA48) {
811 int max_s = 2048; 625 int max_s = 2048;
812 626
813 if (max_s > hwif->rqsize) 627 if (max_s > hwif->rqsize)
814 max_s = hwif->rqsize; 628 max_s = hwif->rqsize;
815 629
816 blk_queue_max_sectors(drive->queue, max_s); 630 blk_queue_max_sectors(q, max_s);
817 } 631 }
818 632
819 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, 633 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
820 drive->queue->max_sectors / 2); 634 q->max_sectors / 2);
821 635
822 /* calculate drive capacity, and select LBA if possible */ 636 if (ata_id_is_ssd(id) || ata_id_is_cfa(id))
823 init_idedisk_capacity(drive); 637 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
824 638
825 /* limit drive capacity to 137GB if LBA48 cannot be used */ 639 /* calculate drive capacity, and select LBA if possible */
826 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) { 640 ide_disk_get_capacity(drive);
827 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
828 "%llu sectors (%llu MB)\n",
829 drive->name, (unsigned long long)drive->capacity64,
830 sectors_to_MB(drive->capacity64));
831 drive->capacity64 = 1ULL << 28;
832 }
833
834 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) {
835 if (drive->capacity64 > 1ULL << 28) {
836 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
837 " will be used for accessing sectors "
838 "> %u\n", drive->name, 1 << 28);
839 } else
840 drive->addressing = 0;
841 }
842 641
843 /* 642 /*
844 * if possible, give fdisk access to more of the drive, 643 * if possible, give fdisk access to more of the drive,
845 * by correcting bios_cyls: 644 * by correcting bios_cyls:
846 */ 645 */
847 capacity = idedisk_capacity(drive); 646 capacity = ide_gd_capacity(drive);
848 647
849 if (!drive->forced_geom) { 648 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
850 649 if (ata_id_lba48_enabled(drive->id)) {
851 if (idedisk_supports_lba48(drive->id)) {
852 /* compatibility */ 650 /* compatibility */
853 drive->bios_sect = 63; 651 drive->bios_sect = 63;
854 drive->bios_head = 255; 652 drive->bios_head = 255;
@@ -874,335 +672,71 @@ static void idedisk_setup(ide_drive_t *drive)
874 drive->name, capacity, sectors_to_MB(capacity)); 672 drive->name, capacity, sectors_to_MB(capacity));
875 673
876 /* Only print cache size when it was specified */ 674 /* Only print cache size when it was specified */
877 if (id->buf_size) 675 if (id[ATA_ID_BUF_SIZE])
878 printk(KERN_CONT " w/%dKiB Cache", id->buf_size / 2); 676 printk(KERN_CONT " w/%dKiB Cache", id[ATA_ID_BUF_SIZE] / 2);
879 677
880 printk(KERN_CONT ", CHS=%d/%d/%d\n", 678 printk(KERN_CONT ", CHS=%d/%d/%d\n",
881 drive->bios_cyl, drive->bios_head, drive->bios_sect); 679 drive->bios_cyl, drive->bios_head, drive->bios_sect);
882 680
883 /* write cache enabled? */ 681 /* write cache enabled? */
884 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5))) 682 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
885 drive->wcache = 1; 683 drive->dev_flags |= IDE_DFLAG_WCACHE;
684
685 set_wcache(drive, 1);
886 686
887 write_cache(drive, 1); 687 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
688 (drive->head == 0 || drive->head > 16)) {
689 printk(KERN_ERR "%s: invalid geometry: %d physical heads?\n",
690 drive->name, drive->head);
691 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
692 } else
693 drive->dev_flags |= IDE_DFLAG_ATTACH;
888} 694}
889 695
890static void ide_cacheflush_p(ide_drive_t *drive) 696static void ide_disk_flush(ide_drive_t *drive)
891{ 697{
892 if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) 698 if (ata_id_flush_enabled(drive->id) == 0 ||
699 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
893 return; 700 return;
894 701
895 if (do_idedisk_flushcache(drive)) 702 if (do_idedisk_flushcache(drive))
896 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name); 703 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
897} 704}
898 705
899static void ide_disk_remove(ide_drive_t *drive) 706static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
900{
901 struct ide_disk_obj *idkp = drive->driver_data;
902 struct gendisk *g = idkp->disk;
903
904 ide_proc_unregister_driver(drive, idkp->driver);
905
906 del_gendisk(g);
907
908 ide_cacheflush_p(drive);
909
910 ide_disk_put(idkp);
911}
912
913static void ide_disk_release(struct kref *kref)
914{
915 struct ide_disk_obj *idkp = to_ide_disk(kref);
916 ide_drive_t *drive = idkp->drive;
917 struct gendisk *g = idkp->disk;
918
919 drive->driver_data = NULL;
920 g->private_data = NULL;
921 put_disk(g);
922 kfree(idkp);
923}
924
925static int ide_disk_probe(ide_drive_t *drive);
926
927/*
928 * On HPA drives the capacity needs to be
929 * reinitilized on resume otherwise the disk
930 * can not be used and a hard reset is required
931 */
932static void ide_disk_resume(ide_drive_t *drive)
933{
934 if (idedisk_supports_hpa(drive->id))
935 init_idedisk_capacity(drive);
936}
937
938static void ide_device_shutdown(ide_drive_t *drive)
939{ 707{
940#ifdef CONFIG_ALPHA 708 return 0;
941 /* On Alpha, halt(8) doesn't actually turn the machine off,
942 it puts you into the sort of firmware monitor. Typically,
943 it's used to boot another kernel image, so it's not much
944 different from reboot(8). Therefore, we don't need to
945 spin down the disk in this case, especially since Alpha
946 firmware doesn't handle disks in standby mode properly.
947 On the other hand, it's reasonably safe to turn the power
948 off when the shutdown process reaches the firmware prompt,
949 as the firmware initialization takes rather long time -
950 at least 10 seconds, which should be sufficient for
951 the disk to expire its write cache. */
952 if (system_state != SYSTEM_POWER_OFF) {
953#else
954 if (system_state == SYSTEM_RESTART) {
955#endif
956 ide_cacheflush_p(drive);
957 return;
958 }
959
960 printk(KERN_INFO "Shutdown: %s\n", drive->name);
961
962 drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
963} 709}
964 710
965static ide_driver_t idedisk_driver = { 711static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
966 .gen_driver = { 712 int on)
967 .owner = THIS_MODULE,
968 .name = "ide-disk",
969 .bus = &ide_bus_type,
970 },
971 .probe = ide_disk_probe,
972 .remove = ide_disk_remove,
973 .resume = ide_disk_resume,
974 .shutdown = ide_device_shutdown,
975 .version = IDEDISK_VERSION,
976 .media = ide_disk,
977 .supports_dsc_overlap = 0,
978 .do_request = ide_do_rw_disk,
979 .end_request = ide_end_request,
980 .error = __ide_error,
981#ifdef CONFIG_IDE_PROC_FS
982 .proc = idedisk_proc,
983#endif
984};
985
986static int idedisk_set_doorlock(ide_drive_t *drive, int on)
987{ 713{
988 ide_task_t task; 714 ide_task_t task;
715 int ret;
716
717 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
718 return 0;
989 719
990 memset(&task, 0, sizeof(task)); 720 memset(&task, 0, sizeof(task));
991 task.tf.command = on ? WIN_DOORLOCK : WIN_DOORUNLOCK; 721 task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
992 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 722 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
993 723
994 return ide_no_data_taskfile(drive, &task); 724 ret = ide_no_data_taskfile(drive, &task);
995}
996
997static int idedisk_open(struct inode *inode, struct file *filp)
998{
999 struct gendisk *disk = inode->i_bdev->bd_disk;
1000 struct ide_disk_obj *idkp;
1001 ide_drive_t *drive;
1002
1003 idkp = ide_disk_get(disk);
1004 if (idkp == NULL)
1005 return -ENXIO;
1006
1007 drive = idkp->drive;
1008 725
1009 idkp->openers++; 726 if (ret)
727 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
1010 728
1011 if (drive->removable && idkp->openers == 1) { 729 return ret;
1012 check_disk_change(inode->i_bdev);
1013 /*
1014 * Ignore the return code from door_lock,
1015 * since the open() has already succeeded,
1016 * and the door_lock is irrelevant at this point.
1017 */
1018 if (drive->doorlocking && idedisk_set_doorlock(drive, 1))
1019 drive->doorlocking = 0;
1020 }
1021 return 0;
1022}
1023
1024static int idedisk_release(struct inode *inode, struct file *filp)
1025{
1026 struct gendisk *disk = inode->i_bdev->bd_disk;
1027 struct ide_disk_obj *idkp = ide_disk_g(disk);
1028 ide_drive_t *drive = idkp->drive;
1029
1030 if (idkp->openers == 1)
1031 ide_cacheflush_p(drive);
1032
1033 if (drive->removable && idkp->openers == 1) {
1034 if (drive->doorlocking && idedisk_set_doorlock(drive, 0))
1035 drive->doorlocking = 0;
1036 }
1037
1038 idkp->openers--;
1039
1040 ide_disk_put(idkp);
1041
1042 return 0;
1043}
1044
1045static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1046{
1047 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1048 ide_drive_t *drive = idkp->drive;
1049
1050 geo->heads = drive->bios_head;
1051 geo->sectors = drive->bios_sect;
1052 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1053 return 0;
1054}
1055
1056static int idedisk_ioctl(struct inode *inode, struct file *file,
1057 unsigned int cmd, unsigned long arg)
1058{
1059 unsigned long flags;
1060 struct block_device *bdev = inode->i_bdev;
1061 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1062 ide_drive_t *drive = idkp->drive;
1063 int err, (*setfunc)(ide_drive_t *, int);
1064 u8 *val;
1065
1066 switch (cmd) {
1067 case HDIO_GET_ADDRESS: val = &drive->addressing; goto read_val;
1068 case HDIO_GET_MULTCOUNT: val = &drive->mult_count; goto read_val;
1069 case HDIO_GET_NOWERR: val = &drive->nowerr; goto read_val;
1070 case HDIO_GET_WCACHE: val = &drive->wcache; goto read_val;
1071 case HDIO_GET_ACOUSTIC: val = &drive->acoustic; goto read_val;
1072 case HDIO_SET_ADDRESS: setfunc = set_lba_addressing; goto set_val;
1073 case HDIO_SET_MULTCOUNT: setfunc = set_multcount; goto set_val;
1074 case HDIO_SET_NOWERR: setfunc = set_nowerr; goto set_val;
1075 case HDIO_SET_WCACHE: setfunc = write_cache; goto set_val;
1076 case HDIO_SET_ACOUSTIC: setfunc = set_acoustic; goto set_val;
1077 }
1078
1079 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1080
1081read_val:
1082 mutex_lock(&ide_setting_mtx);
1083 spin_lock_irqsave(&ide_lock, flags);
1084 err = *val;
1085 spin_unlock_irqrestore(&ide_lock, flags);
1086 mutex_unlock(&ide_setting_mtx);
1087 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1088
1089set_val:
1090 if (bdev != bdev->bd_contains)
1091 err = -EINVAL;
1092 else {
1093 if (!capable(CAP_SYS_ADMIN))
1094 err = -EACCES;
1095 else {
1096 mutex_lock(&ide_setting_mtx);
1097 err = setfunc(drive, arg);
1098 mutex_unlock(&ide_setting_mtx);
1099 }
1100 }
1101 return err;
1102}
1103
1104static int idedisk_media_changed(struct gendisk *disk)
1105{
1106 struct ide_disk_obj *idkp = ide_disk_g(disk);
1107 ide_drive_t *drive = idkp->drive;
1108
1109 /* do not scan partitions twice if this is a removable device */
1110 if (drive->attach) {
1111 drive->attach = 0;
1112 return 0;
1113 }
1114 /* if removable, always assume it was changed */
1115 return drive->removable;
1116}
1117
1118static int idedisk_revalidate_disk(struct gendisk *disk)
1119{
1120 struct ide_disk_obj *idkp = ide_disk_g(disk);
1121 set_capacity(disk, idedisk_capacity(idkp->drive));
1122 return 0;
1123} 730}
1124 731
1125static struct block_device_operations idedisk_ops = { 732const struct ide_disk_ops ide_ata_disk_ops = {
1126 .owner = THIS_MODULE, 733 .check = ide_disk_check,
1127 .open = idedisk_open, 734 .get_capacity = ide_disk_get_capacity,
1128 .release = idedisk_release, 735 .setup = ide_disk_setup,
1129 .ioctl = idedisk_ioctl, 736 .flush = ide_disk_flush,
1130 .getgeo = idedisk_getgeo, 737 .init_media = ide_disk_init_media,
1131 .media_changed = idedisk_media_changed, 738 .set_doorlock = ide_disk_set_doorlock,
1132 .revalidate_disk = idedisk_revalidate_disk 739 .do_request = ide_do_rw_disk,
740 .end_request = ide_end_request,
741 .ioctl = ide_disk_ioctl,
1133}; 742};
1134
1135MODULE_DESCRIPTION("ATA DISK Driver");
1136
1137static int ide_disk_probe(ide_drive_t *drive)
1138{
1139 struct ide_disk_obj *idkp;
1140 struct gendisk *g;
1141
1142 /* strstr("foo", "") is non-NULL */
1143 if (!strstr("ide-disk", drive->driver_req))
1144 goto failed;
1145 if (!drive->present)
1146 goto failed;
1147 if (drive->media != ide_disk)
1148 goto failed;
1149
1150 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
1151 if (!idkp)
1152 goto failed;
1153
1154 g = alloc_disk_node(1 << PARTN_BITS,
1155 hwif_to_node(drive->hwif));
1156 if (!g)
1157 goto out_free_idkp;
1158
1159 ide_init_disk(g, drive);
1160
1161 ide_proc_register_driver(drive, &idedisk_driver);
1162
1163 kref_init(&idkp->kref);
1164
1165 idkp->drive = drive;
1166 idkp->driver = &idedisk_driver;
1167 idkp->disk = g;
1168
1169 g->private_data = &idkp->driver;
1170
1171 drive->driver_data = idkp;
1172
1173 idedisk_setup(drive);
1174 if ((!drive->head || drive->head > 16) && !drive->select.b.lba) {
1175 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
1176 drive->name, drive->head);
1177 drive->attach = 0;
1178 } else
1179 drive->attach = 1;
1180
1181 g->minors = 1 << PARTN_BITS;
1182 g->driverfs_dev = &drive->gendev;
1183 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1184 set_capacity(g, idedisk_capacity(drive));
1185 g->fops = &idedisk_ops;
1186 add_disk(g);
1187 return 0;
1188
1189out_free_idkp:
1190 kfree(idkp);
1191failed:
1192 return -ENODEV;
1193}
1194
1195static void __exit idedisk_exit(void)
1196{
1197 driver_unregister(&idedisk_driver.gen_driver);
1198}
1199
1200static int __init idedisk_init(void)
1201{
1202 return driver_register(&idedisk_driver.gen_driver);
1203}
1204
1205MODULE_ALIAS("ide:*m-disk*");
1206module_init(idedisk_init);
1207module_exit(idedisk_exit);
1208MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h
new file mode 100644
index 000000000000..d511dab7c4aa
--- /dev/null
+++ b/drivers/ide/ide-disk.h
@@ -0,0 +1,29 @@
1#ifndef __IDE_DISK_H
2#define __IDE_DISK_H
3
4#include "ide-gd.h"
5
6#ifdef CONFIG_IDE_GD_ATA
7/* ide-disk.c */
8extern const struct ide_disk_ops ide_ata_disk_ops;
9ide_decl_devset(address);
10ide_decl_devset(multcount);
11ide_decl_devset(nowerr);
12ide_decl_devset(wcache);
13ide_decl_devset(acoustic);
14
15/* ide-disk_ioctl.c */
16int ide_disk_ioctl(ide_drive_t *, struct block_device *, fmode_t, unsigned int,
17 unsigned long);
18
19#ifdef CONFIG_IDE_PROC_FS
20/* ide-disk_proc.c */
21extern ide_proc_entry_t ide_disk_proc[];
22extern const struct ide_proc_devset ide_disk_settings[];
23#endif
24#else
25#define ide_disk_proc NULL
26#define ide_disk_settings NULL
27#endif
28
29#endif /* __IDE_DISK_H */
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
new file mode 100644
index 000000000000..7b783dd7c0be
--- /dev/null
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -0,0 +1,26 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5#include "ide-disk.h"
6
7static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
8{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
9{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
10{ HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr },
11{ HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache },
12{ HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic },
13{ 0 }
14};
15
16int ide_disk_ioctl(ide_drive_t *drive, struct block_device *bdev, fmode_t mode,
17 unsigned int cmd, unsigned long arg)
18{
19 int err;
20
21 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
22 if (err != -EOPNOTSUPP)
23 return err;
24
25 return generic_ide_ioctl(drive, bdev, cmd, arg);
26}
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
new file mode 100644
index 000000000000..1146f4204c6e
--- /dev/null
+++ b/drivers/ide/ide-disk_proc.c
@@ -0,0 +1,129 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5#include "ide-disk.h"
6
7static int smart_enable(ide_drive_t *drive)
8{
9 ide_task_t args;
10 struct ide_taskfile *tf = &args.tf;
11
12 memset(&args, 0, sizeof(ide_task_t));
13 tf->feature = ATA_SMART_ENABLE;
14 tf->lbam = ATA_SMART_LBAM_PASS;
15 tf->lbah = ATA_SMART_LBAH_PASS;
16 tf->command = ATA_CMD_SMART;
17 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
18 return ide_no_data_taskfile(drive, &args);
19}
20
21static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
22{
23 ide_task_t args;
24 struct ide_taskfile *tf = &args.tf;
25
26 memset(&args, 0, sizeof(ide_task_t));
27 tf->feature = sub_cmd;
28 tf->nsect = 0x01;
29 tf->lbam = ATA_SMART_LBAM_PASS;
30 tf->lbah = ATA_SMART_LBAH_PASS;
31 tf->command = ATA_CMD_SMART;
32 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
33 args.data_phase = TASKFILE_IN;
34 (void) smart_enable(drive);
35 return ide_raw_taskfile(drive, &args, buf, 1);
36}
37
38static int proc_idedisk_read_cache
39 (char *page, char **start, off_t off, int count, int *eof, void *data)
40{
41 ide_drive_t *drive = (ide_drive_t *) data;
42 char *out = page;
43 int len;
44
45 if (drive->dev_flags & IDE_DFLAG_ID_READ)
46 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
47 else
48 len = sprintf(out, "(none)\n");
49
50 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
51}
52
53static int proc_idedisk_read_capacity
54 (char *page, char **start, off_t off, int count, int *eof, void *data)
55{
56 ide_drive_t*drive = (ide_drive_t *)data;
57 int len;
58
59 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
60
61 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
62}
63
64static int proc_idedisk_read_smart(char *page, char **start, off_t off,
65 int count, int *eof, void *data, u8 sub_cmd)
66{
67 ide_drive_t *drive = (ide_drive_t *)data;
68 int len = 0, i = 0;
69
70 if (get_smart_data(drive, page, sub_cmd) == 0) {
71 unsigned short *val = (unsigned short *) page;
72 char *out = (char *)val + SECTOR_SIZE;
73
74 page = out;
75 do {
76 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
77 (++i & 7) ? ' ' : '\n');
78 val += 1;
79 } while (i < SECTOR_SIZE / 2);
80 len = out - page;
81 }
82
83 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
84}
85
86static int proc_idedisk_read_sv
87 (char *page, char **start, off_t off, int count, int *eof, void *data)
88{
89 return proc_idedisk_read_smart(page, start, off, count, eof, data,
90 ATA_SMART_READ_VALUES);
91}
92
93static int proc_idedisk_read_st
94 (char *page, char **start, off_t off, int count, int *eof, void *data)
95{
96 return proc_idedisk_read_smart(page, start, off, count, eof, data,
97 ATA_SMART_READ_THRESHOLDS);
98}
99
100ide_proc_entry_t ide_disk_proc[] = {
101 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
102 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
103 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
104 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
105 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
106 { NULL, 0, NULL, NULL }
107};
108
109ide_devset_rw_field(bios_cyl, bios_cyl);
110ide_devset_rw_field(bios_head, bios_head);
111ide_devset_rw_field(bios_sect, bios_sect);
112ide_devset_rw_field(failures, failures);
113ide_devset_rw_field(lun, lun);
114ide_devset_rw_field(max_failures, max_failures);
115
116const struct ide_proc_devset ide_disk_settings[] = {
117 IDE_PROC_DEVSET(acoustic, 0, 254),
118 IDE_PROC_DEVSET(address, 0, 2),
119 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
120 IDE_PROC_DEVSET(bios_head, 0, 255),
121 IDE_PROC_DEVSET(bios_sect, 0, 63),
122 IDE_PROC_DEVSET(failures, 0, 65535),
123 IDE_PROC_DEVSET(lun, 0, 7),
124 IDE_PROC_DEVSET(max_failures, 0, 65535),
125 IDE_PROC_DEVSET(multcount, 0, 16),
126 IDE_PROC_DEVSET(nowerr, 0, 1),
127 IDE_PROC_DEVSET(wcache, 0, 1),
128 { 0 },
129};
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
new file mode 100644
index 000000000000..cac431f0df17
--- /dev/null
+++ b/drivers/ide/ide-dma-sff.c
@@ -0,0 +1,356 @@
1#include <linux/types.h>
2#include <linux/kernel.h>
3#include <linux/ide.h>
4#include <linux/scatterlist.h>
5#include <linux/dma-mapping.h>
6#include <linux/io.h>
7
8/**
9 * config_drive_for_dma - attempt to activate IDE DMA
10 * @drive: the drive to place in DMA mode
11 *
12 * If the drive supports at least mode 2 DMA or UDMA of any kind
13 * then attempt to place it into DMA mode. Drives that are known to
14 * support DMA but predate the DMA properties or that are known
15 * to have DMA handling bugs are also set up appropriately based
16 * on the good/bad drive lists.
17 */
18
19int config_drive_for_dma(ide_drive_t *drive)
20{
21 ide_hwif_t *hwif = drive->hwif;
22 u16 *id = drive->id;
23
24 if (drive->media != ide_disk) {
25 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
26 return 0;
27 }
28
29 /*
30 * Enable DMA on any drive that has
31 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
32 */
33 if ((id[ATA_ID_FIELD_VALID] & 4) &&
34 ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
35 return 1;
36
37 /*
38 * Enable DMA on any drive that has mode2 DMA
39 * (multi or single) enabled
40 */
41 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
42 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
43 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
44 return 1;
45
46 /* Consult the list of known "good" drives */
47 if (ide_dma_good_drive(drive))
48 return 1;
49
50 return 0;
51}
52
53/**
54 * ide_dma_host_set - Enable/disable DMA on a host
55 * @drive: drive to control
56 *
57 * Enable/disable DMA on an IDE controller following generic
58 * bus-mastering IDE controller behaviour.
59 */
60
61void ide_dma_host_set(ide_drive_t *drive, int on)
62{
63 ide_hwif_t *hwif = drive->hwif;
64 u8 unit = drive->dn & 1;
65 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
66
67 if (on)
68 dma_stat |= (1 << (5 + unit));
69 else
70 dma_stat &= ~(1 << (5 + unit));
71
72 if (hwif->host_flags & IDE_HFLAG_MMIO)
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}
78EXPORT_SYMBOL_GPL(ide_dma_host_set);
79
80/**
81 * ide_build_dmatable - build IDE DMA table
82 *
83 * ide_build_dmatable() prepares a dma request. We map the command
84 * to get the pci bus addresses of the buffers and then build up
85 * the PRD table that the IDE layer wants to be fed.
86 *
87 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
88 * but at least one (e.g. CS5530) misinterprets it as zero (!).
89 * So we break the 64KB entry into two 32KB entries instead.
90 *
91 * Returns the number of built PRD entries if all went okay,
92 * returns 0 otherwise.
93 *
94 * May also be invoked from trm290.c
95 */
96
97int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
98{
99 ide_hwif_t *hwif = drive->hwif;
100 __le32 *table = (__le32 *)hwif->dmatable_cpu;
101 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
102 unsigned int count = 0;
103 int i;
104 struct scatterlist *sg;
105
106 hwif->sg_nents = ide_build_sglist(drive, rq);
107 if (hwif->sg_nents == 0)
108 return 0;
109
110 for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
111 u32 cur_addr, cur_len, xcount, bcount;
112
113 cur_addr = sg_dma_address(sg);
114 cur_len = sg_dma_len(sg);
115
116 /*
117 * Fill in the dma table, without crossing any 64kB boundaries.
118 * Most hardware requires 16-bit alignment of all blocks,
119 * but the trm290 requires 32-bit alignment.
120 */
121
122 while (cur_len) {
123 if (count++ >= PRD_ENTRIES)
124 goto use_pio_instead;
125
126 bcount = 0x10000 - (cur_addr & 0xffff);
127 if (bcount > cur_len)
128 bcount = cur_len;
129 *table++ = cpu_to_le32(cur_addr);
130 xcount = bcount & 0xffff;
131 if (is_trm290)
132 xcount = ((xcount >> 2) - 1) << 16;
133 else if (xcount == 0x0000) {
134 if (count++ >= PRD_ENTRIES)
135 goto use_pio_instead;
136 *table++ = cpu_to_le32(0x8000);
137 *table++ = cpu_to_le32(cur_addr + 0x8000);
138 xcount = 0x8000;
139 }
140 *table++ = cpu_to_le32(xcount);
141 cur_addr += bcount;
142 cur_len -= bcount;
143 }
144 }
145
146 if (count) {
147 if (!is_trm290)
148 *--table |= cpu_to_le32(0x80000000);
149 return count;
150 }
151
152use_pio_instead:
153 printk(KERN_ERR "%s: %s\n", drive->name,
154 count ? "DMA table too small" : "empty DMA table?");
155
156 ide_destroy_dmatable(drive);
157
158 return 0; /* revert to PIO for this request */
159}
160EXPORT_SYMBOL_GPL(ide_build_dmatable);
161
162/**
163 * ide_dma_setup - begin a DMA phase
164 * @drive: target device
165 *
166 * Build an IDE DMA PRD (IDE speak for scatter gather table)
167 * and then set up the DMA transfer registers for a device
168 * that follows generic IDE PCI DMA behaviour. Controllers can
169 * override this function if they need to
170 *
171 * Returns 0 on success. If a PIO fallback is required then 1
172 * is returned.
173 */
174
175int ide_dma_setup(ide_drive_t *drive)
176{
177 ide_hwif_t *hwif = drive->hwif;
178 struct request *rq = hwif->hwgroup->rq;
179 unsigned int reading;
180 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
181 u8 dma_stat;
182
183 if (rq_data_dir(rq))
184 reading = 0;
185 else
186 reading = 1 << 3;
187
188 /* fall back to pio! */
189 if (!ide_build_dmatable(drive, rq)) {
190 ide_map_sg(drive, rq);
191 return 1;
192 }
193
194 /* PRD table */
195 if (hwif->host_flags & IDE_HFLAG_MMIO)
196 writel(hwif->dmatable_dma,
197 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
198 else
199 outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
200
201 /* specify r/w */
202 if (mmio)
203 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
204 else
205 outb(reading, hwif->dma_base + ATA_DMA_CMD);
206
207 /* read DMA status for INTR & ERROR flags */
208 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
209
210 /* clear INTR & ERROR flags */
211 if (mmio)
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
217 drive->waiting_for_dma = 1;
218 return 0;
219}
220EXPORT_SYMBOL_GPL(ide_dma_setup);
221
222/**
223 * dma_timer_expiry - handle a DMA timeout
224 * @drive: Drive that timed out
225 *
226 * An IDE DMA transfer timed out. In the event of an error we ask
227 * the driver to resolve the problem, if a DMA transfer is still
228 * in progress we continue to wait (arguably we need to add a
229 * secondary 'I don't care what the drive thinks' timeout here)
230 * Finally if we have an interrupt we let it complete the I/O.
231 * But only one time - we clear expiry and if it's still not
232 * completed after WAIT_CMD, we error and retry in PIO.
233 * This can occur if an interrupt is lost or due to hang or bugs.
234 */
235
236static int dma_timer_expiry(ide_drive_t *drive)
237{
238 ide_hwif_t *hwif = drive->hwif;
239 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
240
241 printk(KERN_WARNING "%s: %s: DMA status (0x%02x)\n",
242 drive->name, __func__, dma_stat);
243
244 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
245 return WAIT_CMD;
246
247 hwif->hwgroup->expiry = NULL; /* one free ride for now */
248
249 /* 1 dmaing, 2 error, 4 intr */
250 if (dma_stat & 2) /* ERROR */
251 return -1;
252
253 if (dma_stat & 1) /* DMAing */
254 return WAIT_CMD;
255
256 if (dma_stat & 4) /* Got an Interrupt */
257 return WAIT_CMD;
258
259 return 0; /* Status is unknown -- reset the bus */
260}
261
262void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
263{
264 /* issue cmd to drive */
265 ide_execute_command(drive, command, &ide_dma_intr, 2 * WAIT_CMD,
266 dma_timer_expiry);
267}
268EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
269
270void ide_dma_start(ide_drive_t *drive)
271{
272 ide_hwif_t *hwif = drive->hwif;
273 u8 dma_cmd;
274
275 /* Note that this is done *after* the cmd has
276 * been issued to the drive, as per the BM-IDE spec.
277 * The Promise Ultra33 doesn't work correctly when
278 * we do this part before issuing the drive cmd.
279 */
280 if (hwif->host_flags & IDE_HFLAG_MMIO) {
281 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
282 /* start DMA */
283 writeb(dma_cmd | 1,
284 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
285 } else {
286 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
287 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
288 }
289
290 wmb();
291}
292EXPORT_SYMBOL_GPL(ide_dma_start);
293
294/* returns 1 on error, 0 otherwise */
295int ide_dma_end(ide_drive_t *drive)
296{
297 ide_hwif_t *hwif = drive->hwif;
298 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
299 u8 dma_stat = 0, dma_cmd = 0;
300
301 drive->waiting_for_dma = 0;
302
303 if (mmio) {
304 /* get DMA command mode */
305 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
306 /* stop DMA */
307 writeb(dma_cmd & ~1,
308 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
309 } else {
310 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
311 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
312 }
313
314 /* get DMA status */
315 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
316
317 if (mmio)
318 /* clear the INTR & ERROR bits */
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
324 /* purge DMA mappings */
325 ide_destroy_dmatable(drive);
326 /* verify good DMA status */
327 wmb();
328 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
329}
330EXPORT_SYMBOL_GPL(ide_dma_end);
331
332/* returns 1 if dma irq issued, 0 otherwise */
333int ide_dma_test_irq(ide_drive_t *drive)
334{
335 ide_hwif_t *hwif = drive->hwif;
336 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
337
338 /* return 1 if INTR asserted */
339 if ((dma_stat & 4) == 4)
340 return 1;
341
342 return 0;
343}
344EXPORT_SYMBOL_GPL(ide_dma_test_irq);
345
346const struct ide_dma_ops sff_dma_ops = {
347 .dma_host_set = ide_dma_host_set,
348 .dma_setup = ide_dma_setup,
349 .dma_exec_cmd = ide_dma_exec_cmd,
350 .dma_start = ide_dma_start,
351 .dma_end = ide_dma_end,
352 .dma_test_irq = ide_dma_test_irq,
353 .dma_timeout = ide_dma_timeout,
354 .dma_lost_irq = ide_dma_lost_irq,
355};
356EXPORT_SYMBOL_GPL(sff_dma_ops);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 3fa07c0aeaa4..fffd11717b2d 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -28,24 +28,13 @@
28 * for supplying a Promise UDMA board & WD UDMA drive for this work! 28 * for supplying a Promise UDMA board & WD UDMA drive for this work!
29 */ 29 */
30 30
31#include <linux/module.h>
32#include <linux/types.h> 31#include <linux/types.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/timer.h>
35#include <linux/mm.h>
36#include <linux/interrupt.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/ide.h> 33#include <linux/ide.h>
40#include <linux/delay.h>
41#include <linux/scatterlist.h> 34#include <linux/scatterlist.h>
42#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
43 36
44#include <asm/io.h> 37static const struct drive_list_entry drive_whitelist[] = {
45#include <asm/irq.h>
46
47static const struct drive_list_entry drive_whitelist [] = {
48
49 { "Micropolis 2112A" , NULL }, 38 { "Micropolis 2112A" , NULL },
50 { "CONNER CTMA 4000" , NULL }, 39 { "CONNER CTMA 4000" , NULL },
51 { "CONNER CTT8000-A" , NULL }, 40 { "CONNER CTT8000-A" , NULL },
@@ -53,8 +42,7 @@ static const struct drive_list_entry drive_whitelist [] = {
53 { NULL , NULL } 42 { NULL , NULL }
54}; 43};
55 44
56static const struct drive_list_entry drive_blacklist [] = { 45static const struct drive_list_entry drive_blacklist[] = {
57
58 { "WDC AC11000H" , NULL }, 46 { "WDC AC11000H" , NULL },
59 { "WDC AC22100H" , NULL }, 47 { "WDC AC22100H" , NULL },
60 { "WDC AC32500H" , NULL }, 48 { "WDC AC32500H" , NULL },
@@ -94,11 +82,11 @@ static const struct drive_list_entry drive_blacklist [] = {
94 * ide_dma_intr - IDE DMA interrupt handler 82 * ide_dma_intr - IDE DMA interrupt handler
95 * @drive: the drive the interrupt is for 83 * @drive: the drive the interrupt is for
96 * 84 *
97 * Handle an interrupt completing a read/write DMA transfer on an 85 * Handle an interrupt completing a read/write DMA transfer on an
98 * IDE device 86 * IDE device
99 */ 87 */
100 88
101ide_startstop_t ide_dma_intr (ide_drive_t *drive) 89ide_startstop_t ide_dma_intr(ide_drive_t *drive)
102{ 90{
103 ide_hwif_t *hwif = drive->hwif; 91 ide_hwif_t *hwif = drive->hwif;
104 u8 stat = 0, dma_stat = 0; 92 u8 stat = 0, dma_stat = 0;
@@ -106,22 +94,21 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
106 dma_stat = hwif->dma_ops->dma_end(drive); 94 dma_stat = hwif->dma_ops->dma_end(drive);
107 stat = hwif->tp_ops->read_status(hwif); 95 stat = hwif->tp_ops->read_status(hwif);
108 96
109 if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) { 97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
110 if (!dma_stat) { 98 if (!dma_stat) {
111 struct request *rq = HWGROUP(drive)->rq; 99 struct request *rq = hwif->hwgroup->rq;
112 100
113 task_end_request(drive, rq, stat); 101 task_end_request(drive, rq, stat);
114 return ide_stopped; 102 return ide_stopped;
115 } 103 }
116 printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", 104 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
117 drive->name, dma_stat); 105 drive->name, __func__, dma_stat);
118 } 106 }
119 return ide_error(drive, "dma_intr", stat); 107 return ide_error(drive, "dma_intr", stat);
120} 108}
121
122EXPORT_SYMBOL_GPL(ide_dma_intr); 109EXPORT_SYMBOL_GPL(ide_dma_intr);
123 110
124static int ide_dma_good_drive(ide_drive_t *drive) 111int ide_dma_good_drive(ide_drive_t *drive)
125{ 112{
126 return ide_in_drive_list(drive->id, drive_whitelist); 113 return ide_in_drive_list(drive->id, drive_whitelist);
127} 114}
@@ -139,7 +126,7 @@ static int ide_dma_good_drive(ide_drive_t *drive)
139 126
140int ide_build_sglist(ide_drive_t *drive, struct request *rq) 127int ide_build_sglist(ide_drive_t *drive, struct request *rq)
141{ 128{
142 ide_hwif_t *hwif = HWIF(drive); 129 ide_hwif_t *hwif = drive->hwif;
143 struct scatterlist *sg = hwif->sg_table; 130 struct scatterlist *sg = hwif->sg_table;
144 131
145 ide_map_sg(drive, rq); 132 ide_map_sg(drive, rq);
@@ -152,106 +139,8 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
152 return dma_map_sg(hwif->dev, sg, hwif->sg_nents, 139 return dma_map_sg(hwif->dev, sg, hwif->sg_nents,
153 hwif->sg_dma_direction); 140 hwif->sg_dma_direction);
154} 141}
155
156EXPORT_SYMBOL_GPL(ide_build_sglist); 142EXPORT_SYMBOL_GPL(ide_build_sglist);
157 143
158#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
159/**
160 * ide_build_dmatable - build IDE DMA table
161 *
162 * ide_build_dmatable() prepares a dma request. We map the command
163 * to get the pci bus addresses of the buffers and then build up
164 * the PRD table that the IDE layer wants to be fed. The code
165 * knows about the 64K wrap bug in the CS5530.
166 *
167 * Returns the number of built PRD entries if all went okay,
168 * returns 0 otherwise.
169 *
170 * May also be invoked from trm290.c
171 */
172
173int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
174{
175 ide_hwif_t *hwif = HWIF(drive);
176 __le32 *table = (__le32 *)hwif->dmatable_cpu;
177 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
178 unsigned int count = 0;
179 int i;
180 struct scatterlist *sg;
181
182 hwif->sg_nents = i = ide_build_sglist(drive, rq);
183
184 if (!i)
185 return 0;
186
187 sg = hwif->sg_table;
188 while (i) {
189 u32 cur_addr;
190 u32 cur_len;
191
192 cur_addr = sg_dma_address(sg);
193 cur_len = sg_dma_len(sg);
194
195 /*
196 * Fill in the dma table, without crossing any 64kB boundaries.
197 * Most hardware requires 16-bit alignment of all blocks,
198 * but the trm290 requires 32-bit alignment.
199 */
200
201 while (cur_len) {
202 if (count++ >= PRD_ENTRIES) {
203 printk(KERN_ERR "%s: DMA table too small\n", drive->name);
204 goto use_pio_instead;
205 } else {
206 u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff);
207
208 if (bcount > cur_len)
209 bcount = cur_len;
210 *table++ = cpu_to_le32(cur_addr);
211 xcount = bcount & 0xffff;
212 if (is_trm290)
213 xcount = ((xcount >> 2) - 1) << 16;
214 else if (xcount == 0x0000) {
215 /*
216 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
217 * but at least one (e.g. CS5530) misinterprets it as zero (!).
218 * So here we break the 64KB entry into two 32KB entries instead.
219 */
220 if (count++ >= PRD_ENTRIES) {
221 printk(KERN_ERR "%s: DMA table too small\n", drive->name);
222 goto use_pio_instead;
223 }
224 *table++ = cpu_to_le32(0x8000);
225 *table++ = cpu_to_le32(cur_addr + 0x8000);
226 xcount = 0x8000;
227 }
228 *table++ = cpu_to_le32(xcount);
229 cur_addr += bcount;
230 cur_len -= bcount;
231 }
232 }
233
234 sg = sg_next(sg);
235 i--;
236 }
237
238 if (count) {
239 if (!is_trm290)
240 *--table |= cpu_to_le32(0x80000000);
241 return count;
242 }
243
244 printk(KERN_ERR "%s: empty DMA table?\n", drive->name);
245
246use_pio_instead:
247 ide_destroy_dmatable(drive);
248
249 return 0; /* revert to PIO for this request */
250}
251
252EXPORT_SYMBOL_GPL(ide_build_dmatable);
253#endif
254
255/** 144/**
256 * ide_destroy_dmatable - clean up DMA mapping 145 * ide_destroy_dmatable - clean up DMA mapping
257 * @drive: The drive to unmap 146 * @drive: The drive to unmap
@@ -262,146 +151,30 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
262 * an oops as only one mapping can be live for each target at a given 151 * an oops as only one mapping can be live for each target at a given
263 * time. 152 * time.
264 */ 153 */
265 154
266void ide_destroy_dmatable (ide_drive_t *drive) 155void ide_destroy_dmatable(ide_drive_t *drive)
267{ 156{
268 ide_hwif_t *hwif = drive->hwif; 157 ide_hwif_t *hwif = drive->hwif;
269 158
270 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents, 159 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents,
271 hwif->sg_dma_direction); 160 hwif->sg_dma_direction);
272} 161}
273
274EXPORT_SYMBOL_GPL(ide_destroy_dmatable); 162EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
275 163
276#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
277/**
278 * config_drive_for_dma - attempt to activate IDE DMA
279 * @drive: the drive to place in DMA mode
280 *
281 * If the drive supports at least mode 2 DMA or UDMA of any kind
282 * then attempt to place it into DMA mode. Drives that are known to
283 * support DMA but predate the DMA properties or that are known
284 * to have DMA handling bugs are also set up appropriately based
285 * on the good/bad drive lists.
286 */
287
288static int config_drive_for_dma (ide_drive_t *drive)
289{
290 ide_hwif_t *hwif = drive->hwif;
291 struct hd_driveid *id = drive->id;
292
293 if (drive->media != ide_disk) {
294 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
295 return 0;
296 }
297
298 /*
299 * Enable DMA on any drive that has
300 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
301 */
302 if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f))
303 return 1;
304
305 /*
306 * Enable DMA on any drive that has mode2 DMA
307 * (multi or single) enabled
308 */
309 if (id->field_valid & 2) /* regular DMA */
310 if ((id->dma_mword & 0x404) == 0x404 ||
311 (id->dma_1word & 0x404) == 0x404)
312 return 1;
313
314 /* Consult the list of known "good" drives */
315 if (ide_dma_good_drive(drive))
316 return 1;
317
318 return 0;
319}
320
321/**
322 * dma_timer_expiry - handle a DMA timeout
323 * @drive: Drive that timed out
324 *
325 * An IDE DMA transfer timed out. In the event of an error we ask
326 * the driver to resolve the problem, if a DMA transfer is still
327 * in progress we continue to wait (arguably we need to add a
328 * secondary 'I don't care what the drive thinks' timeout here)
329 * Finally if we have an interrupt we let it complete the I/O.
330 * But only one time - we clear expiry and if it's still not
331 * completed after WAIT_CMD, we error and retry in PIO.
332 * This can occur if an interrupt is lost or due to hang or bugs.
333 */
334
335static int dma_timer_expiry (ide_drive_t *drive)
336{
337 ide_hwif_t *hwif = HWIF(drive);
338 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
339
340 printk(KERN_WARNING "%s: dma_timer_expiry: dma status == 0x%02x\n",
341 drive->name, dma_stat);
342
343 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
344 return WAIT_CMD;
345
346 HWGROUP(drive)->expiry = NULL; /* one free ride for now */
347
348 /* 1 dmaing, 2 error, 4 intr */
349 if (dma_stat & 2) /* ERROR */
350 return -1;
351
352 if (dma_stat & 1) /* DMAing */
353 return WAIT_CMD;
354
355 if (dma_stat & 4) /* Got an Interrupt */
356 return WAIT_CMD;
357
358 return 0; /* Status is unknown -- reset the bus */
359}
360
361/**
362 * ide_dma_host_set - Enable/disable DMA on a host
363 * @drive: drive to control
364 *
365 * Enable/disable DMA on an IDE controller following generic
366 * bus-mastering IDE controller behaviour.
367 */
368
369void ide_dma_host_set(ide_drive_t *drive, int on)
370{
371 ide_hwif_t *hwif = HWIF(drive);
372 u8 unit = (drive->select.b.unit & 0x01);
373 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
374
375 if (on)
376 dma_stat |= (1 << (5 + unit));
377 else
378 dma_stat &= ~(1 << (5 + unit));
379
380 if (hwif->host_flags & IDE_HFLAG_MMIO)
381 writeb(dma_stat,
382 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
383 else
384 outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
385}
386
387EXPORT_SYMBOL_GPL(ide_dma_host_set);
388#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
389
390/** 164/**
391 * ide_dma_off_quietly - Generic DMA kill 165 * ide_dma_off_quietly - Generic DMA kill
392 * @drive: drive to control 166 * @drive: drive to control
393 * 167 *
394 * Turn off the current DMA on this IDE controller. 168 * Turn off the current DMA on this IDE controller.
395 */ 169 */
396 170
397void ide_dma_off_quietly(ide_drive_t *drive) 171void ide_dma_off_quietly(ide_drive_t *drive)
398{ 172{
399 drive->using_dma = 0; 173 drive->dev_flags &= ~IDE_DFLAG_USING_DMA;
400 ide_toggle_bounce(drive, 0); 174 ide_toggle_bounce(drive, 0);
401 175
402 drive->hwif->dma_ops->dma_host_set(drive, 0); 176 drive->hwif->dma_ops->dma_host_set(drive, 0);
403} 177}
404
405EXPORT_SYMBOL(ide_dma_off_quietly); 178EXPORT_SYMBOL(ide_dma_off_quietly);
406 179
407/** 180/**
@@ -417,7 +190,6 @@ void ide_dma_off(ide_drive_t *drive)
417 printk(KERN_INFO "%s: DMA disabled\n", drive->name); 190 printk(KERN_INFO "%s: DMA disabled\n", drive->name);
418 ide_dma_off_quietly(drive); 191 ide_dma_off_quietly(drive);
419} 192}
420
421EXPORT_SYMBOL(ide_dma_off); 193EXPORT_SYMBOL(ide_dma_off);
422 194
423/** 195/**
@@ -429,179 +201,24 @@ EXPORT_SYMBOL(ide_dma_off);
429 201
430void ide_dma_on(ide_drive_t *drive) 202void ide_dma_on(ide_drive_t *drive)
431{ 203{
432 drive->using_dma = 1; 204 drive->dev_flags |= IDE_DFLAG_USING_DMA;
433 ide_toggle_bounce(drive, 1); 205 ide_toggle_bounce(drive, 1);
434 206
435 drive->hwif->dma_ops->dma_host_set(drive, 1); 207 drive->hwif->dma_ops->dma_host_set(drive, 1);
436} 208}
437 209
438#ifdef CONFIG_BLK_DEV_IDEDMA_SFF 210int __ide_dma_bad_drive(ide_drive_t *drive)
439/**
440 * ide_dma_setup - begin a DMA phase
441 * @drive: target device
442 *
443 * Build an IDE DMA PRD (IDE speak for scatter gather table)
444 * and then set up the DMA transfer registers for a device
445 * that follows generic IDE PCI DMA behaviour. Controllers can
446 * override this function if they need to
447 *
448 * Returns 0 on success. If a PIO fallback is required then 1
449 * is returned.
450 */
451
452int ide_dma_setup(ide_drive_t *drive)
453{ 211{
454 ide_hwif_t *hwif = drive->hwif; 212 u16 *id = drive->id;
455 struct request *rq = HWGROUP(drive)->rq;
456 unsigned int reading;
457 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
458 u8 dma_stat;
459
460 if (rq_data_dir(rq))
461 reading = 0;
462 else
463 reading = 1 << 3;
464
465 /* fall back to pio! */
466 if (!ide_build_dmatable(drive, rq)) {
467 ide_map_sg(drive, rq);
468 return 1;
469 }
470
471 /* PRD table */
472 if (hwif->host_flags & IDE_HFLAG_MMIO)
473 writel(hwif->dmatable_dma,
474 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
475 else
476 outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
477
478 /* specify r/w */
479 if (mmio)
480 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
481 else
482 outb(reading, hwif->dma_base + ATA_DMA_CMD);
483
484 /* read DMA status for INTR & ERROR flags */
485 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
486
487 /* clear INTR & ERROR flags */
488 if (mmio)
489 writeb(dma_stat | 6,
490 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
491 else
492 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
493
494 drive->waiting_for_dma = 1;
495 return 0;
496}
497
498EXPORT_SYMBOL_GPL(ide_dma_setup);
499
500void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
501{
502 /* issue cmd to drive */
503 ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);
504}
505EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
506
507void ide_dma_start(ide_drive_t *drive)
508{
509 ide_hwif_t *hwif = drive->hwif;
510 u8 dma_cmd;
511
512 /* Note that this is done *after* the cmd has
513 * been issued to the drive, as per the BM-IDE spec.
514 * The Promise Ultra33 doesn't work correctly when
515 * we do this part before issuing the drive cmd.
516 */
517 if (hwif->host_flags & IDE_HFLAG_MMIO) {
518 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
519 /* start DMA */
520 writeb(dma_cmd | 1,
521 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
522 } else {
523 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
524 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
525 }
526
527 hwif->dma = 1;
528 wmb();
529}
530
531EXPORT_SYMBOL_GPL(ide_dma_start);
532
533/* returns 1 on error, 0 otherwise */
534int __ide_dma_end (ide_drive_t *drive)
535{
536 ide_hwif_t *hwif = drive->hwif;
537 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
538 u8 dma_stat = 0, dma_cmd = 0;
539
540 drive->waiting_for_dma = 0;
541
542 if (mmio) {
543 /* get DMA command mode */
544 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
545 /* stop DMA */
546 writeb(dma_cmd & ~1,
547 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
548 } else {
549 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
550 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
551 }
552
553 /* get DMA status */
554 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
555
556 if (mmio)
557 /* clear the INTR & ERROR bits */
558 writeb(dma_stat | 6,
559 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
560 else
561 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
562
563 /* purge DMA mappings */
564 ide_destroy_dmatable(drive);
565 /* verify good DMA status */
566 hwif->dma = 0;
567 wmb();
568 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
569}
570
571EXPORT_SYMBOL(__ide_dma_end);
572
573/* returns 1 if dma irq issued, 0 otherwise */
574int ide_dma_test_irq(ide_drive_t *drive)
575{
576 ide_hwif_t *hwif = HWIF(drive);
577 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
578
579 /* return 1 if INTR asserted */
580 if ((dma_stat & 4) == 4)
581 return 1;
582 if (!drive->waiting_for_dma)
583 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
584 drive->name, __func__);
585 return 0;
586}
587EXPORT_SYMBOL_GPL(ide_dma_test_irq);
588#else
589static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
590#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
591
592int __ide_dma_bad_drive (ide_drive_t *drive)
593{
594 struct hd_driveid *id = drive->id;
595 213
596 int blacklist = ide_in_drive_list(id, drive_blacklist); 214 int blacklist = ide_in_drive_list(id, drive_blacklist);
597 if (blacklist) { 215 if (blacklist) {
598 printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n", 216 printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n",
599 drive->name, id->model); 217 drive->name, (char *)&id[ATA_ID_PROD]);
600 return blacklist; 218 return blacklist;
601 } 219 }
602 return 0; 220 return 0;
603} 221}
604
605EXPORT_SYMBOL(__ide_dma_bad_drive); 222EXPORT_SYMBOL(__ide_dma_bad_drive);
606 223
607static const u8 xfer_mode_bases[] = { 224static const u8 xfer_mode_bases[] = {
@@ -612,21 +229,21 @@ static const u8 xfer_mode_bases[] = {
612 229
613static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode) 230static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
614{ 231{
615 struct hd_driveid *id = drive->id; 232 u16 *id = drive->id;
616 ide_hwif_t *hwif = drive->hwif; 233 ide_hwif_t *hwif = drive->hwif;
617 const struct ide_port_ops *port_ops = hwif->port_ops; 234 const struct ide_port_ops *port_ops = hwif->port_ops;
618 unsigned int mask = 0; 235 unsigned int mask = 0;
619 236
620 switch(base) { 237 switch (base) {
621 case XFER_UDMA_0: 238 case XFER_UDMA_0:
622 if ((id->field_valid & 4) == 0) 239 if ((id[ATA_ID_FIELD_VALID] & 4) == 0)
623 break; 240 break;
624 241
625 if (port_ops && port_ops->udma_filter) 242 if (port_ops && port_ops->udma_filter)
626 mask = port_ops->udma_filter(drive); 243 mask = port_ops->udma_filter(drive);
627 else 244 else
628 mask = hwif->ultra_mask; 245 mask = hwif->ultra_mask;
629 mask &= id->dma_ultra; 246 mask &= id[ATA_ID_UDMA_MODES];
630 247
631 /* 248 /*
632 * avoid false cable warning from eighty_ninty_three() 249 * avoid false cable warning from eighty_ninty_three()
@@ -637,19 +254,19 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
637 } 254 }
638 break; 255 break;
639 case XFER_MW_DMA_0: 256 case XFER_MW_DMA_0:
640 if ((id->field_valid & 2) == 0) 257 if ((id[ATA_ID_FIELD_VALID] & 2) == 0)
641 break; 258 break;
642 if (port_ops && port_ops->mdma_filter) 259 if (port_ops && port_ops->mdma_filter)
643 mask = port_ops->mdma_filter(drive); 260 mask = port_ops->mdma_filter(drive);
644 else 261 else
645 mask = hwif->mwdma_mask; 262 mask = hwif->mwdma_mask;
646 mask &= id->dma_mword; 263 mask &= id[ATA_ID_MWDMA_MODES];
647 break; 264 break;
648 case XFER_SW_DMA_0: 265 case XFER_SW_DMA_0:
649 if (id->field_valid & 2) { 266 if (id[ATA_ID_FIELD_VALID] & 2) {
650 mask = id->dma_1word & hwif->swdma_mask; 267 mask = id[ATA_ID_SWDMA_MODES] & hwif->swdma_mask;
651 } else if (id->tDMA) { 268 } else if (id[ATA_ID_OLD_DMA_MODES] >> 8) {
652 u8 mode = id->tDMA; 269 u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8;
653 270
654 /* 271 /*
655 * if the mode is valid convert it to the mask 272 * if the mode is valid convert it to the mask
@@ -706,7 +323,8 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
706 /* 323 /*
707 * is this correct? 324 * is this correct?
708 */ 325 */
709 if (ide_dma_good_drive(drive) && drive->id->eide_dma_time < 150) 326 if (ide_dma_good_drive(drive) &&
327 drive->id[ATA_ID_EIDE_DMA_TIME] < 150)
710 mode = XFER_MW_DMA_1; 328 mode = XFER_MW_DMA_1;
711 } 329 }
712 330
@@ -717,7 +335,6 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
717 335
718 return mode; 336 return mode;
719} 337}
720
721EXPORT_SYMBOL_GPL(ide_find_dma_mode); 338EXPORT_SYMBOL_GPL(ide_find_dma_mode);
722 339
723static int ide_tune_dma(ide_drive_t *drive) 340static int ide_tune_dma(ide_drive_t *drive)
@@ -725,7 +342,8 @@ static int ide_tune_dma(ide_drive_t *drive)
725 ide_hwif_t *hwif = drive->hwif; 342 ide_hwif_t *hwif = drive->hwif;
726 u8 speed; 343 u8 speed;
727 344
728 if (drive->nodma || (drive->id->capability & 1) == 0) 345 if (ata_id_has_dma(drive->id) == 0 ||
346 (drive->dev_flags & IDE_DFLAG_NODMA))
729 return 0; 347 return 0;
730 348
731 /* consult the list of known "bad" drives */ 349 /* consult the list of known "bad" drives */
@@ -767,13 +385,15 @@ static int ide_dma_check(ide_drive_t *drive)
767 385
768int ide_id_dma_bug(ide_drive_t *drive) 386int ide_id_dma_bug(ide_drive_t *drive)
769{ 387{
770 struct hd_driveid *id = drive->id; 388 u16 *id = drive->id;
771 389
772 if (id->field_valid & 4) { 390 if (id[ATA_ID_FIELD_VALID] & 4) {
773 if ((id->dma_ultra >> 8) && (id->dma_mword >> 8)) 391 if ((id[ATA_ID_UDMA_MODES] >> 8) &&
392 (id[ATA_ID_MWDMA_MODES] >> 8))
774 goto err_out; 393 goto err_out;
775 } else if (id->field_valid & 2) { 394 } else if (id[ATA_ID_FIELD_VALID] & 2) {
776 if ((id->dma_mword >> 8) && (id->dma_1word >> 8)) 395 if ((id[ATA_ID_MWDMA_MODES] >> 8) &&
396 (id[ATA_ID_SWDMA_MODES] >> 8))
777 goto err_out; 397 goto err_out;
778 } 398 }
779 return 0; 399 return 0;
@@ -823,66 +443,59 @@ void ide_check_dma_crc(ide_drive_t *drive)
823 ide_dma_on(drive); 443 ide_dma_on(drive);
824} 444}
825 445
826#ifdef CONFIG_BLK_DEV_IDEDMA_SFF 446void ide_dma_lost_irq(ide_drive_t *drive)
827void ide_dma_lost_irq (ide_drive_t *drive)
828{ 447{
829 printk("%s: DMA interrupt recovery\n", drive->name); 448 printk(KERN_ERR "%s: DMA interrupt recovery\n", drive->name);
830} 449}
450EXPORT_SYMBOL_GPL(ide_dma_lost_irq);
831 451
832EXPORT_SYMBOL(ide_dma_lost_irq); 452void ide_dma_timeout(ide_drive_t *drive)
833
834void ide_dma_timeout (ide_drive_t *drive)
835{ 453{
836 ide_hwif_t *hwif = HWIF(drive); 454 ide_hwif_t *hwif = drive->hwif;
837 455
838 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); 456 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name);
839 457
840 if (hwif->dma_ops->dma_test_irq(drive)) 458 if (hwif->dma_ops->dma_test_irq(drive))
841 return; 459 return;
842 460
461 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
462
843 hwif->dma_ops->dma_end(drive); 463 hwif->dma_ops->dma_end(drive);
844} 464}
845 465EXPORT_SYMBOL_GPL(ide_dma_timeout);
846EXPORT_SYMBOL(ide_dma_timeout);
847 466
848void ide_release_dma_engine(ide_hwif_t *hwif) 467void ide_release_dma_engine(ide_hwif_t *hwif)
849{ 468{
850 if (hwif->dmatable_cpu) { 469 if (hwif->dmatable_cpu) {
851 struct pci_dev *pdev = to_pci_dev(hwif->dev); 470 int prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
852 471
853 pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES, 472 dma_free_coherent(hwif->dev, prd_size,
854 hwif->dmatable_cpu, hwif->dmatable_dma); 473 hwif->dmatable_cpu, hwif->dmatable_dma);
855 hwif->dmatable_cpu = NULL; 474 hwif->dmatable_cpu = NULL;
856 } 475 }
857} 476}
477EXPORT_SYMBOL_GPL(ide_release_dma_engine);
858 478
859int ide_allocate_dma_engine(ide_hwif_t *hwif) 479int ide_allocate_dma_engine(ide_hwif_t *hwif)
860{ 480{
861 struct pci_dev *pdev = to_pci_dev(hwif->dev); 481 int prd_size;
862 482
863 hwif->dmatable_cpu = pci_alloc_consistent(pdev, 483 if (hwif->prd_max_nents == 0)
864 PRD_ENTRIES * PRD_BYTES, 484 hwif->prd_max_nents = PRD_ENTRIES;
865 &hwif->dmatable_dma); 485 if (hwif->prd_ent_size == 0)
486 hwif->prd_ent_size = PRD_BYTES;
866 487
867 if (hwif->dmatable_cpu) 488 prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
868 return 0;
869 489
870 printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n", 490 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, prd_size,
491 &hwif->dmatable_dma,
492 GFP_ATOMIC);
493 if (hwif->dmatable_cpu == NULL) {
494 printk(KERN_ERR "%s: unable to allocate PRD table\n",
871 hwif->name); 495 hwif->name);
496 return -ENOMEM;
497 }
872 498
873 return 1; 499 return 0;
874} 500}
875EXPORT_SYMBOL_GPL(ide_allocate_dma_engine); 501EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
876
877const struct ide_dma_ops sff_dma_ops = {
878 .dma_host_set = ide_dma_host_set,
879 .dma_setup = ide_dma_setup,
880 .dma_exec_cmd = ide_dma_exec_cmd,
881 .dma_start = ide_dma_start,
882 .dma_end = __ide_dma_end,
883 .dma_test_irq = ide_dma_test_irq,
884 .dma_timeout = ide_dma_timeout,
885 .dma_lost_irq = ide_dma_lost_irq,
886};
887EXPORT_SYMBOL_GPL(sff_dma_ops);
888#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index e9034c0125f3..aeb1ad782f54 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -15,9 +15,6 @@
15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002 15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
16 */ 16 */
17 17
18#define IDEFLOPPY_VERSION "1.00"
19
20#include <linux/module.h>
21#include <linux/types.h> 18#include <linux/types.h>
22#include <linux/string.h> 19#include <linux/string.h>
23#include <linux/kernel.h> 20#include <linux/kernel.h>
@@ -31,8 +28,10 @@
31#include <linux/slab.h> 28#include <linux/slab.h>
32#include <linux/cdrom.h> 29#include <linux/cdrom.h>
33#include <linux/ide.h> 30#include <linux/ide.h>
31#include <linux/hdreg.h>
34#include <linux/bitops.h> 32#include <linux/bitops.h>
35#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/scatterlist.h>
36 35
37#include <scsi/scsi_ioctl.h> 36#include <scsi/scsi_ioctl.h>
38 37
@@ -42,22 +41,7 @@
42#include <linux/io.h> 41#include <linux/io.h>
43#include <asm/unaligned.h> 42#include <asm/unaligned.h>
44 43
45/* define to see debug info */ 44#include "ide-floppy.h"
46#define IDEFLOPPY_DEBUG_LOG 0
47
48/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
49#define IDEFLOPPY_DEBUG(fmt, args...)
50
51#if IDEFLOPPY_DEBUG_LOG
52#define debug_log(fmt, args...) \
53 printk(KERN_INFO "ide-floppy: " fmt, ## args)
54#else
55#define debug_log(fmt, args...) do {} while (0)
56#endif
57
58
59/* Some drives require a longer irq timeout. */
60#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
61 45
62/* 46/*
63 * After each failed packet command we issue a request sense command and retry 47 * After each failed packet command we issue a request sense command and retry
@@ -65,19 +49,6 @@
65 */ 49 */
66#define IDEFLOPPY_MAX_PC_RETRIES 3 50#define IDEFLOPPY_MAX_PC_RETRIES 3
67 51
68/*
69 * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
70 * bytes.
71 */
72#define IDEFLOPPY_PC_BUFFER_SIZE 256
73
74/*
75 * In various places in the driver, we need to allocate storage for packet
76 * commands and requests, which will remain valid while we leave the driver to
77 * wait for an interrupt or a timeout event.
78 */
79#define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
80
81/* format capacities descriptor codes */ 52/* format capacities descriptor codes */
82#define CAPACITY_INVALID 0x00 53#define CAPACITY_INVALID 0x00
83#define CAPACITY_UNFORMATTED 0x01 54#define CAPACITY_UNFORMATTED 0x01
@@ -85,124 +56,39 @@
85#define CAPACITY_NO_CARTRIDGE 0x03 56#define CAPACITY_NO_CARTRIDGE 0x03
86 57
87/* 58/*
88 * Most of our global data which we need to save even as we leave the driver 59 * The following delay solves a problem with ATAPI Zip 100 drive where BSY bit
89 * due to an interrupt or a timer event is stored in a variable of type 60 * was apparently being deasserted before the unit was ready to receive data.
90 * idefloppy_floppy_t, defined below.
91 */ 61 */
92typedef struct ide_floppy_obj { 62#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */
93 ide_drive_t *drive;
94 ide_driver_t *driver;
95 struct gendisk *disk;
96 struct kref kref;
97 unsigned int openers; /* protected by BKL for now */
98
99 /* Current packet command */
100 struct ide_atapi_pc *pc;
101 /* Last failed packet command */
102 struct ide_atapi_pc *failed_pc;
103 /* Packet command stack */
104 struct ide_atapi_pc pc_stack[IDEFLOPPY_PC_STACK];
105 /* Next free packet command storage space */
106 int pc_stack_index;
107 struct request rq_stack[IDEFLOPPY_PC_STACK];
108 /* We implement a circular array */
109 int rq_stack_index;
110
111 /* Last error information */
112 u8 sense_key, asc, ascq;
113 /* delay this long before sending packet command */
114 u8 ticks;
115 int progress_indication;
116
117 /* Device information */
118 /* Current format */
119 int blocks, block_size, bs_factor;
120 /* Last format capacity descriptor */
121 u8 cap_desc[8];
122 /* Copy of the flexible disk page */
123 u8 flexible_disk_page[32];
124 /* Write protect */
125 int wp;
126 /* Supports format progress report */
127 int srfp;
128} idefloppy_floppy_t;
129
130#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
131
132/* Defines for the MODE SENSE command */
133#define MODE_SENSE_CURRENT 0x00
134#define MODE_SENSE_CHANGEABLE 0x01
135#define MODE_SENSE_DEFAULT 0x02
136#define MODE_SENSE_SAVED 0x03
137
138/* IOCTLs used in low-level formatting. */
139#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
140#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
141#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
142#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
143 63
144/* Error code returned in rq->errors to the higher part of the driver. */ 64/* Error code returned in rq->errors to the higher part of the driver. */
145#define IDEFLOPPY_ERROR_GENERAL 101 65#define IDEFLOPPY_ERROR_GENERAL 101
146 66
147/* 67/*
148 * Pages of the SELECT SENSE / MODE SENSE packet commands.
149 * See SFF-8070i spec.
150 */
151#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
152#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
153
154static DEFINE_MUTEX(idefloppy_ref_mutex);
155
156#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
157
158#define ide_floppy_g(disk) \
159 container_of((disk)->private_data, struct ide_floppy_obj, driver)
160
161static void idefloppy_cleanup_obj(struct kref *);
162
163static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
164{
165 struct ide_floppy_obj *floppy = NULL;
166
167 mutex_lock(&idefloppy_ref_mutex);
168 floppy = ide_floppy_g(disk);
169 if (floppy) {
170 if (ide_device_get(floppy->drive))
171 floppy = NULL;
172 else
173 kref_get(&floppy->kref);
174 }
175 mutex_unlock(&idefloppy_ref_mutex);
176 return floppy;
177}
178
179static void ide_floppy_put(struct ide_floppy_obj *floppy)
180{
181 ide_drive_t *drive = floppy->drive;
182
183 mutex_lock(&idefloppy_ref_mutex);
184 kref_put(&floppy->kref, idefloppy_cleanup_obj);
185 ide_device_put(drive);
186 mutex_unlock(&idefloppy_ref_mutex);
187}
188
189/*
190 * Used to finish servicing a request. For read/write requests, we will call 68 * Used to finish servicing a request. For read/write requests, we will call
191 * ide_end_request to pass to the next buffer. 69 * ide_end_request to pass to the next buffer.
192 */ 70 */
193static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs) 71static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
194{ 72{
195 idefloppy_floppy_t *floppy = drive->driver_data; 73 struct ide_disk_obj *floppy = drive->driver_data;
196 struct request *rq = HWGROUP(drive)->rq; 74 struct request *rq = HWGROUP(drive)->rq;
197 int error; 75 int error;
198 76
199 debug_log("Reached %s\n", __func__); 77 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
200 78
201 switch (uptodate) { 79 switch (uptodate) {
202 case 0: error = IDEFLOPPY_ERROR_GENERAL; break; 80 case 0:
203 case 1: error = 0; break; 81 error = IDEFLOPPY_ERROR_GENERAL;
204 default: error = uptodate; 82 break;
83
84 case 1:
85 error = 0;
86 break;
87
88 default:
89 error = uptodate;
205 } 90 }
91
206 if (error) 92 if (error)
207 floppy->failed_pc = NULL; 93 floppy->failed_pc = NULL;
208 /* Why does this happen? */ 94 /* Why does this happen? */
@@ -219,44 +105,6 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
219 return 0; 105 return 0;
220} 106}
221 107
222static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
223 unsigned int bcount, int direction)
224{
225 ide_hwif_t *hwif = drive->hwif;
226 struct request *rq = pc->rq;
227 struct req_iterator iter;
228 struct bio_vec *bvec;
229 unsigned long flags;
230 int count, done = 0;
231 char *data;
232
233 rq_for_each_segment(bvec, rq, iter) {
234 if (!bcount)
235 break;
236
237 count = min(bvec->bv_len, bcount);
238
239 data = bvec_kmap_irq(bvec, &flags);
240 if (direction)
241 hwif->tp_ops->output_data(drive, NULL, data, count);
242 else
243 hwif->tp_ops->input_data(drive, NULL, data, count);
244 bvec_kunmap_irq(data, &flags);
245
246 bcount -= count;
247 pc->b_count += count;
248 done += count;
249 }
250
251 idefloppy_end_request(drive, 1, done >> 9);
252
253 if (bcount) {
254 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
255 drive->name, __func__, bcount);
256 ide_pad_transfer(drive, direction, bcount);
257 }
258}
259
260static void idefloppy_update_buffers(ide_drive_t *drive, 108static void idefloppy_update_buffers(ide_drive_t *drive,
261 struct ide_atapi_pc *pc) 109 struct ide_atapi_pc *pc)
262{ 110{
@@ -264,53 +112,16 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
264 struct bio *bio = rq->bio; 112 struct bio *bio = rq->bio;
265 113
266 while ((bio = rq->bio) != NULL) 114 while ((bio = rq->bio) != NULL)
267 idefloppy_end_request(drive, 1, 0); 115 ide_floppy_end_request(drive, 1, 0);
268} 116}
269 117
270/* 118static void ide_floppy_callback(ide_drive_t *drive, int dsc)
271 * Generate a new packet command request in front of the request queue, before
272 * the current request so that it will be processed immediately, on the next
273 * pass through the driver.
274 */
275static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
276 struct request *rq)
277{ 119{
278 struct ide_floppy_obj *floppy = drive->driver_data; 120 struct ide_disk_obj *floppy = drive->driver_data;
279 121 struct ide_atapi_pc *pc = drive->pc;
280 blk_rq_init(NULL, rq);
281 rq->buffer = (char *) pc;
282 rq->cmd_type = REQ_TYPE_SPECIAL;
283 rq->cmd_flags |= REQ_PREEMPT;
284 rq->rq_disk = floppy->disk;
285 memcpy(rq->cmd, pc->c, 12);
286 ide_do_drive_cmd(drive, rq);
287}
288
289static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive)
290{
291 idefloppy_floppy_t *floppy = drive->driver_data;
292
293 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
294 floppy->pc_stack_index = 0;
295 return (&floppy->pc_stack[floppy->pc_stack_index++]);
296}
297
298static struct request *idefloppy_next_rq_storage(ide_drive_t *drive)
299{
300 idefloppy_floppy_t *floppy = drive->driver_data;
301
302 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
303 floppy->rq_stack_index = 0;
304 return (&floppy->rq_stack[floppy->rq_stack_index++]);
305}
306
307static void ide_floppy_callback(ide_drive_t *drive)
308{
309 idefloppy_floppy_t *floppy = drive->driver_data;
310 struct ide_atapi_pc *pc = floppy->pc;
311 int uptodate = pc->error ? 0 : 1; 122 int uptodate = pc->error ? 0 : 1;
312 123
313 debug_log("Reached %s\n", __func__); 124 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
314 125
315 if (floppy->failed_pc == pc) 126 if (floppy->failed_pc == pc)
316 floppy->failed_pc = NULL; 127 floppy->failed_pc = NULL;
@@ -319,7 +130,7 @@ static void ide_floppy_callback(ide_drive_t *drive)
319 (pc->rq && blk_pc_request(pc->rq))) 130 (pc->rq && blk_pc_request(pc->rq)))
320 uptodate = 1; /* FIXME */ 131 uptodate = 1; /* FIXME */
321 else if (pc->c[0] == GPCMD_REQUEST_SENSE) { 132 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
322 u8 *buf = floppy->pc->buf; 133 u8 *buf = pc->buf;
323 134
324 if (!pc->error) { 135 if (!pc->error) {
325 floppy->sense_key = buf[2] & 0x0F; 136 floppy->sense_key = buf[2] & 0x0F;
@@ -329,109 +140,21 @@ static void ide_floppy_callback(ide_drive_t *drive)
329 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; 140 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
330 141
331 if (floppy->failed_pc) 142 if (floppy->failed_pc)
332 debug_log("pc = %x, ", floppy->failed_pc->c[0]); 143 ide_debug_log(IDE_DBG_PC, "pc = %x, ",
144 floppy->failed_pc->c[0]);
333 145
334 debug_log("sense key = %x, asc = %x, ascq = %x\n", 146 ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
335 floppy->sense_key, floppy->asc, floppy->ascq); 147 "ascq = %x\n", floppy->sense_key,
148 floppy->asc, floppy->ascq);
336 } else 149 } else
337 printk(KERN_ERR "Error in REQUEST SENSE itself - " 150 printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
338 "Aborting request!\n"); 151 "Aborting request!\n");
339 } 152 }
340 153
341 idefloppy_end_request(drive, uptodate, 0); 154 ide_floppy_end_request(drive, uptodate, 0);
342}
343
344static void idefloppy_init_pc(struct ide_atapi_pc *pc)
345{
346 memset(pc, 0, sizeof(*pc));
347 pc->buf = pc->pc_buf;
348 pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
349}
350
351static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
352{
353 idefloppy_init_pc(pc);
354 pc->c[0] = GPCMD_REQUEST_SENSE;
355 pc->c[4] = 255;
356 pc->req_xfer = 18;
357}
358
359/*
360 * Called when an error was detected during the last packet command. We queue a
361 * request sense packet command in the head of the request list.
362 */
363static void idefloppy_retry_pc(ide_drive_t *drive)
364{
365 struct ide_atapi_pc *pc;
366 struct request *rq;
367
368 (void)ide_read_error(drive);
369 pc = idefloppy_next_pc_storage(drive);
370 rq = idefloppy_next_rq_storage(drive);
371 idefloppy_create_request_sense_cmd(pc);
372 idefloppy_queue_pc_head(drive, pc, rq);
373} 155}
374 156
375/* The usual interrupt handler called during a packet command. */ 157static void ide_floppy_report_error(struct ide_disk_obj *floppy,
376static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
377{
378 idefloppy_floppy_t *floppy = drive->driver_data;
379
380 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
381 IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers,
382 idefloppy_retry_pc, NULL, ide_floppy_io_buffers);
383}
384
385/*
386 * What we have here is a classic case of a top half / bottom half interrupt
387 * service routine. In interrupt mode, the device sends an interrupt to signal
388 * that it is ready to receive a packet. However, we need to delay about 2-3
389 * ticks before issuing the packet or we gets in trouble.
390 */
391static int idefloppy_transfer_pc(ide_drive_t *drive)
392{
393 idefloppy_floppy_t *floppy = drive->driver_data;
394
395 /* Send the actual packet */
396 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
397
398 /* Timeout for the packet command */
399 return IDEFLOPPY_WAIT_CMD;
400}
401
402
403/*
404 * Called as an interrupt (or directly). When the device says it's ready for a
405 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
406 * transfer_pc.
407 */
408static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
409{
410 idefloppy_floppy_t *floppy = drive->driver_data;
411 struct ide_atapi_pc *pc = floppy->pc;
412 ide_expiry_t *expiry;
413 unsigned int timeout;
414
415 /*
416 * The following delay solves a problem with ATAPI Zip 100 drives
417 * where the Busy flag was apparently being deasserted before the
418 * unit was ready to receive data. This was happening on a
419 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
420 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
421 * used until after the packet is moved in about 50 msec.
422 */
423 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
424 timeout = floppy->ticks;
425 expiry = &idefloppy_transfer_pc;
426 } else {
427 timeout = IDEFLOPPY_WAIT_CMD;
428 expiry = NULL;
429 }
430
431 return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
432}
433
434static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
435 struct ide_atapi_pc *pc) 158 struct ide_atapi_pc *pc)
436{ 159{
437 /* supress error messages resulting from Medium not present */ 160 /* supress error messages resulting from Medium not present */
@@ -440,7 +163,7 @@ static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
440 floppy->ascq == 0x00) 163 floppy->ascq == 0x00)
441 return; 164 return;
442 165
443 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, " 166 printk(KERN_ERR PFX "%s: I/O error, pc = %2x, key = %2x, "
444 "asc = %2x, ascq = %2x\n", 167 "asc = %2x, ascq = %2x\n",
445 floppy->drive->name, pc->c[0], floppy->sense_key, 168 floppy->drive->name, pc->c[0], floppy->sense_key,
446 floppy->asc, floppy->ascq); 169 floppy->asc, floppy->ascq);
@@ -450,13 +173,14 @@ static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
450static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive, 173static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
451 struct ide_atapi_pc *pc) 174 struct ide_atapi_pc *pc)
452{ 175{
453 idefloppy_floppy_t *floppy = drive->driver_data; 176 struct ide_disk_obj *floppy = drive->driver_data;
454 177
455 if (floppy->failed_pc == NULL && 178 if (floppy->failed_pc == NULL &&
456 pc->c[0] != GPCMD_REQUEST_SENSE) 179 pc->c[0] != GPCMD_REQUEST_SENSE)
457 floppy->failed_pc = pc; 180 floppy->failed_pc = pc;
181
458 /* Set the current packet command */ 182 /* Set the current packet command */
459 floppy->pc = pc; 183 drive->pc = pc;
460 184
461 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { 185 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
462 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) 186 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
@@ -465,67 +189,35 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
465 pc->error = IDEFLOPPY_ERROR_GENERAL; 189 pc->error = IDEFLOPPY_ERROR_GENERAL;
466 190
467 floppy->failed_pc = NULL; 191 floppy->failed_pc = NULL;
468 drive->pc_callback(drive); 192 drive->pc_callback(drive, 0);
469 return ide_stopped; 193 return ide_stopped;
470 } 194 }
471 195
472 debug_log("Retry number - %d\n", pc->retries); 196 ide_debug_log(IDE_DBG_FUNC, "%s: Retry #%d\n", __func__, pc->retries);
473 197
474 pc->retries++; 198 pc->retries++;
475 199
476 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, 200 return ide_issue_pc(drive, WAIT_FLOPPY_CMD, NULL);
477 IDEFLOPPY_WAIT_CMD, NULL);
478} 201}
479 202
480static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent) 203void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
481{ 204{
482 debug_log("creating prevent removal command, prevent = %d\n", prevent); 205 ide_init_pc(pc);
483
484 idefloppy_init_pc(pc);
485 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
486 pc->c[4] = prevent;
487}
488
489static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
490{
491 idefloppy_init_pc(pc);
492 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; 206 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
493 pc->c[7] = 255; 207 pc->c[7] = 255;
494 pc->c[8] = 255; 208 pc->c[8] = 255;
495 pc->req_xfer = 255; 209 pc->req_xfer = 255;
496} 210}
497 211
498static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
499 int l, int flags)
500{
501 idefloppy_init_pc(pc);
502 pc->c[0] = GPCMD_FORMAT_UNIT;
503 pc->c[1] = 0x17;
504
505 memset(pc->buf, 0, 12);
506 pc->buf[1] = 0xA2;
507 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
508
509 if (flags & 1) /* Verify bit on... */
510 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */
511 pc->buf[3] = 8;
512
513 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4]));
514 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8]));
515 pc->buf_size = 12;
516 pc->flags |= PC_FLAG_WRITING;
517}
518
519/* A mode sense command is used to "sense" floppy parameters. */ 212/* A mode sense command is used to "sense" floppy parameters. */
520static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, 213void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
521 u8 page_code, u8 type)
522{ 214{
523 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ 215 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
524 216
525 idefloppy_init_pc(pc); 217 ide_init_pc(pc);
526 pc->c[0] = GPCMD_MODE_SENSE_10; 218 pc->c[0] = GPCMD_MODE_SENSE_10;
527 pc->c[1] = 0; 219 pc->c[1] = 0;
528 pc->c[2] = page_code + (type << 6); 220 pc->c[2] = page_code;
529 221
530 switch (page_code) { 222 switch (page_code) {
531 case IDEFLOPPY_CAPABILITIES_PAGE: 223 case IDEFLOPPY_CAPABILITIES_PAGE:
@@ -535,32 +227,25 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
535 length += 32; 227 length += 32;
536 break; 228 break;
537 default: 229 default:
538 printk(KERN_ERR "ide-floppy: unsupported page code " 230 printk(KERN_ERR PFX "unsupported page code in %s\n", __func__);
539 "in create_mode_sense_cmd\n");
540 } 231 }
541 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]); 232 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
542 pc->req_xfer = length; 233 pc->req_xfer = length;
543} 234}
544 235
545static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start) 236static void idefloppy_create_rw_cmd(ide_drive_t *drive,
546{
547 idefloppy_init_pc(pc);
548 pc->c[0] = GPCMD_START_STOP_UNIT;
549 pc->c[4] = start;
550}
551
552static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
553 struct ide_atapi_pc *pc, struct request *rq, 237 struct ide_atapi_pc *pc, struct request *rq,
554 unsigned long sector) 238 unsigned long sector)
555{ 239{
240 struct ide_disk_obj *floppy = drive->driver_data;
556 int block = sector / floppy->bs_factor; 241 int block = sector / floppy->bs_factor;
557 int blocks = rq->nr_sectors / floppy->bs_factor; 242 int blocks = rq->nr_sectors / floppy->bs_factor;
558 int cmd = rq_data_dir(rq); 243 int cmd = rq_data_dir(rq);
559 244
560 debug_log("create_rw10_cmd: block == %d, blocks == %d\n", 245 ide_debug_log(IDE_DBG_FUNC, "%s: block: %d, blocks: %d\n", __func__,
561 block, blocks); 246 block, blocks);
562 247
563 idefloppy_init_pc(pc); 248 ide_init_pc(pc);
564 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 249 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
565 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); 250 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
566 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); 251 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
@@ -568,7 +253,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
568 memcpy(rq->cmd, pc->c, 12); 253 memcpy(rq->cmd, pc->c, 12);
569 254
570 pc->rq = rq; 255 pc->rq = rq;
571 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; 256 pc->b_count = 0;
572 if (rq->cmd_flags & REQ_RW) 257 if (rq->cmd_flags & REQ_RW)
573 pc->flags |= PC_FLAG_WRITING; 258 pc->flags |= PC_FLAG_WRITING;
574 pc->buf = NULL; 259 pc->buf = NULL;
@@ -576,13 +261,13 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
576 pc->flags |= PC_FLAG_DMA_OK; 261 pc->flags |= PC_FLAG_DMA_OK;
577} 262}
578 263
579static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, 264static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
580 struct ide_atapi_pc *pc, struct request *rq) 265 struct ide_atapi_pc *pc, struct request *rq)
581{ 266{
582 idefloppy_init_pc(pc); 267 ide_init_pc(pc);
583 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 268 memcpy(pc->c, rq->cmd, sizeof(pc->c));
584 pc->rq = rq; 269 pc->rq = rq;
585 pc->b_count = rq->data_len; 270 pc->b_count = 0;
586 if (rq->data_len && rq_data_dir(rq) == WRITE) 271 if (rq->data_len && rq_data_dir(rq) == WRITE)
587 pc->flags |= PC_FLAG_WRITING; 272 pc->flags |= PC_FLAG_WRITING;
588 pc->buf = rq->data; 273 pc->buf = rq->data;
@@ -595,74 +280,62 @@ static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
595 pc->req_xfer = pc->buf_size = rq->data_len; 280 pc->req_xfer = pc->buf_size = rq->data_len;
596} 281}
597 282
598static ide_startstop_t idefloppy_do_request(ide_drive_t *drive, 283static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
599 struct request *rq, sector_t block_s) 284 struct request *rq, sector_t block)
600{ 285{
601 idefloppy_floppy_t *floppy = drive->driver_data; 286 struct ide_disk_obj *floppy = drive->driver_data;
287 ide_hwif_t *hwif = drive->hwif;
602 struct ide_atapi_pc *pc; 288 struct ide_atapi_pc *pc;
603 unsigned long block = (unsigned long)block_s;
604 289
605 debug_log("dev: %s, cmd_type: %x, errors: %d\n", 290 ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
606 rq->rq_disk ? rq->rq_disk->disk_name : "?", 291 "errors: %d\n",
607 rq->cmd_type, rq->errors); 292 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
608 debug_log("sector: %ld, nr_sectors: %ld, " 293 rq->cmd[0], rq->cmd_type, rq->errors);
609 "current_nr_sectors: %d\n", (long)rq->sector, 294
610 rq->nr_sectors, rq->current_nr_sectors); 295 ide_debug_log(IDE_DBG_FUNC, "%s: sector: %ld, nr_sectors: %ld, "
296 "current_nr_sectors: %d\n",
297 __func__, (long)rq->sector, rq->nr_sectors,
298 rq->current_nr_sectors);
611 299
612 if (rq->errors >= ERROR_MAX) { 300 if (rq->errors >= ERROR_MAX) {
613 if (floppy->failed_pc) 301 if (floppy->failed_pc)
614 ide_floppy_report_error(floppy, floppy->failed_pc); 302 ide_floppy_report_error(floppy, floppy->failed_pc);
615 else 303 else
616 printk(KERN_ERR "ide-floppy: %s: I/O error\n", 304 printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
617 drive->name); 305
618 idefloppy_end_request(drive, 0, 0); 306 ide_floppy_end_request(drive, 0, 0);
619 return ide_stopped; 307 return ide_stopped;
620 } 308 }
621 if (blk_fs_request(rq)) { 309 if (blk_fs_request(rq)) {
622 if (((long)rq->sector % floppy->bs_factor) || 310 if (((long)rq->sector % floppy->bs_factor) ||
623 (rq->nr_sectors % floppy->bs_factor)) { 311 (rq->nr_sectors % floppy->bs_factor)) {
624 printk(KERN_ERR "%s: unsupported r/w request size\n", 312 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
625 drive->name); 313 drive->name);
626 idefloppy_end_request(drive, 0, 0); 314 ide_floppy_end_request(drive, 0, 0);
627 return ide_stopped; 315 return ide_stopped;
628 } 316 }
629 pc = idefloppy_next_pc_storage(drive); 317 pc = &floppy->queued_pc;
630 idefloppy_create_rw_cmd(floppy, pc, rq, block); 318 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
631 } else if (blk_special_request(rq)) { 319 } else if (blk_special_request(rq)) {
632 pc = (struct ide_atapi_pc *) rq->buffer; 320 pc = (struct ide_atapi_pc *) rq->buffer;
633 } else if (blk_pc_request(rq)) { 321 } else if (blk_pc_request(rq)) {
634 pc = idefloppy_next_pc_storage(drive); 322 pc = &floppy->queued_pc;
635 idefloppy_blockpc_cmd(floppy, pc, rq); 323 idefloppy_blockpc_cmd(floppy, pc, rq);
636 } else { 324 } else {
637 blk_dump_rq_flags(rq, 325 blk_dump_rq_flags(rq, PFX "unsupported command in queue");
638 "ide-floppy: unsupported command in queue"); 326 ide_floppy_end_request(drive, 0, 0);
639 idefloppy_end_request(drive, 0, 0);
640 return ide_stopped; 327 return ide_stopped;
641 } 328 }
642 329
643 pc->rq = rq; 330 ide_init_sg_cmd(drive, rq);
331 ide_map_sg(drive, rq);
644 332
645 return idefloppy_issue_pc(drive, pc); 333 pc->sg = hwif->sg_table;
646} 334 pc->sg_cnt = hwif->sg_nents;
647 335
648/* 336 pc->rq = rq;
649 * Add a special packet command request to the tail of the request queue,
650 * and wait for it to be serviced.
651 */
652static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
653{
654 struct ide_floppy_obj *floppy = drive->driver_data;
655 struct request *rq;
656 int error;
657
658 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
659 rq->buffer = (char *) pc;
660 rq->cmd_type = REQ_TYPE_SPECIAL;
661 memcpy(rq->cmd, pc->c, 12);
662 error = blk_execute_rq(drive->queue, floppy->disk, rq, 0);
663 blk_put_request(rq);
664 337
665 return error; 338 return idefloppy_issue_pc(drive, pc);
666} 339}
667 340
668/* 341/*
@@ -671,23 +344,28 @@ static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
671 */ 344 */
672static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) 345static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
673{ 346{
674 idefloppy_floppy_t *floppy = drive->driver_data; 347 struct ide_disk_obj *floppy = drive->driver_data;
348 struct gendisk *disk = floppy->disk;
675 struct ide_atapi_pc pc; 349 struct ide_atapi_pc pc;
676 u8 *page; 350 u8 *page;
677 int capacity, lba_capacity; 351 int capacity, lba_capacity;
678 u16 transfer_rate, sector_size, cyls, rpm; 352 u16 transfer_rate, sector_size, cyls, rpm;
679 u8 heads, sectors; 353 u8 heads, sectors;
680 354
681 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, 355 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
682 MODE_SENSE_CURRENT);
683 356
684 if (idefloppy_queue_pc_tail(drive, &pc)) { 357 if (ide_queue_pc_tail(drive, disk, &pc)) {
685 printk(KERN_ERR "ide-floppy: Can't get flexible disk page" 358 printk(KERN_ERR PFX "Can't get flexible disk page params\n");
686 " parameters\n");
687 return 1; 359 return 1;
688 } 360 }
689 floppy->wp = !!(pc.buf[3] & 0x80); 361
690 set_disk_ro(floppy->disk, floppy->wp); 362 if (pc.buf[3] & 0x80)
363 drive->dev_flags |= IDE_DFLAG_WP;
364 else
365 drive->dev_flags &= ~IDE_DFLAG_WP;
366
367 set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP));
368
691 page = &pc.buf[8]; 369 page = &pc.buf[8];
692 370
693 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); 371 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
@@ -700,7 +378,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
700 capacity = cyls * heads * sectors * sector_size; 378 capacity = cyls * heads * sectors * sector_size;
701 379
702 if (memcmp(page, &floppy->flexible_disk_page, 32)) 380 if (memcmp(page, &floppy->flexible_disk_page, 32))
703 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " 381 printk(KERN_INFO PFX "%s: %dkB, %d/%d/%d CHS, %d kBps, "
704 "%d sector size, %d rpm\n", 382 "%d sector size, %d rpm\n",
705 drive->name, capacity / 1024, cyls, heads, 383 drive->name, capacity / 1024, cyls, heads,
706 sectors, transfer_rate / 8, sector_size, rpm); 384 sectors, transfer_rate / 8, sector_size, rpm);
@@ -712,30 +390,15 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
712 lba_capacity = floppy->blocks * floppy->block_size; 390 lba_capacity = floppy->blocks * floppy->block_size;
713 391
714 if (capacity < lba_capacity) { 392 if (capacity < lba_capacity) {
715 printk(KERN_NOTICE "%s: The disk reports a capacity of %d " 393 printk(KERN_NOTICE PFX "%s: The disk reports a capacity of %d "
716 "bytes, but the drive only handles %d\n", 394 "bytes, but the drive only handles %d\n",
717 drive->name, lba_capacity, capacity); 395 drive->name, lba_capacity, capacity);
718 floppy->blocks = floppy->block_size ? 396 floppy->blocks = floppy->block_size ?
719 capacity / floppy->block_size : 0; 397 capacity / floppy->block_size : 0;
398 drive->capacity64 = floppy->blocks * floppy->bs_factor;
720 } 399 }
721 return 0;
722}
723 400
724static int idefloppy_get_sfrp_bit(ide_drive_t *drive) 401 return 0;
725{
726 idefloppy_floppy_t *floppy = drive->driver_data;
727 struct ide_atapi_pc pc;
728
729 floppy->srfp = 0;
730 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
731 MODE_SENSE_CURRENT);
732
733 pc.flags |= PC_FLAG_SUPPRESS_ERROR;
734 if (idefloppy_queue_pc_tail(drive, &pc))
735 return 1;
736
737 floppy->srfp = pc.buf[8 + 2] & 0x40;
738 return (0);
739} 402}
740 403
741/* 404/*
@@ -744,7 +407,8 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
744 */ 407 */
745static int ide_floppy_get_capacity(ide_drive_t *drive) 408static int ide_floppy_get_capacity(ide_drive_t *drive)
746{ 409{
747 idefloppy_floppy_t *floppy = drive->driver_data; 410 struct ide_disk_obj *floppy = drive->driver_data;
411 struct gendisk *disk = floppy->disk;
748 struct ide_atapi_pc pc; 412 struct ide_atapi_pc pc;
749 u8 *cap_desc; 413 u8 *cap_desc;
750 u8 header_len, desc_cnt; 414 u8 header_len, desc_cnt;
@@ -754,11 +418,11 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
754 drive->bios_head = drive->bios_sect = 0; 418 drive->bios_head = drive->bios_sect = 0;
755 floppy->blocks = 0; 419 floppy->blocks = 0;
756 floppy->bs_factor = 1; 420 floppy->bs_factor = 1;
757 set_capacity(floppy->disk, 0); 421 drive->capacity64 = 0;
758 422
759 idefloppy_create_read_capacity_cmd(&pc); 423 ide_floppy_create_read_capacity_cmd(&pc);
760 if (idefloppy_queue_pc_tail(drive, &pc)) { 424 if (ide_queue_pc_tail(drive, disk, &pc)) {
761 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 425 printk(KERN_ERR PFX "Can't get floppy parameters\n");
762 return 1; 426 return 1;
763 } 427 }
764 header_len = pc.buf[3]; 428 header_len = pc.buf[3];
@@ -771,8 +435,9 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
771 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); 435 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
772 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); 436 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
773 437
774 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", 438 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
775 i, blocks * length / 1024, blocks, length); 439 "%d sector size\n",
440 i, blocks * length / 1024, blocks, length);
776 441
777 if (i) 442 if (i)
778 continue; 443 continue;
@@ -792,23 +457,26 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
792 case CAPACITY_CURRENT: 457 case CAPACITY_CURRENT:
793 /* Normal Zip/LS-120 disks */ 458 /* Normal Zip/LS-120 disks */
794 if (memcmp(cap_desc, &floppy->cap_desc, 8)) 459 if (memcmp(cap_desc, &floppy->cap_desc, 8))
795 printk(KERN_INFO "%s: %dkB, %d blocks, %d " 460 printk(KERN_INFO PFX "%s: %dkB, %d blocks, %d "
796 "sector size\n", drive->name, 461 "sector size\n",
797 blocks * length / 1024, blocks, length); 462 drive->name, blocks * length / 1024,
463 blocks, length);
798 memcpy(&floppy->cap_desc, cap_desc, 8); 464 memcpy(&floppy->cap_desc, cap_desc, 8);
799 465
800 if (!length || length % 512) { 466 if (!length || length % 512) {
801 printk(KERN_NOTICE "%s: %d bytes block size " 467 printk(KERN_NOTICE PFX "%s: %d bytes block size"
802 "not supported\n", drive->name, length); 468 " not supported\n", drive->name, length);
803 } else { 469 } else {
804 floppy->blocks = blocks; 470 floppy->blocks = blocks;
805 floppy->block_size = length; 471 floppy->block_size = length;
806 floppy->bs_factor = length / 512; 472 floppy->bs_factor = length / 512;
807 if (floppy->bs_factor != 1) 473 if (floppy->bs_factor != 1)
808 printk(KERN_NOTICE "%s: warning: non " 474 printk(KERN_NOTICE PFX "%s: Warning: "
809 "512 bytes block size not " 475 "non 512 bytes block size not "
810 "fully supported\n", 476 "fully supported\n",
811 drive->name); 477 drive->name);
478 drive->capacity64 =
479 floppy->blocks * floppy->bs_factor;
812 rc = 0; 480 rc = 0;
813 } 481 }
814 break; 482 break;
@@ -817,221 +485,34 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
817 * This is a KERN_ERR so it appears on screen 485 * This is a KERN_ERR so it appears on screen
818 * for the user to see 486 * for the user to see
819 */ 487 */
820 printk(KERN_ERR "%s: No disk in drive\n", drive->name); 488 printk(KERN_ERR PFX "%s: No disk in drive\n",
489 drive->name);
821 break; 490 break;
822 case CAPACITY_INVALID: 491 case CAPACITY_INVALID:
823 printk(KERN_ERR "%s: Invalid capacity for disk " 492 printk(KERN_ERR PFX "%s: Invalid capacity for disk "
824 "in drive\n", drive->name); 493 "in drive\n", drive->name);
825 break; 494 break;
826 } 495 }
827 debug_log("Descriptor 0 Code: %d\n", 496 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d\n",
828 pc.buf[desc_start + 4] & 0x03); 497 pc.buf[desc_start + 4] & 0x03);
829 } 498 }
830 499
831 /* Clik! disk does not support get_flexible_disk_page */ 500 /* Clik! disk does not support get_flexible_disk_page */
832 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) 501 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
833 (void) ide_floppy_get_flexible_disk_page(drive); 502 (void) ide_floppy_get_flexible_disk_page(drive);
834 503
835 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
836 return rc; 504 return rc;
837} 505}
838 506
839/* 507static void ide_floppy_setup(ide_drive_t *drive)
840 * Obtain the list of formattable capacities.
841 * Very similar to ide_floppy_get_capacity, except that we push the capacity
842 * descriptors to userland, instead of our own structures.
843 *
844 * Userland gives us the following structure:
845 *
846 * struct idefloppy_format_capacities {
847 * int nformats;
848 * struct {
849 * int nblocks;
850 * int blocksize;
851 * } formats[];
852 * };
853 *
854 * userland initializes nformats to the number of allocated formats[] records.
855 * On exit we set nformats to the number of records we've actually initialized.
856 */
857
858static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
859{
860 struct ide_atapi_pc pc;
861 u8 header_len, desc_cnt;
862 int i, blocks, length, u_array_size, u_index;
863 int __user *argp;
864
865 if (get_user(u_array_size, arg))
866 return (-EFAULT);
867
868 if (u_array_size <= 0)
869 return (-EINVAL);
870
871 idefloppy_create_read_capacity_cmd(&pc);
872 if (idefloppy_queue_pc_tail(drive, &pc)) {
873 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
874 return (-EIO);
875 }
876 header_len = pc.buf[3];
877 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
878
879 u_index = 0;
880 argp = arg + 1;
881
882 /*
883 * We always skip the first capacity descriptor. That's the current
884 * capacity. We are interested in the remaining descriptors, the
885 * formattable capacities.
886 */
887 for (i = 1; i < desc_cnt; i++) {
888 unsigned int desc_start = 4 + i*8;
889
890 if (u_index >= u_array_size)
891 break; /* User-supplied buffer too small */
892
893 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
894 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
895
896 if (put_user(blocks, argp))
897 return(-EFAULT);
898 ++argp;
899
900 if (put_user(length, argp))
901 return (-EFAULT);
902 ++argp;
903
904 ++u_index;
905 }
906
907 if (put_user(u_index, arg))
908 return (-EFAULT);
909 return (0);
910}
911
912/*
913 * Get ATAPI_FORMAT_UNIT progress indication.
914 *
915 * Userland gives a pointer to an int. The int is set to a progress
916 * indicator 0-65536, with 65536=100%.
917 *
918 * If the drive does not support format progress indication, we just check
919 * the dsc bit, and return either 0 or 65536.
920 */
921
922static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
923{ 508{
924 idefloppy_floppy_t *floppy = drive->driver_data; 509 struct ide_disk_obj *floppy = drive->driver_data;
925 struct ide_atapi_pc pc; 510 u16 *id = drive->id;
926 int progress_indication = 0x10000;
927
928 if (floppy->srfp) {
929 idefloppy_create_request_sense_cmd(&pc);
930 if (idefloppy_queue_pc_tail(drive, &pc))
931 return (-EIO);
932
933 if (floppy->sense_key == 2 &&
934 floppy->asc == 4 &&
935 floppy->ascq == 4)
936 progress_indication = floppy->progress_indication;
937 511
938 /* Else assume format_unit has finished, and we're at 0x10000 */ 512 drive->pc_callback = ide_floppy_callback;
939 } else { 513 drive->pc_update_buffers = idefloppy_update_buffers;
940 ide_hwif_t *hwif = drive->hwif; 514 drive->pc_io_buffers = ide_io_buffers;
941 unsigned long flags;
942 u8 stat;
943
944 local_irq_save(flags);
945 stat = hwif->tp_ops->read_status(hwif);
946 local_irq_restore(flags);
947 515
948 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
949 }
950 if (put_user(progress_indication, arg))
951 return (-EFAULT);
952
953 return (0);
954}
955
956static sector_t idefloppy_capacity(ide_drive_t *drive)
957{
958 idefloppy_floppy_t *floppy = drive->driver_data;
959 unsigned long capacity = floppy->blocks * floppy->bs_factor;
960
961 return capacity;
962}
963
964/*
965 * Check whether we can support a drive, based on the ATAPI IDENTIFY command
966 * results.
967 */
968static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
969{
970 u8 gcw[2];
971 u8 device_type, protocol, removable, drq_type, packet_size;
972
973 *((u16 *) &gcw) = id->config;
974
975 device_type = gcw[1] & 0x1F;
976 removable = (gcw[0] & 0x80) >> 7;
977 protocol = (gcw[1] & 0xC0) >> 6;
978 drq_type = (gcw[0] & 0x60) >> 5;
979 packet_size = gcw[0] & 0x03;
980
981#ifdef CONFIG_PPC
982 /* kludge for Apple PowerBook internal zip */
983 if (device_type == 5 &&
984 !strstr(id->model, "CD-ROM") && strstr(id->model, "ZIP"))
985 device_type = 0;
986#endif
987
988 if (protocol != 2)
989 printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
990 protocol);
991 else if (device_type != 0)
992 printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
993 "to floppy\n", device_type);
994 else if (!removable)
995 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
996 else if (drq_type == 3)
997 printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
998 "supported\n", drq_type);
999 else if (packet_size != 0)
1000 printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
1001 "bytes\n", packet_size);
1002 else
1003 return 1;
1004 return 0;
1005}
1006
1007#ifdef CONFIG_IDE_PROC_FS
1008static void idefloppy_add_settings(ide_drive_t *drive)
1009{
1010 idefloppy_floppy_t *floppy = drive->driver_data;
1011
1012 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1,
1013 &drive->bios_cyl, NULL);
1014 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
1015 &drive->bios_head, NULL);
1016 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1,
1017 &drive->bios_sect, NULL);
1018 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
1019 &floppy->ticks, NULL);
1020}
1021#else
1022static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1023#endif
1024
1025static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1026{
1027 u8 gcw[2];
1028
1029 *((u16 *) &gcw) = drive->id->config;
1030 floppy->pc = floppy->pc_stack;
1031 drive->pc_callback = ide_floppy_callback;
1032
1033 if (((gcw[0] & 0x60) >> 5) == 1)
1034 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
1035 /* 516 /*
1036 * We used to check revisions here. At this point however I'm giving up. 517 * We used to check revisions here. At this point however I'm giving up.
1037 * Just assume they are all broken, its easier. 518 * Just assume they are all broken, its easier.
@@ -1041,10 +522,10 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1041 * it. It should be fixed as of version 1.9, but to be on the safe side 522 * it. It should be fixed as of version 1.9, but to be on the safe side
1042 * we'll leave the limitation below for the 2.2.x tree. 523 * we'll leave the limitation below for the 2.2.x tree.
1043 */ 524 */
1044 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) { 525 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
1045 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; 526 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
1046 /* This value will be visible in the /proc/ide/hdx/settings */ 527 /* This value will be visible in the /proc/ide/hdx/settings */
1047 floppy->ticks = IDEFLOPPY_TICKS_DELAY; 528 drive->pc_delay = IDEFLOPPY_PC_DELAY;
1048 blk_queue_max_sectors(drive->queue, 64); 529 blk_queue_max_sectors(drive->queue, 64);
1049 } 530 }
1050 531
@@ -1052,406 +533,46 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1052 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes 533 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
1053 * nasty clicking noises without it, so please don't remove this. 534 * nasty clicking noises without it, so please don't remove this.
1054 */ 535 */
1055 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) { 536 if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) {
1056 blk_queue_max_sectors(drive->queue, 64); 537 blk_queue_max_sectors(drive->queue, 64);
1057 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE; 538 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
539 /* IOMEGA Clik! drives do not support lock/unlock commands */
540 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
1058 } 541 }
1059 542
1060 (void) ide_floppy_get_capacity(drive); 543 (void) ide_floppy_get_capacity(drive);
1061 idefloppy_add_settings(drive);
1062}
1063
1064static void ide_floppy_remove(ide_drive_t *drive)
1065{
1066 idefloppy_floppy_t *floppy = drive->driver_data;
1067 struct gendisk *g = floppy->disk;
1068 544
1069 ide_proc_unregister_driver(drive, floppy->driver); 545 ide_proc_register_driver(drive, floppy->driver);
1070 546
1071 del_gendisk(g); 547 drive->dev_flags |= IDE_DFLAG_ATTACH;
1072
1073 ide_floppy_put(floppy);
1074} 548}
1075 549
1076static void idefloppy_cleanup_obj(struct kref *kref) 550static void ide_floppy_flush(ide_drive_t *drive)
1077{ 551{
1078 struct ide_floppy_obj *floppy = to_ide_floppy(kref);
1079 ide_drive_t *drive = floppy->drive;
1080 struct gendisk *g = floppy->disk;
1081
1082 drive->driver_data = NULL;
1083 g->private_data = NULL;
1084 put_disk(g);
1085 kfree(floppy);
1086} 552}
1087 553
1088#ifdef CONFIG_IDE_PROC_FS 554static int ide_floppy_init_media(ide_drive_t *drive, struct gendisk *disk)
1089static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
1090 int count, int *eof, void *data)
1091{
1092 ide_drive_t*drive = (ide_drive_t *)data;
1093 int len;
1094
1095 len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
1096 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
1097}
1098
1099static ide_proc_entry_t idefloppy_proc[] = {
1100 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
1101 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
1102 { NULL, 0, NULL, NULL }
1103};
1104#endif /* CONFIG_IDE_PROC_FS */
1105
1106static int ide_floppy_probe(ide_drive_t *);
1107
1108static ide_driver_t idefloppy_driver = {
1109 .gen_driver = {
1110 .owner = THIS_MODULE,
1111 .name = "ide-floppy",
1112 .bus = &ide_bus_type,
1113 },
1114 .probe = ide_floppy_probe,
1115 .remove = ide_floppy_remove,
1116 .version = IDEFLOPPY_VERSION,
1117 .media = ide_floppy,
1118 .supports_dsc_overlap = 0,
1119 .do_request = idefloppy_do_request,
1120 .end_request = idefloppy_end_request,
1121 .error = __ide_error,
1122#ifdef CONFIG_IDE_PROC_FS
1123 .proc = idefloppy_proc,
1124#endif
1125};
1126
1127static int idefloppy_open(struct inode *inode, struct file *filp)
1128{ 555{
1129 struct gendisk *disk = inode->i_bdev->bd_disk;
1130 struct ide_floppy_obj *floppy;
1131 ide_drive_t *drive;
1132 struct ide_atapi_pc pc;
1133 int ret = 0; 556 int ret = 0;
1134 557
1135 debug_log("Reached %s\n", __func__); 558 if (ide_do_test_unit_ready(drive, disk))
1136 559 ide_do_start_stop(drive, disk, 1);
1137 floppy = ide_floppy_get(disk);
1138 if (!floppy)
1139 return -ENXIO;
1140
1141 drive = floppy->drive;
1142
1143 floppy->openers++;
1144
1145 if (floppy->openers == 1) {
1146 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1147 /* Just in case */
1148 560
1149 idefloppy_init_pc(&pc); 561 ret = ide_floppy_get_capacity(drive);
1150 pc.c[0] = GPCMD_TEST_UNIT_READY;
1151 562
1152 if (idefloppy_queue_pc_tail(drive, &pc)) { 563 set_capacity(disk, ide_gd_capacity(drive));
1153 idefloppy_create_start_stop_cmd(&pc, 1);
1154 (void) idefloppy_queue_pc_tail(drive, &pc);
1155 }
1156
1157 if (ide_floppy_get_capacity(drive)
1158 && (filp->f_flags & O_NDELAY) == 0
1159 /*
1160 * Allow O_NDELAY to open a drive without a disk, or with an
1161 * unreadable disk, so that we can get the format capacity
1162 * of the drive or begin the format - Sam
1163 */
1164 ) {
1165 ret = -EIO;
1166 goto out_put_floppy;
1167 }
1168 564
1169 if (floppy->wp && (filp->f_mode & 2)) {
1170 ret = -EROFS;
1171 goto out_put_floppy;
1172 }
1173 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
1174 /* IOMEGA Clik! drives do not support lock/unlock commands */
1175 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1176 idefloppy_create_prevent_cmd(&pc, 1);
1177 (void) idefloppy_queue_pc_tail(drive, &pc);
1178 }
1179 check_disk_change(inode->i_bdev);
1180 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
1181 ret = -EBUSY;
1182 goto out_put_floppy;
1183 }
1184 return 0;
1185
1186out_put_floppy:
1187 floppy->openers--;
1188 ide_floppy_put(floppy);
1189 return ret; 565 return ret;
1190} 566}
1191 567
1192static int idefloppy_release(struct inode *inode, struct file *filp) 568const struct ide_disk_ops ide_atapi_disk_ops = {
1193{ 569 .check = ide_check_atapi_device,
1194 struct gendisk *disk = inode->i_bdev->bd_disk; 570 .get_capacity = ide_floppy_get_capacity,
1195 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 571 .setup = ide_floppy_setup,
1196 ide_drive_t *drive = floppy->drive; 572 .flush = ide_floppy_flush,
1197 struct ide_atapi_pc pc; 573 .init_media = ide_floppy_init_media,
1198 574 .set_doorlock = ide_set_media_lock,
1199 debug_log("Reached %s\n", __func__); 575 .do_request = ide_floppy_do_request,
1200 576 .end_request = ide_floppy_end_request,
1201 if (floppy->openers == 1) { 577 .ioctl = ide_floppy_ioctl,
1202 /* IOMEGA Clik! drives do not support lock/unlock commands */
1203 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1204 idefloppy_create_prevent_cmd(&pc, 0);
1205 (void) idefloppy_queue_pc_tail(drive, &pc);
1206 }
1207
1208 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1209 }
1210
1211 floppy->openers--;
1212
1213 ide_floppy_put(floppy);
1214
1215 return 0;
1216}
1217
1218static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1219{
1220 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1221 ide_drive_t *drive = floppy->drive;
1222
1223 geo->heads = drive->bios_head;
1224 geo->sectors = drive->bios_sect;
1225 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1226 return 0;
1227}
1228
1229static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
1230 unsigned long arg, unsigned int cmd)
1231{
1232 idefloppy_floppy_t *floppy = drive->driver_data;
1233
1234 if (floppy->openers > 1)
1235 return -EBUSY;
1236
1237 /* The IOMEGA Clik! Drive doesn't support this command -
1238 * no room for an eject mechanism */
1239 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1240 int prevent = arg ? 1 : 0;
1241
1242 if (cmd == CDROMEJECT)
1243 prevent = 0;
1244
1245 idefloppy_create_prevent_cmd(pc, prevent);
1246 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1247 }
1248
1249 if (cmd == CDROMEJECT) {
1250 idefloppy_create_start_stop_cmd(pc, 2);
1251 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1252 }
1253
1254 return 0;
1255}
1256
1257static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1258 int __user *arg)
1259{
1260 struct ide_atapi_pc pc;
1261 ide_drive_t *drive = floppy->drive;
1262 int blocks, length, flags, err = 0;
1263
1264 if (floppy->openers > 1) {
1265 /* Don't format if someone is using the disk */
1266 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1267 return -EBUSY;
1268 }
1269
1270 drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
1271
1272 /*
1273 * Send ATAPI_FORMAT_UNIT to the drive.
1274 *
1275 * Userland gives us the following structure:
1276 *
1277 * struct idefloppy_format_command {
1278 * int nblocks;
1279 * int blocksize;
1280 * int flags;
1281 * } ;
1282 *
1283 * flags is a bitmask, currently, the only defined flag is:
1284 *
1285 * 0x01 - verify media after format.
1286 */
1287 if (get_user(blocks, arg) ||
1288 get_user(length, arg+1) ||
1289 get_user(flags, arg+2)) {
1290 err = -EFAULT;
1291 goto out;
1292 }
1293
1294 (void) idefloppy_get_sfrp_bit(drive);
1295 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1296
1297 if (idefloppy_queue_pc_tail(drive, &pc))
1298 err = -EIO;
1299
1300out:
1301 if (err)
1302 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1303 return err;
1304}
1305
1306
1307static int idefloppy_ioctl(struct inode *inode, struct file *file,
1308 unsigned int cmd, unsigned long arg)
1309{
1310 struct block_device *bdev = inode->i_bdev;
1311 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1312 ide_drive_t *drive = floppy->drive;
1313 struct ide_atapi_pc pc;
1314 void __user *argp = (void __user *)arg;
1315 int err;
1316
1317 switch (cmd) {
1318 case CDROMEJECT:
1319 /* fall through */
1320 case CDROM_LOCKDOOR:
1321 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
1322 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1323 return 0;
1324 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
1325 return ide_floppy_get_format_capacities(drive, argp);
1326 case IDEFLOPPY_IOCTL_FORMAT_START:
1327 if (!(file->f_mode & 2))
1328 return -EPERM;
1329
1330 return ide_floppy_format_unit(floppy, (int __user *)arg);
1331 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1332 return idefloppy_get_format_progress(drive, argp);
1333 }
1334
1335 /*
1336 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1337 * and CDROM_SEND_PACKET (legacy) ioctls
1338 */
1339 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1340 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1341 bdev->bd_disk, cmd, argp);
1342 else
1343 err = -ENOTTY;
1344
1345 if (err == -ENOTTY)
1346 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
1347
1348 return err;
1349}
1350
1351static int idefloppy_media_changed(struct gendisk *disk)
1352{
1353 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1354 ide_drive_t *drive = floppy->drive;
1355 int ret;
1356
1357 /* do not scan partitions twice if this is a removable device */
1358 if (drive->attach) {
1359 drive->attach = 0;
1360 return 0;
1361 }
1362 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
1363 drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED;
1364 return ret;
1365}
1366
1367static int idefloppy_revalidate_disk(struct gendisk *disk)
1368{
1369 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1370 set_capacity(disk, idefloppy_capacity(floppy->drive));
1371 return 0;
1372}
1373
1374static struct block_device_operations idefloppy_ops = {
1375 .owner = THIS_MODULE,
1376 .open = idefloppy_open,
1377 .release = idefloppy_release,
1378 .ioctl = idefloppy_ioctl,
1379 .getgeo = idefloppy_getgeo,
1380 .media_changed = idefloppy_media_changed,
1381 .revalidate_disk = idefloppy_revalidate_disk
1382}; 578};
1383
1384static int ide_floppy_probe(ide_drive_t *drive)
1385{
1386 idefloppy_floppy_t *floppy;
1387 struct gendisk *g;
1388
1389 if (!strstr("ide-floppy", drive->driver_req))
1390 goto failed;
1391 if (!drive->present)
1392 goto failed;
1393 if (drive->media != ide_floppy)
1394 goto failed;
1395 if (!idefloppy_identify_device(drive, drive->id)) {
1396 printk(KERN_ERR "ide-floppy: %s: not supported by this version"
1397 " of ide-floppy\n", drive->name);
1398 goto failed;
1399 }
1400 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
1401 if (!floppy) {
1402 printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
1403 " structure\n", drive->name);
1404 goto failed;
1405 }
1406
1407 g = alloc_disk(1 << PARTN_BITS);
1408 if (!g)
1409 goto out_free_floppy;
1410
1411 ide_init_disk(g, drive);
1412
1413 ide_proc_register_driver(drive, &idefloppy_driver);
1414
1415 kref_init(&floppy->kref);
1416
1417 floppy->drive = drive;
1418 floppy->driver = &idefloppy_driver;
1419 floppy->disk = g;
1420
1421 g->private_data = &floppy->driver;
1422
1423 drive->driver_data = floppy;
1424
1425 idefloppy_setup(drive, floppy);
1426
1427 g->minors = 1 << PARTN_BITS;
1428 g->driverfs_dev = &drive->gendev;
1429 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1430 g->fops = &idefloppy_ops;
1431 drive->attach = 1;
1432 add_disk(g);
1433 return 0;
1434
1435out_free_floppy:
1436 kfree(floppy);
1437failed:
1438 return -ENODEV;
1439}
1440
1441static void __exit idefloppy_exit(void)
1442{
1443 driver_unregister(&idefloppy_driver.gen_driver);
1444}
1445
1446static int __init idefloppy_init(void)
1447{
1448 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
1449 return driver_register(&idefloppy_driver.gen_driver);
1450}
1451
1452MODULE_ALIAS("ide:*m-floppy*");
1453module_init(idefloppy_init);
1454module_exit(idefloppy_exit);
1455MODULE_LICENSE("GPL");
1456MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
1457
diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h
new file mode 100644
index 000000000000..6dd2beb48434
--- /dev/null
+++ b/drivers/ide/ide-floppy.h
@@ -0,0 +1,39 @@
1#ifndef __IDE_FLOPPY_H
2#define __IDE_FLOPPY_H
3
4#include "ide-gd.h"
5
6#ifdef CONFIG_IDE_GD_ATAPI
7/*
8 * Pages of the SELECT SENSE / MODE SENSE packet commands.
9 * See SFF-8070i spec.
10 */
11#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
12#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
13
14/* IOCTLs used in low-level formatting. */
15#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
16#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
17#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
18#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
19
20/* ide-floppy.c */
21extern const struct ide_disk_ops ide_atapi_disk_ops;
22void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
23void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
24
25/* ide-floppy_ioctl.c */
26int ide_floppy_ioctl(ide_drive_t *, struct block_device *, fmode_t,
27 unsigned int, unsigned long);
28
29#ifdef CONFIG_IDE_PROC_FS
30/* ide-floppy_proc.c */
31extern ide_proc_entry_t ide_floppy_proc[];
32extern const struct ide_proc_devset ide_floppy_settings[];
33#endif
34#else
35#define ide_floppy_proc NULL
36#define ide_floppy_settings NULL
37#endif
38
39#endif /*__IDE_FLOPPY_H */
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
new file mode 100644
index 000000000000..2bc51ff73fee
--- /dev/null
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -0,0 +1,289 @@
1/*
2 * ide-floppy IOCTLs handling.
3 */
4
5#include <linux/kernel.h>
6#include <linux/ide.h>
7#include <linux/cdrom.h>
8
9#include <asm/unaligned.h>
10
11#include <scsi/scsi_ioctl.h>
12
13#include "ide-floppy.h"
14
15/*
16 * Obtain the list of formattable capacities.
17 * Very similar to ide_floppy_get_capacity, except that we push the capacity
18 * descriptors to userland, instead of our own structures.
19 *
20 * Userland gives us the following structure:
21 *
22 * struct idefloppy_format_capacities {
23 * int nformats;
24 * struct {
25 * int nblocks;
26 * int blocksize;
27 * } formats[];
28 * };
29 *
30 * userland initializes nformats to the number of allocated formats[] records.
31 * On exit we set nformats to the number of records we've actually initialized.
32 */
33
34static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
35{
36 struct ide_disk_obj *floppy = drive->driver_data;
37 struct ide_atapi_pc pc;
38 u8 header_len, desc_cnt;
39 int i, blocks, length, u_array_size, u_index;
40 int __user *argp;
41
42 if (get_user(u_array_size, arg))
43 return -EFAULT;
44
45 if (u_array_size <= 0)
46 return -EINVAL;
47
48 ide_floppy_create_read_capacity_cmd(&pc);
49 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) {
50 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
51 return -EIO;
52 }
53
54 header_len = pc.buf[3];
55 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
56
57 u_index = 0;
58 argp = arg + 1;
59
60 /*
61 * We always skip the first capacity descriptor. That's the current
62 * capacity. We are interested in the remaining descriptors, the
63 * formattable capacities.
64 */
65 for (i = 1; i < desc_cnt; i++) {
66 unsigned int desc_start = 4 + i*8;
67
68 if (u_index >= u_array_size)
69 break; /* User-supplied buffer too small */
70
71 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
72 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
73
74 if (put_user(blocks, argp))
75 return -EFAULT;
76
77 ++argp;
78
79 if (put_user(length, argp))
80 return -EFAULT;
81
82 ++argp;
83
84 ++u_index;
85 }
86
87 if (put_user(u_index, arg))
88 return -EFAULT;
89
90 return 0;
91}
92
93static void ide_floppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
94 int l, int flags)
95{
96 ide_init_pc(pc);
97 pc->c[0] = GPCMD_FORMAT_UNIT;
98 pc->c[1] = 0x17;
99
100 memset(pc->buf, 0, 12);
101 pc->buf[1] = 0xA2;
102 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
103
104 if (flags & 1) /* Verify bit on... */
105 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */
106 pc->buf[3] = 8;
107
108 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4]));
109 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8]));
110 pc->buf_size = 12;
111 pc->flags |= PC_FLAG_WRITING;
112}
113
114static int ide_floppy_get_sfrp_bit(ide_drive_t *drive)
115{
116 struct ide_disk_obj *floppy = drive->driver_data;
117 struct ide_atapi_pc pc;
118
119 drive->atapi_flags &= ~IDE_AFLAG_SRFP;
120
121 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE);
122 pc.flags |= PC_FLAG_SUPPRESS_ERROR;
123
124 if (ide_queue_pc_tail(drive, floppy->disk, &pc))
125 return 1;
126
127 if (pc.buf[8 + 2] & 0x40)
128 drive->atapi_flags |= IDE_AFLAG_SRFP;
129
130 return 0;
131}
132
133static int ide_floppy_format_unit(ide_drive_t *drive, int __user *arg)
134{
135 struct ide_disk_obj *floppy = drive->driver_data;
136 struct ide_atapi_pc pc;
137 int blocks, length, flags, err = 0;
138
139 if (floppy->openers > 1) {
140 /* Don't format if someone is using the disk */
141 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
142 return -EBUSY;
143 }
144
145 drive->dev_flags |= IDE_DFLAG_FORMAT_IN_PROGRESS;
146
147 /*
148 * Send ATAPI_FORMAT_UNIT to the drive.
149 *
150 * Userland gives us the following structure:
151 *
152 * struct idefloppy_format_command {
153 * int nblocks;
154 * int blocksize;
155 * int flags;
156 * } ;
157 *
158 * flags is a bitmask, currently, the only defined flag is:
159 *
160 * 0x01 - verify media after format.
161 */
162 if (get_user(blocks, arg) ||
163 get_user(length, arg+1) ||
164 get_user(flags, arg+2)) {
165 err = -EFAULT;
166 goto out;
167 }
168
169 (void)ide_floppy_get_sfrp_bit(drive);
170 ide_floppy_create_format_unit_cmd(&pc, blocks, length, flags);
171
172 if (ide_queue_pc_tail(drive, floppy->disk, &pc))
173 err = -EIO;
174
175out:
176 if (err)
177 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
178 return err;
179}
180
181/*
182 * Get ATAPI_FORMAT_UNIT progress indication.
183 *
184 * Userland gives a pointer to an int. The int is set to a progress
185 * indicator 0-65536, with 65536=100%.
186 *
187 * If the drive does not support format progress indication, we just check
188 * the dsc bit, and return either 0 or 65536.
189 */
190
191static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
192{
193 struct ide_disk_obj *floppy = drive->driver_data;
194 struct ide_atapi_pc pc;
195 int progress_indication = 0x10000;
196
197 if (drive->atapi_flags & IDE_AFLAG_SRFP) {
198 ide_create_request_sense_cmd(drive, &pc);
199 if (ide_queue_pc_tail(drive, floppy->disk, &pc))
200 return -EIO;
201
202 if (floppy->sense_key == 2 &&
203 floppy->asc == 4 &&
204 floppy->ascq == 4)
205 progress_indication = floppy->progress_indication;
206
207 /* Else assume format_unit has finished, and we're at 0x10000 */
208 } else {
209 ide_hwif_t *hwif = drive->hwif;
210 unsigned long flags;
211 u8 stat;
212
213 local_irq_save(flags);
214 stat = hwif->tp_ops->read_status(hwif);
215 local_irq_restore(flags);
216
217 progress_indication = ((stat & ATA_DSC) == 0) ? 0 : 0x10000;
218 }
219
220 if (put_user(progress_indication, arg))
221 return -EFAULT;
222
223 return 0;
224}
225
226static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
227 unsigned long arg, unsigned int cmd)
228{
229 struct ide_disk_obj *floppy = drive->driver_data;
230 struct gendisk *disk = floppy->disk;
231 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
232
233 if (floppy->openers > 1)
234 return -EBUSY;
235
236 ide_set_media_lock(drive, disk, prevent);
237
238 if (cmd == CDROMEJECT)
239 ide_do_start_stop(drive, disk, 2);
240
241 return 0;
242}
243
244static int ide_floppy_format_ioctl(ide_drive_t *drive, fmode_t mode,
245 unsigned int cmd, void __user *argp)
246{
247 switch (cmd) {
248 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
249 return 0;
250 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
251 return ide_floppy_get_format_capacities(drive, argp);
252 case IDEFLOPPY_IOCTL_FORMAT_START:
253 if (!(mode & FMODE_WRITE))
254 return -EPERM;
255 return ide_floppy_format_unit(drive, (int __user *)argp);
256 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
257 return ide_floppy_get_format_progress(drive, argp);
258 default:
259 return -ENOTTY;
260 }
261}
262
263int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
264 fmode_t mode, unsigned int cmd, unsigned long arg)
265{
266 struct ide_atapi_pc pc;
267 void __user *argp = (void __user *)arg;
268 int err;
269
270 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
271 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
272
273 err = ide_floppy_format_ioctl(drive, mode, cmd, argp);
274 if (err != -ENOTTY)
275 return err;
276
277 /*
278 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
279 * and CDROM_SEND_PACKET (legacy) ioctls
280 */
281 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
282 err = scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk,
283 mode, cmd, argp);
284
285 if (err == -ENOTTY)
286 err = generic_ide_ioctl(drive, bdev, cmd, arg);
287
288 return err;
289}
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
new file mode 100644
index 000000000000..3ec762cb60ab
--- /dev/null
+++ b/drivers/ide/ide-floppy_proc.c
@@ -0,0 +1,33 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3
4#include "ide-floppy.h"
5
6static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
7 int count, int *eof, void *data)
8{
9 ide_drive_t*drive = (ide_drive_t *)data;
10 int len;
11
12 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
13 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
14}
15
16ide_proc_entry_t ide_floppy_proc[] = {
17 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
18 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
19 { NULL, 0, NULL, NULL }
20};
21
22ide_devset_rw_field(bios_cyl, bios_cyl);
23ide_devset_rw_field(bios_head, bios_head);
24ide_devset_rw_field(bios_sect, bios_sect);
25ide_devset_rw_field(ticks, pc_delay);
26
27const struct ide_proc_devset ide_floppy_settings[] = {
28 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
29 IDE_PROC_DEVSET(bios_head, 0, 255),
30 IDE_PROC_DEVSET(bios_sect, 0, 63),
31 IDE_PROC_DEVSET(ticks, 0, 255),
32 { 0 },
33};
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
new file mode 100644
index 000000000000..b8078b3231f7
--- /dev/null
+++ b/drivers/ide/ide-gd.c
@@ -0,0 +1,401 @@
1#include <linux/module.h>
2#include <linux/types.h>
3#include <linux/string.h>
4#include <linux/kernel.h>
5#include <linux/errno.h>
6#include <linux/genhd.h>
7#include <linux/mutex.h>
8#include <linux/ide.h>
9#include <linux/hdreg.h>
10
11#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
12#define IDE_DISK_MINORS (1 << PARTN_BITS)
13#else
14#define IDE_DISK_MINORS 0
15#endif
16
17#include "ide-disk.h"
18#include "ide-floppy.h"
19
20#define IDE_GD_VERSION "1.18"
21
22/* module parameters */
23static unsigned long debug_mask;
24module_param(debug_mask, ulong, 0644);
25
26static DEFINE_MUTEX(ide_disk_ref_mutex);
27
28static void ide_disk_release(struct kref *);
29
30static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
31{
32 struct ide_disk_obj *idkp = NULL;
33
34 mutex_lock(&ide_disk_ref_mutex);
35 idkp = ide_drv_g(disk, ide_disk_obj);
36 if (idkp) {
37 if (ide_device_get(idkp->drive))
38 idkp = NULL;
39 else
40 kref_get(&idkp->kref);
41 }
42 mutex_unlock(&ide_disk_ref_mutex);
43 return idkp;
44}
45
46static void ide_disk_put(struct ide_disk_obj *idkp)
47{
48 ide_drive_t *drive = idkp->drive;
49
50 mutex_lock(&ide_disk_ref_mutex);
51 kref_put(&idkp->kref, ide_disk_release);
52 ide_device_put(drive);
53 mutex_unlock(&ide_disk_ref_mutex);
54}
55
56sector_t ide_gd_capacity(ide_drive_t *drive)
57{
58 return drive->capacity64;
59}
60
61static int ide_gd_probe(ide_drive_t *);
62
63static void ide_gd_remove(ide_drive_t *drive)
64{
65 struct ide_disk_obj *idkp = drive->driver_data;
66 struct gendisk *g = idkp->disk;
67
68 ide_proc_unregister_driver(drive, idkp->driver);
69
70 del_gendisk(g);
71
72 drive->disk_ops->flush(drive);
73
74 ide_disk_put(idkp);
75}
76
77static void ide_disk_release(struct kref *kref)
78{
79 struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
80 ide_drive_t *drive = idkp->drive;
81 struct gendisk *g = idkp->disk;
82
83 drive->disk_ops = NULL;
84 drive->driver_data = NULL;
85 g->private_data = NULL;
86 put_disk(g);
87 kfree(idkp);
88}
89
90/*
91 * On HPA drives the capacity needs to be
92 * reinitilized on resume otherwise the disk
93 * can not be used and a hard reset is required
94 */
95static void ide_gd_resume(ide_drive_t *drive)
96{
97 if (ata_id_hpa_enabled(drive->id))
98 (void)drive->disk_ops->get_capacity(drive);
99}
100
101static void ide_gd_shutdown(ide_drive_t *drive)
102{
103#ifdef CONFIG_ALPHA
104 /* On Alpha, halt(8) doesn't actually turn the machine off,
105 it puts you into the sort of firmware monitor. Typically,
106 it's used to boot another kernel image, so it's not much
107 different from reboot(8). Therefore, we don't need to
108 spin down the disk in this case, especially since Alpha
109 firmware doesn't handle disks in standby mode properly.
110 On the other hand, it's reasonably safe to turn the power
111 off when the shutdown process reaches the firmware prompt,
112 as the firmware initialization takes rather long time -
113 at least 10 seconds, which should be sufficient for
114 the disk to expire its write cache. */
115 if (system_state != SYSTEM_POWER_OFF) {
116#else
117 if (system_state == SYSTEM_RESTART) {
118#endif
119 drive->disk_ops->flush(drive);
120 return;
121 }
122
123 printk(KERN_INFO "Shutdown: %s\n", drive->name);
124
125 drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
126}
127
128#ifdef CONFIG_IDE_PROC_FS
129static ide_proc_entry_t *ide_disk_proc_entries(ide_drive_t *drive)
130{
131 return (drive->media == ide_disk) ? ide_disk_proc : ide_floppy_proc;
132}
133
134static const struct ide_proc_devset *ide_disk_proc_devsets(ide_drive_t *drive)
135{
136 return (drive->media == ide_disk) ? ide_disk_settings
137 : ide_floppy_settings;
138}
139#endif
140
141static ide_startstop_t ide_gd_do_request(ide_drive_t *drive,
142 struct request *rq, sector_t sector)
143{
144 return drive->disk_ops->do_request(drive, rq, sector);
145}
146
147static int ide_gd_end_request(ide_drive_t *drive, int uptodate, int nrsecs)
148{
149 return drive->disk_ops->end_request(drive, uptodate, nrsecs);
150}
151
152static ide_driver_t ide_gd_driver = {
153 .gen_driver = {
154 .owner = THIS_MODULE,
155 .name = "ide-gd",
156 .bus = &ide_bus_type,
157 },
158 .probe = ide_gd_probe,
159 .remove = ide_gd_remove,
160 .resume = ide_gd_resume,
161 .shutdown = ide_gd_shutdown,
162 .version = IDE_GD_VERSION,
163 .do_request = ide_gd_do_request,
164 .end_request = ide_gd_end_request,
165 .error = __ide_error,
166#ifdef CONFIG_IDE_PROC_FS
167 .proc_entries = ide_disk_proc_entries,
168 .proc_devsets = ide_disk_proc_devsets,
169#endif
170};
171
172static int ide_gd_open(struct block_device *bdev, fmode_t mode)
173{
174 struct gendisk *disk = bdev->bd_disk;
175 struct ide_disk_obj *idkp;
176 ide_drive_t *drive;
177 int ret = 0;
178
179 idkp = ide_disk_get(disk);
180 if (idkp == NULL)
181 return -ENXIO;
182
183 drive = idkp->drive;
184
185 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
186
187 idkp->openers++;
188
189 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
190 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
191 /* Just in case */
192
193 ret = drive->disk_ops->init_media(drive, disk);
194
195 /*
196 * Allow O_NDELAY to open a drive without a disk, or with an
197 * unreadable disk, so that we can get the format capacity
198 * of the drive or begin the format - Sam
199 */
200 if (ret && (mode & FMODE_NDELAY) == 0) {
201 ret = -EIO;
202 goto out_put_idkp;
203 }
204
205 if ((drive->dev_flags & IDE_DFLAG_WP) && (mode & FMODE_WRITE)) {
206 ret = -EROFS;
207 goto out_put_idkp;
208 }
209
210 /*
211 * Ignore the return code from door_lock,
212 * since the open() has already succeeded,
213 * and the door_lock is irrelevant at this point.
214 */
215 drive->disk_ops->set_doorlock(drive, disk, 1);
216 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
217 check_disk_change(bdev);
218 } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
219 ret = -EBUSY;
220 goto out_put_idkp;
221 }
222 return 0;
223
224out_put_idkp:
225 idkp->openers--;
226 ide_disk_put(idkp);
227 return ret;
228}
229
230static int ide_gd_release(struct gendisk *disk, fmode_t mode)
231{
232 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
233 ide_drive_t *drive = idkp->drive;
234
235 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
236
237 if (idkp->openers == 1)
238 drive->disk_ops->flush(drive);
239
240 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
241 drive->disk_ops->set_doorlock(drive, disk, 0);
242 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
243 }
244
245 idkp->openers--;
246
247 ide_disk_put(idkp);
248
249 return 0;
250}
251
252static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
253{
254 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
255 ide_drive_t *drive = idkp->drive;
256
257 geo->heads = drive->bios_head;
258 geo->sectors = drive->bios_sect;
259 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
260 return 0;
261}
262
263static int ide_gd_media_changed(struct gendisk *disk)
264{
265 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
266 ide_drive_t *drive = idkp->drive;
267 int ret;
268
269 /* do not scan partitions twice if this is a removable device */
270 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
271 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
272 return 0;
273 }
274
275 ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED);
276 drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
277
278 return ret;
279}
280
281static int ide_gd_revalidate_disk(struct gendisk *disk)
282{
283 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
284 ide_drive_t *drive = idkp->drive;
285
286 if (ide_gd_media_changed(disk))
287 drive->disk_ops->get_capacity(drive);
288
289 set_capacity(disk, ide_gd_capacity(drive));
290 return 0;
291}
292
293static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode,
294 unsigned int cmd, unsigned long arg)
295{
296 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
297 ide_drive_t *drive = idkp->drive;
298
299 return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg);
300}
301
302static struct block_device_operations ide_gd_ops = {
303 .owner = THIS_MODULE,
304 .open = ide_gd_open,
305 .release = ide_gd_release,
306 .locked_ioctl = ide_gd_ioctl,
307 .getgeo = ide_gd_getgeo,
308 .media_changed = ide_gd_media_changed,
309 .revalidate_disk = ide_gd_revalidate_disk
310};
311
312static int ide_gd_probe(ide_drive_t *drive)
313{
314 const struct ide_disk_ops *disk_ops = NULL;
315 struct ide_disk_obj *idkp;
316 struct gendisk *g;
317
318 /* strstr("foo", "") is non-NULL */
319 if (!strstr("ide-gd", drive->driver_req))
320 goto failed;
321
322#ifdef CONFIG_IDE_GD_ATA
323 if (drive->media == ide_disk)
324 disk_ops = &ide_ata_disk_ops;
325#endif
326#ifdef CONFIG_IDE_GD_ATAPI
327 if (drive->media == ide_floppy)
328 disk_ops = &ide_atapi_disk_ops;
329#endif
330 if (disk_ops == NULL)
331 goto failed;
332
333 if (disk_ops->check(drive, DRV_NAME) == 0) {
334 printk(KERN_ERR PFX "%s: not supported by this driver\n",
335 drive->name);
336 goto failed;
337 }
338
339 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
340 if (!idkp) {
341 printk(KERN_ERR PFX "%s: can't allocate a disk structure\n",
342 drive->name);
343 goto failed;
344 }
345
346 g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif));
347 if (!g)
348 goto out_free_idkp;
349
350 ide_init_disk(g, drive);
351
352 kref_init(&idkp->kref);
353
354 idkp->drive = drive;
355 idkp->driver = &ide_gd_driver;
356 idkp->disk = g;
357
358 g->private_data = &idkp->driver;
359
360 drive->driver_data = idkp;
361 drive->debug_mask = debug_mask;
362 drive->disk_ops = disk_ops;
363
364 disk_ops->setup(drive);
365
366 set_capacity(g, ide_gd_capacity(drive));
367
368 g->minors = IDE_DISK_MINORS;
369 g->driverfs_dev = &drive->gendev;
370 g->flags |= GENHD_FL_EXT_DEVT;
371 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
372 g->flags = GENHD_FL_REMOVABLE;
373 g->fops = &ide_gd_ops;
374 add_disk(g);
375 return 0;
376
377out_free_idkp:
378 kfree(idkp);
379failed:
380 return -ENODEV;
381}
382
383static int __init ide_gd_init(void)
384{
385 printk(KERN_INFO DRV_NAME " driver " IDE_GD_VERSION "\n");
386 return driver_register(&ide_gd_driver.gen_driver);
387}
388
389static void __exit ide_gd_exit(void)
390{
391 driver_unregister(&ide_gd_driver.gen_driver);
392}
393
394MODULE_ALIAS("ide:*m-disk*");
395MODULE_ALIAS("ide-disk");
396MODULE_ALIAS("ide:*m-floppy*");
397MODULE_ALIAS("ide-floppy");
398module_init(ide_gd_init);
399module_exit(ide_gd_exit);
400MODULE_LICENSE("GPL");
401MODULE_DESCRIPTION("generic ATA/ATAPI disk driver");
diff --git a/drivers/ide/ide-gd.h b/drivers/ide/ide-gd.h
new file mode 100644
index 000000000000..7d3d101713e0
--- /dev/null
+++ b/drivers/ide/ide-gd.h
@@ -0,0 +1,44 @@
1#ifndef __IDE_GD_H
2#define __IDE_GD_H
3
4#define DRV_NAME "ide-gd"
5#define PFX DRV_NAME ": "
6
7/* define to see debug info */
8#define IDE_GD_DEBUG_LOG 0
9
10#if IDE_GD_DEBUG_LOG
11#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
12#else
13#define ide_debug_log(lvl, fmt, args...) do {} while (0)
14#endif
15
16struct ide_disk_obj {
17 ide_drive_t *drive;
18 ide_driver_t *driver;
19 struct gendisk *disk;
20 struct kref kref;
21 unsigned int openers; /* protected by BKL for now */
22
23 /* Last failed packet command */
24 struct ide_atapi_pc *failed_pc;
25 /* used for blk_{fs,pc}_request() requests */
26 struct ide_atapi_pc queued_pc;
27
28 /* Last error information */
29 u8 sense_key, asc, ascq;
30
31 int progress_indication;
32
33 /* Device information */
34 /* Current format */
35 int blocks, block_size, bs_factor;
36 /* Last format capacity descriptor */
37 u8 cap_desc[8];
38 /* Copy of the flexible disk page */
39 u8 flexible_disk_page[32];
40};
41
42sector_t ide_gd_capacity(ide_drive_t *);
43
44#endif /* __IDE_GD_H */
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 8fe8b5b9cf7d..81a5282ce1eb 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/ide.h> 21#include <linux/ide.h>
22#include <linux/pci_ids.h>
22 23
23/* FIXME: convert m32r to use ide_platform host driver */ 24/* FIXME: convert m32r to use ide_platform host driver */
24#ifdef CONFIG_M32R 25#ifdef CONFIG_M32R
@@ -27,7 +28,7 @@
27 28
28#define DRV_NAME "ide_generic" 29#define DRV_NAME "ide_generic"
29 30
30static int probe_mask = 0x03; 31static int probe_mask;
31module_param(probe_mask, int, 0); 32module_param(probe_mask, int, 0);
32MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports"); 33MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
33 34
@@ -100,27 +101,64 @@ static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
100static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 }; 101static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
101#endif 102#endif
102 103
104static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
105{
106 struct pci_dev *p = NULL;
107 u16 val;
108
109 for_each_pci_dev(p) {
110
111 if (pci_resource_start(p, 0) == 0x1f0)
112 *primary = 1;
113 if (pci_resource_start(p, 2) == 0x170)
114 *secondary = 1;
115
116 /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
117 if (p->vendor == PCI_VENDOR_ID_CYRIX &&
118 (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
119 p->device == PCI_DEVICE_ID_CYRIX_5520))
120 *primary = *secondary = 1;
121
122 /* Intel MPIIX - PIO ATA on non PCI side of bridge */
123 if (p->vendor == PCI_VENDOR_ID_INTEL &&
124 p->device == PCI_DEVICE_ID_INTEL_82371MX) {
125
126 pci_read_config_word(p, 0x6C, &val);
127 if (val & 0x8000) {
128 /* ATA port enabled */
129 if (val & 0x4000)
130 *secondary = 1;
131 else
132 *primary = 1;
133 }
134 }
135 }
136}
137
103static int __init ide_generic_init(void) 138static int __init ide_generic_init(void)
104{ 139{
105 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS]; 140 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
106 struct ide_host *host;
107 unsigned long io_addr; 141 unsigned long io_addr;
108 int i, rc; 142 int i, rc = 0, primary = 0, secondary = 0;
109 143
110#ifdef CONFIG_MIPS 144 ide_generic_check_pci_legacy_iobases(&primary, &secondary);
111 if (!ide_probe_legacy()) 145
112 return -ENODEV; 146 if (!probe_mask) {
113#endif 147 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
114 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module " 148 "module parameter for probing all legacy ISA IDE ports\n");
115 "parameter for probing all legacy ISA IDE ports\n"); 149
150 if (primary == 0)
151 probe_mask |= 0x1;
116 152
117 memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS); 153 if (secondary == 0)
154 probe_mask |= 0x2;
155 } else
156 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
157 "upon user request\n");
118 158
119 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) { 159 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
120 io_addr = legacy_bases[i]; 160 io_addr = legacy_bases[i];
121 161
122 hws[i] = NULL;
123
124 if ((probe_mask & (1 << i)) && io_addr) { 162 if ((probe_mask & (1 << i)) && io_addr) {
125 if (!request_region(io_addr, 8, DRV_NAME)) { 163 if (!request_region(io_addr, 8, DRV_NAME)) {
126 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX " 164 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
@@ -137,45 +175,27 @@ static int __init ide_generic_init(void)
137 continue; 175 continue;
138 } 176 }
139 177
140 memset(&hw[i], 0, sizeof(hw[i])); 178 memset(&hw, 0, sizeof(hw));
141 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206); 179 ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
142#ifdef CONFIG_IA64 180#ifdef CONFIG_IA64
143 hw[i].irq = isa_irq_to_vector(legacy_irqs[i]); 181 hw.irq = isa_irq_to_vector(legacy_irqs[i]);
144#else 182#else
145 hw[i].irq = legacy_irqs[i]; 183 hw.irq = legacy_irqs[i];
146#endif 184#endif
147 hw[i].chipset = ide_generic; 185 hw.chipset = ide_generic;
148 186
149 hws[i] = &hw[i]; 187 rc = ide_host_add(NULL, hws, NULL);
188 if (rc) {
189 release_region(io_addr + 0x206, 1);
190 release_region(io_addr, 8);
191 }
150 } 192 }
151 } 193 }
152 194
153 host = ide_host_alloc_all(NULL, hws);
154 if (host == NULL) {
155 rc = -ENOMEM;
156 goto err;
157 }
158
159 rc = ide_host_register(host, NULL, hws);
160 if (rc)
161 goto err_free;
162
163 if (ide_generic_sysfs_init()) 195 if (ide_generic_sysfs_init())
164 printk(KERN_ERR DRV_NAME ": failed to create ide_generic " 196 printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
165 "class\n"); 197 "class\n");
166 198
167 return 0;
168err_free:
169 ide_host_free(host);
170err:
171 for (i = 0; i < MAX_HWIFS; i++) {
172 if (hws[i] == NULL)
173 continue;
174
175 io_addr = hws[i]->io_ports.data_addr;
176 release_region(io_addr + 0x206, 1);
177 release_region(io_addr, 8);
178 }
179 return rc; 199 return rc;
180} 200}
181 201
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/ide-h8300.c
index bde7a585f198..e2cdd2e9cdec 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/ide-h8300.c
@@ -80,7 +80,7 @@ static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task)
80 outb(tf->lbah, io_ports->lbah_addr); 80 outb(tf->lbah, io_ports->lbah_addr);
81 81
82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
83 outb((tf->device & HIHI) | drive->select.all, 83 outb((tf->device & HIHI) | drive->select,
84 io_ports->device_addr); 84 io_ports->device_addr);
85} 85}
86 86
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index a896a283f27f..7162d67562af 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -40,6 +40,7 @@
40#include <linux/pci.h> 40#include <linux/pci.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/ide.h> 42#include <linux/ide.h>
43#include <linux/hdreg.h>
43#include <linux/completion.h> 44#include <linux/completion.h>
44#include <linux/reboot.h> 45#include <linux/reboot.h>
45#include <linux/cdrom.h> 46#include <linux/cdrom.h>
@@ -77,8 +78,9 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
77 * decide whether to reenable DMA -- 3 is a random magic for now, 78 * decide whether to reenable DMA -- 3 is a random magic for now,
78 * if we DMA timeout more than 3 times, just stay in PIO 79 * if we DMA timeout more than 3 times, just stay in PIO
79 */ 80 */
80 if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) { 81 if ((drive->dev_flags & IDE_DFLAG_DMA_PIO_RETRY) &&
81 drive->state = 0; 82 drive->retry_pio <= 3) {
83 drive->dev_flags &= ~IDE_DFLAG_DMA_PIO_RETRY;
82 ide_dma_on(drive); 84 ide_dma_on(drive);
83 } 85 }
84 86
@@ -130,21 +132,6 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
130} 132}
131EXPORT_SYMBOL(ide_end_request); 133EXPORT_SYMBOL(ide_end_request);
132 134
133/*
134 * Power Management state machine. This one is rather trivial for now,
135 * we should probably add more, like switching back to PIO on suspend
136 * to help some BIOSes, re-do the door locking on resume, etc...
137 */
138
139enum {
140 ide_pm_flush_cache = ide_pm_state_start_suspend,
141 idedisk_pm_standby,
142
143 idedisk_pm_restore_pio = ide_pm_state_start_resume,
144 idedisk_pm_idle,
145 ide_pm_restore_dma,
146};
147
148static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error) 135static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
149{ 136{
150 struct request_pm_state *pm = rq->data; 137 struct request_pm_state *pm = rq->data;
@@ -153,20 +140,20 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
153 return; 140 return;
154 141
155 switch (pm->pm_step) { 142 switch (pm->pm_step) {
156 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */ 143 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
157 if (pm->pm_state == PM_EVENT_FREEZE) 144 if (pm->pm_state == PM_EVENT_FREEZE)
158 pm->pm_step = ide_pm_state_completed; 145 pm->pm_step = IDE_PM_COMPLETED;
159 else 146 else
160 pm->pm_step = idedisk_pm_standby; 147 pm->pm_step = IDE_PM_STANDBY;
161 break; 148 break;
162 case idedisk_pm_standby: /* Suspend step 2 (standby) complete */ 149 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
163 pm->pm_step = ide_pm_state_completed; 150 pm->pm_step = IDE_PM_COMPLETED;
164 break; 151 break;
165 case idedisk_pm_restore_pio: /* Resume step 1 complete */ 152 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
166 pm->pm_step = idedisk_pm_idle; 153 pm->pm_step = IDE_PM_IDLE;
167 break; 154 break;
168 case idedisk_pm_idle: /* Resume step 2 (idle) complete */ 155 case IDE_PM_IDLE: /* Resume step 2 (idle)*/
169 pm->pm_step = ide_pm_restore_dma; 156 pm->pm_step = IDE_PM_RESTORE_DMA;
170 break; 157 break;
171 } 158 }
172} 159}
@@ -179,40 +166,37 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
179 memset(args, 0, sizeof(*args)); 166 memset(args, 0, sizeof(*args));
180 167
181 switch (pm->pm_step) { 168 switch (pm->pm_step) {
182 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */ 169 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
183 if (drive->media != ide_disk) 170 if (drive->media != ide_disk)
184 break; 171 break;
185 /* Not supported? Switch to next step now. */ 172 /* Not supported? Switch to next step now. */
186 if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) { 173 if (ata_id_flush_enabled(drive->id) == 0 ||
174 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
187 ide_complete_power_step(drive, rq, 0, 0); 175 ide_complete_power_step(drive, rq, 0, 0);
188 return ide_stopped; 176 return ide_stopped;
189 } 177 }
190 if (ide_id_has_flush_cache_ext(drive->id)) 178 if (ata_id_flush_ext_enabled(drive->id))
191 args->tf.command = WIN_FLUSH_CACHE_EXT; 179 args->tf.command = ATA_CMD_FLUSH_EXT;
192 else 180 else
193 args->tf.command = WIN_FLUSH_CACHE; 181 args->tf.command = ATA_CMD_FLUSH;
194 goto out_do_tf; 182 goto out_do_tf;
195 183 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
196 case idedisk_pm_standby: /* Suspend step 2 (standby) */ 184 args->tf.command = ATA_CMD_STANDBYNOW1;
197 args->tf.command = WIN_STANDBYNOW1;
198 goto out_do_tf; 185 goto out_do_tf;
199 186 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
200 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
201 ide_set_max_pio(drive); 187 ide_set_max_pio(drive);
202 /* 188 /*
203 * skip idedisk_pm_idle for ATAPI devices 189 * skip IDE_PM_IDLE for ATAPI devices
204 */ 190 */
205 if (drive->media != ide_disk) 191 if (drive->media != ide_disk)
206 pm->pm_step = ide_pm_restore_dma; 192 pm->pm_step = IDE_PM_RESTORE_DMA;
207 else 193 else
208 ide_complete_power_step(drive, rq, 0, 0); 194 ide_complete_power_step(drive, rq, 0, 0);
209 return ide_stopped; 195 return ide_stopped;
210 196 case IDE_PM_IDLE: /* Resume step 2 (idle) */
211 case idedisk_pm_idle: /* Resume step 2 (idle) */ 197 args->tf.command = ATA_CMD_IDLEIMMEDIATE;
212 args->tf.command = WIN_IDLEIMMEDIATE;
213 goto out_do_tf; 198 goto out_do_tf;
214 199 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
215 case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
216 /* 200 /*
217 * Right now, all we do is call ide_set_dma(drive), 201 * Right now, all we do is call ide_set_dma(drive),
218 * we could be smarter and check for current xfer_speed 202 * we could be smarter and check for current xfer_speed
@@ -221,12 +205,13 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
221 if (drive->hwif->dma_ops == NULL) 205 if (drive->hwif->dma_ops == NULL)
222 break; 206 break;
223 /* 207 /*
224 * TODO: respect ->using_dma setting 208 * TODO: respect IDE_DFLAG_USING_DMA
225 */ 209 */
226 ide_set_dma(drive); 210 ide_set_dma(drive);
227 break; 211 break;
228 } 212 }
229 pm->pm_step = ide_pm_state_completed; 213
214 pm->pm_step = IDE_PM_COMPLETED;
230 return ide_stopped; 215 return ide_stopped;
231 216
232out_do_tf: 217out_do_tf:
@@ -286,7 +271,7 @@ static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
286 if (blk_pm_suspend_request(rq)) { 271 if (blk_pm_suspend_request(rq)) {
287 blk_stop_queue(drive->queue); 272 blk_stop_queue(drive->queue);
288 } else { 273 } else {
289 drive->blocked = 0; 274 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
290 blk_start_queue(drive->queue); 275 blk_start_queue(drive->queue);
291 } 276 }
292 HWGROUP(drive)->rq = NULL; 277 HWGROUP(drive)->rq = NULL;
@@ -322,7 +307,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
322 ide_task_t *task = (ide_task_t *)rq->special; 307 ide_task_t *task = (ide_task_t *)rq->special;
323 308
324 if (rq->errors == 0) 309 if (rq->errors == 0)
325 rq->errors = !OK_STAT(stat, READY_STAT, BAD_STAT); 310 rq->errors = !OK_STAT(stat, ATA_DRDY, BAD_STAT);
326 311
327 if (task) { 312 if (task) {
328 struct ide_taskfile *tf = &task->tf; 313 struct ide_taskfile *tf = &task->tf;
@@ -342,7 +327,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
342 drive->name, rq->pm->pm_step, stat, err); 327 drive->name, rq->pm->pm_step, stat, err);
343#endif 328#endif
344 ide_complete_power_step(drive, rq, stat, err); 329 ide_complete_power_step(drive, rq, stat, err);
345 if (pm->pm_step == ide_pm_state_completed) 330 if (pm->pm_step == IDE_PM_COMPLETED)
346 ide_complete_pm_request(drive, rq); 331 ide_complete_pm_request(drive, rq);
347 return; 332 return;
348 } 333 }
@@ -373,29 +358,30 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
373{ 358{
374 ide_hwif_t *hwif = drive->hwif; 359 ide_hwif_t *hwif = drive->hwif;
375 360
376 if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { 361 if ((stat & ATA_BUSY) ||
362 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
377 /* other bits are useless when BUSY */ 363 /* other bits are useless when BUSY */
378 rq->errors |= ERROR_RESET; 364 rq->errors |= ERROR_RESET;
379 } else if (stat & ERR_STAT) { 365 } else if (stat & ATA_ERR) {
380 /* err has different meaning on cdrom and tape */ 366 /* err has different meaning on cdrom and tape */
381 if (err == ABRT_ERR) { 367 if (err == ATA_ABORTED) {
382 if (drive->select.b.lba && 368 if ((drive->dev_flags & IDE_DFLAG_LBA) &&
383 /* some newer drives don't support WIN_SPECIFY */ 369 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
384 hwif->tp_ops->read_status(hwif) == WIN_SPECIFY) 370 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
385 return ide_stopped; 371 return ide_stopped;
386 } else if ((err & BAD_CRC) == BAD_CRC) { 372 } else if ((err & BAD_CRC) == BAD_CRC) {
387 /* UDMA crc error, just retry the operation */ 373 /* UDMA crc error, just retry the operation */
388 drive->crc_count++; 374 drive->crc_count++;
389 } else if (err & (BBD_ERR | ECC_ERR)) { 375 } else if (err & (ATA_BBK | ATA_UNC)) {
390 /* retries won't help these */ 376 /* retries won't help these */
391 rq->errors = ERROR_MAX; 377 rq->errors = ERROR_MAX;
392 } else if (err & TRK0_ERR) { 378 } else if (err & ATA_TRK0NF) {
393 /* help it find track zero */ 379 /* help it find track zero */
394 rq->errors |= ERROR_RECAL; 380 rq->errors |= ERROR_RECAL;
395 } 381 }
396 } 382 }
397 383
398 if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && 384 if ((stat & ATA_DRQ) && rq_data_dir(rq) == READ &&
399 (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) { 385 (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) {
400 int nsect = drive->mult_count ? drive->mult_count : 1; 386 int nsect = drive->mult_count ? drive->mult_count : 1;
401 387
@@ -407,7 +393,7 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
407 return ide_stopped; 393 return ide_stopped;
408 } 394 }
409 395
410 if (hwif->tp_ops->read_status(hwif) & (BUSY_STAT | DRQ_STAT)) 396 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
411 rq->errors |= ERROR_RESET; 397 rq->errors |= ERROR_RESET;
412 398
413 if ((rq->errors & ERROR_RESET) == ERROR_RESET) { 399 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
@@ -427,16 +413,17 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
427{ 413{
428 ide_hwif_t *hwif = drive->hwif; 414 ide_hwif_t *hwif = drive->hwif;
429 415
430 if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { 416 if ((stat & ATA_BUSY) ||
417 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
431 /* other bits are useless when BUSY */ 418 /* other bits are useless when BUSY */
432 rq->errors |= ERROR_RESET; 419 rq->errors |= ERROR_RESET;
433 } else { 420 } else {
434 /* add decoding error stuff */ 421 /* add decoding error stuff */
435 } 422 }
436 423
437 if (hwif->tp_ops->read_status(hwif) & (BUSY_STAT | DRQ_STAT)) 424 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
438 /* force an abort */ 425 /* force an abort */
439 hwif->tp_ops->exec_command(hwif, WIN_IDLEIMMEDIATE); 426 hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
440 427
441 if (rq->errors >= ERROR_MAX) { 428 if (rq->errors >= ERROR_MAX) {
442 ide_kill_rq(drive, rq); 429 ide_kill_rq(drive, rq);
@@ -508,20 +495,20 @@ static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
508 tf->lbal = drive->sect; 495 tf->lbal = drive->sect;
509 tf->lbam = drive->cyl; 496 tf->lbam = drive->cyl;
510 tf->lbah = drive->cyl >> 8; 497 tf->lbah = drive->cyl >> 8;
511 tf->device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA; 498 tf->device = (drive->head - 1) | drive->select;
512 tf->command = WIN_SPECIFY; 499 tf->command = ATA_CMD_INIT_DEV_PARAMS;
513} 500}
514 501
515static void ide_tf_set_restore_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 502static void ide_tf_set_restore_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
516{ 503{
517 tf->nsect = drive->sect; 504 tf->nsect = drive->sect;
518 tf->command = WIN_RESTORE; 505 tf->command = ATA_CMD_RESTORE;
519} 506}
520 507
521static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 508static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
522{ 509{
523 tf->nsect = drive->mult_req; 510 tf->nsect = drive->mult_req;
524 tf->command = WIN_SETMULT; 511 tf->command = ATA_CMD_SET_MULTI;
525} 512}
526 513
527static ide_startstop_t ide_disk_special(ide_drive_t *drive) 514static ide_startstop_t ide_disk_special(ide_drive_t *drive)
@@ -540,8 +527,6 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
540 ide_tf_set_restore_cmd(drive, &args.tf); 527 ide_tf_set_restore_cmd(drive, &args.tf);
541 } else if (s->b.set_multmode) { 528 } else if (s->b.set_multmode) {
542 s->b.set_multmode = 0; 529 s->b.set_multmode = 0;
543 if (drive->mult_req > drive->id->max_multsect)
544 drive->mult_req = drive->id->max_multsect;
545 ide_tf_set_setmult_cmd(drive, &args.tf); 530 ide_tf_set_setmult_cmd(drive, &args.tf);
546 } else if (s->all) { 531 } else if (s->all) {
547 int special = s->all; 532 int special = s->all;
@@ -558,37 +543,14 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
558 return ide_started; 543 return ide_started;
559} 544}
560 545
561/*
562 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
563 */
564static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
565{
566 switch (req_pio) {
567 case 202:
568 case 201:
569 case 200:
570 case 102:
571 case 101:
572 case 100:
573 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
574 case 9:
575 case 8:
576 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
577 case 7:
578 case 6:
579 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
580 default:
581 return 0;
582 }
583}
584
585/** 546/**
586 * do_special - issue some special commands 547 * do_special - issue some special commands
587 * @drive: drive the command is for 548 * @drive: drive the command is for
588 * 549 *
589 * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT 550 * do_special() is used to issue ATA_CMD_INIT_DEV_PARAMS,
590 * commands to a drive. It used to do much more, but has been scaled 551 * ATA_CMD_RESTORE and ATA_CMD_SET_MULTI commands to a drive.
591 * back. 552 *
553 * It used to do much more, but has been scaled back.
592 */ 554 */
593 555
594static ide_startstop_t do_special (ide_drive_t *drive) 556static ide_startstop_t do_special (ide_drive_t *drive)
@@ -598,45 +560,12 @@ static ide_startstop_t do_special (ide_drive_t *drive)
598#ifdef DEBUG 560#ifdef DEBUG
599 printk("%s: do_special: 0x%02x\n", drive->name, s->all); 561 printk("%s: do_special: 0x%02x\n", drive->name, s->all);
600#endif 562#endif
601 if (s->b.set_tune) { 563 if (drive->media == ide_disk)
602 ide_hwif_t *hwif = drive->hwif; 564 return ide_disk_special(drive);
603 const struct ide_port_ops *port_ops = hwif->port_ops;
604 u8 req_pio = drive->tune_req;
605
606 s->b.set_tune = 0;
607
608 if (set_pio_mode_abuse(drive->hwif, req_pio)) {
609 /*
610 * take ide_lock for drive->[no_]unmask/[no_]io_32bit
611 */
612 if (req_pio == 8 || req_pio == 9) {
613 unsigned long flags;
614
615 spin_lock_irqsave(&ide_lock, flags);
616 port_ops->set_pio_mode(drive, req_pio);
617 spin_unlock_irqrestore(&ide_lock, flags);
618 } else
619 port_ops->set_pio_mode(drive, req_pio);
620 } else {
621 int keep_dma = drive->using_dma;
622
623 ide_set_pio(drive, req_pio);
624
625 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
626 if (keep_dma)
627 ide_dma_on(drive);
628 }
629 }
630
631 return ide_stopped;
632 } else {
633 if (drive->media == ide_disk)
634 return ide_disk_special(drive);
635 565
636 s->all = 0; 566 s->all = 0;
637 drive->mult_req = 0; 567 drive->mult_req = 0;
638 return ide_stopped; 568 return ide_stopped;
639 }
640} 569}
641 570
642void ide_map_sg(ide_drive_t *drive, struct request *rq) 571void ide_map_sg(ide_drive_t *drive, struct request *rq)
@@ -716,9 +645,71 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
716 return ide_stopped; 645 return ide_stopped;
717} 646}
718 647
648int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
649 int arg)
650{
651 struct request_queue *q = drive->queue;
652 struct request *rq;
653 int ret = 0;
654
655 if (!(setting->flags & DS_SYNC))
656 return setting->set(drive, arg);
657
658 rq = blk_get_request(q, READ, __GFP_WAIT);
659 rq->cmd_type = REQ_TYPE_SPECIAL;
660 rq->cmd_len = 5;
661 rq->cmd[0] = REQ_DEVSET_EXEC;
662 *(int *)&rq->cmd[1] = arg;
663 rq->special = setting->set;
664
665 if (blk_execute_rq(q, NULL, rq, 0))
666 ret = rq->errors;
667 blk_put_request(rq);
668
669 return ret;
670}
671EXPORT_SYMBOL_GPL(ide_devset_execute);
672
719static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) 673static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
720{ 674{
721 switch (rq->cmd[0]) { 675 u8 cmd = rq->cmd[0];
676
677 if (cmd == REQ_PARK_HEADS || cmd == REQ_UNPARK_HEADS) {
678 ide_task_t task;
679 struct ide_taskfile *tf = &task.tf;
680
681 memset(&task, 0, sizeof(task));
682 if (cmd == REQ_PARK_HEADS) {
683 drive->sleep = *(unsigned long *)rq->special;
684 drive->dev_flags |= IDE_DFLAG_SLEEPING;
685 tf->command = ATA_CMD_IDLEIMMEDIATE;
686 tf->feature = 0x44;
687 tf->lbal = 0x4c;
688 tf->lbam = 0x4e;
689 tf->lbah = 0x55;
690 task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
691 } else /* cmd == REQ_UNPARK_HEADS */
692 tf->command = ATA_CMD_CHK_POWER;
693
694 task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
695 task.rq = rq;
696 drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
697 return do_rw_taskfile(drive, &task);
698 }
699
700 switch (cmd) {
701 case REQ_DEVSET_EXEC:
702 {
703 int err, (*setfunc)(ide_drive_t *, int) = rq->special;
704
705 err = setfunc(drive, *(int *)&rq->cmd[1]);
706 if (err)
707 rq->errors = err;
708 else
709 err = 1;
710 ide_end_request(drive, err, 0);
711 return ide_stopped;
712 }
722 case REQ_DRIVE_RESET: 713 case REQ_DRIVE_RESET:
723 return ide_do_reset(drive); 714 return ide_do_reset(drive);
724 default: 715 default:
@@ -733,11 +724,11 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
733 struct request_pm_state *pm = rq->data; 724 struct request_pm_state *pm = rq->data;
734 725
735 if (blk_pm_suspend_request(rq) && 726 if (blk_pm_suspend_request(rq) &&
736 pm->pm_step == ide_pm_state_start_suspend) 727 pm->pm_step == IDE_PM_START_SUSPEND)
737 /* Mark drive blocked when starting the suspend sequence. */ 728 /* Mark drive blocked when starting the suspend sequence. */
738 drive->blocked = 1; 729 drive->dev_flags |= IDE_DFLAG_BLOCKED;
739 else if (blk_pm_resume_request(rq) && 730 else if (blk_pm_resume_request(rq) &&
740 pm->pm_step == ide_pm_state_start_resume) { 731 pm->pm_step == IDE_PM_START_RESUME) {
741 /* 732 /*
742 * The first thing we do on wakeup is to wait for BSY bit to 733 * The first thing we do on wakeup is to wait for BSY bit to
743 * go away (with a looong timeout) as a drive on this hwif may 734 * go away (with a looong timeout) as a drive on this hwif may
@@ -766,9 +757,7 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
766 * start_request - start of I/O and command issuing for IDE 757 * start_request - start of I/O and command issuing for IDE
767 * 758 *
768 * start_request() initiates handling of a new I/O request. It 759 * start_request() initiates handling of a new I/O request. It
769 * accepts commands and I/O (read/write) requests. It also does 760 * accepts commands and I/O (read/write) requests.
770 * the final remapping for weird stuff like EZDrive. Once
771 * device mapper can work sector level the EZDrive stuff can go away
772 * 761 *
773 * FIXME: this function needs a rename 762 * FIXME: this function needs a rename
774 */ 763 */
@@ -776,7 +765,6 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
776static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq) 765static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
777{ 766{
778 ide_startstop_t startstop; 767 ide_startstop_t startstop;
779 sector_t block;
780 768
781 BUG_ON(!blk_rq_started(rq)); 769 BUG_ON(!blk_rq_started(rq));
782 770
@@ -791,21 +779,12 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
791 goto kill_rq; 779 goto kill_rq;
792 } 780 }
793 781
794 block = rq->sector;
795 if (blk_fs_request(rq) &&
796 (drive->media == ide_disk || drive->media == ide_floppy)) {
797 block += drive->sect0;
798 }
799 /* Yecch - this will shift the entire interval,
800 possibly killing some innocent following sector */
801 if (block == 0 && drive->remap_0_to_1 == 1)
802 block = 1; /* redirect MBR access to EZ-Drive partn table */
803
804 if (blk_pm_request(rq)) 782 if (blk_pm_request(rq))
805 ide_check_pm_state(drive, rq); 783 ide_check_pm_state(drive, rq);
806 784
807 SELECT_DRIVE(drive); 785 SELECT_DRIVE(drive);
808 if (ide_wait_stat(&startstop, drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) { 786 if (ide_wait_stat(&startstop, drive, drive->ready_stat,
787 ATA_BUSY | ATA_DRQ, WAIT_READY)) {
809 printk(KERN_ERR "%s: drive not ready for command\n", drive->name); 788 printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
810 return startstop; 789 return startstop;
811 } 790 }
@@ -829,7 +808,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
829#endif 808#endif
830 startstop = ide_start_power_step(drive, rq); 809 startstop = ide_start_power_step(drive, rq);
831 if (startstop == ide_stopped && 810 if (startstop == ide_stopped &&
832 pm->pm_step == ide_pm_state_completed) 811 pm->pm_step == IDE_PM_COMPLETED)
833 ide_complete_pm_request(drive, rq); 812 ide_complete_pm_request(drive, rq);
834 return startstop; 813 return startstop;
835 } else if (!rq->rq_disk && blk_special_request(rq)) 814 } else if (!rq->rq_disk && blk_special_request(rq))
@@ -844,7 +823,8 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
844 return ide_special_rq(drive, rq); 823 return ide_special_rq(drive, rq);
845 824
846 drv = *(ide_driver_t **)rq->rq_disk->private_data; 825 drv = *(ide_driver_t **)rq->rq_disk->private_data;
847 return drv->do_request(drive, rq, block); 826
827 return drv->do_request(drive, rq, rq->sector);
848 } 828 }
849 return do_special(drive); 829 return do_special(drive);
850kill_rq: 830kill_rq:
@@ -866,7 +846,7 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
866 if (timeout > WAIT_WORSTCASE) 846 if (timeout > WAIT_WORSTCASE)
867 timeout = WAIT_WORSTCASE; 847 timeout = WAIT_WORSTCASE;
868 drive->sleep = timeout + jiffies; 848 drive->sleep = timeout + jiffies;
869 drive->sleeping = 1; 849 drive->dev_flags |= IDE_DFLAG_SLEEPING;
870} 850}
871 851
872EXPORT_SYMBOL(ide_stall_queue); 852EXPORT_SYMBOL(ide_stall_queue);
@@ -906,18 +886,23 @@ repeat:
906 } 886 }
907 887
908 do { 888 do {
909 if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep)) 889 u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING);
910 && !elv_queue_empty(drive->queue)) { 890 u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING));
911 if (!best 891
912 || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep))) 892 if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) &&
913 || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best)))) 893 !elv_queue_empty(drive->queue)) {
914 { 894 if (best == NULL ||
895 (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) ||
896 (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) {
915 if (!blk_queue_plugged(drive->queue)) 897 if (!blk_queue_plugged(drive->queue))
916 best = drive; 898 best = drive;
917 } 899 }
918 } 900 }
919 } while ((drive = drive->next) != hwgroup->drive); 901 } while ((drive = drive->next) != hwgroup->drive);
920 if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) { 902
903 if (best && (best->dev_flags & IDE_DFLAG_NICE1) &&
904 (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 &&
905 best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
921 long t = (signed long)(WAKEUP(best) - jiffies); 906 long t = (signed long)(WAKEUP(best) - jiffies);
922 if (t >= WAIT_MIN_SLEEP) { 907 if (t >= WAIT_MIN_SLEEP) {
923 /* 908 /*
@@ -926,7 +911,7 @@ repeat:
926 */ 911 */
927 drive = best->next; 912 drive = best->next;
928 do { 913 do {
929 if (!drive->sleeping 914 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0
930 && time_before(jiffies - best->service_time, WAKEUP(drive)) 915 && time_before(jiffies - best->service_time, WAKEUP(drive))
931 && time_before(WAKEUP(drive), jiffies + t)) 916 && time_before(WAKEUP(drive), jiffies + t))
932 { 917 {
@@ -997,7 +982,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
997 hwgroup->rq = NULL; 982 hwgroup->rq = NULL;
998 drive = hwgroup->drive; 983 drive = hwgroup->drive;
999 do { 984 do {
1000 if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) { 985 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) &&
986 (sleeping == 0 ||
987 time_before(drive->sleep, sleep))) {
1001 sleeping = 1; 988 sleeping = 1;
1002 sleep = drive->sleep; 989 sleep = drive->sleep;
1003 } 990 }
@@ -1046,7 +1033,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1046 } 1033 }
1047 hwgroup->hwif = hwif; 1034 hwgroup->hwif = hwif;
1048 hwgroup->drive = drive; 1035 hwgroup->drive = drive;
1049 drive->sleeping = 0; 1036 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
1050 drive->service_start = jiffies; 1037 drive->service_start = jiffies;
1051 1038
1052 if (blk_queue_plugged(drive->queue)) { 1039 if (blk_queue_plugged(drive->queue)) {
@@ -1080,7 +1067,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1080 * We count how many times we loop here to make sure we service 1067 * We count how many times we loop here to make sure we service
1081 * all drives in the hwgroup without looping for ever 1068 * all drives in the hwgroup without looping for ever
1082 */ 1069 */
1083 if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) { 1070 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
1071 blk_pm_request(rq) == 0 &&
1072 (rq->cmd_flags & REQ_PREEMPT) == 0) {
1084 drive = drive->next ? drive->next : hwgroup->drive; 1073 drive = drive->next ? drive->next : hwgroup->drive;
1085 if (loops++ < 4 && !blk_queue_plugged(drive->queue)) 1074 if (loops++ < 4 && !blk_queue_plugged(drive->queue))
1086 goto again; 1075 goto again;
@@ -1153,8 +1142,8 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1153 * a timeout -- we'll reenable after we finish this next request 1142 * a timeout -- we'll reenable after we finish this next request
1154 * (or rather the first chunk of it) in pio. 1143 * (or rather the first chunk of it) in pio.
1155 */ 1144 */
1145 drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
1156 drive->retry_pio++; 1146 drive->retry_pio++;
1157 drive->state = DMA_PIO_RETRY;
1158 ide_dma_off_quietly(drive); 1147 ide_dma_off_quietly(drive);
1159 1148
1160 /* 1149 /*
@@ -1325,7 +1314,7 @@ static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
1325 if (hwif->irq == irq) { 1314 if (hwif->irq == irq) {
1326 stat = hwif->tp_ops->read_status(hwif); 1315 stat = hwif->tp_ops->read_status(hwif);
1327 1316
1328 if (!OK_STAT(stat, READY_STAT, BAD_STAT)) { 1317 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
1329 /* Try to not flood the console with msgs */ 1318 /* Try to not flood the console with msgs */
1330 static unsigned long last_msgtime, count; 1319 static unsigned long last_msgtime, count;
1331 ++count; 1320 ++count;
@@ -1451,23 +1440,16 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1451 del_timer(&hwgroup->timer); 1440 del_timer(&hwgroup->timer);
1452 spin_unlock(&ide_lock); 1441 spin_unlock(&ide_lock);
1453 1442
1454 /* Some controllers might set DMA INTR no matter DMA or PIO; 1443 if (hwif->port_ops && hwif->port_ops->clear_irq)
1455 * bmdma status might need to be cleared even for 1444 hwif->port_ops->clear_irq(drive);
1456 * PIO interrupts to prevent spurious/lost irq.
1457 */
1458 if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
1459 /* ide_dma_end() needs bmdma status for error checking.
1460 * So, skip clearing bmdma status here and leave it
1461 * to ide_dma_end() if this is dma interrupt.
1462 */
1463 hwif->ide_dma_clear_irq(drive);
1464 1445
1465 if (drive->unmask) 1446 if (drive->dev_flags & IDE_DFLAG_UNMASK)
1466 local_irq_enable_in_hardirq(); 1447 local_irq_enable_in_hardirq();
1448
1467 /* service this interrupt, may set handler for next interrupt */ 1449 /* service this interrupt, may set handler for next interrupt */
1468 startstop = handler(drive); 1450 startstop = handler(drive);
1469 spin_lock_irq(&ide_lock);
1470 1451
1452 spin_lock_irq(&ide_lock);
1471 /* 1453 /*
1472 * Note that handler() may have set things up for another 1454 * Note that handler() may have set things up for another
1473 * interrupt to occur soon, but it cannot happen until 1455 * interrupt to occur soon, but it cannot happen until
@@ -1511,8 +1493,8 @@ void ide_do_drive_cmd(ide_drive_t *drive, struct request *rq)
1511 1493
1512 spin_lock_irqsave(&ide_lock, flags); 1494 spin_lock_irqsave(&ide_lock, flags);
1513 hwgroup->rq = NULL; 1495 hwgroup->rq = NULL;
1514 __elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 1); 1496 __elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
1515 __generic_unplug_device(drive->queue); 1497 blk_start_queueing(drive->queue);
1516 spin_unlock_irqrestore(&ide_lock, flags); 1498 spin_unlock_irqrestore(&ide_lock, flags);
1517} 1499}
1518 1500
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
new file mode 100644
index 000000000000..fcde16bb53a7
--- /dev/null
+++ b/drivers/ide/ide-ioctls.c
@@ -0,0 +1,298 @@
1/*
2 * IDE ioctls handling.
3 */
4
5#include <linux/hdreg.h>
6#include <linux/ide.h>
7
8static const struct ide_ioctl_devset ide_ioctl_settings[] = {
9{ HDIO_GET_32BIT, HDIO_SET_32BIT, &ide_devset_io_32bit },
10{ HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, &ide_devset_keepsettings },
11{ HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, &ide_devset_unmaskirq },
12{ HDIO_GET_DMA, HDIO_SET_DMA, &ide_devset_using_dma },
13{ -1, HDIO_SET_PIO_MODE, &ide_devset_pio_mode },
14{ 0 }
15};
16
17int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,
18 unsigned int cmd, unsigned long arg,
19 const struct ide_ioctl_devset *s)
20{
21 const struct ide_devset *ds;
22 unsigned long flags;
23 int err = -EOPNOTSUPP;
24
25 for (; (ds = s->setting); s++) {
26 if (ds->get && s->get_ioctl == cmd)
27 goto read_val;
28 else if (ds->set && s->set_ioctl == cmd)
29 goto set_val;
30 }
31
32 return err;
33
34read_val:
35 mutex_lock(&ide_setting_mtx);
36 spin_lock_irqsave(&ide_lock, flags);
37 err = ds->get(drive);
38 spin_unlock_irqrestore(&ide_lock, flags);
39 mutex_unlock(&ide_setting_mtx);
40 return err >= 0 ? put_user(err, (long __user *)arg) : err;
41
42set_val:
43 if (bdev != bdev->bd_contains)
44 err = -EINVAL;
45 else {
46 if (!capable(CAP_SYS_ADMIN))
47 err = -EACCES;
48 else {
49 mutex_lock(&ide_setting_mtx);
50 err = ide_devset_execute(drive, ds, arg);
51 mutex_unlock(&ide_setting_mtx);
52 }
53 }
54 return err;
55}
56EXPORT_SYMBOL_GPL(ide_setting_ioctl);
57
58static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
59 unsigned long arg)
60{
61 u16 *id = NULL;
62 int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
63 int rc = 0;
64
65 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
66 rc = -ENOMSG;
67 goto out;
68 }
69
70 id = kmalloc(size, GFP_KERNEL);
71 if (id == NULL) {
72 rc = -ENOMEM;
73 goto out;
74 }
75
76 memcpy(id, drive->id, size);
77 ata_id_to_hd_driveid(id);
78
79 if (copy_to_user((void __user *)arg, id, size))
80 rc = -EFAULT;
81
82 kfree(id);
83out:
84 return rc;
85}
86
87static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg)
88{
89 return put_user((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)
90 << IDE_NICE_DSC_OVERLAP) |
91 (!!(drive->dev_flags & IDE_DFLAG_NICE1)
92 << IDE_NICE_1), (long __user *)arg);
93}
94
95static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
96{
97 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
98 return -EPERM;
99
100 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
101 (drive->media == ide_disk || drive->media == ide_floppy ||
102 (drive->dev_flags & IDE_DFLAG_SCSI)))
103 return -EPERM;
104
105 if ((arg >> IDE_NICE_DSC_OVERLAP) & 1)
106 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
107 else
108 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
109
110 if ((arg >> IDE_NICE_1) & 1)
111 drive->dev_flags |= IDE_DFLAG_NICE1;
112 else
113 drive->dev_flags &= ~IDE_DFLAG_NICE1;
114
115 return 0;
116}
117
118static int ide_cmd_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg)
119{
120 u8 *buf = NULL;
121 int bufsize = 0, err = 0;
122 u8 args[4], xfer_rate = 0;
123 ide_task_t tfargs;
124 struct ide_taskfile *tf = &tfargs.tf;
125 u16 *id = drive->id;
126
127 if (NULL == (void *) arg) {
128 struct request *rq;
129
130 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
131 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
132 err = blk_execute_rq(drive->queue, NULL, rq, 0);
133 blk_put_request(rq);
134
135 return err;
136 }
137
138 if (copy_from_user(args, (void __user *)arg, 4))
139 return -EFAULT;
140
141 memset(&tfargs, 0, sizeof(ide_task_t));
142 tf->feature = args[2];
143 if (args[0] == ATA_CMD_SMART) {
144 tf->nsect = args[3];
145 tf->lbal = args[1];
146 tf->lbam = 0x4f;
147 tf->lbah = 0xc2;
148 tfargs.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT;
149 } else {
150 tf->nsect = args[1];
151 tfargs.tf_flags = IDE_TFLAG_OUT_FEATURE |
152 IDE_TFLAG_OUT_NSECT | IDE_TFLAG_IN_NSECT;
153 }
154 tf->command = args[0];
155 tfargs.data_phase = args[3] ? TASKFILE_IN : TASKFILE_NO_DATA;
156
157 if (args[3]) {
158 tfargs.tf_flags |= IDE_TFLAG_IO_16BIT;
159 bufsize = SECTOR_SIZE * args[3];
160 buf = kzalloc(bufsize, GFP_KERNEL);
161 if (buf == NULL)
162 return -ENOMEM;
163 }
164
165 if (tf->command == ATA_CMD_SET_FEATURES &&
166 tf->feature == SETFEATURES_XFER &&
167 tf->nsect >= XFER_SW_DMA_0 &&
168 (id[ATA_ID_UDMA_MODES] ||
169 id[ATA_ID_MWDMA_MODES] ||
170 id[ATA_ID_SWDMA_MODES])) {
171 xfer_rate = args[1];
172 if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
173 printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
174 "be set\n", drive->name);
175 goto abort;
176 }
177 }
178
179 err = ide_raw_taskfile(drive, &tfargs, buf, args[3]);
180
181 args[0] = tf->status;
182 args[1] = tf->error;
183 args[2] = tf->nsect;
184
185 if (!err && xfer_rate) {
186 /* active-retuning-calls future */
187 ide_set_xfer_rate(drive, xfer_rate);
188 ide_driveid_update(drive);
189 }
190abort:
191 if (copy_to_user((void __user *)arg, &args, 4))
192 err = -EFAULT;
193 if (buf) {
194 if (copy_to_user((void __user *)(arg + 4), buf, bufsize))
195 err = -EFAULT;
196 kfree(buf);
197 }
198 return err;
199}
200
201static int ide_task_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg)
202{
203 void __user *p = (void __user *)arg;
204 int err = 0;
205 u8 args[7];
206 ide_task_t task;
207
208 if (copy_from_user(args, p, 7))
209 return -EFAULT;
210
211 memset(&task, 0, sizeof(task));
212 memcpy(&task.tf_array[7], &args[1], 6);
213 task.tf.command = args[0];
214 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
215
216 err = ide_no_data_taskfile(drive, &task);
217
218 args[0] = task.tf.command;
219 memcpy(&args[1], &task.tf_array[7], 6);
220
221 if (copy_to_user(p, args, 7))
222 err = -EFAULT;
223
224 return err;
225}
226
227static int generic_drive_reset(ide_drive_t *drive)
228{
229 struct request *rq;
230 int ret = 0;
231
232 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
233 rq->cmd_type = REQ_TYPE_SPECIAL;
234 rq->cmd_len = 1;
235 rq->cmd[0] = REQ_DRIVE_RESET;
236 rq->cmd_flags |= REQ_SOFTBARRIER;
237 if (blk_execute_rq(drive->queue, NULL, rq, 1))
238 ret = rq->errors;
239 blk_put_request(rq);
240 return ret;
241}
242
243int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,
244 unsigned int cmd, unsigned long arg)
245{
246 int err;
247
248 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_ioctl_settings);
249 if (err != -EOPNOTSUPP)
250 return err;
251
252 switch (cmd) {
253 case HDIO_OBSOLETE_IDENTITY:
254 case HDIO_GET_IDENTITY:
255 if (bdev != bdev->bd_contains)
256 return -EINVAL;
257 return ide_get_identity_ioctl(drive, cmd, arg);
258 case HDIO_GET_NICE:
259 return ide_get_nice_ioctl(drive, arg);
260 case HDIO_SET_NICE:
261 if (!capable(CAP_SYS_ADMIN))
262 return -EACCES;
263 return ide_set_nice_ioctl(drive, arg);
264#ifdef CONFIG_IDE_TASK_IOCTL
265 case HDIO_DRIVE_TASKFILE:
266 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
267 return -EACCES;
268 if (drive->media == ide_disk)
269 return ide_taskfile_ioctl(drive, cmd, arg);
270 return -ENOMSG;
271#endif
272 case HDIO_DRIVE_CMD:
273 if (!capable(CAP_SYS_RAWIO))
274 return -EACCES;
275 return ide_cmd_ioctl(drive, cmd, arg);
276 case HDIO_DRIVE_TASK:
277 if (!capable(CAP_SYS_RAWIO))
278 return -EACCES;
279 return ide_task_ioctl(drive, cmd, arg);
280 case HDIO_DRIVE_RESET:
281 if (!capable(CAP_SYS_ADMIN))
282 return -EACCES;
283 return generic_drive_reset(drive);
284 case HDIO_GET_BUSSTATE:
285 if (!capable(CAP_SYS_ADMIN))
286 return -EACCES;
287 if (put_user(BUSSTATE_ON, (long __user *)arg))
288 return -EFAULT;
289 return 0;
290 case HDIO_SET_BUSSTATE:
291 if (!capable(CAP_SYS_ADMIN))
292 return -EACCES;
293 return -EOPNOTSUPP;
294 default:
295 return -EINVAL;
296 }
297}
298EXPORT_SYMBOL(generic_ide_ioctl);
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 2cbadffe922e..5d6ba14e211d 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
3 * Copyright (C) 2003 Red Hat <alan@redhat.com> 3 * Copyright (C) 2003 Red Hat
4 * 4 *
5 */ 5 */
6 6
@@ -18,7 +18,6 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/hdreg.h>
22#include <linux/ide.h> 21#include <linux/ide.h>
23#include <linux/bitops.h> 22#include <linux/bitops.h>
24#include <linux/nmi.h> 23#include <linux/nmi.h>
@@ -182,7 +181,7 @@ void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
182 tf_outb(tf->lbah, io_ports->lbah_addr); 181 tf_outb(tf->lbah, io_ports->lbah_addr);
183 182
184 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 183 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
185 tf_outb((tf->device & HIHI) | drive->select.all, 184 tf_outb((tf->device & HIHI) | drive->select,
186 io_ports->device_addr); 185 io_ports->device_addr);
187} 186}
188EXPORT_SYMBOL_GPL(ide_tf_load); 187EXPORT_SYMBOL_GPL(ide_tf_load);
@@ -400,97 +399,14 @@ const struct ide_tp_ops default_tp_ops = {
400 .output_data = ide_output_data, 399 .output_data = ide_output_data,
401}; 400};
402 401
403void ide_fix_driveid (struct hd_driveid *id) 402void ide_fix_driveid(u16 *id)
404{ 403{
405#ifndef __LITTLE_ENDIAN 404#ifndef __LITTLE_ENDIAN
406# ifdef __BIG_ENDIAN 405# ifdef __BIG_ENDIAN
407 int i; 406 int i;
408 u16 *stringcast; 407
409 408 for (i = 0; i < 256; i++)
410 id->config = __le16_to_cpu(id->config); 409 id[i] = __le16_to_cpu(id[i]);
411 id->cyls = __le16_to_cpu(id->cyls);
412 id->reserved2 = __le16_to_cpu(id->reserved2);
413 id->heads = __le16_to_cpu(id->heads);
414 id->track_bytes = __le16_to_cpu(id->track_bytes);
415 id->sector_bytes = __le16_to_cpu(id->sector_bytes);
416 id->sectors = __le16_to_cpu(id->sectors);
417 id->vendor0 = __le16_to_cpu(id->vendor0);
418 id->vendor1 = __le16_to_cpu(id->vendor1);
419 id->vendor2 = __le16_to_cpu(id->vendor2);
420 stringcast = (u16 *)&id->serial_no[0];
421 for (i = 0; i < (20/2); i++)
422 stringcast[i] = __le16_to_cpu(stringcast[i]);
423 id->buf_type = __le16_to_cpu(id->buf_type);
424 id->buf_size = __le16_to_cpu(id->buf_size);
425 id->ecc_bytes = __le16_to_cpu(id->ecc_bytes);
426 stringcast = (u16 *)&id->fw_rev[0];
427 for (i = 0; i < (8/2); i++)
428 stringcast[i] = __le16_to_cpu(stringcast[i]);
429 stringcast = (u16 *)&id->model[0];
430 for (i = 0; i < (40/2); i++)
431 stringcast[i] = __le16_to_cpu(stringcast[i]);
432 id->dword_io = __le16_to_cpu(id->dword_io);
433 id->reserved50 = __le16_to_cpu(id->reserved50);
434 id->field_valid = __le16_to_cpu(id->field_valid);
435 id->cur_cyls = __le16_to_cpu(id->cur_cyls);
436 id->cur_heads = __le16_to_cpu(id->cur_heads);
437 id->cur_sectors = __le16_to_cpu(id->cur_sectors);
438 id->cur_capacity0 = __le16_to_cpu(id->cur_capacity0);
439 id->cur_capacity1 = __le16_to_cpu(id->cur_capacity1);
440 id->lba_capacity = __le32_to_cpu(id->lba_capacity);
441 id->dma_1word = __le16_to_cpu(id->dma_1word);
442 id->dma_mword = __le16_to_cpu(id->dma_mword);
443 id->eide_pio_modes = __le16_to_cpu(id->eide_pio_modes);
444 id->eide_dma_min = __le16_to_cpu(id->eide_dma_min);
445 id->eide_dma_time = __le16_to_cpu(id->eide_dma_time);
446 id->eide_pio = __le16_to_cpu(id->eide_pio);
447 id->eide_pio_iordy = __le16_to_cpu(id->eide_pio_iordy);
448 for (i = 0; i < 2; ++i)
449 id->words69_70[i] = __le16_to_cpu(id->words69_70[i]);
450 for (i = 0; i < 4; ++i)
451 id->words71_74[i] = __le16_to_cpu(id->words71_74[i]);
452 id->queue_depth = __le16_to_cpu(id->queue_depth);
453 for (i = 0; i < 4; ++i)
454 id->words76_79[i] = __le16_to_cpu(id->words76_79[i]);
455 id->major_rev_num = __le16_to_cpu(id->major_rev_num);
456 id->minor_rev_num = __le16_to_cpu(id->minor_rev_num);
457 id->command_set_1 = __le16_to_cpu(id->command_set_1);
458 id->command_set_2 = __le16_to_cpu(id->command_set_2);
459 id->cfsse = __le16_to_cpu(id->cfsse);
460 id->cfs_enable_1 = __le16_to_cpu(id->cfs_enable_1);
461 id->cfs_enable_2 = __le16_to_cpu(id->cfs_enable_2);
462 id->csf_default = __le16_to_cpu(id->csf_default);
463 id->dma_ultra = __le16_to_cpu(id->dma_ultra);
464 id->trseuc = __le16_to_cpu(id->trseuc);
465 id->trsEuc = __le16_to_cpu(id->trsEuc);
466 id->CurAPMvalues = __le16_to_cpu(id->CurAPMvalues);
467 id->mprc = __le16_to_cpu(id->mprc);
468 id->hw_config = __le16_to_cpu(id->hw_config);
469 id->acoustic = __le16_to_cpu(id->acoustic);
470 id->msrqs = __le16_to_cpu(id->msrqs);
471 id->sxfert = __le16_to_cpu(id->sxfert);
472 id->sal = __le16_to_cpu(id->sal);
473 id->spg = __le32_to_cpu(id->spg);
474 id->lba_capacity_2 = __le64_to_cpu(id->lba_capacity_2);
475 for (i = 0; i < 22; i++)
476 id->words104_125[i] = __le16_to_cpu(id->words104_125[i]);
477 id->last_lun = __le16_to_cpu(id->last_lun);
478 id->word127 = __le16_to_cpu(id->word127);
479 id->dlf = __le16_to_cpu(id->dlf);
480 id->csfo = __le16_to_cpu(id->csfo);
481 for (i = 0; i < 26; i++)
482 id->words130_155[i] = __le16_to_cpu(id->words130_155[i]);
483 id->word156 = __le16_to_cpu(id->word156);
484 for (i = 0; i < 3; i++)
485 id->words157_159[i] = __le16_to_cpu(id->words157_159[i]);
486 id->cfa_power = __le16_to_cpu(id->cfa_power);
487 for (i = 0; i < 15; i++)
488 id->words161_175[i] = __le16_to_cpu(id->words161_175[i]);
489 for (i = 0; i < 30; i++)
490 id->words176_205[i] = __le16_to_cpu(id->words176_205[i]);
491 for (i = 0; i < 49; i++)
492 id->words206_254[i] = __le16_to_cpu(id->words206_254[i]);
493 id->integrity_word = __le16_to_cpu(id->integrity_word);
494# else 410# else
495# error "Please fix <asm/byteorder.h>" 411# error "Please fix <asm/byteorder.h>"
496# endif 412# endif
@@ -501,19 +417,21 @@ void ide_fix_driveid (struct hd_driveid *id)
501 * ide_fixstring() cleans up and (optionally) byte-swaps a text string, 417 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
502 * removing leading/trailing blanks and compressing internal blanks. 418 * removing leading/trailing blanks and compressing internal blanks.
503 * It is primarily used to tidy up the model name/number fields as 419 * It is primarily used to tidy up the model name/number fields as
504 * returned by the WIN_[P]IDENTIFY commands. 420 * returned by the ATA_CMD_ID_ATA[PI] commands.
505 */ 421 */
506 422
507void ide_fixstring (u8 *s, const int bytecount, const int byteswap) 423void ide_fixstring (u8 *s, const int bytecount, const int byteswap)
508{ 424{
509 u8 *p = s, *end = &s[bytecount & ~1]; /* bytecount must be even */ 425 u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
510 426
511 if (byteswap) { 427 if (byteswap) {
512 /* convert from big-endian to host byte order */ 428 /* convert from big-endian to host byte order */
513 for (p = end ; p != s;) 429 for (p = s ; p != end ; p += 2)
514 be16_to_cpus((u16 *)(p -= 2)); 430 be16_to_cpus((u16 *) p);
515 } 431 }
432
516 /* strip leading blanks */ 433 /* strip leading blanks */
434 p = s;
517 while (s != end && *s == ' ') 435 while (s != end && *s == ' ')
518 ++s; 436 ++s;
519 /* compress internal blanks and strip trailing blanks */ 437 /* compress internal blanks and strip trailing blanks */
@@ -556,7 +474,7 @@ int drive_is_ready (ide_drive_t *drive)
556 /* Note: this may clear a pending IRQ!! */ 474 /* Note: this may clear a pending IRQ!! */
557 stat = hwif->tp_ops->read_status(hwif); 475 stat = hwif->tp_ops->read_status(hwif);
558 476
559 if (stat & BUSY_STAT) 477 if (stat & ATA_BUSY)
560 /* drive busy: definitely not interrupting */ 478 /* drive busy: definitely not interrupting */
561 return 0; 479 return 0;
562 480
@@ -588,10 +506,10 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti
588 udelay(1); /* spec allows drive 400ns to assert "BUSY" */ 506 udelay(1); /* spec allows drive 400ns to assert "BUSY" */
589 stat = tp_ops->read_status(hwif); 507 stat = tp_ops->read_status(hwif);
590 508
591 if (stat & BUSY_STAT) { 509 if (stat & ATA_BUSY) {
592 local_irq_set(flags); 510 local_irq_set(flags);
593 timeout += jiffies; 511 timeout += jiffies;
594 while ((stat = tp_ops->read_status(hwif)) & BUSY_STAT) { 512 while ((stat = tp_ops->read_status(hwif)) & ATA_BUSY) {
595 if (time_after(jiffies, timeout)) { 513 if (time_after(jiffies, timeout)) {
596 /* 514 /*
597 * One last read after the timeout in case 515 * One last read after the timeout in case
@@ -599,7 +517,7 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti
599 * progress during the timeout.. 517 * progress during the timeout..
600 */ 518 */
601 stat = tp_ops->read_status(hwif); 519 stat = tp_ops->read_status(hwif);
602 if (!(stat & BUSY_STAT)) 520 if ((stat & ATA_BUSY) == 0)
603 break; 521 break;
604 522
605 local_irq_restore(flags); 523 local_irq_restore(flags);
@@ -660,18 +578,18 @@ EXPORT_SYMBOL(ide_wait_stat);
660/** 578/**
661 * ide_in_drive_list - look for drive in black/white list 579 * ide_in_drive_list - look for drive in black/white list
662 * @id: drive identifier 580 * @id: drive identifier
663 * @drive_table: list to inspect 581 * @table: list to inspect
664 * 582 *
665 * Look for a drive in the blacklist and the whitelist tables 583 * Look for a drive in the blacklist and the whitelist tables
666 * Returns 1 if the drive is found in the table. 584 * Returns 1 if the drive is found in the table.
667 */ 585 */
668 586
669int ide_in_drive_list(struct hd_driveid *id, const struct drive_list_entry *drive_table) 587int ide_in_drive_list(u16 *id, const struct drive_list_entry *table)
670{ 588{
671 for ( ; drive_table->id_model; drive_table++) 589 for ( ; table->id_model; table++)
672 if ((!strcmp(drive_table->id_model, id->model)) && 590 if ((!strcmp(table->id_model, (char *)&id[ATA_ID_PROD])) &&
673 (!drive_table->id_firmware || 591 (!table->id_firmware ||
674 strstr(id->fw_rev, drive_table->id_firmware))) 592 strstr((char *)&id[ATA_ID_FW_REV], table->id_firmware)))
675 return 1; 593 return 1;
676 return 0; 594 return 0;
677} 595}
@@ -702,7 +620,7 @@ static const struct drive_list_entry ivb_list[] = {
702u8 eighty_ninty_three (ide_drive_t *drive) 620u8 eighty_ninty_three (ide_drive_t *drive)
703{ 621{
704 ide_hwif_t *hwif = drive->hwif; 622 ide_hwif_t *hwif = drive->hwif;
705 struct hd_driveid *id = drive->id; 623 u16 *id = drive->id;
706 int ivb = ide_in_drive_list(id, ivb_list); 624 int ivb = ide_in_drive_list(id, ivb_list);
707 625
708 if (hwif->cbl == ATA_CBL_PATA40_SHORT) 626 if (hwif->cbl == ATA_CBL_PATA40_SHORT)
@@ -712,7 +630,7 @@ u8 eighty_ninty_three (ide_drive_t *drive)
712 printk(KERN_DEBUG "%s: skipping word 93 validity check\n", 630 printk(KERN_DEBUG "%s: skipping word 93 validity check\n",
713 drive->name); 631 drive->name);
714 632
715 if (ide_dev_is_sata(id) && !ivb) 633 if (ata_id_is_sata(id) && !ivb)
716 return 1; 634 return 1;
717 635
718 if (hwif->cbl != ATA_CBL_PATA80 && !ivb) 636 if (hwif->cbl != ATA_CBL_PATA80 && !ivb)
@@ -724,11 +642,12 @@ u8 eighty_ninty_three (ide_drive_t *drive)
724 * - force bit13 (80c cable present) check also for !ivb devices 642 * - force bit13 (80c cable present) check also for !ivb devices
725 * (unless the slave device is pre-ATA3) 643 * (unless the slave device is pre-ATA3)
726 */ 644 */
727 if ((id->hw_config & 0x4000) || (ivb && (id->hw_config & 0x2000))) 645 if ((id[ATA_ID_HW_CONFIG] & 0x4000) ||
646 (ivb && (id[ATA_ID_HW_CONFIG] & 0x2000)))
728 return 1; 647 return 1;
729 648
730no_80w: 649no_80w:
731 if (drive->udma33_warned == 1) 650 if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
732 return 0; 651 return 0;
733 652
734 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, " 653 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
@@ -736,7 +655,7 @@ no_80w:
736 drive->name, 655 drive->name,
737 hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host"); 656 hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host");
738 657
739 drive->udma33_warned = 1; 658 drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED;
740 659
741 return 0; 660 return 0;
742} 661}
@@ -745,8 +664,8 @@ int ide_driveid_update(ide_drive_t *drive)
745{ 664{
746 ide_hwif_t *hwif = drive->hwif; 665 ide_hwif_t *hwif = drive->hwif;
747 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 666 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
748 struct hd_driveid *id; 667 u16 *id;
749 unsigned long timeout, flags; 668 unsigned long flags;
750 u8 stat; 669 u8 stat;
751 670
752 /* 671 /*
@@ -757,29 +676,24 @@ int ide_driveid_update(ide_drive_t *drive)
757 SELECT_MASK(drive, 1); 676 SELECT_MASK(drive, 1);
758 tp_ops->set_irq(hwif, 0); 677 tp_ops->set_irq(hwif, 0);
759 msleep(50); 678 msleep(50);
760 tp_ops->exec_command(hwif, WIN_IDENTIFY); 679 tp_ops->exec_command(hwif, ATA_CMD_ID_ATA);
761 timeout = jiffies + WAIT_WORSTCASE;
762 do {
763 if (time_after(jiffies, timeout)) {
764 SELECT_MASK(drive, 0);
765 return 0; /* drive timed-out */
766 }
767 680
768 msleep(50); /* give drive a breather */ 681 if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 1)) {
769 stat = tp_ops->read_altstatus(hwif); 682 SELECT_MASK(drive, 0);
770 } while (stat & BUSY_STAT); 683 return 0;
684 }
771 685
772 msleep(50); /* wait for IRQ and DRQ_STAT */ 686 msleep(50); /* wait for IRQ and ATA_DRQ */
773 stat = tp_ops->read_status(hwif); 687 stat = tp_ops->read_status(hwif);
774 688
775 if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) { 689 if (!OK_STAT(stat, ATA_DRQ, BAD_R_STAT)) {
776 SELECT_MASK(drive, 0); 690 SELECT_MASK(drive, 0);
777 printk("%s: CHECK for good STATUS\n", drive->name); 691 printk("%s: CHECK for good STATUS\n", drive->name);
778 return 0; 692 return 0;
779 } 693 }
780 local_irq_save(flags); 694 local_irq_save(flags);
781 SELECT_MASK(drive, 0); 695 SELECT_MASK(drive, 0);
782 id = kmalloc(SECTOR_WORDS*4, GFP_ATOMIC); 696 id = kmalloc(SECTOR_SIZE, GFP_ATOMIC);
783 if (!id) { 697 if (!id) {
784 local_irq_restore(flags); 698 local_irq_restore(flags);
785 return 0; 699 return 0;
@@ -789,16 +703,16 @@ int ide_driveid_update(ide_drive_t *drive)
789 local_irq_enable(); 703 local_irq_enable();
790 local_irq_restore(flags); 704 local_irq_restore(flags);
791 ide_fix_driveid(id); 705 ide_fix_driveid(id);
792 if (id) { 706
793 drive->id->dma_ultra = id->dma_ultra; 707 drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES];
794 drive->id->dma_mword = id->dma_mword; 708 drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES];
795 drive->id->dma_1word = id->dma_1word; 709 drive->id[ATA_ID_SWDMA_MODES] = id[ATA_ID_SWDMA_MODES];
796 /* anything more ? */ 710 /* anything more ? */
797 kfree(id); 711
798 712 kfree(id);
799 if (drive->using_dma && ide_id_dma_bug(drive)) 713
800 ide_dma_off(drive); 714 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
801 } 715 ide_dma_off(drive);
802 716
803 return 1; 717 return 1;
804} 718}
@@ -807,6 +721,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
807{ 721{
808 ide_hwif_t *hwif = drive->hwif; 722 ide_hwif_t *hwif = drive->hwif;
809 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 723 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
724 u16 *id = drive->id, i;
810 int error = 0; 725 int error = 0;
811 u8 stat; 726 u8 stat;
812 ide_task_t task; 727 ide_task_t task;
@@ -817,7 +732,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
817#endif 732#endif
818 733
819 /* Skip setting PIO flow-control modes on pre-EIDE drives */ 734 /* Skip setting PIO flow-control modes on pre-EIDE drives */
820 if ((speed & 0xf8) == XFER_PIO_0 && !(drive->id->capability & 0x08)) 735 if ((speed & 0xf8) == XFER_PIO_0 && ata_id_has_iordy(drive->id) == 0)
821 goto skip; 736 goto skip;
822 737
823 /* 738 /*
@@ -840,7 +755,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
840 755
841 udelay(1); 756 udelay(1);
842 SELECT_DRIVE(drive); 757 SELECT_DRIVE(drive);
843 SELECT_MASK(drive, 0); 758 SELECT_MASK(drive, 1);
844 udelay(1); 759 udelay(1);
845 tp_ops->set_irq(hwif, 0); 760 tp_ops->set_irq(hwif, 0);
846 761
@@ -851,13 +766,13 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
851 766
852 tp_ops->tf_load(drive, &task); 767 tp_ops->tf_load(drive, &task);
853 768
854 tp_ops->exec_command(hwif, WIN_SETFEATURES); 769 tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES);
855 770
856 if (drive->quirk_list == 2) 771 if (drive->quirk_list == 2)
857 tp_ops->set_irq(hwif, 1); 772 tp_ops->set_irq(hwif, 1);
858 773
859 error = __ide_wait_stat(drive, drive->ready_stat, 774 error = __ide_wait_stat(drive, drive->ready_stat,
860 BUSY_STAT|DRQ_STAT|ERR_STAT, 775 ATA_BUSY | ATA_DRQ | ATA_ERR,
861 WAIT_CMD, &stat); 776 WAIT_CMD, &stat);
862 777
863 SELECT_MASK(drive, 0); 778 SELECT_MASK(drive, 0);
@@ -869,35 +784,29 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
869 return error; 784 return error;
870 } 785 }
871 786
872 drive->id->dma_ultra &= ~0xFF00; 787 id[ATA_ID_UDMA_MODES] &= ~0xFF00;
873 drive->id->dma_mword &= ~0x0F00; 788 id[ATA_ID_MWDMA_MODES] &= ~0x0F00;
874 drive->id->dma_1word &= ~0x0F00; 789 id[ATA_ID_SWDMA_MODES] &= ~0x0F00;
875 790
876 skip: 791 skip:
877#ifdef CONFIG_BLK_DEV_IDEDMA 792#ifdef CONFIG_BLK_DEV_IDEDMA
878 if (speed >= XFER_SW_DMA_0 && drive->using_dma) 793 if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA))
879 hwif->dma_ops->dma_host_set(drive, 1); 794 hwif->dma_ops->dma_host_set(drive, 1);
880 else if (hwif->dma_ops) /* check if host supports DMA */ 795 else if (hwif->dma_ops) /* check if host supports DMA */
881 ide_dma_off_quietly(drive); 796 ide_dma_off_quietly(drive);
882#endif 797#endif
883 798
884 switch(speed) { 799 if (speed >= XFER_UDMA_0) {
885 case XFER_UDMA_7: drive->id->dma_ultra |= 0x8080; break; 800 i = 1 << (speed - XFER_UDMA_0);
886 case XFER_UDMA_6: drive->id->dma_ultra |= 0x4040; break; 801 id[ATA_ID_UDMA_MODES] |= (i << 8 | i);
887 case XFER_UDMA_5: drive->id->dma_ultra |= 0x2020; break; 802 } else if (speed >= XFER_MW_DMA_0) {
888 case XFER_UDMA_4: drive->id->dma_ultra |= 0x1010; break; 803 i = 1 << (speed - XFER_MW_DMA_0);
889 case XFER_UDMA_3: drive->id->dma_ultra |= 0x0808; break; 804 id[ATA_ID_MWDMA_MODES] |= (i << 8 | i);
890 case XFER_UDMA_2: drive->id->dma_ultra |= 0x0404; break; 805 } else if (speed >= XFER_SW_DMA_0) {
891 case XFER_UDMA_1: drive->id->dma_ultra |= 0x0202; break; 806 i = 1 << (speed - XFER_SW_DMA_0);
892 case XFER_UDMA_0: drive->id->dma_ultra |= 0x0101; break; 807 id[ATA_ID_SWDMA_MODES] |= (i << 8 | i);
893 case XFER_MW_DMA_2: drive->id->dma_mword |= 0x0404; break;
894 case XFER_MW_DMA_1: drive->id->dma_mword |= 0x0202; break;
895 case XFER_MW_DMA_0: drive->id->dma_mword |= 0x0101; break;
896 case XFER_SW_DMA_2: drive->id->dma_1word |= 0x0404; break;
897 case XFER_SW_DMA_1: drive->id->dma_1word |= 0x0202; break;
898 case XFER_SW_DMA_0: drive->id->dma_1word |= 0x0101; break;
899 default: break;
900 } 808 }
809
901 if (!drive->init_speed) 810 if (!drive->init_speed)
902 drive->init_speed = speed; 811 drive->init_speed = speed;
903 drive->current_speed = speed; 812 drive->current_speed = speed;
@@ -977,7 +886,7 @@ void ide_execute_pkt_cmd(ide_drive_t *drive)
977 unsigned long flags; 886 unsigned long flags;
978 887
979 spin_lock_irqsave(&ide_lock, flags); 888 spin_lock_irqsave(&ide_lock, flags);
980 hwif->tp_ops->exec_command(hwif, WIN_PACKETCMD); 889 hwif->tp_ops->exec_command(hwif, ATA_CMD_PACKET);
981 ndelay(400); 890 ndelay(400);
982 spin_unlock_irqrestore(&ide_lock, flags); 891 spin_unlock_irqrestore(&ide_lock, flags);
983} 892}
@@ -1010,7 +919,7 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
1010 udelay (10); 919 udelay (10);
1011 stat = hwif->tp_ops->read_status(hwif); 920 stat = hwif->tp_ops->read_status(hwif);
1012 921
1013 if (OK_STAT(stat, 0, BUSY_STAT)) 922 if (OK_STAT(stat, 0, ATA_BUSY))
1014 printk("%s: ATAPI reset complete\n", drive->name); 923 printk("%s: ATAPI reset complete\n", drive->name);
1015 else { 924 else {
1016 if (time_before(jiffies, hwgroup->poll_timeout)) { 925 if (time_before(jiffies, hwgroup->poll_timeout)) {
@@ -1031,6 +940,25 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
1031 return ide_stopped; 940 return ide_stopped;
1032} 941}
1033 942
943static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
944{
945 static const char *err_master_vals[] =
946 { NULL, "passed", "formatter device error",
947 "sector buffer error", "ECC circuitry error",
948 "controlling MPU error" };
949
950 u8 err_master = err & 0x7f;
951
952 printk(KERN_ERR "%s: reset: master: ", hwif->name);
953 if (err_master && err_master < 6)
954 printk(KERN_CONT "%s", err_master_vals[err_master]);
955 else
956 printk(KERN_CONT "error (0x%02x?)", err);
957 if (err & 0x80)
958 printk(KERN_CONT "; slave: failed");
959 printk(KERN_CONT "\n");
960}
961
1034/* 962/*
1035 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms 963 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
1036 * during an ide reset operation. If the drives have not yet responded, 964 * during an ide reset operation. If the drives have not yet responded,
@@ -1056,7 +984,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
1056 984
1057 tmp = hwif->tp_ops->read_status(hwif); 985 tmp = hwif->tp_ops->read_status(hwif);
1058 986
1059 if (!OK_STAT(tmp, 0, BUSY_STAT)) { 987 if (!OK_STAT(tmp, 0, ATA_BUSY)) {
1060 if (time_before(jiffies, hwgroup->poll_timeout)) { 988 if (time_before(jiffies, hwgroup->poll_timeout)) {
1061 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 989 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
1062 /* continue polling */ 990 /* continue polling */
@@ -1066,31 +994,14 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
1066 drive->failures++; 994 drive->failures++;
1067 err = -EIO; 995 err = -EIO;
1068 } else { 996 } else {
1069 printk("%s: reset: ", hwif->name);
1070 tmp = ide_read_error(drive); 997 tmp = ide_read_error(drive);
1071 998
1072 if (tmp == 1) { 999 if (tmp == 1) {
1073 printk("success\n"); 1000 printk(KERN_INFO "%s: reset: success\n", hwif->name);
1074 drive->failures = 0; 1001 drive->failures = 0;
1075 } else { 1002 } else {
1003 ide_reset_report_error(hwif, tmp);
1076 drive->failures++; 1004 drive->failures++;
1077 printk("master: ");
1078 switch (tmp & 0x7f) {
1079 case 1: printk("passed");
1080 break;
1081 case 2: printk("formatter device error");
1082 break;
1083 case 3: printk("sector buffer error");
1084 break;
1085 case 4: printk("ECC circuitry error");
1086 break;
1087 case 5: printk("controlling MPU error");
1088 break;
1089 default:printk("error (0x%02x?)", tmp);
1090 }
1091 if (tmp & 0x80)
1092 printk("; slave: failed");
1093 printk("\n");
1094 err = -EIO; 1005 err = -EIO;
1095 } 1006 }
1096 } 1007 }
@@ -1102,14 +1013,19 @@ out:
1102 1013
1103static void ide_disk_pre_reset(ide_drive_t *drive) 1014static void ide_disk_pre_reset(ide_drive_t *drive)
1104{ 1015{
1105 int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1; 1016 int legacy = (drive->id[ATA_ID_CFS_ENABLE_2] & 0x0400) ? 0 : 1;
1106 1017
1107 drive->special.all = 0; 1018 drive->special.all = 0;
1108 drive->special.b.set_geometry = legacy; 1019 drive->special.b.set_geometry = legacy;
1109 drive->special.b.recalibrate = legacy; 1020 drive->special.b.recalibrate = legacy;
1021
1110 drive->mult_count = 0; 1022 drive->mult_count = 0;
1111 if (!drive->keep_settings && !drive->using_dma) 1023 drive->dev_flags &= ~IDE_DFLAG_PARKED;
1024
1025 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
1026 (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
1112 drive->mult_req = 0; 1027 drive->mult_req = 0;
1028
1113 if (drive->mult_req != drive->mult_count) 1029 if (drive->mult_req != drive->mult_count)
1114 drive->special.b.set_multmode = 1; 1030 drive->special.b.set_multmode = 1;
1115} 1031}
@@ -1121,18 +1037,18 @@ static void pre_reset(ide_drive_t *drive)
1121 if (drive->media == ide_disk) 1037 if (drive->media == ide_disk)
1122 ide_disk_pre_reset(drive); 1038 ide_disk_pre_reset(drive);
1123 else 1039 else
1124 drive->post_reset = 1; 1040 drive->dev_flags |= IDE_DFLAG_POST_RESET;
1125 1041
1126 if (drive->using_dma) { 1042 if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
1127 if (drive->crc_count) 1043 if (drive->crc_count)
1128 ide_check_dma_crc(drive); 1044 ide_check_dma_crc(drive);
1129 else 1045 else
1130 ide_dma_off(drive); 1046 ide_dma_off(drive);
1131 } 1047 }
1132 1048
1133 if (!drive->keep_settings) { 1049 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
1134 if (!drive->using_dma) { 1050 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
1135 drive->unmask = 0; 1051 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
1136 drive->io_32bit = 0; 1052 drive->io_32bit = 0;
1137 } 1053 }
1138 return; 1054 return;
@@ -1164,12 +1080,13 @@ static void pre_reset(ide_drive_t *drive)
1164static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) 1080static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1165{ 1081{
1166 unsigned int unit; 1082 unsigned int unit;
1167 unsigned long flags; 1083 unsigned long flags, timeout;
1168 ide_hwif_t *hwif; 1084 ide_hwif_t *hwif;
1169 ide_hwgroup_t *hwgroup; 1085 ide_hwgroup_t *hwgroup;
1170 struct ide_io_ports *io_ports; 1086 struct ide_io_ports *io_ports;
1171 const struct ide_tp_ops *tp_ops; 1087 const struct ide_tp_ops *tp_ops;
1172 const struct ide_port_ops *port_ops; 1088 const struct ide_port_ops *port_ops;
1089 DEFINE_WAIT(wait);
1173 1090
1174 spin_lock_irqsave(&ide_lock, flags); 1091 spin_lock_irqsave(&ide_lock, flags);
1175 hwif = HWIF(drive); 1092 hwif = HWIF(drive);
@@ -1187,7 +1104,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1187 pre_reset(drive); 1104 pre_reset(drive);
1188 SELECT_DRIVE(drive); 1105 SELECT_DRIVE(drive);
1189 udelay (20); 1106 udelay (20);
1190 tp_ops->exec_command(hwif, WIN_SRST); 1107 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
1191 ndelay(400); 1108 ndelay(400);
1192 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; 1109 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
1193 hwgroup->polling = 1; 1110 hwgroup->polling = 1;
@@ -1196,6 +1113,31 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1196 return ide_started; 1113 return ide_started;
1197 } 1114 }
1198 1115
1116 /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
1117 do {
1118 unsigned long now;
1119
1120 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
1121 timeout = jiffies;
1122 for (unit = 0; unit < MAX_DRIVES; unit++) {
1123 ide_drive_t *tdrive = &hwif->drives[unit];
1124
1125 if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
1126 tdrive->dev_flags & IDE_DFLAG_PARKED &&
1127 time_after(tdrive->sleep, timeout))
1128 timeout = tdrive->sleep;
1129 }
1130
1131 now = jiffies;
1132 if (time_before_eq(timeout, now))
1133 break;
1134
1135 spin_unlock_irqrestore(&ide_lock, flags);
1136 timeout = schedule_timeout_uninterruptible(timeout - now);
1137 spin_lock_irqsave(&ide_lock, flags);
1138 } while (timeout);
1139 finish_wait(&ide_park_wq, &wait);
1140
1199 /* 1141 /*
1200 * First, reset any device state data we were maintaining 1142 * First, reset any device state data we were maintaining
1201 * for any of the drives on this interface. 1143 * for any of the drives on this interface.
@@ -1270,7 +1212,7 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
1270 */ 1212 */
1271 mdelay(1); 1213 mdelay(1);
1272 stat = hwif->tp_ops->read_status(hwif); 1214 stat = hwif->tp_ops->read_status(hwif);
1273 if ((stat & BUSY_STAT) == 0) 1215 if ((stat & ATA_BUSY) == 0)
1274 return 0; 1216 return 0;
1275 /* 1217 /*
1276 * Assume a value of 0xff means nothing is connected to 1218 * Assume a value of 0xff means nothing is connected to
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 97fefabea8b8..9fc4cfb2a272 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -2,7 +2,6 @@
2#include <linux/string.h> 2#include <linux/string.h>
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/interrupt.h> 4#include <linux/interrupt.h>
5#include <linux/hdreg.h>
6#include <linux/ide.h> 5#include <linux/ide.h>
7#include <linux/bitops.h> 6#include <linux/bitops.h>
8 7
@@ -90,29 +89,31 @@ static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
90 89
91u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode) 90u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
92{ 91{
93 int pio_mode; 92 u16 *id = drive->id;
94 struct hd_driveid* id = drive->id; 93 int pio_mode = -1, overridden = 0;
95 int overridden = 0;
96 94
97 if (mode_wanted != 255) 95 if (mode_wanted != 255)
98 return min_t(u8, mode_wanted, max_mode); 96 return min_t(u8, mode_wanted, max_mode);
99 97
100 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0 && 98 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0)
101 (pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { 99 pio_mode = ide_scan_pio_blacklist((char *)&id[ATA_ID_PROD]);
100
101 if (pio_mode != -1) {
102 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name); 102 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
103 } else { 103 } else {
104 pio_mode = id->tPIO; 104 pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8;
105 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */ 105 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
106 pio_mode = 2; 106 pio_mode = 2;
107 overridden = 1; 107 overridden = 1;
108 } 108 }
109 if (id->field_valid & 2) { /* drive implements ATA2? */ 109
110 if (id->capability & 8) { /* IORDY supported? */ 110 if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */
111 if (id->eide_pio_modes & 7) { 111 if (ata_id_has_iordy(id)) {
112 if (id[ATA_ID_PIO_MODES] & 7) {
112 overridden = 0; 113 overridden = 0;
113 if (id->eide_pio_modes & 4) 114 if (id[ATA_ID_PIO_MODES] & 4)
114 pio_mode = 5; 115 pio_mode = 5;
115 else if (id->eide_pio_modes & 2) 116 else if (id[ATA_ID_PIO_MODES] & 2)
116 pio_mode = 4; 117 pio_mode = 4;
117 else 118 else
118 pio_mode = 3; 119 pio_mode = 3;
@@ -316,7 +317,7 @@ static void ide_dump_sector(ide_drive_t *drive)
316{ 317{
317 ide_task_t task; 318 ide_task_t task;
318 struct ide_taskfile *tf = &task.tf; 319 struct ide_taskfile *tf = &task.tf;
319 int lba48 = (drive->addressing == 1) ? 1 : 0; 320 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
320 321
321 memset(&task, 0, sizeof(task)); 322 memset(&task, 0, sizeof(task));
322 if (lba48) 323 if (lba48)
@@ -338,16 +339,16 @@ static void ide_dump_sector(ide_drive_t *drive)
338static void ide_dump_ata_error(ide_drive_t *drive, u8 err) 339static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
339{ 340{
340 printk("{ "); 341 printk("{ ");
341 if (err & ABRT_ERR) printk("DriveStatusError "); 342 if (err & ATA_ABORTED) printk("DriveStatusError ");
342 if (err & ICRC_ERR) 343 if (err & ATA_ICRC)
343 printk((err & ABRT_ERR) ? "BadCRC " : "BadSector "); 344 printk((err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
344 if (err & ECC_ERR) printk("UncorrectableError "); 345 if (err & ATA_UNC) printk("UncorrectableError ");
345 if (err & ID_ERR) printk("SectorIdNotFound "); 346 if (err & ATA_IDNF) printk("SectorIdNotFound ");
346 if (err & TRK0_ERR) printk("TrackZeroNotFound "); 347 if (err & ATA_TRK0NF) printk("TrackZeroNotFound ");
347 if (err & MARK_ERR) printk("AddrMarkNotFound "); 348 if (err & ATA_AMNF) printk("AddrMarkNotFound ");
348 printk("}"); 349 printk("}");
349 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || 350 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
350 (err & (ECC_ERR|ID_ERR|MARK_ERR))) { 351 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
351 ide_dump_sector(drive); 352 ide_dump_sector(drive);
352 if (HWGROUP(drive) && HWGROUP(drive)->rq) 353 if (HWGROUP(drive) && HWGROUP(drive)->rq)
353 printk(", sector=%llu", 354 printk(", sector=%llu",
@@ -359,12 +360,12 @@ static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
359static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) 360static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
360{ 361{
361 printk("{ "); 362 printk("{ ");
362 if (err & ILI_ERR) printk("IllegalLengthIndication "); 363 if (err & ATAPI_ILI) printk("IllegalLengthIndication ");
363 if (err & EOM_ERR) printk("EndOfMedia "); 364 if (err & ATAPI_EOM) printk("EndOfMedia ");
364 if (err & ABRT_ERR) printk("AbortedCommand "); 365 if (err & ATA_ABORTED) printk("AbortedCommand ");
365 if (err & MCR_ERR) printk("MediaChangeRequested "); 366 if (err & ATA_MCR) printk("MediaChangeRequested ");
366 if (err & LFS_ERR) printk("LastFailedSense=0x%02x ", 367 if (err & ATAPI_LFS) printk("LastFailedSense=0x%02x ",
367 (err & LFS_ERR) >> 4); 368 (err & ATAPI_LFS) >> 4);
368 printk("}\n"); 369 printk("}\n");
369} 370}
370 371
@@ -386,19 +387,19 @@ u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
386 387
387 local_irq_save(flags); 388 local_irq_save(flags);
388 printk("%s: %s: status=0x%02x { ", drive->name, msg, stat); 389 printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
389 if (stat & BUSY_STAT) 390 if (stat & ATA_BUSY)
390 printk("Busy "); 391 printk("Busy ");
391 else { 392 else {
392 if (stat & READY_STAT) printk("DriveReady "); 393 if (stat & ATA_DRDY) printk("DriveReady ");
393 if (stat & WRERR_STAT) printk("DeviceFault "); 394 if (stat & ATA_DF) printk("DeviceFault ");
394 if (stat & SEEK_STAT) printk("SeekComplete "); 395 if (stat & ATA_DSC) printk("SeekComplete ");
395 if (stat & DRQ_STAT) printk("DataRequest "); 396 if (stat & ATA_DRQ) printk("DataRequest ");
396 if (stat & ECC_STAT) printk("CorrectedError "); 397 if (stat & ATA_CORR) printk("CorrectedError ");
397 if (stat & INDEX_STAT) printk("Index "); 398 if (stat & ATA_IDX) printk("Index ");
398 if (stat & ERR_STAT) printk("Error "); 399 if (stat & ATA_ERR) printk("Error ");
399 } 400 }
400 printk("}\n"); 401 printk("}\n");
401 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) { 402 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
402 err = ide_read_error(drive); 403 err = ide_read_error(drive);
403 printk("%s: %s: error=0x%02x ", drive->name, msg, err); 404 printk("%s: %s: error=0x%02x ", drive->name, msg, err);
404 if (drive->media == ide_disk) 405 if (drive->media == ide_disk)
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
new file mode 100644
index 000000000000..03b00e57e93f
--- /dev/null
+++ b/drivers/ide/ide-park.c
@@ -0,0 +1,121 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/jiffies.h>
4#include <linux/blkdev.h>
5
6DECLARE_WAIT_QUEUE_HEAD(ide_park_wq);
7
8static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
9{
10 struct request_queue *q = drive->queue;
11 struct request *rq;
12 int rc;
13
14 timeout += jiffies;
15 spin_lock_irq(&ide_lock);
16 if (drive->dev_flags & IDE_DFLAG_PARKED) {
17 ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
18 int reset_timer;
19
20 reset_timer = time_before(timeout, drive->sleep);
21 drive->sleep = timeout;
22 wake_up_all(&ide_park_wq);
23 if (reset_timer && hwgroup->sleeping &&
24 del_timer(&hwgroup->timer)) {
25 hwgroup->sleeping = 0;
26 hwgroup->busy = 0;
27 blk_start_queueing(q);
28 }
29 spin_unlock_irq(&ide_lock);
30 return;
31 }
32 spin_unlock_irq(&ide_lock);
33
34 rq = blk_get_request(q, READ, __GFP_WAIT);
35 rq->cmd[0] = REQ_PARK_HEADS;
36 rq->cmd_len = 1;
37 rq->cmd_type = REQ_TYPE_SPECIAL;
38 rq->special = &timeout;
39 rc = blk_execute_rq(q, NULL, rq, 1);
40 blk_put_request(rq);
41 if (rc)
42 goto out;
43
44 /*
45 * Make sure that *some* command is sent to the drive after the
46 * timeout has expired, so power management will be reenabled.
47 */
48 rq = blk_get_request(q, READ, GFP_NOWAIT);
49 if (unlikely(!rq))
50 goto out;
51
52 rq->cmd[0] = REQ_UNPARK_HEADS;
53 rq->cmd_len = 1;
54 rq->cmd_type = REQ_TYPE_SPECIAL;
55 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
56
57out:
58 return;
59}
60
61ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
62 char *buf)
63{
64 ide_drive_t *drive = to_ide_device(dev);
65 unsigned long now;
66 unsigned int msecs;
67
68 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
69 return -EOPNOTSUPP;
70
71 spin_lock_irq(&ide_lock);
72 now = jiffies;
73 if (drive->dev_flags & IDE_DFLAG_PARKED &&
74 time_after(drive->sleep, now))
75 msecs = jiffies_to_msecs(drive->sleep - now);
76 else
77 msecs = 0;
78 spin_unlock_irq(&ide_lock);
79
80 return snprintf(buf, 20, "%u\n", msecs);
81}
82
83ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
84 const char *buf, size_t len)
85{
86#define MAX_PARK_TIMEOUT 30000
87 ide_drive_t *drive = to_ide_device(dev);
88 long int input;
89 int rc;
90
91 rc = strict_strtol(buf, 10, &input);
92 if (rc || input < -2)
93 return -EINVAL;
94 if (input > MAX_PARK_TIMEOUT) {
95 input = MAX_PARK_TIMEOUT;
96 rc = -EOVERFLOW;
97 }
98
99 mutex_lock(&ide_setting_mtx);
100 if (input >= 0) {
101 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
102 rc = -EOPNOTSUPP;
103 else if (input || drive->dev_flags & IDE_DFLAG_PARKED)
104 issue_park_cmd(drive, msecs_to_jiffies(input));
105 } else {
106 if (drive->media == ide_disk)
107 switch (input) {
108 case -1:
109 drive->dev_flags &= ~IDE_DFLAG_NO_UNLOAD;
110 break;
111 case -2:
112 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
113 break;
114 }
115 else
116 rc = -EOPNOTSUPP;
117 }
118 mutex_unlock(&ide_setting_mtx);
119
120 return rc ? rc : len;
121}
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/ide-pci-generic.c
index b07d4f4273b3..bddae2b329a0 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/ide-pci-generic.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
3 * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com> 3 * Portions (C) Copyright 2002 Red Hat Inc
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the 6 * under the terms of the GNU General Public License as published by the
@@ -22,7 +22,6 @@
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/hdreg.h>
26#include <linux/pci.h> 25#include <linux/pci.h>
27#include <linux/ide.h> 26#include <linux/ide.h>
28#include <linux/init.h> 27#include <linux/init.h>
@@ -167,21 +166,23 @@ static const struct pci_device_id generic_pci_tbl[] = {
167}; 166};
168MODULE_DEVICE_TABLE(pci, generic_pci_tbl); 167MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
169 168
170static struct pci_driver driver = { 169static struct pci_driver generic_pci_driver = {
171 .name = "PCI_IDE", 170 .name = "PCI_IDE",
172 .id_table = generic_pci_tbl, 171 .id_table = generic_pci_tbl,
173 .probe = generic_init_one, 172 .probe = generic_init_one,
174 .remove = ide_pci_remove, 173 .remove = ide_pci_remove,
174 .suspend = ide_pci_suspend,
175 .resume = ide_pci_resume,
175}; 176};
176 177
177static int __init generic_ide_init(void) 178static int __init generic_ide_init(void)
178{ 179{
179 return ide_pci_register_driver(&driver); 180 return ide_pci_register_driver(&generic_pci_driver);
180} 181}
181 182
182static void __exit generic_ide_exit(void) 183static void __exit generic_ide_exit(void)
183{ 184{
184 pci_unregister_driver(&driver); 185 pci_unregister_driver(&generic_pci_driver);
185} 186}
186 187
187module_init(generic_ide_init); 188module_init(generic_ide_init);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index a51a30e9eab3..1649ea54f76c 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -50,59 +50,54 @@
50 50
51static void generic_id(ide_drive_t *drive) 51static void generic_id(ide_drive_t *drive)
52{ 52{
53 drive->id->cyls = drive->cyl; 53 u16 *id = drive->id;
54 drive->id->heads = drive->head; 54
55 drive->id->sectors = drive->sect; 55 id[ATA_ID_CUR_CYLS] = id[ATA_ID_CYLS] = drive->cyl;
56 drive->id->cur_cyls = drive->cyl; 56 id[ATA_ID_CUR_HEADS] = id[ATA_ID_HEADS] = drive->head;
57 drive->id->cur_heads = drive->head; 57 id[ATA_ID_CUR_SECTORS] = id[ATA_ID_SECTORS] = drive->sect;
58 drive->id->cur_sectors = drive->sect;
59} 58}
60 59
61static void ide_disk_init_chs(ide_drive_t *drive) 60static void ide_disk_init_chs(ide_drive_t *drive)
62{ 61{
63 struct hd_driveid *id = drive->id; 62 u16 *id = drive->id;
64 63
65 /* Extract geometry if we did not already have one for the drive */ 64 /* Extract geometry if we did not already have one for the drive */
66 if (!drive->cyl || !drive->head || !drive->sect) { 65 if (!drive->cyl || !drive->head || !drive->sect) {
67 drive->cyl = drive->bios_cyl = id->cyls; 66 drive->cyl = drive->bios_cyl = id[ATA_ID_CYLS];
68 drive->head = drive->bios_head = id->heads; 67 drive->head = drive->bios_head = id[ATA_ID_HEADS];
69 drive->sect = drive->bios_sect = id->sectors; 68 drive->sect = drive->bios_sect = id[ATA_ID_SECTORS];
70 } 69 }
71 70
72 /* Handle logical geometry translation by the drive */ 71 /* Handle logical geometry translation by the drive */
73 if ((id->field_valid & 1) && id->cur_cyls && 72 if (ata_id_current_chs_valid(id)) {
74 id->cur_heads && (id->cur_heads <= 16) && id->cur_sectors) { 73 drive->cyl = id[ATA_ID_CUR_CYLS];
75 drive->cyl = id->cur_cyls; 74 drive->head = id[ATA_ID_CUR_HEADS];
76 drive->head = id->cur_heads; 75 drive->sect = id[ATA_ID_CUR_SECTORS];
77 drive->sect = id->cur_sectors;
78 } 76 }
79 77
80 /* Use physical geometry if what we have still makes no sense */ 78 /* Use physical geometry if what we have still makes no sense */
81 if (drive->head > 16 && id->heads && id->heads <= 16) { 79 if (drive->head > 16 && id[ATA_ID_HEADS] && id[ATA_ID_HEADS] <= 16) {
82 drive->cyl = id->cyls; 80 drive->cyl = id[ATA_ID_CYLS];
83 drive->head = id->heads; 81 drive->head = id[ATA_ID_HEADS];
84 drive->sect = id->sectors; 82 drive->sect = id[ATA_ID_SECTORS];
85 } 83 }
86} 84}
87 85
88static void ide_disk_init_mult_count(ide_drive_t *drive) 86static void ide_disk_init_mult_count(ide_drive_t *drive)
89{ 87{
90 struct hd_driveid *id = drive->id; 88 u16 *id = drive->id;
91 89 u8 max_multsect = id[ATA_ID_MAX_MULTSECT] & 0xff;
92 drive->mult_count = 0; 90
93 if (id->max_multsect) { 91 if (max_multsect) {
94#ifdef CONFIG_IDEDISK_MULTI_MODE 92 if ((max_multsect / 2) > 1)
95 id->multsect = ((id->max_multsect/2) > 1) ? id->max_multsect : 0; 93 id[ATA_ID_MULTSECT] = max_multsect | 0x100;
96 id->multsect_valid = id->multsect ? 1 : 0; 94 else
97 drive->mult_req = id->multsect_valid ? id->max_multsect : 0; 95 id[ATA_ID_MULTSECT] &= ~0x1ff;
98 drive->special.b.set_multmode = drive->mult_req ? 1 : 0; 96
99#else /* original, pre IDE-NFG, per request of AC */ 97 drive->mult_req = id[ATA_ID_MULTSECT] & 0xff;
100 drive->mult_req = 0; 98
101 if (drive->mult_req > id->max_multsect) 99 if (drive->mult_req)
102 drive->mult_req = id->max_multsect;
103 if (drive->mult_req || ((id->multsect_valid & 1) && id->multsect))
104 drive->special.b.set_multmode = 1; 100 drive->special.b.set_multmode = 1;
105#endif
106 } 101 }
107} 102}
108 103
@@ -119,14 +114,15 @@ static void ide_disk_init_mult_count(ide_drive_t *drive)
119static inline void do_identify (ide_drive_t *drive, u8 cmd) 114static inline void do_identify (ide_drive_t *drive, u8 cmd)
120{ 115{
121 ide_hwif_t *hwif = HWIF(drive); 116 ide_hwif_t *hwif = HWIF(drive);
122 int bswap = 1; 117 u16 *id = drive->id;
123 struct hd_driveid *id; 118 char *m = (char *)&id[ATA_ID_PROD];
119 int bswap = 1, is_cfa;
124 120
125 id = drive->id;
126 /* read 512 bytes of id info */ 121 /* read 512 bytes of id info */
127 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE); 122 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
128 123
129 drive->id_read = 1; 124 drive->dev_flags |= IDE_DFLAG_ID_READ;
125
130 local_irq_enable(); 126 local_irq_enable();
131#ifdef DEBUG 127#ifdef DEBUG
132 printk(KERN_INFO "%s: dumping identify data\n", drive->name); 128 printk(KERN_INFO "%s: dumping identify data\n", drive->name);
@@ -135,59 +131,59 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
135 ide_fix_driveid(id); 131 ide_fix_driveid(id);
136 132
137 /* 133 /*
138 * WIN_IDENTIFY returns little-endian info, 134 * ATA_CMD_ID_ATA returns little-endian info,
139 * WIN_PIDENTIFY *usually* returns little-endian info. 135 * ATA_CMD_ID_ATAPI *usually* returns little-endian info.
140 */ 136 */
141 if (cmd == WIN_PIDENTIFY) { 137 if (cmd == ATA_CMD_ID_ATAPI) {
142 if ((id->model[0] == 'N' && id->model[1] == 'E') /* NEC */ 138 if ((m[0] == 'N' && m[1] == 'E') || /* NEC */
143 || (id->model[0] == 'F' && id->model[1] == 'X') /* Mitsumi */ 139 (m[0] == 'F' && m[1] == 'X') || /* Mitsumi */
144 || (id->model[0] == 'P' && id->model[1] == 'i'))/* Pioneer */ 140 (m[0] == 'P' && m[1] == 'i')) /* Pioneer */
145 /* Vertos drives may still be weird */ 141 /* Vertos drives may still be weird */
146 bswap ^= 1; 142 bswap ^= 1;
147 } 143 }
148 ide_fixstring(id->model, sizeof(id->model), bswap); 144
149 ide_fixstring(id->fw_rev, sizeof(id->fw_rev), bswap); 145 ide_fixstring(m, ATA_ID_PROD_LEN, bswap);
150 ide_fixstring(id->serial_no, sizeof(id->serial_no), bswap); 146 ide_fixstring((char *)&id[ATA_ID_FW_REV], ATA_ID_FW_REV_LEN, bswap);
147 ide_fixstring((char *)&id[ATA_ID_SERNO], ATA_ID_SERNO_LEN, bswap);
151 148
152 /* we depend on this a lot! */ 149 /* we depend on this a lot! */
153 id->model[sizeof(id->model)-1] = '\0'; 150 m[ATA_ID_PROD_LEN - 1] = '\0';
154 151
155 if (strstr(id->model, "E X A B Y T E N E S T")) 152 if (strstr(m, "E X A B Y T E N E S T"))
156 goto err_misc; 153 goto err_misc;
157 154
158 printk(KERN_INFO "%s: %s, ", drive->name, id->model); 155 printk(KERN_INFO "%s: %s, ", drive->name, m);
159 156
160 drive->present = 1; 157 drive->dev_flags |= IDE_DFLAG_PRESENT;
161 drive->dead = 0; 158 drive->dev_flags &= ~IDE_DFLAG_DEAD;
162 159
163 /* 160 /*
164 * Check for an ATAPI device 161 * Check for an ATAPI device
165 */ 162 */
166 if (cmd == WIN_PIDENTIFY) { 163 if (cmd == ATA_CMD_ID_ATAPI) {
167 u8 type = (id->config >> 8) & 0x1f; 164 u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f;
168 165
169 printk(KERN_CONT "ATAPI "); 166 printk(KERN_CONT "ATAPI ");
170 switch (type) { 167 switch (type) {
171 case ide_floppy: 168 case ide_floppy:
172 if (!strstr(id->model, "CD-ROM")) { 169 if (!strstr(m, "CD-ROM")) {
173 if (!strstr(id->model, "oppy") && 170 if (!strstr(m, "oppy") &&
174 !strstr(id->model, "poyp") && 171 !strstr(m, "poyp") &&
175 !strstr(id->model, "ZIP")) 172 !strstr(m, "ZIP"))
176 printk(KERN_CONT "cdrom or floppy?, assuming "); 173 printk(KERN_CONT "cdrom or floppy?, assuming ");
177 if (drive->media != ide_cdrom) { 174 if (drive->media != ide_cdrom) {
178 printk(KERN_CONT "FLOPPY"); 175 printk(KERN_CONT "FLOPPY");
179 drive->removable = 1; 176 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
180 break; 177 break;
181 } 178 }
182 } 179 }
183 /* Early cdrom models used zero */ 180 /* Early cdrom models used zero */
184 type = ide_cdrom; 181 type = ide_cdrom;
185 case ide_cdrom: 182 case ide_cdrom:
186 drive->removable = 1; 183 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
187#ifdef CONFIG_PPC 184#ifdef CONFIG_PPC
188 /* kludge for Apple PowerBook internal zip */ 185 /* kludge for Apple PowerBook internal zip */
189 if (!strstr(id->model, "CD-ROM") && 186 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
190 strstr(id->model, "ZIP")) {
191 printk(KERN_CONT "FLOPPY"); 187 printk(KERN_CONT "FLOPPY");
192 type = ide_floppy; 188 type = ide_floppy;
193 break; 189 break;
@@ -200,7 +196,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
200 break; 196 break;
201 case ide_optical: 197 case ide_optical:
202 printk(KERN_CONT "OPTICAL"); 198 printk(KERN_CONT "OPTICAL");
203 drive->removable = 1; 199 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
204 break; 200 break;
205 default: 201 default:
206 printk(KERN_CONT "UNKNOWN (type %d)", type); 202 printk(KERN_CONT "UNKNOWN (type %d)", type);
@@ -210,6 +206,11 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
210 drive->media = type; 206 drive->media = type;
211 /* an ATAPI device ignores DRDY */ 207 /* an ATAPI device ignores DRDY */
212 drive->ready_stat = 0; 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;
213 return; 214 return;
214 } 215 }
215 216
@@ -217,24 +218,24 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
217 * Not an ATAPI device: looks like a "regular" hard disk 218 * Not an ATAPI device: looks like a "regular" hard disk
218 */ 219 */
219 220
220 /* 221 is_cfa = ata_id_is_cfa(id);
221 * 0x848a = CompactFlash device
222 * These are *not* removable in Linux definition of the term
223 */
224 222
225 if ((id->config != 0x848a) && (id->config & (1<<7))) 223 /* CF devices are *not* removable in Linux definition of the term */
226 drive->removable = 1; 224 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
225 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
227 226
228 drive->media = ide_disk; 227 drive->media = ide_disk;
229 228
230 printk(KERN_CONT "%s DISK drive\n", 229 if (!ata_id_has_unload(drive->id))
231 (id->config == 0x848a) ? "CFA" : "ATA"); 230 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
231
232 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
232 233
233 return; 234 return;
234 235
235err_misc: 236err_misc:
236 kfree(id); 237 kfree(id);
237 drive->present = 0; 238 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
238 return; 239 return;
239} 240}
240 241
@@ -268,7 +269,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
268 if (io_ports->ctl_addr) { 269 if (io_ports->ctl_addr) {
269 a = tp_ops->read_altstatus(hwif); 270 a = tp_ops->read_altstatus(hwif);
270 s = tp_ops->read_status(hwif); 271 s = tp_ops->read_status(hwif);
271 if ((a ^ s) & ~INDEX_STAT) 272 if ((a ^ s) & ~ATA_IDX)
272 /* ancient Seagate drives, broken interfaces */ 273 /* ancient Seagate drives, broken interfaces */
273 printk(KERN_INFO "%s: probing with STATUS(0x%02x) " 274 printk(KERN_INFO "%s: probing with STATUS(0x%02x) "
274 "instead of ALTSTATUS(0x%02x)\n", 275 "instead of ALTSTATUS(0x%02x)\n",
@@ -281,7 +282,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
281 /* set features register for atapi 282 /* set features register for atapi
282 * identify command to be sure of reply 283 * identify command to be sure of reply
283 */ 284 */
284 if (cmd == WIN_PIDENTIFY) { 285 if (cmd == ATA_CMD_ID_ATAPI) {
285 ide_task_t task; 286 ide_task_t task;
286 287
287 memset(&task, 0, sizeof(task)); 288 memset(&task, 0, sizeof(task));
@@ -294,24 +295,16 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
294 /* ask drive for ID */ 295 /* ask drive for ID */
295 tp_ops->exec_command(hwif, cmd); 296 tp_ops->exec_command(hwif, cmd);
296 297
297 timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; 298 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
298 timeout += jiffies;
299 do {
300 if (time_after(jiffies, timeout)) {
301 /* drive timed-out */
302 return 1;
303 }
304 /* give drive a breather */
305 msleep(50);
306 s = use_altstatus ? tp_ops->read_altstatus(hwif)
307 : tp_ops->read_status(hwif);
308 } while (s & BUSY_STAT);
309 299
310 /* wait for IRQ and DRQ_STAT */ 300 if (ide_busy_sleep(hwif, timeout, use_altstatus))
301 return 1;
302
303 /* wait for IRQ and ATA_DRQ */
311 msleep(50); 304 msleep(50);
312 s = tp_ops->read_status(hwif); 305 s = tp_ops->read_status(hwif);
313 306
314 if (OK_STAT(s, DRQ_STAT, BAD_R_STAT)) { 307 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
315 unsigned long flags; 308 unsigned long flags;
316 309
317 /* local CPU only; some systems need this */ 310 /* local CPU only; some systems need this */
@@ -387,19 +380,21 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
387 return retval; 380 return retval;
388} 381}
389 382
390static int ide_busy_sleep(ide_hwif_t *hwif) 383int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
391{ 384{
392 unsigned long timeout = jiffies + WAIT_WORSTCASE;
393 u8 stat; 385 u8 stat;
394 386
387 timeout += jiffies;
388
395 do { 389 do {
396 msleep(50); 390 msleep(50); /* give drive a breather */
397 stat = hwif->tp_ops->read_status(hwif); 391 stat = altstatus ? hwif->tp_ops->read_altstatus(hwif)
398 if ((stat & BUSY_STAT) == 0) 392 : hwif->tp_ops->read_status(hwif);
393 if ((stat & ATA_BUSY) == 0)
399 return 0; 394 return 0;
400 } while (time_before(jiffies, timeout)); 395 } while (time_before(jiffies, timeout));
401 396
402 return 1; 397 return 1; /* drive timed-out */
403} 398}
404 399
405static u8 ide_read_device(ide_drive_t *drive) 400static u8 ide_read_device(ide_drive_t *drive)
@@ -440,17 +435,16 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
440 ide_hwif_t *hwif = HWIF(drive); 435 ide_hwif_t *hwif = HWIF(drive);
441 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 436 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
442 int rc; 437 int rc;
443 u8 stat; 438 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
439
440 /* avoid waiting for inappropriate probes */
441 if (present && drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
442 return 4;
444 443
445 if (drive->present) {
446 /* avoid waiting for inappropriate probes */
447 if ((drive->media != ide_disk) && (cmd == WIN_IDENTIFY))
448 return 4;
449 }
450#ifdef DEBUG 444#ifdef DEBUG
451 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n", 445 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
452 drive->name, drive->present, drive->media, 446 drive->name, present, drive->media,
453 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI"); 447 (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI");
454#endif 448#endif
455 449
456 /* needed for some systems 450 /* needed for some systems
@@ -460,11 +454,11 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
460 SELECT_DRIVE(drive); 454 SELECT_DRIVE(drive);
461 msleep(50); 455 msleep(50);
462 456
463 if (ide_read_device(drive) != drive->select.all && !drive->present) { 457 if (ide_read_device(drive) != drive->select && present == 0) {
464 if (drive->select.b.unit != 0) { 458 if (drive->dn & 1) {
465 /* exit with drive0 selected */ 459 /* exit with drive0 selected */
466 SELECT_DRIVE(&hwif->drives[0]); 460 SELECT_DRIVE(&hwif->drives[0]);
467 /* allow BUSY_STAT to assert & clear */ 461 /* allow ATA_BUSY to assert & clear */
468 msleep(50); 462 msleep(50);
469 } 463 }
470 /* no i/f present: mmm.. this should be a 4 -ml */ 464 /* no i/f present: mmm.. this should be a 4 -ml */
@@ -473,8 +467,8 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
473 467
474 stat = tp_ops->read_status(hwif); 468 stat = tp_ops->read_status(hwif);
475 469
476 if (OK_STAT(stat, READY_STAT, BUSY_STAT) || 470 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
477 drive->present || cmd == WIN_PIDENTIFY) { 471 present || cmd == ATA_CMD_ID_ATAPI) {
478 /* send cmd and wait */ 472 /* send cmd and wait */
479 if ((rc = try_to_identify(drive, cmd))) { 473 if ((rc = try_to_identify(drive, cmd))) {
480 /* failed: try again */ 474 /* failed: try again */
@@ -483,17 +477,17 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
483 477
484 stat = tp_ops->read_status(hwif); 478 stat = tp_ops->read_status(hwif);
485 479
486 if (stat == (BUSY_STAT | READY_STAT)) 480 if (stat == (ATA_BUSY | ATA_DRDY))
487 return 4; 481 return 4;
488 482
489 if (rc == 1 && cmd == WIN_PIDENTIFY) { 483 if (rc == 1 && cmd == ATA_CMD_ID_ATAPI) {
490 printk(KERN_ERR "%s: no response (status = 0x%02x), " 484 printk(KERN_ERR "%s: no response (status = 0x%02x), "
491 "resetting drive\n", drive->name, stat); 485 "resetting drive\n", drive->name, stat);
492 msleep(50); 486 msleep(50);
493 SELECT_DRIVE(drive); 487 SELECT_DRIVE(drive);
494 msleep(50); 488 msleep(50);
495 tp_ops->exec_command(hwif, WIN_SRST); 489 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
496 (void)ide_busy_sleep(hwif); 490 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0);
497 rc = try_to_identify(drive, cmd); 491 rc = try_to_identify(drive, cmd);
498 } 492 }
499 493
@@ -507,7 +501,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
507 /* not present or maybe ATAPI */ 501 /* not present or maybe ATAPI */
508 rc = 3; 502 rc = 3;
509 } 503 }
510 if (drive->select.b.unit != 0) { 504 if (drive->dn & 1) {
511 /* exit with drive0 selected */ 505 /* exit with drive0 selected */
512 SELECT_DRIVE(&hwif->drives[0]); 506 SELECT_DRIVE(&hwif->drives[0]);
513 msleep(50); 507 msleep(50);
@@ -526,13 +520,14 @@ static void enable_nest (ide_drive_t *drive)
526 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 520 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
527 u8 stat; 521 u8 stat;
528 522
529 printk(KERN_INFO "%s: enabling %s -- ", hwif->name, drive->id->model); 523 printk(KERN_INFO "%s: enabling %s -- ",
524 hwif->name, (char *)&drive->id[ATA_ID_PROD]);
530 525
531 SELECT_DRIVE(drive); 526 SELECT_DRIVE(drive);
532 msleep(50); 527 msleep(50);
533 tp_ops->exec_command(hwif, EXABYTE_ENABLE_NEST); 528 tp_ops->exec_command(hwif, ATA_EXABYTE_ENABLE_NEST);
534 529
535 if (ide_busy_sleep(hwif)) { 530 if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 0)) {
536 printk(KERN_CONT "failed (timeout)\n"); 531 printk(KERN_CONT "failed (timeout)\n");
537 return; 532 return;
538 } 533 }
@@ -545,12 +540,6 @@ static void enable_nest (ide_drive_t *drive)
545 printk(KERN_CONT "failed (status = 0x%02x)\n", stat); 540 printk(KERN_CONT "failed (status = 0x%02x)\n", stat);
546 else 541 else
547 printk(KERN_CONT "success\n"); 542 printk(KERN_CONT "success\n");
548
549 /* if !(success||timed-out) */
550 if (do_probe(drive, WIN_IDENTIFY) >= 2) {
551 /* look for ATAPI device */
552 (void) do_probe(drive, WIN_PIDENTIFY);
553 }
554} 543}
555 544
556/** 545/**
@@ -561,12 +550,14 @@ static void enable_nest (ide_drive_t *drive)
561 * and presents things to the user as needed. 550 * and presents things to the user as needed.
562 * 551 *
563 * Returns: 0 no device was found 552 * Returns: 0 no device was found
564 * 1 device was found (note: drive->present might 553 * 1 device was found
565 * still be 0) 554 * (note: IDE_DFLAG_PRESENT might still be not set)
566 */ 555 */
567 556
568static inline u8 probe_for_drive (ide_drive_t *drive) 557static inline u8 probe_for_drive (ide_drive_t *drive)
569{ 558{
559 char *m;
560
570 /* 561 /*
571 * In order to keep things simple we have an id 562 * In order to keep things simple we have an id
572 * block for all drives at all times. If the device 563 * block for all drives at all times. If the device
@@ -576,31 +567,36 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
576 * Also note that 0 everywhere means "can't do X" 567 * Also note that 0 everywhere means "can't do X"
577 */ 568 */
578 569
579 drive->id = kzalloc(SECTOR_WORDS *4, GFP_KERNEL); 570 drive->dev_flags &= ~IDE_DFLAG_ID_READ;
580 drive->id_read = 0; 571
581 if(drive->id == NULL) 572 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL);
582 { 573 if (drive->id == NULL) {
583 printk(KERN_ERR "ide: out of memory for id data.\n"); 574 printk(KERN_ERR "ide: out of memory for id data.\n");
584 return 0; 575 return 0;
585 } 576 }
586 strcpy(drive->id->model, "UNKNOWN"); 577
587 578 m = (char *)&drive->id[ATA_ID_PROD];
579 strcpy(m, "UNKNOWN");
580
588 /* skip probing? */ 581 /* skip probing? */
589 if (!drive->noprobe) 582 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) {
590 { 583retry:
591 /* if !(success||timed-out) */ 584 /* if !(success||timed-out) */
592 if (do_probe(drive, WIN_IDENTIFY) >= 2) { 585 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2)
593 /* look for ATAPI device */ 586 /* look for ATAPI device */
594 (void) do_probe(drive, WIN_PIDENTIFY); 587 (void)do_probe(drive, ATA_CMD_ID_ATAPI);
595 } 588
596 if (!drive->present) 589 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
597 /* drive not found */ 590 /* drive not found */
598 return 0; 591 return 0;
599 if (strstr(drive->id->model, "E X A B Y T E N E S T")) 592
593 if (strstr(m, "E X A B Y T E N E S T")) {
600 enable_nest(drive); 594 enable_nest(drive);
601 595 goto retry;
596 }
597
602 /* identification failed? */ 598 /* identification failed? */
603 if (!drive->id_read) { 599 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
604 if (drive->media == ide_disk) { 600 if (drive->media == ide_disk) {
605 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n", 601 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
606 drive->name, drive->cyl, 602 drive->name, drive->cyl,
@@ -610,15 +606,17 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
610 } else { 606 } else {
611 /* nuke it */ 607 /* nuke it */
612 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name); 608 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
613 drive->present = 0; 609 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
614 } 610 }
615 } 611 }
616 /* drive was found */ 612 /* drive was found */
617 } 613 }
618 if(!drive->present) 614
615 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
619 return 0; 616 return 0;
617
620 /* The drive wasn't being helpful. Add generic info only */ 618 /* The drive wasn't being helpful. Add generic info only */
621 if (drive->id_read == 0) { 619 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
622 generic_id(drive); 620 generic_id(drive);
623 return 1; 621 return 1;
624 } 622 }
@@ -628,7 +626,7 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
628 ide_disk_init_mult_count(drive); 626 ide_disk_init_mult_count(drive);
629 } 627 }
630 628
631 return drive->present; 629 return !!(drive->dev_flags & IDE_DFLAG_PRESENT);
632} 630}
633 631
634static void hwif_release_dev(struct device *dev) 632static void hwif_release_dev(struct device *dev)
@@ -660,8 +658,8 @@ static int ide_register_port(ide_hwif_t *hwif)
660 goto out; 658 goto out;
661 } 659 }
662 660
663 hwif->portdev = device_create_drvdata(ide_port_class, &hwif->gendev, 661 hwif->portdev = device_create(ide_port_class, &hwif->gendev,
664 MKDEV(0, 0), hwif, hwif->name); 662 MKDEV(0, 0), hwif, hwif->name);
665 if (IS_ERR(hwif->portdev)) { 663 if (IS_ERR(hwif->portdev)) {
666 ret = PTR_ERR(hwif->portdev); 664 ret = PTR_ERR(hwif->portdev);
667 device_unregister(&hwif->gendev); 665 device_unregister(&hwif->gendev);
@@ -719,7 +717,8 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
719 ide_drive_t *drive = &hwif->drives[unit]; 717 ide_drive_t *drive = &hwif->drives[unit];
720 718
721 /* Ignore disks that we will not probe for later. */ 719 /* Ignore disks that we will not probe for later. */
722 if (!drive->noprobe || drive->present) { 720 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
721 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
723 SELECT_DRIVE(drive); 722 SELECT_DRIVE(drive);
724 hwif->tp_ops->set_irq(hwif, 1); 723 hwif->tp_ops->set_irq(hwif, 1);
725 mdelay(2); 724 mdelay(2);
@@ -740,36 +739,38 @@ out:
740 739
741/** 740/**
742 * ide_undecoded_slave - look for bad CF adapters 741 * ide_undecoded_slave - look for bad CF adapters
743 * @drive1: drive 742 * @dev1: slave device
744 * 743 *
745 * Analyse the drives on the interface and attempt to decide if we 744 * Analyse the drives on the interface and attempt to decide if we
746 * have the same drive viewed twice. This occurs with crap CF adapters 745 * have the same drive viewed twice. This occurs with crap CF adapters
747 * and PCMCIA sometimes. 746 * and PCMCIA sometimes.
748 */ 747 */
749 748
750void ide_undecoded_slave(ide_drive_t *drive1) 749void ide_undecoded_slave(ide_drive_t *dev1)
751{ 750{
752 ide_drive_t *drive0 = &drive1->hwif->drives[0]; 751 ide_drive_t *dev0 = &dev1->hwif->drives[0];
753 752
754 if ((drive1->dn & 1) == 0 || drive0->present == 0) 753 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
755 return; 754 return;
756 755
757 /* If the models don't match they are not the same product */ 756 /* If the models don't match they are not the same product */
758 if (strcmp(drive0->id->model, drive1->id->model)) 757 if (strcmp((char *)&dev0->id[ATA_ID_PROD],
758 (char *)&dev1->id[ATA_ID_PROD]))
759 return; 759 return;
760 760
761 /* Serial numbers do not match */ 761 /* Serial numbers do not match */
762 if (strncmp(drive0->id->serial_no, drive1->id->serial_no, 20)) 762 if (strncmp((char *)&dev0->id[ATA_ID_SERNO],
763 (char *)&dev1->id[ATA_ID_SERNO], ATA_ID_SERNO_LEN))
763 return; 764 return;
764 765
765 /* No serial number, thankfully very rare for CF */ 766 /* No serial number, thankfully very rare for CF */
766 if (drive0->id->serial_no[0] == 0) 767 if (*(char *)&dev0->id[ATA_ID_SERNO] == 0)
767 return; 768 return;
768 769
769 /* Appears to be an IDE flash adapter with decode bugs */ 770 /* Appears to be an IDE flash adapter with decode bugs */
770 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n"); 771 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
771 772
772 drive1->present = 0; 773 dev1->dev_flags &= ~IDE_DFLAG_PRESENT;
773} 774}
774 775
775EXPORT_SYMBOL_GPL(ide_undecoded_slave); 776EXPORT_SYMBOL_GPL(ide_undecoded_slave);
@@ -782,7 +783,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
782 783
783 BUG_ON(hwif->present); 784 BUG_ON(hwif->present);
784 785
785 if (hwif->drives[0].noprobe && hwif->drives[1].noprobe) 786 if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) &&
787 (hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE))
786 return -EACCES; 788 return -EACCES;
787 789
788 /* 790 /*
@@ -804,9 +806,9 @@ static int ide_probe_port(ide_hwif_t *hwif)
804 */ 806 */
805 for (unit = 0; unit < MAX_DRIVES; ++unit) { 807 for (unit = 0; unit < MAX_DRIVES; ++unit) {
806 ide_drive_t *drive = &hwif->drives[unit]; 808 ide_drive_t *drive = &hwif->drives[unit];
807 drive->dn = (hwif->channel ? 2 : 0) + unit; 809
808 (void) probe_for_drive(drive); 810 (void) probe_for_drive(drive);
809 if (drive->present) 811 if (drive->dev_flags & IDE_DFLAG_PRESENT)
810 rc = 0; 812 rc = 0;
811 } 813 }
812 814
@@ -830,17 +832,19 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
830 for (unit = 0; unit < MAX_DRIVES; unit++) { 832 for (unit = 0; unit < MAX_DRIVES; unit++) {
831 ide_drive_t *drive = &hwif->drives[unit]; 833 ide_drive_t *drive = &hwif->drives[unit];
832 834
833 if (drive->present && port_ops && port_ops->quirkproc) 835 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
834 port_ops->quirkproc(drive); 836 if (port_ops && port_ops->quirkproc)
837 port_ops->quirkproc(drive);
838 }
835 } 839 }
836 840
837 for (unit = 0; unit < MAX_DRIVES; ++unit) { 841 for (unit = 0; unit < MAX_DRIVES; ++unit) {
838 ide_drive_t *drive = &hwif->drives[unit]; 842 ide_drive_t *drive = &hwif->drives[unit];
839 843
840 if (drive->present) { 844 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
841 ide_set_max_pio(drive); 845 ide_set_max_pio(drive);
842 846
843 drive->nice1 = 1; 847 drive->dev_flags |= IDE_DFLAG_NICE1;
844 848
845 if (hwif->dma_ops) 849 if (hwif->dma_ops)
846 ide_set_dma(drive); 850 ide_set_dma(drive);
@@ -850,14 +854,14 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
850 for (unit = 0; unit < MAX_DRIVES; ++unit) { 854 for (unit = 0; unit < MAX_DRIVES; ++unit) {
851 ide_drive_t *drive = &hwif->drives[unit]; 855 ide_drive_t *drive = &hwif->drives[unit];
852 856
853 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) 857 if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
854 drive->no_io_32bit = 1; 858 drive->id[ATA_ID_DWORD_IO])
859 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
855 else 860 else
856 drive->no_io_32bit = drive->id->dword_io ? 1 : 0; 861 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
857 } 862 }
858} 863}
859 864
860#if MAX_HWIFS > 1
861/* 865/*
862 * save_match() is used to simplify logic in init_irq() below. 866 * save_match() is used to simplify logic in init_irq() below.
863 * 867 *
@@ -882,7 +886,6 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
882 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */ 886 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
883 *match = new; 887 *match = new;
884} 888}
885#endif /* MAX_HWIFS > 1 */
886 889
887/* 890/*
888 * init request queue 891 * init request queue
@@ -961,26 +964,33 @@ static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
961 * - allocate the block device queue 964 * - allocate the block device queue
962 * - link drive into the hwgroup 965 * - link drive into the hwgroup
963 */ 966 */
964static void ide_port_setup_devices(ide_hwif_t *hwif) 967static int ide_port_setup_devices(ide_hwif_t *hwif)
965{ 968{
966 int i; 969 int i, j = 0;
967 970
968 mutex_lock(&ide_cfg_mtx); 971 mutex_lock(&ide_cfg_mtx);
969 for (i = 0; i < MAX_DRIVES; i++) { 972 for (i = 0; i < MAX_DRIVES; i++) {
970 ide_drive_t *drive = &hwif->drives[i]; 973 ide_drive_t *drive = &hwif->drives[i];
971 974
972 if (!drive->present) 975 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
973 continue; 976 continue;
974 977
975 if (ide_init_queue(drive)) { 978 if (ide_init_queue(drive)) {
976 printk(KERN_ERR "ide: failed to init %s\n", 979 printk(KERN_ERR "ide: failed to init %s\n",
977 drive->name); 980 drive->name);
981 kfree(drive->id);
982 drive->id = NULL;
983 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
978 continue; 984 continue;
979 } 985 }
980 986
987 j++;
988
981 ide_add_drive_to_hwgroup(drive); 989 ide_add_drive_to_hwgroup(drive);
982 } 990 }
983 mutex_unlock(&ide_cfg_mtx); 991 mutex_unlock(&ide_cfg_mtx);
992
993 return j;
984} 994}
985 995
986static ide_hwif_t *ide_ports[MAX_HWIFS]; 996static ide_hwif_t *ide_ports[MAX_HWIFS];
@@ -1037,14 +1047,9 @@ static int init_irq (ide_hwif_t *hwif)
1037 ide_hwgroup_t *hwgroup; 1047 ide_hwgroup_t *hwgroup;
1038 ide_hwif_t *match = NULL; 1048 ide_hwif_t *match = NULL;
1039 1049
1040
1041 BUG_ON(in_interrupt());
1042 BUG_ON(irqs_disabled());
1043 BUG_ON(hwif == NULL);
1044
1045 mutex_lock(&ide_cfg_mtx); 1050 mutex_lock(&ide_cfg_mtx);
1046 hwif->hwgroup = NULL; 1051 hwif->hwgroup = NULL;
1047#if MAX_HWIFS > 1 1052
1048 /* 1053 /*
1049 * Group up with any other hwifs that share our irq(s). 1054 * Group up with any other hwifs that share our irq(s).
1050 */ 1055 */
@@ -1069,7 +1074,7 @@ static int init_irq (ide_hwif_t *hwif)
1069 } 1074 }
1070 } 1075 }
1071 } 1076 }
1072#endif /* MAX_HWIFS > 1 */ 1077
1073 /* 1078 /*
1074 * If we are still without a hwgroup, then form a new one 1079 * If we are still without a hwgroup, then form a new one
1075 */ 1080 */
@@ -1116,7 +1121,8 @@ static int init_irq (ide_hwif_t *hwif)
1116 sa = IRQF_SHARED; 1121 sa = IRQF_SHARED;
1117#endif /* __mc68000__ */ 1122#endif /* __mc68000__ */
1118 1123
1119 if (IDE_CHIPSET_IS_PCI(hwif->chipset)) 1124 if (hwif->chipset == ide_pci || hwif->chipset == ide_cmd646 ||
1125 hwif->chipset == ide_ali14xx)
1120 sa = IRQF_SHARED; 1126 sa = IRQF_SHARED;
1121 1127
1122 if (io_ports->ctl_addr) 1128 if (io_ports->ctl_addr)
@@ -1167,12 +1173,13 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
1167 ide_hwif_t *hwif = data; 1173 ide_hwif_t *hwif = data;
1168 int unit = *part >> PARTN_BITS; 1174 int unit = *part >> PARTN_BITS;
1169 ide_drive_t *drive = &hwif->drives[unit]; 1175 ide_drive_t *drive = &hwif->drives[unit];
1170 if (!drive->present) 1176
1177 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1171 return NULL; 1178 return NULL;
1172 1179
1173 if (drive->media == ide_disk) 1180 if (drive->media == ide_disk)
1174 request_module("ide-disk"); 1181 request_module("ide-disk");
1175 if (drive->scsi) 1182 if (drive->dev_flags & IDE_DFLAG_SCSI)
1176 request_module("ide-scsi"); 1183 request_module("ide-scsi");
1177 if (drive->media == ide_cdrom || drive->media == ide_optical) 1184 if (drive->media == ide_cdrom || drive->media == ide_optical)
1178 request_module("ide-cd"); 1185 request_module("ide-cd");
@@ -1188,7 +1195,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
1188{ 1195{
1189 struct gendisk *p = data; 1196 struct gendisk *p = data;
1190 *part &= (1 << PARTN_BITS) - 1; 1197 *part &= (1 << PARTN_BITS) - 1;
1191 return &p->dev.kobj; 1198 return &disk_to_dev(p)->kobj;
1192} 1199}
1193 1200
1194static int exact_lock(dev_t dev, void *data) 1201static int exact_lock(dev_t dev, void *data)
@@ -1219,7 +1226,7 @@ EXPORT_SYMBOL_GPL(ide_unregister_region);
1219void ide_init_disk(struct gendisk *disk, ide_drive_t *drive) 1226void ide_init_disk(struct gendisk *disk, ide_drive_t *drive)
1220{ 1227{
1221 ide_hwif_t *hwif = drive->hwif; 1228 ide_hwif_t *hwif = drive->hwif;
1222 unsigned int unit = (drive->select.all >> 4) & 1; 1229 unsigned int unit = drive->dn & 1;
1223 1230
1224 disk->major = hwif->major; 1231 disk->major = hwif->major;
1225 disk->first_minor = unit << PARTN_BITS; 1232 disk->first_minor = unit << PARTN_BITS;
@@ -1262,7 +1269,7 @@ static void drive_release_dev (struct device *dev)
1262 ide_remove_drive_from_hwgroup(drive); 1269 ide_remove_drive_from_hwgroup(drive);
1263 kfree(drive->id); 1270 kfree(drive->id);
1264 drive->id = NULL; 1271 drive->id = NULL;
1265 drive->present = 0; 1272 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
1266 /* Messed up locking ... */ 1273 /* Messed up locking ... */
1267 spin_unlock_irq(&ide_lock); 1274 spin_unlock_irq(&ide_lock);
1268 blk_cleanup_queue(drive->queue); 1275 blk_cleanup_queue(drive->queue);
@@ -1341,11 +1348,9 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1341 struct device *dev = &drive->gendev; 1348 struct device *dev = &drive->gendev;
1342 int ret; 1349 int ret;
1343 1350
1344 if (!drive->present) 1351 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1345 continue; 1352 continue;
1346 1353
1347 ide_add_generic_settings(drive);
1348
1349 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i); 1354 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
1350 dev->parent = &hwif->gendev; 1355 dev->parent = &hwif->gendev;
1351 dev->bus = &ide_bus_type; 1356 dev->bus = &ide_bus_type;
@@ -1367,12 +1372,14 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
1367 for (i = 0; i < MAX_DRIVES; i++) { 1372 for (i = 0; i < MAX_DRIVES; i++) {
1368 ide_drive_t *drive = &hwif->drives[i]; 1373 ide_drive_t *drive = &hwif->drives[i];
1369 1374
1375 drive->dn = i + hwif->channel * 2;
1376
1370 if (hwif->host_flags & IDE_HFLAG_IO_32BIT) 1377 if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
1371 drive->io_32bit = 1; 1378 drive->io_32bit = 1;
1372 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS) 1379 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
1373 drive->unmask = 1; 1380 drive->dev_flags |= IDE_DFLAG_UNMASK;
1374 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS) 1381 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
1375 drive->no_unmask = 1; 1382 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
1376 1383
1377 if (port_ops && port_ops->init_dev) 1384 if (port_ops && port_ops->init_dev)
1378 port_ops->init_dev(drive); 1385 port_ops->init_dev(drive);
@@ -1529,19 +1536,14 @@ static int ide_find_port_slot(const struct ide_port_info *d)
1529 * ports 0x1f0/0x170 (the ide0/ide1 defaults). 1536 * ports 0x1f0/0x170 (the ide0/ide1 defaults).
1530 */ 1537 */
1531 mutex_lock(&ide_cfg_mtx); 1538 mutex_lock(&ide_cfg_mtx);
1532 if (MAX_HWIFS == 1) { 1539 if (bootable) {
1533 if (ide_indexes == 0 && i == 0) 1540 if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
1534 idx = 1; 1541 idx = ffz(ide_indexes | i);
1535 } else { 1542 } else {
1536 if (bootable) { 1543 if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
1537 if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1) 1544 idx = ffz(ide_indexes | 3);
1538 idx = ffz(ide_indexes | i); 1545 else if ((ide_indexes & 3) != 3)
1539 } else { 1546 idx = ffz(ide_indexes);
1540 if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
1541 idx = ffz(ide_indexes | 3);
1542 else if ((ide_indexes & 3) != 3)
1543 idx = ffz(ide_indexes);
1544 }
1545 } 1547 }
1546 if (idx >= 0) 1548 if (idx >= 0)
1547 ide_indexes |= (1 << idx); 1549 ide_indexes |= (1 << idx);
@@ -1557,8 +1559,7 @@ static void ide_free_port_slot(int idx)
1557 mutex_unlock(&ide_cfg_mtx); 1559 mutex_unlock(&ide_cfg_mtx);
1558} 1560}
1559 1561
1560struct ide_host *ide_host_alloc_all(const struct ide_port_info *d, 1562struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1561 hw_regs_t **hws)
1562{ 1563{
1563 struct ide_host *host; 1564 struct ide_host *host;
1564 int i; 1565 int i;
@@ -1567,7 +1568,7 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1567 if (host == NULL) 1568 if (host == NULL)
1568 return NULL; 1569 return NULL;
1569 1570
1570 for (i = 0; i < MAX_HWIFS; i++) { 1571 for (i = 0; i < MAX_HOST_PORTS; i++) {
1571 ide_hwif_t *hwif; 1572 ide_hwif_t *hwif;
1572 int idx; 1573 int idx;
1573 1574
@@ -1602,23 +1603,13 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1602 if (hws[0]) 1603 if (hws[0])
1603 host->dev[0] = hws[0]->dev; 1604 host->dev[0] = hws[0]->dev;
1604 1605
1605 if (d) 1606 if (d) {
1607 host->init_chipset = d->init_chipset;
1606 host->host_flags = d->host_flags; 1608 host->host_flags = d->host_flags;
1609 }
1607 1610
1608 return host; 1611 return host;
1609} 1612}
1610EXPORT_SYMBOL_GPL(ide_host_alloc_all);
1611
1612struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1613{
1614 hw_regs_t *hws_all[MAX_HWIFS];
1615 int i;
1616
1617 for (i = 0; i < MAX_HWIFS; i++)
1618 hws_all[i] = (i < 4) ? hws[i] : NULL;
1619
1620 return ide_host_alloc_all(d, hws_all);
1621}
1622EXPORT_SYMBOL_GPL(ide_host_alloc); 1613EXPORT_SYMBOL_GPL(ide_host_alloc);
1623 1614
1624int ide_host_register(struct ide_host *host, const struct ide_port_info *d, 1615int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
@@ -1627,7 +1618,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1627 ide_hwif_t *hwif, *mate = NULL; 1618 ide_hwif_t *hwif, *mate = NULL;
1628 int i, j = 0; 1619 int i, j = 0;
1629 1620
1630 for (i = 0; i < MAX_HWIFS; i++) { 1621 for (i = 0; i < MAX_HOST_PORTS; i++) {
1631 hwif = host->ports[i]; 1622 hwif = host->ports[i];
1632 1623
1633 if (hwif == NULL) { 1624 if (hwif == NULL) {
@@ -1640,22 +1631,22 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1640 1631
1641 if (d == NULL) { 1632 if (d == NULL) {
1642 mate = NULL; 1633 mate = NULL;
1643 continue; 1634 } else {
1644 } 1635 if ((i & 1) && mate) {
1636 hwif->mate = mate;
1637 mate->mate = hwif;
1638 }
1645 1639
1646 if ((i & 1) && mate) { 1640 mate = (i & 1) ? NULL : hwif;
1647 hwif->mate = mate;
1648 mate->mate = hwif;
1649 }
1650 1641
1651 mate = (i & 1) ? NULL : hwif; 1642 ide_init_port(hwif, i & 1, d);
1643 ide_port_cable_detect(hwif);
1644 }
1652 1645
1653 ide_init_port(hwif, i & 1, d);
1654 ide_port_cable_detect(hwif);
1655 ide_port_init_devices(hwif); 1646 ide_port_init_devices(hwif);
1656 } 1647 }
1657 1648
1658 for (i = 0; i < MAX_HWIFS; i++) { 1649 for (i = 0; i < MAX_HOST_PORTS; i++) {
1659 hwif = host->ports[i]; 1650 hwif = host->ports[i];
1660 1651
1661 if (hwif == NULL) 1652 if (hwif == NULL)
@@ -1672,7 +1663,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1672 ide_port_tune_devices(hwif); 1663 ide_port_tune_devices(hwif);
1673 } 1664 }
1674 1665
1675 for (i = 0; i < MAX_HWIFS; i++) { 1666 for (i = 0; i < MAX_HOST_PORTS; i++) {
1676 hwif = host->ports[i]; 1667 hwif = host->ports[i];
1677 1668
1678 if (hwif == NULL) 1669 if (hwif == NULL)
@@ -1685,10 +1676,13 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1685 continue; 1676 continue;
1686 } 1677 }
1687 1678
1688 j++;
1689
1690 if (hwif->present) 1679 if (hwif->present)
1691 ide_port_setup_devices(hwif); 1680 if (ide_port_setup_devices(hwif) == 0) {
1681 hwif->present = 0;
1682 continue;
1683 }
1684
1685 j++;
1692 1686
1693 ide_acpi_init(hwif); 1687 ide_acpi_init(hwif);
1694 1688
@@ -1696,7 +1690,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1696 ide_acpi_port_init_devices(hwif); 1690 ide_acpi_port_init_devices(hwif);
1697 } 1691 }
1698 1692
1699 for (i = 0; i < MAX_HWIFS; i++) { 1693 for (i = 0; i < MAX_HOST_PORTS; i++) {
1700 hwif = host->ports[i]; 1694 hwif = host->ports[i];
1701 1695
1702 if (hwif == NULL) 1696 if (hwif == NULL)
@@ -1709,7 +1703,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1709 hwif_register_devices(hwif); 1703 hwif_register_devices(hwif);
1710 } 1704 }
1711 1705
1712 for (i = 0; i < MAX_HWIFS; i++) { 1706 for (i = 0; i < MAX_HOST_PORTS; i++) {
1713 hwif = host->ports[i]; 1707 hwif = host->ports[i];
1714 1708
1715 if (hwif == NULL) 1709 if (hwif == NULL)
@@ -1754,7 +1748,7 @@ void ide_host_free(struct ide_host *host)
1754 ide_hwif_t *hwif; 1748 ide_hwif_t *hwif;
1755 int i; 1749 int i;
1756 1750
1757 for (i = 0; i < MAX_HWIFS; i++) { 1751 for (i = 0; i < MAX_HOST_PORTS; i++) {
1758 hwif = host->ports[i]; 1752 hwif = host->ports[i];
1759 1753
1760 if (hwif == NULL) 1754 if (hwif == NULL)
@@ -1772,7 +1766,7 @@ void ide_host_remove(struct ide_host *host)
1772{ 1766{
1773 int i; 1767 int i;
1774 1768
1775 for (i = 0; i < MAX_HWIFS; i++) { 1769 for (i = 0; i < MAX_HOST_PORTS; i++) {
1776 if (host->ports[i]) 1770 if (host->ports[i])
1777 ide_unregister(host->ports[i]); 1771 ide_unregister(host->ports[i]);
1778 } 1772 }
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index f66c9c3f6fc6..f3cddd1b2f8f 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 1997-1998 Mark Lord 2 * Copyright (C) 1997-1998 Mark Lord
3 * Copyright (C) 2003 Red Hat <alan@redhat.com> 3 * Copyright (C) 2003 Red Hat
4 * 4 *
5 * Some code was moved here from ide.c, see it for original copyrights. 5 * Some code was moved here from ide.c, see it for original copyrights.
6 */ 6 */
@@ -12,14 +12,6 @@
12 * "settings" files. e.g. "cat /proc/ide0/hda/settings" 12 * "settings" files. e.g. "cat /proc/ide0/hda/settings"
13 * To write a new value "val" into a specific setting "name", use: 13 * To write a new value "val" into a specific setting "name", use:
14 * echo "name:val" >/proc/ide/ide0/hda/settings 14 * echo "name:val" >/proc/ide/ide0/hda/settings
15 *
16 * Also useful, "cat /proc/ide0/hda/[identify, smart_values,
17 * smart_thresholds, capabilities]" will issue an IDENTIFY /
18 * PACKET_IDENTIFY / SMART_READ_VALUES / SMART_READ_THRESHOLDS /
19 * SENSE CAPABILITIES command to /dev/hda, and then dump out the
20 * returned data as 256 16-bit words. The "hdparm" utility will
21 * be updated someday soon to use this mechanism.
22 *
23 */ 15 */
24 16
25#include <linux/module.h> 17#include <linux/module.h>
@@ -31,7 +23,6 @@
31#include <linux/mm.h> 23#include <linux/mm.h>
32#include <linux/pci.h> 24#include <linux/pci.h>
33#include <linux/ctype.h> 25#include <linux/ctype.h>
34#include <linux/hdreg.h>
35#include <linux/ide.h> 26#include <linux/ide.h>
36#include <linux/seq_file.h> 27#include <linux/seq_file.h>
37 28
@@ -109,13 +100,14 @@ static int proc_ide_read_identify
109 100
110 err = taskfile_lib_get_identify(drive, page); 101 err = taskfile_lib_get_identify(drive, page);
111 if (!err) { 102 if (!err) {
112 char *out = ((char *)page) + (SECTOR_WORDS * 4); 103 char *out = (char *)page + SECTOR_SIZE;
104
113 page = out; 105 page = out;
114 do { 106 do {
115 out += sprintf(out, "%04x%c", 107 out += sprintf(out, "%04x%c",
116 le16_to_cpup(val), (++i & 7) ? ' ' : '\n'); 108 le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
117 val += 1; 109 val += 1;
118 } while (i < (SECTOR_WORDS * 2)); 110 } while (i < SECTOR_SIZE / 2);
119 len = out - page; 111 len = out - page;
120 } 112 }
121 } 113 }
@@ -123,140 +115,25 @@ static int proc_ide_read_identify
123} 115}
124 116
125/** 117/**
126 * __ide_add_setting - add an ide setting option 118 * ide_find_setting - find a specific setting
127 * @drive: drive to use 119 * @st: setting table pointer
128 * @name: setting name
129 * @rw: true if the function is read write
130 * @data_type: type of data
131 * @min: range minimum
132 * @max: range maximum
133 * @mul_factor: multiplication scale
134 * @div_factor: divison scale
135 * @data: private data field
136 * @set: setting
137 * @auto_remove: setting auto removal flag
138 *
139 * Removes the setting named from the device if it is present.
140 * The function takes the settings_lock to protect against
141 * parallel changes. This function must not be called from IRQ
142 * context. Returns 0 on success or -1 on failure.
143 *
144 * BUGS: This code is seriously over-engineered. There is also
145 * magic about how the driver specific features are setup. If
146 * a driver is attached we assume the driver settings are auto
147 * remove.
148 */
149
150static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove)
151{
152 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
153
154 mutex_lock(&ide_setting_mtx);
155 while ((*p) && strcmp((*p)->name, name) < 0)
156 p = &((*p)->next);
157 if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
158 goto abort;
159 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
160 goto abort;
161 strcpy(setting->name, name);
162 setting->rw = rw;
163 setting->data_type = data_type;
164 setting->min = min;
165 setting->max = max;
166 setting->mul_factor = mul_factor;
167 setting->div_factor = div_factor;
168 setting->data = data;
169 setting->set = set;
170
171 setting->next = *p;
172 if (auto_remove)
173 setting->auto_remove = 1;
174 *p = setting;
175 mutex_unlock(&ide_setting_mtx);
176 return 0;
177abort:
178 mutex_unlock(&ide_setting_mtx);
179 kfree(setting);
180 return -1;
181}
182
183int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
184{
185 return __ide_add_setting(drive, name, rw, data_type, min, max, mul_factor, div_factor, data, set, 1);
186}
187
188EXPORT_SYMBOL(ide_add_setting);
189
190/**
191 * __ide_remove_setting - remove an ide setting option
192 * @drive: drive to use
193 * @name: setting name
194 *
195 * Removes the setting named from the device if it is present.
196 * The caller must hold the setting semaphore.
197 */
198
199static void __ide_remove_setting(ide_drive_t *drive, char *name)
200{
201 ide_settings_t **p, *setting;
202
203 p = (ide_settings_t **) &drive->settings;
204
205 while ((*p) && strcmp((*p)->name, name))
206 p = &((*p)->next);
207 setting = (*p);
208 if (setting == NULL)
209 return;
210
211 (*p) = setting->next;
212
213 kfree(setting->name);
214 kfree(setting);
215}
216
217/**
218 * auto_remove_settings - remove driver specific settings
219 * @drive: drive
220 *
221 * Automatically remove all the driver specific settings for this
222 * drive. This function may not be called from IRQ context. The
223 * caller must hold ide_setting_mtx.
224 */
225
226static void auto_remove_settings(ide_drive_t *drive)
227{
228 ide_settings_t *setting;
229repeat:
230 setting = drive->settings;
231 while (setting) {
232 if (setting->auto_remove) {
233 __ide_remove_setting(drive, setting->name);
234 goto repeat;
235 }
236 setting = setting->next;
237 }
238}
239
240/**
241 * ide_find_setting_by_name - find a drive specific setting
242 * @drive: drive to scan
243 * @name: setting name 120 * @name: setting name
244 * 121 *
245 * Scan's the device setting table for a matching entry and returns 122 * Scan's the setting table for a matching entry and returns
246 * this or NULL if no entry is found. The caller must hold the 123 * this or NULL if no entry is found. The caller must hold the
247 * setting semaphore 124 * setting semaphore
248 */ 125 */
249 126
250static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name) 127static
128const struct ide_proc_devset *ide_find_setting(const struct ide_proc_devset *st,
129 char *name)
251{ 130{
252 ide_settings_t *setting = drive->settings; 131 while (st->name) {
253 132 if (strcmp(st->name, name) == 0)
254 while (setting) {
255 if (strcmp(setting->name, name) == 0)
256 break; 133 break;
257 setting = setting->next; 134 st++;
258 } 135 }
259 return setting; 136 return st->name ? st : NULL;
260} 137}
261 138
262/** 139/**
@@ -272,26 +149,20 @@ static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name)
272 * be told apart 149 * be told apart
273 */ 150 */
274 151
275static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting) 152static int ide_read_setting(ide_drive_t *drive,
153 const struct ide_proc_devset *setting)
276{ 154{
277 int val = -EINVAL; 155 const struct ide_devset *ds = setting->setting;
278 unsigned long flags; 156 int val = -EINVAL;
157
158 if (ds->get) {
159 unsigned long flags;
279 160
280 if ((setting->rw & SETTING_READ)) {
281 spin_lock_irqsave(&ide_lock, flags); 161 spin_lock_irqsave(&ide_lock, flags);
282 switch (setting->data_type) { 162 val = ds->get(drive);
283 case TYPE_BYTE:
284 val = *((u8 *) setting->data);
285 break;
286 case TYPE_SHORT:
287 val = *((u16 *) setting->data);
288 break;
289 case TYPE_INT:
290 val = *((u32 *) setting->data);
291 break;
292 }
293 spin_unlock_irqrestore(&ide_lock, flags); 163 spin_unlock_irqrestore(&ide_lock, flags);
294 } 164 }
165
295 return val; 166 return val;
296} 167}
297 168
@@ -313,33 +184,23 @@ static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting)
313 * The current scheme of polling is kludgy, though safe enough. 184 * The current scheme of polling is kludgy, though safe enough.
314 */ 185 */
315 186
316static int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val) 187static int ide_write_setting(ide_drive_t *drive,
188 const struct ide_proc_devset *setting, int val)
317{ 189{
190 const struct ide_devset *ds = setting->setting;
191
318 if (!capable(CAP_SYS_ADMIN)) 192 if (!capable(CAP_SYS_ADMIN))
319 return -EACCES; 193 return -EACCES;
320 if (setting->set) 194 if (!ds->set)
321 return setting->set(drive, val);
322 if (!(setting->rw & SETTING_WRITE))
323 return -EPERM; 195 return -EPERM;
324 if (val < setting->min || val > setting->max) 196 if ((ds->flags & DS_SYNC)
197 && (val < setting->min || val > setting->max))
325 return -EINVAL; 198 return -EINVAL;
326 if (ide_spin_wait_hwgroup(drive)) 199 return ide_devset_execute(drive, ds, val);
327 return -EBUSY;
328 switch (setting->data_type) {
329 case TYPE_BYTE:
330 *((u8 *) setting->data) = val;
331 break;
332 case TYPE_SHORT:
333 *((u16 *) setting->data) = val;
334 break;
335 case TYPE_INT:
336 *((u32 *) setting->data) = val;
337 break;
338 }
339 spin_unlock_irq(&ide_lock);
340 return 0;
341} 200}
342 201
202ide_devset_get(xfer_rate, current_speed);
203
343static int set_xfer_rate (ide_drive_t *drive, int arg) 204static int set_xfer_rate (ide_drive_t *drive, int arg)
344{ 205{
345 ide_task_t task; 206 ide_task_t task;
@@ -349,7 +210,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
349 return -EINVAL; 210 return -EINVAL;
350 211
351 memset(&task, 0, sizeof(task)); 212 memset(&task, 0, sizeof(task));
352 task.tf.command = WIN_SETFEATURES; 213 task.tf.command = ATA_CMD_SET_FEATURES;
353 task.tf.feature = SETFEATURES_XFER; 214 task.tf.feature = SETFEATURES_XFER;
354 task.tf.nsect = (u8)arg; 215 task.tf.nsect = (u8)arg;
355 task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT | 216 task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT |
@@ -364,29 +225,23 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
364 return err; 225 return err;
365} 226}
366 227
367/** 228ide_devset_rw(current_speed, xfer_rate);
368 * ide_add_generic_settings - generic ide settings 229ide_devset_rw_field(init_speed, init_speed);
369 * @drive: drive being configured 230ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1);
370 * 231ide_devset_rw_field(number, dn);
371 * Add the generic parts of the system settings to the /proc files. 232
372 * The caller must not be holding the ide_setting_mtx. 233static const struct ide_proc_devset ide_generic_settings[] = {
373 */ 234 IDE_PROC_DEVSET(current_speed, 0, 70),
374 235 IDE_PROC_DEVSET(init_speed, 0, 70),
375void ide_add_generic_settings (ide_drive_t *drive) 236 IDE_PROC_DEVSET(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1)),
376{ 237 IDE_PROC_DEVSET(keepsettings, 0, 1),
377/* 238 IDE_PROC_DEVSET(nice1, 0, 1),
378 * drive setting name read/write access data type min max mul_factor div_factor data pointer set function 239 IDE_PROC_DEVSET(number, 0, 3),
379 */ 240 IDE_PROC_DEVSET(pio_mode, 0, 255),
380 __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0); 241 IDE_PROC_DEVSET(unmaskirq, 0, 1),
381 __ide_add_setting(drive, "keepsettings", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0); 242 IDE_PROC_DEVSET(using_dma, 0, 1),
382 __ide_add_setting(drive, "nice1", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0); 243 { 0 },
383 __ide_add_setting(drive, "pio_mode", SETTING_WRITE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0); 244};
384 __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0);
385 __ide_add_setting(drive, "using_dma", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0);
386 __ide_add_setting(drive, "init_speed", SETTING_RW, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0);
387 __ide_add_setting(drive, "current_speed", SETTING_RW, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0);
388 __ide_add_setting(drive, "number", SETTING_RW, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0);
389}
390 245
391static void proc_ide_settings_warn(void) 246static void proc_ide_settings_warn(void)
392{ 247{
@@ -403,19 +258,32 @@ static void proc_ide_settings_warn(void)
403static int proc_ide_read_settings 258static int proc_ide_read_settings
404 (char *page, char **start, off_t off, int count, int *eof, void *data) 259 (char *page, char **start, off_t off, int count, int *eof, void *data)
405{ 260{
261 const struct ide_proc_devset *setting, *g, *d;
262 const struct ide_devset *ds;
406 ide_drive_t *drive = (ide_drive_t *) data; 263 ide_drive_t *drive = (ide_drive_t *) data;
407 ide_settings_t *setting = (ide_settings_t *) drive->settings;
408 char *out = page; 264 char *out = page;
409 int len, rc, mul_factor, div_factor; 265 int len, rc, mul_factor, div_factor;
410 266
411 proc_ide_settings_warn(); 267 proc_ide_settings_warn();
412 268
413 mutex_lock(&ide_setting_mtx); 269 mutex_lock(&ide_setting_mtx);
270 g = ide_generic_settings;
271 d = drive->settings;
414 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); 272 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
415 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); 273 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
416 while (setting) { 274 while (g->name || (d && d->name)) {
417 mul_factor = setting->mul_factor; 275 /* read settings in the alphabetical order */
418 div_factor = setting->div_factor; 276 if (g->name && d && d->name) {
277 if (strcmp(d->name, g->name) < 0)
278 setting = d++;
279 else
280 setting = g++;
281 } else if (d && d->name) {
282 setting = d++;
283 } else
284 setting = g++;
285 mul_factor = setting->mulf ? setting->mulf(drive) : 1;
286 div_factor = setting->divf ? setting->divf(drive) : 1;
419 out += sprintf(out, "%-24s", setting->name); 287 out += sprintf(out, "%-24s", setting->name);
420 rc = ide_read_setting(drive, setting); 288 rc = ide_read_setting(drive, setting);
421 if (rc >= 0) 289 if (rc >= 0)
@@ -423,12 +291,12 @@ static int proc_ide_read_settings
423 else 291 else
424 out += sprintf(out, "%-16s", "write-only"); 292 out += sprintf(out, "%-16s", "write-only");
425 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); 293 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
426 if (setting->rw & SETTING_READ) 294 ds = setting->setting;
295 if (ds->get)
427 out += sprintf(out, "r"); 296 out += sprintf(out, "r");
428 if (setting->rw & SETTING_WRITE) 297 if (ds->set)
429 out += sprintf(out, "w"); 298 out += sprintf(out, "w");
430 out += sprintf(out, "\n"); 299 out += sprintf(out, "\n");
431 setting = setting->next;
432 } 300 }
433 len = out - page; 301 len = out - page;
434 mutex_unlock(&ide_setting_mtx); 302 mutex_unlock(&ide_setting_mtx);
@@ -442,9 +310,10 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
442{ 310{
443 ide_drive_t *drive = (ide_drive_t *) data; 311 ide_drive_t *drive = (ide_drive_t *) data;
444 char name[MAX_LEN + 1]; 312 char name[MAX_LEN + 1];
445 int for_real = 0; 313 int for_real = 0, mul_factor, div_factor;
446 unsigned long n; 314 unsigned long n;
447 ide_settings_t *setting; 315
316 const struct ide_proc_devset *setting;
448 char *buf, *s; 317 char *buf, *s;
449 318
450 if (!capable(CAP_SYS_ADMIN)) 319 if (!capable(CAP_SYS_ADMIN))
@@ -512,13 +381,21 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
512 } 381 }
513 382
514 mutex_lock(&ide_setting_mtx); 383 mutex_lock(&ide_setting_mtx);
515 setting = ide_find_setting_by_name(drive, name); 384 /* generic settings first, then driver specific ones */
385 setting = ide_find_setting(ide_generic_settings, name);
516 if (!setting) { 386 if (!setting) {
517 mutex_unlock(&ide_setting_mtx); 387 if (drive->settings)
518 goto parse_error; 388 setting = ide_find_setting(drive->settings, name);
389 if (!setting) {
390 mutex_unlock(&ide_setting_mtx);
391 goto parse_error;
392 }
393 }
394 if (for_real) {
395 mul_factor = setting->mulf ? setting->mulf(drive) : 1;
396 div_factor = setting->divf ? setting->divf(drive) : 1;
397 ide_write_setting(drive, setting, val * div_factor / mul_factor);
519 } 398 }
520 if (for_real)
521 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
522 mutex_unlock(&ide_setting_mtx); 399 mutex_unlock(&ide_setting_mtx);
523 } 400 }
524 } while (!for_real++); 401 } while (!for_real++);
@@ -561,11 +438,10 @@ static int proc_ide_read_dmodel
561 (char *page, char **start, off_t off, int count, int *eof, void *data) 438 (char *page, char **start, off_t off, int count, int *eof, void *data)
562{ 439{
563 ide_drive_t *drive = (ide_drive_t *) data; 440 ide_drive_t *drive = (ide_drive_t *) data;
564 struct hd_driveid *id = drive->id; 441 char *m = (char *)&drive->id[ATA_ID_PROD];
565 int len; 442 int len;
566 443
567 len = sprintf(page, "%.40s\n", 444 len = sprintf(page, "%.40s\n", m[0] ? m : "(none)");
568 (id && id->model[0]) ? (char *)id->model : "(none)");
569 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 445 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
570} 446}
571 447
@@ -690,7 +566,11 @@ static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t
690 566
691void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver) 567void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver)
692{ 568{
693 ide_add_proc_entries(drive->proc, driver->proc, drive); 569 mutex_lock(&ide_setting_mtx);
570 drive->settings = driver->proc_devsets(drive);
571 mutex_unlock(&ide_setting_mtx);
572
573 ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive);
694} 574}
695 575
696EXPORT_SYMBOL(ide_proc_register_driver); 576EXPORT_SYMBOL(ide_proc_register_driver);
@@ -711,7 +591,7 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
711{ 591{
712 unsigned long flags; 592 unsigned long flags;
713 593
714 ide_remove_proc_entries(drive->proc, driver->proc); 594 ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
715 595
716 mutex_lock(&ide_setting_mtx); 596 mutex_lock(&ide_setting_mtx);
717 spin_lock_irqsave(&ide_lock, flags); 597 spin_lock_irqsave(&ide_lock, flags);
@@ -726,7 +606,7 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
726 * OTOH both ide_{read,write}_setting are only ever used under 606 * OTOH both ide_{read,write}_setting are only ever used under
727 * ide_setting_mtx. 607 * ide_setting_mtx.
728 */ 608 */
729 auto_remove_settings(drive); 609 drive->settings = NULL;
730 spin_unlock_irqrestore(&ide_lock, flags); 610 spin_unlock_irqrestore(&ide_lock, flags);
731 mutex_unlock(&ide_setting_mtx); 611 mutex_unlock(&ide_setting_mtx);
732} 612}
@@ -742,9 +622,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
742 for (d = 0; d < MAX_DRIVES; d++) { 622 for (d = 0; d < MAX_DRIVES; d++) {
743 ide_drive_t *drive = &hwif->drives[d]; 623 ide_drive_t *drive = &hwif->drives[d];
744 624
745 if (!drive->present) 625 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
746 continue;
747 if (drive->proc)
748 continue; 626 continue;
749 627
750 drive->proc = proc_mkdir(drive->name, parent); 628 drive->proc = proc_mkdir(drive->name, parent);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 3833189144ed..a2d470eb2b55 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -15,6 +15,8 @@
15 * Documentation/ide/ChangeLog.ide-tape.1995-2002 15 * Documentation/ide/ChangeLog.ide-tape.1995-2002
16 */ 16 */
17 17
18#define DRV_NAME "ide-tape"
19
18#define IDETAPE_VERSION "1.20" 20#define IDETAPE_VERSION "1.20"
19 21
20#include <linux/module.h> 22#include <linux/module.h>
@@ -54,8 +56,6 @@ enum {
54 DBG_CHRDEV = (1 << 2), 56 DBG_CHRDEV = (1 << 2),
55 /* all remaining procedures */ 57 /* all remaining procedures */
56 DBG_PROCS = (1 << 3), 58 DBG_PROCS = (1 << 3),
57 /* buffer alloc info (pc_stack & rq_stack) */
58 DBG_PCRQ_STACK = (1 << 4),
59}; 59};
60 60
61/* define to see debug info */ 61/* define to see debug info */
@@ -81,26 +81,6 @@ enum {
81#define IDETAPE_MAX_PC_RETRIES 3 81#define IDETAPE_MAX_PC_RETRIES 3
82 82
83/* 83/*
84 * With each packet command, we allocate a buffer of IDETAPE_PC_BUFFER_SIZE
85 * bytes. This is used for several packet commands (Not for READ/WRITE commands)
86 */
87#define IDETAPE_PC_BUFFER_SIZE 256
88
89/*
90 * In various places in the driver, we need to allocate storage
91 * for packet commands and requests, which will remain valid while
92 * we leave the driver to wait for an interrupt or a timeout event.
93 */
94#define IDETAPE_PC_STACK (10 + IDETAPE_MAX_PC_RETRIES)
95
96/*
97 * Some drives (for example, Seagate STT3401A Travan) require a very long
98 * timeout, because they don't return an interrupt or clear their busy bit
99 * until after the command completes (even retension commands).
100 */
101#define IDETAPE_WAIT_CMD (900*HZ)
102
103/*
104 * The following parameter is used to select the point in the internal tape fifo 84 * The following parameter is used to select the point in the internal tape fifo
105 * in which we will start to refill the buffer. Decreasing the following 85 * in which we will start to refill the buffer. Decreasing the following
106 * parameter will improve the system's latency and interactive response, while 86 * parameter will improve the system's latency and interactive response, while
@@ -172,20 +152,6 @@ struct idetape_bh {
172#define IDETAPE_LU_RETENSION_MASK 2 152#define IDETAPE_LU_RETENSION_MASK 2
173#define IDETAPE_LU_EOT_MASK 4 153#define IDETAPE_LU_EOT_MASK 4
174 154
175/*
176 * Special requests for our block device strategy routine.
177 *
178 * In order to service a character device command, we add special requests to
179 * the tail of our block device request queue and wait for their completion.
180 */
181
182enum {
183 REQ_IDETAPE_PC1 = (1 << 0), /* packet command (first stage) */
184 REQ_IDETAPE_PC2 = (1 << 1), /* packet command (second stage) */
185 REQ_IDETAPE_READ = (1 << 2),
186 REQ_IDETAPE_WRITE = (1 << 3),
187};
188
189/* Error codes returned in rq->errors to the higher part of the driver. */ 155/* Error codes returned in rq->errors to the higher part of the driver. */
190#define IDETAPE_ERROR_GENERAL 101 156#define IDETAPE_ERROR_GENERAL 101
191#define IDETAPE_ERROR_FILEMARK 102 157#define IDETAPE_ERROR_FILEMARK 102
@@ -206,31 +172,15 @@ typedef struct ide_tape_obj {
206 struct kref kref; 172 struct kref kref;
207 173
208 /* 174 /*
209 * Since a typical character device operation requires more
210 * than one packet command, we provide here enough memory
211 * for the maximum of interconnected packet commands.
212 * The packet commands are stored in the circular array pc_stack.
213 * pc_stack_index points to the last used entry, and warps around
214 * to the start when we get to the last array entry.
215 *
216 * pc points to the current processed packet command.
217 *
218 * failed_pc points to the last failed packet command, or contains 175 * failed_pc points to the last failed packet command, or contains
219 * NULL if we do not need to retry any packet command. This is 176 * NULL if we do not need to retry any packet command. This is
220 * required since an additional packet command is needed before the 177 * required since an additional packet command is needed before the
221 * retry, to get detailed information on what went wrong. 178 * retry, to get detailed information on what went wrong.
222 */ 179 */
223 /* Current packet command */
224 struct ide_atapi_pc *pc;
225 /* Last failed packet command */ 180 /* Last failed packet command */
226 struct ide_atapi_pc *failed_pc; 181 struct ide_atapi_pc *failed_pc;
227 /* Packet command stack */ 182 /* used by REQ_IDETAPE_{READ,WRITE} requests */
228 struct ide_atapi_pc pc_stack[IDETAPE_PC_STACK]; 183 struct ide_atapi_pc queued_pc;
229 /* Next free packet command storage space */
230 int pc_stack_index;
231 struct request rq_stack[IDETAPE_PC_STACK];
232 /* We implement a circular array */
233 int rq_stack_index;
234 184
235 /* 185 /*
236 * DSC polling variables. 186 * DSC polling variables.
@@ -317,11 +267,6 @@ static DEFINE_MUTEX(idetape_ref_mutex);
317 267
318static struct class *idetape_sysfs_class; 268static struct class *idetape_sysfs_class;
319 269
320#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref)
321
322#define ide_tape_g(disk) \
323 container_of((disk)->private_data, struct ide_tape_obj, driver)
324
325static void ide_tape_release(struct kref *); 270static void ide_tape_release(struct kref *);
326 271
327static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) 272static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
@@ -329,7 +274,7 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
329 struct ide_tape_obj *tape = NULL; 274 struct ide_tape_obj *tape = NULL;
330 275
331 mutex_lock(&idetape_ref_mutex); 276 mutex_lock(&idetape_ref_mutex);
332 tape = ide_tape_g(disk); 277 tape = ide_drv_g(disk, ide_tape_obj);
333 if (tape) { 278 if (tape) {
334 if (ide_device_get(tape->drive)) 279 if (ide_device_get(tape->drive))
335 tape = NULL; 280 tape = NULL;
@@ -356,8 +301,6 @@ static void ide_tape_put(struct ide_tape_obj *tape)
356 */ 301 */
357static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES]; 302static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
358 303
359#define ide_tape_f(file) ((file)->private_data)
360
361static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) 304static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
362{ 305{
363 struct ide_tape_obj *tape = NULL; 306 struct ide_tape_obj *tape = NULL;
@@ -451,47 +394,6 @@ static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
451} 394}
452 395
453/* 396/*
454 * idetape_next_pc_storage returns a pointer to a place in which we can
455 * safely store a packet command, even though we intend to leave the
456 * driver. A storage space for a maximum of IDETAPE_PC_STACK packet
457 * commands is allocated at initialization time.
458 */
459static struct ide_atapi_pc *idetape_next_pc_storage(ide_drive_t *drive)
460{
461 idetape_tape_t *tape = drive->driver_data;
462
463 debug_log(DBG_PCRQ_STACK, "pc_stack_index=%d\n", tape->pc_stack_index);
464
465 if (tape->pc_stack_index == IDETAPE_PC_STACK)
466 tape->pc_stack_index = 0;
467 return (&tape->pc_stack[tape->pc_stack_index++]);
468}
469
470/*
471 * idetape_next_rq_storage is used along with idetape_next_pc_storage.
472 * Since we queue packet commands in the request queue, we need to
473 * allocate a request, along with the allocation of a packet command.
474 */
475
476/**************************************************************
477 * *
478 * This should get fixed to use kmalloc(.., GFP_ATOMIC) *
479 * followed later on by kfree(). -ml *
480 * *
481 **************************************************************/
482
483static struct request *idetape_next_rq_storage(ide_drive_t *drive)
484{
485 idetape_tape_t *tape = drive->driver_data;
486
487 debug_log(DBG_PCRQ_STACK, "rq_stack_index=%d\n", tape->rq_stack_index);
488
489 if (tape->rq_stack_index == IDETAPE_PC_STACK)
490 tape->rq_stack_index = 0;
491 return (&tape->rq_stack[tape->rq_stack_index++]);
492}
493
494/*
495 * called on each failed packet command retry to analyze the request sense. We 397 * called on each failed packet command retry to analyze the request sense. We
496 * currently do not utilize this information. 398 * currently do not utilize this information.
497 */ 399 */
@@ -606,14 +508,19 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
606 return 0; 508 return 0;
607} 509}
608 510
609static void ide_tape_callback(ide_drive_t *drive) 511static void ide_tape_handle_dsc(ide_drive_t *);
512
513static void ide_tape_callback(ide_drive_t *drive, int dsc)
610{ 514{
611 idetape_tape_t *tape = drive->driver_data; 515 idetape_tape_t *tape = drive->driver_data;
612 struct ide_atapi_pc *pc = tape->pc; 516 struct ide_atapi_pc *pc = drive->pc;
613 int uptodate = pc->error ? 0 : 1; 517 int uptodate = pc->error ? 0 : 1;
614 518
615 debug_log(DBG_PROCS, "Enter %s\n", __func__); 519 debug_log(DBG_PROCS, "Enter %s\n", __func__);
616 520
521 if (dsc)
522 ide_tape_handle_dsc(drive);
523
617 if (tape->failed_pc == pc) 524 if (tape->failed_pc == pc)
618 tape->failed_pc = NULL; 525 tape->failed_pc = NULL;
619 526
@@ -642,7 +549,7 @@ static void ide_tape_callback(ide_drive_t *drive)
642 if (pc->error) 549 if (pc->error)
643 uptodate = pc->error; 550 uptodate = pc->error;
644 } else if (pc->c[0] == READ_POSITION && uptodate) { 551 } else if (pc->c[0] == READ_POSITION && uptodate) {
645 u8 *readpos = tape->pc->buf; 552 u8 *readpos = pc->buf;
646 553
647 debug_log(DBG_SENSE, "BOP - %s\n", 554 debug_log(DBG_SENSE, "BOP - %s\n",
648 (readpos[0] & 0x80) ? "Yes" : "No"); 555 (readpos[0] & 0x80) ? "Yes" : "No");
@@ -667,79 +574,6 @@ static void ide_tape_callback(ide_drive_t *drive)
667 idetape_end_request(drive, uptodate, 0); 574 idetape_end_request(drive, uptodate, 0);
668} 575}
669 576
670static void idetape_init_pc(struct ide_atapi_pc *pc)
671{
672 memset(pc->c, 0, 12);
673 pc->retries = 0;
674 pc->flags = 0;
675 pc->req_xfer = 0;
676 pc->buf = pc->pc_buf;
677 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
678 pc->bh = NULL;
679 pc->b_data = NULL;
680}
681
682static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
683{
684 idetape_init_pc(pc);
685 pc->c[0] = REQUEST_SENSE;
686 pc->c[4] = 20;
687 pc->req_xfer = 20;
688}
689
690static void idetape_init_rq(struct request *rq, u8 cmd)
691{
692 blk_rq_init(NULL, rq);
693 rq->cmd_type = REQ_TYPE_SPECIAL;
694 rq->cmd[13] = cmd;
695}
696
697/*
698 * Generate a new packet command request in front of the request queue, before
699 * the current request, so that it will be processed immediately, on the next
700 * pass through the driver. The function below is called from the request
701 * handling part of the driver (the "bottom" part). Safe storage for the request
702 * should be allocated with ide_tape_next_{pc,rq}_storage() prior to that.
703 *
704 * Memory for those requests is pre-allocated at initialization time, and is
705 * limited to IDETAPE_PC_STACK requests. We assume that we have enough space for
706 * the maximum possible number of inter-dependent packet commands.
707 *
708 * The higher level of the driver - The ioctl handler and the character device
709 * handling functions should queue request to the lower level part and wait for
710 * their completion using idetape_queue_pc_tail or idetape_queue_rw_tail.
711 */
712static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
713 struct request *rq)
714{
715 struct ide_tape_obj *tape = drive->driver_data;
716
717 idetape_init_rq(rq, REQ_IDETAPE_PC1);
718 rq->cmd_flags |= REQ_PREEMPT;
719 rq->buffer = (char *) pc;
720 rq->rq_disk = tape->disk;
721 memcpy(rq->cmd, pc->c, 12);
722 ide_do_drive_cmd(drive, rq);
723}
724
725/*
726 * idetape_retry_pc is called when an error was detected during the
727 * last packet command. We queue a request sense packet command in
728 * the head of the request list.
729 */
730static void idetape_retry_pc(ide_drive_t *drive)
731{
732 struct ide_atapi_pc *pc;
733 struct request *rq;
734
735 (void)ide_read_error(drive);
736 pc = idetape_next_pc_storage(drive);
737 rq = idetape_next_rq_storage(drive);
738 idetape_create_request_sense_cmd(pc);
739 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
740 idetape_queue_pc_head(drive, pc, rq);
741}
742
743/* 577/*
744 * 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
745 * from another device on the same hwgroup while we are polling for DSC. 579 * from another device on the same hwgroup while we are polling for DSC.
@@ -766,44 +600,30 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
766 idetape_postpone_request(drive); 600 idetape_postpone_request(drive);
767} 601}
768 602
769static void ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, 603static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
770 unsigned int bcount, int write) 604 unsigned int bcount, int write)
771{ 605{
772 if (write) 606 if (write)
773 idetape_output_buffers(drive, pc, bcount); 607 idetape_output_buffers(drive, pc, bcount);
774 else 608 else
775 idetape_input_buffers(drive, pc, bcount); 609 idetape_input_buffers(drive, pc, bcount);
776}
777
778/*
779 * This is the usual interrupt handler which will be called during a packet
780 * command. We will transfer some of the data (as requested by the drive) and
781 * will re-point interrupt handler to us. When data transfer is finished, we
782 * will act according to the algorithm described before
783 * idetape_issue_pc.
784 */
785static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
786{
787 idetape_tape_t *tape = drive->driver_data;
788 610
789 return ide_pc_intr(drive, tape->pc, idetape_pc_intr, IDETAPE_WAIT_CMD, 611 return bcount;
790 NULL, idetape_update_buffers, idetape_retry_pc,
791 ide_tape_handle_dsc, ide_tape_io_buffers);
792} 612}
793 613
794/* 614/*
795 * Packet Command Interface 615 * Packet Command Interface
796 * 616 *
797 * The current Packet Command is available in tape->pc, and will not change 617 * The current Packet Command is available in drive->pc, and will not change
798 * until we finish handling it. Each packet command is associated with a 618 * until we finish handling it. Each packet command is associated with a
799 * callback function that will be called when the command is finished. 619 * callback function that will be called when the command is finished.
800 * 620 *
801 * The handling will be done in three stages: 621 * The handling will be done in three stages:
802 * 622 *
803 * 1. idetape_issue_pc will send the packet command to the drive, and will set 623 * 1. idetape_issue_pc will send the packet command to the drive, and will set
804 * the interrupt handler to idetape_pc_intr. 624 * the interrupt handler to ide_pc_intr.
805 * 625 *
806 * 2. On each interrupt, idetape_pc_intr will be called. This step will be 626 * 2. On each interrupt, ide_pc_intr will be called. This step will be
807 * repeated until the device signals us that no more interrupts will be issued. 627 * repeated until the device signals us that no more interrupts will be issued.
808 * 628 *
809 * 3. ATAPI Tape media access commands have immediate status with a delayed 629 * 3. ATAPI Tape media access commands have immediate status with a delayed
@@ -827,20 +647,13 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
827 * again, the callback function will be called and then we will handle the next 647 * again, the callback function will be called and then we will handle the next
828 * request. 648 * request.
829 */ 649 */
830static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
831{
832 idetape_tape_t *tape = drive->driver_data;
833
834 return ide_transfer_pc(drive, tape->pc, idetape_pc_intr,
835 IDETAPE_WAIT_CMD, NULL);
836}
837 650
838static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, 651static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
839 struct ide_atapi_pc *pc) 652 struct ide_atapi_pc *pc)
840{ 653{
841 idetape_tape_t *tape = drive->driver_data; 654 idetape_tape_t *tape = drive->driver_data;
842 655
843 if (tape->pc->c[0] == REQUEST_SENSE && 656 if (drive->pc->c[0] == REQUEST_SENSE &&
844 pc->c[0] == REQUEST_SENSE) { 657 pc->c[0] == REQUEST_SENSE) {
845 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - " 658 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
846 "Two request sense in serial were issued\n"); 659 "Two request sense in serial were issued\n");
@@ -848,8 +661,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
848 661
849 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) 662 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
850 tape->failed_pc = pc; 663 tape->failed_pc = pc;
664
851 /* Set the current packet command */ 665 /* Set the current packet command */
852 tape->pc = pc; 666 drive->pc = pc;
853 667
854 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 668 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
855 (pc->flags & PC_FLAG_ABORT)) { 669 (pc->flags & PC_FLAG_ABORT)) {
@@ -873,21 +687,20 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
873 pc->error = IDETAPE_ERROR_GENERAL; 687 pc->error = IDETAPE_ERROR_GENERAL;
874 } 688 }
875 tape->failed_pc = NULL; 689 tape->failed_pc = NULL;
876 drive->pc_callback(drive); 690 drive->pc_callback(drive, 0);
877 return ide_stopped; 691 return ide_stopped;
878 } 692 }
879 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 693 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
880 694
881 pc->retries++; 695 pc->retries++;
882 696
883 return ide_issue_pc(drive, pc, idetape_transfer_pc, 697 return ide_issue_pc(drive, WAIT_TAPE_CMD, NULL);
884 IDETAPE_WAIT_CMD, NULL);
885} 698}
886 699
887/* A mode sense command is used to "sense" tape parameters. */ 700/* A mode sense command is used to "sense" tape parameters. */
888static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) 701static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
889{ 702{
890 idetape_init_pc(pc); 703 ide_init_pc(pc);
891 pc->c[0] = MODE_SENSE; 704 pc->c[0] = MODE_SENSE;
892 if (page_code != IDETAPE_BLOCK_DESCRIPTOR) 705 if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
893 /* DBD = 1 - Don't return block descriptors */ 706 /* DBD = 1 - Don't return block descriptors */
@@ -915,19 +728,19 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
915{ 728{
916 ide_hwif_t *hwif = drive->hwif; 729 ide_hwif_t *hwif = drive->hwif;
917 idetape_tape_t *tape = drive->driver_data; 730 idetape_tape_t *tape = drive->driver_data;
918 struct ide_atapi_pc *pc = tape->pc; 731 struct ide_atapi_pc *pc = drive->pc;
919 u8 stat; 732 u8 stat;
920 733
921 stat = hwif->tp_ops->read_status(hwif); 734 stat = hwif->tp_ops->read_status(hwif);
922 735
923 if (stat & SEEK_STAT) { 736 if (stat & ATA_DSC) {
924 if (stat & ERR_STAT) { 737 if (stat & ATA_ERR) {
925 /* Error detected */ 738 /* Error detected */
926 if (pc->c[0] != TEST_UNIT_READY) 739 if (pc->c[0] != TEST_UNIT_READY)
927 printk(KERN_ERR "ide-tape: %s: I/O error, ", 740 printk(KERN_ERR "ide-tape: %s: I/O error, ",
928 tape->name); 741 tape->name);
929 /* Retry operation */ 742 /* Retry operation */
930 idetape_retry_pc(drive); 743 ide_retry_pc(drive, tape->disk);
931 return ide_stopped; 744 return ide_stopped;
932 } 745 }
933 pc->error = 0; 746 pc->error = 0;
@@ -935,7 +748,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
935 pc->error = IDETAPE_ERROR_GENERAL; 748 pc->error = IDETAPE_ERROR_GENERAL;
936 tape->failed_pc = NULL; 749 tape->failed_pc = NULL;
937 } 750 }
938 drive->pc_callback(drive); 751 drive->pc_callback(drive, 0);
939 return ide_stopped; 752 return ide_stopped;
940} 753}
941 754
@@ -946,7 +759,7 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
946 struct idetape_bh *bh = (struct idetape_bh *)rq->special; 759 struct idetape_bh *bh = (struct idetape_bh *)rq->special;
947 unsigned int length = rq->current_nr_sectors; 760 unsigned int length = rq->current_nr_sectors;
948 761
949 idetape_init_pc(pc); 762 ide_init_pc(pc);
950 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 763 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
951 pc->c[1] = 1; 764 pc->c[1] = 1;
952 pc->bh = bh; 765 pc->bh = bh;
@@ -978,9 +791,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
978 struct request *postponed_rq = tape->postponed_rq; 791 struct request *postponed_rq = tape->postponed_rq;
979 u8 stat; 792 u8 stat;
980 793
981 debug_log(DBG_SENSE, "sector: %ld, nr_sectors: %ld," 794 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu,"
982 " current_nr_sectors: %d\n", 795 " current_nr_sectors: %u\n",
983 rq->sector, rq->nr_sectors, rq->current_nr_sectors); 796 (unsigned long long)rq->sector, rq->nr_sectors,
797 rq->current_nr_sectors);
984 798
985 if (!blk_special_request(rq)) { 799 if (!blk_special_request(rq)) {
986 /* We do not support buffer cache originated requests. */ 800 /* We do not support buffer cache originated requests. */
@@ -991,7 +805,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
991 } 805 }
992 806
993 /* Retry a failed packet command */ 807 /* Retry a failed packet command */
994 if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) { 808 if (tape->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
995 pc = tape->failed_pc; 809 pc = tape->failed_pc;
996 goto out; 810 goto out;
997 } 811 }
@@ -1012,16 +826,17 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1012 */ 826 */
1013 stat = hwif->tp_ops->read_status(hwif); 827 stat = hwif->tp_ops->read_status(hwif);
1014 828
1015 if (!drive->dsc_overlap && !(rq->cmd[13] & REQ_IDETAPE_PC2)) 829 if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
830 (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
1016 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 831 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
1017 832
1018 if (drive->post_reset == 1) { 833 if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
1019 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 834 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
1020 drive->post_reset = 0; 835 drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
1021 } 836 }
1022 837
1023 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) && 838 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
1024 (stat & SEEK_STAT) == 0) { 839 (stat & ATA_DSC) == 0) {
1025 if (postponed_rq == NULL) { 840 if (postponed_rq == NULL) {
1026 tape->dsc_polling_start = jiffies; 841 tape->dsc_polling_start = jiffies;
1027 tape->dsc_poll_freq = tape->best_dsc_rw_freq; 842 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
@@ -1043,12 +858,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1043 return ide_stopped; 858 return ide_stopped;
1044 } 859 }
1045 if (rq->cmd[13] & REQ_IDETAPE_READ) { 860 if (rq->cmd[13] & REQ_IDETAPE_READ) {
1046 pc = idetape_next_pc_storage(drive); 861 pc = &tape->queued_pc;
1047 ide_tape_create_rw_cmd(tape, pc, rq, READ_6); 862 ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
1048 goto out; 863 goto out;
1049 } 864 }
1050 if (rq->cmd[13] & REQ_IDETAPE_WRITE) { 865 if (rq->cmd[13] & REQ_IDETAPE_WRITE) {
1051 pc = idetape_next_pc_storage(drive); 866 pc = &tape->queued_pc;
1052 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6); 867 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
1053 goto out; 868 goto out;
1054 } 869 }
@@ -1235,77 +1050,30 @@ static void idetape_init_merge_buffer(idetape_tape_t *tape)
1235static void idetape_create_write_filemark_cmd(ide_drive_t *drive, 1050static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1236 struct ide_atapi_pc *pc, int write_filemark) 1051 struct ide_atapi_pc *pc, int write_filemark)
1237{ 1052{
1238 idetape_init_pc(pc); 1053 ide_init_pc(pc);
1239 pc->c[0] = WRITE_FILEMARKS; 1054 pc->c[0] = WRITE_FILEMARKS;
1240 pc->c[4] = write_filemark; 1055 pc->c[4] = write_filemark;
1241 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1056 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1242} 1057}
1243 1058
1244static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
1245{
1246 idetape_init_pc(pc);
1247 pc->c[0] = TEST_UNIT_READY;
1248}
1249
1250/*
1251 * We add a special packet command request to the tail of the request queue, and
1252 * wait for it to be serviced. This is not to be called from within the request
1253 * handling part of the driver! We allocate here data on the stack and it is
1254 * valid until the request is finished. This is not the case for the bottom part
1255 * of the driver, where we are always leaving the functions to wait for an
1256 * interrupt or a timer event.
1257 *
1258 * From the bottom part of the driver, we should allocate safe memory using
1259 * idetape_next_pc_storage() and ide_tape_next_rq_storage(), and add the request
1260 * to the request list without waiting for it to be serviced! In that case, we
1261 * usually use idetape_queue_pc_head().
1262 */
1263static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
1264{
1265 struct ide_tape_obj *tape = drive->driver_data;
1266 struct request *rq;
1267 int error;
1268
1269 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1270 rq->cmd_type = REQ_TYPE_SPECIAL;
1271 rq->cmd[13] = REQ_IDETAPE_PC1;
1272 rq->buffer = (char *)pc;
1273 memcpy(rq->cmd, pc->c, 12);
1274 error = blk_execute_rq(drive->queue, tape->disk, rq, 0);
1275 blk_put_request(rq);
1276 return error;
1277}
1278
1279static void idetape_create_load_unload_cmd(ide_drive_t *drive,
1280 struct ide_atapi_pc *pc, int cmd)
1281{
1282 idetape_init_pc(pc);
1283 pc->c[0] = START_STOP;
1284 pc->c[4] = cmd;
1285 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1286}
1287
1288static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) 1059static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
1289{ 1060{
1290 idetape_tape_t *tape = drive->driver_data; 1061 idetape_tape_t *tape = drive->driver_data;
1291 struct ide_atapi_pc pc; 1062 struct gendisk *disk = tape->disk;
1292 int load_attempted = 0; 1063 int load_attempted = 0;
1293 1064
1294 /* Wait for the tape to become ready */ 1065 /* Wait for the tape to become ready */
1295 set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags); 1066 set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
1296 timeout += jiffies; 1067 timeout += jiffies;
1297 while (time_before(jiffies, timeout)) { 1068 while (time_before(jiffies, timeout)) {
1298 idetape_create_test_unit_ready_cmd(&pc); 1069 if (ide_do_test_unit_ready(drive, disk) == 0)
1299 if (!idetape_queue_pc_tail(drive, &pc))
1300 return 0; 1070 return 0;
1301 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) 1071 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
1302 || (tape->asc == 0x3A)) { 1072 || (tape->asc == 0x3A)) {
1303 /* no media */ 1073 /* no media */
1304 if (load_attempted) 1074 if (load_attempted)
1305 return -ENOMEDIUM; 1075 return -ENOMEDIUM;
1306 idetape_create_load_unload_cmd(drive, &pc, 1076 ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
1307 IDETAPE_LU_LOAD_MASK);
1308 idetape_queue_pc_tail(drive, &pc);
1309 load_attempted = 1; 1077 load_attempted = 1;
1310 /* not about to be ready */ 1078 /* not about to be ready */
1311 } else if (!(tape->sense_key == 2 && tape->asc == 4 && 1079 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
@@ -1318,11 +1086,12 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
1318 1086
1319static int idetape_flush_tape_buffers(ide_drive_t *drive) 1087static int idetape_flush_tape_buffers(ide_drive_t *drive)
1320{ 1088{
1089 struct ide_tape_obj *tape = drive->driver_data;
1321 struct ide_atapi_pc pc; 1090 struct ide_atapi_pc pc;
1322 int rc; 1091 int rc;
1323 1092
1324 idetape_create_write_filemark_cmd(drive, &pc, 0); 1093 idetape_create_write_filemark_cmd(drive, &pc, 0);
1325 rc = idetape_queue_pc_tail(drive, &pc); 1094 rc = ide_queue_pc_tail(drive, tape->disk, &pc);
1326 if (rc) 1095 if (rc)
1327 return rc; 1096 return rc;
1328 idetape_wait_ready(drive, 60 * 5 * HZ); 1097 idetape_wait_ready(drive, 60 * 5 * HZ);
@@ -1331,7 +1100,7 @@ static int idetape_flush_tape_buffers(ide_drive_t *drive)
1331 1100
1332static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc) 1101static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
1333{ 1102{
1334 idetape_init_pc(pc); 1103 ide_init_pc(pc);
1335 pc->c[0] = READ_POSITION; 1104 pc->c[0] = READ_POSITION;
1336 pc->req_xfer = 20; 1105 pc->req_xfer = 20;
1337} 1106}
@@ -1345,7 +1114,7 @@ static int idetape_read_position(ide_drive_t *drive)
1345 debug_log(DBG_PROCS, "Enter %s\n", __func__); 1114 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1346 1115
1347 idetape_create_read_position_cmd(&pc); 1116 idetape_create_read_position_cmd(&pc);
1348 if (idetape_queue_pc_tail(drive, &pc)) 1117 if (ide_queue_pc_tail(drive, tape->disk, &pc))
1349 return -1; 1118 return -1;
1350 position = tape->first_frame; 1119 position = tape->first_frame;
1351 return position; 1120 return position;
@@ -1355,7 +1124,7 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1355 struct ide_atapi_pc *pc, 1124 struct ide_atapi_pc *pc,
1356 unsigned int block, u8 partition, int skip) 1125 unsigned int block, u8 partition, int skip)
1357{ 1126{
1358 idetape_init_pc(pc); 1127 ide_init_pc(pc);
1359 pc->c[0] = POSITION_TO_ELEMENT; 1128 pc->c[0] = POSITION_TO_ELEMENT;
1360 pc->c[1] = 2; 1129 pc->c[1] = 2;
1361 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); 1130 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
@@ -1363,21 +1132,6 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1363 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1132 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1364} 1133}
1365 1134
1366static int idetape_create_prevent_cmd(ide_drive_t *drive,
1367 struct ide_atapi_pc *pc, int prevent)
1368{
1369 idetape_tape_t *tape = drive->driver_data;
1370
1371 /* device supports locking according to capabilities page */
1372 if (!(tape->caps[6] & 0x01))
1373 return 0;
1374
1375 idetape_init_pc(pc);
1376 pc->c[0] = ALLOW_MEDIUM_REMOVAL;
1377 pc->c[4] = prevent;
1378 return 1;
1379}
1380
1381static void __ide_tape_discard_merge_buffer(ide_drive_t *drive) 1135static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1382{ 1136{
1383 idetape_tape_t *tape = drive->driver_data; 1137 idetape_tape_t *tape = drive->driver_data;
@@ -1405,6 +1159,7 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
1405 u8 partition, int skip) 1159 u8 partition, int skip)
1406{ 1160{
1407 idetape_tape_t *tape = drive->driver_data; 1161 idetape_tape_t *tape = drive->driver_data;
1162 struct gendisk *disk = tape->disk;
1408 int retval; 1163 int retval;
1409 struct ide_atapi_pc pc; 1164 struct ide_atapi_pc pc;
1410 1165
@@ -1412,12 +1167,12 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
1412 __ide_tape_discard_merge_buffer(drive); 1167 __ide_tape_discard_merge_buffer(drive);
1413 idetape_wait_ready(drive, 60 * 5 * HZ); 1168 idetape_wait_ready(drive, 60 * 5 * HZ);
1414 idetape_create_locate_cmd(drive, &pc, block, partition, skip); 1169 idetape_create_locate_cmd(drive, &pc, block, partition, skip);
1415 retval = idetape_queue_pc_tail(drive, &pc); 1170 retval = ide_queue_pc_tail(drive, disk, &pc);
1416 if (retval) 1171 if (retval)
1417 return (retval); 1172 return (retval);
1418 1173
1419 idetape_create_read_position_cmd(&pc); 1174 idetape_create_read_position_cmd(&pc);
1420 return (idetape_queue_pc_tail(drive, &pc)); 1175 return ide_queue_pc_tail(drive, disk, &pc);
1421} 1176}
1422 1177
1423static void ide_tape_discard_merge_buffer(ide_drive_t *drive, 1178static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
@@ -1477,7 +1232,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1477 1232
1478static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) 1233static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1479{ 1234{
1480 idetape_init_pc(pc); 1235 ide_init_pc(pc);
1481 pc->c[0] = INQUIRY; 1236 pc->c[0] = INQUIRY;
1482 pc->c[4] = 254; 1237 pc->c[4] = 254;
1483 pc->req_xfer = 254; 1238 pc->req_xfer = 254;
@@ -1486,14 +1241,14 @@ static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1486static void idetape_create_rewind_cmd(ide_drive_t *drive, 1241static void idetape_create_rewind_cmd(ide_drive_t *drive,
1487 struct ide_atapi_pc *pc) 1242 struct ide_atapi_pc *pc)
1488{ 1243{
1489 idetape_init_pc(pc); 1244 ide_init_pc(pc);
1490 pc->c[0] = REZERO_UNIT; 1245 pc->c[0] = REZERO_UNIT;
1491 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1246 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1492} 1247}
1493 1248
1494static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) 1249static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1495{ 1250{
1496 idetape_init_pc(pc); 1251 ide_init_pc(pc);
1497 pc->c[0] = ERASE; 1252 pc->c[0] = ERASE;
1498 pc->c[1] = 1; 1253 pc->c[1] = 1;
1499 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1254 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
@@ -1501,7 +1256,7 @@ static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1501 1256
1502static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) 1257static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1503{ 1258{
1504 idetape_init_pc(pc); 1259 ide_init_pc(pc);
1505 pc->c[0] = SPACE; 1260 pc->c[0] = SPACE;
1506 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); 1261 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1507 pc->c[1] = cmd; 1262 pc->c[1] = cmd;
@@ -1600,7 +1355,7 @@ static int idetape_init_read(ide_drive_t *drive)
1600 * No point in issuing this if DSC overlap isn't supported, some 1355 * No point in issuing this if DSC overlap isn't supported, some
1601 * drives (Seagate STT3401A) will return an error. 1356 * drives (Seagate STT3401A) will return an error.
1602 */ 1357 */
1603 if (drive->dsc_overlap) { 1358 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1604 bytes_read = idetape_queue_rw_tail(drive, 1359 bytes_read = idetape_queue_rw_tail(drive,
1605 REQ_IDETAPE_READ, 0, 1360 REQ_IDETAPE_READ, 0,
1606 tape->merge_bh); 1361 tape->merge_bh);
@@ -1664,20 +1419,20 @@ static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
1664 */ 1419 */
1665static int idetape_rewind_tape(ide_drive_t *drive) 1420static int idetape_rewind_tape(ide_drive_t *drive)
1666{ 1421{
1422 struct ide_tape_obj *tape = drive->driver_data;
1423 struct gendisk *disk = tape->disk;
1667 int retval; 1424 int retval;
1668 struct ide_atapi_pc pc; 1425 struct ide_atapi_pc pc;
1669 idetape_tape_t *tape;
1670 tape = drive->driver_data;
1671 1426
1672 debug_log(DBG_SENSE, "Enter %s\n", __func__); 1427 debug_log(DBG_SENSE, "Enter %s\n", __func__);
1673 1428
1674 idetape_create_rewind_cmd(drive, &pc); 1429 idetape_create_rewind_cmd(drive, &pc);
1675 retval = idetape_queue_pc_tail(drive, &pc); 1430 retval = ide_queue_pc_tail(drive, disk, &pc);
1676 if (retval) 1431 if (retval)
1677 return retval; 1432 return retval;
1678 1433
1679 idetape_create_read_position_cmd(&pc); 1434 idetape_create_read_position_cmd(&pc);
1680 retval = idetape_queue_pc_tail(drive, &pc); 1435 retval = ide_queue_pc_tail(drive, disk, &pc);
1681 if (retval) 1436 if (retval)
1682 return retval; 1437 return retval;
1683 return 0; 1438 return 0;
@@ -1720,6 +1475,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1720 int mt_count) 1475 int mt_count)
1721{ 1476{
1722 idetape_tape_t *tape = drive->driver_data; 1477 idetape_tape_t *tape = drive->driver_data;
1478 struct gendisk *disk = tape->disk;
1723 struct ide_atapi_pc pc; 1479 struct ide_atapi_pc pc;
1724 int retval, count = 0; 1480 int retval, count = 0;
1725 int sprev = !!(tape->caps[4] & 0x20); 1481 int sprev = !!(tape->caps[4] & 0x20);
@@ -1744,7 +1500,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1744 case MTBSF: 1500 case MTBSF:
1745 idetape_create_space_cmd(&pc, mt_count - count, 1501 idetape_create_space_cmd(&pc, mt_count - count,
1746 IDETAPE_SPACE_OVER_FILEMARK); 1502 IDETAPE_SPACE_OVER_FILEMARK);
1747 return idetape_queue_pc_tail(drive, &pc); 1503 return ide_queue_pc_tail(drive, disk, &pc);
1748 case MTFSFM: 1504 case MTFSFM:
1749 case MTBSFM: 1505 case MTBSFM:
1750 if (!sprev) 1506 if (!sprev)
@@ -1780,7 +1536,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1780static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, 1536static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1781 size_t count, loff_t *ppos) 1537 size_t count, loff_t *ppos)
1782{ 1538{
1783 struct ide_tape_obj *tape = ide_tape_f(file); 1539 struct ide_tape_obj *tape = file->private_data;
1784 ide_drive_t *drive = tape->drive; 1540 ide_drive_t *drive = tape->drive;
1785 ssize_t bytes_read, temp, actually_read = 0, rc; 1541 ssize_t bytes_read, temp, actually_read = 0, rc;
1786 ssize_t ret = 0; 1542 ssize_t ret = 0;
@@ -1842,7 +1598,7 @@ finish:
1842static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, 1598static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1843 size_t count, loff_t *ppos) 1599 size_t count, loff_t *ppos)
1844{ 1600{
1845 struct ide_tape_obj *tape = ide_tape_f(file); 1601 struct ide_tape_obj *tape = file->private_data;
1846 ide_drive_t *drive = tape->drive; 1602 ide_drive_t *drive = tape->drive;
1847 ssize_t actually_written = 0; 1603 ssize_t actually_written = 0;
1848 ssize_t ret = 0; 1604 ssize_t ret = 0;
@@ -1875,7 +1631,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1875 * point in issuing this if DSC overlap isn't supported, some 1631 * point in issuing this if DSC overlap isn't supported, some
1876 * drives (Seagate STT3401A) will return an error. 1632 * drives (Seagate STT3401A) will return an error.
1877 */ 1633 */
1878 if (drive->dsc_overlap) { 1634 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1879 ssize_t retval = idetape_queue_rw_tail(drive, 1635 ssize_t retval = idetape_queue_rw_tail(drive,
1880 REQ_IDETAPE_WRITE, 0, 1636 REQ_IDETAPE_WRITE, 0,
1881 tape->merge_bh); 1637 tape->merge_bh);
@@ -1933,11 +1689,12 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1933 1689
1934static int idetape_write_filemark(ide_drive_t *drive) 1690static int idetape_write_filemark(ide_drive_t *drive)
1935{ 1691{
1692 struct ide_tape_obj *tape = drive->driver_data;
1936 struct ide_atapi_pc pc; 1693 struct ide_atapi_pc pc;
1937 1694
1938 /* Write a filemark */ 1695 /* Write a filemark */
1939 idetape_create_write_filemark_cmd(drive, &pc, 1); 1696 idetape_create_write_filemark_cmd(drive, &pc, 1);
1940 if (idetape_queue_pc_tail(drive, &pc)) { 1697 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1941 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); 1698 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
1942 return -EIO; 1699 return -EIO;
1943 } 1700 }
@@ -1960,6 +1717,7 @@ static int idetape_write_filemark(ide_drive_t *drive)
1960static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) 1717static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1961{ 1718{
1962 idetape_tape_t *tape = drive->driver_data; 1719 idetape_tape_t *tape = drive->driver_data;
1720 struct gendisk *disk = tape->disk;
1963 struct ide_atapi_pc pc; 1721 struct ide_atapi_pc pc;
1964 int i, retval; 1722 int i, retval;
1965 1723
@@ -1996,9 +1754,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1996 return 0; 1754 return 0;
1997 case MTLOAD: 1755 case MTLOAD:
1998 ide_tape_discard_merge_buffer(drive, 0); 1756 ide_tape_discard_merge_buffer(drive, 0);
1999 idetape_create_load_unload_cmd(drive, &pc, 1757 return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
2000 IDETAPE_LU_LOAD_MASK);
2001 return idetape_queue_pc_tail(drive, &pc);
2002 case MTUNLOAD: 1758 case MTUNLOAD:
2003 case MTOFFL: 1759 case MTOFFL:
2004 /* 1760 /*
@@ -2006,14 +1762,11 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2006 * attempting to eject. 1762 * attempting to eject.
2007 */ 1763 */
2008 if (tape->door_locked) { 1764 if (tape->door_locked) {
2009 if (idetape_create_prevent_cmd(drive, &pc, 0)) 1765 if (!ide_set_media_lock(drive, disk, 0))
2010 if (!idetape_queue_pc_tail(drive, &pc)) 1766 tape->door_locked = DOOR_UNLOCKED;
2011 tape->door_locked = DOOR_UNLOCKED;
2012 } 1767 }
2013 ide_tape_discard_merge_buffer(drive, 0); 1768 ide_tape_discard_merge_buffer(drive, 0);
2014 idetape_create_load_unload_cmd(drive, &pc, 1769 retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK);
2015 !IDETAPE_LU_LOAD_MASK);
2016 retval = idetape_queue_pc_tail(drive, &pc);
2017 if (!retval) 1770 if (!retval)
2018 clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags); 1771 clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
2019 return retval; 1772 return retval;
@@ -2022,16 +1775,15 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2022 return idetape_flush_tape_buffers(drive); 1775 return idetape_flush_tape_buffers(drive);
2023 case MTRETEN: 1776 case MTRETEN:
2024 ide_tape_discard_merge_buffer(drive, 0); 1777 ide_tape_discard_merge_buffer(drive, 0);
2025 idetape_create_load_unload_cmd(drive, &pc, 1778 return ide_do_start_stop(drive, disk,
2026 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); 1779 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
2027 return idetape_queue_pc_tail(drive, &pc);
2028 case MTEOM: 1780 case MTEOM:
2029 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); 1781 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
2030 return idetape_queue_pc_tail(drive, &pc); 1782 return ide_queue_pc_tail(drive, disk, &pc);
2031 case MTERASE: 1783 case MTERASE:
2032 (void)idetape_rewind_tape(drive); 1784 (void)idetape_rewind_tape(drive);
2033 idetape_create_erase_cmd(&pc); 1785 idetape_create_erase_cmd(&pc);
2034 return idetape_queue_pc_tail(drive, &pc); 1786 return ide_queue_pc_tail(drive, disk, &pc);
2035 case MTSETBLK: 1787 case MTSETBLK:
2036 if (mt_count) { 1788 if (mt_count) {
2037 if (mt_count < tape->blk_size || 1789 if (mt_count < tape->blk_size ||
@@ -2052,17 +1804,13 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2052 case MTFSR: 1804 case MTFSR:
2053 case MTBSR: 1805 case MTBSR:
2054 case MTLOCK: 1806 case MTLOCK:
2055 if (!idetape_create_prevent_cmd(drive, &pc, 1)) 1807 retval = ide_set_media_lock(drive, disk, 1);
2056 return 0;
2057 retval = idetape_queue_pc_tail(drive, &pc);
2058 if (retval) 1808 if (retval)
2059 return retval; 1809 return retval;
2060 tape->door_locked = DOOR_EXPLICITLY_LOCKED; 1810 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
2061 return 0; 1811 return 0;
2062 case MTUNLOCK: 1812 case MTUNLOCK:
2063 if (!idetape_create_prevent_cmd(drive, &pc, 0)) 1813 retval = ide_set_media_lock(drive, disk, 0);
2064 return 0;
2065 retval = idetape_queue_pc_tail(drive, &pc);
2066 if (retval) 1814 if (retval)
2067 return retval; 1815 return retval;
2068 tape->door_locked = DOOR_UNLOCKED; 1816 tape->door_locked = DOOR_UNLOCKED;
@@ -2082,7 +1830,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2082static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, 1830static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
2083 unsigned int cmd, unsigned long arg) 1831 unsigned int cmd, unsigned long arg)
2084{ 1832{
2085 struct ide_tape_obj *tape = ide_tape_f(file); 1833 struct ide_tape_obj *tape = file->private_data;
2086 ide_drive_t *drive = tape->drive; 1834 ide_drive_t *drive = tape->drive;
2087 struct mtop mtop; 1835 struct mtop mtop;
2088 struct mtget mtget; 1836 struct mtget mtget;
@@ -2144,7 +1892,7 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
2144 struct ide_atapi_pc pc; 1892 struct ide_atapi_pc pc;
2145 1893
2146 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); 1894 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
2147 if (idetape_queue_pc_tail(drive, &pc)) { 1895 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2148 printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); 1896 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
2149 if (tape->blk_size == 0) { 1897 if (tape->blk_size == 0) {
2150 printk(KERN_WARNING "ide-tape: Cannot deal with zero " 1898 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
@@ -2164,7 +1912,6 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2164 unsigned int minor = iminor(inode), i = minor & ~0xc0; 1912 unsigned int minor = iminor(inode), i = minor & ~0xc0;
2165 ide_drive_t *drive; 1913 ide_drive_t *drive;
2166 idetape_tape_t *tape; 1914 idetape_tape_t *tape;
2167 struct ide_atapi_pc pc;
2168 int retval; 1915 int retval;
2169 1916
2170 if (i >= MAX_HWIFS * MAX_DRIVES) 1917 if (i >= MAX_HWIFS * MAX_DRIVES)
@@ -2227,11 +1974,9 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2227 1974
2228 /* Lock the tape drive door so user can't eject. */ 1975 /* Lock the tape drive door so user can't eject. */
2229 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 1976 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2230 if (idetape_create_prevent_cmd(drive, &pc, 1)) { 1977 if (!ide_set_media_lock(drive, tape->disk, 1)) {
2231 if (!idetape_queue_pc_tail(drive, &pc)) { 1978 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
2232 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) 1979 tape->door_locked = DOOR_LOCKED;
2233 tape->door_locked = DOOR_LOCKED;
2234 }
2235 } 1980 }
2236 } 1981 }
2237 unlock_kernel(); 1982 unlock_kernel();
@@ -2262,9 +2007,8 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
2262 2007
2263static int idetape_chrdev_release(struct inode *inode, struct file *filp) 2008static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2264{ 2009{
2265 struct ide_tape_obj *tape = ide_tape_f(filp); 2010 struct ide_tape_obj *tape = filp->private_data;
2266 ide_drive_t *drive = tape->drive; 2011 ide_drive_t *drive = tape->drive;
2267 struct ide_atapi_pc pc;
2268 unsigned int minor = iminor(inode); 2012 unsigned int minor = iminor(inode);
2269 2013
2270 lock_kernel(); 2014 lock_kernel();
@@ -2283,10 +2027,8 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2283 (void) idetape_rewind_tape(drive); 2027 (void) idetape_rewind_tape(drive);
2284 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 2028 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2285 if (tape->door_locked == DOOR_LOCKED) { 2029 if (tape->door_locked == DOOR_LOCKED) {
2286 if (idetape_create_prevent_cmd(drive, &pc, 0)) { 2030 if (!ide_set_media_lock(drive, tape->disk, 0))
2287 if (!idetape_queue_pc_tail(drive, &pc)) 2031 tape->door_locked = DOOR_UNLOCKED;
2288 tape->door_locked = DOOR_UNLOCKED;
2289 }
2290 } 2032 }
2291 } 2033 }
2292 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags); 2034 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
@@ -2295,45 +2037,6 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2295 return 0; 2037 return 0;
2296} 2038}
2297 2039
2298/*
2299 * check the contents of the ATAPI IDENTIFY command results. We return:
2300 *
2301 * 1 - If the tape can be supported by us, based on the information we have so
2302 * far.
2303 *
2304 * 0 - If this tape driver is not currently supported by us.
2305 */
2306static int idetape_identify_device(ide_drive_t *drive)
2307{
2308 u8 gcw[2], protocol, device_type, removable, packet_size;
2309
2310 if (drive->id_read == 0)
2311 return 1;
2312
2313 *((unsigned short *) &gcw) = drive->id->config;
2314
2315 protocol = (gcw[1] & 0xC0) >> 6;
2316 device_type = gcw[1] & 0x1F;
2317 removable = !!(gcw[0] & 0x80);
2318 packet_size = gcw[0] & 0x3;
2319
2320 /* Check that we can support this device */
2321 if (protocol != 2)
2322 printk(KERN_ERR "ide-tape: Protocol (0x%02x) is not ATAPI\n",
2323 protocol);
2324 else if (device_type != 1)
2325 printk(KERN_ERR "ide-tape: Device type (0x%02x) is not set "
2326 "to tape\n", device_type);
2327 else if (!removable)
2328 printk(KERN_ERR "ide-tape: The removable flag is not set\n");
2329 else if (packet_size != 0) {
2330 printk(KERN_ERR "ide-tape: Packet size (0x%02x) is not 12"
2331 " bytes\n", packet_size);
2332 } else
2333 return 1;
2334 return 0;
2335}
2336
2337static void idetape_get_inquiry_results(ide_drive_t *drive) 2040static void idetape_get_inquiry_results(ide_drive_t *drive)
2338{ 2041{
2339 idetape_tape_t *tape = drive->driver_data; 2042 idetape_tape_t *tape = drive->driver_data;
@@ -2341,7 +2044,7 @@ static void idetape_get_inquiry_results(ide_drive_t *drive)
2341 char fw_rev[4], vendor_id[8], product_id[16]; 2044 char fw_rev[4], vendor_id[8], product_id[16];
2342 2045
2343 idetape_create_inquiry_cmd(&pc); 2046 idetape_create_inquiry_cmd(&pc);
2344 if (idetape_queue_pc_tail(drive, &pc)) { 2047 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2345 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", 2048 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
2346 tape->name); 2049 tape->name);
2347 return; 2050 return;
@@ -2370,7 +2073,7 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2370 u8 speed, max_speed; 2073 u8 speed, max_speed;
2371 2074
2372 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); 2075 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
2373 if (idetape_queue_pc_tail(drive, &pc)) { 2076 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2374 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" 2077 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
2375 " some default values\n"); 2078 " some default values\n");
2376 tape->blk_size = 512; 2079 tape->blk_size = 512;
@@ -2402,6 +2105,11 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2402 } 2105 }
2403 2106
2404 memcpy(&tape->caps, caps, 20); 2107 memcpy(&tape->caps, caps, 20);
2108
2109 /* device lacks locking support according to capabilities page */
2110 if ((caps[6] & 1) == 0)
2111 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
2112
2405 if (caps[7] & 0x02) 2113 if (caps[7] & 0x02)
2406 tape->blk_size = 512; 2114 tape->blk_size = 512;
2407 else if (caps[7] & 0x04) 2115 else if (caps[7] & 0x04)
@@ -2409,28 +2117,56 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2409} 2117}
2410 2118
2411#ifdef CONFIG_IDE_PROC_FS 2119#ifdef CONFIG_IDE_PROC_FS
2412static void idetape_add_settings(ide_drive_t *drive) 2120#define ide_tape_devset_get(name, field) \
2413{ 2121static int get_##name(ide_drive_t *drive) \
2414 idetape_tape_t *tape = drive->driver_data; 2122{ \
2415 2123 idetape_tape_t *tape = drive->driver_data; \
2416 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 2124 return tape->field; \
2417 1, 2, (u16 *)&tape->caps[16], NULL); 2125}
2418 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 2126
2419 1, 1, (u16 *)&tape->caps[14], NULL); 2127#define ide_tape_devset_set(name, field) \
2420 ide_add_setting(drive, "buffer_size", SETTING_READ, TYPE_INT, 0, 0xffff, 2128static int set_##name(ide_drive_t *drive, int arg) \
2421 1, 1024, &tape->buffer_size, NULL); 2129{ \
2422 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, 2130 idetape_tape_t *tape = drive->driver_data; \
2423 IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq, 2131 tape->field = arg; \
2424 NULL); 2132 return 0; \
2425 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 2133}
2426 1, &drive->dsc_overlap, NULL); 2134
2427 ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, 2135#define ide_tape_devset_rw_field(_name, _field) \
2428 1, 1, &tape->avg_speed, NULL); 2136ide_tape_devset_get(_name, _field) \
2429 ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1, 2137ide_tape_devset_set(_name, _field) \
2430 1, &tape->debug_mask, NULL); 2138IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
2431} 2139
2432#else 2140#define ide_tape_devset_r_field(_name, _field) \
2433static inline void idetape_add_settings(ide_drive_t *drive) { ; } 2141ide_tape_devset_get(_name, _field) \
2142IDE_DEVSET(_name, 0, get_##_name, NULL)
2143
2144static int mulf_tdsc(ide_drive_t *drive) { return 1000; }
2145static int divf_tdsc(ide_drive_t *drive) { return HZ; }
2146static int divf_buffer(ide_drive_t *drive) { return 2; }
2147static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
2148
2149ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
2150
2151ide_tape_devset_rw_field(debug_mask, debug_mask);
2152ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
2153
2154ide_tape_devset_r_field(avg_speed, avg_speed);
2155ide_tape_devset_r_field(speed, caps[14]);
2156ide_tape_devset_r_field(buffer, caps[16]);
2157ide_tape_devset_r_field(buffer_size, buffer_size);
2158
2159static const struct ide_proc_devset idetape_settings[] = {
2160 __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL),
2161 __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer),
2162 __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size),
2163 __IDE_PROC_DEVSET(debug_mask, 0, 0xffff, NULL, NULL),
2164 __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL),
2165 __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL),
2166 __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
2167 mulf_tdsc, divf_tdsc),
2168 { 0 },
2169};
2434#endif 2170#endif
2435 2171
2436/* 2172/*
@@ -2449,32 +2185,31 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2449 unsigned long t; 2185 unsigned long t;
2450 int speed; 2186 int speed;
2451 int buffer_size; 2187 int buffer_size;
2452 u8 gcw[2];
2453 u16 *ctl = (u16 *)&tape->caps[12]; 2188 u16 *ctl = (u16 *)&tape->caps[12];
2454 2189
2455 drive->pc_callback = ide_tape_callback; 2190 drive->pc_callback = ide_tape_callback;
2191 drive->pc_update_buffers = idetape_update_buffers;
2192 drive->pc_io_buffers = ide_tape_io_buffers;
2456 2193
2457 spin_lock_init(&tape->lock); 2194 spin_lock_init(&tape->lock);
2458 drive->dsc_overlap = 1; 2195
2196 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2197
2459 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { 2198 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
2460 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", 2199 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
2461 tape->name); 2200 tape->name);
2462 drive->dsc_overlap = 0; 2201 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2463 } 2202 }
2203
2464 /* Seagate Travan drives do not support DSC overlap. */ 2204 /* Seagate Travan drives do not support DSC overlap. */
2465 if (strstr(drive->id->model, "Seagate STT3401")) 2205 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
2466 drive->dsc_overlap = 0; 2206 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2207
2467 tape->minor = minor; 2208 tape->minor = minor;
2468 tape->name[0] = 'h'; 2209 tape->name[0] = 'h';
2469 tape->name[1] = 't'; 2210 tape->name[1] = 't';
2470 tape->name[2] = '0' + minor; 2211 tape->name[2] = '0' + minor;
2471 tape->chrdev_dir = IDETAPE_DIR_NONE; 2212 tape->chrdev_dir = IDETAPE_DIR_NONE;
2472 tape->pc = tape->pc_stack;
2473 *((unsigned short *) &gcw) = drive->id->config;
2474
2475 /* Command packet DRQ type */
2476 if (((gcw[0] & 0x60) >> 5) == 1)
2477 set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
2478 2213
2479 idetape_get_inquiry_results(drive); 2214 idetape_get_inquiry_results(drive);
2480 idetape_get_mode_sense_results(drive); 2215 idetape_get_mode_sense_results(drive);
@@ -2510,9 +2245,9 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2510 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, 2245 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
2511 tape->buffer_size / 1024, 2246 tape->buffer_size / 1024,
2512 tape->best_dsc_rw_freq * 1000 / HZ, 2247 tape->best_dsc_rw_freq * 1000 / HZ,
2513 drive->using_dma ? ", DMA":""); 2248 (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
2514 2249
2515 idetape_add_settings(drive); 2250 ide_proc_register_driver(drive, tape->driver);
2516} 2251}
2517 2252
2518static void ide_tape_remove(ide_drive_t *drive) 2253static void ide_tape_remove(ide_drive_t *drive)
@@ -2528,13 +2263,13 @@ static void ide_tape_remove(ide_drive_t *drive)
2528 2263
2529static void ide_tape_release(struct kref *kref) 2264static void ide_tape_release(struct kref *kref)
2530{ 2265{
2531 struct ide_tape_obj *tape = to_ide_tape(kref); 2266 struct ide_tape_obj *tape = to_ide_drv(kref, ide_tape_obj);
2532 ide_drive_t *drive = tape->drive; 2267 ide_drive_t *drive = tape->drive;
2533 struct gendisk *g = tape->disk; 2268 struct gendisk *g = tape->disk;
2534 2269
2535 BUG_ON(tape->merge_bh_size); 2270 BUG_ON(tape->merge_bh_size);
2536 2271
2537 drive->dsc_overlap = 0; 2272 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2538 drive->driver_data = NULL; 2273 drive->driver_data = NULL;
2539 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); 2274 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
2540 device_destroy(idetape_sysfs_class, 2275 device_destroy(idetape_sysfs_class,
@@ -2563,6 +2298,16 @@ static ide_proc_entry_t idetape_proc[] = {
2563 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, 2298 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL },
2564 { NULL, 0, NULL, NULL } 2299 { NULL, 0, NULL, NULL }
2565}; 2300};
2301
2302static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
2303{
2304 return idetape_proc;
2305}
2306
2307static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive)
2308{
2309 return idetape_settings;
2310}
2566#endif 2311#endif
2567 2312
2568static int ide_tape_probe(ide_drive_t *); 2313static int ide_tape_probe(ide_drive_t *);
@@ -2576,13 +2321,12 @@ static ide_driver_t idetape_driver = {
2576 .probe = ide_tape_probe, 2321 .probe = ide_tape_probe,
2577 .remove = ide_tape_remove, 2322 .remove = ide_tape_remove,
2578 .version = IDETAPE_VERSION, 2323 .version = IDETAPE_VERSION,
2579 .media = ide_tape,
2580 .supports_dsc_overlap = 1,
2581 .do_request = idetape_do_request, 2324 .do_request = idetape_do_request,
2582 .end_request = idetape_end_request, 2325 .end_request = idetape_end_request,
2583 .error = __ide_error, 2326 .error = __ide_error,
2584#ifdef CONFIG_IDE_PROC_FS 2327#ifdef CONFIG_IDE_PROC_FS
2585 .proc = idetape_proc, 2328 .proc_entries = ide_tape_proc_entries,
2329 .proc_devsets = ide_tape_proc_devsets,
2586#endif 2330#endif
2587}; 2331};
2588 2332
@@ -2596,35 +2340,30 @@ static const struct file_operations idetape_fops = {
2596 .release = idetape_chrdev_release, 2340 .release = idetape_chrdev_release,
2597}; 2341};
2598 2342
2599static int idetape_open(struct inode *inode, struct file *filp) 2343static int idetape_open(struct block_device *bdev, fmode_t mode)
2600{ 2344{
2601 struct gendisk *disk = inode->i_bdev->bd_disk; 2345 struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk);
2602 struct ide_tape_obj *tape;
2603 2346
2604 tape = ide_tape_get(disk);
2605 if (!tape) 2347 if (!tape)
2606 return -ENXIO; 2348 return -ENXIO;
2607 2349
2608 return 0; 2350 return 0;
2609} 2351}
2610 2352
2611static int idetape_release(struct inode *inode, struct file *filp) 2353static int idetape_release(struct gendisk *disk, fmode_t mode)
2612{ 2354{
2613 struct gendisk *disk = inode->i_bdev->bd_disk; 2355 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
2614 struct ide_tape_obj *tape = ide_tape_g(disk);
2615 2356
2616 ide_tape_put(tape); 2357 ide_tape_put(tape);
2617
2618 return 0; 2358 return 0;
2619} 2359}
2620 2360
2621static int idetape_ioctl(struct inode *inode, struct file *file, 2361static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
2622 unsigned int cmd, unsigned long arg) 2362 unsigned int cmd, unsigned long arg)
2623{ 2363{
2624 struct block_device *bdev = inode->i_bdev; 2364 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
2625 struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk);
2626 ide_drive_t *drive = tape->drive; 2365 ide_drive_t *drive = tape->drive;
2627 int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 2366 int err = generic_ide_ioctl(drive, bdev, cmd, arg);
2628 if (err == -EINVAL) 2367 if (err == -EINVAL)
2629 err = idetape_blkdev_ioctl(drive, cmd, arg); 2368 err = idetape_blkdev_ioctl(drive, cmd, arg);
2630 return err; 2369 return err;
@@ -2634,7 +2373,7 @@ static struct block_device_operations idetape_block_ops = {
2634 .owner = THIS_MODULE, 2373 .owner = THIS_MODULE,
2635 .open = idetape_open, 2374 .open = idetape_open,
2636 .release = idetape_release, 2375 .release = idetape_release,
2637 .ioctl = idetape_ioctl, 2376 .locked_ioctl = idetape_ioctl,
2638}; 2377};
2639 2378
2640static int ide_tape_probe(ide_drive_t *drive) 2379static int ide_tape_probe(ide_drive_t *drive)
@@ -2645,11 +2384,12 @@ static int ide_tape_probe(ide_drive_t *drive)
2645 2384
2646 if (!strstr("ide-tape", drive->driver_req)) 2385 if (!strstr("ide-tape", drive->driver_req))
2647 goto failed; 2386 goto failed;
2648 if (!drive->present) 2387
2649 goto failed;
2650 if (drive->media != ide_tape) 2388 if (drive->media != ide_tape)
2651 goto failed; 2389 goto failed;
2652 if (!idetape_identify_device(drive)) { 2390
2391 if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
2392 ide_check_atapi_device(drive, DRV_NAME) == 0) {
2653 printk(KERN_ERR "ide-tape: %s: not supported by this version of" 2393 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
2654 " the driver\n", drive->name); 2394 " the driver\n", drive->name);
2655 goto failed; 2395 goto failed;
@@ -2667,8 +2407,6 @@ static int ide_tape_probe(ide_drive_t *drive)
2667 2407
2668 ide_init_disk(g, drive); 2408 ide_init_disk(g, drive);
2669 2409
2670 ide_proc_register_driver(drive, &idetape_driver);
2671
2672 kref_init(&tape->kref); 2410 kref_init(&tape->kref);
2673 2411
2674 tape->drive = drive; 2412 tape->drive = drive;
@@ -2687,12 +2425,11 @@ static int ide_tape_probe(ide_drive_t *drive)
2687 2425
2688 idetape_setup(drive, tape, minor); 2426 idetape_setup(drive, tape, minor);
2689 2427
2690 device_create_drvdata(idetape_sysfs_class, &drive->gendev, 2428 device_create(idetape_sysfs_class, &drive->gendev,
2691 MKDEV(IDETAPE_MAJOR, minor), NULL, 2429 MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name);
2692 "%s", tape->name); 2430 device_create(idetape_sysfs_class, &drive->gendev,
2693 device_create_drvdata(idetape_sysfs_class, &drive->gendev, 2431 MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
2694 MKDEV(IDETAPE_MAJOR, minor + 128), NULL, 2432 "n%s", tape->name);
2695 "n%s", tape->name);
2696 2433
2697 g->fops = &idetape_block_ops; 2434 g->fops = &idetape_block_ops;
2698 ide_register_region(g); 2435 ide_register_region(g);
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 7fb6f1c86272..bf4fb9d8d176 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -44,18 +44,15 @@ int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
44 memset(&args, 0, sizeof(ide_task_t)); 44 memset(&args, 0, sizeof(ide_task_t));
45 args.tf.nsect = 0x01; 45 args.tf.nsect = 0x01;
46 if (drive->media == ide_disk) 46 if (drive->media == ide_disk)
47 args.tf.command = WIN_IDENTIFY; 47 args.tf.command = ATA_CMD_ID_ATA;
48 else 48 else
49 args.tf.command = WIN_PIDENTIFY; 49 args.tf.command = ATA_CMD_ID_ATAPI;
50 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 50 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
51 args.data_phase = TASKFILE_IN; 51 args.data_phase = TASKFILE_IN;
52 return ide_raw_taskfile(drive, &args, buf, 1); 52 return ide_raw_taskfile(drive, &args, buf, 1);
53} 53}
54 54
55static ide_startstop_t task_no_data_intr(ide_drive_t *); 55static ide_startstop_t task_no_data_intr(ide_drive_t *);
56static ide_startstop_t set_geometry_intr(ide_drive_t *);
57static ide_startstop_t recal_intr(ide_drive_t *);
58static ide_startstop_t set_multmode_intr(ide_drive_t *);
59static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *); 56static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
60static ide_startstop_t task_in_intr(ide_drive_t *); 57static ide_startstop_t task_in_intr(ide_drive_t *);
61 58
@@ -79,6 +76,8 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
79 if (task->tf_flags & IDE_TFLAG_FLAGGED) 76 if (task->tf_flags & IDE_TFLAG_FLAGGED)
80 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS; 77 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS;
81 78
79 memcpy(&hwif->task, task, sizeof(*task));
80
82 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) { 81 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
83 ide_tf_dump(drive->name, tf); 82 ide_tf_dump(drive->name, tf);
84 tp_ops->set_irq(hwif, 1); 83 tp_ops->set_irq(hwif, 1);
@@ -99,19 +98,12 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
99 case TASKFILE_NO_DATA: 98 case TASKFILE_NO_DATA:
100 if (handler == NULL) 99 if (handler == NULL)
101 handler = task_no_data_intr; 100 handler = task_no_data_intr;
102 /* WIN_{SPECIFY,RESTORE,SETMULT} use custom handlers */
103 if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) {
104 switch (tf->command) {
105 case WIN_SPECIFY: handler = set_geometry_intr; break;
106 case WIN_RESTORE: handler = recal_intr; break;
107 case WIN_SETMULT: handler = set_multmode_intr; break;
108 }
109 }
110 ide_execute_command(drive, tf->command, handler, 101 ide_execute_command(drive, tf->command, handler,
111 WAIT_WORSTCASE, NULL); 102 WAIT_WORSTCASE, NULL);
112 return ide_started; 103 return ide_started;
113 default: 104 default:
114 if (drive->using_dma == 0 || dma_ops->dma_setup(drive)) 105 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
106 dma_ops->dma_setup(drive))
115 return ide_stopped; 107 return ide_stopped;
116 dma_ops->dma_exec_cmd(drive, tf->command); 108 dma_ops->dma_exec_cmd(drive, tf->command);
117 dma_ops->dma_start(drive); 109 dma_ops->dma_start(drive);
@@ -121,88 +113,56 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
121EXPORT_SYMBOL_GPL(do_rw_taskfile); 113EXPORT_SYMBOL_GPL(do_rw_taskfile);
122 114
123/* 115/*
124 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd. 116 * Handler for commands without a data phase
125 */
126static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
127{
128 ide_hwif_t *hwif = drive->hwif;
129 u8 stat;
130
131 local_irq_enable_in_hardirq();
132 stat = hwif->tp_ops->read_status(hwif);
133
134 if (OK_STAT(stat, READY_STAT, BAD_STAT))
135 drive->mult_count = drive->mult_req;
136 else {
137 drive->mult_req = drive->mult_count = 0;
138 drive->special.b.recalibrate = 1;
139 (void) ide_dump_status(drive, "set_multmode", stat);
140 }
141 return ide_stopped;
142}
143
144/*
145 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
146 */ 117 */
147static ide_startstop_t set_geometry_intr(ide_drive_t *drive) 118static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
148{ 119{
149 ide_hwif_t *hwif = drive->hwif; 120 ide_hwif_t *hwif = drive->hwif;
150 int retries = 5; 121 ide_task_t *task = &hwif->task;
122 struct ide_taskfile *tf = &task->tf;
123 int custom = (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
124 int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
151 u8 stat; 125 u8 stat;
152 126
153 local_irq_enable_in_hardirq(); 127 local_irq_enable_in_hardirq();
154 128
155 while (1) { 129 while (1) {
156 stat = hwif->tp_ops->read_status(hwif); 130 stat = hwif->tp_ops->read_status(hwif);
157 if ((stat & BUSY_STAT) == 0 || retries-- == 0) 131 if ((stat & ATA_BUSY) == 0 || retries-- == 0)
158 break; 132 break;
159 udelay(10); 133 udelay(10);
160 }; 134 };
161 135
162 if (OK_STAT(stat, READY_STAT, BAD_STAT)) 136 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
163 return ide_stopped; 137 if (custom && tf->command == ATA_CMD_SET_MULTI) {
164 138 drive->mult_req = drive->mult_count = 0;
165 if (stat & (ERR_STAT|DRQ_STAT)) 139 drive->special.b.recalibrate = 1;
166 return ide_error(drive, "set_geometry_intr", stat); 140 (void)ide_dump_status(drive, __func__, stat);
167 141 return ide_stopped;
168 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); 142 } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
169 return ide_started; 143 if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
170} 144 ide_set_handler(drive, &task_no_data_intr,
171 145 WAIT_WORSTCASE, NULL);
172/* 146 return ide_started;
173 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd. 147 }
174 */ 148 }
175static ide_startstop_t recal_intr(ide_drive_t *drive)
176{
177 ide_hwif_t *hwif = drive->hwif;
178 u8 stat;
179
180 local_irq_enable_in_hardirq();
181 stat = hwif->tp_ops->read_status(hwif);
182
183 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
184 return ide_error(drive, "recal_intr", stat);
185 return ide_stopped;
186}
187
188/*
189 * Handler for commands without a data phase
190 */
191static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
192{
193 ide_hwif_t *hwif = drive->hwif;
194 ide_task_t *args = hwif->hwgroup->rq->special;
195 u8 stat;
196
197 local_irq_enable_in_hardirq();
198 stat = hwif->tp_ops->read_status(hwif);
199
200 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
201 return ide_error(drive, "task_no_data_intr", stat); 149 return ide_error(drive, "task_no_data_intr", stat);
202 /* calls ide_end_drive_cmd */ 150 /* calls ide_end_drive_cmd */
151 }
203 152
204 if (args) 153 if (!custom)
205 ide_end_drive_cmd(drive, stat, ide_read_error(drive)); 154 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
155 else if (tf->command == ATA_CMD_IDLEIMMEDIATE) {
156 hwif->tp_ops->tf_read(drive, task);
157 if (tf->lbal != 0xc4) {
158 printk(KERN_ERR "%s: head unload failed!\n",
159 drive->name);
160 ide_tf_dump(drive->name, tf);
161 } else
162 drive->dev_flags |= IDE_DFLAG_PARKED;
163 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
164 } else if (tf->command == ATA_CMD_SET_MULTI)
165 drive->mult_count = drive->mult_req;
206 166
207 return ide_stopped; 167 return ide_stopped;
208} 168}
@@ -220,13 +180,13 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
220 for (retries = 0; retries < 1000; retries++) { 180 for (retries = 0; retries < 1000; retries++) {
221 stat = hwif->tp_ops->read_status(hwif); 181 stat = hwif->tp_ops->read_status(hwif);
222 182
223 if (stat & BUSY_STAT) 183 if (stat & ATA_BUSY)
224 udelay(10); 184 udelay(10);
225 else 185 else
226 break; 186 break;
227 } 187 }
228 188
229 if (stat & BUSY_STAT) 189 if (stat & ATA_BUSY)
230 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name); 190 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
231 191
232 return stat; 192 return stat;
@@ -385,7 +345,7 @@ void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
385static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat) 345static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
386{ 346{
387 /* Command all done? */ 347 /* Command all done? */
388 if (OK_STAT(stat, READY_STAT, BUSY_STAT)) { 348 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) {
389 task_end_request(drive, rq, stat); 349 task_end_request(drive, rq, stat);
390 return ide_stopped; 350 return ide_stopped;
391 } 351 }
@@ -405,11 +365,11 @@ static ide_startstop_t task_in_intr(ide_drive_t *drive)
405 u8 stat = hwif->tp_ops->read_status(hwif); 365 u8 stat = hwif->tp_ops->read_status(hwif);
406 366
407 /* Error? */ 367 /* Error? */
408 if (stat & ERR_STAT) 368 if (stat & ATA_ERR)
409 return task_error(drive, rq, __func__, stat); 369 return task_error(drive, rq, __func__, stat);
410 370
411 /* Didn't want any data? Odd. */ 371 /* Didn't want any data? Odd. */
412 if (!(stat & DRQ_STAT)) 372 if ((stat & ATA_DRQ) == 0)
413 return task_in_unexpected(drive, rq, stat); 373 return task_in_unexpected(drive, rq, stat);
414 374
415 ide_pio_datablock(drive, rq, 0); 375 ide_pio_datablock(drive, rq, 0);
@@ -442,7 +402,7 @@ static ide_startstop_t task_out_intr (ide_drive_t *drive)
442 return task_error(drive, rq, __func__, stat); 402 return task_error(drive, rq, __func__, stat);
443 403
444 /* Deal with unexpected ATA data phase. */ 404 /* Deal with unexpected ATA data phase. */
445 if (((stat & DRQ_STAT) == 0) ^ !hwif->nleft) 405 if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft)
446 return task_error(drive, rq, __func__, stat); 406 return task_error(drive, rq, __func__, stat);
447 407
448 if (!hwif->nleft) { 408 if (!hwif->nleft) {
@@ -461,16 +421,15 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
461{ 421{
462 ide_startstop_t startstop; 422 ide_startstop_t startstop;
463 423
464 if (ide_wait_stat(&startstop, drive, DRQ_STAT, 424 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
465 drive->bad_wstat, WAIT_DRQ)) { 425 drive->bad_wstat, WAIT_DRQ)) {
466 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", 426 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
467 drive->name, 427 drive->name, drive->hwif->data_phase ? "MULT" : "",
468 drive->hwif->data_phase ? "MULT" : "", 428 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
469 drive->addressing ? "_EXT" : "");
470 return startstop; 429 return startstop;
471 } 430 }
472 431
473 if (!drive->unmask) 432 if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
474 local_irq_disable(); 433 local_irq_disable();
475 434
476 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); 435 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
@@ -586,7 +545,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
586 545
587 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE | 546 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
588 IDE_TFLAG_IN_TF; 547 IDE_TFLAG_IN_TF;
589 if (drive->addressing == 1) 548 if (drive->dev_flags & IDE_DFLAG_LBA48)
590 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB); 549 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
591 550
592 if (req_task->out_flags.all) { 551 if (req_task->out_flags.all) {
@@ -689,7 +648,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
689 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) && 648 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) &&
690 req_task->in_flags.all == 0) { 649 req_task->in_flags.all == 0) {
691 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; 650 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
692 if (drive->addressing == 1) 651 if (drive->dev_flags & IDE_DFLAG_LBA48)
693 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8); 652 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
694 } 653 }
695 654
@@ -721,110 +680,3 @@ abort:
721 return err; 680 return err;
722} 681}
723#endif 682#endif
724
725int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
726{
727 u8 *buf = NULL;
728 int bufsize = 0, err = 0;
729 u8 args[4], xfer_rate = 0;
730 ide_task_t tfargs;
731 struct ide_taskfile *tf = &tfargs.tf;
732 struct hd_driveid *id = drive->id;
733
734 if (NULL == (void *) arg) {
735 struct request *rq;
736
737 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
738 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
739 err = blk_execute_rq(drive->queue, NULL, rq, 0);
740 blk_put_request(rq);
741
742 return err;
743 }
744
745 if (copy_from_user(args, (void __user *)arg, 4))
746 return -EFAULT;
747
748 memset(&tfargs, 0, sizeof(ide_task_t));
749 tf->feature = args[2];
750 if (args[0] == WIN_SMART) {
751 tf->nsect = args[3];
752 tf->lbal = args[1];
753 tf->lbam = 0x4f;
754 tf->lbah = 0xc2;
755 tfargs.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT;
756 } else {
757 tf->nsect = args[1];
758 tfargs.tf_flags = IDE_TFLAG_OUT_FEATURE |
759 IDE_TFLAG_OUT_NSECT | IDE_TFLAG_IN_NSECT;
760 }
761 tf->command = args[0];
762 tfargs.data_phase = args[3] ? TASKFILE_IN : TASKFILE_NO_DATA;
763
764 if (args[3]) {
765 tfargs.tf_flags |= IDE_TFLAG_IO_16BIT;
766 bufsize = SECTOR_WORDS * 4 * args[3];
767 buf = kzalloc(bufsize, GFP_KERNEL);
768 if (buf == NULL)
769 return -ENOMEM;
770 }
771
772 if (tf->command == WIN_SETFEATURES &&
773 tf->feature == SETFEATURES_XFER &&
774 tf->nsect >= XFER_SW_DMA_0 &&
775 (id->dma_ultra || id->dma_mword || id->dma_1word)) {
776 xfer_rate = args[1];
777 if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
778 printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
779 "be set\n", drive->name);
780 goto abort;
781 }
782 }
783
784 err = ide_raw_taskfile(drive, &tfargs, buf, args[3]);
785
786 args[0] = tf->status;
787 args[1] = tf->error;
788 args[2] = tf->nsect;
789
790 if (!err && xfer_rate) {
791 /* active-retuning-calls future */
792 ide_set_xfer_rate(drive, xfer_rate);
793 ide_driveid_update(drive);
794 }
795abort:
796 if (copy_to_user((void __user *)arg, &args, 4))
797 err = -EFAULT;
798 if (buf) {
799 if (copy_to_user((void __user *)(arg + 4), buf, bufsize))
800 err = -EFAULT;
801 kfree(buf);
802 }
803 return err;
804}
805
806int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
807{
808 void __user *p = (void __user *)arg;
809 int err = 0;
810 u8 args[7];
811 ide_task_t task;
812
813 if (copy_from_user(args, p, 7))
814 return -EFAULT;
815
816 memset(&task, 0, sizeof(task));
817 memcpy(&task.tf_array[7], &args[1], 6);
818 task.tf.command = args[0];
819 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
820
821 err = ide_no_data_taskfile(drive, &task);
822
823 args[0] = task.tf.command;
824 memcpy(&args[1], &task.tf_array[7], 6);
825
826 if (copy_to_user(p, args, 7))
827 err = -EFAULT;
828
829 return err;
830}
diff --git a/drivers/ide/ide-timings.c b/drivers/ide/ide-timings.c
index 8c2f8327f487..81f527af8fae 100644
--- a/drivers/ide/ide-timings.c
+++ b/drivers/ide/ide-timings.c
@@ -22,7 +22,6 @@
22 */ 22 */
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/hdreg.h>
26#include <linux/ide.h> 25#include <linux/ide.h>
27#include <linux/module.h> 26#include <linux/module.h>
28 27
@@ -78,15 +77,15 @@ EXPORT_SYMBOL_GPL(ide_timing_find_mode);
78 77
79u16 ide_pio_cycle_time(ide_drive_t *drive, u8 pio) 78u16 ide_pio_cycle_time(ide_drive_t *drive, u8 pio)
80{ 79{
81 struct hd_driveid *id = drive->id; 80 u16 *id = drive->id;
82 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); 81 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
83 u16 cycle = 0; 82 u16 cycle = 0;
84 83
85 if (id->field_valid & 2) { 84 if (id[ATA_ID_FIELD_VALID] & 2) {
86 if (id->capability & 8) 85 if (ata_id_has_iordy(drive->id))
87 cycle = id->eide_pio_iordy; 86 cycle = id[ATA_ID_EIDE_PIO_IORDY];
88 else 87 else
89 cycle = id->eide_pio; 88 cycle = id[ATA_ID_EIDE_PIO];
90 89
91 /* conservative "downgrade" for all pre-ATA2 drives */ 90 /* conservative "downgrade" for all pre-ATA2 drives */
92 if (pio < 3 && cycle < t->cycle) 91 if (pio < 3 && cycle < t->cycle)
@@ -138,7 +137,7 @@ EXPORT_SYMBOL_GPL(ide_timing_merge);
138int ide_timing_compute(ide_drive_t *drive, u8 speed, 137int ide_timing_compute(ide_drive_t *drive, u8 speed,
139 struct ide_timing *t, int T, int UT) 138 struct ide_timing *t, int T, int UT)
140{ 139{
141 struct hd_driveid *id = drive->id; 140 u16 *id = drive->id;
142 struct ide_timing *s, p; 141 struct ide_timing *s, p;
143 142
144 /* 143 /*
@@ -157,16 +156,15 @@ int ide_timing_compute(ide_drive_t *drive, u8 speed,
157 * If the drive is an EIDE drive, it can tell us it needs extended 156 * If the drive is an EIDE drive, it can tell us it needs extended
158 * PIO/MWDMA cycle timing. 157 * PIO/MWDMA cycle timing.
159 */ 158 */
160 if (id && id->field_valid & 2) { /* EIDE drive */ 159 if (id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */
161
162 memset(&p, 0, sizeof(p)); 160 memset(&p, 0, sizeof(p));
163 161
164 if (speed <= XFER_PIO_2) 162 if (speed <= XFER_PIO_2)
165 p.cycle = p.cyc8b = id->eide_pio; 163 p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO];
166 else if (speed <= XFER_PIO_5) 164 else if (speed <= XFER_PIO_5)
167 p.cycle = p.cyc8b = id->eide_pio_iordy; 165 p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY];
168 else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) 166 else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)
169 p.cycle = id->eide_dma_min; 167 p.cycle = id[ATA_ID_EIDE_DMA_MIN];
170 168
171 ide_timing_merge(&p, t, t, IDE_TIMING_CYCLE | IDE_TIMING_CYC8B); 169 ide_timing_merge(&p, t, t, IDE_TIMING_CYCLE | IDE_TIMING_CYC8B);
172 } 170 }
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 772451600e4d..04f8f13cb9d7 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -44,8 +44,6 @@
44 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au 44 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
45 */ 45 */
46 46
47#define _IDE_C /* Tell ide.h it's really us */
48
49#include <linux/module.h> 47#include <linux/module.h>
50#include <linux/types.h> 48#include <linux/types.h>
51#include <linux/string.h> 49#include <linux/string.h>
@@ -58,6 +56,7 @@
58#include <linux/init.h> 56#include <linux/init.h>
59#include <linux/pci.h> 57#include <linux/pci.h>
60#include <linux/ide.h> 58#include <linux/ide.h>
59#include <linux/hdreg.h>
61#include <linux/completion.h> 60#include <linux/completion.h>
62#include <linux/device.h> 61#include <linux/device.h>
63 62
@@ -97,8 +96,6 @@ void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
97 hwif->name[2] = 'e'; 96 hwif->name[2] = 'e';
98 hwif->name[3] = '0' + index; 97 hwif->name[3] = '0' + index;
99 98
100 hwif->bus_state = BUSSTATE_ON;
101
102 init_completion(&hwif->gendev_rel_comp); 99 init_completion(&hwif->gendev_rel_comp);
103 100
104 hwif->tp_ops = &default_tp_ops; 101 hwif->tp_ops = &default_tp_ops;
@@ -117,9 +114,9 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
117 memset(drive, 0, sizeof(*drive)); 114 memset(drive, 0, sizeof(*drive));
118 115
119 drive->media = ide_disk; 116 drive->media = ide_disk;
120 drive->select.all = (unit<<4)|0xa0; 117 drive->select = (unit << 4) | ATA_DEVICE_OBS;
121 drive->hwif = hwif; 118 drive->hwif = hwif;
122 drive->ready_stat = READY_STAT; 119 drive->ready_stat = ATA_DRDY;
123 drive->bad_wstat = BAD_W_STAT; 120 drive->bad_wstat = BAD_W_STAT;
124 drive->special.b.recalibrate = 1; 121 drive->special.b.recalibrate = 1;
125 drive->special.b.set_geometry = 1; 122 drive->special.b.set_geometry = 1;
@@ -141,7 +138,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
141 for (i = 0; i < MAX_DRIVES; i++) { 138 for (i = 0; i < MAX_DRIVES; i++) {
142 ide_drive_t *drive = &hwif->drives[i]; 139 ide_drive_t *drive = &hwif->drives[i];
143 140
144 if (drive->present) { 141 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
145 spin_unlock_irq(&ide_lock); 142 spin_unlock_irq(&ide_lock);
146 device_unregister(&drive->gendev); 143 device_unregister(&drive->gendev);
147 wait_for_completion(&drive->gendev_rel_comp); 144 wait_for_completion(&drive->gendev_rel_comp);
@@ -230,8 +227,7 @@ void ide_unregister(ide_hwif_t *hwif)
230 kfree(hwif->sg_table); 227 kfree(hwif->sg_table);
231 unregister_blkdev(hwif->major, hwif->name); 228 unregister_blkdev(hwif->major, hwif->name);
232 229
233 if (hwif->dma_base) 230 ide_release_dma_engine(hwif);
234 ide_release_dma_engine(hwif);
235 231
236 mutex_unlock(&ide_cfg_mtx); 232 mutex_unlock(&ide_cfg_mtx);
237} 233}
@@ -253,96 +249,52 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
253 249
254DEFINE_MUTEX(ide_setting_mtx); 250DEFINE_MUTEX(ide_setting_mtx);
255 251
256EXPORT_SYMBOL_GPL(ide_setting_mtx); 252ide_devset_get(io_32bit, io_32bit);
257
258/**
259 * ide_spin_wait_hwgroup - wait for group
260 * @drive: drive in the group
261 *
262 * Wait for an IDE device group to go non busy and then return
263 * holding the ide_lock which guards the hwgroup->busy status
264 * and right to use it.
265 */
266
267int ide_spin_wait_hwgroup (ide_drive_t *drive)
268{
269 ide_hwgroup_t *hwgroup = HWGROUP(drive);
270 unsigned long timeout = jiffies + (3 * HZ);
271
272 spin_lock_irq(&ide_lock);
273 253
274 while (hwgroup->busy) { 254static int set_io_32bit(ide_drive_t *drive, int arg)
275 unsigned long lflags;
276 spin_unlock_irq(&ide_lock);
277 local_irq_set(lflags);
278 if (time_after(jiffies, timeout)) {
279 local_irq_restore(lflags);
280 printk(KERN_ERR "%s: channel busy\n", drive->name);
281 return -EBUSY;
282 }
283 local_irq_restore(lflags);
284 spin_lock_irq(&ide_lock);
285 }
286 return 0;
287}
288
289EXPORT_SYMBOL(ide_spin_wait_hwgroup);
290
291int set_io_32bit(ide_drive_t *drive, int arg)
292{ 255{
293 if (drive->no_io_32bit) 256 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
294 return -EPERM; 257 return -EPERM;
295 258
296 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) 259 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
297 return -EINVAL; 260 return -EINVAL;
298 261
299 if (ide_spin_wait_hwgroup(drive))
300 return -EBUSY;
301
302 drive->io_32bit = arg; 262 drive->io_32bit = arg;
303 263
304 spin_unlock_irq(&ide_lock);
305
306 return 0; 264 return 0;
307} 265}
308 266
267ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
268
309static int set_ksettings(ide_drive_t *drive, int arg) 269static int set_ksettings(ide_drive_t *drive, int arg)
310{ 270{
311 if (arg < 0 || arg > 1) 271 if (arg < 0 || arg > 1)
312 return -EINVAL; 272 return -EINVAL;
313 273
314 if (ide_spin_wait_hwgroup(drive)) 274 if (arg)
315 return -EBUSY; 275 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
316 drive->keep_settings = arg; 276 else
317 spin_unlock_irq(&ide_lock); 277 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
318 278
319 return 0; 279 return 0;
320} 280}
321 281
322int set_using_dma(ide_drive_t *drive, int arg) 282ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
283
284static int set_using_dma(ide_drive_t *drive, int arg)
323{ 285{
324#ifdef CONFIG_BLK_DEV_IDEDMA 286#ifdef CONFIG_BLK_DEV_IDEDMA
325 ide_hwif_t *hwif = drive->hwif;
326 int err = -EPERM; 287 int err = -EPERM;
327 288
328 if (arg < 0 || arg > 1) 289 if (arg < 0 || arg > 1)
329 return -EINVAL; 290 return -EINVAL;
330 291
331 if (!drive->id || !(drive->id->capability & 1)) 292 if (ata_id_has_dma(drive->id) == 0)
332 goto out; 293 goto out;
333 294
334 if (hwif->dma_ops == NULL) 295 if (drive->hwif->dma_ops == NULL)
335 goto out; 296 goto out;
336 297
337 err = -EBUSY;
338 if (ide_spin_wait_hwgroup(drive))
339 goto out;
340 /*
341 * set ->busy flag, unlock and let it ride
342 */
343 hwif->hwgroup->busy = 1;
344 spin_unlock_irq(&ide_lock);
345
346 err = 0; 298 err = 0;
347 299
348 if (arg) { 300 if (arg) {
@@ -351,12 +303,6 @@ int set_using_dma(ide_drive_t *drive, int arg)
351 } else 303 } else
352 ide_dma_off(drive); 304 ide_dma_off(drive);
353 305
354 /*
355 * lock, clear ->busy flag and unlock before leaving
356 */
357 spin_lock_irq(&ide_lock);
358 hwif->hwgroup->busy = 0;
359 spin_unlock_irq(&ide_lock);
360out: 306out:
361 return err; 307 return err;
362#else 308#else
@@ -367,9 +313,32 @@ out:
367#endif 313#endif
368} 314}
369 315
370int set_pio_mode(ide_drive_t *drive, int arg) 316/*
317 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
318 */
319static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
320{
321 switch (req_pio) {
322 case 202:
323 case 201:
324 case 200:
325 case 102:
326 case 101:
327 case 100:
328 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
329 case 9:
330 case 8:
331 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
332 case 7:
333 case 6:
334 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
335 default:
336 return 0;
337 }
338}
339
340static int set_pio_mode(ide_drive_t *drive, int arg)
371{ 341{
372 struct request *rq;
373 ide_hwif_t *hwif = drive->hwif; 342 ide_hwif_t *hwif = drive->hwif;
374 const struct ide_port_ops *port_ops = hwif->port_ops; 343 const struct ide_port_ops *port_ops = hwif->port_ops;
375 344
@@ -380,48 +349,65 @@ int set_pio_mode(ide_drive_t *drive, int arg)
380 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) 349 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
381 return -ENOSYS; 350 return -ENOSYS;
382 351
383 if (drive->special.b.set_tune) 352 if (set_pio_mode_abuse(drive->hwif, arg)) {
384 return -EBUSY; 353 if (arg == 8 || arg == 9) {
354 unsigned long flags;
385 355
386 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 356 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
387 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 357 spin_lock_irqsave(&ide_lock, flags);
358 port_ops->set_pio_mode(drive, arg);
359 spin_unlock_irqrestore(&ide_lock, flags);
360 } else
361 port_ops->set_pio_mode(drive, arg);
362 } else {
363 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
388 364
389 drive->tune_req = (u8) arg; 365 ide_set_pio(drive, arg);
390 drive->special.b.set_tune = 1;
391 366
392 blk_execute_rq(drive->queue, NULL, rq, 0); 367 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
393 blk_put_request(rq); 368 if (keep_dma)
369 ide_dma_on(drive);
370 }
371 }
394 372
395 return 0; 373 return 0;
396} 374}
397 375
376ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
377
398static int set_unmaskirq(ide_drive_t *drive, int arg) 378static int set_unmaskirq(ide_drive_t *drive, int arg)
399{ 379{
400 if (drive->no_unmask) 380 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
401 return -EPERM; 381 return -EPERM;
402 382
403 if (arg < 0 || arg > 1) 383 if (arg < 0 || arg > 1)
404 return -EINVAL; 384 return -EINVAL;
405 385
406 if (ide_spin_wait_hwgroup(drive)) 386 if (arg)
407 return -EBUSY; 387 drive->dev_flags |= IDE_DFLAG_UNMASK;
408 drive->unmask = arg; 388 else
409 spin_unlock_irq(&ide_lock); 389 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
410 390
411 return 0; 391 return 0;
412} 392}
413 393
394ide_ext_devset_rw_sync(io_32bit, io_32bit);
395ide_ext_devset_rw_sync(keepsettings, ksettings);
396ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
397ide_ext_devset_rw_sync(using_dma, using_dma);
398__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
399
414static int generic_ide_suspend(struct device *dev, pm_message_t mesg) 400static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
415{ 401{
416 ide_drive_t *drive = dev->driver_data; 402 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
417 ide_hwif_t *hwif = HWIF(drive); 403 ide_hwif_t *hwif = HWIF(drive);
418 struct request *rq; 404 struct request *rq;
419 struct request_pm_state rqpm; 405 struct request_pm_state rqpm;
420 ide_task_t args; 406 ide_task_t args;
421 int ret; 407 int ret;
422 408
423 /* Call ACPI _GTM only once */ 409 /* call ACPI _GTM only once */
424 if (!(drive->dn % 2)) 410 if ((drive->dn & 1) == 0 || pair == NULL)
425 ide_acpi_get_timing(hwif); 411 ide_acpi_get_timing(hwif);
426 412
427 memset(&rqpm, 0, sizeof(rqpm)); 413 memset(&rqpm, 0, sizeof(rqpm));
@@ -430,33 +416,32 @@ static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
430 rq->cmd_type = REQ_TYPE_PM_SUSPEND; 416 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
431 rq->special = &args; 417 rq->special = &args;
432 rq->data = &rqpm; 418 rq->data = &rqpm;
433 rqpm.pm_step = ide_pm_state_start_suspend; 419 rqpm.pm_step = IDE_PM_START_SUSPEND;
434 if (mesg.event == PM_EVENT_PRETHAW) 420 if (mesg.event == PM_EVENT_PRETHAW)
435 mesg.event = PM_EVENT_FREEZE; 421 mesg.event = PM_EVENT_FREEZE;
436 rqpm.pm_state = mesg.event; 422 rqpm.pm_state = mesg.event;
437 423
438 ret = blk_execute_rq(drive->queue, NULL, rq, 0); 424 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
439 blk_put_request(rq); 425 blk_put_request(rq);
440 /* only call ACPI _PS3 after both drivers are suspended */ 426
441 if (!ret && (((drive->dn % 2) && hwif->drives[0].present 427 /* call ACPI _PS3 only after both devices are suspended */
442 && hwif->drives[1].present) 428 if (ret == 0 && ((drive->dn & 1) || pair == NULL))
443 || !hwif->drives[0].present
444 || !hwif->drives[1].present))
445 ide_acpi_set_state(hwif, 0); 429 ide_acpi_set_state(hwif, 0);
430
446 return ret; 431 return ret;
447} 432}
448 433
449static int generic_ide_resume(struct device *dev) 434static int generic_ide_resume(struct device *dev)
450{ 435{
451 ide_drive_t *drive = dev->driver_data; 436 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
452 ide_hwif_t *hwif = HWIF(drive); 437 ide_hwif_t *hwif = HWIF(drive);
453 struct request *rq; 438 struct request *rq;
454 struct request_pm_state rqpm; 439 struct request_pm_state rqpm;
455 ide_task_t args; 440 ide_task_t args;
456 int err; 441 int err;
457 442
458 /* Call ACPI _STM only once */ 443 /* call ACPI _PS0 / _STM only once */
459 if (!(drive->dn % 2)) { 444 if ((drive->dn & 1) == 0 || pair == NULL) {
460 ide_acpi_set_state(hwif, 1); 445 ide_acpi_set_state(hwif, 1);
461 ide_acpi_push_timing(hwif); 446 ide_acpi_push_timing(hwif);
462 } 447 }
@@ -470,7 +455,7 @@ static int generic_ide_resume(struct device *dev)
470 rq->cmd_flags |= REQ_PREEMPT; 455 rq->cmd_flags |= REQ_PREEMPT;
471 rq->special = &args; 456 rq->special = &args;
472 rq->data = &rqpm; 457 rq->data = &rqpm;
473 rqpm.pm_step = ide_pm_state_start_resume; 458 rqpm.pm_step = IDE_PM_START_RESUME;
474 rqpm.pm_state = PM_EVENT_ON; 459 rqpm.pm_state = PM_EVENT_ON;
475 460
476 err = blk_execute_rq(drive->queue, NULL, rq, 1); 461 err = blk_execute_rq(drive->queue, NULL, rq, 1);
@@ -486,138 +471,6 @@ static int generic_ide_resume(struct device *dev)
486 return err; 471 return err;
487} 472}
488 473
489static int generic_drive_reset(ide_drive_t *drive)
490{
491 struct request *rq;
492 int ret = 0;
493
494 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
495 rq->cmd_type = REQ_TYPE_SPECIAL;
496 rq->cmd_len = 1;
497 rq->cmd[0] = REQ_DRIVE_RESET;
498 rq->cmd_flags |= REQ_SOFTBARRIER;
499 if (blk_execute_rq(drive->queue, NULL, rq, 1))
500 ret = rq->errors;
501 blk_put_request(rq);
502 return ret;
503}
504
505int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
506 unsigned int cmd, unsigned long arg)
507{
508 unsigned long flags;
509 ide_driver_t *drv;
510 void __user *p = (void __user *)arg;
511 int err = 0, (*setfunc)(ide_drive_t *, int);
512 u8 *val;
513
514 switch (cmd) {
515 case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
516 case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
517 case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
518 case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
519 case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
520 case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
521 case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
522 case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
523 case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
524 }
525
526 switch (cmd) {
527 case HDIO_OBSOLETE_IDENTITY:
528 case HDIO_GET_IDENTITY:
529 if (bdev != bdev->bd_contains)
530 return -EINVAL;
531 if (drive->id_read == 0)
532 return -ENOMSG;
533 if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
534 return -EFAULT;
535 return 0;
536
537 case HDIO_GET_NICE:
538 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
539 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
540 drive->nice1 << IDE_NICE_1,
541 (long __user *) arg);
542#ifdef CONFIG_IDE_TASK_IOCTL
543 case HDIO_DRIVE_TASKFILE:
544 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
545 return -EACCES;
546 switch(drive->media) {
547 case ide_disk:
548 return ide_taskfile_ioctl(drive, cmd, arg);
549 default:
550 return -ENOMSG;
551 }
552#endif /* CONFIG_IDE_TASK_IOCTL */
553
554 case HDIO_DRIVE_CMD:
555 if (!capable(CAP_SYS_RAWIO))
556 return -EACCES;
557 return ide_cmd_ioctl(drive, cmd, arg);
558
559 case HDIO_DRIVE_TASK:
560 if (!capable(CAP_SYS_RAWIO))
561 return -EACCES;
562 return ide_task_ioctl(drive, cmd, arg);
563 case HDIO_SET_NICE:
564 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
565 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
566 return -EPERM;
567 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
568 drv = *(ide_driver_t **)bdev->bd_disk->private_data;
569 if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
570 drive->dsc_overlap = 0;
571 return -EPERM;
572 }
573 drive->nice1 = (arg >> IDE_NICE_1) & 1;
574 return 0;
575 case HDIO_DRIVE_RESET:
576 if (!capable(CAP_SYS_ADMIN))
577 return -EACCES;
578
579 return generic_drive_reset(drive);
580
581 case HDIO_GET_BUSSTATE:
582 if (!capable(CAP_SYS_ADMIN))
583 return -EACCES;
584 if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
585 return -EFAULT;
586 return 0;
587
588 case HDIO_SET_BUSSTATE:
589 if (!capable(CAP_SYS_ADMIN))
590 return -EACCES;
591 return -EOPNOTSUPP;
592 default:
593 return -EINVAL;
594 }
595
596read_val:
597 mutex_lock(&ide_setting_mtx);
598 spin_lock_irqsave(&ide_lock, flags);
599 err = *val;
600 spin_unlock_irqrestore(&ide_lock, flags);
601 mutex_unlock(&ide_setting_mtx);
602 return err >= 0 ? put_user(err, (long __user *)arg) : err;
603
604set_val:
605 if (bdev != bdev->bd_contains)
606 err = -EINVAL;
607 else {
608 if (!capable(CAP_SYS_ADMIN))
609 err = -EACCES;
610 else {
611 mutex_lock(&ide_setting_mtx);
612 err = setfunc(drive, arg);
613 mutex_unlock(&ide_setting_mtx);
614 }
615 }
616 return err;
617}
618
619EXPORT_SYMBOL(generic_ide_ioctl);
620
621/** 474/**
622 * ide_device_get - get an additional reference to a ide_drive_t 475 * ide_device_get - get an additional reference to a ide_drive_t
623 * @drive: device to get a reference to 476 * @drive: device to get a reference to
@@ -710,21 +563,21 @@ static ssize_t model_show(struct device *dev, struct device_attribute *attr,
710 char *buf) 563 char *buf)
711{ 564{
712 ide_drive_t *drive = to_ide_device(dev); 565 ide_drive_t *drive = to_ide_device(dev);
713 return sprintf(buf, "%s\n", drive->id->model); 566 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
714} 567}
715 568
716static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, 569static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
717 char *buf) 570 char *buf)
718{ 571{
719 ide_drive_t *drive = to_ide_device(dev); 572 ide_drive_t *drive = to_ide_device(dev);
720 return sprintf(buf, "%s\n", drive->id->fw_rev); 573 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
721} 574}
722 575
723static ssize_t serial_show(struct device *dev, struct device_attribute *attr, 576static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
724 char *buf) 577 char *buf)
725{ 578{
726 ide_drive_t *drive = to_ide_device(dev); 579 ide_drive_t *drive = to_ide_device(dev);
727 return sprintf(buf, "%s\n", drive->id->serial_no); 580 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
728} 581}
729 582
730static struct device_attribute ide_dev_attrs[] = { 583static struct device_attribute ide_dev_attrs[] = {
@@ -734,6 +587,7 @@ static struct device_attribute ide_dev_attrs[] = {
734 __ATTR_RO(model), 587 __ATTR_RO(model),
735 __ATTR_RO(firmware), 588 __ATTR_RO(firmware),
736 __ATTR(serial, 0400, serial_show, NULL), 589 __ATTR(serial, 0400, serial_show, NULL),
590 __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
737 __ATTR_NULL 591 __ATTR_NULL
738}; 592};
739 593
@@ -841,7 +695,7 @@ MODULE_PARM_DESC(noprobe, "skip probing for a device");
841static unsigned int ide_nowerr; 695static unsigned int ide_nowerr;
842 696
843module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0); 697module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
844MODULE_PARM_DESC(nowerr, "ignore the WRERR_STAT bit for a device"); 698MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
845 699
846static unsigned int ide_cdroms; 700static unsigned int ide_cdroms;
847 701
@@ -888,31 +742,31 @@ static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
888module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0); 742module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
889MODULE_PARM_DESC(chs, "force device as a disk (using CHS)"); 743MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
890 744
891static void ide_dev_apply_params(ide_drive_t *drive) 745static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
892{ 746{
893 int i = drive->hwif->index * MAX_DRIVES + drive->select.b.unit; 747 int i = drive->hwif->index * MAX_DRIVES + unit;
894 748
895 if (ide_nodma & (1 << i)) { 749 if (ide_nodma & (1 << i)) {
896 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name); 750 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
897 drive->nodma = 1; 751 drive->dev_flags |= IDE_DFLAG_NODMA;
898 } 752 }
899 if (ide_noflush & (1 << i)) { 753 if (ide_noflush & (1 << i)) {
900 printk(KERN_INFO "ide: disabling flush requests for %s\n", 754 printk(KERN_INFO "ide: disabling flush requests for %s\n",
901 drive->name); 755 drive->name);
902 drive->noflush = 1; 756 drive->dev_flags |= IDE_DFLAG_NOFLUSH;
903 } 757 }
904 if (ide_noprobe & (1 << i)) { 758 if (ide_noprobe & (1 << i)) {
905 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name); 759 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
906 drive->noprobe = 1; 760 drive->dev_flags |= IDE_DFLAG_NOPROBE;
907 } 761 }
908 if (ide_nowerr & (1 << i)) { 762 if (ide_nowerr & (1 << i)) {
909 printk(KERN_INFO "ide: ignoring the WRERR_STAT bit for %s\n", 763 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
910 drive->name); 764 drive->name);
911 drive->bad_wstat = BAD_R_STAT; 765 drive->bad_wstat = BAD_R_STAT;
912 } 766 }
913 if (ide_cdroms & (1 << i)) { 767 if (ide_cdroms & (1 << i)) {
914 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name); 768 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
915 drive->present = 1; 769 drive->dev_flags |= IDE_DFLAG_PRESENT;
916 drive->media = ide_cdrom; 770 drive->media = ide_cdrom;
917 /* an ATAPI device ignores DRDY */ 771 /* an ATAPI device ignores DRDY */
918 drive->ready_stat = 0; 772 drive->ready_stat = 0;
@@ -921,13 +775,14 @@ static void ide_dev_apply_params(ide_drive_t *drive)
921 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl; 775 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
922 drive->head = drive->bios_head = ide_disks_chs[i].head; 776 drive->head = drive->bios_head = ide_disks_chs[i].head;
923 drive->sect = drive->bios_sect = ide_disks_chs[i].sect; 777 drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
924 drive->forced_geom = 1; 778
925 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n", 779 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
926 drive->name, 780 drive->name,
927 drive->cyl, drive->head, drive->sect); 781 drive->cyl, drive->head, drive->sect);
928 drive->present = 1; 782
783 drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
929 drive->media = ide_disk; 784 drive->media = ide_disk;
930 drive->ready_stat = READY_STAT; 785 drive->ready_stat = ATA_DRDY;
931 } 786 }
932} 787}
933 788
@@ -965,7 +820,7 @@ void ide_port_apply_params(ide_hwif_t *hwif)
965 } 820 }
966 821
967 for (i = 0; i < MAX_DRIVES; i++) 822 for (i = 0; i < MAX_DRIVES; i++)
968 ide_dev_apply_params(&hwif->drives[i]); 823 ide_dev_apply_params(&hwif->drives[i], i);
969} 824}
970 825
971/* 826/*
diff --git a/drivers/ide/arm/ide_arm.c b/drivers/ide/ide_arm.c
index f728f2927b5a..f728f2927b5a 100644
--- a/drivers/ide/arm/ide_arm.c
+++ b/drivers/ide/ide_arm.c
diff --git a/drivers/ide/legacy/ide_platform.c b/drivers/ide/ide_platform.c
index 051b4ab0f359..051b4ab0f359 100644
--- a/drivers/ide/legacy/ide_platform.c
+++ b/drivers/ide/ide_platform.c
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/it8213.c
index 652e47dd7e89..7c2feeb3c5ec 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/it8213.c
@@ -10,7 +10,6 @@
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/hdreg.h>
14#include <linux/ide.h> 13#include <linux/ide.h>
15#include <linux/init.h> 14#include <linux/init.h>
16 15
@@ -190,21 +189,23 @@ static const struct pci_device_id it8213_pci_tbl[] = {
190 189
191MODULE_DEVICE_TABLE(pci, it8213_pci_tbl); 190MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
192 191
193static struct pci_driver driver = { 192static struct pci_driver it8213_pci_driver = {
194 .name = "ITE8213_IDE", 193 .name = "ITE8213_IDE",
195 .id_table = it8213_pci_tbl, 194 .id_table = it8213_pci_tbl,
196 .probe = it8213_init_one, 195 .probe = it8213_init_one,
197 .remove = ide_pci_remove, 196 .remove = ide_pci_remove,
197 .suspend = ide_pci_suspend,
198 .resume = ide_pci_resume,
198}; 199};
199 200
200static int __init it8213_ide_init(void) 201static int __init it8213_ide_init(void)
201{ 202{
202 return ide_pci_register_driver(&driver); 203 return ide_pci_register_driver(&it8213_pci_driver);
203} 204}
204 205
205static void __exit it8213_ide_exit(void) 206static void __exit it8213_ide_exit(void)
206{ 207{
207 pci_unregister_driver(&driver); 208 pci_unregister_driver(&it8213_pci_driver);
208} 209}
209 210
210module_init(it8213_ide_init); 211module_init(it8213_ide_init);
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/it821x.c
index 4a1508a707cc..ef004089761b 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/it821x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2004 Red Hat <alan@redhat.com> 2 * Copyright (C) 2004 Red Hat
3 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 3 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
4 * 4 *
5 * May be copied or modified under the terms of the GNU General Public License 5 * May be copied or modified under the terms of the GNU General Public License
@@ -63,7 +63,6 @@
63#include <linux/types.h> 63#include <linux/types.h>
64#include <linux/module.h> 64#include <linux/module.h>
65#include <linux/pci.h> 65#include <linux/pci.h>
66#include <linux/hdreg.h>
67#include <linux/ide.h> 66#include <linux/ide.h>
68#include <linux/init.h> 67#include <linux/init.h>
69 68
@@ -139,8 +138,7 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
139 struct pci_dev *dev = to_pci_dev(hwif->dev); 138 struct pci_dev *dev = to_pci_dev(hwif->dev);
140 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 139 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
141 int channel = hwif->channel; 140 int channel = hwif->channel;
142 int unit = drive->select.b.unit; 141 u8 unit = drive->dn & 1, conf;
143 u8 conf;
144 142
145 /* Program UDMA timing bits */ 143 /* Program UDMA timing bits */
146 if(itdev->clock_mode == ATA_66) 144 if(itdev->clock_mode == ATA_66)
@@ -169,13 +167,11 @@ static void it821x_clock_strategy(ide_drive_t *drive)
169 ide_hwif_t *hwif = drive->hwif; 167 ide_hwif_t *hwif = drive->hwif;
170 struct pci_dev *dev = to_pci_dev(hwif->dev); 168 struct pci_dev *dev = to_pci_dev(hwif->dev);
171 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 169 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
170 ide_drive_t *pair;
171 int clock, altclock, sel = 0;
172 u8 unit = drive->dn & 1, v;
172 173
173 u8 unit = drive->select.b.unit; 174 pair = &hwif->drives[1 - unit];
174 ide_drive_t *pair = &hwif->drives[1-unit];
175
176 int clock, altclock;
177 u8 v;
178 int sel = 0;
179 175
180 if(itdev->want[0][0] > itdev->want[1][0]) { 176 if(itdev->want[0][0] > itdev->want[1][0]) {
181 clock = itdev->want[0][1]; 177 clock = itdev->want[0][1];
@@ -241,16 +237,17 @@ static void it821x_clock_strategy(ide_drive_t *drive)
241 237
242static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio) 238static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
243{ 239{
244 ide_hwif_t *hwif = drive->hwif; 240 ide_hwif_t *hwif = drive->hwif;
245 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 241 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
246 int unit = drive->select.b.unit; 242 ide_drive_t *pair;
247 ide_drive_t *pair = &hwif->drives[1 - unit]; 243 u8 unit = drive->dn & 1, set_pio = pio;
248 u8 set_pio = pio;
249 244
250 /* Spec says 89 ref driver uses 88 */ 245 /* Spec says 89 ref driver uses 88 */
251 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 }; 246 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
252 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY }; 247 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
253 248
249 pair = &hwif->drives[1 - unit];
250
254 /* 251 /*
255 * Compute the best PIO mode we can for a given device. We must 252 * Compute the best PIO mode we can for a given device. We must
256 * pick a speed that does not cause problems with the other device 253 * pick a speed that does not cause problems with the other device
@@ -287,9 +284,7 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
287 ide_hwif_t *hwif = drive->hwif; 284 ide_hwif_t *hwif = drive->hwif;
288 struct pci_dev *dev = to_pci_dev(hwif->dev); 285 struct pci_dev *dev = to_pci_dev(hwif->dev);
289 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif); 286 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
290 int unit = drive->select.b.unit; 287 u8 unit = drive->dn & 1, channel = hwif->channel, conf;
291 int channel = hwif->channel;
292 u8 conf;
293 288
294 static u16 dma[] = { 0x8866, 0x3222, 0x3121 }; 289 static u16 dma[] = { 0x8866, 0x3222, 0x3121 };
295 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY }; 290 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
@@ -326,9 +321,7 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
326 ide_hwif_t *hwif = drive->hwif; 321 ide_hwif_t *hwif = drive->hwif;
327 struct pci_dev *dev = to_pci_dev(hwif->dev); 322 struct pci_dev *dev = to_pci_dev(hwif->dev);
328 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 323 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
329 int unit = drive->select.b.unit; 324 u8 unit = drive->dn & 1, channel = hwif->channel, conf;
330 int channel = hwif->channel;
331 u8 conf;
332 325
333 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 }; 326 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
334 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 }; 327 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
@@ -370,7 +363,8 @@ static void it821x_dma_start(ide_drive_t *drive)
370{ 363{
371 ide_hwif_t *hwif = drive->hwif; 364 ide_hwif_t *hwif = drive->hwif;
372 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 365 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
373 int unit = drive->select.b.unit; 366 u8 unit = drive->dn & 1;
367
374 if(itdev->mwdma[unit] != MWDMA_OFF) 368 if(itdev->mwdma[unit] != MWDMA_OFF)
375 it821x_program(drive, itdev->mwdma[unit]); 369 it821x_program(drive, itdev->mwdma[unit]);
376 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10) 370 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
@@ -390,9 +384,10 @@ static void it821x_dma_start(ide_drive_t *drive)
390static int it821x_dma_end(ide_drive_t *drive) 384static int it821x_dma_end(ide_drive_t *drive)
391{ 385{
392 ide_hwif_t *hwif = drive->hwif; 386 ide_hwif_t *hwif = drive->hwif;
393 int unit = drive->select.b.unit;
394 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 387 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
395 int ret = __ide_dma_end(drive); 388 int ret = ide_dma_end(drive);
389 u8 unit = drive->dn & 1;
390
396 if(itdev->mwdma[unit] != MWDMA_OFF) 391 if(itdev->mwdma[unit] != MWDMA_OFF)
397 it821x_program(drive, itdev->pio[unit]); 392 it821x_program(drive, itdev->pio[unit]);
398 return ret; 393 return ret;
@@ -446,8 +441,7 @@ static u8 it821x_cable_detect(ide_hwif_t *hwif)
446static void it821x_quirkproc(ide_drive_t *drive) 441static void it821x_quirkproc(ide_drive_t *drive)
447{ 442{
448 struct it821x_dev *itdev = ide_get_hwifdata(drive->hwif); 443 struct it821x_dev *itdev = ide_get_hwifdata(drive->hwif);
449 struct hd_driveid *id = drive->id; 444 u16 *id = drive->id;
450 u16 *idbits = (u16 *)drive->id;
451 445
452 if (!itdev->smart) { 446 if (!itdev->smart) {
453 /* 447 /*
@@ -456,7 +450,7 @@ static void it821x_quirkproc(ide_drive_t *drive)
456 * IRQ mask as we may well be in PIO (eg rev 0x10) 450 * IRQ mask as we may well be in PIO (eg rev 0x10)
457 * for now and we know unmasking is safe on this chipset. 451 * for now and we know unmasking is safe on this chipset.
458 */ 452 */
459 drive->unmask = 1; 453 drive->dev_flags |= IDE_DFLAG_UNMASK;
460 } else { 454 } else {
461 /* 455 /*
462 * Perform fixups on smart mode. We need to "lose" some 456 * Perform fixups on smart mode. We need to "lose" some
@@ -466,36 +460,36 @@ static void it821x_quirkproc(ide_drive_t *drive)
466 */ 460 */
467 461
468 /* Check for RAID v native */ 462 /* Check for RAID v native */
469 if(strstr(id->model, "Integrated Technology Express")) { 463 if (strstr((char *)&id[ATA_ID_PROD],
464 "Integrated Technology Express")) {
470 /* In raid mode the ident block is slightly buggy 465 /* In raid mode the ident block is slightly buggy
471 We need to set the bits so that the IDE layer knows 466 We need to set the bits so that the IDE layer knows
472 LBA28. LBA48 and DMA ar valid */ 467 LBA28. LBA48 and DMA ar valid */
473 id->capability |= 3; /* LBA28, DMA */ 468 id[ATA_ID_CAPABILITY] |= (3 << 8); /* LBA28, DMA */
474 id->command_set_2 |= 0x0400; /* LBA48 valid */ 469 id[ATA_ID_COMMAND_SET_2] |= 0x0400; /* LBA48 valid */
475 id->cfs_enable_2 |= 0x0400; /* LBA48 on */ 470 id[ATA_ID_CFS_ENABLE_2] |= 0x0400; /* LBA48 on */
476 /* Reporting logic */ 471 /* Reporting logic */
477 printk(KERN_INFO "%s: IT8212 %sRAID %d volume", 472 printk(KERN_INFO "%s: IT8212 %sRAID %d volume",
478 drive->name, 473 drive->name, id[147] ? "Bootable " : "",
479 idbits[147] ? "Bootable ":"", 474 id[ATA_ID_CSFO]);
480 idbits[129]); 475 if (id[ATA_ID_CSFO] != 1)
481 if(idbits[129] != 1) 476 printk(KERN_CONT "(%dK stripe)", id[146]);
482 printk("(%dK stripe)", idbits[146]); 477 printk(KERN_CONT ".\n");
483 printk(".\n");
484 } else { 478 } else {
485 /* Non RAID volume. Fixups to stop the core code 479 /* Non RAID volume. Fixups to stop the core code
486 doing unsupported things */ 480 doing unsupported things */
487 id->field_valid &= 3; 481 id[ATA_ID_FIELD_VALID] &= 3;
488 id->queue_depth = 0; 482 id[ATA_ID_QUEUE_DEPTH] = 0;
489 id->command_set_1 = 0; 483 id[ATA_ID_COMMAND_SET_1] = 0;
490 id->command_set_2 &= 0xC400; 484 id[ATA_ID_COMMAND_SET_2] &= 0xC400;
491 id->cfsse &= 0xC000; 485 id[ATA_ID_CFSSE] &= 0xC000;
492 id->cfs_enable_1 = 0; 486 id[ATA_ID_CFS_ENABLE_1] = 0;
493 id->cfs_enable_2 &= 0xC400; 487 id[ATA_ID_CFS_ENABLE_2] &= 0xC400;
494 id->csf_default &= 0xC000; 488 id[ATA_ID_CSF_DEFAULT] &= 0xC000;
495 id->word127 = 0; 489 id[127] = 0;
496 id->dlf = 0; 490 id[ATA_ID_DLF] = 0;
497 id->csfo = 0; 491 id[ATA_ID_CSFO] = 0;
498 id->cfa_power = 0; 492 id[ATA_ID_CFA_POWER] = 0;
499 printk(KERN_INFO "%s: Performing identify fixups.\n", 493 printk(KERN_INFO "%s: Performing identify fixups.\n",
500 drive->name); 494 drive->name);
501 } 495 }
@@ -505,8 +499,8 @@ static void it821x_quirkproc(ide_drive_t *drive)
505 * IDE core that DMA is supported (it821x hardware 499 * IDE core that DMA is supported (it821x hardware
506 * takes care of DMA mode programming). 500 * takes care of DMA mode programming).
507 */ 501 */
508 if (id->capability & 1) { 502 if (ata_id_has_dma(id)) {
509 id->dma_mword |= 0x0101; 503 id[ATA_ID_MWDMA_MODES] |= 0x0101;
510 drive->current_speed = XFER_MW_DMA_0; 504 drive->current_speed = XFER_MW_DMA_0;
511 } 505 }
512 } 506 }
@@ -588,7 +582,7 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
588 hwif->mwdma_mask = ATA_MWDMA2; 582 hwif->mwdma_mask = ATA_MWDMA2;
589} 583}
590 584
591static void __devinit it8212_disable_raid(struct pci_dev *dev) 585static void it8212_disable_raid(struct pci_dev *dev)
592{ 586{
593 /* Reset local CPU, and set BIOS not ready */ 587 /* Reset local CPU, and set BIOS not ready */
594 pci_write_config_byte(dev, 0x5E, 0x01); 588 pci_write_config_byte(dev, 0x5E, 0x01);
@@ -605,7 +599,7 @@ static void __devinit it8212_disable_raid(struct pci_dev *dev)
605 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 599 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
606} 600}
607 601
608static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev) 602static unsigned int init_chipset_it821x(struct pci_dev *dev)
609{ 603{
610 u8 conf; 604 u8 conf;
611 static char *mode[2] = { "pass through", "smart" }; 605 static char *mode[2] = { "pass through", "smart" };
@@ -682,21 +676,23 @@ static const struct pci_device_id it821x_pci_tbl[] = {
682 676
683MODULE_DEVICE_TABLE(pci, it821x_pci_tbl); 677MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
684 678
685static struct pci_driver driver = { 679static struct pci_driver it821x_pci_driver = {
686 .name = "ITE821x IDE", 680 .name = "ITE821x IDE",
687 .id_table = it821x_pci_tbl, 681 .id_table = it821x_pci_tbl,
688 .probe = it821x_init_one, 682 .probe = it821x_init_one,
689 .remove = __devexit_p(it821x_remove), 683 .remove = __devexit_p(it821x_remove),
684 .suspend = ide_pci_suspend,
685 .resume = ide_pci_resume,
690}; 686};
691 687
692static int __init it821x_ide_init(void) 688static int __init it821x_ide_init(void)
693{ 689{
694 return ide_pci_register_driver(&driver); 690 return ide_pci_register_driver(&it821x_pci_driver);
695} 691}
696 692
697static void __exit it821x_ide_exit(void) 693static void __exit it821x_ide_exit(void)
698{ 694{
699 pci_unregister_driver(&driver); 695 pci_unregister_driver(&it821x_pci_driver);
700} 696}
701 697
702module_init(it821x_ide_init); 698module_init(it821x_ide_init);
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/jmicron.c
index bb9d09d8f196..bf2be6431b20 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/jmicron.c
@@ -1,6 +1,6 @@
1 1
2/* 2/*
3 * Copyright (C) 2006 Red Hat <alan@redhat.com> 3 * Copyright (C) 2006 Red Hat
4 * 4 *
5 * May be copied or modified under the terms of the GNU General Public License 5 * May be copied or modified under the terms of the GNU General Public License
6 */ 6 */
@@ -8,7 +8,6 @@
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/pci.h> 10#include <linux/pci.h>
11#include <linux/hdreg.h>
12#include <linux/ide.h> 11#include <linux/ide.h>
13#include <linux/init.h> 12#include <linux/init.h>
14 13
@@ -150,21 +149,23 @@ static struct pci_device_id jmicron_pci_tbl[] = {
150 149
151MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); 150MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
152 151
153static struct pci_driver driver = { 152static struct pci_driver jmicron_pci_driver = {
154 .name = "JMicron IDE", 153 .name = "JMicron IDE",
155 .id_table = jmicron_pci_tbl, 154 .id_table = jmicron_pci_tbl,
156 .probe = jmicron_init_one, 155 .probe = jmicron_init_one,
157 .remove = ide_pci_remove, 156 .remove = ide_pci_remove,
157 .suspend = ide_pci_suspend,
158 .resume = ide_pci_resume,
158}; 159};
159 160
160static int __init jmicron_ide_init(void) 161static int __init jmicron_ide_init(void)
161{ 162{
162 return ide_pci_register_driver(&driver); 163 return ide_pci_register_driver(&jmicron_pci_driver);
163} 164}
164 165
165static void __exit jmicron_ide_exit(void) 166static void __exit jmicron_ide_exit(void)
166{ 167{
167 pci_unregister_driver(&driver); 168 pci_unregister_driver(&jmicron_pci_driver);
168} 169}
169 170
170module_init(jmicron_ide_init); 171module_init(jmicron_ide_init);
diff --git a/drivers/ide/legacy/Makefile b/drivers/ide/legacy/Makefile
deleted file mode 100644
index 6939329f89e8..000000000000
--- a/drivers/ide/legacy/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
1
2# link order is important here
3
4obj-$(CONFIG_BLK_DEV_ALI14XX) += ali14xx.o
5obj-$(CONFIG_BLK_DEV_UMC8672) += umc8672.o
6obj-$(CONFIG_BLK_DEV_DTC2278) += dtc2278.o
7obj-$(CONFIG_BLK_DEV_HT6560B) += ht6560b.o
8obj-$(CONFIG_BLK_DEV_QD65XX) += qd65xx.o
9obj-$(CONFIG_BLK_DEV_4DRIVES) += ide-4drives.o
10
11obj-$(CONFIG_BLK_DEV_GAYLE) += gayle.o
12obj-$(CONFIG_BLK_DEV_FALCON_IDE) += falconide.o
13obj-$(CONFIG_BLK_DEV_MAC_IDE) += macide.o
14obj-$(CONFIG_BLK_DEV_Q40IDE) += q40ide.o
15obj-$(CONFIG_BLK_DEV_BUDDHA) += buddha.o
16
17ifeq ($(CONFIG_BLK_DEV_IDECS), m)
18 obj-m += ide-cs.o
19endif
20
21ifeq ($(CONFIG_BLK_DEV_PLATFORM), m)
22 obj-m += ide_platform.o
23endif
24
25EXTRA_CFLAGS := -Idrivers/ide
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/macide.c
index a0bb167980e7..43f97cc1d30e 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/macide.c
@@ -15,7 +15,6 @@
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/blkdev.h> 17#include <linux/blkdev.h>
18#include <linux/hdreg.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/ide.h> 19#include <linux/ide.h>
21 20
diff --git a/drivers/ide/mips/Makefile b/drivers/ide/mips/Makefile
deleted file mode 100644
index 5873fa0b8769..000000000000
--- a/drivers/ide/mips/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o
2
3EXTRA_CFLAGS := -Idrivers/ide
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/ns87415.c
index ffefcd15196c..13789060f407 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/ns87415.c
@@ -11,7 +11,6 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/hdreg.h>
15#include <linux/pci.h> 14#include <linux/pci.h>
16#include <linux/delay.h> 15#include <linux/delay.h>
17#include <linux/ide.h> 16#include <linux/ide.h>
@@ -138,7 +137,7 @@ static void __devinit superio_init_iops(struct hwif_s *hwif)
138static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 }; 137static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 };
139 138
140/* 139/*
141 * This routine either enables/disables (according to drive->present) 140 * This routine either enables/disables (according to IDE_DFLAG_PRESENT)
142 * the IRQ associated with the port (HWIF(drive)), 141 * the IRQ associated with the port (HWIF(drive)),
143 * and selects either PIO or DMA handshaking for the next I/O operation. 142 * and selects either PIO or DMA handshaking for the next I/O operation.
144 */ 143 */
@@ -154,11 +153,15 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
154 153
155 /* Adjust IRQ enable bit */ 154 /* Adjust IRQ enable bit */
156 bit = 1 << (8 + hwif->channel); 155 bit = 1 << (8 + hwif->channel);
157 new = drive->present ? (new & ~bit) : (new | bit); 156
157 if (drive->dev_flags & IDE_DFLAG_PRESENT)
158 new &= ~bit;
159 else
160 new |= bit;
158 161
159 /* Select PIO or DMA, DMA may only be selected for one drive/channel. */ 162 /* Select PIO or DMA, DMA may only be selected for one drive/channel. */
160 bit = 1 << (20 + drive->select.b.unit + (hwif->channel << 1)); 163 bit = 1 << (20 + (drive->dn & 1) + (hwif->channel << 1));
161 other = 1 << (20 + (1 - drive->select.b.unit) + (hwif->channel << 1)); 164 other = 1 << (20 + (1 - (drive->dn & 1)) + (hwif->channel << 1));
162 new = use_dma ? ((new & ~other) | bit) : (new & ~bit); 165 new = use_dma ? ((new & ~other) | bit) : (new & ~bit);
163 166
164 if (new != *old) { 167 if (new != *old) {
@@ -188,7 +191,8 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
188 191
189static void ns87415_selectproc (ide_drive_t *drive) 192static void ns87415_selectproc (ide_drive_t *drive)
190{ 193{
191 ns87415_prepare_drive (drive, drive->using_dma); 194 ns87415_prepare_drive(drive,
195 !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
192} 196}
193 197
194static int ns87415_dma_end(ide_drive_t *drive) 198static int ns87415_dma_end(ide_drive_t *drive)
@@ -274,9 +278,9 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
274 do { 278 do {
275 udelay(50); 279 udelay(50);
276 stat = hwif->tp_ops->read_status(hwif); 280 stat = hwif->tp_ops->read_status(hwif);
277 if (stat == 0xff) 281 if (stat == 0xff)
278 break; 282 break;
279 } while ((stat & BUSY_STAT) && --timeout); 283 } while ((stat & ATA_BUSY) && --timeout);
280#endif 284#endif
281 } 285 }
282 286
@@ -335,21 +339,23 @@ static const struct pci_device_id ns87415_pci_tbl[] = {
335}; 339};
336MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl); 340MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl);
337 341
338static struct pci_driver driver = { 342static struct pci_driver ns87415_pci_driver = {
339 .name = "NS87415_IDE", 343 .name = "NS87415_IDE",
340 .id_table = ns87415_pci_tbl, 344 .id_table = ns87415_pci_tbl,
341 .probe = ns87415_init_one, 345 .probe = ns87415_init_one,
342 .remove = ide_pci_remove, 346 .remove = ide_pci_remove,
347 .suspend = ide_pci_suspend,
348 .resume = ide_pci_resume,
343}; 349};
344 350
345static int __init ns87415_ide_init(void) 351static int __init ns87415_ide_init(void)
346{ 352{
347 return ide_pci_register_driver(&driver); 353 return ide_pci_register_driver(&ns87415_pci_driver);
348} 354}
349 355
350static void __exit ns87415_ide_exit(void) 356static void __exit ns87415_ide_exit(void)
351{ 357{
352 pci_unregister_driver(&driver); 358 pci_unregister_driver(&ns87415_pci_driver);
353} 359}
354 360
355module_init(ns87415_ide_init); 361module_init(ns87415_ide_init);
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/opti621.c
index e28e672ddafc..6048eda3cd61 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/opti621.c
@@ -85,7 +85,6 @@
85#include <linux/module.h> 85#include <linux/module.h>
86#include <linux/kernel.h> 86#include <linux/kernel.h>
87#include <linux/pci.h> 87#include <linux/pci.h>
88#include <linux/hdreg.h>
89#include <linux/ide.h> 88#include <linux/ide.h>
90 89
91#include <asm/io.h> 90#include <asm/io.h>
@@ -137,7 +136,7 @@ static u8 read_reg(int reg)
137static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio) 136static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
138{ 137{
139 ide_hwif_t *hwif = drive->hwif; 138 ide_hwif_t *hwif = drive->hwif;
140 ide_drive_t *pair = ide_get_paired_drive(drive); 139 ide_drive_t *pair = ide_get_pair_dev(drive);
141 unsigned long flags; 140 unsigned long flags;
142 u8 tim, misc, addr_pio = pio, clk; 141 u8 tim, misc, addr_pio = pio, clk;
143 142
@@ -153,7 +152,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
153 152
154 drive->drive_data = XFER_PIO_0 + pio; 153 drive->drive_data = XFER_PIO_0 + pio;
155 154
156 if (pair->present) { 155 if (pair) {
157 if (pair->drive_data && pair->drive_data < drive->drive_data) 156 if (pair->drive_data && pair->drive_data < drive->drive_data)
158 addr_pio = pair->drive_data - XFER_PIO_0; 157 addr_pio = pair->drive_data - XFER_PIO_0;
159 } 158 }
@@ -180,7 +179,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
180 misc = addr_timings[clk][addr_pio]; 179 misc = addr_timings[clk][addr_pio];
181 180
182 /* select Index-0/1 for Register-A/B */ 181 /* select Index-0/1 for Register-A/B */
183 write_reg(drive->select.b.unit, MISC_REG); 182 write_reg(drive->dn & 1, MISC_REG);
184 /* set read cycle timings */ 183 /* set read cycle timings */
185 write_reg(tim, READ_REG); 184 write_reg(tim, READ_REG);
186 /* set write cycle timings */ 185 /* set write cycle timings */
@@ -221,21 +220,23 @@ static const struct pci_device_id opti621_pci_tbl[] = {
221}; 220};
222MODULE_DEVICE_TABLE(pci, opti621_pci_tbl); 221MODULE_DEVICE_TABLE(pci, opti621_pci_tbl);
223 222
224static struct pci_driver driver = { 223static struct pci_driver opti621_pci_driver = {
225 .name = "Opti621_IDE", 224 .name = "Opti621_IDE",
226 .id_table = opti621_pci_tbl, 225 .id_table = opti621_pci_tbl,
227 .probe = opti621_init_one, 226 .probe = opti621_init_one,
228 .remove = ide_pci_remove, 227 .remove = ide_pci_remove,
228 .suspend = ide_pci_suspend,
229 .resume = ide_pci_resume,
229}; 230};
230 231
231static int __init opti621_ide_init(void) 232static int __init opti621_ide_init(void)
232{ 233{
233 return ide_pci_register_driver(&driver); 234 return ide_pci_register_driver(&opti621_pci_driver);
234} 235}
235 236
236static void __exit opti621_ide_exit(void) 237static void __exit opti621_ide_exit(void)
237{ 238{
238 pci_unregister_driver(&driver); 239 pci_unregister_driver(&opti621_pci_driver);
239} 240}
240 241
241module_init(opti621_ide_init); 242module_init(opti621_ide_init);
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/palm_bk3710.c
index 4fd91dcf1dc2..122ed3c072fd 100644
--- a/drivers/ide/arm/palm_bk3710.c
+++ b/drivers/ide/palm_bk3710.c
@@ -27,7 +27,6 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/ioport.h> 29#include <linux/ioport.h>
30#include <linux/hdreg.h>
31#include <linux/ide.h> 30#include <linux/ide.h>
32#include <linux/delay.h> 31#include <linux/delay.h>
33#include <linux/init.h> 32#include <linux/init.h>
@@ -180,7 +179,7 @@ static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
180 val32 |= (t2i << (dev ? 8 : 0)); 179 val32 |= (t2i << (dev ? 8 : 0));
181 writel(val32, base + BK3710_DATRCVR); 180 writel(val32, base + BK3710_DATRCVR);
182 181
183 if (mate && mate->present) { 182 if (mate) {
184 u8 mode2 = ide_get_best_pio_mode(mate, 255, 4); 183 u8 mode2 = ide_get_best_pio_mode(mate, 255, 4);
185 184
186 if (mode2 < mode) 185 if (mode2 < mode)
@@ -213,7 +212,8 @@ static void palm_bk3710_set_dma_mode(ide_drive_t *drive, u8 xferspeed)
213 palm_bk3710_setudmamode(base, is_slave, 212 palm_bk3710_setudmamode(base, is_slave,
214 xferspeed - XFER_UDMA_0); 213 xferspeed - XFER_UDMA_0);
215 } else { 214 } else {
216 palm_bk3710_setdmamode(base, is_slave, drive->id->eide_dma_min, 215 palm_bk3710_setdmamode(base, is_slave,
216 drive->id[ATA_ID_EIDE_DMA_MIN],
217 xferspeed); 217 xferspeed);
218 } 218 }
219} 219}
@@ -229,7 +229,7 @@ static void palm_bk3710_set_pio_mode(ide_drive_t *drive, u8 pio)
229 * Obtain the drive PIO data for tuning the Palm Chip registers 229 * Obtain the drive PIO data for tuning the Palm Chip registers
230 */ 230 */
231 cycle_time = ide_pio_cycle_time(drive, pio); 231 cycle_time = ide_pio_cycle_time(drive, pio);
232 mate = ide_get_paired_drive(drive); 232 mate = ide_get_pair_dev(drive);
233 palm_bk3710_setpiomode(base, mate, is_slave, cycle_time, pio); 233 palm_bk3710_setpiomode(base, mate, is_slave, cycle_time, pio);
234} 234}
235 235
diff --git a/drivers/ide/pci/Makefile b/drivers/ide/pci/Makefile
deleted file mode 100644
index 02e6ee7d751d..000000000000
--- a/drivers/ide/pci/Makefile
+++ /dev/null
@@ -1,44 +0,0 @@
1
2obj-$(CONFIG_BLK_DEV_AEC62XX) += aec62xx.o
3obj-$(CONFIG_BLK_DEV_ALI15X3) += alim15x3.o
4obj-$(CONFIG_BLK_DEV_AMD74XX) += amd74xx.o
5obj-$(CONFIG_BLK_DEV_ATIIXP) += atiixp.o
6obj-$(CONFIG_BLK_DEV_CELLEB) += scc_pata.o
7obj-$(CONFIG_BLK_DEV_CMD64X) += cmd64x.o
8obj-$(CONFIG_BLK_DEV_CS5520) += cs5520.o
9obj-$(CONFIG_BLK_DEV_CS5530) += cs5530.o
10obj-$(CONFIG_BLK_DEV_CS5535) += cs5535.o
11obj-$(CONFIG_BLK_DEV_SC1200) += sc1200.o
12obj-$(CONFIG_BLK_DEV_CY82C693) += cy82c693.o
13obj-$(CONFIG_BLK_DEV_DELKIN) += delkin_cb.o
14obj-$(CONFIG_BLK_DEV_HPT34X) += hpt34x.o
15obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o
16obj-$(CONFIG_BLK_DEV_IT8213) += it8213.o
17obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o
18obj-$(CONFIG_BLK_DEV_JMICRON) += jmicron.o
19obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o
20obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o
21obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o
22obj-$(CONFIG_BLK_DEV_PDC202XX_NEW) += pdc202xx_new.o
23obj-$(CONFIG_BLK_DEV_PIIX) += piix.o
24obj-$(CONFIG_BLK_DEV_RZ1000) += rz1000.o
25obj-$(CONFIG_BLK_DEV_SVWKS) += serverworks.o
26obj-$(CONFIG_BLK_DEV_SGIIOC4) += sgiioc4.o
27obj-$(CONFIG_BLK_DEV_SIIMAGE) += siimage.o
28obj-$(CONFIG_BLK_DEV_SIS5513) += sis5513.o
29obj-$(CONFIG_BLK_DEV_SL82C105) += sl82c105.o
30obj-$(CONFIG_BLK_DEV_SLC90E66) += slc90e66.o
31obj-$(CONFIG_BLK_DEV_TC86C001) += tc86c001.o
32obj-$(CONFIG_BLK_DEV_TRIFLEX) += triflex.o
33obj-$(CONFIG_BLK_DEV_TRM290) += trm290.o
34obj-$(CONFIG_BLK_DEV_VIA82CXXX) += via82cxxx.o
35
36# Must appear at the end of the block
37obj-$(CONFIG_BLK_DEV_GENERIC) += ide-pci-generic.o
38ide-pci-generic-y += generic.o
39
40ifeq ($(CONFIG_BLK_DEV_CMD640), m)
41 obj-m += cmd640.o
42endif
43
44EXTRA_CFLAGS := -Idrivers/ide
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
deleted file mode 100644
index 6009b0b9655d..000000000000
--- a/drivers/ide/pci/hpt34x.c
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
3 *
4 * May be copied or modified under the terms of the GNU General Public License
5 *
6 *
7 * 00:12.0 Unknown mass storage controller:
8 * Triones Technologies, Inc.
9 * Unknown device 0003 (rev 01)
10 *
11 * hde: UDMA 2 (0x0000 0x0002) (0x0000 0x0010)
12 * hdf: UDMA 2 (0x0002 0x0012) (0x0010 0x0030)
13 * hde: DMA 2 (0x0000 0x0002) (0x0000 0x0010)
14 * hdf: DMA 2 (0x0002 0x0012) (0x0010 0x0030)
15 * hdg: DMA 1 (0x0012 0x0052) (0x0030 0x0070)
16 * hdh: DMA 1 (0x0052 0x0252) (0x0070 0x00f0)
17 *
18 * ide-pci.c reference
19 *
20 * Since there are two cards that report almost identically,
21 * the only discernable difference is the values reported in pcicmd.
22 * Booting-BIOS card or HPT363 :: pcicmd == 0x07
23 * Non-bootable card or HPT343 :: pcicmd == 0x05
24 */
25
26#include <linux/module.h>
27#include <linux/types.h>
28#include <linux/kernel.h>
29#include <linux/ioport.h>
30#include <linux/hdreg.h>
31#include <linux/interrupt.h>
32#include <linux/pci.h>
33#include <linux/init.h>
34#include <linux/ide.h>
35
36#define DRV_NAME "hpt34x"
37
38#define HPT343_DEBUG_DRIVE_INFO 0
39
40static void hpt34x_set_mode(ide_drive_t *drive, const u8 speed)
41{
42 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
43 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0;
44 u8 hi_speed, lo_speed;
45
46 hi_speed = speed >> 4;
47 lo_speed = speed & 0x0f;
48
49 if (hi_speed & 7) {
50 hi_speed = (hi_speed & 4) ? 0x01 : 0x10;
51 } else {
52 lo_speed <<= 5;
53 lo_speed >>= 5;
54 }
55
56 pci_read_config_dword(dev, 0x44, &reg1);
57 pci_read_config_dword(dev, 0x48, &reg2);
58 tmp1 = ((lo_speed << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn))));
59 tmp2 = ((hi_speed << drive->dn) | (reg2 & ~(0x11 << drive->dn)));
60 pci_write_config_dword(dev, 0x44, tmp1);
61 pci_write_config_dword(dev, 0x48, tmp2);
62
63#if HPT343_DEBUG_DRIVE_INFO
64 printk("%s: %s drive%d (0x%04x 0x%04x) (0x%04x 0x%04x)" \
65 " (0x%02x 0x%02x)\n",
66 drive->name, ide_xfer_verbose(speed),
67 drive->dn, reg1, tmp1, reg2, tmp2,
68 hi_speed, lo_speed);
69#endif /* HPT343_DEBUG_DRIVE_INFO */
70}
71
72static void hpt34x_set_pio_mode(ide_drive_t *drive, const u8 pio)
73{
74 hpt34x_set_mode(drive, XFER_PIO_0 + pio);
75}
76
77/*
78 * If the BIOS does not set the IO base addaress to XX00, 343 will fail.
79 */
80#define HPT34X_PCI_INIT_REG 0x80
81
82static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev)
83{
84 int i = 0;
85 unsigned long hpt34xIoBase = pci_resource_start(dev, 4);
86 unsigned long hpt_addr[4] = { 0x20, 0x34, 0x28, 0x3c };
87 unsigned long hpt_addr_len[4] = { 7, 3, 7, 3 };
88 u16 cmd;
89 unsigned long flags;
90
91 local_irq_save(flags);
92
93 pci_write_config_byte(dev, HPT34X_PCI_INIT_REG, 0x00);
94 pci_read_config_word(dev, PCI_COMMAND, &cmd);
95
96 if (cmd & PCI_COMMAND_MEMORY)
97 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0);
98 else
99 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
100
101 /*
102 * Since 20-23 can be assigned and are R/W, we correct them.
103 */
104 pci_write_config_word(dev, PCI_COMMAND, cmd & ~PCI_COMMAND_IO);
105 for(i=0; i<4; i++) {
106 dev->resource[i].start = (hpt34xIoBase + hpt_addr[i]);
107 dev->resource[i].end = dev->resource[i].start + hpt_addr_len[i];
108 dev->resource[i].flags = IORESOURCE_IO;
109 pci_write_config_dword(dev,
110 (PCI_BASE_ADDRESS_0 + (i * 4)),
111 dev->resource[i].start);
112 }
113 pci_write_config_word(dev, PCI_COMMAND, cmd);
114
115 local_irq_restore(flags);
116
117 return dev->irq;
118}
119
120static const struct ide_port_ops hpt34x_port_ops = {
121 .set_pio_mode = hpt34x_set_pio_mode,
122 .set_dma_mode = hpt34x_set_mode,
123};
124
125#define IDE_HFLAGS_HPT34X \
126 (IDE_HFLAG_NO_ATAPI_DMA | \
127 IDE_HFLAG_NO_DSC | \
128 IDE_HFLAG_NO_AUTODMA)
129
130static const struct ide_port_info hpt34x_chipsets[] __devinitdata = {
131 { /* 0: HPT343 */
132 .name = DRV_NAME,
133 .init_chipset = init_chipset_hpt34x,
134 .port_ops = &hpt34x_port_ops,
135 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_NON_BOOTABLE,
136 .pio_mask = ATA_PIO5,
137 },
138 { /* 1: HPT345 */
139 .name = DRV_NAME,
140 .init_chipset = init_chipset_hpt34x,
141 .port_ops = &hpt34x_port_ops,
142 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_OFF_BOARD,
143 .pio_mask = ATA_PIO5,
144#ifdef CONFIG_HPT34X_AUTODMA
145 .swdma_mask = ATA_SWDMA2,
146 .mwdma_mask = ATA_MWDMA2,
147 .udma_mask = ATA_UDMA2,
148#endif
149 }
150};
151
152static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
153{
154 const struct ide_port_info *d;
155 u16 pcicmd = 0;
156
157 pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
158
159 d = &hpt34x_chipsets[(pcicmd & PCI_COMMAND_MEMORY) ? 1 : 0];
160
161 return ide_pci_init_one(dev, d, NULL);
162}
163
164static const struct pci_device_id hpt34x_pci_tbl[] = {
165 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT343), 0 },
166 { 0, },
167};
168MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl);
169
170static struct pci_driver driver = {
171 .name = "HPT34x_IDE",
172 .id_table = hpt34x_pci_tbl,
173 .probe = hpt34x_init_one,
174 .remove = ide_pci_remove,
175};
176
177static int __init hpt34x_ide_init(void)
178{
179 return ide_pci_register_driver(&driver);
180}
181
182static void __exit hpt34x_ide_exit(void)
183{
184 pci_unregister_driver(&driver);
185}
186
187module_init(hpt34x_ide_init);
188module_exit(hpt34x_ide_exit);
189
190MODULE_AUTHOR("Andre Hedrick");
191MODULE_DESCRIPTION("PCI driver module for Highpoint 34x IDE");
192MODULE_LICENSE("GPL");
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
index d477da6b5858..211ae46e3e0c 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pdc202xx_new.c
@@ -19,7 +19,6 @@
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/hdreg.h>
23#include <linux/pci.h> 22#include <linux/pci.h>
24#include <linux/init.h> 23#include <linux/init.h>
25#include <linux/ide.h> 24#include <linux/ide.h>
@@ -203,10 +202,10 @@ static u8 pdcnew_cable_detect(ide_hwif_t *hwif)
203 202
204static void pdcnew_quirkproc(ide_drive_t *drive) 203static void pdcnew_quirkproc(ide_drive_t *drive)
205{ 204{
206 const char **list, *model = drive->id->model; 205 const char **list, *m = (char *)&drive->id[ATA_ID_PROD];
207 206
208 for (list = pdc_quirk_drives; *list != NULL; list++) 207 for (list = pdc_quirk_drives; *list != NULL; list++)
209 if (strstr(model, *list) != NULL) { 208 if (strstr(m, *list) != NULL) {
210 drive->quirk_list = 2; 209 drive->quirk_list = 2;
211 return; 210 return;
212 } 211 }
@@ -227,7 +226,7 @@ static void pdcnew_reset(ide_drive_t *drive)
227 * read_counter - Read the byte count registers 226 * read_counter - Read the byte count registers
228 * @dma_base: for the port address 227 * @dma_base: for the port address
229 */ 228 */
230static long __devinit read_counter(u32 dma_base) 229static long read_counter(u32 dma_base)
231{ 230{
232 u32 pri_dma_base = dma_base, sec_dma_base = dma_base + 0x08; 231 u32 pri_dma_base = dma_base, sec_dma_base = dma_base + 0x08;
233 u8 cnt0, cnt1, cnt2, cnt3; 232 u8 cnt0, cnt1, cnt2, cnt3;
@@ -267,7 +266,7 @@ static long __devinit read_counter(u32 dma_base)
267 * @dma_base: for the port address 266 * @dma_base: for the port address
268 * E.g. 16949000 on 33 MHz PCI bus, i.e. half of the PCI clock. 267 * E.g. 16949000 on 33 MHz PCI bus, i.e. half of the PCI clock.
269 */ 268 */
270static long __devinit detect_pll_input_clock(unsigned long dma_base) 269static long detect_pll_input_clock(unsigned long dma_base)
271{ 270{
272 struct timeval start_time, end_time; 271 struct timeval start_time, end_time;
273 long start_count, end_count; 272 long start_count, end_count;
@@ -310,7 +309,7 @@ static long __devinit detect_pll_input_clock(unsigned long dma_base)
310} 309}
311 310
312#ifdef CONFIG_PPC_PMAC 311#ifdef CONFIG_PPC_PMAC
313static void __devinit apple_kiwi_init(struct pci_dev *pdev) 312static void apple_kiwi_init(struct pci_dev *pdev)
314{ 313{
315 struct device_node *np = pci_device_to_OF_node(pdev); 314 struct device_node *np = pci_device_to_OF_node(pdev);
316 u8 conf; 315 u8 conf;
@@ -326,7 +325,7 @@ static void __devinit apple_kiwi_init(struct pci_dev *pdev)
326} 325}
327#endif /* CONFIG_PPC_PMAC */ 326#endif /* CONFIG_PPC_PMAC */
328 327
329static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev) 328static unsigned int init_chipset_pdcnew(struct pci_dev *dev)
330{ 329{
331 const char *name = DRV_NAME; 330 const char *name = DRV_NAME;
332 unsigned long dma_base = pci_resource_start(dev, 4); 331 unsigned long dma_base = pci_resource_start(dev, 4);
@@ -562,21 +561,23 @@ static const struct pci_device_id pdc202new_pci_tbl[] = {
562}; 561};
563MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl); 562MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
564 563
565static struct pci_driver driver = { 564static struct pci_driver pdc202new_pci_driver = {
566 .name = "Promise_IDE", 565 .name = "Promise_IDE",
567 .id_table = pdc202new_pci_tbl, 566 .id_table = pdc202new_pci_tbl,
568 .probe = pdc202new_init_one, 567 .probe = pdc202new_init_one,
569 .remove = __devexit_p(pdc202new_remove), 568 .remove = __devexit_p(pdc202new_remove),
569 .suspend = ide_pci_suspend,
570 .resume = ide_pci_resume,
570}; 571};
571 572
572static int __init pdc202new_ide_init(void) 573static int __init pdc202new_ide_init(void)
573{ 574{
574 return ide_pci_register_driver(&driver); 575 return ide_pci_register_driver(&pdc202new_pci_driver);
575} 576}
576 577
577static void __exit pdc202new_ide_exit(void) 578static void __exit pdc202new_ide_exit(void)
578{ 579{
579 pci_unregister_driver(&driver); 580 pci_unregister_driver(&pdc202new_pci_driver);
580} 581}
581 582
582module_init(pdc202new_ide_init); 583module_init(pdc202new_ide_init);
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index de9a27400462..799557c25eef 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -13,7 +13,6 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/hdreg.h>
17#include <linux/pci.h> 16#include <linux/pci.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/ide.h> 18#include <linux/ide.h>
@@ -86,7 +85,7 @@ static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed)
86 * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A 85 * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A
87 */ 86 */
88 AP &= ~0x3f; 87 AP &= ~0x3f;
89 if (drive->id->capability & 4) 88 if (ata_id_iordy_disable(drive->id))
90 AP |= 0x20; /* set IORDY_EN bit */ 89 AP |= 0x20; /* set IORDY_EN bit */
91 if (drive->media == ide_disk) 90 if (drive->media == ide_disk)
92 AP |= 0x10; /* set Prefetch_EN bit */ 91 AP |= 0x10; /* set Prefetch_EN bit */
@@ -154,10 +153,10 @@ static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
154 153
155static void pdc202xx_quirkproc(ide_drive_t *drive) 154static void pdc202xx_quirkproc(ide_drive_t *drive)
156{ 155{
157 const char **list, *model = drive->id->model; 156 const char **list, *m = (char *)&drive->id[ATA_ID_PROD];
158 157
159 for (list = pdc_quirk_drives; *list != NULL; list++) 158 for (list = pdc_quirk_drives; *list != NULL; list++)
160 if (strstr(model, *list) != NULL) { 159 if (strstr(m, *list) != NULL) {
161 drive->quirk_list = 2; 160 drive->quirk_list = 2;
162 return; 161 return;
163 } 162 }
@@ -169,7 +168,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
169{ 168{
170 if (drive->current_speed > XFER_UDMA_2) 169 if (drive->current_speed > XFER_UDMA_2)
171 pdc_old_enable_66MHz_clock(drive->hwif); 170 pdc_old_enable_66MHz_clock(drive->hwif);
172 if (drive->media != ide_disk || drive->addressing == 1) { 171 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
173 struct request *rq = HWGROUP(drive)->rq; 172 struct request *rq = HWGROUP(drive)->rq;
174 ide_hwif_t *hwif = HWIF(drive); 173 ide_hwif_t *hwif = HWIF(drive);
175 unsigned long high_16 = hwif->extra_base - 16; 174 unsigned long high_16 = hwif->extra_base - 16;
@@ -189,7 +188,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
189 188
190static int pdc202xx_dma_end(ide_drive_t *drive) 189static int pdc202xx_dma_end(ide_drive_t *drive)
191{ 190{
192 if (drive->media != ide_disk || drive->addressing == 1) { 191 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
193 ide_hwif_t *hwif = HWIF(drive); 192 ide_hwif_t *hwif = HWIF(drive);
194 unsigned long high_16 = hwif->extra_base - 16; 193 unsigned long high_16 = hwif->extra_base - 16;
195 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
@@ -201,7 +200,7 @@ static int pdc202xx_dma_end(ide_drive_t *drive)
201 } 200 }
202 if (drive->current_speed > XFER_UDMA_2) 201 if (drive->current_speed > XFER_UDMA_2)
203 pdc_old_disable_66MHz_clock(drive->hwif); 202 pdc_old_disable_66MHz_clock(drive->hwif);
204 return __ide_dma_end(drive); 203 return ide_dma_end(drive);
205} 204}
206 205
207static int pdc202xx_dma_test_irq(ide_drive_t *drive) 206static int pdc202xx_dma_test_irq(ide_drive_t *drive)
@@ -265,7 +264,7 @@ static void pdc202xx_dma_timeout(ide_drive_t *drive)
265 ide_dma_timeout(drive); 264 ide_dma_timeout(drive);
266} 265}
267 266
268static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev) 267static unsigned int init_chipset_pdc202xx(struct pci_dev *dev)
269{ 268{
270 unsigned long dmabase = pci_resource_start(dev, 4); 269 unsigned long dmabase = pci_resource_start(dev, 4);
271 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0; 270 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
@@ -334,7 +333,7 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
334 .dma_setup = ide_dma_setup, 333 .dma_setup = ide_dma_setup,
335 .dma_exec_cmd = ide_dma_exec_cmd, 334 .dma_exec_cmd = ide_dma_exec_cmd,
336 .dma_start = ide_dma_start, 335 .dma_start = ide_dma_start,
337 .dma_end = __ide_dma_end, 336 .dma_end = ide_dma_end,
338 .dma_test_irq = pdc202xx_dma_test_irq, 337 .dma_test_irq = pdc202xx_dma_test_irq,
339 .dma_lost_irq = pdc202xx_dma_lost_irq, 338 .dma_lost_irq = pdc202xx_dma_lost_irq,
340 .dma_timeout = pdc202xx_dma_timeout, 339 .dma_timeout = pdc202xx_dma_timeout,
@@ -427,21 +426,23 @@ static const struct pci_device_id pdc202xx_pci_tbl[] = {
427}; 426};
428MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl); 427MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
429 428
430static struct pci_driver driver = { 429static struct pci_driver pdc202xx_pci_driver = {
431 .name = "Promise_Old_IDE", 430 .name = "Promise_Old_IDE",
432 .id_table = pdc202xx_pci_tbl, 431 .id_table = pdc202xx_pci_tbl,
433 .probe = pdc202xx_init_one, 432 .probe = pdc202xx_init_one,
434 .remove = ide_pci_remove, 433 .remove = ide_pci_remove,
434 .suspend = ide_pci_suspend,
435 .resume = ide_pci_resume,
435}; 436};
436 437
437static int __init pdc202xx_ide_init(void) 438static int __init pdc202xx_ide_init(void)
438{ 439{
439 return ide_pci_register_driver(&driver); 440 return ide_pci_register_driver(&pdc202xx_pci_driver);
440} 441}
441 442
442static void __exit pdc202xx_ide_exit(void) 443static void __exit pdc202xx_ide_exit(void)
443{ 444{
444 pci_unregister_driver(&driver); 445 pci_unregister_driver(&pdc202xx_pci_driver);
445} 446}
446 447
447module_init(pdc202xx_ide_init); 448module_init(pdc202xx_ide_init);
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/piix.c
index 30cfc815fe31..61d2d920a5cd 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/piix.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer 2 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
3 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 3 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
4 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com> 4 * Copyright (C) 2003 Red Hat
5 * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com> 5 * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com>
6 * 6 *
7 * May be copied or modified under the terms of the GNU General Public License 7 * May be copied or modified under the terms of the GNU General Public License
@@ -48,7 +48,6 @@
48#include <linux/module.h> 48#include <linux/module.h>
49#include <linux/kernel.h> 49#include <linux/kernel.h>
50#include <linux/pci.h> 50#include <linux/pci.h>
51#include <linux/hdreg.h>
52#include <linux/ide.h> 51#include <linux/ide.h>
53#include <linux/init.h> 52#include <linux/init.h>
54 53
@@ -205,7 +204,7 @@ static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed)
205 * out to be nice and simple. 204 * out to be nice and simple.
206 */ 205 */
207 206
208static unsigned int __devinit init_chipset_ich(struct pci_dev *dev) 207static unsigned int init_chipset_ich(struct pci_dev *dev)
209{ 208{
210 u32 extra = 0; 209 u32 extra = 0;
211 210
@@ -216,17 +215,26 @@ static unsigned int __devinit init_chipset_ich(struct pci_dev *dev)
216} 215}
217 216
218/** 217/**
219 * piix_dma_clear_irq - clear BMDMA status 218 * ich_clear_irq - clear BMDMA status
220 * @drive: IDE drive to clear 219 * @drive: IDE drive
221 * 220 *
222 * Called from ide_intr() for PIO interrupts 221 * ICHx contollers set DMA INTR no matter DMA or PIO.
223 * to clear BMDMA status as needed by ICHx 222 * BMDMA status might need to be cleared even for
223 * PIO interrupts to prevent spurious/lost IRQ.
224 */ 224 */
225static void piix_dma_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 = HWIF(drive);
228 u8 dma_stat; 228 u8 dma_stat;
229 229
230 /*
231 * ide_dma_end() needs BMDMA status for error checking.
232 * So, skip clearing BMDMA status here and leave it
233 * to ide_dma_end() if this is DMA interrupt.
234 */
235 if (drive->waiting_for_dma || hwif->dma_base == 0)
236 return;
237
230 /* clear the INTR & ERROR bits */ 238 /* clear the INTR & ERROR bits */
231 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 239 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
232 /* Should we force the bit as well ? */ 240 /* Should we force the bit as well ? */
@@ -250,6 +258,7 @@ static const struct ich_laptop ich_laptop[] = {
250 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 258 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
251 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 259 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
252 { 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 */
253 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */ 262 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */
254 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 263 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
255 /* end marker */ 264 /* end marker */
@@ -294,21 +303,19 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
294 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0; 303 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
295} 304}
296 305
297static void __devinit init_hwif_ich(ide_hwif_t *hwif)
298{
299 init_hwif_piix(hwif);
300
301 /* ICHx need to clear the BMDMA status for all interrupts */
302 if (hwif->dma_base)
303 hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
304}
305
306static const struct ide_port_ops piix_port_ops = { 306static const struct ide_port_ops piix_port_ops = {
307 .set_pio_mode = piix_set_pio_mode, 307 .set_pio_mode = piix_set_pio_mode,
308 .set_dma_mode = piix_set_dma_mode, 308 .set_dma_mode = piix_set_dma_mode,
309 .cable_detect = piix_cable_detect, 309 .cable_detect = piix_cable_detect,
310}; 310};
311 311
312static const struct ide_port_ops ich_port_ops = {
313 .set_pio_mode = piix_set_pio_mode,
314 .set_dma_mode = piix_set_dma_mode,
315 .clear_irq = ich_clear_irq,
316 .cable_detect = piix_cable_detect,
317};
318
312#ifndef CONFIG_IA64 319#ifndef CONFIG_IA64
313 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS 320 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS
314#else 321#else
@@ -332,9 +339,9 @@ static const struct ide_port_ops piix_port_ops = {
332 { \ 339 { \
333 .name = DRV_NAME, \ 340 .name = DRV_NAME, \
334 .init_chipset = init_chipset_ich, \ 341 .init_chipset = init_chipset_ich, \
335 .init_hwif = init_hwif_ich, \ 342 .init_hwif = init_hwif_piix, \
336 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 343 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
337 .port_ops = &piix_port_ops, \ 344 .port_ops = &ich_port_ops, \
338 .host_flags = IDE_HFLAGS_PIIX, \ 345 .host_flags = IDE_HFLAGS_PIIX, \
339 .pio_mask = ATA_PIO4, \ 346 .pio_mask = ATA_PIO4, \
340 .swdma_mask = ATA_SWDMA2_ONLY, \ 347 .swdma_mask = ATA_SWDMA2_ONLY, \
@@ -445,22 +452,24 @@ static const struct pci_device_id piix_pci_tbl[] = {
445}; 452};
446MODULE_DEVICE_TABLE(pci, piix_pci_tbl); 453MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
447 454
448static struct pci_driver driver = { 455static struct pci_driver piix_pci_driver = {
449 .name = "PIIX_IDE", 456 .name = "PIIX_IDE",
450 .id_table = piix_pci_tbl, 457 .id_table = piix_pci_tbl,
451 .probe = piix_init_one, 458 .probe = piix_init_one,
452 .remove = ide_pci_remove, 459 .remove = ide_pci_remove,
460 .suspend = ide_pci_suspend,
461 .resume = ide_pci_resume,
453}; 462};
454 463
455static int __init piix_ide_init(void) 464static int __init piix_ide_init(void)
456{ 465{
457 piix_check_450nx(); 466 piix_check_450nx();
458 return ide_pci_register_driver(&driver); 467 return ide_pci_register_driver(&piix_pci_driver);
459} 468}
460 469
461static void __exit piix_ide_exit(void) 470static void __exit piix_ide_exit(void)
462{ 471{
463 pci_unregister_driver(&driver); 472 pci_unregister_driver(&piix_pci_driver);
464} 473}
465 474
466module_init(piix_ide_init); 475module_init(piix_ide_init);
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/pmac.c
index fa2be26272d5..2e19d6298536 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/pmac.c
@@ -430,10 +430,7 @@ pmac_ide_selectproc(ide_drive_t *drive)
430 pmac_ide_hwif_t *pmif = 430 pmac_ide_hwif_t *pmif =
431 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 431 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
432 432
433 if (pmif == NULL) 433 if (drive->dn & 1)
434 return;
435
436 if (drive->select.b.unit & 0x01)
437 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG)); 434 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
438 else 435 else
439 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG)); 436 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
@@ -452,10 +449,7 @@ pmac_ide_kauai_selectproc(ide_drive_t *drive)
452 pmac_ide_hwif_t *pmif = 449 pmac_ide_hwif_t *pmif =
453 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 450 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
454 451
455 if (pmif == NULL) 452 if (drive->dn & 1) {
456 return;
457
458 if (drive->select.b.unit & 0x01) {
459 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG)); 453 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
460 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG)); 454 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
461 } else { 455 } else {
@@ -475,9 +469,6 @@ pmac_ide_do_update_timings(ide_drive_t *drive)
475 pmac_ide_hwif_t *pmif = 469 pmac_ide_hwif_t *pmif =
476 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 470 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
477 471
478 if (pmif == NULL)
479 return;
480
481 if (pmif->kind == controller_sh_ata6 || 472 if (pmif->kind == controller_sh_ata6 ||
482 pmif->kind == controller_un_ata6 || 473 pmif->kind == controller_un_ata6 ||
483 pmif->kind == controller_k2_ata6) 474 pmif->kind == controller_k2_ata6)
@@ -524,11 +515,8 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
524 unsigned accessTime, recTime; 515 unsigned accessTime, recTime;
525 unsigned int cycle_time; 516 unsigned int cycle_time;
526 517
527 if (pmif == NULL)
528 return;
529
530 /* which drive is it ? */ 518 /* which drive is it ? */
531 timings = &pmif->timings[drive->select.b.unit & 0x01]; 519 timings = &pmif->timings[drive->dn & 1];
532 t = *timings; 520 t = *timings;
533 521
534 cycle_time = ide_pio_cycle_time(drive, pio); 522 cycle_time = ide_pio_cycle_time(drive, pio);
@@ -669,9 +657,9 @@ static void
669set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2, 657set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
670 u8 speed) 658 u8 speed)
671{ 659{
660 u16 *id = drive->id;
672 int cycleTime, accessTime = 0, recTime = 0; 661 int cycleTime, accessTime = 0, recTime = 0;
673 unsigned accessTicks, recTicks; 662 unsigned accessTicks, recTicks;
674 struct hd_driveid *id = drive->id;
675 struct mdma_timings_t* tm = NULL; 663 struct mdma_timings_t* tm = NULL;
676 int i; 664 int i;
677 665
@@ -686,8 +674,8 @@ set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
686 } 674 }
687 675
688 /* Check if drive provides explicit DMA cycle time */ 676 /* Check if drive provides explicit DMA cycle time */
689 if ((id->field_valid & 2) && id->eide_dma_time) 677 if ((id[ATA_ID_FIELD_VALID] & 2) && id[ATA_ID_EIDE_DMA_TIME])
690 cycleTime = max_t(int, id->eide_dma_time, cycleTime); 678 cycleTime = max_t(int, id[ATA_ID_EIDE_DMA_TIME], cycleTime);
691 679
692 /* OHare limits according to some old Apple sources */ 680 /* OHare limits according to some old Apple sources */
693 if ((intf_type == controller_ohare) && (cycleTime < 150)) 681 if ((intf_type == controller_ohare) && (cycleTime < 150))
@@ -805,9 +793,9 @@ static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
805 ide_hwif_t *hwif = drive->hwif; 793 ide_hwif_t *hwif = drive->hwif;
806 pmac_ide_hwif_t *pmif = 794 pmac_ide_hwif_t *pmif =
807 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 795 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
808 int unit = (drive->select.b.unit & 0x01);
809 int ret = 0; 796 int ret = 0;
810 u32 *timings, *timings2, tl[2]; 797 u32 *timings, *timings2, tl[2];
798 u8 unit = drive->dn & 1;
811 799
812 timings = &pmif->timings[unit]; 800 timings = &pmif->timings[unit];
813 timings2 = &pmif->timings[unit+2]; 801 timings2 = &pmif->timings[unit+2];
@@ -966,11 +954,11 @@ static void pmac_ide_init_dev(ide_drive_t *drive)
966 if (pmif->mediabay) { 954 if (pmif->mediabay) {
967#ifdef CONFIG_PMAC_MEDIABAY 955#ifdef CONFIG_PMAC_MEDIABAY
968 if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) { 956 if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) {
969 drive->noprobe = 0; 957 drive->dev_flags &= ~IDE_DFLAG_NOPROBE;
970 return; 958 return;
971 } 959 }
972#endif 960#endif
973 drive->noprobe = 1; 961 drive->dev_flags |= IDE_DFLAG_NOPROBE;
974 } 962 }
975} 963}
976 964
@@ -1535,18 +1523,6 @@ use_pio_instead:
1535 return 0; /* revert to PIO for this request */ 1523 return 0; /* revert to PIO for this request */
1536} 1524}
1537 1525
1538/* Teardown mappings after DMA has completed. */
1539static void
1540pmac_ide_destroy_dmatable (ide_drive_t *drive)
1541{
1542 ide_hwif_t *hwif = drive->hwif;
1543
1544 if (hwif->sg_nents) {
1545 ide_destroy_dmatable(drive);
1546 hwif->sg_nents = 0;
1547 }
1548}
1549
1550/* 1526/*
1551 * Prepare a DMA transfer. We build the DMA table, adjust the timings for 1527 * Prepare a DMA transfer. We build the DMA table, adjust the timings for
1552 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion 1528 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
@@ -1558,12 +1534,7 @@ pmac_ide_dma_setup(ide_drive_t *drive)
1558 pmac_ide_hwif_t *pmif = 1534 pmac_ide_hwif_t *pmif =
1559 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1535 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1560 struct request *rq = HWGROUP(drive)->rq; 1536 struct request *rq = HWGROUP(drive)->rq;
1561 u8 unit = (drive->select.b.unit & 0x01); 1537 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
1562 u8 ata4;
1563
1564 if (pmif == NULL)
1565 return 1;
1566 ata4 = (pmif->kind == controller_kl_ata4);
1567 1538
1568 if (!pmac_ide_build_dmatable(drive, rq)) { 1539 if (!pmac_ide_build_dmatable(drive, rq)) {
1569 ide_map_sg(drive, rq); 1540 ide_map_sg(drive, rq);
@@ -1617,17 +1588,15 @@ pmac_ide_dma_end (ide_drive_t *drive)
1617 ide_hwif_t *hwif = drive->hwif; 1588 ide_hwif_t *hwif = drive->hwif;
1618 pmac_ide_hwif_t *pmif = 1589 pmac_ide_hwif_t *pmif =
1619 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1590 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1620 volatile struct dbdma_regs __iomem *dma; 1591 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1621 u32 dstat; 1592 u32 dstat;
1622
1623 if (pmif == NULL)
1624 return 0;
1625 dma = pmif->dma_regs;
1626 1593
1627 drive->waiting_for_dma = 0; 1594 drive->waiting_for_dma = 0;
1628 dstat = readl(&dma->status); 1595 dstat = readl(&dma->status);
1629 writel(((RUN|WAKE|DEAD) << 16), &dma->control); 1596 writel(((RUN|WAKE|DEAD) << 16), &dma->control);
1630 pmac_ide_destroy_dmatable(drive); 1597
1598 ide_destroy_dmatable(drive);
1599
1631 /* verify good dma status. we don't check for ACTIVE beeing 0. We should... 1600 /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
1632 * in theory, but with ATAPI decices doing buffer underruns, that would 1601 * in theory, but with ATAPI decices doing buffer underruns, that would
1633 * cause us to disable DMA, which isn't what we want 1602 * cause us to disable DMA, which isn't what we want
@@ -1647,13 +1616,9 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1647 ide_hwif_t *hwif = drive->hwif; 1616 ide_hwif_t *hwif = drive->hwif;
1648 pmac_ide_hwif_t *pmif = 1617 pmac_ide_hwif_t *pmif =
1649 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1618 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1650 volatile struct dbdma_regs __iomem *dma; 1619 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1651 unsigned long status, timeout; 1620 unsigned long status, timeout;
1652 1621
1653 if (pmif == NULL)
1654 return 0;
1655 dma = pmif->dma_regs;
1656
1657 /* We have to things to deal with here: 1622 /* We have to things to deal with here:
1658 * 1623 *
1659 * - The dbdma won't stop if the command was started 1624 * - The dbdma won't stop if the command was started
@@ -1672,9 +1637,6 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1672 status = readl(&dma->status); 1637 status = readl(&dma->status);
1673 if (!(status & ACTIVE)) 1638 if (!(status & ACTIVE))
1674 return 1; 1639 return 1;
1675 if (!drive->waiting_for_dma)
1676 printk(KERN_WARNING "ide%d, ide_dma_test_irq \
1677 called while not waiting\n", HWIF(drive)->index);
1678 1640
1679 /* If dbdma didn't execute the STOP command yet, the 1641 /* If dbdma didn't execute the STOP command yet, the
1680 * active bit is still set. We consider that we aren't 1642 * active bit is still set. We consider that we aren't
@@ -1709,14 +1671,9 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
1709 ide_hwif_t *hwif = drive->hwif; 1671 ide_hwif_t *hwif = drive->hwif;
1710 pmac_ide_hwif_t *pmif = 1672 pmac_ide_hwif_t *pmif =
1711 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1673 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1712 volatile struct dbdma_regs __iomem *dma; 1674 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1713 unsigned long status; 1675 unsigned long status = readl(&dma->status);
1714
1715 if (pmif == NULL)
1716 return;
1717 dma = pmif->dma_regs;
1718 1676
1719 status = readl(&dma->status);
1720 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status); 1677 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
1721} 1678}
1722 1679
diff --git a/drivers/ide/ppc/Makefile b/drivers/ide/ppc/Makefile
deleted file mode 100644
index 74e52adcdf4b..000000000000
--- a/drivers/ide/ppc/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
1
2obj-$(CONFIG_BLK_DEV_IDE_PMAC) += pmac.o
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/q40ide.c
index 4abd8fc78197..4af4a8ce4cdf 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/q40ide.c
@@ -14,8 +14,6 @@
14#include <linux/mm.h> 14#include <linux/mm.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/blkdev.h> 16#include <linux/blkdev.h>
17#include <linux/hdreg.h>
18
19#include <linux/ide.h> 17#include <linux/ide.h>
20 18
21 /* 19 /*
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/qd65xx.c
index 2338f344ea24..bc27c7aba936 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/qd65xx.c
@@ -27,7 +27,6 @@
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/ioport.h> 28#include <linux/ioport.h>
29#include <linux/blkdev.h> 29#include <linux/blkdev.h>
30#include <linux/hdreg.h>
31#include <linux/ide.h> 30#include <linux/ide.h>
32#include <linux/init.h> 31#include <linux/init.h>
33#include <asm/system.h> 32#include <asm/system.h>
@@ -151,12 +150,14 @@ static int qd_find_disk_type (ide_drive_t *drive,
151 int *active_time, int *recovery_time) 150 int *active_time, int *recovery_time)
152{ 151{
153 struct qd65xx_timing_s *p; 152 struct qd65xx_timing_s *p;
154 char model[40]; 153 char *m = (char *)&drive->id[ATA_ID_PROD];
154 char model[ATA_ID_PROD_LEN];
155 155
156 if (!*drive->id->model) return 0; 156 if (*m == 0)
157 return 0;
157 158
158 strncpy(model,drive->id->model,40); 159 strncpy(model, m, ATA_ID_PROD_LEN);
159 ide_fixstring(model,40,1); /* byte-swap */ 160 ide_fixstring(model, ATA_ID_PROD_LEN, 1); /* byte-swap */
160 161
161 for (p = qd65xx_timing ; p->offset != -1 ; p++) { 162 for (p = qd65xx_timing ; p->offset != -1 ; p++) {
162 if (!strncmp(p->model, model+p->offset, 4)) { 163 if (!strncmp(p->model, model+p->offset, 4)) {
@@ -185,20 +186,20 @@ static void qd_set_timing (ide_drive_t *drive, u8 timing)
185 186
186static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio) 187static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio)
187{ 188{
189 u16 *id = drive->id;
188 int active_time = 175; 190 int active_time = 175;
189 int recovery_time = 415; /* worst case values from the dos driver */ 191 int recovery_time = 415; /* worst case values from the dos driver */
190 192
191 /* 193 /*
192 * FIXME: use "pio" value 194 * FIXME: use "pio" value
193 */ 195 */
194 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time) 196 if (!qd_find_disk_type(drive, &active_time, &recovery_time) &&
195 && drive->id->tPIO && (drive->id->field_valid & 0x02) 197 (id[ATA_ID_OLD_PIO_MODES] & 0xff) && (id[ATA_ID_FIELD_VALID] & 2) &&
196 && drive->id->eide_pio >= 240) { 198 id[ATA_ID_EIDE_PIO] >= 240) {
197
198 printk(KERN_INFO "%s: PIO mode%d\n", drive->name, 199 printk(KERN_INFO "%s: PIO mode%d\n", drive->name,
199 drive->id->tPIO); 200 id[ATA_ID_OLD_PIO_MODES] & 0xff);
200 active_time = 110; 201 active_time = 110;
201 recovery_time = drive->id->eide_pio - 120; 202 recovery_time = drive->id[ATA_ID_EIDE_PIO] - 120;
202 } 203 }
203 204
204 qd_set_timing(drive, qd6500_compute_timing(HWIF(drive), active_time, recovery_time)); 205 qd_set_timing(drive, qd6500_compute_timing(HWIF(drive), active_time, recovery_time));
@@ -304,7 +305,7 @@ static void __init qd6580_init_dev(ide_drive_t *drive)
304 } else 305 } else
305 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; 306 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA;
306 307
307 drive->drive_data = drive->select.b.unit ? t2 : t1; 308 drive->drive_data = (drive->dn & 1) ? t2 : t1;
308} 309}
309 310
310static const struct ide_port_ops qd6500_port_ops = { 311static const struct ide_port_ops qd6500_port_ops = {
diff --git a/drivers/ide/legacy/qd65xx.h b/drivers/ide/qd65xx.h
index c83dea85e621..c83dea85e621 100644
--- a/drivers/ide/legacy/qd65xx.h
+++ b/drivers/ide/qd65xx.h
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/rapide.c
index 78d27d9ae430..d5003ca69801 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/rapide.c
@@ -11,7 +11,7 @@
11 11
12#include <asm/ecard.h> 12#include <asm/ecard.h>
13 13
14static struct const ide_port_info rapide_port_info = { 14static const struct ide_port_info rapide_port_info = {
15 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, 15 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
16}; 16};
17 17
@@ -97,7 +97,7 @@ static int __init rapide_init(void)
97 97
98static void __exit rapide_exit(void) 98static void __exit rapide_exit(void)
99{ 99{
100 ecard_unregister_driver(&rapide_driver); 100 ecard_remove_driver(&rapide_driver);
101} 101}
102 102
103MODULE_LICENSE("GPL"); 103MODULE_LICENSE("GPL");
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/rz1000.c
index 8d11ee838a2a..7daf0135cbac 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/rz1000.c
@@ -16,7 +16,6 @@
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/hdreg.h>
20#include <linux/pci.h> 19#include <linux/pci.h>
21#include <linux/ide.h> 20#include <linux/ide.h>
22#include <linux/init.h> 21#include <linux/init.h>
@@ -60,7 +59,7 @@ static const struct pci_device_id rz1000_pci_tbl[] = {
60}; 59};
61MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl); 60MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl);
62 61
63static struct pci_driver driver = { 62static struct pci_driver rz1000_pci_driver = {
64 .name = "RZ1000_IDE", 63 .name = "RZ1000_IDE",
65 .id_table = rz1000_pci_tbl, 64 .id_table = rz1000_pci_tbl,
66 .probe = rz1000_init_one, 65 .probe = rz1000_init_one,
@@ -69,12 +68,12 @@ static struct pci_driver driver = {
69 68
70static int __init rz1000_ide_init(void) 69static int __init rz1000_ide_init(void)
71{ 70{
72 return ide_pci_register_driver(&driver); 71 return ide_pci_register_driver(&rz1000_pci_driver);
73} 72}
74 73
75static void __exit rz1000_ide_exit(void) 74static void __exit rz1000_ide_exit(void)
76{ 75{
77 pci_unregister_driver(&driver); 76 pci_unregister_driver(&rz1000_pci_driver);
78} 77}
79 78
80module_init(rz1000_ide_init); 79module_init(rz1000_ide_init);
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/sc1200.c
index 8efaed16fea3..f1a8758e3a99 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/sc1200.c
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/hdreg.h>
18#include <linux/pci.h> 17#include <linux/pci.h>
19#include <linux/init.h> 18#include <linux/init.h>
20#include <linux/ide.h> 19#include <linux/ide.h>
@@ -104,17 +103,19 @@ static void sc1200_tunepio(ide_drive_t *drive, u8 pio)
104static u8 sc1200_udma_filter(ide_drive_t *drive) 103static u8 sc1200_udma_filter(ide_drive_t *drive)
105{ 104{
106 ide_hwif_t *hwif = drive->hwif; 105 ide_hwif_t *hwif = drive->hwif;
107 ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1]; 106 ide_drive_t *mate = ide_get_pair_dev(drive);
108 struct hd_driveid *mateid = mate->id; 107 u16 *mateid = mate->id;
109 u8 mask = hwif->ultra_mask; 108 u8 mask = hwif->ultra_mask;
110 109
111 if (mate->present == 0) 110 if (mate == NULL)
112 goto out; 111 goto out;
113 112
114 if ((mateid->capability & 1) && __ide_dma_bad_drive(mate) == 0) { 113 if (ata_id_has_dma(mateid) && __ide_dma_bad_drive(mate) == 0) {
115 if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7)) 114 if ((mateid[ATA_ID_FIELD_VALID] & 4) &&
115 (mateid[ATA_ID_UDMA_MODES] & 7))
116 goto out; 116 goto out;
117 if ((mateid->field_valid & 2) && (mateid->dma_mword & 7)) 117 if ((mateid[ATA_ID_FIELD_VALID] & 2) &&
118 (mateid[ATA_ID_MWDMA_MODES] & 7))
118 mask = 0; 119 mask = 0;
119 } 120 }
120out: 121out:
@@ -125,7 +126,6 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
125{ 126{
126 ide_hwif_t *hwif = HWIF(drive); 127 ide_hwif_t *hwif = HWIF(drive);
127 struct pci_dev *dev = to_pci_dev(hwif->dev); 128 struct pci_dev *dev = to_pci_dev(hwif->dev);
128 int unit = drive->select.b.unit;
129 unsigned int reg, timings; 129 unsigned int reg, timings;
130 unsigned short pci_clock; 130 unsigned short pci_clock;
131 unsigned int basereg = hwif->channel ? 0x50 : 0x40; 131 unsigned int basereg = hwif->channel ? 0x50 : 0x40;
@@ -154,7 +154,7 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
154 else 154 else
155 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0]; 155 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0];
156 156
157 if (unit == 0) { /* are we configuring drive0? */ 157 if ((drive->dn & 1) == 0) {
158 pci_read_config_dword(dev, basereg + 4, &reg); 158 pci_read_config_dword(dev, basereg + 4, &reg);
159 timings |= reg & 0x80000000; /* preserve PIO format bit */ 159 timings |= reg & 0x80000000; /* preserve PIO format bit */
160 pci_write_config_dword(dev, basereg + 4, timings); 160 pci_write_config_dword(dev, basereg + 4, timings);
@@ -215,7 +215,8 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
215 if (mode != -1) { 215 if (mode != -1) {
216 printk("SC1200: %s: changing (U)DMA mode\n", drive->name); 216 printk("SC1200: %s: changing (U)DMA mode\n", drive->name);
217 ide_dma_off_quietly(drive); 217 ide_dma_off_quietly(drive);
218 if (ide_set_dma_mode(drive, mode) == 0 && drive->using_dma) 218 if (ide_set_dma_mode(drive, mode) == 0 &&
219 (drive->dev_flags & IDE_DFLAG_USING_DMA))
219 hwif->dma_ops->dma_host_set(drive, 1); 220 hwif->dma_ops->dma_host_set(drive, 1);
220 return; 221 return;
221 } 222 }
@@ -327,7 +328,7 @@ static const struct pci_device_id sc1200_pci_tbl[] = {
327}; 328};
328MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl); 329MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl);
329 330
330static struct pci_driver driver = { 331static struct pci_driver sc1200_pci_driver = {
331 .name = "SC1200_IDE", 332 .name = "SC1200_IDE",
332 .id_table = sc1200_pci_tbl, 333 .id_table = sc1200_pci_tbl,
333 .probe = sc1200_init_one, 334 .probe = sc1200_init_one,
@@ -340,12 +341,12 @@ static struct pci_driver driver = {
340 341
341static int __init sc1200_ide_init(void) 342static int __init sc1200_ide_init(void)
342{ 343{
343 return ide_pci_register_driver(&driver); 344 return ide_pci_register_driver(&sc1200_pci_driver);
344} 345}
345 346
346static void __exit sc1200_ide_exit(void) 347static void __exit sc1200_ide_exit(void)
347{ 348{
348 pci_unregister_driver(&driver); 349 pci_unregister_driver(&sc1200_pci_driver);
349} 350}
350 351
351module_init(sc1200_ide_init); 352module_init(sc1200_ide_init);
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/scc_pata.c
index 44cccd1e086a..0f48f9dacfa5 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/scc_pata.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * This code is based on drivers/ide/pci/siimage.c: 6 * This code is based on drivers/ide/pci/siimage.c:
7 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 7 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
8 * Copyright (C) 2003 Red Hat <alan@redhat.com> 8 * Copyright (C) 2003 Red Hat
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -26,7 +26,6 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/hdreg.h>
30#include <linux/ide.h> 29#include <linux/ide.h>
31#include <linux/init.h> 30#include <linux/init.h>
32 31
@@ -292,7 +291,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
292static void scc_dma_host_set(ide_drive_t *drive, int on) 291static void scc_dma_host_set(ide_drive_t *drive, int on)
293{ 292{
294 ide_hwif_t *hwif = drive->hwif; 293 ide_hwif_t *hwif = drive->hwif;
295 u8 unit = (drive->select.b.unit & 0x01); 294 u8 unit = drive->dn & 1;
296 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4); 295 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4);
297 296
298 if (on) 297 if (on)
@@ -354,7 +353,6 @@ static void scc_dma_start(ide_drive_t *drive)
354 353
355 /* start DMA */ 354 /* start DMA */
356 scc_ide_outb(dma_cmd | 1, hwif->dma_base); 355 scc_ide_outb(dma_cmd | 1, hwif->dma_base);
357 hwif->dma = 1;
358 wmb(); 356 wmb();
359} 357}
360 358
@@ -375,7 +373,6 @@ static int __scc_dma_end(ide_drive_t *drive)
375 /* purge DMA mappings */ 373 /* purge DMA mappings */
376 ide_destroy_dmatable(drive); 374 ide_destroy_dmatable(drive);
377 /* verify good DMA status */ 375 /* verify good DMA status */
378 hwif->dma = 0;
379 wmb(); 376 wmb();
380 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; 377 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
381} 378}
@@ -400,7 +397,7 @@ static int scc_dma_end(ide_drive_t *drive)
400 /* errata A308 workaround: Step5 (check data loss) */ 397 /* errata A308 workaround: Step5 (check data loss) */
401 /* We don't check non ide_disk because it is limited to UDMA4 */ 398 /* We don't check non ide_disk because it is limited to UDMA4 */
402 if (!(in_be32((void __iomem *)hwif->io_ports.ctl_addr) 399 if (!(in_be32((void __iomem *)hwif->io_ports.ctl_addr)
403 & ERR_STAT) && 400 & ATA_ERR) &&
404 drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) { 401 drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) {
405 reg = in_be32((void __iomem *)intsts_port); 402 reg = in_be32((void __iomem *)intsts_port);
406 if (!(reg & INTSTS_ACTEINT)) { 403 if (!(reg & INTSTS_ACTEINT)) {
@@ -504,7 +501,7 @@ static int scc_dma_test_irq(ide_drive_t *drive)
504 501
505 /* SCC errata A252,A308 workaround: Step4 */ 502 /* SCC errata A252,A308 workaround: Step4 */
506 if ((in_be32((void __iomem *)hwif->io_ports.ctl_addr) 503 if ((in_be32((void __iomem *)hwif->io_ports.ctl_addr)
507 & ERR_STAT) && 504 & ATA_ERR) &&
508 (int_stat & INTSTS_INTRQ)) 505 (int_stat & INTSTS_INTRQ))
509 return 1; 506 return 1;
510 507
@@ -512,9 +509,6 @@ static int scc_dma_test_irq(ide_drive_t *drive)
512 if (int_stat & INTSTS_IOIRQS) 509 if (int_stat & INTSTS_IOIRQS)
513 return 1; 510 return 1;
514 511
515 if (!drive->waiting_for_dma)
516 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
517 drive->name, __func__);
518 return 0; 512 return 0;
519} 513}
520 514
@@ -542,10 +536,6 @@ static u8 scc_udma_filter(ide_drive_t *drive)
542 536
543static int setup_mmio_scc (struct pci_dev *dev, const char *name) 537static int setup_mmio_scc (struct pci_dev *dev, const char *name)
544{ 538{
545 unsigned long ctl_base = pci_resource_start(dev, 0);
546 unsigned long dma_base = pci_resource_start(dev, 1);
547 unsigned long ctl_size = pci_resource_len(dev, 0);
548 unsigned long dma_size = pci_resource_len(dev, 1);
549 void __iomem *ctl_addr; 539 void __iomem *ctl_addr;
550 void __iomem *dma_addr; 540 void __iomem *dma_addr;
551 int i, ret; 541 int i, ret;
@@ -563,10 +553,12 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name)
563 return ret; 553 return ret;
564 } 554 }
565 555
566 if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL) 556 ctl_addr = pci_ioremap_bar(dev, 0);
557 if (!ctl_addr)
567 goto fail_0; 558 goto fail_0;
568 559
569 if ((dma_addr = ioremap(dma_base, dma_size)) == NULL) 560 dma_addr = pci_ioremap_bar(dev, 1);
561 if (!dma_addr)
570 goto fail_1; 562 goto fail_1;
571 563
572 pci_set_master(dev); 564 pci_set_master(dev);
@@ -623,7 +615,6 @@ static int __devinit init_setup_scc(struct pci_dev *dev,
623 unsigned long intmask_port; 615 unsigned long intmask_port;
624 unsigned long mode_port; 616 unsigned long mode_port;
625 unsigned long ecmode_port; 617 unsigned long ecmode_port;
626 unsigned long dma_status_port;
627 u32 reg = 0; 618 u32 reg = 0;
628 struct scc_ports *ports; 619 struct scc_ports *ports;
629 int rc; 620 int rc;
@@ -643,7 +634,6 @@ static int __devinit init_setup_scc(struct pci_dev *dev,
643 intmask_port = dma_base + 0x010; 634 intmask_port = dma_base + 0x010;
644 mode_port = ctl_base + 0x024; 635 mode_port = ctl_base + 0x024;
645 ecmode_port = ctl_base + 0xf00; 636 ecmode_port = ctl_base + 0xf00;
646 dma_status_port = dma_base + 0x004;
647 637
648 /* controller initialization */ 638 /* controller initialization */
649 reg = 0; 639 reg = 0;
@@ -711,7 +701,7 @@ static void scc_tf_load(ide_drive_t *drive, ide_task_t *task)
711 scc_ide_outb(tf->lbah, io_ports->lbah_addr); 701 scc_ide_outb(tf->lbah, io_ports->lbah_addr);
712 702
713 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 703 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
714 scc_ide_outb((tf->device & HIHI) | drive->select.all, 704 scc_ide_outb((tf->device & HIHI) | drive->select,
715 io_ports->device_addr); 705 io_ports->device_addr);
716} 706}
717 707
@@ -827,6 +817,12 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
827 init_mmio_iops_scc(hwif); 817 init_mmio_iops_scc(hwif);
828} 818}
829 819
820static int __devinit scc_init_dma(ide_hwif_t *hwif,
821 const struct ide_port_info *d)
822{
823 return ide_allocate_dma_engine(hwif);
824}
825
830static u8 scc_cable_detect(ide_hwif_t *hwif) 826static u8 scc_cable_detect(ide_hwif_t *hwif)
831{ 827{
832 return ATA_CBL_PATA80; 828 return ATA_CBL_PATA80;
@@ -843,8 +839,6 @@ static u8 scc_cable_detect(ide_hwif_t *hwif)
843 839
844static void __devinit init_hwif_scc(ide_hwif_t *hwif) 840static void __devinit init_hwif_scc(ide_hwif_t *hwif)
845{ 841{
846 struct scc_ports *ports = ide_get_hwifdata(hwif);
847
848 /* PTERADD */ 842 /* PTERADD */
849 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma); 843 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma);
850 844
@@ -891,6 +885,7 @@ static const struct ide_dma_ops scc_dma_ops = {
891 { \ 885 { \
892 .name = name_str, \ 886 .name = name_str, \
893 .init_iops = init_iops_scc, \ 887 .init_iops = init_iops_scc, \
888 .init_dma = scc_init_dma, \
894 .init_hwif = init_hwif_scc, \ 889 .init_hwif = init_hwif_scc, \
895 .tp_ops = &scc_tp_ops, \ 890 .tp_ops = &scc_tp_ops, \
896 .port_ops = &scc_port_ops, \ 891 .port_ops = &scc_port_ops, \
@@ -928,13 +923,6 @@ static void __devexit scc_remove(struct pci_dev *dev)
928{ 923{
929 struct scc_ports *ports = pci_get_drvdata(dev); 924 struct scc_ports *ports = pci_get_drvdata(dev);
930 struct ide_host *host = ports->host; 925 struct ide_host *host = ports->host;
931 ide_hwif_t *hwif = host->ports[0];
932
933 if (hwif->dmatable_cpu) {
934 pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
935 hwif->dmatable_cpu, hwif->dmatable_dma);
936 hwif->dmatable_cpu = NULL;
937 }
938 926
939 ide_host_remove(host); 927 ide_host_remove(host);
940 928
@@ -950,7 +938,7 @@ static const struct pci_device_id scc_pci_tbl[] = {
950}; 938};
951MODULE_DEVICE_TABLE(pci, scc_pci_tbl); 939MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
952 940
953static struct pci_driver driver = { 941static struct pci_driver scc_pci_driver = {
954 .name = "SCC IDE", 942 .name = "SCC IDE",
955 .id_table = scc_pci_tbl, 943 .id_table = scc_pci_tbl,
956 .probe = scc_init_one, 944 .probe = scc_init_one,
@@ -959,14 +947,14 @@ static struct pci_driver driver = {
959 947
960static int scc_ide_init(void) 948static int scc_ide_init(void)
961{ 949{
962 return ide_pci_register_driver(&driver); 950 return ide_pci_register_driver(&scc_pci_driver);
963} 951}
964 952
965module_init(scc_ide_init); 953module_init(scc_ide_init);
966/* -- No exit code? 954/* -- No exit code?
967static void scc_ide_exit(void) 955static void scc_ide_exit(void)
968{ 956{
969 ide_pci_unregister_driver(&driver); 957 ide_pci_unregister_driver(&scc_pci_driver);
970} 958}
971module_exit(scc_ide_exit); 959module_exit(scc_ide_exit);
972 */ 960 */
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/serverworks.c
index c3bdc6e51a48..437bc919dafd 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/serverworks.c
@@ -32,7 +32,6 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/hdreg.h>
36#include <linux/ide.h> 35#include <linux/ide.h>
37#include <linux/init.h> 36#include <linux/init.h>
38 37
@@ -57,8 +56,10 @@ static struct pci_dev *isa_dev;
57 56
58static int check_in_drive_lists (ide_drive_t *drive, const char **list) 57static int check_in_drive_lists (ide_drive_t *drive, const char **list)
59{ 58{
59 char *m = (char *)&drive->id[ATA_ID_PROD];
60
60 while (*list) 61 while (*list)
61 if (!strcmp(*list++, drive->id->model)) 62 if (!strcmp(*list++, m))
62 return 1; 63 return 1;
63 return 0; 64 return 0;
64} 65}
@@ -152,7 +153,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
152 153
153 ide_hwif_t *hwif = HWIF(drive); 154 ide_hwif_t *hwif = HWIF(drive);
154 struct pci_dev *dev = to_pci_dev(hwif->dev); 155 struct pci_dev *dev = to_pci_dev(hwif->dev);
155 u8 unit = (drive->select.b.unit & 0x01); 156 u8 unit = drive->dn & 1;
156 157
157 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; 158 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0;
158 159
@@ -174,7 +175,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
174 pci_write_config_byte(dev, 0x54, ultra_enable); 175 pci_write_config_byte(dev, 0x54, ultra_enable);
175} 176}
176 177
177static unsigned int __devinit init_chipset_svwks(struct pci_dev *dev) 178static unsigned int init_chipset_svwks(struct pci_dev *dev)
178{ 179{
179 unsigned int reg; 180 unsigned int reg;
180 u8 btr; 181 u8 btr;
@@ -442,21 +443,23 @@ static const struct pci_device_id svwks_pci_tbl[] = {
442}; 443};
443MODULE_DEVICE_TABLE(pci, svwks_pci_tbl); 444MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
444 445
445static struct pci_driver driver = { 446static struct pci_driver svwks_pci_driver = {
446 .name = "Serverworks_IDE", 447 .name = "Serverworks_IDE",
447 .id_table = svwks_pci_tbl, 448 .id_table = svwks_pci_tbl,
448 .probe = svwks_init_one, 449 .probe = svwks_init_one,
449 .remove = ide_pci_remove, 450 .remove = ide_pci_remove,
451 .suspend = ide_pci_suspend,
452 .resume = ide_pci_resume,
450}; 453};
451 454
452static int __init svwks_ide_init(void) 455static int __init svwks_ide_init(void)
453{ 456{
454 return ide_pci_register_driver(&driver); 457 return ide_pci_register_driver(&svwks_pci_driver);
455} 458}
456 459
457static void __exit svwks_ide_exit(void) 460static void __exit svwks_ide_exit(void)
458{ 461{
459 pci_unregister_driver(&driver); 462 pci_unregister_driver(&svwks_pci_driver);
460} 463}
461 464
462module_init(svwks_ide_init); 465module_init(svwks_ide_init);
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index a8e9e8a69a52..9f1f9163a136 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -659,3 +659,36 @@ void ide_pci_remove(struct pci_dev *dev)
659 pci_disable_device(dev); 659 pci_disable_device(dev);
660} 660}
661EXPORT_SYMBOL_GPL(ide_pci_remove); 661EXPORT_SYMBOL_GPL(ide_pci_remove);
662
663#ifdef CONFIG_PM
664int ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
665{
666 pci_save_state(dev);
667 pci_disable_device(dev);
668 pci_set_power_state(dev, pci_choose_state(dev, state));
669
670 return 0;
671}
672EXPORT_SYMBOL_GPL(ide_pci_suspend);
673
674int ide_pci_resume(struct pci_dev *dev)
675{
676 struct ide_host *host = pci_get_drvdata(dev);
677 int rc;
678
679 pci_set_power_state(dev, PCI_D0);
680
681 rc = pci_enable_device(dev);
682 if (rc)
683 return rc;
684
685 pci_restore_state(dev);
686 pci_set_master(dev);
687
688 if (host->init_chipset)
689 host->init_chipset(dev);
690
691 return 0;
692}
693EXPORT_SYMBOL_GPL(ide_pci_resume);
694#endif
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/sgiioc4.c
index 681306c9d79b..7defa0ae2014 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/sgiioc4.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (C) 2008 MontaVista Software, Inc.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License 6 * under the terms of version 2 of the GNU General Public License
@@ -22,7 +23,6 @@
22#include <linux/types.h> 23#include <linux/types.h>
23#include <linux/pci.h> 24#include <linux/pci.h>
24#include <linux/delay.h> 25#include <linux/delay.h>
25#include <linux/hdreg.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/ioport.h> 28#include <linux/ioport.h>
@@ -101,18 +101,8 @@ sgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
101 for (i = 0; i <= 7; i++) 101 for (i = 0; i <= 7; i++)
102 hw->io_ports_array[i] = reg + i * 4; 102 hw->io_ports_array[i] = reg + i * 4;
103 103
104 if (ctrl_port) 104 hw->io_ports.ctl_addr = ctrl_port;
105 hw->io_ports.ctl_addr = ctrl_port; 105 hw->io_ports.irq_addr = irq_port;
106
107 if (irq_port)
108 hw->io_ports.irq_addr = irq_port;
109}
110
111static void
112sgiioc4_maskproc(ide_drive_t * drive, int mask)
113{
114 writeb(ATA_DEVCTL_OBS | (mask ? 2 : 0),
115 (void __iomem *)drive->hwif->io_ports.ctl_addr);
116} 106}
117 107
118static int 108static int
@@ -151,7 +141,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
151 int count = 0; 141 int count = 0;
152 142
153 stat = sgiioc4_read_status(hwif); 143 stat = sgiioc4_read_status(hwif);
154 while ((stat & 0x80) && (count++ < 100)) { 144 while ((stat & ATA_BUSY) && (count++ < 100)) {
155 udelay(1); 145 udelay(1);
156 stat = sgiioc4_read_status(hwif); 146 stat = sgiioc4_read_status(hwif);
157 } 147 }
@@ -310,16 +300,14 @@ static u8 sgiioc4_read_status(ide_hwif_t *hwif)
310 unsigned long port = hwif->io_ports.status_addr; 300 unsigned long port = hwif->io_ports.status_addr;
311 u8 reg = (u8) readb((void __iomem *) port); 301 u8 reg = (u8) readb((void __iomem *) port);
312 302
313 if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */ 303 if (!(reg & ATA_BUSY)) { /* Not busy... check for interrupt */
314 if (reg & 0x51) { /* Not busy...check for interrupt */ 304 unsigned long other_ir = port - 0x110;
315 unsigned long other_ir = port - 0x110; 305 unsigned int intr_reg = (u32) readl((void __iomem *) other_ir);
316 unsigned int intr_reg = (u32) readl((void __iomem *) other_ir);
317 306
318 /* Clear the Interrupt, Error bits on the IOC4 */ 307 /* Clear the Interrupt, Error bits on the IOC4 */
319 if (intr_reg & 0x03) { 308 if (intr_reg & 0x03) {
320 writel(0x03, (void __iomem *) other_ir); 309 writel(0x03, (void __iomem *) other_ir);
321 intr_reg = (u32) readl((void __iomem *) other_ir); 310 intr_reg = (u32) readl((void __iomem *) other_ir);
322 }
323 } 311 }
324 } 312 }
325 313
@@ -332,42 +320,28 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
332{ 320{
333 struct pci_dev *dev = to_pci_dev(hwif->dev); 321 struct pci_dev *dev = to_pci_dev(hwif->dev);
334 unsigned long dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET; 322 unsigned long dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET;
335 void __iomem *virt_dma_base;
336 int num_ports = sizeof (ioc4_dma_regs_t); 323 int num_ports = sizeof (ioc4_dma_regs_t);
337 void *pad; 324 void *pad;
338 325
339 if (dma_base == 0) 326 printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name);
340 return -1;
341
342 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,
343 dma_base, dma_base + num_ports - 1);
344 327
345 if (!request_mem_region(dma_base, num_ports, hwif->name)) { 328 if (request_mem_region(dma_base, num_ports, hwif->name) == NULL) {
346 printk(KERN_ERR 329 printk(KERN_ERR "%s(%s) -- ERROR: addresses 0x%08lx to 0x%08lx "
347 "%s(%s) -- ERROR, Addresses 0x%p to 0x%p " 330 "already in use\n", __func__, hwif->name,
348 "ALREADY in use\n", 331 dma_base, dma_base + num_ports - 1);
349 __func__, hwif->name, (void *) dma_base,
350 (void *) dma_base + num_ports - 1);
351 return -1; 332 return -1;
352 } 333 }
353 334
354 virt_dma_base = ioremap(dma_base, num_ports); 335 hwif->dma_base = (unsigned long)hwif->io_ports.irq_addr +
355 if (virt_dma_base == NULL) { 336 IOC4_DMA_OFFSET;
356 printk(KERN_ERR
357 "%s(%s) -- ERROR, Unable to map addresses 0x%lx to 0x%lx\n",
358 __func__, hwif->name, dma_base, dma_base + num_ports - 1);
359 goto dma_remap_failure;
360 }
361 hwif->dma_base = (unsigned long) virt_dma_base;
362 337
363 hwif->dmatable_cpu = pci_alloc_consistent(dev, 338 hwif->sg_max_nents = IOC4_PRD_ENTRIES;
364 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
365 &hwif->dmatable_dma);
366 339
367 if (!hwif->dmatable_cpu) 340 hwif->prd_max_nents = IOC4_PRD_ENTRIES;
368 goto dma_pci_alloc_failure; 341 hwif->prd_ent_size = IOC4_PRD_BYTES;
369 342
370 hwif->sg_max_nents = IOC4_PRD_ENTRIES; 343 if (ide_allocate_dma_engine(hwif))
344 goto dma_pci_alloc_failure;
371 345
372 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE, 346 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
373 (dma_addr_t *)&hwif->extra_base); 347 (dma_addr_t *)&hwif->extra_base);
@@ -376,18 +350,13 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
376 return 0; 350 return 0;
377 } 351 }
378 352
379 pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, 353 ide_release_dma_engine(hwif);
380 hwif->dmatable_cpu, hwif->dmatable_dma); 354
381 printk(KERN_INFO 355 printk(KERN_ERR "%s(%s) -- ERROR: Unable to allocate DMA maps\n",
382 "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
383 __func__, hwif->name); 356 __func__, hwif->name);
384 printk(KERN_INFO 357 printk(KERN_INFO "%s: changing from DMA to PIO mode", hwif->name);
385 "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
386 358
387dma_pci_alloc_failure: 359dma_pci_alloc_failure:
388 iounmap(virt_dma_base);
389
390dma_remap_failure:
391 release_mem_region(dma_base, num_ports); 360 release_mem_region(dma_base, num_ports);
392 361
393 return -1; 362 return -1;
@@ -569,8 +538,6 @@ static const struct ide_port_ops sgiioc4_port_ops = {
569 .set_dma_mode = sgiioc4_set_dma_mode, 538 .set_dma_mode = sgiioc4_set_dma_mode,
570 /* reset DMA engine, clear IRQs */ 539 /* reset DMA engine, clear IRQs */
571 .resetproc = sgiioc4_resetproc, 540 .resetproc = sgiioc4_resetproc,
572 /* mask on/off NIEN register */
573 .maskproc = sgiioc4_maskproc,
574}; 541};
575 542
576static const struct ide_dma_ops sgiioc4_dma_ops = { 543static const struct ide_dma_ops sgiioc4_dma_ops = {
@@ -600,14 +567,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
600 unsigned long cmd_base, irqport; 567 unsigned long cmd_base, irqport;
601 unsigned long bar0, cmd_phys_base, ctl; 568 unsigned long bar0, cmd_phys_base, ctl;
602 void __iomem *virt_base; 569 void __iomem *virt_base;
603 struct ide_host *host;
604 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 570 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
605 struct ide_port_info d = sgiioc4_port_info;
606 int rc; 571 int rc;
607 572
608 /* Get the CmdBlk and CtrlBlk Base Registers */ 573 /* Get the CmdBlk and CtrlBlk Base Registers */
609 bar0 = pci_resource_start(dev, 0); 574 bar0 = pci_resource_start(dev, 0);
610 virt_base = ioremap(bar0, pci_resource_len(dev, 0)); 575 virt_base = pci_ioremap_bar(dev, 0);
611 if (virt_base == NULL) { 576 if (virt_base == NULL) {
612 printk(KERN_ERR "%s: Unable to remap BAR 0 address: 0x%lx\n", 577 printk(KERN_ERR "%s: Unable to remap BAR 0 address: 0x%lx\n",
613 DRV_NAME, bar0); 578 DRV_NAME, bar0);
@@ -618,14 +583,13 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
618 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET; 583 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET;
619 584
620 cmd_phys_base = bar0 + IOC4_CMD_OFFSET; 585 cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
621 if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, 586 if (request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
622 DRV_NAME)) { 587 DRV_NAME) == NULL) {
623 printk(KERN_ERR 588 printk(KERN_ERR "%s %s -- ERROR: addresses 0x%08lx to 0x%08lx "
624 "%s %s: -- ERROR, Addresses " 589 "already in use\n", DRV_NAME, pci_name(dev),
625 "0x%p to 0x%p ALREADY in use\n", 590 cmd_phys_base, cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
626 DRV_NAME, pci_name(dev), (void *)cmd_phys_base, 591 rc = -EBUSY;
627 (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE); 592 goto req_mem_rgn_err;
628 return -ENOMEM;
629 } 593 }
630 594
631 /* Initialize the IO registers */ 595 /* Initialize the IO registers */
@@ -638,21 +602,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
638 /* Initializing chipset IRQ Registers */ 602 /* Initializing chipset IRQ Registers */
639 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4)); 603 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
640 604
641 host = ide_host_alloc(&d, hws); 605 rc = ide_host_add(&sgiioc4_port_info, hws, NULL);
642 if (host == NULL) { 606 if (!rc)
643 rc = -ENOMEM; 607 return 0;
644 goto err;
645 }
646
647 rc = ide_host_register(host, &d, hws);
648 if (rc)
649 goto err_free;
650 608
651 return 0;
652err_free:
653 ide_host_free(host);
654err:
655 release_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE); 609 release_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE);
610req_mem_rgn_err:
656 iounmap(virt_base); 611 iounmap(virt_base);
657 return rc; 612 return rc;
658} 613}
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/siimage.c
index db2b88a369ab..7d622d20bc4c 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/siimage.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
3 * Copyright (C) 2003 Red Hat <alan@redhat.com> 3 * Copyright (C) 2003 Red Hat
4 * Copyright (C) 2007-2008 MontaVista Software, Inc. 4 * Copyright (C) 2007-2008 MontaVista Software, Inc.
5 * Copyright (C) 2007-2008 Bartlomiej Zolnierkiewicz 5 * Copyright (C) 2007-2008 Bartlomiej Zolnierkiewicz
6 * 6 *
@@ -39,7 +39,6 @@
39#include <linux/types.h> 39#include <linux/types.h>
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/pci.h> 41#include <linux/pci.h>
42#include <linux/hdreg.h>
43#include <linux/ide.h> 42#include <linux/ide.h>
44#include <linux/init.h> 43#include <linux/init.h>
45#include <linux/io.h> 44#include <linux/io.h>
@@ -117,13 +116,14 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
117{ 116{
118 ide_hwif_t *hwif = HWIF(drive); 117 ide_hwif_t *hwif = HWIF(drive);
119 unsigned long base = (unsigned long)hwif->hwif_data; 118 unsigned long base = (unsigned long)hwif->hwif_data;
119 u8 unit = drive->dn & 1;
120 120
121 base += 0xA0 + r; 121 base += 0xA0 + r;
122 if (hwif->host_flags & IDE_HFLAG_MMIO) 122 if (hwif->host_flags & IDE_HFLAG_MMIO)
123 base += hwif->channel << 6; 123 base += hwif->channel << 6;
124 else 124 else
125 base += hwif->channel << 4; 125 base += hwif->channel << 4;
126 base |= drive->select.b.unit << drive->select.b.unit; 126 base |= unit << unit;
127 return base; 127 return base;
128} 128}
129 129
@@ -223,7 +223,9 @@ static u8 sil_pata_udma_filter(ide_drive_t *drive)
223 223
224static u8 sil_sata_udma_filter(ide_drive_t *drive) 224static u8 sil_sata_udma_filter(ide_drive_t *drive)
225{ 225{
226 return strstr(drive->id->model, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6; 226 char *m = (char *)&drive->id[ATA_ID_PROD];
227
228 return strstr(m, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6;
227} 229}
228 230
229/** 231/**
@@ -243,7 +245,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
243 245
244 ide_hwif_t *hwif = HWIF(drive); 246 ide_hwif_t *hwif = HWIF(drive);
245 struct pci_dev *dev = to_pci_dev(hwif->dev); 247 struct pci_dev *dev = to_pci_dev(hwif->dev);
246 ide_drive_t *pair = ide_get_paired_drive(drive); 248 ide_drive_t *pair = ide_get_pair_dev(drive);
247 u32 speedt = 0; 249 u32 speedt = 0;
248 u16 speedp = 0; 250 u16 speedp = 0;
249 unsigned long addr = siimage_seldev(drive, 0x04); 251 unsigned long addr = siimage_seldev(drive, 0x04);
@@ -254,10 +256,10 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
254 u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84) 256 u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
255 : (mmio ? 0xB4 : 0x80); 257 : (mmio ? 0xB4 : 0x80);
256 u8 mode = 0; 258 u8 mode = 0;
257 u8 unit = drive->select.b.unit; 259 u8 unit = drive->dn & 1;
258 260
259 /* trim *taskfile* PIO to the slowest of the master/slave */ 261 /* trim *taskfile* PIO to the slowest of the master/slave */
260 if (pair->present) { 262 if (pair) {
261 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4); 263 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4);
262 264
263 if (pair_pio < tf_pio) 265 if (pair_pio < tf_pio)
@@ -300,9 +302,9 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
300 302
301 ide_hwif_t *hwif = HWIF(drive); 303 ide_hwif_t *hwif = HWIF(drive);
302 struct pci_dev *dev = to_pci_dev(hwif->dev); 304 struct pci_dev *dev = to_pci_dev(hwif->dev);
303 u16 ultra = 0, multi = 0;
304 u8 mode = 0, unit = drive->select.b.unit;
305 unsigned long base = (unsigned long)hwif->hwif_data; 305 unsigned long base = (unsigned long)hwif->hwif_data;
306 u16 ultra = 0, multi = 0;
307 u8 mode = 0, unit = drive->dn & 1;
306 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 308 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
307 u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84) 309 u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
308 : (mmio ? 0xB4 : 0x80); 310 : (mmio ? 0xB4 : 0x80);
@@ -462,7 +464,7 @@ static void sil_sata_pre_reset(ide_drive_t *drive)
462 * to 133 MHz clocking if the system isn't already set up to do it. 464 * to 133 MHz clocking if the system isn't already set up to do it.
463 */ 465 */
464 466
465static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev) 467static unsigned int init_chipset_siimage(struct pci_dev *dev)
466{ 468{
467 struct ide_host *host = pci_get_drvdata(dev); 469 struct ide_host *host = pci_get_drvdata(dev);
468 void __iomem *ioaddr = host->host_priv; 470 void __iomem *ioaddr = host->host_priv;
@@ -616,8 +618,8 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
616 618
617static int is_dev_seagate_sata(ide_drive_t *drive) 619static int is_dev_seagate_sata(ide_drive_t *drive)
618{ 620{
619 const char *s = &drive->id->model[0]; 621 const char *s = (const char *)&drive->id[ATA_ID_PROD];
620 unsigned len = strnlen(s, sizeof(drive->id->model)); 622 unsigned len = strnlen(s, ATA_ID_PROD_LEN);
621 623
622 if ((len > 4) && (!memcmp(s, "ST", 2))) 624 if ((len > 4) && (!memcmp(s, "ST", 2)))
623 if ((!memcmp(s + len - 2, "AS", 2)) || 625 if ((!memcmp(s + len - 2, "AS", 2)) ||
@@ -711,7 +713,7 @@ static const struct ide_dma_ops sil_dma_ops = {
711 .dma_setup = ide_dma_setup, 713 .dma_setup = ide_dma_setup,
712 .dma_exec_cmd = ide_dma_exec_cmd, 714 .dma_exec_cmd = ide_dma_exec_cmd,
713 .dma_start = ide_dma_start, 715 .dma_start = ide_dma_start,
714 .dma_end = __ide_dma_end, 716 .dma_end = ide_dma_end,
715 .dma_test_irq = siimage_dma_test_irq, 717 .dma_test_irq = siimage_dma_test_irq,
716 .dma_timeout = ide_dma_timeout, 718 .dma_timeout = ide_dma_timeout,
717 .dma_lost_irq = ide_dma_lost_irq, 719 .dma_lost_irq = ide_dma_lost_irq,
@@ -782,7 +784,7 @@ static int __devinit siimage_init_one(struct pci_dev *dev,
782 printk(KERN_WARNING DRV_NAME " %s: MMIO ports not " 784 printk(KERN_WARNING DRV_NAME " %s: MMIO ports not "
783 "available\n", pci_name(dev)); 785 "available\n", pci_name(dev));
784 } else { 786 } else {
785 ioaddr = ioremap(bar5, barsize); 787 ioaddr = pci_ioremap_bar(dev, 5);
786 if (ioaddr == NULL) 788 if (ioaddr == NULL)
787 release_mem_region(bar5, barsize); 789 release_mem_region(bar5, barsize);
788 } 790 }
@@ -828,21 +830,23 @@ static const struct pci_device_id siimage_pci_tbl[] = {
828}; 830};
829MODULE_DEVICE_TABLE(pci, siimage_pci_tbl); 831MODULE_DEVICE_TABLE(pci, siimage_pci_tbl);
830 832
831static struct pci_driver driver = { 833static struct pci_driver siimage_pci_driver = {
832 .name = "SiI_IDE", 834 .name = "SiI_IDE",
833 .id_table = siimage_pci_tbl, 835 .id_table = siimage_pci_tbl,
834 .probe = siimage_init_one, 836 .probe = siimage_init_one,
835 .remove = __devexit_p(siimage_remove), 837 .remove = __devexit_p(siimage_remove),
838 .suspend = ide_pci_suspend,
839 .resume = ide_pci_resume,
836}; 840};
837 841
838static int __init siimage_ide_init(void) 842static int __init siimage_ide_init(void)
839{ 843{
840 return ide_pci_register_driver(&driver); 844 return ide_pci_register_driver(&siimage_pci_driver);
841} 845}
842 846
843static void __exit siimage_ide_exit(void) 847static void __exit siimage_ide_exit(void)
844{ 848{
845 pci_unregister_driver(&driver); 849 pci_unregister_driver(&siimage_pci_driver);
846} 850}
847 851
848module_init(siimage_ide_init); 852module_init(siimage_ide_init);
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/sis5513.c
index 5efe21d6ef97..ad32e18c5ba3 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/sis5513.c
@@ -47,7 +47,6 @@
47#include <linux/types.h> 47#include <linux/types.h>
48#include <linux/module.h> 48#include <linux/module.h>
49#include <linux/kernel.h> 49#include <linux/kernel.h>
50#include <linux/hdreg.h>
51#include <linux/pci.h> 50#include <linux/pci.h>
52#include <linux/init.h> 51#include <linux/init.h>
53#include <linux/ide.h> 52#include <linux/ide.h>
@@ -448,7 +447,7 @@ static int __devinit sis_find_family(struct pci_dev *dev)
448 return chipset_family; 447 return chipset_family;
449} 448}
450 449
451static unsigned int __devinit init_chipset_sis5513(struct pci_dev *dev) 450static unsigned int init_chipset_sis5513(struct pci_dev *dev)
452{ 451{
453 /* Make general config ops here 452 /* Make general config ops here
454 1/ tell IDE channels to operate in Compatibility mode only 453 1/ tell IDE channels to operate in Compatibility mode only
@@ -606,21 +605,23 @@ static const struct pci_device_id sis5513_pci_tbl[] = {
606}; 605};
607MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl); 606MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
608 607
609static struct pci_driver driver = { 608static struct pci_driver sis5513_pci_driver = {
610 .name = "SIS_IDE", 609 .name = "SIS_IDE",
611 .id_table = sis5513_pci_tbl, 610 .id_table = sis5513_pci_tbl,
612 .probe = sis5513_init_one, 611 .probe = sis5513_init_one,
613 .remove = __devexit_p(sis5513_remove), 612 .remove = __devexit_p(sis5513_remove),
613 .suspend = ide_pci_suspend,
614 .resume = ide_pci_resume,
614}; 615};
615 616
616static int __init sis5513_ide_init(void) 617static int __init sis5513_ide_init(void)
617{ 618{
618 return ide_pci_register_driver(&driver); 619 return ide_pci_register_driver(&sis5513_pci_driver);
619} 620}
620 621
621static void __exit sis5513_ide_exit(void) 622static void __exit sis5513_ide_exit(void)
622{ 623{
623 pci_unregister_driver(&driver); 624 pci_unregister_driver(&sis5513_pci_driver);
624} 625}
625 626
626module_init(sis5513_ide_init); 627module_init(sis5513_ide_init);
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/sl82c105.c
index 73905bcc08fb..84dc33602ff8 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/sl82c105.c
@@ -17,7 +17,6 @@
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/hdreg.h>
21#include <linux/pci.h> 20#include <linux/pci.h>
22#include <linux/ide.h> 21#include <linux/ide.h>
23 22
@@ -62,7 +61,7 @@ static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
62 if (cmd_off == 0) 61 if (cmd_off == 0)
63 cmd_off = 1; 62 cmd_off = 1;
64 63
65 if (pio > 2 || ide_dev_has_iordy(drive->id)) 64 if (pio > 2 || ata_id_has_iordy(drive->id))
66 iordy = 0x40; 65 iordy = 0x40;
67 66
68 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy; 67 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy;
@@ -208,7 +207,7 @@ static int sl82c105_dma_end(ide_drive_t *drive)
208 207
209 DBG(("%s(drive:%s)\n", __func__, drive->name)); 208 DBG(("%s(drive:%s)\n", __func__, drive->name));
210 209
211 ret = __ide_dma_end(drive); 210 ret = ide_dma_end(drive);
212 211
213 pci_write_config_word(dev, reg, drive->drive_data); 212 pci_write_config_word(dev, reg, drive->drive_data);
214 213
@@ -272,7 +271,7 @@ static u8 sl82c105_bridge_revision(struct pci_dev *dev)
272 * channel 0 here at least, but channel 1 has to be enabled by 271 * channel 0 here at least, but channel 1 has to be enabled by
273 * firmware or arch code. We still set both to 16 bits mode. 272 * firmware or arch code. We still set both to 16 bits mode.
274 */ 273 */
275static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev) 274static unsigned int init_chipset_sl82c105(struct pci_dev *dev)
276{ 275{
277 u32 val; 276 u32 val;
278 277
@@ -346,21 +345,23 @@ static const struct pci_device_id sl82c105_pci_tbl[] = {
346}; 345};
347MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl); 346MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl);
348 347
349static struct pci_driver driver = { 348static struct pci_driver sl82c105_pci_driver = {
350 .name = "W82C105_IDE", 349 .name = "W82C105_IDE",
351 .id_table = sl82c105_pci_tbl, 350 .id_table = sl82c105_pci_tbl,
352 .probe = sl82c105_init_one, 351 .probe = sl82c105_init_one,
353 .remove = ide_pci_remove, 352 .remove = ide_pci_remove,
353 .suspend = ide_pci_suspend,
354 .resume = ide_pci_resume,
354}; 355};
355 356
356static int __init sl82c105_ide_init(void) 357static int __init sl82c105_ide_init(void)
357{ 358{
358 return ide_pci_register_driver(&driver); 359 return ide_pci_register_driver(&sl82c105_pci_driver);
359} 360}
360 361
361static void __exit sl82c105_ide_exit(void) 362static void __exit sl82c105_ide_exit(void)
362{ 363{
363 pci_unregister_driver(&driver); 364 pci_unregister_driver(&sl82c105_pci_driver);
364} 365}
365 366
366module_init(sl82c105_ide_init); 367module_init(sl82c105_ide_init);
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/slc90e66.c
index 866d6c65e3a0..0f759e4ed779 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/slc90e66.c
@@ -11,7 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/hdreg.h>
15#include <linux/ide.h> 14#include <linux/ide.h>
16#include <linux/init.h> 15#include <linux/init.h>
17 16
@@ -155,21 +154,23 @@ static const struct pci_device_id slc90e66_pci_tbl[] = {
155}; 154};
156MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl); 155MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl);
157 156
158static struct pci_driver driver = { 157static struct pci_driver slc90e66_pci_driver = {
159 .name = "SLC90e66_IDE", 158 .name = "SLC90e66_IDE",
160 .id_table = slc90e66_pci_tbl, 159 .id_table = slc90e66_pci_tbl,
161 .probe = slc90e66_init_one, 160 .probe = slc90e66_init_one,
162 .remove = ide_pci_remove, 161 .remove = ide_pci_remove,
162 .suspend = ide_pci_suspend,
163 .resume = ide_pci_resume,
163}; 164};
164 165
165static int __init slc90e66_ide_init(void) 166static int __init slc90e66_ide_init(void)
166{ 167{
167 return ide_pci_register_driver(&driver); 168 return ide_pci_register_driver(&slc90e66_pci_driver);
168} 169}
169 170
170static void __exit slc90e66_ide_exit(void) 171static void __exit slc90e66_ide_exit(void)
171{ 172{
172 pci_unregister_driver(&driver); 173 pci_unregister_driver(&slc90e66_pci_driver);
173} 174}
174 175
175module_init(slc90e66_ide_init); 176module_init(slc90e66_ide_init);
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/tc86c001.c
index 927277c54ec9..93e2cce4b296 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -186,7 +186,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
186 .dma_setup = ide_dma_setup, 186 .dma_setup = ide_dma_setup,
187 .dma_exec_cmd = ide_dma_exec_cmd, 187 .dma_exec_cmd = ide_dma_exec_cmd,
188 .dma_start = tc86c001_dma_start, 188 .dma_start = tc86c001_dma_start,
189 .dma_end = __ide_dma_end, 189 .dma_end = ide_dma_end,
190 .dma_test_irq = ide_dma_test_irq, 190 .dma_test_irq = ide_dma_test_irq,
191 .dma_lost_irq = ide_dma_lost_irq, 191 .dma_lost_irq = ide_dma_lost_irq,
192 .dma_timeout = ide_dma_timeout, 192 .dma_timeout = ide_dma_timeout,
@@ -245,7 +245,7 @@ static const struct pci_device_id tc86c001_pci_tbl[] = {
245}; 245};
246MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl); 246MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl);
247 247
248static struct pci_driver driver = { 248static struct pci_driver tc86c001_pci_driver = {
249 .name = "TC86C001", 249 .name = "TC86C001",
250 .id_table = tc86c001_pci_tbl, 250 .id_table = tc86c001_pci_tbl,
251 .probe = tc86c001_init_one, 251 .probe = tc86c001_init_one,
@@ -254,12 +254,12 @@ static struct pci_driver driver = {
254 254
255static int __init tc86c001_ide_init(void) 255static int __init tc86c001_ide_init(void)
256{ 256{
257 return ide_pci_register_driver(&driver); 257 return ide_pci_register_driver(&tc86c001_pci_driver);
258} 258}
259 259
260static void __exit tc86c001_ide_exit(void) 260static void __exit tc86c001_ide_exit(void)
261{ 261{
262 pci_unregister_driver(&driver); 262 pci_unregister_driver(&tc86c001_pci_driver);
263} 263}
264 264
265module_init(tc86c001_ide_init); 265module_init(tc86c001_ide_init);
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/triflex.c
index b77ec35151b3..b6ff40336aa9 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/triflex.c
@@ -28,7 +28,6 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/hdreg.h>
32#include <linux/pci.h> 31#include <linux/pci.h>
33#include <linux/ide.h> 32#include <linux/ide.h>
34#include <linux/init.h> 33#include <linux/init.h>
@@ -39,13 +38,12 @@ static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
39{ 38{
40 ide_hwif_t *hwif = HWIF(drive); 39 ide_hwif_t *hwif = HWIF(drive);
41 struct pci_dev *dev = to_pci_dev(hwif->dev); 40 struct pci_dev *dev = to_pci_dev(hwif->dev);
42 u8 channel_offset = hwif->channel ? 0x74 : 0x70;
43 u16 timing = 0;
44 u32 triflex_timings = 0; 41 u32 triflex_timings = 0;
45 u8 unit = (drive->select.b.unit & 0x01); 42 u16 timing = 0;
46 43 u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
44
47 pci_read_config_dword(dev, channel_offset, &triflex_timings); 45 pci_read_config_dword(dev, channel_offset, &triflex_timings);
48 46
49 switch(speed) { 47 switch(speed) {
50 case XFER_MW_DMA_2: 48 case XFER_MW_DMA_2:
51 timing = 0x0103; 49 timing = 0x0103;
@@ -115,21 +113,23 @@ static const struct pci_device_id triflex_pci_tbl[] = {
115}; 113};
116MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); 114MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
117 115
118static struct pci_driver driver = { 116static struct pci_driver triflex_pci_driver = {
119 .name = "TRIFLEX_IDE", 117 .name = "TRIFLEX_IDE",
120 .id_table = triflex_pci_tbl, 118 .id_table = triflex_pci_tbl,
121 .probe = triflex_init_one, 119 .probe = triflex_init_one,
122 .remove = ide_pci_remove, 120 .remove = ide_pci_remove,
121 .suspend = ide_pci_suspend,
122 .resume = ide_pci_resume,
123}; 123};
124 124
125static int __init triflex_ide_init(void) 125static int __init triflex_ide_init(void)
126{ 126{
127 return ide_pci_register_driver(&driver); 127 return ide_pci_register_driver(&triflex_pci_driver);
128} 128}
129 129
130static void __exit triflex_ide_exit(void) 130static void __exit triflex_ide_exit(void)
131{ 131{
132 pci_unregister_driver(&driver); 132 pci_unregister_driver(&triflex_pci_driver);
133} 133}
134 134
135module_init(triflex_ide_init); 135module_init(triflex_ide_init);
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/trm290.c
index fd28b49977fd..75ea61526566 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/trm290.c
@@ -135,7 +135,6 @@
135#include <linux/interrupt.h> 135#include <linux/interrupt.h>
136#include <linux/blkdev.h> 136#include <linux/blkdev.h>
137#include <linux/init.h> 137#include <linux/init.h>
138#include <linux/hdreg.h>
139#include <linux/pci.h> 138#include <linux/pci.h>
140#include <linux/ide.h> 139#include <linux/ide.h>
141 140
@@ -162,7 +161,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
162 } 161 }
163 162
164 /* enable IRQ if not probing */ 163 /* enable IRQ if not probing */
165 if (drive->present) { 164 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
166 reg = inw(hwif->config_data + 3); 165 reg = inw(hwif->config_data + 3);
167 reg &= 0x13; 166 reg &= 0x13;
168 reg &= ~(1 << hwif->channel); 167 reg &= ~(1 << hwif->channel);
@@ -174,7 +173,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
174 173
175static void trm290_selectproc (ide_drive_t *drive) 174static void trm290_selectproc (ide_drive_t *drive)
176{ 175{
177 trm290_prepare_drive(drive, drive->using_dma); 176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
178} 177}
179 178
180static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command) 179static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command)
@@ -351,7 +350,7 @@ static const struct pci_device_id trm290_pci_tbl[] = {
351}; 350};
352MODULE_DEVICE_TABLE(pci, trm290_pci_tbl); 351MODULE_DEVICE_TABLE(pci, trm290_pci_tbl);
353 352
354static struct pci_driver driver = { 353static struct pci_driver trm290_pci_driver = {
355 .name = "TRM290_IDE", 354 .name = "TRM290_IDE",
356 .id_table = trm290_pci_tbl, 355 .id_table = trm290_pci_tbl,
357 .probe = trm290_init_one, 356 .probe = trm290_init_one,
@@ -360,12 +359,12 @@ static struct pci_driver driver = {
360 359
361static int __init trm290_ide_init(void) 360static int __init trm290_ide_init(void)
362{ 361{
363 return ide_pci_register_driver(&driver); 362 return ide_pci_register_driver(&trm290_pci_driver);
364} 363}
365 364
366static void __exit trm290_ide_exit(void) 365static void __exit trm290_ide_exit(void)
367{ 366{
368 pci_unregister_driver(&driver); 367 pci_unregister_driver(&trm290_pci_driver);
369} 368}
370 369
371module_init(trm290_ide_init); 370module_init(trm290_ide_init);
diff --git a/drivers/ide/tx4938ide.c b/drivers/ide/tx4938ide.c
new file mode 100644
index 000000000000..9120063e8f87
--- /dev/null
+++ b/drivers/ide/tx4938ide.c
@@ -0,0 +1,323 @@
1/*
2 * TX4938 internal IDE driver
3 * Based on tx4939ide.c.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 *
9 * (C) Copyright TOSHIBA CORPORATION 2005-2007
10 */
11
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/ide.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/io.h>
18#include <asm/txx9/tx4938.h>
19
20static void tx4938ide_tune_ebusc(unsigned int ebus_ch,
21 unsigned int gbus_clock,
22 u8 pio)
23{
24 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
25 u64 cr = __raw_readq(&tx4938_ebuscptr->cr[ebus_ch]);
26 unsigned int sp = (cr >> 4) & 3;
27 unsigned int clock = gbus_clock / (4 - sp);
28 unsigned int cycle = 1000000000 / clock;
29 unsigned int shwt;
30 int wt;
31
32 /* Minimum DIOx- active time */
33 wt = DIV_ROUND_UP(t->act8b, cycle) - 2;
34 /* IORDY setup time: 35ns */
35 wt = max_t(int, wt, DIV_ROUND_UP(35, cycle));
36 /* actual wait-cycle is max(wt & ~1, 1) */
37 if (wt > 2 && (wt & 1))
38 wt++;
39 wt &= ~1;
40 /* Address-valid to DIOR/DIOW setup */
41 shwt = DIV_ROUND_UP(t->setup, cycle);
42
43 /* -DIOx recovery time (SHWT * 4) and cycle time requirement */
44 while ((shwt * 4 + wt + (wt ? 2 : 3)) * cycle < t->cycle)
45 shwt++;
46 if (shwt > 7) {
47 pr_warning("tx4938ide: SHWT violation (%d)\n", shwt);
48 shwt = 7;
49 }
50 pr_debug("tx4938ide: ebus %d, bus cycle %dns, WT %d, SHWT %d\n",
51 ebus_ch, cycle, wt, shwt);
52
53 __raw_writeq((cr & ~0x3f007ull) | (wt << 12) | shwt,
54 &tx4938_ebuscptr->cr[ebus_ch]);
55}
56
57static void tx4938ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
58{
59 ide_hwif_t *hwif = drive->hwif;
60 struct tx4938ide_platform_info *pdata = hwif->dev->platform_data;
61 u8 safe = pio;
62 ide_drive_t *pair;
63
64 pair = ide_get_pair_dev(drive);
65 if (pair)
66 safe = min(safe, ide_get_best_pio_mode(pair, 255, 5));
67 tx4938ide_tune_ebusc(pdata->ebus_ch, pdata->gbus_clock, safe);
68}
69
70#ifdef __BIG_ENDIAN
71
72/* custom iops (independent from SWAP_IO_SPACE) */
73static u8 tx4938ide_inb(unsigned long port)
74{
75 return __raw_readb((void __iomem *)port);
76}
77
78static void tx4938ide_outb(u8 value, unsigned long port)
79{
80 __raw_writeb(value, (void __iomem *)port);
81}
82
83static void tx4938ide_tf_load(ide_drive_t *drive, ide_task_t *task)
84{
85 ide_hwif_t *hwif = drive->hwif;
86 struct ide_io_ports *io_ports = &hwif->io_ports;
87 struct ide_taskfile *tf = &task->tf;
88 u8 HIHI = task->tf_flags & IDE_TFLAG_LBA48 ? 0xE0 : 0xEF;
89
90 if (task->tf_flags & IDE_TFLAG_FLAGGED)
91 HIHI = 0xFF;
92
93 if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
94 u16 data = (tf->hob_data << 8) | tf->data;
95
96 /* no endian swap */
97 __raw_writew(data, (void __iomem *)io_ports->data_addr);
98 }
99
100 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
101 tx4938ide_outb(tf->hob_feature, io_ports->feature_addr);
102 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
103 tx4938ide_outb(tf->hob_nsect, io_ports->nsect_addr);
104 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
105 tx4938ide_outb(tf->hob_lbal, io_ports->lbal_addr);
106 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
107 tx4938ide_outb(tf->hob_lbam, io_ports->lbam_addr);
108 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
109 tx4938ide_outb(tf->hob_lbah, io_ports->lbah_addr);
110
111 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
112 tx4938ide_outb(tf->feature, io_ports->feature_addr);
113 if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
114 tx4938ide_outb(tf->nsect, io_ports->nsect_addr);
115 if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
116 tx4938ide_outb(tf->lbal, io_ports->lbal_addr);
117 if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
118 tx4938ide_outb(tf->lbam, io_ports->lbam_addr);
119 if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
120 tx4938ide_outb(tf->lbah, io_ports->lbah_addr);
121
122 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
123 tx4938ide_outb((tf->device & HIHI) | drive->select,
124 io_ports->device_addr);
125}
126
127static void tx4938ide_tf_read(ide_drive_t *drive, ide_task_t *task)
128{
129 ide_hwif_t *hwif = drive->hwif;
130 struct ide_io_ports *io_ports = &hwif->io_ports;
131 struct ide_taskfile *tf = &task->tf;
132
133 if (task->tf_flags & IDE_TFLAG_IN_DATA) {
134 u16 data;
135
136 /* no endian swap */
137 data = __raw_readw((void __iomem *)io_ports->data_addr);
138 tf->data = data & 0xff;
139 tf->hob_data = (data >> 8) & 0xff;
140 }
141
142 /* be sure we're looking at the low order bits */
143 tx4938ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
144
145 if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
146 tf->feature = tx4938ide_inb(io_ports->feature_addr);
147 if (task->tf_flags & IDE_TFLAG_IN_NSECT)
148 tf->nsect = tx4938ide_inb(io_ports->nsect_addr);
149 if (task->tf_flags & IDE_TFLAG_IN_LBAL)
150 tf->lbal = tx4938ide_inb(io_ports->lbal_addr);
151 if (task->tf_flags & IDE_TFLAG_IN_LBAM)
152 tf->lbam = tx4938ide_inb(io_ports->lbam_addr);
153 if (task->tf_flags & IDE_TFLAG_IN_LBAH)
154 tf->lbah = tx4938ide_inb(io_ports->lbah_addr);
155 if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
156 tf->device = tx4938ide_inb(io_ports->device_addr);
157
158 if (task->tf_flags & IDE_TFLAG_LBA48) {
159 tx4938ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
160
161 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
162 tf->hob_feature =
163 tx4938ide_inb(io_ports->feature_addr);
164 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
165 tf->hob_nsect = tx4938ide_inb(io_ports->nsect_addr);
166 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
167 tf->hob_lbal = tx4938ide_inb(io_ports->lbal_addr);
168 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
169 tf->hob_lbam = tx4938ide_inb(io_ports->lbam_addr);
170 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
171 tf->hob_lbah = tx4938ide_inb(io_ports->lbah_addr);
172 }
173}
174
175static void tx4938ide_input_data_swap(ide_drive_t *drive, struct request *rq,
176 void *buf, unsigned int len)
177{
178 unsigned long port = drive->hwif->io_ports.data_addr;
179 unsigned short *ptr = buf;
180 unsigned int count = (len + 1) / 2;
181
182 while (count--)
183 *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port));
184 __ide_flush_dcache_range((unsigned long)buf, count * 2);
185}
186
187static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq,
188 void *buf, unsigned int len)
189{
190 unsigned long port = drive->hwif->io_ports.data_addr;
191 unsigned short *ptr = buf;
192 unsigned int count = (len + 1) / 2;
193
194 while (count--) {
195 __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port);
196 ptr++;
197 }
198 __ide_flush_dcache_range((unsigned long)buf, count * 2);
199}
200
201static const struct ide_tp_ops tx4938ide_tp_ops = {
202 .exec_command = ide_exec_command,
203 .read_status = ide_read_status,
204 .read_altstatus = ide_read_altstatus,
205 .read_sff_dma_status = ide_read_sff_dma_status,
206
207 .set_irq = ide_set_irq,
208
209 .tf_load = tx4938ide_tf_load,
210 .tf_read = tx4938ide_tf_read,
211
212 .input_data = tx4938ide_input_data_swap,
213 .output_data = tx4938ide_output_data_swap,
214};
215
216#endif /* __BIG_ENDIAN */
217
218static const struct ide_port_ops tx4938ide_port_ops = {
219 .set_pio_mode = tx4938ide_set_pio_mode,
220};
221
222static const struct ide_port_info tx4938ide_port_info __initdata = {
223 .port_ops = &tx4938ide_port_ops,
224#ifdef __BIG_ENDIAN
225 .tp_ops = &tx4938ide_tp_ops,
226#endif
227 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
228 .pio_mask = ATA_PIO5,
229};
230
231static int __init tx4938ide_probe(struct platform_device *pdev)
232{
233 hw_regs_t hw;
234 hw_regs_t *hws[] = { &hw, NULL, NULL, NULL };
235 struct ide_host *host;
236 struct resource *res;
237 struct tx4938ide_platform_info *pdata = pdev->dev.platform_data;
238 int irq, ret, i;
239 unsigned long mapbase, mapctl;
240 struct ide_port_info d = tx4938ide_port_info;
241
242 irq = platform_get_irq(pdev, 0);
243 if (irq < 0)
244 return -ENODEV;
245 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
246 if (!res)
247 return -ENODEV;
248
249 if (!devm_request_mem_region(&pdev->dev, res->start,
250 res->end - res->start + 1, "tx4938ide"))
251 return -EBUSY;
252 mapbase = (unsigned long)devm_ioremap(&pdev->dev, res->start,
253 8 << pdata->ioport_shift);
254 mapctl = (unsigned long)devm_ioremap(&pdev->dev,
255 res->start + 0x10000 +
256 (6 << pdata->ioport_shift),
257 1 << pdata->ioport_shift);
258 if (!mapbase || !mapctl)
259 return -EBUSY;
260
261 memset(&hw, 0, sizeof(hw));
262 if (pdata->ioport_shift) {
263 unsigned long port = mapbase;
264 unsigned long ctl = mapctl;
265
266 hw.io_ports_array[0] = port;
267#ifdef __BIG_ENDIAN
268 port++;
269 ctl++;
270#endif
271 for (i = 1; i <= 7; i++)
272 hw.io_ports_array[i] =
273 port + (i << pdata->ioport_shift);
274 hw.io_ports.ctl_addr = ctl;
275 } else
276 ide_std_init_ports(&hw, mapbase, mapctl);
277 hw.irq = irq;
278 hw.dev = &pdev->dev;
279
280 pr_info("TX4938 IDE interface (base %#lx, ctl %#lx, irq %d)\n",
281 mapbase, mapctl, hw.irq);
282 if (pdata->gbus_clock)
283 tx4938ide_tune_ebusc(pdata->ebus_ch, pdata->gbus_clock, 0);
284 else
285 d.port_ops = NULL;
286 ret = ide_host_add(&d, hws, &host);
287 if (!ret)
288 platform_set_drvdata(pdev, host);
289 return ret;
290}
291
292static int __exit tx4938ide_remove(struct platform_device *pdev)
293{
294 struct ide_host *host = platform_get_drvdata(pdev);
295
296 ide_host_remove(host);
297 return 0;
298}
299
300static struct platform_driver tx4938ide_driver = {
301 .driver = {
302 .name = "tx4938ide",
303 .owner = THIS_MODULE,
304 },
305 .remove = __exit_p(tx4938ide_remove),
306};
307
308static int __init tx4938ide_init(void)
309{
310 return platform_driver_probe(&tx4938ide_driver, tx4938ide_probe);
311}
312
313static void __exit tx4938ide_exit(void)
314{
315 platform_driver_unregister(&tx4938ide_driver);
316}
317
318module_init(tx4938ide_init);
319module_exit(tx4938ide_exit);
320
321MODULE_DESCRIPTION("TX4938 internal IDE driver");
322MODULE_LICENSE("GPL");
323MODULE_ALIAS("platform:tx4938ide");
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
new file mode 100644
index 000000000000..bafb7d1a22e2
--- /dev/null
+++ b/drivers/ide/tx4939ide.c
@@ -0,0 +1,754 @@
1/*
2 * TX4939 internal IDE driver
3 * Based on RBTX49xx patch from CELF patch archive.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 *
9 * (C) Copyright TOSHIBA CORPORATION 2005-2007
10 */
11
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/ide.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/platform_device.h>
18#include <linux/io.h>
19#include <linux/scatterlist.h>
20
21#define MODNAME "tx4939ide"
22
23/* ATA Shadow Registers (8-bit except for Data which is 16-bit) */
24#define TX4939IDE_Data 0x000
25#define TX4939IDE_Error_Feature 0x001
26#define TX4939IDE_Sec 0x002
27#define TX4939IDE_LBA0 0x003
28#define TX4939IDE_LBA1 0x004
29#define TX4939IDE_LBA2 0x005
30#define TX4939IDE_DevHead 0x006
31#define TX4939IDE_Stat_Cmd 0x007
32#define TX4939IDE_AltStat_DevCtl 0x402
33/* H/W DMA Registers */
34#define TX4939IDE_DMA_Cmd 0x800 /* 8-bit */
35#define TX4939IDE_DMA_Stat 0x802 /* 8-bit */
36#define TX4939IDE_PRD_Ptr 0x804 /* 32-bit */
37/* ATA100 CORE Registers (16-bit) */
38#define TX4939IDE_Sys_Ctl 0xc00
39#define TX4939IDE_Xfer_Cnt_1 0xc08
40#define TX4939IDE_Xfer_Cnt_2 0xc0a
41#define TX4939IDE_Sec_Cnt 0xc10
42#define TX4939IDE_Start_Lo_Addr 0xc18
43#define TX4939IDE_Start_Up_Addr 0xc20
44#define TX4939IDE_Add_Ctl 0xc28
45#define TX4939IDE_Lo_Burst_Cnt 0xc30
46#define TX4939IDE_Up_Burst_Cnt 0xc38
47#define TX4939IDE_PIO_Addr 0xc88
48#define TX4939IDE_H_Rst_Tim 0xc90
49#define TX4939IDE_Int_Ctl 0xc98
50#define TX4939IDE_Pkt_Cmd 0xcb8
51#define TX4939IDE_Bxfer_Cnt_Hi 0xcc0
52#define TX4939IDE_Bxfer_Cnt_Lo 0xcc8
53#define TX4939IDE_Dev_TErr 0xcd0
54#define TX4939IDE_Pkt_Xfer_Ctl 0xcd8
55#define TX4939IDE_Start_TAddr 0xce0
56
57/* bits for Int_Ctl */
58#define TX4939IDE_INT_ADDRERR 0x80
59#define TX4939IDE_INT_REACHMUL 0x40
60#define TX4939IDE_INT_DEVTIMING 0x20
61#define TX4939IDE_INT_UDMATERM 0x10
62#define TX4939IDE_INT_TIMER 0x08
63#define TX4939IDE_INT_BUSERR 0x04
64#define TX4939IDE_INT_XFEREND 0x02
65#define TX4939IDE_INT_HOST 0x01
66
67#define TX4939IDE_IGNORE_INTS \
68 (TX4939IDE_INT_ADDRERR | TX4939IDE_INT_REACHMUL | \
69 TX4939IDE_INT_DEVTIMING | TX4939IDE_INT_UDMATERM | \
70 TX4939IDE_INT_TIMER | TX4939IDE_INT_XFEREND)
71
72#ifdef __BIG_ENDIAN
73#define tx4939ide_swizzlel(a) ((a) ^ 4)
74#define tx4939ide_swizzlew(a) ((a) ^ 6)
75#define tx4939ide_swizzleb(a) ((a) ^ 7)
76#else
77#define tx4939ide_swizzlel(a) (a)
78#define tx4939ide_swizzlew(a) (a)
79#define tx4939ide_swizzleb(a) (a)
80#endif
81
82static u16 tx4939ide_readw(void __iomem *base, u32 reg)
83{
84 return __raw_readw(base + tx4939ide_swizzlew(reg));
85}
86static u8 tx4939ide_readb(void __iomem *base, u32 reg)
87{
88 return __raw_readb(base + tx4939ide_swizzleb(reg));
89}
90static void tx4939ide_writel(u32 val, void __iomem *base, u32 reg)
91{
92 __raw_writel(val, base + tx4939ide_swizzlel(reg));
93}
94static void tx4939ide_writew(u16 val, void __iomem *base, u32 reg)
95{
96 __raw_writew(val, base + tx4939ide_swizzlew(reg));
97}
98static void tx4939ide_writeb(u8 val, void __iomem *base, u32 reg)
99{
100 __raw_writeb(val, base + tx4939ide_swizzleb(reg));
101}
102
103#define TX4939IDE_BASE(hwif) ((void __iomem *)(hwif)->extra_base)
104
105static void tx4939ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
106{
107 ide_hwif_t *hwif = drive->hwif;
108 int is_slave = drive->dn;
109 u32 mask, val;
110 u8 safe = pio;
111 ide_drive_t *pair;
112
113 pair = ide_get_pair_dev(drive);
114 if (pair)
115 safe = min(safe, ide_get_best_pio_mode(pair, 255, 4));
116 /*
117 * Update Command Transfer Mode for master/slave and Data
118 * Transfer Mode for this drive.
119 */
120 mask = is_slave ? 0x07f00000 : 0x000007f0;
121 val = ((safe << 8) | (pio << 4)) << (is_slave ? 16 : 0);
122 hwif->select_data = (hwif->select_data & ~mask) | val;
123 /* tx4939ide_tf_load_fixup() will set the Sys_Ctl register */
124}
125
126static void tx4939ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
127{
128 ide_hwif_t *hwif = drive->hwif;
129 u32 mask, val;
130
131 /* Update Data Transfer Mode for this drive. */
132 if (mode >= XFER_UDMA_0)
133 val = mode - XFER_UDMA_0 + 8;
134 else
135 val = mode - XFER_MW_DMA_0 + 5;
136 if (drive->dn) {
137 mask = 0x00f00000;
138 val <<= 20;
139 } else {
140 mask = 0x000000f0;
141 val <<= 4;
142 }
143 hwif->select_data = (hwif->select_data & ~mask) | val;
144 /* tx4939ide_tf_load_fixup() will set the Sys_Ctl register */
145}
146
147static u16 tx4939ide_check_error_ints(ide_hwif_t *hwif)
148{
149 void __iomem *base = TX4939IDE_BASE(hwif);
150 u16 ctl = tx4939ide_readw(base, TX4939IDE_Int_Ctl);
151
152 if (ctl & TX4939IDE_INT_BUSERR) {
153 /* reset FIFO */
154 u16 sysctl = tx4939ide_readw(base, TX4939IDE_Sys_Ctl);
155
156 tx4939ide_writew(sysctl | 0x4000, base, TX4939IDE_Sys_Ctl);
157 mmiowb();
158 /* wait 12GBUSCLK (typ. 60ns @ GBUS200MHz, max 270ns) */
159 ndelay(270);
160 tx4939ide_writew(sysctl, base, TX4939IDE_Sys_Ctl);
161 }
162 if (ctl & (TX4939IDE_INT_ADDRERR |
163 TX4939IDE_INT_DEVTIMING | TX4939IDE_INT_BUSERR))
164 pr_err("%s: Error interrupt %#x (%s%s%s )\n",
165 hwif->name, ctl,
166 ctl & TX4939IDE_INT_ADDRERR ? " Address-Error" : "",
167 ctl & TX4939IDE_INT_DEVTIMING ? " DEV-Timing" : "",
168 ctl & TX4939IDE_INT_BUSERR ? " Bus-Error" : "");
169 return ctl;
170}
171
172static void tx4939ide_clear_irq(ide_drive_t *drive)
173{
174 ide_hwif_t *hwif;
175 void __iomem *base;
176 u16 ctl;
177
178 /*
179 * tx4939ide_dma_test_irq() and tx4939ide_dma_end() do all job
180 * for DMA case.
181 */
182 if (drive->waiting_for_dma)
183 return;
184 hwif = drive->hwif;
185 base = TX4939IDE_BASE(hwif);
186 ctl = tx4939ide_check_error_ints(hwif);
187 tx4939ide_writew(ctl, base, TX4939IDE_Int_Ctl);
188}
189
190static u8 tx4939ide_cable_detect(ide_hwif_t *hwif)
191{
192 void __iomem *base = TX4939IDE_BASE(hwif);
193
194 return tx4939ide_readw(base, TX4939IDE_Sys_Ctl) & 0x2000 ?
195 ATA_CBL_PATA40 : ATA_CBL_PATA80;
196}
197
198#ifdef __BIG_ENDIAN
199static void tx4939ide_dma_host_set(ide_drive_t *drive, int on)
200{
201 ide_hwif_t *hwif = drive->hwif;
202 u8 unit = drive->dn;
203 void __iomem *base = TX4939IDE_BASE(hwif);
204 u8 dma_stat = tx4939ide_readb(base, TX4939IDE_DMA_Stat);
205
206 if (on)
207 dma_stat |= (1 << (5 + unit));
208 else
209 dma_stat &= ~(1 << (5 + unit));
210
211 tx4939ide_writeb(dma_stat, base, TX4939IDE_DMA_Stat);
212}
213#else
214#define tx4939ide_dma_host_set ide_dma_host_set
215#endif
216
217static u8 tx4939ide_clear_dma_status(void __iomem *base)
218{
219 u8 dma_stat;
220
221 /* read DMA status for INTR & ERROR flags */
222 dma_stat = tx4939ide_readb(base, TX4939IDE_DMA_Stat);
223 /* clear INTR & ERROR flags */
224 tx4939ide_writeb(dma_stat | ATA_DMA_INTR | ATA_DMA_ERR, base,
225 TX4939IDE_DMA_Stat);
226 /* recover intmask cleared by writing to bit2 of DMA_Stat */
227 tx4939ide_writew(TX4939IDE_IGNORE_INTS << 8, base, TX4939IDE_Int_Ctl);
228 return dma_stat;
229}
230
231#ifdef __BIG_ENDIAN
232/* custom ide_build_dmatable to handle swapped layout */
233static int tx4939ide_build_dmatable(ide_drive_t *drive, struct request *rq)
234{
235 ide_hwif_t *hwif = drive->hwif;
236 u32 *table = (u32 *)hwif->dmatable_cpu;
237 unsigned int count = 0;
238 int i;
239 struct scatterlist *sg;
240
241 hwif->sg_nents = ide_build_sglist(drive, rq);
242 if (hwif->sg_nents == 0)
243 return 0;
244
245 for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
246 u32 cur_addr, cur_len, bcount;
247
248 cur_addr = sg_dma_address(sg);
249 cur_len = sg_dma_len(sg);
250
251 /*
252 * Fill in the DMA table, without crossing any 64kB boundaries.
253 */
254
255 while (cur_len) {
256 if (count++ >= PRD_ENTRIES)
257 goto use_pio_instead;
258
259 bcount = 0x10000 - (cur_addr & 0xffff);
260 if (bcount > cur_len)
261 bcount = cur_len;
262 *table++ = bcount & 0xffff;
263 *table++ = cur_addr;
264 cur_addr += bcount;
265 cur_len -= bcount;
266 }
267 }
268
269 if (count) {
270 *(table - 2) |= 0x80000000;
271 return count;
272 }
273
274use_pio_instead:
275 printk(KERN_ERR "%s: %s\n", drive->name,
276 count ? "DMA table too small" : "empty DMA table?");
277
278 ide_destroy_dmatable(drive);
279
280 return 0; /* revert to PIO for this request */
281}
282#else
283#define tx4939ide_build_dmatable ide_build_dmatable
284#endif
285
286static int tx4939ide_dma_setup(ide_drive_t *drive)
287{
288 ide_hwif_t *hwif = drive->hwif;
289 void __iomem *base = TX4939IDE_BASE(hwif);
290 struct request *rq = hwif->hwgroup->rq;
291 u8 reading;
292 int nent;
293
294 if (rq_data_dir(rq))
295 reading = 0;
296 else
297 reading = ATA_DMA_WR;
298
299 /* fall back to PIO! */
300 nent = tx4939ide_build_dmatable(drive, rq);
301 if (!nent) {
302 ide_map_sg(drive, rq);
303 return 1;
304 }
305
306 /* PRD table */
307 tx4939ide_writel(hwif->dmatable_dma, base, TX4939IDE_PRD_Ptr);
308
309 /* specify r/w */
310 tx4939ide_writeb(reading, base, TX4939IDE_DMA_Cmd);
311
312 /* clear INTR & ERROR flags */
313 tx4939ide_clear_dma_status(base);
314
315 drive->waiting_for_dma = 1;
316
317 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ?
318 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1);
319 tx4939ide_writew(rq->nr_sectors, base, TX4939IDE_Sec_Cnt);
320 return 0;
321}
322
323static int tx4939ide_dma_end(ide_drive_t *drive)
324{
325 ide_hwif_t *hwif = drive->hwif;
326 u8 dma_stat, dma_cmd;
327 void __iomem *base = TX4939IDE_BASE(hwif);
328 u16 ctl = tx4939ide_readw(base, TX4939IDE_Int_Ctl);
329
330 drive->waiting_for_dma = 0;
331
332 /* get DMA command mode */
333 dma_cmd = tx4939ide_readb(base, TX4939IDE_DMA_Cmd);
334 /* stop DMA */
335 tx4939ide_writeb(dma_cmd & ~ATA_DMA_START, base, TX4939IDE_DMA_Cmd);
336
337 /* read and clear the INTR & ERROR bits */
338 dma_stat = tx4939ide_clear_dma_status(base);
339
340 /* purge DMA mappings */
341 ide_destroy_dmatable(drive);
342 /* verify good DMA status */
343 wmb();
344
345 if ((dma_stat & (ATA_DMA_INTR | ATA_DMA_ERR | ATA_DMA_ACTIVE)) == 0 &&
346 (ctl & (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST)) ==
347 (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST))
348 /* INT_IDE lost... bug? */
349 return 0;
350 return ((dma_stat & (ATA_DMA_INTR | ATA_DMA_ERR | ATA_DMA_ACTIVE)) !=
351 ATA_DMA_INTR) ? 0x10 | dma_stat : 0;
352}
353
354/* returns 1 if DMA IRQ issued, 0 otherwise */
355static int tx4939ide_dma_test_irq(ide_drive_t *drive)
356{
357 ide_hwif_t *hwif = drive->hwif;
358 void __iomem *base = TX4939IDE_BASE(hwif);
359 u16 ctl, ide_int;
360 u8 dma_stat, stat;
361 int found = 0;
362
363 ctl = tx4939ide_check_error_ints(hwif);
364 ide_int = ctl & (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST);
365 switch (ide_int) {
366 case TX4939IDE_INT_HOST:
367 /* On error, XFEREND might not be asserted. */
368 stat = tx4939ide_readb(base, TX4939IDE_AltStat_DevCtl);
369 if ((stat & (ATA_BUSY | ATA_DRQ | ATA_ERR)) == ATA_ERR)
370 found = 1;
371 else
372 /* Wait for XFEREND (Mask HOST and unmask XFEREND) */
373 ctl &= ~TX4939IDE_INT_XFEREND << 8;
374 ctl |= ide_int << 8;
375 break;
376 case TX4939IDE_INT_HOST | TX4939IDE_INT_XFEREND:
377 dma_stat = tx4939ide_readb(base, TX4939IDE_DMA_Stat);
378 if (!(dma_stat & ATA_DMA_INTR))
379 pr_warning("%s: weird interrupt status. "
380 "DMA_Stat %#02x int_ctl %#04x\n",
381 hwif->name, dma_stat, ctl);
382 found = 1;
383 break;
384 }
385 /*
386 * Do not clear XFEREND, HOST now. They will be cleared by
387 * clearing bit2 of DMA_Stat.
388 */
389 ctl &= ~ide_int;
390 tx4939ide_writew(ctl, base, TX4939IDE_Int_Ctl);
391 return found;
392}
393
394static void tx4939ide_init_hwif(ide_hwif_t *hwif)
395{
396 void __iomem *base = TX4939IDE_BASE(hwif);
397
398 /* Soft Reset */
399 tx4939ide_writew(0x8000, base, TX4939IDE_Sys_Ctl);
400 mmiowb();
401 /* at least 20 GBUSCLK (typ. 100ns @ GBUS200MHz, max 450ns) */
402 ndelay(450);
403 tx4939ide_writew(0x0000, base, TX4939IDE_Sys_Ctl);
404 /* mask some interrupts and clear all interrupts */
405 tx4939ide_writew((TX4939IDE_IGNORE_INTS << 8) | 0xff, base,
406 TX4939IDE_Int_Ctl);
407
408 tx4939ide_writew(0x0008, base, TX4939IDE_Lo_Burst_Cnt);
409 tx4939ide_writew(0, base, TX4939IDE_Up_Burst_Cnt);
410}
411
412static int tx4939ide_init_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
413{
414 hwif->dma_base =
415 hwif->extra_base + tx4939ide_swizzleb(TX4939IDE_DMA_Cmd);
416 /*
417 * Note that we cannot use ATA_DMA_TABLE_OFS, ATA_DMA_STATUS
418 * for big endian.
419 */
420 return ide_allocate_dma_engine(hwif);
421}
422
423static void tx4939ide_tf_load_fixup(ide_drive_t *drive, ide_task_t *task)
424{
425 ide_hwif_t *hwif = drive->hwif;
426 void __iomem *base = TX4939IDE_BASE(hwif);
427 u16 sysctl = hwif->select_data >> (drive->dn ? 16 : 0);
428
429 /*
430 * Fix ATA100 CORE System Control Register. (The write to the
431 * Device/Head register may write wrong data to the System
432 * Control Register)
433 * While Sys_Ctl is written here, selectproc is not needed.
434 */
435 tx4939ide_writew(sysctl, base, TX4939IDE_Sys_Ctl);
436}
437
438#ifdef __BIG_ENDIAN
439
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) */
448static u8 tx4939ide_inb(unsigned long port)
449{
450 return __raw_readb((void __iomem *)port);
451}
452
453static void tx4939ide_outb(u8 value, unsigned long port)
454{
455 __raw_writeb(value, (void __iomem *)port);
456}
457
458static void tx4939ide_tf_load(ide_drive_t *drive, ide_task_t *task)
459{
460 ide_hwif_t *hwif = drive->hwif;
461 struct ide_io_ports *io_ports = &hwif->io_ports;
462 struct ide_taskfile *tf = &task->tf;
463 u8 HIHI = task->tf_flags & IDE_TFLAG_LBA48 ? 0xE0 : 0xEF;
464
465 if (task->tf_flags & IDE_TFLAG_FLAGGED)
466 HIHI = 0xFF;
467
468 if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
469 u16 data = (tf->hob_data << 8) | tf->data;
470
471 /* no endian swap */
472 __raw_writew(data, (void __iomem *)io_ports->data_addr);
473 }
474
475 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
476 tx4939ide_outb(tf->hob_feature, io_ports->feature_addr);
477 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
478 tx4939ide_outb(tf->hob_nsect, io_ports->nsect_addr);
479 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
480 tx4939ide_outb(tf->hob_lbal, io_ports->lbal_addr);
481 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
482 tx4939ide_outb(tf->hob_lbam, io_ports->lbam_addr);
483 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
484 tx4939ide_outb(tf->hob_lbah, io_ports->lbah_addr);
485
486 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
487 tx4939ide_outb(tf->feature, io_ports->feature_addr);
488 if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
489 tx4939ide_outb(tf->nsect, io_ports->nsect_addr);
490 if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
491 tx4939ide_outb(tf->lbal, io_ports->lbal_addr);
492 if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
493 tx4939ide_outb(tf->lbam, io_ports->lbam_addr);
494 if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
495 tx4939ide_outb(tf->lbah, io_ports->lbah_addr);
496
497 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) {
498 tx4939ide_outb((tf->device & HIHI) | drive->select,
499 io_ports->device_addr);
500 tx4939ide_tf_load_fixup(drive, task);
501 }
502}
503
504static void tx4939ide_tf_read(ide_drive_t *drive, ide_task_t *task)
505{
506 ide_hwif_t *hwif = drive->hwif;
507 struct ide_io_ports *io_ports = &hwif->io_ports;
508 struct ide_taskfile *tf = &task->tf;
509
510 if (task->tf_flags & IDE_TFLAG_IN_DATA) {
511 u16 data;
512
513 /* no endian swap */
514 data = __raw_readw((void __iomem *)io_ports->data_addr);
515 tf->data = data & 0xff;
516 tf->hob_data = (data >> 8) & 0xff;
517 }
518
519 /* be sure we're looking at the low order bits */
520 tx4939ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
521
522 if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
523 tf->feature = tx4939ide_inb(io_ports->feature_addr);
524 if (task->tf_flags & IDE_TFLAG_IN_NSECT)
525 tf->nsect = tx4939ide_inb(io_ports->nsect_addr);
526 if (task->tf_flags & IDE_TFLAG_IN_LBAL)
527 tf->lbal = tx4939ide_inb(io_ports->lbal_addr);
528 if (task->tf_flags & IDE_TFLAG_IN_LBAM)
529 tf->lbam = tx4939ide_inb(io_ports->lbam_addr);
530 if (task->tf_flags & IDE_TFLAG_IN_LBAH)
531 tf->lbah = tx4939ide_inb(io_ports->lbah_addr);
532 if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
533 tf->device = tx4939ide_inb(io_ports->device_addr);
534
535 if (task->tf_flags & IDE_TFLAG_LBA48) {
536 tx4939ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
537
538 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
539 tf->hob_feature =
540 tx4939ide_inb(io_ports->feature_addr);
541 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
542 tf->hob_nsect = tx4939ide_inb(io_ports->nsect_addr);
543 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
544 tf->hob_lbal = tx4939ide_inb(io_ports->lbal_addr);
545 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
546 tf->hob_lbam = tx4939ide_inb(io_ports->lbam_addr);
547 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
548 tf->hob_lbah = tx4939ide_inb(io_ports->lbah_addr);
549 }
550}
551
552static void tx4939ide_input_data_swap(ide_drive_t *drive, struct request *rq,
553 void *buf, unsigned int len)
554{
555 unsigned long port = drive->hwif->io_ports.data_addr;
556 unsigned short *ptr = buf;
557 unsigned int count = (len + 1) / 2;
558
559 while (count--)
560 *ptr++ = cpu_to_le16(__raw_readw((void __iomem *)port));
561 __ide_flush_dcache_range((unsigned long)buf, count * 2);
562}
563
564static void tx4939ide_output_data_swap(ide_drive_t *drive, struct request *rq,
565 void *buf, unsigned int len)
566{
567 unsigned long port = drive->hwif->io_ports.data_addr;
568 unsigned short *ptr = buf;
569 unsigned int count = (len + 1) / 2;
570
571 while (count--) {
572 __raw_writew(le16_to_cpu(*ptr), (void __iomem *)port);
573 ptr++;
574 }
575 __ide_flush_dcache_range((unsigned long)buf, count * 2);
576}
577
578static const struct ide_tp_ops tx4939ide_tp_ops = {
579 .exec_command = ide_exec_command,
580 .read_status = ide_read_status,
581 .read_altstatus = ide_read_altstatus,
582 .read_sff_dma_status = tx4939ide_read_sff_dma_status,
583
584 .set_irq = ide_set_irq,
585
586 .tf_load = tx4939ide_tf_load,
587 .tf_read = tx4939ide_tf_read,
588
589 .input_data = tx4939ide_input_data_swap,
590 .output_data = tx4939ide_output_data_swap,
591};
592
593#else /* __LITTLE_ENDIAN */
594
595static void tx4939ide_tf_load(ide_drive_t *drive, ide_task_t *task)
596{
597 ide_tf_load(drive, task);
598 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
599 tx4939ide_tf_load_fixup(drive, task);
600}
601
602static const struct ide_tp_ops tx4939ide_tp_ops = {
603 .exec_command = ide_exec_command,
604 .read_status = ide_read_status,
605 .read_altstatus = ide_read_altstatus,
606 .read_sff_dma_status = ide_read_sff_dma_status,
607
608 .set_irq = ide_set_irq,
609
610 .tf_load = tx4939ide_tf_load,
611 .tf_read = ide_tf_read,
612
613 .input_data = ide_input_data,
614 .output_data = ide_output_data,
615};
616
617#endif /* __LITTLE_ENDIAN */
618
619static const struct ide_port_ops tx4939ide_port_ops = {
620 .set_pio_mode = tx4939ide_set_pio_mode,
621 .set_dma_mode = tx4939ide_set_dma_mode,
622 .clear_irq = tx4939ide_clear_irq,
623 .cable_detect = tx4939ide_cable_detect,
624};
625
626static const struct ide_dma_ops tx4939ide_dma_ops = {
627 .dma_host_set = tx4939ide_dma_host_set,
628 .dma_setup = tx4939ide_dma_setup,
629 .dma_exec_cmd = ide_dma_exec_cmd,
630 .dma_start = ide_dma_start,
631 .dma_end = tx4939ide_dma_end,
632 .dma_test_irq = tx4939ide_dma_test_irq,
633 .dma_lost_irq = ide_dma_lost_irq,
634 .dma_timeout = ide_dma_timeout,
635};
636
637static const struct ide_port_info tx4939ide_port_info __initdata = {
638 .init_hwif = tx4939ide_init_hwif,
639 .init_dma = tx4939ide_init_dma,
640 .port_ops = &tx4939ide_port_ops,
641 .dma_ops = &tx4939ide_dma_ops,
642 .tp_ops = &tx4939ide_tp_ops,
643 .host_flags = IDE_HFLAG_MMIO,
644 .pio_mask = ATA_PIO4,
645 .mwdma_mask = ATA_MWDMA2,
646 .udma_mask = ATA_UDMA5,
647};
648
649static int __init tx4939ide_probe(struct platform_device *pdev)
650{
651 hw_regs_t hw;
652 hw_regs_t *hws[] = { &hw, NULL, NULL, NULL };
653 struct ide_host *host;
654 struct resource *res;
655 int irq, ret;
656 unsigned long mapbase;
657
658 irq = platform_get_irq(pdev, 0);
659 if (irq < 0)
660 return -ENODEV;
661 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
662 if (!res)
663 return -ENODEV;
664
665 if (!devm_request_mem_region(&pdev->dev, res->start,
666 res->end - res->start + 1, "tx4938ide"))
667 return -EBUSY;
668 mapbase = (unsigned long)devm_ioremap(&pdev->dev, res->start,
669 res->end - res->start + 1);
670 if (!mapbase)
671 return -EBUSY;
672 memset(&hw, 0, sizeof(hw));
673 hw.io_ports.data_addr =
674 mapbase + tx4939ide_swizzlew(TX4939IDE_Data);
675 hw.io_ports.error_addr =
676 mapbase + tx4939ide_swizzleb(TX4939IDE_Error_Feature);
677 hw.io_ports.nsect_addr =
678 mapbase + tx4939ide_swizzleb(TX4939IDE_Sec);
679 hw.io_ports.lbal_addr =
680 mapbase + tx4939ide_swizzleb(TX4939IDE_LBA0);
681 hw.io_ports.lbam_addr =
682 mapbase + tx4939ide_swizzleb(TX4939IDE_LBA1);
683 hw.io_ports.lbah_addr =
684 mapbase + tx4939ide_swizzleb(TX4939IDE_LBA2);
685 hw.io_ports.device_addr =
686 mapbase + tx4939ide_swizzleb(TX4939IDE_DevHead);
687 hw.io_ports.command_addr =
688 mapbase + tx4939ide_swizzleb(TX4939IDE_Stat_Cmd);
689 hw.io_ports.ctl_addr =
690 mapbase + tx4939ide_swizzleb(TX4939IDE_AltStat_DevCtl);
691 hw.irq = irq;
692 hw.dev = &pdev->dev;
693
694 pr_info("TX4939 IDE interface (base %#lx, irq %d)\n", mapbase, irq);
695 host = ide_host_alloc(&tx4939ide_port_info, hws);
696 if (!host)
697 return -ENOMEM;
698 /* use extra_base for base address of the all registers */
699 host->ports[0]->extra_base = mapbase;
700 ret = ide_host_register(host, &tx4939ide_port_info, hws);
701 if (ret) {
702 ide_host_free(host);
703 return ret;
704 }
705 platform_set_drvdata(pdev, host);
706 return 0;
707}
708
709static int __exit tx4939ide_remove(struct platform_device *pdev)
710{
711 struct ide_host *host = platform_get_drvdata(pdev);
712
713 ide_host_remove(host);
714 return 0;
715}
716
717#ifdef CONFIG_PM
718static int tx4939ide_resume(struct platform_device *dev)
719{
720 struct ide_host *host = platform_get_drvdata(dev);
721 ide_hwif_t *hwif = host->ports[0];
722
723 tx4939ide_init_hwif(hwif);
724 return 0;
725}
726#else
727#define tx4939ide_resume NULL
728#endif
729
730static struct platform_driver tx4939ide_driver = {
731 .driver = {
732 .name = MODNAME,
733 .owner = THIS_MODULE,
734 },
735 .remove = __exit_p(tx4939ide_remove),
736 .resume = tx4939ide_resume,
737};
738
739static int __init tx4939ide_init(void)
740{
741 return platform_driver_probe(&tx4939ide_driver, tx4939ide_probe);
742}
743
744static void __exit tx4939ide_exit(void)
745{
746 platform_driver_unregister(&tx4939ide_driver);
747}
748
749module_init(tx4939ide_init);
750module_exit(tx4939ide_exit);
751
752MODULE_DESCRIPTION("TX4939 internal IDE driver");
753MODULE_LICENSE("GPL");
754MODULE_ALIAS("platform:tx4939ide");
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/umc8672.c
index b54a14a57755..1da076e0c917 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/umc8672.c
@@ -45,7 +45,6 @@
45#include <linux/mm.h> 45#include <linux/mm.h>
46#include <linux/ioport.h> 46#include <linux/ioport.h>
47#include <linux/blkdev.h> 47#include <linux/blkdev.h>
48#include <linux/hdreg.h>
49#include <linux/ide.h> 48#include <linux/ide.h>
50#include <linux/init.h> 49#include <linux/init.h>
51 50
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/via82cxxx.c
index 94fb9ab3223f..2a812d3207e9 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/via82cxxx.c
@@ -154,7 +154,7 @@ static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
154static void via_set_drive(ide_drive_t *drive, const u8 speed) 154static void via_set_drive(ide_drive_t *drive, const u8 speed)
155{ 155{
156 ide_hwif_t *hwif = drive->hwif; 156 ide_hwif_t *hwif = drive->hwif;
157 ide_drive_t *peer = hwif->drives + (~drive->dn & 1); 157 ide_drive_t *peer = ide_get_pair_dev(drive);
158 struct pci_dev *dev = to_pci_dev(hwif->dev); 158 struct pci_dev *dev = to_pci_dev(hwif->dev);
159 struct ide_host *host = pci_get_drvdata(dev); 159 struct ide_host *host = pci_get_drvdata(dev);
160 struct via82cxxx_dev *vdev = host->host_priv; 160 struct via82cxxx_dev *vdev = host->host_priv;
@@ -173,7 +173,7 @@ static void via_set_drive(ide_drive_t *drive, const u8 speed)
173 173
174 ide_timing_compute(drive, speed, &t, T, UT); 174 ide_timing_compute(drive, speed, &t, T, UT);
175 175
176 if (peer->present) { 176 if (peer) {
177 ide_timing_compute(peer, peer->current_speed, &p, T, UT); 177 ide_timing_compute(peer, peer->current_speed, &p, T, UT);
178 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); 178 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
179 } 179 }
@@ -215,7 +215,7 @@ static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
215/* 215/*
216 * Check and handle 80-wire cable presence 216 * Check and handle 80-wire cable presence
217 */ 217 */
218static void __devinit via_cable_detect(struct via82cxxx_dev *vdev, u32 u) 218static void via_cable_detect(struct via82cxxx_dev *vdev, u32 u)
219{ 219{
220 int i; 220 int i;
221 221
@@ -267,7 +267,7 @@ static void __devinit via_cable_detect(struct via82cxxx_dev *vdev, u32 u)
267 * and initialize its drive independent registers. 267 * and initialize its drive independent registers.
268 */ 268 */
269 269
270static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev) 270static unsigned int init_chipset_via82cxxx(struct pci_dev *dev)
271{ 271{
272 struct ide_host *host = pci_get_drvdata(dev); 272 struct ide_host *host = pci_get_drvdata(dev);
273 struct via82cxxx_dev *vdev = host->host_priv; 273 struct via82cxxx_dev *vdev = host->host_priv;
@@ -487,21 +487,23 @@ static const struct pci_device_id via_pci_tbl[] = {
487}; 487};
488MODULE_DEVICE_TABLE(pci, via_pci_tbl); 488MODULE_DEVICE_TABLE(pci, via_pci_tbl);
489 489
490static struct pci_driver driver = { 490static struct pci_driver via_pci_driver = {
491 .name = "VIA_IDE", 491 .name = "VIA_IDE",
492 .id_table = via_pci_tbl, 492 .id_table = via_pci_tbl,
493 .probe = via_init_one, 493 .probe = via_init_one,
494 .remove = __devexit_p(via_remove), 494 .remove = __devexit_p(via_remove),
495 .suspend = ide_pci_suspend,
496 .resume = ide_pci_resume,
495}; 497};
496 498
497static int __init via_ide_init(void) 499static int __init via_ide_init(void)
498{ 500{
499 return ide_pci_register_driver(&driver); 501 return ide_pci_register_driver(&via_pci_driver);
500} 502}
501 503
502static void __exit via_ide_exit(void) 504static void __exit via_ide_exit(void)
503{ 505{
504 pci_unregister_driver(&driver); 506 pci_unregister_driver(&via_pci_driver);
505} 507}
506 508
507module_init(via_ide_init); 509module_init(via_ide_init);