aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-13 17:15:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-13 17:15:06 -0400
commit7591103c08abade60aeddb432ed0686ddd0de1c6 (patch)
tree523343b43b0c420666da18c64e1e9f21ff63dea5 /drivers/ide
parent2be4ff2f084842839b041b793ed6237e8d1d315a (diff)
parent9c6102d446985bca9c426cb2d9b478ed21d2b024 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (66 commits) ata: Add documentation for hard disk shock protection interface (v3) ide: Implement disk shock protection support (v4) ide-cd: fix printk format warning piix: add Hercules EC-900 mini-notebook to ich_laptop short cable list ide-atapi: assign taskfile flags per device type ide-cd: move cdrom_info.dma to ide_drive_t.dma ide: add ide_drive_t.dma flag ide-cd: add a debug_mask module parameter ide-cd: convert driver to new ide debugging macro (v3) ide: move SFF DMA code to ide-dma-sff.c ide: cleanup ide-dma.c ide: cleanup ide_build_dmatable() ide: remove needless includes from ide-dma.c ide: switch to DMA-mapping API part #2 ide: make ide_dma_timeout() available also for CONFIG_BLK_DEV_IDEDMA_SFF=n ide: make ide_dma_lost_irq() available also for CONFIG_BLK_DEV_IDEDMA_SFF=n ide: __ide_dma_end() -> ide_dma_end() pmac: remove needless pmac_ide_destroy_dmatable() wrapper pmac: remove superfluous pmif == NULL checks ide: Two fixes regarding memory allocation ...
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/Kconfig38
-rw-r--r--drivers/ide/Makefile19
-rw-r--r--drivers/ide/arm/icside.c23
-rw-r--r--drivers/ide/h8300/ide-h8300.c2
-rw-r--r--drivers/ide/ide-acpi.c12
-rw-r--r--drivers/ide/ide-atapi.c183
-rw-r--r--drivers/ide/ide-cd.c261
-rw-r--r--drivers/ide/ide-cd.h1
-rw-r--r--drivers/ide/ide-disk.c357
-rw-r--r--drivers/ide/ide-disk.h32
-rw-r--r--drivers/ide/ide-disk_ioctl.c29
-rw-r--r--drivers/ide/ide-disk_proc.c129
-rw-r--r--drivers/ide/ide-dma-sff.c356
-rw-r--r--drivers/ide/ide-dma.c481
-rw-r--r--drivers/ide/ide-floppy.c392
-rw-r--r--drivers/ide/ide-floppy.h19
-rw-r--r--drivers/ide/ide-floppy_ioctl.c56
-rw-r--r--drivers/ide/ide-floppy_proc.c33
-rw-r--r--drivers/ide/ide-generic.c51
-rw-r--r--drivers/ide/ide-io.c237
-rw-r--r--drivers/ide/ide-ioctls.c21
-rw-r--r--drivers/ide/ide-iops.c95
-rw-r--r--drivers/ide/ide-lib.c2
-rw-r--r--drivers/ide/ide-park.c121
-rw-r--r--drivers/ide/ide-probe.c215
-rw-r--r--drivers/ide/ide-proc.c6
-rw-r--r--drivers/ide/ide-tape.c155
-rw-r--r--drivers/ide/ide-taskfile.c128
-rw-r--r--drivers/ide/ide.c135
-rw-r--r--drivers/ide/legacy/ali14xx.c2
-rw-r--r--drivers/ide/legacy/ht6560b.c9
-rw-r--r--drivers/ide/legacy/ide-4drives.c2
-rw-r--r--drivers/ide/legacy/qd65xx.c2
-rw-r--r--drivers/ide/mips/au1xxx-ide.c34
-rw-r--r--drivers/ide/pci/aec62xx.c8
-rw-r--r--drivers/ide/pci/alim15x3.c15
-rw-r--r--drivers/ide/pci/amd74xx.c8
-rw-r--r--drivers/ide/pci/atiixp.c6
-rw-r--r--drivers/ide/pci/cmd640.c18
-rw-r--r--drivers/ide/pci/cmd64x.c10
-rw-r--r--drivers/ide/pci/cs5520.c4
-rw-r--r--drivers/ide/pci/cs5530.c6
-rw-r--r--drivers/ide/pci/cs5535.c8
-rw-r--r--drivers/ide/pci/cy82c693.c124
-rw-r--r--drivers/ide/pci/delkin_cb.c6
-rw-r--r--drivers/ide/pci/generic.c6
-rw-r--r--drivers/ide/pci/hpt34x.c6
-rw-r--r--drivers/ide/pci/hpt366.c15
-rw-r--r--drivers/ide/pci/it8213.c6
-rw-r--r--drivers/ide/pci/it821x.c46
-rw-r--r--drivers/ide/pci/jmicron.c6
-rw-r--r--drivers/ide/pci/ns87415.c21
-rw-r--r--drivers/ide/pci/opti621.c8
-rw-r--r--drivers/ide/pci/pdc202xx_new.c6
-rw-r--r--drivers/ide/pci/pdc202xx_old.c14
-rw-r--r--drivers/ide/pci/piix.c46
-rw-r--r--drivers/ide/pci/rz1000.c6
-rw-r--r--drivers/ide/pci/sc1200.c12
-rw-r--r--drivers/ide/pci/scc_pata.c29
-rw-r--r--drivers/ide/pci/serverworks.c8
-rw-r--r--drivers/ide/pci/sgiioc4.c59
-rw-r--r--drivers/ide/pci/siimage.c17
-rw-r--r--drivers/ide/pci/sis5513.c6
-rw-r--r--drivers/ide/pci/sl82c105.c8
-rw-r--r--drivers/ide/pci/slc90e66.c6
-rw-r--r--drivers/ide/pci/tc86c001.c8
-rw-r--r--drivers/ide/pci/triflex.c15
-rw-r--r--drivers/ide/pci/trm290.c10
-rw-r--r--drivers/ide/pci/via82cxxx.c6
-rw-r--r--drivers/ide/ppc/pmac.c71
70 files changed, 2113 insertions, 2179 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index b50b5dac95b0..6c6dd2facede 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -54,38 +54,6 @@ menuconfig IDE
54 54
55if IDE 55if IDE
56 56
57config BLK_DEV_IDE
58 tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support"
59 ---help---
60 If you say Y here, you will use the full-featured IDE driver to
61 control up to ten ATA/IDE interfaces, each being able to serve a
62 "master" and a "slave" device, for a total of up to twenty ATA/IDE
63 disk/cdrom/tape/floppy drives.
64
65 Useful information about large (>540 MB) IDE disks, multiple
66 interfaces, what to do if ATA/IDE devices are not automatically
67 detected, sound card ATA/IDE ports, module support, and other
68 topics, is contained in <file:Documentation/ide/ide.txt>. For detailed
69 information about hard drives, consult the Disk-HOWTO and the
70 Multi-Disk-HOWTO, available from
71 <http://www.tldp.org/docs.html#howto>.
72
73 To fine-tune ATA/IDE drive/interface parameters for improved
74 performance, look for the hdparm package at
75 <ftp://ibiblio.org/pub/Linux/system/hardware/>.
76
77 To compile this driver as a module, choose M here and read
78 <file:Documentation/ide/ide.txt>. The module will be called ide-mod.
79 Do not compile this driver as a module if your root file system (the
80 one containing the directory /) is located on an IDE device.
81
82 If you have one or more IDE drives, say Y or M here. If your system
83 has no IDE drives, or if memory requirements are really tight, you
84 could say N here, and select the "Old hard disk driver" below
85 instead to save about 13 KB of memory in the kernel.
86
87if BLK_DEV_IDE
88
89comment "Please see Documentation/ide/ide.txt for help/info on IDE drives" 57comment "Please see Documentation/ide/ide.txt for help/info on IDE drives"
90 58
91config IDE_TIMINGS 59config IDE_TIMINGS
@@ -348,7 +316,7 @@ config BLK_DEV_IDEPCI
348 316
349config IDEPCI_PCIBUS_ORDER 317config IDEPCI_PCIBUS_ORDER
350 bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)" 318 bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)"
351 depends on BLK_DEV_IDE=y && BLK_DEV_IDEPCI 319 depends on IDE=y && BLK_DEV_IDEPCI
352 default y 320 default y
353 help 321 help
354 Probe IDE PCI devices in the order in which they appear on the 322 Probe IDE PCI devices in the order in which they appear on the
@@ -729,7 +697,7 @@ endif
729 697
730config BLK_DEV_IDE_PMAC 698config BLK_DEV_IDE_PMAC
731 tristate "PowerMac on-board IDE support" 699 tristate "PowerMac on-board IDE support"
732 depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y 700 depends on PPC_PMAC && IDE=y
733 select IDE_TIMINGS 701 select IDE_TIMINGS
734 help 702 help
735 This driver provides support for the on-board IDE controller on 703 This driver provides support for the on-board IDE controller on
@@ -963,6 +931,4 @@ config BLK_DEV_IDEDMA
963 def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \ 931 def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \
964 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 932 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
965 933
966endif
967
968endif # IDE 934endif # IDE
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 308b8a12f314..ceaf779054ea 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -5,24 +5,25 @@
5EXTRA_CFLAGS += -Idrivers/ide 5EXTRA_CFLAGS += -Idrivers/ide
6 6
7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ 7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8 ide-taskfile.o ide-pio-blacklist.o 8 ide-taskfile.o ide-park.o ide-pio-blacklist.o
9 9
10# core IDE code 10# core IDE code
11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o 11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o
12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o 12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o
13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o 13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o
14ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o 14ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o
15ide-core-$(CONFIG_BLK_DEV_IDEDMA_SFF) += ide-dma-sff.o
15ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o 16ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o
16ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o 17ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o
17 18
18obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o 19obj-$(CONFIG_IDE) += ide-core.o
19 20
20ifeq ($(CONFIG_IDE_ARM), y) 21ifeq ($(CONFIG_IDE_ARM), y)
21 ide-arm-core-y += arm/ide_arm.o 22 ide-arm-core-y += arm/ide_arm.o
22 obj-y += ide-arm-core.o 23 obj-y += ide-arm-core.o
23endif 24endif
24 25
25obj-$(CONFIG_BLK_DEV_IDE) += legacy/ pci/ 26obj-$(CONFIG_IDE) += legacy/ pci/
26 27
27obj-$(CONFIG_IDEPCI_PCIBUS_ORDER) += ide-scan-pci.o 28obj-$(CONFIG_IDEPCI_PCIBUS_ORDER) += ide-scan-pci.o
28 29
@@ -31,15 +32,21 @@ ifeq ($(CONFIG_BLK_DEV_CMD640), y)
31 obj-y += cmd640-core.o 32 obj-y += cmd640-core.o
32endif 33endif
33 34
34obj-$(CONFIG_BLK_DEV_IDE) += ppc/ 35obj-$(CONFIG_IDE) += ppc/
35obj-$(CONFIG_IDE_H8300) += h8300/ 36obj-$(CONFIG_IDE_H8300) += h8300/
36obj-$(CONFIG_IDE_GENERIC) += ide-generic.o 37obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
37obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 38obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
38 39
40ide-disk_mod-y += ide-disk.o ide-disk_ioctl.o
39ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o 41ide-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 42ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
41 43
42obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o 44ifeq ($(CONFIG_IDE_PROC_FS), y)
45 ide-disk_mod-y += ide-disk_proc.o
46 ide-floppy_mod-y += ide-floppy_proc.o
47endif
48
49obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk_mod.o
43obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o 50obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
44obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o 51obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o
45obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o 52obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o
@@ -54,4 +61,4 @@ ifeq ($(CONFIG_BLK_DEV_PLATFORM), y)
54 obj-y += ide-platform-core.o 61 obj-y += ide-platform-core.o
55endif 62endif
56 63
57obj-$(CONFIG_BLK_DEV_IDE) += arm/ mips/ 64obj-$(CONFIG_IDE) += arm/ mips/
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index 70f5b164828b..76bdc9a27f6f 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -372,25 +372,6 @@ static int icside_dma_test_irq(ide_drive_t *drive)
372 ICS_ARCIN_V6_INTRSTAT_1)) & 1; 372 ICS_ARCIN_V6_INTRSTAT_1)) & 1;
373} 373}
374 374
375static void icside_dma_timeout(ide_drive_t *drive)
376{
377 ide_hwif_t *hwif = drive->hwif;
378
379 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
380
381 if (icside_dma_test_irq(drive))
382 return;
383
384 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
385
386 icside_dma_end(drive);
387}
388
389static void icside_dma_lost_irq(ide_drive_t *drive)
390{
391 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
392}
393
394static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 375static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
395{ 376{
396 hwif->dmatable_cpu = NULL; 377 hwif->dmatable_cpu = NULL;
@@ -406,8 +387,8 @@ static const struct ide_dma_ops icside_v6_dma_ops = {
406 .dma_start = icside_dma_start, 387 .dma_start = icside_dma_start,
407 .dma_end = icside_dma_end, 388 .dma_end = icside_dma_end,
408 .dma_test_irq = icside_dma_test_irq, 389 .dma_test_irq = icside_dma_test_irq,
409 .dma_timeout = icside_dma_timeout, 390 .dma_timeout = ide_dma_timeout,
410 .dma_lost_irq = icside_dma_lost_irq, 391 .dma_lost_irq = ide_dma_lost_irq,
411}; 392};
412#else 393#else
413#define icside_v6_dma_ops NULL 394#define icside_v6_dma_ops NULL
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index bde7a585f198..e2cdd2e9cdec 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -80,7 +80,7 @@ static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task)
80 outb(tf->lbah, io_ports->lbah_addr); 80 outb(tf->lbah, io_ports->lbah_addr);
81 81
82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
83 outb((tf->device & HIHI) | drive->select.all, 83 outb((tf->device & HIHI) | drive->select,
84 io_ports->device_addr); 84 io_ports->device_addr);
85} 85}
86 86
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 2427c380b3dc..244a8a052ce8 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -290,7 +290,7 @@ static int do_drive_get_GTF(ide_drive_t *drive,
290 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n", 290 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
291 hwif->name, dev->bus_id, port, hwif->channel); 291 hwif->name, dev->bus_id, port, hwif->channel);
292 292
293 if (!drive->present) { 293 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) {
294 DEBPRINT("%s drive %d:%d not present\n", 294 DEBPRINT("%s drive %d:%d not present\n",
295 hwif->name, hwif->channel, port); 295 hwif->name, hwif->channel, port);
296 goto out; 296 goto out;
@@ -420,8 +420,9 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
420 420
421 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn); 421 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
422 422
423 if (!drive->present) 423 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
424 goto out; 424 goto out;
425
425 if (!gtf_count) /* shouldn't be here */ 426 if (!gtf_count) /* shouldn't be here */
426 goto out; 427 goto out;
427 428
@@ -660,7 +661,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
660 if (!drive->acpidata->obj_handle) 661 if (!drive->acpidata->obj_handle)
661 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); 662 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
662 663
663 if (drive->acpidata->obj_handle && drive->present) { 664 if (drive->acpidata->obj_handle &&
665 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
664 acpi_bus_set_power(drive->acpidata->obj_handle, 666 acpi_bus_set_power(drive->acpidata->obj_handle,
665 on? ACPI_STATE_D0: ACPI_STATE_D3); 667 on? ACPI_STATE_D0: ACPI_STATE_D3);
666 } 668 }
@@ -720,7 +722,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
720 722
721 memset(drive->acpidata, 0, sizeof(*drive->acpidata)); 723 memset(drive->acpidata, 0, sizeof(*drive->acpidata));
722 724
723 if (!drive->present) 725 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
724 continue; 726 continue;
725 727
726 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff); 728 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
@@ -745,7 +747,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
745 for (i = 0; i < MAX_DRIVES; i++) { 747 for (i = 0; i < MAX_DRIVES; i++) {
746 drive = &hwif->drives[i]; 748 drive = &hwif->drives[i];
747 749
748 if (drive->present) 750 if (drive->dev_flags & IDE_DFLAG_PRESENT)
749 /* Execute ACPI startup code */ 751 /* Execute ACPI startup code */
750 ide_acpi_exec_tfs(drive); 752 ide_acpi_exec_tfs(drive);
751 } 753 }
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 608c5bade929..2e305714c209 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -124,8 +124,8 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
124 * the current request, so that it will be processed immediately, on the next 124 * the current request, so that it will be processed immediately, on the next
125 * pass through the driver. 125 * pass through the driver.
126 */ 126 */
127void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk, 127static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
128 struct ide_atapi_pc *pc, struct request *rq) 128 struct ide_atapi_pc *pc, struct request *rq)
129{ 129{
130 blk_rq_init(NULL, rq); 130 blk_rq_init(NULL, rq);
131 rq->cmd_type = REQ_TYPE_SPECIAL; 131 rq->cmd_type = REQ_TYPE_SPECIAL;
@@ -137,7 +137,6 @@ void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
137 rq->cmd[13] = REQ_IDETAPE_PC1; 137 rq->cmd[13] = REQ_IDETAPE_PC1;
138 ide_do_drive_cmd(drive, rq); 138 ide_do_drive_cmd(drive, rq);
139} 139}
140EXPORT_SYMBOL_GPL(ide_queue_pc_head);
141 140
142/* 141/*
143 * Add a special packet command request to the tail of the request queue, 142 * Add a special packet command request to the tail of the request queue,
@@ -203,25 +202,80 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
203} 202}
204EXPORT_SYMBOL_GPL(ide_set_media_lock); 203EXPORT_SYMBOL_GPL(ide_set_media_lock);
205 204
206/* TODO: unify the code thus making some arguments go away */ 205void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
207ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
208 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
209 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
210 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
211 int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
212{ 206{
207 ide_init_pc(pc);
208 pc->c[0] = REQUEST_SENSE;
209 if (drive->media == ide_floppy) {
210 pc->c[4] = 255;
211 pc->req_xfer = 18;
212 } else {
213 pc->c[4] = 20;
214 pc->req_xfer = 20;
215 }
216}
217EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
218
219/*
220 * Called when an error was detected during the last packet command.
221 * We queue a request sense packet command in the head of the request list.
222 */
223void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
224{
225 struct request *rq = &drive->request_sense_rq;
226 struct ide_atapi_pc *pc = &drive->request_sense_pc;
227
228 (void)ide_read_error(drive);
229 ide_create_request_sense_cmd(drive, pc);
230 if (drive->media == ide_tape)
231 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
232 ide_queue_pc_head(drive, disk, pc, rq);
233}
234EXPORT_SYMBOL_GPL(ide_retry_pc);
235
236int ide_scsi_expiry(ide_drive_t *drive)
237{
238 struct ide_atapi_pc *pc = drive->pc;
239
240 debug_log("%s called for %lu at %lu\n", __func__,
241 pc->scsi_cmd->serial_number, jiffies);
242
243 pc->flags |= PC_FLAG_TIMEDOUT;
244
245 return 0; /* we do not want the IDE subsystem to retry */
246}
247EXPORT_SYMBOL_GPL(ide_scsi_expiry);
248
249/*
250 * This is the usual interrupt handler which will be called during a packet
251 * command. We will transfer some of the data (as requested by the drive)
252 * and will re-point interrupt handler to us.
253 */
254static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
255{
256 struct ide_atapi_pc *pc = drive->pc;
213 ide_hwif_t *hwif = drive->hwif; 257 ide_hwif_t *hwif = drive->hwif;
214 struct request *rq = hwif->hwgroup->rq; 258 struct request *rq = hwif->hwgroup->rq;
215 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 259 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
216 xfer_func_t *xferfunc; 260 xfer_func_t *xferfunc;
217 unsigned int temp; 261 ide_expiry_t *expiry;
262 unsigned int timeout, temp;
218 u16 bcount; 263 u16 bcount;
219 u8 stat, ireason, scsi = drive->scsi; 264 u8 stat, ireason, scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI), dsc = 0;
220 265
221 debug_log("Enter %s - interrupt handler\n", __func__); 266 debug_log("Enter %s - interrupt handler\n", __func__);
222 267
268 if (scsi) {
269 timeout = ide_scsi_get_timeout(pc);
270 expiry = ide_scsi_expiry;
271 } else {
272 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
273 : WAIT_TAPE_CMD;
274 expiry = NULL;
275 }
276
223 if (pc->flags & PC_FLAG_TIMEDOUT) { 277 if (pc->flags & PC_FLAG_TIMEDOUT) {
224 drive->pc_callback(drive); 278 drive->pc_callback(drive, 0);
225 return ide_stopped; 279 return ide_stopped;
226 } 280 }
227 281
@@ -238,8 +292,8 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
238 pc->flags |= PC_FLAG_DMA_ERROR; 292 pc->flags |= PC_FLAG_DMA_ERROR;
239 } else { 293 } else {
240 pc->xferred = pc->req_xfer; 294 pc->xferred = pc->req_xfer;
241 if (update_buffers) 295 if (drive->pc_update_buffers)
242 update_buffers(drive, pc); 296 drive->pc_update_buffers(drive, pc);
243 } 297 }
244 debug_log("%s: DMA finished\n", drive->name); 298 debug_log("%s: DMA finished\n", drive->name);
245 } 299 }
@@ -276,21 +330,19 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
276 debug_log("[cmd %x]: check condition\n", rq->cmd[0]); 330 debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
277 331
278 /* Retry operation */ 332 /* Retry operation */
279 retry_pc(drive); 333 ide_retry_pc(drive, rq->rq_disk);
280 334
281 /* queued, but not started */ 335 /* queued, but not started */
282 return ide_stopped; 336 return ide_stopped;
283 } 337 }
284cmd_finished: 338cmd_finished:
285 pc->error = 0; 339 pc->error = 0;
286 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && 340
287 (stat & ATA_DSC) == 0) { 341 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
288 dsc_handle(drive); 342 dsc = 1;
289 return ide_stopped;
290 }
291 343
292 /* Command finished - Call the callback function */ 344 /* Command finished - Call the callback function */
293 drive->pc_callback(drive); 345 drive->pc_callback(drive, dsc);
294 346
295 return ide_stopped; 347 return ide_stopped;
296 } 348 }
@@ -336,7 +388,8 @@ cmd_finished:
336 temp = 0; 388 temp = 0;
337 if (temp) { 389 if (temp) {
338 if (pc->sg) 390 if (pc->sg)
339 io_buffers(drive, pc, temp, 0); 391 drive->pc_io_buffers(drive, pc,
392 temp, 0);
340 else 393 else
341 tp_ops->input_data(drive, NULL, 394 tp_ops->input_data(drive, NULL,
342 pc->cur_pos, temp); 395 pc->cur_pos, temp);
@@ -348,9 +401,7 @@ cmd_finished:
348 pc->xferred += temp; 401 pc->xferred += temp;
349 pc->cur_pos += temp; 402 pc->cur_pos += temp;
350 ide_pad_transfer(drive, 0, bcount - temp); 403 ide_pad_transfer(drive, 0, bcount - temp);
351 ide_set_handler(drive, handler, timeout, 404 goto next_irq;
352 expiry);
353 return ide_started;
354 } 405 }
355 debug_log("The device wants to send us more data than " 406 debug_log("The device wants to send us more data than "
356 "expected - allowing transfer\n"); 407 "expected - allowing transfer\n");
@@ -362,7 +413,7 @@ cmd_finished:
362 if ((drive->media == ide_floppy && !scsi && !pc->buf) || 413 if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
363 (drive->media == ide_tape && !scsi && pc->bh) || 414 (drive->media == ide_tape && !scsi && pc->bh) ||
364 (scsi && pc->sg)) { 415 (scsi && pc->sg)) {
365 int done = io_buffers(drive, pc, bcount, 416 int done = drive->pc_io_buffers(drive, pc, bcount,
366 !!(pc->flags & PC_FLAG_WRITING)); 417 !!(pc->flags & PC_FLAG_WRITING));
367 418
368 /* FIXME: don't do partial completions */ 419 /* FIXME: don't do partial completions */
@@ -377,12 +428,11 @@ cmd_finished:
377 428
378 debug_log("[cmd %x] transferred %d bytes on that intr.\n", 429 debug_log("[cmd %x] transferred %d bytes on that intr.\n",
379 rq->cmd[0], bcount); 430 rq->cmd[0], bcount);
380 431next_irq:
381 /* And set the interrupt handler again */ 432 /* And set the interrupt handler again */
382 ide_set_handler(drive, handler, timeout, expiry); 433 ide_set_handler(drive, ide_pc_intr, timeout, expiry);
383 return ide_started; 434 return ide_started;
384} 435}
385EXPORT_SYMBOL_GPL(ide_pc_intr);
386 436
387static u8 ide_read_ireason(ide_drive_t *drive) 437static u8 ide_read_ireason(ide_drive_t *drive)
388{ 438{
@@ -418,12 +468,22 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
418 return ireason; 468 return ireason;
419} 469}
420 470
421ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc, 471static int ide_delayed_transfer_pc(ide_drive_t *drive)
422 ide_handler_t *handler, unsigned int timeout,
423 ide_expiry_t *expiry)
424{ 472{
473 /* Send the actual packet */
474 drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
475
476 /* Timeout for the packet command */
477 return WAIT_FLOPPY_CMD;
478}
479
480static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
481{
482 struct ide_atapi_pc *pc = drive->pc;
425 ide_hwif_t *hwif = drive->hwif; 483 ide_hwif_t *hwif = drive->hwif;
426 struct request *rq = hwif->hwgroup->rq; 484 struct request *rq = hwif->hwgroup->rq;
485 ide_expiry_t *expiry;
486 unsigned int timeout;
427 ide_startstop_t startstop; 487 ide_startstop_t startstop;
428 u8 ireason; 488 u8 ireason;
429 489
@@ -434,7 +494,8 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
434 } 494 }
435 495
436 ireason = ide_read_ireason(drive); 496 ireason = ide_read_ireason(drive);
437 if (drive->media == ide_tape && !drive->scsi) 497 if (drive->media == ide_tape &&
498 (drive->dev_flags & IDE_DFLAG_SCSI) == 0)
438 ireason = ide_wait_ireason(drive, ireason); 499 ireason = ide_wait_ireason(drive, ireason);
439 500
440 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) { 501 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
@@ -443,8 +504,27 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
443 return ide_do_reset(drive); 504 return ide_do_reset(drive);
444 } 505 }
445 506
507 /*
508 * If necessary schedule the packet transfer to occur 'timeout'
509 * miliseconds later in ide_delayed_transfer_pc() after the device
510 * says it's ready for a packet.
511 */
512 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
513 timeout = drive->pc_delay;
514 expiry = &ide_delayed_transfer_pc;
515 } else {
516 if (drive->dev_flags & IDE_DFLAG_SCSI) {
517 timeout = ide_scsi_get_timeout(pc);
518 expiry = ide_scsi_expiry;
519 } else {
520 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
521 : WAIT_TAPE_CMD;
522 expiry = NULL;
523 }
524 }
525
446 /* Set the interrupt routine */ 526 /* Set the interrupt routine */
447 ide_set_handler(drive, handler, timeout, expiry); 527 ide_set_handler(drive, ide_pc_intr, timeout, expiry);
448 528
449 /* Begin DMA, if necessary */ 529 /* Begin DMA, if necessary */
450 if (pc->flags & PC_FLAG_DMA_OK) { 530 if (pc->flags & PC_FLAG_DMA_OK) {
@@ -458,22 +538,22 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
458 538
459 return ide_started; 539 return ide_started;
460} 540}
461EXPORT_SYMBOL_GPL(ide_transfer_pc);
462 541
463ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc, 542ide_startstop_t ide_issue_pc(ide_drive_t *drive, unsigned int timeout,
464 ide_handler_t *handler, unsigned int timeout,
465 ide_expiry_t *expiry) 543 ide_expiry_t *expiry)
466{ 544{
545 struct ide_atapi_pc *pc = drive->pc;
467 ide_hwif_t *hwif = drive->hwif; 546 ide_hwif_t *hwif = drive->hwif;
547 u32 tf_flags;
468 u16 bcount; 548 u16 bcount;
469 u8 dma = 0; 549 u8 scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI);
470 550
471 /* We haven't transferred any data yet */ 551 /* We haven't transferred any data yet */
472 pc->xferred = 0; 552 pc->xferred = 0;
473 pc->cur_pos = pc->buf; 553 pc->cur_pos = pc->buf;
474 554
475 /* Request to transfer the entire buffer at once */ 555 /* Request to transfer the entire buffer at once */
476 if (drive->media == ide_tape && !drive->scsi) 556 if (drive->media == ide_tape && scsi == 0)
477 bcount = pc->req_xfer; 557 bcount = pc->req_xfer;
478 else 558 else
479 bcount = min(pc->req_xfer, 63 * 1024); 559 bcount = min(pc->req_xfer, 63 * 1024);
@@ -483,28 +563,35 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
483 ide_dma_off(drive); 563 ide_dma_off(drive);
484 } 564 }
485 565
486 if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma) { 566 if ((pc->flags & PC_FLAG_DMA_OK) &&
487 if (drive->scsi) 567 (drive->dev_flags & IDE_DFLAG_USING_DMA)) {
568 if (scsi)
488 hwif->sg_mapped = 1; 569 hwif->sg_mapped = 1;
489 dma = !hwif->dma_ops->dma_setup(drive); 570 drive->dma = !hwif->dma_ops->dma_setup(drive);
490 if (drive->scsi) 571 if (scsi)
491 hwif->sg_mapped = 0; 572 hwif->sg_mapped = 0;
492 } 573 }
493 574
494 if (!dma) 575 if (!drive->dma)
495 pc->flags &= ~PC_FLAG_DMA_OK; 576 pc->flags &= ~PC_FLAG_DMA_OK;
496 577
497 ide_pktcmd_tf_load(drive, drive->scsi ? 0 : IDE_TFLAG_OUT_DEVICE, 578 if (scsi)
498 bcount, dma); 579 tf_flags = 0;
580 else if (drive->media == ide_cdrom || drive->media == ide_optical)
581 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
582 else
583 tf_flags = IDE_TFLAG_OUT_DEVICE;
584
585 ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);
499 586
500 /* Issue the packet command */ 587 /* Issue the packet command */
501 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 588 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
502 ide_execute_command(drive, ATA_CMD_PACKET, handler, 589 ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc,
503 timeout, NULL); 590 timeout, NULL);
504 return ide_started; 591 return ide_started;
505 } else { 592 } else {
506 ide_execute_pkt_cmd(drive); 593 ide_execute_pkt_cmd(drive);
507 return (*handler)(drive); 594 return ide_transfer_pc(drive);
508 } 595 }
509} 596}
510EXPORT_SYMBOL_GPL(ide_issue_pc); 597EXPORT_SYMBOL_GPL(ide_issue_pc);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 465a92ca0179..3308b1cd3a33 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -23,6 +23,9 @@
23 * Documentation/ide/ChangeLog.ide-cd.1994-2004 23 * Documentation/ide/ChangeLog.ide-cd.1994-2004
24 */ 24 */
25 25
26#define DRV_NAME "ide-cd"
27#define PFX DRV_NAME ": "
28
26#define IDECD_VERSION "5.00" 29#define IDECD_VERSION "5.00"
27 30
28#include <linux/module.h> 31#include <linux/module.h>
@@ -50,12 +53,15 @@
50 53
51#include "ide-cd.h" 54#include "ide-cd.h"
52 55
53static DEFINE_MUTEX(idecd_ref_mutex); 56#define IDECD_DEBUG_LOG 1
54 57
55#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) 58#if IDECD_DEBUG_LOG
59#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
60#else
61#define ide_debug_log(lvl, fmt, args...) do {} while (0)
62#endif
56 63
57#define ide_cd_g(disk) \ 64static DEFINE_MUTEX(idecd_ref_mutex);
58 container_of((disk)->private_data, struct cdrom_info, driver)
59 65
60static void ide_cd_release(struct kref *); 66static void ide_cd_release(struct kref *);
61 67
@@ -64,7 +70,7 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
64 struct cdrom_info *cd = NULL; 70 struct cdrom_info *cd = NULL;
65 71
66 mutex_lock(&idecd_ref_mutex); 72 mutex_lock(&idecd_ref_mutex);
67 cd = ide_cd_g(disk); 73 cd = ide_drv_g(disk, cdrom_info);
68 if (cd) { 74 if (cd) {
69 if (ide_device_get(cd->drive)) 75 if (ide_device_get(cd->drive))
70 cd = NULL; 76 cd = NULL;
@@ -102,6 +108,9 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
102{ 108{
103 int log = 0; 109 int log = 0;
104 110
111 ide_debug_log(IDE_DBG_SENSE, "Call %s, sense_key: 0x%x\n", __func__,
112 sense->sense_key);
113
105 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) 114 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
106 return 0; 115 return 0;
107 116
@@ -150,6 +159,14 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
150 unsigned long bio_sectors; 159 unsigned long bio_sectors;
151 struct cdrom_info *info = drive->driver_data; 160 struct cdrom_info *info = drive->driver_data;
152 161
162 ide_debug_log(IDE_DBG_SENSE, "Call %s, error_code: 0x%x, "
163 "sense_key: 0x%x\n", __func__, sense->error_code,
164 sense->sense_key);
165
166 if (failed_command)
167 ide_debug_log(IDE_DBG_SENSE, "%s: failed cmd: 0x%x\n",
168 __func__, failed_command->cmd[0]);
169
153 if (!cdrom_log_sense(drive, failed_command, sense)) 170 if (!cdrom_log_sense(drive, failed_command, sense))
154 return; 171 return;
155 172
@@ -200,6 +217,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
200 struct cdrom_info *info = drive->driver_data; 217 struct cdrom_info *info = drive->driver_data;
201 struct request *rq = &info->request_sense_request; 218 struct request *rq = &info->request_sense_request;
202 219
220 ide_debug_log(IDE_DBG_SENSE, "Call %s\n", __func__);
221
203 if (sense == NULL) 222 if (sense == NULL)
204 sense = &info->sense_data; 223 sense = &info->sense_data;
205 224
@@ -219,6 +238,10 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
219 /* NOTE! Save the failed command in "rq->buffer" */ 238 /* NOTE! Save the failed command in "rq->buffer" */
220 rq->buffer = (void *) failed_command; 239 rq->buffer = (void *) failed_command;
221 240
241 if (failed_command)
242 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n",
243 failed_command->cmd[0]);
244
222 ide_do_drive_cmd(drive, rq); 245 ide_do_drive_cmd(drive, rq);
223} 246}
224 247
@@ -227,6 +250,10 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
227 struct request *rq = HWGROUP(drive)->rq; 250 struct request *rq = HWGROUP(drive)->rq;
228 int nsectors = rq->hard_cur_sectors; 251 int nsectors = rq->hard_cur_sectors;
229 252
253 ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, "
254 "nsectors: %d\n", __func__, rq->cmd[0], uptodate,
255 nsectors);
256
230 if (blk_sense_request(rq) && uptodate) { 257 if (blk_sense_request(rq) && uptodate) {
231 /* 258 /*
232 * For REQ_TYPE_SENSE, "rq->buffer" points to the original 259 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
@@ -269,6 +296,9 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
269 if (!nsectors) 296 if (!nsectors)
270 nsectors = 1; 297 nsectors = 1;
271 298
299 ide_debug_log(IDE_DBG_FUNC, "Exit %s, uptodate: 0x%x, nsectors: %d\n",
300 __func__, uptodate, nsectors);
301
272 ide_end_request(drive, uptodate, nsectors); 302 ide_end_request(drive, uptodate, nsectors);
273} 303}
274 304
@@ -304,11 +334,15 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
304 sense_key = err >> 4; 334 sense_key = err >> 4;
305 335
306 if (rq == NULL) { 336 if (rq == NULL) {
307 printk(KERN_ERR "%s: missing rq in %s\n", 337 printk(KERN_ERR PFX "%s: missing rq in %s\n",
308 drive->name, __func__); 338 drive->name, __func__);
309 return 1; 339 return 1;
310 } 340 }
311 341
342 ide_debug_log(IDE_DBG_RQ, "%s: stat: 0x%x, good_stat: 0x%x, "
343 "rq->cmd_type: 0x%x, err: 0x%x\n", __func__, stat,
344 good_stat, rq->cmd_type, err);
345
312 if (blk_sense_request(rq)) { 346 if (blk_sense_request(rq)) {
313 /* 347 /*
314 * We got an error trying to get sense info from the drive 348 * We got an error trying to get sense info from the drive
@@ -374,7 +408,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
374 cdrom_saw_media_change(drive); 408 cdrom_saw_media_change(drive);
375 409
376 /* fail the request */ 410 /* fail the request */
377 printk(KERN_ERR "%s: tray open\n", drive->name); 411 printk(KERN_ERR PFX "%s: tray open\n",
412 drive->name);
378 do_end_request = 1; 413 do_end_request = 1;
379 } else { 414 } else {
380 struct cdrom_info *info = drive->driver_data; 415 struct cdrom_info *info = drive->driver_data;
@@ -460,7 +495,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
460 if (stat & ATA_ERR) 495 if (stat & ATA_ERR)
461 cdrom_queue_request_sense(drive, NULL, NULL); 496 cdrom_queue_request_sense(drive, NULL, NULL);
462 } else { 497 } else {
463 blk_dump_rq_flags(rq, "ide-cd: bad rq"); 498 blk_dump_rq_flags(rq, PFX "bad rq");
464 cdrom_end_request(drive, 0); 499 cdrom_end_request(drive, 0);
465 } 500 }
466 501
@@ -488,6 +523,9 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
488 struct request *rq = HWGROUP(drive)->rq; 523 struct request *rq = HWGROUP(drive)->rq;
489 unsigned long wait = 0; 524 unsigned long wait = 0;
490 525
526 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd[0]: 0x%x\n", __func__,
527 rq->cmd[0]);
528
491 /* 529 /*
492 * Some commands are *slow* and normally take a long time to complete. 530 * Some commands are *slow* and normally take a long time to complete.
493 * Usually we can use the ATAPI "disconnect" to bypass this, but not all 531 * Usually we can use the ATAPI "disconnect" to bypass this, but not all
@@ -504,7 +542,7 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
504 break; 542 break;
505 default: 543 default:
506 if (!(rq->cmd_flags & REQ_QUIET)) 544 if (!(rq->cmd_flags & REQ_QUIET))
507 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", 545 printk(KERN_INFO PFX "cmd 0x%x timed out\n",
508 rq->cmd[0]); 546 rq->cmd[0]);
509 wait = 0; 547 wait = 0;
510 break; 548 break;
@@ -524,20 +562,21 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
524 int xferlen, 562 int xferlen,
525 ide_handler_t *handler) 563 ide_handler_t *handler)
526{ 564{
527 struct cdrom_info *info = drive->driver_data;
528 ide_hwif_t *hwif = drive->hwif; 565 ide_hwif_t *hwif = drive->hwif;
529 566
567 ide_debug_log(IDE_DBG_PC, "Call %s, xferlen: %d\n", __func__, xferlen);
568
530 /* FIXME: for Virtual DMA we must check harder */ 569 /* FIXME: for Virtual DMA we must check harder */
531 if (info->dma) 570 if (drive->dma)
532 info->dma = !hwif->dma_ops->dma_setup(drive); 571 drive->dma = !hwif->dma_ops->dma_setup(drive);
533 572
534 /* set up the controller registers */ 573 /* set up the controller registers */
535 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL, 574 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL,
536 xferlen, info->dma); 575 xferlen, drive->dma);
537 576
538 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 577 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
539 /* waiting for CDB interrupt, not DMA yet. */ 578 /* waiting for CDB interrupt, not DMA yet. */
540 if (info->dma) 579 if (drive->dma)
541 drive->waiting_for_dma = 0; 580 drive->waiting_for_dma = 0;
542 581
543 /* packet command */ 582 /* packet command */
@@ -564,9 +603,10 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
564{ 603{
565 ide_hwif_t *hwif = drive->hwif; 604 ide_hwif_t *hwif = drive->hwif;
566 int cmd_len; 605 int cmd_len;
567 struct cdrom_info *info = drive->driver_data;
568 ide_startstop_t startstop; 606 ide_startstop_t startstop;
569 607
608 ide_debug_log(IDE_DBG_PC, "Call %s\n", __func__);
609
570 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 610 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
571 /* 611 /*
572 * Here we should have been called after receiving an interrupt 612 * Here we should have been called after receiving an interrupt
@@ -578,7 +618,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
578 return ide_stopped; 618 return ide_stopped;
579 619
580 /* ok, next interrupt will be DMA interrupt */ 620 /* ok, next interrupt will be DMA interrupt */
581 if (info->dma) 621 if (drive->dma)
582 drive->waiting_for_dma = 1; 622 drive->waiting_for_dma = 1;
583 } else { 623 } else {
584 /* otherwise, we must wait for DRQ to get set */ 624 /* otherwise, we must wait for DRQ to get set */
@@ -599,7 +639,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
599 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len); 639 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
600 640
601 /* start the DMA if need be */ 641 /* start the DMA if need be */
602 if (info->dma) 642 if (drive->dma)
603 hwif->dma_ops->dma_start(drive); 643 hwif->dma_ops->dma_start(drive);
604 644
605 return ide_started; 645 return ide_started;
@@ -615,6 +655,9 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
615{ 655{
616 ide_hwif_t *hwif = drive->hwif; 656 ide_hwif_t *hwif = drive->hwif;
617 657
658 ide_debug_log(IDE_DBG_FUNC, "Call %s, ireason: 0x%x, rw: 0x%x\n",
659 __func__, ireason, rw);
660
618 /* 661 /*
619 * ireason == 0: the drive wants to receive data from us 662 * ireason == 0: the drive wants to receive data from us
620 * ireason == 2: the drive is expecting to transfer data to us 663 * ireason == 2: the drive is expecting to transfer data to us
@@ -624,7 +667,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
624 else if (ireason == (rw << 1)) { 667 else if (ireason == (rw << 1)) {
625 668
626 /* whoops... */ 669 /* whoops... */
627 printk(KERN_ERR "%s: %s: wrong transfer direction!\n", 670 printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
628 drive->name, __func__); 671 drive->name, __func__);
629 672
630 ide_pad_transfer(drive, rw, len); 673 ide_pad_transfer(drive, rw, len);
@@ -637,7 +680,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
637 return 0; 680 return 0;
638 } else { 681 } else {
639 /* drive wants a command packet, or invalid ireason... */ 682 /* drive wants a command packet, or invalid ireason... */
640 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", 683 printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
641 drive->name, __func__, ireason); 684 drive->name, __func__, ireason);
642 } 685 }
643 686
@@ -654,17 +697,19 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
654 */ 697 */
655static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) 698static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
656{ 699{
700 ide_debug_log(IDE_DBG_FUNC, "Call %s, len: %d\n", __func__, len);
701
657 if ((len % SECTOR_SIZE) == 0) 702 if ((len % SECTOR_SIZE) == 0)
658 return 0; 703 return 0;
659 704
660 printk(KERN_ERR "%s: %s: Bad transfer size %d\n", 705 printk(KERN_ERR PFX "%s: %s: Bad transfer size %d\n", drive->name,
661 drive->name, __func__, len); 706 __func__, len);
662 707
663 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES) 708 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES)
664 printk(KERN_ERR " This drive is not supported by " 709 printk(KERN_ERR PFX "This drive is not supported by this "
665 "this version of the driver\n"); 710 "version of the driver\n");
666 else { 711 else {
667 printk(KERN_ERR " Trying to limit transfer sizes\n"); 712 printk(KERN_ERR PFX "Trying to limit transfer sizes\n");
668 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES; 713 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES;
669 } 714 }
670 715
@@ -676,6 +721,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
676static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, 721static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
677 struct request *rq) 722 struct request *rq)
678{ 723{
724 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd_flags: 0x%x\n", __func__,
725 rq->cmd_flags);
726
679 if (rq_data_dir(rq) == READ) { 727 if (rq_data_dir(rq) == READ) {
680 unsigned short sectors_per_frame = 728 unsigned short sectors_per_frame =
681 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 729 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
@@ -695,7 +743,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
695 /* sanity check... */ 743 /* sanity check... */
696 if (rq->current_nr_sectors != 744 if (rq->current_nr_sectors !=
697 bio_cur_sectors(rq->bio)) { 745 bio_cur_sectors(rq->bio)) {
698 printk(KERN_ERR "%s: %s: buffer botch (%u)\n", 746 printk(KERN_ERR PFX "%s: %s: buffer botch (%u)\n",
699 drive->name, __func__, 747 drive->name, __func__,
700 rq->current_nr_sectors); 748 rq->current_nr_sectors);
701 cdrom_end_request(drive, 0); 749 cdrom_end_request(drive, 0);
@@ -704,11 +752,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
704 rq->current_nr_sectors += nskip; 752 rq->current_nr_sectors += nskip;
705 } 753 }
706 } 754 }
707#if 0 755
708 else
709 /* the immediate bit */
710 rq->cmd[1] = 1 << 3;
711#endif
712 /* set up the command */ 756 /* set up the command */
713 rq->timeout = ATAPI_WAIT_PC; 757 rq->timeout = ATAPI_WAIT_PC;
714 758
@@ -739,6 +783,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
739 int stat; 783 int stat;
740 static int retry = 10; 784 static int retry = 10;
741 785
786 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
787
742 if (cdrom_decode_status(drive, 0, &stat)) 788 if (cdrom_decode_status(drive, 0, &stat))
743 return ide_stopped; 789 return ide_stopped;
744 790
@@ -746,7 +792,7 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
746 792
747 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { 793 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) {
748 if (--retry == 0) 794 if (--retry == 0)
749 drive->dsc_overlap = 0; 795 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
750 } 796 }
751 return ide_stopped; 797 return ide_stopped;
752} 798}
@@ -755,6 +801,8 @@ static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq)
755{ 801{
756 sector_t frame = rq->sector; 802 sector_t frame = rq->sector;
757 803
804 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
805
758 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); 806 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
759 807
760 memset(rq->cmd, 0, BLK_MAX_CDB); 808 memset(rq->cmd, 0, BLK_MAX_CDB);
@@ -775,8 +823,11 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
775 * Fix up a possibly partially-processed request so that we can start it over 823 * Fix up a possibly partially-processed request so that we can start it over
776 * entirely, or even put it back on the request queue. 824 * entirely, or even put it back on the request queue.
777 */ 825 */
778static void restore_request(struct request *rq) 826static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
779{ 827{
828
829 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
830
780 if (rq->buffer != bio_data(rq->bio)) { 831 if (rq->buffer != bio_data(rq->bio)) {
781 sector_t n = 832 sector_t n =
782 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE; 833 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE;
@@ -795,8 +846,11 @@ static void restore_request(struct request *rq)
795/* 846/*
796 * All other packet commands. 847 * All other packet commands.
797 */ 848 */
798static void ide_cd_request_sense_fixup(struct request *rq) 849static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
799{ 850{
851
852 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
853
800 /* 854 /*
801 * Some of the trailing request sense fields are optional, 855 * Some of the trailing request sense fields are optional,
802 * and some drives don't send them. Sigh. 856 * and some drives don't send them. Sigh.
@@ -822,6 +876,10 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
822 if (!sense) 876 if (!sense)
823 sense = &local_sense; 877 sense = &local_sense;
824 878
879 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x, "
880 "timeout: %d, cmd_flags: 0x%x\n", __func__, cmd[0], write,
881 timeout, cmd_flags);
882
825 /* start of retry loop */ 883 /* start of retry loop */
826 do { 884 do {
827 struct request *rq; 885 struct request *rq;
@@ -895,7 +953,6 @@ static int cdrom_newpc_intr_dummy_cb(struct request *rq)
895static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 953static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
896{ 954{
897 ide_hwif_t *hwif = drive->hwif; 955 ide_hwif_t *hwif = drive->hwif;
898 struct cdrom_info *info = drive->driver_data;
899 struct request *rq = HWGROUP(drive)->rq; 956 struct request *rq = HWGROUP(drive)->rq;
900 xfer_func_t *xferfunc; 957 xfer_func_t *xferfunc;
901 ide_expiry_t *expiry = NULL; 958 ide_expiry_t *expiry = NULL;
@@ -905,13 +962,16 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
905 u16 len; 962 u16 len;
906 u8 ireason; 963 u8 ireason;
907 964
965 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x\n",
966 __func__, rq->cmd[0], write);
967
908 /* check for errors */ 968 /* check for errors */
909 dma = info->dma; 969 dma = drive->dma;
910 if (dma) { 970 if (dma) {
911 info->dma = 0; 971 drive->dma = 0;
912 dma_error = hwif->dma_ops->dma_end(drive); 972 dma_error = hwif->dma_ops->dma_end(drive);
913 if (dma_error) { 973 if (dma_error) {
914 printk(KERN_ERR "%s: DMA %s error\n", drive->name, 974 printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name,
915 write ? "write" : "read"); 975 write ? "write" : "read");
916 ide_dma_off(drive); 976 ide_dma_off(drive);
917 } 977 }
@@ -937,6 +997,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
937 if (thislen > len) 997 if (thislen > len)
938 thislen = len; 998 thislen = len;
939 999
1000 ide_debug_log(IDE_DBG_PC, "%s: DRQ: stat: 0x%x, thislen: %d\n",
1001 __func__, stat, thislen);
1002
940 /* If DRQ is clear, the command has completed. */ 1003 /* If DRQ is clear, the command has completed. */
941 if ((stat & ATA_DRQ) == 0) { 1004 if ((stat & ATA_DRQ) == 0) {
942 if (blk_fs_request(rq)) { 1005 if (blk_fs_request(rq)) {
@@ -946,7 +1009,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
946 */ 1009 */
947 uptodate = 1; 1010 uptodate = 1;
948 if (rq->current_nr_sectors > 0) { 1011 if (rq->current_nr_sectors > 0) {
949 printk(KERN_ERR "%s: %s: data underrun " 1012 printk(KERN_ERR PFX "%s: %s: data underrun "
950 "(%d blocks)\n", 1013 "(%d blocks)\n",
951 drive->name, __func__, 1014 drive->name, __func__,
952 rq->current_nr_sectors); 1015 rq->current_nr_sectors);
@@ -957,7 +1020,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
957 cdrom_end_request(drive, uptodate); 1020 cdrom_end_request(drive, uptodate);
958 return ide_stopped; 1021 return ide_stopped;
959 } else if (!blk_pc_request(rq)) { 1022 } else if (!blk_pc_request(rq)) {
960 ide_cd_request_sense_fixup(rq); 1023 ide_cd_request_sense_fixup(drive, rq);
961 /* complain if we still have data left to transfer */ 1024 /* complain if we still have data left to transfer */
962 uptodate = rq->data_len ? 0 : 1; 1025 uptodate = rq->data_len ? 0 : 1;
963 } 1026 }
@@ -1000,6 +1063,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1000 xferfunc = hwif->tp_ops->input_data; 1063 xferfunc = hwif->tp_ops->input_data;
1001 } 1064 }
1002 1065
1066 ide_debug_log(IDE_DBG_PC, "%s: data transfer, rq->cmd_type: 0x%x, "
1067 "ireason: 0x%x\n", __func__, rq->cmd_type, ireason);
1068
1003 /* transfer data */ 1069 /* transfer data */
1004 while (thislen > 0) { 1070 while (thislen > 0) {
1005 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; 1071 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data;
@@ -1024,7 +1090,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1024 */ 1090 */
1025 ide_pad_transfer(drive, 0, thislen); 1091 ide_pad_transfer(drive, 0, thislen);
1026 else { 1092 else {
1027 printk(KERN_ERR "%s: confused, missing data\n", 1093 printk(KERN_ERR PFX "%s: confused, missing data\n",
1028 drive->name); 1094 drive->name);
1029 blk_dump_rq_flags(rq, rq_data_dir(rq) 1095 blk_dump_rq_flags(rq, rq_data_dir(rq)
1030 ? "cdrom_newpc_intr, write" 1096 ? "cdrom_newpc_intr, write"
@@ -1111,6 +1177,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1111 unsigned short sectors_per_frame = 1177 unsigned short sectors_per_frame =
1112 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 1178 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
1113 1179
1180 ide_debug_log(IDE_DBG_RQ, "Call %s, write: 0x%x, secs_per_frame: %u\n",
1181 __func__, write, sectors_per_frame);
1182
1114 if (write) { 1183 if (write) {
1115 /* disk has become write protected */ 1184 /* disk has become write protected */
1116 if (get_disk_ro(cd->disk)) { 1185 if (get_disk_ro(cd->disk)) {
@@ -1122,7 +1191,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1122 * We may be retrying this request after an error. Fix up any 1191 * We may be retrying this request after an error. Fix up any
1123 * weirdness which might be present in the request packet. 1192 * weirdness which might be present in the request packet.
1124 */ 1193 */
1125 restore_request(rq); 1194 ide_cd_restore_request(drive, rq);
1126 } 1195 }
1127 1196
1128 /* use DMA, if possible / writes *must* be hardware frame aligned */ 1197 /* use DMA, if possible / writes *must* be hardware frame aligned */
@@ -1132,9 +1201,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1132 cdrom_end_request(drive, 0); 1201 cdrom_end_request(drive, 0);
1133 return ide_stopped; 1202 return ide_stopped;
1134 } 1203 }
1135 cd->dma = 0; 1204 drive->dma = 0;
1136 } else 1205 } else
1137 cd->dma = drive->using_dma; 1206 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1138 1207
1139 if (write) 1208 if (write)
1140 cd->devinfo.media_written = 1; 1209 cd->devinfo.media_written = 1;
@@ -1151,14 +1220,16 @@ static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
1151 1220
1152static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) 1221static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1153{ 1222{
1154 struct cdrom_info *info = drive->driver_data; 1223
1224 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd_type: 0x%x\n", __func__,
1225 rq->cmd_type);
1155 1226
1156 if (blk_pc_request(rq)) 1227 if (blk_pc_request(rq))
1157 rq->cmd_flags |= REQ_QUIET; 1228 rq->cmd_flags |= REQ_QUIET;
1158 else 1229 else
1159 rq->cmd_flags &= ~REQ_FAILED; 1230 rq->cmd_flags &= ~REQ_FAILED;
1160 1231
1161 info->dma = 0; 1232 drive->dma = 0;
1162 1233
1163 /* sg request */ 1234 /* sg request */
1164 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { 1235 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) {
@@ -1171,7 +1242,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1171 else 1242 else
1172 buf = rq->data; 1243 buf = rq->data;
1173 1244
1174 info->dma = drive->using_dma; 1245 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1175 1246
1176 /* 1247 /*
1177 * check if dma is safe 1248 * check if dma is safe
@@ -1182,7 +1253,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1182 alignment = queue_dma_alignment(q) | q->dma_pad_mask; 1253 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1183 if ((unsigned long)buf & alignment || rq->data_len & alignment 1254 if ((unsigned long)buf & alignment || rq->data_len & alignment
1184 || object_is_on_stack(buf)) 1255 || object_is_on_stack(buf))
1185 info->dma = 0; 1256 drive->dma = 0;
1186 } 1257 }
1187} 1258}
1188 1259
@@ -1196,6 +1267,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1196 ide_handler_t *fn; 1267 ide_handler_t *fn;
1197 int xferlen; 1268 int xferlen;
1198 1269
1270 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd_type: 0x%x, block: %llu\n",
1271 __func__, rq->cmd_type, (unsigned long long)block);
1272
1199 if (blk_fs_request(rq)) { 1273 if (blk_fs_request(rq)) {
1200 if (drive->atapi_flags & IDE_AFLAG_SEEKING) { 1274 if (drive->atapi_flags & IDE_AFLAG_SEEKING) {
1201 ide_hwif_t *hwif = drive->hwif; 1275 ide_hwif_t *hwif = drive->hwif;
@@ -1208,7 +1282,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1208 IDECD_SEEK_TIMER); 1282 IDECD_SEEK_TIMER);
1209 return ide_stopped; 1283 return ide_stopped;
1210 } 1284 }
1211 printk(KERN_ERR "%s: DSC timeout\n", 1285 printk(KERN_ERR PFX "%s: DSC timeout\n",
1212 drive->name); 1286 drive->name);
1213 } 1287 }
1214 drive->atapi_flags &= ~IDE_AFLAG_SEEKING; 1288 drive->atapi_flags &= ~IDE_AFLAG_SEEKING;
@@ -1216,11 +1290,11 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1216 if (rq_data_dir(rq) == READ && 1290 if (rq_data_dir(rq) == READ &&
1217 IDE_LARGE_SEEK(info->last_block, block, 1291 IDE_LARGE_SEEK(info->last_block, block,
1218 IDECD_SEEK_THRESHOLD) && 1292 IDECD_SEEK_THRESHOLD) &&
1219 drive->dsc_overlap) { 1293 (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)) {
1220 xferlen = 0; 1294 xferlen = 0;
1221 fn = cdrom_start_seek_continuation; 1295 fn = cdrom_start_seek_continuation;
1222 1296
1223 info->dma = 0; 1297 drive->dma = 0;
1224 info->start_seek = jiffies; 1298 info->start_seek = jiffies;
1225 1299
1226 ide_cd_prepare_seek_request(drive, rq); 1300 ide_cd_prepare_seek_request(drive, rq);
@@ -1249,7 +1323,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1249 cdrom_end_request(drive, 1); 1323 cdrom_end_request(drive, 1);
1250 return ide_stopped; 1324 return ide_stopped;
1251 } else { 1325 } else {
1252 blk_dump_rq_flags(rq, "ide-cd bad flags"); 1326 blk_dump_rq_flags(rq, DRV_NAME " bad flags");
1253 cdrom_end_request(drive, 0); 1327 cdrom_end_request(drive, 0);
1254 return ide_stopped; 1328 return ide_stopped;
1255 } 1329 }
@@ -1279,6 +1353,8 @@ int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
1279 struct cdrom_device_info *cdi = &info->devinfo; 1353 struct cdrom_device_info *cdi = &info->devinfo;
1280 unsigned char cmd[BLK_MAX_CDB]; 1354 unsigned char cmd[BLK_MAX_CDB];
1281 1355
1356 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1357
1282 memset(cmd, 0, BLK_MAX_CDB); 1358 memset(cmd, 0, BLK_MAX_CDB);
1283 cmd[0] = GPCMD_TEST_UNIT_READY; 1359 cmd[0] = GPCMD_TEST_UNIT_READY;
1284 1360
@@ -1305,6 +1381,8 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1305 unsigned len = sizeof(capbuf); 1381 unsigned len = sizeof(capbuf);
1306 u32 blocklen; 1382 u32 blocklen;
1307 1383
1384 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1385
1308 memset(cmd, 0, BLK_MAX_CDB); 1386 memset(cmd, 0, BLK_MAX_CDB);
1309 cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1387 cmd[0] = GPCMD_READ_CDVD_CAPACITY;
1310 1388
@@ -1324,10 +1402,10 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1324 case 4096: 1402 case 4096:
1325 break; 1403 break;
1326 default: 1404 default:
1327 printk(KERN_ERR "%s: weird block size %u\n", 1405 printk(KERN_ERR PFX "%s: weird block size %u\n",
1328 drive->name, blocklen); 1406 drive->name, blocklen);
1329 printk(KERN_ERR "%s: default to 2kb block size\n", 1407 printk(KERN_ERR PFX "%s: default to 2kb block size\n",
1330 drive->name); 1408 drive->name);
1331 blocklen = 2048; 1409 blocklen = 2048;
1332 break; 1410 break;
1333 } 1411 }
@@ -1343,6 +1421,8 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
1343{ 1421{
1344 unsigned char cmd[BLK_MAX_CDB]; 1422 unsigned char cmd[BLK_MAX_CDB];
1345 1423
1424 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1425
1346 memset(cmd, 0, BLK_MAX_CDB); 1426 memset(cmd, 0, BLK_MAX_CDB);
1347 1427
1348 cmd[0] = GPCMD_READ_TOC_PMA_ATIP; 1428 cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
@@ -1371,11 +1451,13 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1371 long last_written; 1451 long last_written;
1372 unsigned long sectors_per_frame = SECTORS_PER_FRAME; 1452 unsigned long sectors_per_frame = SECTORS_PER_FRAME;
1373 1453
1454 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1455
1374 if (toc == NULL) { 1456 if (toc == NULL) {
1375 /* try to allocate space */ 1457 /* try to allocate space */
1376 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); 1458 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
1377 if (toc == NULL) { 1459 if (toc == NULL) {
1378 printk(KERN_ERR "%s: No cdrom TOC buffer!\n", 1460 printk(KERN_ERR PFX "%s: No cdrom TOC buffer!\n",
1379 drive->name); 1461 drive->name);
1380 return -ENOMEM; 1462 return -ENOMEM;
1381 } 1463 }
@@ -1531,6 +1613,8 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
1531 struct packet_command cgc; 1613 struct packet_command cgc;
1532 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE; 1614 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
1533 1615
1616 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1617
1534 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) 1618 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0)
1535 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; 1619 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
1536 1620
@@ -1549,6 +1633,8 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1549 struct cdrom_info *cd = drive->driver_data; 1633 struct cdrom_info *cd = drive->driver_data;
1550 u16 curspeed, maxspeed; 1634 u16 curspeed, maxspeed;
1551 1635
1636 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1637
1552 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { 1638 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) {
1553 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]); 1639 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]);
1554 maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]); 1640 maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]);
@@ -1589,6 +1675,8 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
1589 struct cdrom_info *info = drive->driver_data; 1675 struct cdrom_info *info = drive->driver_data;
1590 struct cdrom_device_info *devinfo = &info->devinfo; 1676 struct cdrom_device_info *devinfo = &info->devinfo;
1591 1677
1678 ide_debug_log(IDE_DBG_PROBE, "Call %s, nslots: %d\n", __func__, nslots);
1679
1592 devinfo->ops = &ide_cdrom_dops; 1680 devinfo->ops = &ide_cdrom_dops;
1593 devinfo->speed = info->current_speed; 1681 devinfo->speed = info->current_speed;
1594 devinfo->capacity = nslots; 1682 devinfo->capacity = nslots;
@@ -1610,13 +1698,17 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1610 mechtype_t mechtype; 1698 mechtype_t mechtype;
1611 int nslots = 1; 1699 int nslots = 1;
1612 1700
1701 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->media: 0x%x, "
1702 "drive->atapi_flags: 0x%lx\n", __func__, drive->media,
1703 drive->atapi_flags);
1704
1613 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | 1705 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
1614 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO | 1706 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
1615 CDC_MO_DRIVE | CDC_RAM); 1707 CDC_MO_DRIVE | CDC_RAM);
1616 1708
1617 if (drive->media == ide_optical) { 1709 if (drive->media == ide_optical) {
1618 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); 1710 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
1619 printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", 1711 printk(KERN_ERR PFX "%s: ATAPI magneto-optical drive\n",
1620 drive->name); 1712 drive->name);
1621 return nslots; 1713 return nslots;
1622 } 1714 }
@@ -1674,7 +1766,7 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1674 1766
1675 ide_cdrom_update_speed(drive, buf); 1767 ide_cdrom_update_speed(drive, buf);
1676 1768
1677 printk(KERN_INFO "%s: ATAPI", drive->name); 1769 printk(KERN_INFO PFX "%s: ATAPI", drive->name);
1678 1770
1679 /* don't print speed if the drive reported 0 */ 1771 /* don't print speed if the drive reported 0 */
1680 if (cd->max_speed) 1772 if (cd->max_speed)
@@ -1697,7 +1789,8 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1697 else 1789 else
1698 printk(KERN_CONT " drive"); 1790 printk(KERN_CONT " drive");
1699 1791
1700 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpup((__be16 *)&buf[8 + 12])); 1792 printk(KERN_CONT ", %dkB Cache\n",
1793 be16_to_cpup((__be16 *)&buf[8 + 12]));
1701 1794
1702 return nslots; 1795 return nslots;
1703} 1796}
@@ -1809,7 +1902,7 @@ static ide_proc_entry_t idecd_proc[] = {
1809 { NULL, 0, NULL, NULL } 1902 { NULL, 0, NULL, NULL }
1810}; 1903};
1811 1904
1812ide_devset_rw_field(dsc_overlap, dsc_overlap); 1905ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
1813 1906
1814static const struct ide_proc_devset idecd_settings[] = { 1907static const struct ide_proc_devset idecd_settings[] = {
1815 IDE_PROC_DEVSET(dsc_overlap, 0, 1), 1908 IDE_PROC_DEVSET(dsc_overlap, 0, 1),
@@ -1884,6 +1977,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1884 char *fw_rev = (char *)&id[ATA_ID_FW_REV]; 1977 char *fw_rev = (char *)&id[ATA_ID_FW_REV];
1885 int nslots; 1978 int nslots;
1886 1979
1980 ide_debug_log(IDE_DBG_PROBE, "Call %s\n", __func__);
1981
1887 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1982 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
1888 blk_queue_dma_alignment(drive->queue, 31); 1983 blk_queue_dma_alignment(drive->queue, 31);
1889 blk_queue_update_dma_pad(drive->queue, 15); 1984 blk_queue_update_dma_pad(drive->queue, 15);
@@ -1891,14 +1986,9 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1891 if (!drive->queue->unplug_delay) 1986 if (!drive->queue->unplug_delay)
1892 drive->queue->unplug_delay = 1; 1987 drive->queue->unplug_delay = 1;
1893 1988
1894 drive->special.all = 0;
1895
1896 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT | 1989 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
1897 ide_cd_flags(id); 1990 ide_cd_flags(id);
1898 1991
1899 if ((id[ATA_ID_CONFIG] & 0x0060) == 0x20)
1900 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
1901
1902 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && 1992 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
1903 fw_rev[4] == '1' && fw_rev[6] <= '2') 1993 fw_rev[4] == '1' && fw_rev[6] <= '2')
1904 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | 1994 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
@@ -1915,10 +2005,13 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1915 /* set correct block size */ 2005 /* set correct block size */
1916 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); 2006 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
1917 2007
1918 drive->dsc_overlap = (drive->next != drive); 2008 if (drive->next != drive)
2009 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2010 else
2011 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1919 2012
1920 if (ide_cdrom_register(drive, nslots)) { 2013 if (ide_cdrom_register(drive, nslots)) {
1921 printk(KERN_ERR "%s: %s failed to register device with the" 2014 printk(KERN_ERR PFX "%s: %s failed to register device with the"
1922 " cdrom driver.\n", drive->name, __func__); 2015 " cdrom driver.\n", drive->name, __func__);
1923 cd->devinfo.handle = NULL; 2016 cd->devinfo.handle = NULL;
1924 return 1; 2017 return 1;
@@ -1932,6 +2025,8 @@ static void ide_cd_remove(ide_drive_t *drive)
1932{ 2025{
1933 struct cdrom_info *info = drive->driver_data; 2026 struct cdrom_info *info = drive->driver_data;
1934 2027
2028 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
2029
1935 ide_proc_unregister_driver(drive, info->driver); 2030 ide_proc_unregister_driver(drive, info->driver);
1936 2031
1937 del_gendisk(info->disk); 2032 del_gendisk(info->disk);
@@ -1941,15 +2036,17 @@ static void ide_cd_remove(ide_drive_t *drive)
1941 2036
1942static void ide_cd_release(struct kref *kref) 2037static void ide_cd_release(struct kref *kref)
1943{ 2038{
1944 struct cdrom_info *info = to_ide_cd(kref); 2039 struct cdrom_info *info = to_ide_drv(kref, cdrom_info);
1945 struct cdrom_device_info *devinfo = &info->devinfo; 2040 struct cdrom_device_info *devinfo = &info->devinfo;
1946 ide_drive_t *drive = info->drive; 2041 ide_drive_t *drive = info->drive;
1947 struct gendisk *g = info->disk; 2042 struct gendisk *g = info->disk;
1948 2043
2044 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
2045
1949 kfree(info->toc); 2046 kfree(info->toc);
1950 if (devinfo->handle == drive) 2047 if (devinfo->handle == drive)
1951 unregister_cdrom(devinfo); 2048 unregister_cdrom(devinfo);
1952 drive->dsc_overlap = 0; 2049 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1953 drive->driver_data = NULL; 2050 drive->driver_data = NULL;
1954 blk_queue_prep_rq(drive->queue, NULL); 2051 blk_queue_prep_rq(drive->queue, NULL);
1955 g->private_data = NULL; 2052 g->private_data = NULL;
@@ -1968,7 +2065,6 @@ static ide_driver_t ide_cdrom_driver = {
1968 .probe = ide_cd_probe, 2065 .probe = ide_cd_probe,
1969 .remove = ide_cd_remove, 2066 .remove = ide_cd_remove,
1970 .version = IDECD_VERSION, 2067 .version = IDECD_VERSION,
1971 .media = ide_cdrom,
1972 .do_request = ide_cd_do_request, 2068 .do_request = ide_cd_do_request,
1973 .end_request = ide_end_request, 2069 .end_request = ide_end_request,
1974 .error = __ide_error, 2070 .error = __ide_error,
@@ -1999,7 +2095,7 @@ static int idecd_open(struct inode *inode, struct file *file)
1999static int idecd_release(struct inode *inode, struct file *file) 2095static int idecd_release(struct inode *inode, struct file *file)
2000{ 2096{
2001 struct gendisk *disk = inode->i_bdev->bd_disk; 2097 struct gendisk *disk = inode->i_bdev->bd_disk;
2002 struct cdrom_info *info = ide_cd_g(disk); 2098 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2003 2099
2004 cdrom_release(&info->devinfo, file); 2100 cdrom_release(&info->devinfo, file);
2005 2101
@@ -2051,7 +2147,7 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
2051 unsigned int cmd, unsigned long arg) 2147 unsigned int cmd, unsigned long arg)
2052{ 2148{
2053 struct block_device *bdev = inode->i_bdev; 2149 struct block_device *bdev = inode->i_bdev;
2054 struct cdrom_info *info = ide_cd_g(bdev->bd_disk); 2150 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
2055 int err; 2151 int err;
2056 2152
2057 switch (cmd) { 2153 switch (cmd) {
@@ -2072,13 +2168,13 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
2072 2168
2073static int idecd_media_changed(struct gendisk *disk) 2169static int idecd_media_changed(struct gendisk *disk)
2074{ 2170{
2075 struct cdrom_info *info = ide_cd_g(disk); 2171 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2076 return cdrom_media_changed(&info->devinfo); 2172 return cdrom_media_changed(&info->devinfo);
2077} 2173}
2078 2174
2079static int idecd_revalidate_disk(struct gendisk *disk) 2175static int idecd_revalidate_disk(struct gendisk *disk)
2080{ 2176{
2081 struct cdrom_info *info = ide_cd_g(disk); 2177 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2082 struct request_sense sense; 2178 struct request_sense sense;
2083 2179
2084 ide_cd_read_toc(info->drive, &sense); 2180 ide_cd_read_toc(info->drive, &sense);
@@ -2097,8 +2193,11 @@ static struct block_device_operations idecd_ops = {
2097 2193
2098/* module options */ 2194/* module options */
2099static char *ignore; 2195static char *ignore;
2100
2101module_param(ignore, charp, 0400); 2196module_param(ignore, charp, 0400);
2197
2198static unsigned long debug_mask;
2199module_param(debug_mask, ulong, 0644);
2200
2102MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); 2201MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
2103 2202
2104static int ide_cd_probe(ide_drive_t *drive) 2203static int ide_cd_probe(ide_drive_t *drive)
@@ -2107,6 +2206,10 @@ static int ide_cd_probe(ide_drive_t *drive)
2107 struct gendisk *g; 2206 struct gendisk *g;
2108 struct request_sense sense; 2207 struct request_sense sense;
2109 2208
2209 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->driver_req: %s, "
2210 "drive->media: 0x%x\n", __func__, drive->driver_req,
2211 drive->media);
2212
2110 if (!strstr("ide-cdrom", drive->driver_req)) 2213 if (!strstr("ide-cdrom", drive->driver_req))
2111 goto failed; 2214 goto failed;
2112 2215
@@ -2116,14 +2219,17 @@ static int ide_cd_probe(ide_drive_t *drive)
2116 /* skip drives that we were told to ignore */ 2219 /* skip drives that we were told to ignore */
2117 if (ignore != NULL) { 2220 if (ignore != NULL) {
2118 if (strstr(ignore, drive->name)) { 2221 if (strstr(ignore, drive->name)) {
2119 printk(KERN_INFO "ide-cd: ignoring drive %s\n", 2222 printk(KERN_INFO PFX "ignoring drive %s\n",
2120 drive->name); 2223 drive->name);
2121 goto failed; 2224 goto failed;
2122 } 2225 }
2123 } 2226 }
2227
2228 drive->debug_mask = debug_mask;
2229
2124 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); 2230 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
2125 if (info == NULL) { 2231 if (info == NULL) {
2126 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", 2232 printk(KERN_ERR PFX "%s: Can't allocate a cdrom structure\n",
2127 drive->name); 2233 drive->name);
2128 goto failed; 2234 goto failed;
2129 } 2235 }
@@ -2171,6 +2277,7 @@ static void __exit ide_cdrom_exit(void)
2171 2277
2172static int __init ide_cdrom_init(void) 2278static int __init ide_cdrom_init(void)
2173{ 2279{
2280 printk(KERN_INFO DRV_NAME " driver " IDECD_VERSION "\n");
2174 return driver_register(&ide_cdrom_driver.gen_driver); 2281 return driver_register(&ide_cdrom_driver.gen_driver);
2175} 2282}
2176 2283
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 61a4599b77db..5882b9a9ea8b 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -88,7 +88,6 @@ struct cdrom_info {
88 struct request_sense sense_data; 88 struct request_sense sense_data;
89 89
90 struct request request_sense_request; 90 struct request request_sense_request;
91 int dma;
92 unsigned long last_block; 91 unsigned long last_block;
93 unsigned long start_seek; 92 unsigned long start_seek;
94 93
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 01846f244b40..3853bde8eedc 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -45,21 +45,12 @@
45#define IDE_DISK_MINORS 0 45#define IDE_DISK_MINORS 0
46#endif 46#endif
47 47
48struct ide_disk_obj { 48#include "ide-disk.h"
49 ide_drive_t *drive;
50 ide_driver_t *driver;
51 struct gendisk *disk;
52 struct kref kref;
53 unsigned int openers; /* protected by BKL for now */
54};
55 49
56static DEFINE_MUTEX(idedisk_ref_mutex); 50static DEFINE_MUTEX(idedisk_ref_mutex);
57 51
58#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref) 52#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
59 53
60#define ide_disk_g(disk) \
61 container_of((disk)->private_data, struct ide_disk_obj, driver)
62
63static void ide_disk_release(struct kref *); 54static void ide_disk_release(struct kref *);
64 55
65static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) 56static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
@@ -140,9 +131,9 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
140 sector_t block) 131 sector_t block)
141{ 132{
142 ide_hwif_t *hwif = HWIF(drive); 133 ide_hwif_t *hwif = HWIF(drive);
143 unsigned int dma = drive->using_dma;
144 u16 nsectors = (u16)rq->nr_sectors; 134 u16 nsectors = (u16)rq->nr_sectors;
145 u8 lba48 = (drive->addressing == 1) ? 1 : 0; 135 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
136 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
146 ide_task_t task; 137 ide_task_t task;
147 struct ide_taskfile *tf = &task.tf; 138 struct ide_taskfile *tf = &task.tf;
148 ide_startstop_t rc; 139 ide_startstop_t rc;
@@ -162,7 +153,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
162 memset(&task, 0, sizeof(task)); 153 memset(&task, 0, sizeof(task));
163 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 154 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
164 155
165 if (drive->select.b.lba) { 156 if (drive->dev_flags & IDE_DFLAG_LBA) {
166 if (lba48) { 157 if (lba48) {
167 pr_debug("%s: LBA=0x%012llx\n", drive->name, 158 pr_debug("%s: LBA=0x%012llx\n", drive->name,
168 (unsigned long long)block); 159 (unsigned long long)block);
@@ -187,6 +178,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
187 tf->lbah = block >>= 8; 178 tf->lbah = block >>= 8;
188 tf->device = (block >> 8) & 0xf; 179 tf->device = (block >> 8) & 0xf;
189 } 180 }
181
182 tf->device |= ATA_LBA;
190 } else { 183 } else {
191 unsigned int sect, head, cyl, track; 184 unsigned int sect, head, cyl, track;
192 185
@@ -237,7 +230,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
237{ 230{
238 ide_hwif_t *hwif = HWIF(drive); 231 ide_hwif_t *hwif = HWIF(drive);
239 232
240 BUG_ON(drive->blocked); 233 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
241 234
242 if (!blk_fs_request(rq)) { 235 if (!blk_fs_request(rq)) {
243 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); 236 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
@@ -384,139 +377,39 @@ static void idedisk_check_hpa(ide_drive_t *drive)
384static void init_idedisk_capacity(ide_drive_t *drive) 377static void init_idedisk_capacity(ide_drive_t *drive)
385{ 378{
386 u16 *id = drive->id; 379 u16 *id = drive->id;
387 /* 380 int lba;
388 * If this drive supports the Host Protected Area feature set,
389 * then we may need to change our opinion about the drive's capacity.
390 */
391 int hpa = ata_id_hpa_enabled(id);
392 381
393 if (ata_id_lba48_enabled(id)) { 382 if (ata_id_lba48_enabled(id)) {
394 /* drive speaks 48-bit LBA */ 383 /* drive speaks 48-bit LBA */
395 drive->select.b.lba = 1; 384 lba = 1;
396 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2); 385 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
397 if (hpa)
398 idedisk_check_hpa(drive);
399 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) { 386 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
400 /* drive speaks 28-bit LBA */ 387 /* drive speaks 28-bit LBA */
401 drive->select.b.lba = 1; 388 lba = 1;
402 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY); 389 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
403 if (hpa)
404 idedisk_check_hpa(drive);
405 } else { 390 } else {
406 /* drive speaks boring old 28-bit CHS */ 391 /* drive speaks boring old 28-bit CHS */
392 lba = 0;
407 drive->capacity64 = drive->cyl * drive->head * drive->sect; 393 drive->capacity64 = drive->cyl * drive->head * drive->sect;
408 } 394 }
409}
410 395
411static sector_t idedisk_capacity(ide_drive_t *drive) 396 if (lba) {
412{ 397 drive->dev_flags |= IDE_DFLAG_LBA;
413 return drive->capacity64;
414}
415 398
416#ifdef CONFIG_IDE_PROC_FS 399 /*
417static int smart_enable(ide_drive_t *drive) 400 * If this device supports the Host Protected Area feature set,
418{ 401 * then we may need to change our opinion about its capacity.
419 ide_task_t args; 402 */
420 struct ide_taskfile *tf = &args.tf; 403 if (ata_id_hpa_enabled(id))
421 404 idedisk_check_hpa(drive);
422 memset(&args, 0, sizeof(ide_task_t));
423 tf->feature = ATA_SMART_ENABLE;
424 tf->lbam = ATA_SMART_LBAM_PASS;
425 tf->lbah = ATA_SMART_LBAH_PASS;
426 tf->command = ATA_CMD_SMART;
427 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
428 return ide_no_data_taskfile(drive, &args);
429}
430
431static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
432{
433 ide_task_t args;
434 struct ide_taskfile *tf = &args.tf;
435
436 memset(&args, 0, sizeof(ide_task_t));
437 tf->feature = sub_cmd;
438 tf->nsect = 0x01;
439 tf->lbam = ATA_SMART_LBAM_PASS;
440 tf->lbah = ATA_SMART_LBAH_PASS;
441 tf->command = ATA_CMD_SMART;
442 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
443 args.data_phase = TASKFILE_IN;
444 (void) smart_enable(drive);
445 return ide_raw_taskfile(drive, &args, buf, 1);
446}
447
448static int proc_idedisk_read_cache
449 (char *page, char **start, off_t off, int count, int *eof, void *data)
450{
451 ide_drive_t *drive = (ide_drive_t *) data;
452 char *out = page;
453 int len;
454
455 if (drive->id_read)
456 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
457 else
458 len = sprintf(out, "(none)\n");
459
460 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
461}
462
463static int proc_idedisk_read_capacity
464 (char *page, char **start, off_t off, int count, int *eof, void *data)
465{
466 ide_drive_t*drive = (ide_drive_t *)data;
467 int len;
468
469 len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive));
470
471 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
472}
473
474static int proc_idedisk_read_smart(char *page, char **start, off_t off,
475 int count, int *eof, void *data, u8 sub_cmd)
476{
477 ide_drive_t *drive = (ide_drive_t *)data;
478 int len = 0, i = 0;
479
480 if (get_smart_data(drive, page, sub_cmd) == 0) {
481 unsigned short *val = (unsigned short *) page;
482 char *out = (char *)val + SECTOR_SIZE;
483
484 page = out;
485 do {
486 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
487 (++i & 7) ? ' ' : '\n');
488 val += 1;
489 } while (i < SECTOR_SIZE / 2);
490 len = out - page;
491 } 405 }
492
493 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
494} 406}
495 407
496static int proc_idedisk_read_sv 408sector_t ide_disk_capacity(ide_drive_t *drive)
497 (char *page, char **start, off_t off, int count, int *eof, void *data)
498{ 409{
499 return proc_idedisk_read_smart(page, start, off, count, eof, data, 410 return drive->capacity64;
500 ATA_SMART_READ_VALUES);
501}
502
503static int proc_idedisk_read_st
504 (char *page, char **start, off_t off, int count, int *eof, void *data)
505{
506 return proc_idedisk_read_smart(page, start, off, count, eof, data,
507 ATA_SMART_READ_THRESHOLDS);
508} 411}
509 412
510static ide_proc_entry_t idedisk_proc[] = {
511 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
512 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
513 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
514 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
515 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
516 { NULL, 0, NULL, NULL }
517};
518#endif /* CONFIG_IDE_PROC_FS */
519
520static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 413static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
521{ 414{
522 ide_drive_t *drive = q->queuedata; 415 ide_drive_t *drive = q->queuedata;
@@ -568,25 +461,43 @@ static int set_multcount(ide_drive_t *drive, int arg)
568 return (drive->mult_count == arg) ? 0 : -EIO; 461 return (drive->mult_count == arg) ? 0 : -EIO;
569} 462}
570 463
571ide_devset_get(nowerr, nowerr); 464ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR);
572 465
573static int set_nowerr(ide_drive_t *drive, int arg) 466static int set_nowerr(ide_drive_t *drive, int arg)
574{ 467{
575 if (arg < 0 || arg > 1) 468 if (arg < 0 || arg > 1)
576 return -EINVAL; 469 return -EINVAL;
577 470
578 drive->nowerr = arg; 471 if (arg)
472 drive->dev_flags |= IDE_DFLAG_NOWERR;
473 else
474 drive->dev_flags &= ~IDE_DFLAG_NOWERR;
475
579 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; 476 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
477
580 return 0; 478 return 0;
581} 479}
582 480
481static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
482{
483 ide_task_t task;
484
485 memset(&task, 0, sizeof(task));
486 task.tf.feature = feature;
487 task.tf.nsect = nsect;
488 task.tf.command = ATA_CMD_SET_FEATURES;
489 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
490
491 return ide_no_data_taskfile(drive, &task);
492}
493
583static void update_ordered(ide_drive_t *drive) 494static void update_ordered(ide_drive_t *drive)
584{ 495{
585 u16 *id = drive->id; 496 u16 *id = drive->id;
586 unsigned ordered = QUEUE_ORDERED_NONE; 497 unsigned ordered = QUEUE_ORDERED_NONE;
587 prepare_flush_fn *prep_fn = NULL; 498 prepare_flush_fn *prep_fn = NULL;
588 499
589 if (drive->wcache) { 500 if (drive->dev_flags & IDE_DFLAG_WCACHE) {
590 unsigned long long capacity; 501 unsigned long long capacity;
591 int barrier; 502 int barrier;
592 /* 503 /*
@@ -597,9 +508,11 @@ static void update_ordered(ide_drive_t *drive)
597 * time we have trimmed the drive capacity if LBA48 is 508 * time we have trimmed the drive capacity if LBA48 is
598 * not available so we don't need to recheck that. 509 * not available so we don't need to recheck that.
599 */ 510 */
600 capacity = idedisk_capacity(drive); 511 capacity = ide_disk_capacity(drive);
601 barrier = ata_id_flush_enabled(id) && !drive->noflush && 512 barrier = ata_id_flush_enabled(id) &&
602 (drive->addressing == 0 || capacity <= (1ULL << 28) || 513 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
514 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
515 capacity <= (1ULL << 28) ||
603 ata_id_flush_ext_enabled(id)); 516 ata_id_flush_ext_enabled(id));
604 517
605 printk(KERN_INFO "%s: cache flushes %ssupported\n", 518 printk(KERN_INFO "%s: cache flushes %ssupported\n",
@@ -615,25 +528,24 @@ static void update_ordered(ide_drive_t *drive)
615 blk_queue_ordered(drive->queue, ordered, prep_fn); 528 blk_queue_ordered(drive->queue, ordered, prep_fn);
616} 529}
617 530
618ide_devset_get(wcache, wcache); 531ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
619 532
620static int set_wcache(ide_drive_t *drive, int arg) 533static int set_wcache(ide_drive_t *drive, int arg)
621{ 534{
622 ide_task_t args;
623 int err = 1; 535 int err = 1;
624 536
625 if (arg < 0 || arg > 1) 537 if (arg < 0 || arg > 1)
626 return -EINVAL; 538 return -EINVAL;
627 539
628 if (ata_id_flush_enabled(drive->id)) { 540 if (ata_id_flush_enabled(drive->id)) {
629 memset(&args, 0, sizeof(ide_task_t)); 541 err = ide_do_setfeature(drive,
630 args.tf.feature = arg ? 542 arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
631 SETFEATURES_WC_ON : SETFEATURES_WC_OFF; 543 if (err == 0) {
632 args.tf.command = ATA_CMD_SET_FEATURES; 544 if (arg)
633 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 545 drive->dev_flags |= IDE_DFLAG_WCACHE;
634 err = ide_no_data_taskfile(drive, &args); 546 else
635 if (err == 0) 547 drive->dev_flags &= ~IDE_DFLAG_WCACHE;
636 drive->wcache = arg; 548 }
637 } 549 }
638 550
639 update_ordered(drive); 551 update_ordered(drive);
@@ -658,22 +570,18 @@ ide_devset_get(acoustic, acoustic);
658 570
659static int set_acoustic(ide_drive_t *drive, int arg) 571static int set_acoustic(ide_drive_t *drive, int arg)
660{ 572{
661 ide_task_t args;
662
663 if (arg < 0 || arg > 254) 573 if (arg < 0 || arg > 254)
664 return -EINVAL; 574 return -EINVAL;
665 575
666 memset(&args, 0, sizeof(ide_task_t)); 576 ide_do_setfeature(drive,
667 args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF; 577 arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
668 args.tf.nsect = arg; 578
669 args.tf.command = ATA_CMD_SET_FEATURES;
670 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
671 ide_no_data_taskfile(drive, &args);
672 drive->acoustic = arg; 579 drive->acoustic = arg;
580
673 return 0; 581 return 0;
674} 582}
675 583
676ide_devset_get(addressing, addressing); 584ide_devset_get_flag(addressing, IDE_DFLAG_LBA48);
677 585
678/* 586/*
679 * drive->addressing: 587 * drive->addressing:
@@ -686,49 +594,27 @@ static int set_addressing(ide_drive_t *drive, int arg)
686 if (arg < 0 || arg > 2) 594 if (arg < 0 || arg > 2)
687 return -EINVAL; 595 return -EINVAL;
688 596
689 drive->addressing = 0; 597 if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
690 598 ata_id_lba48_enabled(drive->id) == 0))
691 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
692 return 0;
693
694 if (ata_id_lba48_enabled(drive->id) == 0)
695 return -EIO; 599 return -EIO;
696 600
697 drive->addressing = arg; 601 if (arg == 2)
602 arg = 0;
603
604 if (arg)
605 drive->dev_flags |= IDE_DFLAG_LBA48;
606 else
607 drive->dev_flags &= ~IDE_DFLAG_LBA48;
698 608
699 return 0; 609 return 0;
700} 610}
701 611
702ide_devset_rw(acoustic, acoustic); 612ide_ext_devset_rw(acoustic, acoustic);
703ide_devset_rw(address, addressing); 613ide_ext_devset_rw(address, addressing);
704ide_devset_rw(multcount, multcount); 614ide_ext_devset_rw(multcount, multcount);
705ide_devset_rw(wcache, wcache); 615ide_ext_devset_rw(wcache, wcache);
706
707ide_devset_rw_sync(nowerr, nowerr);
708 616
709#ifdef CONFIG_IDE_PROC_FS 617ide_ext_devset_rw_sync(nowerr, nowerr);
710ide_devset_rw_field(bios_cyl, bios_cyl);
711ide_devset_rw_field(bios_head, bios_head);
712ide_devset_rw_field(bios_sect, bios_sect);
713ide_devset_rw_field(failures, failures);
714ide_devset_rw_field(lun, lun);
715ide_devset_rw_field(max_failures, max_failures);
716
717static const struct ide_proc_devset idedisk_settings[] = {
718 IDE_PROC_DEVSET(acoustic, 0, 254),
719 IDE_PROC_DEVSET(address, 0, 2),
720 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
721 IDE_PROC_DEVSET(bios_head, 0, 255),
722 IDE_PROC_DEVSET(bios_sect, 0, 63),
723 IDE_PROC_DEVSET(failures, 0, 65535),
724 IDE_PROC_DEVSET(lun, 0, 7),
725 IDE_PROC_DEVSET(max_failures, 0, 65535),
726 IDE_PROC_DEVSET(multcount, 0, 16),
727 IDE_PROC_DEVSET(nowerr, 0, 1),
728 IDE_PROC_DEVSET(wcache, 0, 1),
729 { 0 },
730};
731#endif
732 618
733static void idedisk_setup(ide_drive_t *drive) 619static void idedisk_setup(ide_drive_t *drive)
734{ 620{
@@ -740,20 +626,20 @@ static void idedisk_setup(ide_drive_t *drive)
740 626
741 ide_proc_register_driver(drive, idkp->driver); 627 ide_proc_register_driver(drive, idkp->driver);
742 628
743 if (drive->id_read == 0) 629 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
744 return; 630 return;
745 631
746 if (drive->removable) { 632 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
747 /* 633 /*
748 * Removable disks (eg. SYQUEST); ignore 'WD' drives 634 * Removable disks (eg. SYQUEST); ignore 'WD' drives
749 */ 635 */
750 if (m[0] != 'W' || m[1] != 'D') 636 if (m[0] != 'W' || m[1] != 'D')
751 drive->doorlocking = 1; 637 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
752 } 638 }
753 639
754 (void)set_addressing(drive, 1); 640 (void)set_addressing(drive, 1);
755 641
756 if (drive->addressing == 1) { 642 if (drive->dev_flags & IDE_DFLAG_LBA48) {
757 int max_s = 2048; 643 int max_s = 2048;
758 644
759 if (max_s > hwif->rqsize) 645 if (max_s > hwif->rqsize)
@@ -769,7 +655,8 @@ static void idedisk_setup(ide_drive_t *drive)
769 init_idedisk_capacity(drive); 655 init_idedisk_capacity(drive);
770 656
771 /* limit drive capacity to 137GB if LBA48 cannot be used */ 657 /* limit drive capacity to 137GB if LBA48 cannot be used */
772 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) { 658 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
659 drive->capacity64 > 1ULL << 28) {
773 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity " 660 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
774 "%llu sectors (%llu MB)\n", 661 "%llu sectors (%llu MB)\n",
775 drive->name, (unsigned long long)drive->capacity64, 662 drive->name, (unsigned long long)drive->capacity64,
@@ -777,22 +664,23 @@ static void idedisk_setup(ide_drive_t *drive)
777 drive->capacity64 = 1ULL << 28; 664 drive->capacity64 = 1ULL << 28;
778 } 665 }
779 666
780 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) { 667 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
668 (drive->dev_flags & IDE_DFLAG_LBA48)) {
781 if (drive->capacity64 > 1ULL << 28) { 669 if (drive->capacity64 > 1ULL << 28) {
782 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode" 670 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
783 " will be used for accessing sectors " 671 " will be used for accessing sectors "
784 "> %u\n", drive->name, 1 << 28); 672 "> %u\n", drive->name, 1 << 28);
785 } else 673 } else
786 drive->addressing = 0; 674 drive->dev_flags &= ~IDE_DFLAG_LBA48;
787 } 675 }
788 676
789 /* 677 /*
790 * if possible, give fdisk access to more of the drive, 678 * if possible, give fdisk access to more of the drive,
791 * by correcting bios_cyls: 679 * by correcting bios_cyls:
792 */ 680 */
793 capacity = idedisk_capacity(drive); 681 capacity = ide_disk_capacity(drive);
794 682
795 if (!drive->forced_geom) { 683 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
796 if (ata_id_lba48_enabled(drive->id)) { 684 if (ata_id_lba48_enabled(drive->id)) {
797 /* compatibility */ 685 /* compatibility */
798 drive->bios_sect = 63; 686 drive->bios_sect = 63;
@@ -827,14 +715,15 @@ static void idedisk_setup(ide_drive_t *drive)
827 715
828 /* write cache enabled? */ 716 /* write cache enabled? */
829 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id)) 717 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
830 drive->wcache = 1; 718 drive->dev_flags |= IDE_DFLAG_WCACHE;
831 719
832 set_wcache(drive, 1); 720 set_wcache(drive, 1);
833} 721}
834 722
835static void ide_cacheflush_p(ide_drive_t *drive) 723static void ide_cacheflush_p(ide_drive_t *drive)
836{ 724{
837 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) 725 if (ata_id_flush_enabled(drive->id) == 0 ||
726 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
838 return; 727 return;
839 728
840 if (do_idedisk_flushcache(drive)) 729 if (do_idedisk_flushcache(drive))
@@ -918,13 +807,12 @@ static ide_driver_t idedisk_driver = {
918 .resume = ide_disk_resume, 807 .resume = ide_disk_resume,
919 .shutdown = ide_device_shutdown, 808 .shutdown = ide_device_shutdown,
920 .version = IDEDISK_VERSION, 809 .version = IDEDISK_VERSION,
921 .media = ide_disk,
922 .do_request = ide_do_rw_disk, 810 .do_request = ide_do_rw_disk,
923 .end_request = ide_end_request, 811 .end_request = ide_end_request,
924 .error = __ide_error, 812 .error = __ide_error,
925#ifdef CONFIG_IDE_PROC_FS 813#ifdef CONFIG_IDE_PROC_FS
926 .proc = idedisk_proc, 814 .proc = ide_disk_proc,
927 .settings = idedisk_settings, 815 .settings = ide_disk_settings,
928#endif 816#endif
929}; 817};
930 818
@@ -953,15 +841,16 @@ static int idedisk_open(struct inode *inode, struct file *filp)
953 841
954 idkp->openers++; 842 idkp->openers++;
955 843
956 if (drive->removable && idkp->openers == 1) { 844 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
957 check_disk_change(inode->i_bdev); 845 check_disk_change(inode->i_bdev);
958 /* 846 /*
959 * Ignore the return code from door_lock, 847 * Ignore the return code from door_lock,
960 * since the open() has already succeeded, 848 * since the open() has already succeeded,
961 * and the door_lock is irrelevant at this point. 849 * and the door_lock is irrelevant at this point.
962 */ 850 */
963 if (drive->doorlocking && idedisk_set_doorlock(drive, 1)) 851 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
964 drive->doorlocking = 0; 852 idedisk_set_doorlock(drive, 1))
853 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
965 } 854 }
966 return 0; 855 return 0;
967} 856}
@@ -975,9 +864,10 @@ static int idedisk_release(struct inode *inode, struct file *filp)
975 if (idkp->openers == 1) 864 if (idkp->openers == 1)
976 ide_cacheflush_p(drive); 865 ide_cacheflush_p(drive);
977 866
978 if (drive->removable && idkp->openers == 1) { 867 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
979 if (drive->doorlocking && idedisk_set_doorlock(drive, 0)) 868 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
980 drive->doorlocking = 0; 869 idedisk_set_doorlock(drive, 0))
870 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
981 } 871 }
982 872
983 idkp->openers--; 873 idkp->openers--;
@@ -998,48 +888,25 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
998 return 0; 888 return 0;
999} 889}
1000 890
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
1010static int idedisk_ioctl(struct inode *inode, struct file *file,
1011 unsigned int cmd, unsigned long arg)
1012{
1013 struct block_device *bdev = inode->i_bdev;
1014 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1015 ide_drive_t *drive = idkp->drive;
1016 int err;
1017
1018 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
1019 if (err != -EOPNOTSUPP)
1020 return err;
1021
1022 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1023}
1024
1025static int idedisk_media_changed(struct gendisk *disk) 891static int idedisk_media_changed(struct gendisk *disk)
1026{ 892{
1027 struct ide_disk_obj *idkp = ide_disk_g(disk); 893 struct ide_disk_obj *idkp = ide_disk_g(disk);
1028 ide_drive_t *drive = idkp->drive; 894 ide_drive_t *drive = idkp->drive;
1029 895
1030 /* do not scan partitions twice if this is a removable device */ 896 /* do not scan partitions twice if this is a removable device */
1031 if (drive->attach) { 897 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
1032 drive->attach = 0; 898 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
1033 return 0; 899 return 0;
1034 } 900 }
901
1035 /* if removable, always assume it was changed */ 902 /* if removable, always assume it was changed */
1036 return drive->removable; 903 return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
1037} 904}
1038 905
1039static int idedisk_revalidate_disk(struct gendisk *disk) 906static int idedisk_revalidate_disk(struct gendisk *disk)
1040{ 907{
1041 struct ide_disk_obj *idkp = ide_disk_g(disk); 908 struct ide_disk_obj *idkp = ide_disk_g(disk);
1042 set_capacity(disk, idedisk_capacity(idkp->drive)); 909 set_capacity(disk, ide_disk_capacity(idkp->drive));
1043 return 0; 910 return 0;
1044} 911}
1045 912
@@ -1047,7 +914,7 @@ static struct block_device_operations idedisk_ops = {
1047 .owner = THIS_MODULE, 914 .owner = THIS_MODULE,
1048 .open = idedisk_open, 915 .open = idedisk_open,
1049 .release = idedisk_release, 916 .release = idedisk_release,
1050 .ioctl = idedisk_ioctl, 917 .ioctl = ide_disk_ioctl,
1051 .getgeo = idedisk_getgeo, 918 .getgeo = idedisk_getgeo,
1052 .media_changed = idedisk_media_changed, 919 .media_changed = idedisk_media_changed,
1053 .revalidate_disk = idedisk_revalidate_disk 920 .revalidate_disk = idedisk_revalidate_disk
@@ -1088,19 +955,20 @@ static int ide_disk_probe(ide_drive_t *drive)
1088 drive->driver_data = idkp; 955 drive->driver_data = idkp;
1089 956
1090 idedisk_setup(drive); 957 idedisk_setup(drive);
1091 if ((!drive->head || drive->head > 16) && !drive->select.b.lba) { 958 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
959 (drive->head == 0 || drive->head > 16)) {
1092 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", 960 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
1093 drive->name, drive->head); 961 drive->name, drive->head);
1094 drive->attach = 0; 962 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
1095 } else 963 } else
1096 drive->attach = 1; 964 drive->dev_flags |= IDE_DFLAG_ATTACH;
1097 965
1098 g->minors = IDE_DISK_MINORS; 966 g->minors = IDE_DISK_MINORS;
1099 g->driverfs_dev = &drive->gendev; 967 g->driverfs_dev = &drive->gendev;
1100 g->flags |= GENHD_FL_EXT_DEVT; 968 g->flags |= GENHD_FL_EXT_DEVT;
1101 if (drive->removable) 969 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
1102 g->flags |= GENHD_FL_REMOVABLE; 970 g->flags = GENHD_FL_REMOVABLE;
1103 set_capacity(g, idedisk_capacity(drive)); 971 set_capacity(g, ide_disk_capacity(drive));
1104 g->fops = &idedisk_ops; 972 g->fops = &idedisk_ops;
1105 add_disk(g); 973 add_disk(g);
1106 return 0; 974 return 0;
@@ -1122,6 +990,7 @@ static int __init idedisk_init(void)
1122} 990}
1123 991
1124MODULE_ALIAS("ide:*m-disk*"); 992MODULE_ALIAS("ide:*m-disk*");
993MODULE_ALIAS("ide-disk");
1125module_init(idedisk_init); 994module_init(idedisk_init);
1126module_exit(idedisk_exit); 995module_exit(idedisk_exit);
1127MODULE_LICENSE("GPL"); 996MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h
new file mode 100644
index 000000000000..a82fa4355665
--- /dev/null
+++ b/drivers/ide/ide-disk.h
@@ -0,0 +1,32 @@
1#ifndef __IDE_DISK_H
2#define __IDE_DISK_H
3
4struct ide_disk_obj {
5 ide_drive_t *drive;
6 ide_driver_t *driver;
7 struct gendisk *disk;
8 struct kref kref;
9 unsigned int openers; /* protected by BKL for now */
10};
11
12#define ide_disk_g(disk) \
13 container_of((disk)->private_data, struct ide_disk_obj, driver)
14
15/* ide-disk.c */
16sector_t ide_disk_capacity(ide_drive_t *);
17ide_decl_devset(address);
18ide_decl_devset(multcount);
19ide_decl_devset(nowerr);
20ide_decl_devset(wcache);
21ide_decl_devset(acoustic);
22
23/* ide-disk_ioctl.c */
24int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
25
26#ifdef CONFIG_IDE_PROC_FS
27/* ide-disk_proc.c */
28extern ide_proc_entry_t ide_disk_proc[];
29extern const struct ide_proc_devset ide_disk_settings[];
30#endif
31
32#endif /* __IDE_DISK_H */
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
new file mode 100644
index 000000000000..a6cf1a03a806
--- /dev/null
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -0,0 +1,29 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5#include "ide-disk.h"
6
7static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
8{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
9{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
10{ HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr },
11{ HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache },
12{ HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic },
13{ 0 }
14};
15
16int ide_disk_ioctl(struct inode *inode, struct file *file,
17 unsigned int cmd, unsigned long arg)
18{
19 struct block_device *bdev = inode->i_bdev;
20 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
21 ide_drive_t *drive = idkp->drive;
22 int err;
23
24 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
25 if (err != -EOPNOTSUPP)
26 return err;
27
28 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
29}
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
new file mode 100644
index 000000000000..4724976afe71
--- /dev/null
+++ b/drivers/ide/ide-disk_proc.c
@@ -0,0 +1,129 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5#include "ide-disk.h"
6
7static int smart_enable(ide_drive_t *drive)
8{
9 ide_task_t args;
10 struct ide_taskfile *tf = &args.tf;
11
12 memset(&args, 0, sizeof(ide_task_t));
13 tf->feature = ATA_SMART_ENABLE;
14 tf->lbam = ATA_SMART_LBAM_PASS;
15 tf->lbah = ATA_SMART_LBAH_PASS;
16 tf->command = ATA_CMD_SMART;
17 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
18 return ide_no_data_taskfile(drive, &args);
19}
20
21static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
22{
23 ide_task_t args;
24 struct ide_taskfile *tf = &args.tf;
25
26 memset(&args, 0, sizeof(ide_task_t));
27 tf->feature = sub_cmd;
28 tf->nsect = 0x01;
29 tf->lbam = ATA_SMART_LBAM_PASS;
30 tf->lbah = ATA_SMART_LBAH_PASS;
31 tf->command = ATA_CMD_SMART;
32 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
33 args.data_phase = TASKFILE_IN;
34 (void) smart_enable(drive);
35 return ide_raw_taskfile(drive, &args, buf, 1);
36}
37
38static int proc_idedisk_read_cache
39 (char *page, char **start, off_t off, int count, int *eof, void *data)
40{
41 ide_drive_t *drive = (ide_drive_t *) data;
42 char *out = page;
43 int len;
44
45 if (drive->dev_flags & IDE_DFLAG_ID_READ)
46 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
47 else
48 len = sprintf(out, "(none)\n");
49
50 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
51}
52
53static int proc_idedisk_read_capacity
54 (char *page, char **start, off_t off, int count, int *eof, void *data)
55{
56 ide_drive_t*drive = (ide_drive_t *)data;
57 int len;
58
59 len = sprintf(page, "%llu\n", (long long)ide_disk_capacity(drive));
60
61 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
62}
63
64static int proc_idedisk_read_smart(char *page, char **start, off_t off,
65 int count, int *eof, void *data, u8 sub_cmd)
66{
67 ide_drive_t *drive = (ide_drive_t *)data;
68 int len = 0, i = 0;
69
70 if (get_smart_data(drive, page, sub_cmd) == 0) {
71 unsigned short *val = (unsigned short *) page;
72 char *out = (char *)val + SECTOR_SIZE;
73
74 page = out;
75 do {
76 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
77 (++i & 7) ? ' ' : '\n');
78 val += 1;
79 } while (i < SECTOR_SIZE / 2);
80 len = out - page;
81 }
82
83 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
84}
85
86static int proc_idedisk_read_sv
87 (char *page, char **start, off_t off, int count, int *eof, void *data)
88{
89 return proc_idedisk_read_smart(page, start, off, count, eof, data,
90 ATA_SMART_READ_VALUES);
91}
92
93static int proc_idedisk_read_st
94 (char *page, char **start, off_t off, int count, int *eof, void *data)
95{
96 return proc_idedisk_read_smart(page, start, off, count, eof, data,
97 ATA_SMART_READ_THRESHOLDS);
98}
99
100ide_proc_entry_t ide_disk_proc[] = {
101 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
102 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
103 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
104 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
105 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
106 { NULL, 0, NULL, NULL }
107};
108
109ide_devset_rw_field(bios_cyl, bios_cyl);
110ide_devset_rw_field(bios_head, bios_head);
111ide_devset_rw_field(bios_sect, bios_sect);
112ide_devset_rw_field(failures, failures);
113ide_devset_rw_field(lun, lun);
114ide_devset_rw_field(max_failures, max_failures);
115
116const struct ide_proc_devset ide_disk_settings[] = {
117 IDE_PROC_DEVSET(acoustic, 0, 254),
118 IDE_PROC_DEVSET(address, 0, 2),
119 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
120 IDE_PROC_DEVSET(bios_head, 0, 255),
121 IDE_PROC_DEVSET(bios_sect, 0, 63),
122 IDE_PROC_DEVSET(failures, 0, 65535),
123 IDE_PROC_DEVSET(lun, 0, 7),
124 IDE_PROC_DEVSET(max_failures, 0, 65535),
125 IDE_PROC_DEVSET(multcount, 0, 16),
126 IDE_PROC_DEVSET(nowerr, 0, 1),
127 IDE_PROC_DEVSET(wcache, 0, 1),
128 { 0 },
129};
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
new file mode 100644
index 000000000000..0903782689e9
--- /dev/null
+++ b/drivers/ide/ide-dma-sff.c
@@ -0,0 +1,356 @@
1#include <linux/types.h>
2#include <linux/kernel.h>
3#include <linux/ide.h>
4#include <linux/scatterlist.h>
5#include <linux/dma-mapping.h>
6#include <linux/io.h>
7
8/**
9 * config_drive_for_dma - attempt to activate IDE DMA
10 * @drive: the drive to place in DMA mode
11 *
12 * If the drive supports at least mode 2 DMA or UDMA of any kind
13 * then attempt to place it into DMA mode. Drives that are known to
14 * support DMA but predate the DMA properties or that are known
15 * to have DMA handling bugs are also set up appropriately based
16 * on the good/bad drive lists.
17 */
18
19int config_drive_for_dma(ide_drive_t *drive)
20{
21 ide_hwif_t *hwif = drive->hwif;
22 u16 *id = drive->id;
23
24 if (drive->media != ide_disk) {
25 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
26 return 0;
27 }
28
29 /*
30 * Enable DMA on any drive that has
31 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
32 */
33 if ((id[ATA_ID_FIELD_VALID] & 4) &&
34 ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
35 return 1;
36
37 /*
38 * Enable DMA on any drive that has mode2 DMA
39 * (multi or single) enabled
40 */
41 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
42 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
43 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
44 return 1;
45
46 /* Consult the list of known "good" drives */
47 if (ide_dma_good_drive(drive))
48 return 1;
49
50 return 0;
51}
52
53/**
54 * ide_dma_host_set - Enable/disable DMA on a host
55 * @drive: drive to control
56 *
57 * Enable/disable DMA on an IDE controller following generic
58 * bus-mastering IDE controller behaviour.
59 */
60
61void ide_dma_host_set(ide_drive_t *drive, int on)
62{
63 ide_hwif_t *hwif = drive->hwif;
64 u8 unit = drive->dn & 1;
65 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
66
67 if (on)
68 dma_stat |= (1 << (5 + unit));
69 else
70 dma_stat &= ~(1 << (5 + unit));
71
72 if (hwif->host_flags & IDE_HFLAG_MMIO)
73 writeb(dma_stat,
74 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
75 else
76 outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
77}
78EXPORT_SYMBOL_GPL(ide_dma_host_set);
79
80/**
81 * ide_build_dmatable - build IDE DMA table
82 *
83 * ide_build_dmatable() prepares a dma request. We map the command
84 * to get the pci bus addresses of the buffers and then build up
85 * the PRD table that the IDE layer wants to be fed.
86 *
87 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
88 * but at least one (e.g. CS5530) misinterprets it as zero (!).
89 * So we break the 64KB entry into two 32KB entries instead.
90 *
91 * Returns the number of built PRD entries if all went okay,
92 * returns 0 otherwise.
93 *
94 * May also be invoked from trm290.c
95 */
96
97int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
98{
99 ide_hwif_t *hwif = drive->hwif;
100 __le32 *table = (__le32 *)hwif->dmatable_cpu;
101 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
102 unsigned int count = 0;
103 int i;
104 struct scatterlist *sg;
105
106 hwif->sg_nents = ide_build_sglist(drive, rq);
107 if (hwif->sg_nents == 0)
108 return 0;
109
110 for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
111 u32 cur_addr, cur_len, xcount, bcount;
112
113 cur_addr = sg_dma_address(sg);
114 cur_len = sg_dma_len(sg);
115
116 /*
117 * Fill in the dma table, without crossing any 64kB boundaries.
118 * Most hardware requires 16-bit alignment of all blocks,
119 * but the trm290 requires 32-bit alignment.
120 */
121
122 while (cur_len) {
123 if (count++ >= PRD_ENTRIES)
124 goto use_pio_instead;
125
126 bcount = 0x10000 - (cur_addr & 0xffff);
127 if (bcount > cur_len)
128 bcount = cur_len;
129 *table++ = cpu_to_le32(cur_addr);
130 xcount = bcount & 0xffff;
131 if (is_trm290)
132 xcount = ((xcount >> 2) - 1) << 16;
133 if (xcount == 0x0000) {
134 if (count++ >= PRD_ENTRIES)
135 goto use_pio_instead;
136 *table++ = cpu_to_le32(0x8000);
137 *table++ = cpu_to_le32(cur_addr + 0x8000);
138 xcount = 0x8000;
139 }
140 *table++ = cpu_to_le32(xcount);
141 cur_addr += bcount;
142 cur_len -= bcount;
143 }
144 }
145
146 if (count) {
147 if (!is_trm290)
148 *--table |= cpu_to_le32(0x80000000);
149 return count;
150 }
151
152use_pio_instead:
153 printk(KERN_ERR "%s: %s\n", drive->name,
154 count ? "DMA table too small" : "empty DMA table?");
155
156 ide_destroy_dmatable(drive);
157
158 return 0; /* revert to PIO for this request */
159}
160EXPORT_SYMBOL_GPL(ide_build_dmatable);
161
162/**
163 * ide_dma_setup - begin a DMA phase
164 * @drive: target device
165 *
166 * Build an IDE DMA PRD (IDE speak for scatter gather table)
167 * and then set up the DMA transfer registers for a device
168 * that follows generic IDE PCI DMA behaviour. Controllers can
169 * override this function if they need to
170 *
171 * Returns 0 on success. If a PIO fallback is required then 1
172 * is returned.
173 */
174
175int ide_dma_setup(ide_drive_t *drive)
176{
177 ide_hwif_t *hwif = drive->hwif;
178 struct request *rq = hwif->hwgroup->rq;
179 unsigned int reading;
180 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
181 u8 dma_stat;
182
183 if (rq_data_dir(rq))
184 reading = 0;
185 else
186 reading = 1 << 3;
187
188 /* fall back to pio! */
189 if (!ide_build_dmatable(drive, rq)) {
190 ide_map_sg(drive, rq);
191 return 1;
192 }
193
194 /* PRD table */
195 if (hwif->host_flags & IDE_HFLAG_MMIO)
196 writel(hwif->dmatable_dma,
197 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
198 else
199 outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
200
201 /* specify r/w */
202 if (mmio)
203 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
204 else
205 outb(reading, hwif->dma_base + ATA_DMA_CMD);
206
207 /* read DMA status for INTR & ERROR flags */
208 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
209
210 /* clear INTR & ERROR flags */
211 if (mmio)
212 writeb(dma_stat | 6,
213 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
214 else
215 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
216
217 drive->waiting_for_dma = 1;
218 return 0;
219}
220EXPORT_SYMBOL_GPL(ide_dma_setup);
221
222/**
223 * dma_timer_expiry - handle a DMA timeout
224 * @drive: Drive that timed out
225 *
226 * An IDE DMA transfer timed out. In the event of an error we ask
227 * the driver to resolve the problem, if a DMA transfer is still
228 * in progress we continue to wait (arguably we need to add a
229 * secondary 'I don't care what the drive thinks' timeout here)
230 * Finally if we have an interrupt we let it complete the I/O.
231 * But only one time - we clear expiry and if it's still not
232 * completed after WAIT_CMD, we error and retry in PIO.
233 * This can occur if an interrupt is lost or due to hang or bugs.
234 */
235
236static int dma_timer_expiry(ide_drive_t *drive)
237{
238 ide_hwif_t *hwif = drive->hwif;
239 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
240
241 printk(KERN_WARNING "%s: %s: DMA status (0x%02x)\n",
242 drive->name, __func__, dma_stat);
243
244 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
245 return WAIT_CMD;
246
247 hwif->hwgroup->expiry = NULL; /* one free ride for now */
248
249 /* 1 dmaing, 2 error, 4 intr */
250 if (dma_stat & 2) /* ERROR */
251 return -1;
252
253 if (dma_stat & 1) /* DMAing */
254 return WAIT_CMD;
255
256 if (dma_stat & 4) /* Got an Interrupt */
257 return WAIT_CMD;
258
259 return 0; /* Status is unknown -- reset the bus */
260}
261
262void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
263{
264 /* issue cmd to drive */
265 ide_execute_command(drive, command, &ide_dma_intr, 2 * WAIT_CMD,
266 dma_timer_expiry);
267}
268EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
269
270void ide_dma_start(ide_drive_t *drive)
271{
272 ide_hwif_t *hwif = drive->hwif;
273 u8 dma_cmd;
274
275 /* Note that this is done *after* the cmd has
276 * been issued to the drive, as per the BM-IDE spec.
277 * The Promise Ultra33 doesn't work correctly when
278 * we do this part before issuing the drive cmd.
279 */
280 if (hwif->host_flags & IDE_HFLAG_MMIO) {
281 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
282 /* start DMA */
283 writeb(dma_cmd | 1,
284 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
285 } else {
286 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
287 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
288 }
289
290 wmb();
291}
292EXPORT_SYMBOL_GPL(ide_dma_start);
293
294/* returns 1 on error, 0 otherwise */
295int ide_dma_end(ide_drive_t *drive)
296{
297 ide_hwif_t *hwif = drive->hwif;
298 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
299 u8 dma_stat = 0, dma_cmd = 0;
300
301 drive->waiting_for_dma = 0;
302
303 if (mmio) {
304 /* get DMA command mode */
305 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
306 /* stop DMA */
307 writeb(dma_cmd & ~1,
308 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
309 } else {
310 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
311 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
312 }
313
314 /* get DMA status */
315 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
316
317 if (mmio)
318 /* clear the INTR & ERROR bits */
319 writeb(dma_stat | 6,
320 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
321 else
322 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
323
324 /* purge DMA mappings */
325 ide_destroy_dmatable(drive);
326 /* verify good DMA status */
327 wmb();
328 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
329}
330EXPORT_SYMBOL_GPL(ide_dma_end);
331
332/* returns 1 if dma irq issued, 0 otherwise */
333int ide_dma_test_irq(ide_drive_t *drive)
334{
335 ide_hwif_t *hwif = drive->hwif;
336 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
337
338 /* return 1 if INTR asserted */
339 if ((dma_stat & 4) == 4)
340 return 1;
341
342 return 0;
343}
344EXPORT_SYMBOL_GPL(ide_dma_test_irq);
345
346const struct ide_dma_ops sff_dma_ops = {
347 .dma_host_set = ide_dma_host_set,
348 .dma_setup = ide_dma_setup,
349 .dma_exec_cmd = ide_dma_exec_cmd,
350 .dma_start = ide_dma_start,
351 .dma_end = ide_dma_end,
352 .dma_test_irq = ide_dma_test_irq,
353 .dma_timeout = ide_dma_timeout,
354 .dma_lost_irq = ide_dma_lost_irq,
355};
356EXPORT_SYMBOL_GPL(sff_dma_ops);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index ef2f1504c0d5..fffd11717b2d 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -28,24 +28,13 @@
28 * for supplying a Promise UDMA board & WD UDMA drive for this work! 28 * for supplying a Promise UDMA board & WD UDMA drive for this work!
29 */ 29 */
30 30
31#include <linux/module.h>
32#include <linux/types.h> 31#include <linux/types.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/timer.h>
35#include <linux/mm.h>
36#include <linux/interrupt.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/ide.h> 33#include <linux/ide.h>
40#include <linux/delay.h>
41#include <linux/scatterlist.h> 34#include <linux/scatterlist.h>
42#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
43 36
44#include <asm/io.h> 37static const struct drive_list_entry drive_whitelist[] = {
45#include <asm/irq.h>
46
47static const struct drive_list_entry drive_whitelist [] = {
48
49 { "Micropolis 2112A" , NULL }, 38 { "Micropolis 2112A" , NULL },
50 { "CONNER CTMA 4000" , NULL }, 39 { "CONNER CTMA 4000" , NULL },
51 { "CONNER CTT8000-A" , NULL }, 40 { "CONNER CTT8000-A" , NULL },
@@ -53,8 +42,7 @@ static const struct drive_list_entry drive_whitelist [] = {
53 { NULL , NULL } 42 { NULL , NULL }
54}; 43};
55 44
56static const struct drive_list_entry drive_blacklist [] = { 45static const struct drive_list_entry drive_blacklist[] = {
57
58 { "WDC AC11000H" , NULL }, 46 { "WDC AC11000H" , NULL },
59 { "WDC AC22100H" , NULL }, 47 { "WDC AC22100H" , NULL },
60 { "WDC AC32500H" , NULL }, 48 { "WDC AC32500H" , NULL },
@@ -94,11 +82,11 @@ static const struct drive_list_entry drive_blacklist [] = {
94 * ide_dma_intr - IDE DMA interrupt handler 82 * ide_dma_intr - IDE DMA interrupt handler
95 * @drive: the drive the interrupt is for 83 * @drive: the drive the interrupt is for
96 * 84 *
97 * Handle an interrupt completing a read/write DMA transfer on an 85 * Handle an interrupt completing a read/write DMA transfer on an
98 * IDE device 86 * IDE device
99 */ 87 */
100 88
101ide_startstop_t ide_dma_intr (ide_drive_t *drive) 89ide_startstop_t ide_dma_intr(ide_drive_t *drive)
102{ 90{
103 ide_hwif_t *hwif = drive->hwif; 91 ide_hwif_t *hwif = drive->hwif;
104 u8 stat = 0, dma_stat = 0; 92 u8 stat = 0, dma_stat = 0;
@@ -108,20 +96,19 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
108 96
109 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) { 97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
110 if (!dma_stat) { 98 if (!dma_stat) {
111 struct request *rq = HWGROUP(drive)->rq; 99 struct request *rq = hwif->hwgroup->rq;
112 100
113 task_end_request(drive, rq, stat); 101 task_end_request(drive, rq, stat);
114 return ide_stopped; 102 return ide_stopped;
115 } 103 }
116 printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", 104 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
117 drive->name, dma_stat); 105 drive->name, __func__, dma_stat);
118 } 106 }
119 return ide_error(drive, "dma_intr", stat); 107 return ide_error(drive, "dma_intr", stat);
120} 108}
121
122EXPORT_SYMBOL_GPL(ide_dma_intr); 109EXPORT_SYMBOL_GPL(ide_dma_intr);
123 110
124static int ide_dma_good_drive(ide_drive_t *drive) 111int ide_dma_good_drive(ide_drive_t *drive)
125{ 112{
126 return ide_in_drive_list(drive->id, drive_whitelist); 113 return ide_in_drive_list(drive->id, drive_whitelist);
127} 114}
@@ -139,7 +126,7 @@ static int ide_dma_good_drive(ide_drive_t *drive)
139 126
140int ide_build_sglist(ide_drive_t *drive, struct request *rq) 127int ide_build_sglist(ide_drive_t *drive, struct request *rq)
141{ 128{
142 ide_hwif_t *hwif = HWIF(drive); 129 ide_hwif_t *hwif = drive->hwif;
143 struct scatterlist *sg = hwif->sg_table; 130 struct scatterlist *sg = hwif->sg_table;
144 131
145 ide_map_sg(drive, rq); 132 ide_map_sg(drive, rq);
@@ -152,106 +139,8 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
152 return dma_map_sg(hwif->dev, sg, hwif->sg_nents, 139 return dma_map_sg(hwif->dev, sg, hwif->sg_nents,
153 hwif->sg_dma_direction); 140 hwif->sg_dma_direction);
154} 141}
155
156EXPORT_SYMBOL_GPL(ide_build_sglist); 142EXPORT_SYMBOL_GPL(ide_build_sglist);
157 143
158#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
159/**
160 * ide_build_dmatable - build IDE DMA table
161 *
162 * ide_build_dmatable() prepares a dma request. We map the command
163 * to get the pci bus addresses of the buffers and then build up
164 * the PRD table that the IDE layer wants to be fed. The code
165 * knows about the 64K wrap bug in the CS5530.
166 *
167 * Returns the number of built PRD entries if all went okay,
168 * returns 0 otherwise.
169 *
170 * May also be invoked from trm290.c
171 */
172
173int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
174{
175 ide_hwif_t *hwif = HWIF(drive);
176 __le32 *table = (__le32 *)hwif->dmatable_cpu;
177 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
178 unsigned int count = 0;
179 int i;
180 struct scatterlist *sg;
181
182 hwif->sg_nents = i = ide_build_sglist(drive, rq);
183
184 if (!i)
185 return 0;
186
187 sg = hwif->sg_table;
188 while (i) {
189 u32 cur_addr;
190 u32 cur_len;
191
192 cur_addr = sg_dma_address(sg);
193 cur_len = sg_dma_len(sg);
194
195 /*
196 * Fill in the dma table, without crossing any 64kB boundaries.
197 * Most hardware requires 16-bit alignment of all blocks,
198 * but the trm290 requires 32-bit alignment.
199 */
200
201 while (cur_len) {
202 if (count++ >= PRD_ENTRIES) {
203 printk(KERN_ERR "%s: DMA table too small\n", drive->name);
204 goto use_pio_instead;
205 } else {
206 u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff);
207
208 if (bcount > cur_len)
209 bcount = cur_len;
210 *table++ = cpu_to_le32(cur_addr);
211 xcount = bcount & 0xffff;
212 if (is_trm290)
213 xcount = ((xcount >> 2) - 1) << 16;
214 else if (xcount == 0x0000) {
215 /*
216 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
217 * but at least one (e.g. CS5530) misinterprets it as zero (!).
218 * So here we break the 64KB entry into two 32KB entries instead.
219 */
220 if (count++ >= PRD_ENTRIES) {
221 printk(KERN_ERR "%s: DMA table too small\n", drive->name);
222 goto use_pio_instead;
223 }
224 *table++ = cpu_to_le32(0x8000);
225 *table++ = cpu_to_le32(cur_addr + 0x8000);
226 xcount = 0x8000;
227 }
228 *table++ = cpu_to_le32(xcount);
229 cur_addr += bcount;
230 cur_len -= bcount;
231 }
232 }
233
234 sg = sg_next(sg);
235 i--;
236 }
237
238 if (count) {
239 if (!is_trm290)
240 *--table |= cpu_to_le32(0x80000000);
241 return count;
242 }
243
244 printk(KERN_ERR "%s: empty DMA table?\n", drive->name);
245
246use_pio_instead:
247 ide_destroy_dmatable(drive);
248
249 return 0; /* revert to PIO for this request */
250}
251
252EXPORT_SYMBOL_GPL(ide_build_dmatable);
253#endif
254
255/** 144/**
256 * ide_destroy_dmatable - clean up DMA mapping 145 * ide_destroy_dmatable - clean up DMA mapping
257 * @drive: The drive to unmap 146 * @drive: The drive to unmap
@@ -262,147 +151,30 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
262 * an oops as only one mapping can be live for each target at a given 151 * an oops as only one mapping can be live for each target at a given
263 * time. 152 * time.
264 */ 153 */
265 154
266void ide_destroy_dmatable (ide_drive_t *drive) 155void ide_destroy_dmatable(ide_drive_t *drive)
267{ 156{
268 ide_hwif_t *hwif = drive->hwif; 157 ide_hwif_t *hwif = drive->hwif;
269 158
270 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents, 159 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents,
271 hwif->sg_dma_direction); 160 hwif->sg_dma_direction);
272} 161}
273
274EXPORT_SYMBOL_GPL(ide_destroy_dmatable); 162EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
275 163
276#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
277/**
278 * config_drive_for_dma - attempt to activate IDE DMA
279 * @drive: the drive to place in DMA mode
280 *
281 * If the drive supports at least mode 2 DMA or UDMA of any kind
282 * then attempt to place it into DMA mode. Drives that are known to
283 * support DMA but predate the DMA properties or that are known
284 * to have DMA handling bugs are also set up appropriately based
285 * on the good/bad drive lists.
286 */
287
288static int config_drive_for_dma (ide_drive_t *drive)
289{
290 ide_hwif_t *hwif = drive->hwif;
291 u16 *id = drive->id;
292
293 if (drive->media != ide_disk) {
294 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
295 return 0;
296 }
297
298 /*
299 * Enable DMA on any drive that has
300 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
301 */
302 if ((id[ATA_ID_FIELD_VALID] & 4) &&
303 ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
304 return 1;
305
306 /*
307 * Enable DMA on any drive that has mode2 DMA
308 * (multi or single) enabled
309 */
310 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
311 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
312 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
313 return 1;
314
315 /* Consult the list of known "good" drives */
316 if (ide_dma_good_drive(drive))
317 return 1;
318
319 return 0;
320}
321
322/**
323 * dma_timer_expiry - handle a DMA timeout
324 * @drive: Drive that timed out
325 *
326 * An IDE DMA transfer timed out. In the event of an error we ask
327 * the driver to resolve the problem, if a DMA transfer is still
328 * in progress we continue to wait (arguably we need to add a
329 * secondary 'I don't care what the drive thinks' timeout here)
330 * Finally if we have an interrupt we let it complete the I/O.
331 * But only one time - we clear expiry and if it's still not
332 * completed after WAIT_CMD, we error and retry in PIO.
333 * This can occur if an interrupt is lost or due to hang or bugs.
334 */
335
336static int dma_timer_expiry (ide_drive_t *drive)
337{
338 ide_hwif_t *hwif = HWIF(drive);
339 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
340
341 printk(KERN_WARNING "%s: dma_timer_expiry: dma status == 0x%02x\n",
342 drive->name, dma_stat);
343
344 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
345 return WAIT_CMD;
346
347 HWGROUP(drive)->expiry = NULL; /* one free ride for now */
348
349 /* 1 dmaing, 2 error, 4 intr */
350 if (dma_stat & 2) /* ERROR */
351 return -1;
352
353 if (dma_stat & 1) /* DMAing */
354 return WAIT_CMD;
355
356 if (dma_stat & 4) /* Got an Interrupt */
357 return WAIT_CMD;
358
359 return 0; /* Status is unknown -- reset the bus */
360}
361
362/**
363 * ide_dma_host_set - Enable/disable DMA on a host
364 * @drive: drive to control
365 *
366 * Enable/disable DMA on an IDE controller following generic
367 * bus-mastering IDE controller behaviour.
368 */
369
370void ide_dma_host_set(ide_drive_t *drive, int on)
371{
372 ide_hwif_t *hwif = HWIF(drive);
373 u8 unit = (drive->select.b.unit & 0x01);
374 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
375
376 if (on)
377 dma_stat |= (1 << (5 + unit));
378 else
379 dma_stat &= ~(1 << (5 + unit));
380
381 if (hwif->host_flags & IDE_HFLAG_MMIO)
382 writeb(dma_stat,
383 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
384 else
385 outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
386}
387
388EXPORT_SYMBOL_GPL(ide_dma_host_set);
389#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
390
391/** 164/**
392 * ide_dma_off_quietly - Generic DMA kill 165 * ide_dma_off_quietly - Generic DMA kill
393 * @drive: drive to control 166 * @drive: drive to control
394 * 167 *
395 * Turn off the current DMA on this IDE controller. 168 * Turn off the current DMA on this IDE controller.
396 */ 169 */
397 170
398void ide_dma_off_quietly(ide_drive_t *drive) 171void ide_dma_off_quietly(ide_drive_t *drive)
399{ 172{
400 drive->using_dma = 0; 173 drive->dev_flags &= ~IDE_DFLAG_USING_DMA;
401 ide_toggle_bounce(drive, 0); 174 ide_toggle_bounce(drive, 0);
402 175
403 drive->hwif->dma_ops->dma_host_set(drive, 0); 176 drive->hwif->dma_ops->dma_host_set(drive, 0);
404} 177}
405
406EXPORT_SYMBOL(ide_dma_off_quietly); 178EXPORT_SYMBOL(ide_dma_off_quietly);
407 179
408/** 180/**
@@ -418,7 +190,6 @@ void ide_dma_off(ide_drive_t *drive)
418 printk(KERN_INFO "%s: DMA disabled\n", drive->name); 190 printk(KERN_INFO "%s: DMA disabled\n", drive->name);
419 ide_dma_off_quietly(drive); 191 ide_dma_off_quietly(drive);
420} 192}
421
422EXPORT_SYMBOL(ide_dma_off); 193EXPORT_SYMBOL(ide_dma_off);
423 194
424/** 195/**
@@ -430,167 +201,13 @@ EXPORT_SYMBOL(ide_dma_off);
430 201
431void ide_dma_on(ide_drive_t *drive) 202void ide_dma_on(ide_drive_t *drive)
432{ 203{
433 drive->using_dma = 1; 204 drive->dev_flags |= IDE_DFLAG_USING_DMA;
434 ide_toggle_bounce(drive, 1); 205 ide_toggle_bounce(drive, 1);
435 206
436 drive->hwif->dma_ops->dma_host_set(drive, 1); 207 drive->hwif->dma_ops->dma_host_set(drive, 1);
437} 208}
438 209
439#ifdef CONFIG_BLK_DEV_IDEDMA_SFF 210int __ide_dma_bad_drive(ide_drive_t *drive)
440/**
441 * ide_dma_setup - begin a DMA phase
442 * @drive: target device
443 *
444 * Build an IDE DMA PRD (IDE speak for scatter gather table)
445 * and then set up the DMA transfer registers for a device
446 * that follows generic IDE PCI DMA behaviour. Controllers can
447 * override this function if they need to
448 *
449 * Returns 0 on success. If a PIO fallback is required then 1
450 * is returned.
451 */
452
453int ide_dma_setup(ide_drive_t *drive)
454{
455 ide_hwif_t *hwif = drive->hwif;
456 struct request *rq = HWGROUP(drive)->rq;
457 unsigned int reading;
458 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
459 u8 dma_stat;
460
461 if (rq_data_dir(rq))
462 reading = 0;
463 else
464 reading = 1 << 3;
465
466 /* fall back to pio! */
467 if (!ide_build_dmatable(drive, rq)) {
468 ide_map_sg(drive, rq);
469 return 1;
470 }
471
472 /* PRD table */
473 if (hwif->host_flags & IDE_HFLAG_MMIO)
474 writel(hwif->dmatable_dma,
475 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
476 else
477 outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
478
479 /* specify r/w */
480 if (mmio)
481 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
482 else
483 outb(reading, hwif->dma_base + ATA_DMA_CMD);
484
485 /* read DMA status for INTR & ERROR flags */
486 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
487
488 /* clear INTR & ERROR flags */
489 if (mmio)
490 writeb(dma_stat | 6,
491 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
492 else
493 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
494
495 drive->waiting_for_dma = 1;
496 return 0;
497}
498
499EXPORT_SYMBOL_GPL(ide_dma_setup);
500
501void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
502{
503 /* issue cmd to drive */
504 ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);
505}
506EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
507
508void ide_dma_start(ide_drive_t *drive)
509{
510 ide_hwif_t *hwif = drive->hwif;
511 u8 dma_cmd;
512
513 /* Note that this is done *after* the cmd has
514 * been issued to the drive, as per the BM-IDE spec.
515 * The Promise Ultra33 doesn't work correctly when
516 * we do this part before issuing the drive cmd.
517 */
518 if (hwif->host_flags & IDE_HFLAG_MMIO) {
519 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
520 /* start DMA */
521 writeb(dma_cmd | 1,
522 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
523 } else {
524 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
525 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
526 }
527
528 hwif->dma = 1;
529 wmb();
530}
531
532EXPORT_SYMBOL_GPL(ide_dma_start);
533
534/* returns 1 on error, 0 otherwise */
535int __ide_dma_end (ide_drive_t *drive)
536{
537 ide_hwif_t *hwif = drive->hwif;
538 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
539 u8 dma_stat = 0, dma_cmd = 0;
540
541 drive->waiting_for_dma = 0;
542
543 if (mmio) {
544 /* get DMA command mode */
545 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
546 /* stop DMA */
547 writeb(dma_cmd & ~1,
548 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
549 } else {
550 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
551 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
552 }
553
554 /* get DMA status */
555 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
556
557 if (mmio)
558 /* clear the INTR & ERROR bits */
559 writeb(dma_stat | 6,
560 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
561 else
562 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
563
564 /* purge DMA mappings */
565 ide_destroy_dmatable(drive);
566 /* verify good DMA status */
567 hwif->dma = 0;
568 wmb();
569 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
570}
571
572EXPORT_SYMBOL(__ide_dma_end);
573
574/* returns 1 if dma irq issued, 0 otherwise */
575int ide_dma_test_irq(ide_drive_t *drive)
576{
577 ide_hwif_t *hwif = HWIF(drive);
578 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
579
580 /* return 1 if INTR asserted */
581 if ((dma_stat & 4) == 4)
582 return 1;
583 if (!drive->waiting_for_dma)
584 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
585 drive->name, __func__);
586 return 0;
587}
588EXPORT_SYMBOL_GPL(ide_dma_test_irq);
589#else
590static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
591#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
592
593int __ide_dma_bad_drive (ide_drive_t *drive)
594{ 211{
595 u16 *id = drive->id; 212 u16 *id = drive->id;
596 213
@@ -602,7 +219,6 @@ int __ide_dma_bad_drive (ide_drive_t *drive)
602 } 219 }
603 return 0; 220 return 0;
604} 221}
605
606EXPORT_SYMBOL(__ide_dma_bad_drive); 222EXPORT_SYMBOL(__ide_dma_bad_drive);
607 223
608static const u8 xfer_mode_bases[] = { 224static const u8 xfer_mode_bases[] = {
@@ -618,7 +234,7 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
618 const struct ide_port_ops *port_ops = hwif->port_ops; 234 const struct ide_port_ops *port_ops = hwif->port_ops;
619 unsigned int mask = 0; 235 unsigned int mask = 0;
620 236
621 switch(base) { 237 switch (base) {
622 case XFER_UDMA_0: 238 case XFER_UDMA_0:
623 if ((id[ATA_ID_FIELD_VALID] & 4) == 0) 239 if ((id[ATA_ID_FIELD_VALID] & 4) == 0)
624 break; 240 break;
@@ -719,7 +335,6 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
719 335
720 return mode; 336 return mode;
721} 337}
722
723EXPORT_SYMBOL_GPL(ide_find_dma_mode); 338EXPORT_SYMBOL_GPL(ide_find_dma_mode);
724 339
725static int ide_tune_dma(ide_drive_t *drive) 340static int ide_tune_dma(ide_drive_t *drive)
@@ -727,7 +342,8 @@ static int ide_tune_dma(ide_drive_t *drive)
727 ide_hwif_t *hwif = drive->hwif; 342 ide_hwif_t *hwif = drive->hwif;
728 u8 speed; 343 u8 speed;
729 344
730 if (drive->nodma || ata_id_has_dma(drive->id) == 0) 345 if (ata_id_has_dma(drive->id) == 0 ||
346 (drive->dev_flags & IDE_DFLAG_NODMA))
731 return 0; 347 return 0;
732 348
733 /* consult the list of known "bad" drives */ 349 /* consult the list of known "bad" drives */
@@ -827,66 +443,59 @@ void ide_check_dma_crc(ide_drive_t *drive)
827 ide_dma_on(drive); 443 ide_dma_on(drive);
828} 444}
829 445
830#ifdef CONFIG_BLK_DEV_IDEDMA_SFF 446void ide_dma_lost_irq(ide_drive_t *drive)
831void ide_dma_lost_irq (ide_drive_t *drive)
832{ 447{
833 printk("%s: DMA interrupt recovery\n", drive->name); 448 printk(KERN_ERR "%s: DMA interrupt recovery\n", drive->name);
834} 449}
450EXPORT_SYMBOL_GPL(ide_dma_lost_irq);
835 451
836EXPORT_SYMBOL(ide_dma_lost_irq); 452void ide_dma_timeout(ide_drive_t *drive)
837
838void ide_dma_timeout (ide_drive_t *drive)
839{ 453{
840 ide_hwif_t *hwif = HWIF(drive); 454 ide_hwif_t *hwif = drive->hwif;
841 455
842 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); 456 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name);
843 457
844 if (hwif->dma_ops->dma_test_irq(drive)) 458 if (hwif->dma_ops->dma_test_irq(drive))
845 return; 459 return;
846 460
461 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
462
847 hwif->dma_ops->dma_end(drive); 463 hwif->dma_ops->dma_end(drive);
848} 464}
849 465EXPORT_SYMBOL_GPL(ide_dma_timeout);
850EXPORT_SYMBOL(ide_dma_timeout);
851 466
852void ide_release_dma_engine(ide_hwif_t *hwif) 467void ide_release_dma_engine(ide_hwif_t *hwif)
853{ 468{
854 if (hwif->dmatable_cpu) { 469 if (hwif->dmatable_cpu) {
855 struct pci_dev *pdev = to_pci_dev(hwif->dev); 470 int prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
856 471
857 pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES, 472 dma_free_coherent(hwif->dev, prd_size,
858 hwif->dmatable_cpu, hwif->dmatable_dma); 473 hwif->dmatable_cpu, hwif->dmatable_dma);
859 hwif->dmatable_cpu = NULL; 474 hwif->dmatable_cpu = NULL;
860 } 475 }
861} 476}
477EXPORT_SYMBOL_GPL(ide_release_dma_engine);
862 478
863int ide_allocate_dma_engine(ide_hwif_t *hwif) 479int ide_allocate_dma_engine(ide_hwif_t *hwif)
864{ 480{
865 struct pci_dev *pdev = to_pci_dev(hwif->dev); 481 int prd_size;
866 482
867 hwif->dmatable_cpu = pci_alloc_consistent(pdev, 483 if (hwif->prd_max_nents == 0)
868 PRD_ENTRIES * PRD_BYTES, 484 hwif->prd_max_nents = PRD_ENTRIES;
869 &hwif->dmatable_dma); 485 if (hwif->prd_ent_size == 0)
486 hwif->prd_ent_size = PRD_BYTES;
870 487
871 if (hwif->dmatable_cpu) 488 prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
872 return 0;
873 489
874 printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n", 490 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, prd_size,
491 &hwif->dmatable_dma,
492 GFP_ATOMIC);
493 if (hwif->dmatable_cpu == NULL) {
494 printk(KERN_ERR "%s: unable to allocate PRD table\n",
875 hwif->name); 495 hwif->name);
496 return -ENOMEM;
497 }
876 498
877 return 1; 499 return 0;
878} 500}
879EXPORT_SYMBOL_GPL(ide_allocate_dma_engine); 501EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
880
881const struct ide_dma_ops sff_dma_ops = {
882 .dma_host_set = ide_dma_host_set,
883 .dma_setup = ide_dma_setup,
884 .dma_exec_cmd = ide_dma_exec_cmd,
885 .dma_start = ide_dma_start,
886 .dma_end = __ide_dma_end,
887 .dma_test_irq = ide_dma_test_irq,
888 .dma_timeout = ide_dma_timeout,
889 .dma_lost_irq = ide_dma_lost_irq,
890};
891EXPORT_SYMBOL_GPL(sff_dma_ops);
892#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index d36f155470a4..cf0aa25470ee 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#define DRV_NAME "ide-floppy" 18#define DRV_NAME "ide-floppy"
19#define PFX DRV_NAME ": "
19 20
20#define IDEFLOPPY_VERSION "1.00" 21#define IDEFLOPPY_VERSION "1.00"
21 22
@@ -48,17 +49,17 @@
48 49
49#include "ide-floppy.h" 50#include "ide-floppy.h"
50 51
51/* define to see debug info */ 52/* module parameters */
52#define IDEFLOPPY_DEBUG_LOG 0 53static unsigned long debug_mask;
54module_param(debug_mask, ulong, 0644);
53 55
54/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */ 56/* define to see debug info */
55#define IDEFLOPPY_DEBUG(fmt, args...) 57#define IDEFLOPPY_DEBUG_LOG 0
56 58
57#if IDEFLOPPY_DEBUG_LOG 59#if IDEFLOPPY_DEBUG_LOG
58#define debug_log(fmt, args...) \ 60#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
59 printk(KERN_INFO "ide-floppy: " fmt, ## args)
60#else 61#else
61#define debug_log(fmt, args...) do {} while (0) 62#define ide_debug_log(lvl, fmt, args...) do {} while (0)
62#endif 63#endif
63 64
64/* 65/*
@@ -73,18 +74,17 @@
73#define CAPACITY_CURRENT 0x02 74#define CAPACITY_CURRENT 0x02
74#define CAPACITY_NO_CARTRIDGE 0x03 75#define CAPACITY_NO_CARTRIDGE 0x03
75 76
76#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */ 77/*
78 * The following delay solves a problem with ATAPI Zip 100 drive where BSY bit
79 * was apparently being deasserted before the unit was ready to receive data.
80 */
81#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */
77 82
78/* Error code returned in rq->errors to the higher part of the driver. */ 83/* Error code returned in rq->errors to the higher part of the driver. */
79#define IDEFLOPPY_ERROR_GENERAL 101 84#define IDEFLOPPY_ERROR_GENERAL 101
80 85
81static DEFINE_MUTEX(idefloppy_ref_mutex); 86static DEFINE_MUTEX(idefloppy_ref_mutex);
82 87
83#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
84
85#define ide_floppy_g(disk) \
86 container_of((disk)->private_data, struct ide_floppy_obj, driver)
87
88static void idefloppy_cleanup_obj(struct kref *); 88static void idefloppy_cleanup_obj(struct kref *);
89 89
90static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) 90static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
@@ -92,7 +92,7 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
92 struct ide_floppy_obj *floppy = NULL; 92 struct ide_floppy_obj *floppy = NULL;
93 93
94 mutex_lock(&idefloppy_ref_mutex); 94 mutex_lock(&idefloppy_ref_mutex);
95 floppy = ide_floppy_g(disk); 95 floppy = ide_drv_g(disk, ide_floppy_obj);
96 if (floppy) { 96 if (floppy) {
97 if (ide_device_get(floppy->drive)) 97 if (ide_device_get(floppy->drive))
98 floppy = NULL; 98 floppy = NULL;
@@ -123,13 +123,21 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
123 struct request *rq = HWGROUP(drive)->rq; 123 struct request *rq = HWGROUP(drive)->rq;
124 int error; 124 int error;
125 125
126 debug_log("Reached %s\n", __func__); 126 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
127 127
128 switch (uptodate) { 128 switch (uptodate) {
129 case 0: error = IDEFLOPPY_ERROR_GENERAL; break; 129 case 0:
130 case 1: error = 0; break; 130 error = IDEFLOPPY_ERROR_GENERAL;
131 default: error = uptodate; 131 break;
132
133 case 1:
134 error = 0;
135 break;
136
137 default:
138 error = uptodate;
132 } 139 }
140
133 if (error) 141 if (error)
134 floppy->failed_pc = NULL; 142 floppy->failed_pc = NULL;
135 /* Why does this happen? */ 143 /* Why does this happen? */
@@ -156,13 +164,13 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
156 idefloppy_end_request(drive, 1, 0); 164 idefloppy_end_request(drive, 1, 0);
157} 165}
158 166
159static void ide_floppy_callback(ide_drive_t *drive) 167static void ide_floppy_callback(ide_drive_t *drive, int dsc)
160{ 168{
161 idefloppy_floppy_t *floppy = drive->driver_data; 169 idefloppy_floppy_t *floppy = drive->driver_data;
162 struct ide_atapi_pc *pc = floppy->pc; 170 struct ide_atapi_pc *pc = drive->pc;
163 int uptodate = pc->error ? 0 : 1; 171 int uptodate = pc->error ? 0 : 1;
164 172
165 debug_log("Reached %s\n", __func__); 173 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
166 174
167 if (floppy->failed_pc == pc) 175 if (floppy->failed_pc == pc)
168 floppy->failed_pc = NULL; 176 floppy->failed_pc = NULL;
@@ -171,7 +179,7 @@ static void ide_floppy_callback(ide_drive_t *drive)
171 (pc->rq && blk_pc_request(pc->rq))) 179 (pc->rq && blk_pc_request(pc->rq)))
172 uptodate = 1; /* FIXME */ 180 uptodate = 1; /* FIXME */
173 else if (pc->c[0] == GPCMD_REQUEST_SENSE) { 181 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
174 u8 *buf = floppy->pc->buf; 182 u8 *buf = pc->buf;
175 183
176 if (!pc->error) { 184 if (!pc->error) {
177 floppy->sense_key = buf[2] & 0x0F; 185 floppy->sense_key = buf[2] & 0x0F;
@@ -181,99 +189,20 @@ static void ide_floppy_callback(ide_drive_t *drive)
181 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; 189 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
182 190
183 if (floppy->failed_pc) 191 if (floppy->failed_pc)
184 debug_log("pc = %x, ", floppy->failed_pc->c[0]); 192 ide_debug_log(IDE_DBG_PC, "pc = %x, ",
193 floppy->failed_pc->c[0]);
185 194
186 debug_log("sense key = %x, asc = %x, ascq = %x\n", 195 ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
187 floppy->sense_key, floppy->asc, floppy->ascq); 196 "ascq = %x\n", floppy->sense_key,
197 floppy->asc, floppy->ascq);
188 } else 198 } else
189 printk(KERN_ERR "Error in REQUEST SENSE itself - " 199 printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
190 "Aborting request!\n"); 200 "Aborting request!\n");
191 } 201 }
192 202
193 idefloppy_end_request(drive, uptodate, 0); 203 idefloppy_end_request(drive, uptodate, 0);
194} 204}
195 205
196void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
197{
198 ide_init_pc(pc);
199 pc->c[0] = GPCMD_REQUEST_SENSE;
200 pc->c[4] = 255;
201 pc->req_xfer = 18;
202}
203
204/*
205 * Called when an error was detected during the last packet command. We queue a
206 * request sense packet command in the head of the request list.
207 */
208static void idefloppy_retry_pc(ide_drive_t *drive)
209{
210 struct ide_floppy_obj *floppy = drive->driver_data;
211 struct request *rq = &floppy->request_sense_rq;
212 struct ide_atapi_pc *pc = &floppy->request_sense_pc;
213
214 (void)ide_read_error(drive);
215 ide_floppy_create_request_sense_cmd(pc);
216 ide_queue_pc_head(drive, floppy->disk, pc, rq);
217}
218
219/* The usual interrupt handler called during a packet command. */
220static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
221{
222 idefloppy_floppy_t *floppy = drive->driver_data;
223
224 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
225 WAIT_FLOPPY_CMD, NULL, idefloppy_update_buffers,
226 idefloppy_retry_pc, NULL, ide_io_buffers);
227}
228
229/*
230 * What we have here is a classic case of a top half / bottom half interrupt
231 * service routine. In interrupt mode, the device sends an interrupt to signal
232 * that it is ready to receive a packet. However, we need to delay about 2-3
233 * ticks before issuing the packet or we gets in trouble.
234 */
235static int idefloppy_transfer_pc(ide_drive_t *drive)
236{
237 idefloppy_floppy_t *floppy = drive->driver_data;
238
239 /* Send the actual packet */
240 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
241
242 /* Timeout for the packet command */
243 return WAIT_FLOPPY_CMD;
244}
245
246/*
247 * Called as an interrupt (or directly). When the device says it's ready for a
248 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
249 * transfer_pc.
250 */
251static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
252{
253 idefloppy_floppy_t *floppy = drive->driver_data;
254 struct ide_atapi_pc *pc = floppy->pc;
255 ide_expiry_t *expiry;
256 unsigned int timeout;
257
258 /*
259 * The following delay solves a problem with ATAPI Zip 100 drives
260 * where the Busy flag was apparently being deasserted before the
261 * unit was ready to receive data. This was happening on a
262 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
263 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
264 * used until after the packet is moved in about 50 msec.
265 */
266 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
267 timeout = floppy->ticks;
268 expiry = &idefloppy_transfer_pc;
269 } else {
270 timeout = WAIT_FLOPPY_CMD;
271 expiry = NULL;
272 }
273
274 return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
275}
276
277static void ide_floppy_report_error(idefloppy_floppy_t *floppy, 206static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
278 struct ide_atapi_pc *pc) 207 struct ide_atapi_pc *pc)
279{ 208{
@@ -283,7 +212,7 @@ static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
283 floppy->ascq == 0x00) 212 floppy->ascq == 0x00)
284 return; 213 return;
285 214
286 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, " 215 printk(KERN_ERR PFX "%s: I/O error, pc = %2x, key = %2x, "
287 "asc = %2x, ascq = %2x\n", 216 "asc = %2x, ascq = %2x\n",
288 floppy->drive->name, pc->c[0], floppy->sense_key, 217 floppy->drive->name, pc->c[0], floppy->sense_key,
289 floppy->asc, floppy->ascq); 218 floppy->asc, floppy->ascq);
@@ -298,8 +227,9 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
298 if (floppy->failed_pc == NULL && 227 if (floppy->failed_pc == NULL &&
299 pc->c[0] != GPCMD_REQUEST_SENSE) 228 pc->c[0] != GPCMD_REQUEST_SENSE)
300 floppy->failed_pc = pc; 229 floppy->failed_pc = pc;
230
301 /* Set the current packet command */ 231 /* Set the current packet command */
302 floppy->pc = pc; 232 drive->pc = pc;
303 233
304 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { 234 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
305 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) 235 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
@@ -308,16 +238,15 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
308 pc->error = IDEFLOPPY_ERROR_GENERAL; 238 pc->error = IDEFLOPPY_ERROR_GENERAL;
309 239
310 floppy->failed_pc = NULL; 240 floppy->failed_pc = NULL;
311 drive->pc_callback(drive); 241 drive->pc_callback(drive, 0);
312 return ide_stopped; 242 return ide_stopped;
313 } 243 }
314 244
315 debug_log("Retry number - %d\n", pc->retries); 245 ide_debug_log(IDE_DBG_FUNC, "%s: Retry #%d\n", __func__, pc->retries);
316 246
317 pc->retries++; 247 pc->retries++;
318 248
319 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, 249 return ide_issue_pc(drive, WAIT_FLOPPY_CMD, NULL);
320 WAIT_FLOPPY_CMD, NULL);
321} 250}
322 251
323void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 252void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
@@ -347,23 +276,23 @@ void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
347 length += 32; 276 length += 32;
348 break; 277 break;
349 default: 278 default:
350 printk(KERN_ERR "ide-floppy: unsupported page code " 279 printk(KERN_ERR PFX "unsupported page code in %s\n", __func__);
351 "in create_mode_sense_cmd\n");
352 } 280 }
353 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]); 281 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
354 pc->req_xfer = length; 282 pc->req_xfer = length;
355} 283}
356 284
357static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, 285static void idefloppy_create_rw_cmd(ide_drive_t *drive,
358 struct ide_atapi_pc *pc, struct request *rq, 286 struct ide_atapi_pc *pc, struct request *rq,
359 unsigned long sector) 287 unsigned long sector)
360{ 288{
289 idefloppy_floppy_t *floppy = drive->driver_data;
361 int block = sector / floppy->bs_factor; 290 int block = sector / floppy->bs_factor;
362 int blocks = rq->nr_sectors / floppy->bs_factor; 291 int blocks = rq->nr_sectors / floppy->bs_factor;
363 int cmd = rq_data_dir(rq); 292 int cmd = rq_data_dir(rq);
364 293
365 debug_log("create_rw10_cmd: block == %d, blocks == %d\n", 294 ide_debug_log(IDE_DBG_FUNC, "%s: block: %d, blocks: %d\n", __func__,
366 block, blocks); 295 block, blocks);
367 296
368 ide_init_pc(pc); 297 ide_init_pc(pc);
369 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 298 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
@@ -408,41 +337,42 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
408 struct ide_atapi_pc *pc; 337 struct ide_atapi_pc *pc;
409 unsigned long block = (unsigned long)block_s; 338 unsigned long block = (unsigned long)block_s;
410 339
411 debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n", 340 ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
412 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?", 341 "errors: %d\n",
413 rq->cmd[0], rq->cmd_type, rq->errors); 342 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
343 rq->cmd[0], rq->cmd_type, rq->errors);
414 344
415 debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n", 345 ide_debug_log(IDE_DBG_FUNC, "%s: sector: %ld, nr_sectors: %ld, "
416 __func__, (long)rq->sector, rq->nr_sectors, 346 "current_nr_sectors: %d\n",
417 rq->current_nr_sectors); 347 __func__, (long)rq->sector, rq->nr_sectors,
348 rq->current_nr_sectors);
418 349
419 if (rq->errors >= ERROR_MAX) { 350 if (rq->errors >= ERROR_MAX) {
420 if (floppy->failed_pc) 351 if (floppy->failed_pc)
421 ide_floppy_report_error(floppy, floppy->failed_pc); 352 ide_floppy_report_error(floppy, floppy->failed_pc);
422 else 353 else
423 printk(KERN_ERR "ide-floppy: %s: I/O error\n", 354 printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
424 drive->name); 355
425 idefloppy_end_request(drive, 0, 0); 356 idefloppy_end_request(drive, 0, 0);
426 return ide_stopped; 357 return ide_stopped;
427 } 358 }
428 if (blk_fs_request(rq)) { 359 if (blk_fs_request(rq)) {
429 if (((long)rq->sector % floppy->bs_factor) || 360 if (((long)rq->sector % floppy->bs_factor) ||
430 (rq->nr_sectors % floppy->bs_factor)) { 361 (rq->nr_sectors % floppy->bs_factor)) {
431 printk(KERN_ERR "%s: unsupported r/w request size\n", 362 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
432 drive->name); 363 drive->name);
433 idefloppy_end_request(drive, 0, 0); 364 idefloppy_end_request(drive, 0, 0);
434 return ide_stopped; 365 return ide_stopped;
435 } 366 }
436 pc = &floppy->queued_pc; 367 pc = &floppy->queued_pc;
437 idefloppy_create_rw_cmd(floppy, pc, rq, block); 368 idefloppy_create_rw_cmd(drive, pc, rq, block);
438 } else if (blk_special_request(rq)) { 369 } else if (blk_special_request(rq)) {
439 pc = (struct ide_atapi_pc *) rq->buffer; 370 pc = (struct ide_atapi_pc *) rq->buffer;
440 } else if (blk_pc_request(rq)) { 371 } else if (blk_pc_request(rq)) {
441 pc = &floppy->queued_pc; 372 pc = &floppy->queued_pc;
442 idefloppy_blockpc_cmd(floppy, pc, rq); 373 idefloppy_blockpc_cmd(floppy, pc, rq);
443 } else { 374 } else {
444 blk_dump_rq_flags(rq, 375 blk_dump_rq_flags(rq, PFX "unsupported command in queue");
445 "ide-floppy: unsupported command in queue");
446 idefloppy_end_request(drive, 0, 0); 376 idefloppy_end_request(drive, 0, 0);
447 return ide_stopped; 377 return ide_stopped;
448 } 378 }
@@ -475,8 +405,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
475 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE); 405 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
476 406
477 if (ide_queue_pc_tail(drive, disk, &pc)) { 407 if (ide_queue_pc_tail(drive, disk, &pc)) {
478 printk(KERN_ERR "ide-floppy: Can't get flexible disk page" 408 printk(KERN_ERR PFX "Can't get flexible disk page params\n");
479 " parameters\n");
480 return 1; 409 return 1;
481 } 410 }
482 411
@@ -499,7 +428,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
499 capacity = cyls * heads * sectors * sector_size; 428 capacity = cyls * heads * sectors * sector_size;
500 429
501 if (memcmp(page, &floppy->flexible_disk_page, 32)) 430 if (memcmp(page, &floppy->flexible_disk_page, 32))
502 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " 431 printk(KERN_INFO PFX "%s: %dkB, %d/%d/%d CHS, %d kBps, "
503 "%d sector size, %d rpm\n", 432 "%d sector size, %d rpm\n",
504 drive->name, capacity / 1024, cyls, heads, 433 drive->name, capacity / 1024, cyls, heads,
505 sectors, transfer_rate / 8, sector_size, rpm); 434 sectors, transfer_rate / 8, sector_size, rpm);
@@ -511,7 +440,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
511 lba_capacity = floppy->blocks * floppy->block_size; 440 lba_capacity = floppy->blocks * floppy->block_size;
512 441
513 if (capacity < lba_capacity) { 442 if (capacity < lba_capacity) {
514 printk(KERN_NOTICE "%s: The disk reports a capacity of %d " 443 printk(KERN_NOTICE PFX "%s: The disk reports a capacity of %d "
515 "bytes, but the drive only handles %d\n", 444 "bytes, but the drive only handles %d\n",
516 drive->name, lba_capacity, capacity); 445 drive->name, lba_capacity, capacity);
517 floppy->blocks = floppy->block_size ? 446 floppy->blocks = floppy->block_size ?
@@ -541,7 +470,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
541 470
542 ide_floppy_create_read_capacity_cmd(&pc); 471 ide_floppy_create_read_capacity_cmd(&pc);
543 if (ide_queue_pc_tail(drive, disk, &pc)) { 472 if (ide_queue_pc_tail(drive, disk, &pc)) {
544 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 473 printk(KERN_ERR PFX "Can't get floppy parameters\n");
545 return 1; 474 return 1;
546 } 475 }
547 header_len = pc.buf[3]; 476 header_len = pc.buf[3];
@@ -554,8 +483,9 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
554 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); 483 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
555 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); 484 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
556 485
557 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", 486 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
558 i, blocks * length / 1024, blocks, length); 487 "%d sector size\n",
488 i, blocks * length / 1024, blocks, length);
559 489
560 if (i) 490 if (i)
561 continue; 491 continue;
@@ -575,23 +505,24 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
575 case CAPACITY_CURRENT: 505 case CAPACITY_CURRENT:
576 /* Normal Zip/LS-120 disks */ 506 /* Normal Zip/LS-120 disks */
577 if (memcmp(cap_desc, &floppy->cap_desc, 8)) 507 if (memcmp(cap_desc, &floppy->cap_desc, 8))
578 printk(KERN_INFO "%s: %dkB, %d blocks, %d " 508 printk(KERN_INFO PFX "%s: %dkB, %d blocks, %d "
579 "sector size\n", drive->name, 509 "sector size\n",
580 blocks * length / 1024, blocks, length); 510 drive->name, blocks * length / 1024,
511 blocks, length);
581 memcpy(&floppy->cap_desc, cap_desc, 8); 512 memcpy(&floppy->cap_desc, cap_desc, 8);
582 513
583 if (!length || length % 512) { 514 if (!length || length % 512) {
584 printk(KERN_NOTICE "%s: %d bytes block size " 515 printk(KERN_NOTICE PFX "%s: %d bytes block size"
585 "not supported\n", drive->name, length); 516 " not supported\n", drive->name, length);
586 } else { 517 } else {
587 floppy->blocks = blocks; 518 floppy->blocks = blocks;
588 floppy->block_size = length; 519 floppy->block_size = length;
589 floppy->bs_factor = length / 512; 520 floppy->bs_factor = length / 512;
590 if (floppy->bs_factor != 1) 521 if (floppy->bs_factor != 1)
591 printk(KERN_NOTICE "%s: warning: non " 522 printk(KERN_NOTICE PFX "%s: Warning: "
592 "512 bytes block size not " 523 "non 512 bytes block size not "
593 "fully supported\n", 524 "fully supported\n",
594 drive->name); 525 drive->name);
595 rc = 0; 526 rc = 0;
596 } 527 }
597 break; 528 break;
@@ -600,15 +531,16 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
600 * This is a KERN_ERR so it appears on screen 531 * This is a KERN_ERR so it appears on screen
601 * for the user to see 532 * for the user to see
602 */ 533 */
603 printk(KERN_ERR "%s: No disk in drive\n", drive->name); 534 printk(KERN_ERR PFX "%s: No disk in drive\n",
535 drive->name);
604 break; 536 break;
605 case CAPACITY_INVALID: 537 case CAPACITY_INVALID:
606 printk(KERN_ERR "%s: Invalid capacity for disk " 538 printk(KERN_ERR PFX "%s: Invalid capacity for disk "
607 "in drive\n", drive->name); 539 "in drive\n", drive->name);
608 break; 540 break;
609 } 541 }
610 debug_log("Descriptor 0 Code: %d\n", 542 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d\n",
611 pc.buf[desc_start + 4] & 0x03); 543 pc.buf[desc_start + 4] & 0x03);
612 } 544 }
613 545
614 /* Clik! disk does not support get_flexible_disk_page */ 546 /* Clik! disk does not support get_flexible_disk_page */
@@ -620,7 +552,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
620 return rc; 552 return rc;
621} 553}
622 554
623static sector_t idefloppy_capacity(ide_drive_t *drive) 555sector_t ide_floppy_capacity(ide_drive_t *drive)
624{ 556{
625 idefloppy_floppy_t *floppy = drive->driver_data; 557 idefloppy_floppy_t *floppy = drive->driver_data;
626 unsigned long capacity = floppy->blocks * floppy->bs_factor; 558 unsigned long capacity = floppy->blocks * floppy->bs_factor;
@@ -628,46 +560,14 @@ static sector_t idefloppy_capacity(ide_drive_t *drive)
628 return capacity; 560 return capacity;
629} 561}
630 562
631#ifdef CONFIG_IDE_PROC_FS
632ide_devset_rw_field(bios_cyl, bios_cyl);
633ide_devset_rw_field(bios_head, bios_head);
634ide_devset_rw_field(bios_sect, bios_sect);
635
636static int get_ticks(ide_drive_t *drive)
637{
638 idefloppy_floppy_t *floppy = drive->driver_data;
639 return floppy->ticks;
640}
641
642static int set_ticks(ide_drive_t *drive, int arg)
643{
644 idefloppy_floppy_t *floppy = drive->driver_data;
645 floppy->ticks = arg;
646 return 0;
647}
648
649IDE_DEVSET(ticks, DS_SYNC, get_ticks, set_ticks);
650
651static const struct ide_proc_devset idefloppy_settings[] = {
652 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
653 IDE_PROC_DEVSET(bios_head, 0, 255),
654 IDE_PROC_DEVSET(bios_sect, 0, 63),
655 IDE_PROC_DEVSET(ticks, 0, 255),
656 { 0 },
657};
658#endif
659
660static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) 563static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
661{ 564{
662 u16 *id = drive->id; 565 u16 *id = drive->id;
663 u8 gcw[2];
664
665 *((u16 *)&gcw) = id[ATA_ID_CONFIG];
666 566
667 drive->pc_callback = ide_floppy_callback; 567 drive->pc_callback = ide_floppy_callback;
568 drive->pc_update_buffers = idefloppy_update_buffers;
569 drive->pc_io_buffers = ide_io_buffers;
668 570
669 if (((gcw[0] & 0x60) >> 5) == 1)
670 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
671 /* 571 /*
672 * We used to check revisions here. At this point however I'm giving up. 572 * We used to check revisions here. At this point however I'm giving up.
673 * Just assume they are all broken, its easier. 573 * Just assume they are all broken, its easier.
@@ -680,7 +580,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
680 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) { 580 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
681 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; 581 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
682 /* This value will be visible in the /proc/ide/hdx/settings */ 582 /* This value will be visible in the /proc/ide/hdx/settings */
683 floppy->ticks = IDEFLOPPY_TICKS_DELAY; 583 drive->pc_delay = IDEFLOPPY_PC_DELAY;
684 blk_queue_max_sectors(drive->queue, 64); 584 blk_queue_max_sectors(drive->queue, 64);
685 } 585 }
686 586
@@ -714,7 +614,7 @@ static void ide_floppy_remove(ide_drive_t *drive)
714 614
715static void idefloppy_cleanup_obj(struct kref *kref) 615static void idefloppy_cleanup_obj(struct kref *kref)
716{ 616{
717 struct ide_floppy_obj *floppy = to_ide_floppy(kref); 617 struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
718 ide_drive_t *drive = floppy->drive; 618 ide_drive_t *drive = floppy->drive;
719 struct gendisk *g = floppy->disk; 619 struct gendisk *g = floppy->disk;
720 620
@@ -724,24 +624,6 @@ static void idefloppy_cleanup_obj(struct kref *kref)
724 kfree(floppy); 624 kfree(floppy);
725} 625}
726 626
727#ifdef CONFIG_IDE_PROC_FS
728static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
729 int count, int *eof, void *data)
730{
731 ide_drive_t*drive = (ide_drive_t *)data;
732 int len;
733
734 len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
735 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
736}
737
738static ide_proc_entry_t idefloppy_proc[] = {
739 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
740 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
741 { NULL, 0, NULL, NULL }
742};
743#endif /* CONFIG_IDE_PROC_FS */
744
745static int ide_floppy_probe(ide_drive_t *); 627static int ide_floppy_probe(ide_drive_t *);
746 628
747static ide_driver_t idefloppy_driver = { 629static ide_driver_t idefloppy_driver = {
@@ -753,13 +635,12 @@ static ide_driver_t idefloppy_driver = {
753 .probe = ide_floppy_probe, 635 .probe = ide_floppy_probe,
754 .remove = ide_floppy_remove, 636 .remove = ide_floppy_remove,
755 .version = IDEFLOPPY_VERSION, 637 .version = IDEFLOPPY_VERSION,
756 .media = ide_floppy,
757 .do_request = idefloppy_do_request, 638 .do_request = idefloppy_do_request,
758 .end_request = idefloppy_end_request, 639 .end_request = idefloppy_end_request,
759 .error = __ide_error, 640 .error = __ide_error,
760#ifdef CONFIG_IDE_PROC_FS 641#ifdef CONFIG_IDE_PROC_FS
761 .proc = idefloppy_proc, 642 .proc = ide_floppy_proc,
762 .settings = idefloppy_settings, 643 .settings = ide_floppy_settings,
763#endif 644#endif
764}; 645};
765 646
@@ -770,14 +651,14 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
770 ide_drive_t *drive; 651 ide_drive_t *drive;
771 int ret = 0; 652 int ret = 0;
772 653
773 debug_log("Reached %s\n", __func__);
774
775 floppy = ide_floppy_get(disk); 654 floppy = ide_floppy_get(disk);
776 if (!floppy) 655 if (!floppy)
777 return -ENXIO; 656 return -ENXIO;
778 657
779 drive = floppy->drive; 658 drive = floppy->drive;
780 659
660 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
661
781 floppy->openers++; 662 floppy->openers++;
782 663
783 if (floppy->openers == 1) { 664 if (floppy->openers == 1) {
@@ -822,10 +703,10 @@ out_put_floppy:
822static int idefloppy_release(struct inode *inode, struct file *filp) 703static int idefloppy_release(struct inode *inode, struct file *filp)
823{ 704{
824 struct gendisk *disk = inode->i_bdev->bd_disk; 705 struct gendisk *disk = inode->i_bdev->bd_disk;
825 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 706 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
826 ide_drive_t *drive = floppy->drive; 707 ide_drive_t *drive = floppy->drive;
827 708
828 debug_log("Reached %s\n", __func__); 709 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
829 710
830 if (floppy->openers == 1) { 711 if (floppy->openers == 1) {
831 ide_set_media_lock(drive, disk, 0); 712 ide_set_media_lock(drive, disk, 0);
@@ -841,7 +722,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
841 722
842static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) 723static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
843{ 724{
844 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); 725 struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
726 ide_floppy_obj);
845 ide_drive_t *drive = floppy->drive; 727 ide_drive_t *drive = floppy->drive;
846 728
847 geo->heads = drive->bios_head; 729 geo->heads = drive->bios_head;
@@ -850,64 +732,15 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
850 return 0; 732 return 0;
851} 733}
852 734
853static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
854 unsigned long arg, unsigned int cmd)
855{
856 idefloppy_floppy_t *floppy = drive->driver_data;
857 struct gendisk *disk = floppy->disk;
858 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
859
860 if (floppy->openers > 1)
861 return -EBUSY;
862
863 ide_set_media_lock(drive, disk, prevent);
864
865 if (cmd == CDROMEJECT)
866 ide_do_start_stop(drive, disk, 2);
867
868 return 0;
869}
870
871static int idefloppy_ioctl(struct inode *inode, struct file *file,
872 unsigned int cmd, unsigned long arg)
873{
874 struct block_device *bdev = inode->i_bdev;
875 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
876 ide_drive_t *drive = floppy->drive;
877 struct ide_atapi_pc pc;
878 void __user *argp = (void __user *)arg;
879 int err;
880
881 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
882 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
883
884 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
885 if (err != -ENOTTY)
886 return err;
887
888 /*
889 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
890 * and CDROM_SEND_PACKET (legacy) ioctls
891 */
892 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
893 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
894 bdev->bd_disk, cmd, argp);
895
896 if (err == -ENOTTY)
897 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
898
899 return err;
900}
901
902static int idefloppy_media_changed(struct gendisk *disk) 735static int idefloppy_media_changed(struct gendisk *disk)
903{ 736{
904 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 737 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
905 ide_drive_t *drive = floppy->drive; 738 ide_drive_t *drive = floppy->drive;
906 int ret; 739 int ret;
907 740
908 /* do not scan partitions twice if this is a removable device */ 741 /* do not scan partitions twice if this is a removable device */
909 if (drive->attach) { 742 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
910 drive->attach = 0; 743 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
911 return 0; 744 return 0;
912 } 745 }
913 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED); 746 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
@@ -917,8 +750,8 @@ static int idefloppy_media_changed(struct gendisk *disk)
917 750
918static int idefloppy_revalidate_disk(struct gendisk *disk) 751static int idefloppy_revalidate_disk(struct gendisk *disk)
919{ 752{
920 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 753 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
921 set_capacity(disk, idefloppy_capacity(floppy->drive)); 754 set_capacity(disk, ide_floppy_capacity(floppy->drive));
922 return 0; 755 return 0;
923} 756}
924 757
@@ -926,7 +759,7 @@ static struct block_device_operations idefloppy_ops = {
926 .owner = THIS_MODULE, 759 .owner = THIS_MODULE,
927 .open = idefloppy_open, 760 .open = idefloppy_open,
928 .release = idefloppy_release, 761 .release = idefloppy_release,
929 .ioctl = idefloppy_ioctl, 762 .ioctl = ide_floppy_ioctl,
930 .getgeo = idefloppy_getgeo, 763 .getgeo = idefloppy_getgeo,
931 .media_changed = idefloppy_media_changed, 764 .media_changed = idefloppy_media_changed,
932 .revalidate_disk = idefloppy_revalidate_disk 765 .revalidate_disk = idefloppy_revalidate_disk
@@ -944,14 +777,14 @@ static int ide_floppy_probe(ide_drive_t *drive)
944 goto failed; 777 goto failed;
945 778
946 if (!ide_check_atapi_device(drive, DRV_NAME)) { 779 if (!ide_check_atapi_device(drive, DRV_NAME)) {
947 printk(KERN_ERR "ide-floppy: %s: not supported by this version" 780 printk(KERN_ERR PFX "%s: not supported by this version of "
948 " of ide-floppy\n", drive->name); 781 DRV_NAME "\n", drive->name);
949 goto failed; 782 goto failed;
950 } 783 }
951 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL); 784 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
952 if (!floppy) { 785 if (!floppy) {
953 printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy" 786 printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
954 " structure\n", drive->name); 787 drive->name);
955 goto failed; 788 goto failed;
956 } 789 }
957 790
@@ -971,13 +804,16 @@ static int ide_floppy_probe(ide_drive_t *drive)
971 804
972 drive->driver_data = floppy; 805 drive->driver_data = floppy;
973 806
807 drive->debug_mask = debug_mask;
808
974 idefloppy_setup(drive, floppy); 809 idefloppy_setup(drive, floppy);
810 drive->dev_flags |= IDE_DFLAG_ATTACH;
975 811
976 g->minors = 1 << PARTN_BITS; 812 g->minors = 1 << PARTN_BITS;
977 g->driverfs_dev = &drive->gendev; 813 g->driverfs_dev = &drive->gendev;
978 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; 814 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
815 g->flags = GENHD_FL_REMOVABLE;
979 g->fops = &idefloppy_ops; 816 g->fops = &idefloppy_ops;
980 drive->attach = 1;
981 add_disk(g); 817 add_disk(g);
982 return 0; 818 return 0;
983 819
@@ -994,7 +830,7 @@ static void __exit idefloppy_exit(void)
994 830
995static int __init idefloppy_init(void) 831static int __init idefloppy_init(void)
996{ 832{
997 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); 833 printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
998 return driver_register(&idefloppy_driver.gen_driver); 834 return driver_register(&idefloppy_driver.gen_driver);
999} 835}
1000 836
diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h
index ecadc2bc322d..17cf865e583d 100644
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -13,20 +13,14 @@ typedef struct ide_floppy_obj {
13 struct kref kref; 13 struct kref kref;
14 unsigned int openers; /* protected by BKL for now */ 14 unsigned int openers; /* protected by BKL for now */
15 15
16 /* Current packet command */
17 struct ide_atapi_pc *pc;
18 /* Last failed packet command */ 16 /* Last failed packet command */
19 struct ide_atapi_pc *failed_pc; 17 struct ide_atapi_pc *failed_pc;
20 /* used for blk_{fs,pc}_request() requests */ 18 /* used for blk_{fs,pc}_request() requests */
21 struct ide_atapi_pc queued_pc; 19 struct ide_atapi_pc queued_pc;
22 20
23 struct ide_atapi_pc request_sense_pc;
24 struct request request_sense_rq;
25
26 /* Last error information */ 21 /* Last error information */
27 u8 sense_key, asc, ascq; 22 u8 sense_key, asc, ascq;
28 /* delay this long before sending packet command */ 23
29 u8 ticks;
30 int progress_indication; 24 int progress_indication;
31 25
32 /* Device information */ 26 /* Device information */
@@ -54,10 +48,15 @@ typedef struct ide_floppy_obj {
54/* ide-floppy.c */ 48/* ide-floppy.c */
55void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8); 49void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
56void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *); 50void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
57void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *); 51sector_t ide_floppy_capacity(ide_drive_t *);
58 52
59/* ide-floppy_ioctl.c */ 53/* ide-floppy_ioctl.c */
60int ide_floppy_format_ioctl(ide_drive_t *, struct file *, unsigned int, 54int ide_floppy_ioctl(struct inode *, struct file *, unsigned, unsigned long);
61 void __user *); 55
56#ifdef CONFIG_IDE_PROC_FS
57/* ide-floppy_proc.c */
58extern ide_proc_entry_t ide_floppy_proc[];
59extern const struct ide_proc_devset ide_floppy_settings[];
60#endif
62 61
63#endif /*__IDE_FLOPPY_H */ 62#endif /*__IDE_FLOPPY_H */
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index 5ffc4512d14b..a3a7a0809e2b 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -195,7 +195,7 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
195 int progress_indication = 0x10000; 195 int progress_indication = 0x10000;
196 196
197 if (drive->atapi_flags & IDE_AFLAG_SRFP) { 197 if (drive->atapi_flags & IDE_AFLAG_SRFP) {
198 ide_floppy_create_request_sense_cmd(&pc); 198 ide_create_request_sense_cmd(drive, &pc);
199 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) 199 if (ide_queue_pc_tail(drive, floppy->disk, &pc))
200 return -EIO; 200 return -EIO;
201 201
@@ -223,8 +223,26 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
223 return 0; 223 return 0;
224} 224}
225 225
226int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file, 226static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
227 unsigned int cmd, void __user *argp) 227 unsigned long arg, unsigned int cmd)
228{
229 idefloppy_floppy_t *floppy = drive->driver_data;
230 struct gendisk *disk = floppy->disk;
231 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
232
233 if (floppy->openers > 1)
234 return -EBUSY;
235
236 ide_set_media_lock(drive, disk, prevent);
237
238 if (cmd == CDROMEJECT)
239 ide_do_start_stop(drive, disk, 2);
240
241 return 0;
242}
243
244static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
245 unsigned int cmd, void __user *argp)
228{ 246{
229 switch (cmd) { 247 switch (cmd) {
230 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: 248 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
@@ -241,3 +259,35 @@ int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
241 return -ENOTTY; 259 return -ENOTTY;
242 } 260 }
243} 261}
262
263int ide_floppy_ioctl(struct inode *inode, struct file *file,
264 unsigned int cmd, unsigned long arg)
265{
266 struct block_device *bdev = inode->i_bdev;
267 struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
268 ide_floppy_obj);
269 ide_drive_t *drive = floppy->drive;
270 struct ide_atapi_pc pc;
271 void __user *argp = (void __user *)arg;
272 int err;
273
274 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
275 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
276
277 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
278 if (err != -ENOTTY)
279 return err;
280
281 /*
282 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
283 * and CDROM_SEND_PACKET (legacy) ioctls
284 */
285 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
286 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
287 bdev->bd_disk, cmd, argp);
288
289 if (err == -ENOTTY)
290 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
291
292 return err;
293}
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
new file mode 100644
index 000000000000..76f0c6c4eca3
--- /dev/null
+++ b/drivers/ide/ide-floppy_proc.c
@@ -0,0 +1,33 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3
4#include "ide-floppy.h"
5
6static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
7 int count, int *eof, void *data)
8{
9 ide_drive_t*drive = (ide_drive_t *)data;
10 int len;
11
12 len = sprintf(page, "%llu\n", (long long)ide_floppy_capacity(drive));
13 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
14}
15
16ide_proc_entry_t ide_floppy_proc[] = {
17 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
18 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
19 { NULL, 0, NULL, NULL }
20};
21
22ide_devset_rw_field(bios_cyl, bios_cyl);
23ide_devset_rw_field(bios_head, bios_head);
24ide_devset_rw_field(bios_sect, bios_sect);
25ide_devset_rw_field(ticks, pc_delay);
26
27const struct ide_proc_devset ide_floppy_settings[] = {
28 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
29 IDE_PROC_DEVSET(bios_head, 0, 255),
30 IDE_PROC_DEVSET(bios_sect, 0, 63),
31 IDE_PROC_DEVSET(ticks, 0, 255),
32 { 0 },
33};
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 0a3cb0c33ae5..81a5282ce1eb 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -137,15 +137,10 @@ static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
137 137
138static int __init ide_generic_init(void) 138static int __init ide_generic_init(void)
139{ 139{
140 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS]; 140 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
141 struct ide_host *host;
142 unsigned long io_addr; 141 unsigned long io_addr;
143 int i, rc, primary = 0, secondary = 0; 142 int i, rc = 0, primary = 0, secondary = 0;
144 143
145#ifdef CONFIG_MIPS
146 if (!ide_probe_legacy())
147 return -ENODEV;
148#endif
149 ide_generic_check_pci_legacy_iobases(&primary, &secondary); 144 ide_generic_check_pci_legacy_iobases(&primary, &secondary);
150 145
151 if (!probe_mask) { 146 if (!probe_mask) {
@@ -161,13 +156,9 @@ static int __init ide_generic_init(void)
161 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports " 156 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
162 "upon user request\n"); 157 "upon user request\n");
163 158
164 memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
165
166 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) { 159 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
167 io_addr = legacy_bases[i]; 160 io_addr = legacy_bases[i];
168 161
169 hws[i] = NULL;
170
171 if ((probe_mask & (1 << i)) && io_addr) { 162 if ((probe_mask & (1 << i)) && io_addr) {
172 if (!request_region(io_addr, 8, DRV_NAME)) { 163 if (!request_region(io_addr, 8, DRV_NAME)) {
173 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX " 164 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
@@ -184,45 +175,27 @@ static int __init ide_generic_init(void)
184 continue; 175 continue;
185 } 176 }
186 177
187 memset(&hw[i], 0, sizeof(hw[i])); 178 memset(&hw, 0, sizeof(hw));
188 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206); 179 ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
189#ifdef CONFIG_IA64 180#ifdef CONFIG_IA64
190 hw[i].irq = isa_irq_to_vector(legacy_irqs[i]); 181 hw.irq = isa_irq_to_vector(legacy_irqs[i]);
191#else 182#else
192 hw[i].irq = legacy_irqs[i]; 183 hw.irq = legacy_irqs[i];
193#endif 184#endif
194 hw[i].chipset = ide_generic; 185 hw.chipset = ide_generic;
195 186
196 hws[i] = &hw[i]; 187 rc = ide_host_add(NULL, hws, NULL);
188 if (rc) {
189 release_region(io_addr + 0x206, 1);
190 release_region(io_addr, 8);
191 }
197 } 192 }
198 } 193 }
199 194
200 host = ide_host_alloc_all(NULL, hws);
201 if (host == NULL) {
202 rc = -ENOMEM;
203 goto err;
204 }
205
206 rc = ide_host_register(host, NULL, hws);
207 if (rc)
208 goto err_free;
209
210 if (ide_generic_sysfs_init()) 195 if (ide_generic_sysfs_init())
211 printk(KERN_ERR DRV_NAME ": failed to create ide_generic " 196 printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
212 "class\n"); 197 "class\n");
213 198
214 return 0;
215err_free:
216 ide_host_free(host);
217err:
218 for (i = 0; i < MAX_HWIFS; i++) {
219 if (hws[i] == NULL)
220 continue;
221
222 io_addr = hws[i]->io_ports.data_addr;
223 release_region(io_addr + 0x206, 1);
224 release_region(io_addr, 8);
225 }
226 return rc; 199 return rc;
227} 200}
228 201
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 1c51949833be..77c6eaeacefa 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -78,8 +78,9 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
78 * decide whether to reenable DMA -- 3 is a random magic for now, 78 * decide whether to reenable DMA -- 3 is a random magic for now,
79 * if we DMA timeout more than 3 times, just stay in PIO 79 * if we DMA timeout more than 3 times, just stay in PIO
80 */ 80 */
81 if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) { 81 if ((drive->dev_flags & IDE_DFLAG_DMA_PIO_RETRY) &&
82 drive->state = 0; 82 drive->retry_pio <= 3) {
83 drive->dev_flags &= ~IDE_DFLAG_DMA_PIO_RETRY;
83 ide_dma_on(drive); 84 ide_dma_on(drive);
84 } 85 }
85 86
@@ -131,21 +132,6 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
131} 132}
132EXPORT_SYMBOL(ide_end_request); 133EXPORT_SYMBOL(ide_end_request);
133 134
134/*
135 * Power Management state machine. This one is rather trivial for now,
136 * we should probably add more, like switching back to PIO on suspend
137 * to help some BIOSes, re-do the door locking on resume, etc...
138 */
139
140enum {
141 ide_pm_flush_cache = ide_pm_state_start_suspend,
142 idedisk_pm_standby,
143
144 idedisk_pm_restore_pio = ide_pm_state_start_resume,
145 idedisk_pm_idle,
146 ide_pm_restore_dma,
147};
148
149static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error) 135static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
150{ 136{
151 struct request_pm_state *pm = rq->data; 137 struct request_pm_state *pm = rq->data;
@@ -154,20 +140,20 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
154 return; 140 return;
155 141
156 switch (pm->pm_step) { 142 switch (pm->pm_step) {
157 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */ 143 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
158 if (pm->pm_state == PM_EVENT_FREEZE) 144 if (pm->pm_state == PM_EVENT_FREEZE)
159 pm->pm_step = ide_pm_state_completed; 145 pm->pm_step = IDE_PM_COMPLETED;
160 else 146 else
161 pm->pm_step = idedisk_pm_standby; 147 pm->pm_step = IDE_PM_STANDBY;
162 break; 148 break;
163 case idedisk_pm_standby: /* Suspend step 2 (standby) complete */ 149 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
164 pm->pm_step = ide_pm_state_completed; 150 pm->pm_step = IDE_PM_COMPLETED;
165 break; 151 break;
166 case idedisk_pm_restore_pio: /* Resume step 1 complete */ 152 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
167 pm->pm_step = idedisk_pm_idle; 153 pm->pm_step = IDE_PM_IDLE;
168 break; 154 break;
169 case idedisk_pm_idle: /* Resume step 2 (idle) complete */ 155 case IDE_PM_IDLE: /* Resume step 2 (idle)*/
170 pm->pm_step = ide_pm_restore_dma; 156 pm->pm_step = IDE_PM_RESTORE_DMA;
171 break; 157 break;
172 } 158 }
173} 159}
@@ -180,11 +166,12 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
180 memset(args, 0, sizeof(*args)); 166 memset(args, 0, sizeof(*args));
181 167
182 switch (pm->pm_step) { 168 switch (pm->pm_step) {
183 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */ 169 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
184 if (drive->media != ide_disk) 170 if (drive->media != ide_disk)
185 break; 171 break;
186 /* Not supported? Switch to next step now. */ 172 /* Not supported? Switch to next step now. */
187 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) { 173 if (ata_id_flush_enabled(drive->id) == 0 ||
174 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
188 ide_complete_power_step(drive, rq, 0, 0); 175 ide_complete_power_step(drive, rq, 0, 0);
189 return ide_stopped; 176 return ide_stopped;
190 } 177 }
@@ -193,27 +180,23 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
193 else 180 else
194 args->tf.command = ATA_CMD_FLUSH; 181 args->tf.command = ATA_CMD_FLUSH;
195 goto out_do_tf; 182 goto out_do_tf;
196 183 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
197 case idedisk_pm_standby: /* Suspend step 2 (standby) */
198 args->tf.command = ATA_CMD_STANDBYNOW1; 184 args->tf.command = ATA_CMD_STANDBYNOW1;
199 goto out_do_tf; 185 goto out_do_tf;
200 186 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
201 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
202 ide_set_max_pio(drive); 187 ide_set_max_pio(drive);
203 /* 188 /*
204 * skip idedisk_pm_idle for ATAPI devices 189 * skip IDE_PM_IDLE for ATAPI devices
205 */ 190 */
206 if (drive->media != ide_disk) 191 if (drive->media != ide_disk)
207 pm->pm_step = ide_pm_restore_dma; 192 pm->pm_step = IDE_PM_RESTORE_DMA;
208 else 193 else
209 ide_complete_power_step(drive, rq, 0, 0); 194 ide_complete_power_step(drive, rq, 0, 0);
210 return ide_stopped; 195 return ide_stopped;
211 196 case IDE_PM_IDLE: /* Resume step 2 (idle) */
212 case idedisk_pm_idle: /* Resume step 2 (idle) */
213 args->tf.command = ATA_CMD_IDLEIMMEDIATE; 197 args->tf.command = ATA_CMD_IDLEIMMEDIATE;
214 goto out_do_tf; 198 goto out_do_tf;
215 199 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
216 case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
217 /* 200 /*
218 * Right now, all we do is call ide_set_dma(drive), 201 * Right now, all we do is call ide_set_dma(drive),
219 * we could be smarter and check for current xfer_speed 202 * we could be smarter and check for current xfer_speed
@@ -222,12 +205,13 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
222 if (drive->hwif->dma_ops == NULL) 205 if (drive->hwif->dma_ops == NULL)
223 break; 206 break;
224 /* 207 /*
225 * TODO: respect ->using_dma setting 208 * TODO: respect IDE_DFLAG_USING_DMA
226 */ 209 */
227 ide_set_dma(drive); 210 ide_set_dma(drive);
228 break; 211 break;
229 } 212 }
230 pm->pm_step = ide_pm_state_completed; 213
214 pm->pm_step = IDE_PM_COMPLETED;
231 return ide_stopped; 215 return ide_stopped;
232 216
233out_do_tf: 217out_do_tf:
@@ -287,7 +271,7 @@ static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
287 if (blk_pm_suspend_request(rq)) { 271 if (blk_pm_suspend_request(rq)) {
288 blk_stop_queue(drive->queue); 272 blk_stop_queue(drive->queue);
289 } else { 273 } else {
290 drive->blocked = 0; 274 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
291 blk_start_queue(drive->queue); 275 blk_start_queue(drive->queue);
292 } 276 }
293 HWGROUP(drive)->rq = NULL; 277 HWGROUP(drive)->rq = NULL;
@@ -343,7 +327,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
343 drive->name, rq->pm->pm_step, stat, err); 327 drive->name, rq->pm->pm_step, stat, err);
344#endif 328#endif
345 ide_complete_power_step(drive, rq, stat, err); 329 ide_complete_power_step(drive, rq, stat, err);
346 if (pm->pm_step == ide_pm_state_completed) 330 if (pm->pm_step == IDE_PM_COMPLETED)
347 ide_complete_pm_request(drive, rq); 331 ide_complete_pm_request(drive, rq);
348 return; 332 return;
349 } 333 }
@@ -374,13 +358,14 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
374{ 358{
375 ide_hwif_t *hwif = drive->hwif; 359 ide_hwif_t *hwif = drive->hwif;
376 360
377 if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) { 361 if ((stat & ATA_BUSY) ||
362 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
378 /* other bits are useless when BUSY */ 363 /* other bits are useless when BUSY */
379 rq->errors |= ERROR_RESET; 364 rq->errors |= ERROR_RESET;
380 } else if (stat & ATA_ERR) { 365 } else if (stat & ATA_ERR) {
381 /* err has different meaning on cdrom and tape */ 366 /* err has different meaning on cdrom and tape */
382 if (err == ATA_ABORTED) { 367 if (err == ATA_ABORTED) {
383 if (drive->select.b.lba && 368 if ((drive->dev_flags & IDE_DFLAG_LBA) &&
384 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */ 369 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
385 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS) 370 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
386 return ide_stopped; 371 return ide_stopped;
@@ -428,7 +413,8 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
428{ 413{
429 ide_hwif_t *hwif = drive->hwif; 414 ide_hwif_t *hwif = drive->hwif;
430 415
431 if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) { 416 if ((stat & ATA_BUSY) ||
417 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
432 /* other bits are useless when BUSY */ 418 /* other bits are useless when BUSY */
433 rq->errors |= ERROR_RESET; 419 rq->errors |= ERROR_RESET;
434 } else { 420 } else {
@@ -509,7 +495,7 @@ static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
509 tf->lbal = drive->sect; 495 tf->lbal = drive->sect;
510 tf->lbam = drive->cyl; 496 tf->lbam = drive->cyl;
511 tf->lbah = drive->cyl >> 8; 497 tf->lbah = drive->cyl >> 8;
512 tf->device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA; 498 tf->device = (drive->head - 1) | drive->select;
513 tf->command = ATA_CMD_INIT_DEV_PARAMS; 499 tf->command = ATA_CMD_INIT_DEV_PARAMS;
514} 500}
515 501
@@ -557,30 +543,6 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
557 return ide_started; 543 return ide_started;
558} 544}
559 545
560/*
561 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
562 */
563static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
564{
565 switch (req_pio) {
566 case 202:
567 case 201:
568 case 200:
569 case 102:
570 case 101:
571 case 100:
572 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
573 case 9:
574 case 8:
575 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
576 case 7:
577 case 6:
578 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
579 default:
580 return 0;
581 }
582}
583
584/** 546/**
585 * do_special - issue some special commands 547 * do_special - issue some special commands
586 * @drive: drive the command is for 548 * @drive: drive the command is for
@@ -598,45 +560,12 @@ static ide_startstop_t do_special (ide_drive_t *drive)
598#ifdef DEBUG 560#ifdef DEBUG
599 printk("%s: do_special: 0x%02x\n", drive->name, s->all); 561 printk("%s: do_special: 0x%02x\n", drive->name, s->all);
600#endif 562#endif
601 if (s->b.set_tune) { 563 if (drive->media == ide_disk)
602 ide_hwif_t *hwif = drive->hwif; 564 return ide_disk_special(drive);
603 const struct ide_port_ops *port_ops = hwif->port_ops;
604 u8 req_pio = drive->tune_req;
605
606 s->b.set_tune = 0;
607
608 if (set_pio_mode_abuse(drive->hwif, req_pio)) {
609 /*
610 * take ide_lock for drive->[no_]unmask/[no_]io_32bit
611 */
612 if (req_pio == 8 || req_pio == 9) {
613 unsigned long flags;
614
615 spin_lock_irqsave(&ide_lock, flags);
616 port_ops->set_pio_mode(drive, req_pio);
617 spin_unlock_irqrestore(&ide_lock, flags);
618 } else
619 port_ops->set_pio_mode(drive, req_pio);
620 } else {
621 int keep_dma = drive->using_dma;
622
623 ide_set_pio(drive, req_pio);
624
625 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
626 if (keep_dma)
627 ide_dma_on(drive);
628 }
629 }
630
631 return ide_stopped;
632 } else {
633 if (drive->media == ide_disk)
634 return ide_disk_special(drive);
635 565
636 s->all = 0; 566 s->all = 0;
637 drive->mult_req = 0; 567 drive->mult_req = 0;
638 return ide_stopped; 568 return ide_stopped;
639 }
640} 569}
641 570
642void ide_map_sg(ide_drive_t *drive, struct request *rq) 571void ide_map_sg(ide_drive_t *drive, struct request *rq)
@@ -726,10 +655,7 @@ int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
726 if (!(setting->flags & DS_SYNC)) 655 if (!(setting->flags & DS_SYNC))
727 return setting->set(drive, arg); 656 return setting->set(drive, arg);
728 657
729 rq = blk_get_request(q, READ, GFP_KERNEL); 658 rq = blk_get_request(q, READ, __GFP_WAIT);
730 if (!rq)
731 return -ENOMEM;
732
733 rq->cmd_type = REQ_TYPE_SPECIAL; 659 rq->cmd_type = REQ_TYPE_SPECIAL;
734 rq->cmd_len = 5; 660 rq->cmd_len = 5;
735 rq->cmd[0] = REQ_DEVSET_EXEC; 661 rq->cmd[0] = REQ_DEVSET_EXEC;
@@ -746,7 +672,32 @@ EXPORT_SYMBOL_GPL(ide_devset_execute);
746 672
747static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) 673static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
748{ 674{
749 switch (rq->cmd[0]) { 675 u8 cmd = rq->cmd[0];
676
677 if (cmd == REQ_PARK_HEADS || cmd == REQ_UNPARK_HEADS) {
678 ide_task_t task;
679 struct ide_taskfile *tf = &task.tf;
680
681 memset(&task, 0, sizeof(task));
682 if (cmd == REQ_PARK_HEADS) {
683 drive->sleep = *(unsigned long *)rq->special;
684 drive->dev_flags |= IDE_DFLAG_SLEEPING;
685 tf->command = ATA_CMD_IDLEIMMEDIATE;
686 tf->feature = 0x44;
687 tf->lbal = 0x4c;
688 tf->lbam = 0x4e;
689 tf->lbah = 0x55;
690 task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
691 } else /* cmd == REQ_UNPARK_HEADS */
692 tf->command = ATA_CMD_CHK_POWER;
693
694 task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
695 task.rq = rq;
696 drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
697 return do_rw_taskfile(drive, &task);
698 }
699
700 switch (cmd) {
750 case REQ_DEVSET_EXEC: 701 case REQ_DEVSET_EXEC:
751 { 702 {
752 int err, (*setfunc)(ide_drive_t *, int) = rq->special; 703 int err, (*setfunc)(ide_drive_t *, int) = rq->special;
@@ -773,11 +724,11 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
773 struct request_pm_state *pm = rq->data; 724 struct request_pm_state *pm = rq->data;
774 725
775 if (blk_pm_suspend_request(rq) && 726 if (blk_pm_suspend_request(rq) &&
776 pm->pm_step == ide_pm_state_start_suspend) 727 pm->pm_step == IDE_PM_START_SUSPEND)
777 /* Mark drive blocked when starting the suspend sequence. */ 728 /* Mark drive blocked when starting the suspend sequence. */
778 drive->blocked = 1; 729 drive->dev_flags |= IDE_DFLAG_BLOCKED;
779 else if (blk_pm_resume_request(rq) && 730 else if (blk_pm_resume_request(rq) &&
780 pm->pm_step == ide_pm_state_start_resume) { 731 pm->pm_step == IDE_PM_START_RESUME) {
781 /* 732 /*
782 * The first thing we do on wakeup is to wait for BSY bit to 733 * The first thing we do on wakeup is to wait for BSY bit to
783 * go away (with a looong timeout) as a drive on this hwif may 734 * go away (with a looong timeout) as a drive on this hwif may
@@ -857,7 +808,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
857#endif 808#endif
858 startstop = ide_start_power_step(drive, rq); 809 startstop = ide_start_power_step(drive, rq);
859 if (startstop == ide_stopped && 810 if (startstop == ide_stopped &&
860 pm->pm_step == ide_pm_state_completed) 811 pm->pm_step == IDE_PM_COMPLETED)
861 ide_complete_pm_request(drive, rq); 812 ide_complete_pm_request(drive, rq);
862 return startstop; 813 return startstop;
863 } else if (!rq->rq_disk && blk_special_request(rq)) 814 } else if (!rq->rq_disk && blk_special_request(rq))
@@ -895,7 +846,7 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
895 if (timeout > WAIT_WORSTCASE) 846 if (timeout > WAIT_WORSTCASE)
896 timeout = WAIT_WORSTCASE; 847 timeout = WAIT_WORSTCASE;
897 drive->sleep = timeout + jiffies; 848 drive->sleep = timeout + jiffies;
898 drive->sleeping = 1; 849 drive->dev_flags |= IDE_DFLAG_SLEEPING;
899} 850}
900 851
901EXPORT_SYMBOL(ide_stall_queue); 852EXPORT_SYMBOL(ide_stall_queue);
@@ -935,18 +886,23 @@ repeat:
935 } 886 }
936 887
937 do { 888 do {
938 if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep)) 889 u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING);
939 && !elv_queue_empty(drive->queue)) { 890 u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING));
940 if (!best 891
941 || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep))) 892 if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) &&
942 || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best)))) 893 !elv_queue_empty(drive->queue)) {
943 { 894 if (best == NULL ||
895 (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) ||
896 (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) {
944 if (!blk_queue_plugged(drive->queue)) 897 if (!blk_queue_plugged(drive->queue))
945 best = drive; 898 best = drive;
946 } 899 }
947 } 900 }
948 } while ((drive = drive->next) != hwgroup->drive); 901 } while ((drive = drive->next) != hwgroup->drive);
949 if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) { 902
903 if (best && (best->dev_flags & IDE_DFLAG_NICE1) &&
904 (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 &&
905 best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
950 long t = (signed long)(WAKEUP(best) - jiffies); 906 long t = (signed long)(WAKEUP(best) - jiffies);
951 if (t >= WAIT_MIN_SLEEP) { 907 if (t >= WAIT_MIN_SLEEP) {
952 /* 908 /*
@@ -955,7 +911,7 @@ repeat:
955 */ 911 */
956 drive = best->next; 912 drive = best->next;
957 do { 913 do {
958 if (!drive->sleeping 914 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0
959 && time_before(jiffies - best->service_time, WAKEUP(drive)) 915 && time_before(jiffies - best->service_time, WAKEUP(drive))
960 && time_before(WAKEUP(drive), jiffies + t)) 916 && time_before(WAKEUP(drive), jiffies + t))
961 { 917 {
@@ -1026,7 +982,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1026 hwgroup->rq = NULL; 982 hwgroup->rq = NULL;
1027 drive = hwgroup->drive; 983 drive = hwgroup->drive;
1028 do { 984 do {
1029 if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) { 985 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) &&
986 (sleeping == 0 ||
987 time_before(drive->sleep, sleep))) {
1030 sleeping = 1; 988 sleeping = 1;
1031 sleep = drive->sleep; 989 sleep = drive->sleep;
1032 } 990 }
@@ -1075,7 +1033,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1075 } 1033 }
1076 hwgroup->hwif = hwif; 1034 hwgroup->hwif = hwif;
1077 hwgroup->drive = drive; 1035 hwgroup->drive = drive;
1078 drive->sleeping = 0; 1036 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
1079 drive->service_start = jiffies; 1037 drive->service_start = jiffies;
1080 1038
1081 if (blk_queue_plugged(drive->queue)) { 1039 if (blk_queue_plugged(drive->queue)) {
@@ -1109,7 +1067,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1109 * We count how many times we loop here to make sure we service 1067 * We count how many times we loop here to make sure we service
1110 * all drives in the hwgroup without looping for ever 1068 * all drives in the hwgroup without looping for ever
1111 */ 1069 */
1112 if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) { 1070 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
1071 blk_pm_request(rq) == 0 &&
1072 (rq->cmd_flags & REQ_PREEMPT) == 0) {
1113 drive = drive->next ? drive->next : hwgroup->drive; 1073 drive = drive->next ? drive->next : hwgroup->drive;
1114 if (loops++ < 4 && !blk_queue_plugged(drive->queue)) 1074 if (loops++ < 4 && !blk_queue_plugged(drive->queue))
1115 goto again; 1075 goto again;
@@ -1182,8 +1142,8 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1182 * a timeout -- we'll reenable after we finish this next request 1142 * a timeout -- we'll reenable after we finish this next request
1183 * (or rather the first chunk of it) in pio. 1143 * (or rather the first chunk of it) in pio.
1184 */ 1144 */
1145 drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
1185 drive->retry_pio++; 1146 drive->retry_pio++;
1186 drive->state = DMA_PIO_RETRY;
1187 ide_dma_off_quietly(drive); 1147 ide_dma_off_quietly(drive);
1188 1148
1189 /* 1149 /*
@@ -1480,23 +1440,16 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1480 del_timer(&hwgroup->timer); 1440 del_timer(&hwgroup->timer);
1481 spin_unlock(&ide_lock); 1441 spin_unlock(&ide_lock);
1482 1442
1483 /* Some controllers might set DMA INTR no matter DMA or PIO; 1443 if (hwif->port_ops && hwif->port_ops->clear_irq)
1484 * bmdma status might need to be cleared even for 1444 hwif->port_ops->clear_irq(drive);
1485 * PIO interrupts to prevent spurious/lost irq.
1486 */
1487 if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
1488 /* ide_dma_end() needs bmdma status for error checking.
1489 * So, skip clearing bmdma status here and leave it
1490 * to ide_dma_end() if this is dma interrupt.
1491 */
1492 hwif->ide_dma_clear_irq(drive);
1493 1445
1494 if (drive->unmask) 1446 if (drive->dev_flags & IDE_DFLAG_UNMASK)
1495 local_irq_enable_in_hardirq(); 1447 local_irq_enable_in_hardirq();
1448
1496 /* service this interrupt, may set handler for next interrupt */ 1449 /* service this interrupt, may set handler for next interrupt */
1497 startstop = handler(drive); 1450 startstop = handler(drive);
1498 spin_lock_irq(&ide_lock);
1499 1451
1452 spin_lock_irq(&ide_lock);
1500 /* 1453 /*
1501 * Note that handler() may have set things up for another 1454 * Note that handler() may have set things up for another
1502 * interrupt to occur soon, but it cannot happen until 1455 * interrupt to occur soon, but it cannot happen until
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index cf01564901af..a90945f49792 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -62,7 +62,7 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
62 int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142; 62 int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
63 int rc = 0; 63 int rc = 0;
64 64
65 if (drive->id_read == 0) { 65 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
66 rc = -ENOMSG; 66 rc = -ENOMSG;
67 goto out; 67 goto out;
68 } 68 }
@@ -86,8 +86,10 @@ out:
86 86
87static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg) 87static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg)
88{ 88{
89 return put_user((drive->dsc_overlap << IDE_NICE_DSC_OVERLAP) | 89 return put_user((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)
90 (drive->nice1 << IDE_NICE_1), (long __user *)arg); 90 << IDE_NICE_DSC_OVERLAP) |
91 (!!(drive->dev_flags & IDE_DFLAG_NICE1)
92 << IDE_NICE_1), (long __user *)arg);
91} 93}
92 94
93static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) 95static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
@@ -97,11 +99,18 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
97 99
98 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) && 100 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
99 (drive->media == ide_disk || drive->media == ide_floppy || 101 (drive->media == ide_disk || drive->media == ide_floppy ||
100 drive->scsi)) 102 (drive->dev_flags & IDE_DFLAG_SCSI)))
101 return -EPERM; 103 return -EPERM;
102 104
103 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1; 105 if ((arg >> IDE_NICE_DSC_OVERLAP) & 1)
104 drive->nice1 = (arg >> IDE_NICE_1) & 1; 106 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
107 else
108 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
109
110 if ((arg >> IDE_NICE_1) & 1)
111 drive->dev_flags |= IDE_DFLAG_NICE1;
112 else
113 drive->dev_flags &= ~IDE_DFLAG_NICE1;
105 114
106 return 0; 115 return 0;
107} 116}
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 0a2fd3b37ac4..b762deb2dacb 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -181,7 +181,7 @@ void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
181 tf_outb(tf->lbah, io_ports->lbah_addr); 181 tf_outb(tf->lbah, io_ports->lbah_addr);
182 182
183 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 183 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
184 tf_outb((tf->device & HIHI) | drive->select.all, 184 tf_outb((tf->device & HIHI) | drive->select,
185 io_ports->device_addr); 185 io_ports->device_addr);
186} 186}
187EXPORT_SYMBOL_GPL(ide_tf_load); 187EXPORT_SYMBOL_GPL(ide_tf_load);
@@ -647,7 +647,7 @@ u8 eighty_ninty_three (ide_drive_t *drive)
647 return 1; 647 return 1;
648 648
649no_80w: 649no_80w:
650 if (drive->udma33_warned == 1) 650 if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
651 return 0; 651 return 0;
652 652
653 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, " 653 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
@@ -655,7 +655,7 @@ no_80w:
655 drive->name, 655 drive->name,
656 hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host"); 656 hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host");
657 657
658 drive->udma33_warned = 1; 658 drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED;
659 659
660 return 0; 660 return 0;
661} 661}
@@ -711,7 +711,7 @@ int ide_driveid_update(ide_drive_t *drive)
711 711
712 kfree(id); 712 kfree(id);
713 713
714 if (drive->using_dma && ide_id_dma_bug(drive)) 714 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
715 ide_dma_off(drive); 715 ide_dma_off(drive);
716 716
717 return 1; 717 return 1;
@@ -790,7 +790,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
790 790
791 skip: 791 skip:
792#ifdef CONFIG_BLK_DEV_IDEDMA 792#ifdef CONFIG_BLK_DEV_IDEDMA
793 if (speed >= XFER_SW_DMA_0 && drive->using_dma) 793 if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA))
794 hwif->dma_ops->dma_host_set(drive, 1); 794 hwif->dma_ops->dma_host_set(drive, 1);
795 else if (hwif->dma_ops) /* check if host supports DMA */ 795 else if (hwif->dma_ops) /* check if host supports DMA */
796 ide_dma_off_quietly(drive); 796 ide_dma_off_quietly(drive);
@@ -940,6 +940,25 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
940 return ide_stopped; 940 return ide_stopped;
941} 941}
942 942
943static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
944{
945 static const char *err_master_vals[] =
946 { NULL, "passed", "formatter device error",
947 "sector buffer error", "ECC circuitry error",
948 "controlling MPU error" };
949
950 u8 err_master = err & 0x7f;
951
952 printk(KERN_ERR "%s: reset: master: ", hwif->name);
953 if (err_master && err_master < 6)
954 printk(KERN_CONT "%s", err_master_vals[err_master]);
955 else
956 printk(KERN_CONT "error (0x%02x?)", err);
957 if (err & 0x80)
958 printk(KERN_CONT "; slave: failed");
959 printk(KERN_CONT "\n");
960}
961
943/* 962/*
944 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms 963 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
945 * during an ide reset operation. If the drives have not yet responded, 964 * during an ide reset operation. If the drives have not yet responded,
@@ -975,31 +994,14 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
975 drive->failures++; 994 drive->failures++;
976 err = -EIO; 995 err = -EIO;
977 } else { 996 } else {
978 printk("%s: reset: ", hwif->name);
979 tmp = ide_read_error(drive); 997 tmp = ide_read_error(drive);
980 998
981 if (tmp == 1) { 999 if (tmp == 1) {
982 printk("success\n"); 1000 printk(KERN_INFO "%s: reset: success\n", hwif->name);
983 drive->failures = 0; 1001 drive->failures = 0;
984 } else { 1002 } else {
1003 ide_reset_report_error(hwif, tmp);
985 drive->failures++; 1004 drive->failures++;
986 printk("master: ");
987 switch (tmp & 0x7f) {
988 case 1: printk("passed");
989 break;
990 case 2: printk("formatter device error");
991 break;
992 case 3: printk("sector buffer error");
993 break;
994 case 4: printk("ECC circuitry error");
995 break;
996 case 5: printk("controlling MPU error");
997 break;
998 default:printk("error (0x%02x?)", tmp);
999 }
1000 if (tmp & 0x80)
1001 printk("; slave: failed");
1002 printk("\n");
1003 err = -EIO; 1005 err = -EIO;
1004 } 1006 }
1005 } 1007 }
@@ -1016,9 +1018,14 @@ static void ide_disk_pre_reset(ide_drive_t *drive)
1016 drive->special.all = 0; 1018 drive->special.all = 0;
1017 drive->special.b.set_geometry = legacy; 1019 drive->special.b.set_geometry = legacy;
1018 drive->special.b.recalibrate = legacy; 1020 drive->special.b.recalibrate = legacy;
1021
1019 drive->mult_count = 0; 1022 drive->mult_count = 0;
1020 if (!drive->keep_settings && !drive->using_dma) 1023 drive->dev_flags &= ~IDE_DFLAG_PARKED;
1024
1025 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
1026 (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
1021 drive->mult_req = 0; 1027 drive->mult_req = 0;
1028
1022 if (drive->mult_req != drive->mult_count) 1029 if (drive->mult_req != drive->mult_count)
1023 drive->special.b.set_multmode = 1; 1030 drive->special.b.set_multmode = 1;
1024} 1031}
@@ -1030,18 +1037,18 @@ static void pre_reset(ide_drive_t *drive)
1030 if (drive->media == ide_disk) 1037 if (drive->media == ide_disk)
1031 ide_disk_pre_reset(drive); 1038 ide_disk_pre_reset(drive);
1032 else 1039 else
1033 drive->post_reset = 1; 1040 drive->dev_flags |= IDE_DFLAG_POST_RESET;
1034 1041
1035 if (drive->using_dma) { 1042 if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
1036 if (drive->crc_count) 1043 if (drive->crc_count)
1037 ide_check_dma_crc(drive); 1044 ide_check_dma_crc(drive);
1038 else 1045 else
1039 ide_dma_off(drive); 1046 ide_dma_off(drive);
1040 } 1047 }
1041 1048
1042 if (!drive->keep_settings) { 1049 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
1043 if (!drive->using_dma) { 1050 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
1044 drive->unmask = 0; 1051 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
1045 drive->io_32bit = 0; 1052 drive->io_32bit = 0;
1046 } 1053 }
1047 return; 1054 return;
@@ -1073,12 +1080,13 @@ static void pre_reset(ide_drive_t *drive)
1073static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) 1080static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1074{ 1081{
1075 unsigned int unit; 1082 unsigned int unit;
1076 unsigned long flags; 1083 unsigned long flags, timeout;
1077 ide_hwif_t *hwif; 1084 ide_hwif_t *hwif;
1078 ide_hwgroup_t *hwgroup; 1085 ide_hwgroup_t *hwgroup;
1079 struct ide_io_ports *io_ports; 1086 struct ide_io_ports *io_ports;
1080 const struct ide_tp_ops *tp_ops; 1087 const struct ide_tp_ops *tp_ops;
1081 const struct ide_port_ops *port_ops; 1088 const struct ide_port_ops *port_ops;
1089 DEFINE_WAIT(wait);
1082 1090
1083 spin_lock_irqsave(&ide_lock, flags); 1091 spin_lock_irqsave(&ide_lock, flags);
1084 hwif = HWIF(drive); 1092 hwif = HWIF(drive);
@@ -1105,6 +1113,31 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1105 return ide_started; 1113 return ide_started;
1106 } 1114 }
1107 1115
1116 /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
1117 do {
1118 unsigned long now;
1119
1120 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
1121 timeout = jiffies;
1122 for (unit = 0; unit < MAX_DRIVES; unit++) {
1123 ide_drive_t *tdrive = &hwif->drives[unit];
1124
1125 if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
1126 tdrive->dev_flags & IDE_DFLAG_PARKED &&
1127 time_after(tdrive->sleep, timeout))
1128 timeout = tdrive->sleep;
1129 }
1130
1131 now = jiffies;
1132 if (time_before_eq(timeout, now))
1133 break;
1134
1135 spin_unlock_irqrestore(&ide_lock, flags);
1136 timeout = schedule_timeout_uninterruptible(timeout - now);
1137 spin_lock_irqsave(&ide_lock, flags);
1138 } while (timeout);
1139 finish_wait(&ide_park_wq, &wait);
1140
1108 /* 1141 /*
1109 * First, reset any device state data we were maintaining 1142 * First, reset any device state data we were maintaining
1110 * for any of the drives on this interface. 1143 * for any of the drives on this interface.
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index ed426dd0fdd8..9fc4cfb2a272 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -317,7 +317,7 @@ static void ide_dump_sector(ide_drive_t *drive)
317{ 317{
318 ide_task_t task; 318 ide_task_t task;
319 struct ide_taskfile *tf = &task.tf; 319 struct ide_taskfile *tf = &task.tf;
320 int lba48 = (drive->addressing == 1) ? 1 : 0; 320 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
321 321
322 memset(&task, 0, sizeof(task)); 322 memset(&task, 0, sizeof(task));
323 if (lba48) 323 if (lba48)
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
new file mode 100644
index 000000000000..03b00e57e93f
--- /dev/null
+++ b/drivers/ide/ide-park.c
@@ -0,0 +1,121 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/jiffies.h>
4#include <linux/blkdev.h>
5
6DECLARE_WAIT_QUEUE_HEAD(ide_park_wq);
7
8static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
9{
10 struct request_queue *q = drive->queue;
11 struct request *rq;
12 int rc;
13
14 timeout += jiffies;
15 spin_lock_irq(&ide_lock);
16 if (drive->dev_flags & IDE_DFLAG_PARKED) {
17 ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
18 int reset_timer;
19
20 reset_timer = time_before(timeout, drive->sleep);
21 drive->sleep = timeout;
22 wake_up_all(&ide_park_wq);
23 if (reset_timer && hwgroup->sleeping &&
24 del_timer(&hwgroup->timer)) {
25 hwgroup->sleeping = 0;
26 hwgroup->busy = 0;
27 blk_start_queueing(q);
28 }
29 spin_unlock_irq(&ide_lock);
30 return;
31 }
32 spin_unlock_irq(&ide_lock);
33
34 rq = blk_get_request(q, READ, __GFP_WAIT);
35 rq->cmd[0] = REQ_PARK_HEADS;
36 rq->cmd_len = 1;
37 rq->cmd_type = REQ_TYPE_SPECIAL;
38 rq->special = &timeout;
39 rc = blk_execute_rq(q, NULL, rq, 1);
40 blk_put_request(rq);
41 if (rc)
42 goto out;
43
44 /*
45 * Make sure that *some* command is sent to the drive after the
46 * timeout has expired, so power management will be reenabled.
47 */
48 rq = blk_get_request(q, READ, GFP_NOWAIT);
49 if (unlikely(!rq))
50 goto out;
51
52 rq->cmd[0] = REQ_UNPARK_HEADS;
53 rq->cmd_len = 1;
54 rq->cmd_type = REQ_TYPE_SPECIAL;
55 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
56
57out:
58 return;
59}
60
61ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
62 char *buf)
63{
64 ide_drive_t *drive = to_ide_device(dev);
65 unsigned long now;
66 unsigned int msecs;
67
68 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
69 return -EOPNOTSUPP;
70
71 spin_lock_irq(&ide_lock);
72 now = jiffies;
73 if (drive->dev_flags & IDE_DFLAG_PARKED &&
74 time_after(drive->sleep, now))
75 msecs = jiffies_to_msecs(drive->sleep - now);
76 else
77 msecs = 0;
78 spin_unlock_irq(&ide_lock);
79
80 return snprintf(buf, 20, "%u\n", msecs);
81}
82
83ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
84 const char *buf, size_t len)
85{
86#define MAX_PARK_TIMEOUT 30000
87 ide_drive_t *drive = to_ide_device(dev);
88 long int input;
89 int rc;
90
91 rc = strict_strtol(buf, 10, &input);
92 if (rc || input < -2)
93 return -EINVAL;
94 if (input > MAX_PARK_TIMEOUT) {
95 input = MAX_PARK_TIMEOUT;
96 rc = -EOVERFLOW;
97 }
98
99 mutex_lock(&ide_setting_mtx);
100 if (input >= 0) {
101 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
102 rc = -EOPNOTSUPP;
103 else if (input || drive->dev_flags & IDE_DFLAG_PARKED)
104 issue_park_cmd(drive, msecs_to_jiffies(input));
105 } else {
106 if (drive->media == ide_disk)
107 switch (input) {
108 case -1:
109 drive->dev_flags &= ~IDE_DFLAG_NO_UNLOAD;
110 break;
111 case -2:
112 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
113 break;
114 }
115 else
116 rc = -EOPNOTSUPP;
117 }
118 mutex_unlock(&ide_setting_mtx);
119
120 return rc ? rc : len;
121}
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 06575a12b635..f27baa5f140e 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -121,7 +121,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
121 /* read 512 bytes of id info */ 121 /* read 512 bytes of id info */
122 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE); 122 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
123 123
124 drive->id_read = 1; 124 drive->dev_flags |= IDE_DFLAG_ID_READ;
125
125 local_irq_enable(); 126 local_irq_enable();
126#ifdef DEBUG 127#ifdef DEBUG
127 printk(KERN_INFO "%s: dumping identify data\n", drive->name); 128 printk(KERN_INFO "%s: dumping identify data\n", drive->name);
@@ -153,8 +154,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
153 154
154 printk(KERN_INFO "%s: %s, ", drive->name, m); 155 printk(KERN_INFO "%s: %s, ", drive->name, m);
155 156
156 drive->present = 1; 157 drive->dev_flags |= IDE_DFLAG_PRESENT;
157 drive->dead = 0; 158 drive->dev_flags &= ~IDE_DFLAG_DEAD;
158 159
159 /* 160 /*
160 * Check for an ATAPI device 161 * Check for an ATAPI device
@@ -172,14 +173,14 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
172 printk(KERN_CONT "cdrom or floppy?, assuming "); 173 printk(KERN_CONT "cdrom or floppy?, assuming ");
173 if (drive->media != ide_cdrom) { 174 if (drive->media != ide_cdrom) {
174 printk(KERN_CONT "FLOPPY"); 175 printk(KERN_CONT "FLOPPY");
175 drive->removable = 1; 176 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
176 break; 177 break;
177 } 178 }
178 } 179 }
179 /* Early cdrom models used zero */ 180 /* Early cdrom models used zero */
180 type = ide_cdrom; 181 type = ide_cdrom;
181 case ide_cdrom: 182 case ide_cdrom:
182 drive->removable = 1; 183 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
183#ifdef CONFIG_PPC 184#ifdef CONFIG_PPC
184 /* kludge for Apple PowerBook internal zip */ 185 /* kludge for Apple PowerBook internal zip */
185 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) { 186 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
@@ -195,7 +196,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
195 break; 196 break;
196 case ide_optical: 197 case ide_optical:
197 printk(KERN_CONT "OPTICAL"); 198 printk(KERN_CONT "OPTICAL");
198 drive->removable = 1; 199 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
199 break; 200 break;
200 default: 201 default:
201 printk(KERN_CONT "UNKNOWN (type %d)", type); 202 printk(KERN_CONT "UNKNOWN (type %d)", type);
@@ -205,6 +206,10 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
205 drive->media = type; 206 drive->media = type;
206 /* an ATAPI device ignores DRDY */ 207 /* an ATAPI device ignores DRDY */
207 drive->ready_stat = 0; 208 drive->ready_stat = 0;
209 if (ata_id_cdb_intr(id))
210 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
211 /* we don't do head unloading on ATAPI devices */
212 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
208 return; 213 return;
209 } 214 }
210 215
@@ -216,17 +221,20 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
216 221
217 /* CF devices are *not* removable in Linux definition of the term */ 222 /* CF devices are *not* removable in Linux definition of the term */
218 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7))) 223 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
219 drive->removable = 1; 224 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
220 225
221 drive->media = ide_disk; 226 drive->media = ide_disk;
222 227
228 if (!ata_id_has_unload(drive->id))
229 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
230
223 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA"); 231 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
224 232
225 return; 233 return;
226 234
227err_misc: 235err_misc:
228 kfree(id); 236 kfree(id);
229 drive->present = 0; 237 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
230 return; 238 return;
231} 239}
232 240
@@ -426,16 +434,15 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
426 ide_hwif_t *hwif = HWIF(drive); 434 ide_hwif_t *hwif = HWIF(drive);
427 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 435 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
428 int rc; 436 int rc;
429 u8 stat; 437 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
438
439 /* avoid waiting for inappropriate probes */
440 if (present && drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
441 return 4;
430 442
431 if (drive->present) {
432 /* avoid waiting for inappropriate probes */
433 if (drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
434 return 4;
435 }
436#ifdef DEBUG 443#ifdef DEBUG
437 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n", 444 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
438 drive->name, drive->present, drive->media, 445 drive->name, present, drive->media,
439 (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI"); 446 (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI");
440#endif 447#endif
441 448
@@ -446,8 +453,8 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
446 SELECT_DRIVE(drive); 453 SELECT_DRIVE(drive);
447 msleep(50); 454 msleep(50);
448 455
449 if (ide_read_device(drive) != drive->select.all && !drive->present) { 456 if (ide_read_device(drive) != drive->select && present == 0) {
450 if (drive->select.b.unit != 0) { 457 if (drive->dn & 1) {
451 /* exit with drive0 selected */ 458 /* exit with drive0 selected */
452 SELECT_DRIVE(&hwif->drives[0]); 459 SELECT_DRIVE(&hwif->drives[0]);
453 /* allow ATA_BUSY to assert & clear */ 460 /* allow ATA_BUSY to assert & clear */
@@ -460,7 +467,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
460 stat = tp_ops->read_status(hwif); 467 stat = tp_ops->read_status(hwif);
461 468
462 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) || 469 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
463 drive->present || cmd == ATA_CMD_ID_ATAPI) { 470 present || cmd == ATA_CMD_ID_ATAPI) {
464 /* send cmd and wait */ 471 /* send cmd and wait */
465 if ((rc = try_to_identify(drive, cmd))) { 472 if ((rc = try_to_identify(drive, cmd))) {
466 /* failed: try again */ 473 /* failed: try again */
@@ -493,7 +500,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
493 /* not present or maybe ATAPI */ 500 /* not present or maybe ATAPI */
494 rc = 3; 501 rc = 3;
495 } 502 }
496 if (drive->select.b.unit != 0) { 503 if (drive->dn & 1) {
497 /* exit with drive0 selected */ 504 /* exit with drive0 selected */
498 SELECT_DRIVE(&hwif->drives[0]); 505 SELECT_DRIVE(&hwif->drives[0]);
499 msleep(50); 506 msleep(50);
@@ -542,8 +549,8 @@ static void enable_nest (ide_drive_t *drive)
542 * and presents things to the user as needed. 549 * and presents things to the user as needed.
543 * 550 *
544 * Returns: 0 no device was found 551 * Returns: 0 no device was found
545 * 1 device was found (note: drive->present might 552 * 1 device was found
546 * still be 0) 553 * (note: IDE_DFLAG_PRESENT might still be not set)
547 */ 554 */
548 555
549static inline u8 probe_for_drive (ide_drive_t *drive) 556static inline u8 probe_for_drive (ide_drive_t *drive)
@@ -559,10 +566,10 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
559 * Also note that 0 everywhere means "can't do X" 566 * Also note that 0 everywhere means "can't do X"
560 */ 567 */
561 568
569 drive->dev_flags &= ~IDE_DFLAG_ID_READ;
570
562 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL); 571 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL);
563 drive->id_read = 0; 572 if (drive->id == NULL) {
564 if(drive->id == NULL)
565 {
566 printk(KERN_ERR "ide: out of memory for id data.\n"); 573 printk(KERN_ERR "ide: out of memory for id data.\n");
567 return 0; 574 return 0;
568 } 575 }
@@ -571,14 +578,14 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
571 strcpy(m, "UNKNOWN"); 578 strcpy(m, "UNKNOWN");
572 579
573 /* skip probing? */ 580 /* skip probing? */
574 if (!drive->noprobe) { 581 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) {
575retry: 582retry:
576 /* if !(success||timed-out) */ 583 /* if !(success||timed-out) */
577 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2) 584 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2)
578 /* look for ATAPI device */ 585 /* look for ATAPI device */
579 (void)do_probe(drive, ATA_CMD_ID_ATAPI); 586 (void)do_probe(drive, ATA_CMD_ID_ATAPI);
580 587
581 if (!drive->present) 588 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
582 /* drive not found */ 589 /* drive not found */
583 return 0; 590 return 0;
584 591
@@ -588,7 +595,7 @@ retry:
588 } 595 }
589 596
590 /* identification failed? */ 597 /* identification failed? */
591 if (!drive->id_read) { 598 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
592 if (drive->media == ide_disk) { 599 if (drive->media == ide_disk) {
593 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n", 600 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
594 drive->name, drive->cyl, 601 drive->name, drive->cyl,
@@ -598,15 +605,17 @@ retry:
598 } else { 605 } else {
599 /* nuke it */ 606 /* nuke it */
600 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name); 607 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
601 drive->present = 0; 608 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
602 } 609 }
603 } 610 }
604 /* drive was found */ 611 /* drive was found */
605 } 612 }
606 if(!drive->present) 613
614 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
607 return 0; 615 return 0;
616
608 /* The drive wasn't being helpful. Add generic info only */ 617 /* The drive wasn't being helpful. Add generic info only */
609 if (drive->id_read == 0) { 618 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
610 generic_id(drive); 619 generic_id(drive);
611 return 1; 620 return 1;
612 } 621 }
@@ -616,7 +625,7 @@ retry:
616 ide_disk_init_mult_count(drive); 625 ide_disk_init_mult_count(drive);
617 } 626 }
618 627
619 return drive->present; 628 return !!(drive->dev_flags & IDE_DFLAG_PRESENT);
620} 629}
621 630
622static void hwif_release_dev(struct device *dev) 631static void hwif_release_dev(struct device *dev)
@@ -707,7 +716,8 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
707 ide_drive_t *drive = &hwif->drives[unit]; 716 ide_drive_t *drive = &hwif->drives[unit];
708 717
709 /* Ignore disks that we will not probe for later. */ 718 /* Ignore disks that we will not probe for later. */
710 if (!drive->noprobe || drive->present) { 719 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
720 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
711 SELECT_DRIVE(drive); 721 SELECT_DRIVE(drive);
712 hwif->tp_ops->set_irq(hwif, 1); 722 hwif->tp_ops->set_irq(hwif, 1);
713 mdelay(2); 723 mdelay(2);
@@ -739,7 +749,7 @@ void ide_undecoded_slave(ide_drive_t *dev1)
739{ 749{
740 ide_drive_t *dev0 = &dev1->hwif->drives[0]; 750 ide_drive_t *dev0 = &dev1->hwif->drives[0];
741 751
742 if ((dev1->dn & 1) == 0 || dev0->present == 0) 752 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
743 return; 753 return;
744 754
745 /* If the models don't match they are not the same product */ 755 /* If the models don't match they are not the same product */
@@ -759,7 +769,7 @@ void ide_undecoded_slave(ide_drive_t *dev1)
759 /* Appears to be an IDE flash adapter with decode bugs */ 769 /* Appears to be an IDE flash adapter with decode bugs */
760 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n"); 770 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
761 771
762 dev1->present = 0; 772 dev1->dev_flags &= ~IDE_DFLAG_PRESENT;
763} 773}
764 774
765EXPORT_SYMBOL_GPL(ide_undecoded_slave); 775EXPORT_SYMBOL_GPL(ide_undecoded_slave);
@@ -772,7 +782,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
772 782
773 BUG_ON(hwif->present); 783 BUG_ON(hwif->present);
774 784
775 if (hwif->drives[0].noprobe && hwif->drives[1].noprobe) 785 if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) &&
786 (hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE))
776 return -EACCES; 787 return -EACCES;
777 788
778 /* 789 /*
@@ -794,9 +805,9 @@ static int ide_probe_port(ide_hwif_t *hwif)
794 */ 805 */
795 for (unit = 0; unit < MAX_DRIVES; ++unit) { 806 for (unit = 0; unit < MAX_DRIVES; ++unit) {
796 ide_drive_t *drive = &hwif->drives[unit]; 807 ide_drive_t *drive = &hwif->drives[unit];
797 drive->dn = (hwif->channel ? 2 : 0) + unit; 808
798 (void) probe_for_drive(drive); 809 (void) probe_for_drive(drive);
799 if (drive->present) 810 if (drive->dev_flags & IDE_DFLAG_PRESENT)
800 rc = 0; 811 rc = 0;
801 } 812 }
802 813
@@ -820,17 +831,19 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
820 for (unit = 0; unit < MAX_DRIVES; unit++) { 831 for (unit = 0; unit < MAX_DRIVES; unit++) {
821 ide_drive_t *drive = &hwif->drives[unit]; 832 ide_drive_t *drive = &hwif->drives[unit];
822 833
823 if (drive->present && port_ops && port_ops->quirkproc) 834 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
824 port_ops->quirkproc(drive); 835 if (port_ops && port_ops->quirkproc)
836 port_ops->quirkproc(drive);
837 }
825 } 838 }
826 839
827 for (unit = 0; unit < MAX_DRIVES; ++unit) { 840 for (unit = 0; unit < MAX_DRIVES; ++unit) {
828 ide_drive_t *drive = &hwif->drives[unit]; 841 ide_drive_t *drive = &hwif->drives[unit];
829 842
830 if (drive->present) { 843 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
831 ide_set_max_pio(drive); 844 ide_set_max_pio(drive);
832 845
833 drive->nice1 = 1; 846 drive->dev_flags |= IDE_DFLAG_NICE1;
834 847
835 if (hwif->dma_ops) 848 if (hwif->dma_ops)
836 ide_set_dma(drive); 849 ide_set_dma(drive);
@@ -840,14 +853,14 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
840 for (unit = 0; unit < MAX_DRIVES; ++unit) { 853 for (unit = 0; unit < MAX_DRIVES; ++unit) {
841 ide_drive_t *drive = &hwif->drives[unit]; 854 ide_drive_t *drive = &hwif->drives[unit];
842 855
843 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) 856 if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
844 drive->no_io_32bit = 1; 857 drive->id[ATA_ID_DWORD_IO])
858 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
845 else 859 else
846 drive->no_io_32bit = drive->id[ATA_ID_DWORD_IO] ? 1 : 0; 860 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
847 } 861 }
848} 862}
849 863
850#if MAX_HWIFS > 1
851/* 864/*
852 * save_match() is used to simplify logic in init_irq() below. 865 * save_match() is used to simplify logic in init_irq() below.
853 * 866 *
@@ -872,7 +885,6 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
872 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */ 885 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
873 *match = new; 886 *match = new;
874} 887}
875#endif /* MAX_HWIFS > 1 */
876 888
877/* 889/*
878 * init request queue 890 * init request queue
@@ -951,26 +963,33 @@ static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
951 * - allocate the block device queue 963 * - allocate the block device queue
952 * - link drive into the hwgroup 964 * - link drive into the hwgroup
953 */ 965 */
954static void ide_port_setup_devices(ide_hwif_t *hwif) 966static int ide_port_setup_devices(ide_hwif_t *hwif)
955{ 967{
956 int i; 968 int i, j = 0;
957 969
958 mutex_lock(&ide_cfg_mtx); 970 mutex_lock(&ide_cfg_mtx);
959 for (i = 0; i < MAX_DRIVES; i++) { 971 for (i = 0; i < MAX_DRIVES; i++) {
960 ide_drive_t *drive = &hwif->drives[i]; 972 ide_drive_t *drive = &hwif->drives[i];
961 973
962 if (!drive->present) 974 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
963 continue; 975 continue;
964 976
965 if (ide_init_queue(drive)) { 977 if (ide_init_queue(drive)) {
966 printk(KERN_ERR "ide: failed to init %s\n", 978 printk(KERN_ERR "ide: failed to init %s\n",
967 drive->name); 979 drive->name);
980 kfree(drive->id);
981 drive->id = NULL;
982 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
968 continue; 983 continue;
969 } 984 }
970 985
986 j++;
987
971 ide_add_drive_to_hwgroup(drive); 988 ide_add_drive_to_hwgroup(drive);
972 } 989 }
973 mutex_unlock(&ide_cfg_mtx); 990 mutex_unlock(&ide_cfg_mtx);
991
992 return j;
974} 993}
975 994
976static ide_hwif_t *ide_ports[MAX_HWIFS]; 995static ide_hwif_t *ide_ports[MAX_HWIFS];
@@ -1029,7 +1048,7 @@ static int init_irq (ide_hwif_t *hwif)
1029 1048
1030 mutex_lock(&ide_cfg_mtx); 1049 mutex_lock(&ide_cfg_mtx);
1031 hwif->hwgroup = NULL; 1050 hwif->hwgroup = NULL;
1032#if MAX_HWIFS > 1 1051
1033 /* 1052 /*
1034 * Group up with any other hwifs that share our irq(s). 1053 * Group up with any other hwifs that share our irq(s).
1035 */ 1054 */
@@ -1054,7 +1073,7 @@ static int init_irq (ide_hwif_t *hwif)
1054 } 1073 }
1055 } 1074 }
1056 } 1075 }
1057#endif /* MAX_HWIFS > 1 */ 1076
1058 /* 1077 /*
1059 * If we are still without a hwgroup, then form a new one 1078 * If we are still without a hwgroup, then form a new one
1060 */ 1079 */
@@ -1153,12 +1172,13 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
1153 ide_hwif_t *hwif = data; 1172 ide_hwif_t *hwif = data;
1154 int unit = *part >> PARTN_BITS; 1173 int unit = *part >> PARTN_BITS;
1155 ide_drive_t *drive = &hwif->drives[unit]; 1174 ide_drive_t *drive = &hwif->drives[unit];
1156 if (!drive->present) 1175
1176 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1157 return NULL; 1177 return NULL;
1158 1178
1159 if (drive->media == ide_disk) 1179 if (drive->media == ide_disk)
1160 request_module("ide-disk"); 1180 request_module("ide-disk");
1161 if (drive->scsi) 1181 if (drive->dev_flags & IDE_DFLAG_SCSI)
1162 request_module("ide-scsi"); 1182 request_module("ide-scsi");
1163 if (drive->media == ide_cdrom || drive->media == ide_optical) 1183 if (drive->media == ide_cdrom || drive->media == ide_optical)
1164 request_module("ide-cd"); 1184 request_module("ide-cd");
@@ -1205,7 +1225,7 @@ EXPORT_SYMBOL_GPL(ide_unregister_region);
1205void ide_init_disk(struct gendisk *disk, ide_drive_t *drive) 1225void ide_init_disk(struct gendisk *disk, ide_drive_t *drive)
1206{ 1226{
1207 ide_hwif_t *hwif = drive->hwif; 1227 ide_hwif_t *hwif = drive->hwif;
1208 unsigned int unit = (drive->select.all >> 4) & 1; 1228 unsigned int unit = drive->dn & 1;
1209 1229
1210 disk->major = hwif->major; 1230 disk->major = hwif->major;
1211 disk->first_minor = unit << PARTN_BITS; 1231 disk->first_minor = unit << PARTN_BITS;
@@ -1248,7 +1268,7 @@ static void drive_release_dev (struct device *dev)
1248 ide_remove_drive_from_hwgroup(drive); 1268 ide_remove_drive_from_hwgroup(drive);
1249 kfree(drive->id); 1269 kfree(drive->id);
1250 drive->id = NULL; 1270 drive->id = NULL;
1251 drive->present = 0; 1271 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
1252 /* Messed up locking ... */ 1272 /* Messed up locking ... */
1253 spin_unlock_irq(&ide_lock); 1273 spin_unlock_irq(&ide_lock);
1254 blk_cleanup_queue(drive->queue); 1274 blk_cleanup_queue(drive->queue);
@@ -1327,7 +1347,7 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1327 struct device *dev = &drive->gendev; 1347 struct device *dev = &drive->gendev;
1328 int ret; 1348 int ret;
1329 1349
1330 if (!drive->present) 1350 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1331 continue; 1351 continue;
1332 1352
1333 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i); 1353 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
@@ -1351,12 +1371,14 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
1351 for (i = 0; i < MAX_DRIVES; i++) { 1371 for (i = 0; i < MAX_DRIVES; i++) {
1352 ide_drive_t *drive = &hwif->drives[i]; 1372 ide_drive_t *drive = &hwif->drives[i];
1353 1373
1374 drive->dn = i + hwif->channel * 2;
1375
1354 if (hwif->host_flags & IDE_HFLAG_IO_32BIT) 1376 if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
1355 drive->io_32bit = 1; 1377 drive->io_32bit = 1;
1356 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS) 1378 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
1357 drive->unmask = 1; 1379 drive->dev_flags |= IDE_DFLAG_UNMASK;
1358 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS) 1380 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
1359 drive->no_unmask = 1; 1381 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
1360 1382
1361 if (port_ops && port_ops->init_dev) 1383 if (port_ops && port_ops->init_dev)
1362 port_ops->init_dev(drive); 1384 port_ops->init_dev(drive);
@@ -1513,19 +1535,14 @@ static int ide_find_port_slot(const struct ide_port_info *d)
1513 * ports 0x1f0/0x170 (the ide0/ide1 defaults). 1535 * ports 0x1f0/0x170 (the ide0/ide1 defaults).
1514 */ 1536 */
1515 mutex_lock(&ide_cfg_mtx); 1537 mutex_lock(&ide_cfg_mtx);
1516 if (MAX_HWIFS == 1) { 1538 if (bootable) {
1517 if (ide_indexes == 0 && i == 0) 1539 if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
1518 idx = 1; 1540 idx = ffz(ide_indexes | i);
1519 } else { 1541 } else {
1520 if (bootable) { 1542 if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
1521 if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1) 1543 idx = ffz(ide_indexes | 3);
1522 idx = ffz(ide_indexes | i); 1544 else if ((ide_indexes & 3) != 3)
1523 } else { 1545 idx = ffz(ide_indexes);
1524 if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
1525 idx = ffz(ide_indexes | 3);
1526 else if ((ide_indexes & 3) != 3)
1527 idx = ffz(ide_indexes);
1528 }
1529 } 1546 }
1530 if (idx >= 0) 1547 if (idx >= 0)
1531 ide_indexes |= (1 << idx); 1548 ide_indexes |= (1 << idx);
@@ -1541,8 +1558,7 @@ static void ide_free_port_slot(int idx)
1541 mutex_unlock(&ide_cfg_mtx); 1558 mutex_unlock(&ide_cfg_mtx);
1542} 1559}
1543 1560
1544struct ide_host *ide_host_alloc_all(const struct ide_port_info *d, 1561struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1545 hw_regs_t **hws)
1546{ 1562{
1547 struct ide_host *host; 1563 struct ide_host *host;
1548 int i; 1564 int i;
@@ -1551,7 +1567,7 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1551 if (host == NULL) 1567 if (host == NULL)
1552 return NULL; 1568 return NULL;
1553 1569
1554 for (i = 0; i < MAX_HWIFS; i++) { 1570 for (i = 0; i < MAX_HOST_PORTS; i++) {
1555 ide_hwif_t *hwif; 1571 ide_hwif_t *hwif;
1556 int idx; 1572 int idx;
1557 1573
@@ -1593,18 +1609,6 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1593 1609
1594 return host; 1610 return host;
1595} 1611}
1596EXPORT_SYMBOL_GPL(ide_host_alloc_all);
1597
1598struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1599{
1600 hw_regs_t *hws_all[MAX_HWIFS];
1601 int i;
1602
1603 for (i = 0; i < MAX_HWIFS; i++)
1604 hws_all[i] = (i < 4) ? hws[i] : NULL;
1605
1606 return ide_host_alloc_all(d, hws_all);
1607}
1608EXPORT_SYMBOL_GPL(ide_host_alloc); 1612EXPORT_SYMBOL_GPL(ide_host_alloc);
1609 1613
1610int ide_host_register(struct ide_host *host, const struct ide_port_info *d, 1614int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
@@ -1613,7 +1617,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1613 ide_hwif_t *hwif, *mate = NULL; 1617 ide_hwif_t *hwif, *mate = NULL;
1614 int i, j = 0; 1618 int i, j = 0;
1615 1619
1616 for (i = 0; i < MAX_HWIFS; i++) { 1620 for (i = 0; i < MAX_HOST_PORTS; i++) {
1617 hwif = host->ports[i]; 1621 hwif = host->ports[i];
1618 1622
1619 if (hwif == NULL) { 1623 if (hwif == NULL) {
@@ -1626,22 +1630,22 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1626 1630
1627 if (d == NULL) { 1631 if (d == NULL) {
1628 mate = NULL; 1632 mate = NULL;
1629 continue; 1633 } else {
1630 } 1634 if ((i & 1) && mate) {
1635 hwif->mate = mate;
1636 mate->mate = hwif;
1637 }
1631 1638
1632 if ((i & 1) && mate) { 1639 mate = (i & 1) ? NULL : hwif;
1633 hwif->mate = mate;
1634 mate->mate = hwif;
1635 }
1636 1640
1637 mate = (i & 1) ? NULL : hwif; 1641 ide_init_port(hwif, i & 1, d);
1642 ide_port_cable_detect(hwif);
1643 }
1638 1644
1639 ide_init_port(hwif, i & 1, d);
1640 ide_port_cable_detect(hwif);
1641 ide_port_init_devices(hwif); 1645 ide_port_init_devices(hwif);
1642 } 1646 }
1643 1647
1644 for (i = 0; i < MAX_HWIFS; i++) { 1648 for (i = 0; i < MAX_HOST_PORTS; i++) {
1645 hwif = host->ports[i]; 1649 hwif = host->ports[i];
1646 1650
1647 if (hwif == NULL) 1651 if (hwif == NULL)
@@ -1658,7 +1662,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1658 ide_port_tune_devices(hwif); 1662 ide_port_tune_devices(hwif);
1659 } 1663 }
1660 1664
1661 for (i = 0; i < MAX_HWIFS; i++) { 1665 for (i = 0; i < MAX_HOST_PORTS; i++) {
1662 hwif = host->ports[i]; 1666 hwif = host->ports[i];
1663 1667
1664 if (hwif == NULL) 1668 if (hwif == NULL)
@@ -1671,10 +1675,13 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1671 continue; 1675 continue;
1672 } 1676 }
1673 1677
1674 j++;
1675
1676 if (hwif->present) 1678 if (hwif->present)
1677 ide_port_setup_devices(hwif); 1679 if (ide_port_setup_devices(hwif) == 0) {
1680 hwif->present = 0;
1681 continue;
1682 }
1683
1684 j++;
1678 1685
1679 ide_acpi_init(hwif); 1686 ide_acpi_init(hwif);
1680 1687
@@ -1682,7 +1689,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1682 ide_acpi_port_init_devices(hwif); 1689 ide_acpi_port_init_devices(hwif);
1683 } 1690 }
1684 1691
1685 for (i = 0; i < MAX_HWIFS; i++) { 1692 for (i = 0; i < MAX_HOST_PORTS; i++) {
1686 hwif = host->ports[i]; 1693 hwif = host->ports[i];
1687 1694
1688 if (hwif == NULL) 1695 if (hwif == NULL)
@@ -1695,7 +1702,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1695 hwif_register_devices(hwif); 1702 hwif_register_devices(hwif);
1696 } 1703 }
1697 1704
1698 for (i = 0; i < MAX_HWIFS; i++) { 1705 for (i = 0; i < MAX_HOST_PORTS; i++) {
1699 hwif = host->ports[i]; 1706 hwif = host->ports[i];
1700 1707
1701 if (hwif == NULL) 1708 if (hwif == NULL)
@@ -1740,7 +1747,7 @@ void ide_host_free(struct ide_host *host)
1740 ide_hwif_t *hwif; 1747 ide_hwif_t *hwif;
1741 int i; 1748 int i;
1742 1749
1743 for (i = 0; i < MAX_HWIFS; i++) { 1750 for (i = 0; i < MAX_HOST_PORTS; i++) {
1744 hwif = host->ports[i]; 1751 hwif = host->ports[i];
1745 1752
1746 if (hwif == NULL) 1753 if (hwif == NULL)
@@ -1758,7 +1765,7 @@ void ide_host_remove(struct ide_host *host)
1758{ 1765{
1759 int i; 1766 int i;
1760 1767
1761 for (i = 0; i < MAX_HWIFS; i++) { 1768 for (i = 0; i < MAX_HOST_PORTS; i++) {
1762 if (host->ports[i]) 1769 if (host->ports[i])
1763 ide_unregister(host->ports[i]); 1770 ide_unregister(host->ports[i]);
1764 } 1771 }
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index e7030a491463..b26926487cc0 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -227,7 +227,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
227 227
228ide_devset_rw(current_speed, xfer_rate); 228ide_devset_rw(current_speed, xfer_rate);
229ide_devset_rw_field(init_speed, init_speed); 229ide_devset_rw_field(init_speed, init_speed);
230ide_devset_rw_field(nice1, nice1); 230ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1);
231ide_devset_rw_field(number, dn); 231ide_devset_rw_field(number, dn);
232 232
233static const struct ide_proc_devset ide_generic_settings[] = { 233static const struct ide_proc_devset ide_generic_settings[] = {
@@ -622,9 +622,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
622 for (d = 0; d < MAX_DRIVES; d++) { 622 for (d = 0; d < MAX_DRIVES; d++) {
623 ide_drive_t *drive = &hwif->drives[d]; 623 ide_drive_t *drive = &hwif->drives[d];
624 624
625 if (!drive->present) 625 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
626 continue;
627 if (drive->proc)
628 continue; 626 continue;
629 627
630 drive->proc = proc_mkdir(drive->name, parent); 628 drive->proc = proc_mkdir(drive->name, parent);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index f8c84df4a0bc..25ac60f53273 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -172,23 +172,16 @@ typedef struct ide_tape_obj {
172 struct kref kref; 172 struct kref kref;
173 173
174 /* 174 /*
175 * pc points to the current processed packet command.
176 *
177 * failed_pc points to the last failed packet command, or contains 175 * failed_pc points to the last failed packet command, or contains
178 * NULL if we do not need to retry any packet command. This is 176 * NULL if we do not need to retry any packet command. This is
179 * required since an additional packet command is needed before the 177 * required since an additional packet command is needed before the
180 * retry, to get detailed information on what went wrong. 178 * retry, to get detailed information on what went wrong.
181 */ 179 */
182 /* Current packet command */
183 struct ide_atapi_pc *pc;
184 /* Last failed packet command */ 180 /* Last failed packet command */
185 struct ide_atapi_pc *failed_pc; 181 struct ide_atapi_pc *failed_pc;
186 /* used by REQ_IDETAPE_{READ,WRITE} requests */ 182 /* used by REQ_IDETAPE_{READ,WRITE} requests */
187 struct ide_atapi_pc queued_pc; 183 struct ide_atapi_pc queued_pc;
188 184
189 struct ide_atapi_pc request_sense_pc;
190 struct request request_sense_rq;
191
192 /* 185 /*
193 * DSC polling variables. 186 * DSC polling variables.
194 * 187 *
@@ -274,11 +267,6 @@ static DEFINE_MUTEX(idetape_ref_mutex);
274 267
275static struct class *idetape_sysfs_class; 268static struct class *idetape_sysfs_class;
276 269
277#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref)
278
279#define ide_tape_g(disk) \
280 container_of((disk)->private_data, struct ide_tape_obj, driver)
281
282static void ide_tape_release(struct kref *); 270static void ide_tape_release(struct kref *);
283 271
284static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) 272static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
@@ -286,7 +274,7 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
286 struct ide_tape_obj *tape = NULL; 274 struct ide_tape_obj *tape = NULL;
287 275
288 mutex_lock(&idetape_ref_mutex); 276 mutex_lock(&idetape_ref_mutex);
289 tape = ide_tape_g(disk); 277 tape = ide_drv_g(disk, ide_tape_obj);
290 if (tape) { 278 if (tape) {
291 if (ide_device_get(tape->drive)) 279 if (ide_device_get(tape->drive))
292 tape = NULL; 280 tape = NULL;
@@ -313,8 +301,6 @@ static void ide_tape_put(struct ide_tape_obj *tape)
313 */ 301 */
314static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES]; 302static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
315 303
316#define ide_tape_f(file) ((file)->private_data)
317
318static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) 304static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
319{ 305{
320 struct ide_tape_obj *tape = NULL; 306 struct ide_tape_obj *tape = NULL;
@@ -522,14 +508,19 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
522 return 0; 508 return 0;
523} 509}
524 510
525static void ide_tape_callback(ide_drive_t *drive) 511static void ide_tape_handle_dsc(ide_drive_t *);
512
513static void ide_tape_callback(ide_drive_t *drive, int dsc)
526{ 514{
527 idetape_tape_t *tape = drive->driver_data; 515 idetape_tape_t *tape = drive->driver_data;
528 struct ide_atapi_pc *pc = tape->pc; 516 struct ide_atapi_pc *pc = drive->pc;
529 int uptodate = pc->error ? 0 : 1; 517 int uptodate = pc->error ? 0 : 1;
530 518
531 debug_log(DBG_PROCS, "Enter %s\n", __func__); 519 debug_log(DBG_PROCS, "Enter %s\n", __func__);
532 520
521 if (dsc)
522 ide_tape_handle_dsc(drive);
523
533 if (tape->failed_pc == pc) 524 if (tape->failed_pc == pc)
534 tape->failed_pc = NULL; 525 tape->failed_pc = NULL;
535 526
@@ -558,7 +549,7 @@ static void ide_tape_callback(ide_drive_t *drive)
558 if (pc->error) 549 if (pc->error)
559 uptodate = pc->error; 550 uptodate = pc->error;
560 } else if (pc->c[0] == READ_POSITION && uptodate) { 551 } else if (pc->c[0] == READ_POSITION && uptodate) {
561 u8 *readpos = tape->pc->buf; 552 u8 *readpos = pc->buf;
562 553
563 debug_log(DBG_SENSE, "BOP - %s\n", 554 debug_log(DBG_SENSE, "BOP - %s\n",
564 (readpos[0] & 0x80) ? "Yes" : "No"); 555 (readpos[0] & 0x80) ? "Yes" : "No");
@@ -583,31 +574,6 @@ static void ide_tape_callback(ide_drive_t *drive)
583 idetape_end_request(drive, uptodate, 0); 574 idetape_end_request(drive, uptodate, 0);
584} 575}
585 576
586static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
587{
588 ide_init_pc(pc);
589 pc->c[0] = REQUEST_SENSE;
590 pc->c[4] = 20;
591 pc->req_xfer = 20;
592}
593
594/*
595 * idetape_retry_pc is called when an error was detected during the
596 * last packet command. We queue a request sense packet command in
597 * the head of the request list.
598 */
599static void idetape_retry_pc(ide_drive_t *drive)
600{
601 struct ide_tape_obj *tape = drive->driver_data;
602 struct request *rq = &tape->request_sense_rq;
603 struct ide_atapi_pc *pc = &tape->request_sense_pc;
604
605 (void)ide_read_error(drive);
606 idetape_create_request_sense_cmd(pc);
607 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
608 ide_queue_pc_head(drive, tape->disk, pc, rq);
609}
610
611/* 577/*
612 * Postpone the current request so that ide.c will be able to service requests 578 * Postpone the current request so that ide.c will be able to service requests
613 * from another device on the same hwgroup while we are polling for DSC. 579 * from another device on the same hwgroup while we are polling for DSC.
@@ -646,34 +612,18 @@ static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
646} 612}
647 613
648/* 614/*
649 * This is the usual interrupt handler which will be called during a packet
650 * command. We will transfer some of the data (as requested by the drive) and
651 * will re-point interrupt handler to us. When data transfer is finished, we
652 * will act according to the algorithm described before
653 * idetape_issue_pc.
654 */
655static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
656{
657 idetape_tape_t *tape = drive->driver_data;
658
659 return ide_pc_intr(drive, tape->pc, idetape_pc_intr, WAIT_TAPE_CMD,
660 NULL, idetape_update_buffers, idetape_retry_pc,
661 ide_tape_handle_dsc, ide_tape_io_buffers);
662}
663
664/*
665 * Packet Command Interface 615 * Packet Command Interface
666 * 616 *
667 * The current Packet Command is available in tape->pc, and will not change 617 * The current Packet Command is available in drive->pc, and will not change
668 * until we finish handling it. Each packet command is associated with a 618 * until we finish handling it. Each packet command is associated with a
669 * callback function that will be called when the command is finished. 619 * callback function that will be called when the command is finished.
670 * 620 *
671 * The handling will be done in three stages: 621 * The handling will be done in three stages:
672 * 622 *
673 * 1. idetape_issue_pc will send the packet command to the drive, and will set 623 * 1. idetape_issue_pc will send the packet command to the drive, and will set
674 * the interrupt handler to idetape_pc_intr. 624 * the interrupt handler to ide_pc_intr.
675 * 625 *
676 * 2. On each interrupt, idetape_pc_intr will be called. This step will be 626 * 2. On each interrupt, ide_pc_intr will be called. This step will be
677 * repeated until the device signals us that no more interrupts will be issued. 627 * repeated until the device signals us that no more interrupts will be issued.
678 * 628 *
679 * 3. ATAPI Tape media access commands have immediate status with a delayed 629 * 3. ATAPI Tape media access commands have immediate status with a delayed
@@ -697,20 +647,13 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
697 * again, the callback function will be called and then we will handle the next 647 * again, the callback function will be called and then we will handle the next
698 * request. 648 * request.
699 */ 649 */
700static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
701{
702 idetape_tape_t *tape = drive->driver_data;
703
704 return ide_transfer_pc(drive, tape->pc, idetape_pc_intr,
705 WAIT_TAPE_CMD, NULL);
706}
707 650
708static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, 651static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
709 struct ide_atapi_pc *pc) 652 struct ide_atapi_pc *pc)
710{ 653{
711 idetape_tape_t *tape = drive->driver_data; 654 idetape_tape_t *tape = drive->driver_data;
712 655
713 if (tape->pc->c[0] == REQUEST_SENSE && 656 if (drive->pc->c[0] == REQUEST_SENSE &&
714 pc->c[0] == REQUEST_SENSE) { 657 pc->c[0] == REQUEST_SENSE) {
715 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - " 658 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
716 "Two request sense in serial were issued\n"); 659 "Two request sense in serial were issued\n");
@@ -718,8 +661,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
718 661
719 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) 662 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
720 tape->failed_pc = pc; 663 tape->failed_pc = pc;
664
721 /* Set the current packet command */ 665 /* Set the current packet command */
722 tape->pc = pc; 666 drive->pc = pc;
723 667
724 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 668 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
725 (pc->flags & PC_FLAG_ABORT)) { 669 (pc->flags & PC_FLAG_ABORT)) {
@@ -743,15 +687,14 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
743 pc->error = IDETAPE_ERROR_GENERAL; 687 pc->error = IDETAPE_ERROR_GENERAL;
744 } 688 }
745 tape->failed_pc = NULL; 689 tape->failed_pc = NULL;
746 drive->pc_callback(drive); 690 drive->pc_callback(drive, 0);
747 return ide_stopped; 691 return ide_stopped;
748 } 692 }
749 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 693 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
750 694
751 pc->retries++; 695 pc->retries++;
752 696
753 return ide_issue_pc(drive, pc, idetape_transfer_pc, 697 return ide_issue_pc(drive, WAIT_TAPE_CMD, NULL);
754 WAIT_TAPE_CMD, NULL);
755} 698}
756 699
757/* A mode sense command is used to "sense" tape parameters. */ 700/* A mode sense command is used to "sense" tape parameters. */
@@ -785,7 +728,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
785{ 728{
786 ide_hwif_t *hwif = drive->hwif; 729 ide_hwif_t *hwif = drive->hwif;
787 idetape_tape_t *tape = drive->driver_data; 730 idetape_tape_t *tape = drive->driver_data;
788 struct ide_atapi_pc *pc = tape->pc; 731 struct ide_atapi_pc *pc = drive->pc;
789 u8 stat; 732 u8 stat;
790 733
791 stat = hwif->tp_ops->read_status(hwif); 734 stat = hwif->tp_ops->read_status(hwif);
@@ -797,7 +740,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
797 printk(KERN_ERR "ide-tape: %s: I/O error, ", 740 printk(KERN_ERR "ide-tape: %s: I/O error, ",
798 tape->name); 741 tape->name);
799 /* Retry operation */ 742 /* Retry operation */
800 idetape_retry_pc(drive); 743 ide_retry_pc(drive, tape->disk);
801 return ide_stopped; 744 return ide_stopped;
802 } 745 }
803 pc->error = 0; 746 pc->error = 0;
@@ -805,7 +748,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
805 pc->error = IDETAPE_ERROR_GENERAL; 748 pc->error = IDETAPE_ERROR_GENERAL;
806 tape->failed_pc = NULL; 749 tape->failed_pc = NULL;
807 } 750 }
808 drive->pc_callback(drive); 751 drive->pc_callback(drive, 0);
809 return ide_stopped; 752 return ide_stopped;
810} 753}
811 754
@@ -862,7 +805,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
862 } 805 }
863 806
864 /* Retry a failed packet command */ 807 /* Retry a failed packet command */
865 if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) { 808 if (tape->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
866 pc = tape->failed_pc; 809 pc = tape->failed_pc;
867 goto out; 810 goto out;
868 } 811 }
@@ -883,12 +826,13 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
883 */ 826 */
884 stat = hwif->tp_ops->read_status(hwif); 827 stat = hwif->tp_ops->read_status(hwif);
885 828
886 if (!drive->dsc_overlap && !(rq->cmd[13] & REQ_IDETAPE_PC2)) 829 if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
830 (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
887 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 831 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
888 832
889 if (drive->post_reset == 1) { 833 if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
890 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 834 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
891 drive->post_reset = 0; 835 drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
892 } 836 }
893 837
894 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) && 838 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
@@ -1411,7 +1355,7 @@ static int idetape_init_read(ide_drive_t *drive)
1411 * No point in issuing this if DSC overlap isn't supported, some 1355 * No point in issuing this if DSC overlap isn't supported, some
1412 * drives (Seagate STT3401A) will return an error. 1356 * drives (Seagate STT3401A) will return an error.
1413 */ 1357 */
1414 if (drive->dsc_overlap) { 1358 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1415 bytes_read = idetape_queue_rw_tail(drive, 1359 bytes_read = idetape_queue_rw_tail(drive,
1416 REQ_IDETAPE_READ, 0, 1360 REQ_IDETAPE_READ, 0,
1417 tape->merge_bh); 1361 tape->merge_bh);
@@ -1592,7 +1536,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1592static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, 1536static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1593 size_t count, loff_t *ppos) 1537 size_t count, loff_t *ppos)
1594{ 1538{
1595 struct ide_tape_obj *tape = ide_tape_f(file); 1539 struct ide_tape_obj *tape = file->private_data;
1596 ide_drive_t *drive = tape->drive; 1540 ide_drive_t *drive = tape->drive;
1597 ssize_t bytes_read, temp, actually_read = 0, rc; 1541 ssize_t bytes_read, temp, actually_read = 0, rc;
1598 ssize_t ret = 0; 1542 ssize_t ret = 0;
@@ -1654,7 +1598,7 @@ finish:
1654static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, 1598static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1655 size_t count, loff_t *ppos) 1599 size_t count, loff_t *ppos)
1656{ 1600{
1657 struct ide_tape_obj *tape = ide_tape_f(file); 1601 struct ide_tape_obj *tape = file->private_data;
1658 ide_drive_t *drive = tape->drive; 1602 ide_drive_t *drive = tape->drive;
1659 ssize_t actually_written = 0; 1603 ssize_t actually_written = 0;
1660 ssize_t ret = 0; 1604 ssize_t ret = 0;
@@ -1687,7 +1631,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1687 * point in issuing this if DSC overlap isn't supported, some 1631 * point in issuing this if DSC overlap isn't supported, some
1688 * drives (Seagate STT3401A) will return an error. 1632 * drives (Seagate STT3401A) will return an error.
1689 */ 1633 */
1690 if (drive->dsc_overlap) { 1634 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1691 ssize_t retval = idetape_queue_rw_tail(drive, 1635 ssize_t retval = idetape_queue_rw_tail(drive,
1692 REQ_IDETAPE_WRITE, 0, 1636 REQ_IDETAPE_WRITE, 0,
1693 tape->merge_bh); 1637 tape->merge_bh);
@@ -1886,7 +1830,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1886static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, 1830static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1887 unsigned int cmd, unsigned long arg) 1831 unsigned int cmd, unsigned long arg)
1888{ 1832{
1889 struct ide_tape_obj *tape = ide_tape_f(file); 1833 struct ide_tape_obj *tape = file->private_data;
1890 ide_drive_t *drive = tape->drive; 1834 ide_drive_t *drive = tape->drive;
1891 struct mtop mtop; 1835 struct mtop mtop;
1892 struct mtget mtget; 1836 struct mtget mtget;
@@ -2063,7 +2007,7 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
2063 2007
2064static int idetape_chrdev_release(struct inode *inode, struct file *filp) 2008static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2065{ 2009{
2066 struct ide_tape_obj *tape = ide_tape_f(filp); 2010 struct ide_tape_obj *tape = filp->private_data;
2067 ide_drive_t *drive = tape->drive; 2011 ide_drive_t *drive = tape->drive;
2068 unsigned int minor = iminor(inode); 2012 unsigned int minor = iminor(inode);
2069 2013
@@ -2202,7 +2146,7 @@ static int divf_tdsc(ide_drive_t *drive) { return HZ; }
2202static int divf_buffer(ide_drive_t *drive) { return 2; } 2146static int divf_buffer(ide_drive_t *drive) { return 2; }
2203static int divf_buffer_size(ide_drive_t *drive) { return 1024; } 2147static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
2204 2148
2205ide_devset_rw_field(dsc_overlap, dsc_overlap); 2149ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
2206 2150
2207ide_tape_devset_rw_field(debug_mask, debug_mask); 2151ide_tape_devset_rw_field(debug_mask, debug_mask);
2208ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq); 2152ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
@@ -2241,33 +2185,32 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2241 unsigned long t; 2185 unsigned long t;
2242 int speed; 2186 int speed;
2243 int buffer_size; 2187 int buffer_size;
2244 u8 gcw[2];
2245 u16 *ctl = (u16 *)&tape->caps[12]; 2188 u16 *ctl = (u16 *)&tape->caps[12];
2246 2189
2247 drive->pc_callback = ide_tape_callback; 2190 drive->pc_callback = ide_tape_callback;
2191 drive->pc_update_buffers = idetape_update_buffers;
2192 drive->pc_io_buffers = ide_tape_io_buffers;
2248 2193
2249 spin_lock_init(&tape->lock); 2194 spin_lock_init(&tape->lock);
2250 drive->dsc_overlap = 1; 2195
2196 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2197
2251 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { 2198 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
2252 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", 2199 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
2253 tape->name); 2200 tape->name);
2254 drive->dsc_overlap = 0; 2201 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2255 } 2202 }
2203
2256 /* Seagate Travan drives do not support DSC overlap. */ 2204 /* Seagate Travan drives do not support DSC overlap. */
2257 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401")) 2205 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
2258 drive->dsc_overlap = 0; 2206 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2207
2259 tape->minor = minor; 2208 tape->minor = minor;
2260 tape->name[0] = 'h'; 2209 tape->name[0] = 'h';
2261 tape->name[1] = 't'; 2210 tape->name[1] = 't';
2262 tape->name[2] = '0' + minor; 2211 tape->name[2] = '0' + minor;
2263 tape->chrdev_dir = IDETAPE_DIR_NONE; 2212 tape->chrdev_dir = IDETAPE_DIR_NONE;
2264 2213
2265 *((u16 *)&gcw) = drive->id[ATA_ID_CONFIG];
2266
2267 /* Command packet DRQ type */
2268 if (((gcw[0] & 0x60) >> 5) == 1)
2269 set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
2270
2271 idetape_get_inquiry_results(drive); 2214 idetape_get_inquiry_results(drive);
2272 idetape_get_mode_sense_results(drive); 2215 idetape_get_mode_sense_results(drive);
2273 ide_tape_get_bsize_from_bdesc(drive); 2216 ide_tape_get_bsize_from_bdesc(drive);
@@ -2302,7 +2245,7 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2302 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, 2245 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
2303 tape->buffer_size / 1024, 2246 tape->buffer_size / 1024,
2304 tape->best_dsc_rw_freq * 1000 / HZ, 2247 tape->best_dsc_rw_freq * 1000 / HZ,
2305 drive->using_dma ? ", DMA":""); 2248 (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
2306 2249
2307 ide_proc_register_driver(drive, tape->driver); 2250 ide_proc_register_driver(drive, tape->driver);
2308} 2251}
@@ -2320,13 +2263,13 @@ static void ide_tape_remove(ide_drive_t *drive)
2320 2263
2321static void ide_tape_release(struct kref *kref) 2264static void ide_tape_release(struct kref *kref)
2322{ 2265{
2323 struct ide_tape_obj *tape = to_ide_tape(kref); 2266 struct ide_tape_obj *tape = to_ide_drv(kref, ide_tape_obj);
2324 ide_drive_t *drive = tape->drive; 2267 ide_drive_t *drive = tape->drive;
2325 struct gendisk *g = tape->disk; 2268 struct gendisk *g = tape->disk;
2326 2269
2327 BUG_ON(tape->merge_bh_size); 2270 BUG_ON(tape->merge_bh_size);
2328 2271
2329 drive->dsc_overlap = 0; 2272 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2330 drive->driver_data = NULL; 2273 drive->driver_data = NULL;
2331 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); 2274 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
2332 device_destroy(idetape_sysfs_class, 2275 device_destroy(idetape_sysfs_class,
@@ -2368,7 +2311,6 @@ static ide_driver_t idetape_driver = {
2368 .probe = ide_tape_probe, 2311 .probe = ide_tape_probe,
2369 .remove = ide_tape_remove, 2312 .remove = ide_tape_remove,
2370 .version = IDETAPE_VERSION, 2313 .version = IDETAPE_VERSION,
2371 .media = ide_tape,
2372 .do_request = idetape_do_request, 2314 .do_request = idetape_do_request,
2373 .end_request = idetape_end_request, 2315 .end_request = idetape_end_request,
2374 .error = __ide_error, 2316 .error = __ide_error,
@@ -2403,7 +2345,7 @@ static int idetape_open(struct inode *inode, struct file *filp)
2403static int idetape_release(struct inode *inode, struct file *filp) 2345static int idetape_release(struct inode *inode, struct file *filp)
2404{ 2346{
2405 struct gendisk *disk = inode->i_bdev->bd_disk; 2347 struct gendisk *disk = inode->i_bdev->bd_disk;
2406 struct ide_tape_obj *tape = ide_tape_g(disk); 2348 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
2407 2349
2408 ide_tape_put(tape); 2350 ide_tape_put(tape);
2409 2351
@@ -2414,7 +2356,7 @@ static int idetape_ioctl(struct inode *inode, struct file *file,
2414 unsigned int cmd, unsigned long arg) 2356 unsigned int cmd, unsigned long arg)
2415{ 2357{
2416 struct block_device *bdev = inode->i_bdev; 2358 struct block_device *bdev = inode->i_bdev;
2417 struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk); 2359 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
2418 ide_drive_t *drive = tape->drive; 2360 ide_drive_t *drive = tape->drive;
2419 int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 2361 int err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
2420 if (err == -EINVAL) 2362 if (err == -EINVAL)
@@ -2441,7 +2383,8 @@ static int ide_tape_probe(ide_drive_t *drive)
2441 if (drive->media != ide_tape) 2383 if (drive->media != ide_tape)
2442 goto failed; 2384 goto failed;
2443 2385
2444 if (drive->id_read == 1 && !ide_check_atapi_device(drive, DRV_NAME)) { 2386 if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
2387 ide_check_atapi_device(drive, DRV_NAME) == 0) {
2445 printk(KERN_ERR "ide-tape: %s: not supported by this version of" 2388 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
2446 " the driver\n", drive->name); 2389 " the driver\n", drive->name);
2447 goto failed; 2390 goto failed;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 487b18b3ebae..bf4fb9d8d176 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -53,9 +53,6 @@ int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
53} 53}
54 54
55static ide_startstop_t task_no_data_intr(ide_drive_t *); 55static ide_startstop_t task_no_data_intr(ide_drive_t *);
56static ide_startstop_t set_geometry_intr(ide_drive_t *);
57static ide_startstop_t recal_intr(ide_drive_t *);
58static ide_startstop_t set_multmode_intr(ide_drive_t *);
59static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *); 56static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
60static ide_startstop_t task_in_intr(ide_drive_t *); 57static ide_startstop_t task_in_intr(ide_drive_t *);
61 58
@@ -79,6 +76,8 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
79 if (task->tf_flags & IDE_TFLAG_FLAGGED) 76 if (task->tf_flags & IDE_TFLAG_FLAGGED)
80 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS; 77 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS;
81 78
79 memcpy(&hwif->task, task, sizeof(*task));
80
82 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) { 81 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
83 ide_tf_dump(drive->name, tf); 82 ide_tf_dump(drive->name, tf);
84 tp_ops->set_irq(hwif, 1); 83 tp_ops->set_irq(hwif, 1);
@@ -99,24 +98,12 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
99 case TASKFILE_NO_DATA: 98 case TASKFILE_NO_DATA:
100 if (handler == NULL) 99 if (handler == NULL)
101 handler = task_no_data_intr; 100 handler = task_no_data_intr;
102 if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) {
103 switch (tf->command) {
104 case ATA_CMD_INIT_DEV_PARAMS:
105 handler = set_geometry_intr;
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;
113 }
114 }
115 ide_execute_command(drive, tf->command, handler, 101 ide_execute_command(drive, tf->command, handler,
116 WAIT_WORSTCASE, NULL); 102 WAIT_WORSTCASE, NULL);
117 return ide_started; 103 return ide_started;
118 default: 104 default:
119 if (drive->using_dma == 0 || dma_ops->dma_setup(drive)) 105 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
106 dma_ops->dma_setup(drive))
120 return ide_stopped; 107 return ide_stopped;
121 dma_ops->dma_exec_cmd(drive, tf->command); 108 dma_ops->dma_exec_cmd(drive, tf->command);
122 dma_ops->dma_start(drive); 109 dma_ops->dma_start(drive);
@@ -126,33 +113,15 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
126EXPORT_SYMBOL_GPL(do_rw_taskfile); 113EXPORT_SYMBOL_GPL(do_rw_taskfile);
127 114
128/* 115/*
129 * set_multmode_intr() is invoked on completion of a ATA_CMD_SET_MULTI cmd. 116 * Handler for commands without a data phase
130 */
131static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
132{
133 ide_hwif_t *hwif = drive->hwif;
134 u8 stat;
135
136 local_irq_enable_in_hardirq();
137 stat = hwif->tp_ops->read_status(hwif);
138
139 if (OK_STAT(stat, ATA_DRDY, BAD_STAT))
140 drive->mult_count = drive->mult_req;
141 else {
142 drive->mult_req = drive->mult_count = 0;
143 drive->special.b.recalibrate = 1;
144 (void) ide_dump_status(drive, "set_multmode", stat);
145 }
146 return ide_stopped;
147}
148
149/*
150 * set_geometry_intr() is invoked on completion of a ATA_CMD_INIT_DEV_PARAMS cmd.
151 */ 117 */
152static ide_startstop_t set_geometry_intr(ide_drive_t *drive) 118static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
153{ 119{
154 ide_hwif_t *hwif = drive->hwif; 120 ide_hwif_t *hwif = drive->hwif;
155 int retries = 5; 121 ide_task_t *task = &hwif->task;
122 struct ide_taskfile *tf = &task->tf;
123 int custom = (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
124 int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
156 u8 stat; 125 u8 stat;
157 126
158 local_irq_enable_in_hardirq(); 127 local_irq_enable_in_hardirq();
@@ -164,50 +133,36 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
164 udelay(10); 133 udelay(10);
165 }; 134 };
166 135
167 if (OK_STAT(stat, ATA_DRDY, BAD_STAT)) 136 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
168 return ide_stopped; 137 if (custom && tf->command == ATA_CMD_SET_MULTI) {
169 138 drive->mult_req = drive->mult_count = 0;
170 if (stat & (ATA_ERR | ATA_DRQ)) 139 drive->special.b.recalibrate = 1;
171 return ide_error(drive, "set_geometry_intr", stat); 140 (void)ide_dump_status(drive, __func__, stat);
172 141 return ide_stopped;
173 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); 142 } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
174 return ide_started; 143 if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
175} 144 ide_set_handler(drive, &task_no_data_intr,
176 145 WAIT_WORSTCASE, NULL);
177/* 146 return ide_started;
178 * recal_intr() is invoked on completion of a ATA_CMD_RESTORE (recalibrate) cmd. 147 }
179 */ 148 }
180static ide_startstop_t recal_intr(ide_drive_t *drive)
181{
182 ide_hwif_t *hwif = drive->hwif;
183 u8 stat;
184
185 local_irq_enable_in_hardirq();
186 stat = hwif->tp_ops->read_status(hwif);
187
188 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
189 return ide_error(drive, "recal_intr", stat);
190 return ide_stopped;
191}
192
193/*
194 * Handler for commands without a data phase
195 */
196static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
197{
198 ide_hwif_t *hwif = drive->hwif;
199 ide_task_t *args = hwif->hwgroup->rq->special;
200 u8 stat;
201
202 local_irq_enable_in_hardirq();
203 stat = hwif->tp_ops->read_status(hwif);
204
205 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
206 return ide_error(drive, "task_no_data_intr", stat); 149 return ide_error(drive, "task_no_data_intr", stat);
207 /* calls ide_end_drive_cmd */ 150 /* calls ide_end_drive_cmd */
151 }
208 152
209 if (args) 153 if (!custom)
154 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
155 else if (tf->command == ATA_CMD_IDLEIMMEDIATE) {
156 hwif->tp_ops->tf_read(drive, task);
157 if (tf->lbal != 0xc4) {
158 printk(KERN_ERR "%s: head unload failed!\n",
159 drive->name);
160 ide_tf_dump(drive->name, tf);
161 } else
162 drive->dev_flags |= IDE_DFLAG_PARKED;
210 ide_end_drive_cmd(drive, stat, ide_read_error(drive)); 163 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
164 } else if (tf->command == ATA_CMD_SET_MULTI)
165 drive->mult_count = drive->mult_req;
211 166
212 return ide_stopped; 167 return ide_stopped;
213} 168}
@@ -469,13 +424,12 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
469 if (ide_wait_stat(&startstop, drive, ATA_DRQ, 424 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
470 drive->bad_wstat, WAIT_DRQ)) { 425 drive->bad_wstat, WAIT_DRQ)) {
471 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", 426 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
472 drive->name, 427 drive->name, drive->hwif->data_phase ? "MULT" : "",
473 drive->hwif->data_phase ? "MULT" : "", 428 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
474 drive->addressing ? "_EXT" : "");
475 return startstop; 429 return startstop;
476 } 430 }
477 431
478 if (!drive->unmask) 432 if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
479 local_irq_disable(); 433 local_irq_disable();
480 434
481 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); 435 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
@@ -591,7 +545,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
591 545
592 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE | 546 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
593 IDE_TFLAG_IN_TF; 547 IDE_TFLAG_IN_TF;
594 if (drive->addressing == 1) 548 if (drive->dev_flags & IDE_DFLAG_LBA48)
595 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB); 549 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
596 550
597 if (req_task->out_flags.all) { 551 if (req_task->out_flags.all) {
@@ -694,7 +648,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
694 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) && 648 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) &&
695 req_task->in_flags.all == 0) { 649 req_task->in_flags.all == 0) {
696 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; 650 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
697 if (drive->addressing == 1) 651 if (drive->dev_flags & IDE_DFLAG_LBA48)
698 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8); 652 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
699 } 653 }
700 654
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 9dcf5aed92cb..04f8f13cb9d7 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -114,7 +114,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
114 memset(drive, 0, sizeof(*drive)); 114 memset(drive, 0, sizeof(*drive));
115 115
116 drive->media = ide_disk; 116 drive->media = ide_disk;
117 drive->select.all = (unit<<4)|0xa0; 117 drive->select = (unit << 4) | ATA_DEVICE_OBS;
118 drive->hwif = hwif; 118 drive->hwif = hwif;
119 drive->ready_stat = ATA_DRDY; 119 drive->ready_stat = ATA_DRDY;
120 drive->bad_wstat = BAD_W_STAT; 120 drive->bad_wstat = BAD_W_STAT;
@@ -138,7 +138,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
138 for (i = 0; i < MAX_DRIVES; i++) { 138 for (i = 0; i < MAX_DRIVES; i++) {
139 ide_drive_t *drive = &hwif->drives[i]; 139 ide_drive_t *drive = &hwif->drives[i];
140 140
141 if (drive->present) { 141 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
142 spin_unlock_irq(&ide_lock); 142 spin_unlock_irq(&ide_lock);
143 device_unregister(&drive->gendev); 143 device_unregister(&drive->gendev);
144 wait_for_completion(&drive->gendev_rel_comp); 144 wait_for_completion(&drive->gendev_rel_comp);
@@ -227,8 +227,7 @@ void ide_unregister(ide_hwif_t *hwif)
227 kfree(hwif->sg_table); 227 kfree(hwif->sg_table);
228 unregister_blkdev(hwif->major, hwif->name); 228 unregister_blkdev(hwif->major, hwif->name);
229 229
230 if (hwif->dma_base) 230 ide_release_dma_engine(hwif);
231 ide_release_dma_engine(hwif);
232 231
233 mutex_unlock(&ide_cfg_mtx); 232 mutex_unlock(&ide_cfg_mtx);
234} 233}
@@ -254,7 +253,7 @@ ide_devset_get(io_32bit, io_32bit);
254 253
255static int set_io_32bit(ide_drive_t *drive, int arg) 254static int set_io_32bit(ide_drive_t *drive, int arg)
256{ 255{
257 if (drive->no_io_32bit) 256 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
258 return -EPERM; 257 return -EPERM;
259 258
260 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) 259 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
@@ -265,19 +264,22 @@ static int set_io_32bit(ide_drive_t *drive, int arg)
265 return 0; 264 return 0;
266} 265}
267 266
268ide_devset_get(ksettings, keep_settings); 267ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
269 268
270static int set_ksettings(ide_drive_t *drive, int arg) 269static int set_ksettings(ide_drive_t *drive, int arg)
271{ 270{
272 if (arg < 0 || arg > 1) 271 if (arg < 0 || arg > 1)
273 return -EINVAL; 272 return -EINVAL;
274 273
275 drive->keep_settings = arg; 274 if (arg)
275 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
276 else
277 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
276 278
277 return 0; 279 return 0;
278} 280}
279 281
280ide_devset_get(using_dma, using_dma); 282ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
281 283
282static int set_using_dma(ide_drive_t *drive, int arg) 284static int set_using_dma(ide_drive_t *drive, int arg)
283{ 285{
@@ -311,9 +313,32 @@ out:
311#endif 313#endif
312} 314}
313 315
316/*
317 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
318 */
319static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
320{
321 switch (req_pio) {
322 case 202:
323 case 201:
324 case 200:
325 case 102:
326 case 101:
327 case 100:
328 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
329 case 9:
330 case 8:
331 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
332 case 7:
333 case 6:
334 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
335 default:
336 return 0;
337 }
338}
339
314static int set_pio_mode(ide_drive_t *drive, int arg) 340static int set_pio_mode(ide_drive_t *drive, int arg)
315{ 341{
316 struct request *rq;
317 ide_hwif_t *hwif = drive->hwif; 342 ide_hwif_t *hwif = drive->hwif;
318 const struct ide_port_ops *port_ops = hwif->port_ops; 343 const struct ide_port_ops *port_ops = hwif->port_ops;
319 344
@@ -324,56 +349,65 @@ static int set_pio_mode(ide_drive_t *drive, int arg)
324 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) 349 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
325 return -ENOSYS; 350 return -ENOSYS;
326 351
327 if (drive->special.b.set_tune) 352 if (set_pio_mode_abuse(drive->hwif, arg)) {
328 return -EBUSY; 353 if (arg == 8 || arg == 9) {
354 unsigned long flags;
329 355
330 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 356 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
331 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 357 spin_lock_irqsave(&ide_lock, flags);
358 port_ops->set_pio_mode(drive, arg);
359 spin_unlock_irqrestore(&ide_lock, flags);
360 } else
361 port_ops->set_pio_mode(drive, arg);
362 } else {
363 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
332 364
333 drive->tune_req = (u8) arg; 365 ide_set_pio(drive, arg);
334 drive->special.b.set_tune = 1;
335 366
336 blk_execute_rq(drive->queue, NULL, rq, 0); 367 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
337 blk_put_request(rq); 368 if (keep_dma)
369 ide_dma_on(drive);
370 }
371 }
338 372
339 return 0; 373 return 0;
340} 374}
341 375
342ide_devset_get(unmaskirq, unmask); 376ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
343 377
344static int set_unmaskirq(ide_drive_t *drive, int arg) 378static int set_unmaskirq(ide_drive_t *drive, int arg)
345{ 379{
346 if (drive->no_unmask) 380 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
347 return -EPERM; 381 return -EPERM;
348 382
349 if (arg < 0 || arg > 1) 383 if (arg < 0 || arg > 1)
350 return -EINVAL; 384 return -EINVAL;
351 385
352 drive->unmask = arg; 386 if (arg)
387 drive->dev_flags |= IDE_DFLAG_UNMASK;
388 else
389 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
353 390
354 return 0; 391 return 0;
355} 392}
356 393
357#define ide_gen_devset_rw(_name, _func) \ 394ide_ext_devset_rw_sync(io_32bit, io_32bit);
358__IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func) 395ide_ext_devset_rw_sync(keepsettings, ksettings);
359 396ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
360ide_gen_devset_rw(io_32bit, io_32bit); 397ide_ext_devset_rw_sync(using_dma, using_dma);
361ide_gen_devset_rw(keepsettings, ksettings); 398__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
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 399
366static int generic_ide_suspend(struct device *dev, pm_message_t mesg) 400static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
367{ 401{
368 ide_drive_t *drive = dev->driver_data; 402 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
369 ide_hwif_t *hwif = HWIF(drive); 403 ide_hwif_t *hwif = HWIF(drive);
370 struct request *rq; 404 struct request *rq;
371 struct request_pm_state rqpm; 405 struct request_pm_state rqpm;
372 ide_task_t args; 406 ide_task_t args;
373 int ret; 407 int ret;
374 408
375 /* Call ACPI _GTM only once */ 409 /* call ACPI _GTM only once */
376 if (!(drive->dn % 2)) 410 if ((drive->dn & 1) == 0 || pair == NULL)
377 ide_acpi_get_timing(hwif); 411 ide_acpi_get_timing(hwif);
378 412
379 memset(&rqpm, 0, sizeof(rqpm)); 413 memset(&rqpm, 0, sizeof(rqpm));
@@ -382,33 +416,32 @@ static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
382 rq->cmd_type = REQ_TYPE_PM_SUSPEND; 416 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
383 rq->special = &args; 417 rq->special = &args;
384 rq->data = &rqpm; 418 rq->data = &rqpm;
385 rqpm.pm_step = ide_pm_state_start_suspend; 419 rqpm.pm_step = IDE_PM_START_SUSPEND;
386 if (mesg.event == PM_EVENT_PRETHAW) 420 if (mesg.event == PM_EVENT_PRETHAW)
387 mesg.event = PM_EVENT_FREEZE; 421 mesg.event = PM_EVENT_FREEZE;
388 rqpm.pm_state = mesg.event; 422 rqpm.pm_state = mesg.event;
389 423
390 ret = blk_execute_rq(drive->queue, NULL, rq, 0); 424 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
391 blk_put_request(rq); 425 blk_put_request(rq);
392 /* only call ACPI _PS3 after both drivers are suspended */ 426
393 if (!ret && (((drive->dn % 2) && hwif->drives[0].present 427 /* call ACPI _PS3 only after both devices are suspended */
394 && hwif->drives[1].present) 428 if (ret == 0 && ((drive->dn & 1) || pair == NULL))
395 || !hwif->drives[0].present
396 || !hwif->drives[1].present))
397 ide_acpi_set_state(hwif, 0); 429 ide_acpi_set_state(hwif, 0);
430
398 return ret; 431 return ret;
399} 432}
400 433
401static int generic_ide_resume(struct device *dev) 434static int generic_ide_resume(struct device *dev)
402{ 435{
403 ide_drive_t *drive = dev->driver_data; 436 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
404 ide_hwif_t *hwif = HWIF(drive); 437 ide_hwif_t *hwif = HWIF(drive);
405 struct request *rq; 438 struct request *rq;
406 struct request_pm_state rqpm; 439 struct request_pm_state rqpm;
407 ide_task_t args; 440 ide_task_t args;
408 int err; 441 int err;
409 442
410 /* Call ACPI _STM only once */ 443 /* call ACPI _PS0 / _STM only once */
411 if (!(drive->dn % 2)) { 444 if ((drive->dn & 1) == 0 || pair == NULL) {
412 ide_acpi_set_state(hwif, 1); 445 ide_acpi_set_state(hwif, 1);
413 ide_acpi_push_timing(hwif); 446 ide_acpi_push_timing(hwif);
414 } 447 }
@@ -422,7 +455,7 @@ static int generic_ide_resume(struct device *dev)
422 rq->cmd_flags |= REQ_PREEMPT; 455 rq->cmd_flags |= REQ_PREEMPT;
423 rq->special = &args; 456 rq->special = &args;
424 rq->data = &rqpm; 457 rq->data = &rqpm;
425 rqpm.pm_step = ide_pm_state_start_resume; 458 rqpm.pm_step = IDE_PM_START_RESUME;
426 rqpm.pm_state = PM_EVENT_ON; 459 rqpm.pm_state = PM_EVENT_ON;
427 460
428 err = blk_execute_rq(drive->queue, NULL, rq, 1); 461 err = blk_execute_rq(drive->queue, NULL, rq, 1);
@@ -554,6 +587,7 @@ static struct device_attribute ide_dev_attrs[] = {
554 __ATTR_RO(model), 587 __ATTR_RO(model),
555 __ATTR_RO(firmware), 588 __ATTR_RO(firmware),
556 __ATTR(serial, 0400, serial_show, NULL), 589 __ATTR(serial, 0400, serial_show, NULL),
590 __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
557 __ATTR_NULL 591 __ATTR_NULL
558}; 592};
559 593
@@ -708,22 +742,22 @@ static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
708module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0); 742module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
709MODULE_PARM_DESC(chs, "force device as a disk (using CHS)"); 743MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
710 744
711static void ide_dev_apply_params(ide_drive_t *drive) 745static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
712{ 746{
713 int i = drive->hwif->index * MAX_DRIVES + drive->select.b.unit; 747 int i = drive->hwif->index * MAX_DRIVES + unit;
714 748
715 if (ide_nodma & (1 << i)) { 749 if (ide_nodma & (1 << i)) {
716 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name); 750 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
717 drive->nodma = 1; 751 drive->dev_flags |= IDE_DFLAG_NODMA;
718 } 752 }
719 if (ide_noflush & (1 << i)) { 753 if (ide_noflush & (1 << i)) {
720 printk(KERN_INFO "ide: disabling flush requests for %s\n", 754 printk(KERN_INFO "ide: disabling flush requests for %s\n",
721 drive->name); 755 drive->name);
722 drive->noflush = 1; 756 drive->dev_flags |= IDE_DFLAG_NOFLUSH;
723 } 757 }
724 if (ide_noprobe & (1 << i)) { 758 if (ide_noprobe & (1 << i)) {
725 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name); 759 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
726 drive->noprobe = 1; 760 drive->dev_flags |= IDE_DFLAG_NOPROBE;
727 } 761 }
728 if (ide_nowerr & (1 << i)) { 762 if (ide_nowerr & (1 << i)) {
729 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n", 763 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
@@ -732,7 +766,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
732 } 766 }
733 if (ide_cdroms & (1 << i)) { 767 if (ide_cdroms & (1 << i)) {
734 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name); 768 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
735 drive->present = 1; 769 drive->dev_flags |= IDE_DFLAG_PRESENT;
736 drive->media = ide_cdrom; 770 drive->media = ide_cdrom;
737 /* an ATAPI device ignores DRDY */ 771 /* an ATAPI device ignores DRDY */
738 drive->ready_stat = 0; 772 drive->ready_stat = 0;
@@ -741,11 +775,12 @@ static void ide_dev_apply_params(ide_drive_t *drive)
741 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl; 775 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
742 drive->head = drive->bios_head = ide_disks_chs[i].head; 776 drive->head = drive->bios_head = ide_disks_chs[i].head;
743 drive->sect = drive->bios_sect = ide_disks_chs[i].sect; 777 drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
744 drive->forced_geom = 1; 778
745 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n", 779 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
746 drive->name, 780 drive->name,
747 drive->cyl, drive->head, drive->sect); 781 drive->cyl, drive->head, drive->sect);
748 drive->present = 1; 782
783 drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
749 drive->media = ide_disk; 784 drive->media = ide_disk;
750 drive->ready_stat = ATA_DRDY; 785 drive->ready_stat = ATA_DRDY;
751 } 786 }
@@ -785,7 +820,7 @@ void ide_port_apply_params(ide_hwif_t *hwif)
785 } 820 }
786 821
787 for (i = 0; i < MAX_DRIVES; i++) 822 for (i = 0; i < MAX_DRIVES; i++)
788 ide_dev_apply_params(&hwif->drives[i]); 823 ide_dev_apply_params(&hwif->drives[i], i);
789} 824}
790 825
791/* 826/*
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 7276c96aaa2a..90da1f953ed0 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -131,7 +131,7 @@ static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
131 drive->name, pio, time1, time2, param1, param2, param3, param4); 131 drive->name, pio, time1, time2, param1, param2, param3, param4);
132 132
133 /* stuff timing parameters into controller registers */ 133 /* stuff timing parameters into controller registers */
134 driveNum = (HWIF(drive)->index << 1) + drive->select.b.unit; 134 driveNum = (drive->hwif->index << 1) + (drive->dn & 1);
135 spin_lock_irqsave(&ali14xx_lock, flags); 135 spin_lock_irqsave(&ali14xx_lock, flags);
136 outb_p(regOn, basePort); 136 outb_p(regOn, basePort);
137 outReg(param1, regTab[driveNum].reg1); 137 outReg(param1, regTab[driveNum].reg1);
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index 5123ea291d07..c7e5c2246b79 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -120,7 +120,8 @@ static void ht6560b_selectproc (ide_drive_t *drive)
120 * Need to enforce prefetch sometimes because otherwise 120 * Need to enforce prefetch sometimes because otherwise
121 * it'll hang (hard). 121 * it'll hang (hard).
122 */ 122 */
123 if (drive->media != ide_disk || !drive->present) 123 if (drive->media != ide_disk ||
124 (drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
124 select |= HT_PREFETCH_MODE; 125 select |= HT_PREFETCH_MODE;
125 126
126 if (select != current_select || timing != current_timing) { 127 if (select != current_select || timing != current_timing) {
@@ -249,11 +250,11 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
249 */ 250 */
250 if (state) { 251 if (state) {
251 drive->drive_data |= t; /* enable prefetch mode */ 252 drive->drive_data |= t; /* enable prefetch mode */
252 drive->no_unmask = 1; 253 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
253 drive->unmask = 0; 254 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
254 } else { 255 } else {
255 drive->drive_data &= ~t; /* disable prefetch mode */ 256 drive->drive_data &= ~t; /* disable prefetch mode */
256 drive->no_unmask = 0; 257 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
257 } 258 }
258 259
259 spin_unlock_irqrestore(&ht6560b_lock, flags); 260 spin_unlock_irqrestore(&ht6560b_lock, flags);
diff --git a/drivers/ide/legacy/ide-4drives.c b/drivers/ide/legacy/ide-4drives.c
index c76d55de6996..9e85b1ec9607 100644
--- a/drivers/ide/legacy/ide-4drives.c
+++ b/drivers/ide/legacy/ide-4drives.c
@@ -14,7 +14,7 @@ MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port");
14static void ide_4drives_init_dev(ide_drive_t *drive) 14static void ide_4drives_init_dev(ide_drive_t *drive)
15{ 15{
16 if (drive->hwif->channel) 16 if (drive->hwif->channel)
17 drive->select.all ^= 0x20; 17 drive->select ^= 0x20;
18} 18}
19 19
20static const struct ide_port_ops ide_4drives_port_ops = { 20static const struct ide_port_ops ide_4drives_port_ops = {
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index ec408b3a7100..bc27c7aba936 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -305,7 +305,7 @@ static void __init qd6580_init_dev(ide_drive_t *drive)
305 } else 305 } else
306 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; 306 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA;
307 307
308 drive->drive_data = drive->select.b.unit ? t2 : t1; 308 drive->drive_data = (drive->dn & 1) ? t2 : t1;
309} 309}
310 310
311static const struct ide_port_ops qd6500_port_ops = { 311static const struct ide_port_ops qd6500_port_ops = {
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 11b7f61aae40..0ec8fd1e4dcb 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -322,11 +322,7 @@ static int auide_dma_setup(ide_drive_t *drive)
322} 322}
323 323
324static int auide_dma_test_irq(ide_drive_t *drive) 324static int auide_dma_test_irq(ide_drive_t *drive)
325{ 325{
326 if (drive->waiting_for_dma == 0)
327 printk(KERN_WARNING "%s: ide_dma_test_irq \
328 called while not waiting\n", drive->name);
329
330 /* If dbdma didn't execute the STOP command yet, the 326 /* If dbdma didn't execute the STOP command yet, the
331 * active bit is still set 327 * active bit is still set
332 */ 328 */
@@ -344,11 +340,6 @@ static void auide_dma_host_set(ide_drive_t *drive, int on)
344{ 340{
345} 341}
346 342
347static void auide_dma_lost_irq(ide_drive_t *drive)
348{
349 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
350}
351
352static void auide_ddma_tx_callback(int irq, void *param) 343static void auide_ddma_tx_callback(int irq, void *param)
353{ 344{
354 _auide_hwif *ahwif = (_auide_hwif*)param; 345 _auide_hwif *ahwif = (_auide_hwif*)param;
@@ -375,18 +366,6 @@ static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 de
375} 366}
376 367
377#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 368#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
378static void auide_dma_timeout(ide_drive_t *drive)
379{
380 ide_hwif_t *hwif = HWIF(drive);
381
382 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
383
384 if (auide_dma_test_irq(drive))
385 return;
386
387 auide_dma_end(drive);
388}
389
390static const struct ide_dma_ops au1xxx_dma_ops = { 369static const struct ide_dma_ops au1xxx_dma_ops = {
391 .dma_host_set = auide_dma_host_set, 370 .dma_host_set = auide_dma_host_set,
392 .dma_setup = auide_dma_setup, 371 .dma_setup = auide_dma_setup,
@@ -394,8 +373,8 @@ static const struct ide_dma_ops au1xxx_dma_ops = {
394 .dma_start = auide_dma_start, 373 .dma_start = auide_dma_start,
395 .dma_end = auide_dma_end, 374 .dma_end = auide_dma_end,
396 .dma_test_irq = auide_dma_test_irq, 375 .dma_test_irq = auide_dma_test_irq,
397 .dma_lost_irq = auide_dma_lost_irq, 376 .dma_lost_irq = ide_dma_lost_irq,
398 .dma_timeout = auide_dma_timeout, 377 .dma_timeout = ide_dma_timeout,
399}; 378};
400 379
401static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 380static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
@@ -448,10 +427,9 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
448 NUM_DESCRIPTORS); 427 NUM_DESCRIPTORS);
449 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan, 428 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
450 NUM_DESCRIPTORS); 429 NUM_DESCRIPTORS);
451 430
452 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, 431 /* FIXME: check return value */
453 PRD_ENTRIES * PRD_BYTES, /* 1 Page */ 432 (void)ide_allocate_dma_engine(hwif);
454 &hwif->dmatable_dma, GFP_KERNEL);
455 433
456 au1xxx_dbdma_start( auide->tx_chan ); 434 au1xxx_dbdma_start( auide->tx_chan );
457 au1xxx_dbdma_start( auide->rx_chan ); 435 au1xxx_dbdma_start( auide->rx_chan );
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index e7475ba559c7..4142c698e0d3 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -115,7 +115,7 @@ static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
115 struct pci_dev *dev = to_pci_dev(hwif->dev); 115 struct pci_dev *dev = to_pci_dev(hwif->dev);
116 struct ide_host *host = pci_get_drvdata(dev); 116 struct ide_host *host = pci_get_drvdata(dev);
117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv; 117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
118 u8 unit = (drive->select.b.unit & 0x01); 118 u8 unit = drive->dn & 1;
119 u8 tmp1 = 0, tmp2 = 0; 119 u8 tmp1 = 0, tmp2 = 0;
120 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 120 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
121 unsigned long flags; 121 unsigned long flags;
@@ -302,7 +302,7 @@ static const struct pci_device_id aec62xx_pci_tbl[] = {
302}; 302};
303MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl); 303MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);
304 304
305static struct pci_driver driver = { 305static struct pci_driver aec62xx_pci_driver = {
306 .name = "AEC62xx_IDE", 306 .name = "AEC62xx_IDE",
307 .id_table = aec62xx_pci_tbl, 307 .id_table = aec62xx_pci_tbl,
308 .probe = aec62xx_init_one, 308 .probe = aec62xx_init_one,
@@ -313,12 +313,12 @@ static struct pci_driver driver = {
313 313
314static int __init aec62xx_ide_init(void) 314static int __init aec62xx_ide_init(void)
315{ 315{
316 return ide_pci_register_driver(&driver); 316 return ide_pci_register_driver(&aec62xx_pci_driver);
317} 317}
318 318
319static void __exit aec62xx_ide_exit(void) 319static void __exit aec62xx_ide_exit(void)
320{ 320{
321 pci_unregister_driver(&driver); 321 pci_unregister_driver(&aec62xx_pci_driver);
322} 322}
323 323
324module_init(aec62xx_ide_init); 324module_init(aec62xx_ide_init);
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 053c75263918..daf9dce39e52 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -77,8 +77,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
77 int bus_speed = ide_pci_clk ? ide_pci_clk : 33; 77 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
78 int port = hwif->channel ? 0x5c : 0x58; 78 int port = hwif->channel ? 0x5c : 0x58;
79 int portFIFO = hwif->channel ? 0x55 : 0x54; 79 int portFIFO = hwif->channel ? 0x55 : 0x54;
80 u8 cd_dma_fifo = 0; 80 u8 cd_dma_fifo = 0, unit = drive->dn & 1;
81 int unit = drive->select.b.unit & 1;
82 81
83 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) 82 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
84 s_clc = 0; 83 s_clc = 0;
@@ -112,7 +111,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
112 } 111 }
113 112
114 pci_write_config_byte(dev, port, s_clc); 113 pci_write_config_byte(dev, port, s_clc);
115 pci_write_config_byte(dev, port+drive->select.b.unit+2, (a_clc << 4) | r_clc); 114 pci_write_config_byte(dev, port + unit + 2, (a_clc << 4) | r_clc);
116 local_irq_restore(flags); 115 local_irq_restore(flags);
117} 116}
118 117
@@ -154,7 +153,7 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
154 ide_hwif_t *hwif = HWIF(drive); 153 ide_hwif_t *hwif = HWIF(drive);
155 struct pci_dev *dev = to_pci_dev(hwif->dev); 154 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 u8 speed1 = speed; 155 u8 speed1 = speed;
157 u8 unit = (drive->select.b.unit & 0x01); 156 u8 unit = drive->dn & 1;
158 u8 tmpbyte = 0x00; 157 u8 tmpbyte = 0x00;
159 int m5229_udma = (hwif->channel) ? 0x57 : 0x56; 158 int m5229_udma = (hwif->channel) ? 0x57 : 0x56;
160 159
@@ -508,7 +507,7 @@ static const struct ide_dma_ops ali_dma_ops = {
508 .dma_setup = ali15x3_dma_setup, 507 .dma_setup = ali15x3_dma_setup,
509 .dma_exec_cmd = ide_dma_exec_cmd, 508 .dma_exec_cmd = ide_dma_exec_cmd,
510 .dma_start = ide_dma_start, 509 .dma_start = ide_dma_start,
511 .dma_end = __ide_dma_end, 510 .dma_end = ide_dma_end,
512 .dma_test_irq = ide_dma_test_irq, 511 .dma_test_irq = ide_dma_test_irq,
513 .dma_lost_irq = ide_dma_lost_irq, 512 .dma_lost_irq = ide_dma_lost_irq,
514 .dma_timeout = ide_dma_timeout, 513 .dma_timeout = ide_dma_timeout,
@@ -576,7 +575,7 @@ static const struct pci_device_id alim15x3_pci_tbl[] = {
576}; 575};
577MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl); 576MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
578 577
579static struct pci_driver driver = { 578static struct pci_driver alim15x3_pci_driver = {
580 .name = "ALI15x3_IDE", 579 .name = "ALI15x3_IDE",
581 .id_table = alim15x3_pci_tbl, 580 .id_table = alim15x3_pci_tbl,
582 .probe = alim15x3_init_one, 581 .probe = alim15x3_init_one,
@@ -587,12 +586,12 @@ static struct pci_driver driver = {
587 586
588static int __init ali15x3_ide_init(void) 587static int __init ali15x3_ide_init(void)
589{ 588{
590 return ide_pci_register_driver(&driver); 589 return ide_pci_register_driver(&alim15x3_pci_driver);
591} 590}
592 591
593static void __exit ali15x3_ide_exit(void) 592static void __exit ali15x3_ide_exit(void)
594{ 593{
595 return pci_unregister_driver(&driver); 594 return pci_unregister_driver(&alim15x3_pci_driver);
596} 595}
597 596
598module_init(ali15x3_ide_init); 597module_init(ali15x3_ide_init);
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 824471f91bf5..81ec73134eda 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -92,7 +92,7 @@ static void amd_set_drive(ide_drive_t *drive, const u8 speed)
92 92
93 ide_timing_compute(drive, speed, &t, T, UT); 93 ide_timing_compute(drive, speed, &t, T, UT);
94 94
95 if (peer->present) { 95 if (peer->dev_flags & IDE_DFLAG_PRESENT) {
96 ide_timing_compute(peer, peer->current_speed, &p, T, UT); 96 ide_timing_compute(peer, peer->current_speed, &p, T, UT);
97 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); 97 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
98 } 98 }
@@ -319,7 +319,7 @@ static const struct pci_device_id amd74xx_pci_tbl[] = {
319}; 319};
320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); 320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);
321 321
322static struct pci_driver driver = { 322static struct pci_driver amd74xx_pci_driver = {
323 .name = "AMD_IDE", 323 .name = "AMD_IDE",
324 .id_table = amd74xx_pci_tbl, 324 .id_table = amd74xx_pci_tbl,
325 .probe = amd74xx_probe, 325 .probe = amd74xx_probe,
@@ -330,12 +330,12 @@ static struct pci_driver driver = {
330 330
331static int __init amd74xx_ide_init(void) 331static int __init amd74xx_ide_init(void)
332{ 332{
333 return ide_pci_register_driver(&driver); 333 return ide_pci_register_driver(&amd74xx_pci_driver);
334} 334}
335 335
336static void __exit amd74xx_ide_exit(void) 336static void __exit amd74xx_ide_exit(void)
337{ 337{
338 pci_unregister_driver(&driver); 338 pci_unregister_driver(&amd74xx_pci_driver);
339} 339}
340 340
341module_init(amd74xx_ide_init); 341module_init(amd74xx_ide_init);
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index e4437034dd08..b2735d28f5cc 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -182,7 +182,7 @@ static const struct pci_device_id atiixp_pci_tbl[] = {
182}; 182};
183MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 183MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
184 184
185static struct pci_driver driver = { 185static struct pci_driver atiixp_pci_driver = {
186 .name = "ATIIXP_IDE", 186 .name = "ATIIXP_IDE",
187 .id_table = atiixp_pci_tbl, 187 .id_table = atiixp_pci_tbl,
188 .probe = atiixp_init_one, 188 .probe = atiixp_init_one,
@@ -193,12 +193,12 @@ static struct pci_driver driver = {
193 193
194static int __init atiixp_ide_init(void) 194static int __init atiixp_ide_init(void)
195{ 195{
196 return ide_pci_register_driver(&driver); 196 return ide_pci_register_driver(&atiixp_pci_driver);
197} 197}
198 198
199static void __exit atiixp_ide_exit(void) 199static void __exit atiixp_ide_exit(void)
200{ 200{
201 pci_unregister_driver(&driver); 201 pci_unregister_driver(&atiixp_pci_driver);
202} 202}
203 203
204module_init(atiixp_ide_init); 204module_init(atiixp_ide_init);
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index 7f39cdb41410..e4306647d00d 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -378,13 +378,13 @@ static void __set_prefetch_mode(ide_drive_t *drive, int mode)
378{ 378{
379 if (mode) { /* want prefetch on? */ 379 if (mode) { /* want prefetch on? */
380#if CMD640_PREFETCH_MASKS 380#if CMD640_PREFETCH_MASKS
381 drive->no_unmask = 1; 381 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
382 drive->unmask = 0; 382 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
383#endif 383#endif
384 drive->no_io_32bit = 0; 384 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
385 } else { 385 } else {
386 drive->no_unmask = 0; 386 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
387 drive->no_io_32bit = 1; 387 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
388 drive->io_32bit = 0; 388 drive->io_32bit = 0;
389 } 389 }
390} 390}
@@ -468,10 +468,10 @@ static void program_drive_counts(ide_drive_t *drive, unsigned int index)
468 */ 468 */
469 if (index > 1) { 469 if (index > 1) {
470 ide_hwif_t *hwif = drive->hwif; 470 ide_hwif_t *hwif = drive->hwif;
471 ide_drive_t *peer = &hwif->drives[!drive->select.b.unit]; 471 ide_drive_t *peer = &hwif->drives[!(drive->dn & 1)];
472 unsigned int mate = index ^ 1; 472 unsigned int mate = index ^ 1;
473 473
474 if (peer->present) { 474 if (peer->dev_flags & IDE_DFLAG_PRESENT) {
475 if (setup_count < setup_counts[mate]) 475 if (setup_count < setup_counts[mate])
476 setup_count = setup_counts[mate]; 476 setup_count = setup_counts[mate];
477 if (active_count < active_counts[mate]) 477 if (active_count < active_counts[mate])
@@ -607,7 +607,7 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
607 607
608static void cmd640_init_dev(ide_drive_t *drive) 608static void cmd640_init_dev(ide_drive_t *drive)
609{ 609{
610 unsigned int i = drive->hwif->channel * 2 + drive->select.b.unit; 610 unsigned int i = drive->hwif->channel * 2 + (drive->dn & 1);
611 611
612#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 612#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
613 /* 613 /*
@@ -626,7 +626,7 @@ static void cmd640_init_dev(ide_drive_t *drive)
626 */ 626 */
627 check_prefetch(drive, i); 627 check_prefetch(drive, i);
628 printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n", 628 printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n",
629 i, drive->no_io_32bit ? "off" : "on"); 629 i, (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT) ? "off" : "on");
630#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 630#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
631} 631}
632 632
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 456dee18b660..935385c77e06 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -228,7 +228,7 @@ static int cmd648_dma_end(ide_drive_t *drive)
228{ 228{
229 ide_hwif_t *hwif = HWIF(drive); 229 ide_hwif_t *hwif = HWIF(drive);
230 unsigned long base = hwif->dma_base - (hwif->channel * 8); 230 unsigned long base = hwif->dma_base - (hwif->channel * 8);
231 int err = __ide_dma_end(drive); 231 int err = ide_dma_end(drive);
232 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 232 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
233 MRDMODE_INTR_CH0; 233 MRDMODE_INTR_CH0;
234 u8 mrdmode = inb(base + 1); 234 u8 mrdmode = inb(base + 1);
@@ -248,7 +248,7 @@ static int cmd64x_dma_end(ide_drive_t *drive)
248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
249 CFR_INTR_CH0; 249 CFR_INTR_CH0;
250 u8 irq_stat = 0; 250 u8 irq_stat = 0;
251 int err = __ide_dma_end(drive); 251 int err = ide_dma_end(drive);
252 252
253 (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 253 (void) pci_read_config_byte(dev, irq_reg, &irq_stat);
254 /* clear the interrupt bit */ 254 /* clear the interrupt bit */
@@ -505,7 +505,7 @@ static const struct pci_device_id cmd64x_pci_tbl[] = {
505}; 505};
506MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl); 506MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl);
507 507
508static struct pci_driver driver = { 508static struct pci_driver cmd64x_pci_driver = {
509 .name = "CMD64x_IDE", 509 .name = "CMD64x_IDE",
510 .id_table = cmd64x_pci_tbl, 510 .id_table = cmd64x_pci_tbl,
511 .probe = cmd64x_init_one, 511 .probe = cmd64x_init_one,
@@ -516,12 +516,12 @@ static struct pci_driver driver = {
516 516
517static int __init cmd64x_ide_init(void) 517static int __init cmd64x_ide_init(void)
518{ 518{
519 return ide_pci_register_driver(&driver); 519 return ide_pci_register_driver(&cmd64x_pci_driver);
520} 520}
521 521
522static void __exit cmd64x_ide_exit(void) 522static void __exit cmd64x_ide_exit(void)
523{ 523{
524 pci_unregister_driver(&driver); 524 pci_unregister_driver(&cmd64x_pci_driver);
525} 525}
526 526
527module_init(cmd64x_ide_init); 527module_init(cmd64x_ide_init);
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index d6341f7c4144..5efb467f8fa0 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -145,7 +145,7 @@ static const struct pci_device_id cs5520_pci_tbl[] = {
145}; 145};
146MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl); 146MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl);
147 147
148static struct pci_driver driver = { 148static struct pci_driver cs5520_pci_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,
@@ -155,7 +155,7 @@ static struct pci_driver driver = {
155 155
156static int __init cs5520_ide_init(void) 156static int __init cs5520_ide_init(void)
157{ 157{
158 return ide_pci_register_driver(&driver); 158 return ide_pci_register_driver(&cs5520_pci_driver);
159} 159}
160 160
161module_init(cs5520_ide_init); 161module_init(cs5520_ide_init);
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index da42fa7e9f97..53f079cc00af 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -267,7 +267,7 @@ static const struct pci_device_id cs5530_pci_tbl[] = {
267}; 267};
268MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl); 268MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl);
269 269
270static struct pci_driver driver = { 270static struct pci_driver cs5530_pci_driver = {
271 .name = "CS5530 IDE", 271 .name = "CS5530 IDE",
272 .id_table = cs5530_pci_tbl, 272 .id_table = cs5530_pci_tbl,
273 .probe = cs5530_init_one, 273 .probe = cs5530_init_one,
@@ -278,12 +278,12 @@ static struct pci_driver driver = {
278 278
279static int __init cs5530_ide_init(void) 279static int __init cs5530_ide_init(void)
280{ 280{
281 return ide_pci_register_driver(&driver); 281 return ide_pci_register_driver(&cs5530_pci_driver);
282} 282}
283 283
284static void __exit cs5530_ide_exit(void) 284static void __exit cs5530_ide_exit(void)
285{ 285{
286 pci_unregister_driver(&driver); 286 pci_unregister_driver(&cs5530_pci_driver);
287} 287}
288 288
289module_init(cs5530_ide_init); 289module_init(cs5530_ide_init);
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 1e5bc59ea2fb..983d957a0189 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -76,7 +76,7 @@ static unsigned int cs5535_udma_timings[5] =
76static void cs5535_set_speed(ide_drive_t *drive, const u8 speed) 76static void cs5535_set_speed(ide_drive_t *drive, const u8 speed)
77{ 77{
78 u32 reg = 0, dummy; 78 u32 reg = 0, dummy;
79 int unit = drive->select.b.unit; 79 u8 unit = drive->dn & 1;
80 80
81 /* Set the PIO timings */ 81 /* Set the PIO timings */
82 if (speed < XFER_SW_DMA_0) { 82 if (speed < XFER_SW_DMA_0) {
@@ -192,7 +192,7 @@ static const struct pci_device_id cs5535_pci_tbl[] = {
192 192
193MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl); 193MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl);
194 194
195static struct pci_driver driver = { 195static struct pci_driver cs5535_pci_driver = {
196 .name = "CS5535_IDE", 196 .name = "CS5535_IDE",
197 .id_table = cs5535_pci_tbl, 197 .id_table = cs5535_pci_tbl,
198 .probe = cs5535_init_one, 198 .probe = cs5535_init_one,
@@ -203,12 +203,12 @@ static struct pci_driver driver = {
203 203
204static int __init cs5535_ide_init(void) 204static int __init cs5535_ide_init(void)
205{ 205{
206 return ide_pci_register_driver(&driver); 206 return ide_pci_register_driver(&cs5535_pci_driver);
207} 207}
208 208
209static void __exit cs5535_ide_exit(void) 209static void __exit cs5535_ide_exit(void)
210{ 210{
211 pci_unregister_driver(&driver); 211 pci_unregister_driver(&cs5535_pci_driver);
212} 212}
213 213
214module_init(cs5535_ide_init); 214module_init(cs5535_ide_init);
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 69820e9224d1..5297f07d2933 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -50,18 +50,11 @@
50 50
51#define DRV_NAME "cy82c693" 51#define DRV_NAME "cy82c693"
52 52
53/* the current version */
54#define CY82_VERSION "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)"
55
56/* 53/*
57 * The following are used to debug the driver. 54 * The following are used to debug the driver.
58 */ 55 */
59#define CY82C693_DEBUG_LOGS 0
60#define CY82C693_DEBUG_INFO 0 56#define CY82C693_DEBUG_INFO 0
61 57
62/* define CY82C693_SETDMA_CLOCK to set DMA Controller Clock Speed to ATCLK */
63#undef CY82C693_SETDMA_CLOCK
64
65/* 58/*
66 * NOTE: the value for busmaster timeout is tricky and I got it by 59 * NOTE: the value for busmaster timeout is tricky and I got it by
67 * trial and error! By using a to low value will cause DMA timeouts 60 * trial and error! By using a to low value will cause DMA timeouts
@@ -89,7 +82,6 @@
89#define CY82_INDEX_PORT 0x22 82#define CY82_INDEX_PORT 0x22
90#define CY82_DATA_PORT 0x23 83#define CY82_DATA_PORT 0x23
91 84
92#define CY82_INDEX_CTRLREG1 0x01
93#define CY82_INDEX_CHANNEL0 0x30 85#define CY82_INDEX_CHANNEL0 0x30
94#define CY82_INDEX_CHANNEL1 0x31 86#define CY82_INDEX_CHANNEL1 0x31
95#define CY82_INDEX_TIMEOUT 0x32 87#define CY82_INDEX_TIMEOUT 0x32
@@ -179,17 +171,6 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
179 171
180 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0; 172 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0;
181 173
182#if CY82C693_DEBUG_LOGS
183 /* for debug let's show the previous values */
184
185 outb(index, CY82_INDEX_PORT);
186 data = inb(CY82_DATA_PORT);
187
188 printk(KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
189 drive->name, HWIF(drive)->channel, drive->select.b.unit,
190 (data&0x3), ((data>>2)&1));
191#endif /* CY82C693_DEBUG_LOGS */
192
193 data = (mode & 3) | (single << 2); 174 data = (mode & 3) | (single << 2);
194 175
195 outb(index, CY82_INDEX_PORT); 176 outb(index, CY82_INDEX_PORT);
@@ -197,8 +178,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
197 178
198#if CY82C693_DEBUG_INFO 179#if CY82C693_DEBUG_INFO
199 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n", 180 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
200 drive->name, HWIF(drive)->channel, drive->select.b.unit, 181 drive->name, hwif->channel, drive->dn & 1, mode & 3, single);
201 mode & 3, single);
202#endif /* CY82C693_DEBUG_INFO */ 182#endif /* CY82C693_DEBUG_INFO */
203 183
204 /* 184 /*
@@ -239,50 +219,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
239 } 219 }
240 } 220 }
241 221
242#if CY82C693_DEBUG_LOGS
243 /* for debug let's show the register values */
244
245 if (drive->select.b.unit == 0) {
246 /*
247 * get master drive registers
248 * address setup control register
249 * is 32 bit !!!
250 */
251 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
252 addrCtrl &= 0x0F;
253
254 /* now let's get the remaining registers */
255 pci_read_config_byte(dev, CY82_IDE_MASTER_IOR, &pclk.time_16r);
256 pci_read_config_byte(dev, CY82_IDE_MASTER_IOW, &pclk.time_16w);
257 pci_read_config_byte(dev, CY82_IDE_MASTER_8BIT, &pclk.time_8);
258 } else {
259 /*
260 * set slave drive registers
261 * address setup control register
262 * is 32 bit !!!
263 */
264 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
265
266 addrCtrl &= 0xF0;
267 addrCtrl >>= 4;
268
269 /* now let's get the remaining registers */
270 pci_read_config_byte(dev, CY82_IDE_SLAVE_IOR, &pclk.time_16r);
271 pci_read_config_byte(dev, CY82_IDE_SLAVE_IOW, &pclk.time_16w);
272 pci_read_config_byte(dev, CY82_IDE_SLAVE_8BIT, &pclk.time_8);
273 }
274
275 printk(KERN_INFO "%s (ch=%d, dev=%d): PIO timing is "
276 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
277 drive->name, hwif->channel, drive->select.b.unit,
278 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
279#endif /* CY82C693_DEBUG_LOGS */
280
281 /* let's calc the values for this PIO mode */ 222 /* let's calc the values for this PIO mode */
282 compute_clocks(pio, &pclk); 223 compute_clocks(pio, &pclk);
283 224
284 /* now let's write the clocks registers */ 225 /* now let's write the clocks registers */
285 if (drive->select.b.unit == 0) { 226 if ((drive->dn & 1) == 0) {
286 /* 227 /*
287 * set master drive 228 * set master drive
288 * address setup control register 229 * address setup control register
@@ -324,63 +265,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
324#if CY82C693_DEBUG_INFO 265#if CY82C693_DEBUG_INFO
325 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to " 266 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to "
326 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n", 267 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
327 drive->name, hwif->channel, drive->select.b.unit, 268 drive->name, hwif->channel, drive->dn & 1,
328 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8); 269 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
329#endif /* CY82C693_DEBUG_INFO */ 270#endif /* CY82C693_DEBUG_INFO */
330} 271}
331 272
332/*
333 * this function is called during init and is used to setup the cy82c693 chip
334 */
335static unsigned int init_chipset_cy82c693(struct pci_dev *dev)
336{
337 if (PCI_FUNC(dev->devfn) != 1)
338 return 0;
339
340#ifdef CY82C693_SETDMA_CLOCK
341 u8 data = 0;
342#endif /* CY82C693_SETDMA_CLOCK */
343
344 /* write info about this verion of the driver */
345 printk(KERN_INFO CY82_VERSION "\n");
346
347#ifdef CY82C693_SETDMA_CLOCK
348 /* okay let's set the DMA clock speed */
349
350 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
351 data = inb(CY82_DATA_PORT);
352
353#if CY82C693_DEBUG_INFO
354 printk(KERN_INFO DRV_NAME ": Peripheral Configuration Register: 0x%X\n",
355 data);
356#endif /* CY82C693_DEBUG_INFO */
357
358 /*
359 * for some reason sometimes the DMA controller
360 * speed is set to ATCLK/2 ???? - we fix this here
361 *
362 * note: i don't know what causes this strange behaviour,
363 * but even changing the dma speed doesn't solve it :-(
364 * the ide performance is still only half the normal speed
365 *
366 * if anybody knows what goes wrong with my machine, please
367 * let me know - ASK
368 */
369
370 data |= 0x03;
371
372 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
373 outb(data, CY82_DATA_PORT);
374
375#if CY82C693_DEBUG_INFO
376 printk(KERN_INFO ": New Peripheral Configuration Register: 0x%X\n",
377 data);
378#endif /* CY82C693_DEBUG_INFO */
379
380#endif /* CY82C693_SETDMA_CLOCK */
381 return 0;
382}
383
384static void __devinit init_iops_cy82c693(ide_hwif_t *hwif) 273static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
385{ 274{
386 static ide_hwif_t *primary; 275 static ide_hwif_t *primary;
@@ -401,7 +290,6 @@ static const struct ide_port_ops cy82c693_port_ops = {
401 290
402static const struct ide_port_info cy82c693_chipset __devinitdata = { 291static const struct ide_port_info cy82c693_chipset __devinitdata = {
403 .name = DRV_NAME, 292 .name = DRV_NAME,
404 .init_chipset = init_chipset_cy82c693,
405 .init_iops = init_iops_cy82c693, 293 .init_iops = init_iops_cy82c693,
406 .port_ops = &cy82c693_port_ops, 294 .port_ops = &cy82c693_port_ops,
407 .chipset = ide_cy82c693, 295 .chipset = ide_cy82c693,
@@ -443,7 +331,7 @@ static const struct pci_device_id cy82c693_pci_tbl[] = {
443}; 331};
444MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl); 332MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl);
445 333
446static struct pci_driver driver = { 334static struct pci_driver cy82c693_pci_driver = {
447 .name = "Cypress_IDE", 335 .name = "Cypress_IDE",
448 .id_table = cy82c693_pci_tbl, 336 .id_table = cy82c693_pci_tbl,
449 .probe = cy82c693_init_one, 337 .probe = cy82c693_init_one,
@@ -454,12 +342,12 @@ static struct pci_driver driver = {
454 342
455static int __init cy82c693_ide_init(void) 343static int __init cy82c693_ide_init(void)
456{ 344{
457 return ide_pci_register_driver(&driver); 345 return ide_pci_register_driver(&cy82c693_pci_driver);
458} 346}
459 347
460static void __exit cy82c693_ide_exit(void) 348static void __exit cy82c693_ide_exit(void)
461{ 349{
462 pci_unregister_driver(&driver); 350 pci_unregister_driver(&cy82c693_pci_driver);
463} 351}
464 352
465module_init(cy82c693_ide_init); 353module_init(cy82c693_ide_init);
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index 83b63b365e51..8689a706f537 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -117,7 +117,7 @@ static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
117}; 117};
118MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl); 118MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
119 119
120static struct pci_driver driver = { 120static struct pci_driver delkin_cb_pci_driver = {
121 .name = "Delkin-ASKA-Workbit Cardbus IDE", 121 .name = "Delkin-ASKA-Workbit Cardbus IDE",
122 .id_table = delkin_cb_pci_tbl, 122 .id_table = delkin_cb_pci_tbl,
123 .probe = delkin_cb_probe, 123 .probe = delkin_cb_probe,
@@ -126,12 +126,12 @@ static struct pci_driver driver = {
126 126
127static int __init delkin_cb_init(void) 127static int __init delkin_cb_init(void)
128{ 128{
129 return pci_register_driver(&driver); 129 return pci_register_driver(&delkin_cb_pci_driver);
130} 130}
131 131
132static void __exit delkin_cb_exit(void) 132static void __exit delkin_cb_exit(void)
133{ 133{
134 pci_unregister_driver(&driver); 134 pci_unregister_driver(&delkin_cb_pci_driver);
135} 135}
136 136
137module_init(delkin_cb_init); 137module_init(delkin_cb_init);
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 092b238cb250..474f96a7c076 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -166,7 +166,7 @@ static const struct pci_device_id generic_pci_tbl[] = {
166}; 166};
167MODULE_DEVICE_TABLE(pci, generic_pci_tbl); 167MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
168 168
169static struct pci_driver driver = { 169static struct pci_driver generic_pci_driver = {
170 .name = "PCI_IDE", 170 .name = "PCI_IDE",
171 .id_table = generic_pci_tbl, 171 .id_table = generic_pci_tbl,
172 .probe = generic_init_one, 172 .probe = generic_init_one,
@@ -177,12 +177,12 @@ static struct pci_driver driver = {
177 177
178static int __init generic_ide_init(void) 178static int __init generic_ide_init(void)
179{ 179{
180 return ide_pci_register_driver(&driver); 180 return ide_pci_register_driver(&generic_pci_driver);
181} 181}
182 182
183static void __exit generic_ide_exit(void) 183static void __exit generic_ide_exit(void)
184{ 184{
185 pci_unregister_driver(&driver); 185 pci_unregister_driver(&generic_pci_driver);
186} 186}
187 187
188module_init(generic_ide_init); 188module_init(generic_ide_init);
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 644de29f8fe4..fb1a3aa57f07 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -166,7 +166,7 @@ static const struct pci_device_id hpt34x_pci_tbl[] = {
166}; 166};
167MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl); 167MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl);
168 168
169static struct pci_driver driver = { 169static struct pci_driver hpt34x_pci_driver = {
170 .name = "HPT34x_IDE", 170 .name = "HPT34x_IDE",
171 .id_table = hpt34x_pci_tbl, 171 .id_table = hpt34x_pci_tbl,
172 .probe = hpt34x_init_one, 172 .probe = hpt34x_init_one,
@@ -177,12 +177,12 @@ static struct pci_driver driver = {
177 177
178static int __init hpt34x_ide_init(void) 178static int __init hpt34x_ide_init(void)
179{ 179{
180 return ide_pci_register_driver(&driver); 180 return ide_pci_register_driver(&hpt34x_pci_driver);
181} 181}
182 182
183static void __exit hpt34x_ide_exit(void) 183static void __exit hpt34x_ide_exit(void)
184{ 184{
185 pci_unregister_driver(&driver); 185 pci_unregister_driver(&hpt34x_pci_driver);
186} 186}
187 187
188module_init(hpt34x_ide_init); 188module_init(hpt34x_ide_init);
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index a194022b6a61..9cf171cb9376 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -835,7 +835,7 @@ static int hpt370_dma_end(ide_drive_t *drive)
835 if (dma_stat & 0x01) 835 if (dma_stat & 0x01)
836 hpt370_irq_timeout(drive); 836 hpt370_irq_timeout(drive);
837 } 837 }
838 return __ide_dma_end(drive); 838 return ide_dma_end(drive);
839} 839}
840 840
841static void hpt370_dma_timeout(ide_drive_t *drive) 841static void hpt370_dma_timeout(ide_drive_t *drive)
@@ -863,9 +863,6 @@ static int hpt374_dma_test_irq(ide_drive_t *drive)
863 if (dma_stat & 4) 863 if (dma_stat & 4)
864 return 1; 864 return 1;
865 865
866 if (!drive->waiting_for_dma)
867 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
868 drive->name, __func__);
869 return 0; 866 return 0;
870} 867}
871 868
@@ -880,7 +877,7 @@ static int hpt374_dma_end(ide_drive_t *drive)
880 pci_read_config_byte(dev, mcr_addr, &mcr); 877 pci_read_config_byte(dev, mcr_addr, &mcr);
881 if (bwsr & mask) 878 if (bwsr & mask)
882 pci_write_config_byte(dev, mcr_addr, mcr | 0x30); 879 pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
883 return __ide_dma_end(drive); 880 return ide_dma_end(drive);
884} 881}
885 882
886/** 883/**
@@ -1456,7 +1453,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1456 .dma_setup = ide_dma_setup, 1453 .dma_setup = ide_dma_setup,
1457 .dma_exec_cmd = ide_dma_exec_cmd, 1454 .dma_exec_cmd = ide_dma_exec_cmd,
1458 .dma_start = ide_dma_start, 1455 .dma_start = ide_dma_start,
1459 .dma_end = __ide_dma_end, 1456 .dma_end = ide_dma_end,
1460 .dma_test_irq = ide_dma_test_irq, 1457 .dma_test_irq = ide_dma_test_irq,
1461 .dma_lost_irq = hpt366_dma_lost_irq, 1458 .dma_lost_irq = hpt366_dma_lost_irq,
1462 .dma_timeout = ide_dma_timeout, 1459 .dma_timeout = ide_dma_timeout,
@@ -1622,7 +1619,7 @@ static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
1622}; 1619};
1623MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl); 1620MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
1624 1621
1625static struct pci_driver driver = { 1622static struct pci_driver hpt366_pci_driver = {
1626 .name = "HPT366_IDE", 1623 .name = "HPT366_IDE",
1627 .id_table = hpt366_pci_tbl, 1624 .id_table = hpt366_pci_tbl,
1628 .probe = hpt366_init_one, 1625 .probe = hpt366_init_one,
@@ -1633,12 +1630,12 @@ static struct pci_driver driver = {
1633 1630
1634static int __init hpt366_ide_init(void) 1631static int __init hpt366_ide_init(void)
1635{ 1632{
1636 return ide_pci_register_driver(&driver); 1633 return ide_pci_register_driver(&hpt366_pci_driver);
1637} 1634}
1638 1635
1639static void __exit hpt366_ide_exit(void) 1636static void __exit hpt366_ide_exit(void)
1640{ 1637{
1641 pci_unregister_driver(&driver); 1638 pci_unregister_driver(&hpt366_pci_driver);
1642} 1639}
1643 1640
1644module_init(hpt366_ide_init); 1641module_init(hpt366_ide_init);
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 0954ccd08d6f..7c2feeb3c5ec 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -189,7 +189,7 @@ static const struct pci_device_id it8213_pci_tbl[] = {
189 189
190MODULE_DEVICE_TABLE(pci, it8213_pci_tbl); 190MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
191 191
192static struct pci_driver driver = { 192static struct pci_driver it8213_pci_driver = {
193 .name = "ITE8213_IDE", 193 .name = "ITE8213_IDE",
194 .id_table = it8213_pci_tbl, 194 .id_table = it8213_pci_tbl,
195 .probe = it8213_init_one, 195 .probe = it8213_init_one,
@@ -200,12 +200,12 @@ static struct pci_driver driver = {
200 200
201static int __init it8213_ide_init(void) 201static int __init it8213_ide_init(void)
202{ 202{
203 return ide_pci_register_driver(&driver); 203 return ide_pci_register_driver(&it8213_pci_driver);
204} 204}
205 205
206static void __exit it8213_ide_exit(void) 206static void __exit it8213_ide_exit(void)
207{ 207{
208 pci_unregister_driver(&driver); 208 pci_unregister_driver(&it8213_pci_driver);
209} 209}
210 210
211module_init(it8213_ide_init); 211module_init(it8213_ide_init);
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 46edd083b348..995e18bb3139 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -138,8 +138,7 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
138 struct pci_dev *dev = to_pci_dev(hwif->dev); 138 struct pci_dev *dev = to_pci_dev(hwif->dev);
139 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 139 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
140 int channel = hwif->channel; 140 int channel = hwif->channel;
141 int unit = drive->select.b.unit; 141 u8 unit = drive->dn & 1, conf;
142 u8 conf;
143 142
144 /* Program UDMA timing bits */ 143 /* Program UDMA timing bits */
145 if(itdev->clock_mode == ATA_66) 144 if(itdev->clock_mode == ATA_66)
@@ -168,13 +167,11 @@ static void it821x_clock_strategy(ide_drive_t *drive)
168 ide_hwif_t *hwif = drive->hwif; 167 ide_hwif_t *hwif = drive->hwif;
169 struct pci_dev *dev = to_pci_dev(hwif->dev); 168 struct pci_dev *dev = to_pci_dev(hwif->dev);
170 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 169 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
170 ide_drive_t *pair;
171 int clock, altclock, sel = 0;
172 u8 unit = drive->dn & 1, v;
171 173
172 u8 unit = drive->select.b.unit; 174 pair = &hwif->drives[1 - unit];
173 ide_drive_t *pair = &hwif->drives[1-unit];
174
175 int clock, altclock;
176 u8 v;
177 int sel = 0;
178 175
179 if(itdev->want[0][0] > itdev->want[1][0]) { 176 if(itdev->want[0][0] > itdev->want[1][0]) {
180 clock = itdev->want[0][1]; 177 clock = itdev->want[0][1];
@@ -240,16 +237,17 @@ static void it821x_clock_strategy(ide_drive_t *drive)
240 237
241static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio) 238static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
242{ 239{
243 ide_hwif_t *hwif = drive->hwif; 240 ide_hwif_t *hwif = drive->hwif;
244 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 241 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
245 int unit = drive->select.b.unit; 242 ide_drive_t *pair;
246 ide_drive_t *pair = &hwif->drives[1 - unit]; 243 u8 unit = drive->dn & 1, set_pio = pio;
247 u8 set_pio = pio;
248 244
249 /* Spec says 89 ref driver uses 88 */ 245 /* Spec says 89 ref driver uses 88 */
250 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 }; 246 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
251 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY }; 247 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
252 248
249 pair = &hwif->drives[1 - unit];
250
253 /* 251 /*
254 * Compute the best PIO mode we can for a given device. We must 252 * Compute the best PIO mode we can for a given device. We must
255 * pick a speed that does not cause problems with the other device 253 * pick a speed that does not cause problems with the other device
@@ -286,9 +284,7 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
286 ide_hwif_t *hwif = drive->hwif; 284 ide_hwif_t *hwif = drive->hwif;
287 struct pci_dev *dev = to_pci_dev(hwif->dev); 285 struct pci_dev *dev = to_pci_dev(hwif->dev);
288 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif); 286 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
289 int unit = drive->select.b.unit; 287 u8 unit = drive->dn & 1, channel = hwif->channel, conf;
290 int channel = hwif->channel;
291 u8 conf;
292 288
293 static u16 dma[] = { 0x8866, 0x3222, 0x3121 }; 289 static u16 dma[] = { 0x8866, 0x3222, 0x3121 };
294 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY }; 290 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
@@ -325,9 +321,7 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
325 ide_hwif_t *hwif = drive->hwif; 321 ide_hwif_t *hwif = drive->hwif;
326 struct pci_dev *dev = to_pci_dev(hwif->dev); 322 struct pci_dev *dev = to_pci_dev(hwif->dev);
327 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 323 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
328 int unit = drive->select.b.unit; 324 u8 unit = drive->dn & 1, channel = hwif->channel, conf;
329 int channel = hwif->channel;
330 u8 conf;
331 325
332 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 }; 326 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
333 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 }; 327 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
@@ -369,7 +363,8 @@ static void it821x_dma_start(ide_drive_t *drive)
369{ 363{
370 ide_hwif_t *hwif = drive->hwif; 364 ide_hwif_t *hwif = drive->hwif;
371 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 365 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
372 int unit = drive->select.b.unit; 366 u8 unit = drive->dn & 1;
367
373 if(itdev->mwdma[unit] != MWDMA_OFF) 368 if(itdev->mwdma[unit] != MWDMA_OFF)
374 it821x_program(drive, itdev->mwdma[unit]); 369 it821x_program(drive, itdev->mwdma[unit]);
375 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10) 370 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
@@ -389,9 +384,10 @@ static void it821x_dma_start(ide_drive_t *drive)
389static int it821x_dma_end(ide_drive_t *drive) 384static int it821x_dma_end(ide_drive_t *drive)
390{ 385{
391 ide_hwif_t *hwif = drive->hwif; 386 ide_hwif_t *hwif = drive->hwif;
392 int unit = drive->select.b.unit;
393 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 387 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
394 int ret = __ide_dma_end(drive); 388 int ret = ide_dma_end(drive);
389 u8 unit = drive->dn & 1;
390
395 if(itdev->mwdma[unit] != MWDMA_OFF) 391 if(itdev->mwdma[unit] != MWDMA_OFF)
396 it821x_program(drive, itdev->pio[unit]); 392 it821x_program(drive, itdev->pio[unit]);
397 return ret; 393 return ret;
@@ -454,7 +450,7 @@ static void it821x_quirkproc(ide_drive_t *drive)
454 * IRQ mask as we may well be in PIO (eg rev 0x10) 450 * IRQ mask as we may well be in PIO (eg rev 0x10)
455 * for now and we know unmasking is safe on this chipset. 451 * for now and we know unmasking is safe on this chipset.
456 */ 452 */
457 drive->unmask = 1; 453 drive->dev_flags |= IDE_DFLAG_UNMASK;
458 } else { 454 } else {
459 /* 455 /*
460 * Perform fixups on smart mode. We need to "lose" some 456 * Perform fixups on smart mode. We need to "lose" some
@@ -680,7 +676,7 @@ static const struct pci_device_id it821x_pci_tbl[] = {
680 676
681MODULE_DEVICE_TABLE(pci, it821x_pci_tbl); 677MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
682 678
683static struct pci_driver driver = { 679static struct pci_driver it821x_pci_driver = {
684 .name = "ITE821x IDE", 680 .name = "ITE821x IDE",
685 .id_table = it821x_pci_tbl, 681 .id_table = it821x_pci_tbl,
686 .probe = it821x_init_one, 682 .probe = it821x_init_one,
@@ -691,12 +687,12 @@ static struct pci_driver driver = {
691 687
692static int __init it821x_ide_init(void) 688static int __init it821x_ide_init(void)
693{ 689{
694 return ide_pci_register_driver(&driver); 690 return ide_pci_register_driver(&it821x_pci_driver);
695} 691}
696 692
697static void __exit it821x_ide_exit(void) 693static void __exit it821x_ide_exit(void)
698{ 694{
699 pci_unregister_driver(&driver); 695 pci_unregister_driver(&it821x_pci_driver);
700} 696}
701 697
702module_init(it821x_ide_init); 698module_init(it821x_ide_init);
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index acd647110648..9a68433cf46d 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -149,7 +149,7 @@ static struct pci_device_id jmicron_pci_tbl[] = {
149 149
150MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); 150MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
151 151
152static struct pci_driver driver = { 152static struct pci_driver jmicron_pci_driver = {
153 .name = "JMicron IDE", 153 .name = "JMicron IDE",
154 .id_table = jmicron_pci_tbl, 154 .id_table = jmicron_pci_tbl,
155 .probe = jmicron_init_one, 155 .probe = jmicron_init_one,
@@ -160,12 +160,12 @@ static struct pci_driver driver = {
160 160
161static int __init jmicron_ide_init(void) 161static int __init jmicron_ide_init(void)
162{ 162{
163 return ide_pci_register_driver(&driver); 163 return ide_pci_register_driver(&jmicron_pci_driver);
164} 164}
165 165
166static void __exit jmicron_ide_exit(void) 166static void __exit jmicron_ide_exit(void)
167{ 167{
168 pci_unregister_driver(&driver); 168 pci_unregister_driver(&jmicron_pci_driver);
169} 169}
170 170
171module_init(jmicron_ide_init); 171module_init(jmicron_ide_init);
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 53bd645736d9..13789060f407 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -137,7 +137,7 @@ static void __devinit superio_init_iops(struct hwif_s *hwif)
137static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 }; 137static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 };
138 138
139/* 139/*
140 * This routine either enables/disables (according to drive->present) 140 * This routine either enables/disables (according to IDE_DFLAG_PRESENT)
141 * the IRQ associated with the port (HWIF(drive)), 141 * the IRQ associated with the port (HWIF(drive)),
142 * and selects either PIO or DMA handshaking for the next I/O operation. 142 * and selects either PIO or DMA handshaking for the next I/O operation.
143 */ 143 */
@@ -153,11 +153,15 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
153 153
154 /* Adjust IRQ enable bit */ 154 /* Adjust IRQ enable bit */
155 bit = 1 << (8 + hwif->channel); 155 bit = 1 << (8 + hwif->channel);
156 new = drive->present ? (new & ~bit) : (new | bit); 156
157 if (drive->dev_flags & IDE_DFLAG_PRESENT)
158 new &= ~bit;
159 else
160 new |= bit;
157 161
158 /* Select PIO or DMA, DMA may only be selected for one drive/channel. */ 162 /* Select PIO or DMA, DMA may only be selected for one drive/channel. */
159 bit = 1 << (20 + drive->select.b.unit + (hwif->channel << 1)); 163 bit = 1 << (20 + (drive->dn & 1) + (hwif->channel << 1));
160 other = 1 << (20 + (1 - drive->select.b.unit) + (hwif->channel << 1)); 164 other = 1 << (20 + (1 - (drive->dn & 1)) + (hwif->channel << 1));
161 new = use_dma ? ((new & ~other) | bit) : (new & ~bit); 165 new = use_dma ? ((new & ~other) | bit) : (new & ~bit);
162 166
163 if (new != *old) { 167 if (new != *old) {
@@ -187,7 +191,8 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
187 191
188static void ns87415_selectproc (ide_drive_t *drive) 192static void ns87415_selectproc (ide_drive_t *drive)
189{ 193{
190 ns87415_prepare_drive (drive, drive->using_dma); 194 ns87415_prepare_drive(drive,
195 !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
191} 196}
192 197
193static int ns87415_dma_end(ide_drive_t *drive) 198static int ns87415_dma_end(ide_drive_t *drive)
@@ -334,7 +339,7 @@ static const struct pci_device_id ns87415_pci_tbl[] = {
334}; 339};
335MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl); 340MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl);
336 341
337static struct pci_driver driver = { 342static struct pci_driver ns87415_pci_driver = {
338 .name = "NS87415_IDE", 343 .name = "NS87415_IDE",
339 .id_table = ns87415_pci_tbl, 344 .id_table = ns87415_pci_tbl,
340 .probe = ns87415_init_one, 345 .probe = ns87415_init_one,
@@ -345,12 +350,12 @@ static struct pci_driver driver = {
345 350
346static int __init ns87415_ide_init(void) 351static int __init ns87415_ide_init(void)
347{ 352{
348 return ide_pci_register_driver(&driver); 353 return ide_pci_register_driver(&ns87415_pci_driver);
349} 354}
350 355
351static void __exit ns87415_ide_exit(void) 356static void __exit ns87415_ide_exit(void)
352{ 357{
353 pci_unregister_driver(&driver); 358 pci_unregister_driver(&ns87415_pci_driver);
354} 359}
355 360
356module_init(ns87415_ide_init); 361module_init(ns87415_ide_init);
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 3de11ddcf863..6048eda3cd61 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -179,7 +179,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
179 misc = addr_timings[clk][addr_pio]; 179 misc = addr_timings[clk][addr_pio];
180 180
181 /* select Index-0/1 for Register-A/B */ 181 /* select Index-0/1 for Register-A/B */
182 write_reg(drive->select.b.unit, MISC_REG); 182 write_reg(drive->dn & 1, MISC_REG);
183 /* set read cycle timings */ 183 /* set read cycle timings */
184 write_reg(tim, READ_REG); 184 write_reg(tim, READ_REG);
185 /* set write cycle timings */ 185 /* set write cycle timings */
@@ -220,7 +220,7 @@ static const struct pci_device_id opti621_pci_tbl[] = {
220}; 220};
221MODULE_DEVICE_TABLE(pci, opti621_pci_tbl); 221MODULE_DEVICE_TABLE(pci, opti621_pci_tbl);
222 222
223static struct pci_driver driver = { 223static struct pci_driver opti621_pci_driver = {
224 .name = "Opti621_IDE", 224 .name = "Opti621_IDE",
225 .id_table = opti621_pci_tbl, 225 .id_table = opti621_pci_tbl,
226 .probe = opti621_init_one, 226 .probe = opti621_init_one,
@@ -231,12 +231,12 @@ static struct pci_driver driver = {
231 231
232static int __init opti621_ide_init(void) 232static int __init opti621_ide_init(void)
233{ 233{
234 return ide_pci_register_driver(&driver); 234 return ide_pci_register_driver(&opti621_pci_driver);
235} 235}
236 236
237static void __exit opti621_ide_exit(void) 237static void __exit opti621_ide_exit(void)
238{ 238{
239 pci_unregister_driver(&driver); 239 pci_unregister_driver(&opti621_pci_driver);
240} 240}
241 241
242module_init(opti621_ide_init); 242module_init(opti621_ide_init);
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 9fc59962553b..211ae46e3e0c 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -561,7 +561,7 @@ static const struct pci_device_id pdc202new_pci_tbl[] = {
561}; 561};
562MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl); 562MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
563 563
564static struct pci_driver driver = { 564static struct pci_driver pdc202new_pci_driver = {
565 .name = "Promise_IDE", 565 .name = "Promise_IDE",
566 .id_table = pdc202new_pci_tbl, 566 .id_table = pdc202new_pci_tbl,
567 .probe = pdc202new_init_one, 567 .probe = pdc202new_init_one,
@@ -572,12 +572,12 @@ static struct pci_driver driver = {
572 572
573static int __init pdc202new_ide_init(void) 573static int __init pdc202new_ide_init(void)
574{ 574{
575 return ide_pci_register_driver(&driver); 575 return ide_pci_register_driver(&pdc202new_pci_driver);
576} 576}
577 577
578static void __exit pdc202new_ide_exit(void) 578static void __exit pdc202new_ide_exit(void)
579{ 579{
580 pci_unregister_driver(&driver); 580 pci_unregister_driver(&pdc202new_pci_driver);
581} 581}
582 582
583module_init(pdc202new_ide_init); 583module_init(pdc202new_ide_init);
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index cb6d2a00c514..799557c25eef 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -168,7 +168,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
168{ 168{
169 if (drive->current_speed > XFER_UDMA_2) 169 if (drive->current_speed > XFER_UDMA_2)
170 pdc_old_enable_66MHz_clock(drive->hwif); 170 pdc_old_enable_66MHz_clock(drive->hwif);
171 if (drive->media != ide_disk || drive->addressing == 1) { 171 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
172 struct request *rq = HWGROUP(drive)->rq; 172 struct request *rq = HWGROUP(drive)->rq;
173 ide_hwif_t *hwif = HWIF(drive); 173 ide_hwif_t *hwif = HWIF(drive);
174 unsigned long high_16 = hwif->extra_base - 16; 174 unsigned long high_16 = hwif->extra_base - 16;
@@ -188,7 +188,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
188 188
189static int pdc202xx_dma_end(ide_drive_t *drive) 189static int pdc202xx_dma_end(ide_drive_t *drive)
190{ 190{
191 if (drive->media != ide_disk || drive->addressing == 1) { 191 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
192 ide_hwif_t *hwif = HWIF(drive); 192 ide_hwif_t *hwif = HWIF(drive);
193 unsigned long high_16 = hwif->extra_base - 16; 193 unsigned long high_16 = hwif->extra_base - 16;
194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
@@ -200,7 +200,7 @@ static int pdc202xx_dma_end(ide_drive_t *drive)
200 } 200 }
201 if (drive->current_speed > XFER_UDMA_2) 201 if (drive->current_speed > XFER_UDMA_2)
202 pdc_old_disable_66MHz_clock(drive->hwif); 202 pdc_old_disable_66MHz_clock(drive->hwif);
203 return __ide_dma_end(drive); 203 return ide_dma_end(drive);
204} 204}
205 205
206static int pdc202xx_dma_test_irq(ide_drive_t *drive) 206static int pdc202xx_dma_test_irq(ide_drive_t *drive)
@@ -333,7 +333,7 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
333 .dma_setup = ide_dma_setup, 333 .dma_setup = ide_dma_setup,
334 .dma_exec_cmd = ide_dma_exec_cmd, 334 .dma_exec_cmd = ide_dma_exec_cmd,
335 .dma_start = ide_dma_start, 335 .dma_start = ide_dma_start,
336 .dma_end = __ide_dma_end, 336 .dma_end = ide_dma_end,
337 .dma_test_irq = pdc202xx_dma_test_irq, 337 .dma_test_irq = pdc202xx_dma_test_irq,
338 .dma_lost_irq = pdc202xx_dma_lost_irq, 338 .dma_lost_irq = pdc202xx_dma_lost_irq,
339 .dma_timeout = pdc202xx_dma_timeout, 339 .dma_timeout = pdc202xx_dma_timeout,
@@ -426,7 +426,7 @@ static const struct pci_device_id pdc202xx_pci_tbl[] = {
426}; 426};
427MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl); 427MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
428 428
429static struct pci_driver driver = { 429static struct pci_driver pdc202xx_pci_driver = {
430 .name = "Promise_Old_IDE", 430 .name = "Promise_Old_IDE",
431 .id_table = pdc202xx_pci_tbl, 431 .id_table = pdc202xx_pci_tbl,
432 .probe = pdc202xx_init_one, 432 .probe = pdc202xx_init_one,
@@ -437,12 +437,12 @@ static struct pci_driver driver = {
437 437
438static int __init pdc202xx_ide_init(void) 438static int __init pdc202xx_ide_init(void)
439{ 439{
440 return ide_pci_register_driver(&driver); 440 return ide_pci_register_driver(&pdc202xx_pci_driver);
441} 441}
442 442
443static void __exit pdc202xx_ide_exit(void) 443static void __exit pdc202xx_ide_exit(void)
444{ 444{
445 pci_unregister_driver(&driver); 445 pci_unregister_driver(&pdc202xx_pci_driver);
446} 446}
447 447
448module_init(pdc202xx_ide_init); 448module_init(pdc202xx_ide_init);
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index a06c03f8e295..d63f9fdca76b 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -215,17 +215,26 @@ static unsigned int init_chipset_ich(struct pci_dev *dev)
215} 215}
216 216
217/** 217/**
218 * piix_dma_clear_irq - clear BMDMA status 218 * ich_clear_irq - clear BMDMA status
219 * @drive: IDE drive to clear 219 * @drive: IDE drive
220 * 220 *
221 * Called from ide_intr() for PIO interrupts 221 * ICHx contollers set DMA INTR no matter DMA or PIO.
222 * to clear BMDMA status as needed by ICHx 222 * BMDMA status might need to be cleared even for
223 * PIO interrupts to prevent spurious/lost IRQ.
223 */ 224 */
224static void piix_dma_clear_irq(ide_drive_t *drive) 225static void ich_clear_irq(ide_drive_t *drive)
225{ 226{
226 ide_hwif_t *hwif = HWIF(drive); 227 ide_hwif_t *hwif = HWIF(drive);
227 u8 dma_stat; 228 u8 dma_stat;
228 229
230 /*
231 * ide_dma_end() needs BMDMA status for error checking.
232 * So, skip clearing BMDMA status here and leave it
233 * to ide_dma_end() if this is DMA interrupt.
234 */
235 if (drive->waiting_for_dma || hwif->dma_base == 0)
236 return;
237
229 /* clear the INTR & ERROR bits */ 238 /* clear the INTR & ERROR bits */
230 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 239 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
231 /* Should we force the bit as well ? */ 240 /* Should we force the bit as well ? */
@@ -249,6 +258,7 @@ static const struct ich_laptop ich_laptop[] = {
249 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 258 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
250 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 259 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
251 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 260 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
261 { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */
252 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */ 262 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */
253 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 263 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
254 /* end marker */ 264 /* end marker */
@@ -293,21 +303,19 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
293 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0; 303 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
294} 304}
295 305
296static void __devinit init_hwif_ich(ide_hwif_t *hwif)
297{
298 init_hwif_piix(hwif);
299
300 /* ICHx need to clear the BMDMA status for all interrupts */
301 if (hwif->dma_base)
302 hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
303}
304
305static const struct ide_port_ops piix_port_ops = { 306static const struct ide_port_ops piix_port_ops = {
306 .set_pio_mode = piix_set_pio_mode, 307 .set_pio_mode = piix_set_pio_mode,
307 .set_dma_mode = piix_set_dma_mode, 308 .set_dma_mode = piix_set_dma_mode,
308 .cable_detect = piix_cable_detect, 309 .cable_detect = piix_cable_detect,
309}; 310};
310 311
312static const struct ide_port_ops ich_port_ops = {
313 .set_pio_mode = piix_set_pio_mode,
314 .set_dma_mode = piix_set_dma_mode,
315 .clear_irq = ich_clear_irq,
316 .cable_detect = piix_cable_detect,
317};
318
311#ifndef CONFIG_IA64 319#ifndef CONFIG_IA64
312 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS 320 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS
313#else 321#else
@@ -331,9 +339,9 @@ static const struct ide_port_ops piix_port_ops = {
331 { \ 339 { \
332 .name = DRV_NAME, \ 340 .name = DRV_NAME, \
333 .init_chipset = init_chipset_ich, \ 341 .init_chipset = init_chipset_ich, \
334 .init_hwif = init_hwif_ich, \ 342 .init_hwif = init_hwif_piix, \
335 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 343 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
336 .port_ops = &piix_port_ops, \ 344 .port_ops = &ich_port_ops, \
337 .host_flags = IDE_HFLAGS_PIIX, \ 345 .host_flags = IDE_HFLAGS_PIIX, \
338 .pio_mask = ATA_PIO4, \ 346 .pio_mask = ATA_PIO4, \
339 .swdma_mask = ATA_SWDMA2_ONLY, \ 347 .swdma_mask = ATA_SWDMA2_ONLY, \
@@ -444,7 +452,7 @@ static const struct pci_device_id piix_pci_tbl[] = {
444}; 452};
445MODULE_DEVICE_TABLE(pci, piix_pci_tbl); 453MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
446 454
447static struct pci_driver driver = { 455static struct pci_driver piix_pci_driver = {
448 .name = "PIIX_IDE", 456 .name = "PIIX_IDE",
449 .id_table = piix_pci_tbl, 457 .id_table = piix_pci_tbl,
450 .probe = piix_init_one, 458 .probe = piix_init_one,
@@ -456,12 +464,12 @@ static struct pci_driver driver = {
456static int __init piix_ide_init(void) 464static int __init piix_ide_init(void)
457{ 465{
458 piix_check_450nx(); 466 piix_check_450nx();
459 return ide_pci_register_driver(&driver); 467 return ide_pci_register_driver(&piix_pci_driver);
460} 468}
461 469
462static void __exit piix_ide_exit(void) 470static void __exit piix_ide_exit(void)
463{ 471{
464 pci_unregister_driver(&driver); 472 pci_unregister_driver(&piix_pci_driver);
465} 473}
466 474
467module_init(piix_ide_init); 475module_init(piix_ide_init);
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index c117a068761b..7daf0135cbac 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -59,7 +59,7 @@ static const struct pci_device_id rz1000_pci_tbl[] = {
59}; 59};
60MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl); 60MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl);
61 61
62static struct pci_driver driver = { 62static struct pci_driver rz1000_pci_driver = {
63 .name = "RZ1000_IDE", 63 .name = "RZ1000_IDE",
64 .id_table = rz1000_pci_tbl, 64 .id_table = rz1000_pci_tbl,
65 .probe = rz1000_init_one, 65 .probe = rz1000_init_one,
@@ -68,12 +68,12 @@ static struct pci_driver driver = {
68 68
69static int __init rz1000_ide_init(void) 69static int __init rz1000_ide_init(void)
70{ 70{
71 return ide_pci_register_driver(&driver); 71 return ide_pci_register_driver(&rz1000_pci_driver);
72} 72}
73 73
74static void __exit rz1000_ide_exit(void) 74static void __exit rz1000_ide_exit(void)
75{ 75{
76 pci_unregister_driver(&driver); 76 pci_unregister_driver(&rz1000_pci_driver);
77} 77}
78 78
79module_init(rz1000_ide_init); 79module_init(rz1000_ide_init);
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index bdc1fed41260..f1a8758e3a99 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -126,7 +126,6 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
126{ 126{
127 ide_hwif_t *hwif = HWIF(drive); 127 ide_hwif_t *hwif = HWIF(drive);
128 struct pci_dev *dev = to_pci_dev(hwif->dev); 128 struct pci_dev *dev = to_pci_dev(hwif->dev);
129 int unit = drive->select.b.unit;
130 unsigned int reg, timings; 129 unsigned int reg, timings;
131 unsigned short pci_clock; 130 unsigned short pci_clock;
132 unsigned int basereg = hwif->channel ? 0x50 : 0x40; 131 unsigned int basereg = hwif->channel ? 0x50 : 0x40;
@@ -155,7 +154,7 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
155 else 154 else
156 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0]; 155 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0];
157 156
158 if (unit == 0) { /* are we configuring drive0? */ 157 if ((drive->dn & 1) == 0) {
159 pci_read_config_dword(dev, basereg + 4, &reg); 158 pci_read_config_dword(dev, basereg + 4, &reg);
160 timings |= reg & 0x80000000; /* preserve PIO format bit */ 159 timings |= reg & 0x80000000; /* preserve PIO format bit */
161 pci_write_config_dword(dev, basereg + 4, timings); 160 pci_write_config_dword(dev, basereg + 4, timings);
@@ -216,7 +215,8 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
216 if (mode != -1) { 215 if (mode != -1) {
217 printk("SC1200: %s: changing (U)DMA mode\n", drive->name); 216 printk("SC1200: %s: changing (U)DMA mode\n", drive->name);
218 ide_dma_off_quietly(drive); 217 ide_dma_off_quietly(drive);
219 if (ide_set_dma_mode(drive, mode) == 0 && drive->using_dma) 218 if (ide_set_dma_mode(drive, mode) == 0 &&
219 (drive->dev_flags & IDE_DFLAG_USING_DMA))
220 hwif->dma_ops->dma_host_set(drive, 1); 220 hwif->dma_ops->dma_host_set(drive, 1);
221 return; 221 return;
222 } 222 }
@@ -328,7 +328,7 @@ static const struct pci_device_id sc1200_pci_tbl[] = {
328}; 328};
329MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl); 329MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl);
330 330
331static struct pci_driver driver = { 331static struct pci_driver sc1200_pci_driver = {
332 .name = "SC1200_IDE", 332 .name = "SC1200_IDE",
333 .id_table = sc1200_pci_tbl, 333 .id_table = sc1200_pci_tbl,
334 .probe = sc1200_init_one, 334 .probe = sc1200_init_one,
@@ -341,12 +341,12 @@ static struct pci_driver driver = {
341 341
342static int __init sc1200_ide_init(void) 342static int __init sc1200_ide_init(void)
343{ 343{
344 return ide_pci_register_driver(&driver); 344 return ide_pci_register_driver(&sc1200_pci_driver);
345} 345}
346 346
347static void __exit sc1200_ide_exit(void) 347static void __exit sc1200_ide_exit(void)
348{ 348{
349 pci_unregister_driver(&driver); 349 pci_unregister_driver(&sc1200_pci_driver);
350} 350}
351 351
352module_init(sc1200_ide_init); 352module_init(sc1200_ide_init);
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index e92a874b31df..9ce1d8059921 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -291,7 +291,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
291static void scc_dma_host_set(ide_drive_t *drive, int on) 291static void scc_dma_host_set(ide_drive_t *drive, int on)
292{ 292{
293 ide_hwif_t *hwif = drive->hwif; 293 ide_hwif_t *hwif = drive->hwif;
294 u8 unit = (drive->select.b.unit & 0x01); 294 u8 unit = drive->dn & 1;
295 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4); 295 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4);
296 296
297 if (on) 297 if (on)
@@ -353,7 +353,6 @@ static void scc_dma_start(ide_drive_t *drive)
353 353
354 /* start DMA */ 354 /* start DMA */
355 scc_ide_outb(dma_cmd | 1, hwif->dma_base); 355 scc_ide_outb(dma_cmd | 1, hwif->dma_base);
356 hwif->dma = 1;
357 wmb(); 356 wmb();
358} 357}
359 358
@@ -374,7 +373,6 @@ static int __scc_dma_end(ide_drive_t *drive)
374 /* purge DMA mappings */ 373 /* purge DMA mappings */
375 ide_destroy_dmatable(drive); 374 ide_destroy_dmatable(drive);
376 /* verify good DMA status */ 375 /* verify good DMA status */
377 hwif->dma = 0;
378 wmb(); 376 wmb();
379 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; 377 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
380} 378}
@@ -511,9 +509,6 @@ static int scc_dma_test_irq(ide_drive_t *drive)
511 if (int_stat & INTSTS_IOIRQS) 509 if (int_stat & INTSTS_IOIRQS)
512 return 1; 510 return 1;
513 511
514 if (!drive->waiting_for_dma)
515 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
516 drive->name, __func__);
517 return 0; 512 return 0;
518} 513}
519 514
@@ -710,7 +705,7 @@ static void scc_tf_load(ide_drive_t *drive, ide_task_t *task)
710 scc_ide_outb(tf->lbah, io_ports->lbah_addr); 705 scc_ide_outb(tf->lbah, io_ports->lbah_addr);
711 706
712 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 707 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
713 scc_ide_outb((tf->device & HIHI) | drive->select.all, 708 scc_ide_outb((tf->device & HIHI) | drive->select,
714 io_ports->device_addr); 709 io_ports->device_addr);
715} 710}
716 711
@@ -826,6 +821,12 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
826 init_mmio_iops_scc(hwif); 821 init_mmio_iops_scc(hwif);
827} 822}
828 823
824static int __devinit scc_init_dma(ide_hwif_t *hwif,
825 const struct ide_port_info *d)
826{
827 return ide_allocate_dma_engine(hwif);
828}
829
829static u8 scc_cable_detect(ide_hwif_t *hwif) 830static u8 scc_cable_detect(ide_hwif_t *hwif)
830{ 831{
831 return ATA_CBL_PATA80; 832 return ATA_CBL_PATA80;
@@ -890,6 +891,7 @@ static const struct ide_dma_ops scc_dma_ops = {
890 { \ 891 { \
891 .name = name_str, \ 892 .name = name_str, \
892 .init_iops = init_iops_scc, \ 893 .init_iops = init_iops_scc, \
894 .init_dma = scc_init_dma, \
893 .init_hwif = init_hwif_scc, \ 895 .init_hwif = init_hwif_scc, \
894 .tp_ops = &scc_tp_ops, \ 896 .tp_ops = &scc_tp_ops, \
895 .port_ops = &scc_port_ops, \ 897 .port_ops = &scc_port_ops, \
@@ -927,13 +929,6 @@ static void __devexit scc_remove(struct pci_dev *dev)
927{ 929{
928 struct scc_ports *ports = pci_get_drvdata(dev); 930 struct scc_ports *ports = pci_get_drvdata(dev);
929 struct ide_host *host = ports->host; 931 struct ide_host *host = ports->host;
930 ide_hwif_t *hwif = host->ports[0];
931
932 if (hwif->dmatable_cpu) {
933 pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
934 hwif->dmatable_cpu, hwif->dmatable_dma);
935 hwif->dmatable_cpu = NULL;
936 }
937 932
938 ide_host_remove(host); 933 ide_host_remove(host);
939 934
@@ -949,7 +944,7 @@ static const struct pci_device_id scc_pci_tbl[] = {
949}; 944};
950MODULE_DEVICE_TABLE(pci, scc_pci_tbl); 945MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
951 946
952static struct pci_driver driver = { 947static struct pci_driver scc_pci_driver = {
953 .name = "SCC IDE", 948 .name = "SCC IDE",
954 .id_table = scc_pci_tbl, 949 .id_table = scc_pci_tbl,
955 .probe = scc_init_one, 950 .probe = scc_init_one,
@@ -958,14 +953,14 @@ static struct pci_driver driver = {
958 953
959static int scc_ide_init(void) 954static int scc_ide_init(void)
960{ 955{
961 return ide_pci_register_driver(&driver); 956 return ide_pci_register_driver(&scc_pci_driver);
962} 957}
963 958
964module_init(scc_ide_init); 959module_init(scc_ide_init);
965/* -- No exit code? 960/* -- No exit code?
966static void scc_ide_exit(void) 961static void scc_ide_exit(void)
967{ 962{
968 ide_pci_unregister_driver(&driver); 963 ide_pci_unregister_driver(&scc_pci_driver);
969} 964}
970module_exit(scc_ide_exit); 965module_exit(scc_ide_exit);
971 */ 966 */
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 3dff2aea317e..437bc919dafd 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -153,7 +153,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
153 153
154 ide_hwif_t *hwif = HWIF(drive); 154 ide_hwif_t *hwif = HWIF(drive);
155 struct pci_dev *dev = to_pci_dev(hwif->dev); 155 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 u8 unit = (drive->select.b.unit & 0x01); 156 u8 unit = drive->dn & 1;
157 157
158 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; 158 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0;
159 159
@@ -443,7 +443,7 @@ static const struct pci_device_id svwks_pci_tbl[] = {
443}; 443};
444MODULE_DEVICE_TABLE(pci, svwks_pci_tbl); 444MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
445 445
446static struct pci_driver driver = { 446static struct pci_driver svwks_pci_driver = {
447 .name = "Serverworks_IDE", 447 .name = "Serverworks_IDE",
448 .id_table = svwks_pci_tbl, 448 .id_table = svwks_pci_tbl,
449 .probe = svwks_init_one, 449 .probe = svwks_init_one,
@@ -454,12 +454,12 @@ static struct pci_driver driver = {
454 454
455static int __init svwks_ide_init(void) 455static int __init svwks_ide_init(void)
456{ 456{
457 return ide_pci_register_driver(&driver); 457 return ide_pci_register_driver(&svwks_pci_driver);
458} 458}
459 459
460static void __exit svwks_ide_exit(void) 460static void __exit svwks_ide_exit(void)
461{ 461{
462 pci_unregister_driver(&driver); 462 pci_unregister_driver(&svwks_pci_driver);
463} 463}
464 464
465module_init(svwks_ide_init); 465module_init(svwks_ide_init);
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 1017fb4f6317..dd634541ce36 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (C) 2008 MontaVista Software, Inc.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License 6 * under the terms of version 2 of the GNU General Public License
@@ -150,7 +151,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
150 int count = 0; 151 int count = 0;
151 152
152 stat = sgiioc4_read_status(hwif); 153 stat = sgiioc4_read_status(hwif);
153 while ((stat & 0x80) && (count++ < 100)) { 154 while ((stat & ATA_BUSY) && (count++ < 100)) {
154 udelay(1); 155 udelay(1);
155 stat = sgiioc4_read_status(hwif); 156 stat = sgiioc4_read_status(hwif);
156 } 157 }
@@ -310,7 +311,7 @@ static u8 sgiioc4_read_status(ide_hwif_t *hwif)
310 u8 reg = (u8) readb((void __iomem *) port); 311 u8 reg = (u8) readb((void __iomem *) port);
311 312
312 if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */ 313 if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */
313 if (reg & 0x51) { /* Not busy...check for interrupt */ 314 if (!(reg & ATA_BUSY)) { /* Not busy... check for interrupt */
314 unsigned long other_ir = port - 0x110; 315 unsigned long other_ir = port - 0x110;
315 unsigned int intr_reg = (u32) readl((void __iomem *) other_ir); 316 unsigned int intr_reg = (u32) readl((void __iomem *) other_ir);
316 317
@@ -338,35 +339,31 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
338 if (dma_base == 0) 339 if (dma_base == 0)
339 return -1; 340 return -1;
340 341
341 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name, 342 printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name);
342 dma_base, dma_base + num_ports - 1);
343 343
344 if (!request_mem_region(dma_base, num_ports, hwif->name)) { 344 if (request_mem_region(dma_base, num_ports, hwif->name) == NULL) {
345 printk(KERN_ERR 345 printk(KERN_ERR "%s(%s) -- ERROR: addresses 0x%08lx to 0x%08lx "
346 "%s(%s) -- ERROR, Addresses 0x%p to 0x%p " 346 "already in use\n", __func__, hwif->name,
347 "ALREADY in use\n", 347 dma_base, dma_base + num_ports - 1);
348 __func__, hwif->name, (void *) dma_base,
349 (void *) dma_base + num_ports - 1);
350 return -1; 348 return -1;
351 } 349 }
352 350
353 virt_dma_base = ioremap(dma_base, num_ports); 351 virt_dma_base = ioremap(dma_base, num_ports);
354 if (virt_dma_base == NULL) { 352 if (virt_dma_base == NULL) {
355 printk(KERN_ERR 353 printk(KERN_ERR "%s(%s) -- ERROR: unable to map addresses "
356 "%s(%s) -- ERROR, Unable to map addresses 0x%lx to 0x%lx\n", 354 "0x%lx to 0x%lx\n", __func__, hwif->name,
357 __func__, hwif->name, dma_base, dma_base + num_ports - 1); 355 dma_base, dma_base + num_ports - 1);
358 goto dma_remap_failure; 356 goto dma_remap_failure;
359 } 357 }
360 hwif->dma_base = (unsigned long) virt_dma_base; 358 hwif->dma_base = (unsigned long) virt_dma_base;
361 359
362 hwif->dmatable_cpu = pci_alloc_consistent(dev, 360 hwif->sg_max_nents = IOC4_PRD_ENTRIES;
363 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
364 &hwif->dmatable_dma);
365 361
366 if (!hwif->dmatable_cpu) 362 hwif->prd_max_nents = IOC4_PRD_ENTRIES;
367 goto dma_pci_alloc_failure; 363 hwif->prd_ent_size = IOC4_PRD_BYTES;
368 364
369 hwif->sg_max_nents = IOC4_PRD_ENTRIES; 365 if (ide_allocate_dma_engine(hwif))
366 goto dma_pci_alloc_failure;
370 367
371 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE, 368 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
372 (dma_addr_t *)&hwif->extra_base); 369 (dma_addr_t *)&hwif->extra_base);
@@ -375,13 +372,11 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
375 return 0; 372 return 0;
376 } 373 }
377 374
378 pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, 375 ide_release_dma_engine(hwif);
379 hwif->dmatable_cpu, hwif->dmatable_dma); 376
380 printk(KERN_INFO 377 printk(KERN_ERR "%s(%s) -- ERROR: Unable to allocate DMA maps\n",
381 "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
382 __func__, hwif->name); 378 __func__, hwif->name);
383 printk(KERN_INFO 379 printk(KERN_INFO "%s: changing from DMA to PIO mode", hwif->name);
384 "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
385 380
386dma_pci_alloc_failure: 381dma_pci_alloc_failure:
387 iounmap(virt_dma_base); 382 iounmap(virt_dma_base);
@@ -617,14 +612,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
617 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET; 612 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET;
618 613
619 cmd_phys_base = bar0 + IOC4_CMD_OFFSET; 614 cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
620 if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, 615 if (request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
621 DRV_NAME)) { 616 DRV_NAME) == NULL) {
622 printk(KERN_ERR 617 printk(KERN_ERR "%s %s -- ERROR: addresses 0x%08lx to 0x%08lx "
623 "%s %s: -- ERROR, Addresses " 618 "already in use\n", DRV_NAME, pci_name(dev),
624 "0x%p to 0x%p ALREADY in use\n", 619 cmd_phys_base, cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
625 DRV_NAME, pci_name(dev), (void *)cmd_phys_base, 620 return -EBUSY;
626 (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
627 return -ENOMEM;
628 } 621 }
629 622
630 /* Initialize the IO registers */ 623 /* Initialize the IO registers */
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 174a873b4c64..eb4faf92c571 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -116,13 +116,14 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
116{ 116{
117 ide_hwif_t *hwif = HWIF(drive); 117 ide_hwif_t *hwif = HWIF(drive);
118 unsigned long base = (unsigned long)hwif->hwif_data; 118 unsigned long base = (unsigned long)hwif->hwif_data;
119 u8 unit = drive->dn & 1;
119 120
120 base += 0xA0 + r; 121 base += 0xA0 + r;
121 if (hwif->host_flags & IDE_HFLAG_MMIO) 122 if (hwif->host_flags & IDE_HFLAG_MMIO)
122 base += hwif->channel << 6; 123 base += hwif->channel << 6;
123 else 124 else
124 base += hwif->channel << 4; 125 base += hwif->channel << 4;
125 base |= drive->select.b.unit << drive->select.b.unit; 126 base |= unit << unit;
126 return base; 127 return base;
127} 128}
128 129
@@ -255,7 +256,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
255 u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84) 256 u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
256 : (mmio ? 0xB4 : 0x80); 257 : (mmio ? 0xB4 : 0x80);
257 u8 mode = 0; 258 u8 mode = 0;
258 u8 unit = drive->select.b.unit; 259 u8 unit = drive->dn & 1;
259 260
260 /* trim *taskfile* PIO to the slowest of the master/slave */ 261 /* trim *taskfile* PIO to the slowest of the master/slave */
261 if (pair) { 262 if (pair) {
@@ -301,9 +302,9 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
301 302
302 ide_hwif_t *hwif = HWIF(drive); 303 ide_hwif_t *hwif = HWIF(drive);
303 struct pci_dev *dev = to_pci_dev(hwif->dev); 304 struct pci_dev *dev = to_pci_dev(hwif->dev);
304 u16 ultra = 0, multi = 0;
305 u8 mode = 0, unit = drive->select.b.unit;
306 unsigned long base = (unsigned long)hwif->hwif_data; 305 unsigned long base = (unsigned long)hwif->hwif_data;
306 u16 ultra = 0, multi = 0;
307 u8 mode = 0, unit = drive->dn & 1;
307 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 308 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
308 u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84) 309 u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
309 : (mmio ? 0xB4 : 0x80); 310 : (mmio ? 0xB4 : 0x80);
@@ -712,7 +713,7 @@ static const struct ide_dma_ops sil_dma_ops = {
712 .dma_setup = ide_dma_setup, 713 .dma_setup = ide_dma_setup,
713 .dma_exec_cmd = ide_dma_exec_cmd, 714 .dma_exec_cmd = ide_dma_exec_cmd,
714 .dma_start = ide_dma_start, 715 .dma_start = ide_dma_start,
715 .dma_end = __ide_dma_end, 716 .dma_end = ide_dma_end,
716 .dma_test_irq = siimage_dma_test_irq, 717 .dma_test_irq = siimage_dma_test_irq,
717 .dma_timeout = ide_dma_timeout, 718 .dma_timeout = ide_dma_timeout,
718 .dma_lost_irq = ide_dma_lost_irq, 719 .dma_lost_irq = ide_dma_lost_irq,
@@ -829,7 +830,7 @@ static const struct pci_device_id siimage_pci_tbl[] = {
829}; 830};
830MODULE_DEVICE_TABLE(pci, siimage_pci_tbl); 831MODULE_DEVICE_TABLE(pci, siimage_pci_tbl);
831 832
832static struct pci_driver driver = { 833static struct pci_driver siimage_pci_driver = {
833 .name = "SiI_IDE", 834 .name = "SiI_IDE",
834 .id_table = siimage_pci_tbl, 835 .id_table = siimage_pci_tbl,
835 .probe = siimage_init_one, 836 .probe = siimage_init_one,
@@ -840,12 +841,12 @@ static struct pci_driver driver = {
840 841
841static int __init siimage_ide_init(void) 842static int __init siimage_ide_init(void)
842{ 843{
843 return ide_pci_register_driver(&driver); 844 return ide_pci_register_driver(&siimage_pci_driver);
844} 845}
845 846
846static void __exit siimage_ide_exit(void) 847static void __exit siimage_ide_exit(void)
847{ 848{
848 pci_unregister_driver(&driver); 849 pci_unregister_driver(&siimage_pci_driver);
849} 850}
850 851
851module_init(siimage_ide_init); 852module_init(siimage_ide_init);
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 734dd41f1f67..ad32e18c5ba3 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -605,7 +605,7 @@ static const struct pci_device_id sis5513_pci_tbl[] = {
605}; 605};
606MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl); 606MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
607 607
608static struct pci_driver driver = { 608static struct pci_driver sis5513_pci_driver = {
609 .name = "SIS_IDE", 609 .name = "SIS_IDE",
610 .id_table = sis5513_pci_tbl, 610 .id_table = sis5513_pci_tbl,
611 .probe = sis5513_init_one, 611 .probe = sis5513_init_one,
@@ -616,12 +616,12 @@ static struct pci_driver driver = {
616 616
617static int __init sis5513_ide_init(void) 617static int __init sis5513_ide_init(void)
618{ 618{
619 return ide_pci_register_driver(&driver); 619 return ide_pci_register_driver(&sis5513_pci_driver);
620} 620}
621 621
622static void __exit sis5513_ide_exit(void) 622static void __exit sis5513_ide_exit(void)
623{ 623{
624 pci_unregister_driver(&driver); 624 pci_unregister_driver(&sis5513_pci_driver);
625} 625}
626 626
627module_init(sis5513_ide_init); 627module_init(sis5513_ide_init);
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 37a6b7bdc040..84dc33602ff8 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -207,7 +207,7 @@ static int sl82c105_dma_end(ide_drive_t *drive)
207 207
208 DBG(("%s(drive:%s)\n", __func__, drive->name)); 208 DBG(("%s(drive:%s)\n", __func__, drive->name));
209 209
210 ret = __ide_dma_end(drive); 210 ret = ide_dma_end(drive);
211 211
212 pci_write_config_word(dev, reg, drive->drive_data); 212 pci_write_config_word(dev, reg, drive->drive_data);
213 213
@@ -345,7 +345,7 @@ static const struct pci_device_id sl82c105_pci_tbl[] = {
345}; 345};
346MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl); 346MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl);
347 347
348static struct pci_driver driver = { 348static struct pci_driver sl82c105_pci_driver = {
349 .name = "W82C105_IDE", 349 .name = "W82C105_IDE",
350 .id_table = sl82c105_pci_tbl, 350 .id_table = sl82c105_pci_tbl,
351 .probe = sl82c105_init_one, 351 .probe = sl82c105_init_one,
@@ -356,12 +356,12 @@ static struct pci_driver driver = {
356 356
357static int __init sl82c105_ide_init(void) 357static int __init sl82c105_ide_init(void)
358{ 358{
359 return ide_pci_register_driver(&driver); 359 return ide_pci_register_driver(&sl82c105_pci_driver);
360} 360}
361 361
362static void __exit sl82c105_ide_exit(void) 362static void __exit sl82c105_ide_exit(void)
363{ 363{
364 pci_unregister_driver(&driver); 364 pci_unregister_driver(&sl82c105_pci_driver);
365} 365}
366 366
367module_init(sl82c105_ide_init); 367module_init(sl82c105_ide_init);
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index a9551a13ac57..0f759e4ed779 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -154,7 +154,7 @@ static const struct pci_device_id slc90e66_pci_tbl[] = {
154}; 154};
155MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl); 155MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl);
156 156
157static struct pci_driver driver = { 157static struct pci_driver slc90e66_pci_driver = {
158 .name = "SLC90e66_IDE", 158 .name = "SLC90e66_IDE",
159 .id_table = slc90e66_pci_tbl, 159 .id_table = slc90e66_pci_tbl,
160 .probe = slc90e66_init_one, 160 .probe = slc90e66_init_one,
@@ -165,12 +165,12 @@ static struct pci_driver driver = {
165 165
166static int __init slc90e66_ide_init(void) 166static int __init slc90e66_ide_init(void)
167{ 167{
168 return ide_pci_register_driver(&driver); 168 return ide_pci_register_driver(&slc90e66_pci_driver);
169} 169}
170 170
171static void __exit slc90e66_ide_exit(void) 171static void __exit slc90e66_ide_exit(void)
172{ 172{
173 pci_unregister_driver(&driver); 173 pci_unregister_driver(&slc90e66_pci_driver);
174} 174}
175 175
176module_init(slc90e66_ide_init); 176module_init(slc90e66_ide_init);
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 927277c54ec9..93e2cce4b296 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -186,7 +186,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
186 .dma_setup = ide_dma_setup, 186 .dma_setup = ide_dma_setup,
187 .dma_exec_cmd = ide_dma_exec_cmd, 187 .dma_exec_cmd = ide_dma_exec_cmd,
188 .dma_start = tc86c001_dma_start, 188 .dma_start = tc86c001_dma_start,
189 .dma_end = __ide_dma_end, 189 .dma_end = ide_dma_end,
190 .dma_test_irq = ide_dma_test_irq, 190 .dma_test_irq = ide_dma_test_irq,
191 .dma_lost_irq = ide_dma_lost_irq, 191 .dma_lost_irq = ide_dma_lost_irq,
192 .dma_timeout = ide_dma_timeout, 192 .dma_timeout = ide_dma_timeout,
@@ -245,7 +245,7 @@ static const struct pci_device_id tc86c001_pci_tbl[] = {
245}; 245};
246MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl); 246MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl);
247 247
248static struct pci_driver driver = { 248static struct pci_driver tc86c001_pci_driver = {
249 .name = "TC86C001", 249 .name = "TC86C001",
250 .id_table = tc86c001_pci_tbl, 250 .id_table = tc86c001_pci_tbl,
251 .probe = tc86c001_init_one, 251 .probe = tc86c001_init_one,
@@ -254,12 +254,12 @@ static struct pci_driver driver = {
254 254
255static int __init tc86c001_ide_init(void) 255static int __init tc86c001_ide_init(void)
256{ 256{
257 return ide_pci_register_driver(&driver); 257 return ide_pci_register_driver(&tc86c001_pci_driver);
258} 258}
259 259
260static void __exit tc86c001_ide_exit(void) 260static void __exit tc86c001_ide_exit(void)
261{ 261{
262 pci_unregister_driver(&driver); 262 pci_unregister_driver(&tc86c001_pci_driver);
263} 263}
264 264
265module_init(tc86c001_ide_init); 265module_init(tc86c001_ide_init);
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index be8715dcee05..b6ff40336aa9 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -38,13 +38,12 @@ static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
38{ 38{
39 ide_hwif_t *hwif = HWIF(drive); 39 ide_hwif_t *hwif = HWIF(drive);
40 struct pci_dev *dev = to_pci_dev(hwif->dev); 40 struct pci_dev *dev = to_pci_dev(hwif->dev);
41 u8 channel_offset = hwif->channel ? 0x74 : 0x70;
42 u16 timing = 0;
43 u32 triflex_timings = 0; 41 u32 triflex_timings = 0;
44 u8 unit = (drive->select.b.unit & 0x01); 42 u16 timing = 0;
45 43 u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
44
46 pci_read_config_dword(dev, channel_offset, &triflex_timings); 45 pci_read_config_dword(dev, channel_offset, &triflex_timings);
47 46
48 switch(speed) { 47 switch(speed) {
49 case XFER_MW_DMA_2: 48 case XFER_MW_DMA_2:
50 timing = 0x0103; 49 timing = 0x0103;
@@ -114,7 +113,7 @@ static const struct pci_device_id triflex_pci_tbl[] = {
114}; 113};
115MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); 114MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
116 115
117static struct pci_driver driver = { 116static struct pci_driver triflex_pci_driver = {
118 .name = "TRIFLEX_IDE", 117 .name = "TRIFLEX_IDE",
119 .id_table = triflex_pci_tbl, 118 .id_table = triflex_pci_tbl,
120 .probe = triflex_init_one, 119 .probe = triflex_init_one,
@@ -125,12 +124,12 @@ static struct pci_driver driver = {
125 124
126static int __init triflex_ide_init(void) 125static int __init triflex_ide_init(void)
127{ 126{
128 return ide_pci_register_driver(&driver); 127 return ide_pci_register_driver(&triflex_pci_driver);
129} 128}
130 129
131static void __exit triflex_ide_exit(void) 130static void __exit triflex_ide_exit(void)
132{ 131{
133 pci_unregister_driver(&driver); 132 pci_unregister_driver(&triflex_pci_driver);
134} 133}
135 134
136module_init(triflex_ide_init); 135module_init(triflex_ide_init);
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 4dfbc6a68b5b..75ea61526566 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -161,7 +161,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
161 } 161 }
162 162
163 /* enable IRQ if not probing */ 163 /* enable IRQ if not probing */
164 if (drive->present) { 164 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
165 reg = inw(hwif->config_data + 3); 165 reg = inw(hwif->config_data + 3);
166 reg &= 0x13; 166 reg &= 0x13;
167 reg &= ~(1 << hwif->channel); 167 reg &= ~(1 << hwif->channel);
@@ -173,7 +173,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
173 173
174static void trm290_selectproc (ide_drive_t *drive) 174static void trm290_selectproc (ide_drive_t *drive)
175{ 175{
176 trm290_prepare_drive(drive, drive->using_dma); 176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
177} 177}
178 178
179static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command) 179static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command)
@@ -350,7 +350,7 @@ static const struct pci_device_id trm290_pci_tbl[] = {
350}; 350};
351MODULE_DEVICE_TABLE(pci, trm290_pci_tbl); 351MODULE_DEVICE_TABLE(pci, trm290_pci_tbl);
352 352
353static struct pci_driver driver = { 353static struct pci_driver trm290_pci_driver = {
354 .name = "TRM290_IDE", 354 .name = "TRM290_IDE",
355 .id_table = trm290_pci_tbl, 355 .id_table = trm290_pci_tbl,
356 .probe = trm290_init_one, 356 .probe = trm290_init_one,
@@ -359,12 +359,12 @@ static struct pci_driver driver = {
359 359
360static int __init trm290_ide_init(void) 360static int __init trm290_ide_init(void)
361{ 361{
362 return ide_pci_register_driver(&driver); 362 return ide_pci_register_driver(&trm290_pci_driver);
363} 363}
364 364
365static void __exit trm290_ide_exit(void) 365static void __exit trm290_ide_exit(void)
366{ 366{
367 pci_unregister_driver(&driver); 367 pci_unregister_driver(&trm290_pci_driver);
368} 368}
369 369
370module_init(trm290_ide_init); 370module_init(trm290_ide_init);
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index acacdaab69c2..2a812d3207e9 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -487,7 +487,7 @@ static const struct pci_device_id via_pci_tbl[] = {
487}; 487};
488MODULE_DEVICE_TABLE(pci, via_pci_tbl); 488MODULE_DEVICE_TABLE(pci, via_pci_tbl);
489 489
490static struct pci_driver driver = { 490static struct pci_driver via_pci_driver = {
491 .name = "VIA_IDE", 491 .name = "VIA_IDE",
492 .id_table = via_pci_tbl, 492 .id_table = via_pci_tbl,
493 .probe = via_init_one, 493 .probe = via_init_one,
@@ -498,12 +498,12 @@ static struct pci_driver driver = {
498 498
499static int __init via_ide_init(void) 499static int __init via_ide_init(void)
500{ 500{
501 return ide_pci_register_driver(&driver); 501 return ide_pci_register_driver(&via_pci_driver);
502} 502}
503 503
504static void __exit via_ide_exit(void) 504static void __exit via_ide_exit(void)
505{ 505{
506 pci_unregister_driver(&driver); 506 pci_unregister_driver(&via_pci_driver);
507} 507}
508 508
509module_init(via_ide_init); 509module_init(via_ide_init);
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index c3432da78d52..2e19d6298536 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -430,10 +430,7 @@ pmac_ide_selectproc(ide_drive_t *drive)
430 pmac_ide_hwif_t *pmif = 430 pmac_ide_hwif_t *pmif =
431 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 431 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
432 432
433 if (pmif == NULL) 433 if (drive->dn & 1)
434 return;
435
436 if (drive->select.b.unit & 0x01)
437 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG)); 434 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
438 else 435 else
439 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG)); 436 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
@@ -452,10 +449,7 @@ pmac_ide_kauai_selectproc(ide_drive_t *drive)
452 pmac_ide_hwif_t *pmif = 449 pmac_ide_hwif_t *pmif =
453 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 450 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
454 451
455 if (pmif == NULL) 452 if (drive->dn & 1) {
456 return;
457
458 if (drive->select.b.unit & 0x01) {
459 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG)); 453 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
460 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG)); 454 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
461 } else { 455 } else {
@@ -475,9 +469,6 @@ pmac_ide_do_update_timings(ide_drive_t *drive)
475 pmac_ide_hwif_t *pmif = 469 pmac_ide_hwif_t *pmif =
476 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 470 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
477 471
478 if (pmif == NULL)
479 return;
480
481 if (pmif->kind == controller_sh_ata6 || 472 if (pmif->kind == controller_sh_ata6 ||
482 pmif->kind == controller_un_ata6 || 473 pmif->kind == controller_un_ata6 ||
483 pmif->kind == controller_k2_ata6) 474 pmif->kind == controller_k2_ata6)
@@ -524,11 +515,8 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
524 unsigned accessTime, recTime; 515 unsigned accessTime, recTime;
525 unsigned int cycle_time; 516 unsigned int cycle_time;
526 517
527 if (pmif == NULL)
528 return;
529
530 /* which drive is it ? */ 518 /* which drive is it ? */
531 timings = &pmif->timings[drive->select.b.unit & 0x01]; 519 timings = &pmif->timings[drive->dn & 1];
532 t = *timings; 520 t = *timings;
533 521
534 cycle_time = ide_pio_cycle_time(drive, pio); 522 cycle_time = ide_pio_cycle_time(drive, pio);
@@ -805,9 +793,9 @@ static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
805 ide_hwif_t *hwif = drive->hwif; 793 ide_hwif_t *hwif = drive->hwif;
806 pmac_ide_hwif_t *pmif = 794 pmac_ide_hwif_t *pmif =
807 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 795 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
808 int unit = (drive->select.b.unit & 0x01);
809 int ret = 0; 796 int ret = 0;
810 u32 *timings, *timings2, tl[2]; 797 u32 *timings, *timings2, tl[2];
798 u8 unit = drive->dn & 1;
811 799
812 timings = &pmif->timings[unit]; 800 timings = &pmif->timings[unit];
813 timings2 = &pmif->timings[unit+2]; 801 timings2 = &pmif->timings[unit+2];
@@ -966,11 +954,11 @@ static void pmac_ide_init_dev(ide_drive_t *drive)
966 if (pmif->mediabay) { 954 if (pmif->mediabay) {
967#ifdef CONFIG_PMAC_MEDIABAY 955#ifdef CONFIG_PMAC_MEDIABAY
968 if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) { 956 if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) {
969 drive->noprobe = 0; 957 drive->dev_flags &= ~IDE_DFLAG_NOPROBE;
970 return; 958 return;
971 } 959 }
972#endif 960#endif
973 drive->noprobe = 1; 961 drive->dev_flags |= IDE_DFLAG_NOPROBE;
974 } 962 }
975} 963}
976 964
@@ -1535,18 +1523,6 @@ use_pio_instead:
1535 return 0; /* revert to PIO for this request */ 1523 return 0; /* revert to PIO for this request */
1536} 1524}
1537 1525
1538/* Teardown mappings after DMA has completed. */
1539static void
1540pmac_ide_destroy_dmatable (ide_drive_t *drive)
1541{
1542 ide_hwif_t *hwif = drive->hwif;
1543
1544 if (hwif->sg_nents) {
1545 ide_destroy_dmatable(drive);
1546 hwif->sg_nents = 0;
1547 }
1548}
1549
1550/* 1526/*
1551 * Prepare a DMA transfer. We build the DMA table, adjust the timings for 1527 * Prepare a DMA transfer. We build the DMA table, adjust the timings for
1552 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion 1528 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
@@ -1558,12 +1534,7 @@ pmac_ide_dma_setup(ide_drive_t *drive)
1558 pmac_ide_hwif_t *pmif = 1534 pmac_ide_hwif_t *pmif =
1559 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1535 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1560 struct request *rq = HWGROUP(drive)->rq; 1536 struct request *rq = HWGROUP(drive)->rq;
1561 u8 unit = (drive->select.b.unit & 0x01); 1537 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
1562 u8 ata4;
1563
1564 if (pmif == NULL)
1565 return 1;
1566 ata4 = (pmif->kind == controller_kl_ata4);
1567 1538
1568 if (!pmac_ide_build_dmatable(drive, rq)) { 1539 if (!pmac_ide_build_dmatable(drive, rq)) {
1569 ide_map_sg(drive, rq); 1540 ide_map_sg(drive, rq);
@@ -1617,17 +1588,15 @@ pmac_ide_dma_end (ide_drive_t *drive)
1617 ide_hwif_t *hwif = drive->hwif; 1588 ide_hwif_t *hwif = drive->hwif;
1618 pmac_ide_hwif_t *pmif = 1589 pmac_ide_hwif_t *pmif =
1619 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1590 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1620 volatile struct dbdma_regs __iomem *dma; 1591 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1621 u32 dstat; 1592 u32 dstat;
1622
1623 if (pmif == NULL)
1624 return 0;
1625 dma = pmif->dma_regs;
1626 1593
1627 drive->waiting_for_dma = 0; 1594 drive->waiting_for_dma = 0;
1628 dstat = readl(&dma->status); 1595 dstat = readl(&dma->status);
1629 writel(((RUN|WAKE|DEAD) << 16), &dma->control); 1596 writel(((RUN|WAKE|DEAD) << 16), &dma->control);
1630 pmac_ide_destroy_dmatable(drive); 1597
1598 ide_destroy_dmatable(drive);
1599
1631 /* verify good dma status. we don't check for ACTIVE beeing 0. We should... 1600 /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
1632 * in theory, but with ATAPI decices doing buffer underruns, that would 1601 * in theory, but with ATAPI decices doing buffer underruns, that would
1633 * cause us to disable DMA, which isn't what we want 1602 * cause us to disable DMA, which isn't what we want
@@ -1647,13 +1616,9 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1647 ide_hwif_t *hwif = drive->hwif; 1616 ide_hwif_t *hwif = drive->hwif;
1648 pmac_ide_hwif_t *pmif = 1617 pmac_ide_hwif_t *pmif =
1649 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1618 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1650 volatile struct dbdma_regs __iomem *dma; 1619 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1651 unsigned long status, timeout; 1620 unsigned long status, timeout;
1652 1621
1653 if (pmif == NULL)
1654 return 0;
1655 dma = pmif->dma_regs;
1656
1657 /* We have to things to deal with here: 1622 /* We have to things to deal with here:
1658 * 1623 *
1659 * - The dbdma won't stop if the command was started 1624 * - The dbdma won't stop if the command was started
@@ -1672,9 +1637,6 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1672 status = readl(&dma->status); 1637 status = readl(&dma->status);
1673 if (!(status & ACTIVE)) 1638 if (!(status & ACTIVE))
1674 return 1; 1639 return 1;
1675 if (!drive->waiting_for_dma)
1676 printk(KERN_WARNING "ide%d, ide_dma_test_irq \
1677 called while not waiting\n", HWIF(drive)->index);
1678 1640
1679 /* If dbdma didn't execute the STOP command yet, the 1641 /* If dbdma didn't execute the STOP command yet, the
1680 * active bit is still set. We consider that we aren't 1642 * active bit is still set. We consider that we aren't
@@ -1709,14 +1671,9 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
1709 ide_hwif_t *hwif = drive->hwif; 1671 ide_hwif_t *hwif = drive->hwif;
1710 pmac_ide_hwif_t *pmif = 1672 pmac_ide_hwif_t *pmif =
1711 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1673 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1712 volatile struct dbdma_regs __iomem *dma; 1674 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1713 unsigned long status; 1675 unsigned long status = readl(&dma->status);
1714
1715 if (pmif == NULL)
1716 return;
1717 dma = pmif->dma_regs;
1718 1676
1719 status = readl(&dma->status);
1720 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status); 1677 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
1721} 1678}
1722 1679