aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ide/Kconfig33
-rw-r--r--drivers/ide/Makefile2
-rw-r--r--drivers/ide/alim15x3.c10
-rw-r--r--drivers/ide/at91_ide.c39
-rw-r--r--drivers/ide/au1xxx-ide.c26
-rw-r--r--drivers/ide/cmd64x.c6
-rw-r--r--drivers/ide/cs5530.c3
-rw-r--r--drivers/ide/cs5536.c1
-rw-r--r--drivers/ide/falconide.c4
-rw-r--r--drivers/ide/gayle.c12
-rw-r--r--drivers/ide/hpt366.c10
-rw-r--r--drivers/ide/ht6560b.c20
-rw-r--r--drivers/ide/icside.c8
-rw-r--r--drivers/ide/ide-atapi.c168
-rw-r--r--drivers/ide/ide-cd.c525
-rw-r--r--drivers/ide/ide-disk.c4
-rw-r--r--drivers/ide/ide-dma-sff.c17
-rw-r--r--drivers/ide/ide-dma.c118
-rw-r--r--drivers/ide/ide-eh.c14
-rw-r--r--drivers/ide/ide-floppy.c29
-rw-r--r--drivers/ide/ide-floppy_ioctl.c5
-rw-r--r--drivers/ide/ide-generic.c86
-rw-r--r--drivers/ide/ide-h8300.c34
-rw-r--r--drivers/ide/ide-io-std.c130
-rw-r--r--drivers/ide/ide-io.c27
-rw-r--r--drivers/ide/ide-iops.c41
-rw-r--r--drivers/ide/ide-pm.c5
-rw-r--r--drivers/ide/ide-probe.c31
-rw-r--r--drivers/ide/ide-tape.c36
-rw-r--r--drivers/ide/ide-taskfile.c96
-rw-r--r--drivers/ide/ide-timings.c12
-rw-r--r--drivers/ide/ide-xfer-mode.c15
-rw-r--r--drivers/ide/ide_arm.c53
-rw-r--r--drivers/ide/it821x.c3
-rw-r--r--drivers/ide/ns87415.c85
-rw-r--r--drivers/ide/pdc202xx_old.c10
-rw-r--r--drivers/ide/pmac.c101
-rw-r--r--drivers/ide/q40ide.c4
-rw-r--r--drivers/ide/qd65xx.c21
-rw-r--r--drivers/ide/sc1200.c7
-rw-r--r--drivers/ide/scc_pata.c56
-rw-r--r--drivers/ide/sgiioc4.c24
-rw-r--r--drivers/ide/siimage.c1
-rw-r--r--drivers/ide/sl82c105.c10
-rw-r--r--drivers/ide/tc86c001.c1
-rw-r--r--drivers/ide/trm290.c57
-rw-r--r--drivers/ide/tx4938ide.c41
-rw-r--r--drivers/ide/tx4939ide.c62
48 files changed, 810 insertions, 1293 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 640c99207242..cf06494bb744 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -222,7 +222,8 @@ comment "IDE chipset support/bugfixes"
222 222
223config IDE_GENERIC 223config IDE_GENERIC
224 tristate "generic/default IDE chipset support" 224 tristate "generic/default IDE chipset support"
225 depends on ALPHA || X86 || IA64 || M32R || MIPS 225 depends on ALPHA || X86 || IA64 || M32R || MIPS || ARCH_RPC || ARCH_SHARK
226 default ARM && (ARCH_RPC || ARCH_SHARK)
226 help 227 help
227 This is the generic IDE driver. This driver attaches to the 228 This is the generic IDE driver. This driver attaches to the
228 fixed legacy ports (e.g. on PCs 0x1f0/0x170, 0x1e8/0x168 and 229 fixed legacy ports (e.g. on PCs 0x1f0/0x170, 0x1e8/0x168 and
@@ -680,7 +681,7 @@ endif
680# TODO: BLK_DEV_IDEDMA_PCI -> BLK_DEV_IDEDMA_SFF 681# TODO: BLK_DEV_IDEDMA_PCI -> BLK_DEV_IDEDMA_SFF
681config BLK_DEV_IDE_PMAC 682config BLK_DEV_IDE_PMAC
682 tristate "PowerMac on-board IDE support" 683 tristate "PowerMac on-board IDE support"
683 depends on PPC_PMAC && IDE=y 684 depends on PPC_PMAC
684 select IDE_TIMINGS 685 select IDE_TIMINGS
685 select BLK_DEV_IDEDMA_PCI 686 select BLK_DEV_IDEDMA_PCI
686 help 687 help
@@ -731,11 +732,6 @@ config BLK_DEV_IDE_AT91
731 depends on ARM && ARCH_AT91 && !ARCH_AT91RM9200 && !ARCH_AT91X40 732 depends on ARM && ARCH_AT91 && !ARCH_AT91RM9200 && !ARCH_AT91X40
732 select IDE_TIMINGS 733 select IDE_TIMINGS
733 734
734config IDE_ARM
735 tristate "ARM IDE support"
736 depends on ARM && (ARCH_RPC || ARCH_SHARK)
737 default y
738
739config BLK_DEV_IDE_ICSIDE 735config BLK_DEV_IDE_ICSIDE
740 tristate "ICS IDE interface support" 736 tristate "ICS IDE interface support"
741 depends on ARM && ARCH_ACORN 737 depends on ARM && ARCH_ACORN
@@ -774,27 +770,20 @@ config BLK_DEV_GAYLE
774 This includes on-board IDE interfaces on some Amiga models (A600, 770 This includes on-board IDE interfaces on some Amiga models (A600,
775 A1200, A4000, and A4000T), and IDE interfaces on the Zorro expansion 771 A1200, A4000, and A4000T), and IDE interfaces on the Zorro expansion
776 bus (M-Tech E-Matrix 530 expansion card). 772 bus (M-Tech E-Matrix 530 expansion card).
777 Say Y if you have an Amiga with a Gayle IDE interface and want to use
778 IDE devices (hard disks, CD-ROM drives, etc.) that are connected to
779 it.
780 Note that you also have to enable Zorro bus support if you want to
781 use Gayle IDE interfaces on the Zorro expansion bus.
782 773
783config BLK_DEV_IDEDOUBLER 774 It also provides support for the so-called `IDE doublers' (made
784 bool "Amiga IDE Doubler support (EXPERIMENTAL)"
785 depends on BLK_DEV_GAYLE && EXPERIMENTAL
786 ---help---
787 This feature provides support for the so-called `IDE doublers' (made
788 by various manufacturers, e.g. Eyetech) that can be connected to 775 by various manufacturers, e.g. Eyetech) that can be connected to
789 the on-board IDE interface of some Amiga models. Using such an IDE 776 the on-board IDE interface of some Amiga models. Using such an IDE
790 doubler, you can connect up to four instead of two IDE devices to 777 doubler, you can connect up to four instead of two IDE devices to
791 the Amiga's on-board IDE interface. 778 the Amiga's on-board IDE interface. The feature is enabled at kernel
779 runtime using the "gayle.doubler" kernel boot parameter.
792 780
793 Note that the normal Amiga Gayle IDE driver may not work correctly 781 Say Y if you have an Amiga with a Gayle IDE interface and want to use
794 if you have an IDE doubler and don't enable this feature! 782 IDE devices (hard disks, CD-ROM drives, etc.) that are connected to
783 it.
795 784
796 Say Y if you have an IDE doubler. The feature is enabled at kernel 785 Note that you also have to enable Zorro bus support if you want to
797 runtime using the "gayle.doubler" kernel boot parameter. 786 use Gayle IDE interfaces on the Zorro expansion bus.
798 787
799config BLK_DEV_BUDDHA 788config BLK_DEV_BUDDHA
800 tristate "Buddha/Catweasel/X-Surf IDE interface support (EXPERIMENTAL)" 789 tristate "Buddha/Catweasel/X-Surf IDE interface support (EXPERIMENTAL)"
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 9b4bbe1cdc1a..81df925f0e8b 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -21,8 +21,6 @@ ide-core-$(CONFIG_IDE_LEGACY) += ide-legacy.o
21 21
22obj-$(CONFIG_IDE) += ide-core.o 22obj-$(CONFIG_IDE) += ide-core.o
23 23
24obj-$(CONFIG_IDE_ARM) += ide_arm.o
25
26obj-$(CONFIG_BLK_DEV_ALI14XX) += ali14xx.o 24obj-$(CONFIG_BLK_DEV_ALI14XX) += ali14xx.o
27obj-$(CONFIG_BLK_DEV_UMC8672) += umc8672.o 25obj-$(CONFIG_BLK_DEV_UMC8672) += umc8672.o
28obj-$(CONFIG_BLK_DEV_DTC2278) += dtc2278.o 26obj-$(CONFIG_BLK_DEV_DTC2278) += dtc2278.o
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
index d516168464fc..537da1cde16d 100644
--- a/drivers/ide/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -189,20 +189,20 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
189} 189}
190 190
191/** 191/**
192 * ali15x3_dma_setup - begin a DMA phase 192 * ali_dma_check - DMA check
193 * @drive: target device 193 * @drive: target device
194 * @cmd: command 194 * @cmd: command
195 * 195 *
196 * Returns 1 if the DMA cannot be performed, zero on success. 196 * Returns 1 if the DMA cannot be performed, zero on success.
197 */ 197 */
198 198
199static int ali15x3_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd) 199static int ali_dma_check(ide_drive_t *drive, struct ide_cmd *cmd)
200{ 200{
201 if (m5229_revision < 0xC2 && drive->media != ide_disk) { 201 if (m5229_revision < 0xC2 && drive->media != ide_disk) {
202 if (cmd->tf_flags & IDE_TFLAG_WRITE) 202 if (cmd->tf_flags & IDE_TFLAG_WRITE)
203 return 1; /* try PIO instead of DMA */ 203 return 1; /* try PIO instead of DMA */
204 } 204 }
205 return ide_dma_setup(drive, cmd); 205 return 0;
206} 206}
207 207
208/** 208/**
@@ -503,13 +503,13 @@ static const struct ide_port_ops ali_port_ops = {
503 503
504static const struct ide_dma_ops ali_dma_ops = { 504static const struct ide_dma_ops ali_dma_ops = {
505 .dma_host_set = ide_dma_host_set, 505 .dma_host_set = ide_dma_host_set,
506 .dma_setup = ali15x3_dma_setup, 506 .dma_setup = ide_dma_setup,
507 .dma_start = ide_dma_start, 507 .dma_start = ide_dma_start,
508 .dma_end = ide_dma_end, 508 .dma_end = ide_dma_end,
509 .dma_test_irq = ide_dma_test_irq, 509 .dma_test_irq = ide_dma_test_irq,
510 .dma_lost_irq = ide_dma_lost_irq, 510 .dma_lost_irq = ide_dma_lost_irq,
511 .dma_check = ali_dma_check,
511 .dma_timer_expiry = ide_dma_sff_timer_expiry, 512 .dma_timer_expiry = ide_dma_sff_timer_expiry,
512 .dma_timeout = ide_dma_timeout,
513 .dma_sff_read_status = ide_dma_sff_read_status, 513 .dma_sff_read_status = ide_dma_sff_read_status,
514}; 514};
515 515
diff --git a/drivers/ide/at91_ide.c b/drivers/ide/at91_ide.c
index 27547121daff..8eda552326e9 100644
--- a/drivers/ide/at91_ide.c
+++ b/drivers/ide/at91_ide.c
@@ -192,15 +192,9 @@ static void at91_ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
192 struct ide_taskfile *tf = &cmd->tf; 192 struct ide_taskfile *tf = &cmd->tf;
193 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; 193 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
194 194
195 if (cmd->tf_flags & IDE_FTFLAG_FLAGGED) 195 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
196 HIHI = 0xFF; 196 HIHI = 0xFF;
197 197
198 if (cmd->tf_flags & IDE_FTFLAG_OUT_DATA) {
199 u16 data = (tf->hob_data << 8) | tf->data;
200
201 at91_ide_output_data(drive, NULL, &data, 2);
202 }
203
204 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 198 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
205 ide_mm_outb(tf->hob_feature, io_ports->feature_addr); 199 ide_mm_outb(tf->hob_feature, io_ports->feature_addr);
206 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 200 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
@@ -233,19 +227,11 @@ static void at91_ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
233 struct ide_io_ports *io_ports = &hwif->io_ports; 227 struct ide_io_ports *io_ports = &hwif->io_ports;
234 struct ide_taskfile *tf = &cmd->tf; 228 struct ide_taskfile *tf = &cmd->tf;
235 229
236 if (cmd->tf_flags & IDE_FTFLAG_IN_DATA) {
237 u16 data;
238
239 at91_ide_input_data(drive, NULL, &data, 2);
240 tf->data = data & 0xff;
241 tf->hob_data = (data >> 8) & 0xff;
242 }
243
244 /* be sure we're looking at the low order bits */ 230 /* be sure we're looking at the low order bits */
245 ide_mm_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 231 ide_mm_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
246 232
247 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 233 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
248 tf->feature = ide_mm_inb(io_ports->feature_addr); 234 tf->error = ide_mm_inb(io_ports->feature_addr);
249 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 235 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
250 tf->nsect = ide_mm_inb(io_ports->nsect_addr); 236 tf->nsect = ide_mm_inb(io_ports->nsect_addr);
251 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 237 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -258,18 +244,18 @@ static void at91_ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
258 tf->device = ide_mm_inb(io_ports->device_addr); 244 tf->device = ide_mm_inb(io_ports->device_addr);
259 245
260 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 246 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
261 ide_mm_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 247 ide_mm_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
262 248
263 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 249 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
264 tf->hob_feature = ide_mm_inb(io_ports->feature_addr); 250 tf->hob_error = ide_mm_inb(io_ports->feature_addr);
265 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 251 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
266 tf->hob_nsect = ide_mm_inb(io_ports->nsect_addr); 252 tf->hob_nsect = ide_mm_inb(io_ports->nsect_addr);
267 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 253 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
268 tf->hob_lbal = ide_mm_inb(io_ports->lbal_addr); 254 tf->hob_lbal = ide_mm_inb(io_ports->lbal_addr);
269 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 255 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
270 tf->hob_lbam = ide_mm_inb(io_ports->lbam_addr); 256 tf->hob_lbam = ide_mm_inb(io_ports->lbam_addr);
271 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 257 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
272 tf->hob_lbah = ide_mm_inb(io_ports->lbah_addr); 258 tf->hob_lbah = ide_mm_inb(io_ports->lbah_addr);
273 } 259 }
274} 260}
275 261
@@ -295,8 +281,9 @@ static const struct ide_tp_ops at91_ide_tp_ops = {
295 .exec_command = ide_exec_command, 281 .exec_command = ide_exec_command,
296 .read_status = ide_read_status, 282 .read_status = ide_read_status,
297 .read_altstatus = ide_read_altstatus, 283 .read_altstatus = ide_read_altstatus,
298 .set_irq = ide_set_irq, 284 .write_devctl = ide_write_devctl,
299 285
286 .dev_select = ide_dev_select,
300 .tf_load = at91_ide_tf_load, 287 .tf_load = at91_ide_tf_load,
301 .tf_read = at91_ide_tf_read, 288 .tf_read = at91_ide_tf_read,
302 289
diff --git a/drivers/ide/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index d3a9d6c15328..46013644c965 100644
--- a/drivers/ide/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -50,7 +50,7 @@ static _auide_hwif auide_hwif;
50 50
51#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA) 51#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
52 52
53void auide_insw(unsigned long port, void *addr, u32 count) 53static inline void auide_insw(unsigned long port, void *addr, u32 count)
54{ 54{
55 _auide_hwif *ahwif = &auide_hwif; 55 _auide_hwif *ahwif = &auide_hwif;
56 chan_tab_t *ctp; 56 chan_tab_t *ctp;
@@ -68,7 +68,7 @@ void auide_insw(unsigned long port, void *addr, u32 count)
68 ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp); 68 ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
69} 69}
70 70
71void auide_outsw(unsigned long port, void *addr, u32 count) 71static inline void auide_outsw(unsigned long port, void *addr, u32 count)
72{ 72{
73 _auide_hwif *ahwif = &auide_hwif; 73 _auide_hwif *ahwif = &auide_hwif;
74 chan_tab_t *ctp; 74 chan_tab_t *ctp;
@@ -236,7 +236,7 @@ static int auide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
236 if (++count >= PRD_ENTRIES) { 236 if (++count >= PRD_ENTRIES) {
237 printk(KERN_WARNING "%s: DMA table too small\n", 237 printk(KERN_WARNING "%s: DMA table too small\n",
238 drive->name); 238 drive->name);
239 goto use_pio_instead; 239 return 0;
240 } 240 }
241 241
242 /* Lets enable intr for the last descriptor only */ 242 /* Lets enable intr for the last descriptor only */
@@ -272,16 +272,11 @@ static int auide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
272 if (count) 272 if (count)
273 return 1; 273 return 1;
274 274
275 use_pio_instead:
276 ide_destroy_dmatable(drive);
277
278 return 0; /* revert to PIO for this request */ 275 return 0; /* revert to PIO for this request */
279} 276}
280 277
281static int auide_dma_end(ide_drive_t *drive) 278static int auide_dma_end(ide_drive_t *drive)
282{ 279{
283 ide_destroy_dmatable(drive);
284
285 return 0; 280 return 0;
286} 281}
287 282
@@ -292,12 +287,9 @@ static void auide_dma_start(ide_drive_t *drive )
292 287
293static int auide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd) 288static int auide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
294{ 289{
295 if (auide_build_dmatable(drive, cmd) == 0) { 290 if (auide_build_dmatable(drive, cmd) == 0)
296 ide_map_sg(drive, cmd);
297 return 1; 291 return 1;
298 }
299 292
300 drive->waiting_for_dma = 1;
301 return 0; 293 return 0;
302} 294}
303 295
@@ -322,16 +314,11 @@ static void auide_dma_host_set(ide_drive_t *drive, int on)
322 314
323static void auide_ddma_tx_callback(int irq, void *param) 315static void auide_ddma_tx_callback(int irq, void *param)
324{ 316{
325 _auide_hwif *ahwif = (_auide_hwif*)param;
326 ahwif->drive->waiting_for_dma = 0;
327} 317}
328 318
329static void auide_ddma_rx_callback(int irq, void *param) 319static void auide_ddma_rx_callback(int irq, void *param)
330{ 320{
331 _auide_hwif *ahwif = (_auide_hwif*)param;
332 ahwif->drive->waiting_for_dma = 0;
333} 321}
334
335#endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */ 322#endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
336 323
337static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 devwidth, u32 flags) 324static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 devwidth, u32 flags)
@@ -353,7 +340,6 @@ static const struct ide_dma_ops au1xxx_dma_ops = {
353 .dma_end = auide_dma_end, 340 .dma_end = auide_dma_end,
354 .dma_test_irq = auide_dma_test_irq, 341 .dma_test_irq = auide_dma_test_irq,
355 .dma_lost_irq = ide_dma_lost_irq, 342 .dma_lost_irq = ide_dma_lost_irq,
356 .dma_timeout = ide_dma_timeout,
357}; 343};
358 344
359static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 345static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
@@ -481,9 +467,9 @@ static const struct ide_tp_ops au1xxx_tp_ops = {
481 .exec_command = ide_exec_command, 467 .exec_command = ide_exec_command,
482 .read_status = ide_read_status, 468 .read_status = ide_read_status,
483 .read_altstatus = ide_read_altstatus, 469 .read_altstatus = ide_read_altstatus,
470 .write_devctl = ide_write_devctl,
484 471
485 .set_irq = ide_set_irq, 472 .dev_select = ide_dev_select,
486
487 .tf_load = ide_tf_load, 473 .tf_load = ide_tf_load,
488 .tf_read = ide_tf_read, 474 .tf_read = ide_tf_read,
489 475
diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
index bf0e3f470824..80b777e4247b 100644
--- a/drivers/ide/cmd64x.c
+++ b/drivers/ide/cmd64x.c
@@ -318,7 +318,6 @@ static int cmd646_1_dma_end(ide_drive_t *drive)
318 ide_hwif_t *hwif = drive->hwif; 318 ide_hwif_t *hwif = drive->hwif;
319 u8 dma_stat = 0, dma_cmd = 0; 319 u8 dma_stat = 0, dma_cmd = 0;
320 320
321 drive->waiting_for_dma = 0;
322 /* get DMA status */ 321 /* get DMA status */
323 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 322 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
324 /* read DMA command state */ 323 /* read DMA command state */
@@ -327,8 +326,6 @@ static int cmd646_1_dma_end(ide_drive_t *drive)
327 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD); 326 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
328 /* clear the INTR & ERROR bits */ 327 /* clear the INTR & ERROR bits */
329 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS); 328 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
330 /* and free any DMA resources */
331 ide_destroy_dmatable(drive);
332 /* verify good DMA status */ 329 /* verify good DMA status */
333 return (dma_stat & 7) != 4; 330 return (dma_stat & 7) != 4;
334} 331}
@@ -384,7 +381,6 @@ static const struct ide_dma_ops cmd64x_dma_ops = {
384 .dma_test_irq = cmd64x_dma_test_irq, 381 .dma_test_irq = cmd64x_dma_test_irq,
385 .dma_lost_irq = ide_dma_lost_irq, 382 .dma_lost_irq = ide_dma_lost_irq,
386 .dma_timer_expiry = ide_dma_sff_timer_expiry, 383 .dma_timer_expiry = ide_dma_sff_timer_expiry,
387 .dma_timeout = ide_dma_timeout,
388 .dma_sff_read_status = ide_dma_sff_read_status, 384 .dma_sff_read_status = ide_dma_sff_read_status,
389}; 385};
390 386
@@ -396,7 +392,6 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
396 .dma_test_irq = ide_dma_test_irq, 392 .dma_test_irq = ide_dma_test_irq,
397 .dma_lost_irq = ide_dma_lost_irq, 393 .dma_lost_irq = ide_dma_lost_irq,
398 .dma_timer_expiry = ide_dma_sff_timer_expiry, 394 .dma_timer_expiry = ide_dma_sff_timer_expiry,
399 .dma_timeout = ide_dma_timeout,
400 .dma_sff_read_status = ide_dma_sff_read_status, 395 .dma_sff_read_status = ide_dma_sff_read_status,
401}; 396};
402 397
@@ -408,7 +403,6 @@ static const struct ide_dma_ops cmd648_dma_ops = {
408 .dma_test_irq = cmd648_dma_test_irq, 403 .dma_test_irq = cmd648_dma_test_irq,
409 .dma_lost_irq = ide_dma_lost_irq, 404 .dma_lost_irq = ide_dma_lost_irq,
410 .dma_timer_expiry = ide_dma_sff_timer_expiry, 405 .dma_timer_expiry = ide_dma_sff_timer_expiry,
411 .dma_timeout = ide_dma_timeout,
412 .dma_sff_read_status = ide_dma_sff_read_status, 406 .dma_sff_read_status = ide_dma_sff_read_status,
413}; 407};
414 408
diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
index 8e8b35a89901..40bf05eddf6e 100644
--- a/drivers/ide/cs5530.c
+++ b/drivers/ide/cs5530.c
@@ -92,8 +92,7 @@ static u8 cs5530_udma_filter(ide_drive_t *drive)
92 if ((mateid[ATA_ID_FIELD_VALID] & 4) && 92 if ((mateid[ATA_ID_FIELD_VALID] & 4) &&
93 (mateid[ATA_ID_UDMA_MODES] & 7)) 93 (mateid[ATA_ID_UDMA_MODES] & 7))
94 goto out; 94 goto out;
95 if ((mateid[ATA_ID_FIELD_VALID] & 2) && 95 if (mateid[ATA_ID_MWDMA_MODES] & 7)
96 (mateid[ATA_ID_MWDMA_MODES] & 7))
97 mask = 0; 96 mask = 0;
98 } 97 }
99out: 98out:
diff --git a/drivers/ide/cs5536.c b/drivers/ide/cs5536.c
index d5dcf4899607..353a35bbba63 100644
--- a/drivers/ide/cs5536.c
+++ b/drivers/ide/cs5536.c
@@ -236,7 +236,6 @@ static const struct ide_dma_ops cs5536_dma_ops = {
236 .dma_test_irq = ide_dma_test_irq, 236 .dma_test_irq = ide_dma_test_irq,
237 .dma_lost_irq = ide_dma_lost_irq, 237 .dma_lost_irq = ide_dma_lost_irq,
238 .dma_timer_expiry = ide_dma_sff_timer_expiry, 238 .dma_timer_expiry = ide_dma_sff_timer_expiry,
239 .dma_timeout = ide_dma_timeout,
240}; 239};
241 240
242static const struct ide_port_info cs5536_info = { 241static const struct ide_port_info cs5536_info = {
diff --git a/drivers/ide/falconide.c b/drivers/ide/falconide.c
index b368a5effc3a..afa2af9a362b 100644
--- a/drivers/ide/falconide.c
+++ b/drivers/ide/falconide.c
@@ -89,9 +89,9 @@ static const struct ide_tp_ops falconide_tp_ops = {
89 .exec_command = ide_exec_command, 89 .exec_command = ide_exec_command,
90 .read_status = ide_read_status, 90 .read_status = ide_read_status,
91 .read_altstatus = ide_read_altstatus, 91 .read_altstatus = ide_read_altstatus,
92 .write_devctl = ide_write_devctl,
92 93
93 .set_irq = ide_set_irq, 94 .dev_select = ide_dev_select,
94
95 .tf_load = ide_tf_load, 95 .tf_load = ide_tf_load,
96 .tf_read = ide_tf_read, 96 .tf_read = ide_tf_read,
97 97
diff --git a/drivers/ide/gayle.c b/drivers/ide/gayle.c
index dc778251cb05..c7119516c5a7 100644
--- a/drivers/ide/gayle.c
+++ b/drivers/ide/gayle.c
@@ -53,11 +53,6 @@
53 53
54#define GAYLE_NEXT_PORT 0x1000 54#define GAYLE_NEXT_PORT 0x1000
55 55
56#ifndef CONFIG_BLK_DEV_IDEDOUBLER
57#define GAYLE_NUM_HWIFS 1
58#define GAYLE_NUM_PROBE_HWIFS GAYLE_NUM_HWIFS
59#define GAYLE_HAS_CONTROL_REG 1
60#else /* CONFIG_BLK_DEV_IDEDOUBLER */
61#define GAYLE_NUM_HWIFS 2 56#define GAYLE_NUM_HWIFS 2
62#define GAYLE_NUM_PROBE_HWIFS (ide_doubler ? GAYLE_NUM_HWIFS : \ 57#define GAYLE_NUM_PROBE_HWIFS (ide_doubler ? GAYLE_NUM_HWIFS : \
63 GAYLE_NUM_HWIFS-1) 58 GAYLE_NUM_HWIFS-1)
@@ -66,8 +61,6 @@
66static int ide_doubler; 61static int ide_doubler;
67module_param_named(doubler, ide_doubler, bool, 0); 62module_param_named(doubler, ide_doubler, bool, 0);
68MODULE_PARM_DESC(doubler, "enable support for IDE doublers"); 63MODULE_PARM_DESC(doubler, "enable support for IDE doublers");
69#endif /* CONFIG_BLK_DEV_IDEDOUBLER */
70
71 64
72 /* 65 /*
73 * Check and acknowledge the interrupt status 66 * Check and acknowledge the interrupt status
@@ -151,10 +144,7 @@ static int __init gayle_init(void)
151found: 144found:
152 printk(KERN_INFO "ide: Gayle IDE controller (A%d style%s)\n", 145 printk(KERN_INFO "ide: Gayle IDE controller (A%d style%s)\n",
153 a4000 ? 4000 : 1200, 146 a4000 ? 4000 : 1200,
154#ifdef CONFIG_BLK_DEV_IDEDOUBLER 147 ide_doubler ? ", IDE doubler" : "");
155 ide_doubler ? ", IDE doubler" :
156#endif
157 "");
158 148
159 if (a4000) { 149 if (a4000) {
160 phys_base = GAYLE_BASE_4000; 150 phys_base = GAYLE_BASE_4000;
diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
index dbaf184ed9c5..a0eb87f59134 100644
--- a/drivers/ide/hpt366.c
+++ b/drivers/ide/hpt366.c
@@ -835,12 +835,6 @@ static int hpt370_dma_end(ide_drive_t *drive)
835 return ide_dma_end(drive); 835 return ide_dma_end(drive);
836} 836}
837 837
838static void hpt370_dma_timeout(ide_drive_t *drive)
839{
840 hpt370_irq_timeout(drive);
841 ide_dma_timeout(drive);
842}
843
844/* returns 1 if DMA IRQ issued, 0 otherwise */ 838/* returns 1 if DMA IRQ issued, 0 otherwise */
845static int hpt374_dma_test_irq(ide_drive_t *drive) 839static int hpt374_dma_test_irq(ide_drive_t *drive)
846{ 840{
@@ -1423,7 +1417,6 @@ static const struct ide_dma_ops hpt37x_dma_ops = {
1423 .dma_test_irq = hpt374_dma_test_irq, 1417 .dma_test_irq = hpt374_dma_test_irq,
1424 .dma_lost_irq = ide_dma_lost_irq, 1418 .dma_lost_irq = ide_dma_lost_irq,
1425 .dma_timer_expiry = ide_dma_sff_timer_expiry, 1419 .dma_timer_expiry = ide_dma_sff_timer_expiry,
1426 .dma_timeout = ide_dma_timeout,
1427 .dma_sff_read_status = ide_dma_sff_read_status, 1420 .dma_sff_read_status = ide_dma_sff_read_status,
1428}; 1421};
1429 1422
@@ -1435,7 +1428,7 @@ static const struct ide_dma_ops hpt370_dma_ops = {
1435 .dma_test_irq = ide_dma_test_irq, 1428 .dma_test_irq = ide_dma_test_irq,
1436 .dma_lost_irq = ide_dma_lost_irq, 1429 .dma_lost_irq = ide_dma_lost_irq,
1437 .dma_timer_expiry = ide_dma_sff_timer_expiry, 1430 .dma_timer_expiry = ide_dma_sff_timer_expiry,
1438 .dma_timeout = hpt370_dma_timeout, 1431 .dma_clear = hpt370_irq_timeout,
1439 .dma_sff_read_status = ide_dma_sff_read_status, 1432 .dma_sff_read_status = ide_dma_sff_read_status,
1440}; 1433};
1441 1434
@@ -1447,7 +1440,6 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1447 .dma_test_irq = ide_dma_test_irq, 1440 .dma_test_irq = ide_dma_test_irq,
1448 .dma_lost_irq = hpt366_dma_lost_irq, 1441 .dma_lost_irq = hpt366_dma_lost_irq,
1449 .dma_timer_expiry = ide_dma_sff_timer_expiry, 1442 .dma_timer_expiry = ide_dma_sff_timer_expiry,
1450 .dma_timeout = ide_dma_timeout,
1451 .dma_sff_read_status = ide_dma_sff_read_status, 1443 .dma_sff_read_status = ide_dma_sff_read_status,
1452}; 1444};
1453 1445
diff --git a/drivers/ide/ht6560b.c b/drivers/ide/ht6560b.c
index c7e5c2246b79..2fb0f2965009 100644
--- a/drivers/ide/ht6560b.c
+++ b/drivers/ide/ht6560b.c
@@ -103,7 +103,7 @@
103/* 103/*
104 * This routine is invoked from ide.c to prepare for access to a given drive. 104 * This routine is invoked from ide.c to prepare for access to a given drive.
105 */ 105 */
106static void ht6560b_selectproc (ide_drive_t *drive) 106static void ht6560b_dev_select(ide_drive_t *drive)
107{ 107{
108 ide_hwif_t *hwif = drive->hwif; 108 ide_hwif_t *hwif = drive->hwif;
109 unsigned long flags; 109 unsigned long flags;
@@ -143,6 +143,8 @@ static void ht6560b_selectproc (ide_drive_t *drive)
143#endif 143#endif
144 } 144 }
145 local_irq_restore(flags); 145 local_irq_restore(flags);
146
147 outb(drive->select | ATA_DEVICE_OBS, hwif->io_ports.device_addr);
146} 148}
147 149
148/* 150/*
@@ -305,15 +307,29 @@ static int probe_ht6560b;
305module_param_named(probe, probe_ht6560b, bool, 0); 307module_param_named(probe, probe_ht6560b, bool, 0);
306MODULE_PARM_DESC(probe, "probe for HT6560B chipset"); 308MODULE_PARM_DESC(probe, "probe for HT6560B chipset");
307 309
310static const struct ide_tp_ops ht6560b_tp_ops = {
311 .exec_command = ide_exec_command,
312 .read_status = ide_read_status,
313 .read_altstatus = ide_read_altstatus,
314 .write_devctl = ide_write_devctl,
315
316 .dev_select = ht6560b_dev_select,
317 .tf_load = ide_tf_load,
318 .tf_read = ide_tf_read,
319
320 .input_data = ide_input_data,
321 .output_data = ide_output_data,
322};
323
308static const struct ide_port_ops ht6560b_port_ops = { 324static const struct ide_port_ops ht6560b_port_ops = {
309 .init_dev = ht6560b_init_dev, 325 .init_dev = ht6560b_init_dev,
310 .set_pio_mode = ht6560b_set_pio_mode, 326 .set_pio_mode = ht6560b_set_pio_mode,
311 .selectproc = ht6560b_selectproc,
312}; 327};
313 328
314static const struct ide_port_info ht6560b_port_info __initdata = { 329static const struct ide_port_info ht6560b_port_info __initdata = {
315 .name = DRV_NAME, 330 .name = DRV_NAME,
316 .chipset = ide_ht6560b, 331 .chipset = ide_ht6560b,
332 .tp_ops = &ht6560b_tp_ops,
317 .port_ops = &ht6560b_port_ops, 333 .port_ops = &ht6560b_port_ops,
318 .host_flags = IDE_HFLAG_SERIALIZE | /* is this needed? */ 334 .host_flags = IDE_HFLAG_SERIALIZE | /* is this needed? */
319 IDE_HFLAG_NO_DMA | 335 IDE_HFLAG_NO_DMA |
diff --git a/drivers/ide/icside.c b/drivers/ide/icside.c
index 51ce404fe532..4e16ce68b063 100644
--- a/drivers/ide/icside.c
+++ b/drivers/ide/icside.c
@@ -287,13 +287,8 @@ static int icside_dma_end(ide_drive_t *drive)
287 ide_hwif_t *hwif = drive->hwif; 287 ide_hwif_t *hwif = drive->hwif;
288 struct expansion_card *ec = ECARD_DEV(hwif->dev); 288 struct expansion_card *ec = ECARD_DEV(hwif->dev);
289 289
290 drive->waiting_for_dma = 0;
291
292 disable_dma(ec->dma); 290 disable_dma(ec->dma);
293 291
294 /* Teardown mappings after DMA has completed. */
295 ide_destroy_dmatable(drive);
296
297 return get_dma_residue(ec->dma) != 0; 292 return get_dma_residue(ec->dma) != 0;
298} 293}
299 294
@@ -346,8 +341,6 @@ static int icside_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
346 set_dma_sg(ec->dma, hwif->sg_table, cmd->sg_nents); 341 set_dma_sg(ec->dma, hwif->sg_table, cmd->sg_nents);
347 set_dma_mode(ec->dma, dma_mode); 342 set_dma_mode(ec->dma, dma_mode);
348 343
349 drive->waiting_for_dma = 1;
350
351 return 0; 344 return 0;
352} 345}
353 346
@@ -377,7 +370,6 @@ static const struct ide_dma_ops icside_v6_dma_ops = {
377 .dma_start = icside_dma_start, 370 .dma_start = icside_dma_start,
378 .dma_end = icside_dma_end, 371 .dma_end = icside_dma_end,
379 .dma_test_irq = icside_dma_test_irq, 372 .dma_test_irq = icside_dma_test_irq,
380 .dma_timeout = ide_dma_timeout,
381 .dma_lost_irq = ide_dma_lost_irq, 373 .dma_lost_irq = ide_dma_lost_irq,
382}; 374};
383#else 375#else
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 2fb5d28a9be5..3e43b889dd64 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -6,6 +6,8 @@
6#include <linux/cdrom.h> 6#include <linux/cdrom.h>
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/ide.h> 8#include <linux/ide.h>
9#include <linux/scatterlist.h>
10
9#include <scsi/scsi.h> 11#include <scsi/scsi.h>
10 12
11#ifdef DEBUG 13#ifdef DEBUG
@@ -69,56 +71,6 @@ int ide_check_atapi_device(ide_drive_t *drive, const char *s)
69} 71}
70EXPORT_SYMBOL_GPL(ide_check_atapi_device); 72EXPORT_SYMBOL_GPL(ide_check_atapi_device);
71 73
72/* PIO data transfer routine using the scatter gather table. */
73int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
74 unsigned int bcount, int write)
75{
76 ide_hwif_t *hwif = drive->hwif;
77 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
78 xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data;
79 struct scatterlist *sg = pc->sg;
80 char *buf;
81 int count, done = 0;
82
83 while (bcount) {
84 count = min(sg->length - pc->b_count, bcount);
85
86 if (PageHighMem(sg_page(sg))) {
87 unsigned long flags;
88
89 local_irq_save(flags);
90 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
91 xf(drive, NULL, buf + pc->b_count, count);
92 kunmap_atomic(buf - sg->offset, KM_IRQ0);
93 local_irq_restore(flags);
94 } else {
95 buf = sg_virt(sg);
96 xf(drive, NULL, buf + pc->b_count, count);
97 }
98
99 bcount -= count;
100 pc->b_count += count;
101 done += count;
102
103 if (pc->b_count == sg->length) {
104 if (!--pc->sg_cnt)
105 break;
106 pc->sg = sg = sg_next(sg);
107 pc->b_count = 0;
108 }
109 }
110
111 if (bcount) {
112 printk(KERN_ERR "%s: %d leftover bytes, %s\n", drive->name,
113 bcount, write ? "padding with zeros"
114 : "discarding data");
115 ide_pad_transfer(drive, write, bcount);
116 }
117
118 return done;
119}
120EXPORT_SYMBOL_GPL(ide_io_buffers);
121
122void ide_init_pc(struct ide_atapi_pc *pc) 74void ide_init_pc(struct ide_atapi_pc *pc)
123{ 75{
124 memset(pc, 0, sizeof(*pc)); 76 memset(pc, 0, sizeof(*pc));
@@ -324,12 +276,14 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
324{ 276{
325 struct ide_atapi_pc *pc = drive->pc; 277 struct ide_atapi_pc *pc = drive->pc;
326 ide_hwif_t *hwif = drive->hwif; 278 ide_hwif_t *hwif = drive->hwif;
279 struct ide_cmd *cmd = &hwif->cmd;
327 struct request *rq = hwif->rq; 280 struct request *rq = hwif->rq;
328 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 281 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
329 xfer_func_t *xferfunc; 282 xfer_func_t *xferfunc;
330 unsigned int timeout, temp; 283 unsigned int timeout, done;
331 u16 bcount; 284 u16 bcount;
332 u8 stat, ireason, dsc = 0; 285 u8 stat, ireason, dsc = 0;
286 u8 write = !!(pc->flags & PC_FLAG_WRITING);
333 287
334 debug_log("Enter %s - interrupt handler\n", __func__); 288 debug_log("Enter %s - interrupt handler\n", __func__);
335 289
@@ -340,8 +294,13 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
340 stat = tp_ops->read_status(hwif); 294 stat = tp_ops->read_status(hwif);
341 295
342 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { 296 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
343 if (hwif->dma_ops->dma_end(drive) || 297 int rc;
344 (drive->media == ide_tape && (stat & ATA_ERR))) { 298
299 drive->waiting_for_dma = 0;
300 rc = hwif->dma_ops->dma_end(drive);
301 ide_dma_unmap_sg(drive, cmd);
302
303 if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) {
345 if (drive->media == ide_floppy) 304 if (drive->media == ide_floppy)
346 printk(KERN_ERR "%s: DMA %s error\n", 305 printk(KERN_ERR "%s: DMA %s error\n",
347 drive->name, rq_data_dir(pc->rq) 306 drive->name, rq_data_dir(pc->rq)
@@ -357,7 +316,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
357 316
358 /* No more interrupts */ 317 /* No more interrupts */
359 if ((stat & ATA_DRQ) == 0) { 318 if ((stat & ATA_DRQ) == 0) {
360 int uptodate; 319 int uptodate, error;
320 unsigned int done;
361 321
362 debug_log("Packet command completed, %d bytes transferred\n", 322 debug_log("Packet command completed, %d bytes transferred\n",
363 pc->xferred); 323 pc->xferred);
@@ -404,16 +364,24 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
404 364
405 if (blk_special_request(rq)) { 365 if (blk_special_request(rq)) {
406 rq->errors = 0; 366 rq->errors = 0;
407 ide_complete_rq(drive, 0, blk_rq_bytes(rq)); 367 done = blk_rq_bytes(rq);
368 error = 0;
408 } else { 369 } else {
370
409 if (blk_fs_request(rq) == 0 && uptodate <= 0) { 371 if (blk_fs_request(rq) == 0 && uptodate <= 0) {
410 if (rq->errors == 0) 372 if (rq->errors == 0)
411 rq->errors = -EIO; 373 rq->errors = -EIO;
412 } 374 }
413 ide_complete_rq(drive, uptodate ? 0 : -EIO, 375
414 ide_rq_bytes(rq)); 376 if (drive->media == ide_tape)
377 done = ide_rq_bytes(rq); /* FIXME */
378 else
379 done = blk_rq_bytes(rq);
380
381 error = uptodate ? 0 : -EIO;
415 } 382 }
416 383
384 ide_complete_rq(drive, error, done);
417 return ide_stopped; 385 return ide_stopped;
418 } 386 }
419 387
@@ -433,8 +401,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
433 return ide_do_reset(drive); 401 return ide_do_reset(drive);
434 } 402 }
435 403
436 if (((ireason & ATAPI_IO) == ATAPI_IO) == 404 if (((ireason & ATAPI_IO) == ATAPI_IO) == write) {
437 !!(pc->flags & PC_FLAG_WRITING)) {
438 /* Hopefully, we will never get here */ 405 /* Hopefully, we will never get here */
439 printk(KERN_ERR "%s: We wanted to %s, but the device wants us " 406 printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
440 "to %s!\n", drive->name, 407 "to %s!\n", drive->name,
@@ -443,45 +410,30 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
443 return ide_do_reset(drive); 410 return ide_do_reset(drive);
444 } 411 }
445 412
446 if (!(pc->flags & PC_FLAG_WRITING)) { 413 xferfunc = write ? tp_ops->output_data : tp_ops->input_data;
447 /* Reading - Check that we have enough space */ 414
448 temp = pc->xferred + bcount; 415 if (drive->media == ide_floppy && pc->buf == NULL) {
449 if (temp > pc->req_xfer) { 416 done = min_t(unsigned int, bcount, cmd->nleft);
450 if (temp > pc->buf_size) { 417 ide_pio_bytes(drive, cmd, write, done);
451 printk(KERN_ERR "%s: The device wants to send " 418 } else if (drive->media == ide_tape && pc->bh) {
452 "us more data than expected - " 419 done = drive->pc_io_buffers(drive, pc, bcount, write);
453 "discarding data\n", 420 } else {
454 drive->name); 421 done = min_t(unsigned int, bcount, pc->req_xfer - pc->xferred);
455 422 xferfunc(drive, NULL, pc->cur_pos, done);
456 ide_pad_transfer(drive, 0, bcount); 423 }
457 goto next_irq;
458 }
459 debug_log("The device wants to send us more data than "
460 "expected - allowing transfer\n");
461 }
462 xferfunc = tp_ops->input_data;
463 } else
464 xferfunc = tp_ops->output_data;
465
466 if ((drive->media == ide_floppy && !pc->buf) ||
467 (drive->media == ide_tape && pc->bh)) {
468 int done = drive->pc_io_buffers(drive, pc, bcount,
469 !!(pc->flags & PC_FLAG_WRITING));
470
471 /* FIXME: don't do partial completions */
472 if (drive->media == ide_floppy)
473 ide_complete_rq(drive, 0,
474 done ? done : ide_rq_bytes(rq));
475 } else
476 xferfunc(drive, NULL, pc->cur_pos, bcount);
477 424
478 /* Update the current position */ 425 /* Update the current position */
479 pc->xferred += bcount; 426 pc->xferred += done;
480 pc->cur_pos += bcount; 427 pc->cur_pos += done;
428
429 bcount -= done;
430
431 if (bcount)
432 ide_pad_transfer(drive, write, bcount);
433
434 debug_log("[cmd %x] transferred %d bytes, padded %d bytes\n",
435 rq->cmd[0], done, bcount);
481 436
482 debug_log("[cmd %x] transferred %d bytes on that intr.\n",
483 rq->cmd[0], bcount);
484next_irq:
485 /* And set the interrupt handler again */ 437 /* And set the interrupt handler again */
486 ide_set_handler(drive, ide_pc_intr, timeout); 438 ide_set_handler(drive, ide_pc_intr, timeout);
487 return ide_started; 439 return ide_started;
@@ -611,6 +563,10 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
611 : ide_pc_intr), 563 : ide_pc_intr),
612 timeout); 564 timeout);
613 565
566 /* Send the actual packet */
567 if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0)
568 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
569
614 /* Begin DMA, if necessary */ 570 /* Begin DMA, if necessary */
615 if (dev_is_idecd(drive)) { 571 if (dev_is_idecd(drive)) {
616 if (drive->dma) 572 if (drive->dma)
@@ -622,10 +578,6 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
622 } 578 }
623 } 579 }
624 580
625 /* Send the actual packet */
626 if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0)
627 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
628
629 return ide_started; 581 return ide_started;
630} 582}
631 583
@@ -633,7 +585,6 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
633{ 585{
634 struct ide_atapi_pc *pc; 586 struct ide_atapi_pc *pc;
635 ide_hwif_t *hwif = drive->hwif; 587 ide_hwif_t *hwif = drive->hwif;
636 const struct ide_dma_ops *dma_ops = hwif->dma_ops;
637 ide_expiry_t *expiry = NULL; 588 ide_expiry_t *expiry = NULL;
638 struct request *rq = hwif->rq; 589 struct request *rq = hwif->rq;
639 unsigned int timeout; 590 unsigned int timeout;
@@ -647,12 +598,8 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
647 expiry = ide_cd_expiry; 598 expiry = ide_cd_expiry;
648 timeout = ATAPI_WAIT_PC; 599 timeout = ATAPI_WAIT_PC;
649 600
650 if (drive->dma) { 601 if (drive->dma)
651 if (ide_build_sglist(drive, cmd)) 602 drive->dma = !ide_dma_prepare(drive, cmd);
652 drive->dma = !dma_ops->dma_setup(drive, cmd);
653 else
654 drive->dma = 0;
655 }
656 } else { 603 } else {
657 pc = drive->pc; 604 pc = drive->pc;
658 605
@@ -670,13 +617,8 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
670 ide_dma_off(drive); 617 ide_dma_off(drive);
671 } 618 }
672 619
673 if ((pc->flags & PC_FLAG_DMA_OK) && 620 if (pc->flags & PC_FLAG_DMA_OK)
674 (drive->dev_flags & IDE_DFLAG_USING_DMA)) { 621 drive->dma = !ide_dma_prepare(drive, cmd);
675 if (ide_build_sglist(drive, cmd))
676 drive->dma = !dma_ops->dma_setup(drive, cmd);
677 else
678 drive->dma = 0;
679 }
680 622
681 if (!drive->dma) 623 if (!drive->dma)
682 pc->flags &= ~PC_FLAG_DMA_OK; 624 pc->flags &= ~PC_FLAG_DMA_OK;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 3f630e4080d4..35729a47f797 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -4,7 +4,7 @@
4 * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov> 4 * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org> 5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de> 6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
7 * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz 7 * Copyright (C) 2005, 2007-2009 Bartlomiej Zolnierkiewicz
8 * 8 *
9 * May be copied or modified under the terms of the GNU General Public 9 * May be copied or modified under the terms of the GNU General Public
10 * License. See linux/COPYING for more information. 10 * License. See linux/COPYING for more information.
@@ -12,12 +12,9 @@
12 * See Documentation/cdrom/ide-cd for usage information. 12 * See Documentation/cdrom/ide-cd for usage information.
13 * 13 *
14 * Suggestions are welcome. Patches that work are more welcome though. ;-) 14 * Suggestions are welcome. Patches that work are more welcome though. ;-)
15 * For those wishing to work on this driver, please be sure you download 15 *
16 * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI 16 * Documentation:
17 * (SFF-8020i rev 2.6) standards. These documents can be obtained by 17 * Mt. Fuji (SFF8090 version 4) and ATAPI (SFF-8020i rev 2.6) standards.
18 * anonymous ftp from:
19 * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps
20 * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf
21 * 18 *
22 * For historical changelog please see: 19 * For historical changelog please see:
23 * Documentation/ide/ChangeLog.ide-cd.1994-2004 20 * Documentation/ide/ChangeLog.ide-cd.1994-2004
@@ -245,73 +242,34 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
245 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0); 242 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
246} 243}
247 244
248static void cdrom_end_request(ide_drive_t *drive, int uptodate) 245static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
249{ 246{
250 struct request *rq = drive->hwif->rq; 247 /*
251 int nsectors = rq->hard_cur_sectors; 248 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
252 249 * failed request
253 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, uptodate: 0x%x, nsectors: %d", 250 */
254 rq->cmd[0], uptodate, nsectors); 251 struct request *failed = (struct request *)rq->buffer;
255 252 struct cdrom_info *info = drive->driver_data;
256 if (blk_sense_request(rq) && uptodate) { 253 void *sense = &info->sense_data;
257 /*
258 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
259 * failed request
260 */
261 struct request *failed = (struct request *) rq->buffer;
262 struct cdrom_info *info = drive->driver_data;
263 void *sense = &info->sense_data;
264
265 if (failed) {
266 if (failed->sense) {
267 sense = failed->sense;
268 failed->sense_len = rq->sense_len;
269 }
270 cdrom_analyze_sense_data(drive, failed, sense);
271 /*
272 * now end the failed request
273 */
274 if (blk_fs_request(failed)) {
275 if (ide_end_rq(drive, failed, -EIO,
276 failed->hard_nr_sectors << 9))
277 BUG();
278 } else {
279 if (blk_end_request(failed, -EIO,
280 failed->data_len))
281 BUG();
282 }
283 } else
284 cdrom_analyze_sense_data(drive, NULL, sense);
285 }
286
287 if (!rq->current_nr_sectors && blk_fs_request(rq))
288 uptodate = 1;
289 /* make sure it's fully ended */
290 if (blk_pc_request(rq))
291 nsectors = (rq->data_len + 511) >> 9;
292 if (!nsectors)
293 nsectors = 1;
294
295 ide_debug_log(IDE_DBG_FUNC, "uptodate: 0x%x, nsectors: %d",
296 uptodate, nsectors);
297
298 if (blk_fs_request(rq) == 0 && uptodate <= 0 && rq->errors == 0)
299 rq->errors = -EIO;
300 254
301 ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9); 255 if (failed) {
302} 256 if (failed->sense) {
257 sense = failed->sense;
258 failed->sense_len = rq->sense_len;
259 }
260 cdrom_analyze_sense_data(drive, failed, sense);
303 261
304static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st) 262 if (ide_end_rq(drive, failed, -EIO, blk_rq_bytes(failed)))
305{ 263 BUG();
306 if (st & 0x80) 264 } else
307 return; 265 cdrom_analyze_sense_data(drive, NULL, sense);
308 ide_dump_status(drive, msg, st);
309} 266}
310 267
311/* 268/*
312 * Returns: 269 * Returns:
313 * 0: if the request should be continued. 270 * 0: if the request should be continued.
314 * 1: if the request was ended. 271 * 1: if the request will be going through error recovery.
272 * 2: if the request should be ended.
315 */ 273 */
316static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) 274static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
317{ 275{
@@ -332,12 +290,6 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
332 err = ide_read_error(drive); 290 err = ide_read_error(drive);
333 sense_key = err >> 4; 291 sense_key = err >> 4;
334 292
335 if (rq == NULL) {
336 printk(KERN_ERR PFX "%s: missing rq in %s\n",
337 drive->name, __func__);
338 return 1;
339 }
340
341 ide_debug_log(IDE_DBG_RQ, "stat: 0x%x, good_stat: 0x%x, cmd[0]: 0x%x, " 293 ide_debug_log(IDE_DBG_RQ, "stat: 0x%x, good_stat: 0x%x, cmd[0]: 0x%x, "
342 "rq->cmd_type: 0x%x, err: 0x%x", 294 "rq->cmd_type: 0x%x, err: 0x%x",
343 stat, good_stat, rq->cmd[0], rq->cmd_type, 295 stat, good_stat, rq->cmd[0], rq->cmd_type,
@@ -350,10 +302,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
350 * Just give up. 302 * Just give up.
351 */ 303 */
352 rq->cmd_flags |= REQ_FAILED; 304 rq->cmd_flags |= REQ_FAILED;
353 cdrom_end_request(drive, 0); 305 return 2;
354 ide_error(drive, "request sense failure", stat);
355 return 1;
356
357 } else if (blk_pc_request(rq) || rq->cmd_type == REQ_TYPE_ATA_PC) { 306 } else if (blk_pc_request(rq) || rq->cmd_type == REQ_TYPE_ATA_PC) {
358 /* All other functions, except for READ. */ 307 /* All other functions, except for READ. */
359 308
@@ -456,21 +405,19 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
456 * No point in retrying after an illegal request or data 405 * No point in retrying after an illegal request or data
457 * protect error. 406 * protect error.
458 */ 407 */
459 ide_dump_status_no_sense(drive, "command error", stat); 408 ide_dump_status(drive, "command error", stat);
460 do_end_request = 1; 409 do_end_request = 1;
461 } else if (sense_key == MEDIUM_ERROR) { 410 } else if (sense_key == MEDIUM_ERROR) {
462 /* 411 /*
463 * No point in re-trying a zillion times on a bad 412 * No point in re-trying a zillion times on a bad
464 * sector. If we got here the error is not correctable. 413 * sector. If we got here the error is not correctable.
465 */ 414 */
466 ide_dump_status_no_sense(drive, 415 ide_dump_status(drive, "media error (bad sector)",
467 "media error (bad sector)", 416 stat);
468 stat);
469 do_end_request = 1; 417 do_end_request = 1;
470 } else if (sense_key == BLANK_CHECK) { 418 } else if (sense_key == BLANK_CHECK) {
471 /* disk appears blank ?? */ 419 /* disk appears blank ?? */
472 ide_dump_status_no_sense(drive, "media error (blank)", 420 ide_dump_status(drive, "media error (blank)", stat);
473 stat);
474 do_end_request = 1; 421 do_end_request = 1;
475 } else if ((err & ~ATA_ABORTED) != 0) { 422 } else if ((err & ~ATA_ABORTED) != 0) {
476 /* go to the default handler for other errors */ 423 /* go to the default handler for other errors */
@@ -495,14 +442,12 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
495 */ 442 */
496 if (stat & ATA_ERR) 443 if (stat & ATA_ERR)
497 cdrom_queue_request_sense(drive, NULL, NULL); 444 cdrom_queue_request_sense(drive, NULL, NULL);
445 return 1;
498 } else { 446 } else {
499 blk_dump_rq_flags(rq, PFX "bad rq"); 447 blk_dump_rq_flags(rq, PFX "bad rq");
500 cdrom_end_request(drive, 0); 448 return 2;
501 } 449 }
502 450
503 /* retry, or handle the next request */
504 return 1;
505
506end_request: 451end_request:
507 if (stat & ATA_ERR) { 452 if (stat & ATA_ERR) {
508 struct request_queue *q = drive->queue; 453 struct request_queue *q = drive->queue;
@@ -515,10 +460,9 @@ end_request:
515 hwif->rq = NULL; 460 hwif->rq = NULL;
516 461
517 cdrom_queue_request_sense(drive, rq->sense, rq); 462 cdrom_queue_request_sense(drive, rq->sense, rq);
463 return 1;
518 } else 464 } else
519 cdrom_end_request(drive, 0); 465 return 2;
520
521 return 1;
522} 466}
523 467
524/* 468/*
@@ -562,101 +506,13 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
562 if (rq->cmd_type == REQ_TYPE_ATA_PC) 506 if (rq->cmd_type == REQ_TYPE_ATA_PC)
563 rq->cmd_flags |= REQ_FAILED; 507 rq->cmd_flags |= REQ_FAILED;
564 508
565 cdrom_end_request(drive, 0);
566 return -1; 509 return -1;
567} 510}
568 511
569/* 512static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd)
570 * Assume that the drive will always provide data in multiples of at least
571 * SECTOR_SIZE, as it gets hairy to keep track of the transfers otherwise.
572 */
573static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
574{ 513{
575 ide_debug_log(IDE_DBG_FUNC, "len: %d", len); 514 struct request *rq = cmd->rq;
576
577 if ((len % SECTOR_SIZE) == 0)
578 return 0;
579 515
580 printk(KERN_ERR PFX "%s: %s: Bad transfer size %d\n", drive->name,
581 __func__, len);
582
583 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES)
584 printk(KERN_ERR PFX "This drive is not supported by this "
585 "version of the driver\n");
586 else {
587 printk(KERN_ERR PFX "Trying to limit transfer sizes\n");
588 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES;
589 }
590
591 return 1;
592}
593
594static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
595 struct request *rq)
596{
597 ide_debug_log(IDE_DBG_RQ, "rq->cmd_flags: 0x%x", rq->cmd_flags);
598
599 if (rq_data_dir(rq) == READ) {
600 unsigned short sectors_per_frame =
601 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
602 int nskip = rq->sector & (sectors_per_frame - 1);
603
604 /*
605 * If the requested sector doesn't start on a frame boundary,
606 * we must adjust the start of the transfer so that it does,
607 * and remember to skip the first few sectors.
608 *
609 * If the rq->current_nr_sectors field is larger than the size
610 * of the buffer, it will mean that we're to skip a number of
611 * sectors equal to the amount by which rq->current_nr_sectors
612 * is larger than the buffer size.
613 */
614 if (nskip > 0) {
615 /* sanity check... */
616 if (rq->current_nr_sectors !=
617 bio_cur_sectors(rq->bio)) {
618 printk(KERN_ERR PFX "%s: %s: buffer botch (%u)\n",
619 drive->name, __func__,
620 rq->current_nr_sectors);
621 cdrom_end_request(drive, 0);
622 return ide_stopped;
623 }
624 rq->current_nr_sectors += nskip;
625 }
626 }
627
628 /* set up the command */
629 rq->timeout = ATAPI_WAIT_PC;
630
631 return ide_started;
632}
633
634/*
635 * Fix up a possibly partially-processed request so that we can start it over
636 * entirely, or even put it back on the request queue.
637 */
638static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
639{
640
641 ide_debug_log(IDE_DBG_FUNC, "enter");
642
643 if (rq->buffer != bio_data(rq->bio)) {
644 sector_t n =
645 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE;
646
647 rq->buffer = bio_data(rq->bio);
648 rq->nr_sectors += n;
649 rq->sector -= n;
650 }
651 rq->current_nr_sectors = bio_cur_sectors(rq->bio);
652 rq->hard_cur_sectors = rq->current_nr_sectors;
653 rq->hard_nr_sectors = rq->nr_sectors;
654 rq->hard_sector = rq->sector;
655 rq->q->prep_rq_fn(rq->q, rq);
656}
657
658static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
659{
660 ide_debug_log(IDE_DBG_FUNC, "rq->cmd[0]: 0x%x", rq->cmd[0]); 516 ide_debug_log(IDE_DBG_FUNC, "rq->cmd[0]: 0x%x", rq->cmd[0]);
661 517
662 /* 518 /*
@@ -664,11 +520,14 @@ static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
664 * and some drives don't send them. Sigh. 520 * and some drives don't send them. Sigh.
665 */ 521 */
666 if (rq->cmd[0] == GPCMD_REQUEST_SENSE && 522 if (rq->cmd[0] == GPCMD_REQUEST_SENSE &&
667 rq->data_len > 0 && rq->data_len <= 5) 523 cmd->nleft > 0 && cmd->nleft <= 5) {
668 while (rq->data_len > 0) { 524 unsigned int ofs = cmd->nbytes - cmd->nleft;
669 *(u8 *)rq->data++ = 0; 525
670 --rq->data_len; 526 while (cmd->nleft > 0) {
527 *((u8 *)rq->data + ofs++) = 0;
528 cmd->nleft--;
671 } 529 }
530 }
672} 531}
673 532
674int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, 533int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
@@ -748,24 +607,26 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
748 return (flags & REQ_FAILED) ? -EIO : 0; 607 return (flags & REQ_FAILED) ? -EIO : 0;
749} 608}
750 609
751/* 610static void ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
752 * Called from blk_end_request_callback() after the data of the request is
753 * completed and before the request itself is completed. By returning value '1',
754 * blk_end_request_callback() returns immediately without completing it.
755 */
756static int cdrom_newpc_intr_dummy_cb(struct request *rq)
757{ 611{
758 return 1; 612 unsigned int nr_bytes = cmd->nbytes - cmd->nleft;
613
614 if (cmd->tf_flags & IDE_TFLAG_WRITE)
615 nr_bytes -= cmd->last_xfer_len;
616
617 if (nr_bytes > 0)
618 ide_complete_rq(drive, 0, nr_bytes);
759} 619}
760 620
761static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 621static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
762{ 622{
763 ide_hwif_t *hwif = drive->hwif; 623 ide_hwif_t *hwif = drive->hwif;
624 struct ide_cmd *cmd = &hwif->cmd;
764 struct request *rq = hwif->rq; 625 struct request *rq = hwif->rq;
765 xfer_func_t *xferfunc;
766 ide_expiry_t *expiry = NULL; 626 ide_expiry_t *expiry = NULL;
767 int dma_error = 0, dma, stat, thislen, uptodate = 0; 627 int dma_error = 0, dma, stat, thislen, uptodate = 0;
768 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0; 628 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc, nsectors;
629 int sense = blk_sense_request(rq);
769 unsigned int timeout; 630 unsigned int timeout;
770 u16 len; 631 u16 len;
771 u8 ireason; 632 u8 ireason;
@@ -777,7 +638,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
777 dma = drive->dma; 638 dma = drive->dma;
778 if (dma) { 639 if (dma) {
779 drive->dma = 0; 640 drive->dma = 0;
641 drive->waiting_for_dma = 0;
780 dma_error = hwif->dma_ops->dma_end(drive); 642 dma_error = hwif->dma_ops->dma_end(drive);
643 ide_dma_unmap_sg(drive, cmd);
781 if (dma_error) { 644 if (dma_error) {
782 printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name, 645 printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name,
783 write ? "write" : "read"); 646 write ? "write" : "read");
@@ -785,27 +648,24 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
785 } 648 }
786 } 649 }
787 650
788 if (cdrom_decode_status(drive, 0, &stat)) 651 rc = cdrom_decode_status(drive, 0, &stat);
652 if (rc) {
653 if (rc == 2)
654 goto out_end;
789 return ide_stopped; 655 return ide_stopped;
656 }
790 657
791 /* using dma, transfer is complete now */ 658 /* using dma, transfer is complete now */
792 if (dma) { 659 if (dma) {
793 if (dma_error) 660 if (dma_error)
794 return ide_error(drive, "dma error", stat); 661 return ide_error(drive, "dma error", stat);
795 if (blk_fs_request(rq)) { 662 uptodate = 1;
796 ide_complete_rq(drive, 0, rq->nr_sectors 663 goto out_end;
797 ? (rq->nr_sectors << 9) : ide_rq_bytes(rq));
798 return ide_stopped;
799 } else if (rq->cmd_type == REQ_TYPE_ATA_PC && !rq->bio) {
800 ide_complete_rq(drive, 0, 512);
801 return ide_stopped;
802 }
803 goto end_request;
804 } 664 }
805 665
806 ide_read_bcount_and_ireason(drive, &len, &ireason); 666 ide_read_bcount_and_ireason(drive, &len, &ireason);
807 667
808 thislen = blk_fs_request(rq) ? len : rq->data_len; 668 thislen = blk_fs_request(rq) ? len : cmd->nleft;
809 if (thislen > len) 669 if (thislen > len)
810 thislen = len; 670 thislen = len;
811 671
@@ -820,60 +680,30 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
820 * Otherwise, complete the command normally. 680 * Otherwise, complete the command normally.
821 */ 681 */
822 uptodate = 1; 682 uptodate = 1;
823 if (rq->current_nr_sectors > 0) { 683 if (cmd->nleft > 0) {
824 printk(KERN_ERR PFX "%s: %s: data underrun " 684 printk(KERN_ERR PFX "%s: %s: data underrun "
825 "(%d blocks)\n", 685 "(%u bytes)\n", drive->name, __func__,
826 drive->name, __func__, 686 cmd->nleft);
827 rq->current_nr_sectors);
828 if (!write) 687 if (!write)
829 rq->cmd_flags |= REQ_FAILED; 688 rq->cmd_flags |= REQ_FAILED;
830 uptodate = 0; 689 uptodate = 0;
831 } 690 }
832 cdrom_end_request(drive, uptodate);
833 return ide_stopped;
834 } else if (!blk_pc_request(rq)) { 691 } else if (!blk_pc_request(rq)) {
835 ide_cd_request_sense_fixup(drive, rq); 692 ide_cd_request_sense_fixup(drive, cmd);
836 /* complain if we still have data left to transfer */ 693 /* complain if we still have data left to transfer */
837 uptodate = rq->data_len ? 0 : 1; 694 uptodate = cmd->nleft ? 0 : 1;
695 if (uptodate == 0)
696 rq->cmd_flags |= REQ_FAILED;
838 } 697 }
839 goto end_request; 698 goto out_end;
840 } 699 }
841 700
842 /* check which way to transfer data */ 701 /* check which way to transfer data */
843 if (ide_cd_check_ireason(drive, rq, len, ireason, write)) 702 rc = ide_cd_check_ireason(drive, rq, len, ireason, write);
844 return ide_stopped; 703 if (rc)
704 goto out_end;
845 705
846 if (blk_fs_request(rq)) { 706 cmd->last_xfer_len = 0;
847 if (write == 0) {
848 int nskip;
849
850 if (ide_cd_check_transfer_size(drive, len)) {
851 cdrom_end_request(drive, 0);
852 return ide_stopped;
853 }
854
855 /*
856 * First, figure out if we need to bit-bucket
857 * any of the leading sectors.
858 */
859 nskip = min_t(int, rq->current_nr_sectors
860 - bio_cur_sectors(rq->bio),
861 thislen >> 9);
862 if (nskip > 0) {
863 ide_pad_transfer(drive, write, nskip << 9);
864 rq->current_nr_sectors -= nskip;
865 thislen -= (nskip << 9);
866 }
867 }
868 }
869
870 if (ireason == 0) {
871 write = 1;
872 xferfunc = hwif->tp_ops->output_data;
873 } else {
874 write = 0;
875 xferfunc = hwif->tp_ops->input_data;
876 }
877 707
878 ide_debug_log(IDE_DBG_PC, "data transfer, rq->cmd_type: 0x%x, " 708 ide_debug_log(IDE_DBG_PC, "data transfer, rq->cmd_type: 0x%x, "
879 "ireason: 0x%x", 709 "ireason: 0x%x",
@@ -881,75 +711,31 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
881 711
882 /* transfer data */ 712 /* transfer data */
883 while (thislen > 0) { 713 while (thislen > 0) {
884 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; 714 int blen = min_t(int, thislen, cmd->nleft);
885 int blen = rq->data_len;
886
887 /* bio backed? */
888 if (rq->bio) {
889 if (blk_fs_request(rq)) {
890 ptr = rq->buffer;
891 blen = rq->current_nr_sectors << 9;
892 } else {
893 ptr = bio_data(rq->bio);
894 blen = bio_iovec(rq->bio)->bv_len;
895 }
896 }
897 715
898 if (!ptr) { 716 if (cmd->nleft == 0)
899 if (blk_fs_request(rq) && !write)
900 /*
901 * If the buffers are full, pipe the rest into
902 * oblivion.
903 */
904 ide_pad_transfer(drive, 0, thislen);
905 else {
906 printk(KERN_ERR PFX "%s: confused, missing data\n",
907 drive->name);
908 blk_dump_rq_flags(rq, rq_data_dir(rq)
909 ? "cdrom_newpc_intr, write"
910 : "cdrom_newpc_intr, read");
911 }
912 break; 717 break;
913 }
914
915 if (blen > thislen)
916 blen = thislen;
917 718
918 xferfunc(drive, NULL, ptr, blen); 719 ide_pio_bytes(drive, cmd, write, blen);
720 cmd->last_xfer_len += blen;
919 721
920 thislen -= blen; 722 thislen -= blen;
921 len -= blen; 723 len -= blen;
922 724
923 if (blk_fs_request(rq)) { 725 if (sense && write == 0)
924 rq->buffer += blen;
925 rq->nr_sectors -= (blen >> 9);
926 rq->current_nr_sectors -= (blen >> 9);
927 rq->sector += (blen >> 9);
928
929 if (rq->current_nr_sectors == 0 && rq->nr_sectors)
930 cdrom_end_request(drive, 1);
931 } else {
932 rq->data_len -= blen;
933
934 /*
935 * The request can't be completed until DRQ is cleared.
936 * So complete the data, but don't complete the request
937 * using the dummy function for the callback feature
938 * of blk_end_request_callback().
939 */
940 if (rq->bio)
941 blk_end_request_callback(rq, 0, blen,
942 cdrom_newpc_intr_dummy_cb);
943 else
944 rq->data += blen;
945 }
946 if (!write && blk_sense_request(rq))
947 rq->sense_len += blen; 726 rq->sense_len += blen;
948 } 727 }
949 728
950 /* pad, if necessary */ 729 /* pad, if necessary */
951 if (!blk_fs_request(rq) && len > 0) 730 if (len > 0) {
952 ide_pad_transfer(drive, write, len); 731 if (blk_fs_request(rq) == 0 || write == 0)
732 ide_pad_transfer(drive, write, len);
733 else {
734 printk(KERN_ERR PFX "%s: confused, missing data\n",
735 drive->name);
736 blk_dump_rq_flags(rq, "cdrom_newpc_intr");
737 }
738 }
953 739
954 if (blk_pc_request(rq)) { 740 if (blk_pc_request(rq)) {
955 timeout = rq->timeout; 741 timeout = rq->timeout;
@@ -963,21 +749,50 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
963 ide_set_handler(drive, cdrom_newpc_intr, timeout); 749 ide_set_handler(drive, cdrom_newpc_intr, timeout);
964 return ide_started; 750 return ide_started;
965 751
966end_request: 752out_end:
967 if (blk_pc_request(rq)) { 753 if (blk_pc_request(rq) && rc == 0) {
968 unsigned int dlen = rq->data_len; 754 unsigned int dlen = rq->data_len;
969 755
970 if (dma) 756 rq->data_len = 0;
971 rq->data_len = 0;
972 757
973 if (blk_end_request(rq, 0, dlen)) 758 if (blk_end_request(rq, 0, dlen))
974 BUG(); 759 BUG();
975 760
976 hwif->rq = NULL; 761 hwif->rq = NULL;
977 } else { 762 } else {
978 if (!uptodate) 763 if (sense && uptodate)
979 rq->cmd_flags |= REQ_FAILED; 764 ide_cd_complete_failed_rq(drive, rq);
980 cdrom_end_request(drive, uptodate); 765
766 if (blk_fs_request(rq)) {
767 if (cmd->nleft == 0)
768 uptodate = 1;
769 } else {
770 if (uptodate <= 0 && rq->errors == 0)
771 rq->errors = -EIO;
772 }
773
774 if (uptodate == 0)
775 ide_cd_error_cmd(drive, cmd);
776
777 /* make sure it's fully ended */
778 if (blk_pc_request(rq))
779 nsectors = (rq->data_len + 511) >> 9;
780 else
781 nsectors = rq->hard_nr_sectors;
782
783 if (nsectors == 0)
784 nsectors = 1;
785
786 if (blk_fs_request(rq) == 0) {
787 rq->data_len -= (cmd->nbytes - cmd->nleft);
788 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
789 rq->data_len += cmd->last_xfer_len;
790 }
791
792 ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9);
793
794 if (sense && rc == 2)
795 ide_error(drive, "request sense failure", stat);
981 } 796 }
982 return ide_stopped; 797 return ide_stopped;
983} 798}
@@ -985,42 +800,40 @@ end_request:
985static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) 800static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
986{ 801{
987 struct cdrom_info *cd = drive->driver_data; 802 struct cdrom_info *cd = drive->driver_data;
803 struct request_queue *q = drive->queue;
988 int write = rq_data_dir(rq) == WRITE; 804 int write = rq_data_dir(rq) == WRITE;
989 unsigned short sectors_per_frame = 805 unsigned short sectors_per_frame =
990 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 806 queue_hardsect_size(q) >> SECTOR_BITS;
991 807
992 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, write: 0x%x, " 808 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, "
993 "secs_per_frame: %u", 809 "secs_per_frame: %u",
994 rq->cmd[0], write, sectors_per_frame); 810 rq->cmd[0], rq->cmd_flags, sectors_per_frame);
995 811
996 if (write) { 812 if (write) {
997 /* disk has become write protected */ 813 /* disk has become write protected */
998 if (get_disk_ro(cd->disk)) { 814 if (get_disk_ro(cd->disk))
999 cdrom_end_request(drive, 0);
1000 return ide_stopped; 815 return ide_stopped;
1001 }
1002 } else { 816 } else {
1003 /* 817 /*
1004 * We may be retrying this request after an error. Fix up any 818 * We may be retrying this request after an error. Fix up any
1005 * weirdness which might be present in the request packet. 819 * weirdness which might be present in the request packet.
1006 */ 820 */
1007 ide_cd_restore_request(drive, rq); 821 q->prep_rq_fn(q, rq);
1008 } 822 }
1009 823
1010 /* use DMA, if possible / writes *must* be hardware frame aligned */ 824 /* fs requests *must* be hardware frame aligned */
1011 if ((rq->nr_sectors & (sectors_per_frame - 1)) || 825 if ((rq->nr_sectors & (sectors_per_frame - 1)) ||
1012 (rq->sector & (sectors_per_frame - 1))) { 826 (rq->sector & (sectors_per_frame - 1)))
1013 if (write) { 827 return ide_stopped;
1014 cdrom_end_request(drive, 0); 828
1015 return ide_stopped; 829 /* use DMA, if possible */
1016 } 830 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1017 drive->dma = 0;
1018 } else
1019 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1020 831
1021 if (write) 832 if (write)
1022 cd->devinfo.media_written = 1; 833 cd->devinfo.media_written = 1;
1023 834
835 rq->timeout = ATAPI_WAIT_PC;
836
1024 return ide_started; 837 return ide_started;
1025} 838}
1026 839
@@ -1068,6 +881,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1068 sector_t block) 881 sector_t block)
1069{ 882{
1070 struct ide_cmd cmd; 883 struct ide_cmd cmd;
884 int uptodate = 0, nsectors;
1071 885
1072 ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, block: %llu", 886 ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, block: %llu",
1073 rq->cmd[0], (unsigned long long)block); 887 rq->cmd[0], (unsigned long long)block);
@@ -1077,10 +891,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1077 891
1078 if (blk_fs_request(rq)) { 892 if (blk_fs_request(rq)) {
1079 if (cdrom_start_rw(drive, rq) == ide_stopped) 893 if (cdrom_start_rw(drive, rq) == ide_stopped)
1080 return ide_stopped; 894 goto out_end;
1081
1082 if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped)
1083 return ide_stopped;
1084 } else if (blk_sense_request(rq) || blk_pc_request(rq) || 895 } else if (blk_sense_request(rq) || blk_pc_request(rq) ||
1085 rq->cmd_type == REQ_TYPE_ATA_PC) { 896 rq->cmd_type == REQ_TYPE_ATA_PC) {
1086 if (!rq->timeout) 897 if (!rq->timeout)
@@ -1089,12 +900,13 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1089 cdrom_do_block_pc(drive, rq); 900 cdrom_do_block_pc(drive, rq);
1090 } else if (blk_special_request(rq)) { 901 } else if (blk_special_request(rq)) {
1091 /* right now this can only be a reset... */ 902 /* right now this can only be a reset... */
1092 cdrom_end_request(drive, 1); 903 uptodate = 1;
1093 return ide_stopped; 904 goto out_end;
1094 } else { 905 } else {
1095 blk_dump_rq_flags(rq, DRV_NAME " bad flags"); 906 blk_dump_rq_flags(rq, DRV_NAME " bad flags");
1096 cdrom_end_request(drive, 0); 907 if (rq->errors == 0)
1097 return ide_stopped; 908 rq->errors = -EIO;
909 goto out_end;
1098 } 910 }
1099 911
1100 memset(&cmd, 0, sizeof(cmd)); 912 memset(&cmd, 0, sizeof(cmd));
@@ -1104,7 +916,22 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1104 916
1105 cmd.rq = rq; 917 cmd.rq = rq;
1106 918
919 if (blk_fs_request(rq) || rq->data_len) {
920 ide_init_sg_cmd(&cmd, blk_fs_request(rq) ? (rq->nr_sectors << 9)
921 : rq->data_len);
922 ide_map_sg(drive, &cmd);
923 }
924
1107 return ide_issue_pc(drive, &cmd); 925 return ide_issue_pc(drive, &cmd);
926out_end:
927 nsectors = rq->hard_nr_sectors;
928
929 if (nsectors == 0)
930 nsectors = 1;
931
932 ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9);
933
934 return ide_stopped;
1108} 935}
1109 936
1110/* 937/*
@@ -1696,9 +1523,6 @@ static const struct ide_proc_devset *ide_cd_proc_devsets(ide_drive_t *drive)
1696#endif 1523#endif
1697 1524
1698static const struct cd_list_entry ide_cd_quirks_list[] = { 1525static const struct cd_list_entry ide_cd_quirks_list[] = {
1699 /* Limit transfer size per interrupt. */
1700 { "SAMSUNG CD-ROM SCR-2430", NULL, IDE_AFLAG_LIMIT_NFRAMES },
1701 { "SAMSUNG CD-ROM SCR-2432", NULL, IDE_AFLAG_LIMIT_NFRAMES },
1702 /* SCR-3231 doesn't support the SET_CD_SPEED command. */ 1526 /* SCR-3231 doesn't support the SET_CD_SPEED command. */
1703 { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_AFLAG_NO_SPEED_SELECT }, 1527 { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_AFLAG_NO_SPEED_SELECT },
1704 /* Old NEC260 (not R) was released before ATAPI 1.2 spec. */ 1528 /* Old NEC260 (not R) was released before ATAPI 1.2 spec. */
@@ -1759,18 +1583,18 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1759{ 1583{
1760 struct cdrom_info *cd = drive->driver_data; 1584 struct cdrom_info *cd = drive->driver_data;
1761 struct cdrom_device_info *cdi = &cd->devinfo; 1585 struct cdrom_device_info *cdi = &cd->devinfo;
1586 struct request_queue *q = drive->queue;
1762 u16 *id = drive->id; 1587 u16 *id = drive->id;
1763 char *fw_rev = (char *)&id[ATA_ID_FW_REV]; 1588 char *fw_rev = (char *)&id[ATA_ID_FW_REV];
1764 int nslots; 1589 int nslots;
1765 1590
1766 ide_debug_log(IDE_DBG_PROBE, "enter"); 1591 ide_debug_log(IDE_DBG_PROBE, "enter");
1767 1592
1768 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1593 blk_queue_prep_rq(q, ide_cdrom_prep_fn);
1769 blk_queue_dma_alignment(drive->queue, 31); 1594 blk_queue_dma_alignment(q, 31);
1770 blk_queue_update_dma_pad(drive->queue, 15); 1595 blk_queue_update_dma_pad(q, 15);
1771 drive->queue->unplug_delay = (1 * HZ) / 1000; 1596
1772 if (!drive->queue->unplug_delay) 1597 q->unplug_delay = max((1 * HZ) / 1000, 1);
1773 drive->queue->unplug_delay = 1;
1774 1598
1775 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; 1599 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
1776 drive->atapi_flags = IDE_AFLAG_NO_EJECT | ide_cd_flags(id); 1600 drive->atapi_flags = IDE_AFLAG_NO_EJECT | ide_cd_flags(id);
@@ -1788,8 +1612,7 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1788 1612
1789 nslots = ide_cdrom_probe_capabilities(drive); 1613 nslots = ide_cdrom_probe_capabilities(drive);
1790 1614
1791 /* set correct block size */ 1615 blk_queue_hardsect_size(q, CD_FRAMESIZE);
1792 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
1793 1616
1794 if (ide_cdrom_register(drive, nslots)) { 1617 if (ide_cdrom_register(drive, nslots)) {
1795 printk(KERN_ERR PFX "%s: %s failed to register device with the" 1618 printk(KERN_ERR PFX "%s: %s failed to register device with the"
@@ -1968,9 +1791,6 @@ static struct block_device_operations idecd_ops = {
1968}; 1791};
1969 1792
1970/* module options */ 1793/* module options */
1971static char *ignore;
1972module_param(ignore, charp, 0400);
1973
1974static unsigned long debug_mask; 1794static unsigned long debug_mask;
1975module_param(debug_mask, ulong, 0644); 1795module_param(debug_mask, ulong, 0644);
1976 1796
@@ -1991,15 +1811,6 @@ static int ide_cd_probe(ide_drive_t *drive)
1991 if (drive->media != ide_cdrom && drive->media != ide_optical) 1811 if (drive->media != ide_cdrom && drive->media != ide_optical)
1992 goto failed; 1812 goto failed;
1993 1813
1994 /* skip drives that we were told to ignore */
1995 if (ignore != NULL) {
1996 if (strstr(ignore, drive->name)) {
1997 printk(KERN_INFO PFX "ignoring drive %s\n",
1998 drive->name);
1999 goto failed;
2000 }
2001 }
2002
2003 drive->debug_mask = debug_mask; 1814 drive->debug_mask = debug_mask;
2004 drive->irq_handler = cdrom_newpc_intr; 1815 drive->irq_handler = cdrom_newpc_intr;
2005 1816
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index ca934c8a1289..c998cf8e971a 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -227,7 +227,7 @@ static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
227 ide_no_data_taskfile(drive, &cmd); 227 ide_no_data_taskfile(drive, &cmd);
228 228
229 /* if OK, compute maximum address value */ 229 /* if OK, compute maximum address value */
230 if ((tf->status & 0x01) == 0) 230 if (!(tf->status & ATA_ERR))
231 addr = ide_get_lba_addr(tf, lba48) + 1; 231 addr = ide_get_lba_addr(tf, lba48) + 1;
232 232
233 return addr; 233 return addr;
@@ -267,7 +267,7 @@ static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
267 ide_no_data_taskfile(drive, &cmd); 267 ide_no_data_taskfile(drive, &cmd);
268 268
269 /* if OK, compute maximum address value */ 269 /* if OK, compute maximum address value */
270 if ((tf->status & 0x01) == 0) 270 if (!(tf->status & ATA_ERR))
271 addr_set = ide_get_lba_addr(tf, lba48) + 1; 271 addr_set = ide_get_lba_addr(tf, lba48) + 1;
272 272
273 return addr_set; 273 return addr_set;
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
index 75a9ea2e4c82..16fc46edc32d 100644
--- a/drivers/ide/ide-dma-sff.c
+++ b/drivers/ide/ide-dma-sff.c
@@ -38,10 +38,9 @@ int config_drive_for_dma(ide_drive_t *drive)
38 * Enable DMA on any drive that has mode2 DMA 38 * Enable DMA on any drive that has mode2 DMA
39 * (multi or single) enabled 39 * (multi or single) enabled
40 */ 40 */
41 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */ 41 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
42 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 || 42 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
43 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404) 43 return 1;
44 return 1;
45 44
46 /* Consult the list of known "good" drives */ 45 /* Consult the list of known "good" drives */
47 if (ide_dma_good_drive(drive)) 46 if (ide_dma_good_drive(drive))
@@ -166,8 +165,6 @@ use_pio_instead:
166 printk(KERN_ERR "%s: %s\n", drive->name, 165 printk(KERN_ERR "%s: %s\n", drive->name,
167 count ? "DMA table too small" : "empty DMA table?"); 166 count ? "DMA table too small" : "empty DMA table?");
168 167
169 ide_destroy_dmatable(drive);
170
171 return 0; /* revert to PIO for this request */ 168 return 0; /* revert to PIO for this request */
172} 169}
173EXPORT_SYMBOL_GPL(ide_build_dmatable); 170EXPORT_SYMBOL_GPL(ide_build_dmatable);
@@ -218,7 +215,6 @@ int ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
218 /* clear INTR & ERROR flags */ 215 /* clear INTR & ERROR flags */
219 ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR); 216 ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR);
220 217
221 drive->waiting_for_dma = 1;
222 return 0; 218 return 0;
223} 219}
224EXPORT_SYMBOL_GPL(ide_dma_setup); 220EXPORT_SYMBOL_GPL(ide_dma_setup);
@@ -292,8 +288,6 @@ int ide_dma_end(ide_drive_t *drive)
292 ide_hwif_t *hwif = drive->hwif; 288 ide_hwif_t *hwif = drive->hwif;
293 u8 dma_stat = 0, dma_cmd = 0, mask; 289 u8 dma_stat = 0, dma_cmd = 0, mask;
294 290
295 drive->waiting_for_dma = 0;
296
297 /* stop DMA */ 291 /* stop DMA */
298 if (hwif->host_flags & IDE_HFLAG_MMIO) { 292 if (hwif->host_flags & IDE_HFLAG_MMIO) {
299 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); 293 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
@@ -310,8 +304,6 @@ int ide_dma_end(ide_drive_t *drive)
310 /* clear INTR & ERROR bits */ 304 /* clear INTR & ERROR bits */
311 ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR); 305 ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR);
312 306
313 /* purge DMA mappings */
314 ide_destroy_dmatable(drive);
315 wmb(); 307 wmb();
316 308
317 /* verify good DMA status */ 309 /* verify good DMA status */
@@ -338,9 +330,8 @@ const struct ide_dma_ops sff_dma_ops = {
338 .dma_start = ide_dma_start, 330 .dma_start = ide_dma_start,
339 .dma_end = ide_dma_end, 331 .dma_end = ide_dma_end,
340 .dma_test_irq = ide_dma_test_irq, 332 .dma_test_irq = ide_dma_test_irq,
341 .dma_timer_expiry = ide_dma_sff_timer_expiry,
342 .dma_timeout = ide_dma_timeout,
343 .dma_lost_irq = ide_dma_lost_irq, 333 .dma_lost_irq = ide_dma_lost_irq,
334 .dma_timer_expiry = ide_dma_sff_timer_expiry,
344 .dma_sff_read_status = ide_dma_sff_read_status, 335 .dma_sff_read_status = ide_dma_sff_read_status,
345}; 336};
346EXPORT_SYMBOL_GPL(sff_dma_ops); 337EXPORT_SYMBOL_GPL(sff_dma_ops);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 3dbf80c15491..a0b8cab1d9a6 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -89,15 +89,16 @@ static const struct drive_list_entry drive_blacklist[] = {
89ide_startstop_t ide_dma_intr(ide_drive_t *drive) 89ide_startstop_t ide_dma_intr(ide_drive_t *drive)
90{ 90{
91 ide_hwif_t *hwif = drive->hwif; 91 ide_hwif_t *hwif = drive->hwif;
92 struct ide_cmd *cmd = &hwif->cmd;
92 u8 stat = 0, dma_stat = 0; 93 u8 stat = 0, dma_stat = 0;
93 94
95 drive->waiting_for_dma = 0;
94 dma_stat = hwif->dma_ops->dma_end(drive); 96 dma_stat = hwif->dma_ops->dma_end(drive);
97 ide_dma_unmap_sg(drive, cmd);
95 stat = hwif->tp_ops->read_status(hwif); 98 stat = hwif->tp_ops->read_status(hwif);
96 99
97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) { 100 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
98 if (!dma_stat) { 101 if (!dma_stat) {
99 struct ide_cmd *cmd = &hwif->cmd;
100
101 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0) 102 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
102 ide_finish_cmd(drive, cmd, stat); 103 ide_finish_cmd(drive, cmd, stat);
103 else 104 else
@@ -117,8 +118,8 @@ int ide_dma_good_drive(ide_drive_t *drive)
117} 118}
118 119
119/** 120/**
120 * ide_build_sglist - map IDE scatter gather for DMA I/O 121 * ide_dma_map_sg - map IDE scatter gather for DMA I/O
121 * @drive: the drive to build the DMA table for 122 * @drive: the drive to map the DMA table for
122 * @cmd: command 123 * @cmd: command
123 * 124 *
124 * Perform the DMA mapping magic necessary to access the source or 125 * Perform the DMA mapping magic necessary to access the source or
@@ -127,23 +128,19 @@ int ide_dma_good_drive(ide_drive_t *drive)
127 * operate in a portable fashion. 128 * operate in a portable fashion.
128 */ 129 */
129 130
130int ide_build_sglist(ide_drive_t *drive, struct ide_cmd *cmd) 131static int ide_dma_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
131{ 132{
132 ide_hwif_t *hwif = drive->hwif; 133 ide_hwif_t *hwif = drive->hwif;
133 struct scatterlist *sg = hwif->sg_table; 134 struct scatterlist *sg = hwif->sg_table;
134 int i; 135 int i;
135 136
136 ide_map_sg(drive, cmd);
137
138 if (cmd->tf_flags & IDE_TFLAG_WRITE) 137 if (cmd->tf_flags & IDE_TFLAG_WRITE)
139 cmd->sg_dma_direction = DMA_TO_DEVICE; 138 cmd->sg_dma_direction = DMA_TO_DEVICE;
140 else 139 else
141 cmd->sg_dma_direction = DMA_FROM_DEVICE; 140 cmd->sg_dma_direction = DMA_FROM_DEVICE;
142 141
143 i = dma_map_sg(hwif->dev, sg, cmd->sg_nents, cmd->sg_dma_direction); 142 i = dma_map_sg(hwif->dev, sg, cmd->sg_nents, cmd->sg_dma_direction);
144 if (i == 0) 143 if (i) {
145 ide_map_sg(drive, cmd);
146 else {
147 cmd->orig_sg_nents = cmd->sg_nents; 144 cmd->orig_sg_nents = cmd->sg_nents;
148 cmd->sg_nents = i; 145 cmd->sg_nents = i;
149 } 146 }
@@ -152,7 +149,7 @@ int ide_build_sglist(ide_drive_t *drive, struct ide_cmd *cmd)
152} 149}
153 150
154/** 151/**
155 * ide_destroy_dmatable - clean up DMA mapping 152 * ide_dma_unmap_sg - clean up DMA mapping
156 * @drive: The drive to unmap 153 * @drive: The drive to unmap
157 * 154 *
158 * Teardown mappings after DMA has completed. This must be called 155 * Teardown mappings after DMA has completed. This must be called
@@ -162,15 +159,14 @@ int ide_build_sglist(ide_drive_t *drive, struct ide_cmd *cmd)
162 * time. 159 * time.
163 */ 160 */
164 161
165void ide_destroy_dmatable(ide_drive_t *drive) 162void ide_dma_unmap_sg(ide_drive_t *drive, struct ide_cmd *cmd)
166{ 163{
167 ide_hwif_t *hwif = drive->hwif; 164 ide_hwif_t *hwif = drive->hwif;
168 struct ide_cmd *cmd = &hwif->cmd;
169 165
170 dma_unmap_sg(hwif->dev, hwif->sg_table, cmd->orig_sg_nents, 166 dma_unmap_sg(hwif->dev, hwif->sg_table, cmd->orig_sg_nents,
171 cmd->sg_dma_direction); 167 cmd->sg_dma_direction);
172} 168}
173EXPORT_SYMBOL_GPL(ide_destroy_dmatable); 169EXPORT_SYMBOL_GPL(ide_dma_unmap_sg);
174 170
175/** 171/**
176 * ide_dma_off_quietly - Generic DMA kill 172 * ide_dma_off_quietly - Generic DMA kill
@@ -249,12 +245,11 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
249 case XFER_UDMA_0: 245 case XFER_UDMA_0:
250 if ((id[ATA_ID_FIELD_VALID] & 4) == 0) 246 if ((id[ATA_ID_FIELD_VALID] & 4) == 0)
251 break; 247 break;
252 248 mask = id[ATA_ID_UDMA_MODES];
253 if (port_ops && port_ops->udma_filter) 249 if (port_ops && port_ops->udma_filter)
254 mask = port_ops->udma_filter(drive); 250 mask &= port_ops->udma_filter(drive);
255 else 251 else
256 mask = hwif->ultra_mask; 252 mask &= hwif->ultra_mask;
257 mask &= id[ATA_ID_UDMA_MODES];
258 253
259 /* 254 /*
260 * avoid false cable warning from eighty_ninty_three() 255 * avoid false cable warning from eighty_ninty_three()
@@ -265,18 +260,23 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
265 } 260 }
266 break; 261 break;
267 case XFER_MW_DMA_0: 262 case XFER_MW_DMA_0:
268 if ((id[ATA_ID_FIELD_VALID] & 2) == 0) 263 mask = id[ATA_ID_MWDMA_MODES];
269 break; 264
265 /* Also look for the CF specific MWDMA modes... */
266 if (ata_id_is_cfa(id) && (id[ATA_ID_CFA_MODES] & 0x38)) {
267 u8 mode = ((id[ATA_ID_CFA_MODES] & 0x38) >> 3) - 1;
268
269 mask |= ((2 << mode) - 1) << 3;
270 }
271
270 if (port_ops && port_ops->mdma_filter) 272 if (port_ops && port_ops->mdma_filter)
271 mask = port_ops->mdma_filter(drive); 273 mask &= port_ops->mdma_filter(drive);
272 else 274 else
273 mask = hwif->mwdma_mask; 275 mask &= hwif->mwdma_mask;
274 mask &= id[ATA_ID_MWDMA_MODES];
275 break; 276 break;
276 case XFER_SW_DMA_0: 277 case XFER_SW_DMA_0:
277 if (id[ATA_ID_FIELD_VALID] & 2) { 278 mask = id[ATA_ID_SWDMA_MODES];
278 mask = id[ATA_ID_SWDMA_MODES] & hwif->swdma_mask; 279 if (!(mask & ATA_SWDMA2) && (id[ATA_ID_OLD_DMA_MODES] >> 8)) {
279 } else if (id[ATA_ID_OLD_DMA_MODES] >> 8) {
280 u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8; 280 u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8;
281 281
282 /* 282 /*
@@ -284,8 +284,9 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
284 * (the maximum allowed mode is XFER_SW_DMA_2) 284 * (the maximum allowed mode is XFER_SW_DMA_2)
285 */ 285 */
286 if (mode <= 2) 286 if (mode <= 2)
287 mask = ((2 << mode) - 1) & hwif->swdma_mask; 287 mask = (2 << mode) - 1;
288 } 288 }
289 mask &= hwif->swdma_mask;
289 break; 290 break;
290 default: 291 default:
291 BUG(); 292 BUG();
@@ -402,11 +403,10 @@ int ide_id_dma_bug(ide_drive_t *drive)
402 if ((id[ATA_ID_UDMA_MODES] >> 8) && 403 if ((id[ATA_ID_UDMA_MODES] >> 8) &&
403 (id[ATA_ID_MWDMA_MODES] >> 8)) 404 (id[ATA_ID_MWDMA_MODES] >> 8))
404 goto err_out; 405 goto err_out;
405 } else if (id[ATA_ID_FIELD_VALID] & 2) { 406 } else if ((id[ATA_ID_MWDMA_MODES] >> 8) &&
406 if ((id[ATA_ID_MWDMA_MODES] >> 8) && 407 (id[ATA_ID_SWDMA_MODES] >> 8))
407 (id[ATA_ID_SWDMA_MODES] >> 8)) 408 goto err_out;
408 goto err_out; 409
409 }
410 return 0; 410 return 0;
411err_out: 411err_out:
412 printk(KERN_ERR "%s: bad DMA info in identify block\n", drive->name); 412 printk(KERN_ERR "%s: bad DMA info in identify block\n", drive->name);
@@ -460,21 +460,6 @@ void ide_dma_lost_irq(ide_drive_t *drive)
460} 460}
461EXPORT_SYMBOL_GPL(ide_dma_lost_irq); 461EXPORT_SYMBOL_GPL(ide_dma_lost_irq);
462 462
463void ide_dma_timeout(ide_drive_t *drive)
464{
465 ide_hwif_t *hwif = drive->hwif;
466
467 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name);
468
469 if (hwif->dma_ops->dma_test_irq(drive))
470 return;
471
472 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
473
474 hwif->dma_ops->dma_end(drive);
475}
476EXPORT_SYMBOL_GPL(ide_dma_timeout);
477
478/* 463/*
479 * un-busy the port etc, and clear any pending DMA status. we want to 464 * un-busy the port etc, and clear any pending DMA status. we want to
480 * retry the current request in pio mode instead of risking tossing it 465 * retry the current request in pio mode instead of risking tossing it
@@ -483,6 +468,8 @@ EXPORT_SYMBOL_GPL(ide_dma_timeout);
483ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) 468ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
484{ 469{
485 ide_hwif_t *hwif = drive->hwif; 470 ide_hwif_t *hwif = drive->hwif;
471 const struct ide_dma_ops *dma_ops = hwif->dma_ops;
472 struct ide_cmd *cmd = &hwif->cmd;
486 struct request *rq; 473 struct request *rq;
487 ide_startstop_t ret = ide_stopped; 474 ide_startstop_t ret = ide_stopped;
488 475
@@ -492,12 +479,23 @@ ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
492 479
493 if (error < 0) { 480 if (error < 0) {
494 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name); 481 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
495 (void)hwif->dma_ops->dma_end(drive); 482 drive->waiting_for_dma = 0;
483 (void)dma_ops->dma_end(drive);
484 ide_dma_unmap_sg(drive, cmd);
496 ret = ide_error(drive, "dma timeout error", 485 ret = ide_error(drive, "dma timeout error",
497 hwif->tp_ops->read_status(hwif)); 486 hwif->tp_ops->read_status(hwif));
498 } else { 487 } else {
499 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name); 488 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
500 hwif->dma_ops->dma_timeout(drive); 489 if (dma_ops->dma_clear)
490 dma_ops->dma_clear(drive);
491 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name);
492 if (dma_ops->dma_test_irq(drive) == 0) {
493 ide_dump_status(drive, "DMA timeout",
494 hwif->tp_ops->read_status(hwif));
495 drive->waiting_for_dma = 0;
496 (void)dma_ops->dma_end(drive);
497 ide_dma_unmap_sg(drive, cmd);
498 }
501 } 499 }
502 500
503 /* 501 /*
@@ -567,3 +565,25 @@ int ide_allocate_dma_engine(ide_hwif_t *hwif)
567 return 0; 565 return 0;
568} 566}
569EXPORT_SYMBOL_GPL(ide_allocate_dma_engine); 567EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
568
569int ide_dma_prepare(ide_drive_t *drive, struct ide_cmd *cmd)
570{
571 const struct ide_dma_ops *dma_ops = drive->hwif->dma_ops;
572
573 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
574 (dma_ops->dma_check && dma_ops->dma_check(drive, cmd)))
575 goto out;
576 ide_map_sg(drive, cmd);
577 if (ide_dma_map_sg(drive, cmd) == 0)
578 goto out_map;
579 if (dma_ops->dma_setup(drive, cmd))
580 goto out_dma_unmap;
581 drive->waiting_for_dma = 1;
582 return 0;
583out_dma_unmap:
584 ide_dma_unmap_sg(drive, cmd);
585out_map:
586 ide_map_sg(drive, cmd);
587out:
588 return 1;
589}
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
index 11664976eea3..5d5fb961b5ce 100644
--- a/drivers/ide/ide-eh.c
+++ b/drivers/ide/ide-eh.c
@@ -165,11 +165,12 @@ static ide_startstop_t do_reset1(ide_drive_t *, int);
165static ide_startstop_t atapi_reset_pollfunc(ide_drive_t *drive) 165static ide_startstop_t atapi_reset_pollfunc(ide_drive_t *drive)
166{ 166{
167 ide_hwif_t *hwif = drive->hwif; 167 ide_hwif_t *hwif = drive->hwif;
168 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
168 u8 stat; 169 u8 stat;
169 170
170 SELECT_DRIVE(drive); 171 tp_ops->dev_select(drive);
171 udelay(10); 172 udelay(10);
172 stat = hwif->tp_ops->read_status(hwif); 173 stat = tp_ops->read_status(hwif);
173 174
174 if (OK_STAT(stat, 0, ATA_BUSY)) 175 if (OK_STAT(stat, 0, ATA_BUSY))
175 printk(KERN_INFO "%s: ATAPI reset complete\n", drive->name); 176 printk(KERN_INFO "%s: ATAPI reset complete\n", drive->name);
@@ -348,7 +349,7 @@ static ide_startstop_t do_reset1(ide_drive_t *drive, int do_not_try_atapi)
348 /* For an ATAPI device, first try an ATAPI SRST. */ 349 /* For an ATAPI device, first try an ATAPI SRST. */
349 if (drive->media != ide_disk && !do_not_try_atapi) { 350 if (drive->media != ide_disk && !do_not_try_atapi) {
350 pre_reset(drive); 351 pre_reset(drive);
351 SELECT_DRIVE(drive); 352 tp_ops->dev_select(drive);
352 udelay(20); 353 udelay(20);
353 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 354 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
354 ndelay(400); 355 ndelay(400);
@@ -401,15 +402,14 @@ static ide_startstop_t do_reset1(ide_drive_t *drive, int do_not_try_atapi)
401 * immediate interrupt due to the edge transition it produces. 402 * immediate interrupt due to the edge transition it produces.
402 * This single interrupt gives us a "fast poll" for drives that 403 * This single interrupt gives us a "fast poll" for drives that
403 * recover from reset very quickly, saving us the first 50ms wait time. 404 * recover from reset very quickly, saving us the first 50ms wait time.
404 *
405 * TODO: add ->softreset method and stop abusing ->set_irq
406 */ 405 */
407 /* set SRST and nIEN */ 406 /* set SRST and nIEN */
408 tp_ops->set_irq(hwif, 4); 407 tp_ops->write_devctl(hwif, ATA_SRST | ATA_NIEN | ATA_DEVCTL_OBS);
409 /* more than enough time */ 408 /* more than enough time */
410 udelay(10); 409 udelay(10);
411 /* clear SRST, leave nIEN (unless device is on the quirk list) */ 410 /* clear SRST, leave nIEN (unless device is on the quirk list) */
412 tp_ops->set_irq(hwif, drive->quirk_list == 2); 411 tp_ops->write_devctl(hwif, (drive->quirk_list == 2 ? 0 : ATA_NIEN) |
412 ATA_DEVCTL_OBS);
413 /* more than enough time */ 413 /* more than enough time */
414 udelay(10); 414 udelay(10);
415 hwif->poll_timeout = jiffies + WAIT_WORSTCASE; 415 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 7ae662334835..2b4868d95f8b 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -61,16 +61,6 @@
61 */ 61 */
62#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */ 62#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */
63 63
64static void idefloppy_update_buffers(ide_drive_t *drive,
65 struct ide_atapi_pc *pc)
66{
67 struct request *rq = pc->rq;
68 struct bio *bio = rq->bio;
69
70 while ((bio = rq->bio) != NULL)
71 ide_complete_rq(drive, 0, ide_rq_bytes(rq));
72}
73
74static int ide_floppy_callback(ide_drive_t *drive, int dsc) 64static int ide_floppy_callback(ide_drive_t *drive, int dsc)
75{ 65{
76 struct ide_disk_obj *floppy = drive->driver_data; 66 struct ide_disk_obj *floppy = drive->driver_data;
@@ -213,7 +203,6 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
213 memcpy(rq->cmd, pc->c, 12); 203 memcpy(rq->cmd, pc->c, 12);
214 204
215 pc->rq = rq; 205 pc->rq = rq;
216 pc->b_count = 0;
217 if (rq->cmd_flags & REQ_RW) 206 if (rq->cmd_flags & REQ_RW)
218 pc->flags |= PC_FLAG_WRITING; 207 pc->flags |= PC_FLAG_WRITING;
219 pc->buf = NULL; 208 pc->buf = NULL;
@@ -227,7 +216,6 @@ static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
227 ide_init_pc(pc); 216 ide_init_pc(pc);
228 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 217 memcpy(pc->c, rq->cmd, sizeof(pc->c));
229 pc->rq = rq; 218 pc->rq = rq;
230 pc->b_count = 0;
231 if (rq->data_len && rq_data_dir(rq) == WRITE) 219 if (rq->data_len && rq_data_dir(rq) == WRITE)
232 pc->flags |= PC_FLAG_WRITING; 220 pc->flags |= PC_FLAG_WRITING;
233 pc->buf = rq->data; 221 pc->buf = rq->data;
@@ -244,10 +232,11 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
244 struct request *rq, sector_t block) 232 struct request *rq, sector_t block)
245{ 233{
246 struct ide_disk_obj *floppy = drive->driver_data; 234 struct ide_disk_obj *floppy = drive->driver_data;
247 ide_hwif_t *hwif = drive->hwif;
248 struct ide_cmd cmd; 235 struct ide_cmd cmd;
249 struct ide_atapi_pc *pc; 236 struct ide_atapi_pc *pc;
250 237
238 ide_debug_log(IDE_DBG_FUNC, "enter, cmd: 0x%x\n", rq->cmd[0]);
239
251 if (drive->debug_mask & IDE_DBG_RQ) 240 if (drive->debug_mask & IDE_DBG_RQ)
252 blk_dump_rq_flags(rq, (rq->rq_disk 241 blk_dump_rq_flags(rq, (rq->rq_disk
253 ? rq->rq_disk->disk_name 242 ? rq->rq_disk->disk_name
@@ -294,13 +283,10 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
294 cmd.rq = rq; 283 cmd.rq = rq;
295 284
296 if (blk_fs_request(rq) || pc->req_xfer) { 285 if (blk_fs_request(rq) || pc->req_xfer) {
297 ide_init_sg_cmd(&cmd, rq->nr_sectors << 9); 286 ide_init_sg_cmd(&cmd, pc->req_xfer);
298 ide_map_sg(drive, &cmd); 287 ide_map_sg(drive, &cmd);
299 } 288 }
300 289
301 pc->sg = hwif->sg_table;
302 pc->sg_cnt = cmd.sg_nents;
303
304 pc->rq = rq; 290 pc->rq = rq;
305 291
306 return ide_floppy_issue_pc(drive, &cmd, pc); 292 return ide_floppy_issue_pc(drive, &cmd, pc);
@@ -385,9 +371,11 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
385 struct gendisk *disk = floppy->disk; 371 struct gendisk *disk = floppy->disk;
386 struct ide_atapi_pc pc; 372 struct ide_atapi_pc pc;
387 u8 *cap_desc; 373 u8 *cap_desc;
388 u8 header_len, desc_cnt; 374 u8 pc_buf[256], header_len, desc_cnt;
389 int i, rc = 1, blocks, length; 375 int i, rc = 1, blocks, length;
390 376
377 ide_debug_log(IDE_DBG_FUNC, "enter");
378
391 drive->bios_cyl = 0; 379 drive->bios_cyl = 0;
392 drive->bios_head = drive->bios_sect = 0; 380 drive->bios_head = drive->bios_sect = 0;
393 floppy->blocks = 0; 381 floppy->blocks = 0;
@@ -395,6 +383,9 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
395 drive->capacity64 = 0; 383 drive->capacity64 = 0;
396 384
397 ide_floppy_create_read_capacity_cmd(&pc); 385 ide_floppy_create_read_capacity_cmd(&pc);
386 pc.buf = &pc_buf[0];
387 pc.buf_size = sizeof(pc_buf);
388
398 if (ide_queue_pc_tail(drive, disk, &pc)) { 389 if (ide_queue_pc_tail(drive, disk, &pc)) {
399 printk(KERN_ERR PFX "Can't get floppy parameters\n"); 390 printk(KERN_ERR PFX "Can't get floppy parameters\n");
400 return 1; 391 return 1;
@@ -485,8 +476,6 @@ static void ide_floppy_setup(ide_drive_t *drive)
485 u16 *id = drive->id; 476 u16 *id = drive->id;
486 477
487 drive->pc_callback = ide_floppy_callback; 478 drive->pc_callback = ide_floppy_callback;
488 drive->pc_update_buffers = idefloppy_update_buffers;
489 drive->pc_io_buffers = ide_io_buffers;
490 479
491 /* 480 /*
492 * We used to check revisions here. At this point however I'm giving up. 481 * We used to check revisions here. At this point however I'm giving up.
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index 8f8be8546038..cd8a42027ede 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -36,9 +36,9 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive,
36 int __user *arg) 36 int __user *arg)
37{ 37{
38 struct ide_disk_obj *floppy = drive->driver_data; 38 struct ide_disk_obj *floppy = drive->driver_data;
39 u8 header_len, desc_cnt;
40 int i, blocks, length, u_array_size, u_index; 39 int i, blocks, length, u_array_size, u_index;
41 int __user *argp; 40 int __user *argp;
41 u8 pc_buf[256], header_len, desc_cnt;
42 42
43 if (get_user(u_array_size, arg)) 43 if (get_user(u_array_size, arg))
44 return -EFAULT; 44 return -EFAULT;
@@ -47,6 +47,9 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive,
47 return -EINVAL; 47 return -EINVAL;
48 48
49 ide_floppy_create_read_capacity_cmd(pc); 49 ide_floppy_create_read_capacity_cmd(pc);
50 pc->buf = &pc_buf[0];
51 pc->buf_size = sizeof(pc_buf);
52
50 if (ide_queue_pc_tail(drive, floppy->disk, pc)) { 53 if (ide_queue_pc_tail(drive, floppy->disk, pc)) {
51 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 54 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
52 return -EIO; 55 return -EIO;
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 9d03e8211536..7812ca0be13b 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -1,27 +1,22 @@
1/* 1/*
2 * generic/default IDE host driver 2 * generic/default IDE host driver
3 * 3 *
4 * Copyright (C) 2004, 2008 Bartlomiej Zolnierkiewicz 4 * Copyright (C) 2004, 2008-2009 Bartlomiej Zolnierkiewicz
5 * This code was split off from ide.c. See it for original copyrights. 5 * This code was split off from ide.c. See it for original copyrights.
6 * 6 *
7 * May be copied or modified under the terms of the GNU General Public License. 7 * May be copied or modified under the terms of the GNU General Public License.
8 */ 8 */
9 9
10/*
11 * For special cases new interfaces may be added using sysfs, i.e.
12 *
13 * echo -n "0x168:0x36e:10" > /sys/class/ide_generic/add
14 *
15 * will add an interface using I/O ports 0x168-0x16f/0x36e and IRQ 10.
16 */
17
18#include <linux/kernel.h> 10#include <linux/kernel.h>
19#include <linux/init.h> 11#include <linux/init.h>
20#include <linux/module.h> 12#include <linux/module.h>
21#include <linux/ide.h> 13#include <linux/ide.h>
22#include <linux/pci_ids.h> 14#include <linux/pci_ids.h>
23 15
24/* FIXME: convert m32r to use ide_platform host driver */ 16/* FIXME: convert arm and m32r to use ide_platform host driver */
17#ifdef CONFIG_ARM
18#include <asm/irq.h>
19#endif
25#ifdef CONFIG_M32R 20#ifdef CONFIG_M32R
26#include <asm/m32r.h> 21#include <asm/m32r.h>
27#endif 22#endif
@@ -36,62 +31,11 @@ static const struct ide_port_info ide_generic_port_info = {
36 .host_flags = IDE_HFLAG_NO_DMA, 31 .host_flags = IDE_HFLAG_NO_DMA,
37}; 32};
38 33
39static ssize_t store_add(struct class *cls, const char *buf, size_t n) 34#ifdef CONFIG_ARM
40{ 35static const u16 legacy_bases[] = { 0x1f0 };
41 unsigned int base, ctl; 36static const int legacy_irqs[] = { IRQ_HARDDISK };
42 int irq, rc; 37#elif defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) || \
43 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 38 defined(CONFIG_PLAT_OPSPUT)
44
45 if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
46 return -EINVAL;
47
48 memset(&hw, 0, sizeof(hw));
49 ide_std_init_ports(&hw, base, ctl);
50 hw.irq = irq;
51 hw.chipset = ide_generic;
52
53 rc = ide_host_add(&ide_generic_port_info, hws, NULL);
54 if (rc)
55 return rc;
56
57 return n;
58};
59
60static struct class_attribute ide_generic_class_attrs[] = {
61 __ATTR(add, S_IWUSR, NULL, store_add),
62 __ATTR_NULL
63};
64
65static void ide_generic_class_release(struct class *cls)
66{
67 kfree(cls);
68}
69
70static int __init ide_generic_sysfs_init(void)
71{
72 struct class *cls;
73 int rc;
74
75 cls = kzalloc(sizeof(*cls), GFP_KERNEL);
76 if (!cls)
77 return -ENOMEM;
78
79 cls->name = DRV_NAME;
80 cls->owner = THIS_MODULE;
81 cls->class_release = ide_generic_class_release;
82 cls->class_attrs = ide_generic_class_attrs;
83
84 rc = class_register(cls);
85 if (rc) {
86 kfree(cls);
87 return rc;
88 }
89
90 return 0;
91}
92
93#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) \
94 || defined(CONFIG_PLAT_OPSPUT)
95static const u16 legacy_bases[] = { 0x1f0 }; 39static const u16 legacy_bases[] = { 0x1f0 };
96static const int legacy_irqs[] = { PLD_IRQ_CFIREQ }; 40static const int legacy_irqs[] = { PLD_IRQ_CFIREQ };
97#elif defined(CONFIG_PLAT_MAPPI3) 41#elif defined(CONFIG_PLAT_MAPPI3)
@@ -107,11 +51,11 @@ static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
107 51
108static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary) 52static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
109{ 53{
54#ifdef CONFIG_PCI
110 struct pci_dev *p = NULL; 55 struct pci_dev *p = NULL;
111 u16 val; 56 u16 val;
112 57
113 for_each_pci_dev(p) { 58 for_each_pci_dev(p) {
114
115 if (pci_resource_start(p, 0) == 0x1f0) 59 if (pci_resource_start(p, 0) == 0x1f0)
116 *primary = 1; 60 *primary = 1;
117 if (pci_resource_start(p, 2) == 0x170) 61 if (pci_resource_start(p, 2) == 0x170)
@@ -126,7 +70,6 @@ static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
126 /* Intel MPIIX - PIO ATA on non PCI side of bridge */ 70 /* Intel MPIIX - PIO ATA on non PCI side of bridge */
127 if (p->vendor == PCI_VENDOR_ID_INTEL && 71 if (p->vendor == PCI_VENDOR_ID_INTEL &&
128 p->device == PCI_DEVICE_ID_INTEL_82371MX) { 72 p->device == PCI_DEVICE_ID_INTEL_82371MX) {
129
130 pci_read_config_word(p, 0x6C, &val); 73 pci_read_config_word(p, 0x6C, &val);
131 if (val & 0x8000) { 74 if (val & 0x8000) {
132 /* ATA port enabled */ 75 /* ATA port enabled */
@@ -137,6 +80,7 @@ static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
137 } 80 }
138 } 81 }
139 } 82 }
83#endif
140} 84}
141 85
142static int __init ide_generic_init(void) 86static int __init ide_generic_init(void)
@@ -168,6 +112,7 @@ static int __init ide_generic_init(void)
168 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX " 112 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
169 "not free.\n", 113 "not free.\n",
170 DRV_NAME, io_addr, io_addr + 7); 114 DRV_NAME, io_addr, io_addr + 7);
115 rc = -EBUSY;
171 continue; 116 continue;
172 } 117 }
173 118
@@ -176,6 +121,7 @@ static int __init ide_generic_init(void)
176 "not free.\n", 121 "not free.\n",
177 DRV_NAME, io_addr + 0x206); 122 DRV_NAME, io_addr + 0x206);
178 release_region(io_addr, 8); 123 release_region(io_addr, 8);
124 rc = -EBUSY;
179 continue; 125 continue;
180 } 126 }
181 127
@@ -196,10 +142,6 @@ static int __init ide_generic_init(void)
196 } 142 }
197 } 143 }
198 144
199 if (ide_generic_sysfs_init())
200 printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
201 "class\n");
202
203 return rc; 145 return rc;
204} 146}
205 147
diff --git a/drivers/ide/ide-h8300.c b/drivers/ide/ide-h8300.c
index ff8339ed59ab..dac9a6d44963 100644
--- a/drivers/ide/ide-h8300.c
+++ b/drivers/ide/ide-h8300.c
@@ -54,9 +54,6 @@ static void h8300_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
54 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) 54 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
55 HIHI = 0xFF; 55 HIHI = 0xFF;
56 56
57 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA)
58 mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr);
59
60 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 57 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
61 outb(tf->hob_feature, io_ports->feature_addr); 58 outb(tf->hob_feature, io_ports->feature_addr);
62 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 59 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
@@ -90,18 +87,11 @@ static void h8300_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
90 struct ide_io_ports *io_ports = &hwif->io_ports; 87 struct ide_io_ports *io_ports = &hwif->io_ports;
91 struct ide_taskfile *tf = &cmd->tf; 88 struct ide_taskfile *tf = &cmd->tf;
92 89
93 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
94 u16 data = mm_inw(io_ports->data_addr);
95
96 tf->data = data & 0xff;
97 tf->hob_data = (data >> 8) & 0xff;
98 }
99
100 /* be sure we're looking at the low order bits */ 90 /* be sure we're looking at the low order bits */
101 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 91 outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
102 92
103 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 93 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
104 tf->feature = inb(io_ports->feature_addr); 94 tf->error = inb(io_ports->feature_addr);
105 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 95 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
106 tf->nsect = inb(io_ports->nsect_addr); 96 tf->nsect = inb(io_ports->nsect_addr);
107 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 97 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -114,18 +104,18 @@ static void h8300_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
114 tf->device = inb(io_ports->device_addr); 104 tf->device = inb(io_ports->device_addr);
115 105
116 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 106 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
117 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 107 outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
118 108
119 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 109 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
120 tf->hob_feature = inb(io_ports->feature_addr); 110 tf->hob_error = inb(io_ports->feature_addr);
121 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 111 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
122 tf->hob_nsect = inb(io_ports->nsect_addr); 112 tf->hob_nsect = inb(io_ports->nsect_addr);
123 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 113 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
124 tf->hob_lbal = inb(io_ports->lbal_addr); 114 tf->hob_lbal = inb(io_ports->lbal_addr);
125 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 115 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
126 tf->hob_lbam = inb(io_ports->lbam_addr); 116 tf->hob_lbam = inb(io_ports->lbam_addr);
127 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 117 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
128 tf->hob_lbah = inb(io_ports->lbah_addr); 118 tf->hob_lbah = inb(io_ports->lbah_addr);
129 } 119 }
130} 120}
131 121
@@ -159,9 +149,9 @@ static const struct ide_tp_ops h8300_tp_ops = {
159 .exec_command = ide_exec_command, 149 .exec_command = ide_exec_command,
160 .read_status = ide_read_status, 150 .read_status = ide_read_status,
161 .read_altstatus = ide_read_altstatus, 151 .read_altstatus = ide_read_altstatus,
152 .write_devctl = ide_write_devctl,
162 153
163 .set_irq = ide_set_irq, 154 .dev_select = ide_dev_select,
164
165 .tf_load = h8300_tf_load, 155 .tf_load = h8300_tf_load,
166 .tf_read = h8300_tf_read, 156 .tf_read = h8300_tf_read,
167 157
diff --git a/drivers/ide/ide-io-std.c b/drivers/ide/ide-io-std.c
index 2d9c6dc3f956..9cac281d82c4 100644
--- a/drivers/ide/ide-io-std.c
+++ b/drivers/ide/ide-io-std.c
@@ -64,23 +64,26 @@ u8 ide_read_altstatus(ide_hwif_t *hwif)
64} 64}
65EXPORT_SYMBOL_GPL(ide_read_altstatus); 65EXPORT_SYMBOL_GPL(ide_read_altstatus);
66 66
67void ide_set_irq(ide_hwif_t *hwif, int on) 67void ide_write_devctl(ide_hwif_t *hwif, u8 ctl)
68{ 68{
69 u8 ctl = ATA_DEVCTL_OBS;
70
71 if (on == 4) { /* hack for SRST */
72 ctl |= 4;
73 on &= ~4;
74 }
75
76 ctl |= on ? 0 : 2;
77
78 if (hwif->host_flags & IDE_HFLAG_MMIO) 69 if (hwif->host_flags & IDE_HFLAG_MMIO)
79 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr); 70 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
80 else 71 else
81 outb(ctl, hwif->io_ports.ctl_addr); 72 outb(ctl, hwif->io_ports.ctl_addr);
82} 73}
83EXPORT_SYMBOL_GPL(ide_set_irq); 74EXPORT_SYMBOL_GPL(ide_write_devctl);
75
76void ide_dev_select(ide_drive_t *drive)
77{
78 ide_hwif_t *hwif = drive->hwif;
79 u8 select = drive->select | ATA_DEVICE_OBS;
80
81 if (hwif->host_flags & IDE_HFLAG_MMIO)
82 writeb(select, (void __iomem *)hwif->io_ports.device_addr);
83 else
84 outb(select, hwif->io_ports.device_addr);
85}
86EXPORT_SYMBOL_GPL(ide_dev_select);
84 87
85void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd) 88void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
86{ 89{
@@ -99,15 +102,6 @@ void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
99 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) 102 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
100 HIHI = 0xFF; 103 HIHI = 0xFF;
101 104
102 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
103 u16 data = (tf->hob_data << 8) | tf->data;
104
105 if (mmio)
106 writew(data, (void __iomem *)io_ports->data_addr);
107 else
108 outw(data, io_ports->data_addr);
109 }
110
111 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 105 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
112 tf_outb(tf->hob_feature, io_ports->feature_addr); 106 tf_outb(tf->hob_feature, io_ports->feature_addr);
113 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 107 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
@@ -153,23 +147,11 @@ void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
153 tf_inb = ide_inb; 147 tf_inb = ide_inb;
154 } 148 }
155 149
156 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
157 u16 data;
158
159 if (mmio)
160 data = readw((void __iomem *)io_ports->data_addr);
161 else
162 data = inw(io_ports->data_addr);
163
164 tf->data = data & 0xff;
165 tf->hob_data = (data >> 8) & 0xff;
166 }
167
168 /* be sure we're looking at the low order bits */ 150 /* be sure we're looking at the low order bits */
169 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 151 tf_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
170 152
171 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 153 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
172 tf->feature = tf_inb(io_ports->feature_addr); 154 tf->error = tf_inb(io_ports->feature_addr);
173 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 155 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
174 tf->nsect = tf_inb(io_ports->nsect_addr); 156 tf->nsect = tf_inb(io_ports->nsect_addr);
175 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 157 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -182,18 +164,18 @@ void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
182 tf->device = tf_inb(io_ports->device_addr); 164 tf->device = tf_inb(io_ports->device_addr);
183 165
184 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 166 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
185 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 167 tf_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
186 168
187 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 169 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
188 tf->hob_feature = tf_inb(io_ports->feature_addr); 170 tf->hob_error = tf_inb(io_ports->feature_addr);
189 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 171 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
190 tf->hob_nsect = tf_inb(io_ports->nsect_addr); 172 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
191 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 173 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
192 tf->hob_lbal = tf_inb(io_ports->lbal_addr); 174 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
193 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 175 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
194 tf->hob_lbam = tf_inb(io_ports->lbam_addr); 176 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
195 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 177 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
196 tf->hob_lbah = tf_inb(io_ports->lbah_addr); 178 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
197 } 179 }
198} 180}
199EXPORT_SYMBOL_GPL(ide_tf_read); 181EXPORT_SYMBOL_GPL(ide_tf_read);
@@ -225,11 +207,10 @@ void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
225 ide_hwif_t *hwif = drive->hwif; 207 ide_hwif_t *hwif = drive->hwif;
226 struct ide_io_ports *io_ports = &hwif->io_ports; 208 struct ide_io_ports *io_ports = &hwif->io_ports;
227 unsigned long data_addr = io_ports->data_addr; 209 unsigned long data_addr = io_ports->data_addr;
210 unsigned int words = (len + 1) >> 1;
228 u8 io_32bit = drive->io_32bit; 211 u8 io_32bit = drive->io_32bit;
229 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 212 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
230 213
231 len++;
232
233 if (io_32bit) { 214 if (io_32bit) {
234 unsigned long uninitialized_var(flags); 215 unsigned long uninitialized_var(flags);
235 216
@@ -238,27 +219,26 @@ void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
238 ata_vlb_sync(io_ports->nsect_addr); 219 ata_vlb_sync(io_ports->nsect_addr);
239 } 220 }
240 221
222 words >>= 1;
241 if (mmio) 223 if (mmio)
242 __ide_mm_insl((void __iomem *)data_addr, buf, len / 4); 224 __ide_mm_insl((void __iomem *)data_addr, buf, words);
243 else 225 else
244 insl(data_addr, buf, len / 4); 226 insl(data_addr, buf, words);
245 227
246 if ((io_32bit & 2) && !mmio) 228 if ((io_32bit & 2) && !mmio)
247 local_irq_restore(flags); 229 local_irq_restore(flags);
248 230
249 if ((len & 3) >= 2) { 231 if (((len + 1) & 3) < 2)
250 if (mmio) 232 return;
251 __ide_mm_insw((void __iomem *)data_addr, 233
252 (u8 *)buf + (len & ~3), 1); 234 buf += len & ~3;
253 else 235 words = 1;
254 insw(data_addr, (u8 *)buf + (len & ~3), 1);
255 }
256 } else {
257 if (mmio)
258 __ide_mm_insw((void __iomem *)data_addr, buf, len / 2);
259 else
260 insw(data_addr, buf, len / 2);
261 } 236 }
237
238 if (mmio)
239 __ide_mm_insw((void __iomem *)data_addr, buf, words);
240 else
241 insw(data_addr, buf, words);
262} 242}
263EXPORT_SYMBOL_GPL(ide_input_data); 243EXPORT_SYMBOL_GPL(ide_input_data);
264 244
@@ -271,11 +251,10 @@ void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
271 ide_hwif_t *hwif = drive->hwif; 251 ide_hwif_t *hwif = drive->hwif;
272 struct ide_io_ports *io_ports = &hwif->io_ports; 252 struct ide_io_ports *io_ports = &hwif->io_ports;
273 unsigned long data_addr = io_ports->data_addr; 253 unsigned long data_addr = io_ports->data_addr;
254 unsigned int words = (len + 1) >> 1;
274 u8 io_32bit = drive->io_32bit; 255 u8 io_32bit = drive->io_32bit;
275 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 256 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
276 257
277 len++;
278
279 if (io_32bit) { 258 if (io_32bit) {
280 unsigned long uninitialized_var(flags); 259 unsigned long uninitialized_var(flags);
281 260
@@ -284,27 +263,26 @@ void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
284 ata_vlb_sync(io_ports->nsect_addr); 263 ata_vlb_sync(io_ports->nsect_addr);
285 } 264 }
286 265
266 words >>= 1;
287 if (mmio) 267 if (mmio)
288 __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4); 268 __ide_mm_outsl((void __iomem *)data_addr, buf, words);
289 else 269 else
290 outsl(data_addr, buf, len / 4); 270 outsl(data_addr, buf, words);
291 271
292 if ((io_32bit & 2) && !mmio) 272 if ((io_32bit & 2) && !mmio)
293 local_irq_restore(flags); 273 local_irq_restore(flags);
294 274
295 if ((len & 3) >= 2) { 275 if (((len + 1) & 3) < 2)
296 if (mmio) 276 return;
297 __ide_mm_outsw((void __iomem *)data_addr, 277
298 (u8 *)buf + (len & ~3), 1); 278 buf += len & ~3;
299 else 279 words = 1;
300 outsw(data_addr, (u8 *)buf + (len & ~3), 1);
301 }
302 } else {
303 if (mmio)
304 __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2);
305 else
306 outsw(data_addr, buf, len / 2);
307 } 280 }
281
282 if (mmio)
283 __ide_mm_outsw((void __iomem *)data_addr, buf, words);
284 else
285 outsw(data_addr, buf, words);
308} 286}
309EXPORT_SYMBOL_GPL(ide_output_data); 287EXPORT_SYMBOL_GPL(ide_output_data);
310 288
@@ -312,9 +290,9 @@ const struct ide_tp_ops default_tp_ops = {
312 .exec_command = ide_exec_command, 290 .exec_command = ide_exec_command,
313 .read_status = ide_read_status, 291 .read_status = ide_read_status,
314 .read_altstatus = ide_read_altstatus, 292 .read_altstatus = ide_read_altstatus,
293 .write_devctl = ide_write_devctl,
315 294
316 .set_irq = ide_set_irq, 295 .dev_select = ide_dev_select,
317
318 .tf_load = ide_tf_load, 296 .tf_load = ide_tf_load,
319 .tf_read = ide_tf_read, 297 .tf_read = ide_tf_read,
320 298
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 1adc5e2e7fb3..1deb6d29b186 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -73,6 +73,7 @@ EXPORT_SYMBOL_GPL(ide_end_rq);
73 73
74void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err) 74void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
75{ 75{
76 const struct ide_tp_ops *tp_ops = drive->hwif->tp_ops;
76 struct ide_taskfile *tf = &cmd->tf; 77 struct ide_taskfile *tf = &cmd->tf;
77 struct request *rq = cmd->rq; 78 struct request *rq = cmd->rq;
78 u8 tf_cmd = tf->command; 79 u8 tf_cmd = tf->command;
@@ -80,7 +81,16 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
80 tf->error = err; 81 tf->error = err;
81 tf->status = stat; 82 tf->status = stat;
82 83
83 drive->hwif->tp_ops->tf_read(drive, cmd); 84 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
85 u8 data[2];
86
87 tp_ops->input_data(drive, cmd, data, 2);
88
89 tf->data = data[0];
90 tf->hob_data = data[1];
91 }
92
93 tp_ops->tf_read(drive, cmd);
84 94
85 if ((cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) && 95 if ((cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) &&
86 tf_cmd == ATA_CMD_IDLEIMMEDIATE) { 96 tf_cmd == ATA_CMD_IDLEIMMEDIATE) {
@@ -338,7 +348,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
338 if (blk_pm_request(rq)) 348 if (blk_pm_request(rq))
339 ide_check_pm_state(drive, rq); 349 ide_check_pm_state(drive, rq);
340 350
341 SELECT_DRIVE(drive); 351 drive->hwif->tp_ops->dev_select(drive);
342 if (ide_wait_stat(&startstop, drive, drive->ready_stat, 352 if (ide_wait_stat(&startstop, drive, drive->ready_stat,
343 ATA_BUSY | ATA_DRQ, WAIT_READY)) { 353 ATA_BUSY | ATA_DRQ, WAIT_READY)) {
344 printk(KERN_ERR "%s: drive not ready for command\n", drive->name); 354 printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
@@ -481,11 +491,10 @@ repeat:
481 prev_port = hwif->host->cur_port; 491 prev_port = hwif->host->cur_port;
482 hwif->rq = NULL; 492 hwif->rq = NULL;
483 493
484 if (drive->dev_flags & IDE_DFLAG_SLEEPING) { 494 if (drive->dev_flags & IDE_DFLAG_SLEEPING &&
485 if (time_before(drive->sleep, jiffies)) { 495 time_after(drive->sleep, jiffies)) {
486 ide_unlock_port(hwif); 496 ide_unlock_port(hwif);
487 goto plug_device; 497 goto plug_device;
488 }
489 } 498 }
490 499
491 if ((hwif->host->host_flags & IDE_HFLAG_SERIALIZE) && 500 if ((hwif->host->host_flags & IDE_HFLAG_SERIALIZE) &&
@@ -495,7 +504,9 @@ repeat:
495 * quirk_list may not like intr setups/cleanups 504 * quirk_list may not like intr setups/cleanups
496 */ 505 */
497 if (prev_port && prev_port->cur_dev->quirk_list == 0) 506 if (prev_port && prev_port->cur_dev->quirk_list == 0)
498 prev_port->tp_ops->set_irq(prev_port, 0); 507 prev_port->tp_ops->write_devctl(prev_port,
508 ATA_NIEN |
509 ATA_DEVCTL_OBS);
499 510
500 hwif->host->cur_port = hwif; 511 hwif->host->cur_port = hwif;
501 } 512 }
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 5403e4a44be4..27bb70ddd459 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -27,21 +27,6 @@
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <asm/io.h> 28#include <asm/io.h>
29 29
30void SELECT_DRIVE(ide_drive_t *drive)
31{
32 ide_hwif_t *hwif = drive->hwif;
33 const struct ide_port_ops *port_ops = hwif->port_ops;
34 struct ide_cmd cmd;
35
36 if (port_ops && port_ops->selectproc)
37 port_ops->selectproc(drive);
38
39 memset(&cmd, 0, sizeof(cmd));
40 cmd.tf_flags = IDE_TFLAG_OUT_DEVICE;
41
42 drive->hwif->tp_ops->tf_load(drive, &cmd);
43}
44
45void SELECT_MASK(ide_drive_t *drive, int mask) 30void SELECT_MASK(ide_drive_t *drive, int mask)
46{ 31{
47 const struct ide_port_ops *port_ops = drive->hwif->port_ops; 32 const struct ide_port_ops *port_ops = drive->hwif->port_ops;
@@ -55,7 +40,7 @@ u8 ide_read_error(ide_drive_t *drive)
55 struct ide_cmd cmd; 40 struct ide_cmd cmd;
56 41
57 memset(&cmd, 0, sizeof(cmd)); 42 memset(&cmd, 0, sizeof(cmd));
58 cmd.tf_flags = IDE_TFLAG_IN_FEATURE; 43 cmd.tf_flags = IDE_TFLAG_IN_ERROR;
59 44
60 drive->hwif->tp_ops->tf_read(drive, &cmd); 45 drive->hwif->tp_ops->tf_read(drive, &cmd);
61 46
@@ -306,6 +291,7 @@ int ide_driveid_update(ide_drive_t *drive)
306 drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES]; 291 drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES];
307 drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES]; 292 drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES];
308 drive->id[ATA_ID_SWDMA_MODES] = id[ATA_ID_SWDMA_MODES]; 293 drive->id[ATA_ID_SWDMA_MODES] = id[ATA_ID_SWDMA_MODES];
294 drive->id[ATA_ID_CFA_MODES] = id[ATA_ID_CFA_MODES];
309 /* anything more ? */ 295 /* anything more ? */
310 296
311 kfree(id); 297 kfree(id);
@@ -356,10 +342,10 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
356 disable_irq_nosync(hwif->irq); 342 disable_irq_nosync(hwif->irq);
357 343
358 udelay(1); 344 udelay(1);
359 SELECT_DRIVE(drive); 345 tp_ops->dev_select(drive);
360 SELECT_MASK(drive, 1); 346 SELECT_MASK(drive, 1);
361 udelay(1); 347 udelay(1);
362 tp_ops->set_irq(hwif, 0); 348 tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
363 349
364 memset(&cmd, 0, sizeof(cmd)); 350 memset(&cmd, 0, sizeof(cmd));
365 cmd.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT; 351 cmd.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT;
@@ -371,7 +357,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
371 tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES); 357 tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES);
372 358
373 if (drive->quirk_list == 2) 359 if (drive->quirk_list == 2)
374 tp_ops->set_irq(hwif, 1); 360 tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
375 361
376 error = __ide_wait_stat(drive, drive->ready_stat, 362 error = __ide_wait_stat(drive, drive->ready_stat,
377 ATA_BUSY | ATA_DRQ | ATA_ERR, 363 ATA_BUSY | ATA_DRQ | ATA_ERR,
@@ -386,9 +372,14 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
386 return error; 372 return error;
387 } 373 }
388 374
389 id[ATA_ID_UDMA_MODES] &= ~0xFF00; 375 if (speed >= XFER_SW_DMA_0) {
390 id[ATA_ID_MWDMA_MODES] &= ~0x0F00; 376 id[ATA_ID_UDMA_MODES] &= ~0xFF00;
391 id[ATA_ID_SWDMA_MODES] &= ~0x0F00; 377 id[ATA_ID_MWDMA_MODES] &= ~0x0700;
378 id[ATA_ID_SWDMA_MODES] &= ~0x0700;
379 if (ata_id_is_cfa(id))
380 id[ATA_ID_CFA_MODES] &= ~0x0E00;
381 } else if (ata_id_is_cfa(id))
382 id[ATA_ID_CFA_MODES] &= ~0x01C0;
392 383
393 skip: 384 skip:
394#ifdef CONFIG_BLK_DEV_IDEDMA 385#ifdef CONFIG_BLK_DEV_IDEDMA
@@ -401,12 +392,18 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
401 if (speed >= XFER_UDMA_0) { 392 if (speed >= XFER_UDMA_0) {
402 i = 1 << (speed - XFER_UDMA_0); 393 i = 1 << (speed - XFER_UDMA_0);
403 id[ATA_ID_UDMA_MODES] |= (i << 8 | i); 394 id[ATA_ID_UDMA_MODES] |= (i << 8 | i);
395 } else if (ata_id_is_cfa(id) && speed >= XFER_MW_DMA_3) {
396 i = speed - XFER_MW_DMA_2;
397 id[ATA_ID_CFA_MODES] |= i << 9;
404 } else if (speed >= XFER_MW_DMA_0) { 398 } else if (speed >= XFER_MW_DMA_0) {
405 i = 1 << (speed - XFER_MW_DMA_0); 399 i = 1 << (speed - XFER_MW_DMA_0);
406 id[ATA_ID_MWDMA_MODES] |= (i << 8 | i); 400 id[ATA_ID_MWDMA_MODES] |= (i << 8 | i);
407 } else if (speed >= XFER_SW_DMA_0) { 401 } else if (speed >= XFER_SW_DMA_0) {
408 i = 1 << (speed - XFER_SW_DMA_0); 402 i = 1 << (speed - XFER_SW_DMA_0);
409 id[ATA_ID_SWDMA_MODES] |= (i << 8 | i); 403 id[ATA_ID_SWDMA_MODES] |= (i << 8 | i);
404 } else if (ata_id_is_cfa(id) && speed >= XFER_PIO_5) {
405 i = speed - XFER_PIO_4;
406 id[ATA_ID_CFA_MODES] |= i << 6;
410 } 407 }
411 408
412 if (!drive->init_speed) 409 if (!drive->init_speed)
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index ebf2d21ebdcb..bb7858ebb7d1 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -223,6 +223,7 @@ void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
223 * point. 223 * point.
224 */ 224 */
225 ide_hwif_t *hwif = drive->hwif; 225 ide_hwif_t *hwif = drive->hwif;
226 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
226 struct request_queue *q = drive->queue; 227 struct request_queue *q = drive->queue;
227 unsigned long flags; 228 unsigned long flags;
228 int rc; 229 int rc;
@@ -232,8 +233,8 @@ void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
232 rc = ide_wait_not_busy(hwif, 35000); 233 rc = ide_wait_not_busy(hwif, 35000);
233 if (rc) 234 if (rc)
234 printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name); 235 printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
235 SELECT_DRIVE(drive); 236 tp_ops->dev_select(drive);
236 hwif->tp_ops->set_irq(hwif, 1); 237 tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
237 rc = ide_wait_not_busy(hwif, 100000); 238 rc = ide_wait_not_busy(hwif, 100000);
238 if (rc) 239 if (rc)
239 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name); 240 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 548864510ba9..d8c1c3e735bb 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -260,7 +260,7 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
260 * during the identify phase that the IRQ handler isn't expecting. 260 * during the identify phase that the IRQ handler isn't expecting.
261 */ 261 */
262 if (io_ports->ctl_addr) 262 if (io_ports->ctl_addr)
263 tp_ops->set_irq(hwif, 0); 263 tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
264 264
265 /* take a deep breath */ 265 /* take a deep breath */
266 msleep(50); 266 msleep(50);
@@ -390,13 +390,13 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
390 * (e.g. crw9624 as drive0 with disk as slave) 390 * (e.g. crw9624 as drive0 with disk as slave)
391 */ 391 */
392 msleep(50); 392 msleep(50);
393 SELECT_DRIVE(drive); 393 tp_ops->dev_select(drive);
394 msleep(50); 394 msleep(50);
395 395
396 if (ide_read_device(drive) != drive->select && present == 0) { 396 if (ide_read_device(drive) != drive->select && present == 0) {
397 if (drive->dn & 1) { 397 if (drive->dn & 1) {
398 /* exit with drive0 selected */ 398 /* exit with drive0 selected */
399 SELECT_DRIVE(hwif->devices[0]); 399 tp_ops->dev_select(hwif->devices[0]);
400 /* allow ATA_BUSY to assert & clear */ 400 /* allow ATA_BUSY to assert & clear */
401 msleep(50); 401 msleep(50);
402 } 402 }
@@ -422,7 +422,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
422 printk(KERN_ERR "%s: no response (status = 0x%02x), " 422 printk(KERN_ERR "%s: no response (status = 0x%02x), "
423 "resetting drive\n", drive->name, stat); 423 "resetting drive\n", drive->name, stat);
424 msleep(50); 424 msleep(50);
425 SELECT_DRIVE(drive); 425 tp_ops->dev_select(drive);
426 msleep(50); 426 msleep(50);
427 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 427 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
428 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0); 428 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0);
@@ -441,7 +441,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
441 } 441 }
442 if (drive->dn & 1) { 442 if (drive->dn & 1) {
443 /* exit with drive0 selected */ 443 /* exit with drive0 selected */
444 SELECT_DRIVE(hwif->devices[0]); 444 tp_ops->dev_select(hwif->devices[0]);
445 msleep(50); 445 msleep(50);
446 /* ensure drive irq is clear */ 446 /* ensure drive irq is clear */
447 (void)tp_ops->read_status(hwif); 447 (void)tp_ops->read_status(hwif);
@@ -605,6 +605,7 @@ out:
605 605
606static int ide_port_wait_ready(ide_hwif_t *hwif) 606static int ide_port_wait_ready(ide_hwif_t *hwif)
607{ 607{
608 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
608 ide_drive_t *drive; 609 ide_drive_t *drive;
609 int i, rc; 610 int i, rc;
610 611
@@ -627,8 +628,8 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
627 /* Ignore disks that we will not probe for later. */ 628 /* Ignore disks that we will not probe for later. */
628 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 || 629 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
629 (drive->dev_flags & IDE_DFLAG_PRESENT)) { 630 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
630 SELECT_DRIVE(drive); 631 tp_ops->dev_select(drive);
631 hwif->tp_ops->set_irq(hwif, 1); 632 tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
632 mdelay(2); 633 mdelay(2);
633 rc = ide_wait_not_busy(hwif, 35000); 634 rc = ide_wait_not_busy(hwif, 35000);
634 if (rc) 635 if (rc)
@@ -640,7 +641,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
640out: 641out:
641 /* Exit function with master reselected (let's be sane) */ 642 /* Exit function with master reselected (let's be sane) */
642 if (i) 643 if (i)
643 SELECT_DRIVE(hwif->devices[0]); 644 tp_ops->dev_select(hwif->devices[0]);
644 645
645 return rc; 646 return rc;
646} 647}
@@ -845,7 +846,7 @@ static int init_irq (ide_hwif_t *hwif)
845 irq_handler = ide_intr; 846 irq_handler = ide_intr;
846 847
847 if (io_ports->ctl_addr) 848 if (io_ports->ctl_addr)
848 hwif->tp_ops->set_irq(hwif, 1); 849 hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
849 850
850 if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif)) 851 if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif))
851 goto out_up; 852 goto out_up;
@@ -942,20 +943,16 @@ EXPORT_SYMBOL_GPL(ide_init_disk);
942static void drive_release_dev (struct device *dev) 943static void drive_release_dev (struct device *dev)
943{ 944{
944 ide_drive_t *drive = container_of(dev, ide_drive_t, gendev); 945 ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
945 ide_hwif_t *hwif = drive->hwif;
946 946
947 ide_proc_unregister_device(drive); 947 ide_proc_unregister_device(drive);
948 948
949 spin_lock_irq(&hwif->lock); 949 blk_cleanup_queue(drive->queue);
950 drive->queue = NULL;
951
950 kfree(drive->id); 952 kfree(drive->id);
951 drive->id = NULL; 953 drive->id = NULL;
954
952 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 955 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
953 /* Messed up locking ... */
954 spin_unlock_irq(&hwif->lock);
955 blk_cleanup_queue(drive->queue);
956 spin_lock_irq(&hwif->lock);
957 drive->queue = NULL;
958 spin_unlock_irq(&hwif->lock);
959 956
960 complete(&drive->gendev_rel_comp); 957 complete(&drive->gendev_rel_comp);
961} 958}
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 64dfa7458f8d..cb942a9b580f 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -297,19 +297,15 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
297 return tape; 297 return tape;
298} 298}
299 299
300static void idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, 300static int idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
301 unsigned int bcount) 301 unsigned int bcount)
302{ 302{
303 struct idetape_bh *bh = pc->bh; 303 struct idetape_bh *bh = pc->bh;
304 int count; 304 int count;
305 305
306 while (bcount) { 306 while (bcount) {
307 if (bh == NULL) { 307 if (bh == NULL)
308 printk(KERN_ERR "ide-tape: bh == NULL in " 308 break;
309 "idetape_input_buffers\n");
310 ide_pad_transfer(drive, 0, bcount);
311 return;
312 }
313 count = min( 309 count = min(
314 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)), 310 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
315 bcount); 311 bcount);
@@ -323,21 +319,21 @@ static void idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
323 atomic_set(&bh->b_count, 0); 319 atomic_set(&bh->b_count, 0);
324 } 320 }
325 } 321 }
322
326 pc->bh = bh; 323 pc->bh = bh;
324
325 return bcount;
327} 326}
328 327
329static void idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, 328static int idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
330 unsigned int bcount) 329 unsigned int bcount)
331{ 330{
332 struct idetape_bh *bh = pc->bh; 331 struct idetape_bh *bh = pc->bh;
333 int count; 332 int count;
334 333
335 while (bcount) { 334 while (bcount) {
336 if (bh == NULL) { 335 if (bh == NULL)
337 printk(KERN_ERR "ide-tape: bh == NULL in %s\n", 336 break;
338 __func__);
339 return;
340 }
341 count = min((unsigned int)pc->b_count, (unsigned int)bcount); 337 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
342 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count); 338 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count);
343 bcount -= count; 339 bcount -= count;
@@ -352,6 +348,8 @@ static void idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
352 } 348 }
353 } 349 }
354 } 350 }
351
352 return bcount;
355} 353}
356 354
357static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc) 355static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
@@ -563,12 +561,14 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
563static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, 561static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
564 unsigned int bcount, int write) 562 unsigned int bcount, int write)
565{ 563{
564 unsigned int bleft;
565
566 if (write) 566 if (write)
567 idetape_output_buffers(drive, pc, bcount); 567 bleft = idetape_output_buffers(drive, pc, bcount);
568 else 568 else
569 idetape_input_buffers(drive, pc, bcount); 569 bleft = idetape_input_buffers(drive, pc, bcount);
570 570
571 return bcount; 571 return bcount - bleft;
572} 572}
573 573
574/* 574/*
@@ -2014,9 +2014,13 @@ static void idetape_get_inquiry_results(ide_drive_t *drive)
2014{ 2014{
2015 idetape_tape_t *tape = drive->driver_data; 2015 idetape_tape_t *tape = drive->driver_data;
2016 struct ide_atapi_pc pc; 2016 struct ide_atapi_pc pc;
2017 u8 pc_buf[256];
2017 char fw_rev[4], vendor_id[8], product_id[16]; 2018 char fw_rev[4], vendor_id[8], product_id[16];
2018 2019
2019 idetape_create_inquiry_cmd(&pc); 2020 idetape_create_inquiry_cmd(&pc);
2021 pc.buf = &pc_buf[0];
2022 pc.buf_size = sizeof(pc_buf);
2023
2020 if (ide_queue_pc_tail(drive, tape->disk, &pc)) { 2024 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
2021 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", 2025 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
2022 tape->name); 2026 tape->name);
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 84532be97c00..243421ce40d0 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -80,8 +80,14 @@ ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *orig_cmd)
80 80
81 if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) { 81 if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
82 ide_tf_dump(drive->name, tf); 82 ide_tf_dump(drive->name, tf);
83 tp_ops->set_irq(hwif, 1); 83 tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
84 SELECT_MASK(drive, 0); 84 SELECT_MASK(drive, 0);
85
86 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
87 u8 data[2] = { tf->data, tf->hob_data };
88
89 tp_ops->output_data(drive, cmd, data, 2);
90 }
85 tp_ops->tf_load(drive, cmd); 91 tp_ops->tf_load(drive, cmd);
86 } 92 }
87 93
@@ -100,9 +106,7 @@ ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *orig_cmd)
100 ide_execute_command(drive, cmd, handler, WAIT_WORSTCASE); 106 ide_execute_command(drive, cmd, handler, WAIT_WORSTCASE);
101 return ide_started; 107 return ide_started;
102 case ATA_PROT_DMA: 108 case ATA_PROT_DMA:
103 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 || 109 if (ide_dma_prepare(drive, cmd))
104 ide_build_sglist(drive, cmd) == 0 ||
105 dma_ops->dma_setup(drive, cmd))
106 return ide_stopped; 110 return ide_stopped;
107 hwif->expiry = dma_ops->dma_timer_expiry; 111 hwif->expiry = dma_ops->dma_timer_expiry;
108 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD); 112 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD);
@@ -188,70 +192,68 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
188 return stat; 192 return stat;
189} 193}
190 194
191static void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd, 195void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
192 unsigned int write, unsigned int nr_bytes) 196 unsigned int write, unsigned int len)
193{ 197{
194 ide_hwif_t *hwif = drive->hwif; 198 ide_hwif_t *hwif = drive->hwif;
195 struct scatterlist *sg = hwif->sg_table; 199 struct scatterlist *sg = hwif->sg_table;
196 struct scatterlist *cursg = cmd->cursg; 200 struct scatterlist *cursg = cmd->cursg;
197 struct page *page; 201 struct page *page;
198#ifdef CONFIG_HIGHMEM
199 unsigned long flags; 202 unsigned long flags;
200#endif
201 unsigned int offset; 203 unsigned int offset;
202 u8 *buf; 204 u8 *buf;
203 205
204 cursg = cmd->cursg; 206 cursg = cmd->cursg;
205 if (!cursg) { 207 if (cursg == NULL)
206 cursg = sg; 208 cursg = cmd->cursg = sg;
207 cmd->cursg = sg;
208 }
209 209
210 page = sg_page(cursg); 210 while (len) {
211 offset = cursg->offset + cmd->cursg_ofs; 211 unsigned nr_bytes = min(len, cursg->length - cmd->cursg_ofs);
212 212
213 /* get the current page and offset */ 213 if (nr_bytes > PAGE_SIZE)
214 page = nth_page(page, (offset >> PAGE_SHIFT)); 214 nr_bytes = PAGE_SIZE;
215 offset %= PAGE_SIZE;
216 215
217#ifdef CONFIG_HIGHMEM 216 page = sg_page(cursg);
218 local_irq_save(flags); 217 offset = cursg->offset + cmd->cursg_ofs;
219#endif
220 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
221 218
222 cmd->nleft -= nr_bytes; 219 /* get the current page and offset */
223 cmd->cursg_ofs += nr_bytes; 220 page = nth_page(page, (offset >> PAGE_SHIFT));
221 offset %= PAGE_SIZE;
224 222
225 if (cmd->cursg_ofs == cursg->length) { 223 if (PageHighMem(page))
226 cmd->cursg = sg_next(cmd->cursg); 224 local_irq_save(flags);
227 cmd->cursg_ofs = 0;
228 }
229 225
230 /* do the actual data transfer */ 226 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
231 if (write)
232 hwif->tp_ops->output_data(drive, cmd, buf, nr_bytes);
233 else
234 hwif->tp_ops->input_data(drive, cmd, buf, nr_bytes);
235 227
236 kunmap_atomic(buf, KM_BIO_SRC_IRQ); 228 cmd->nleft -= nr_bytes;
237#ifdef CONFIG_HIGHMEM 229 cmd->cursg_ofs += nr_bytes;
238 local_irq_restore(flags);
239#endif
240}
241 230
242static void ide_pio_multi(ide_drive_t *drive, struct ide_cmd *cmd, 231 if (cmd->cursg_ofs == cursg->length) {
243 unsigned int write) 232 cursg = cmd->cursg = sg_next(cmd->cursg);
244{ 233 cmd->cursg_ofs = 0;
245 unsigned int nsect; 234 }
235
236 /* do the actual data transfer */
237 if (write)
238 hwif->tp_ops->output_data(drive, cmd, buf, nr_bytes);
239 else
240 hwif->tp_ops->input_data(drive, cmd, buf, nr_bytes);
241
242 kunmap_atomic(buf, KM_BIO_SRC_IRQ);
246 243
247 nsect = min_t(unsigned int, cmd->nleft >> 9, drive->mult_count); 244 if (PageHighMem(page))
248 while (nsect--) 245 local_irq_restore(flags);
249 ide_pio_bytes(drive, cmd, write, SECTOR_SIZE); 246
247 len -= nr_bytes;
248 }
250} 249}
250EXPORT_SYMBOL_GPL(ide_pio_bytes);
251 251
252static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd, 252static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,
253 unsigned int write) 253 unsigned int write)
254{ 254{
255 unsigned int nr_bytes;
256
255 u8 saved_io_32bit = drive->io_32bit; 257 u8 saved_io_32bit = drive->io_32bit;
256 258
257 if (cmd->tf_flags & IDE_TFLAG_FS) 259 if (cmd->tf_flags & IDE_TFLAG_FS)
@@ -263,9 +265,11 @@ static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,
263 touch_softlockup_watchdog(); 265 touch_softlockup_watchdog();
264 266
265 if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) 267 if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
266 ide_pio_multi(drive, cmd, write); 268 nr_bytes = min_t(unsigned, cmd->nleft, drive->mult_count << 9);
267 else 269 else
268 ide_pio_bytes(drive, cmd, write, SECTOR_SIZE); 270 nr_bytes = SECTOR_SIZE;
271
272 ide_pio_bytes(drive, cmd, write, nr_bytes);
269 273
270 drive->io_32bit = saved_io_32bit; 274 drive->io_32bit = saved_io_32bit;
271} 275}
diff --git a/drivers/ide/ide-timings.c b/drivers/ide/ide-timings.c
index 81f527af8fae..001a56365be5 100644
--- a/drivers/ide/ide-timings.c
+++ b/drivers/ide/ide-timings.c
@@ -43,6 +43,8 @@ static struct ide_timing ide_timing[] = {
43 { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, 43 { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 },
44 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, 44 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 },
45 45
46 { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 80, 0 },
47 { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 100, 0 },
46 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, 48 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 },
47 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, 49 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 },
48 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, 50 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 },
@@ -51,7 +53,8 @@ static struct ide_timing ide_timing[] = {
51 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, 53 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 },
52 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, 54 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 },
53 55
54 { XFER_PIO_5, 20, 50, 30, 100, 50, 30, 100, 0 }, 56 { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 80, 0 },
57 { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 100, 0 },
55 { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 }, 58 { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 },
56 { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 }, 59 { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 },
57 60
@@ -90,6 +93,10 @@ u16 ide_pio_cycle_time(ide_drive_t *drive, u8 pio)
90 /* conservative "downgrade" for all pre-ATA2 drives */ 93 /* conservative "downgrade" for all pre-ATA2 drives */
91 if (pio < 3 && cycle < t->cycle) 94 if (pio < 3 && cycle < t->cycle)
92 cycle = 0; /* use standard timing */ 95 cycle = 0; /* use standard timing */
96
97 /* Use the standard timing for the CF specific modes too */
98 if (pio > 4 && ata_id_is_cfa(id))
99 cycle = 0;
93 } 100 }
94 101
95 return cycle ? cycle : t->cycle; 102 return cycle ? cycle : t->cycle;
@@ -161,7 +168,8 @@ int ide_timing_compute(ide_drive_t *drive, u8 speed,
161 168
162 if (speed <= XFER_PIO_2) 169 if (speed <= XFER_PIO_2)
163 p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO]; 170 p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO];
164 else if (speed <= XFER_PIO_5) 171 else if ((speed <= XFER_PIO_4) ||
172 (speed == XFER_PIO_5 && !ata_id_is_cfa(id)))
165 p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY]; 173 p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY];
166 else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) 174 else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)
167 p.cycle = id[ATA_ID_EIDE_DMA_MIN]; 175 p.cycle = id[ATA_ID_EIDE_DMA_MIN];
diff --git a/drivers/ide/ide-xfer-mode.c b/drivers/ide/ide-xfer-mode.c
index 6910f6a257e8..af44be9d546c 100644
--- a/drivers/ide/ide-xfer-mode.c
+++ b/drivers/ide/ide-xfer-mode.c
@@ -9,11 +9,11 @@ static const char *udma_str[] =
9 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44", 9 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44",
10 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" }; 10 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" };
11static const char *mwdma_str[] = 11static const char *mwdma_str[] =
12 { "MWDMA0", "MWDMA1", "MWDMA2" }; 12 { "MWDMA0", "MWDMA1", "MWDMA2", "MWDMA3", "MWDMA4" };
13static const char *swdma_str[] = 13static const char *swdma_str[] =
14 { "SWDMA0", "SWDMA1", "SWDMA2" }; 14 { "SWDMA0", "SWDMA1", "SWDMA2" };
15static const char *pio_str[] = 15static const char *pio_str[] =
16 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" }; 16 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5", "PIO6" };
17 17
18/** 18/**
19 * ide_xfer_verbose - return IDE mode names 19 * ide_xfer_verbose - return IDE mode names
@@ -30,11 +30,11 @@ const char *ide_xfer_verbose(u8 mode)
30 30
31 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7) 31 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7)
32 s = udma_str[i]; 32 s = udma_str[i];
33 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2) 33 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_4)
34 s = mwdma_str[i]; 34 s = mwdma_str[i];
35 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2) 35 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2)
36 s = swdma_str[i]; 36 s = swdma_str[i];
37 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5) 37 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_6)
38 s = pio_str[i & 0x7]; 38 s = pio_str[i & 0x7];
39 else if (mode == XFER_PIO_SLOW) 39 else if (mode == XFER_PIO_SLOW)
40 s = "PIO SLOW"; 40 s = "PIO SLOW";
@@ -79,7 +79,10 @@ u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
79 } 79 }
80 80
81 if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */ 81 if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */
82 if (ata_id_has_iordy(id)) { 82 if (ata_id_is_cfa(id) && (id[ATA_ID_CFA_MODES] & 7))
83 pio_mode = 4 + min_t(int, 2,
84 id[ATA_ID_CFA_MODES] & 7);
85 else if (ata_id_has_iordy(id)) {
83 if (id[ATA_ID_PIO_MODES] & 7) { 86 if (id[ATA_ID_PIO_MODES] & 7) {
84 overridden = 0; 87 overridden = 0;
85 if (id[ATA_ID_PIO_MODES] & 4) 88 if (id[ATA_ID_PIO_MODES] & 4)
@@ -239,7 +242,7 @@ int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
239 242
240 BUG_ON(rate < XFER_PIO_0); 243 BUG_ON(rate < XFER_PIO_0);
241 244
242 if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5) 245 if (rate >= XFER_PIO_0 && rate <= XFER_PIO_6)
243 return ide_set_pio_mode(drive, rate); 246 return ide_set_pio_mode(drive, rate);
244 247
245 return ide_set_dma_mode(drive, rate); 248 return ide_set_dma_mode(drive, rate);
diff --git a/drivers/ide/ide_arm.c b/drivers/ide/ide_arm.c
deleted file mode 100644
index cf6385446ece..000000000000
--- a/drivers/ide/ide_arm.c
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 * ARM default IDE host driver
3 *
4 * Copyright (C) 2004 Bartlomiej Zolnierkiewicz
5 * Based on code by: Russell King, Ian Molton and Alexander Schulz.
6 *
7 * May be copied or modified under the terms of the GNU General Public License.
8 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/ide.h>
13
14#include <asm/irq.h>
15
16#define DRV_NAME "ide_arm"
17
18#define IDE_ARM_IO 0x1f0
19#define IDE_ARM_IRQ IRQ_HARDDISK
20
21static const struct ide_port_info ide_arm_port_info = {
22 .host_flags = IDE_HFLAG_NO_DMA,
23};
24
25static int __init ide_arm_init(void)
26{
27 unsigned long base = IDE_ARM_IO, ctl = IDE_ARM_IO + 0x206;
28 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
29
30 if (!request_region(base, 8, DRV_NAME)) {
31 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
32 DRV_NAME, base, base + 7);
33 return -EBUSY;
34 }
35
36 if (!request_region(ctl, 1, DRV_NAME)) {
37 printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
38 DRV_NAME, ctl);
39 release_region(base, 8);
40 return -EBUSY;
41 }
42
43 memset(&hw, 0, sizeof(hw));
44 ide_std_init_ports(&hw, base, ctl);
45 hw.irq = IDE_ARM_IRQ;
46 hw.chipset = ide_generic;
47
48 return ide_host_add(&ide_arm_port_info, hws, NULL);
49}
50
51module_init(ide_arm_init);
52
53MODULE_LICENSE("GPL");
diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
index 0d4ac65cf949..51aa745246dc 100644
--- a/drivers/ide/it821x.c
+++ b/drivers/ide/it821x.c
@@ -511,9 +511,8 @@ static struct ide_dma_ops it821x_pass_through_dma_ops = {
511 .dma_start = it821x_dma_start, 511 .dma_start = it821x_dma_start,
512 .dma_end = it821x_dma_end, 512 .dma_end = it821x_dma_end,
513 .dma_test_irq = ide_dma_test_irq, 513 .dma_test_irq = ide_dma_test_irq,
514 .dma_timer_expiry = ide_dma_sff_timer_expiry,
515 .dma_timeout = ide_dma_timeout,
516 .dma_lost_irq = ide_dma_lost_irq, 514 .dma_lost_irq = ide_dma_lost_irq,
515 .dma_timer_expiry = ide_dma_sff_timer_expiry,
517 .dma_sff_read_status = ide_dma_sff_read_status, 516 .dma_sff_read_status = ide_dma_sff_read_status,
518}; 517};
519 518
diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
index 7b65fe5bf449..71a39fb3856f 100644
--- a/drivers/ide/ns87415.c
+++ b/drivers/ide/ns87415.c
@@ -66,18 +66,11 @@ static void superio_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
66 struct ide_io_ports *io_ports = &drive->hwif->io_ports; 66 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
67 struct ide_taskfile *tf = &cmd->tf; 67 struct ide_taskfile *tf = &cmd->tf;
68 68
69 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
70 u16 data = inw(io_ports->data_addr);
71
72 tf->data = data & 0xff;
73 tf->hob_data = (data >> 8) & 0xff;
74 }
75
76 /* be sure we're looking at the low order bits */ 69 /* be sure we're looking at the low order bits */
77 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 70 outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
78 71
79 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 72 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
80 tf->feature = inb(io_ports->feature_addr); 73 tf->error = inb(io_ports->feature_addr);
81 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 74 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
82 tf->nsect = inb(io_ports->nsect_addr); 75 tf->nsect = inb(io_ports->nsect_addr);
83 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 76 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -90,28 +83,30 @@ static void superio_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
90 tf->device = superio_ide_inb(io_ports->device_addr); 83 tf->device = superio_ide_inb(io_ports->device_addr);
91 84
92 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 85 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
93 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 86 outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
94 87
95 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 88 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
96 tf->hob_feature = inb(io_ports->feature_addr); 89 tf->hob_error = inb(io_ports->feature_addr);
97 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 90 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
98 tf->hob_nsect = inb(io_ports->nsect_addr); 91 tf->hob_nsect = inb(io_ports->nsect_addr);
99 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 92 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
100 tf->hob_lbal = inb(io_ports->lbal_addr); 93 tf->hob_lbal = inb(io_ports->lbal_addr);
101 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 94 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
102 tf->hob_lbam = inb(io_ports->lbam_addr); 95 tf->hob_lbam = inb(io_ports->lbam_addr);
103 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 96 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
104 tf->hob_lbah = inb(io_ports->lbah_addr); 97 tf->hob_lbah = inb(io_ports->lbah_addr);
105 } 98 }
106} 99}
107 100
101static void ns87415_dev_select(ide_drive_t *drive);
102
108static const struct ide_tp_ops superio_tp_ops = { 103static const struct ide_tp_ops superio_tp_ops = {
109 .exec_command = ide_exec_command, 104 .exec_command = ide_exec_command,
110 .read_status = superio_read_status, 105 .read_status = superio_read_status,
111 .read_altstatus = ide_read_altstatus, 106 .read_altstatus = ide_read_altstatus,
107 .write_devctl = ide_write_devctl,
112 108
113 .set_irq = ide_set_irq, 109 .dev_select = ns87415_dev_select,
114
115 .tf_load = ide_tf_load, 110 .tf_load = ide_tf_load,
116 .tf_read = superio_tf_read, 111 .tf_read = superio_tf_read,
117 112
@@ -190,10 +185,18 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
190 local_irq_restore(flags); 185 local_irq_restore(flags);
191} 186}
192 187
193static void ns87415_selectproc (ide_drive_t *drive) 188static void ns87415_dev_select(ide_drive_t *drive)
194{ 189{
195 ns87415_prepare_drive(drive, 190 ns87415_prepare_drive(drive,
196 !!(drive->dev_flags & IDE_DFLAG_USING_DMA)); 191 !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
192
193 outb(drive->select | ATA_DEVICE_OBS, drive->hwif->io_ports.device_addr);
194}
195
196static void ns87415_dma_start(ide_drive_t *drive)
197{
198 ns87415_prepare_drive(drive, 1);
199 ide_dma_start(drive);
197} 200}
198 201
199static int ns87415_dma_end(ide_drive_t *drive) 202static int ns87415_dma_end(ide_drive_t *drive)
@@ -201,7 +204,6 @@ static int ns87415_dma_end(ide_drive_t *drive)
201 ide_hwif_t *hwif = drive->hwif; 204 ide_hwif_t *hwif = drive->hwif;
202 u8 dma_stat = 0, dma_cmd = 0; 205 u8 dma_stat = 0, dma_cmd = 0;
203 206
204 drive->waiting_for_dma = 0;
205 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); 207 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
206 /* get DMA command mode */ 208 /* get DMA command mode */
207 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); 209 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
@@ -210,21 +212,11 @@ static int ns87415_dma_end(ide_drive_t *drive)
210 /* from ERRATA: clear the INTR & ERROR bits */ 212 /* from ERRATA: clear the INTR & ERROR bits */
211 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); 213 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
212 outb(dma_cmd | 6, hwif->dma_base + ATA_DMA_CMD); 214 outb(dma_cmd | 6, hwif->dma_base + ATA_DMA_CMD);
213 /* and free any DMA resources */
214 ide_destroy_dmatable(drive);
215 /* verify good DMA status */
216 return (dma_stat & 7) != 4;
217}
218 215
219static int ns87415_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
220{
221 /* select DMA xfer */
222 ns87415_prepare_drive(drive, 1);
223 if (ide_dma_setup(drive, cmd) == 0)
224 return 0;
225 /* DMA failed: select PIO xfer */
226 ns87415_prepare_drive(drive, 0); 216 ns87415_prepare_drive(drive, 0);
227 return 1; 217
218 /* verify good DMA status */
219 return (dma_stat & 7) != 4;
228} 220}
229 221
230static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif) 222static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
@@ -242,7 +234,7 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
242 * Also, leave IRQ masked during drive probing, to prevent infinite 234 * Also, leave IRQ masked during drive probing, to prevent infinite
243 * interrupts from a potentially floating INTA.. 235 * interrupts from a potentially floating INTA..
244 * 236 *
245 * IRQs get unmasked in selectproc when drive is first used. 237 * IRQs get unmasked in dev_select() when drive is first used.
246 */ 238 */
247 (void) pci_read_config_dword(dev, 0x40, &ctrl); 239 (void) pci_read_config_dword(dev, 0x40, &ctrl);
248 (void) pci_read_config_byte(dev, 0x09, &progif); 240 (void) pci_read_config_byte(dev, 0x09, &progif);
@@ -270,7 +262,7 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
270#ifdef __sparc_v9__ 262#ifdef __sparc_v9__
271 /* 263 /*
272 * XXX: Reset the device, if we don't it will not respond to 264 * XXX: Reset the device, if we don't it will not respond to
273 * SELECT_DRIVE() properly during first ide_probe_port(). 265 * dev_select() properly during first ide_probe_port().
274 */ 266 */
275 timeout = 10000; 267 timeout = 10000;
276 outb(12, hwif->io_ports.ctl_addr); 268 outb(12, hwif->io_ports.ctl_addr);
@@ -294,26 +286,35 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
294 outb(0x60, hwif->dma_base + ATA_DMA_STATUS); 286 outb(0x60, hwif->dma_base + ATA_DMA_STATUS);
295} 287}
296 288
297static const struct ide_port_ops ns87415_port_ops = { 289static const struct ide_tp_ops ns87415_tp_ops = {
298 .selectproc = ns87415_selectproc, 290 .exec_command = ide_exec_command,
291 .read_status = ide_read_status,
292 .read_altstatus = ide_read_altstatus,
293 .write_devctl = ide_write_devctl,
294
295 .dev_select = ns87415_dev_select,
296 .tf_load = ide_tf_load,
297 .tf_read = ide_tf_read,
298
299 .input_data = ide_input_data,
300 .output_data = ide_output_data,
299}; 301};
300 302
301static const struct ide_dma_ops ns87415_dma_ops = { 303static const struct ide_dma_ops ns87415_dma_ops = {
302 .dma_host_set = ide_dma_host_set, 304 .dma_host_set = ide_dma_host_set,
303 .dma_setup = ns87415_dma_setup, 305 .dma_setup = ide_dma_setup,
304 .dma_start = ide_dma_start, 306 .dma_start = ns87415_dma_start,
305 .dma_end = ns87415_dma_end, 307 .dma_end = ns87415_dma_end,
306 .dma_test_irq = ide_dma_test_irq, 308 .dma_test_irq = ide_dma_test_irq,
307 .dma_lost_irq = ide_dma_lost_irq, 309 .dma_lost_irq = ide_dma_lost_irq,
308 .dma_timer_expiry = ide_dma_sff_timer_expiry, 310 .dma_timer_expiry = ide_dma_sff_timer_expiry,
309 .dma_timeout = ide_dma_timeout,
310 .dma_sff_read_status = superio_dma_sff_read_status, 311 .dma_sff_read_status = superio_dma_sff_read_status,
311}; 312};
312 313
313static const struct ide_port_info ns87415_chipset __devinitdata = { 314static const struct ide_port_info ns87415_chipset __devinitdata = {
314 .name = DRV_NAME, 315 .name = DRV_NAME,
315 .init_hwif = init_hwif_ns87415, 316 .init_hwif = init_hwif_ns87415,
316 .port_ops = &ns87415_port_ops, 317 .tp_ops = &ns87415_tp_ops,
317 .dma_ops = &ns87415_dma_ops, 318 .dma_ops = &ns87415_dma_ops,
318 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 319 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA |
319 IDE_HFLAG_NO_ATAPI_DMA, 320 IDE_HFLAG_NO_ATAPI_DMA,
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index f7536d1943f7..248a54bd2386 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -258,12 +258,6 @@ static void pdc202xx_dma_lost_irq(ide_drive_t *drive)
258 ide_dma_lost_irq(drive); 258 ide_dma_lost_irq(drive);
259} 259}
260 260
261static void pdc202xx_dma_timeout(ide_drive_t *drive)
262{
263 pdc202xx_reset(drive);
264 ide_dma_timeout(drive);
265}
266
267static int init_chipset_pdc202xx(struct pci_dev *dev) 261static int init_chipset_pdc202xx(struct pci_dev *dev)
268{ 262{
269 unsigned long dmabase = pci_resource_start(dev, 4); 263 unsigned long dmabase = pci_resource_start(dev, 4);
@@ -336,7 +330,7 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
336 .dma_test_irq = pdc202xx_dma_test_irq, 330 .dma_test_irq = pdc202xx_dma_test_irq,
337 .dma_lost_irq = pdc202xx_dma_lost_irq, 331 .dma_lost_irq = pdc202xx_dma_lost_irq,
338 .dma_timer_expiry = ide_dma_sff_timer_expiry, 332 .dma_timer_expiry = ide_dma_sff_timer_expiry,
339 .dma_timeout = pdc202xx_dma_timeout, 333 .dma_clear = pdc202xx_reset,
340 .dma_sff_read_status = ide_dma_sff_read_status, 334 .dma_sff_read_status = ide_dma_sff_read_status,
341}; 335};
342 336
@@ -348,7 +342,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
348 .dma_test_irq = pdc202xx_dma_test_irq, 342 .dma_test_irq = pdc202xx_dma_test_irq,
349 .dma_lost_irq = pdc202xx_dma_lost_irq, 343 .dma_lost_irq = pdc202xx_dma_lost_irq,
350 .dma_timer_expiry = ide_dma_sff_timer_expiry, 344 .dma_timer_expiry = ide_dma_sff_timer_expiry,
351 .dma_timeout = pdc202xx_dma_timeout, 345 .dma_clear = pdc202xx_reset,
352 .dma_sff_read_status = ide_dma_sff_read_status, 346 .dma_sff_read_status = ide_dma_sff_read_status,
353}; 347};
354 348
diff --git a/drivers/ide/pmac.c b/drivers/ide/pmac.c
index 2bfcfedaa076..052b9bf1f8fb 100644
--- a/drivers/ide/pmac.c
+++ b/drivers/ide/pmac.c
@@ -404,8 +404,6 @@ kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
404#define IDE_WAKEUP_DELAY (1*HZ) 404#define IDE_WAKEUP_DELAY (1*HZ)
405 405
406static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *); 406static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *);
407static void pmac_ide_selectproc(ide_drive_t *drive);
408static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
409 407
410#define PMAC_IDE_REG(x) \ 408#define PMAC_IDE_REG(x) \
411 ((void __iomem *)((drive)->hwif->io_ports.data_addr + (x))) 409 ((void __iomem *)((drive)->hwif->io_ports.data_addr + (x)))
@@ -415,8 +413,7 @@ static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
415 * timing register when selecting that unit. This version is for 413 * timing register when selecting that unit. This version is for
416 * ASICs with a single timing register 414 * ASICs with a single timing register
417 */ 415 */
418static void 416static void pmac_ide_apply_timings(ide_drive_t *drive)
419pmac_ide_selectproc(ide_drive_t *drive)
420{ 417{
421 ide_hwif_t *hwif = drive->hwif; 418 ide_hwif_t *hwif = drive->hwif;
422 pmac_ide_hwif_t *pmif = 419 pmac_ide_hwif_t *pmif =
@@ -434,8 +431,7 @@ pmac_ide_selectproc(ide_drive_t *drive)
434 * timing register when selecting that unit. This version is for 431 * timing register when selecting that unit. This version is for
435 * ASICs with a dual timing register (Kauai) 432 * ASICs with a dual timing register (Kauai)
436 */ 433 */
437static void 434static void pmac_ide_kauai_apply_timings(ide_drive_t *drive)
438pmac_ide_kauai_selectproc(ide_drive_t *drive)
439{ 435{
440 ide_hwif_t *hwif = drive->hwif; 436 ide_hwif_t *hwif = drive->hwif;
441 pmac_ide_hwif_t *pmif = 437 pmac_ide_hwif_t *pmif =
@@ -464,9 +460,25 @@ pmac_ide_do_update_timings(ide_drive_t *drive)
464 if (pmif->kind == controller_sh_ata6 || 460 if (pmif->kind == controller_sh_ata6 ||
465 pmif->kind == controller_un_ata6 || 461 pmif->kind == controller_un_ata6 ||
466 pmif->kind == controller_k2_ata6) 462 pmif->kind == controller_k2_ata6)
467 pmac_ide_kauai_selectproc(drive); 463 pmac_ide_kauai_apply_timings(drive);
468 else 464 else
469 pmac_ide_selectproc(drive); 465 pmac_ide_apply_timings(drive);
466}
467
468static void pmac_dev_select(ide_drive_t *drive)
469{
470 pmac_ide_apply_timings(drive);
471
472 writeb(drive->select | ATA_DEVICE_OBS,
473 (void __iomem *)drive->hwif->io_ports.device_addr);
474}
475
476static void pmac_kauai_dev_select(ide_drive_t *drive)
477{
478 pmac_ide_kauai_apply_timings(drive);
479
480 writeb(drive->select | ATA_DEVICE_OBS,
481 (void __iomem *)drive->hwif->io_ports.device_addr);
470} 482}
471 483
472static void pmac_exec_command(ide_hwif_t *hwif, u8 cmd) 484static void pmac_exec_command(ide_hwif_t *hwif, u8 cmd)
@@ -476,17 +488,8 @@ static void pmac_exec_command(ide_hwif_t *hwif, u8 cmd)
476 + IDE_TIMING_CONFIG)); 488 + IDE_TIMING_CONFIG));
477} 489}
478 490
479static void pmac_set_irq(ide_hwif_t *hwif, int on) 491static void pmac_write_devctl(ide_hwif_t *hwif, u8 ctl)
480{ 492{
481 u8 ctl = ATA_DEVCTL_OBS;
482
483 if (on == 4) { /* hack for SRST */
484 ctl |= 4;
485 on &= ~4;
486 }
487
488 ctl |= on ? 0 : 2;
489
490 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr); 493 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
491 (void)readl((void __iomem *)(hwif->io_ports.data_addr 494 (void)readl((void __iomem *)(hwif->io_ports.data_addr
492 + IDE_TIMING_CONFIG)); 495 + IDE_TIMING_CONFIG));
@@ -916,10 +919,18 @@ static u8 pmac_ide_cable_detect(ide_hwif_t *hwif)
916 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 919 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
917 struct device_node *np = pmif->node; 920 struct device_node *np = pmif->node;
918 const char *cable = of_get_property(np, "cable-type", NULL); 921 const char *cable = of_get_property(np, "cable-type", NULL);
922 struct device_node *root = of_find_node_by_path("/");
923 const char *model = of_get_property(root, "model", NULL);
919 924
920 /* Get cable type from device-tree. */ 925 /* Get cable type from device-tree. */
921 if (cable && !strncmp(cable, "80-", 3)) 926 if (cable && !strncmp(cable, "80-", 3)) {
922 return ATA_CBL_PATA80; 927 /* Some drives fail to detect 80c cable in PowerBook */
928 /* These machine use proprietary short IDE cable anyway */
929 if (!strncmp(model, "PowerBook", 9))
930 return ATA_CBL_PATA40_SHORT;
931 else
932 return ATA_CBL_PATA80;
933 }
923 934
924 /* 935 /*
925 * G5's seem to have incorrect cable type in device-tree. 936 * G5's seem to have incorrect cable type in device-tree.
@@ -954,9 +965,9 @@ static const struct ide_tp_ops pmac_tp_ops = {
954 .exec_command = pmac_exec_command, 965 .exec_command = pmac_exec_command,
955 .read_status = ide_read_status, 966 .read_status = ide_read_status,
956 .read_altstatus = ide_read_altstatus, 967 .read_altstatus = ide_read_altstatus,
968 .write_devctl = pmac_write_devctl,
957 969
958 .set_irq = pmac_set_irq, 970 .dev_select = pmac_dev_select,
959
960 .tf_load = ide_tf_load, 971 .tf_load = ide_tf_load,
961 .tf_read = ide_tf_read, 972 .tf_read = ide_tf_read,
962 973
@@ -964,19 +975,24 @@ static const struct ide_tp_ops pmac_tp_ops = {
964 .output_data = ide_output_data, 975 .output_data = ide_output_data,
965}; 976};
966 977
967static const struct ide_port_ops pmac_ide_ata6_port_ops = { 978static const struct ide_tp_ops pmac_ata6_tp_ops = {
968 .init_dev = pmac_ide_init_dev, 979 .exec_command = pmac_exec_command,
969 .set_pio_mode = pmac_ide_set_pio_mode, 980 .read_status = ide_read_status,
970 .set_dma_mode = pmac_ide_set_dma_mode, 981 .read_altstatus = ide_read_altstatus,
971 .selectproc = pmac_ide_kauai_selectproc, 982 .write_devctl = pmac_write_devctl,
972 .cable_detect = pmac_ide_cable_detect, 983
984 .dev_select = pmac_kauai_dev_select,
985 .tf_load = ide_tf_load,
986 .tf_read = ide_tf_read,
987
988 .input_data = ide_input_data,
989 .output_data = ide_output_data,
973}; 990};
974 991
975static const struct ide_port_ops pmac_ide_ata4_port_ops = { 992static const struct ide_port_ops pmac_ide_ata4_port_ops = {
976 .init_dev = pmac_ide_init_dev, 993 .init_dev = pmac_ide_init_dev,
977 .set_pio_mode = pmac_ide_set_pio_mode, 994 .set_pio_mode = pmac_ide_set_pio_mode,
978 .set_dma_mode = pmac_ide_set_dma_mode, 995 .set_dma_mode = pmac_ide_set_dma_mode,
979 .selectproc = pmac_ide_selectproc,
980 .cable_detect = pmac_ide_cable_detect, 996 .cable_detect = pmac_ide_cable_detect,
981}; 997};
982 998
@@ -984,7 +1000,6 @@ static const struct ide_port_ops pmac_ide_port_ops = {
984 .init_dev = pmac_ide_init_dev, 1000 .init_dev = pmac_ide_init_dev,
985 .set_pio_mode = pmac_ide_set_pio_mode, 1001 .set_pio_mode = pmac_ide_set_pio_mode,
986 .set_dma_mode = pmac_ide_set_dma_mode, 1002 .set_dma_mode = pmac_ide_set_dma_mode,
987 .selectproc = pmac_ide_selectproc,
988}; 1003};
989 1004
990static const struct ide_dma_ops pmac_dma_ops; 1005static const struct ide_dma_ops pmac_dma_ops;
@@ -1021,15 +1036,18 @@ static int __devinit pmac_ide_setup_device(pmac_ide_hwif_t *pmif, hw_regs_t *hw)
1021 pmif->broken_dma = pmif->broken_dma_warn = 0; 1036 pmif->broken_dma = pmif->broken_dma_warn = 0;
1022 if (of_device_is_compatible(np, "shasta-ata")) { 1037 if (of_device_is_compatible(np, "shasta-ata")) {
1023 pmif->kind = controller_sh_ata6; 1038 pmif->kind = controller_sh_ata6;
1024 d.port_ops = &pmac_ide_ata6_port_ops; 1039 d.tp_ops = &pmac_ata6_tp_ops;
1040 d.port_ops = &pmac_ide_ata4_port_ops;
1025 d.udma_mask = ATA_UDMA6; 1041 d.udma_mask = ATA_UDMA6;
1026 } else if (of_device_is_compatible(np, "kauai-ata")) { 1042 } else if (of_device_is_compatible(np, "kauai-ata")) {
1027 pmif->kind = controller_un_ata6; 1043 pmif->kind = controller_un_ata6;
1028 d.port_ops = &pmac_ide_ata6_port_ops; 1044 d.tp_ops = &pmac_ata6_tp_ops;
1045 d.port_ops = &pmac_ide_ata4_port_ops;
1029 d.udma_mask = ATA_UDMA5; 1046 d.udma_mask = ATA_UDMA5;
1030 } else if (of_device_is_compatible(np, "K2-UATA")) { 1047 } else if (of_device_is_compatible(np, "K2-UATA")) {
1031 pmif->kind = controller_k2_ata6; 1048 pmif->kind = controller_k2_ata6;
1032 d.port_ops = &pmac_ide_ata6_port_ops; 1049 d.tp_ops = &pmac_ata6_tp_ops;
1050 d.port_ops = &pmac_ide_ata4_port_ops;
1033 d.udma_mask = ATA_UDMA5; 1051 d.udma_mask = ATA_UDMA5;
1034 } else if (of_device_is_compatible(np, "keylargo-ata")) { 1052 } else if (of_device_is_compatible(np, "keylargo-ata")) {
1035 if (strcmp(np->name, "ata-4") == 0) { 1053 if (strcmp(np->name, "ata-4") == 0) {
@@ -1455,7 +1473,7 @@ static int pmac_ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
1455 "switching to PIO on Ohare chipset\n", drive->name); 1473 "switching to PIO on Ohare chipset\n", drive->name);
1456 pmif->broken_dma_warn = 1; 1474 pmif->broken_dma_warn = 1;
1457 } 1475 }
1458 goto use_pio_instead; 1476 return 0;
1459 } 1477 }
1460 while (cur_len) { 1478 while (cur_len) {
1461 unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00; 1479 unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
@@ -1463,7 +1481,7 @@ static int pmac_ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
1463 if (count++ >= MAX_DCMDS) { 1481 if (count++ >= MAX_DCMDS) {
1464 printk(KERN_WARNING "%s: DMA table too small\n", 1482 printk(KERN_WARNING "%s: DMA table too small\n",
1465 drive->name); 1483 drive->name);
1466 goto use_pio_instead; 1484 return 0;
1467 } 1485 }
1468 st_le16(&table->command, wr? OUTPUT_MORE: INPUT_MORE); 1486 st_le16(&table->command, wr? OUTPUT_MORE: INPUT_MORE);
1469 st_le16(&table->req_count, tc); 1487 st_le16(&table->req_count, tc);
@@ -1492,9 +1510,6 @@ static int pmac_ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
1492 1510
1493 printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name); 1511 printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name);
1494 1512
1495use_pio_instead:
1496 ide_destroy_dmatable(drive);
1497
1498 return 0; /* revert to PIO for this request */ 1513 return 0; /* revert to PIO for this request */
1499} 1514}
1500 1515
@@ -1510,10 +1525,8 @@ static int pmac_ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
1510 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4); 1525 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
1511 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE); 1526 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
1512 1527
1513 if (pmac_ide_build_dmatable(drive, cmd) == 0) { 1528 if (pmac_ide_build_dmatable(drive, cmd) == 0)
1514 ide_map_sg(drive, cmd);
1515 return 1; 1529 return 1;
1516 }
1517 1530
1518 /* Apple adds 60ns to wrDataSetup on reads */ 1531 /* Apple adds 60ns to wrDataSetup on reads */
1519 if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) { 1532 if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) {
@@ -1522,8 +1535,6 @@ static int pmac_ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
1522 (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG)); 1535 (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
1523 } 1536 }
1524 1537
1525 drive->waiting_for_dma = 1;
1526
1527 return 0; 1538 return 0;
1528} 1539}
1529 1540
@@ -1558,12 +1569,9 @@ pmac_ide_dma_end (ide_drive_t *drive)
1558 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs; 1569 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1559 u32 dstat; 1570 u32 dstat;
1560 1571
1561 drive->waiting_for_dma = 0;
1562 dstat = readl(&dma->status); 1572 dstat = readl(&dma->status);
1563 writel(((RUN|WAKE|DEAD) << 16), &dma->control); 1573 writel(((RUN|WAKE|DEAD) << 16), &dma->control);
1564 1574
1565 ide_destroy_dmatable(drive);
1566
1567 /* verify good dma status. we don't check for ACTIVE beeing 0. We should... 1575 /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
1568 * in theory, but with ATAPI decices doing buffer underruns, that would 1576 * in theory, but with ATAPI decices doing buffer underruns, that would
1569 * cause us to disable DMA, which isn't what we want 1577 * cause us to disable DMA, which isn't what we want
@@ -1650,7 +1658,6 @@ static const struct ide_dma_ops pmac_dma_ops = {
1650 .dma_start = pmac_ide_dma_start, 1658 .dma_start = pmac_ide_dma_start,
1651 .dma_end = pmac_ide_dma_end, 1659 .dma_end = pmac_ide_dma_end,
1652 .dma_test_irq = pmac_ide_dma_test_irq, 1660 .dma_test_irq = pmac_ide_dma_test_irq,
1653 .dma_timeout = ide_dma_timeout,
1654 .dma_lost_irq = pmac_ide_dma_lost_irq, 1661 .dma_lost_irq = pmac_ide_dma_lost_irq,
1655}; 1662};
1656 1663
diff --git a/drivers/ide/q40ide.c b/drivers/ide/q40ide.c
index 2a43a2f49633..d007e7f66598 100644
--- a/drivers/ide/q40ide.c
+++ b/drivers/ide/q40ide.c
@@ -99,9 +99,9 @@ static const struct ide_tp_ops q40ide_tp_ops = {
99 .exec_command = ide_exec_command, 99 .exec_command = ide_exec_command,
100 .read_status = ide_read_status, 100 .read_status = ide_read_status,
101 .read_altstatus = ide_read_altstatus, 101 .read_altstatus = ide_read_altstatus,
102 .write_devctl = ide_write_devctl,
102 103
103 .set_irq = ide_set_irq, 104 .dev_select = ide_dev_select,
104
105 .tf_load = ide_tf_load, 105 .tf_load = ide_tf_load,
106 .tf_read = ide_tf_read, 106 .tf_read = ide_tf_read,
107 107
diff --git a/drivers/ide/qd65xx.c b/drivers/ide/qd65xx.c
index 08c4fa35e9b1..c9a134986891 100644
--- a/drivers/ide/qd65xx.c
+++ b/drivers/ide/qd65xx.c
@@ -90,13 +90,15 @@ static int timings[4]={-1,-1,-1,-1}; /* stores current timing for each timer */
90 * This routine is invoked to prepare for access to a given drive. 90 * This routine is invoked to prepare for access to a given drive.
91 */ 91 */
92 92
93static void qd65xx_select(ide_drive_t *drive) 93static void qd65xx_dev_select(ide_drive_t *drive)
94{ 94{
95 u8 index = (( (QD_TIMREG(drive)) & 0x80 ) >> 7) | 95 u8 index = (( (QD_TIMREG(drive)) & 0x80 ) >> 7) |
96 (QD_TIMREG(drive) & 0x02); 96 (QD_TIMREG(drive) & 0x02);
97 97
98 if (timings[index] != QD_TIMING(drive)) 98 if (timings[index] != QD_TIMING(drive))
99 outb(timings[index] = QD_TIMING(drive), QD_TIMREG(drive)); 99 outb(timings[index] = QD_TIMING(drive), QD_TIMREG(drive));
100
101 outb(drive->select | ATA_DEVICE_OBS, drive->hwif->io_ports.device_addr);
100} 102}
101 103
102/* 104/*
@@ -309,20 +311,33 @@ static void __init qd6580_init_dev(ide_drive_t *drive)
309 drive->drive_data = (drive->dn & 1) ? t2 : t1; 311 drive->drive_data = (drive->dn & 1) ? t2 : t1;
310} 312}
311 313
314static const struct ide_tp_ops qd65xx_tp_ops = {
315 .exec_command = ide_exec_command,
316 .read_status = ide_read_status,
317 .read_altstatus = ide_read_altstatus,
318 .write_devctl = ide_write_devctl,
319
320 .dev_select = qd65xx_dev_select,
321 .tf_load = ide_tf_load,
322 .tf_read = ide_tf_read,
323
324 .input_data = ide_input_data,
325 .output_data = ide_output_data,
326};
327
312static const struct ide_port_ops qd6500_port_ops = { 328static const struct ide_port_ops qd6500_port_ops = {
313 .init_dev = qd6500_init_dev, 329 .init_dev = qd6500_init_dev,
314 .set_pio_mode = qd6500_set_pio_mode, 330 .set_pio_mode = qd6500_set_pio_mode,
315 .selectproc = qd65xx_select,
316}; 331};
317 332
318static const struct ide_port_ops qd6580_port_ops = { 333static const struct ide_port_ops qd6580_port_ops = {
319 .init_dev = qd6580_init_dev, 334 .init_dev = qd6580_init_dev,
320 .set_pio_mode = qd6580_set_pio_mode, 335 .set_pio_mode = qd6580_set_pio_mode,
321 .selectproc = qd65xx_select,
322}; 336};
323 337
324static const struct ide_port_info qd65xx_port_info __initdata = { 338static const struct ide_port_info qd65xx_port_info __initdata = {
325 .name = DRV_NAME, 339 .name = DRV_NAME,
340 .tp_ops = &qd65xx_tp_ops,
326 .chipset = ide_qd65xx, 341 .chipset = ide_qd65xx,
327 .host_flags = IDE_HFLAG_IO_32BIT | 342 .host_flags = IDE_HFLAG_IO_32BIT |
328 IDE_HFLAG_NO_DMA, 343 IDE_HFLAG_NO_DMA,
diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
index 1c3a82914999..d467478d68da 100644
--- a/drivers/ide/sc1200.c
+++ b/drivers/ide/sc1200.c
@@ -115,8 +115,7 @@ static u8 sc1200_udma_filter(ide_drive_t *drive)
115 if ((mateid[ATA_ID_FIELD_VALID] & 4) && 115 if ((mateid[ATA_ID_FIELD_VALID] & 4) &&
116 (mateid[ATA_ID_UDMA_MODES] & 7)) 116 (mateid[ATA_ID_UDMA_MODES] & 7))
117 goto out; 117 goto out;
118 if ((mateid[ATA_ID_FIELD_VALID] & 2) && 118 if (mateid[ATA_ID_MWDMA_MODES] & 7)
119 (mateid[ATA_ID_MWDMA_MODES] & 7))
120 mask = 0; 119 mask = 0;
121 } 120 }
122out: 121out:
@@ -183,9 +182,6 @@ static int sc1200_dma_end(ide_drive_t *drive)
183 outb(dma_stat|0x1b, dma_base+2); /* clear the INTR & ERROR bits */ 182 outb(dma_stat|0x1b, dma_base+2); /* clear the INTR & ERROR bits */
184 outb(inb(dma_base)&~1, dma_base); /* !! DO THIS HERE !! stop DMA */ 183 outb(inb(dma_base)&~1, dma_base); /* !! DO THIS HERE !! stop DMA */
185 184
186 drive->waiting_for_dma = 0;
187 ide_destroy_dmatable(drive); /* purge DMA mappings */
188
189 return (dma_stat & 7) != 4; /* verify good DMA status */ 185 return (dma_stat & 7) != 4; /* verify good DMA status */
190} 186}
191 187
@@ -291,7 +287,6 @@ static const struct ide_dma_ops sc1200_dma_ops = {
291 .dma_test_irq = ide_dma_test_irq, 287 .dma_test_irq = ide_dma_test_irq,
292 .dma_lost_irq = ide_dma_lost_irq, 288 .dma_lost_irq = ide_dma_lost_irq,
293 .dma_timer_expiry = ide_dma_sff_timer_expiry, 289 .dma_timer_expiry = ide_dma_sff_timer_expiry,
294 .dma_timeout = ide_dma_timeout,
295 .dma_sff_read_status = ide_dma_sff_read_status, 290 .dma_sff_read_status = ide_dma_sff_read_status,
296}; 291};
297 292
diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
index 0cc137cfe76d..6d8dbd9c10bc 100644
--- a/drivers/ide/scc_pata.c
+++ b/drivers/ide/scc_pata.c
@@ -148,17 +148,8 @@ static u8 scc_dma_sff_read_status(ide_hwif_t *hwif)
148 return (u8)in_be32((void *)(hwif->dma_base + 4)); 148 return (u8)in_be32((void *)(hwif->dma_base + 4));
149} 149}
150 150
151static void scc_set_irq(ide_hwif_t *hwif, int on) 151static void scc_write_devctl(ide_hwif_t *hwif, u8 ctl)
152{ 152{
153 u8 ctl = ATA_DEVCTL_OBS;
154
155 if (on == 4) { /* hack for SRST */
156 ctl |= 4;
157 on &= ~4;
158 }
159
160 ctl |= on ? 0 : 2;
161
162 out_be32((void *)hwif->io_ports.ctl_addr, ctl); 153 out_be32((void *)hwif->io_ports.ctl_addr, ctl);
163 eieio(); 154 eieio();
164 in_be32((void *)(hwif->dma_base + 0x01c)); 155 in_be32((void *)(hwif->dma_base + 0x01c));
@@ -321,10 +312,8 @@ static int scc_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
321 u8 dma_stat; 312 u8 dma_stat;
322 313
323 /* fall back to pio! */ 314 /* fall back to pio! */
324 if (ide_build_dmatable(drive, cmd) == 0) { 315 if (ide_build_dmatable(drive, cmd) == 0)
325 ide_map_sg(drive, cmd);
326 return 1; 316 return 1;
327 }
328 317
329 /* PRD table */ 318 /* PRD table */
330 out_be32((void __iomem *)(hwif->dma_base + 8), hwif->dmatable_dma); 319 out_be32((void __iomem *)(hwif->dma_base + 8), hwif->dmatable_dma);
@@ -337,7 +326,7 @@ static int scc_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
337 326
338 /* clear INTR & ERROR flags */ 327 /* clear INTR & ERROR flags */
339 out_be32((void __iomem *)(hwif->dma_base + 4), dma_stat | 6); 328 out_be32((void __iomem *)(hwif->dma_base + 4), dma_stat | 6);
340 drive->waiting_for_dma = 1; 329
341 return 0; 330 return 0;
342} 331}
343 332
@@ -356,7 +345,6 @@ static int __scc_dma_end(ide_drive_t *drive)
356 ide_hwif_t *hwif = drive->hwif; 345 ide_hwif_t *hwif = drive->hwif;
357 u8 dma_stat, dma_cmd; 346 u8 dma_stat, dma_cmd;
358 347
359 drive->waiting_for_dma = 0;
360 /* get DMA command mode */ 348 /* get DMA command mode */
361 dma_cmd = scc_ide_inb(hwif->dma_base); 349 dma_cmd = scc_ide_inb(hwif->dma_base);
362 /* stop DMA */ 350 /* stop DMA */
@@ -365,8 +353,6 @@ static int __scc_dma_end(ide_drive_t *drive)
365 dma_stat = scc_dma_sff_read_status(hwif); 353 dma_stat = scc_dma_sff_read_status(hwif);
366 /* clear the INTR & ERROR bits */ 354 /* clear the INTR & ERROR bits */
367 scc_ide_outb(dma_stat | 6, hwif->dma_base + 4); 355 scc_ide_outb(dma_stat | 6, hwif->dma_base + 4);
368 /* purge DMA mappings */
369 ide_destroy_dmatable(drive);
370 /* verify good DMA status */ 356 /* verify good DMA status */
371 wmb(); 357 wmb();
372 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; 358 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
@@ -670,10 +656,6 @@ static void scc_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
670 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) 656 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
671 HIHI = 0xFF; 657 HIHI = 0xFF;
672 658
673 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA)
674 out_be32((void *)io_ports->data_addr,
675 (tf->hob_data << 8) | tf->data);
676
677 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 659 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
678 scc_ide_outb(tf->hob_feature, io_ports->feature_addr); 660 scc_ide_outb(tf->hob_feature, io_ports->feature_addr);
679 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 661 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
@@ -706,18 +688,11 @@ static void scc_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
706 struct ide_io_ports *io_ports = &drive->hwif->io_ports; 688 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
707 struct ide_taskfile *tf = &cmd->tf; 689 struct ide_taskfile *tf = &cmd->tf;
708 690
709 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
710 u16 data = (u16)in_be32((void *)io_ports->data_addr);
711
712 tf->data = data & 0xff;
713 tf->hob_data = (data >> 8) & 0xff;
714 }
715
716 /* be sure we're looking at the low order bits */ 691 /* be sure we're looking at the low order bits */
717 scc_ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 692 scc_ide_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
718 693
719 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 694 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
720 tf->feature = scc_ide_inb(io_ports->feature_addr); 695 tf->error = scc_ide_inb(io_ports->feature_addr);
721 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 696 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
722 tf->nsect = scc_ide_inb(io_ports->nsect_addr); 697 tf->nsect = scc_ide_inb(io_ports->nsect_addr);
723 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 698 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -730,18 +705,18 @@ static void scc_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
730 tf->device = scc_ide_inb(io_ports->device_addr); 705 tf->device = scc_ide_inb(io_ports->device_addr);
731 706
732 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 707 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
733 scc_ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 708 scc_ide_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
734 709
735 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 710 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
736 tf->hob_feature = scc_ide_inb(io_ports->feature_addr); 711 tf->hob_error = scc_ide_inb(io_ports->feature_addr);
737 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 712 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
738 tf->hob_nsect = scc_ide_inb(io_ports->nsect_addr); 713 tf->hob_nsect = scc_ide_inb(io_ports->nsect_addr);
739 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 714 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
740 tf->hob_lbal = scc_ide_inb(io_ports->lbal_addr); 715 tf->hob_lbal = scc_ide_inb(io_ports->lbal_addr);
741 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 716 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
742 tf->hob_lbam = scc_ide_inb(io_ports->lbam_addr); 717 tf->hob_lbam = scc_ide_inb(io_ports->lbam_addr);
743 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 718 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
744 tf->hob_lbah = scc_ide_inb(io_ports->lbah_addr); 719 tf->hob_lbah = scc_ide_inb(io_ports->lbah_addr);
745 } 720 }
746} 721}
747 722
@@ -848,9 +823,9 @@ static const struct ide_tp_ops scc_tp_ops = {
848 .exec_command = scc_exec_command, 823 .exec_command = scc_exec_command,
849 .read_status = scc_read_status, 824 .read_status = scc_read_status,
850 .read_altstatus = scc_read_altstatus, 825 .read_altstatus = scc_read_altstatus,
826 .write_devctl = scc_write_devctl,
851 827
852 .set_irq = scc_set_irq, 828 .dev_select = ide_dev_select,
853
854 .tf_load = scc_tf_load, 829 .tf_load = scc_tf_load,
855 .tf_read = scc_tf_read, 830 .tf_read = scc_tf_read,
856 831
@@ -872,7 +847,6 @@ static const struct ide_dma_ops scc_dma_ops = {
872 .dma_end = scc_dma_end, 847 .dma_end = scc_dma_end,
873 .dma_test_irq = scc_dma_test_irq, 848 .dma_test_irq = scc_dma_test_irq,
874 .dma_lost_irq = ide_dma_lost_irq, 849 .dma_lost_irq = ide_dma_lost_irq,
875 .dma_timeout = ide_dma_timeout,
876 .dma_timer_expiry = ide_dma_sff_timer_expiry, 850 .dma_timer_expiry = ide_dma_sff_timer_expiry,
877 .dma_sff_read_status = scc_dma_sff_read_status, 851 .dma_sff_read_status = scc_dma_sff_read_status,
878}; 852};
diff --git a/drivers/ide/sgiioc4.c b/drivers/ide/sgiioc4.c
index b12de8346c73..e5d2a48a84de 100644
--- a/drivers/ide/sgiioc4.c
+++ b/drivers/ide/sgiioc4.c
@@ -258,9 +258,6 @@ static int sgiioc4_dma_end(ide_drive_t *drive)
258 } 258 }
259 } 259 }
260 260
261 drive->waiting_for_dma = 0;
262 ide_destroy_dmatable(drive);
263
264 return dma_stat; 261 return dma_stat;
265} 262}
266 263
@@ -280,10 +277,12 @@ static void sgiioc4_dma_host_set(ide_drive_t *drive, int on)
280 sgiioc4_clearirq(drive); 277 sgiioc4_clearirq(drive);
281} 278}
282 279
283static void 280static void sgiioc4_resetproc(ide_drive_t *drive)
284sgiioc4_resetproc(ide_drive_t * drive)
285{ 281{
282 struct ide_cmd *cmd = &drive->hwif->cmd;
283
286 sgiioc4_dma_end(drive); 284 sgiioc4_dma_end(drive);
285 ide_dma_unmap_sg(drive, cmd);
287 sgiioc4_clearirq(drive); 286 sgiioc4_clearirq(drive);
288} 287}
289 288
@@ -412,7 +411,6 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
412 writel(ending_dma_addr, (void __iomem *)(dma_base + IOC4_DMA_END_ADDR * 4)); 411 writel(ending_dma_addr, (void __iomem *)(dma_base + IOC4_DMA_END_ADDR * 4));
413 412
414 writel(dma_direction, (void __iomem *)ioc4_dma_addr); 413 writel(dma_direction, (void __iomem *)ioc4_dma_addr);
415 drive->waiting_for_dma = 1;
416} 414}
417 415
418/* IOC4 Scatter Gather list Format */ 416/* IOC4 Scatter Gather list Format */
@@ -442,7 +440,7 @@ static int sgiioc4_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
442 printk(KERN_WARNING 440 printk(KERN_WARNING
443 "%s: DMA table too small\n", 441 "%s: DMA table too small\n",
444 drive->name); 442 drive->name);
445 goto use_pio_instead; 443 return 0;
446 } else { 444 } else {
447 u32 bcount = 445 u32 bcount =
448 0x10000 - (cur_addr & 0xffff); 446 0x10000 - (cur_addr & 0xffff);
@@ -477,9 +475,6 @@ static int sgiioc4_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
477 return count; 475 return count;
478 } 476 }
479 477
480use_pio_instead:
481 ide_destroy_dmatable(drive);
482
483 return 0; /* revert to PIO for this request */ 478 return 0; /* revert to PIO for this request */
484} 479}
485 480
@@ -488,11 +483,9 @@ static int sgiioc4_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
488 int ddir; 483 int ddir;
489 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE); 484 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
490 485
491 if (sgiioc4_build_dmatable(drive, cmd) == 0) { 486 if (sgiioc4_build_dmatable(drive, cmd) == 0)
492 /* try PIO instead of DMA */ 487 /* try PIO instead of DMA */
493 ide_map_sg(drive, cmd);
494 return 1; 488 return 1;
495 }
496 489
497 if (write) 490 if (write)
498 /* Writes TO the IOC4 FROM Main Memory */ 491 /* Writes TO the IOC4 FROM Main Memory */
@@ -510,9 +503,9 @@ static const struct ide_tp_ops sgiioc4_tp_ops = {
510 .exec_command = ide_exec_command, 503 .exec_command = ide_exec_command,
511 .read_status = sgiioc4_read_status, 504 .read_status = sgiioc4_read_status,
512 .read_altstatus = ide_read_altstatus, 505 .read_altstatus = ide_read_altstatus,
506 .write_devctl = ide_write_devctl,
513 507
514 .set_irq = ide_set_irq, 508 .dev_select = ide_dev_select,
515
516 .tf_load = ide_tf_load, 509 .tf_load = ide_tf_load,
517 .tf_read = ide_tf_read, 510 .tf_read = ide_tf_read,
518 511
@@ -533,7 +526,6 @@ static const struct ide_dma_ops sgiioc4_dma_ops = {
533 .dma_end = sgiioc4_dma_end, 526 .dma_end = sgiioc4_dma_end,
534 .dma_test_irq = sgiioc4_dma_test_irq, 527 .dma_test_irq = sgiioc4_dma_test_irq,
535 .dma_lost_irq = sgiioc4_dma_lost_irq, 528 .dma_lost_irq = sgiioc4_dma_lost_irq,
536 .dma_timeout = ide_dma_timeout,
537}; 529};
538 530
539static const struct ide_port_info sgiioc4_port_info __devinitconst = { 531static const struct ide_port_info sgiioc4_port_info __devinitconst = {
diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
index 075cb1243b2a..e4973cd1fba9 100644
--- a/drivers/ide/siimage.c
+++ b/drivers/ide/siimage.c
@@ -715,7 +715,6 @@ static const struct ide_dma_ops sil_dma_ops = {
715 .dma_end = ide_dma_end, 715 .dma_end = ide_dma_end,
716 .dma_test_irq = siimage_dma_test_irq, 716 .dma_test_irq = siimage_dma_test_irq,
717 .dma_timer_expiry = ide_dma_sff_timer_expiry, 717 .dma_timer_expiry = ide_dma_sff_timer_expiry,
718 .dma_timeout = ide_dma_timeout,
719 .dma_lost_irq = ide_dma_lost_irq, 718 .dma_lost_irq = ide_dma_lost_irq,
720 .dma_sff_read_status = ide_dma_sff_read_status, 719 .dma_sff_read_status = ide_dma_sff_read_status,
721}; 720};
diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
index d25137b04e7a..b0a460625335 100644
--- a/drivers/ide/sl82c105.c
+++ b/drivers/ide/sl82c105.c
@@ -61,7 +61,8 @@ static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
61 if (cmd_off == 0) 61 if (cmd_off == 0)
62 cmd_off = 1; 62 cmd_off = 1;
63 63
64 if (pio > 2 || ata_id_has_iordy(drive->id)) 64 if ((pio > 2 || ata_id_has_iordy(drive->id)) &&
65 !(pio > 4 && ata_id_is_cfa(drive->id)))
65 iordy = 0x40; 66 iordy = 0x40;
66 67
67 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy; 68 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy;
@@ -189,14 +190,13 @@ static void sl82c105_dma_start(ide_drive_t *drive)
189 ide_dma_start(drive); 190 ide_dma_start(drive);
190} 191}
191 192
192static void sl82c105_dma_timeout(ide_drive_t *drive) 193static void sl82c105_dma_clear(ide_drive_t *drive)
193{ 194{
194 struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 195 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
195 196
196 DBG(("sl82c105_dma_timeout(drive:%s)\n", drive->name)); 197 DBG(("sl82c105_dma_clear(drive:%s)\n", drive->name));
197 198
198 sl82c105_reset_host(dev); 199 sl82c105_reset_host(dev);
199 ide_dma_timeout(drive);
200} 200}
201 201
202static int sl82c105_dma_end(ide_drive_t *drive) 202static int sl82c105_dma_end(ide_drive_t *drive)
@@ -298,7 +298,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
298 .dma_test_irq = ide_dma_test_irq, 298 .dma_test_irq = ide_dma_test_irq,
299 .dma_lost_irq = sl82c105_dma_lost_irq, 299 .dma_lost_irq = sl82c105_dma_lost_irq,
300 .dma_timer_expiry = ide_dma_sff_timer_expiry, 300 .dma_timer_expiry = ide_dma_sff_timer_expiry,
301 .dma_timeout = sl82c105_dma_timeout, 301 .dma_clear = sl82c105_dma_clear,
302 .dma_sff_read_status = ide_dma_sff_read_status, 302 .dma_sff_read_status = ide_dma_sff_read_status,
303}; 303};
304 304
diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
index 427d4b3c2c63..b4cf42dc8a6f 100644
--- a/drivers/ide/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -187,7 +187,6 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
187 .dma_test_irq = ide_dma_test_irq, 187 .dma_test_irq = ide_dma_test_irq,
188 .dma_lost_irq = ide_dma_lost_irq, 188 .dma_lost_irq = ide_dma_lost_irq,
189 .dma_timer_expiry = ide_dma_sff_timer_expiry, 189 .dma_timer_expiry = ide_dma_sff_timer_expiry,
190 .dma_timeout = ide_dma_timeout,
191 .dma_sff_read_status = ide_dma_sff_read_status, 190 .dma_sff_read_status = ide_dma_sff_read_status,
192}; 191};
193 192
diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
index ed1496845a93..4b42ca091534 100644
--- a/drivers/ide/trm290.c
+++ b/drivers/ide/trm290.c
@@ -171,54 +171,51 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
171 local_irq_restore(flags); 171 local_irq_restore(flags);
172} 172}
173 173
174static void trm290_selectproc (ide_drive_t *drive) 174static void trm290_dev_select(ide_drive_t *drive)
175{ 175{
176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA)); 176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
177
178 outb(drive->select | ATA_DEVICE_OBS, drive->hwif->io_ports.device_addr);
177} 179}
178 180
179static int trm290_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd) 181static int trm290_dma_check(ide_drive_t *drive, struct ide_cmd *cmd)
180{ 182{
181 ide_hwif_t *hwif = drive->hwif;
182 unsigned int count, rw;
183
184 if (cmd->tf_flags & IDE_TFLAG_WRITE) { 183 if (cmd->tf_flags & IDE_TFLAG_WRITE) {
185#ifdef TRM290_NO_DMA_WRITES 184#ifdef TRM290_NO_DMA_WRITES
186 /* always use PIO for writes */ 185 /* always use PIO for writes */
187 trm290_prepare_drive(drive, 0); /* select PIO xfer */
188 return 1; 186 return 1;
189#endif 187#endif
190 rw = 1; 188 }
191 } else 189 return 0;
192 rw = 2; 190}
191
192static int trm290_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
193{
194 ide_hwif_t *hwif = drive->hwif;
195 unsigned int count, rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 1 : 2;
193 196
194 count = ide_build_dmatable(drive, cmd); 197 count = ide_build_dmatable(drive, cmd);
195 if (count == 0) { 198 if (count == 0)
196 ide_map_sg(drive, cmd);
197 /* try PIO instead of DMA */ 199 /* try PIO instead of DMA */
198 trm290_prepare_drive(drive, 0); /* select PIO xfer */
199 return 1; 200 return 1;
200 } 201
201 /* select DMA xfer */
202 trm290_prepare_drive(drive, 1);
203 outl(hwif->dmatable_dma | rw, hwif->dma_base); 202 outl(hwif->dmatable_dma | rw, hwif->dma_base);
204 drive->waiting_for_dma = 1;
205 /* start DMA */ 203 /* start DMA */
206 outw(count * 2 - 1, hwif->dma_base + 2); 204 outw(count * 2 - 1, hwif->dma_base + 2);
205
207 return 0; 206 return 0;
208} 207}
209 208
210static void trm290_dma_start(ide_drive_t *drive) 209static void trm290_dma_start(ide_drive_t *drive)
211{ 210{
211 trm290_prepare_drive(drive, 1);
212} 212}
213 213
214static int trm290_dma_end(ide_drive_t *drive) 214static int trm290_dma_end(ide_drive_t *drive)
215{ 215{
216 u16 status; 216 u16 status = inw(drive->hwif->dma_base + 2);
217 217
218 drive->waiting_for_dma = 0; 218 trm290_prepare_drive(drive, 0);
219 /* purge DMA mappings */
220 ide_destroy_dmatable(drive);
221 status = inw(drive->hwif->dma_base + 2);
222 219
223 return status != 0x00ff; 220 return status != 0x00ff;
224} 221}
@@ -303,8 +300,18 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
303#endif 300#endif
304} 301}
305 302
306static const struct ide_port_ops trm290_port_ops = { 303static const struct ide_tp_ops trm290_tp_ops = {
307 .selectproc = trm290_selectproc, 304 .exec_command = ide_exec_command,
305 .read_status = ide_read_status,
306 .read_altstatus = ide_read_altstatus,
307 .write_devctl = ide_write_devctl,
308
309 .dev_select = trm290_dev_select,
310 .tf_load = ide_tf_load,
311 .tf_read = ide_tf_read,
312
313 .input_data = ide_input_data,
314 .output_data = ide_output_data,
308}; 315};
309 316
310static struct ide_dma_ops trm290_dma_ops = { 317static struct ide_dma_ops trm290_dma_ops = {
@@ -314,13 +321,13 @@ static struct ide_dma_ops trm290_dma_ops = {
314 .dma_end = trm290_dma_end, 321 .dma_end = trm290_dma_end,
315 .dma_test_irq = trm290_dma_test_irq, 322 .dma_test_irq = trm290_dma_test_irq,
316 .dma_lost_irq = ide_dma_lost_irq, 323 .dma_lost_irq = ide_dma_lost_irq,
317 .dma_timeout = ide_dma_timeout, 324 .dma_check = trm290_dma_check,
318}; 325};
319 326
320static const struct ide_port_info trm290_chipset __devinitdata = { 327static const struct ide_port_info trm290_chipset __devinitdata = {
321 .name = DRV_NAME, 328 .name = DRV_NAME,
322 .init_hwif = init_hwif_trm290, 329 .init_hwif = init_hwif_trm290,
323 .port_ops = &trm290_port_ops, 330 .tp_ops = &trm290_tp_ops,
324 .dma_ops = &trm290_dma_ops, 331 .dma_ops = &trm290_dma_ops,
325 .host_flags = IDE_HFLAG_TRM290 | 332 .host_flags = IDE_HFLAG_TRM290 |
326 IDE_HFLAG_NO_ATAPI_DMA | 333 IDE_HFLAG_NO_ATAPI_DMA |
diff --git a/drivers/ide/tx4938ide.c b/drivers/ide/tx4938ide.c
index 657a61890b1c..4cb79c4c2604 100644
--- a/drivers/ide/tx4938ide.c
+++ b/drivers/ide/tx4938ide.c
@@ -92,13 +92,6 @@ static void tx4938ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
92 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) 92 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
93 HIHI = 0xFF; 93 HIHI = 0xFF;
94 94
95 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
96 u16 data = (tf->hob_data << 8) | tf->data;
97
98 /* no endian swap */
99 __raw_writew(data, (void __iomem *)io_ports->data_addr);
100 }
101
102 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 95 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
103 tx4938ide_outb(tf->hob_feature, io_ports->feature_addr); 96 tx4938ide_outb(tf->hob_feature, io_ports->feature_addr);
104 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 97 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
@@ -132,20 +125,11 @@ static void tx4938ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
132 struct ide_io_ports *io_ports = &hwif->io_ports; 125 struct ide_io_ports *io_ports = &hwif->io_ports;
133 struct ide_taskfile *tf = &cmd->tf; 126 struct ide_taskfile *tf = &cmd->tf;
134 127
135 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
136 u16 data;
137
138 /* no endian swap */
139 data = __raw_readw((void __iomem *)io_ports->data_addr);
140 tf->data = data & 0xff;
141 tf->hob_data = (data >> 8) & 0xff;
142 }
143
144 /* be sure we're looking at the low order bits */ 128 /* be sure we're looking at the low order bits */
145 tx4938ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 129 tx4938ide_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
146 130
147 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 131 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
148 tf->feature = tx4938ide_inb(io_ports->feature_addr); 132 tf->error = tx4938ide_inb(io_ports->feature_addr);
149 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 133 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
150 tf->nsect = tx4938ide_inb(io_ports->nsect_addr); 134 tf->nsect = tx4938ide_inb(io_ports->nsect_addr);
151 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 135 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -158,19 +142,18 @@ static void tx4938ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
158 tf->device = tx4938ide_inb(io_ports->device_addr); 142 tf->device = tx4938ide_inb(io_ports->device_addr);
159 143
160 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 144 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
161 tx4938ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 145 tx4938ide_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
162 146
163 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 147 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
164 tf->hob_feature = 148 tf->hob_error = tx4938ide_inb(io_ports->feature_addr);
165 tx4938ide_inb(io_ports->feature_addr);
166 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 149 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
167 tf->hob_nsect = tx4938ide_inb(io_ports->nsect_addr); 150 tf->hob_nsect = tx4938ide_inb(io_ports->nsect_addr);
168 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 151 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
169 tf->hob_lbal = tx4938ide_inb(io_ports->lbal_addr); 152 tf->hob_lbal = tx4938ide_inb(io_ports->lbal_addr);
170 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 153 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
171 tf->hob_lbam = tx4938ide_inb(io_ports->lbam_addr); 154 tf->hob_lbam = tx4938ide_inb(io_ports->lbam_addr);
172 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 155 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
173 tf->hob_lbah = tx4938ide_inb(io_ports->lbah_addr); 156 tf->hob_lbah = tx4938ide_inb(io_ports->lbah_addr);
174 } 157 }
175} 158}
176 159
@@ -204,9 +187,9 @@ static const struct ide_tp_ops tx4938ide_tp_ops = {
204 .exec_command = ide_exec_command, 187 .exec_command = ide_exec_command,
205 .read_status = ide_read_status, 188 .read_status = ide_read_status,
206 .read_altstatus = ide_read_altstatus, 189 .read_altstatus = ide_read_altstatus,
190 .write_devctl = ide_write_devctl,
207 191
208 .set_irq = ide_set_irq, 192 .dev_select = ide_dev_select,
209
210 .tf_load = tx4938ide_tf_load, 193 .tf_load = tx4938ide_tf_load,
211 .tf_read = tx4938ide_tf_read, 194 .tf_read = tx4938ide_tf_read,
212 195
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
index e0e0a803dde3..0040a9a3e26e 100644
--- a/drivers/ide/tx4939ide.c
+++ b/drivers/ide/tx4939ide.c
@@ -279,8 +279,6 @@ use_pio_instead:
279 printk(KERN_ERR "%s: %s\n", drive->name, 279 printk(KERN_ERR "%s: %s\n", drive->name,
280 count ? "DMA table too small" : "empty DMA table?"); 280 count ? "DMA table too small" : "empty DMA table?");
281 281
282 ide_destroy_dmatable(drive);
283
284 return 0; /* revert to PIO for this request */ 282 return 0; /* revert to PIO for this request */
285} 283}
286#else 284#else
@@ -294,10 +292,8 @@ static int tx4939ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
294 u8 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR; 292 u8 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR;
295 293
296 /* fall back to PIO! */ 294 /* fall back to PIO! */
297 if (tx4939ide_build_dmatable(drive, cmd) == 0) { 295 if (tx4939ide_build_dmatable(drive, cmd) == 0)
298 ide_map_sg(drive, cmd);
299 return 1; 296 return 1;
300 }
301 297
302 /* PRD table */ 298 /* PRD table */
303 tx4939ide_writel(hwif->dmatable_dma, base, TX4939IDE_PRD_Ptr); 299 tx4939ide_writel(hwif->dmatable_dma, base, TX4939IDE_PRD_Ptr);
@@ -308,8 +304,6 @@ static int tx4939ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
308 /* clear INTR & ERROR flags */ 304 /* clear INTR & ERROR flags */
309 tx4939ide_clear_dma_status(base); 305 tx4939ide_clear_dma_status(base);
310 306
311 drive->waiting_for_dma = 1;
312
313 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ? 307 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ?
314 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1); 308 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1);
315 309
@@ -325,8 +319,6 @@ static int tx4939ide_dma_end(ide_drive_t *drive)
325 void __iomem *base = TX4939IDE_BASE(hwif); 319 void __iomem *base = TX4939IDE_BASE(hwif);
326 u16 ctl = tx4939ide_readw(base, TX4939IDE_Int_Ctl); 320 u16 ctl = tx4939ide_readw(base, TX4939IDE_Int_Ctl);
327 321
328 drive->waiting_for_dma = 0;
329
330 /* get DMA command mode */ 322 /* get DMA command mode */
331 dma_cmd = tx4939ide_readb(base, TX4939IDE_DMA_Cmd); 323 dma_cmd = tx4939ide_readb(base, TX4939IDE_DMA_Cmd);
332 /* stop DMA */ 324 /* stop DMA */
@@ -335,11 +327,9 @@ static int tx4939ide_dma_end(ide_drive_t *drive)
335 /* read and clear the INTR & ERROR bits */ 327 /* read and clear the INTR & ERROR bits */
336 dma_stat = tx4939ide_clear_dma_status(base); 328 dma_stat = tx4939ide_clear_dma_status(base);
337 329
338 /* purge DMA mappings */
339 ide_destroy_dmatable(drive);
340 /* verify good DMA status */
341 wmb(); 330 wmb();
342 331
332 /* verify good DMA status */
343 if ((dma_stat & (ATA_DMA_INTR | ATA_DMA_ERR | ATA_DMA_ACTIVE)) == 0 && 333 if ((dma_stat & (ATA_DMA_INTR | ATA_DMA_ERR | ATA_DMA_ACTIVE)) == 0 &&
344 (ctl & (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST)) == 334 (ctl & (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST)) ==
345 (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST)) 335 (TX4939IDE_INT_XFEREND | TX4939IDE_INT_HOST))
@@ -439,7 +429,7 @@ static void tx4939ide_tf_load_fixup(ide_drive_t *drive)
439 * Fix ATA100 CORE System Control Register. (The write to the 429 * Fix ATA100 CORE System Control Register. (The write to the
440 * Device/Head register may write wrong data to the System 430 * Device/Head register may write wrong data to the System
441 * Control Register) 431 * Control Register)
442 * While Sys_Ctl is written here, selectproc is not needed. 432 * While Sys_Ctl is written here, dev_select() is not needed.
443 */ 433 */
444 tx4939ide_writew(sysctl, base, TX4939IDE_Sys_Ctl); 434 tx4939ide_writew(sysctl, base, TX4939IDE_Sys_Ctl);
445} 435}
@@ -467,13 +457,6 @@ static void tx4939ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
467 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) 457 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
468 HIHI = 0xFF; 458 HIHI = 0xFF;
469 459
470 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
471 u16 data = (tf->hob_data << 8) | tf->data;
472
473 /* no endian swap */
474 __raw_writew(data, (void __iomem *)io_ports->data_addr);
475 }
476
477 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 460 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
478 tx4939ide_outb(tf->hob_feature, io_ports->feature_addr); 461 tx4939ide_outb(tf->hob_feature, io_ports->feature_addr);
479 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 462 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
@@ -509,20 +492,11 @@ static void tx4939ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
509 struct ide_io_ports *io_ports = &hwif->io_ports; 492 struct ide_io_ports *io_ports = &hwif->io_ports;
510 struct ide_taskfile *tf = &cmd->tf; 493 struct ide_taskfile *tf = &cmd->tf;
511 494
512 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
513 u16 data;
514
515 /* no endian swap */
516 data = __raw_readw((void __iomem *)io_ports->data_addr);
517 tf->data = data & 0xff;
518 tf->hob_data = (data >> 8) & 0xff;
519 }
520
521 /* be sure we're looking at the low order bits */ 495 /* be sure we're looking at the low order bits */
522 tx4939ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 496 tx4939ide_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
523 497
524 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) 498 if (cmd->tf_flags & IDE_TFLAG_IN_ERROR)
525 tf->feature = tx4939ide_inb(io_ports->feature_addr); 499 tf->error = tx4939ide_inb(io_ports->feature_addr);
526 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) 500 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
527 tf->nsect = tx4939ide_inb(io_ports->nsect_addr); 501 tf->nsect = tx4939ide_inb(io_ports->nsect_addr);
528 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) 502 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
@@ -535,19 +509,18 @@ static void tx4939ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
535 tf->device = tx4939ide_inb(io_ports->device_addr); 509 tf->device = tx4939ide_inb(io_ports->device_addr);
536 510
537 if (cmd->tf_flags & IDE_TFLAG_LBA48) { 511 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
538 tx4939ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 512 tx4939ide_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
539 513
540 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 514 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR)
541 tf->hob_feature = 515 tf->hob_error = tx4939ide_inb(io_ports->feature_addr);
542 tx4939ide_inb(io_ports->feature_addr);
543 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 516 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
544 tf->hob_nsect = tx4939ide_inb(io_ports->nsect_addr); 517 tf->hob_nsect = tx4939ide_inb(io_ports->nsect_addr);
545 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 518 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
546 tf->hob_lbal = tx4939ide_inb(io_ports->lbal_addr); 519 tf->hob_lbal = tx4939ide_inb(io_ports->lbal_addr);
547 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 520 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
548 tf->hob_lbam = tx4939ide_inb(io_ports->lbam_addr); 521 tf->hob_lbam = tx4939ide_inb(io_ports->lbam_addr);
549 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 522 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
550 tf->hob_lbah = tx4939ide_inb(io_ports->lbah_addr); 523 tf->hob_lbah = tx4939ide_inb(io_ports->lbah_addr);
551 } 524 }
552} 525}
553 526
@@ -581,9 +554,9 @@ static const struct ide_tp_ops tx4939ide_tp_ops = {
581 .exec_command = ide_exec_command, 554 .exec_command = ide_exec_command,
582 .read_status = ide_read_status, 555 .read_status = ide_read_status,
583 .read_altstatus = ide_read_altstatus, 556 .read_altstatus = ide_read_altstatus,
557 .write_devctl = ide_write_devctl,
584 558
585 .set_irq = ide_set_irq, 559 .dev_select = ide_dev_select,
586
587 .tf_load = tx4939ide_tf_load, 560 .tf_load = tx4939ide_tf_load,
588 .tf_read = tx4939ide_tf_read, 561 .tf_read = tx4939ide_tf_read,
589 562
@@ -605,9 +578,9 @@ static const struct ide_tp_ops tx4939ide_tp_ops = {
605 .exec_command = ide_exec_command, 578 .exec_command = ide_exec_command,
606 .read_status = ide_read_status, 579 .read_status = ide_read_status,
607 .read_altstatus = ide_read_altstatus, 580 .read_altstatus = ide_read_altstatus,
581 .write_devctl = ide_write_devctl,
608 582
609 .set_irq = ide_set_irq, 583 .dev_select = ide_dev_select,
610
611 .tf_load = tx4939ide_tf_load, 584 .tf_load = tx4939ide_tf_load,
612 .tf_read = ide_tf_read, 585 .tf_read = ide_tf_read,
613 586
@@ -632,7 +605,6 @@ static const struct ide_dma_ops tx4939ide_dma_ops = {
632 .dma_test_irq = tx4939ide_dma_test_irq, 605 .dma_test_irq = tx4939ide_dma_test_irq,
633 .dma_lost_irq = ide_dma_lost_irq, 606 .dma_lost_irq = ide_dma_lost_irq,
634 .dma_timer_expiry = ide_dma_sff_timer_expiry, 607 .dma_timer_expiry = ide_dma_sff_timer_expiry,
635 .dma_timeout = ide_dma_timeout,
636 .dma_sff_read_status = tx4939ide_dma_sff_read_status, 608 .dma_sff_read_status = tx4939ide_dma_sff_read_status,
637}; 609};
638 610