aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/Kconfig67
-rw-r--r--drivers/ide/Makefile7
-rw-r--r--drivers/ide/arm/icside.c5
-rw-r--r--drivers/ide/arm/ide_arm.c3
-rw-r--r--drivers/ide/arm/palm_bk3710.c18
-rw-r--r--drivers/ide/ide-acpi.c6
-rw-r--r--drivers/ide/ide-atapi.c236
-rw-r--r--drivers/ide/ide-cd.c130
-rw-r--r--drivers/ide/ide-disk.c380
-rw-r--r--drivers/ide/ide-dma.c58
-rw-r--r--drivers/ide/ide-floppy.c679
-rw-r--r--drivers/ide/ide-floppy.h63
-rw-r--r--drivers/ide/ide-floppy_ioctl.c243
-rw-r--r--drivers/ide/ide-generic.c55
-rw-r--r--drivers/ide/ide-io.c117
-rw-r--r--drivers/ide/ide-ioctls.c290
-rw-r--r--drivers/ide/ide-iops.c225
-rw-r--r--drivers/ide/ide-lib.c73
-rw-r--r--drivers/ide/ide-probe.c256
-rw-r--r--drivers/ide/ide-proc.c306
-rw-r--r--drivers/ide/ide-tape.c499
-rw-r--r--drivers/ide/ide-taskfile.c156
-rw-r--r--drivers/ide/ide-timings.c22
-rw-r--r--drivers/ide/ide.c238
-rw-r--r--drivers/ide/legacy/ali14xx.c1
-rw-r--r--drivers/ide/legacy/buddha.c1
-rw-r--r--drivers/ide/legacy/dtc2278.c1
-rw-r--r--drivers/ide/legacy/falconide.c1
-rw-r--r--drivers/ide/legacy/gayle.c1
-rw-r--r--drivers/ide/legacy/ht6560b.c1
-rw-r--r--drivers/ide/legacy/ide-cs.c1
-rw-r--r--drivers/ide/legacy/macide.c1
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/legacy/qd65xx.c23
-rw-r--r--drivers/ide/legacy/umc8672.c1
-rw-r--r--drivers/ide/mips/Makefile1
-rw-r--r--drivers/ide/mips/swarm.c196
-rw-r--r--drivers/ide/pci/aec62xx.c9
-rw-r--r--drivers/ide/pci/alim15x3.c11
-rw-r--r--drivers/ide/pci/amd74xx.c10
-rw-r--r--drivers/ide/pci/atiixp.c5
-rw-r--r--drivers/ide/pci/cmd640.c43
-rw-r--r--drivers/ide/pci/cmd64x.c7
-rw-r--r--drivers/ide/pci/cs5520.c4
-rw-r--r--drivers/ide/pci/cs5530.c19
-rw-r--r--drivers/ide/pci/cs5535.c16
-rw-r--r--drivers/ide/pci/cy82c693.c6
-rw-r--r--drivers/ide/pci/delkin_cb.c1
-rw-r--r--drivers/ide/pci/generic.c3
-rw-r--r--drivers/ide/pci/hpt34x.c5
-rw-r--r--drivers/ide/pci/hpt366.c110
-rw-r--r--drivers/ide/pci/it8213.c5
-rw-r--r--drivers/ide/pci/it821x.c64
-rw-r--r--drivers/ide/pci/jmicron.c5
-rw-r--r--drivers/ide/pci/ns87415.c9
-rw-r--r--drivers/ide/pci/opti621.c7
-rw-r--r--drivers/ide/pci/pdc202xx_new.c19
-rw-r--r--drivers/ide/pci/pdc202xx_old.c13
-rw-r--r--drivers/ide/pci/piix.c7
-rw-r--r--drivers/ide/pci/rz1000.c1
-rw-r--r--drivers/ide/pci/sc1200.c15
-rw-r--r--drivers/ide/pci/scc_pata.c9
-rw-r--r--drivers/ide/pci/serverworks.c17
-rw-r--r--drivers/ide/pci/sgiioc4.c5
-rw-r--r--drivers/ide/pci/siimage.c23
-rw-r--r--drivers/ide/pci/sis5513.c9
-rw-r--r--drivers/ide/pci/sl82c105.c7
-rw-r--r--drivers/ide/pci/slc90e66.c5
-rw-r--r--drivers/ide/pci/tc86c001.c4
-rw-r--r--drivers/ide/pci/triflex.c3
-rw-r--r--drivers/ide/pci/trm290.c1
-rw-r--r--drivers/ide/pci/via82cxxx.c14
-rw-r--r--drivers/ide/ppc/pmac.c19
-rw-r--r--drivers/ide/setup-pci.c33
74 files changed, 2172 insertions, 2734 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 130ef64b44f7..b50b5dac95b0 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -54,16 +54,6 @@ menuconfig IDE
54 54
55if IDE 55if IDE
56 56
57config IDE_MAX_HWIFS
58 int "Max IDE interfaces"
59 depends on ALPHA || SUPERH || IA64 || EMBEDDED
60 range 1 10
61 default 4
62 help
63 This is the maximum number of IDE hardware interfaces that will
64 be supported by the driver. Make sure it is at least as high as
65 the number of IDE interfaces in your system.
66
67config BLK_DEV_IDE 57config BLK_DEV_IDE
68 tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support" 58 tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support"
69 ---help--- 59 ---help---
@@ -141,29 +131,6 @@ config BLK_DEV_IDEDISK
141 131
142 If unsure, say Y. 132 If unsure, say Y.
143 133
144config IDEDISK_MULTI_MODE
145 bool "Use multiple sector mode for Programmed Input/Output by default"
146 help
147 This setting is irrelevant for most IDE disks, with direct memory
148 access, to which multiple sector mode does not apply. Multiple sector
149 mode is a feature of most modern IDE hard drives, permitting the
150 transfer of multiple sectors per Programmed Input/Output interrupt,
151 rather than the usual one sector per interrupt. When this feature is
152 enabled, it can reduce operating system overhead for disk Programmed
153 Input/Output. On some systems, it also can increase the data
154 throughput of Programmed Input/Output. Some drives, however, seemed
155 to run slower with multiple sector mode enabled. Some drives claimed
156 to support multiple sector mode, but lost data at some settings.
157 Under rare circumstances, such failures could result in massive
158 filesystem corruption.
159
160 If you get the following error, try to say Y here:
161
162 hda: set_multmode: status=0x51 { DriveReady SeekComplete Error }
163 hda: set_multmode: error=0x04 { DriveStatusError }
164
165 If in doubt, say N.
166
167config BLK_DEV_IDECS 134config BLK_DEV_IDECS
168 tristate "PCMCIA IDE support" 135 tristate "PCMCIA IDE support"
169 depends on PCMCIA 136 depends on PCMCIA
@@ -252,7 +219,7 @@ config BLK_DEV_IDEFLOPPY
252 module will be called ide-floppy. 219 module will be called ide-floppy.
253 220
254config BLK_DEV_IDESCSI 221config BLK_DEV_IDESCSI
255 tristate "SCSI emulation support" 222 tristate "SCSI emulation support (DEPRECATED)"
256 depends on SCSI 223 depends on SCSI
257 select IDE_ATAPI 224 select IDE_ATAPI
258 ---help--- 225 ---help---
@@ -265,20 +232,6 @@ config BLK_DEV_IDESCSI
265 and will allow you to use a SCSI device driver instead of a native 232 and will allow you to use a SCSI device driver instead of a native
266 ATAPI driver. 233 ATAPI driver.
267 234
268 This is useful if you have an ATAPI device for which no native
269 driver has been written (for example, an ATAPI PD-CD drive);
270 you can then use this emulation together with an appropriate SCSI
271 device driver. In order to do this, say Y here and to "SCSI support"
272 and "SCSI generic support", below. You must then provide the kernel
273 command line "hdx=ide-scsi" (try "man bootparam" or see the
274 documentation of your boot loader (lilo or loadlin) about how to
275 pass options to the kernel at boot time) for devices if you want the
276 native EIDE sub-drivers to skip over the native support, so that
277 this SCSI emulation can be used instead.
278
279 Note that this option does NOT allow you to attach SCSI devices to a
280 box that doesn't have a SCSI host adapter installed.
281
282 If both this SCSI emulation and native ATAPI support are compiled 235 If both this SCSI emulation and native ATAPI support are compiled
283 into the kernel, the native support will be used. 236 into the kernel, the native support will be used.
284 237
@@ -316,6 +269,20 @@ config IDE_GENERIC
316 tristate "generic/default IDE chipset support" 269 tristate "generic/default IDE chipset support"
317 depends on ALPHA || X86 || IA64 || M32R || MIPS 270 depends on ALPHA || X86 || IA64 || M32R || MIPS
318 help 271 help
272 This is the generic IDE driver. This driver attaches to the
273 fixed legacy ports (e.g. on PCs 0x1f0/0x170, 0x1e8/0x168 and
274 so on). Please note that if this driver is built into the
275 kernel or loaded before other ATA (IDE or libata) drivers
276 and the controller is located at legacy ports, this driver
277 may grab those ports and thus can prevent the controller
278 specific driver from attaching.
279
280 Also, currently, IDE generic doesn't allow IRQ sharing
281 meaning that the IRQs it grabs won't be available to other
282 controllers sharing those IRQs which usually makes drivers
283 for those controllers fail. Generally, it's not a good idea
284 to load IDE generic driver on modern systems.
285
319 If unsure, say N. 286 If unsure, say N.
320 287
321config BLK_DEV_PLATFORM 288config BLK_DEV_PLATFORM
@@ -790,10 +757,6 @@ config BLK_DEV_IDEDMA_PMAC
790 to transfer data to and from memory. Saying Y is safe and improves 757 to transfer data to and from memory. Saying Y is safe and improves
791 performance. 758 performance.
792 759
793config BLK_DEV_IDE_SWARM
794 tristate "IDE for Sibyte evaluation boards"
795 depends on SIBYTE_SB1xxx_SOC
796
797config BLK_DEV_IDE_AU1XXX 760config BLK_DEV_IDE_AU1XXX
798 bool "IDE for AMD Alchemy Au1200" 761 bool "IDE for AMD Alchemy Au1200"
799 depends on SOC_AU1200 762 depends on SOC_AU1200
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 64e0ecdc4ed5..308b8a12f314 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -4,8 +4,8 @@
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-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
@@ -37,11 +37,12 @@ obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
37obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 37obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
38 38
39ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o 39ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
40ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
40 41
41obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o 42obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o
42obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o 43obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
44obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o
43obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o 45obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o
44obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy.o
45 46
46ifeq ($(CONFIG_BLK_DEV_IDECS), y) 47ifeq ($(CONFIG_BLK_DEV_IDECS), y)
47 ide-cs-core-y += legacy/ide-cs.o 48 ide-cs-core-y += legacy/ide-cs.o
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index df4af4083954..70f5b164828b 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/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
diff --git a/drivers/ide/arm/ide_arm.c b/drivers/ide/arm/ide_arm.c
index 176532ffae0e..f728f2927b5a 100644
--- a/drivers/ide/arm/ide_arm.c
+++ b/drivers/ide/arm/ide_arm.c
@@ -11,13 +11,12 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/ide.h> 12#include <linux/ide.h>
13 13
14#include <asm/mach-types.h>
15#include <asm/irq.h> 14#include <asm/irq.h>
16 15
17#define DRV_NAME "ide_arm" 16#define DRV_NAME "ide_arm"
18 17
19#ifdef CONFIG_ARCH_CLPS7500 18#ifdef CONFIG_ARCH_CLPS7500
20# include <asm/arch/hardware.h> 19# include <mach/hardware.h>
21# 20#
22# define IDE_ARM_IO (ISASLOT_IO + 0x1f0) 21# define IDE_ARM_IO (ISASLOT_IO + 0x1f0)
23# define IDE_ARM_IRQ IRQ_ISA_14 22# define IDE_ARM_IRQ IRQ_ISA_14
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
index 3e842d60eae9..122ed3c072fd 100644
--- a/drivers/ide/arm/palm_bk3710.c
+++ b/drivers/ide/arm/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
@@ -309,7 +309,7 @@ static void __devinit palm_bk3710_chipinit(void __iomem *base)
309 palm_bk3710_setpiomode(base, NULL, 1, 600, 0); 309 palm_bk3710_setpiomode(base, NULL, 1, 600, 0);
310} 310}
311 311
312static u8 __devinit palm_bk3710_cable_detect(ide_hwif_t *hwif) 312static u8 palm_bk3710_cable_detect(ide_hwif_t *hwif)
313{ 313{
314 return ATA_CBL_PATA80; 314 return ATA_CBL_PATA80;
315} 315}
@@ -343,11 +343,10 @@ static struct ide_port_info __devinitdata palm_bk3710_port_info = {
343 .mwdma_mask = ATA_MWDMA2, 343 .mwdma_mask = ATA_MWDMA2,
344}; 344};
345 345
346static int __devinit palm_bk3710_probe(struct platform_device *pdev) 346static int __init palm_bk3710_probe(struct platform_device *pdev)
347{ 347{
348 struct clk *clk; 348 struct clk *clk;
349 struct resource *mem, *irq; 349 struct resource *mem, *irq;
350 struct ide_host *host;
351 unsigned long base, rate; 350 unsigned long base, rate;
352 int i, rc; 351 int i, rc;
353 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 352 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
@@ -390,6 +389,7 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev)
390 hw.io_ports_array[i] = base + IDE_PALM_ATA_PRI_REG_OFFSET + i; 389 hw.io_ports_array[i] = base + IDE_PALM_ATA_PRI_REG_OFFSET + i;
391 hw.io_ports.ctl_addr = base + IDE_PALM_ATA_PRI_CTL_OFFSET; 390 hw.io_ports.ctl_addr = base + IDE_PALM_ATA_PRI_CTL_OFFSET;
392 hw.irq = irq->start; 391 hw.irq = irq->start;
392 hw.dev = &pdev->dev;
393 hw.chipset = ide_palm3710; 393 hw.chipset = ide_palm3710;
394 394
395 palm_bk3710_port_info.udma_mask = rate < 100000000 ? ATA_UDMA4 : 395 palm_bk3710_port_info.udma_mask = rate < 100000000 ? ATA_UDMA4 :
@@ -413,13 +413,11 @@ static struct platform_driver platform_bk_driver = {
413 .name = "palm_bk3710", 413 .name = "palm_bk3710",
414 .owner = THIS_MODULE, 414 .owner = THIS_MODULE,
415 }, 415 },
416 .probe = palm_bk3710_probe,
417 .remove = NULL,
418}; 416};
419 417
420static int __init palm_bk3710_init(void) 418static int __init palm_bk3710_init(void)
421{ 419{
422 return platform_driver_register(&platform_bk_driver); 420 return platform_driver_probe(&platform_bk_driver, palm_bk3710_probe);
423} 421}
424 422
425module_init(palm_bk3710_init); 423module_init(palm_bk3710_init);
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 6f704628c27d..2427c380b3dc 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -584,7 +584,7 @@ void ide_acpi_get_timing(ide_hwif_t *hwif)
584 * This function executes the _STM ACPI method for the target channel. 584 * This function executes the _STM ACPI method for the target channel.
585 * 585 *
586 * _STM requires Identify Drive data, which has to passed as an argument. 586 * _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 587 * Unfortunately drive->id is a mangled version which we can't readily
588 * use; hence we'll get the information afresh. 588 * use; hence we'll get the information afresh.
589 */ 589 */
590void ide_acpi_push_timing(ide_hwif_t *hwif) 590void ide_acpi_push_timing(ide_hwif_t *hwif)
@@ -614,10 +614,10 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
614 in_params[0].buffer.length = sizeof(struct GTM_buffer); 614 in_params[0].buffer.length = sizeof(struct GTM_buffer);
615 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm; 615 in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
616 in_params[1].type = ACPI_TYPE_BUFFER; 616 in_params[1].type = ACPI_TYPE_BUFFER;
617 in_params[1].buffer.length = sizeof(struct hd_driveid); 617 in_params[1].buffer.length = sizeof(ATA_ID_WORDS * 2);
618 in_params[1].buffer.pointer = (u8 *)&master->idbuff; 618 in_params[1].buffer.pointer = (u8 *)&master->idbuff;
619 in_params[2].type = ACPI_TYPE_BUFFER; 619 in_params[2].type = ACPI_TYPE_BUFFER;
620 in_params[2].buffer.length = sizeof(struct hd_driveid); 620 in_params[2].buffer.length = sizeof(ATA_ID_WORDS * 2);
621 in_params[2].buffer.pointer = (u8 *)&slave->idbuff; 621 in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
622 /* Output buffer: _STM has no output */ 622 /* Output buffer: _STM has no output */
623 623
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index adf04f99cdeb..608c5bade929 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -14,12 +14,201 @@
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/*
18 * Check whether we can support a device,
19 * based on the ATAPI IDENTIFY command results.
20 */
21int ide_check_atapi_device(ide_drive_t *drive, const char *s)
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 */
127void 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}
140EXPORT_SYMBOL_GPL(ide_queue_pc_head);
141
142/*
143 * Add a special packet command request to the tail of the request queue,
144 * and wait for it to be serviced.
145 */
146int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
147 struct ide_atapi_pc *pc)
148{
149 struct request *rq;
150 int error;
151
152 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
153 rq->cmd_type = REQ_TYPE_SPECIAL;
154 rq->buffer = (char *)pc;
155 memcpy(rq->cmd, pc->c, 12);
156 if (drive->media == ide_tape)
157 rq->cmd[13] = REQ_IDETAPE_PC1;
158 error = blk_execute_rq(drive->queue, disk, rq, 0);
159 blk_put_request(rq);
160
161 return error;
162}
163EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
164
165int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
166{
167 struct ide_atapi_pc pc;
168
169 ide_init_pc(&pc);
170 pc.c[0] = TEST_UNIT_READY;
171
172 return ide_queue_pc_tail(drive, disk, &pc);
173}
174EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
175
176int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
177{
178 struct ide_atapi_pc pc;
179
180 ide_init_pc(&pc);
181 pc.c[0] = START_STOP;
182 pc.c[4] = start;
183
184 if (drive->media == ide_tape)
185 pc.flags |= PC_FLAG_WAIT_FOR_DSC;
186
187 return ide_queue_pc_tail(drive, disk, &pc);
188}
189EXPORT_SYMBOL_GPL(ide_do_start_stop);
190
191int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
192{
193 struct ide_atapi_pc pc;
194
195 if (drive->atapi_flags & IDE_AFLAG_NO_DOORLOCK)
196 return 0;
197
198 ide_init_pc(&pc);
199 pc.c[0] = ALLOW_MEDIUM_REMOVAL;
200 pc.c[4] = on;
201
202 return ide_queue_pc_tail(drive, disk, &pc);
203}
204EXPORT_SYMBOL_GPL(ide_set_media_lock);
205
17/* TODO: unify the code thus making some arguments go away */ 206/* TODO: unify the code thus making some arguments go away */
18ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, 207ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
19 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, 208 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
20 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), 209 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
21 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), 210 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
22 void (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int)) 211 int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
23{ 212{
24 ide_hwif_t *hwif = drive->hwif; 213 ide_hwif_t *hwif = drive->hwif;
25 struct request *rq = hwif->hwgroup->rq; 214 struct request *rq = hwif->hwgroup->rq;
@@ -41,7 +230,7 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
41 230
42 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { 231 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
43 if (hwif->dma_ops->dma_end(drive) || 232 if (hwif->dma_ops->dma_end(drive) ||
44 (drive->media == ide_tape && !scsi && (stat & ERR_STAT))) { 233 (drive->media == ide_tape && !scsi && (stat & ATA_ERR))) {
45 if (drive->media == ide_floppy && !scsi) 234 if (drive->media == ide_floppy && !scsi)
46 printk(KERN_ERR "%s: DMA %s error\n", 235 printk(KERN_ERR "%s: DMA %s error\n",
47 drive->name, rq_data_dir(pc->rq) 236 drive->name, rq_data_dir(pc->rq)
@@ -56,7 +245,7 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
56 } 245 }
57 246
58 /* No more interrupts */ 247 /* No more interrupts */
59 if ((stat & DRQ_STAT) == 0) { 248 if ((stat & ATA_DRQ) == 0) {
60 debug_log("Packet command completed, %d bytes transferred\n", 249 debug_log("Packet command completed, %d bytes transferred\n",
61 pc->xferred); 250 pc->xferred);
62 251
@@ -65,10 +254,10 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
65 local_irq_enable_in_hardirq(); 254 local_irq_enable_in_hardirq();
66 255
67 if (drive->media == ide_tape && !scsi && 256 if (drive->media == ide_tape && !scsi &&
68 (stat & ERR_STAT) && rq->cmd[0] == REQUEST_SENSE) 257 (stat & ATA_ERR) && rq->cmd[0] == REQUEST_SENSE)
69 stat &= ~ERR_STAT; 258 stat &= ~ATA_ERR;
70 259
71 if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) { 260 if ((stat & ATA_ERR) || (pc->flags & PC_FLAG_DMA_ERROR)) {
72 /* Error detected */ 261 /* Error detected */
73 debug_log("%s: I/O error\n", drive->name); 262 debug_log("%s: I/O error\n", drive->name);
74 263
@@ -95,7 +284,7 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
95cmd_finished: 284cmd_finished:
96 pc->error = 0; 285 pc->error = 0;
97 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && 286 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) &&
98 (stat & SEEK_STAT) == 0) { 287 (stat & ATA_DSC) == 0) {
99 dsc_handle(drive); 288 dsc_handle(drive);
100 return ide_stopped; 289 return ide_stopped;
101 } 290 }
@@ -117,17 +306,18 @@ cmd_finished:
117 /* Get the number of bytes to transfer on this interrupt. */ 306 /* Get the number of bytes to transfer on this interrupt. */
118 ide_read_bcount_and_ireason(drive, &bcount, &ireason); 307 ide_read_bcount_and_ireason(drive, &bcount, &ireason);
119 308
120 if (ireason & CD) { 309 if (ireason & ATAPI_COD) {
121 printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__); 310 printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__);
122 return ide_do_reset(drive); 311 return ide_do_reset(drive);
123 } 312 }
124 313
125 if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) { 314 if (((ireason & ATAPI_IO) == ATAPI_IO) ==
315 !!(pc->flags & PC_FLAG_WRITING)) {
126 /* Hopefully, we will never get here */ 316 /* Hopefully, we will never get here */
127 printk(KERN_ERR "%s: We wanted to %s, but the device wants us " 317 printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
128 "to %s!\n", drive->name, 318 "to %s!\n", drive->name,
129 (ireason & IO) ? "Write" : "Read", 319 (ireason & ATAPI_IO) ? "Write" : "Read",
130 (ireason & IO) ? "Read" : "Write"); 320 (ireason & ATAPI_IO) ? "Read" : "Write");
131 return ide_do_reset(drive); 321 return ide_do_reset(drive);
132 } 322 }
133 323
@@ -171,9 +361,14 @@ cmd_finished:
171 361
172 if ((drive->media == ide_floppy && !scsi && !pc->buf) || 362 if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
173 (drive->media == ide_tape && !scsi && pc->bh) || 363 (drive->media == ide_tape && !scsi && pc->bh) ||
174 (scsi && pc->sg)) 364 (scsi && pc->sg)) {
175 io_buffers(drive, pc, bcount, !!(pc->flags & PC_FLAG_WRITING)); 365 int done = io_buffers(drive, pc, bcount,
176 else 366 !!(pc->flags & PC_FLAG_WRITING));
367
368 /* FIXME: don't do partial completions */
369 if (drive->media == ide_floppy && !scsi)
370 ide_end_request(drive, 1, done >> 9);
371 } else
177 xferfunc(drive, NULL, pc->cur_pos, bcount); 372 xferfunc(drive, NULL, pc->cur_pos, bcount);
178 373
179 /* Update the current position */ 374 /* Update the current position */
@@ -205,7 +400,8 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
205{ 400{
206 int retries = 100; 401 int retries = 100;
207 402
208 while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) { 403 while (retries-- && ((ireason & ATAPI_COD) == 0 ||
404 (ireason & ATAPI_IO))) {
209 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " 405 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
210 "a packet command, retrying\n", drive->name); 406 "a packet command, retrying\n", drive->name);
211 udelay(100); 407 udelay(100);
@@ -214,8 +410,8 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
214 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " 410 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
215 "a packet command, ignoring\n", 411 "a packet command, ignoring\n",
216 drive->name); 412 drive->name);
217 ireason |= CD; 413 ireason |= ATAPI_COD;
218 ireason &= ~IO; 414 ireason &= ~ATAPI_IO;
219 } 415 }
220 } 416 }
221 417
@@ -231,7 +427,7 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
231 ide_startstop_t startstop; 427 ide_startstop_t startstop;
232 u8 ireason; 428 u8 ireason;
233 429
234 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { 430 if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) {
235 printk(KERN_ERR "%s: Strange, packet command initiated yet " 431 printk(KERN_ERR "%s: Strange, packet command initiated yet "
236 "DRQ isn't asserted\n", drive->name); 432 "DRQ isn't asserted\n", drive->name);
237 return startstop; 433 return startstop;
@@ -241,7 +437,7 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
241 if (drive->media == ide_tape && !drive->scsi) 437 if (drive->media == ide_tape && !drive->scsi)
242 ireason = ide_wait_ireason(drive, ireason); 438 ireason = ide_wait_ireason(drive, ireason);
243 439
244 if ((ireason & CD) == 0 || (ireason & IO)) { 440 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
245 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing " 441 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
246 "a packet command\n", drive->name); 442 "a packet command\n", drive->name);
247 return ide_do_reset(drive); 443 return ide_do_reset(drive);
@@ -303,7 +499,7 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
303 499
304 /* Issue the packet command */ 500 /* Issue the packet command */
305 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 501 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
306 ide_execute_command(drive, WIN_PACKETCMD, handler, 502 ide_execute_command(drive, ATA_CMD_PACKET, handler,
307 timeout, NULL); 503 timeout, NULL);
308 return ide_started; 504 return ide_started;
309 } else { 505 } else {
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index e617cf08aef6..465a92ca0179 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -66,11 +66,11 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
66 mutex_lock(&idecd_ref_mutex); 66 mutex_lock(&idecd_ref_mutex);
67 cd = ide_cd_g(disk); 67 cd = ide_cd_g(disk);
68 if (cd) { 68 if (cd) {
69 kref_get(&cd->kref); 69 if (ide_device_get(cd->drive))
70 if (ide_device_get(cd->drive)) {
71 kref_put(&cd->kref, ide_cd_release);
72 cd = NULL; 70 cd = NULL;
73 } 71 else
72 kref_get(&cd->kref);
73
74 } 74 }
75 mutex_unlock(&idecd_ref_mutex); 75 mutex_unlock(&idecd_ref_mutex);
76 return cd; 76 return cd;
@@ -78,9 +78,11 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
78 78
79static void ide_cd_put(struct cdrom_info *cd) 79static void ide_cd_put(struct cdrom_info *cd)
80{ 80{
81 ide_drive_t *drive = cd->drive;
82
81 mutex_lock(&idecd_ref_mutex); 83 mutex_lock(&idecd_ref_mutex);
82 ide_device_put(cd->drive);
83 kref_put(&cd->kref, ide_cd_release); 84 kref_put(&cd->kref, ide_cd_release);
85 ide_device_put(drive);
84 mutex_unlock(&idecd_ref_mutex); 86 mutex_unlock(&idecd_ref_mutex);
85} 87}
86 88
@@ -434,7 +436,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
434 ide_dump_status_no_sense(drive, "media error (blank)", 436 ide_dump_status_no_sense(drive, "media error (blank)",
435 stat); 437 stat);
436 do_end_request = 1; 438 do_end_request = 1;
437 } else if ((err & ~ABRT_ERR) != 0) { 439 } else if ((err & ~ATA_ABORTED) != 0) {
438 /* go to the default handler for other errors */ 440 /* go to the default handler for other errors */
439 ide_error(drive, "cdrom_decode_status", stat); 441 ide_error(drive, "cdrom_decode_status", stat);
440 return 1; 442 return 1;
@@ -455,7 +457,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
455 * If we got a CHECK_CONDITION status, queue 457 * If we got a CHECK_CONDITION status, queue
456 * a request sense command. 458 * a request sense command.
457 */ 459 */
458 if (stat & ERR_STAT) 460 if (stat & ATA_ERR)
459 cdrom_queue_request_sense(drive, NULL, NULL); 461 cdrom_queue_request_sense(drive, NULL, NULL);
460 } else { 462 } else {
461 blk_dump_rq_flags(rq, "ide-cd: bad rq"); 463 blk_dump_rq_flags(rq, "ide-cd: bad rq");
@@ -466,7 +468,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
466 return 1; 468 return 1;
467 469
468end_request: 470end_request:
469 if (stat & ERR_STAT) { 471 if (stat & ATA_ERR) {
470 unsigned long flags; 472 unsigned long flags;
471 473
472 spin_lock_irqsave(&ide_lock, flags); 474 spin_lock_irqsave(&ide_lock, flags);
@@ -539,7 +541,7 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
539 drive->waiting_for_dma = 0; 541 drive->waiting_for_dma = 0;
540 542
541 /* packet command */ 543 /* packet command */
542 ide_execute_command(drive, WIN_PACKETCMD, handler, 544 ide_execute_command(drive, ATA_CMD_PACKET, handler,
543 ATAPI_WAIT_PC, cdrom_timer_expiry); 545 ATAPI_WAIT_PC, cdrom_timer_expiry);
544 return ide_started; 546 return ide_started;
545 } else { 547 } else {
@@ -572,7 +574,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
572 */ 574 */
573 575
574 /* check for errors */ 576 /* check for errors */
575 if (cdrom_decode_status(drive, DRQ_STAT, NULL)) 577 if (cdrom_decode_status(drive, ATA_DRQ, NULL))
576 return ide_stopped; 578 return ide_stopped;
577 579
578 /* ok, next interrupt will be DMA interrupt */ 580 /* ok, next interrupt will be DMA interrupt */
@@ -580,8 +582,8 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
580 drive->waiting_for_dma = 1; 582 drive->waiting_for_dma = 1;
581 } else { 583 } else {
582 /* otherwise, we must wait for DRQ to get set */ 584 /* otherwise, we must wait for DRQ to get set */
583 if (ide_wait_stat(&startstop, drive, DRQ_STAT, 585 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
584 BUSY_STAT, WAIT_READY)) 586 ATA_BUSY, WAIT_READY))
585 return startstop; 587 return startstop;
586 } 588 }
587 589
@@ -936,7 +938,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
936 thislen = len; 938 thislen = len;
937 939
938 /* If DRQ is clear, the command has completed. */ 940 /* If DRQ is clear, the command has completed. */
939 if ((stat & DRQ_STAT) == 0) { 941 if ((stat & ATA_DRQ) == 0) {
940 if (blk_fs_request(rq)) { 942 if (blk_fs_request(rq)) {
941 /* 943 /*
942 * If we're not done reading/writing, complain. 944 * If we're not done reading/writing, complain.
@@ -1111,7 +1113,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1111 1113
1112 if (write) { 1114 if (write) {
1113 /* disk has become write protected */ 1115 /* disk has become write protected */
1114 if (cd->disk->policy) { 1116 if (get_disk_ro(cd->disk)) {
1115 cdrom_end_request(drive, 0); 1117 cdrom_end_request(drive, 0);
1116 return ide_stopped; 1118 return ide_stopped;
1117 } 1119 }
@@ -1162,13 +1164,12 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1162 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { 1164 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) {
1163 struct request_queue *q = drive->queue; 1165 struct request_queue *q = drive->queue;
1164 unsigned int alignment; 1166 unsigned int alignment;
1165 unsigned long addr; 1167 char *buf;
1166 unsigned long stack_mask = ~(THREAD_SIZE - 1);
1167 1168
1168 if (rq->bio) 1169 if (rq->bio)
1169 addr = (unsigned long)bio_data(rq->bio); 1170 buf = bio_data(rq->bio);
1170 else 1171 else
1171 addr = (unsigned long)rq->data; 1172 buf = rq->data;
1172 1173
1173 info->dma = drive->using_dma; 1174 info->dma = drive->using_dma;
1174 1175
@@ -1179,11 +1180,8 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1179 * separate masks. 1180 * separate masks.
1180 */ 1181 */
1181 alignment = queue_dma_alignment(q) | q->dma_pad_mask; 1182 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1182 if (addr & alignment || rq->data_len & alignment) 1183 if ((unsigned long)buf & alignment || rq->data_len & alignment
1183 info->dma = 0; 1184 || object_is_on_stack(buf))
1184
1185 if (!((addr & stack_mask) ^
1186 ((unsigned long)current->stack & stack_mask)))
1187 info->dma = 0; 1185 info->dma = 0;
1188 } 1186 }
1189} 1187}
@@ -1204,7 +1202,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1204 unsigned long elapsed = jiffies - info->start_seek; 1202 unsigned long elapsed = jiffies - info->start_seek;
1205 int stat = hwif->tp_ops->read_status(hwif); 1203 int stat = hwif->tp_ops->read_status(hwif);
1206 1204
1207 if ((stat & SEEK_STAT) != SEEK_STAT) { 1205 if ((stat & ATA_DSC) != ATA_DSC) {
1208 if (elapsed < IDECD_SEEK_TIMEOUT) { 1206 if (elapsed < IDECD_SEEK_TIMEOUT) {
1209 ide_stall_queue(drive, 1207 ide_stall_queue(drive,
1210 IDECD_SEEK_TIMER); 1208 IDECD_SEEK_TIMER);
@@ -1270,9 +1268,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1270 */ 1268 */
1271static void msf_from_bcd(struct atapi_msf *msf) 1269static void msf_from_bcd(struct atapi_msf *msf)
1272{ 1270{
1273 msf->minute = BCD2BIN(msf->minute); 1271 msf->minute = bcd2bin(msf->minute);
1274 msf->second = BCD2BIN(msf->second); 1272 msf->second = bcd2bin(msf->second);
1275 msf->frame = BCD2BIN(msf->frame); 1273 msf->frame = bcd2bin(msf->frame);
1276} 1274}
1277 1275
1278int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense) 1276int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
@@ -1305,6 +1303,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1305 int stat; 1303 int stat;
1306 unsigned char cmd[BLK_MAX_CDB]; 1304 unsigned char cmd[BLK_MAX_CDB];
1307 unsigned len = sizeof(capbuf); 1305 unsigned len = sizeof(capbuf);
1306 u32 blocklen;
1308 1307
1309 memset(cmd, 0, BLK_MAX_CDB); 1308 memset(cmd, 0, BLK_MAX_CDB);
1310 cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1309 cmd[0] = GPCMD_READ_CDVD_CAPACITY;
@@ -1317,23 +1316,24 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1317 /* 1316 /*
1318 * Sanity check the given block size 1317 * Sanity check the given block size
1319 */ 1318 */
1320 switch (capbuf.blocklen) { 1319 blocklen = be32_to_cpu(capbuf.blocklen);
1321 case __constant_cpu_to_be32(512): 1320 switch (blocklen) {
1322 case __constant_cpu_to_be32(1024): 1321 case 512:
1323 case __constant_cpu_to_be32(2048): 1322 case 1024:
1324 case __constant_cpu_to_be32(4096): 1323 case 2048:
1324 case 4096:
1325 break; 1325 break;
1326 default: 1326 default:
1327 printk(KERN_ERR "%s: weird block size %u\n", 1327 printk(KERN_ERR "%s: weird block size %u\n",
1328 drive->name, capbuf.blocklen); 1328 drive->name, blocklen);
1329 printk(KERN_ERR "%s: default to 2kb block size\n", 1329 printk(KERN_ERR "%s: default to 2kb block size\n",
1330 drive->name); 1330 drive->name);
1331 capbuf.blocklen = __constant_cpu_to_be32(2048); 1331 blocklen = 2048;
1332 break; 1332 break;
1333 } 1333 }
1334 1334
1335 *capacity = 1 + be32_to_cpu(capbuf.lba); 1335 *capacity = 1 + be32_to_cpu(capbuf.lba);
1336 *sectors_per_frame = be32_to_cpu(capbuf.blocklen) >> SECTOR_BITS; 1336 *sectors_per_frame = blocklen >> SECTOR_BITS;
1337 return 0; 1337 return 0;
1338} 1338}
1339 1339
@@ -1411,8 +1411,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1411 return stat; 1411 return stat;
1412 1412
1413 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { 1413 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) {
1414 toc->hdr.first_track = BCD2BIN(toc->hdr.first_track); 1414 toc->hdr.first_track = bcd2bin(toc->hdr.first_track);
1415 toc->hdr.last_track = BCD2BIN(toc->hdr.last_track); 1415 toc->hdr.last_track = bcd2bin(toc->hdr.last_track);
1416 } 1416 }
1417 1417
1418 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; 1418 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
@@ -1452,8 +1452,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1452 return stat; 1452 return stat;
1453 1453
1454 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { 1454 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) {
1455 toc->hdr.first_track = (u8)BIN2BCD(CDROM_LEADOUT); 1455 toc->hdr.first_track = (u8)bin2bcd(CDROM_LEADOUT);
1456 toc->hdr.last_track = (u8)BIN2BCD(CDROM_LEADOUT); 1456 toc->hdr.last_track = (u8)bin2bcd(CDROM_LEADOUT);
1457 } else { 1457 } else {
1458 toc->hdr.first_track = CDROM_LEADOUT; 1458 toc->hdr.first_track = CDROM_LEADOUT;
1459 toc->hdr.last_track = CDROM_LEADOUT; 1459 toc->hdr.last_track = CDROM_LEADOUT;
@@ -1466,14 +1466,14 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1466 toc->hdr.toc_length = be16_to_cpu(toc->hdr.toc_length); 1466 toc->hdr.toc_length = be16_to_cpu(toc->hdr.toc_length);
1467 1467
1468 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { 1468 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) {
1469 toc->hdr.first_track = BCD2BIN(toc->hdr.first_track); 1469 toc->hdr.first_track = bcd2bin(toc->hdr.first_track);
1470 toc->hdr.last_track = BCD2BIN(toc->hdr.last_track); 1470 toc->hdr.last_track = bcd2bin(toc->hdr.last_track);
1471 } 1471 }
1472 1472
1473 for (i = 0; i <= ntracks; i++) { 1473 for (i = 0; i <= ntracks; i++) {
1474 if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { 1474 if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) {
1475 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) 1475 if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD)
1476 toc->ent[i].track = BCD2BIN(toc->ent[i].track); 1476 toc->ent[i].track = bcd2bin(toc->ent[i].track);
1477 msf_from_bcd(&toc->ent[i].addr.msf); 1477 msf_from_bcd(&toc->ent[i].addr.msf);
1478 } 1478 }
1479 toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute, 1479 toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute,
@@ -1657,7 +1657,9 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1657 cdi->mask &= ~CDC_PLAY_AUDIO; 1657 cdi->mask &= ~CDC_PLAY_AUDIO;
1658 1658
1659 mechtype = buf[8 + 6] >> 5; 1659 mechtype = buf[8 + 6] >> 5;
1660 if (mechtype == mechtype_caddy || mechtype == mechtype_popup) 1660 if (mechtype == mechtype_caddy ||
1661 mechtype == mechtype_popup ||
1662 (drive->atapi_flags & IDE_AFLAG_NO_AUTOCLOSE))
1661 cdi->mask |= CDC_CLOSE_TRAY; 1663 cdi->mask |= CDC_CLOSE_TRAY;
1662 1664
1663 if (cdi->sanyo_slot > 0) { 1665 if (cdi->sanyo_slot > 0) {
@@ -1807,13 +1809,12 @@ static ide_proc_entry_t idecd_proc[] = {
1807 { NULL, 0, NULL, NULL } 1809 { NULL, 0, NULL, NULL }
1808}; 1810};
1809 1811
1810static void ide_cdrom_add_settings(ide_drive_t *drive) 1812ide_devset_rw_field(dsc_overlap, dsc_overlap);
1811{ 1813
1812 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, 1814static const struct ide_proc_devset idecd_settings[] = {
1813 &drive->dsc_overlap, NULL); 1815 IDE_PROC_DEVSET(dsc_overlap, 0, 1),
1814} 1816 { 0 },
1815#else 1817};
1816static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; }
1817#endif 1818#endif
1818 1819
1819static const struct cd_list_entry ide_cd_quirks_list[] = { 1820static const struct cd_list_entry ide_cd_quirks_list[] = {
@@ -1855,17 +1856,19 @@ static const struct cd_list_entry ide_cd_quirks_list[] = {
1855 { "MATSHITADVD-ROM SR-8176", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, 1856 { "MATSHITADVD-ROM SR-8176", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1856 { "MATSHITADVD-ROM SR-8174", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, 1857 { "MATSHITADVD-ROM SR-8174", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1857 { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, 1858 { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1859 { "Optiarc DVD RW AD-7200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK },
1860 { "Optiarc DVD RW AD-7543A", NULL, IDE_AFLAG_NO_AUTOCLOSE },
1858 { NULL, NULL, 0 } 1861 { NULL, NULL, 0 }
1859}; 1862};
1860 1863
1861static unsigned int ide_cd_flags(struct hd_driveid *id) 1864static unsigned int ide_cd_flags(u16 *id)
1862{ 1865{
1863 const struct cd_list_entry *cle = ide_cd_quirks_list; 1866 const struct cd_list_entry *cle = ide_cd_quirks_list;
1864 1867
1865 while (cle->id_model) { 1868 while (cle->id_model) {
1866 if (strcmp(cle->id_model, id->model) == 0 && 1869 if (strcmp(cle->id_model, (char *)&id[ATA_ID_PROD]) == 0 &&
1867 (cle->id_firmware == NULL || 1870 (cle->id_firmware == NULL ||
1868 strstr(id->fw_rev, cle->id_firmware))) 1871 strstr((char *)&id[ATA_ID_FW_REV], cle->id_firmware)))
1869 return cle->cd_flags; 1872 return cle->cd_flags;
1870 cle++; 1873 cle++;
1871 } 1874 }
@@ -1877,7 +1880,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1877{ 1880{
1878 struct cdrom_info *cd = drive->driver_data; 1881 struct cdrom_info *cd = drive->driver_data;
1879 struct cdrom_device_info *cdi = &cd->devinfo; 1882 struct cdrom_device_info *cdi = &cd->devinfo;
1880 struct hd_driveid *id = drive->id; 1883 u16 *id = drive->id;
1884 char *fw_rev = (char *)&id[ATA_ID_FW_REV];
1881 int nslots; 1885 int nslots;
1882 1886
1883 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1887 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
@@ -1892,15 +1896,15 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1892 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT | 1896 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
1893 ide_cd_flags(id); 1897 ide_cd_flags(id);
1894 1898
1895 if ((id->config & 0x0060) == 0x20) 1899 if ((id[ATA_ID_CONFIG] & 0x0060) == 0x20)
1896 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT; 1900 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
1897 1901
1898 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && 1902 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
1899 id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') 1903 fw_rev[4] == '1' && fw_rev[6] <= '2')
1900 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | 1904 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
1901 IDE_AFLAG_TOCADDR_AS_BCD); 1905 IDE_AFLAG_TOCADDR_AS_BCD);
1902 else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) && 1906 else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) &&
1903 id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') 1907 fw_rev[4] == '1' && fw_rev[6] <= '2')
1904 drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD; 1908 drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD;
1905 else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD) 1909 else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD)
1906 /* 3 => use CD in slot 0 */ 1910 /* 3 => use CD in slot 0 */
@@ -1919,7 +1923,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1919 cd->devinfo.handle = NULL; 1923 cd->devinfo.handle = NULL;
1920 return 1; 1924 return 1;
1921 } 1925 }
1922 ide_cdrom_add_settings(drive); 1926
1927 ide_proc_register_driver(drive, cd->driver);
1923 return 0; 1928 return 0;
1924} 1929}
1925 1930
@@ -1964,12 +1969,12 @@ static ide_driver_t ide_cdrom_driver = {
1964 .remove = ide_cd_remove, 1969 .remove = ide_cd_remove,
1965 .version = IDECD_VERSION, 1970 .version = IDECD_VERSION,
1966 .media = ide_cdrom, 1971 .media = ide_cdrom,
1967 .supports_dsc_overlap = 1,
1968 .do_request = ide_cd_do_request, 1972 .do_request = ide_cd_do_request,
1969 .end_request = ide_end_request, 1973 .end_request = ide_end_request,
1970 .error = __ide_error, 1974 .error = __ide_error,
1971#ifdef CONFIG_IDE_PROC_FS 1975#ifdef CONFIG_IDE_PROC_FS
1972 .proc = idecd_proc, 1976 .proc = idecd_proc,
1977 .settings = idecd_settings,
1973#endif 1978#endif
1974}; 1979};
1975 1980
@@ -2104,10 +2109,10 @@ static int ide_cd_probe(ide_drive_t *drive)
2104 2109
2105 if (!strstr("ide-cdrom", drive->driver_req)) 2110 if (!strstr("ide-cdrom", drive->driver_req))
2106 goto failed; 2111 goto failed;
2107 if (!drive->present) 2112
2108 goto failed;
2109 if (drive->media != ide_cdrom && drive->media != ide_optical) 2113 if (drive->media != ide_cdrom && drive->media != ide_optical)
2110 goto failed; 2114 goto failed;
2115
2111 /* skip drives that we were told to ignore */ 2116 /* skip drives that we were told to ignore */
2112 if (ignore != NULL) { 2117 if (ignore != NULL) {
2113 if (strstr(ignore, drive->name)) { 2118 if (strstr(ignore, drive->name)) {
@@ -2129,8 +2134,6 @@ static int ide_cd_probe(ide_drive_t *drive)
2129 2134
2130 ide_init_disk(g, drive); 2135 ide_init_disk(g, drive);
2131 2136
2132 ide_proc_register_driver(drive, &ide_cdrom_driver);
2133
2134 kref_init(&info->kref); 2137 kref_init(&info->kref);
2135 2138
2136 info->drive = drive; 2139 info->drive = drive;
@@ -2145,7 +2148,6 @@ static int ide_cd_probe(ide_drive_t *drive)
2145 g->driverfs_dev = &drive->gendev; 2148 g->driverfs_dev = &drive->gendev;
2146 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; 2149 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE;
2147 if (ide_cdrom_setup(drive)) { 2150 if (ide_cdrom_setup(drive)) {
2148 ide_proc_unregister_driver(drive, &ide_cdrom_driver);
2149 ide_cd_release(&info->kref); 2151 ide_cd_release(&info->kref);
2150 goto failed; 2152 goto failed;
2151 } 2153 }
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 28d85b410f7c..01846f244b40 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -30,10 +30,8 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/leds.h> 32#include <linux/leds.h>
33
34#define _IDE_DISK
35
36#include <linux/ide.h> 33#include <linux/ide.h>
34#include <linux/hdreg.h>
37 35
38#include <asm/byteorder.h> 36#include <asm/byteorder.h>
39#include <asm/irq.h> 37#include <asm/irq.h>
@@ -41,6 +39,12 @@
41#include <asm/io.h> 39#include <asm/io.h>
42#include <asm/div64.h> 40#include <asm/div64.h>
43 41
42#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
43#define IDE_DISK_MINORS (1 << PARTN_BITS)
44#else
45#define IDE_DISK_MINORS 0
46#endif
47
44struct ide_disk_obj { 48struct ide_disk_obj {
45 ide_drive_t *drive; 49 ide_drive_t *drive;
46 ide_driver_t *driver; 50 ide_driver_t *driver;
@@ -65,11 +69,10 @@ static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
65 mutex_lock(&idedisk_ref_mutex); 69 mutex_lock(&idedisk_ref_mutex);
66 idkp = ide_disk_g(disk); 70 idkp = ide_disk_g(disk);
67 if (idkp) { 71 if (idkp) {
68 kref_get(&idkp->kref); 72 if (ide_device_get(idkp->drive))
69 if (ide_device_get(idkp->drive)) {
70 kref_put(&idkp->kref, ide_disk_release);
71 idkp = NULL; 73 idkp = NULL;
72 } 74 else
75 kref_get(&idkp->kref);
73 } 76 }
74 mutex_unlock(&idedisk_ref_mutex); 77 mutex_unlock(&idedisk_ref_mutex);
75 return idkp; 78 return idkp;
@@ -77,74 +80,27 @@ static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
77 80
78static void ide_disk_put(struct ide_disk_obj *idkp) 81static void ide_disk_put(struct ide_disk_obj *idkp)
79{ 82{
83 ide_drive_t *drive = idkp->drive;
84
80 mutex_lock(&idedisk_ref_mutex); 85 mutex_lock(&idedisk_ref_mutex);
81 ide_device_put(idkp->drive);
82 kref_put(&idkp->kref, ide_disk_release); 86 kref_put(&idkp->kref, ide_disk_release);
87 ide_device_put(drive);
83 mutex_unlock(&idedisk_ref_mutex); 88 mutex_unlock(&idedisk_ref_mutex);
84} 89}
85 90
86/*
87 * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity"
88 * value for this drive (from its reported identification information).
89 *
90 * Returns: 1 if lba_capacity looks sensible
91 * 0 otherwise
92 *
93 * It is called only once for each drive.
94 */
95static int lba_capacity_is_ok(struct hd_driveid *id)
96{
97 unsigned long lba_sects, chs_sects, head, tail;
98
99 /* No non-LBA info .. so valid! */
100 if (id->cyls == 0)
101 return 1;
102
103 /*
104 * The ATA spec tells large drives to return
105 * C/H/S = 16383/16/63 independent of their size.
106 * Some drives can be jumpered to use 15 heads instead of 16.
107 * Some drives can be jumpered to use 4092 cyls instead of 16383.
108 */
109 if ((id->cyls == 16383
110 || (id->cyls == 4092 && id->cur_cyls == 16383)) &&
111 id->sectors == 63 &&
112 (id->heads == 15 || id->heads == 16) &&
113 (id->lba_capacity >= 16383*63*id->heads))
114 return 1;
115
116 lba_sects = id->lba_capacity;
117 chs_sects = id->cyls * id->heads * id->sectors;
118
119 /* perform a rough sanity check on lba_sects: within 10% is OK */
120 if ((lba_sects - chs_sects) < chs_sects/10)
121 return 1;
122
123 /* some drives have the word order reversed */
124 head = ((lba_sects >> 16) & 0xffff);
125 tail = (lba_sects & 0xffff);
126 lba_sects = (head | (tail << 16));
127 if ((lba_sects - chs_sects) < chs_sects/10) {
128 id->lba_capacity = lba_sects;
129 return 1; /* lba_capacity is (now) good */
130 }
131
132 return 0; /* lba_capacity value may be bad */
133}
134
135static const u8 ide_rw_cmds[] = { 91static const u8 ide_rw_cmds[] = {
136 WIN_MULTREAD, 92 ATA_CMD_READ_MULTI,
137 WIN_MULTWRITE, 93 ATA_CMD_WRITE_MULTI,
138 WIN_MULTREAD_EXT, 94 ATA_CMD_READ_MULTI_EXT,
139 WIN_MULTWRITE_EXT, 95 ATA_CMD_WRITE_MULTI_EXT,
140 WIN_READ, 96 ATA_CMD_PIO_READ,
141 WIN_WRITE, 97 ATA_CMD_PIO_WRITE,
142 WIN_READ_EXT, 98 ATA_CMD_PIO_READ_EXT,
143 WIN_WRITE_EXT, 99 ATA_CMD_PIO_WRITE_EXT,
144 WIN_READDMA, 100 ATA_CMD_READ,
145 WIN_WRITEDMA, 101 ATA_CMD_WRITE,
146 WIN_READDMA_EXT, 102 ATA_CMD_READ_EXT,
147 WIN_WRITEDMA_EXT, 103 ATA_CMD_WRITE_EXT,
148}; 104};
149 105
150static const u8 ide_data_phases[] = { 106static const u8 ide_data_phases[] = {
@@ -315,9 +271,9 @@ static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
315 /* Create IDE/ATA command request structure */ 271 /* Create IDE/ATA command request structure */
316 memset(&args, 0, sizeof(ide_task_t)); 272 memset(&args, 0, sizeof(ide_task_t));
317 if (lba48) 273 if (lba48)
318 tf->command = WIN_READ_NATIVE_MAX_EXT; 274 tf->command = ATA_CMD_READ_NATIVE_MAX_EXT;
319 else 275 else
320 tf->command = WIN_READ_NATIVE_MAX; 276 tf->command = ATA_CMD_READ_NATIVE_MAX;
321 tf->device = ATA_LBA; 277 tf->device = ATA_LBA;
322 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 278 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
323 if (lba48) 279 if (lba48)
@@ -352,10 +308,10 @@ static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
352 tf->hob_lbal = (addr_req >>= 8) & 0xff; 308 tf->hob_lbal = (addr_req >>= 8) & 0xff;
353 tf->hob_lbam = (addr_req >>= 8) & 0xff; 309 tf->hob_lbam = (addr_req >>= 8) & 0xff;
354 tf->hob_lbah = (addr_req >>= 8) & 0xff; 310 tf->hob_lbah = (addr_req >>= 8) & 0xff;
355 tf->command = WIN_SET_MAX_EXT; 311 tf->command = ATA_CMD_SET_MAX_EXT;
356 } else { 312 } else {
357 tf->device = (addr_req >>= 8) & 0x0f; 313 tf->device = (addr_req >>= 8) & 0x0f;
358 tf->command = WIN_SET_MAX; 314 tf->command = ATA_CMD_SET_MAX;
359 } 315 }
360 tf->device |= ATA_LBA; 316 tf->device |= ATA_LBA;
361 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 317 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
@@ -378,25 +334,6 @@ static unsigned long long sectors_to_MB(unsigned long long n)
378} 334}
379 335
380/* 336/*
381 * Bits 10 of command_set_1 and cfs_enable_1 must be equal,
382 * so on non-buggy drives we need test only one.
383 * However, we should also check whether these fields are valid.
384 */
385static inline int idedisk_supports_hpa(const struct hd_driveid *id)
386{
387 return (id->command_set_1 & 0x0400) && (id->cfs_enable_1 & 0x0400);
388}
389
390/*
391 * The same here.
392 */
393static inline int idedisk_supports_lba48(const struct hd_driveid *id)
394{
395 return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400)
396 && id->lba_capacity_2;
397}
398
399/*
400 * Some disks report total number of sectors instead of 337 * Some disks report total number of sectors instead of
401 * maximum sector address. We list them here. 338 * maximum sector address. We list them here.
402 */ 339 */
@@ -410,7 +347,7 @@ static const struct drive_list_entry hpa_list[] = {
410static void idedisk_check_hpa(ide_drive_t *drive) 347static void idedisk_check_hpa(ide_drive_t *drive)
411{ 348{
412 unsigned long long capacity, set_max; 349 unsigned long long capacity, set_max;
413 int lba48 = idedisk_supports_lba48(drive->id); 350 int lba48 = ata_id_lba48_enabled(drive->id);
414 351
415 capacity = drive->capacity64; 352 capacity = drive->capacity64;
416 353
@@ -444,39 +381,25 @@ static void idedisk_check_hpa(ide_drive_t *drive)
444 } 381 }
445} 382}
446 383
447/*
448 * Compute drive->capacity, the full capacity of the drive
449 * Called with drive->id != NULL.
450 *
451 * To compute capacity, this uses either of
452 *
453 * 1. CHS value set by user (whatever user sets will be trusted)
454 * 2. LBA value from target drive (require new ATA feature)
455 * 3. LBA value from system BIOS (new one is OK, old one may break)
456 * 4. CHS value from system BIOS (traditional style)
457 *
458 * in above order (i.e., if value of higher priority is available,
459 * reset will be ignored).
460 */
461static void init_idedisk_capacity(ide_drive_t *drive) 384static void init_idedisk_capacity(ide_drive_t *drive)
462{ 385{
463 struct hd_driveid *id = drive->id; 386 u16 *id = drive->id;
464 /* 387 /*
465 * If this drive supports the Host Protected Area feature set, 388 * If this drive supports the Host Protected Area feature set,
466 * then we may need to change our opinion about the drive's capacity. 389 * then we may need to change our opinion about the drive's capacity.
467 */ 390 */
468 int hpa = idedisk_supports_hpa(id); 391 int hpa = ata_id_hpa_enabled(id);
469 392
470 if (idedisk_supports_lba48(id)) { 393 if (ata_id_lba48_enabled(id)) {
471 /* drive speaks 48-bit LBA */ 394 /* drive speaks 48-bit LBA */
472 drive->select.b.lba = 1; 395 drive->select.b.lba = 1;
473 drive->capacity64 = id->lba_capacity_2; 396 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
474 if (hpa) 397 if (hpa)
475 idedisk_check_hpa(drive); 398 idedisk_check_hpa(drive);
476 } else if ((id->capability & 2) && lba_capacity_is_ok(id)) { 399 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
477 /* drive speaks 28-bit LBA */ 400 /* drive speaks 28-bit LBA */
478 drive->select.b.lba = 1; 401 drive->select.b.lba = 1;
479 drive->capacity64 = id->lba_capacity; 402 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
480 if (hpa) 403 if (hpa)
481 idedisk_check_hpa(drive); 404 idedisk_check_hpa(drive);
482 } else { 405 } else {
@@ -487,7 +410,7 @@ static void init_idedisk_capacity(ide_drive_t *drive)
487 410
488static sector_t idedisk_capacity(ide_drive_t *drive) 411static sector_t idedisk_capacity(ide_drive_t *drive)
489{ 412{
490 return drive->capacity64 - drive->sect0; 413 return drive->capacity64;
491} 414}
492 415
493#ifdef CONFIG_IDE_PROC_FS 416#ifdef CONFIG_IDE_PROC_FS
@@ -497,10 +420,10 @@ static int smart_enable(ide_drive_t *drive)
497 struct ide_taskfile *tf = &args.tf; 420 struct ide_taskfile *tf = &args.tf;
498 421
499 memset(&args, 0, sizeof(ide_task_t)); 422 memset(&args, 0, sizeof(ide_task_t));
500 tf->feature = SMART_ENABLE; 423 tf->feature = ATA_SMART_ENABLE;
501 tf->lbam = SMART_LCYL_PASS; 424 tf->lbam = ATA_SMART_LBAM_PASS;
502 tf->lbah = SMART_HCYL_PASS; 425 tf->lbah = ATA_SMART_LBAH_PASS;
503 tf->command = WIN_SMART; 426 tf->command = ATA_CMD_SMART;
504 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 427 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
505 return ide_no_data_taskfile(drive, &args); 428 return ide_no_data_taskfile(drive, &args);
506} 429}
@@ -513,9 +436,9 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
513 memset(&args, 0, sizeof(ide_task_t)); 436 memset(&args, 0, sizeof(ide_task_t));
514 tf->feature = sub_cmd; 437 tf->feature = sub_cmd;
515 tf->nsect = 0x01; 438 tf->nsect = 0x01;
516 tf->lbam = SMART_LCYL_PASS; 439 tf->lbam = ATA_SMART_LBAM_PASS;
517 tf->lbah = SMART_HCYL_PASS; 440 tf->lbah = ATA_SMART_LBAH_PASS;
518 tf->command = WIN_SMART; 441 tf->command = ATA_CMD_SMART;
519 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 442 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
520 args.data_phase = TASKFILE_IN; 443 args.data_phase = TASKFILE_IN;
521 (void) smart_enable(drive); 444 (void) smart_enable(drive);
@@ -530,7 +453,7 @@ static int proc_idedisk_read_cache
530 int len; 453 int len;
531 454
532 if (drive->id_read) 455 if (drive->id_read)
533 len = sprintf(out, "%i\n", drive->id->buf_size / 2); 456 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
534 else 457 else
535 len = sprintf(out, "(none)\n"); 458 len = sprintf(out, "(none)\n");
536 459
@@ -556,13 +479,14 @@ static int proc_idedisk_read_smart(char *page, char **start, off_t off,
556 479
557 if (get_smart_data(drive, page, sub_cmd) == 0) { 480 if (get_smart_data(drive, page, sub_cmd) == 0) {
558 unsigned short *val = (unsigned short *) page; 481 unsigned short *val = (unsigned short *) page;
559 char *out = ((char *)val) + (SECTOR_WORDS * 4); 482 char *out = (char *)val + SECTOR_SIZE;
483
560 page = out; 484 page = out;
561 do { 485 do {
562 out += sprintf(out, "%04x%c", le16_to_cpu(*val), 486 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
563 (++i & 7) ? ' ' : '\n'); 487 (++i & 7) ? ' ' : '\n');
564 val += 1; 488 val += 1;
565 } while (i < (SECTOR_WORDS * 2)); 489 } while (i < SECTOR_SIZE / 2);
566 len = out - page; 490 len = out - page;
567 } 491 }
568 492
@@ -573,14 +497,14 @@ static int proc_idedisk_read_sv
573 (char *page, char **start, off_t off, int count, int *eof, void *data) 497 (char *page, char **start, off_t off, int count, int *eof, void *data)
574{ 498{
575 return proc_idedisk_read_smart(page, start, off, count, eof, data, 499 return proc_idedisk_read_smart(page, start, off, count, eof, data,
576 SMART_READ_VALUES); 500 ATA_SMART_READ_VALUES);
577} 501}
578 502
579static int proc_idedisk_read_st 503static int proc_idedisk_read_st
580 (char *page, char **start, off_t off, int count, int *eof, void *data) 504 (char *page, char **start, off_t off, int count, int *eof, void *data)
581{ 505{
582 return proc_idedisk_read_smart(page, start, off, count, eof, data, 506 return proc_idedisk_read_smart(page, start, off, count, eof, data,
583 SMART_READ_THRESHOLDS); 507 ATA_SMART_READ_THRESHOLDS);
584} 508}
585 509
586static ide_proc_entry_t idedisk_proc[] = { 510static ide_proc_entry_t idedisk_proc[] = {
@@ -602,11 +526,11 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
602 BUG_ON(task == NULL); 526 BUG_ON(task == NULL);
603 527
604 memset(task, 0, sizeof(*task)); 528 memset(task, 0, sizeof(*task));
605 if (ide_id_has_flush_cache_ext(drive->id) && 529 if (ata_id_flush_ext_enabled(drive->id) &&
606 (drive->capacity64 >= (1UL << 28))) 530 (drive->capacity64 >= (1UL << 28)))
607 task->tf.command = WIN_FLUSH_CACHE_EXT; 531 task->tf.command = ATA_CMD_FLUSH_EXT;
608 else 532 else
609 task->tf.command = WIN_FLUSH_CACHE; 533 task->tf.command = ATA_CMD_FLUSH;
610 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE | 534 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE |
611 IDE_TFLAG_DYN; 535 IDE_TFLAG_DYN;
612 task->data_phase = TASKFILE_NO_DATA; 536 task->data_phase = TASKFILE_NO_DATA;
@@ -616,6 +540,8 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
616 rq->special = task; 540 rq->special = task;
617} 541}
618 542
543ide_devset_get(multcount, mult_count);
544
619/* 545/*
620 * This is tightly woven into the driver->do_special can not touch. 546 * This is tightly woven into the driver->do_special can not touch.
621 * DON'T do it again until a total personality rewrite is committed. 547 * DON'T do it again until a total personality rewrite is committed.
@@ -625,7 +551,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
625 struct request *rq; 551 struct request *rq;
626 int error; 552 int error;
627 553
628 if (arg < 0 || arg > drive->id->max_multsect) 554 if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff))
629 return -EINVAL; 555 return -EINVAL;
630 556
631 if (drive->special.b.set_multmode) 557 if (drive->special.b.set_multmode)
@@ -642,22 +568,21 @@ static int set_multcount(ide_drive_t *drive, int arg)
642 return (drive->mult_count == arg) ? 0 : -EIO; 568 return (drive->mult_count == arg) ? 0 : -EIO;
643} 569}
644 570
571ide_devset_get(nowerr, nowerr);
572
645static int set_nowerr(ide_drive_t *drive, int arg) 573static int set_nowerr(ide_drive_t *drive, int arg)
646{ 574{
647 if (arg < 0 || arg > 1) 575 if (arg < 0 || arg > 1)
648 return -EINVAL; 576 return -EINVAL;
649 577
650 if (ide_spin_wait_hwgroup(drive))
651 return -EBUSY;
652 drive->nowerr = arg; 578 drive->nowerr = arg;
653 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; 579 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
654 spin_unlock_irq(&ide_lock);
655 return 0; 580 return 0;
656} 581}
657 582
658static void update_ordered(ide_drive_t *drive) 583static void update_ordered(ide_drive_t *drive)
659{ 584{
660 struct hd_driveid *id = drive->id; 585 u16 *id = drive->id;
661 unsigned ordered = QUEUE_ORDERED_NONE; 586 unsigned ordered = QUEUE_ORDERED_NONE;
662 prepare_flush_fn *prep_fn = NULL; 587 prepare_flush_fn *prep_fn = NULL;
663 588
@@ -673,9 +598,9 @@ static void update_ordered(ide_drive_t *drive)
673 * not available so we don't need to recheck that. 598 * not available so we don't need to recheck that.
674 */ 599 */
675 capacity = idedisk_capacity(drive); 600 capacity = idedisk_capacity(drive);
676 barrier = ide_id_has_flush_cache(id) && !drive->noflush && 601 barrier = ata_id_flush_enabled(id) && !drive->noflush &&
677 (drive->addressing == 0 || capacity <= (1ULL << 28) || 602 (drive->addressing == 0 || capacity <= (1ULL << 28) ||
678 ide_id_has_flush_cache_ext(id)); 603 ata_id_flush_ext_enabled(id));
679 604
680 printk(KERN_INFO "%s: cache flushes %ssupported\n", 605 printk(KERN_INFO "%s: cache flushes %ssupported\n",
681 drive->name, barrier ? "" : "not "); 606 drive->name, barrier ? "" : "not ");
@@ -690,7 +615,9 @@ static void update_ordered(ide_drive_t *drive)
690 blk_queue_ordered(drive->queue, ordered, prep_fn); 615 blk_queue_ordered(drive->queue, ordered, prep_fn);
691} 616}
692 617
693static int write_cache(ide_drive_t *drive, int arg) 618ide_devset_get(wcache, wcache);
619
620static int set_wcache(ide_drive_t *drive, int arg)
694{ 621{
695 ide_task_t args; 622 ide_task_t args;
696 int err = 1; 623 int err = 1;
@@ -698,11 +625,11 @@ static int write_cache(ide_drive_t *drive, int arg)
698 if (arg < 0 || arg > 1) 625 if (arg < 0 || arg > 1)
699 return -EINVAL; 626 return -EINVAL;
700 627
701 if (ide_id_has_flush_cache(drive->id)) { 628 if (ata_id_flush_enabled(drive->id)) {
702 memset(&args, 0, sizeof(ide_task_t)); 629 memset(&args, 0, sizeof(ide_task_t));
703 args.tf.feature = arg ? 630 args.tf.feature = arg ?
704 SETFEATURES_EN_WCACHE : SETFEATURES_DIS_WCACHE; 631 SETFEATURES_WC_ON : SETFEATURES_WC_OFF;
705 args.tf.command = WIN_SETFEATURES; 632 args.tf.command = ATA_CMD_SET_FEATURES;
706 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 633 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
707 err = ide_no_data_taskfile(drive, &args); 634 err = ide_no_data_taskfile(drive, &args);
708 if (err == 0) 635 if (err == 0)
@@ -719,14 +646,16 @@ static int do_idedisk_flushcache(ide_drive_t *drive)
719 ide_task_t args; 646 ide_task_t args;
720 647
721 memset(&args, 0, sizeof(ide_task_t)); 648 memset(&args, 0, sizeof(ide_task_t));
722 if (ide_id_has_flush_cache_ext(drive->id)) 649 if (ata_id_flush_ext_enabled(drive->id))
723 args.tf.command = WIN_FLUSH_CACHE_EXT; 650 args.tf.command = ATA_CMD_FLUSH_EXT;
724 else 651 else
725 args.tf.command = WIN_FLUSH_CACHE; 652 args.tf.command = ATA_CMD_FLUSH;
726 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 653 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
727 return ide_no_data_taskfile(drive, &args); 654 return ide_no_data_taskfile(drive, &args);
728} 655}
729 656
657ide_devset_get(acoustic, acoustic);
658
730static int set_acoustic(ide_drive_t *drive, int arg) 659static int set_acoustic(ide_drive_t *drive, int arg)
731{ 660{
732 ide_task_t args; 661 ide_task_t args;
@@ -735,22 +664,24 @@ static int set_acoustic(ide_drive_t *drive, int arg)
735 return -EINVAL; 664 return -EINVAL;
736 665
737 memset(&args, 0, sizeof(ide_task_t)); 666 memset(&args, 0, sizeof(ide_task_t));
738 args.tf.feature = arg ? SETFEATURES_EN_AAM : SETFEATURES_DIS_AAM; 667 args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF;
739 args.tf.nsect = arg; 668 args.tf.nsect = arg;
740 args.tf.command = WIN_SETFEATURES; 669 args.tf.command = ATA_CMD_SET_FEATURES;
741 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 670 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
742 ide_no_data_taskfile(drive, &args); 671 ide_no_data_taskfile(drive, &args);
743 drive->acoustic = arg; 672 drive->acoustic = arg;
744 return 0; 673 return 0;
745} 674}
746 675
676ide_devset_get(addressing, addressing);
677
747/* 678/*
748 * drive->addressing: 679 * drive->addressing:
749 * 0: 28-bit 680 * 0: 28-bit
750 * 1: 48-bit 681 * 1: 48-bit
751 * 2: 48-bit capable doing 28-bit 682 * 2: 48-bit capable doing 28-bit
752 */ 683 */
753static int set_lba_addressing(ide_drive_t *drive, int arg) 684static int set_addressing(ide_drive_t *drive, int arg)
754{ 685{
755 if (arg < 0 || arg > 2) 686 if (arg < 0 || arg > 2)
756 return -EINVAL; 687 return -EINVAL;
@@ -760,52 +691,54 @@ static int set_lba_addressing(ide_drive_t *drive, int arg)
760 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) 691 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
761 return 0; 692 return 0;
762 693
763 if (!idedisk_supports_lba48(drive->id)) 694 if (ata_id_lba48_enabled(drive->id) == 0)
764 return -EIO; 695 return -EIO;
696
765 drive->addressing = arg; 697 drive->addressing = arg;
698
766 return 0; 699 return 0;
767} 700}
768 701
702ide_devset_rw(acoustic, acoustic);
703ide_devset_rw(address, addressing);
704ide_devset_rw(multcount, multcount);
705ide_devset_rw(wcache, wcache);
706
707ide_devset_rw_sync(nowerr, nowerr);
708
769#ifdef CONFIG_IDE_PROC_FS 709#ifdef CONFIG_IDE_PROC_FS
770static void idedisk_add_settings(ide_drive_t *drive) 710ide_devset_rw_field(bios_cyl, bios_cyl);
771{ 711ide_devset_rw_field(bios_head, bios_head);
772 struct hd_driveid *id = drive->id; 712ide_devset_rw_field(bios_sect, bios_sect);
773 713ide_devset_rw_field(failures, failures);
774 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, 714ide_devset_rw_field(lun, lun);
775 &drive->bios_cyl, NULL); 715ide_devset_rw_field(max_failures, max_failures);
776 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, 716
777 &drive->bios_head, NULL); 717static const struct ide_proc_devset idedisk_settings[] = {
778 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, 718 IDE_PROC_DEVSET(acoustic, 0, 254),
779 &drive->bios_sect, NULL); 719 IDE_PROC_DEVSET(address, 0, 2),
780 ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1, 720 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
781 &drive->addressing, set_lba_addressing); 721 IDE_PROC_DEVSET(bios_head, 0, 255),
782 ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0, 722 IDE_PROC_DEVSET(bios_sect, 0, 63),
783 id->max_multsect, 1, 1, &drive->mult_count, 723 IDE_PROC_DEVSET(failures, 0, 65535),
784 set_multcount); 724 IDE_PROC_DEVSET(lun, 0, 7),
785 ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, 725 IDE_PROC_DEVSET(max_failures, 0, 65535),
786 &drive->nowerr, set_nowerr); 726 IDE_PROC_DEVSET(multcount, 0, 16),
787 ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1, 727 IDE_PROC_DEVSET(nowerr, 0, 1),
788 &drive->lun, NULL); 728 IDE_PROC_DEVSET(wcache, 0, 1),
789 ide_add_setting(drive, "wcache", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, 729 { 0 },
790 &drive->wcache, write_cache); 730};
791 ide_add_setting(drive, "acoustic", SETTING_RW, TYPE_BYTE, 0, 254, 1, 1,
792 &drive->acoustic, set_acoustic);
793 ide_add_setting(drive, "failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
794 &drive->failures, NULL);
795 ide_add_setting(drive, "max_failures", SETTING_RW, TYPE_INT, 0, 65535,
796 1, 1, &drive->max_failures, NULL);
797}
798#else
799static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
800#endif 731#endif
801 732
802static void idedisk_setup(ide_drive_t *drive) 733static void idedisk_setup(ide_drive_t *drive)
803{ 734{
735 struct ide_disk_obj *idkp = drive->driver_data;
804 ide_hwif_t *hwif = drive->hwif; 736 ide_hwif_t *hwif = drive->hwif;
805 struct hd_driveid *id = drive->id; 737 u16 *id = drive->id;
738 char *m = (char *)&id[ATA_ID_PROD];
806 unsigned long long capacity; 739 unsigned long long capacity;
807 740
808 idedisk_add_settings(drive); 741 ide_proc_register_driver(drive, idkp->driver);
809 742
810 if (drive->id_read == 0) 743 if (drive->id_read == 0)
811 return; 744 return;
@@ -814,11 +747,11 @@ static void idedisk_setup(ide_drive_t *drive)
814 /* 747 /*
815 * Removable disks (eg. SYQUEST); ignore 'WD' drives 748 * Removable disks (eg. SYQUEST); ignore 'WD' drives
816 */ 749 */
817 if (id->model[0] != 'W' || id->model[1] != 'D') 750 if (m[0] != 'W' || m[1] != 'D')
818 drive->doorlocking = 1; 751 drive->doorlocking = 1;
819 } 752 }
820 753
821 (void)set_lba_addressing(drive, 1); 754 (void)set_addressing(drive, 1);
822 755
823 if (drive->addressing == 1) { 756 if (drive->addressing == 1) {
824 int max_s = 2048; 757 int max_s = 2048;
@@ -860,8 +793,7 @@ static void idedisk_setup(ide_drive_t *drive)
860 capacity = idedisk_capacity(drive); 793 capacity = idedisk_capacity(drive);
861 794
862 if (!drive->forced_geom) { 795 if (!drive->forced_geom) {
863 796 if (ata_id_lba48_enabled(drive->id)) {
864 if (idedisk_supports_lba48(drive->id)) {
865 /* compatibility */ 797 /* compatibility */
866 drive->bios_sect = 63; 798 drive->bios_sect = 63;
867 drive->bios_head = 255; 799 drive->bios_head = 255;
@@ -887,22 +819,22 @@ static void idedisk_setup(ide_drive_t *drive)
887 drive->name, capacity, sectors_to_MB(capacity)); 819 drive->name, capacity, sectors_to_MB(capacity));
888 820
889 /* Only print cache size when it was specified */ 821 /* Only print cache size when it was specified */
890 if (id->buf_size) 822 if (id[ATA_ID_BUF_SIZE])
891 printk(KERN_CONT " w/%dKiB Cache", id->buf_size / 2); 823 printk(KERN_CONT " w/%dKiB Cache", id[ATA_ID_BUF_SIZE] / 2);
892 824
893 printk(KERN_CONT ", CHS=%d/%d/%d\n", 825 printk(KERN_CONT ", CHS=%d/%d/%d\n",
894 drive->bios_cyl, drive->bios_head, drive->bios_sect); 826 drive->bios_cyl, drive->bios_head, drive->bios_sect);
895 827
896 /* write cache enabled? */ 828 /* write cache enabled? */
897 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5))) 829 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
898 drive->wcache = 1; 830 drive->wcache = 1;
899 831
900 write_cache(drive, 1); 832 set_wcache(drive, 1);
901} 833}
902 834
903static void ide_cacheflush_p(ide_drive_t *drive) 835static void ide_cacheflush_p(ide_drive_t *drive)
904{ 836{
905 if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) 837 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0)
906 return; 838 return;
907 839
908 if (do_idedisk_flushcache(drive)) 840 if (do_idedisk_flushcache(drive))
@@ -944,7 +876,7 @@ static int ide_disk_probe(ide_drive_t *drive);
944 */ 876 */
945static void ide_disk_resume(ide_drive_t *drive) 877static void ide_disk_resume(ide_drive_t *drive)
946{ 878{
947 if (idedisk_supports_hpa(drive->id)) 879 if (ata_id_hpa_enabled(drive->id))
948 init_idedisk_capacity(drive); 880 init_idedisk_capacity(drive);
949} 881}
950 882
@@ -987,12 +919,12 @@ static ide_driver_t idedisk_driver = {
987 .shutdown = ide_device_shutdown, 919 .shutdown = ide_device_shutdown,
988 .version = IDEDISK_VERSION, 920 .version = IDEDISK_VERSION,
989 .media = ide_disk, 921 .media = ide_disk,
990 .supports_dsc_overlap = 0,
991 .do_request = ide_do_rw_disk, 922 .do_request = ide_do_rw_disk,
992 .end_request = ide_end_request, 923 .end_request = ide_end_request,
993 .error = __ide_error, 924 .error = __ide_error,
994#ifdef CONFIG_IDE_PROC_FS 925#ifdef CONFIG_IDE_PROC_FS
995 .proc = idedisk_proc, 926 .proc = idedisk_proc,
927 .settings = idedisk_settings,
996#endif 928#endif
997}; 929};
998 930
@@ -1001,7 +933,7 @@ static int idedisk_set_doorlock(ide_drive_t *drive, int on)
1001 ide_task_t task; 933 ide_task_t task;
1002 934
1003 memset(&task, 0, sizeof(task)); 935 memset(&task, 0, sizeof(task));
1004 task.tf.command = on ? WIN_DOORLOCK : WIN_DOORUNLOCK; 936 task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
1005 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 937 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
1006 938
1007 return ide_no_data_taskfile(drive, &task); 939 return ide_no_data_taskfile(drive, &task);
@@ -1066,52 +998,28 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1066 return 0; 998 return 0;
1067} 999}
1068 1000
1001static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
1002{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
1003{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
1004{ HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr },
1005{ HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache },
1006{ HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic },
1007{ 0 }
1008};
1009
1069static int idedisk_ioctl(struct inode *inode, struct file *file, 1010static int idedisk_ioctl(struct inode *inode, struct file *file,
1070 unsigned int cmd, unsigned long arg) 1011 unsigned int cmd, unsigned long arg)
1071{ 1012{
1072 unsigned long flags;
1073 struct block_device *bdev = inode->i_bdev; 1013 struct block_device *bdev = inode->i_bdev;
1074 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); 1014 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1075 ide_drive_t *drive = idkp->drive; 1015 ide_drive_t *drive = idkp->drive;
1076 int err, (*setfunc)(ide_drive_t *, int); 1016 int err;
1077 u8 *val;
1078
1079 switch (cmd) {
1080 case HDIO_GET_ADDRESS: val = &drive->addressing; goto read_val;
1081 case HDIO_GET_MULTCOUNT: val = &drive->mult_count; goto read_val;
1082 case HDIO_GET_NOWERR: val = &drive->nowerr; goto read_val;
1083 case HDIO_GET_WCACHE: val = &drive->wcache; goto read_val;
1084 case HDIO_GET_ACOUSTIC: val = &drive->acoustic; goto read_val;
1085 case HDIO_SET_ADDRESS: setfunc = set_lba_addressing; goto set_val;
1086 case HDIO_SET_MULTCOUNT: setfunc = set_multcount; goto set_val;
1087 case HDIO_SET_NOWERR: setfunc = set_nowerr; goto set_val;
1088 case HDIO_SET_WCACHE: setfunc = write_cache; goto set_val;
1089 case HDIO_SET_ACOUSTIC: setfunc = set_acoustic; goto set_val;
1090 }
1091 1017
1092 return generic_ide_ioctl(drive, file, bdev, cmd, arg); 1018 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
1019 if (err != -EOPNOTSUPP)
1020 return err;
1093 1021
1094read_val: 1022 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1095 mutex_lock(&ide_setting_mtx);
1096 spin_lock_irqsave(&ide_lock, flags);
1097 err = *val;
1098 spin_unlock_irqrestore(&ide_lock, flags);
1099 mutex_unlock(&ide_setting_mtx);
1100 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1101
1102set_val:
1103 if (bdev != bdev->bd_contains)
1104 err = -EINVAL;
1105 else {
1106 if (!capable(CAP_SYS_ADMIN))
1107 err = -EACCES;
1108 else {
1109 mutex_lock(&ide_setting_mtx);
1110 err = setfunc(drive, arg);
1111 mutex_unlock(&ide_setting_mtx);
1112 }
1113 }
1114 return err;
1115} 1023}
1116 1024
1117static int idedisk_media_changed(struct gendisk *disk) 1025static int idedisk_media_changed(struct gendisk *disk)
@@ -1155,8 +1063,7 @@ static int ide_disk_probe(ide_drive_t *drive)
1155 /* strstr("foo", "") is non-NULL */ 1063 /* strstr("foo", "") is non-NULL */
1156 if (!strstr("ide-disk", drive->driver_req)) 1064 if (!strstr("ide-disk", drive->driver_req))
1157 goto failed; 1065 goto failed;
1158 if (!drive->present) 1066
1159 goto failed;
1160 if (drive->media != ide_disk) 1067 if (drive->media != ide_disk)
1161 goto failed; 1068 goto failed;
1162 1069
@@ -1164,15 +1071,12 @@ static int ide_disk_probe(ide_drive_t *drive)
1164 if (!idkp) 1071 if (!idkp)
1165 goto failed; 1072 goto failed;
1166 1073
1167 g = alloc_disk_node(1 << PARTN_BITS, 1074 g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif));
1168 hwif_to_node(drive->hwif));
1169 if (!g) 1075 if (!g)
1170 goto out_free_idkp; 1076 goto out_free_idkp;
1171 1077
1172 ide_init_disk(g, drive); 1078 ide_init_disk(g, drive);
1173 1079
1174 ide_proc_register_driver(drive, &idedisk_driver);
1175
1176 kref_init(&idkp->kref); 1080 kref_init(&idkp->kref);
1177 1081
1178 idkp->drive = drive; 1082 idkp->drive = drive;
@@ -1191,9 +1095,11 @@ static int ide_disk_probe(ide_drive_t *drive)
1191 } else 1095 } else
1192 drive->attach = 1; 1096 drive->attach = 1;
1193 1097
1194 g->minors = 1 << PARTN_BITS; 1098 g->minors = IDE_DISK_MINORS;
1195 g->driverfs_dev = &drive->gendev; 1099 g->driverfs_dev = &drive->gendev;
1196 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; 1100 g->flags |= GENHD_FL_EXT_DEVT;
1101 if (drive->removable)
1102 g->flags |= GENHD_FL_REMOVABLE;
1197 set_capacity(g, idedisk_capacity(drive)); 1103 set_capacity(g, idedisk_capacity(drive));
1198 g->fops = &idedisk_ops; 1104 g->fops = &idedisk_ops;
1199 add_disk(g); 1105 add_disk(g);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 71c377a7bcf2..ef2f1504c0d5 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -106,7 +106,7 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
106 dma_stat = hwif->dma_ops->dma_end(drive); 106 dma_stat = hwif->dma_ops->dma_end(drive);
107 stat = hwif->tp_ops->read_status(hwif); 107 stat = hwif->tp_ops->read_status(hwif);
108 108
109 if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) { 109 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
110 if (!dma_stat) { 110 if (!dma_stat) {
111 struct request *rq = HWGROUP(drive)->rq; 111 struct request *rq = HWGROUP(drive)->rq;
112 112
@@ -211,7 +211,7 @@ int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
211 xcount = bcount & 0xffff; 211 xcount = bcount & 0xffff;
212 if (is_trm290) 212 if (is_trm290)
213 xcount = ((xcount >> 2) - 1) << 16; 213 xcount = ((xcount >> 2) - 1) << 16;
214 if (xcount == 0x0000) { 214 else if (xcount == 0x0000) {
215 /* 215 /*
216 * Most chipsets correctly interpret a length of 0x0000 as 64KB, 216 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
217 * but at least one (e.g. CS5530) misinterprets it as zero (!). 217 * but at least one (e.g. CS5530) misinterprets it as zero (!).
@@ -288,7 +288,7 @@ EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
288static int config_drive_for_dma (ide_drive_t *drive) 288static int config_drive_for_dma (ide_drive_t *drive)
289{ 289{
290 ide_hwif_t *hwif = drive->hwif; 290 ide_hwif_t *hwif = drive->hwif;
291 struct hd_driveid *id = drive->id; 291 u16 *id = drive->id;
292 292
293 if (drive->media != ide_disk) { 293 if (drive->media != ide_disk) {
294 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA) 294 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
@@ -299,16 +299,17 @@ static int config_drive_for_dma (ide_drive_t *drive)
299 * Enable DMA on any drive that has 299 * Enable DMA on any drive that has
300 * UltraDMA (mode 0/1/2/3/4/5/6) enabled 300 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
301 */ 301 */
302 if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f)) 302 if ((id[ATA_ID_FIELD_VALID] & 4) &&
303 ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
303 return 1; 304 return 1;
304 305
305 /* 306 /*
306 * Enable DMA on any drive that has mode2 DMA 307 * Enable DMA on any drive that has mode2 DMA
307 * (multi or single) enabled 308 * (multi or single) enabled
308 */ 309 */
309 if (id->field_valid & 2) /* regular DMA */ 310 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
310 if ((id->dma_mword & 0x404) == 0x404 || 311 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
311 (id->dma_1word & 0x404) == 0x404) 312 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
312 return 1; 313 return 1;
313 314
314 /* Consult the list of known "good" drives */ 315 /* Consult the list of known "good" drives */
@@ -591,12 +592,12 @@ static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
591 592
592int __ide_dma_bad_drive (ide_drive_t *drive) 593int __ide_dma_bad_drive (ide_drive_t *drive)
593{ 594{
594 struct hd_driveid *id = drive->id; 595 u16 *id = drive->id;
595 596
596 int blacklist = ide_in_drive_list(id, drive_blacklist); 597 int blacklist = ide_in_drive_list(id, drive_blacklist);
597 if (blacklist) { 598 if (blacklist) {
598 printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n", 599 printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n",
599 drive->name, id->model); 600 drive->name, (char *)&id[ATA_ID_PROD]);
600 return blacklist; 601 return blacklist;
601 } 602 }
602 return 0; 603 return 0;
@@ -612,21 +613,21 @@ static const u8 xfer_mode_bases[] = {
612 613
613static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode) 614static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
614{ 615{
615 struct hd_driveid *id = drive->id; 616 u16 *id = drive->id;
616 ide_hwif_t *hwif = drive->hwif; 617 ide_hwif_t *hwif = drive->hwif;
617 const struct ide_port_ops *port_ops = hwif->port_ops; 618 const struct ide_port_ops *port_ops = hwif->port_ops;
618 unsigned int mask = 0; 619 unsigned int mask = 0;
619 620
620 switch(base) { 621 switch(base) {
621 case XFER_UDMA_0: 622 case XFER_UDMA_0:
622 if ((id->field_valid & 4) == 0) 623 if ((id[ATA_ID_FIELD_VALID] & 4) == 0)
623 break; 624 break;
624 625
625 if (port_ops && port_ops->udma_filter) 626 if (port_ops && port_ops->udma_filter)
626 mask = port_ops->udma_filter(drive); 627 mask = port_ops->udma_filter(drive);
627 else 628 else
628 mask = hwif->ultra_mask; 629 mask = hwif->ultra_mask;
629 mask &= id->dma_ultra; 630 mask &= id[ATA_ID_UDMA_MODES];
630 631
631 /* 632 /*
632 * avoid false cable warning from eighty_ninty_three() 633 * avoid false cable warning from eighty_ninty_three()
@@ -637,23 +638,19 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
637 } 638 }
638 break; 639 break;
639 case XFER_MW_DMA_0: 640 case XFER_MW_DMA_0:
640 if ((id->field_valid & 2) == 0) 641 if ((id[ATA_ID_FIELD_VALID] & 2) == 0)
641 break; 642 break;
642 if (port_ops && port_ops->mdma_filter) 643 if (port_ops && port_ops->mdma_filter)
643 mask = port_ops->mdma_filter(drive); 644 mask = port_ops->mdma_filter(drive);
644 else 645 else
645 mask = hwif->mwdma_mask; 646 mask = hwif->mwdma_mask;
646 mask &= id->dma_mword; 647 mask &= id[ATA_ID_MWDMA_MODES];
647 break; 648 break;
648 case XFER_SW_DMA_0: 649 case XFER_SW_DMA_0:
649 if (id->field_valid & 2) { 650 if (id[ATA_ID_FIELD_VALID] & 2) {
650 mask = id->dma_1word & hwif->swdma_mask; 651 mask = id[ATA_ID_SWDMA_MODES] & hwif->swdma_mask;
651 } else if (id->tDMA) { 652 } else if (id[ATA_ID_OLD_DMA_MODES] >> 8) {
652 /* 653 u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8;
653 * ide_fix_driveid() doesn't convert ->tDMA to the
654 * CPU endianness so we need to do it here
655 */
656 u8 mode = le16_to_cpu(id->tDMA);
657 654
658 /* 655 /*
659 * if the mode is valid convert it to the mask 656 * if the mode is valid convert it to the mask
@@ -710,7 +707,8 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
710 /* 707 /*
711 * is this correct? 708 * is this correct?
712 */ 709 */
713 if (ide_dma_good_drive(drive) && drive->id->eide_dma_time < 150) 710 if (ide_dma_good_drive(drive) &&
711 drive->id[ATA_ID_EIDE_DMA_TIME] < 150)
714 mode = XFER_MW_DMA_1; 712 mode = XFER_MW_DMA_1;
715 } 713 }
716 714
@@ -729,7 +727,7 @@ static int ide_tune_dma(ide_drive_t *drive)
729 ide_hwif_t *hwif = drive->hwif; 727 ide_hwif_t *hwif = drive->hwif;
730 u8 speed; 728 u8 speed;
731 729
732 if (drive->nodma || (drive->id->capability & 1) == 0) 730 if (drive->nodma || ata_id_has_dma(drive->id) == 0)
733 return 0; 731 return 0;
734 732
735 /* consult the list of known "bad" drives */ 733 /* consult the list of known "bad" drives */
@@ -771,13 +769,15 @@ static int ide_dma_check(ide_drive_t *drive)
771 769
772int ide_id_dma_bug(ide_drive_t *drive) 770int ide_id_dma_bug(ide_drive_t *drive)
773{ 771{
774 struct hd_driveid *id = drive->id; 772 u16 *id = drive->id;
775 773
776 if (id->field_valid & 4) { 774 if (id[ATA_ID_FIELD_VALID] & 4) {
777 if ((id->dma_ultra >> 8) && (id->dma_mword >> 8)) 775 if ((id[ATA_ID_UDMA_MODES] >> 8) &&
776 (id[ATA_ID_MWDMA_MODES] >> 8))
778 goto err_out; 777 goto err_out;
779 } else if (id->field_valid & 2) { 778 } else if (id[ATA_ID_FIELD_VALID] & 2) {
780 if ((id->dma_mword >> 8) && (id->dma_1word >> 8)) 779 if ((id[ATA_ID_MWDMA_MODES] >> 8) &&
780 (id[ATA_ID_SWDMA_MODES] >> 8))
781 goto err_out; 781 goto err_out;
782 } 782 }
783 return 0; 783 return 0;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index ca11a26746f1..d36f155470a4 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -15,6 +15,8 @@
15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002 15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
16 */ 16 */
17 17
18#define DRV_NAME "ide-floppy"
19
18#define IDEFLOPPY_VERSION "1.00" 20#define IDEFLOPPY_VERSION "1.00"
19 21
20#include <linux/module.h> 22#include <linux/module.h>
@@ -31,8 +33,10 @@
31#include <linux/slab.h> 33#include <linux/slab.h>
32#include <linux/cdrom.h> 34#include <linux/cdrom.h>
33#include <linux/ide.h> 35#include <linux/ide.h>
36#include <linux/hdreg.h>
34#include <linux/bitops.h> 37#include <linux/bitops.h>
35#include <linux/mutex.h> 38#include <linux/mutex.h>
39#include <linux/scatterlist.h>
36 40
37#include <scsi/scsi_ioctl.h> 41#include <scsi/scsi_ioctl.h>
38 42
@@ -42,6 +46,8 @@
42#include <linux/io.h> 46#include <linux/io.h>
43#include <asm/unaligned.h> 47#include <asm/unaligned.h>
44 48
49#include "ide-floppy.h"
50
45/* define to see debug info */ 51/* define to see debug info */
46#define IDEFLOPPY_DEBUG_LOG 0 52#define IDEFLOPPY_DEBUG_LOG 0
47 53
@@ -55,102 +61,23 @@
55#define debug_log(fmt, args...) do {} while (0) 61#define debug_log(fmt, args...) do {} while (0)
56#endif 62#endif
57 63
58
59/* Some drives require a longer irq timeout. */
60#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
61
62/* 64/*
63 * After each failed packet command we issue a request sense command and retry 65 * After each failed packet command we issue a request sense command and retry
64 * the packet command IDEFLOPPY_MAX_PC_RETRIES times. 66 * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
65 */ 67 */
66#define IDEFLOPPY_MAX_PC_RETRIES 3 68#define IDEFLOPPY_MAX_PC_RETRIES 3
67 69
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 */ 70/* format capacities descriptor codes */
82#define CAPACITY_INVALID 0x00 71#define CAPACITY_INVALID 0x00
83#define CAPACITY_UNFORMATTED 0x01 72#define CAPACITY_UNFORMATTED 0x01
84#define CAPACITY_CURRENT 0x02 73#define CAPACITY_CURRENT 0x02
85#define CAPACITY_NO_CARTRIDGE 0x03 74#define CAPACITY_NO_CARTRIDGE 0x03
86 75
87/*
88 * Most of our global data which we need to save even as we leave the driver
89 * due to an interrupt or a timer event is stored in a variable of type
90 * idefloppy_floppy_t, defined below.
91 */
92typedef struct ide_floppy_obj {
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) */ 76#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
131 77
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
144/* Error code returned in rq->errors to the higher part of the driver. */ 78/* Error code returned in rq->errors to the higher part of the driver. */
145#define IDEFLOPPY_ERROR_GENERAL 101 79#define IDEFLOPPY_ERROR_GENERAL 101
146 80
147/*
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); 81static DEFINE_MUTEX(idefloppy_ref_mutex);
155 82
156#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref) 83#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
@@ -167,11 +94,10 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
167 mutex_lock(&idefloppy_ref_mutex); 94 mutex_lock(&idefloppy_ref_mutex);
168 floppy = ide_floppy_g(disk); 95 floppy = ide_floppy_g(disk);
169 if (floppy) { 96 if (floppy) {
170 kref_get(&floppy->kref); 97 if (ide_device_get(floppy->drive))
171 if (ide_device_get(floppy->drive)) {
172 kref_put(&floppy->kref, idefloppy_cleanup_obj);
173 floppy = NULL; 98 floppy = NULL;
174 } 99 else
100 kref_get(&floppy->kref);
175 } 101 }
176 mutex_unlock(&idefloppy_ref_mutex); 102 mutex_unlock(&idefloppy_ref_mutex);
177 return floppy; 103 return floppy;
@@ -179,9 +105,11 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
179 105
180static void ide_floppy_put(struct ide_floppy_obj *floppy) 106static void ide_floppy_put(struct ide_floppy_obj *floppy)
181{ 107{
108 ide_drive_t *drive = floppy->drive;
109
182 mutex_lock(&idefloppy_ref_mutex); 110 mutex_lock(&idefloppy_ref_mutex);
183 ide_device_put(floppy->drive);
184 kref_put(&floppy->kref, idefloppy_cleanup_obj); 111 kref_put(&floppy->kref, idefloppy_cleanup_obj);
112 ide_device_put(drive);
185 mutex_unlock(&idefloppy_ref_mutex); 113 mutex_unlock(&idefloppy_ref_mutex);
186} 114}
187 115
@@ -218,44 +146,6 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
218 return 0; 146 return 0;
219} 147}
220 148
221static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
222 unsigned int bcount, int direction)
223{
224 ide_hwif_t *hwif = drive->hwif;
225 struct request *rq = pc->rq;
226 struct req_iterator iter;
227 struct bio_vec *bvec;
228 unsigned long flags;
229 int count, done = 0;
230 char *data;
231
232 rq_for_each_segment(bvec, rq, iter) {
233 if (!bcount)
234 break;
235
236 count = min(bvec->bv_len, bcount);
237
238 data = bvec_kmap_irq(bvec, &flags);
239 if (direction)
240 hwif->tp_ops->output_data(drive, NULL, data, count);
241 else
242 hwif->tp_ops->input_data(drive, NULL, data, count);
243 bvec_kunmap_irq(data, &flags);
244
245 bcount -= count;
246 pc->b_count += count;
247 done += count;
248 }
249
250 idefloppy_end_request(drive, 1, done >> 9);
251
252 if (bcount) {
253 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
254 drive->name, __func__, bcount);
255 ide_pad_transfer(drive, direction, bcount);
256 }
257}
258
259static void idefloppy_update_buffers(ide_drive_t *drive, 149static void idefloppy_update_buffers(ide_drive_t *drive,
260 struct ide_atapi_pc *pc) 150 struct ide_atapi_pc *pc)
261{ 151{
@@ -266,43 +156,6 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
266 idefloppy_end_request(drive, 1, 0); 156 idefloppy_end_request(drive, 1, 0);
267} 157}
268 158
269/*
270 * Generate a new packet command request in front of the request queue, before
271 * the current request so that it will be processed immediately, on the next
272 * pass through the driver.
273 */
274static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
275 struct request *rq)
276{
277 struct ide_floppy_obj *floppy = drive->driver_data;
278
279 blk_rq_init(NULL, rq);
280 rq->buffer = (char *) pc;
281 rq->cmd_type = REQ_TYPE_SPECIAL;
282 rq->cmd_flags |= REQ_PREEMPT;
283 rq->rq_disk = floppy->disk;
284 memcpy(rq->cmd, pc->c, 12);
285 ide_do_drive_cmd(drive, rq);
286}
287
288static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive)
289{
290 idefloppy_floppy_t *floppy = drive->driver_data;
291
292 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
293 floppy->pc_stack_index = 0;
294 return (&floppy->pc_stack[floppy->pc_stack_index++]);
295}
296
297static struct request *idefloppy_next_rq_storage(ide_drive_t *drive)
298{
299 idefloppy_floppy_t *floppy = drive->driver_data;
300
301 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
302 floppy->rq_stack_index = 0;
303 return (&floppy->rq_stack[floppy->rq_stack_index++]);
304}
305
306static void ide_floppy_callback(ide_drive_t *drive) 159static void ide_floppy_callback(ide_drive_t *drive)
307{ 160{
308 idefloppy_floppy_t *floppy = drive->driver_data; 161 idefloppy_floppy_t *floppy = drive->driver_data;
@@ -340,16 +193,9 @@ static void ide_floppy_callback(ide_drive_t *drive)
340 idefloppy_end_request(drive, uptodate, 0); 193 idefloppy_end_request(drive, uptodate, 0);
341} 194}
342 195
343static void idefloppy_init_pc(struct ide_atapi_pc *pc) 196void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
344{ 197{
345 memset(pc, 0, sizeof(*pc)); 198 ide_init_pc(pc);
346 pc->buf = pc->pc_buf;
347 pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
348}
349
350static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
351{
352 idefloppy_init_pc(pc);
353 pc->c[0] = GPCMD_REQUEST_SENSE; 199 pc->c[0] = GPCMD_REQUEST_SENSE;
354 pc->c[4] = 255; 200 pc->c[4] = 255;
355 pc->req_xfer = 18; 201 pc->req_xfer = 18;
@@ -361,14 +207,13 @@ static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
361 */ 207 */
362static void idefloppy_retry_pc(ide_drive_t *drive) 208static void idefloppy_retry_pc(ide_drive_t *drive)
363{ 209{
364 struct ide_atapi_pc *pc; 210 struct ide_floppy_obj *floppy = drive->driver_data;
365 struct request *rq; 211 struct request *rq = &floppy->request_sense_rq;
212 struct ide_atapi_pc *pc = &floppy->request_sense_pc;
366 213
367 (void)ide_read_error(drive); 214 (void)ide_read_error(drive);
368 pc = idefloppy_next_pc_storage(drive); 215 ide_floppy_create_request_sense_cmd(pc);
369 rq = idefloppy_next_rq_storage(drive); 216 ide_queue_pc_head(drive, floppy->disk, pc, rq);
370 idefloppy_create_request_sense_cmd(pc);
371 idefloppy_queue_pc_head(drive, pc, rq);
372} 217}
373 218
374/* The usual interrupt handler called during a packet command. */ 219/* The usual interrupt handler called during a packet command. */
@@ -377,8 +222,8 @@ static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
377 idefloppy_floppy_t *floppy = drive->driver_data; 222 idefloppy_floppy_t *floppy = drive->driver_data;
378 223
379 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr, 224 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
380 IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers, 225 WAIT_FLOPPY_CMD, NULL, idefloppy_update_buffers,
381 idefloppy_retry_pc, NULL, ide_floppy_io_buffers); 226 idefloppy_retry_pc, NULL, ide_io_buffers);
382} 227}
383 228
384/* 229/*
@@ -395,10 +240,9 @@ static int idefloppy_transfer_pc(ide_drive_t *drive)
395 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12); 240 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
396 241
397 /* Timeout for the packet command */ 242 /* Timeout for the packet command */
398 return IDEFLOPPY_WAIT_CMD; 243 return WAIT_FLOPPY_CMD;
399} 244}
400 245
401
402/* 246/*
403 * Called as an interrupt (or directly). When the device says it's ready for a 247 * Called as an interrupt (or directly). When the device says it's ready for a
404 * packet, we schedule the packet transfer to occur about 2-3 ticks later in 248 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
@@ -423,7 +267,7 @@ static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
423 timeout = floppy->ticks; 267 timeout = floppy->ticks;
424 expiry = &idefloppy_transfer_pc; 268 expiry = &idefloppy_transfer_pc;
425 } else { 269 } else {
426 timeout = IDEFLOPPY_WAIT_CMD; 270 timeout = WAIT_FLOPPY_CMD;
427 expiry = NULL; 271 expiry = NULL;
428 } 272 }
429 273
@@ -473,58 +317,27 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
473 pc->retries++; 317 pc->retries++;
474 318
475 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, 319 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer,
476 IDEFLOPPY_WAIT_CMD, NULL); 320 WAIT_FLOPPY_CMD, NULL);
477}
478
479static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
480{
481 debug_log("creating prevent removal command, prevent = %d\n", prevent);
482
483 idefloppy_init_pc(pc);
484 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
485 pc->c[4] = prevent;
486} 321}
487 322
488static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 323void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
489{ 324{
490 idefloppy_init_pc(pc); 325 ide_init_pc(pc);
491 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; 326 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
492 pc->c[7] = 255; 327 pc->c[7] = 255;
493 pc->c[8] = 255; 328 pc->c[8] = 255;
494 pc->req_xfer = 255; 329 pc->req_xfer = 255;
495} 330}
496 331
497static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
498 int l, int flags)
499{
500 idefloppy_init_pc(pc);
501 pc->c[0] = GPCMD_FORMAT_UNIT;
502 pc->c[1] = 0x17;
503
504 memset(pc->buf, 0, 12);
505 pc->buf[1] = 0xA2;
506 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
507
508 if (flags & 1) /* Verify bit on... */
509 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */
510 pc->buf[3] = 8;
511
512 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4]));
513 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8]));
514 pc->buf_size = 12;
515 pc->flags |= PC_FLAG_WRITING;
516}
517
518/* A mode sense command is used to "sense" floppy parameters. */ 332/* A mode sense command is used to "sense" floppy parameters. */
519static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, 333void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
520 u8 page_code, u8 type)
521{ 334{
522 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ 335 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
523 336
524 idefloppy_init_pc(pc); 337 ide_init_pc(pc);
525 pc->c[0] = GPCMD_MODE_SENSE_10; 338 pc->c[0] = GPCMD_MODE_SENSE_10;
526 pc->c[1] = 0; 339 pc->c[1] = 0;
527 pc->c[2] = page_code + (type << 6); 340 pc->c[2] = page_code;
528 341
529 switch (page_code) { 342 switch (page_code) {
530 case IDEFLOPPY_CAPABILITIES_PAGE: 343 case IDEFLOPPY_CAPABILITIES_PAGE:
@@ -541,13 +354,6 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
541 pc->req_xfer = length; 354 pc->req_xfer = length;
542} 355}
543 356
544static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
545{
546 idefloppy_init_pc(pc);
547 pc->c[0] = GPCMD_START_STOP_UNIT;
548 pc->c[4] = start;
549}
550
551static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, 357static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
552 struct ide_atapi_pc *pc, struct request *rq, 358 struct ide_atapi_pc *pc, struct request *rq,
553 unsigned long sector) 359 unsigned long sector)
@@ -559,7 +365,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
559 debug_log("create_rw10_cmd: block == %d, blocks == %d\n", 365 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
560 block, blocks); 366 block, blocks);
561 367
562 idefloppy_init_pc(pc); 368 ide_init_pc(pc);
563 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 369 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
564 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); 370 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
565 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); 371 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
@@ -567,7 +373,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
567 memcpy(rq->cmd, pc->c, 12); 373 memcpy(rq->cmd, pc->c, 12);
568 374
569 pc->rq = rq; 375 pc->rq = rq;
570 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; 376 pc->b_count = 0;
571 if (rq->cmd_flags & REQ_RW) 377 if (rq->cmd_flags & REQ_RW)
572 pc->flags |= PC_FLAG_WRITING; 378 pc->flags |= PC_FLAG_WRITING;
573 pc->buf = NULL; 379 pc->buf = NULL;
@@ -578,10 +384,10 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
578static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, 384static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
579 struct ide_atapi_pc *pc, struct request *rq) 385 struct ide_atapi_pc *pc, struct request *rq)
580{ 386{
581 idefloppy_init_pc(pc); 387 ide_init_pc(pc);
582 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 388 memcpy(pc->c, rq->cmd, sizeof(pc->c));
583 pc->rq = rq; 389 pc->rq = rq;
584 pc->b_count = rq->data_len; 390 pc->b_count = 0;
585 if (rq->data_len && rq_data_dir(rq) == WRITE) 391 if (rq->data_len && rq_data_dir(rq) == WRITE)
586 pc->flags |= PC_FLAG_WRITING; 392 pc->flags |= PC_FLAG_WRITING;
587 pc->buf = rq->data; 393 pc->buf = rq->data;
@@ -598,15 +404,17 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
598 struct request *rq, sector_t block_s) 404 struct request *rq, sector_t block_s)
599{ 405{
600 idefloppy_floppy_t *floppy = drive->driver_data; 406 idefloppy_floppy_t *floppy = drive->driver_data;
407 ide_hwif_t *hwif = drive->hwif;
601 struct ide_atapi_pc *pc; 408 struct ide_atapi_pc *pc;
602 unsigned long block = (unsigned long)block_s; 409 unsigned long block = (unsigned long)block_s;
603 410
604 debug_log("dev: %s, cmd_type: %x, errors: %d\n", 411 debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n",
605 rq->rq_disk ? rq->rq_disk->disk_name : "?", 412 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
606 rq->cmd_type, rq->errors); 413 rq->cmd[0], rq->cmd_type, rq->errors);
607 debug_log("sector: %ld, nr_sectors: %ld, " 414
608 "current_nr_sectors: %d\n", (long)rq->sector, 415 debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",
609 rq->nr_sectors, rq->current_nr_sectors); 416 __func__, (long)rq->sector, rq->nr_sectors,
417 rq->current_nr_sectors);
610 418
611 if (rq->errors >= ERROR_MAX) { 419 if (rq->errors >= ERROR_MAX) {
612 if (floppy->failed_pc) 420 if (floppy->failed_pc)
@@ -625,12 +433,12 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
625 idefloppy_end_request(drive, 0, 0); 433 idefloppy_end_request(drive, 0, 0);
626 return ide_stopped; 434 return ide_stopped;
627 } 435 }
628 pc = idefloppy_next_pc_storage(drive); 436 pc = &floppy->queued_pc;
629 idefloppy_create_rw_cmd(floppy, pc, rq, block); 437 idefloppy_create_rw_cmd(floppy, pc, rq, block);
630 } else if (blk_special_request(rq)) { 438 } else if (blk_special_request(rq)) {
631 pc = (struct ide_atapi_pc *) rq->buffer; 439 pc = (struct ide_atapi_pc *) rq->buffer;
632 } else if (blk_pc_request(rq)) { 440 } else if (blk_pc_request(rq)) {
633 pc = idefloppy_next_pc_storage(drive); 441 pc = &floppy->queued_pc;
634 idefloppy_blockpc_cmd(floppy, pc, rq); 442 idefloppy_blockpc_cmd(floppy, pc, rq);
635 } else { 443 } else {
636 blk_dump_rq_flags(rq, 444 blk_dump_rq_flags(rq,
@@ -639,29 +447,15 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
639 return ide_stopped; 447 return ide_stopped;
640 } 448 }
641 449
642 pc->rq = rq; 450 ide_init_sg_cmd(drive, rq);
451 ide_map_sg(drive, rq);
643 452
644 return idefloppy_issue_pc(drive, pc); 453 pc->sg = hwif->sg_table;
645} 454 pc->sg_cnt = hwif->sg_nents;
646
647/*
648 * Add a special packet command request to the tail of the request queue,
649 * and wait for it to be serviced.
650 */
651static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
652{
653 struct ide_floppy_obj *floppy = drive->driver_data;
654 struct request *rq;
655 int error;
656 455
657 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 456 pc->rq = rq;
658 rq->buffer = (char *) pc;
659 rq->cmd_type = REQ_TYPE_SPECIAL;
660 memcpy(rq->cmd, pc->c, 12);
661 error = blk_execute_rq(drive->queue, floppy->disk, rq, 0);
662 blk_put_request(rq);
663 457
664 return error; 458 return idefloppy_issue_pc(drive, pc);
665} 459}
666 460
667/* 461/*
@@ -671,22 +465,28 @@ static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
671static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) 465static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
672{ 466{
673 idefloppy_floppy_t *floppy = drive->driver_data; 467 idefloppy_floppy_t *floppy = drive->driver_data;
468 struct gendisk *disk = floppy->disk;
674 struct ide_atapi_pc pc; 469 struct ide_atapi_pc pc;
675 u8 *page; 470 u8 *page;
676 int capacity, lba_capacity; 471 int capacity, lba_capacity;
677 u16 transfer_rate, sector_size, cyls, rpm; 472 u16 transfer_rate, sector_size, cyls, rpm;
678 u8 heads, sectors; 473 u8 heads, sectors;
679 474
680 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, 475 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
681 MODE_SENSE_CURRENT);
682 476
683 if (idefloppy_queue_pc_tail(drive, &pc)) { 477 if (ide_queue_pc_tail(drive, disk, &pc)) {
684 printk(KERN_ERR "ide-floppy: Can't get flexible disk page" 478 printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
685 " parameters\n"); 479 " parameters\n");
686 return 1; 480 return 1;
687 } 481 }
688 floppy->wp = !!(pc.buf[3] & 0x80); 482
689 set_disk_ro(floppy->disk, floppy->wp); 483 if (pc.buf[3] & 0x80)
484 drive->atapi_flags |= IDE_AFLAG_WP;
485 else
486 drive->atapi_flags &= ~IDE_AFLAG_WP;
487
488 set_disk_ro(disk, !!(drive->atapi_flags & IDE_AFLAG_WP));
489
690 page = &pc.buf[8]; 490 page = &pc.buf[8];
691 491
692 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); 492 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
@@ -720,23 +520,6 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
720 return 0; 520 return 0;
721} 521}
722 522
723static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
724{
725 idefloppy_floppy_t *floppy = drive->driver_data;
726 struct ide_atapi_pc pc;
727
728 floppy->srfp = 0;
729 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
730 MODE_SENSE_CURRENT);
731
732 pc.flags |= PC_FLAG_SUPPRESS_ERROR;
733 if (idefloppy_queue_pc_tail(drive, &pc))
734 return 1;
735
736 floppy->srfp = pc.buf[8 + 2] & 0x40;
737 return (0);
738}
739
740/* 523/*
741 * Determine if a media is present in the floppy drive, and if so, its LBA 524 * Determine if a media is present in the floppy drive, and if so, its LBA
742 * capacity. 525 * capacity.
@@ -744,6 +527,7 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
744static int ide_floppy_get_capacity(ide_drive_t *drive) 527static int ide_floppy_get_capacity(ide_drive_t *drive)
745{ 528{
746 idefloppy_floppy_t *floppy = drive->driver_data; 529 idefloppy_floppy_t *floppy = drive->driver_data;
530 struct gendisk *disk = floppy->disk;
747 struct ide_atapi_pc pc; 531 struct ide_atapi_pc pc;
748 u8 *cap_desc; 532 u8 *cap_desc;
749 u8 header_len, desc_cnt; 533 u8 header_len, desc_cnt;
@@ -755,8 +539,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
755 floppy->bs_factor = 1; 539 floppy->bs_factor = 1;
756 set_capacity(floppy->disk, 0); 540 set_capacity(floppy->disk, 0);
757 541
758 idefloppy_create_read_capacity_cmd(&pc); 542 ide_floppy_create_read_capacity_cmd(&pc);
759 if (idefloppy_queue_pc_tail(drive, &pc)) { 543 if (ide_queue_pc_tail(drive, disk, &pc)) {
760 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 544 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
761 return 1; 545 return 1;
762 } 546 }
@@ -831,202 +615,55 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
831 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) 615 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
832 (void) ide_floppy_get_flexible_disk_page(drive); 616 (void) ide_floppy_get_flexible_disk_page(drive);
833 617
834 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); 618 set_capacity(disk, floppy->blocks * floppy->bs_factor);
619
835 return rc; 620 return rc;
836} 621}
837 622
838/* 623static sector_t idefloppy_capacity(ide_drive_t *drive)
839 * Obtain the list of formattable capacities.
840 * Very similar to ide_floppy_get_capacity, except that we push the capacity
841 * descriptors to userland, instead of our own structures.
842 *
843 * Userland gives us the following structure:
844 *
845 * struct idefloppy_format_capacities {
846 * int nformats;
847 * struct {
848 * int nblocks;
849 * int blocksize;
850 * } formats[];
851 * };
852 *
853 * userland initializes nformats to the number of allocated formats[] records.
854 * On exit we set nformats to the number of records we've actually initialized.
855 */
856
857static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
858{ 624{
859 struct ide_atapi_pc pc; 625 idefloppy_floppy_t *floppy = drive->driver_data;
860 u8 header_len, desc_cnt; 626 unsigned long capacity = floppy->blocks * floppy->bs_factor;
861 int i, blocks, length, u_array_size, u_index;
862 int __user *argp;
863
864 if (get_user(u_array_size, arg))
865 return (-EFAULT);
866
867 if (u_array_size <= 0)
868 return (-EINVAL);
869
870 idefloppy_create_read_capacity_cmd(&pc);
871 if (idefloppy_queue_pc_tail(drive, &pc)) {
872 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
873 return (-EIO);
874 }
875 header_len = pc.buf[3];
876 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
877
878 u_index = 0;
879 argp = arg + 1;
880
881 /*
882 * We always skip the first capacity descriptor. That's the current
883 * capacity. We are interested in the remaining descriptors, the
884 * formattable capacities.
885 */
886 for (i = 1; i < desc_cnt; i++) {
887 unsigned int desc_start = 4 + i*8;
888
889 if (u_index >= u_array_size)
890 break; /* User-supplied buffer too small */
891
892 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
893 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
894
895 if (put_user(blocks, argp))
896 return(-EFAULT);
897 ++argp;
898
899 if (put_user(length, argp))
900 return (-EFAULT);
901 ++argp;
902
903 ++u_index;
904 }
905 627
906 if (put_user(u_index, arg)) 628 return capacity;
907 return (-EFAULT);
908 return (0);
909} 629}
910 630
911/* 631#ifdef CONFIG_IDE_PROC_FS
912 * Get ATAPI_FORMAT_UNIT progress indication. 632ide_devset_rw_field(bios_cyl, bios_cyl);
913 * 633ide_devset_rw_field(bios_head, bios_head);
914 * Userland gives a pointer to an int. The int is set to a progress 634ide_devset_rw_field(bios_sect, bios_sect);
915 * indicator 0-65536, with 65536=100%.
916 *
917 * If the drive does not support format progress indication, we just check
918 * the dsc bit, and return either 0 or 65536.
919 */
920 635
921static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg) 636static int get_ticks(ide_drive_t *drive)
922{ 637{
923 idefloppy_floppy_t *floppy = drive->driver_data; 638 idefloppy_floppy_t *floppy = drive->driver_data;
924 struct ide_atapi_pc pc; 639 return floppy->ticks;
925 int progress_indication = 0x10000;
926
927 if (floppy->srfp) {
928 idefloppy_create_request_sense_cmd(&pc);
929 if (idefloppy_queue_pc_tail(drive, &pc))
930 return (-EIO);
931
932 if (floppy->sense_key == 2 &&
933 floppy->asc == 4 &&
934 floppy->ascq == 4)
935 progress_indication = floppy->progress_indication;
936
937 /* Else assume format_unit has finished, and we're at 0x10000 */
938 } else {
939 ide_hwif_t *hwif = drive->hwif;
940 unsigned long flags;
941 u8 stat;
942
943 local_irq_save(flags);
944 stat = hwif->tp_ops->read_status(hwif);
945 local_irq_restore(flags);
946
947 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
948 }
949 if (put_user(progress_indication, arg))
950 return (-EFAULT);
951
952 return (0);
953} 640}
954 641
955static sector_t idefloppy_capacity(ide_drive_t *drive) 642static int set_ticks(ide_drive_t *drive, int arg)
956{ 643{
957 idefloppy_floppy_t *floppy = drive->driver_data; 644 idefloppy_floppy_t *floppy = drive->driver_data;
958 unsigned long capacity = floppy->blocks * floppy->bs_factor; 645 floppy->ticks = arg;
959
960 return capacity;
961}
962
963/*
964 * Check whether we can support a drive, based on the ATAPI IDENTIFY command
965 * results.
966 */
967static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
968{
969 u8 gcw[2];
970 u8 device_type, protocol, removable, drq_type, packet_size;
971
972 *((u16 *) &gcw) = id->config;
973
974 device_type = gcw[1] & 0x1F;
975 removable = (gcw[0] & 0x80) >> 7;
976 protocol = (gcw[1] & 0xC0) >> 6;
977 drq_type = (gcw[0] & 0x60) >> 5;
978 packet_size = gcw[0] & 0x03;
979
980#ifdef CONFIG_PPC
981 /* kludge for Apple PowerBook internal zip */
982 if (device_type == 5 &&
983 !strstr(id->model, "CD-ROM") && strstr(id->model, "ZIP"))
984 device_type = 0;
985#endif
986
987 if (protocol != 2)
988 printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
989 protocol);
990 else if (device_type != 0)
991 printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
992 "to floppy\n", device_type);
993 else if (!removable)
994 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
995 else if (drq_type == 3)
996 printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
997 "supported\n", drq_type);
998 else if (packet_size != 0)
999 printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
1000 "bytes\n", packet_size);
1001 else
1002 return 1;
1003 return 0; 646 return 0;
1004} 647}
1005 648
1006#ifdef CONFIG_IDE_PROC_FS 649IDE_DEVSET(ticks, DS_SYNC, get_ticks, set_ticks);
1007static void idefloppy_add_settings(ide_drive_t *drive)
1008{
1009 idefloppy_floppy_t *floppy = drive->driver_data;
1010 650
1011 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, 651static const struct ide_proc_devset idefloppy_settings[] = {
1012 &drive->bios_cyl, NULL); 652 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
1013 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, 653 IDE_PROC_DEVSET(bios_head, 0, 255),
1014 &drive->bios_head, NULL); 654 IDE_PROC_DEVSET(bios_sect, 0, 63),
1015 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, 655 IDE_PROC_DEVSET(ticks, 0, 255),
1016 &drive->bios_sect, NULL); 656 { 0 },
1017 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, 657};
1018 &floppy->ticks, NULL);
1019}
1020#else
1021static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1022#endif 658#endif
1023 659
1024static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) 660static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1025{ 661{
662 u16 *id = drive->id;
1026 u8 gcw[2]; 663 u8 gcw[2];
1027 664
1028 *((u16 *) &gcw) = drive->id->config; 665 *((u16 *)&gcw) = id[ATA_ID_CONFIG];
1029 floppy->pc = floppy->pc_stack; 666
1030 drive->pc_callback = ide_floppy_callback; 667 drive->pc_callback = ide_floppy_callback;
1031 668
1032 if (((gcw[0] & 0x60) >> 5) == 1) 669 if (((gcw[0] & 0x60) >> 5) == 1)
@@ -1040,7 +677,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1040 * it. It should be fixed as of version 1.9, but to be on the safe side 677 * it. It should be fixed as of version 1.9, but to be on the safe side
1041 * we'll leave the limitation below for the 2.2.x tree. 678 * we'll leave the limitation below for the 2.2.x tree.
1042 */ 679 */
1043 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) { 680 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
1044 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; 681 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
1045 /* This value will be visible in the /proc/ide/hdx/settings */ 682 /* This value will be visible in the /proc/ide/hdx/settings */
1046 floppy->ticks = IDEFLOPPY_TICKS_DELAY; 683 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
@@ -1051,13 +688,16 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1051 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes 688 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
1052 * nasty clicking noises without it, so please don't remove this. 689 * nasty clicking noises without it, so please don't remove this.
1053 */ 690 */
1054 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) { 691 if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) {
1055 blk_queue_max_sectors(drive->queue, 64); 692 blk_queue_max_sectors(drive->queue, 64);
1056 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE; 693 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
694 /* IOMEGA Clik! drives do not support lock/unlock commands */
695 drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
1057 } 696 }
1058 697
1059 (void) ide_floppy_get_capacity(drive); 698 (void) ide_floppy_get_capacity(drive);
1060 idefloppy_add_settings(drive); 699
700 ide_proc_register_driver(drive, floppy->driver);
1061} 701}
1062 702
1063static void ide_floppy_remove(ide_drive_t *drive) 703static void ide_floppy_remove(ide_drive_t *drive)
@@ -1114,12 +754,12 @@ static ide_driver_t idefloppy_driver = {
1114 .remove = ide_floppy_remove, 754 .remove = ide_floppy_remove,
1115 .version = IDEFLOPPY_VERSION, 755 .version = IDEFLOPPY_VERSION,
1116 .media = ide_floppy, 756 .media = ide_floppy,
1117 .supports_dsc_overlap = 0,
1118 .do_request = idefloppy_do_request, 757 .do_request = idefloppy_do_request,
1119 .end_request = idefloppy_end_request, 758 .end_request = idefloppy_end_request,
1120 .error = __ide_error, 759 .error = __ide_error,
1121#ifdef CONFIG_IDE_PROC_FS 760#ifdef CONFIG_IDE_PROC_FS
1122 .proc = idefloppy_proc, 761 .proc = idefloppy_proc,
762 .settings = idefloppy_settings,
1123#endif 763#endif
1124}; 764};
1125 765
@@ -1128,7 +768,6 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1128 struct gendisk *disk = inode->i_bdev->bd_disk; 768 struct gendisk *disk = inode->i_bdev->bd_disk;
1129 struct ide_floppy_obj *floppy; 769 struct ide_floppy_obj *floppy;
1130 ide_drive_t *drive; 770 ide_drive_t *drive;
1131 struct ide_atapi_pc pc;
1132 int ret = 0; 771 int ret = 0;
1133 772
1134 debug_log("Reached %s\n", __func__); 773 debug_log("Reached %s\n", __func__);
@@ -1145,13 +784,8 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1145 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; 784 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1146 /* Just in case */ 785 /* Just in case */
1147 786
1148 idefloppy_init_pc(&pc); 787 if (ide_do_test_unit_ready(drive, disk))
1149 pc.c[0] = GPCMD_TEST_UNIT_READY; 788 ide_do_start_stop(drive, disk, 1);
1150
1151 if (idefloppy_queue_pc_tail(drive, &pc)) {
1152 idefloppy_create_start_stop_cmd(&pc, 1);
1153 (void) idefloppy_queue_pc_tail(drive, &pc);
1154 }
1155 789
1156 if (ide_floppy_get_capacity(drive) 790 if (ide_floppy_get_capacity(drive)
1157 && (filp->f_flags & O_NDELAY) == 0 791 && (filp->f_flags & O_NDELAY) == 0
@@ -1165,16 +799,13 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1165 goto out_put_floppy; 799 goto out_put_floppy;
1166 } 800 }
1167 801
1168 if (floppy->wp && (filp->f_mode & 2)) { 802 if ((drive->atapi_flags & IDE_AFLAG_WP) && (filp->f_mode & 2)) {
1169 ret = -EROFS; 803 ret = -EROFS;
1170 goto out_put_floppy; 804 goto out_put_floppy;
1171 } 805 }
806
1172 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; 807 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
1173 /* IOMEGA Clik! drives do not support lock/unlock commands */ 808 ide_set_media_lock(drive, disk, 1);
1174 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1175 idefloppy_create_prevent_cmd(&pc, 1);
1176 (void) idefloppy_queue_pc_tail(drive, &pc);
1177 }
1178 check_disk_change(inode->i_bdev); 809 check_disk_change(inode->i_bdev);
1179 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) { 810 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
1180 ret = -EBUSY; 811 ret = -EBUSY;
@@ -1193,17 +824,11 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
1193 struct gendisk *disk = inode->i_bdev->bd_disk; 824 struct gendisk *disk = inode->i_bdev->bd_disk;
1194 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 825 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1195 ide_drive_t *drive = floppy->drive; 826 ide_drive_t *drive = floppy->drive;
1196 struct ide_atapi_pc pc;
1197 827
1198 debug_log("Reached %s\n", __func__); 828 debug_log("Reached %s\n", __func__);
1199 829
1200 if (floppy->openers == 1) { 830 if (floppy->openers == 1) {
1201 /* IOMEGA Clik! drives do not support lock/unlock commands */ 831 ide_set_media_lock(drive, disk, 0);
1202 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1203 idefloppy_create_prevent_cmd(&pc, 0);
1204 (void) idefloppy_queue_pc_tail(drive, &pc);
1205 }
1206
1207 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; 832 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1208 } 833 }
1209 834
@@ -1229,80 +854,20 @@ static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
1229 unsigned long arg, unsigned int cmd) 854 unsigned long arg, unsigned int cmd)
1230{ 855{
1231 idefloppy_floppy_t *floppy = drive->driver_data; 856 idefloppy_floppy_t *floppy = drive->driver_data;
857 struct gendisk *disk = floppy->disk;
858 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
1232 859
1233 if (floppy->openers > 1) 860 if (floppy->openers > 1)
1234 return -EBUSY; 861 return -EBUSY;
1235 862
1236 /* The IOMEGA Clik! Drive doesn't support this command - 863 ide_set_media_lock(drive, disk, prevent);
1237 * no room for an eject mechanism */
1238 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1239 int prevent = arg ? 1 : 0;
1240 864
1241 if (cmd == CDROMEJECT) 865 if (cmd == CDROMEJECT)
1242 prevent = 0; 866 ide_do_start_stop(drive, disk, 2);
1243
1244 idefloppy_create_prevent_cmd(pc, prevent);
1245 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1246 }
1247
1248 if (cmd == CDROMEJECT) {
1249 idefloppy_create_start_stop_cmd(pc, 2);
1250 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1251 }
1252 867
1253 return 0; 868 return 0;
1254} 869}
1255 870
1256static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1257 int __user *arg)
1258{
1259 struct ide_atapi_pc pc;
1260 ide_drive_t *drive = floppy->drive;
1261 int blocks, length, flags, err = 0;
1262
1263 if (floppy->openers > 1) {
1264 /* Don't format if someone is using the disk */
1265 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1266 return -EBUSY;
1267 }
1268
1269 drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
1270
1271 /*
1272 * Send ATAPI_FORMAT_UNIT to the drive.
1273 *
1274 * Userland gives us the following structure:
1275 *
1276 * struct idefloppy_format_command {
1277 * int nblocks;
1278 * int blocksize;
1279 * int flags;
1280 * } ;
1281 *
1282 * flags is a bitmask, currently, the only defined flag is:
1283 *
1284 * 0x01 - verify media after format.
1285 */
1286 if (get_user(blocks, arg) ||
1287 get_user(length, arg+1) ||
1288 get_user(flags, arg+2)) {
1289 err = -EFAULT;
1290 goto out;
1291 }
1292
1293 (void) idefloppy_get_sfrp_bit(drive);
1294 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1295
1296 if (idefloppy_queue_pc_tail(drive, &pc))
1297 err = -EIO;
1298
1299out:
1300 if (err)
1301 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1302 return err;
1303}
1304
1305
1306static int idefloppy_ioctl(struct inode *inode, struct file *file, 871static int idefloppy_ioctl(struct inode *inode, struct file *file,
1307 unsigned int cmd, unsigned long arg) 872 unsigned int cmd, unsigned long arg)
1308{ 873{
@@ -1313,23 +878,12 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
1313 void __user *argp = (void __user *)arg; 878 void __user *argp = (void __user *)arg;
1314 int err; 879 int err;
1315 880
1316 switch (cmd) { 881 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
1317 case CDROMEJECT:
1318 /* fall through */
1319 case CDROM_LOCKDOOR:
1320 return ide_floppy_lockdoor(drive, &pc, arg, cmd); 882 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
1321 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: 883
1322 return 0; 884 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
1323 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: 885 if (err != -ENOTTY)
1324 return ide_floppy_get_format_capacities(drive, argp); 886 return err;
1325 case IDEFLOPPY_IOCTL_FORMAT_START:
1326 if (!(file->f_mode & 2))
1327 return -EPERM;
1328
1329 return ide_floppy_format_unit(floppy, (int __user *)arg);
1330 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1331 return idefloppy_get_format_progress(drive, argp);
1332 }
1333 887
1334 /* 888 /*
1335 * skip SCSI_IOCTL_SEND_COMMAND (deprecated) 889 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
@@ -1338,8 +892,6 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
1338 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) 892 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1339 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, 893 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1340 bdev->bd_disk, cmd, argp); 894 bdev->bd_disk, cmd, argp);
1341 else
1342 err = -ENOTTY;
1343 895
1344 if (err == -ENOTTY) 896 if (err == -ENOTTY)
1345 err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 897 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
@@ -1387,11 +939,11 @@ static int ide_floppy_probe(ide_drive_t *drive)
1387 939
1388 if (!strstr("ide-floppy", drive->driver_req)) 940 if (!strstr("ide-floppy", drive->driver_req))
1389 goto failed; 941 goto failed;
1390 if (!drive->present) 942
1391 goto failed;
1392 if (drive->media != ide_floppy) 943 if (drive->media != ide_floppy)
1393 goto failed; 944 goto failed;
1394 if (!idefloppy_identify_device(drive, drive->id)) { 945
946 if (!ide_check_atapi_device(drive, DRV_NAME)) {
1395 printk(KERN_ERR "ide-floppy: %s: not supported by this version" 947 printk(KERN_ERR "ide-floppy: %s: not supported by this version"
1396 " of ide-floppy\n", drive->name); 948 " of ide-floppy\n", drive->name);
1397 goto failed; 949 goto failed;
@@ -1409,8 +961,6 @@ static int ide_floppy_probe(ide_drive_t *drive)
1409 961
1410 ide_init_disk(g, drive); 962 ide_init_disk(g, drive);
1411 963
1412 ide_proc_register_driver(drive, &idefloppy_driver);
1413
1414 kref_init(&floppy->kref); 964 kref_init(&floppy->kref);
1415 965
1416 floppy->drive = drive; 966 floppy->drive = drive;
@@ -1449,6 +999,7 @@ static int __init idefloppy_init(void)
1449} 999}
1450 1000
1451MODULE_ALIAS("ide:*m-floppy*"); 1001MODULE_ALIAS("ide:*m-floppy*");
1002MODULE_ALIAS("ide-floppy");
1452module_init(idefloppy_init); 1003module_init(idefloppy_init);
1453module_exit(idefloppy_exit); 1004module_exit(idefloppy_exit);
1454MODULE_LICENSE("GPL"); 1005MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h
new file mode 100644
index 000000000000..ecadc2bc322d
--- /dev/null
+++ b/drivers/ide/ide-floppy.h
@@ -0,0 +1,63 @@
1#ifndef __IDE_FLOPPY_H
2#define __IDE_FLOPPY_H
3
4/*
5 * Most of our global data which we need to save even as we leave the driver
6 * due to an interrupt or a timer event is stored in a variable of type
7 * idefloppy_floppy_t, defined below.
8 */
9typedef struct ide_floppy_obj {
10 ide_drive_t *drive;
11 ide_driver_t *driver;
12 struct gendisk *disk;
13 struct kref kref;
14 unsigned int openers; /* protected by BKL for now */
15
16 /* Current packet command */
17 struct ide_atapi_pc *pc;
18 /* Last failed packet command */
19 struct ide_atapi_pc *failed_pc;
20 /* used for blk_{fs,pc}_request() requests */
21 struct ide_atapi_pc queued_pc;
22
23 struct ide_atapi_pc request_sense_pc;
24 struct request request_sense_rq;
25
26 /* Last error information */
27 u8 sense_key, asc, ascq;
28 /* delay this long before sending packet command */
29 u8 ticks;
30 int progress_indication;
31
32 /* Device information */
33 /* Current format */
34 int blocks, block_size, bs_factor;
35 /* Last format capacity descriptor */
36 u8 cap_desc[8];
37 /* Copy of the flexible disk page */
38 u8 flexible_disk_page[32];
39} idefloppy_floppy_t;
40
41/*
42 * Pages of the SELECT SENSE / MODE SENSE packet commands.
43 * See SFF-8070i spec.
44 */
45#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
46#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
47
48/* IOCTLs used in low-level formatting. */
49#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
50#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
51#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
52#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
53
54/* ide-floppy.c */
55void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
56void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
57void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *);
58
59/* ide-floppy_ioctl.c */
60int ide_floppy_format_ioctl(ide_drive_t *, struct file *, unsigned int,
61 void __user *);
62
63#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..5ffc4512d14b
--- /dev/null
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -0,0 +1,243 @@
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_floppy_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 idefloppy_floppy_t *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 idefloppy_floppy_t *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->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
142 return -EBUSY;
143 }
144
145 drive->atapi_flags |= IDE_AFLAG_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->atapi_flags &= ~IDE_AFLAG_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 idefloppy_floppy_t *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_floppy_create_request_sense_cmd(&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
226int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
227 unsigned int cmd, void __user *argp)
228{
229 switch (cmd) {
230 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
231 return 0;
232 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
233 return ide_floppy_get_format_capacities(drive, argp);
234 case IDEFLOPPY_IOCTL_FORMAT_START:
235 if (!(file->f_mode & 2))
236 return -EPERM;
237 return ide_floppy_format_unit(drive, (int __user *)argp);
238 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
239 return ide_floppy_get_format_progress(drive, argp);
240 default:
241 return -ENOTTY;
242 }
243}
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 8fe8b5b9cf7d..0a3cb0c33ae5 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,19 +101,65 @@ 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[MAX_HWIFS], *hws[MAX_HWIFS];
106 struct ide_host *host; 141 struct ide_host *host;
107 unsigned long io_addr; 142 unsigned long io_addr;
108 int i, rc; 143 int i, rc, primary = 0, secondary = 0;
109 144
110#ifdef CONFIG_MIPS 145#ifdef CONFIG_MIPS
111 if (!ide_probe_legacy()) 146 if (!ide_probe_legacy())
112 return -ENODEV; 147 return -ENODEV;
113#endif 148#endif
114 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module " 149 ide_generic_check_pci_legacy_iobases(&primary, &secondary);
115 "parameter for probing all legacy ISA IDE ports\n"); 150
151 if (!probe_mask) {
152 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
153 "module parameter for probing all legacy ISA IDE ports\n");
154
155 if (primary == 0)
156 probe_mask |= 0x1;
157
158 if (secondary == 0)
159 probe_mask |= 0x2;
160 } else
161 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
162 "upon user request\n");
116 163
117 memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS); 164 memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
118 165
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index a896a283f27f..1c51949833be 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>
@@ -183,18 +184,18 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
183 if (drive->media != ide_disk) 184 if (drive->media != ide_disk)
184 break; 185 break;
185 /* Not supported? Switch to next step now. */ 186 /* Not supported? Switch to next step now. */
186 if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) { 187 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) {
187 ide_complete_power_step(drive, rq, 0, 0); 188 ide_complete_power_step(drive, rq, 0, 0);
188 return ide_stopped; 189 return ide_stopped;
189 } 190 }
190 if (ide_id_has_flush_cache_ext(drive->id)) 191 if (ata_id_flush_ext_enabled(drive->id))
191 args->tf.command = WIN_FLUSH_CACHE_EXT; 192 args->tf.command = ATA_CMD_FLUSH_EXT;
192 else 193 else
193 args->tf.command = WIN_FLUSH_CACHE; 194 args->tf.command = ATA_CMD_FLUSH;
194 goto out_do_tf; 195 goto out_do_tf;
195 196
196 case idedisk_pm_standby: /* Suspend step 2 (standby) */ 197 case idedisk_pm_standby: /* Suspend step 2 (standby) */
197 args->tf.command = WIN_STANDBYNOW1; 198 args->tf.command = ATA_CMD_STANDBYNOW1;
198 goto out_do_tf; 199 goto out_do_tf;
199 200
200 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */ 201 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
@@ -209,7 +210,7 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
209 return ide_stopped; 210 return ide_stopped;
210 211
211 case idedisk_pm_idle: /* Resume step 2 (idle) */ 212 case idedisk_pm_idle: /* Resume step 2 (idle) */
212 args->tf.command = WIN_IDLEIMMEDIATE; 213 args->tf.command = ATA_CMD_IDLEIMMEDIATE;
213 goto out_do_tf; 214 goto out_do_tf;
214 215
215 case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */ 216 case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
@@ -322,7 +323,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
322 ide_task_t *task = (ide_task_t *)rq->special; 323 ide_task_t *task = (ide_task_t *)rq->special;
323 324
324 if (rq->errors == 0) 325 if (rq->errors == 0)
325 rq->errors = !OK_STAT(stat, READY_STAT, BAD_STAT); 326 rq->errors = !OK_STAT(stat, ATA_DRDY, BAD_STAT);
326 327
327 if (task) { 328 if (task) {
328 struct ide_taskfile *tf = &task->tf; 329 struct ide_taskfile *tf = &task->tf;
@@ -373,29 +374,29 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
373{ 374{
374 ide_hwif_t *hwif = drive->hwif; 375 ide_hwif_t *hwif = drive->hwif;
375 376
376 if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { 377 if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) {
377 /* other bits are useless when BUSY */ 378 /* other bits are useless when BUSY */
378 rq->errors |= ERROR_RESET; 379 rq->errors |= ERROR_RESET;
379 } else if (stat & ERR_STAT) { 380 } else if (stat & ATA_ERR) {
380 /* err has different meaning on cdrom and tape */ 381 /* err has different meaning on cdrom and tape */
381 if (err == ABRT_ERR) { 382 if (err == ATA_ABORTED) {
382 if (drive->select.b.lba && 383 if (drive->select.b.lba &&
383 /* some newer drives don't support WIN_SPECIFY */ 384 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
384 hwif->tp_ops->read_status(hwif) == WIN_SPECIFY) 385 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
385 return ide_stopped; 386 return ide_stopped;
386 } else if ((err & BAD_CRC) == BAD_CRC) { 387 } else if ((err & BAD_CRC) == BAD_CRC) {
387 /* UDMA crc error, just retry the operation */ 388 /* UDMA crc error, just retry the operation */
388 drive->crc_count++; 389 drive->crc_count++;
389 } else if (err & (BBD_ERR | ECC_ERR)) { 390 } else if (err & (ATA_BBK | ATA_UNC)) {
390 /* retries won't help these */ 391 /* retries won't help these */
391 rq->errors = ERROR_MAX; 392 rq->errors = ERROR_MAX;
392 } else if (err & TRK0_ERR) { 393 } else if (err & ATA_TRK0NF) {
393 /* help it find track zero */ 394 /* help it find track zero */
394 rq->errors |= ERROR_RECAL; 395 rq->errors |= ERROR_RECAL;
395 } 396 }
396 } 397 }
397 398
398 if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && 399 if ((stat & ATA_DRQ) && rq_data_dir(rq) == READ &&
399 (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) { 400 (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) {
400 int nsect = drive->mult_count ? drive->mult_count : 1; 401 int nsect = drive->mult_count ? drive->mult_count : 1;
401 402
@@ -407,7 +408,7 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
407 return ide_stopped; 408 return ide_stopped;
408 } 409 }
409 410
410 if (hwif->tp_ops->read_status(hwif) & (BUSY_STAT | DRQ_STAT)) 411 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
411 rq->errors |= ERROR_RESET; 412 rq->errors |= ERROR_RESET;
412 413
413 if ((rq->errors & ERROR_RESET) == ERROR_RESET) { 414 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
@@ -427,16 +428,16 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
427{ 428{
428 ide_hwif_t *hwif = drive->hwif; 429 ide_hwif_t *hwif = drive->hwif;
429 430
430 if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { 431 if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) {
431 /* other bits are useless when BUSY */ 432 /* other bits are useless when BUSY */
432 rq->errors |= ERROR_RESET; 433 rq->errors |= ERROR_RESET;
433 } else { 434 } else {
434 /* add decoding error stuff */ 435 /* add decoding error stuff */
435 } 436 }
436 437
437 if (hwif->tp_ops->read_status(hwif) & (BUSY_STAT | DRQ_STAT)) 438 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
438 /* force an abort */ 439 /* force an abort */
439 hwif->tp_ops->exec_command(hwif, WIN_IDLEIMMEDIATE); 440 hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
440 441
441 if (rq->errors >= ERROR_MAX) { 442 if (rq->errors >= ERROR_MAX) {
442 ide_kill_rq(drive, rq); 443 ide_kill_rq(drive, rq);
@@ -509,19 +510,19 @@ static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
509 tf->lbam = drive->cyl; 510 tf->lbam = drive->cyl;
510 tf->lbah = drive->cyl >> 8; 511 tf->lbah = drive->cyl >> 8;
511 tf->device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA; 512 tf->device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA;
512 tf->command = WIN_SPECIFY; 513 tf->command = ATA_CMD_INIT_DEV_PARAMS;
513} 514}
514 515
515static void ide_tf_set_restore_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 516static void ide_tf_set_restore_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
516{ 517{
517 tf->nsect = drive->sect; 518 tf->nsect = drive->sect;
518 tf->command = WIN_RESTORE; 519 tf->command = ATA_CMD_RESTORE;
519} 520}
520 521
521static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 522static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
522{ 523{
523 tf->nsect = drive->mult_req; 524 tf->nsect = drive->mult_req;
524 tf->command = WIN_SETMULT; 525 tf->command = ATA_CMD_SET_MULTI;
525} 526}
526 527
527static ide_startstop_t ide_disk_special(ide_drive_t *drive) 528static ide_startstop_t ide_disk_special(ide_drive_t *drive)
@@ -540,8 +541,6 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
540 ide_tf_set_restore_cmd(drive, &args.tf); 541 ide_tf_set_restore_cmd(drive, &args.tf);
541 } else if (s->b.set_multmode) { 542 } else if (s->b.set_multmode) {
542 s->b.set_multmode = 0; 543 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); 544 ide_tf_set_setmult_cmd(drive, &args.tf);
546 } else if (s->all) { 545 } else if (s->all) {
547 int special = s->all; 546 int special = s->all;
@@ -586,9 +585,10 @@ static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
586 * do_special - issue some special commands 585 * do_special - issue some special commands
587 * @drive: drive the command is for 586 * @drive: drive the command is for
588 * 587 *
589 * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT 588 * 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 589 * ATA_CMD_RESTORE and ATA_CMD_SET_MULTI commands to a drive.
591 * back. 590 *
591 * It used to do much more, but has been scaled back.
592 */ 592 */
593 593
594static ide_startstop_t do_special (ide_drive_t *drive) 594static ide_startstop_t do_special (ide_drive_t *drive)
@@ -716,9 +716,49 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
716 return ide_stopped; 716 return ide_stopped;
717} 717}
718 718
719int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
720 int arg)
721{
722 struct request_queue *q = drive->queue;
723 struct request *rq;
724 int ret = 0;
725
726 if (!(setting->flags & DS_SYNC))
727 return setting->set(drive, arg);
728
729 rq = blk_get_request(q, READ, GFP_KERNEL);
730 if (!rq)
731 return -ENOMEM;
732
733 rq->cmd_type = REQ_TYPE_SPECIAL;
734 rq->cmd_len = 5;
735 rq->cmd[0] = REQ_DEVSET_EXEC;
736 *(int *)&rq->cmd[1] = arg;
737 rq->special = setting->set;
738
739 if (blk_execute_rq(q, NULL, rq, 0))
740 ret = rq->errors;
741 blk_put_request(rq);
742
743 return ret;
744}
745EXPORT_SYMBOL_GPL(ide_devset_execute);
746
719static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) 747static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
720{ 748{
721 switch (rq->cmd[0]) { 749 switch (rq->cmd[0]) {
750 case REQ_DEVSET_EXEC:
751 {
752 int err, (*setfunc)(ide_drive_t *, int) = rq->special;
753
754 err = setfunc(drive, *(int *)&rq->cmd[1]);
755 if (err)
756 rq->errors = err;
757 else
758 err = 1;
759 ide_end_request(drive, err, 0);
760 return ide_stopped;
761 }
722 case REQ_DRIVE_RESET: 762 case REQ_DRIVE_RESET:
723 return ide_do_reset(drive); 763 return ide_do_reset(drive);
724 default: 764 default:
@@ -766,9 +806,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 806 * start_request - start of I/O and command issuing for IDE
767 * 807 *
768 * start_request() initiates handling of a new I/O request. It 808 * start_request() initiates handling of a new I/O request. It
769 * accepts commands and I/O (read/write) requests. It also does 809 * 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 * 810 *
773 * FIXME: this function needs a rename 811 * FIXME: this function needs a rename
774 */ 812 */
@@ -776,7 +814,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) 814static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
777{ 815{
778 ide_startstop_t startstop; 816 ide_startstop_t startstop;
779 sector_t block;
780 817
781 BUG_ON(!blk_rq_started(rq)); 818 BUG_ON(!blk_rq_started(rq));
782 819
@@ -791,21 +828,12 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
791 goto kill_rq; 828 goto kill_rq;
792 } 829 }
793 830
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)) 831 if (blk_pm_request(rq))
805 ide_check_pm_state(drive, rq); 832 ide_check_pm_state(drive, rq);
806 833
807 SELECT_DRIVE(drive); 834 SELECT_DRIVE(drive);
808 if (ide_wait_stat(&startstop, drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) { 835 if (ide_wait_stat(&startstop, drive, drive->ready_stat,
836 ATA_BUSY | ATA_DRQ, WAIT_READY)) {
809 printk(KERN_ERR "%s: drive not ready for command\n", drive->name); 837 printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
810 return startstop; 838 return startstop;
811 } 839 }
@@ -844,7 +872,8 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
844 return ide_special_rq(drive, rq); 872 return ide_special_rq(drive, rq);
845 873
846 drv = *(ide_driver_t **)rq->rq_disk->private_data; 874 drv = *(ide_driver_t **)rq->rq_disk->private_data;
847 return drv->do_request(drive, rq, block); 875
876 return drv->do_request(drive, rq, rq->sector);
848 } 877 }
849 return do_special(drive); 878 return do_special(drive);
850kill_rq: 879kill_rq:
@@ -1325,7 +1354,7 @@ static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
1325 if (hwif->irq == irq) { 1354 if (hwif->irq == irq) {
1326 stat = hwif->tp_ops->read_status(hwif); 1355 stat = hwif->tp_ops->read_status(hwif);
1327 1356
1328 if (!OK_STAT(stat, READY_STAT, BAD_STAT)) { 1357 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
1329 /* Try to not flood the console with msgs */ 1358 /* Try to not flood the console with msgs */
1330 static unsigned long last_msgtime, count; 1359 static unsigned long last_msgtime, count;
1331 ++count; 1360 ++count;
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
new file mode 100644
index 000000000000..cf01564901af
--- /dev/null
+++ b/drivers/ide/ide-ioctls.c
@@ -0,0 +1,290 @@
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->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->dsc_overlap << IDE_NICE_DSC_OVERLAP) |
90 (drive->nice1 << IDE_NICE_1), (long __user *)arg);
91}
92
93static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
94{
95 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
96 return -EPERM;
97
98 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
99 (drive->media == ide_disk || drive->media == ide_floppy ||
100 drive->scsi))
101 return -EPERM;
102
103 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
104 drive->nice1 = (arg >> IDE_NICE_1) & 1;
105
106 return 0;
107}
108
109static int ide_cmd_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg)
110{
111 u8 *buf = NULL;
112 int bufsize = 0, err = 0;
113 u8 args[4], xfer_rate = 0;
114 ide_task_t tfargs;
115 struct ide_taskfile *tf = &tfargs.tf;
116 u16 *id = drive->id;
117
118 if (NULL == (void *) arg) {
119 struct request *rq;
120
121 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
122 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
123 err = blk_execute_rq(drive->queue, NULL, rq, 0);
124 blk_put_request(rq);
125
126 return err;
127 }
128
129 if (copy_from_user(args, (void __user *)arg, 4))
130 return -EFAULT;
131
132 memset(&tfargs, 0, sizeof(ide_task_t));
133 tf->feature = args[2];
134 if (args[0] == ATA_CMD_SMART) {
135 tf->nsect = args[3];
136 tf->lbal = args[1];
137 tf->lbam = 0x4f;
138 tf->lbah = 0xc2;
139 tfargs.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT;
140 } else {
141 tf->nsect = args[1];
142 tfargs.tf_flags = IDE_TFLAG_OUT_FEATURE |
143 IDE_TFLAG_OUT_NSECT | IDE_TFLAG_IN_NSECT;
144 }
145 tf->command = args[0];
146 tfargs.data_phase = args[3] ? TASKFILE_IN : TASKFILE_NO_DATA;
147
148 if (args[3]) {
149 tfargs.tf_flags |= IDE_TFLAG_IO_16BIT;
150 bufsize = SECTOR_SIZE * args[3];
151 buf = kzalloc(bufsize, GFP_KERNEL);
152 if (buf == NULL)
153 return -ENOMEM;
154 }
155
156 if (tf->command == ATA_CMD_SET_FEATURES &&
157 tf->feature == SETFEATURES_XFER &&
158 tf->nsect >= XFER_SW_DMA_0 &&
159 (id[ATA_ID_UDMA_MODES] ||
160 id[ATA_ID_MWDMA_MODES] ||
161 id[ATA_ID_SWDMA_MODES])) {
162 xfer_rate = args[1];
163 if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
164 printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
165 "be set\n", drive->name);
166 goto abort;
167 }
168 }
169
170 err = ide_raw_taskfile(drive, &tfargs, buf, args[3]);
171
172 args[0] = tf->status;
173 args[1] = tf->error;
174 args[2] = tf->nsect;
175
176 if (!err && xfer_rate) {
177 /* active-retuning-calls future */
178 ide_set_xfer_rate(drive, xfer_rate);
179 ide_driveid_update(drive);
180 }
181abort:
182 if (copy_to_user((void __user *)arg, &args, 4))
183 err = -EFAULT;
184 if (buf) {
185 if (copy_to_user((void __user *)(arg + 4), buf, bufsize))
186 err = -EFAULT;
187 kfree(buf);
188 }
189 return err;
190}
191
192static int ide_task_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg)
193{
194 void __user *p = (void __user *)arg;
195 int err = 0;
196 u8 args[7];
197 ide_task_t task;
198
199 if (copy_from_user(args, p, 7))
200 return -EFAULT;
201
202 memset(&task, 0, sizeof(task));
203 memcpy(&task.tf_array[7], &args[1], 6);
204 task.tf.command = args[0];
205 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
206
207 err = ide_no_data_taskfile(drive, &task);
208
209 args[0] = task.tf.command;
210 memcpy(&args[1], &task.tf_array[7], 6);
211
212 if (copy_to_user(p, args, 7))
213 err = -EFAULT;
214
215 return err;
216}
217
218static int generic_drive_reset(ide_drive_t *drive)
219{
220 struct request *rq;
221 int ret = 0;
222
223 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
224 rq->cmd_type = REQ_TYPE_SPECIAL;
225 rq->cmd_len = 1;
226 rq->cmd[0] = REQ_DRIVE_RESET;
227 rq->cmd_flags |= REQ_SOFTBARRIER;
228 if (blk_execute_rq(drive->queue, NULL, rq, 1))
229 ret = rq->errors;
230 blk_put_request(rq);
231 return ret;
232}
233
234int generic_ide_ioctl(ide_drive_t *drive, struct file *file,
235 struct block_device *bdev,
236 unsigned int cmd, unsigned long arg)
237{
238 int err;
239
240 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_ioctl_settings);
241 if (err != -EOPNOTSUPP)
242 return err;
243
244 switch (cmd) {
245 case HDIO_OBSOLETE_IDENTITY:
246 case HDIO_GET_IDENTITY:
247 if (bdev != bdev->bd_contains)
248 return -EINVAL;
249 return ide_get_identity_ioctl(drive, cmd, arg);
250 case HDIO_GET_NICE:
251 return ide_get_nice_ioctl(drive, arg);
252 case HDIO_SET_NICE:
253 if (!capable(CAP_SYS_ADMIN))
254 return -EACCES;
255 return ide_set_nice_ioctl(drive, arg);
256#ifdef CONFIG_IDE_TASK_IOCTL
257 case HDIO_DRIVE_TASKFILE:
258 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
259 return -EACCES;
260 if (drive->media == ide_disk)
261 return ide_taskfile_ioctl(drive, cmd, arg);
262 return -ENOMSG;
263#endif
264 case HDIO_DRIVE_CMD:
265 if (!capable(CAP_SYS_RAWIO))
266 return -EACCES;
267 return ide_cmd_ioctl(drive, cmd, arg);
268 case HDIO_DRIVE_TASK:
269 if (!capable(CAP_SYS_RAWIO))
270 return -EACCES;
271 return ide_task_ioctl(drive, cmd, arg);
272 case HDIO_DRIVE_RESET:
273 if (!capable(CAP_SYS_ADMIN))
274 return -EACCES;
275 return generic_drive_reset(drive);
276 case HDIO_GET_BUSSTATE:
277 if (!capable(CAP_SYS_ADMIN))
278 return -EACCES;
279 if (put_user(BUSSTATE_ON, (long __user *)arg))
280 return -EFAULT;
281 return 0;
282 case HDIO_SET_BUSSTATE:
283 if (!capable(CAP_SYS_ADMIN))
284 return -EACCES;
285 return -EOPNOTSUPP;
286 default:
287 return -EINVAL;
288 }
289}
290EXPORT_SYMBOL(generic_ide_ioctl);
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 8aae91764513..0a2fd3b37ac4 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -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>
@@ -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 < 14; i++)
488 id->words161_175[i] = __le16_to_cpu(id->words161_175[i]);
489 for (i = 0; i < 31; i++)
490 id->words176_205[i] = __le16_to_cpu(id->words176_205[i]);
491 for (i = 0; i < 48; 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,7 +642,8 @@ 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:
@@ -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->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 /*
@@ -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,9 +784,9 @@ 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
@@ -881,23 +796,17 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
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)) {
@@ -1056,7 +965,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
1056 965
1057 tmp = hwif->tp_ops->read_status(hwif); 966 tmp = hwif->tp_ops->read_status(hwif);
1058 967
1059 if (!OK_STAT(tmp, 0, BUSY_STAT)) { 968 if (!OK_STAT(tmp, 0, ATA_BUSY)) {
1060 if (time_before(jiffies, hwgroup->poll_timeout)) { 969 if (time_before(jiffies, hwgroup->poll_timeout)) {
1061 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 970 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
1062 /* continue polling */ 971 /* continue polling */
@@ -1102,7 +1011,7 @@ out:
1102 1011
1103static void ide_disk_pre_reset(ide_drive_t *drive) 1012static void ide_disk_pre_reset(ide_drive_t *drive)
1104{ 1013{
1105 int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1; 1014 int legacy = (drive->id[ATA_ID_CFS_ENABLE_2] & 0x0400) ? 0 : 1;
1106 1015
1107 drive->special.all = 0; 1016 drive->special.all = 0;
1108 drive->special.b.set_geometry = legacy; 1017 drive->special.b.set_geometry = legacy;
@@ -1187,7 +1096,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1187 pre_reset(drive); 1096 pre_reset(drive);
1188 SELECT_DRIVE(drive); 1097 SELECT_DRIVE(drive);
1189 udelay (20); 1098 udelay (20);
1190 tp_ops->exec_command(hwif, WIN_SRST); 1099 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
1191 ndelay(400); 1100 ndelay(400);
1192 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; 1101 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
1193 hwgroup->polling = 1; 1102 hwgroup->polling = 1;
@@ -1270,7 +1179,7 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
1270 */ 1179 */
1271 mdelay(1); 1180 mdelay(1);
1272 stat = hwif->tp_ops->read_status(hwif); 1181 stat = hwif->tp_ops->read_status(hwif);
1273 if ((stat & BUSY_STAT) == 0) 1182 if ((stat & ATA_BUSY) == 0)
1274 return 0; 1183 return 0;
1275 /* 1184 /*
1276 * Assume a value of 0xff means nothing is connected to 1185 * 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..ed426dd0fdd8 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;
@@ -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-probe.c b/drivers/ide/ide-probe.c
index 994e41099b42..06575a12b635 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,10 +114,10 @@ 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
@@ -135,27 +130,28 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
135 ide_fix_driveid(id); 130 ide_fix_driveid(id);
136 131
137 /* 132 /*
138 * WIN_IDENTIFY returns little-endian info, 133 * ATA_CMD_ID_ATA returns little-endian info,
139 * WIN_PIDENTIFY *usually* returns little-endian info. 134 * ATA_CMD_ID_ATAPI *usually* returns little-endian info.
140 */ 135 */
141 if (cmd == WIN_PIDENTIFY) { 136 if (cmd == ATA_CMD_ID_ATAPI) {
142 if ((id->model[0] == 'N' && id->model[1] == 'E') /* NEC */ 137 if ((m[0] == 'N' && m[1] == 'E') || /* NEC */
143 || (id->model[0] == 'F' && id->model[1] == 'X') /* Mitsumi */ 138 (m[0] == 'F' && m[1] == 'X') || /* Mitsumi */
144 || (id->model[0] == 'P' && id->model[1] == 'i'))/* Pioneer */ 139 (m[0] == 'P' && m[1] == 'i')) /* Pioneer */
145 /* Vertos drives may still be weird */ 140 /* Vertos drives may still be weird */
146 bswap ^= 1; 141 bswap ^= 1;
147 } 142 }
148 ide_fixstring(id->model, sizeof(id->model), bswap); 143
149 ide_fixstring(id->fw_rev, sizeof(id->fw_rev), bswap); 144 ide_fixstring(m, ATA_ID_PROD_LEN, bswap);
150 ide_fixstring(id->serial_no, sizeof(id->serial_no), bswap); 145 ide_fixstring((char *)&id[ATA_ID_FW_REV], ATA_ID_FW_REV_LEN, bswap);
146 ide_fixstring((char *)&id[ATA_ID_SERNO], ATA_ID_SERNO_LEN, bswap);
151 147
152 /* we depend on this a lot! */ 148 /* we depend on this a lot! */
153 id->model[sizeof(id->model)-1] = '\0'; 149 m[ATA_ID_PROD_LEN - 1] = '\0';
154 150
155 if (strstr(id->model, "E X A B Y T E N E S T")) 151 if (strstr(m, "E X A B Y T E N E S T"))
156 goto err_misc; 152 goto err_misc;
157 153
158 printk(KERN_INFO "%s: %s, ", drive->name, id->model); 154 printk(KERN_INFO "%s: %s, ", drive->name, m);
159 155
160 drive->present = 1; 156 drive->present = 1;
161 drive->dead = 0; 157 drive->dead = 0;
@@ -163,16 +159,16 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
163 /* 159 /*
164 * Check for an ATAPI device 160 * Check for an ATAPI device
165 */ 161 */
166 if (cmd == WIN_PIDENTIFY) { 162 if (cmd == ATA_CMD_ID_ATAPI) {
167 u8 type = (id->config >> 8) & 0x1f; 163 u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f;
168 164
169 printk(KERN_CONT "ATAPI "); 165 printk(KERN_CONT "ATAPI ");
170 switch (type) { 166 switch (type) {
171 case ide_floppy: 167 case ide_floppy:
172 if (!strstr(id->model, "CD-ROM")) { 168 if (!strstr(m, "CD-ROM")) {
173 if (!strstr(id->model, "oppy") && 169 if (!strstr(m, "oppy") &&
174 !strstr(id->model, "poyp") && 170 !strstr(m, "poyp") &&
175 !strstr(id->model, "ZIP")) 171 !strstr(m, "ZIP"))
176 printk(KERN_CONT "cdrom or floppy?, assuming "); 172 printk(KERN_CONT "cdrom or floppy?, assuming ");
177 if (drive->media != ide_cdrom) { 173 if (drive->media != ide_cdrom) {
178 printk(KERN_CONT "FLOPPY"); 174 printk(KERN_CONT "FLOPPY");
@@ -186,8 +182,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
186 drive->removable = 1; 182 drive->removable = 1;
187#ifdef CONFIG_PPC 183#ifdef CONFIG_PPC
188 /* kludge for Apple PowerBook internal zip */ 184 /* kludge for Apple PowerBook internal zip */
189 if (!strstr(id->model, "CD-ROM") && 185 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
190 strstr(id->model, "ZIP")) {
191 printk(KERN_CONT "FLOPPY"); 186 printk(KERN_CONT "FLOPPY");
192 type = ide_floppy; 187 type = ide_floppy;
193 break; 188 break;
@@ -217,18 +212,15 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
217 * Not an ATAPI device: looks like a "regular" hard disk 212 * Not an ATAPI device: looks like a "regular" hard disk
218 */ 213 */
219 214
220 /* 215 is_cfa = ata_id_is_cfa(id);
221 * 0x848a = CompactFlash device
222 * These are *not* removable in Linux definition of the term
223 */
224 216
225 if ((id->config != 0x848a) && (id->config & (1<<7))) 217 /* CF devices are *not* removable in Linux definition of the term */
218 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
226 drive->removable = 1; 219 drive->removable = 1;
227 220
228 drive->media = ide_disk; 221 drive->media = ide_disk;
229 222
230 printk(KERN_CONT "%s DISK drive\n", 223 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
231 (id->config == 0x848a) ? "CFA" : "ATA");
232 224
233 return; 225 return;
234 226
@@ -268,7 +260,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
268 if (io_ports->ctl_addr) { 260 if (io_ports->ctl_addr) {
269 a = tp_ops->read_altstatus(hwif); 261 a = tp_ops->read_altstatus(hwif);
270 s = tp_ops->read_status(hwif); 262 s = tp_ops->read_status(hwif);
271 if ((a ^ s) & ~INDEX_STAT) 263 if ((a ^ s) & ~ATA_IDX)
272 /* ancient Seagate drives, broken interfaces */ 264 /* ancient Seagate drives, broken interfaces */
273 printk(KERN_INFO "%s: probing with STATUS(0x%02x) " 265 printk(KERN_INFO "%s: probing with STATUS(0x%02x) "
274 "instead of ALTSTATUS(0x%02x)\n", 266 "instead of ALTSTATUS(0x%02x)\n",
@@ -281,7 +273,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
281 /* set features register for atapi 273 /* set features register for atapi
282 * identify command to be sure of reply 274 * identify command to be sure of reply
283 */ 275 */
284 if (cmd == WIN_PIDENTIFY) { 276 if (cmd == ATA_CMD_ID_ATAPI) {
285 ide_task_t task; 277 ide_task_t task;
286 278
287 memset(&task, 0, sizeof(task)); 279 memset(&task, 0, sizeof(task));
@@ -294,24 +286,16 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
294 /* ask drive for ID */ 286 /* ask drive for ID */
295 tp_ops->exec_command(hwif, cmd); 287 tp_ops->exec_command(hwif, cmd);
296 288
297 timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; 289 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 290
310 /* wait for IRQ and DRQ_STAT */ 291 if (ide_busy_sleep(hwif, timeout, use_altstatus))
292 return 1;
293
294 /* wait for IRQ and ATA_DRQ */
311 msleep(50); 295 msleep(50);
312 s = tp_ops->read_status(hwif); 296 s = tp_ops->read_status(hwif);
313 297
314 if (OK_STAT(s, DRQ_STAT, BAD_R_STAT)) { 298 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
315 unsigned long flags; 299 unsigned long flags;
316 300
317 /* local CPU only; some systems need this */ 301 /* local CPU only; some systems need this */
@@ -387,19 +371,21 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
387 return retval; 371 return retval;
388} 372}
389 373
390static int ide_busy_sleep(ide_hwif_t *hwif) 374int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
391{ 375{
392 unsigned long timeout = jiffies + WAIT_WORSTCASE;
393 u8 stat; 376 u8 stat;
394 377
378 timeout += jiffies;
379
395 do { 380 do {
396 msleep(50); 381 msleep(50); /* give drive a breather */
397 stat = hwif->tp_ops->read_status(hwif); 382 stat = altstatus ? hwif->tp_ops->read_altstatus(hwif)
398 if ((stat & BUSY_STAT) == 0) 383 : hwif->tp_ops->read_status(hwif);
384 if ((stat & ATA_BUSY) == 0)
399 return 0; 385 return 0;
400 } while (time_before(jiffies, timeout)); 386 } while (time_before(jiffies, timeout));
401 387
402 return 1; 388 return 1; /* drive timed-out */
403} 389}
404 390
405static u8 ide_read_device(ide_drive_t *drive) 391static u8 ide_read_device(ide_drive_t *drive)
@@ -444,13 +430,13 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
444 430
445 if (drive->present) { 431 if (drive->present) {
446 /* avoid waiting for inappropriate probes */ 432 /* avoid waiting for inappropriate probes */
447 if ((drive->media != ide_disk) && (cmd == WIN_IDENTIFY)) 433 if (drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
448 return 4; 434 return 4;
449 } 435 }
450#ifdef DEBUG 436#ifdef DEBUG
451 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n", 437 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
452 drive->name, drive->present, drive->media, 438 drive->name, drive->present, drive->media,
453 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI"); 439 (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI");
454#endif 440#endif
455 441
456 /* needed for some systems 442 /* needed for some systems
@@ -464,7 +450,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
464 if (drive->select.b.unit != 0) { 450 if (drive->select.b.unit != 0) {
465 /* exit with drive0 selected */ 451 /* exit with drive0 selected */
466 SELECT_DRIVE(&hwif->drives[0]); 452 SELECT_DRIVE(&hwif->drives[0]);
467 /* allow BUSY_STAT to assert & clear */ 453 /* allow ATA_BUSY to assert & clear */
468 msleep(50); 454 msleep(50);
469 } 455 }
470 /* no i/f present: mmm.. this should be a 4 -ml */ 456 /* no i/f present: mmm.. this should be a 4 -ml */
@@ -473,8 +459,8 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
473 459
474 stat = tp_ops->read_status(hwif); 460 stat = tp_ops->read_status(hwif);
475 461
476 if (OK_STAT(stat, READY_STAT, BUSY_STAT) || 462 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
477 drive->present || cmd == WIN_PIDENTIFY) { 463 drive->present || cmd == ATA_CMD_ID_ATAPI) {
478 /* send cmd and wait */ 464 /* send cmd and wait */
479 if ((rc = try_to_identify(drive, cmd))) { 465 if ((rc = try_to_identify(drive, cmd))) {
480 /* failed: try again */ 466 /* failed: try again */
@@ -483,17 +469,17 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
483 469
484 stat = tp_ops->read_status(hwif); 470 stat = tp_ops->read_status(hwif);
485 471
486 if (stat == (BUSY_STAT | READY_STAT)) 472 if (stat == (ATA_BUSY | ATA_DRDY))
487 return 4; 473 return 4;
488 474
489 if (rc == 1 && cmd == WIN_PIDENTIFY) { 475 if (rc == 1 && cmd == ATA_CMD_ID_ATAPI) {
490 printk(KERN_ERR "%s: no response (status = 0x%02x), " 476 printk(KERN_ERR "%s: no response (status = 0x%02x), "
491 "resetting drive\n", drive->name, stat); 477 "resetting drive\n", drive->name, stat);
492 msleep(50); 478 msleep(50);
493 SELECT_DRIVE(drive); 479 SELECT_DRIVE(drive);
494 msleep(50); 480 msleep(50);
495 tp_ops->exec_command(hwif, WIN_SRST); 481 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
496 (void)ide_busy_sleep(hwif); 482 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0);
497 rc = try_to_identify(drive, cmd); 483 rc = try_to_identify(drive, cmd);
498 } 484 }
499 485
@@ -526,13 +512,14 @@ static void enable_nest (ide_drive_t *drive)
526 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 512 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
527 u8 stat; 513 u8 stat;
528 514
529 printk(KERN_INFO "%s: enabling %s -- ", hwif->name, drive->id->model); 515 printk(KERN_INFO "%s: enabling %s -- ",
516 hwif->name, (char *)&drive->id[ATA_ID_PROD]);
530 517
531 SELECT_DRIVE(drive); 518 SELECT_DRIVE(drive);
532 msleep(50); 519 msleep(50);
533 tp_ops->exec_command(hwif, EXABYTE_ENABLE_NEST); 520 tp_ops->exec_command(hwif, ATA_EXABYTE_ENABLE_NEST);
534 521
535 if (ide_busy_sleep(hwif)) { 522 if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 0)) {
536 printk(KERN_CONT "failed (timeout)\n"); 523 printk(KERN_CONT "failed (timeout)\n");
537 return; 524 return;
538 } 525 }
@@ -545,12 +532,6 @@ static void enable_nest (ide_drive_t *drive)
545 printk(KERN_CONT "failed (status = 0x%02x)\n", stat); 532 printk(KERN_CONT "failed (status = 0x%02x)\n", stat);
546 else 533 else
547 printk(KERN_CONT "success\n"); 534 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} 535}
555 536
556/** 537/**
@@ -567,6 +548,8 @@ static void enable_nest (ide_drive_t *drive)
567 548
568static inline u8 probe_for_drive (ide_drive_t *drive) 549static inline u8 probe_for_drive (ide_drive_t *drive)
569{ 550{
551 char *m;
552
570 /* 553 /*
571 * In order to keep things simple we have an id 554 * In order to keep things simple we have an id
572 * block for all drives at all times. If the device 555 * block for all drives at all times. If the device
@@ -576,29 +559,34 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
576 * Also note that 0 everywhere means "can't do X" 559 * Also note that 0 everywhere means "can't do X"
577 */ 560 */
578 561
579 drive->id = kzalloc(SECTOR_WORDS *4, GFP_KERNEL); 562 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL);
580 drive->id_read = 0; 563 drive->id_read = 0;
581 if(drive->id == NULL) 564 if(drive->id == NULL)
582 { 565 {
583 printk(KERN_ERR "ide: out of memory for id data.\n"); 566 printk(KERN_ERR "ide: out of memory for id data.\n");
584 return 0; 567 return 0;
585 } 568 }
586 strcpy(drive->id->model, "UNKNOWN"); 569
587 570 m = (char *)&drive->id[ATA_ID_PROD];
571 strcpy(m, "UNKNOWN");
572
588 /* skip probing? */ 573 /* skip probing? */
589 if (!drive->noprobe) 574 if (!drive->noprobe) {
590 { 575retry:
591 /* if !(success||timed-out) */ 576 /* if !(success||timed-out) */
592 if (do_probe(drive, WIN_IDENTIFY) >= 2) { 577 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2)
593 /* look for ATAPI device */ 578 /* look for ATAPI device */
594 (void) do_probe(drive, WIN_PIDENTIFY); 579 (void)do_probe(drive, ATA_CMD_ID_ATAPI);
595 } 580
596 if (!drive->present) 581 if (!drive->present)
597 /* drive not found */ 582 /* drive not found */
598 return 0; 583 return 0;
599 if (strstr(drive->id->model, "E X A B Y T E N E S T")) 584
585 if (strstr(m, "E X A B Y T E N E S T")) {
600 enable_nest(drive); 586 enable_nest(drive);
601 587 goto retry;
588 }
589
602 /* identification failed? */ 590 /* identification failed? */
603 if (!drive->id_read) { 591 if (!drive->id_read) {
604 if (drive->media == ide_disk) { 592 if (drive->media == ide_disk) {
@@ -740,36 +728,38 @@ out:
740 728
741/** 729/**
742 * ide_undecoded_slave - look for bad CF adapters 730 * ide_undecoded_slave - look for bad CF adapters
743 * @drive1: drive 731 * @dev1: slave device
744 * 732 *
745 * Analyse the drives on the interface and attempt to decide if we 733 * 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 734 * have the same drive viewed twice. This occurs with crap CF adapters
747 * and PCMCIA sometimes. 735 * and PCMCIA sometimes.
748 */ 736 */
749 737
750void ide_undecoded_slave(ide_drive_t *drive1) 738void ide_undecoded_slave(ide_drive_t *dev1)
751{ 739{
752 ide_drive_t *drive0 = &drive1->hwif->drives[0]; 740 ide_drive_t *dev0 = &dev1->hwif->drives[0];
753 741
754 if ((drive1->dn & 1) == 0 || drive0->present == 0) 742 if ((dev1->dn & 1) == 0 || dev0->present == 0)
755 return; 743 return;
756 744
757 /* If the models don't match they are not the same product */ 745 /* If the models don't match they are not the same product */
758 if (strcmp(drive0->id->model, drive1->id->model)) 746 if (strcmp((char *)&dev0->id[ATA_ID_PROD],
747 (char *)&dev1->id[ATA_ID_PROD]))
759 return; 748 return;
760 749
761 /* Serial numbers do not match */ 750 /* Serial numbers do not match */
762 if (strncmp(drive0->id->serial_no, drive1->id->serial_no, 20)) 751 if (strncmp((char *)&dev0->id[ATA_ID_SERNO],
752 (char *)&dev1->id[ATA_ID_SERNO], ATA_ID_SERNO_LEN))
763 return; 753 return;
764 754
765 /* No serial number, thankfully very rare for CF */ 755 /* No serial number, thankfully very rare for CF */
766 if (drive0->id->serial_no[0] == 0) 756 if (*(char *)&dev0->id[ATA_ID_SERNO] == 0)
767 return; 757 return;
768 758
769 /* Appears to be an IDE flash adapter with decode bugs */ 759 /* Appears to be an IDE flash adapter with decode bugs */
770 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n"); 760 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
771 761
772 drive1->present = 0; 762 dev1->present = 0;
773} 763}
774 764
775EXPORT_SYMBOL_GPL(ide_undecoded_slave); 765EXPORT_SYMBOL_GPL(ide_undecoded_slave);
@@ -853,7 +843,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
853 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) 843 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
854 drive->no_io_32bit = 1; 844 drive->no_io_32bit = 1;
855 else 845 else
856 drive->no_io_32bit = drive->id->dword_io ? 1 : 0; 846 drive->no_io_32bit = drive->id[ATA_ID_DWORD_IO] ? 1 : 0;
857 } 847 }
858} 848}
859 849
@@ -1037,11 +1027,6 @@ static int init_irq (ide_hwif_t *hwif)
1037 ide_hwgroup_t *hwgroup; 1027 ide_hwgroup_t *hwgroup;
1038 ide_hwif_t *match = NULL; 1028 ide_hwif_t *match = NULL;
1039 1029
1040
1041 BUG_ON(in_interrupt());
1042 BUG_ON(irqs_disabled());
1043 BUG_ON(hwif == NULL);
1044
1045 mutex_lock(&ide_cfg_mtx); 1030 mutex_lock(&ide_cfg_mtx);
1046 hwif->hwgroup = NULL; 1031 hwif->hwgroup = NULL;
1047#if MAX_HWIFS > 1 1032#if MAX_HWIFS > 1
@@ -1116,7 +1101,8 @@ static int init_irq (ide_hwif_t *hwif)
1116 sa = IRQF_SHARED; 1101 sa = IRQF_SHARED;
1117#endif /* __mc68000__ */ 1102#endif /* __mc68000__ */
1118 1103
1119 if (IDE_CHIPSET_IS_PCI(hwif->chipset)) 1104 if (hwif->chipset == ide_pci || hwif->chipset == ide_cmd646 ||
1105 hwif->chipset == ide_ali14xx)
1120 sa = IRQF_SHARED; 1106 sa = IRQF_SHARED;
1121 1107
1122 if (io_ports->ctl_addr) 1108 if (io_ports->ctl_addr)
@@ -1188,7 +1174,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
1188{ 1174{
1189 struct gendisk *p = data; 1175 struct gendisk *p = data;
1190 *part &= (1 << PARTN_BITS) - 1; 1176 *part &= (1 << PARTN_BITS) - 1;
1191 return &p->dev.kobj; 1177 return &disk_to_dev(p)->kobj;
1192} 1178}
1193 1179
1194static int exact_lock(dev_t dev, void *data) 1180static int exact_lock(dev_t dev, void *data)
@@ -1344,8 +1330,6 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1344 if (!drive->present) 1330 if (!drive->present)
1345 continue; 1331 continue;
1346 1332
1347 ide_add_generic_settings(drive);
1348
1349 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i); 1333 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
1350 dev->parent = &hwif->gendev; 1334 dev->parent = &hwif->gendev;
1351 dev->bus = &ide_bus_type; 1335 dev->bus = &ide_bus_type;
@@ -1492,7 +1476,7 @@ static struct device_attribute *ide_port_attrs[] = {
1492 1476
1493static int ide_sysfs_register_port(ide_hwif_t *hwif) 1477static int ide_sysfs_register_port(ide_hwif_t *hwif)
1494{ 1478{
1495 int i, rc; 1479 int i, uninitialized_var(rc);
1496 1480
1497 for (i = 0; ide_port_attrs[i]; i++) { 1481 for (i = 0; ide_port_attrs[i]; i++) {
1498 rc = device_create_file(hwif->portdev, ide_port_attrs[i]); 1482 rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
@@ -1602,8 +1586,10 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1602 if (hws[0]) 1586 if (hws[0])
1603 host->dev[0] = hws[0]->dev; 1587 host->dev[0] = hws[0]->dev;
1604 1588
1605 if (d) 1589 if (d) {
1590 host->init_chipset = d->init_chipset;
1606 host->host_flags = d->host_flags; 1591 host->host_flags = d->host_flags;
1592 }
1607 1593
1608 return host; 1594 return host;
1609} 1595}
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index f66c9c3f6fc6..e7030a491463 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -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_field(nice1, 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,6 +566,10 @@ 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{
569 mutex_lock(&ide_setting_mtx);
570 drive->settings = driver->settings;
571 mutex_unlock(&ide_setting_mtx);
572
693 ide_add_proc_entries(drive->proc, driver->proc, drive); 573 ide_add_proc_entries(drive->proc, driver->proc, drive);
694} 574}
695 575
@@ -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}
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 82c2afe4d28a..f8c84df4a0bc 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,13 +172,6 @@ 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. 175 * pc points to the current processed packet command.
217 * 176 *
218 * failed_pc points to the last failed packet command, or contains 177 * failed_pc points to the last failed packet command, or contains
@@ -224,13 +183,11 @@ typedef struct ide_tape_obj {
224 struct ide_atapi_pc *pc; 183 struct ide_atapi_pc *pc;
225 /* Last failed packet command */ 184 /* Last failed packet command */
226 struct ide_atapi_pc *failed_pc; 185 struct ide_atapi_pc *failed_pc;
227 /* Packet command stack */ 186 /* used by REQ_IDETAPE_{READ,WRITE} requests */
228 struct ide_atapi_pc pc_stack[IDETAPE_PC_STACK]; 187 struct ide_atapi_pc queued_pc;
229 /* Next free packet command storage space */ 188
230 int pc_stack_index; 189 struct ide_atapi_pc request_sense_pc;
231 struct request rq_stack[IDETAPE_PC_STACK]; 190 struct request request_sense_rq;
232 /* We implement a circular array */
233 int rq_stack_index;
234 191
235 /* 192 /*
236 * DSC polling variables. 193 * DSC polling variables.
@@ -331,11 +288,10 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
331 mutex_lock(&idetape_ref_mutex); 288 mutex_lock(&idetape_ref_mutex);
332 tape = ide_tape_g(disk); 289 tape = ide_tape_g(disk);
333 if (tape) { 290 if (tape) {
334 kref_get(&tape->kref); 291 if (ide_device_get(tape->drive))
335 if (ide_device_get(tape->drive)) {
336 kref_put(&tape->kref, ide_tape_release);
337 tape = NULL; 292 tape = NULL;
338 } 293 else
294 kref_get(&tape->kref);
339 } 295 }
340 mutex_unlock(&idetape_ref_mutex); 296 mutex_unlock(&idetape_ref_mutex);
341 return tape; 297 return tape;
@@ -343,9 +299,11 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
343 299
344static void ide_tape_put(struct ide_tape_obj *tape) 300static void ide_tape_put(struct ide_tape_obj *tape)
345{ 301{
302 ide_drive_t *drive = tape->drive;
303
346 mutex_lock(&idetape_ref_mutex); 304 mutex_lock(&idetape_ref_mutex);
347 ide_device_put(tape->drive);
348 kref_put(&tape->kref, ide_tape_release); 305 kref_put(&tape->kref, ide_tape_release);
306 ide_device_put(drive);
349 mutex_unlock(&idetape_ref_mutex); 307 mutex_unlock(&idetape_ref_mutex);
350} 308}
351 309
@@ -450,47 +408,6 @@ static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
450} 408}
451 409
452/* 410/*
453 * idetape_next_pc_storage returns a pointer to a place in which we can
454 * safely store a packet command, even though we intend to leave the
455 * driver. A storage space for a maximum of IDETAPE_PC_STACK packet
456 * commands is allocated at initialization time.
457 */
458static struct ide_atapi_pc *idetape_next_pc_storage(ide_drive_t *drive)
459{
460 idetape_tape_t *tape = drive->driver_data;
461
462 debug_log(DBG_PCRQ_STACK, "pc_stack_index=%d\n", tape->pc_stack_index);
463
464 if (tape->pc_stack_index == IDETAPE_PC_STACK)
465 tape->pc_stack_index = 0;
466 return (&tape->pc_stack[tape->pc_stack_index++]);
467}
468
469/*
470 * idetape_next_rq_storage is used along with idetape_next_pc_storage.
471 * Since we queue packet commands in the request queue, we need to
472 * allocate a request, along with the allocation of a packet command.
473 */
474
475/**************************************************************
476 * *
477 * This should get fixed to use kmalloc(.., GFP_ATOMIC) *
478 * followed later on by kfree(). -ml *
479 * *
480 **************************************************************/
481
482static struct request *idetape_next_rq_storage(ide_drive_t *drive)
483{
484 idetape_tape_t *tape = drive->driver_data;
485
486 debug_log(DBG_PCRQ_STACK, "rq_stack_index=%d\n", tape->rq_stack_index);
487
488 if (tape->rq_stack_index == IDETAPE_PC_STACK)
489 tape->rq_stack_index = 0;
490 return (&tape->rq_stack[tape->rq_stack_index++]);
491}
492
493/*
494 * called on each failed packet command retry to analyze the request sense. We 411 * called on each failed packet command retry to analyze the request sense. We
495 * currently do not utilize this information. 412 * currently do not utilize this information.
496 */ 413 */
@@ -666,61 +583,14 @@ static void ide_tape_callback(ide_drive_t *drive)
666 idetape_end_request(drive, uptodate, 0); 583 idetape_end_request(drive, uptodate, 0);
667} 584}
668 585
669static void idetape_init_pc(struct ide_atapi_pc *pc)
670{
671 memset(pc->c, 0, 12);
672 pc->retries = 0;
673 pc->flags = 0;
674 pc->req_xfer = 0;
675 pc->buf = pc->pc_buf;
676 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
677 pc->bh = NULL;
678 pc->b_data = NULL;
679}
680
681static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc) 586static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
682{ 587{
683 idetape_init_pc(pc); 588 ide_init_pc(pc);
684 pc->c[0] = REQUEST_SENSE; 589 pc->c[0] = REQUEST_SENSE;
685 pc->c[4] = 20; 590 pc->c[4] = 20;
686 pc->req_xfer = 20; 591 pc->req_xfer = 20;
687} 592}
688 593
689static void idetape_init_rq(struct request *rq, u8 cmd)
690{
691 blk_rq_init(NULL, rq);
692 rq->cmd_type = REQ_TYPE_SPECIAL;
693 rq->cmd[13] = cmd;
694}
695
696/*
697 * Generate a new packet command request in front of the request queue, before
698 * the current request, so that it will be processed immediately, on the next
699 * pass through the driver. The function below is called from the request
700 * handling part of the driver (the "bottom" part). Safe storage for the request
701 * should be allocated with ide_tape_next_{pc,rq}_storage() prior to that.
702 *
703 * Memory for those requests is pre-allocated at initialization time, and is
704 * limited to IDETAPE_PC_STACK requests. We assume that we have enough space for
705 * the maximum possible number of inter-dependent packet commands.
706 *
707 * The higher level of the driver - The ioctl handler and the character device
708 * handling functions should queue request to the lower level part and wait for
709 * their completion using idetape_queue_pc_tail or idetape_queue_rw_tail.
710 */
711static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
712 struct request *rq)
713{
714 struct ide_tape_obj *tape = drive->driver_data;
715
716 idetape_init_rq(rq, REQ_IDETAPE_PC1);
717 rq->cmd_flags |= REQ_PREEMPT;
718 rq->buffer = (char *) pc;
719 rq->rq_disk = tape->disk;
720 memcpy(rq->cmd, pc->c, 12);
721 ide_do_drive_cmd(drive, rq);
722}
723
724/* 594/*
725 * idetape_retry_pc is called when an error was detected during the 595 * idetape_retry_pc is called when an error was detected during the
726 * last packet command. We queue a request sense packet command in 596 * last packet command. We queue a request sense packet command in
@@ -728,15 +598,14 @@ static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
728 */ 598 */
729static void idetape_retry_pc(ide_drive_t *drive) 599static void idetape_retry_pc(ide_drive_t *drive)
730{ 600{
731 struct ide_atapi_pc *pc; 601 struct ide_tape_obj *tape = drive->driver_data;
732 struct request *rq; 602 struct request *rq = &tape->request_sense_rq;
603 struct ide_atapi_pc *pc = &tape->request_sense_pc;
733 604
734 (void)ide_read_error(drive); 605 (void)ide_read_error(drive);
735 pc = idetape_next_pc_storage(drive);
736 rq = idetape_next_rq_storage(drive);
737 idetape_create_request_sense_cmd(pc); 606 idetape_create_request_sense_cmd(pc);
738 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 607 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
739 idetape_queue_pc_head(drive, pc, rq); 608 ide_queue_pc_head(drive, tape->disk, pc, rq);
740} 609}
741 610
742/* 611/*
@@ -765,13 +634,15 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
765 idetape_postpone_request(drive); 634 idetape_postpone_request(drive);
766} 635}
767 636
768static void ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, 637static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
769 unsigned int bcount, int write) 638 unsigned int bcount, int write)
770{ 639{
771 if (write) 640 if (write)
772 idetape_output_buffers(drive, pc, bcount); 641 idetape_output_buffers(drive, pc, bcount);
773 else 642 else
774 idetape_input_buffers(drive, pc, bcount); 643 idetape_input_buffers(drive, pc, bcount);
644
645 return bcount;
775} 646}
776 647
777/* 648/*
@@ -785,7 +656,7 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
785{ 656{
786 idetape_tape_t *tape = drive->driver_data; 657 idetape_tape_t *tape = drive->driver_data;
787 658
788 return ide_pc_intr(drive, tape->pc, idetape_pc_intr, IDETAPE_WAIT_CMD, 659 return ide_pc_intr(drive, tape->pc, idetape_pc_intr, WAIT_TAPE_CMD,
789 NULL, idetape_update_buffers, idetape_retry_pc, 660 NULL, idetape_update_buffers, idetape_retry_pc,
790 ide_tape_handle_dsc, ide_tape_io_buffers); 661 ide_tape_handle_dsc, ide_tape_io_buffers);
791} 662}
@@ -831,7 +702,7 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
831 idetape_tape_t *tape = drive->driver_data; 702 idetape_tape_t *tape = drive->driver_data;
832 703
833 return ide_transfer_pc(drive, tape->pc, idetape_pc_intr, 704 return ide_transfer_pc(drive, tape->pc, idetape_pc_intr,
834 IDETAPE_WAIT_CMD, NULL); 705 WAIT_TAPE_CMD, NULL);
835} 706}
836 707
837static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, 708static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
@@ -880,13 +751,13 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
880 pc->retries++; 751 pc->retries++;
881 752
882 return ide_issue_pc(drive, pc, idetape_transfer_pc, 753 return ide_issue_pc(drive, pc, idetape_transfer_pc,
883 IDETAPE_WAIT_CMD, NULL); 754 WAIT_TAPE_CMD, NULL);
884} 755}
885 756
886/* A mode sense command is used to "sense" tape parameters. */ 757/* A mode sense command is used to "sense" tape parameters. */
887static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) 758static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
888{ 759{
889 idetape_init_pc(pc); 760 ide_init_pc(pc);
890 pc->c[0] = MODE_SENSE; 761 pc->c[0] = MODE_SENSE;
891 if (page_code != IDETAPE_BLOCK_DESCRIPTOR) 762 if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
892 /* DBD = 1 - Don't return block descriptors */ 763 /* DBD = 1 - Don't return block descriptors */
@@ -919,8 +790,8 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
919 790
920 stat = hwif->tp_ops->read_status(hwif); 791 stat = hwif->tp_ops->read_status(hwif);
921 792
922 if (stat & SEEK_STAT) { 793 if (stat & ATA_DSC) {
923 if (stat & ERR_STAT) { 794 if (stat & ATA_ERR) {
924 /* Error detected */ 795 /* Error detected */
925 if (pc->c[0] != TEST_UNIT_READY) 796 if (pc->c[0] != TEST_UNIT_READY)
926 printk(KERN_ERR "ide-tape: %s: I/O error, ", 797 printk(KERN_ERR "ide-tape: %s: I/O error, ",
@@ -945,7 +816,7 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
945 struct idetape_bh *bh = (struct idetape_bh *)rq->special; 816 struct idetape_bh *bh = (struct idetape_bh *)rq->special;
946 unsigned int length = rq->current_nr_sectors; 817 unsigned int length = rq->current_nr_sectors;
947 818
948 idetape_init_pc(pc); 819 ide_init_pc(pc);
949 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 820 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
950 pc->c[1] = 1; 821 pc->c[1] = 1;
951 pc->bh = bh; 822 pc->bh = bh;
@@ -977,9 +848,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
977 struct request *postponed_rq = tape->postponed_rq; 848 struct request *postponed_rq = tape->postponed_rq;
978 u8 stat; 849 u8 stat;
979 850
980 debug_log(DBG_SENSE, "sector: %ld, nr_sectors: %ld," 851 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu,"
981 " current_nr_sectors: %d\n", 852 " current_nr_sectors: %u\n",
982 rq->sector, rq->nr_sectors, rq->current_nr_sectors); 853 (unsigned long long)rq->sector, rq->nr_sectors,
854 rq->current_nr_sectors);
983 855
984 if (!blk_special_request(rq)) { 856 if (!blk_special_request(rq)) {
985 /* We do not support buffer cache originated requests. */ 857 /* We do not support buffer cache originated requests. */
@@ -1020,7 +892,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1020 } 892 }
1021 893
1022 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) && 894 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
1023 (stat & SEEK_STAT) == 0) { 895 (stat & ATA_DSC) == 0) {
1024 if (postponed_rq == NULL) { 896 if (postponed_rq == NULL) {
1025 tape->dsc_polling_start = jiffies; 897 tape->dsc_polling_start = jiffies;
1026 tape->dsc_poll_freq = tape->best_dsc_rw_freq; 898 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
@@ -1042,12 +914,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1042 return ide_stopped; 914 return ide_stopped;
1043 } 915 }
1044 if (rq->cmd[13] & REQ_IDETAPE_READ) { 916 if (rq->cmd[13] & REQ_IDETAPE_READ) {
1045 pc = idetape_next_pc_storage(drive); 917 pc = &tape->queued_pc;
1046 ide_tape_create_rw_cmd(tape, pc, rq, READ_6); 918 ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
1047 goto out; 919 goto out;
1048 } 920 }
1049 if (rq->cmd[13] & REQ_IDETAPE_WRITE) { 921 if (rq->cmd[13] & REQ_IDETAPE_WRITE) {
1050 pc = idetape_next_pc_storage(drive); 922 pc = &tape->queued_pc;
1051 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6); 923 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
1052 goto out; 924 goto out;
1053 } 925 }
@@ -1234,77 +1106,30 @@ static void idetape_init_merge_buffer(idetape_tape_t *tape)
1234static void idetape_create_write_filemark_cmd(ide_drive_t *drive, 1106static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1235 struct ide_atapi_pc *pc, int write_filemark) 1107 struct ide_atapi_pc *pc, int write_filemark)
1236{ 1108{
1237 idetape_init_pc(pc); 1109 ide_init_pc(pc);
1238 pc->c[0] = WRITE_FILEMARKS; 1110 pc->c[0] = WRITE_FILEMARKS;
1239 pc->c[4] = write_filemark; 1111 pc->c[4] = write_filemark;
1240 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1112 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1241} 1113}
1242 1114
1243static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
1244{
1245 idetape_init_pc(pc);
1246 pc->c[0] = TEST_UNIT_READY;
1247}
1248
1249/*
1250 * We add a special packet command request to the tail of the request queue, and
1251 * wait for it to be serviced. This is not to be called from within the request
1252 * handling part of the driver! We allocate here data on the stack and it is
1253 * valid until the request is finished. This is not the case for the bottom part
1254 * of the driver, where we are always leaving the functions to wait for an
1255 * interrupt or a timer event.
1256 *
1257 * From the bottom part of the driver, we should allocate safe memory using
1258 * idetape_next_pc_storage() and ide_tape_next_rq_storage(), and add the request
1259 * to the request list without waiting for it to be serviced! In that case, we
1260 * usually use idetape_queue_pc_head().
1261 */
1262static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
1263{
1264 struct ide_tape_obj *tape = drive->driver_data;
1265 struct request *rq;
1266 int error;
1267
1268 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1269 rq->cmd_type = REQ_TYPE_SPECIAL;
1270 rq->cmd[13] = REQ_IDETAPE_PC1;
1271 rq->buffer = (char *)pc;
1272 memcpy(rq->cmd, pc->c, 12);
1273 error = blk_execute_rq(drive->queue, tape->disk, rq, 0);
1274 blk_put_request(rq);
1275 return error;
1276}
1277
1278static void idetape_create_load_unload_cmd(ide_drive_t *drive,
1279 struct ide_atapi_pc *pc, int cmd)
1280{
1281 idetape_init_pc(pc);
1282 pc->c[0] = START_STOP;
1283 pc->c[4] = cmd;
1284 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1285}
1286
1287static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) 1115static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
1288{ 1116{
1289 idetape_tape_t *tape = drive->driver_data; 1117 idetape_tape_t *tape = drive->driver_data;
1290 struct ide_atapi_pc pc; 1118 struct gendisk *disk = tape->disk;
1291 int load_attempted = 0; 1119 int load_attempted = 0;
1292 1120
1293 /* Wait for the tape to become ready */ 1121 /* Wait for the tape to become ready */
1294 set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags); 1122 set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
1295 timeout += jiffies; 1123 timeout += jiffies;
1296 while (time_before(jiffies, timeout)) { 1124 while (time_before(jiffies, timeout)) {
1297 idetape_create_test_unit_ready_cmd(&pc); 1125 if (ide_do_test_unit_ready(drive, disk) == 0)
1298 if (!idetape_queue_pc_tail(drive, &pc))
1299 return 0; 1126 return 0;
1300 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) 1127 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
1301 || (tape->asc == 0x3A)) { 1128 || (tape->asc == 0x3A)) {
1302 /* no media */ 1129 /* no media */
1303 if (load_attempted) 1130 if (load_attempted)
1304 return -ENOMEDIUM; 1131 return -ENOMEDIUM;
1305 idetape_create_load_unload_cmd(drive, &pc, 1132 ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
1306 IDETAPE_LU_LOAD_MASK);
1307 idetape_queue_pc_tail(drive, &pc);
1308 load_attempted = 1; 1133 load_attempted = 1;
1309 /* not about to be ready */ 1134 /* not about to be ready */
1310 } else if (!(tape->sense_key == 2 && tape->asc == 4 && 1135 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
@@ -1317,11 +1142,12 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
1317 1142
1318static int idetape_flush_tape_buffers(ide_drive_t *drive) 1143static int idetape_flush_tape_buffers(ide_drive_t *drive)
1319{ 1144{
1145 struct ide_tape_obj *tape = drive->driver_data;
1320 struct ide_atapi_pc pc; 1146 struct ide_atapi_pc pc;
1321 int rc; 1147 int rc;
1322 1148
1323 idetape_create_write_filemark_cmd(drive, &pc, 0); 1149 idetape_create_write_filemark_cmd(drive, &pc, 0);
1324 rc = idetape_queue_pc_tail(drive, &pc); 1150 rc = ide_queue_pc_tail(drive, tape->disk, &pc);
1325 if (rc) 1151 if (rc)
1326 return rc; 1152 return rc;
1327 idetape_wait_ready(drive, 60 * 5 * HZ); 1153 idetape_wait_ready(drive, 60 * 5 * HZ);
@@ -1330,7 +1156,7 @@ static int idetape_flush_tape_buffers(ide_drive_t *drive)
1330 1156
1331static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc) 1157static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
1332{ 1158{
1333 idetape_init_pc(pc); 1159 ide_init_pc(pc);
1334 pc->c[0] = READ_POSITION; 1160 pc->c[0] = READ_POSITION;
1335 pc->req_xfer = 20; 1161 pc->req_xfer = 20;
1336} 1162}
@@ -1344,7 +1170,7 @@ static int idetape_read_position(ide_drive_t *drive)
1344 debug_log(DBG_PROCS, "Enter %s\n", __func__); 1170 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1345 1171
1346 idetape_create_read_position_cmd(&pc); 1172 idetape_create_read_position_cmd(&pc);
1347 if (idetape_queue_pc_tail(drive, &pc)) 1173 if (ide_queue_pc_tail(drive, tape->disk, &pc))
1348 return -1; 1174 return -1;
1349 position = tape->first_frame; 1175 position = tape->first_frame;
1350 return position; 1176 return position;
@@ -1354,7 +1180,7 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1354 struct ide_atapi_pc *pc, 1180 struct ide_atapi_pc *pc,
1355 unsigned int block, u8 partition, int skip) 1181 unsigned int block, u8 partition, int skip)
1356{ 1182{
1357 idetape_init_pc(pc); 1183 ide_init_pc(pc);
1358 pc->c[0] = POSITION_TO_ELEMENT; 1184 pc->c[0] = POSITION_TO_ELEMENT;
1359 pc->c[1] = 2; 1185 pc->c[1] = 2;
1360 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); 1186 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
@@ -1362,21 +1188,6 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1362 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1188 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1363} 1189}
1364 1190
1365static int idetape_create_prevent_cmd(ide_drive_t *drive,
1366 struct ide_atapi_pc *pc, int prevent)
1367{
1368 idetape_tape_t *tape = drive->driver_data;
1369
1370 /* device supports locking according to capabilities page */
1371 if (!(tape->caps[6] & 0x01))
1372 return 0;
1373
1374 idetape_init_pc(pc);
1375 pc->c[0] = ALLOW_MEDIUM_REMOVAL;
1376 pc->c[4] = prevent;
1377 return 1;
1378}
1379
1380static void __ide_tape_discard_merge_buffer(ide_drive_t *drive) 1191static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1381{ 1192{
1382 idetape_tape_t *tape = drive->driver_data; 1193 idetape_tape_t *tape = drive->driver_data;
@@ -1404,6 +1215,7 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
1404 u8 partition, int skip) 1215 u8 partition, int skip)
1405{ 1216{
1406 idetape_tape_t *tape = drive->driver_data; 1217 idetape_tape_t *tape = drive->driver_data;
1218 struct gendisk *disk = tape->disk;
1407 int retval; 1219 int retval;
1408 struct ide_atapi_pc pc; 1220 struct ide_atapi_pc pc;
1409 1221
@@ -1411,12 +1223,12 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
1411 __ide_tape_discard_merge_buffer(drive); 1223 __ide_tape_discard_merge_buffer(drive);
1412 idetape_wait_ready(drive, 60 * 5 * HZ); 1224 idetape_wait_ready(drive, 60 * 5 * HZ);
1413 idetape_create_locate_cmd(drive, &pc, block, partition, skip); 1225 idetape_create_locate_cmd(drive, &pc, block, partition, skip);
1414 retval = idetape_queue_pc_tail(drive, &pc); 1226 retval = ide_queue_pc_tail(drive, disk, &pc);
1415 if (retval) 1227 if (retval)
1416 return (retval); 1228 return (retval);
1417 1229
1418 idetape_create_read_position_cmd(&pc); 1230 idetape_create_read_position_cmd(&pc);
1419 return (idetape_queue_pc_tail(drive, &pc)); 1231 return ide_queue_pc_tail(drive, disk, &pc);
1420} 1232}
1421 1233
1422static void ide_tape_discard_merge_buffer(ide_drive_t *drive, 1234static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
@@ -1476,7 +1288,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1476 1288
1477static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) 1289static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1478{ 1290{
1479 idetape_init_pc(pc); 1291 ide_init_pc(pc);
1480 pc->c[0] = INQUIRY; 1292 pc->c[0] = INQUIRY;
1481 pc->c[4] = 254; 1293 pc->c[4] = 254;
1482 pc->req_xfer = 254; 1294 pc->req_xfer = 254;
@@ -1485,14 +1297,14 @@ static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1485static void idetape_create_rewind_cmd(ide_drive_t *drive, 1297static void idetape_create_rewind_cmd(ide_drive_t *drive,
1486 struct ide_atapi_pc *pc) 1298 struct ide_atapi_pc *pc)
1487{ 1299{
1488 idetape_init_pc(pc); 1300 ide_init_pc(pc);
1489 pc->c[0] = REZERO_UNIT; 1301 pc->c[0] = REZERO_UNIT;
1490 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1302 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1491} 1303}
1492 1304
1493static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) 1305static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1494{ 1306{
1495 idetape_init_pc(pc); 1307 ide_init_pc(pc);
1496 pc->c[0] = ERASE; 1308 pc->c[0] = ERASE;
1497 pc->c[1] = 1; 1309 pc->c[1] = 1;
1498 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1310 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
@@ -1500,7 +1312,7 @@ static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1500 1312
1501static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) 1313static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1502{ 1314{
1503 idetape_init_pc(pc); 1315 ide_init_pc(pc);
1504 pc->c[0] = SPACE; 1316 pc->c[0] = SPACE;
1505 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); 1317 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1506 pc->c[1] = cmd; 1318 pc->c[1] = cmd;
@@ -1663,20 +1475,20 @@ static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
1663 */ 1475 */
1664static int idetape_rewind_tape(ide_drive_t *drive) 1476static int idetape_rewind_tape(ide_drive_t *drive)
1665{ 1477{
1478 struct ide_tape_obj *tape = drive->driver_data;
1479 struct gendisk *disk = tape->disk;
1666 int retval; 1480 int retval;
1667 struct ide_atapi_pc pc; 1481 struct ide_atapi_pc pc;
1668 idetape_tape_t *tape;
1669 tape = drive->driver_data;
1670 1482
1671 debug_log(DBG_SENSE, "Enter %s\n", __func__); 1483 debug_log(DBG_SENSE, "Enter %s\n", __func__);
1672 1484
1673 idetape_create_rewind_cmd(drive, &pc); 1485 idetape_create_rewind_cmd(drive, &pc);
1674 retval = idetape_queue_pc_tail(drive, &pc); 1486 retval = ide_queue_pc_tail(drive, disk, &pc);
1675 if (retval) 1487 if (retval)
1676 return retval; 1488 return retval;
1677 1489
1678 idetape_create_read_position_cmd(&pc); 1490 idetape_create_read_position_cmd(&pc);
1679 retval = idetape_queue_pc_tail(drive, &pc); 1491 retval = ide_queue_pc_tail(drive, disk, &pc);
1680 if (retval) 1492 if (retval)
1681 return retval; 1493 return retval;
1682 return 0; 1494 return 0;
@@ -1719,6 +1531,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1719 int mt_count) 1531 int mt_count)
1720{ 1532{
1721 idetape_tape_t *tape = drive->driver_data; 1533 idetape_tape_t *tape = drive->driver_data;
1534 struct gendisk *disk = tape->disk;
1722 struct ide_atapi_pc pc; 1535 struct ide_atapi_pc pc;
1723 int retval, count = 0; 1536 int retval, count = 0;
1724 int sprev = !!(tape->caps[4] & 0x20); 1537 int sprev = !!(tape->caps[4] & 0x20);
@@ -1743,7 +1556,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1743 case MTBSF: 1556 case MTBSF:
1744 idetape_create_space_cmd(&pc, mt_count - count, 1557 idetape_create_space_cmd(&pc, mt_count - count,
1745 IDETAPE_SPACE_OVER_FILEMARK); 1558 IDETAPE_SPACE_OVER_FILEMARK);
1746 return idetape_queue_pc_tail(drive, &pc); 1559 return ide_queue_pc_tail(drive, disk, &pc);
1747 case MTFSFM: 1560 case MTFSFM:
1748 case MTBSFM: 1561 case MTBSFM:
1749 if (!sprev) 1562 if (!sprev)
@@ -1932,11 +1745,12 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1932 1745
1933static int idetape_write_filemark(ide_drive_t *drive) 1746static int idetape_write_filemark(ide_drive_t *drive)
1934{ 1747{
1748 struct ide_tape_obj *tape = drive->driver_data;
1935 struct ide_atapi_pc pc; 1749 struct ide_atapi_pc pc;
1936 1750
1937 /* Write a filemark */ 1751 /* Write a filemark */
1938 idetape_create_write_filemark_cmd(drive, &pc, 1); 1752 idetape_create_write_filemark_cmd(drive, &pc, 1);
1939 if (idetape_queue_pc_tail(drive, &pc)) { 1753 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1940 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); 1754 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
1941 return -EIO; 1755 return -EIO;
1942 } 1756 }
@@ -1959,6 +1773,7 @@ static int idetape_write_filemark(ide_drive_t *drive)
1959static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) 1773static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1960{ 1774{
1961 idetape_tape_t *tape = drive->driver_data; 1775 idetape_tape_t *tape = drive->driver_data;
1776 struct gendisk *disk = tape->disk;
1962 struct ide_atapi_pc pc; 1777 struct ide_atapi_pc pc;
1963 int i, retval; 1778 int i, retval;
1964 1779
@@ -1995,9 +1810,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1995 return 0; 1810 return 0;
1996 case MTLOAD: 1811 case MTLOAD:
1997 ide_tape_discard_merge_buffer(drive, 0); 1812 ide_tape_discard_merge_buffer(drive, 0);
1998 idetape_create_load_unload_cmd(drive, &pc, 1813 return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
1999 IDETAPE_LU_LOAD_MASK);
2000 return idetape_queue_pc_tail(drive, &pc);
2001 case MTUNLOAD: 1814 case MTUNLOAD:
2002 case MTOFFL: 1815 case MTOFFL:
2003 /* 1816 /*
@@ -2005,14 +1818,11 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2005 * attempting to eject. 1818 * attempting to eject.
2006 */ 1819 */
2007 if (tape->door_locked) { 1820 if (tape->door_locked) {
2008 if (idetape_create_prevent_cmd(drive, &pc, 0)) 1821 if (!ide_set_media_lock(drive, disk, 0))
2009 if (!idetape_queue_pc_tail(drive, &pc)) 1822 tape->door_locked = DOOR_UNLOCKED;
2010 tape->door_locked = DOOR_UNLOCKED;
2011 } 1823 }
2012 ide_tape_discard_merge_buffer(drive, 0); 1824 ide_tape_discard_merge_buffer(drive, 0);
2013 idetape_create_load_unload_cmd(drive, &pc, 1825 retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK);
2014 !IDETAPE_LU_LOAD_MASK);
2015 retval = idetape_queue_pc_tail(drive, &pc);
2016 if (!retval) 1826 if (!retval)
2017 clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags); 1827 clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
2018 return retval; 1828 return retval;
@@ -2021,16 +1831,15 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2021 return idetape_flush_tape_buffers(drive); 1831 return idetape_flush_tape_buffers(drive);
2022 case MTRETEN: 1832 case MTRETEN:
2023 ide_tape_discard_merge_buffer(drive, 0); 1833 ide_tape_discard_merge_buffer(drive, 0);
2024 idetape_create_load_unload_cmd(drive, &pc, 1834 return ide_do_start_stop(drive, disk,
2025 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); 1835 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
2026 return idetape_queue_pc_tail(drive, &pc);
2027 case MTEOM: 1836 case MTEOM:
2028 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); 1837 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
2029 return idetape_queue_pc_tail(drive, &pc); 1838 return ide_queue_pc_tail(drive, disk, &pc);
2030 case MTERASE: 1839 case MTERASE:
2031 (void)idetape_rewind_tape(drive); 1840 (void)idetape_rewind_tape(drive);
2032 idetape_create_erase_cmd(&pc); 1841 idetape_create_erase_cmd(&pc);
2033 return idetape_queue_pc_tail(drive, &pc); 1842 return ide_queue_pc_tail(drive, disk, &pc);
2034 case MTSETBLK: 1843 case MTSETBLK:
2035 if (mt_count) { 1844 if (mt_count) {
2036 if (mt_count < tape->blk_size || 1845 if (mt_count < tape->blk_size ||
@@ -2051,17 +1860,13 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2051 case MTFSR: 1860 case MTFSR:
2052 case MTBSR: 1861 case MTBSR:
2053 case MTLOCK: 1862 case MTLOCK:
2054 if (!idetape_create_prevent_cmd(drive, &pc, 1)) 1863 retval = ide_set_media_lock(drive, disk, 1);
2055 return 0;
2056 retval = idetape_queue_pc_tail(drive, &pc);
2057 if (retval) 1864 if (retval)
2058 return retval; 1865 return retval;
2059 tape->door_locked = DOOR_EXPLICITLY_LOCKED; 1866 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
2060 return 0; 1867 return 0;
2061 case MTUNLOCK: 1868 case MTUNLOCK:
2062 if (!idetape_create_prevent_cmd(drive, &pc, 0)) 1869 retval = ide_set_media_lock(drive, disk, 0);
2063 return 0;
2064 retval = idetape_queue_pc_tail(drive, &pc);
2065 if (retval) 1870 if (retval)
2066 return retval; 1871 return retval;
2067 tape->door_locked = DOOR_UNLOCKED; 1872 tape->door_locked = DOOR_UNLOCKED;
@@ -2143,7 +1948,7 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
2143 struct ide_atapi_pc pc; 1948 struct ide_atapi_pc pc;
2144 1949
2145 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); 1950 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
2146 if (idetape_queue_pc_tail(drive, &pc)) { 1951 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2147 printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); 1952 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
2148 if (tape->blk_size == 0) { 1953 if (tape->blk_size == 0) {
2149 printk(KERN_WARNING "ide-tape: Cannot deal with zero " 1954 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
@@ -2163,7 +1968,6 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2163 unsigned int minor = iminor(inode), i = minor & ~0xc0; 1968 unsigned int minor = iminor(inode), i = minor & ~0xc0;
2164 ide_drive_t *drive; 1969 ide_drive_t *drive;
2165 idetape_tape_t *tape; 1970 idetape_tape_t *tape;
2166 struct ide_atapi_pc pc;
2167 int retval; 1971 int retval;
2168 1972
2169 if (i >= MAX_HWIFS * MAX_DRIVES) 1973 if (i >= MAX_HWIFS * MAX_DRIVES)
@@ -2226,11 +2030,9 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2226 2030
2227 /* Lock the tape drive door so user can't eject. */ 2031 /* Lock the tape drive door so user can't eject. */
2228 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 2032 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2229 if (idetape_create_prevent_cmd(drive, &pc, 1)) { 2033 if (!ide_set_media_lock(drive, tape->disk, 1)) {
2230 if (!idetape_queue_pc_tail(drive, &pc)) { 2034 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
2231 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) 2035 tape->door_locked = DOOR_LOCKED;
2232 tape->door_locked = DOOR_LOCKED;
2233 }
2234 } 2036 }
2235 } 2037 }
2236 unlock_kernel(); 2038 unlock_kernel();
@@ -2263,7 +2065,6 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2263{ 2065{
2264 struct ide_tape_obj *tape = ide_tape_f(filp); 2066 struct ide_tape_obj *tape = ide_tape_f(filp);
2265 ide_drive_t *drive = tape->drive; 2067 ide_drive_t *drive = tape->drive;
2266 struct ide_atapi_pc pc;
2267 unsigned int minor = iminor(inode); 2068 unsigned int minor = iminor(inode);
2268 2069
2269 lock_kernel(); 2070 lock_kernel();
@@ -2282,10 +2083,8 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2282 (void) idetape_rewind_tape(drive); 2083 (void) idetape_rewind_tape(drive);
2283 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 2084 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2284 if (tape->door_locked == DOOR_LOCKED) { 2085 if (tape->door_locked == DOOR_LOCKED) {
2285 if (idetape_create_prevent_cmd(drive, &pc, 0)) { 2086 if (!ide_set_media_lock(drive, tape->disk, 0))
2286 if (!idetape_queue_pc_tail(drive, &pc)) 2087 tape->door_locked = DOOR_UNLOCKED;
2287 tape->door_locked = DOOR_UNLOCKED;
2288 }
2289 } 2088 }
2290 } 2089 }
2291 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags); 2090 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
@@ -2294,53 +2093,14 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2294 return 0; 2093 return 0;
2295} 2094}
2296 2095
2297/*
2298 * check the contents of the ATAPI IDENTIFY command results. We return:
2299 *
2300 * 1 - If the tape can be supported by us, based on the information we have so
2301 * far.
2302 *
2303 * 0 - If this tape driver is not currently supported by us.
2304 */
2305static int idetape_identify_device(ide_drive_t *drive)
2306{
2307 u8 gcw[2], protocol, device_type, removable, packet_size;
2308
2309 if (drive->id_read == 0)
2310 return 1;
2311
2312 *((unsigned short *) &gcw) = drive->id->config;
2313
2314 protocol = (gcw[1] & 0xC0) >> 6;
2315 device_type = gcw[1] & 0x1F;
2316 removable = !!(gcw[0] & 0x80);
2317 packet_size = gcw[0] & 0x3;
2318
2319 /* Check that we can support this device */
2320 if (protocol != 2)
2321 printk(KERN_ERR "ide-tape: Protocol (0x%02x) is not ATAPI\n",
2322 protocol);
2323 else if (device_type != 1)
2324 printk(KERN_ERR "ide-tape: Device type (0x%02x) is not set "
2325 "to tape\n", device_type);
2326 else if (!removable)
2327 printk(KERN_ERR "ide-tape: The removable flag is not set\n");
2328 else if (packet_size != 0) {
2329 printk(KERN_ERR "ide-tape: Packet size (0x%02x) is not 12"
2330 " bytes\n", packet_size);
2331 } else
2332 return 1;
2333 return 0;
2334}
2335
2336static void idetape_get_inquiry_results(ide_drive_t *drive) 2096static void idetape_get_inquiry_results(ide_drive_t *drive)
2337{ 2097{
2338 idetape_tape_t *tape = drive->driver_data; 2098 idetape_tape_t *tape = drive->driver_data;
2339 struct ide_atapi_pc pc; 2099 struct ide_atapi_pc pc;
2340 char fw_rev[6], vendor_id[10], product_id[18]; 2100 char fw_rev[4], vendor_id[8], product_id[16];
2341 2101
2342 idetape_create_inquiry_cmd(&pc); 2102 idetape_create_inquiry_cmd(&pc);
2343 if (idetape_queue_pc_tail(drive, &pc)) { 2103 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2344 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", 2104 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
2345 tape->name); 2105 tape->name);
2346 return; 2106 return;
@@ -2349,11 +2109,11 @@ static void idetape_get_inquiry_results(ide_drive_t *drive)
2349 memcpy(product_id, &pc.buf[16], 16); 2109 memcpy(product_id, &pc.buf[16], 16);
2350 memcpy(fw_rev, &pc.buf[32], 4); 2110 memcpy(fw_rev, &pc.buf[32], 4);
2351 2111
2352 ide_fixstring(vendor_id, 10, 0); 2112 ide_fixstring(vendor_id, 8, 0);
2353 ide_fixstring(product_id, 18, 0); 2113 ide_fixstring(product_id, 16, 0);
2354 ide_fixstring(fw_rev, 6, 0); 2114 ide_fixstring(fw_rev, 4, 0);
2355 2115
2356 printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n", 2116 printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n",
2357 drive->name, tape->name, vendor_id, product_id, fw_rev); 2117 drive->name, tape->name, vendor_id, product_id, fw_rev);
2358} 2118}
2359 2119
@@ -2369,7 +2129,7 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2369 u8 speed, max_speed; 2129 u8 speed, max_speed;
2370 2130
2371 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); 2131 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
2372 if (idetape_queue_pc_tail(drive, &pc)) { 2132 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2373 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" 2133 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
2374 " some default values\n"); 2134 " some default values\n");
2375 tape->blk_size = 512; 2135 tape->blk_size = 512;
@@ -2401,6 +2161,11 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2401 } 2161 }
2402 2162
2403 memcpy(&tape->caps, caps, 20); 2163 memcpy(&tape->caps, caps, 20);
2164
2165 /* device lacks locking support according to capabilities page */
2166 if ((caps[6] & 1) == 0)
2167 drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
2168
2404 if (caps[7] & 0x02) 2169 if (caps[7] & 0x02)
2405 tape->blk_size = 512; 2170 tape->blk_size = 512;
2406 else if (caps[7] & 0x04) 2171 else if (caps[7] & 0x04)
@@ -2408,28 +2173,56 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2408} 2173}
2409 2174
2410#ifdef CONFIG_IDE_PROC_FS 2175#ifdef CONFIG_IDE_PROC_FS
2411static void idetape_add_settings(ide_drive_t *drive) 2176#define ide_tape_devset_get(name, field) \
2412{ 2177static int get_##name(ide_drive_t *drive) \
2413 idetape_tape_t *tape = drive->driver_data; 2178{ \
2414 2179 idetape_tape_t *tape = drive->driver_data; \
2415 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 2180 return tape->field; \
2416 1, 2, (u16 *)&tape->caps[16], NULL); 2181}
2417 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 2182
2418 1, 1, (u16 *)&tape->caps[14], NULL); 2183#define ide_tape_devset_set(name, field) \
2419 ide_add_setting(drive, "buffer_size", SETTING_READ, TYPE_INT, 0, 0xffff, 2184static int set_##name(ide_drive_t *drive, int arg) \
2420 1, 1024, &tape->buffer_size, NULL); 2185{ \
2421 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, 2186 idetape_tape_t *tape = drive->driver_data; \
2422 IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq, 2187 tape->field = arg; \
2423 NULL); 2188 return 0; \
2424 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 2189}
2425 1, &drive->dsc_overlap, NULL); 2190
2426 ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, 2191#define ide_tape_devset_rw_field(_name, _field) \
2427 1, 1, &tape->avg_speed, NULL); 2192ide_tape_devset_get(_name, _field) \
2428 ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1, 2193ide_tape_devset_set(_name, _field) \
2429 1, &tape->debug_mask, NULL); 2194IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
2430} 2195
2431#else 2196#define ide_tape_devset_r_field(_name, _field) \
2432static inline void idetape_add_settings(ide_drive_t *drive) { ; } 2197ide_tape_devset_get(_name, _field) \
2198IDE_DEVSET(_name, 0, get_##_name, NULL)
2199
2200static int mulf_tdsc(ide_drive_t *drive) { return 1000; }
2201static int divf_tdsc(ide_drive_t *drive) { return HZ; }
2202static int divf_buffer(ide_drive_t *drive) { return 2; }
2203static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
2204
2205ide_devset_rw_field(dsc_overlap, dsc_overlap);
2206
2207ide_tape_devset_rw_field(debug_mask, debug_mask);
2208ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
2209
2210ide_tape_devset_r_field(avg_speed, avg_speed);
2211ide_tape_devset_r_field(speed, caps[14]);
2212ide_tape_devset_r_field(buffer, caps[16]);
2213ide_tape_devset_r_field(buffer_size, buffer_size);
2214
2215static const struct ide_proc_devset idetape_settings[] = {
2216 __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL),
2217 __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer),
2218 __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size),
2219 __IDE_PROC_DEVSET(debug_mask, 0, 0xffff, NULL, NULL),
2220 __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL),
2221 __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL),
2222 __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
2223 mulf_tdsc, divf_tdsc),
2224 { 0 },
2225};
2433#endif 2226#endif
2434 2227
2435/* 2228/*
@@ -2461,15 +2254,15 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2461 drive->dsc_overlap = 0; 2254 drive->dsc_overlap = 0;
2462 } 2255 }
2463 /* Seagate Travan drives do not support DSC overlap. */ 2256 /* Seagate Travan drives do not support DSC overlap. */
2464 if (strstr(drive->id->model, "Seagate STT3401")) 2257 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
2465 drive->dsc_overlap = 0; 2258 drive->dsc_overlap = 0;
2466 tape->minor = minor; 2259 tape->minor = minor;
2467 tape->name[0] = 'h'; 2260 tape->name[0] = 'h';
2468 tape->name[1] = 't'; 2261 tape->name[1] = 't';
2469 tape->name[2] = '0' + minor; 2262 tape->name[2] = '0' + minor;
2470 tape->chrdev_dir = IDETAPE_DIR_NONE; 2263 tape->chrdev_dir = IDETAPE_DIR_NONE;
2471 tape->pc = tape->pc_stack; 2264
2472 *((unsigned short *) &gcw) = drive->id->config; 2265 *((u16 *)&gcw) = drive->id[ATA_ID_CONFIG];
2473 2266
2474 /* Command packet DRQ type */ 2267 /* Command packet DRQ type */
2475 if (((gcw[0] & 0x60) >> 5) == 1) 2268 if (((gcw[0] & 0x60) >> 5) == 1)
@@ -2511,7 +2304,7 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2511 tape->best_dsc_rw_freq * 1000 / HZ, 2304 tape->best_dsc_rw_freq * 1000 / HZ,
2512 drive->using_dma ? ", DMA":""); 2305 drive->using_dma ? ", DMA":"");
2513 2306
2514 idetape_add_settings(drive); 2307 ide_proc_register_driver(drive, tape->driver);
2515} 2308}
2516 2309
2517static void ide_tape_remove(ide_drive_t *drive) 2310static void ide_tape_remove(ide_drive_t *drive)
@@ -2576,12 +2369,12 @@ static ide_driver_t idetape_driver = {
2576 .remove = ide_tape_remove, 2369 .remove = ide_tape_remove,
2577 .version = IDETAPE_VERSION, 2370 .version = IDETAPE_VERSION,
2578 .media = ide_tape, 2371 .media = ide_tape,
2579 .supports_dsc_overlap = 1,
2580 .do_request = idetape_do_request, 2372 .do_request = idetape_do_request,
2581 .end_request = idetape_end_request, 2373 .end_request = idetape_end_request,
2582 .error = __ide_error, 2374 .error = __ide_error,
2583#ifdef CONFIG_IDE_PROC_FS 2375#ifdef CONFIG_IDE_PROC_FS
2584 .proc = idetape_proc, 2376 .proc = idetape_proc,
2377 .settings = idetape_settings,
2585#endif 2378#endif
2586}; 2379};
2587 2380
@@ -2644,11 +2437,11 @@ static int ide_tape_probe(ide_drive_t *drive)
2644 2437
2645 if (!strstr("ide-tape", drive->driver_req)) 2438 if (!strstr("ide-tape", drive->driver_req))
2646 goto failed; 2439 goto failed;
2647 if (!drive->present) 2440
2648 goto failed;
2649 if (drive->media != ide_tape) 2441 if (drive->media != ide_tape)
2650 goto failed; 2442 goto failed;
2651 if (!idetape_identify_device(drive)) { 2443
2444 if (drive->id_read == 1 && !ide_check_atapi_device(drive, DRV_NAME)) {
2652 printk(KERN_ERR "ide-tape: %s: not supported by this version of" 2445 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
2653 " the driver\n", drive->name); 2446 " the driver\n", drive->name);
2654 goto failed; 2447 goto failed;
@@ -2666,8 +2459,6 @@ static int ide_tape_probe(ide_drive_t *drive)
2666 2459
2667 ide_init_disk(g, drive); 2460 ide_init_disk(g, drive);
2668 2461
2669 ide_proc_register_driver(drive, &idetape_driver);
2670
2671 kref_init(&tape->kref); 2462 kref_init(&tape->kref);
2672 2463
2673 tape->drive = drive; 2464 tape->drive = drive;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 7fb6f1c86272..487b18b3ebae 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -44,9 +44,9 @@ 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);
@@ -99,12 +99,17 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
99 case TASKFILE_NO_DATA: 99 case TASKFILE_NO_DATA:
100 if (handler == NULL) 100 if (handler == NULL)
101 handler = task_no_data_intr; 101 handler = task_no_data_intr;
102 /* WIN_{SPECIFY,RESTORE,SETMULT} use custom handlers */
103 if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) { 102 if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) {
104 switch (tf->command) { 103 switch (tf->command) {
105 case WIN_SPECIFY: handler = set_geometry_intr; break; 104 case ATA_CMD_INIT_DEV_PARAMS:
106 case WIN_RESTORE: handler = recal_intr; break; 105 handler = set_geometry_intr;
107 case WIN_SETMULT: handler = set_multmode_intr; break; 106 break;
107 case ATA_CMD_RESTORE:
108 handler = recal_intr;
109 break;
110 case ATA_CMD_SET_MULTI:
111 handler = set_multmode_intr;
112 break;
108 } 113 }
109 } 114 }
110 ide_execute_command(drive, tf->command, handler, 115 ide_execute_command(drive, tf->command, handler,
@@ -121,7 +126,7 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
121EXPORT_SYMBOL_GPL(do_rw_taskfile); 126EXPORT_SYMBOL_GPL(do_rw_taskfile);
122 127
123/* 128/*
124 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd. 129 * set_multmode_intr() is invoked on completion of a ATA_CMD_SET_MULTI cmd.
125 */ 130 */
126static ide_startstop_t set_multmode_intr(ide_drive_t *drive) 131static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
127{ 132{
@@ -131,7 +136,7 @@ static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
131 local_irq_enable_in_hardirq(); 136 local_irq_enable_in_hardirq();
132 stat = hwif->tp_ops->read_status(hwif); 137 stat = hwif->tp_ops->read_status(hwif);
133 138
134 if (OK_STAT(stat, READY_STAT, BAD_STAT)) 139 if (OK_STAT(stat, ATA_DRDY, BAD_STAT))
135 drive->mult_count = drive->mult_req; 140 drive->mult_count = drive->mult_req;
136 else { 141 else {
137 drive->mult_req = drive->mult_count = 0; 142 drive->mult_req = drive->mult_count = 0;
@@ -142,7 +147,7 @@ static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
142} 147}
143 148
144/* 149/*
145 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd. 150 * set_geometry_intr() is invoked on completion of a ATA_CMD_INIT_DEV_PARAMS cmd.
146 */ 151 */
147static ide_startstop_t set_geometry_intr(ide_drive_t *drive) 152static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
148{ 153{
@@ -154,15 +159,15 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
154 159
155 while (1) { 160 while (1) {
156 stat = hwif->tp_ops->read_status(hwif); 161 stat = hwif->tp_ops->read_status(hwif);
157 if ((stat & BUSY_STAT) == 0 || retries-- == 0) 162 if ((stat & ATA_BUSY) == 0 || retries-- == 0)
158 break; 163 break;
159 udelay(10); 164 udelay(10);
160 }; 165 };
161 166
162 if (OK_STAT(stat, READY_STAT, BAD_STAT)) 167 if (OK_STAT(stat, ATA_DRDY, BAD_STAT))
163 return ide_stopped; 168 return ide_stopped;
164 169
165 if (stat & (ERR_STAT|DRQ_STAT)) 170 if (stat & (ATA_ERR | ATA_DRQ))
166 return ide_error(drive, "set_geometry_intr", stat); 171 return ide_error(drive, "set_geometry_intr", stat);
167 172
168 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); 173 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
@@ -170,7 +175,7 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
170} 175}
171 176
172/* 177/*
173 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd. 178 * recal_intr() is invoked on completion of a ATA_CMD_RESTORE (recalibrate) cmd.
174 */ 179 */
175static ide_startstop_t recal_intr(ide_drive_t *drive) 180static ide_startstop_t recal_intr(ide_drive_t *drive)
176{ 181{
@@ -180,7 +185,7 @@ static ide_startstop_t recal_intr(ide_drive_t *drive)
180 local_irq_enable_in_hardirq(); 185 local_irq_enable_in_hardirq();
181 stat = hwif->tp_ops->read_status(hwif); 186 stat = hwif->tp_ops->read_status(hwif);
182 187
183 if (!OK_STAT(stat, READY_STAT, BAD_STAT)) 188 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
184 return ide_error(drive, "recal_intr", stat); 189 return ide_error(drive, "recal_intr", stat);
185 return ide_stopped; 190 return ide_stopped;
186} 191}
@@ -197,7 +202,7 @@ static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
197 local_irq_enable_in_hardirq(); 202 local_irq_enable_in_hardirq();
198 stat = hwif->tp_ops->read_status(hwif); 203 stat = hwif->tp_ops->read_status(hwif);
199 204
200 if (!OK_STAT(stat, READY_STAT, BAD_STAT)) 205 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
201 return ide_error(drive, "task_no_data_intr", stat); 206 return ide_error(drive, "task_no_data_intr", stat);
202 /* calls ide_end_drive_cmd */ 207 /* calls ide_end_drive_cmd */
203 208
@@ -220,13 +225,13 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
220 for (retries = 0; retries < 1000; retries++) { 225 for (retries = 0; retries < 1000; retries++) {
221 stat = hwif->tp_ops->read_status(hwif); 226 stat = hwif->tp_ops->read_status(hwif);
222 227
223 if (stat & BUSY_STAT) 228 if (stat & ATA_BUSY)
224 udelay(10); 229 udelay(10);
225 else 230 else
226 break; 231 break;
227 } 232 }
228 233
229 if (stat & BUSY_STAT) 234 if (stat & ATA_BUSY)
230 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name); 235 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
231 236
232 return stat; 237 return stat;
@@ -385,7 +390,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) 390static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
386{ 391{
387 /* Command all done? */ 392 /* Command all done? */
388 if (OK_STAT(stat, READY_STAT, BUSY_STAT)) { 393 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) {
389 task_end_request(drive, rq, stat); 394 task_end_request(drive, rq, stat);
390 return ide_stopped; 395 return ide_stopped;
391 } 396 }
@@ -405,11 +410,11 @@ static ide_startstop_t task_in_intr(ide_drive_t *drive)
405 u8 stat = hwif->tp_ops->read_status(hwif); 410 u8 stat = hwif->tp_ops->read_status(hwif);
406 411
407 /* Error? */ 412 /* Error? */
408 if (stat & ERR_STAT) 413 if (stat & ATA_ERR)
409 return task_error(drive, rq, __func__, stat); 414 return task_error(drive, rq, __func__, stat);
410 415
411 /* Didn't want any data? Odd. */ 416 /* Didn't want any data? Odd. */
412 if (!(stat & DRQ_STAT)) 417 if ((stat & ATA_DRQ) == 0)
413 return task_in_unexpected(drive, rq, stat); 418 return task_in_unexpected(drive, rq, stat);
414 419
415 ide_pio_datablock(drive, rq, 0); 420 ide_pio_datablock(drive, rq, 0);
@@ -442,7 +447,7 @@ static ide_startstop_t task_out_intr (ide_drive_t *drive)
442 return task_error(drive, rq, __func__, stat); 447 return task_error(drive, rq, __func__, stat);
443 448
444 /* Deal with unexpected ATA data phase. */ 449 /* Deal with unexpected ATA data phase. */
445 if (((stat & DRQ_STAT) == 0) ^ !hwif->nleft) 450 if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft)
446 return task_error(drive, rq, __func__, stat); 451 return task_error(drive, rq, __func__, stat);
447 452
448 if (!hwif->nleft) { 453 if (!hwif->nleft) {
@@ -461,7 +466,7 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
461{ 466{
462 ide_startstop_t startstop; 467 ide_startstop_t startstop;
463 468
464 if (ide_wait_stat(&startstop, drive, DRQ_STAT, 469 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
465 drive->bad_wstat, WAIT_DRQ)) { 470 drive->bad_wstat, WAIT_DRQ)) {
466 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", 471 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
467 drive->name, 472 drive->name,
@@ -721,110 +726,3 @@ abort:
721 return err; 726 return err;
722} 727}
723#endif 728#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..9dcf5aed92cb 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;
@@ -119,7 +116,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
119 drive->media = ide_disk; 116 drive->media = ide_disk;
120 drive->select.all = (unit<<4)|0xa0; 117 drive->select.all = (unit<<4)|0xa0;
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;
@@ -253,42 +250,9 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
253 250
254DEFINE_MUTEX(ide_setting_mtx); 251DEFINE_MUTEX(ide_setting_mtx);
255 252
256EXPORT_SYMBOL_GPL(ide_setting_mtx); 253ide_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 254
267int ide_spin_wait_hwgroup (ide_drive_t *drive) 255static int set_io_32bit(ide_drive_t *drive, int arg)
268{
269 ide_hwgroup_t *hwgroup = HWGROUP(drive);
270 unsigned long timeout = jiffies + (3 * HZ);
271
272 spin_lock_irq(&ide_lock);
273
274 while (hwgroup->busy) {
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{ 256{
293 if (drive->no_io_32bit) 257 if (drive->no_io_32bit)
294 return -EPERM; 258 return -EPERM;
@@ -296,53 +260,39 @@ int set_io_32bit(ide_drive_t *drive, int arg)
296 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) 260 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
297 return -EINVAL; 261 return -EINVAL;
298 262
299 if (ide_spin_wait_hwgroup(drive))
300 return -EBUSY;
301
302 drive->io_32bit = arg; 263 drive->io_32bit = arg;
303 264
304 spin_unlock_irq(&ide_lock);
305
306 return 0; 265 return 0;
307} 266}
308 267
268ide_devset_get(ksettings, keep_settings);
269
309static int set_ksettings(ide_drive_t *drive, int arg) 270static int set_ksettings(ide_drive_t *drive, int arg)
310{ 271{
311 if (arg < 0 || arg > 1) 272 if (arg < 0 || arg > 1)
312 return -EINVAL; 273 return -EINVAL;
313 274
314 if (ide_spin_wait_hwgroup(drive))
315 return -EBUSY;
316 drive->keep_settings = arg; 275 drive->keep_settings = arg;
317 spin_unlock_irq(&ide_lock);
318 276
319 return 0; 277 return 0;
320} 278}
321 279
322int set_using_dma(ide_drive_t *drive, int arg) 280ide_devset_get(using_dma, using_dma);
281
282static int set_using_dma(ide_drive_t *drive, int arg)
323{ 283{
324#ifdef CONFIG_BLK_DEV_IDEDMA 284#ifdef CONFIG_BLK_DEV_IDEDMA
325 ide_hwif_t *hwif = drive->hwif;
326 int err = -EPERM; 285 int err = -EPERM;
327 286
328 if (arg < 0 || arg > 1) 287 if (arg < 0 || arg > 1)
329 return -EINVAL; 288 return -EINVAL;
330 289
331 if (!drive->id || !(drive->id->capability & 1)) 290 if (ata_id_has_dma(drive->id) == 0)
332 goto out; 291 goto out;
333 292
334 if (hwif->dma_ops == NULL) 293 if (drive->hwif->dma_ops == NULL)
335 goto out; 294 goto out;
336 295
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; 296 err = 0;
347 297
348 if (arg) { 298 if (arg) {
@@ -351,12 +301,6 @@ int set_using_dma(ide_drive_t *drive, int arg)
351 } else 301 } else
352 ide_dma_off(drive); 302 ide_dma_off(drive);
353 303
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: 304out:
361 return err; 305 return err;
362#else 306#else
@@ -367,7 +311,7 @@ out:
367#endif 311#endif
368} 312}
369 313
370int set_pio_mode(ide_drive_t *drive, int arg) 314static int set_pio_mode(ide_drive_t *drive, int arg)
371{ 315{
372 struct request *rq; 316 struct request *rq;
373 ide_hwif_t *hwif = drive->hwif; 317 ide_hwif_t *hwif = drive->hwif;
@@ -395,6 +339,8 @@ int set_pio_mode(ide_drive_t *drive, int arg)
395 return 0; 339 return 0;
396} 340}
397 341
342ide_devset_get(unmaskirq, unmask);
343
398static int set_unmaskirq(ide_drive_t *drive, int arg) 344static int set_unmaskirq(ide_drive_t *drive, int arg)
399{ 345{
400 if (drive->no_unmask) 346 if (drive->no_unmask)
@@ -403,14 +349,20 @@ static int set_unmaskirq(ide_drive_t *drive, int arg)
403 if (arg < 0 || arg > 1) 349 if (arg < 0 || arg > 1)
404 return -EINVAL; 350 return -EINVAL;
405 351
406 if (ide_spin_wait_hwgroup(drive))
407 return -EBUSY;
408 drive->unmask = arg; 352 drive->unmask = arg;
409 spin_unlock_irq(&ide_lock);
410 353
411 return 0; 354 return 0;
412} 355}
413 356
357#define ide_gen_devset_rw(_name, _func) \
358__IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func)
359
360ide_gen_devset_rw(io_32bit, io_32bit);
361ide_gen_devset_rw(keepsettings, ksettings);
362ide_gen_devset_rw(unmaskirq, unmaskirq);
363ide_gen_devset_rw(using_dma, using_dma);
364__IDE_DEVSET(pio_mode, 0, NULL, set_pio_mode);
365
414static int generic_ide_suspend(struct device *dev, pm_message_t mesg) 366static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
415{ 367{
416 ide_drive_t *drive = dev->driver_data; 368 ide_drive_t *drive = dev->driver_data;
@@ -486,138 +438,6 @@ static int generic_ide_resume(struct device *dev)
486 return err; 438 return err;
487} 439}
488 440
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/** 441/**
622 * ide_device_get - get an additional reference to a ide_drive_t 442 * ide_device_get - get an additional reference to a ide_drive_t
623 * @drive: device to get a reference to 443 * @drive: device to get a reference to
@@ -710,21 +530,21 @@ static ssize_t model_show(struct device *dev, struct device_attribute *attr,
710 char *buf) 530 char *buf)
711{ 531{
712 ide_drive_t *drive = to_ide_device(dev); 532 ide_drive_t *drive = to_ide_device(dev);
713 return sprintf(buf, "%s\n", drive->id->model); 533 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
714} 534}
715 535
716static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, 536static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
717 char *buf) 537 char *buf)
718{ 538{
719 ide_drive_t *drive = to_ide_device(dev); 539 ide_drive_t *drive = to_ide_device(dev);
720 return sprintf(buf, "%s\n", drive->id->fw_rev); 540 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
721} 541}
722 542
723static ssize_t serial_show(struct device *dev, struct device_attribute *attr, 543static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
724 char *buf) 544 char *buf)
725{ 545{
726 ide_drive_t *drive = to_ide_device(dev); 546 ide_drive_t *drive = to_ide_device(dev);
727 return sprintf(buf, "%s\n", drive->id->serial_no); 547 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
728} 548}
729 549
730static struct device_attribute ide_dev_attrs[] = { 550static struct device_attribute ide_dev_attrs[] = {
@@ -841,7 +661,7 @@ MODULE_PARM_DESC(noprobe, "skip probing for a device");
841static unsigned int ide_nowerr; 661static unsigned int ide_nowerr;
842 662
843module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0); 663module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
844MODULE_PARM_DESC(nowerr, "ignore the WRERR_STAT bit for a device"); 664MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
845 665
846static unsigned int ide_cdroms; 666static unsigned int ide_cdroms;
847 667
@@ -906,7 +726,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
906 drive->noprobe = 1; 726 drive->noprobe = 1;
907 } 727 }
908 if (ide_nowerr & (1 << i)) { 728 if (ide_nowerr & (1 << i)) {
909 printk(KERN_INFO "ide: ignoring the WRERR_STAT bit for %s\n", 729 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
910 drive->name); 730 drive->name);
911 drive->bad_wstat = BAD_R_STAT; 731 drive->bad_wstat = BAD_R_STAT;
912 } 732 }
@@ -927,7 +747,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
927 drive->cyl, drive->head, drive->sect); 747 drive->cyl, drive->head, drive->sect);
928 drive->present = 1; 748 drive->present = 1;
929 drive->media = ide_disk; 749 drive->media = ide_disk;
930 drive->ready_stat = READY_STAT; 750 drive->ready_stat = ATA_DRDY;
931 } 751 }
932} 752}
933 753
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 4ec19737f3c5..7276c96aaa2a 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/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
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index 7c2afa97f417..c5a3c9ef6a5d 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/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/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index af791a02a120..689b2e493413 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/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/legacy/falconide.c
index 724f95073d80..39d500d84b07 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/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/legacy/gayle.c
index 51ba085d7aa8..691506886561 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/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/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index 98f7c95e39ed..5123ea291d07 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/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
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index fe20cdbd56f5..cb199c815b53 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/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>
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index a0bb167980e7..43f97cc1d30e 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/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/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 4abd8fc78197..4af4a8ce4cdf 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/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/legacy/qd65xx.c
index 2338f344ea24..ec408b3a7100 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/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));
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index b54a14a57755..1da076e0c917 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/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/mips/Makefile b/drivers/ide/mips/Makefile
index 677c7b2bac92..5873fa0b8769 100644
--- a/drivers/ide/mips/Makefile
+++ b/drivers/ide/mips/Makefile
@@ -1,4 +1,3 @@
1obj-$(CONFIG_BLK_DEV_IDE_SWARM) += swarm.o
2obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o 1obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o
3 2
4EXTRA_CFLAGS := -Idrivers/ide 3EXTRA_CFLAGS := -Idrivers/ide
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c
deleted file mode 100644
index badf79fc9e3a..000000000000
--- a/drivers/ide/mips/swarm.c
+++ /dev/null
@@ -1,196 +0,0 @@
1/*
2 * Copyright (C) 2001, 2002, 2003 Broadcom Corporation
3 * Copyright (C) 2004 MontaVista Software Inc.
4 * Author: Manish Lachwani, mlachwani@mvista.com
5 * Copyright (C) 2004 MIPS Technologies, Inc. All rights reserved.
6 * Author: Maciej W. Rozycki <macro@mips.com>
7 * Copyright (c) 2006, 2008 Maciej W. Rozycki
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/*
25 * Derived loosely from ide-pmac.c, so:
26 * Copyright (C) 1998 Paul Mackerras.
27 * Copyright (C) 1995-1998 Mark Lord
28 */
29
30/*
31 * Boards with SiByte processors so far have supported IDE devices via
32 * the Generic Bus, PCI bus, and built-in PCMCIA interface. In all
33 * cases, byte-swapping must be avoided for these devices (whereas
34 * other PCI devices, for example, will require swapping). Any
35 * SiByte-targetted kernel including IDE support will include this
36 * file. Probing of a Generic Bus for an IDE device is controlled by
37 * the definition of "SIBYTE_HAVE_IDE", which is provided by
38 * <asm/sibyte/board.h> for Broadcom boards.
39 */
40
41#include <linux/ide.h>
42#include <linux/ioport.h>
43#include <linux/kernel.h>
44#include <linux/types.h>
45#include <linux/platform_device.h>
46
47#include <asm/io.h>
48
49#include <asm/sibyte/board.h>
50#include <asm/sibyte/sb1250_genbus.h>
51#include <asm/sibyte/sb1250_regs.h>
52
53#define DRV_NAME "ide-swarm"
54
55static char swarm_ide_string[] = DRV_NAME;
56
57static struct resource swarm_ide_resource = {
58 .name = "SWARM GenBus IDE",
59 .flags = IORESOURCE_MEM,
60};
61
62static struct platform_device *swarm_ide_dev;
63
64static const struct ide_port_info swarm_port_info = {
65 .name = DRV_NAME,
66 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
67};
68
69/*
70 * swarm_ide_probe - if the board header indicates the existence of
71 * Generic Bus IDE, allocate a HWIF for it.
72 */
73static int __devinit swarm_ide_probe(struct device *dev)
74{
75 u8 __iomem *base;
76 struct ide_host *host;
77 phys_t offset, size;
78 int i, rc;
79 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
80
81 if (!SIBYTE_HAVE_IDE)
82 return -ENODEV;
83
84 base = ioremap(A_IO_EXT_BASE, 0x800);
85 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
86 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
87 iounmap(base);
88
89 offset = G_IO_START_ADDR(offset) << S_IO_ADDRBASE;
90 size = (G_IO_MULT_SIZE(size) + 1) << S_IO_REGSIZE;
91 if (offset < A_PHYS_GENBUS || offset >= A_PHYS_GENBUS_END) {
92 printk(KERN_INFO DRV_NAME
93 ": IDE interface at GenBus disabled\n");
94 return -EBUSY;
95 }
96
97 printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n",
98 IDE_CS);
99
100 swarm_ide_resource.start = offset;
101 swarm_ide_resource.end = offset + size - 1;
102 if (request_resource(&iomem_resource, &swarm_ide_resource)) {
103 printk(KERN_ERR DRV_NAME
104 ": can't request I/O memory resource\n");
105 return -EBUSY;
106 }
107
108 base = ioremap(offset, size);
109
110 for (i = 0; i <= 7; i++)
111 hw.io_ports_array[i] =
112 (unsigned long)(base + ((0x1f0 + i) << 5));
113 hw.io_ports.ctl_addr =
114 (unsigned long)(base + (0x3f6 << 5));
115 hw.irq = K_INT_GB_IDE;
116 hw.chipset = ide_generic;
117
118 rc = ide_host_add(&swarm_port_info, hws, &host);
119 if (rc)
120 goto err;
121
122 dev_set_drvdata(dev, host);
123
124 return 0;
125err:
126 release_resource(&swarm_ide_resource);
127 iounmap(base);
128 return rc;
129}
130
131static struct device_driver swarm_ide_driver = {
132 .name = swarm_ide_string,
133 .bus = &platform_bus_type,
134 .probe = swarm_ide_probe,
135};
136
137static void swarm_ide_platform_release(struct device *device)
138{
139 struct platform_device *pldev;
140
141 /* free device */
142 pldev = to_platform_device(device);
143 kfree(pldev);
144}
145
146static int __devinit swarm_ide_init_module(void)
147{
148 struct platform_device *pldev;
149 int err;
150
151 printk(KERN_INFO "SWARM IDE driver\n");
152
153 if (driver_register(&swarm_ide_driver)) {
154 printk(KERN_ERR "Driver registration failed\n");
155 err = -ENODEV;
156 goto out;
157 }
158
159 if (!(pldev = kzalloc(sizeof (*pldev), GFP_KERNEL))) {
160 err = -ENOMEM;
161 goto out_unregister_driver;
162 }
163
164 pldev->name = swarm_ide_string;
165 pldev->id = 0;
166 pldev->dev.release = swarm_ide_platform_release;
167
168 if (platform_device_register(pldev)) {
169 err = -ENODEV;
170 goto out_free_pldev;
171 }
172
173 if (!pldev->dev.driver) {
174 /*
175 * The driver was not bound to this device, there was
176 * no hardware at this address. Unregister it, as the
177 * release fuction will take care of freeing the
178 * allocated structure
179 */
180 platform_device_unregister (pldev);
181 }
182
183 swarm_ide_dev = pldev;
184
185 return 0;
186
187out_free_pldev:
188 kfree(pldev);
189
190out_unregister_driver:
191 driver_unregister(&swarm_ide_driver);
192out:
193 return err;
194}
195
196module_init(swarm_ide_init_module);
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index e0c8fe7d9fea..e7475ba559c7 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/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
@@ -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) ||
@@ -160,7 +159,7 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev)
160 return dev->irq; 159 return dev->irq;
161} 160}
162 161
163static u8 __devinit atp86x_cable_detect(ide_hwif_t *hwif) 162static u8 atp86x_cable_detect(ide_hwif_t *hwif)
164{ 163{
165 struct pci_dev *dev = to_pci_dev(hwif->dev); 164 struct pci_dev *dev = to_pci_dev(hwif->dev);
166 u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01; 165 u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
@@ -307,7 +306,9 @@ static struct pci_driver 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 = 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)
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index b582687e0cd4..053c75263918 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -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>
@@ -134,8 +133,8 @@ static u8 ali_udma_filter(ide_drive_t *drive)
134 if (m5229_revision > 0x20 && m5229_revision < 0xC2) { 133 if (m5229_revision > 0x20 && m5229_revision < 0xC2) {
135 if (drive->media != ide_disk) 134 if (drive->media != ide_disk)
136 return 0; 135 return 0;
137 if (chip_is_1543c_e && strstr(drive->id->model, "WDC ") && 136 if (wdc_udma == 0 && chip_is_1543c_e &&
138 wdc_udma == 0) 137 strstr((char *)&drive->id[ATA_ID_PROD], "WDC "))
139 return 0; 138 return 0;
140 } 139 }
141 140
@@ -214,7 +213,7 @@ static int ali15x3_dma_setup(ide_drive_t *drive)
214 * appropriate also sets up the 1533 southbridge. 213 * appropriate also sets up the 1533 southbridge.
215 */ 214 */
216 215
217static unsigned int __devinit init_chipset_ali15x3(struct pci_dev *dev) 216static unsigned int init_chipset_ali15x3(struct pci_dev *dev)
218{ 217{
219 unsigned long flags; 218 unsigned long flags;
220 u8 tmpbyte; 219 u8 tmpbyte;
@@ -371,7 +370,7 @@ static int ali_cable_override(struct pci_dev *pdev)
371 * FIXME: frobs bits that are not defined on newer ALi devicea 370 * FIXME: frobs bits that are not defined on newer ALi devicea
372 */ 371 */
373 372
374static u8 __devinit ali_cable_detect(ide_hwif_t *hwif) 373static u8 ali_cable_detect(ide_hwif_t *hwif)
375{ 374{
376 struct pci_dev *dev = to_pci_dev(hwif->dev); 375 struct pci_dev *dev = to_pci_dev(hwif->dev);
377 unsigned long flags; 376 unsigned long flags;
@@ -582,6 +581,8 @@ static struct pci_driver driver = {
582 .id_table = alim15x3_pci_tbl, 581 .id_table = alim15x3_pci_tbl,
583 .probe = alim15x3_init_one, 582 .probe = alim15x3_init_one,
584 .remove = ide_pci_remove, 583 .remove = ide_pci_remove,
584 .suspend = ide_pci_suspend,
585 .resume = ide_pci_resume,
585}; 586};
586 587
587static int __init ali15x3_ide_init(void) 588static int __init ali15x3_ide_init(void)
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 2cea7bf51a0f..824471f91bf5 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -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
@@ -175,7 +175,7 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev)
175 return dev->irq; 175 return dev->irq;
176} 176}
177 177
178static u8 __devinit amd_cable_detect(ide_hwif_t *hwif) 178static u8 amd_cable_detect(ide_hwif_t *hwif)
179{ 179{
180 if ((amd_80w >> hwif->channel) & 1) 180 if ((amd_80w >> hwif->channel) & 1)
181 return ATA_CBL_PATA80; 181 return ATA_CBL_PATA80;
@@ -324,6 +324,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 332f08f43b56..e4437034dd08 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/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
@@ -119,7 +118,7 @@ static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed)
119 spin_unlock_irqrestore(&atiixp_lock, flags); 118 spin_unlock_irqrestore(&atiixp_lock, flags);
120} 119}
121 120
122static u8 __devinit atiixp_cable_detect(ide_hwif_t *hwif) 121static u8 atiixp_cable_detect(ide_hwif_t *hwif)
123{ 122{
124 struct pci_dev *pdev = to_pci_dev(hwif->dev); 123 struct pci_dev *pdev = to_pci_dev(hwif->dev);
125 u8 udma_mode = 0, ch = hwif->channel; 124 u8 udma_mode = 0, ch = hwif->channel;
@@ -188,6 +187,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index e6c62006ca1a..7f39cdb41410 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/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->no_unmask = 1;
382 drive->unmask = 0;
383#endif
384 drive->no_io_32bit = 0;
385 } else {
386 drive->no_unmask = 0;
387 drive->no_io_32bit = 1;
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}
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 1360b4fa9fd3..456dee18b660 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/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
@@ -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
@@ -354,7 +353,7 @@ static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev)
354 return 0; 353 return 0;
355} 354}
356 355
357static u8 __devinit cmd64x_cable_detect(ide_hwif_t *hwif) 356static u8 cmd64x_cable_detect(ide_hwif_t *hwif)
358{ 357{
359 struct pci_dev *dev = to_pci_dev(hwif->dev); 358 struct pci_dev *dev = to_pci_dev(hwif->dev);
360 u8 bmidecsr = 0, mask = hwif->channel ? 0x02 : 0x01; 359 u8 bmidecsr = 0, mask = hwif->channel ? 0x02 : 0x01;
@@ -511,6 +510,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index c0364b287f17..d6341f7c4144 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/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>
@@ -96,6 +95,7 @@ static const struct ide_port_ops cs5520_port_ops = {
96 95
97static const struct ide_port_info cyrix_chipset __devinitdata = { 96static const struct ide_port_info cyrix_chipset __devinitdata = {
98 .name = DRV_NAME, 97 .name = DRV_NAME,
98 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
99 .port_ops = &cs5520_port_ops, 99 .port_ops = &cs5520_port_ops,
100 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_CS5520, 100 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_CS5520,
101 .pio_mask = ATA_PIO4, 101 .pio_mask = ATA_PIO4,
@@ -149,6 +149,8 @@ static struct pci_driver driver = {
149 .name = "Cyrix_IDE", 149 .name = "Cyrix_IDE",
150 .id_table = cs5520_pci_tbl, 150 .id_table = cs5520_pci_tbl,
151 .probe = cs5520_init_one, 151 .probe = cs5520_init_one,
152 .suspend = ide_pci_suspend,
153 .resume = ide_pci_resume,
152}; 154};
153 155
154static int __init cs5520_ide_init(void) 156static int __init cs5520_ide_init(void)
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index f235db8c678b..da42fa7e9f97 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/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
@@ -271,6 +272,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index f7b50cdeefa6..1e5bc59ea2fb 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -80,12 +80,12 @@ static void cs5535_set_speed(ide_drive_t *drive, const u8 speed)
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)
@@ -153,7 +153,7 @@ static void cs5535_set_pio_mode(ide_drive_t *drive, const u8 pio)
153 cs5535_set_speed(drive, XFER_PIO_0 + pio); 153 cs5535_set_speed(drive, XFER_PIO_0 + pio);
154} 154}
155 155
156static u8 __devinit cs5535_cable_detect(ide_hwif_t *hwif) 156static u8 cs5535_cable_detect(ide_hwif_t *hwif)
157{ 157{
158 struct pci_dev *dev = to_pci_dev(hwif->dev); 158 struct pci_dev *dev = to_pci_dev(hwif->dev);
159 u8 bit; 159 u8 bit;
@@ -193,10 +193,12 @@ static const struct pci_device_id cs5535_pci_tbl[] = {
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 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)
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index bfae2f882f48..69820e9224d1 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -332,7 +332,7 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
332/* 332/*
333 * this function is called during init and is used to setup the cy82c693 chip 333 * this function is called during init and is used to setup the cy82c693 chip
334 */ 334 */
335static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev) 335static unsigned int init_chipset_cy82c693(struct pci_dev *dev)
336{ 336{
337 if (PCI_FUNC(dev->devfn) != 1) 337 if (PCI_FUNC(dev->devfn) != 1)
338 return 0; 338 return 0;
@@ -447,7 +447,9 @@ static struct pci_driver driver = {
447 .name = "Cypress_IDE", 447 .name = "Cypress_IDE",
448 .id_table = cy82c693_pci_tbl, 448 .id_table = cy82c693_pci_tbl,
449 .probe = cy82c693_init_one, 449 .probe = cy82c693_init_one,
450 .remove = cy82c693_remove, 450 .remove = __devexit_p(cy82c693_remove),
451 .suspend = ide_pci_suspend,
452 .resume = ide_pci_resume,
451}; 453};
452 454
453static int __init cy82c693_ide_init(void) 455static int __init cy82c693_ide_init(void)
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index f84bfb4f600f..83b63b365e51 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/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>
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index b07d4f4273b3..092b238cb250 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -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>
@@ -172,6 +171,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 6009b0b9655d..644de29f8fe4 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -27,7 +27,6 @@
27#include <linux/types.h> 27#include <linux/types.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/interrupt.h> 30#include <linux/interrupt.h>
32#include <linux/pci.h> 31#include <linux/pci.h>
33#include <linux/init.h> 32#include <linux/init.h>
@@ -79,7 +78,7 @@ static void hpt34x_set_pio_mode(ide_drive_t *drive, const u8 pio)
79 */ 78 */
80#define HPT34X_PCI_INIT_REG 0x80 79#define HPT34X_PCI_INIT_REG 0x80
81 80
82static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev) 81static unsigned int init_chipset_hpt34x(struct pci_dev *dev)
83{ 82{
84 int i = 0; 83 int i = 0;
85 unsigned long hpt34xIoBase = pci_resource_start(dev, 4); 84 unsigned long hpt34xIoBase = pci_resource_start(dev, 4);
@@ -172,6 +171,8 @@ static struct pci_driver driver = {
172 .id_table = hpt34x_pci_tbl, 171 .id_table = hpt34x_pci_tbl,
173 .probe = hpt34x_init_one, 172 .probe = hpt34x_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 hpt34x_ide_init(void) 178static int __init hpt34x_ide_init(void)
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 5271b246b88c..a194022b6a61 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -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,14 +604,22 @@ 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}
615 614
615static struct hpt_info *hpt3xx_get_info(struct device *dev)
616{
617 struct ide_host *host = dev_get_drvdata(dev);
618 struct hpt_info *info = (struct hpt_info *)host->host_priv;
619
620 return dev == host->dev[1] ? info + 1 : info;
621}
622
616/* 623/*
617 * The Marvell bridge chips used on the HighPoint SATA cards do not seem 624 * The Marvell bridge chips used on the HighPoint SATA cards do not seem
618 * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes... 625 * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes...
@@ -621,9 +628,7 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)
621static u8 hpt3xx_udma_filter(ide_drive_t *drive) 628static u8 hpt3xx_udma_filter(ide_drive_t *drive)
622{ 629{
623 ide_hwif_t *hwif = HWIF(drive); 630 ide_hwif_t *hwif = HWIF(drive);
624 struct pci_dev *dev = to_pci_dev(hwif->dev); 631 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
625 struct ide_host *host = pci_get_drvdata(dev);
626 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
627 u8 mask = hwif->ultra_mask; 632 u8 mask = hwif->ultra_mask;
628 633
629 switch (info->chip_type) { 634 switch (info->chip_type) {
@@ -649,7 +654,7 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
649 case HPT372A: 654 case HPT372A:
650 case HPT372N: 655 case HPT372N:
651 case HPT374 : 656 case HPT374 :
652 if (ide_dev_is_sata(drive->id)) 657 if (ata_id_is_sata(drive->id))
653 mask &= ~0x0e; 658 mask &= ~0x0e;
654 /* Fall thru */ 659 /* Fall thru */
655 default: 660 default:
@@ -662,16 +667,14 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
662static u8 hpt3xx_mdma_filter(ide_drive_t *drive) 667static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
663{ 668{
664 ide_hwif_t *hwif = HWIF(drive); 669 ide_hwif_t *hwif = HWIF(drive);
665 struct pci_dev *dev = to_pci_dev(hwif->dev); 670 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
666 struct ide_host *host = pci_get_drvdata(dev);
667 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
668 671
669 switch (info->chip_type) { 672 switch (info->chip_type) {
670 case HPT372 : 673 case HPT372 :
671 case HPT372A: 674 case HPT372A:
672 case HPT372N: 675 case HPT372N:
673 case HPT374 : 676 case HPT374 :
674 if (ide_dev_is_sata(drive->id)) 677 if (ata_id_is_sata(drive->id))
675 return 0x00; 678 return 0x00;
676 /* Fall thru */ 679 /* Fall thru */
677 default: 680 default:
@@ -700,8 +703,7 @@ static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed)
700{ 703{
701 ide_hwif_t *hwif = drive->hwif; 704 ide_hwif_t *hwif = drive->hwif;
702 struct pci_dev *dev = to_pci_dev(hwif->dev); 705 struct pci_dev *dev = to_pci_dev(hwif->dev);
703 struct ide_host *host = pci_get_drvdata(dev); 706 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
704 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
705 struct hpt_timings *t = info->timings; 707 struct hpt_timings *t = info->timings;
706 u8 itr_addr = 0x40 + (drive->dn * 4); 708 u8 itr_addr = 0x40 + (drive->dn * 4);
707 u32 old_itr = 0; 709 u32 old_itr = 0;
@@ -728,11 +730,11 @@ static void hpt3xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
728 730
729static void hpt3xx_quirkproc(ide_drive_t *drive) 731static void hpt3xx_quirkproc(ide_drive_t *drive)
730{ 732{
731 struct hd_driveid *id = drive->id; 733 char *m = (char *)&drive->id[ATA_ID_PROD];
732 const char **list = quirk_drives; 734 const char **list = quirk_drives;
733 735
734 while (*list) 736 while (*list)
735 if (strstr(id->model, *list++)) { 737 if (strstr(m, *list++)) {
736 drive->quirk_list = 1; 738 drive->quirk_list = 1;
737 return; 739 return;
738 } 740 }
@@ -744,8 +746,7 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
744{ 746{
745 ide_hwif_t *hwif = HWIF(drive); 747 ide_hwif_t *hwif = HWIF(drive);
746 struct pci_dev *dev = to_pci_dev(hwif->dev); 748 struct pci_dev *dev = to_pci_dev(hwif->dev);
747 struct ide_host *host = pci_get_drvdata(dev); 749 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
748 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
749 750
750 if (drive->quirk_list) { 751 if (drive->quirk_list) {
751 if (info->chip_type >= HPT370) { 752 if (info->chip_type >= HPT370) {
@@ -942,7 +943,7 @@ static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq)
942 * Perform a calibration cycle on the DPLL. 943 * Perform a calibration cycle on the DPLL.
943 * Returns 1 if this succeeds 944 * Returns 1 if this succeeds
944 */ 945 */
945static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high) 946static int hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high)
946{ 947{
947 u32 dpll = (f_high << 16) | f_low | 0x100; 948 u32 dpll = (f_high << 16) | f_low | 0x100;
948 u8 scr2; 949 u8 scr2;
@@ -970,11 +971,40 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f
970 return 1; 971 return 1;
971} 972}
972 973
973static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev) 974static void hpt3xx_disable_fast_irq(struct pci_dev *dev, u8 mcr_addr)
974{ 975{
975 unsigned long io_base = pci_resource_start(dev, 4);
976 struct ide_host *host = pci_get_drvdata(dev); 976 struct ide_host *host = pci_get_drvdata(dev);
977 struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]); 977 struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]);
978 u8 chip_type = info->chip_type;
979 u8 new_mcr, old_mcr = 0;
980
981 /*
982 * Disable the "fast interrupt" prediction. Don't hold off
983 * on interrupts. (== 0x01 despite what the docs say)
984 */
985 pci_read_config_byte(dev, mcr_addr + 1, &old_mcr);
986
987 if (chip_type >= HPT374)
988 new_mcr = old_mcr & ~0x07;
989 else if (chip_type >= HPT370) {
990 new_mcr = old_mcr;
991 new_mcr &= ~0x02;
992#ifdef HPT_DELAY_INTERRUPT
993 new_mcr &= ~0x01;
994#else
995 new_mcr |= 0x01;
996#endif
997 } else /* HPT366 and HPT368 */
998 new_mcr = old_mcr & ~0x80;
999
1000 if (new_mcr != old_mcr)
1001 pci_write_config_byte(dev, mcr_addr + 1, new_mcr);
1002}
1003
1004static unsigned int init_chipset_hpt366(struct pci_dev *dev)
1005{
1006 unsigned long io_base = pci_resource_start(dev, 4);
1007 struct hpt_info *info = hpt3xx_get_info(&dev->dev);
978 const char *name = DRV_NAME; 1008 const char *name = DRV_NAME;
979 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ 1009 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */
980 u8 chip_type; 1010 u8 chip_type;
@@ -1208,17 +1238,18 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev)
1208 * NOTE: This register is only writeable via I/O space. 1238 * NOTE: This register is only writeable via I/O space.
1209 */ 1239 */
1210 if (chip_type == HPT371N && clock == ATA_CLOCK_66MHZ) 1240 if (chip_type == HPT371N && clock == ATA_CLOCK_66MHZ)
1211
1212 outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c); 1241 outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c);
1213 1242
1243 hpt3xx_disable_fast_irq(dev, 0x50);
1244 hpt3xx_disable_fast_irq(dev, 0x54);
1245
1214 return dev->irq; 1246 return dev->irq;
1215} 1247}
1216 1248
1217static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif) 1249static u8 hpt3xx_cable_detect(ide_hwif_t *hwif)
1218{ 1250{
1219 struct pci_dev *dev = to_pci_dev(hwif->dev); 1251 struct pci_dev *dev = to_pci_dev(hwif->dev);
1220 struct ide_host *host = pci_get_drvdata(dev); 1252 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
1221 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
1222 u8 chip_type = info->chip_type; 1253 u8 chip_type = info->chip_type;
1223 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; 1254 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
1224 1255
@@ -1262,11 +1293,9 @@ static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
1262static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1293static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1263{ 1294{
1264 struct pci_dev *dev = to_pci_dev(hwif->dev); 1295 struct pci_dev *dev = to_pci_dev(hwif->dev);
1265 struct ide_host *host = pci_get_drvdata(dev); 1296 struct hpt_info *info = hpt3xx_get_info(hwif->dev);
1266 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
1267 int serialize = HPT_SERIALIZE_IO; 1297 int serialize = HPT_SERIALIZE_IO;
1268 u8 chip_type = info->chip_type; 1298 u8 chip_type = info->chip_type;
1269 u8 new_mcr, old_mcr = 0;
1270 1299
1271 /* Cache the channel's MISC. control registers' offset */ 1300 /* Cache the channel's MISC. control registers' offset */
1272 hwif->select_data = hwif->channel ? 0x54 : 0x50; 1301 hwif->select_data = hwif->channel ? 0x54 : 0x50;
@@ -1289,29 +1318,6 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1289 /* Serialize access to this device if needed */ 1318 /* Serialize access to this device if needed */
1290 if (serialize && hwif->mate) 1319 if (serialize && hwif->mate)
1291 hwif->serialized = hwif->mate->serialized = 1; 1320 hwif->serialized = hwif->mate->serialized = 1;
1292
1293 /*
1294 * Disable the "fast interrupt" prediction. Don't hold off
1295 * on interrupts. (== 0x01 despite what the docs say)
1296 */
1297 pci_read_config_byte(dev, hwif->select_data + 1, &old_mcr);
1298
1299 if (info->chip_type >= HPT374)
1300 new_mcr = old_mcr & ~0x07;
1301 else if (info->chip_type >= HPT370) {
1302 new_mcr = old_mcr;
1303 new_mcr &= ~0x02;
1304
1305#ifdef HPT_DELAY_INTERRUPT
1306 new_mcr &= ~0x01;
1307#else
1308 new_mcr |= 0x01;
1309#endif
1310 } else /* HPT366 and HPT368 */
1311 new_mcr = old_mcr & ~0x80;
1312
1313 if (new_mcr != old_mcr)
1314 pci_write_config_byte(dev, hwif->select_data + 1, new_mcr);
1315} 1321}
1316 1322
1317static int __devinit init_dma_hpt366(ide_hwif_t *hwif, 1323static int __devinit init_dma_hpt366(ide_hwif_t *hwif,
@@ -1620,7 +1626,9 @@ static struct pci_driver driver = {
1620 .name = "HPT366_IDE", 1626 .name = "HPT366_IDE",
1621 .id_table = hpt366_pci_tbl, 1627 .id_table = hpt366_pci_tbl,
1622 .probe = hpt366_init_one, 1628 .probe = hpt366_init_one,
1623 .remove = hpt366_remove, 1629 .remove = __devexit_p(hpt366_remove),
1630 .suspend = ide_pci_suspend,
1631 .resume = ide_pci_resume,
1624}; 1632};
1625 1633
1626static int __init hpt366_ide_init(void) 1634static int __init hpt366_ide_init(void)
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 6eba8f188264..0954ccd08d6f 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/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
@@ -141,7 +140,7 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
141 } 140 }
142} 141}
143 142
144static u8 __devinit it8213_cable_detect(ide_hwif_t *hwif) 143static u8 it8213_cable_detect(ide_hwif_t *hwif)
145{ 144{
146 struct pci_dev *dev = to_pci_dev(hwif->dev); 145 struct pci_dev *dev = to_pci_dev(hwif->dev);
147 u8 reg42h = 0; 146 u8 reg42h = 0;
@@ -195,6 +194,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index e16a1d113a2a..46edd083b348 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -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
@@ -428,7 +427,7 @@ static void it821x_set_dma_mode(ide_drive_t *drive, const u8 speed)
428 * the needed logic onboard. 427 * the needed logic onboard.
429 */ 428 */
430 429
431static u8 __devinit it821x_cable_detect(ide_hwif_t *hwif) 430static u8 it821x_cable_detect(ide_hwif_t *hwif)
432{ 431{
433 /* The reference driver also only does disk side */ 432 /* The reference driver also only does disk side */
434 return ATA_CBL_PATA80; 433 return ATA_CBL_PATA80;
@@ -443,11 +442,10 @@ static u8 __devinit it821x_cable_detect(ide_hwif_t *hwif)
443 * final tuning that is needed, or fixups to work around bugs. 442 * final tuning that is needed, or fixups to work around bugs.
444 */ 443 */
445 444
446static void __devinit it821x_quirkproc(ide_drive_t *drive) 445static void it821x_quirkproc(ide_drive_t *drive)
447{ 446{
448 struct it821x_dev *itdev = ide_get_hwifdata(drive->hwif); 447 struct it821x_dev *itdev = ide_get_hwifdata(drive->hwif);
449 struct hd_driveid *id = drive->id; 448 u16 *id = drive->id;
450 u16 *idbits = (u16 *)drive->id;
451 449
452 if (!itdev->smart) { 450 if (!itdev->smart) {
453 /* 451 /*
@@ -466,36 +464,36 @@ static void __devinit it821x_quirkproc(ide_drive_t *drive)
466 */ 464 */
467 465
468 /* Check for RAID v native */ 466 /* Check for RAID v native */
469 if(strstr(id->model, "Integrated Technology Express")) { 467 if (strstr((char *)&id[ATA_ID_PROD],
468 "Integrated Technology Express")) {
470 /* In raid mode the ident block is slightly buggy 469 /* In raid mode the ident block is slightly buggy
471 We need to set the bits so that the IDE layer knows 470 We need to set the bits so that the IDE layer knows
472 LBA28. LBA48 and DMA ar valid */ 471 LBA28. LBA48 and DMA ar valid */
473 id->capability |= 3; /* LBA28, DMA */ 472 id[ATA_ID_CAPABILITY] |= (3 << 8); /* LBA28, DMA */
474 id->command_set_2 |= 0x0400; /* LBA48 valid */ 473 id[ATA_ID_COMMAND_SET_2] |= 0x0400; /* LBA48 valid */
475 id->cfs_enable_2 |= 0x0400; /* LBA48 on */ 474 id[ATA_ID_CFS_ENABLE_2] |= 0x0400; /* LBA48 on */
476 /* Reporting logic */ 475 /* Reporting logic */
477 printk(KERN_INFO "%s: IT8212 %sRAID %d volume", 476 printk(KERN_INFO "%s: IT8212 %sRAID %d volume",
478 drive->name, 477 drive->name, id[147] ? "Bootable " : "",
479 idbits[147] ? "Bootable ":"", 478 id[ATA_ID_CSFO]);
480 idbits[129]); 479 if (id[ATA_ID_CSFO] != 1)
481 if(idbits[129] != 1) 480 printk(KERN_CONT "(%dK stripe)", id[146]);
482 printk("(%dK stripe)", idbits[146]); 481 printk(KERN_CONT ".\n");
483 printk(".\n");
484 } else { 482 } else {
485 /* Non RAID volume. Fixups to stop the core code 483 /* Non RAID volume. Fixups to stop the core code
486 doing unsupported things */ 484 doing unsupported things */
487 id->field_valid &= 3; 485 id[ATA_ID_FIELD_VALID] &= 3;
488 id->queue_depth = 0; 486 id[ATA_ID_QUEUE_DEPTH] = 0;
489 id->command_set_1 = 0; 487 id[ATA_ID_COMMAND_SET_1] = 0;
490 id->command_set_2 &= 0xC400; 488 id[ATA_ID_COMMAND_SET_2] &= 0xC400;
491 id->cfsse &= 0xC000; 489 id[ATA_ID_CFSSE] &= 0xC000;
492 id->cfs_enable_1 = 0; 490 id[ATA_ID_CFS_ENABLE_1] = 0;
493 id->cfs_enable_2 &= 0xC400; 491 id[ATA_ID_CFS_ENABLE_2] &= 0xC400;
494 id->csf_default &= 0xC000; 492 id[ATA_ID_CSF_DEFAULT] &= 0xC000;
495 id->word127 = 0; 493 id[127] = 0;
496 id->dlf = 0; 494 id[ATA_ID_DLF] = 0;
497 id->csfo = 0; 495 id[ATA_ID_CSFO] = 0;
498 id->cfa_power = 0; 496 id[ATA_ID_CFA_POWER] = 0;
499 printk(KERN_INFO "%s: Performing identify fixups.\n", 497 printk(KERN_INFO "%s: Performing identify fixups.\n",
500 drive->name); 498 drive->name);
501 } 499 }
@@ -505,8 +503,8 @@ static void __devinit it821x_quirkproc(ide_drive_t *drive)
505 * IDE core that DMA is supported (it821x hardware 503 * IDE core that DMA is supported (it821x hardware
506 * takes care of DMA mode programming). 504 * takes care of DMA mode programming).
507 */ 505 */
508 if (id->capability & 1) { 506 if (ata_id_has_dma(id)) {
509 id->dma_mword |= 0x0101; 507 id[ATA_ID_MWDMA_MODES] |= 0x0101;
510 drive->current_speed = XFER_MW_DMA_0; 508 drive->current_speed = XFER_MW_DMA_0;
511 } 509 }
512 } 510 }
@@ -588,7 +586,7 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
588 hwif->mwdma_mask = ATA_MWDMA2; 586 hwif->mwdma_mask = ATA_MWDMA2;
589} 587}
590 588
591static void __devinit it8212_disable_raid(struct pci_dev *dev) 589static void it8212_disable_raid(struct pci_dev *dev)
592{ 590{
593 /* Reset local CPU, and set BIOS not ready */ 591 /* Reset local CPU, and set BIOS not ready */
594 pci_write_config_byte(dev, 0x5E, 0x01); 592 pci_write_config_byte(dev, 0x5E, 0x01);
@@ -605,7 +603,7 @@ static void __devinit it8212_disable_raid(struct pci_dev *dev)
605 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 603 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
606} 604}
607 605
608static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev) 606static unsigned int init_chipset_it821x(struct pci_dev *dev)
609{ 607{
610 u8 conf; 608 u8 conf;
611 static char *mode[2] = { "pass through", "smart" }; 609 static char *mode[2] = { "pass through", "smart" };
@@ -686,7 +684,9 @@ static struct pci_driver driver = {
686 .name = "ITE821x IDE", 684 .name = "ITE821x IDE",
687 .id_table = it821x_pci_tbl, 685 .id_table = it821x_pci_tbl,
688 .probe = it821x_init_one, 686 .probe = it821x_init_one,
689 .remove = it821x_remove, 687 .remove = __devexit_p(it821x_remove),
688 .suspend = ide_pci_suspend,
689 .resume = ide_pci_resume,
690}; 690};
691 691
692static int __init it821x_ide_init(void) 692static int __init it821x_ide_init(void)
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index 545b6e172d9b..acd647110648 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -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
@@ -27,7 +26,7 @@ typedef enum {
27 * Returns the cable type. 26 * Returns the cable type.
28 */ 27 */
29 28
30static u8 __devinit jmicron_cable_detect(ide_hwif_t *hwif) 29static u8 jmicron_cable_detect(ide_hwif_t *hwif)
31{ 30{
32 struct pci_dev *pdev = to_pci_dev(hwif->dev); 31 struct pci_dev *pdev = to_pci_dev(hwif->dev);
33 32
@@ -155,6 +154,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index ffefcd15196c..53bd645736d9 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/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>
@@ -274,9 +273,9 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
274 do { 273 do {
275 udelay(50); 274 udelay(50);
276 stat = hwif->tp_ops->read_status(hwif); 275 stat = hwif->tp_ops->read_status(hwif);
277 if (stat == 0xff) 276 if (stat == 0xff)
278 break; 277 break;
279 } while ((stat & BUSY_STAT) && --timeout); 278 } while ((stat & ATA_BUSY) && --timeout);
280#endif 279#endif
281 } 280 }
282 281
@@ -340,6 +339,8 @@ static struct pci_driver driver = {
340 .id_table = ns87415_pci_tbl, 339 .id_table = ns87415_pci_tbl,
341 .probe = ns87415_init_one, 340 .probe = ns87415_init_one,
342 .remove = ide_pci_remove, 341 .remove = ide_pci_remove,
342 .suspend = ide_pci_suspend,
343 .resume = ide_pci_resume,
343}; 344};
344 345
345static int __init ns87415_ide_init(void) 346static int __init ns87415_ide_init(void)
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index e28e672ddafc..3de11ddcf863 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/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 }
@@ -226,6 +225,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 998615fa285f..9fc59962553b 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/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>
@@ -193,7 +192,7 @@ static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio)
193 } 192 }
194} 193}
195 194
196static u8 __devinit pdcnew_cable_detect(ide_hwif_t *hwif) 195static u8 pdcnew_cable_detect(ide_hwif_t *hwif)
197{ 196{
198 if (get_indexed_reg(hwif, 0x0b) & 0x04) 197 if (get_indexed_reg(hwif, 0x0b) & 0x04)
199 return ATA_CBL_PATA40; 198 return ATA_CBL_PATA40;
@@ -203,10 +202,10 @@ static u8 __devinit 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);
@@ -566,7 +565,9 @@ static struct pci_driver 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 = 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)
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 6ff2def58da0..cb6d2a00c514 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/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 */
@@ -117,7 +116,7 @@ static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
117 pdc202xx_set_mode(drive, XFER_PIO_0 + pio); 116 pdc202xx_set_mode(drive, XFER_PIO_0 + pio);
118} 117}
119 118
120static u8 __devinit pdc2026x_cable_detect(ide_hwif_t *hwif) 119static u8 pdc2026x_cable_detect(ide_hwif_t *hwif)
121{ 120{
122 struct pci_dev *dev = to_pci_dev(hwif->dev); 121 struct pci_dev *dev = to_pci_dev(hwif->dev);
123 u16 CIS, mask = hwif->channel ? (1 << 11) : (1 << 10); 122 u16 CIS, mask = hwif->channel ? (1 << 11) : (1 << 10);
@@ -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 }
@@ -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;
@@ -432,6 +431,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 7fc3022dcf68..a06c03f8e295 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -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
@@ -256,7 +255,7 @@ static const struct ich_laptop ich_laptop[] = {
256 { 0, } 255 { 0, }
257}; 256};
258 257
259static u8 __devinit piix_cable_detect(ide_hwif_t *hwif) 258static u8 piix_cable_detect(ide_hwif_t *hwif)
260{ 259{
261 struct pci_dev *pdev = to_pci_dev(hwif->dev); 260 struct pci_dev *pdev = to_pci_dev(hwif->dev);
262 const struct ich_laptop *lap = &ich_laptop[0]; 261 const struct ich_laptop *lap = &ich_laptop[0];
@@ -450,6 +449,8 @@ static struct pci_driver driver = {
450 .id_table = piix_pci_tbl, 449 .id_table = piix_pci_tbl,
451 .probe = piix_init_one, 450 .probe = piix_init_one,
452 .remove = ide_pci_remove, 451 .remove = ide_pci_remove,
452 .suspend = ide_pci_suspend,
453 .resume = ide_pci_resume,
453}; 454};
454 455
455static int __init piix_ide_init(void) 456static int __init piix_ide_init(void)
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index 8d11ee838a2a..c117a068761b 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/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>
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 8efaed16fea3..bdc1fed41260 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/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:
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index 94a7ab864236..e92a874b31df 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -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
@@ -400,7 +399,7 @@ static int scc_dma_end(ide_drive_t *drive)
400 /* errata A308 workaround: Step5 (check data loss) */ 399 /* errata A308 workaround: Step5 (check data loss) */
401 /* We don't check non ide_disk because it is limited to UDMA4 */ 400 /* We don't check non ide_disk because it is limited to UDMA4 */
402 if (!(in_be32((void __iomem *)hwif->io_ports.ctl_addr) 401 if (!(in_be32((void __iomem *)hwif->io_ports.ctl_addr)
403 & ERR_STAT) && 402 & ATA_ERR) &&
404 drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) { 403 drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) {
405 reg = in_be32((void __iomem *)intsts_port); 404 reg = in_be32((void __iomem *)intsts_port);
406 if (!(reg & INTSTS_ACTEINT)) { 405 if (!(reg & INTSTS_ACTEINT)) {
@@ -504,7 +503,7 @@ static int scc_dma_test_irq(ide_drive_t *drive)
504 503
505 /* SCC errata A252,A308 workaround: Step4 */ 504 /* SCC errata A252,A308 workaround: Step4 */
506 if ((in_be32((void __iomem *)hwif->io_ports.ctl_addr) 505 if ((in_be32((void __iomem *)hwif->io_ports.ctl_addr)
507 & ERR_STAT) && 506 & ATA_ERR) &&
508 (int_stat & INTSTS_INTRQ)) 507 (int_stat & INTSTS_INTRQ))
509 return 1; 508 return 1;
510 509
@@ -827,7 +826,7 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
827 init_mmio_iops_scc(hwif); 826 init_mmio_iops_scc(hwif);
828} 827}
829 828
830static u8 __devinit scc_cable_detect(ide_hwif_t *hwif) 829static u8 scc_cable_detect(ide_hwif_t *hwif)
831{ 830{
832 return ATA_CBL_PATA80; 831 return ATA_CBL_PATA80;
833} 832}
@@ -954,7 +953,7 @@ static struct pci_driver driver = {
954 .name = "SCC IDE", 953 .name = "SCC IDE",
955 .id_table = scc_pci_tbl, 954 .id_table = scc_pci_tbl,
956 .probe = scc_init_one, 955 .probe = scc_init_one,
957 .remove = scc_remove, 956 .remove = __devexit_p(scc_remove),
958}; 957};
959 958
960static int scc_ide_init(void) 959static int scc_ide_init(void)
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index d173f2937722..3dff2aea317e 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/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}
@@ -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;
@@ -272,7 +273,7 @@ static unsigned int __devinit init_chipset_svwks(struct pci_dev *dev)
272 return dev->irq; 273 return dev->irq;
273} 274}
274 275
275static u8 __devinit ata66_svwks_svwks(ide_hwif_t *hwif) 276static u8 ata66_svwks_svwks(ide_hwif_t *hwif)
276{ 277{
277 return ATA_CBL_PATA80; 278 return ATA_CBL_PATA80;
278} 279}
@@ -284,7 +285,7 @@ static u8 __devinit ata66_svwks_svwks(ide_hwif_t *hwif)
284 * Bit 14 clear = primary IDE channel does not have 80-pin cable. 285 * Bit 14 clear = primary IDE channel does not have 80-pin cable.
285 * Bit 14 set = primary IDE channel has 80-pin cable. 286 * Bit 14 set = primary IDE channel has 80-pin cable.
286 */ 287 */
287static u8 __devinit ata66_svwks_dell(ide_hwif_t *hwif) 288static u8 ata66_svwks_dell(ide_hwif_t *hwif)
288{ 289{
289 struct pci_dev *dev = to_pci_dev(hwif->dev); 290 struct pci_dev *dev = to_pci_dev(hwif->dev);
290 291
@@ -303,7 +304,7 @@ static u8 __devinit ata66_svwks_dell(ide_hwif_t *hwif)
303 * 304 *
304 * WARNING: this only works on Alpine hardware! 305 * WARNING: this only works on Alpine hardware!
305 */ 306 */
306static u8 __devinit ata66_svwks_cobalt(ide_hwif_t *hwif) 307static u8 ata66_svwks_cobalt(ide_hwif_t *hwif)
307{ 308{
308 struct pci_dev *dev = to_pci_dev(hwif->dev); 309 struct pci_dev *dev = to_pci_dev(hwif->dev);
309 310
@@ -315,7 +316,7 @@ static u8 __devinit ata66_svwks_cobalt(ide_hwif_t *hwif)
315 return ATA_CBL_PATA40; 316 return ATA_CBL_PATA40;
316} 317}
317 318
318static u8 __devinit svwks_cable_detect(ide_hwif_t *hwif) 319static u8 svwks_cable_detect(ide_hwif_t *hwif)
319{ 320{
320 struct pci_dev *dev = to_pci_dev(hwif->dev); 321 struct pci_dev *dev = to_pci_dev(hwif->dev);
321 322
@@ -447,6 +448,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 42eef19a18f1..1017fb4f6317 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -22,7 +22,6 @@
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/hdreg.h>
26#include <linux/init.h> 25#include <linux/init.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/ioport.h> 27#include <linux/ioport.h>
@@ -621,9 +620,9 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
621 if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, 620 if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
622 DRV_NAME)) { 621 DRV_NAME)) {
623 printk(KERN_ERR 622 printk(KERN_ERR
624 "%s : %s -- ERROR, Addresses " 623 "%s %s: -- ERROR, Addresses "
625 "0x%p to 0x%p ALREADY in use\n", 624 "0x%p to 0x%p ALREADY in use\n",
626 __func__, DRV_NAME, (void *) cmd_phys_base, 625 DRV_NAME, pci_name(dev), (void *)cmd_phys_base,
627 (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE); 626 (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
628 return -ENOMEM; 627 return -ENOMEM;
629 } 628 }
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index b8ad9ad6cf0d..174a873b4c64 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -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>
@@ -223,7 +222,9 @@ static u8 sil_pata_udma_filter(ide_drive_t *drive)
223 222
224static u8 sil_sata_udma_filter(ide_drive_t *drive) 223static u8 sil_sata_udma_filter(ide_drive_t *drive)
225{ 224{
226 return strstr(drive->id->model, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6; 225 char *m = (char *)&drive->id[ATA_ID_PROD];
226
227 return strstr(m, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6;
227} 228}
228 229
229/** 230/**
@@ -243,7 +244,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
243 244
244 ide_hwif_t *hwif = HWIF(drive); 245 ide_hwif_t *hwif = HWIF(drive);
245 struct pci_dev *dev = to_pci_dev(hwif->dev); 246 struct pci_dev *dev = to_pci_dev(hwif->dev);
246 ide_drive_t *pair = ide_get_paired_drive(drive); 247 ide_drive_t *pair = ide_get_pair_dev(drive);
247 u32 speedt = 0; 248 u32 speedt = 0;
248 u16 speedp = 0; 249 u16 speedp = 0;
249 unsigned long addr = siimage_seldev(drive, 0x04); 250 unsigned long addr = siimage_seldev(drive, 0x04);
@@ -257,7 +258,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
257 u8 unit = drive->select.b.unit; 258 u8 unit = drive->select.b.unit;
258 259
259 /* trim *taskfile* PIO to the slowest of the master/slave */ 260 /* trim *taskfile* PIO to the slowest of the master/slave */
260 if (pair->present) { 261 if (pair) {
261 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4); 262 u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4);
262 263
263 if (pair_pio < tf_pio) 264 if (pair_pio < tf_pio)
@@ -462,7 +463,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. 463 * to 133 MHz clocking if the system isn't already set up to do it.
463 */ 464 */
464 465
465static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev) 466static unsigned int init_chipset_siimage(struct pci_dev *dev)
466{ 467{
467 struct ide_host *host = pci_get_drvdata(dev); 468 struct ide_host *host = pci_get_drvdata(dev);
468 void __iomem *ioaddr = host->host_priv; 469 void __iomem *ioaddr = host->host_priv;
@@ -616,8 +617,8 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
616 617
617static int is_dev_seagate_sata(ide_drive_t *drive) 618static int is_dev_seagate_sata(ide_drive_t *drive)
618{ 619{
619 const char *s = &drive->id->model[0]; 620 const char *s = (const char *)&drive->id[ATA_ID_PROD];
620 unsigned len = strnlen(s, sizeof(drive->id->model)); 621 unsigned len = strnlen(s, ATA_ID_PROD_LEN);
621 622
622 if ((len > 4) && (!memcmp(s, "ST", 2))) 623 if ((len > 4) && (!memcmp(s, "ST", 2)))
623 if ((!memcmp(s + len - 2, "AS", 2)) || 624 if ((!memcmp(s + len - 2, "AS", 2)) ||
@@ -639,7 +640,7 @@ static int is_dev_seagate_sata(ide_drive_t *drive)
639 * that can occur before we know what drives are present. 640 * that can occur before we know what drives are present.
640 */ 641 */
641 642
642static void __devinit sil_quirkproc(ide_drive_t *drive) 643static void sil_quirkproc(ide_drive_t *drive)
643{ 644{
644 ide_hwif_t *hwif = drive->hwif; 645 ide_hwif_t *hwif = drive->hwif;
645 646
@@ -679,7 +680,7 @@ static void __devinit init_iops_siimage(ide_hwif_t *hwif)
679 * Check for the presence of an ATA66 capable cable on the interface. 680 * Check for the presence of an ATA66 capable cable on the interface.
680 */ 681 */
681 682
682static u8 __devinit sil_cable_detect(ide_hwif_t *hwif) 683static u8 sil_cable_detect(ide_hwif_t *hwif)
683{ 684{
684 struct pci_dev *dev = to_pci_dev(hwif->dev); 685 struct pci_dev *dev = to_pci_dev(hwif->dev);
685 unsigned long addr = siimage_selreg(hwif, 0); 686 unsigned long addr = siimage_selreg(hwif, 0);
@@ -832,7 +833,9 @@ static struct pci_driver driver = {
832 .name = "SiI_IDE", 833 .name = "SiI_IDE",
833 .id_table = siimage_pci_tbl, 834 .id_table = siimage_pci_tbl,
834 .probe = siimage_init_one, 835 .probe = siimage_init_one,
835 .remove = siimage_remove, 836 .remove = __devexit_p(siimage_remove),
837 .suspend = ide_pci_suspend,
838 .resume = ide_pci_resume,
836}; 839};
837 840
838static int __init siimage_ide_init(void) 841static int __init siimage_ide_init(void)
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index cc95f90b53b7..734dd41f1f67 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/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
@@ -518,7 +517,7 @@ static const struct sis_laptop sis_laptop[] = {
518 { 0, } 517 { 0, }
519}; 518};
520 519
521static u8 __devinit sis_cable_detect(ide_hwif_t *hwif) 520static u8 sis_cable_detect(ide_hwif_t *hwif)
522{ 521{
523 struct pci_dev *pdev = to_pci_dev(hwif->dev); 522 struct pci_dev *pdev = to_pci_dev(hwif->dev);
524 const struct sis_laptop *lap = &sis_laptop[0]; 523 const struct sis_laptop *lap = &sis_laptop[0];
@@ -610,7 +609,9 @@ static struct pci_driver 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 = 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)
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 73905bcc08fb..37a6b7bdc040 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/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;
@@ -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
@@ -351,6 +350,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 13d1fa491f26..a9551a13ac57 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/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
@@ -116,7 +115,7 @@ static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
116 } 115 }
117} 116}
118 117
119static u8 __devinit slc90e66_cable_detect(ide_hwif_t *hwif) 118static u8 slc90e66_cable_detect(ide_hwif_t *hwif)
120{ 119{
121 struct pci_dev *dev = to_pci_dev(hwif->dev); 120 struct pci_dev *dev = to_pci_dev(hwif->dev);
122 u8 reg47 = 0, mask = hwif->channel ? 0x01 : 0x02; 121 u8 reg47 = 0, mask = hwif->channel ? 0x01 : 0x02;
@@ -160,6 +159,8 @@ static struct pci_driver driver = {
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)
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index b1cb8a9ce5a9..927277c54ec9 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -131,7 +131,7 @@ static void tc86c001_dma_start(ide_drive_t *drive)
131 ide_dma_start(drive); 131 ide_dma_start(drive);
132} 132}
133 133
134static u8 __devinit tc86c001_cable_detect(ide_hwif_t *hwif) 134static u8 tc86c001_cable_detect(ide_hwif_t *hwif)
135{ 135{
136 struct pci_dev *dev = to_pci_dev(hwif->dev); 136 struct pci_dev *dev = to_pci_dev(hwif->dev);
137 unsigned long sc_base = pci_resource_start(dev, 5); 137 unsigned long sc_base = pci_resource_start(dev, 5);
@@ -249,7 +249,7 @@ static struct pci_driver 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,
252 .remove = tc86c001_remove, 252 .remove = __devexit_p(tc86c001_remove),
253}; 253};
254 254
255static int __init tc86c001_ide_init(void) 255static int __init tc86c001_ide_init(void)
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index b77ec35151b3..be8715dcee05 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/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>
@@ -120,6 +119,8 @@ static struct pci_driver driver = {
120 .id_table = triflex_pci_tbl, 119 .id_table = triflex_pci_tbl,
121 .probe = triflex_init_one, 120 .probe = triflex_init_one,
122 .remove = ide_pci_remove, 121 .remove = ide_pci_remove,
122 .suspend = ide_pci_suspend,
123 .resume = ide_pci_resume,
123}; 124};
124 125
125static int __init triflex_ide_init(void) 126static int __init triflex_ide_init(void)
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index fd28b49977fd..4dfbc6a68b5b 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/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
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 454d2bf62dce..acacdaab69c2 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/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;
@@ -352,7 +352,7 @@ static int via_cable_override(struct pci_dev *pdev)
352 return 0; 352 return 0;
353} 353}
354 354
355static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif) 355static u8 via82cxxx_cable_detect(ide_hwif_t *hwif)
356{ 356{
357 struct pci_dev *pdev = to_pci_dev(hwif->dev); 357 struct pci_dev *pdev = to_pci_dev(hwif->dev);
358 struct ide_host *host = pci_get_drvdata(pdev); 358 struct ide_host *host = pci_get_drvdata(pdev);
@@ -491,7 +491,9 @@ static struct pci_driver 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 = 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)
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index c521bf6e1bf2..c3432da78d52 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -669,9 +669,9 @@ static void
669set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2, 669set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
670 u8 speed) 670 u8 speed)
671{ 671{
672 u16 *id = drive->id;
672 int cycleTime, accessTime = 0, recTime = 0; 673 int cycleTime, accessTime = 0, recTime = 0;
673 unsigned accessTicks, recTicks; 674 unsigned accessTicks, recTicks;
674 struct hd_driveid *id = drive->id;
675 struct mdma_timings_t* tm = NULL; 675 struct mdma_timings_t* tm = NULL;
676 int i; 676 int i;
677 677
@@ -686,8 +686,8 @@ set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
686 } 686 }
687 687
688 /* Check if drive provides explicit DMA cycle time */ 688 /* Check if drive provides explicit DMA cycle time */
689 if ((id->field_valid & 2) && id->eide_dma_time) 689 if ((id[ATA_ID_FIELD_VALID] & 2) && id[ATA_ID_EIDE_DMA_TIME])
690 cycleTime = max_t(int, id->eide_dma_time, cycleTime); 690 cycleTime = max_t(int, id[ATA_ID_EIDE_DMA_TIME], cycleTime);
691 691
692 /* OHare limits according to some old Apple sources */ 692 /* OHare limits according to some old Apple sources */
693 if ((intf_type == controller_ohare) && (cycleTime < 150)) 693 if ((intf_type == controller_ohare) && (cycleTime < 150))
@@ -1086,6 +1086,11 @@ static int __devinit pmac_ide_setup_device(pmac_ide_hwif_t *pmif, hw_regs_t *hw)
1086 /* Make sure we have sane timings */ 1086 /* Make sure we have sane timings */
1087 sanitize_timings(pmif); 1087 sanitize_timings(pmif);
1088 1088
1089 host = ide_host_alloc(&d, hws);
1090 if (host == NULL)
1091 return -ENOMEM;
1092 hwif = host->ports[0];
1093
1089#ifndef CONFIG_PPC64 1094#ifndef CONFIG_PPC64
1090 /* XXX FIXME: Media bay stuff need re-organizing */ 1095 /* XXX FIXME: Media bay stuff need re-organizing */
1091 if (np->parent && np->parent->name 1096 if (np->parent && np->parent->name
@@ -1119,11 +1124,11 @@ static int __devinit pmac_ide_setup_device(pmac_ide_hwif_t *pmif, hw_regs_t *hw)
1119 pmif->mdev ? "macio" : "PCI", pmif->aapl_bus_id, 1124 pmif->mdev ? "macio" : "PCI", pmif->aapl_bus_id,
1120 pmif->mediabay ? " (mediabay)" : "", hw->irq); 1125 pmif->mediabay ? " (mediabay)" : "", hw->irq);
1121 1126
1122 rc = ide_host_add(&d, hws, &host); 1127 rc = ide_host_register(host, &d, hws);
1123 if (rc) 1128 if (rc) {
1129 ide_host_free(host);
1124 return rc; 1130 return rc;
1125 1131 }
1126 hwif = host->ports[0];
1127 1132
1128 return 0; 1133 return 0;
1129} 1134}
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