aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-06-20 13:11:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-20 13:11:11 -0400
commite6423407d01168f7760cdee7270d9f51d1240301 (patch)
tree979795cfa8f6946238ab31f544159142f3e7df93 /drivers/ide
parent7f8189068726492950bf1a2dcfd9b51314560abf (diff)
parent39c58f37a10198054c656c28202fb1e6d22fd505 (diff)
Merge branch 'for-2.6.31' of git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
* 'for-2.6.31' of git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (34 commits) ide-cd: prevent null pointer deref via cdrom_newpc_intr ide: BUG() on unknown requests ide: filter out invalid DMA xfer mode changes in HDIO_DRIVE_CMD ioctl handler ide: do not access ide_drive_t 'drive_data' field directly sl82c105: implement test_irq() method siimage: implement test_irq() method pdc202xx_old: implement test_irq() method (take 2) cmd64x: implement test_irq() method cmd640: implement test_irq() method ide: move ack_intr() method into 'struct ide_port_ops' (take 2) ide: move IRQ clearing from ack_intr() method to clear_irq() method (take 2) siimage: use ide_dma_test_irq() (take 2) cmd64x: implement clear_irq() method (take 2) ide: call clear_irq() method in ide_timer_expiry() sgiioc4: coding style cleanup ide: don't enable IORDY at a probe time ide: IORDY handling fixes ata: add ata_id_pio_need_iordy() helper (v2) ide-tape: fix build issue ide: unify interrupt reason checking ...
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/at91_ide.c3
-rw-r--r--drivers/ide/buddha.c40
-rw-r--r--drivers/ide/cmd640.c13
-rw-r--r--drivers/ide/cmd64x.c103
-rw-r--r--drivers/ide/cs5536.c23
-rw-r--r--drivers/ide/falconide.c1
-rw-r--r--drivers/ide/gayle.c33
-rw-r--r--drivers/ide/ht6560b.c33
-rw-r--r--drivers/ide/icside.c10
-rw-r--r--drivers/ide/ide-atapi.c138
-rw-r--r--drivers/ide/ide-cd.c78
-rw-r--r--drivers/ide/ide-disk.c9
-rw-r--r--drivers/ide/ide-floppy.c56
-rw-r--r--drivers/ide/ide-floppy_ioctl.c43
-rw-r--r--drivers/ide/ide-io.c8
-rw-r--r--drivers/ide/ide-ioctls.c13
-rw-r--r--drivers/ide/ide-probe.c17
-rw-r--r--drivers/ide/ide-tape.c186
-rw-r--r--drivers/ide/ide-xfer-mode.c12
-rw-r--r--drivers/ide/it8172.c2
-rw-r--r--drivers/ide/it8213.c2
-rw-r--r--drivers/ide/macide.c30
-rw-r--r--drivers/ide/opti621.c8
-rw-r--r--drivers/ide/pdc202xx_old.c24
-rw-r--r--drivers/ide/piix.c2
-rw-r--r--drivers/ide/q40ide.c7
-rw-r--r--drivers/ide/qd65xx.c11
-rw-r--r--drivers/ide/qd65xx.h11
-rw-r--r--drivers/ide/sgiioc4.c119
-rw-r--r--drivers/ide/siimage.c42
-rw-r--r--drivers/ide/sl82c105.c32
-rw-r--r--drivers/ide/slc90e66.c2
32 files changed, 561 insertions, 550 deletions
diff --git a/drivers/ide/at91_ide.c b/drivers/ide/at91_ide.c
index fc0949a8cfde..dbfeda42b940 100644
--- a/drivers/ide/at91_ide.c
+++ b/drivers/ide/at91_ide.c
@@ -185,8 +185,7 @@ static void at91_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
185 timing = ide_timing_find_mode(XFER_PIO_0 + pio); 185 timing = ide_timing_find_mode(XFER_PIO_0 + pio);
186 BUG_ON(!timing); 186 BUG_ON(!timing);
187 187
188 if ((pio > 2 || ata_id_has_iordy(drive->id)) && 188 if (ide_pio_need_iordy(drive, pio))
189 !(ata_id_is_cfa(drive->id) && pio > 4))
190 use_iordy = 1; 189 use_iordy = 1;
191 190
192 apply_timings(chipselect, pio, timing, use_iordy); 191 apply_timings(chipselect, pio, timing, use_iordy);
diff --git a/drivers/ide/buddha.c b/drivers/ide/buddha.c
index e3c6a5913305..ab4f169d0837 100644
--- a/drivers/ide/buddha.c
+++ b/drivers/ide/buddha.c
@@ -99,7 +99,7 @@ static const char *buddha_board_name[] = { "Buddha", "Catweasel", "X-Surf" };
99 * Check and acknowledge the interrupt status 99 * Check and acknowledge the interrupt status
100 */ 100 */
101 101
102static int buddha_ack_intr(ide_hwif_t *hwif) 102static int buddha_test_irq(ide_hwif_t *hwif)
103{ 103{
104 unsigned char ch; 104 unsigned char ch;
105 105
@@ -109,21 +109,16 @@ static int buddha_ack_intr(ide_hwif_t *hwif)
109 return 1; 109 return 1;
110} 110}
111 111
112static int xsurf_ack_intr(ide_hwif_t *hwif) 112static void xsurf_clear_irq(ide_drive_t *drive)
113{ 113{
114 unsigned char ch; 114 /*
115 115 * X-Surf needs 0 written to IRQ register to ensure ISA bit A11 stays at 0
116 ch = z_readb(hwif->io_ports.irq_addr); 116 */
117 /* X-Surf needs a 0 written to IRQ register to ensure ISA bit A11 stays at 0 */ 117 z_writeb(0, drive->hwif->io_ports.irq_addr);
118 z_writeb(0, hwif->io_ports.irq_addr);
119 if (!(ch & 0x80))
120 return 0;
121 return 1;
122} 118}
123 119
124static void __init buddha_setup_ports(struct ide_hw *hw, unsigned long base, 120static void __init buddha_setup_ports(struct ide_hw *hw, unsigned long base,
125 unsigned long ctl, unsigned long irq_port, 121 unsigned long ctl, unsigned long irq_port)
126 ide_ack_intr_t *ack_intr)
127{ 122{
128 int i; 123 int i;
129 124
@@ -138,10 +133,19 @@ static void __init buddha_setup_ports(struct ide_hw *hw, unsigned long base,
138 hw->io_ports.irq_addr = irq_port; 133 hw->io_ports.irq_addr = irq_port;
139 134
140 hw->irq = IRQ_AMIGA_PORTS; 135 hw->irq = IRQ_AMIGA_PORTS;
141 hw->ack_intr = ack_intr;
142} 136}
143 137
138static const struct ide_port_ops buddha_port_ops = {
139 .test_irq = buddha_test_irq,
140};
141
142static const struct ide_port_ops xsurf_port_ops = {
143 .clear_irq = xsurf_clear_irq,
144 .test_irq = buddha_test_irq,
145};
146
144static const struct ide_port_info buddha_port_info = { 147static const struct ide_port_info buddha_port_info = {
148 .port_ops = &buddha_port_ops,
145 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, 149 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
146 .irq_flags = IRQF_SHARED, 150 .irq_flags = IRQF_SHARED,
147 .chipset = ide_generic, 151 .chipset = ide_generic,
@@ -161,6 +165,7 @@ static int __init buddha_init(void)
161 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { 165 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
162 unsigned long board; 166 unsigned long board;
163 struct ide_hw hw[MAX_NUM_HWIFS], *hws[MAX_NUM_HWIFS]; 167 struct ide_hw hw[MAX_NUM_HWIFS], *hws[MAX_NUM_HWIFS];
168 struct ide_port_info d = buddha_port_info;
164 169
165 if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) { 170 if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
166 buddha_num_hwifs = BUDDHA_NUM_HWIFS; 171 buddha_num_hwifs = BUDDHA_NUM_HWIFS;
@@ -171,6 +176,7 @@ static int __init buddha_init(void)
171 } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) { 176 } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) {
172 buddha_num_hwifs = XSURF_NUM_HWIFS; 177 buddha_num_hwifs = XSURF_NUM_HWIFS;
173 type=BOARD_XSURF; 178 type=BOARD_XSURF;
179 d.port_ops = &xsurf_port_ops;
174 } else 180 } else
175 continue; 181 continue;
176 182
@@ -203,28 +209,24 @@ fail_base2:
203 209
204 for (i = 0; i < buddha_num_hwifs; i++) { 210 for (i = 0; i < buddha_num_hwifs; i++) {
205 unsigned long base, ctl, irq_port; 211 unsigned long base, ctl, irq_port;
206 ide_ack_intr_t *ack_intr;
207 212
208 if (type != BOARD_XSURF) { 213 if (type != BOARD_XSURF) {
209 base = buddha_board + buddha_bases[i]; 214 base = buddha_board + buddha_bases[i];
210 ctl = base + BUDDHA_CONTROL; 215 ctl = base + BUDDHA_CONTROL;
211 irq_port = buddha_board + buddha_irqports[i]; 216 irq_port = buddha_board + buddha_irqports[i];
212 ack_intr = buddha_ack_intr;
213 } else { 217 } else {
214 base = buddha_board + xsurf_bases[i]; 218 base = buddha_board + xsurf_bases[i];
215 /* X-Surf has no CS1* (Control/AltStat) */ 219 /* X-Surf has no CS1* (Control/AltStat) */
216 ctl = 0; 220 ctl = 0;
217 irq_port = buddha_board + xsurf_irqports[i]; 221 irq_port = buddha_board + xsurf_irqports[i];
218 ack_intr = xsurf_ack_intr;
219 } 222 }
220 223
221 buddha_setup_ports(&hw[i], base, ctl, irq_port, 224 buddha_setup_ports(&hw[i], base, ctl, irq_port);
222 ack_intr);
223 225
224 hws[i] = &hw[i]; 226 hws[i] = &hw[i];
225 } 227 }
226 228
227 ide_host_add(&buddha_port_info, hws, i, NULL); 229 ide_host_add(&d, hws, i, NULL);
228 } 230 }
229 231
230 return 0; 232 return 0;
diff --git a/drivers/ide/cmd640.c b/drivers/ide/cmd640.c
index 1683ed5c7329..1a32d62ed86b 100644
--- a/drivers/ide/cmd640.c
+++ b/drivers/ide/cmd640.c
@@ -153,6 +153,7 @@ static int cmd640_vlb;
153#define ARTTIM23 0x57 153#define ARTTIM23 0x57
154#define ARTTIM23_DIS_RA2 0x04 154#define ARTTIM23_DIS_RA2 0x04
155#define ARTTIM23_DIS_RA3 0x08 155#define ARTTIM23_DIS_RA3 0x08
156#define ARTTIM23_IDE23INTR 0x10
156#define DRWTIM23 0x58 157#define DRWTIM23 0x58
157#define BRST 0x59 158#define BRST 0x59
158 159
@@ -629,12 +630,24 @@ static void cmd640_init_dev(ide_drive_t *drive)
629#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 630#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
630} 631}
631 632
633static int cmd640_test_irq(ide_hwif_t *hwif)
634{
635 struct pci_dev *dev = to_pci_dev(hwif->dev);
636 int irq_reg = hwif->channel ? ARTTIM23 : CFR;
637 u8 irq_stat, irq_mask = hwif->channel ? ARTTIM23_IDE23INTR :
638 CFR_IDE01INTR;
639
640 pci_read_config_byte(dev, irq_reg, &irq_stat);
641
642 return (irq_stat & irq_mask) ? 1 : 0;
643}
632 644
633static const struct ide_port_ops cmd640_port_ops = { 645static const struct ide_port_ops cmd640_port_ops = {
634 .init_dev = cmd640_init_dev, 646 .init_dev = cmd640_init_dev,
635#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 647#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
636 .set_pio_mode = cmd640_set_pio_mode, 648 .set_pio_mode = cmd640_set_pio_mode,
637#endif 649#endif
650 .test_irq = cmd640_test_irq,
638}; 651};
639 652
640static int pci_conf1(void) 653static int pci_conf1(void)
diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
index 80b777e4247b..03c86209446f 100644
--- a/drivers/ide/cmd64x.c
+++ b/drivers/ide/cmd64x.c
@@ -7,7 +7,7 @@
7 * Copyright (C) 1998 David S. Miller (davem@redhat.com) 7 * Copyright (C) 1998 David S. Miller (davem@redhat.com)
8 * 8 *
9 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org> 9 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
10 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com> 10 * Copyright (C) 2007,2009 MontaVista Software, Inc. <source@mvista.com>
11 */ 11 */
12 12
13#include <linux/module.h> 13#include <linux/module.h>
@@ -118,8 +118,9 @@ static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
118 ide_hwif_t *hwif = drive->hwif; 118 ide_hwif_t *hwif = drive->hwif;
119 struct pci_dev *dev = to_pci_dev(hwif->dev); 119 struct pci_dev *dev = to_pci_dev(hwif->dev);
120 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); 120 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
121 unsigned long setup_count;
121 unsigned int cycle_time; 122 unsigned int cycle_time;
122 u8 setup_count, arttim = 0; 123 u8 arttim = 0;
123 124
124 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; 125 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0};
125 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; 126 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23};
@@ -140,10 +141,11 @@ static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
140 if (hwif->channel) { 141 if (hwif->channel) {
141 ide_drive_t *pair = ide_get_pair_dev(drive); 142 ide_drive_t *pair = ide_get_pair_dev(drive);
142 143
143 drive->drive_data = setup_count; 144 ide_set_drivedata(drive, (void *)setup_count);
144 145
145 if (pair) 146 if (pair)
146 setup_count = max_t(u8, setup_count, pair->drive_data); 147 setup_count = max_t(u8, setup_count,
148 (unsigned long)ide_get_drivedata(pair));
147 } 149 }
148 150
149 if (setup_count > 5) /* shouldn't actually happen... */ 151 if (setup_count > 5) /* shouldn't actually happen... */
@@ -226,11 +228,11 @@ static void cmd64x_set_dma_mode(ide_drive_t *drive, const u8 speed)
226 (void) pci_write_config_byte(dev, pciU, regU); 228 (void) pci_write_config_byte(dev, pciU, regU);
227} 229}
228 230
229static int cmd648_dma_end(ide_drive_t *drive) 231static void cmd648_clear_irq(ide_drive_t *drive)
230{ 232{
231 ide_hwif_t *hwif = drive->hwif; 233 ide_hwif_t *hwif = drive->hwif;
232 unsigned long base = hwif->dma_base - (hwif->channel * 8); 234 struct pci_dev *dev = to_pci_dev(hwif->dev);
233 int err = ide_dma_end(drive); 235 unsigned long base = pci_resource_start(dev, 4);
234 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 236 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
235 MRDMODE_INTR_CH0; 237 MRDMODE_INTR_CH0;
236 u8 mrdmode = inb(base + 1); 238 u8 mrdmode = inb(base + 1);
@@ -238,11 +240,9 @@ static int cmd648_dma_end(ide_drive_t *drive)
238 /* clear the interrupt bit */ 240 /* clear the interrupt bit */
239 outb((mrdmode & ~(MRDMODE_INTR_CH0 | MRDMODE_INTR_CH1)) | irq_mask, 241 outb((mrdmode & ~(MRDMODE_INTR_CH0 | MRDMODE_INTR_CH1)) | irq_mask,
240 base + 1); 242 base + 1);
241
242 return err;
243} 243}
244 244
245static int cmd64x_dma_end(ide_drive_t *drive) 245static void cmd64x_clear_irq(ide_drive_t *drive)
246{ 246{
247 ide_hwif_t *hwif = drive->hwif; 247 ide_hwif_t *hwif = drive->hwif;
248 struct pci_dev *dev = to_pci_dev(hwif->dev); 248 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -250,62 +250,40 @@ static int cmd64x_dma_end(ide_drive_t *drive)
250 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 250 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
251 CFR_INTR_CH0; 251 CFR_INTR_CH0;
252 u8 irq_stat = 0; 252 u8 irq_stat = 0;
253 int err = ide_dma_end(drive);
254 253
255 (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 254 (void) pci_read_config_byte(dev, irq_reg, &irq_stat);
256 /* clear the interrupt bit */ 255 /* clear the interrupt bit */
257 (void) pci_write_config_byte(dev, irq_reg, irq_stat | irq_mask); 256 (void) pci_write_config_byte(dev, irq_reg, irq_stat | irq_mask);
258
259 return err;
260} 257}
261 258
262static int cmd648_dma_test_irq(ide_drive_t *drive) 259static int cmd648_test_irq(ide_hwif_t *hwif)
263{ 260{
264 ide_hwif_t *hwif = drive->hwif; 261 struct pci_dev *dev = to_pci_dev(hwif->dev);
265 unsigned long base = hwif->dma_base - (hwif->channel * 8); 262 unsigned long base = pci_resource_start(dev, 4);
266 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 263 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
267 MRDMODE_INTR_CH0; 264 MRDMODE_INTR_CH0;
268 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
269 u8 mrdmode = inb(base + 1); 265 u8 mrdmode = inb(base + 1);
270 266
271#ifdef DEBUG 267 pr_debug("%s: mrdmode: 0x%02x irq_mask: 0x%02x\n",
272 printk("%s: dma_stat: 0x%02x mrdmode: 0x%02x irq_mask: 0x%02x\n", 268 hwif->name, mrdmode, irq_mask);
273 drive->name, dma_stat, mrdmode, irq_mask);
274#endif
275 if (!(mrdmode & irq_mask))
276 return 0;
277
278 /* return 1 if INTR asserted */
279 if (dma_stat & 4)
280 return 1;
281 269
282 return 0; 270 return (mrdmode & irq_mask) ? 1 : 0;
283} 271}
284 272
285static int cmd64x_dma_test_irq(ide_drive_t *drive) 273static int cmd64x_test_irq(ide_hwif_t *hwif)
286{ 274{
287 ide_hwif_t *hwif = drive->hwif;
288 struct pci_dev *dev = to_pci_dev(hwif->dev); 275 struct pci_dev *dev = to_pci_dev(hwif->dev);
289 int irq_reg = hwif->channel ? ARTTIM23 : CFR; 276 int irq_reg = hwif->channel ? ARTTIM23 : CFR;
290 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 277 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
291 CFR_INTR_CH0; 278 CFR_INTR_CH0;
292 u8 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
293 u8 irq_stat = 0; 279 u8 irq_stat = 0;
294 280
295 (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 281 (void) pci_read_config_byte(dev, irq_reg, &irq_stat);
296 282
297#ifdef DEBUG 283 pr_debug("%s: irq_stat: 0x%02x irq_mask: 0x%02x\n",
298 printk("%s: dma_stat: 0x%02x irq_stat: 0x%02x irq_mask: 0x%02x\n", 284 hwif->name, irq_stat, irq_mask);
299 drive->name, dma_stat, irq_stat, irq_mask);
300#endif
301 if (!(irq_stat & irq_mask))
302 return 0;
303
304 /* return 1 if INTR asserted */
305 if (dma_stat & 4)
306 return 1;
307 285
308 return 0; 286 return (irq_stat & irq_mask) ? 1 : 0;
309} 287}
310 288
311/* 289/*
@@ -370,18 +348,17 @@ static u8 cmd64x_cable_detect(ide_hwif_t *hwif)
370static const struct ide_port_ops cmd64x_port_ops = { 348static const struct ide_port_ops cmd64x_port_ops = {
371 .set_pio_mode = cmd64x_set_pio_mode, 349 .set_pio_mode = cmd64x_set_pio_mode,
372 .set_dma_mode = cmd64x_set_dma_mode, 350 .set_dma_mode = cmd64x_set_dma_mode,
351 .clear_irq = cmd64x_clear_irq,
352 .test_irq = cmd64x_test_irq,
373 .cable_detect = cmd64x_cable_detect, 353 .cable_detect = cmd64x_cable_detect,
374}; 354};
375 355
376static const struct ide_dma_ops cmd64x_dma_ops = { 356static const struct ide_port_ops cmd648_port_ops = {
377 .dma_host_set = ide_dma_host_set, 357 .set_pio_mode = cmd64x_set_pio_mode,
378 .dma_setup = ide_dma_setup, 358 .set_dma_mode = cmd64x_set_dma_mode,
379 .dma_start = ide_dma_start, 359 .clear_irq = cmd648_clear_irq,
380 .dma_end = cmd64x_dma_end, 360 .test_irq = cmd648_test_irq,
381 .dma_test_irq = cmd64x_dma_test_irq, 361 .cable_detect = cmd64x_cable_detect,
382 .dma_lost_irq = ide_dma_lost_irq,
383 .dma_timer_expiry = ide_dma_sff_timer_expiry,
384 .dma_sff_read_status = ide_dma_sff_read_status,
385}; 362};
386 363
387static const struct ide_dma_ops cmd646_rev1_dma_ops = { 364static const struct ide_dma_ops cmd646_rev1_dma_ops = {
@@ -395,24 +372,12 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
395 .dma_sff_read_status = ide_dma_sff_read_status, 372 .dma_sff_read_status = ide_dma_sff_read_status,
396}; 373};
397 374
398static const struct ide_dma_ops cmd648_dma_ops = {
399 .dma_host_set = ide_dma_host_set,
400 .dma_setup = ide_dma_setup,
401 .dma_start = ide_dma_start,
402 .dma_end = cmd648_dma_end,
403 .dma_test_irq = cmd648_dma_test_irq,
404 .dma_lost_irq = ide_dma_lost_irq,
405 .dma_timer_expiry = ide_dma_sff_timer_expiry,
406 .dma_sff_read_status = ide_dma_sff_read_status,
407};
408
409static const struct ide_port_info cmd64x_chipsets[] __devinitdata = { 375static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
410 { /* 0: CMD643 */ 376 { /* 0: CMD643 */
411 .name = DRV_NAME, 377 .name = DRV_NAME,
412 .init_chipset = init_chipset_cmd64x, 378 .init_chipset = init_chipset_cmd64x,
413 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 379 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
414 .port_ops = &cmd64x_port_ops, 380 .port_ops = &cmd64x_port_ops,
415 .dma_ops = &cmd64x_dma_ops,
416 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | 381 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX |
417 IDE_HFLAG_ABUSE_PREFETCH, 382 IDE_HFLAG_ABUSE_PREFETCH,
418 .pio_mask = ATA_PIO5, 383 .pio_mask = ATA_PIO5,
@@ -423,8 +388,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
423 .name = DRV_NAME, 388 .name = DRV_NAME,
424 .init_chipset = init_chipset_cmd64x, 389 .init_chipset = init_chipset_cmd64x,
425 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 390 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
426 .port_ops = &cmd64x_port_ops, 391 .port_ops = &cmd648_port_ops,
427 .dma_ops = &cmd648_dma_ops,
428 .host_flags = IDE_HFLAG_SERIALIZE | 392 .host_flags = IDE_HFLAG_SERIALIZE |
429 IDE_HFLAG_ABUSE_PREFETCH, 393 IDE_HFLAG_ABUSE_PREFETCH,
430 .pio_mask = ATA_PIO5, 394 .pio_mask = ATA_PIO5,
@@ -435,8 +399,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
435 .name = DRV_NAME, 399 .name = DRV_NAME,
436 .init_chipset = init_chipset_cmd64x, 400 .init_chipset = init_chipset_cmd64x,
437 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 401 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
438 .port_ops = &cmd64x_port_ops, 402 .port_ops = &cmd648_port_ops,
439 .dma_ops = &cmd648_dma_ops,
440 .host_flags = IDE_HFLAG_ABUSE_PREFETCH, 403 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
441 .pio_mask = ATA_PIO5, 404 .pio_mask = ATA_PIO5,
442 .mwdma_mask = ATA_MWDMA2, 405 .mwdma_mask = ATA_MWDMA2,
@@ -446,8 +409,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
446 .name = DRV_NAME, 409 .name = DRV_NAME,
447 .init_chipset = init_chipset_cmd64x, 410 .init_chipset = init_chipset_cmd64x,
448 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 411 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
449 .port_ops = &cmd64x_port_ops, 412 .port_ops = &cmd648_port_ops,
450 .dma_ops = &cmd648_dma_ops,
451 .host_flags = IDE_HFLAG_ABUSE_PREFETCH, 413 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
452 .pio_mask = ATA_PIO5, 414 .pio_mask = ATA_PIO5,
453 .mwdma_mask = ATA_MWDMA2, 415 .mwdma_mask = ATA_MWDMA2,
@@ -484,10 +446,9 @@ static int __devinit cmd64x_init_one(struct pci_dev *dev, const struct pci_devic
484 */ 446 */
485 if (dev->revision < 3) { 447 if (dev->revision < 3) {
486 d.enablebits[0].reg = 0; 448 d.enablebits[0].reg = 0;
449 d.port_ops = &cmd64x_port_ops;
487 if (dev->revision == 1) 450 if (dev->revision == 1)
488 d.dma_ops = &cmd646_rev1_dma_ops; 451 d.dma_ops = &cmd646_rev1_dma_ops;
489 else
490 d.dma_ops = &cmd64x_dma_ops;
491 } 452 }
492 } 453 }
493 } 454 }
diff --git a/drivers/ide/cs5536.c b/drivers/ide/cs5536.c
index 0332a95eefd4..9623b852c616 100644
--- a/drivers/ide/cs5536.c
+++ b/drivers/ide/cs5536.c
@@ -146,14 +146,16 @@ static void cs5536_set_pio_mode(ide_drive_t *drive, const u8 pio)
146 struct pci_dev *pdev = to_pci_dev(drive->hwif->dev); 146 struct pci_dev *pdev = to_pci_dev(drive->hwif->dev);
147 ide_drive_t *pair = ide_get_pair_dev(drive); 147 ide_drive_t *pair = ide_get_pair_dev(drive);
148 int cshift = (drive->dn & 1) ? IDE_CAST_D1_SHIFT : IDE_CAST_D0_SHIFT; 148 int cshift = (drive->dn & 1) ? IDE_CAST_D1_SHIFT : IDE_CAST_D0_SHIFT;
149 unsigned long timings = (unsigned long)ide_get_drivedata(drive);
149 u32 cast; 150 u32 cast;
150 u8 cmd_pio = pio; 151 u8 cmd_pio = pio;
151 152
152 if (pair) 153 if (pair)
153 cmd_pio = min(pio, ide_get_best_pio_mode(pair, 255, 4)); 154 cmd_pio = min(pio, ide_get_best_pio_mode(pair, 255, 4));
154 155
155 drive->drive_data &= (IDE_DRV_MASK << 8); 156 timings &= (IDE_DRV_MASK << 8);
156 drive->drive_data |= drv_timings[pio]; 157 timings |= drv_timings[pio];
158 ide_set_drivedata(drive, (void *)timings);
157 159
158 cs5536_program_dtc(drive, drv_timings[pio]); 160 cs5536_program_dtc(drive, drv_timings[pio]);
159 161
@@ -186,6 +188,7 @@ static void cs5536_set_dma_mode(ide_drive_t *drive, const u8 mode)
186 188
187 struct pci_dev *pdev = to_pci_dev(drive->hwif->dev); 189 struct pci_dev *pdev = to_pci_dev(drive->hwif->dev);
188 int dshift = (drive->dn & 1) ? IDE_D1_SHIFT : IDE_D0_SHIFT; 190 int dshift = (drive->dn & 1) ? IDE_D1_SHIFT : IDE_D0_SHIFT;
191 unsigned long timings = (unsigned long)ide_get_drivedata(drive);
189 u32 etc; 192 u32 etc;
190 193
191 cs5536_read(pdev, ETC, &etc); 194 cs5536_read(pdev, ETC, &etc);
@@ -195,8 +198,9 @@ static void cs5536_set_dma_mode(ide_drive_t *drive, const u8 mode)
195 etc |= udma_timings[mode - XFER_UDMA_0] << dshift; 198 etc |= udma_timings[mode - XFER_UDMA_0] << dshift;
196 } else { /* MWDMA */ 199 } else { /* MWDMA */
197 etc &= ~(IDE_ETC_UDMA_MASK << dshift); 200 etc &= ~(IDE_ETC_UDMA_MASK << dshift);
198 drive->drive_data &= IDE_DRV_MASK; 201 timings &= IDE_DRV_MASK;
199 drive->drive_data |= mwdma_timings[mode - XFER_MW_DMA_0] << 8; 202 timings |= mwdma_timings[mode - XFER_MW_DMA_0] << 8;
203 ide_set_drivedata(drive, (void *)timings);
200 } 204 }
201 205
202 cs5536_write(pdev, ETC, etc); 206 cs5536_write(pdev, ETC, etc);
@@ -204,9 +208,11 @@ static void cs5536_set_dma_mode(ide_drive_t *drive, const u8 mode)
204 208
205static void cs5536_dma_start(ide_drive_t *drive) 209static void cs5536_dma_start(ide_drive_t *drive)
206{ 210{
211 unsigned long timings = (unsigned long)ide_get_drivedata(drive);
212
207 if (drive->current_speed < XFER_UDMA_0 && 213 if (drive->current_speed < XFER_UDMA_0 &&
208 (drive->drive_data >> 8) != (drive->drive_data & IDE_DRV_MASK)) 214 (timings >> 8) != (timings & IDE_DRV_MASK))
209 cs5536_program_dtc(drive, drive->drive_data >> 8); 215 cs5536_program_dtc(drive, timings >> 8);
210 216
211 ide_dma_start(drive); 217 ide_dma_start(drive);
212} 218}
@@ -214,10 +220,11 @@ static void cs5536_dma_start(ide_drive_t *drive)
214static int cs5536_dma_end(ide_drive_t *drive) 220static int cs5536_dma_end(ide_drive_t *drive)
215{ 221{
216 int ret = ide_dma_end(drive); 222 int ret = ide_dma_end(drive);
223 unsigned long timings = (unsigned long)ide_get_drivedata(drive);
217 224
218 if (drive->current_speed < XFER_UDMA_0 && 225 if (drive->current_speed < XFER_UDMA_0 &&
219 (drive->drive_data >> 8) != (drive->drive_data & IDE_DRV_MASK)) 226 (timings >> 8) != (timings & IDE_DRV_MASK))
220 cs5536_program_dtc(drive, drive->drive_data & IDE_DRV_MASK); 227 cs5536_program_dtc(drive, timings & IDE_DRV_MASK);
221 228
222 return ret; 229 return ret;
223} 230}
diff --git a/drivers/ide/falconide.c b/drivers/ide/falconide.c
index 22fa27389c3b..a5a07ccb81a7 100644
--- a/drivers/ide/falconide.c
+++ b/drivers/ide/falconide.c
@@ -128,7 +128,6 @@ static void __init falconide_setup_ports(struct ide_hw *hw)
128 hw->io_ports.ctl_addr = ATA_HD_BASE + ATA_HD_CONTROL; 128 hw->io_ports.ctl_addr = ATA_HD_BASE + ATA_HD_CONTROL;
129 129
130 hw->irq = IRQ_MFP_IDE; 130 hw->irq = IRQ_MFP_IDE;
131 hw->ack_intr = NULL;
132} 131}
133 132
134 /* 133 /*
diff --git a/drivers/ide/gayle.c b/drivers/ide/gayle.c
index 4451a6a5dfe0..b9e517de6a82 100644
--- a/drivers/ide/gayle.c
+++ b/drivers/ide/gayle.c
@@ -66,7 +66,7 @@ MODULE_PARM_DESC(doubler, "enable support for IDE doublers");
66 * Check and acknowledge the interrupt status 66 * Check and acknowledge the interrupt status
67 */ 67 */
68 68
69static int gayle_ack_intr_a4000(ide_hwif_t *hwif) 69static int gayle_test_irq(ide_hwif_t *hwif)
70{ 70{
71 unsigned char ch; 71 unsigned char ch;
72 72
@@ -76,21 +76,16 @@ static int gayle_ack_intr_a4000(ide_hwif_t *hwif)
76 return 1; 76 return 1;
77} 77}
78 78
79static int gayle_ack_intr_a1200(ide_hwif_t *hwif) 79static void gayle_a1200_clear_irq(ide_drive_t *drive)
80{ 80{
81 unsigned char ch; 81 ide_hwif_t *hwif = drive->hwif;
82 82
83 ch = z_readb(hwif->io_ports.irq_addr);
84 if (!(ch & GAYLE_IRQ_IDE))
85 return 0;
86 (void)z_readb(hwif->io_ports.status_addr); 83 (void)z_readb(hwif->io_ports.status_addr);
87 z_writeb(0x7c, hwif->io_ports.irq_addr); 84 z_writeb(0x7c, hwif->io_ports.irq_addr);
88 return 1;
89} 85}
90 86
91static void __init gayle_setup_ports(struct ide_hw *hw, unsigned long base, 87static void __init gayle_setup_ports(struct ide_hw *hw, unsigned long base,
92 unsigned long ctl, unsigned long irq_port, 88 unsigned long ctl, unsigned long irq_port)
93 ide_ack_intr_t *ack_intr)
94{ 89{
95 int i; 90 int i;
96 91
@@ -105,9 +100,17 @@ static void __init gayle_setup_ports(struct ide_hw *hw, unsigned long base,
105 hw->io_ports.irq_addr = irq_port; 100 hw->io_ports.irq_addr = irq_port;
106 101
107 hw->irq = IRQ_AMIGA_PORTS; 102 hw->irq = IRQ_AMIGA_PORTS;
108 hw->ack_intr = ack_intr;
109} 103}
110 104
105static const struct ide_port_ops gayle_a4000_port_ops = {
106 .test_irq = gayle_test_irq,
107};
108
109static const struct ide_port_ops gayle_a1200_port_ops = {
110 .clear_irq = gayle_a1200_clear_irq,
111 .test_irq = gayle_test_irq,
112};
113
111static const struct ide_port_info gayle_port_info = { 114static const struct ide_port_info gayle_port_info = {
112 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE | 115 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
113 IDE_HFLAG_NO_DMA, 116 IDE_HFLAG_NO_DMA,
@@ -123,9 +126,9 @@ static int __init gayle_init(void)
123{ 126{
124 unsigned long phys_base, res_start, res_n; 127 unsigned long phys_base, res_start, res_n;
125 unsigned long base, ctrlport, irqport; 128 unsigned long base, ctrlport, irqport;
126 ide_ack_intr_t *ack_intr;
127 int a4000, i, rc; 129 int a4000, i, rc;
128 struct ide_hw hw[GAYLE_NUM_HWIFS], *hws[GAYLE_NUM_HWIFS]; 130 struct ide_hw hw[GAYLE_NUM_HWIFS], *hws[GAYLE_NUM_HWIFS];
131 struct ide_port_info d = gayle_port_info;
129 132
130 if (!MACH_IS_AMIGA) 133 if (!MACH_IS_AMIGA)
131 return -ENODEV; 134 return -ENODEV;
@@ -148,11 +151,11 @@ found:
148 if (a4000) { 151 if (a4000) {
149 phys_base = GAYLE_BASE_4000; 152 phys_base = GAYLE_BASE_4000;
150 irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_4000); 153 irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_4000);
151 ack_intr = gayle_ack_intr_a4000; 154 d.port_ops = &gayle_a4000_port_ops;
152 } else { 155 } else {
153 phys_base = GAYLE_BASE_1200; 156 phys_base = GAYLE_BASE_1200;
154 irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200); 157 irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200);
155 ack_intr = gayle_ack_intr_a1200; 158 d.port_ops = &gayle_a1200_port_ops;
156 } 159 }
157 160
158 res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1); 161 res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1);
@@ -165,12 +168,12 @@ found:
165 base = (unsigned long)ZTWO_VADDR(phys_base + i * GAYLE_NEXT_PORT); 168 base = (unsigned long)ZTWO_VADDR(phys_base + i * GAYLE_NEXT_PORT);
166 ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0; 169 ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
167 170
168 gayle_setup_ports(&hw[i], base, ctrlport, irqport, ack_intr); 171 gayle_setup_ports(&hw[i], base, ctrlport, irqport);
169 172
170 hws[i] = &hw[i]; 173 hws[i] = &hw[i];
171 } 174 }
172 175
173 rc = ide_host_add(&gayle_port_info, hws, i, NULL); 176 rc = ide_host_add(&d, hws, i, NULL);
174 if (rc) 177 if (rc)
175 release_mem_region(res_start, res_n); 178 release_mem_region(res_start, res_n);
176 179
diff --git a/drivers/ide/ht6560b.c b/drivers/ide/ht6560b.c
index 2fb0f2965009..aafed8060e17 100644
--- a/drivers/ide/ht6560b.c
+++ b/drivers/ide/ht6560b.c
@@ -44,7 +44,12 @@
44 * bit3 (0x08): "1" 3 cycle time, "0" 2 cycle time (?) 44 * bit3 (0x08): "1" 3 cycle time, "0" 2 cycle time (?)
45 */ 45 */
46#define HT_CONFIG_PORT 0x3e6 46#define HT_CONFIG_PORT 0x3e6
47#define HT_CONFIG(drivea) (u8)(((drivea)->drive_data & 0xff00) >> 8) 47
48static inline u8 HT_CONFIG(ide_drive_t *drive)
49{
50 return ((unsigned long)ide_get_drivedata(drive) & 0xff00) >> 8;
51}
52
48/* 53/*
49 * FIFO + PREFETCH (both a/b-model) 54 * FIFO + PREFETCH (both a/b-model)
50 */ 55 */
@@ -90,7 +95,11 @@
90 * Active Time for each drive. Smaller value gives higher speed. 95 * Active Time for each drive. Smaller value gives higher speed.
91 * In case of failures you should probably fall back to a higher value. 96 * In case of failures you should probably fall back to a higher value.
92 */ 97 */
93#define HT_TIMING(drivea) (u8)((drivea)->drive_data & 0x00ff) 98static inline u8 HT_TIMING(ide_drive_t *drive)
99{
100 return (unsigned long)ide_get_drivedata(drive) & 0x00ff;
101}
102
94#define HT_TIMING_DEFAULT 0xff 103#define HT_TIMING_DEFAULT 0xff
95 104
96/* 105/*
@@ -242,23 +251,27 @@ static DEFINE_SPINLOCK(ht6560b_lock);
242 */ 251 */
243static void ht_set_prefetch(ide_drive_t *drive, u8 state) 252static void ht_set_prefetch(ide_drive_t *drive, u8 state)
244{ 253{
245 unsigned long flags; 254 unsigned long flags, config;
246 int t = HT_PREFETCH_MODE << 8; 255 int t = HT_PREFETCH_MODE << 8;
247 256
248 spin_lock_irqsave(&ht6560b_lock, flags); 257 spin_lock_irqsave(&ht6560b_lock, flags);
249 258
259 config = (unsigned long)ide_get_drivedata(drive);
260
250 /* 261 /*
251 * Prefetch mode and unmask irq seems to conflict 262 * Prefetch mode and unmask irq seems to conflict
252 */ 263 */
253 if (state) { 264 if (state) {
254 drive->drive_data |= t; /* enable prefetch mode */ 265 config |= t; /* enable prefetch mode */
255 drive->dev_flags |= IDE_DFLAG_NO_UNMASK; 266 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
256 drive->dev_flags &= ~IDE_DFLAG_UNMASK; 267 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
257 } else { 268 } else {
258 drive->drive_data &= ~t; /* disable prefetch mode */ 269 config &= ~t; /* disable prefetch mode */
259 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK; 270 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
260 } 271 }
261 272
273 ide_set_drivedata(drive, (void *)config);
274
262 spin_unlock_irqrestore(&ht6560b_lock, flags); 275 spin_unlock_irqrestore(&ht6560b_lock, flags);
263 276
264#ifdef DEBUG 277#ifdef DEBUG
@@ -268,7 +281,7 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
268 281
269static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio) 282static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio)
270{ 283{
271 unsigned long flags; 284 unsigned long flags, config;
272 u8 timing; 285 u8 timing;
273 286
274 switch (pio) { 287 switch (pio) {
@@ -281,8 +294,10 @@ static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio)
281 timing = ht_pio2timings(drive, pio); 294 timing = ht_pio2timings(drive, pio);
282 295
283 spin_lock_irqsave(&ht6560b_lock, flags); 296 spin_lock_irqsave(&ht6560b_lock, flags);
284 drive->drive_data &= 0xff00; 297 config = (unsigned long)ide_get_drivedata(drive);
285 drive->drive_data |= timing; 298 config &= 0xff00;
299 config |= timing;
300 ide_set_drivedata(drive, (void *)config);
286 spin_unlock_irqrestore(&ht6560b_lock, flags); 301 spin_unlock_irqrestore(&ht6560b_lock, flags);
287 302
288#ifdef DEBUG 303#ifdef DEBUG
@@ -299,7 +314,7 @@ static void __init ht6560b_init_dev(ide_drive_t *drive)
299 if (hwif->channel) 314 if (hwif->channel)
300 t |= (HT_SECONDARY_IF << 8); 315 t |= (HT_SECONDARY_IF << 8);
301 316
302 drive->drive_data = t; 317 ide_set_drivedata(drive, (void *)t);
303} 318}
304 319
305static int probe_ht6560b; 320static int probe_ht6560b;
diff --git a/drivers/ide/icside.c b/drivers/ide/icside.c
index 5af3d0ffaf0a..0f67f1abbbd3 100644
--- a/drivers/ide/icside.c
+++ b/drivers/ide/icside.c
@@ -187,7 +187,8 @@ static const expansioncard_ops_t icside_ops_arcin_v6 = {
187 */ 187 */
188static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode) 188static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
189{ 189{
190 int cycle_time, use_dma_info = 0; 190 unsigned long cycle_time;
191 int use_dma_info = 0;
191 192
192 switch (xfer_mode) { 193 switch (xfer_mode) {
193 case XFER_MW_DMA_2: 194 case XFER_MW_DMA_2:
@@ -218,10 +219,11 @@ static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
218 if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time) 219 if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time)
219 cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME]; 220 cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME];
220 221
221 drive->drive_data = cycle_time; 222 ide_set_drivedata(drive, (void *)cycle_time);
222 223
223 printk("%s: %s selected (peak %dMB/s)\n", drive->name, 224 printk("%s: %s selected (peak %dMB/s)\n", drive->name,
224 ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data); 225 ide_xfer_verbose(xfer_mode),
226 2000 / (unsigned long)ide_get_drivedata(drive));
225} 227}
226 228
227static const struct ide_port_ops icside_v6_port_ops = { 229static const struct ide_port_ops icside_v6_port_ops = {
@@ -277,7 +279,7 @@ static int icside_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
277 /* 279 /*
278 * Select the correct timing for this drive. 280 * Select the correct timing for this drive.
279 */ 281 */
280 set_dma_speed(ec->dma, drive->drive_data); 282 set_dma_speed(ec->dma, (unsigned long)ide_get_drivedata(drive));
281 283
282 /* 284 /*
283 * Tell the DMA engine about the SG table and 285 * Tell the DMA engine about the SG table and
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 702ef64a0f12..eb2181a6a11c 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -10,6 +10,9 @@
10 10
11#include <scsi/scsi.h> 11#include <scsi/scsi.h>
12 12
13#define DRV_NAME "ide-atapi"
14#define PFX DRV_NAME ": "
15
13#ifdef DEBUG 16#ifdef DEBUG
14#define debug_log(fmt, args...) \ 17#define debug_log(fmt, args...) \
15 printk(KERN_INFO "ide: " fmt, ## args) 18 printk(KERN_INFO "ide: " fmt, ## args)
@@ -74,8 +77,6 @@ EXPORT_SYMBOL_GPL(ide_check_atapi_device);
74void ide_init_pc(struct ide_atapi_pc *pc) 77void ide_init_pc(struct ide_atapi_pc *pc)
75{ 78{
76 memset(pc, 0, sizeof(*pc)); 79 memset(pc, 0, sizeof(*pc));
77 pc->buf = pc->pc_buf;
78 pc->buf_size = IDE_PC_BUFFER_SIZE;
79} 80}
80EXPORT_SYMBOL_GPL(ide_init_pc); 81EXPORT_SYMBOL_GPL(ide_init_pc);
81 82
@@ -84,7 +85,7 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
84 * and wait for it to be serviced. 85 * and wait for it to be serviced.
85 */ 86 */
86int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk, 87int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
87 struct ide_atapi_pc *pc) 88 struct ide_atapi_pc *pc, void *buf, unsigned int bufflen)
88{ 89{
89 struct request *rq; 90 struct request *rq;
90 int error; 91 int error;
@@ -93,8 +94,8 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
93 rq->cmd_type = REQ_TYPE_SPECIAL; 94 rq->cmd_type = REQ_TYPE_SPECIAL;
94 rq->special = (char *)pc; 95 rq->special = (char *)pc;
95 96
96 if (pc->req_xfer) { 97 if (buf && bufflen) {
97 error = blk_rq_map_kern(drive->queue, rq, pc->buf, pc->req_xfer, 98 error = blk_rq_map_kern(drive->queue, rq, buf, bufflen,
98 GFP_NOIO); 99 GFP_NOIO);
99 if (error) 100 if (error)
100 goto put_req; 101 goto put_req;
@@ -117,7 +118,7 @@ int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
117 ide_init_pc(&pc); 118 ide_init_pc(&pc);
118 pc.c[0] = TEST_UNIT_READY; 119 pc.c[0] = TEST_UNIT_READY;
119 120
120 return ide_queue_pc_tail(drive, disk, &pc); 121 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
121} 122}
122EXPORT_SYMBOL_GPL(ide_do_test_unit_ready); 123EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
123 124
@@ -132,7 +133,7 @@ int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
132 if (drive->media == ide_tape) 133 if (drive->media == ide_tape)
133 pc.flags |= PC_FLAG_WAIT_FOR_DSC; 134 pc.flags |= PC_FLAG_WAIT_FOR_DSC;
134 135
135 return ide_queue_pc_tail(drive, disk, &pc); 136 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
136} 137}
137EXPORT_SYMBOL_GPL(ide_do_start_stop); 138EXPORT_SYMBOL_GPL(ide_do_start_stop);
138 139
@@ -147,7 +148,7 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
147 pc.c[0] = ALLOW_MEDIUM_REMOVAL; 148 pc.c[0] = ALLOW_MEDIUM_REMOVAL;
148 pc.c[4] = on; 149 pc.c[4] = on;
149 150
150 return ide_queue_pc_tail(drive, disk, &pc); 151 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
151} 152}
152EXPORT_SYMBOL_GPL(ide_set_media_lock); 153EXPORT_SYMBOL_GPL(ide_set_media_lock);
153 154
@@ -172,8 +173,6 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
172 unsigned int cmd_len, sense_len; 173 unsigned int cmd_len, sense_len;
173 int err; 174 int err;
174 175
175 debug_log("%s: enter\n", __func__);
176
177 switch (drive->media) { 176 switch (drive->media) {
178 case ide_floppy: 177 case ide_floppy:
179 cmd_len = 255; 178 cmd_len = 255;
@@ -201,8 +200,8 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
201 GFP_NOIO); 200 GFP_NOIO);
202 if (unlikely(err)) { 201 if (unlikely(err)) {
203 if (printk_ratelimit()) 202 if (printk_ratelimit())
204 printk(KERN_WARNING "%s: failed to map sense buffer\n", 203 printk(KERN_WARNING PFX "%s: failed to map sense "
205 drive->name); 204 "buffer\n", drive->name);
206 return; 205 return;
207 } 206 }
208 207
@@ -223,7 +222,7 @@ int ide_queue_sense_rq(ide_drive_t *drive, void *special)
223{ 222{
224 /* deferred failure from ide_prep_sense() */ 223 /* deferred failure from ide_prep_sense() */
225 if (!drive->sense_rq_armed) { 224 if (!drive->sense_rq_armed) {
226 printk(KERN_WARNING "%s: failed queue sense request\n", 225 printk(KERN_WARNING PFX "%s: error queuing a sense request\n",
227 drive->name); 226 drive->name);
228 return -ENOMEM; 227 return -ENOMEM;
229 } 228 }
@@ -255,8 +254,6 @@ void ide_retry_pc(ide_drive_t *drive)
255 /* init pc from sense_rq */ 254 /* init pc from sense_rq */
256 ide_init_pc(pc); 255 ide_init_pc(pc);
257 memcpy(pc->c, sense_rq->cmd, 12); 256 memcpy(pc->c, sense_rq->cmd, 12);
258 pc->buf = bio_data(sense_rq->bio); /* pointer to mapped address */
259 pc->req_xfer = blk_rq_bytes(sense_rq);
260 257
261 if (drive->media == ide_tape) 258 if (drive->media == ide_tape)
262 drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; 259 drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
@@ -298,7 +295,7 @@ int ide_cd_expiry(ide_drive_t *drive)
298 break; 295 break;
299 default: 296 default:
300 if (!(rq->cmd_flags & REQ_QUIET)) 297 if (!(rq->cmd_flags & REQ_QUIET))
301 printk(KERN_INFO "cmd 0x%x timed out\n", 298 printk(KERN_INFO PFX "cmd 0x%x timed out\n",
302 rq->cmd[0]); 299 rq->cmd[0]);
303 wait = 0; 300 wait = 0;
304 break; 301 break;
@@ -332,6 +329,55 @@ void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
332EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason); 329EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
333 330
334/* 331/*
332 * Check the contents of the interrupt reason register and attempt to recover if
333 * there are problems.
334 *
335 * Returns:
336 * - 0 if everything's ok
337 * - 1 if the request has to be terminated.
338 */
339int ide_check_ireason(ide_drive_t *drive, struct request *rq, int len,
340 int ireason, int rw)
341{
342 ide_hwif_t *hwif = drive->hwif;
343
344 debug_log("ireason: 0x%x, rw: 0x%x\n", ireason, rw);
345
346 if (ireason == (!rw << 1))
347 return 0;
348 else if (ireason == (rw << 1)) {
349 printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
350 drive->name, __func__);
351
352 if (dev_is_idecd(drive))
353 ide_pad_transfer(drive, rw, len);
354 } else if (!rw && ireason == ATAPI_COD) {
355 if (dev_is_idecd(drive)) {
356 /*
357 * Some drives (ASUS) seem to tell us that status info
358 * is available. Just get it and ignore.
359 */
360 (void)hwif->tp_ops->read_status(hwif);
361 return 0;
362 }
363 } else {
364 if (ireason & ATAPI_COD)
365 printk(KERN_ERR PFX "%s: CoD != 0 in %s\n", drive->name,
366 __func__);
367
368 /* drive wants a command packet, or invalid ireason... */
369 printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
370 drive->name, __func__, ireason);
371 }
372
373 if (dev_is_idecd(drive) && rq->cmd_type == REQ_TYPE_ATA_PC)
374 rq->cmd_flags |= REQ_FAILED;
375
376 return 1;
377}
378EXPORT_SYMBOL_GPL(ide_check_ireason);
379
380/*
335 * This is the usual interrupt handler which will be called during a packet 381 * This is the usual interrupt handler which will be called during a packet
336 * command. We will transfer some of the data (as requested by the drive) 382 * command. We will transfer some of the data (as requested by the drive)
337 * and will re-point interrupt handler to us. 383 * and will re-point interrupt handler to us.
@@ -365,12 +411,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
365 411
366 if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) { 412 if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) {
367 if (drive->media == ide_floppy) 413 if (drive->media == ide_floppy)
368 printk(KERN_ERR "%s: DMA %s error\n", 414 printk(KERN_ERR PFX "%s: DMA %s error\n",
369 drive->name, rq_data_dir(pc->rq) 415 drive->name, rq_data_dir(pc->rq)
370 ? "write" : "read"); 416 ? "write" : "read");
371 pc->flags |= PC_FLAG_DMA_ERROR; 417 pc->flags |= PC_FLAG_DMA_ERROR;
372 } else 418 } else
373 pc->xferred = pc->req_xfer; 419 rq->resid_len = 0;
374 debug_log("%s: DMA finished\n", drive->name); 420 debug_log("%s: DMA finished\n", drive->name);
375 } 421 }
376 422
@@ -379,7 +425,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
379 int uptodate, error; 425 int uptodate, error;
380 426
381 debug_log("Packet command completed, %d bytes transferred\n", 427 debug_log("Packet command completed, %d bytes transferred\n",
382 pc->xferred); 428 blk_rq_bytes(rq));
383 429
384 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; 430 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
385 431
@@ -397,8 +443,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
397 pc->rq->errors++; 443 pc->rq->errors++;
398 444
399 if (rq->cmd[0] == REQUEST_SENSE) { 445 if (rq->cmd[0] == REQUEST_SENSE) {
400 printk(KERN_ERR "%s: I/O error in request sense" 446 printk(KERN_ERR PFX "%s: I/O error in request "
401 " command\n", drive->name); 447 "sense command\n", drive->name);
402 return ide_do_reset(drive); 448 return ide_do_reset(drive);
403 } 449 }
404 450
@@ -446,8 +492,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
446 492
447 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { 493 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
448 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; 494 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
449 printk(KERN_ERR "%s: The device wants to issue more interrupts " 495 printk(KERN_ERR PFX "%s: The device wants to issue more "
450 "in DMA mode\n", drive->name); 496 "interrupts in DMA mode\n", drive->name);
451 ide_dma_off(drive); 497 ide_dma_off(drive);
452 return ide_do_reset(drive); 498 return ide_do_reset(drive);
453 } 499 }
@@ -455,33 +501,22 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
455 /* Get the number of bytes to transfer on this interrupt. */ 501 /* Get the number of bytes to transfer on this interrupt. */
456 ide_read_bcount_and_ireason(drive, &bcount, &ireason); 502 ide_read_bcount_and_ireason(drive, &bcount, &ireason);
457 503
458 if (ireason & ATAPI_COD) { 504 if (ide_check_ireason(drive, rq, bcount, ireason, write))
459 printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__);
460 return ide_do_reset(drive); 505 return ide_do_reset(drive);
461 }
462
463 if (((ireason & ATAPI_IO) == ATAPI_IO) == write) {
464 /* Hopefully, we will never get here */
465 printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
466 "to %s!\n", drive->name,
467 (ireason & ATAPI_IO) ? "Write" : "Read",
468 (ireason & ATAPI_IO) ? "Read" : "Write");
469 return ide_do_reset(drive);
470 }
471 506
472 done = min_t(unsigned int, bcount, cmd->nleft); 507 done = min_t(unsigned int, bcount, cmd->nleft);
473 ide_pio_bytes(drive, cmd, write, done); 508 ide_pio_bytes(drive, cmd, write, done);
474 509
475 /* Update transferred byte count */ 510 /* Update transferred byte count */
476 pc->xferred += done; 511 rq->resid_len -= done;
477 512
478 bcount -= done; 513 bcount -= done;
479 514
480 if (bcount) 515 if (bcount)
481 ide_pad_transfer(drive, write, bcount); 516 ide_pad_transfer(drive, write, bcount);
482 517
483 debug_log("[cmd %x] transferred %d bytes, padded %d bytes\n", 518 debug_log("[cmd %x] transferred %d bytes, padded %d bytes, resid: %u\n",
484 rq->cmd[0], done, bcount); 519 rq->cmd[0], done, bcount, rq->resid_len);
485 520
486 /* And set the interrupt handler again */ 521 /* And set the interrupt handler again */
487 ide_set_handler(drive, ide_pc_intr, timeout); 522 ide_set_handler(drive, ide_pc_intr, timeout);
@@ -515,13 +550,13 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
515 550
516 while (retries-- && ((ireason & ATAPI_COD) == 0 || 551 while (retries-- && ((ireason & ATAPI_COD) == 0 ||
517 (ireason & ATAPI_IO))) { 552 (ireason & ATAPI_IO))) {
518 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " 553 printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing "
519 "a packet command, retrying\n", drive->name); 554 "a packet command, retrying\n", drive->name);
520 udelay(100); 555 udelay(100);
521 ireason = ide_read_ireason(drive); 556 ireason = ide_read_ireason(drive);
522 if (retries == 0) { 557 if (retries == 0) {
523 printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " 558 printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing"
524 "a packet command, ignoring\n", 559 " a packet command, ignoring\n",
525 drive->name); 560 drive->name);
526 ireason |= ATAPI_COD; 561 ireason |= ATAPI_COD;
527 ireason &= ~ATAPI_IO; 562 ireason &= ~ATAPI_IO;
@@ -552,7 +587,7 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
552 u8 ireason; 587 u8 ireason;
553 588
554 if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) { 589 if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) {
555 printk(KERN_ERR "%s: Strange, packet command initiated yet " 590 printk(KERN_ERR PFX "%s: Strange, packet command initiated yet "
556 "DRQ isn't asserted\n", drive->name); 591 "DRQ isn't asserted\n", drive->name);
557 return startstop; 592 return startstop;
558 } 593 }
@@ -594,8 +629,8 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
594 ireason = ide_wait_ireason(drive, ireason); 629 ireason = ide_wait_ireason(drive, ireason);
595 630
596 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) { 631 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
597 printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing " 632 printk(KERN_ERR PFX "%s: (IO,CoD) != (0,1) while "
598 "a packet command\n", drive->name); 633 "issuing a packet command\n", drive->name);
599 634
600 return ide_do_reset(drive); 635 return ide_do_reset(drive);
601 } 636 }
@@ -633,7 +668,7 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
633 ide_hwif_t *hwif = drive->hwif; 668 ide_hwif_t *hwif = drive->hwif;
634 ide_expiry_t *expiry = NULL; 669 ide_expiry_t *expiry = NULL;
635 struct request *rq = hwif->rq; 670 struct request *rq = hwif->rq;
636 unsigned int timeout; 671 unsigned int timeout, bytes;
637 u16 bcount; 672 u16 bcount;
638 u8 valid_tf; 673 u8 valid_tf;
639 u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT); 674 u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT);
@@ -649,13 +684,14 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
649 } else { 684 } else {
650 pc = drive->pc; 685 pc = drive->pc;
651 686
652 /* We haven't transferred any data yet */
653 pc->xferred = 0;
654
655 valid_tf = IDE_VALID_DEVICE; 687 valid_tf = IDE_VALID_DEVICE;
656 bcount = ((drive->media == ide_tape) ? 688 bytes = blk_rq_bytes(rq);
657 pc->req_xfer : 689 bcount = ((drive->media == ide_tape) ? bytes
658 min(pc->req_xfer, 63 * 1024)); 690 : min_t(unsigned int,
691 bytes, 63 * 1024));
692
693 /* We haven't transferred any data yet */
694 rq->resid_len = bcount;
659 695
660 if (pc->flags & PC_FLAG_DMA_ERROR) { 696 if (pc->flags & PC_FLAG_DMA_ERROR) {
661 pc->flags &= ~PC_FLAG_DMA_ERROR; 697 pc->flags &= ~PC_FLAG_DMA_ERROR;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 424140c6c400..4a19686fcfe9 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -92,16 +92,16 @@ static void cdrom_saw_media_change(ide_drive_t *drive)
92 drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID; 92 drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID;
93} 93}
94 94
95static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, 95static int cdrom_log_sense(ide_drive_t *drive, struct request *rq)
96 struct request_sense *sense)
97{ 96{
97 struct request_sense *sense = &drive->sense_data;
98 int log = 0; 98 int log = 0;
99 99
100 ide_debug_log(IDE_DBG_SENSE, "sense_key: 0x%x", sense->sense_key);
101
102 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) 100 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
103 return 0; 101 return 0;
104 102
103 ide_debug_log(IDE_DBG_SENSE, "sense_key: 0x%x", sense->sense_key);
104
105 switch (sense->sense_key) { 105 switch (sense->sense_key) {
106 case NO_SENSE: 106 case NO_SENSE:
107 case RECOVERED_ERROR: 107 case RECOVERED_ERROR:
@@ -140,12 +140,12 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
140} 140}
141 141
142static void cdrom_analyze_sense_data(ide_drive_t *drive, 142static void cdrom_analyze_sense_data(ide_drive_t *drive,
143 struct request *failed_command, 143 struct request *failed_command)
144 struct request_sense *sense)
145{ 144{
145 struct request_sense *sense = &drive->sense_data;
146 struct cdrom_info *info = drive->driver_data;
146 unsigned long sector; 147 unsigned long sector;
147 unsigned long bio_sectors; 148 unsigned long bio_sectors;
148 struct cdrom_info *info = drive->driver_data;
149 149
150 ide_debug_log(IDE_DBG_SENSE, "error_code: 0x%x, sense_key: 0x%x", 150 ide_debug_log(IDE_DBG_SENSE, "error_code: 0x%x, sense_key: 0x%x",
151 sense->error_code, sense->sense_key); 151 sense->error_code, sense->sense_key);
@@ -154,7 +154,7 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
154 ide_debug_log(IDE_DBG_SENSE, "failed cmd: 0x%x", 154 ide_debug_log(IDE_DBG_SENSE, "failed cmd: 0x%x",
155 failed_command->cmd[0]); 155 failed_command->cmd[0]);
156 156
157 if (!cdrom_log_sense(drive, failed_command, sense)) 157 if (!cdrom_log_sense(drive, failed_command))
158 return; 158 return;
159 159
160 /* 160 /*
@@ -225,15 +225,14 @@ static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
225 * sense pointer set. 225 * sense pointer set.
226 */ 226 */
227 memcpy(failed->sense, sense, 18); 227 memcpy(failed->sense, sense, 18);
228 sense = failed->sense;
229 failed->sense_len = rq->sense_len; 228 failed->sense_len = rq->sense_len;
230 } 229 }
231 cdrom_analyze_sense_data(drive, failed, sense); 230 cdrom_analyze_sense_data(drive, failed);
232 231
233 if (ide_end_rq(drive, failed, -EIO, blk_rq_bytes(failed))) 232 if (ide_end_rq(drive, failed, -EIO, blk_rq_bytes(failed)))
234 BUG(); 233 BUG();
235 } else 234 } else
236 cdrom_analyze_sense_data(drive, NULL, sense); 235 cdrom_analyze_sense_data(drive, NULL);
237} 236}
238 237
239 238
@@ -410,50 +409,6 @@ end_request:
410 return 2; 409 return 2;
411} 410}
412 411
413/*
414 * Check the contents of the interrupt reason register from the cdrom
415 * and attempt to recover if there are problems. Returns 0 if everything's
416 * ok; nonzero if the request has been terminated.
417 */
418static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
419 int len, int ireason, int rw)
420{
421 ide_hwif_t *hwif = drive->hwif;
422
423 ide_debug_log(IDE_DBG_FUNC, "ireason: 0x%x, rw: 0x%x", ireason, rw);
424
425 /*
426 * ireason == 0: the drive wants to receive data from us
427 * ireason == 2: the drive is expecting to transfer data to us
428 */
429 if (ireason == (!rw << 1))
430 return 0;
431 else if (ireason == (rw << 1)) {
432
433 /* whoops... */
434 printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
435 drive->name, __func__);
436
437 ide_pad_transfer(drive, rw, len);
438 } else if (rw == 0 && ireason == 1) {
439 /*
440 * Some drives (ASUS) seem to tell us that status info is
441 * available. Just get it and ignore.
442 */
443 (void)hwif->tp_ops->read_status(hwif);
444 return 0;
445 } else {
446 /* drive wants a command packet, or invalid ireason... */
447 printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
448 drive->name, __func__, ireason);
449 }
450
451 if (rq->cmd_type == REQ_TYPE_ATA_PC)
452 rq->cmd_flags |= REQ_FAILED;
453
454 return -1;
455}
456
457static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd) 412static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd)
458{ 413{
459 struct request *rq = cmd->rq; 414 struct request *rq = cmd->rq;
@@ -645,8 +600,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
645 goto out_end; 600 goto out_end;
646 } 601 }
647 602
648 /* check which way to transfer data */ 603 rc = ide_check_ireason(drive, rq, len, ireason, write);
649 rc = ide_cd_check_ireason(drive, rq, len, ireason, write);
650 if (rc) 604 if (rc)
651 goto out_end; 605 goto out_end;
652 606
@@ -713,7 +667,7 @@ out_end:
713 rq->errors = -EIO; 667 rq->errors = -EIO;
714 } 668 }
715 669
716 if (uptodate == 0) 670 if (uptodate == 0 && rq->bio)
717 ide_cd_error_cmd(drive, cmd); 671 ide_cd_error_cmd(drive, cmd);
718 672
719 /* make sure it's fully ended */ 673 /* make sure it's fully ended */
@@ -831,12 +785,8 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
831 /* right now this can only be a reset... */ 785 /* right now this can only be a reset... */
832 uptodate = 1; 786 uptodate = 1;
833 goto out_end; 787 goto out_end;
834 } else { 788 } else
835 blk_dump_rq_flags(rq, DRV_NAME " bad flags"); 789 BUG();
836 if (rq->errors == 0)
837 rq->errors = -EIO;
838 goto out_end;
839 }
840 790
841 /* prepare sense request for this command */ 791 /* prepare sense request for this command */
842 ide_prep_sense(drive, rq); 792 ide_prep_sense(drive, rq);
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 6a1de2169709..695181120cdb 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -184,14 +184,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
184 ide_hwif_t *hwif = drive->hwif; 184 ide_hwif_t *hwif = drive->hwif;
185 185
186 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED); 186 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
187 187 BUG_ON(!blk_fs_request(rq));
188 if (!blk_fs_request(rq)) {
189 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
190 if (rq->errors == 0)
191 rq->errors = -EIO;
192 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
193 return ide_stopped;
194 }
195 188
196 ledtrig_ide_activity(); 189 ledtrig_ide_activity();
197 190
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 650981758f15..8b3f204f7d73 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -77,7 +77,8 @@ static int ide_floppy_callback(ide_drive_t *drive, int dsc)
77 (rq && blk_pc_request(rq))) 77 (rq && blk_pc_request(rq)))
78 uptodate = 1; /* FIXME */ 78 uptodate = 1; /* FIXME */
79 else if (pc->c[0] == GPCMD_REQUEST_SENSE) { 79 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
80 u8 *buf = pc->buf; 80
81 u8 *buf = bio_data(rq->bio);
81 82
82 if (!pc->error) { 83 if (!pc->error) {
83 floppy->sense_key = buf[2] & 0x0F; 84 floppy->sense_key = buf[2] & 0x0F;
@@ -209,8 +210,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
209 pc->rq = rq; 210 pc->rq = rq;
210 if (rq->cmd_flags & REQ_RW) 211 if (rq->cmd_flags & REQ_RW)
211 pc->flags |= PC_FLAG_WRITING; 212 pc->flags |= PC_FLAG_WRITING;
212 pc->buf = NULL; 213
213 pc->req_xfer = pc->buf_size = blocks * floppy->block_size;
214 pc->flags |= PC_FLAG_DMA_OK; 214 pc->flags |= PC_FLAG_DMA_OK;
215} 215}
216 216
@@ -225,9 +225,6 @@ static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
225 if (rq_data_dir(rq) == WRITE) 225 if (rq_data_dir(rq) == WRITE)
226 pc->flags |= PC_FLAG_WRITING; 226 pc->flags |= PC_FLAG_WRITING;
227 } 227 }
228 /* pio will be performed by ide_pio_bytes() which handles sg fine */
229 pc->buf = NULL;
230 pc->req_xfer = pc->buf_size = blk_rq_bytes(rq);
231} 228}
232 229
233static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, 230static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
@@ -272,10 +269,8 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
272 } else if (blk_pc_request(rq)) { 269 } else if (blk_pc_request(rq)) {
273 pc = &floppy->queued_pc; 270 pc = &floppy->queued_pc;
274 idefloppy_blockpc_cmd(floppy, pc, rq); 271 idefloppy_blockpc_cmd(floppy, pc, rq);
275 } else { 272 } else
276 blk_dump_rq_flags(rq, PFX "unsupported command in queue"); 273 BUG();
277 goto out_end;
278 }
279 274
280 ide_prep_sense(drive, rq); 275 ide_prep_sense(drive, rq);
281 276
@@ -286,8 +281,8 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
286 281
287 cmd.rq = rq; 282 cmd.rq = rq;
288 283
289 if (blk_fs_request(rq) || pc->req_xfer) { 284 if (blk_fs_request(rq) || blk_rq_bytes(rq)) {
290 ide_init_sg_cmd(&cmd, pc->req_xfer); 285 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
291 ide_map_sg(drive, &cmd); 286 ide_map_sg(drive, &cmd);
292 } 287 }
293 288
@@ -311,33 +306,33 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive,
311{ 306{
312 struct ide_disk_obj *floppy = drive->driver_data; 307 struct ide_disk_obj *floppy = drive->driver_data;
313 struct gendisk *disk = floppy->disk; 308 struct gendisk *disk = floppy->disk;
314 u8 *page; 309 u8 *page, buf[40];
315 int capacity, lba_capacity; 310 int capacity, lba_capacity;
316 u16 transfer_rate, sector_size, cyls, rpm; 311 u16 transfer_rate, sector_size, cyls, rpm;
317 u8 heads, sectors; 312 u8 heads, sectors;
318 313
319 ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE); 314 ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
320 315
321 if (ide_queue_pc_tail(drive, disk, pc)) { 316 if (ide_queue_pc_tail(drive, disk, pc, buf, pc->req_xfer)) {
322 printk(KERN_ERR PFX "Can't get flexible disk page params\n"); 317 printk(KERN_ERR PFX "Can't get flexible disk page params\n");
323 return 1; 318 return 1;
324 } 319 }
325 320
326 if (pc->buf[3] & 0x80) 321 if (buf[3] & 0x80)
327 drive->dev_flags |= IDE_DFLAG_WP; 322 drive->dev_flags |= IDE_DFLAG_WP;
328 else 323 else
329 drive->dev_flags &= ~IDE_DFLAG_WP; 324 drive->dev_flags &= ~IDE_DFLAG_WP;
330 325
331 set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP)); 326 set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP));
332 327
333 page = &pc->buf[8]; 328 page = &buf[8];
334 329
335 transfer_rate = be16_to_cpup((__be16 *)&pc->buf[8 + 2]); 330 transfer_rate = be16_to_cpup((__be16 *)&buf[8 + 2]);
336 sector_size = be16_to_cpup((__be16 *)&pc->buf[8 + 6]); 331 sector_size = be16_to_cpup((__be16 *)&buf[8 + 6]);
337 cyls = be16_to_cpup((__be16 *)&pc->buf[8 + 8]); 332 cyls = be16_to_cpup((__be16 *)&buf[8 + 8]);
338 rpm = be16_to_cpup((__be16 *)&pc->buf[8 + 28]); 333 rpm = be16_to_cpup((__be16 *)&buf[8 + 28]);
339 heads = pc->buf[8 + 4]; 334 heads = buf[8 + 4];
340 sectors = pc->buf[8 + 5]; 335 sectors = buf[8 + 5];
341 336
342 capacity = cyls * heads * sectors * sector_size; 337 capacity = cyls * heads * sectors * sector_size;
343 338
@@ -387,22 +382,19 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
387 drive->capacity64 = 0; 382 drive->capacity64 = 0;
388 383
389 ide_floppy_create_read_capacity_cmd(&pc); 384 ide_floppy_create_read_capacity_cmd(&pc);
390 pc.buf = &pc_buf[0]; 385 if (ide_queue_pc_tail(drive, disk, &pc, pc_buf, pc.req_xfer)) {
391 pc.buf_size = sizeof(pc_buf);
392
393 if (ide_queue_pc_tail(drive, disk, &pc)) {
394 printk(KERN_ERR PFX "Can't get floppy parameters\n"); 386 printk(KERN_ERR PFX "Can't get floppy parameters\n");
395 return 1; 387 return 1;
396 } 388 }
397 header_len = pc.buf[3]; 389 header_len = pc_buf[3];
398 cap_desc = &pc.buf[4]; 390 cap_desc = &pc_buf[4];
399 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ 391 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
400 392
401 for (i = 0; i < desc_cnt; i++) { 393 for (i = 0; i < desc_cnt; i++) {
402 unsigned int desc_start = 4 + i*8; 394 unsigned int desc_start = 4 + i*8;
403 395
404 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); 396 blocks = be32_to_cpup((__be32 *)&pc_buf[desc_start]);
405 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); 397 length = be16_to_cpup((__be16 *)&pc_buf[desc_start + 6]);
406 398
407 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, " 399 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
408 "%d sector size", 400 "%d sector size",
@@ -415,7 +407,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
415 * the code below is valid only for the 1st descriptor, ie i=0 407 * the code below is valid only for the 1st descriptor, ie i=0
416 */ 408 */
417 409
418 switch (pc.buf[desc_start + 4] & 0x03) { 410 switch (pc_buf[desc_start + 4] & 0x03) {
419 /* Clik! drive returns this instead of CAPACITY_CURRENT */ 411 /* Clik! drive returns this instead of CAPACITY_CURRENT */
420 case CAPACITY_UNFORMATTED: 412 case CAPACITY_UNFORMATTED:
421 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) 413 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
@@ -464,7 +456,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
464 break; 456 break;
465 } 457 }
466 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d", 458 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d",
467 pc.buf[desc_start + 4] & 0x03); 459 pc_buf[desc_start + 4] & 0x03);
468 } 460 }
469 461
470 /* Clik! disk does not support get_flexible_disk_page */ 462 /* Clik! disk does not support get_flexible_disk_page */
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index cd8a42027ede..9c2288234dea 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -47,15 +47,13 @@ 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
53 if (ide_queue_pc_tail(drive, floppy->disk, pc)) { 51 if (ide_queue_pc_tail(drive, floppy->disk, pc, pc_buf, pc->req_xfer)) {
54 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 52 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
55 return -EIO; 53 return -EIO;
56 } 54 }
57 55
58 header_len = pc->buf[3]; 56 header_len = pc_buf[3];
59 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ 57 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
60 58
61 u_index = 0; 59 u_index = 0;
@@ -72,8 +70,8 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive,
72 if (u_index >= u_array_size) 70 if (u_index >= u_array_size)
73 break; /* User-supplied buffer too small */ 71 break; /* User-supplied buffer too small */
74 72
75 blocks = be32_to_cpup((__be32 *)&pc->buf[desc_start]); 73 blocks = be32_to_cpup((__be32 *)&pc_buf[desc_start]);
76 length = be16_to_cpup((__be16 *)&pc->buf[desc_start + 6]); 74 length = be16_to_cpup((__be16 *)&pc_buf[desc_start + 6]);
77 75
78 if (put_user(blocks, argp)) 76 if (put_user(blocks, argp))
79 return -EFAULT; 77 return -EFAULT;
@@ -94,40 +92,42 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive,
94 return 0; 92 return 0;
95} 93}
96 94
97static void ide_floppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b, 95static void ide_floppy_create_format_unit_cmd(struct ide_atapi_pc *pc,
98 int l, int flags) 96 u8 *buf, int b, int l,
97 int flags)
99{ 98{
100 ide_init_pc(pc); 99 ide_init_pc(pc);
101 pc->c[0] = GPCMD_FORMAT_UNIT; 100 pc->c[0] = GPCMD_FORMAT_UNIT;
102 pc->c[1] = 0x17; 101 pc->c[1] = 0x17;
103 102
104 memset(pc->buf, 0, 12); 103 memset(buf, 0, 12);
105 pc->buf[1] = 0xA2; 104 buf[1] = 0xA2;
106 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */ 105 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
107 106
108 if (flags & 1) /* Verify bit on... */ 107 if (flags & 1) /* Verify bit on... */
109 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */ 108 buf[1] ^= 0x20; /* ... turn off DCRT bit */
110 pc->buf[3] = 8; 109 buf[3] = 8;
111 110
112 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4])); 111 put_unaligned(cpu_to_be32(b), (unsigned int *)(&buf[4]));
113 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8])); 112 put_unaligned(cpu_to_be32(l), (unsigned int *)(&buf[8]));
114 pc->buf_size = 12; 113 pc->req_xfer = 12;
115 pc->flags |= PC_FLAG_WRITING; 114 pc->flags |= PC_FLAG_WRITING;
116} 115}
117 116
118static int ide_floppy_get_sfrp_bit(ide_drive_t *drive, struct ide_atapi_pc *pc) 117static int ide_floppy_get_sfrp_bit(ide_drive_t *drive, struct ide_atapi_pc *pc)
119{ 118{
120 struct ide_disk_obj *floppy = drive->driver_data; 119 struct ide_disk_obj *floppy = drive->driver_data;
120 u8 buf[20];
121 121
122 drive->atapi_flags &= ~IDE_AFLAG_SRFP; 122 drive->atapi_flags &= ~IDE_AFLAG_SRFP;
123 123
124 ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_CAPABILITIES_PAGE); 124 ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_CAPABILITIES_PAGE);
125 pc->flags |= PC_FLAG_SUPPRESS_ERROR; 125 pc->flags |= PC_FLAG_SUPPRESS_ERROR;
126 126
127 if (ide_queue_pc_tail(drive, floppy->disk, pc)) 127 if (ide_queue_pc_tail(drive, floppy->disk, pc, buf, pc->req_xfer))
128 return 1; 128 return 1;
129 129
130 if (pc->buf[8 + 2] & 0x40) 130 if (buf[8 + 2] & 0x40)
131 drive->atapi_flags |= IDE_AFLAG_SRFP; 131 drive->atapi_flags |= IDE_AFLAG_SRFP;
132 132
133 return 0; 133 return 0;
@@ -137,6 +137,7 @@ static int ide_floppy_format_unit(ide_drive_t *drive, struct ide_atapi_pc *pc,
137 int __user *arg) 137 int __user *arg)
138{ 138{
139 struct ide_disk_obj *floppy = drive->driver_data; 139 struct ide_disk_obj *floppy = drive->driver_data;
140 u8 buf[12];
140 int blocks, length, flags, err = 0; 141 int blocks, length, flags, err = 0;
141 142
142 if (floppy->openers > 1) { 143 if (floppy->openers > 1) {
@@ -170,9 +171,9 @@ static int ide_floppy_format_unit(ide_drive_t *drive, struct ide_atapi_pc *pc,
170 } 171 }
171 172
172 ide_floppy_get_sfrp_bit(drive, pc); 173 ide_floppy_get_sfrp_bit(drive, pc);
173 ide_floppy_create_format_unit_cmd(pc, blocks, length, flags); 174 ide_floppy_create_format_unit_cmd(pc, buf, blocks, length, flags);
174 175
175 if (ide_queue_pc_tail(drive, floppy->disk, pc)) 176 if (ide_queue_pc_tail(drive, floppy->disk, pc, buf, pc->req_xfer))
176 err = -EIO; 177 err = -EIO;
177 178
178out: 179out:
@@ -196,11 +197,13 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive,
196 int __user *arg) 197 int __user *arg)
197{ 198{
198 struct ide_disk_obj *floppy = drive->driver_data; 199 struct ide_disk_obj *floppy = drive->driver_data;
200 u8 sense_buf[18];
199 int progress_indication = 0x10000; 201 int progress_indication = 0x10000;
200 202
201 if (drive->atapi_flags & IDE_AFLAG_SRFP) { 203 if (drive->atapi_flags & IDE_AFLAG_SRFP) {
202 ide_create_request_sense_cmd(drive, pc); 204 ide_create_request_sense_cmd(drive, pc);
203 if (ide_queue_pc_tail(drive, floppy->disk, pc)) 205 if (ide_queue_pc_tail(drive, floppy->disk, pc, sense_buf,
206 pc->req_xfer))
204 return -EIO; 207 return -EIO;
205 208
206 if (floppy->sense_key == 2 && 209 if (floppy->sense_key == 2 &&
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 272cc38f6dbe..1059f809b809 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -683,8 +683,9 @@ void ide_timer_expiry (unsigned long data)
683 } else if (drive_is_ready(drive)) { 683 } else if (drive_is_ready(drive)) {
684 if (drive->waiting_for_dma) 684 if (drive->waiting_for_dma)
685 hwif->dma_ops->dma_lost_irq(drive); 685 hwif->dma_ops->dma_lost_irq(drive);
686 if (hwif->ack_intr) 686 if (hwif->port_ops && hwif->port_ops->clear_irq)
687 hwif->ack_intr(hwif); 687 hwif->port_ops->clear_irq(drive);
688
688 printk(KERN_WARNING "%s: lost interrupt\n", 689 printk(KERN_WARNING "%s: lost interrupt\n",
689 drive->name); 690 drive->name);
690 startstop = handler(drive); 691 startstop = handler(drive);
@@ -803,7 +804,8 @@ irqreturn_t ide_intr (int irq, void *dev_id)
803 804
804 spin_lock_irqsave(&hwif->lock, flags); 805 spin_lock_irqsave(&hwif->lock, flags);
805 806
806 if (hwif->ack_intr && hwif->ack_intr(hwif) == 0) 807 if (hwif->port_ops && hwif->port_ops->test_irq &&
808 hwif->port_ops->test_irq(hwif) == 0)
807 goto out; 809 goto out;
808 810
809 handler = hwif->handler; 811 handler = hwif->handler;
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index 5991b23793f2..82f252c3ee6e 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -118,7 +118,6 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg)
118 u8 args[4], xfer_rate = 0; 118 u8 args[4], xfer_rate = 0;
119 struct ide_cmd cmd; 119 struct ide_cmd cmd;
120 struct ide_taskfile *tf = &cmd.tf; 120 struct ide_taskfile *tf = &cmd.tf;
121 u16 *id = drive->id;
122 121
123 if (NULL == (void *) arg) { 122 if (NULL == (void *) arg) {
124 struct request *rq; 123 struct request *rq;
@@ -161,14 +160,10 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg)
161 160
162 if (tf->command == ATA_CMD_SET_FEATURES && 161 if (tf->command == ATA_CMD_SET_FEATURES &&
163 tf->feature == SETFEATURES_XFER && 162 tf->feature == SETFEATURES_XFER &&
164 tf->nsect >= XFER_SW_DMA_0 && 163 tf->nsect >= XFER_SW_DMA_0) {
165 (id[ATA_ID_UDMA_MODES] || 164 xfer_rate = ide_find_dma_mode(drive, XFER_UDMA_6);
166 id[ATA_ID_MWDMA_MODES] || 165 if (xfer_rate != tf->nsect) {
167 id[ATA_ID_SWDMA_MODES])) { 166 err = -EINVAL;
168 xfer_rate = args[1];
169 if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
170 printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
171 "be set\n", drive->name);
172 goto abort; 167 goto abort;
173 } 168 }
174 } 169 }
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 79e0af3fd158..51af4eea0d36 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1170,7 +1170,6 @@ static void ide_init_port_hw(ide_hwif_t *hwif, struct ide_hw *hw)
1170 hwif->irq = hw->irq; 1170 hwif->irq = hw->irq;
1171 hwif->dev = hw->dev; 1171 hwif->dev = hw->dev;
1172 hwif->gendev.parent = hw->parent ? hw->parent : hw->dev; 1172 hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
1173 hwif->ack_intr = hw->ack_intr;
1174 hwif->config_data = hw->config; 1173 hwif->config_data = hw->config;
1175} 1174}
1176 1175
@@ -1378,6 +1377,9 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1378 1377
1379 ide_init_port(hwif, i & 1, d); 1378 ide_init_port(hwif, i & 1, d);
1380 ide_port_cable_detect(hwif); 1379 ide_port_cable_detect(hwif);
1380
1381 hwif->port_flags |= IDE_PFLAG_PROBING;
1382
1381 ide_port_init_devices(hwif); 1383 ide_port_init_devices(hwif);
1382 } 1384 }
1383 1385
@@ -1388,6 +1390,8 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1388 if (ide_probe_port(hwif) == 0) 1390 if (ide_probe_port(hwif) == 0)
1389 hwif->present = 1; 1391 hwif->present = 1;
1390 1392
1393 hwif->port_flags &= ~IDE_PFLAG_PROBING;
1394
1391 if ((hwif->host_flags & IDE_HFLAG_4DRIVES) == 0 || 1395 if ((hwif->host_flags & IDE_HFLAG_4DRIVES) == 0 ||
1392 hwif->mate == NULL || hwif->mate->present == 0) { 1396 hwif->mate == NULL || hwif->mate->present == 0) {
1393 if (ide_register_port(hwif)) { 1397 if (ide_register_port(hwif)) {
@@ -1569,11 +1573,20 @@ EXPORT_SYMBOL_GPL(ide_host_remove);
1569 1573
1570void ide_port_scan(ide_hwif_t *hwif) 1574void ide_port_scan(ide_hwif_t *hwif)
1571{ 1575{
1576 int rc;
1577
1572 ide_port_apply_params(hwif); 1578 ide_port_apply_params(hwif);
1573 ide_port_cable_detect(hwif); 1579 ide_port_cable_detect(hwif);
1580
1581 hwif->port_flags |= IDE_PFLAG_PROBING;
1582
1574 ide_port_init_devices(hwif); 1583 ide_port_init_devices(hwif);
1575 1584
1576 if (ide_probe_port(hwif) < 0) 1585 rc = ide_probe_port(hwif);
1586
1587 hwif->port_flags &= ~IDE_PFLAG_PROBING;
1588
1589 if (rc < 0)
1577 return; 1590 return;
1578 1591
1579 hwif->present = 1; 1592 hwif->present = 1;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 4b447a8a49d4..013dc595fab6 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -279,10 +279,12 @@ static void ide_tape_put(struct ide_tape_obj *tape)
279 * called on each failed packet command retry to analyze the request sense. We 279 * called on each failed packet command retry to analyze the request sense. We
280 * currently do not utilize this information. 280 * currently do not utilize this information.
281 */ 281 */
282static void idetape_analyze_error(ide_drive_t *drive, u8 *sense) 282static void idetape_analyze_error(ide_drive_t *drive)
283{ 283{
284 idetape_tape_t *tape = drive->driver_data; 284 idetape_tape_t *tape = drive->driver_data;
285 struct ide_atapi_pc *pc = drive->failed_pc; 285 struct ide_atapi_pc *pc = drive->failed_pc;
286 struct request *rq = drive->hwif->rq;
287 u8 *sense = bio_data(rq->bio);
286 288
287 tape->sense_key = sense[2] & 0xF; 289 tape->sense_key = sense[2] & 0xF;
288 tape->asc = sense[12]; 290 tape->asc = sense[12];
@@ -291,11 +293,9 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
291 debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n", 293 debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n",
292 pc->c[0], tape->sense_key, tape->asc, tape->ascq); 294 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
293 295
294 /* Correct pc->xferred by asking the tape. */ 296 /* correct remaining bytes to transfer */
295 if (pc->flags & PC_FLAG_DMA_ERROR) 297 if (pc->flags & PC_FLAG_DMA_ERROR)
296 pc->xferred = pc->req_xfer - 298 rq->resid_len = tape->blk_size * get_unaligned_be32(&sense[3]);
297 tape->blk_size *
298 get_unaligned_be32(&sense[3]);
299 299
300 /* 300 /*
301 * If error was the result of a zero-length read or write command, 301 * If error was the result of a zero-length read or write command,
@@ -329,7 +329,7 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
329 pc->flags |= PC_FLAG_ABORT; 329 pc->flags |= PC_FLAG_ABORT;
330 } 330 }
331 if (!(pc->flags & PC_FLAG_ABORT) && 331 if (!(pc->flags & PC_FLAG_ABORT) &&
332 pc->xferred) 332 (blk_rq_bytes(rq) - rq->resid_len))
333 pc->retries = IDETAPE_MAX_PC_RETRIES + 1; 333 pc->retries = IDETAPE_MAX_PC_RETRIES + 1;
334 } 334 }
335} 335}
@@ -354,12 +354,13 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
354 354
355 if (pc->c[0] == REQUEST_SENSE) { 355 if (pc->c[0] == REQUEST_SENSE) {
356 if (uptodate) 356 if (uptodate)
357 idetape_analyze_error(drive, pc->buf); 357 idetape_analyze_error(drive);
358 else 358 else
359 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE " 359 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
360 "itself - Aborting request!\n"); 360 "itself - Aborting request!\n");
361 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { 361 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
362 int blocks = pc->xferred / tape->blk_size; 362 unsigned int blocks =
363 (blk_rq_bytes(rq) - rq->resid_len) / tape->blk_size;
363 364
364 tape->avg_size += blocks * tape->blk_size; 365 tape->avg_size += blocks * tape->blk_size;
365 366
@@ -371,38 +372,12 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
371 } 372 }
372 373
373 tape->first_frame += blocks; 374 tape->first_frame += blocks;
374 rq->resid_len -= blocks * tape->blk_size;
375 375
376 if (pc->error) { 376 if (pc->error) {
377 uptodate = 0; 377 uptodate = 0;
378 err = pc->error; 378 err = pc->error;
379 } 379 }
380 } else if (pc->c[0] == READ_POSITION && uptodate) {
381 u8 *readpos = pc->buf;
382
383 debug_log(DBG_SENSE, "BOP - %s\n",
384 (readpos[0] & 0x80) ? "Yes" : "No");
385 debug_log(DBG_SENSE, "EOP - %s\n",
386 (readpos[0] & 0x40) ? "Yes" : "No");
387
388 if (readpos[0] & 0x4) {
389 printk(KERN_INFO "ide-tape: Block location is unknown"
390 "to the tape\n");
391 clear_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
392 &drive->atapi_flags);
393 uptodate = 0;
394 err = IDE_DRV_ERROR_GENERAL;
395 } else {
396 debug_log(DBG_SENSE, "Block Location - %u\n",
397 be32_to_cpup((__be32 *)&readpos[4]));
398
399 tape->partition = readpos[1];
400 tape->first_frame = be32_to_cpup((__be32 *)&readpos[4]);
401 set_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
402 &drive->atapi_flags);
403 }
404 } 380 }
405
406 rq->errors = err; 381 rq->errors = err;
407 382
408 return uptodate; 383 return uptodate;
@@ -477,6 +452,7 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
477 struct ide_atapi_pc *pc) 452 struct ide_atapi_pc *pc)
478{ 453{
479 idetape_tape_t *tape = drive->driver_data; 454 idetape_tape_t *tape = drive->driver_data;
455 struct request *rq = drive->hwif->rq;
480 456
481 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) 457 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
482 drive->failed_pc = pc; 458 drive->failed_pc = pc;
@@ -486,7 +462,6 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
486 462
487 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 463 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
488 (pc->flags & PC_FLAG_ABORT)) { 464 (pc->flags & PC_FLAG_ABORT)) {
489 unsigned int done = blk_rq_bytes(drive->hwif->rq);
490 465
491 /* 466 /*
492 * We will "abort" retrying a packet command in case legitimate 467 * We will "abort" retrying a packet command in case legitimate
@@ -510,7 +485,7 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
510 485
511 drive->failed_pc = NULL; 486 drive->failed_pc = NULL;
512 drive->pc_callback(drive, 0); 487 drive->pc_callback(drive, 0);
513 ide_complete_rq(drive, -EIO, done); 488 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
514 return ide_stopped; 489 return ide_stopped;
515 } 490 }
516 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 491 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
@@ -579,15 +554,13 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
579 struct ide_atapi_pc *pc, struct request *rq, 554 struct ide_atapi_pc *pc, struct request *rq,
580 u8 opcode) 555 u8 opcode)
581{ 556{
582 unsigned int length = blk_rq_sectors(rq); 557 unsigned int length = blk_rq_sectors(rq) / (tape->blk_size >> 9);
583 558
584 ide_init_pc(pc); 559 ide_init_pc(pc);
585 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 560 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
586 pc->c[1] = 1; 561 pc->c[1] = 1;
587 pc->buf = NULL; 562
588 pc->buf_size = length * tape->blk_size; 563 if (blk_rq_bytes(rq) == tape->buffer_size)
589 pc->req_xfer = pc->buf_size;
590 if (pc->req_xfer == tape->buffer_size)
591 pc->flags |= PC_FLAG_DMA_OK; 564 pc->flags |= PC_FLAG_DMA_OK;
592 565
593 if (opcode == READ_6) 566 if (opcode == READ_6)
@@ -613,15 +586,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
613 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n" 586 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n"
614 (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq)); 587 (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq));
615 588
616 if (!(blk_special_request(rq) || blk_sense_request(rq))) { 589 BUG_ON(!(blk_special_request(rq) || blk_sense_request(rq)));
617 /* We do not support buffer cache originated requests. */
618 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
619 "request queue (%d)\n", drive->name, rq->cmd_type);
620 if (blk_fs_request(rq) == 0 && rq->errors == 0)
621 rq->errors = -EIO;
622 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
623 return ide_stopped;
624 }
625 590
626 /* Retry a failed packet command */ 591 /* Retry a failed packet command */
627 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { 592 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
@@ -713,7 +678,7 @@ out:
713 678
714 cmd.rq = rq; 679 cmd.rq = rq;
715 680
716 ide_init_sg_cmd(&cmd, pc->req_xfer); 681 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
717 ide_map_sg(drive, &cmd); 682 ide_map_sg(drive, &cmd);
718 683
719 return ide_tape_issue_pc(drive, &cmd, pc); 684 return ide_tape_issue_pc(drive, &cmd, pc);
@@ -767,33 +732,53 @@ static int idetape_flush_tape_buffers(ide_drive_t *drive)
767 int rc; 732 int rc;
768 733
769 idetape_create_write_filemark_cmd(drive, &pc, 0); 734 idetape_create_write_filemark_cmd(drive, &pc, 0);
770 rc = ide_queue_pc_tail(drive, tape->disk, &pc); 735 rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0);
771 if (rc) 736 if (rc)
772 return rc; 737 return rc;
773 idetape_wait_ready(drive, 60 * 5 * HZ); 738 idetape_wait_ready(drive, 60 * 5 * HZ);
774 return 0; 739 return 0;
775} 740}
776 741
777static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc) 742static int ide_tape_read_position(ide_drive_t *drive)
778{
779 ide_init_pc(pc);
780 pc->c[0] = READ_POSITION;
781 pc->req_xfer = 20;
782}
783
784static int idetape_read_position(ide_drive_t *drive)
785{ 743{
786 idetape_tape_t *tape = drive->driver_data; 744 idetape_tape_t *tape = drive->driver_data;
787 struct ide_atapi_pc pc; 745 struct ide_atapi_pc pc;
788 int position; 746 u8 buf[20];
789 747
790 debug_log(DBG_PROCS, "Enter %s\n", __func__); 748 debug_log(DBG_PROCS, "Enter %s\n", __func__);
791 749
792 idetape_create_read_position_cmd(&pc); 750 /* prep cmd */
793 if (ide_queue_pc_tail(drive, tape->disk, &pc)) 751 ide_init_pc(&pc);
752 pc.c[0] = READ_POSITION;
753 pc.req_xfer = 20;
754
755 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer))
794 return -1; 756 return -1;
795 position = tape->first_frame; 757
796 return position; 758 if (!pc.error) {
759 debug_log(DBG_SENSE, "BOP - %s\n",
760 (buf[0] & 0x80) ? "Yes" : "No");
761 debug_log(DBG_SENSE, "EOP - %s\n",
762 (buf[0] & 0x40) ? "Yes" : "No");
763
764 if (buf[0] & 0x4) {
765 printk(KERN_INFO "ide-tape: Block location is unknown"
766 "to the tape\n");
767 clear_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
768 &drive->atapi_flags);
769 return -1;
770 } else {
771 debug_log(DBG_SENSE, "Block Location - %u\n",
772 be32_to_cpup((__be32 *)&buf[4]));
773
774 tape->partition = buf[1];
775 tape->first_frame = be32_to_cpup((__be32 *)&buf[4]);
776 set_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
777 &drive->atapi_flags);
778 }
779 }
780
781 return tape->first_frame;
797} 782}
798 783
799static void idetape_create_locate_cmd(ide_drive_t *drive, 784static void idetape_create_locate_cmd(ide_drive_t *drive,
@@ -836,19 +821,21 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
836{ 821{
837 idetape_tape_t *tape = drive->driver_data; 822 idetape_tape_t *tape = drive->driver_data;
838 struct gendisk *disk = tape->disk; 823 struct gendisk *disk = tape->disk;
839 int retval; 824 int ret;
840 struct ide_atapi_pc pc; 825 struct ide_atapi_pc pc;
841 826
842 if (tape->chrdev_dir == IDETAPE_DIR_READ) 827 if (tape->chrdev_dir == IDETAPE_DIR_READ)
843 __ide_tape_discard_merge_buffer(drive); 828 __ide_tape_discard_merge_buffer(drive);
844 idetape_wait_ready(drive, 60 * 5 * HZ); 829 idetape_wait_ready(drive, 60 * 5 * HZ);
845 idetape_create_locate_cmd(drive, &pc, block, partition, skip); 830 idetape_create_locate_cmd(drive, &pc, block, partition, skip);
846 retval = ide_queue_pc_tail(drive, disk, &pc); 831 ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
847 if (retval) 832 if (ret)
848 return (retval); 833 return ret;
849 834
850 idetape_create_read_position_cmd(&pc); 835 ret = ide_tape_read_position(drive);
851 return ide_queue_pc_tail(drive, disk, &pc); 836 if (ret < 0)
837 return ret;
838 return 0;
852} 839}
853 840
854static void ide_tape_discard_merge_buffer(ide_drive_t *drive, 841static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
@@ -859,7 +846,7 @@ static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
859 846
860 __ide_tape_discard_merge_buffer(drive); 847 __ide_tape_discard_merge_buffer(drive);
861 if (restore_position) { 848 if (restore_position) {
862 position = idetape_read_position(drive); 849 position = ide_tape_read_position(drive);
863 seek = position > 0 ? position : 0; 850 seek = position > 0 ? position : 0;
864 if (idetape_position_tape(drive, seek, 0, 0)) { 851 if (idetape_position_tape(drive, seek, 0, 0)) {
865 printk(KERN_INFO "ide-tape: %s: position_tape failed in" 852 printk(KERN_INFO "ide-tape: %s: position_tape failed in"
@@ -1039,20 +1026,19 @@ static int idetape_rewind_tape(ide_drive_t *drive)
1039{ 1026{
1040 struct ide_tape_obj *tape = drive->driver_data; 1027 struct ide_tape_obj *tape = drive->driver_data;
1041 struct gendisk *disk = tape->disk; 1028 struct gendisk *disk = tape->disk;
1042 int retval;
1043 struct ide_atapi_pc pc; 1029 struct ide_atapi_pc pc;
1030 int ret;
1044 1031
1045 debug_log(DBG_SENSE, "Enter %s\n", __func__); 1032 debug_log(DBG_SENSE, "Enter %s\n", __func__);
1046 1033
1047 idetape_create_rewind_cmd(drive, &pc); 1034 idetape_create_rewind_cmd(drive, &pc);
1048 retval = ide_queue_pc_tail(drive, disk, &pc); 1035 ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
1049 if (retval) 1036 if (ret)
1050 return retval; 1037 return ret;
1051 1038
1052 idetape_create_read_position_cmd(&pc); 1039 ret = ide_tape_read_position(drive);
1053 retval = ide_queue_pc_tail(drive, disk, &pc); 1040 if (ret < 0)
1054 if (retval) 1041 return ret;
1055 return retval;
1056 return 0; 1042 return 0;
1057} 1043}
1058 1044
@@ -1119,7 +1105,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1119 case MTBSF: 1105 case MTBSF:
1120 idetape_create_space_cmd(&pc, mt_count - count, 1106 idetape_create_space_cmd(&pc, mt_count - count,
1121 IDETAPE_SPACE_OVER_FILEMARK); 1107 IDETAPE_SPACE_OVER_FILEMARK);
1122 return ide_queue_pc_tail(drive, disk, &pc); 1108 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
1123 case MTFSFM: 1109 case MTFSFM:
1124 case MTBSFM: 1110 case MTBSFM:
1125 if (!sprev) 1111 if (!sprev)
@@ -1259,7 +1245,7 @@ static int idetape_write_filemark(ide_drive_t *drive)
1259 1245
1260 /* Write a filemark */ 1246 /* Write a filemark */
1261 idetape_create_write_filemark_cmd(drive, &pc, 1); 1247 idetape_create_write_filemark_cmd(drive, &pc, 1);
1262 if (ide_queue_pc_tail(drive, tape->disk, &pc)) { 1248 if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) {
1263 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); 1249 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
1264 return -EIO; 1250 return -EIO;
1265 } 1251 }
@@ -1345,11 +1331,11 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1345 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); 1331 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
1346 case MTEOM: 1332 case MTEOM:
1347 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); 1333 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
1348 return ide_queue_pc_tail(drive, disk, &pc); 1334 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
1349 case MTERASE: 1335 case MTERASE:
1350 (void)idetape_rewind_tape(drive); 1336 (void)idetape_rewind_tape(drive);
1351 idetape_create_erase_cmd(&pc); 1337 idetape_create_erase_cmd(&pc);
1352 return ide_queue_pc_tail(drive, disk, &pc); 1338 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
1353 case MTSETBLK: 1339 case MTSETBLK:
1354 if (mt_count) { 1340 if (mt_count) {
1355 if (mt_count < tape->blk_size || 1341 if (mt_count < tape->blk_size ||
@@ -1415,7 +1401,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1415 if (cmd == MTIOCGET || cmd == MTIOCPOS) { 1401 if (cmd == MTIOCGET || cmd == MTIOCPOS) {
1416 block_offset = tape->valid / 1402 block_offset = tape->valid /
1417 (tape->blk_size * tape->user_bs_factor); 1403 (tape->blk_size * tape->user_bs_factor);
1418 position = idetape_read_position(drive); 1404 position = ide_tape_read_position(drive);
1419 if (position < 0) 1405 if (position < 0)
1420 return -EIO; 1406 return -EIO;
1421 } 1407 }
@@ -1458,9 +1444,10 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
1458{ 1444{
1459 idetape_tape_t *tape = drive->driver_data; 1445 idetape_tape_t *tape = drive->driver_data;
1460 struct ide_atapi_pc pc; 1446 struct ide_atapi_pc pc;
1447 u8 buf[12];
1461 1448
1462 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); 1449 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
1463 if (ide_queue_pc_tail(drive, tape->disk, &pc)) { 1450 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
1464 printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); 1451 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
1465 if (tape->blk_size == 0) { 1452 if (tape->blk_size == 0) {
1466 printk(KERN_WARNING "ide-tape: Cannot deal with zero " 1453 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
@@ -1469,10 +1456,10 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
1469 } 1456 }
1470 return; 1457 return;
1471 } 1458 }
1472 tape->blk_size = (pc.buf[4 + 5] << 16) + 1459 tape->blk_size = (buf[4 + 5] << 16) +
1473 (pc.buf[4 + 6] << 8) + 1460 (buf[4 + 6] << 8) +
1474 pc.buf[4 + 7]; 1461 buf[4 + 7];
1475 tape->drv_write_prot = (pc.buf[2] & 0x80) >> 7; 1462 tape->drv_write_prot = (buf[2] & 0x80) >> 7;
1476} 1463}
1477 1464
1478static int idetape_chrdev_open(struct inode *inode, struct file *filp) 1465static int idetape_chrdev_open(struct inode *inode, struct file *filp)
@@ -1517,7 +1504,7 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
1517 goto out_put_tape; 1504 goto out_put_tape;
1518 } 1505 }
1519 1506
1520 idetape_read_position(drive); 1507 ide_tape_read_position(drive);
1521 if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags)) 1508 if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags))
1522 (void)idetape_rewind_tape(drive); 1509 (void)idetape_rewind_tape(drive);
1523 1510
@@ -1615,17 +1602,14 @@ static void idetape_get_inquiry_results(ide_drive_t *drive)
1615 char fw_rev[4], vendor_id[8], product_id[16]; 1602 char fw_rev[4], vendor_id[8], product_id[16];
1616 1603
1617 idetape_create_inquiry_cmd(&pc); 1604 idetape_create_inquiry_cmd(&pc);
1618 pc.buf = &pc_buf[0]; 1605 if (ide_queue_pc_tail(drive, tape->disk, &pc, pc_buf, pc.req_xfer)) {
1619 pc.buf_size = sizeof(pc_buf);
1620
1621 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1622 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", 1606 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
1623 tape->name); 1607 tape->name);
1624 return; 1608 return;
1625 } 1609 }
1626 memcpy(vendor_id, &pc.buf[8], 8); 1610 memcpy(vendor_id, &pc_buf[8], 8);
1627 memcpy(product_id, &pc.buf[16], 16); 1611 memcpy(product_id, &pc_buf[16], 16);
1628 memcpy(fw_rev, &pc.buf[32], 4); 1612 memcpy(fw_rev, &pc_buf[32], 4);
1629 1613
1630 ide_fixstring(vendor_id, 8, 0); 1614 ide_fixstring(vendor_id, 8, 0);
1631 ide_fixstring(product_id, 16, 0); 1615 ide_fixstring(product_id, 16, 0);
@@ -1643,11 +1627,11 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
1643{ 1627{
1644 idetape_tape_t *tape = drive->driver_data; 1628 idetape_tape_t *tape = drive->driver_data;
1645 struct ide_atapi_pc pc; 1629 struct ide_atapi_pc pc;
1646 u8 *caps; 1630 u8 buf[24], *caps;
1647 u8 speed, max_speed; 1631 u8 speed, max_speed;
1648 1632
1649 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); 1633 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
1650 if (ide_queue_pc_tail(drive, tape->disk, &pc)) { 1634 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
1651 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" 1635 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
1652 " some default values\n"); 1636 " some default values\n");
1653 tape->blk_size = 512; 1637 tape->blk_size = 512;
@@ -1656,7 +1640,7 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
1656 put_unaligned(6*52, (u16 *)&tape->caps[16]); 1640 put_unaligned(6*52, (u16 *)&tape->caps[16]);
1657 return; 1641 return;
1658 } 1642 }
1659 caps = pc.buf + 4 + pc.buf[3]; 1643 caps = buf + 4 + buf[3];
1660 1644
1661 /* convert to host order and save for later use */ 1645 /* convert to host order and save for later use */
1662 speed = be16_to_cpup((__be16 *)&caps[14]); 1646 speed = be16_to_cpup((__be16 *)&caps[14]);
diff --git a/drivers/ide/ide-xfer-mode.c b/drivers/ide/ide-xfer-mode.c
index af44be9d546c..46d203ce60cc 100644
--- a/drivers/ide/ide-xfer-mode.c
+++ b/drivers/ide/ide-xfer-mode.c
@@ -107,6 +107,18 @@ u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
107} 107}
108EXPORT_SYMBOL_GPL(ide_get_best_pio_mode); 108EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
109 109
110int ide_pio_need_iordy(ide_drive_t *drive, const u8 pio)
111{
112 /*
113 * IORDY may lead to controller lock up on certain controllers
114 * if the port is not occupied.
115 */
116 if (pio == 0 && (drive->hwif->port_flags & IDE_PFLAG_PROBING))
117 return 0;
118 return ata_id_pio_need_iordy(drive->id, pio);
119}
120EXPORT_SYMBOL_GPL(ide_pio_need_iordy);
121
110int ide_set_pio_mode(ide_drive_t *drive, const u8 mode) 122int ide_set_pio_mode(ide_drive_t *drive, const u8 mode)
111{ 123{
112 ide_hwif_t *hwif = drive->hwif; 124 ide_hwif_t *hwif = drive->hwif;
diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
index e021078cd06b..0d266a5b524d 100644
--- a/drivers/ide/it8172.c
+++ b/drivers/ide/it8172.c
@@ -66,7 +66,7 @@ static void it8172_set_pio_mode(ide_drive_t *drive, const u8 pio)
66 if (drive->media == ide_disk) 66 if (drive->media == ide_disk)
67 /* enable prefetch */ 67 /* enable prefetch */
68 drive_enables |= 0x0004 << (drive->dn * 4); 68 drive_enables |= 0x0004 << (drive->dn * 4);
69 if (ata_id_has_iordy(drive->id)) 69 if (ide_pio_need_iordy(drive, pio))
70 /* enable IORDY sample-point */ 70 /* enable IORDY sample-point */
71 drive_enables |= 0x0002 << (drive->dn * 4); 71 drive_enables |= 0x0002 << (drive->dn * 4);
72 72
diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
index d7969b6d139e..47976167796a 100644
--- a/drivers/ide/it8213.c
+++ b/drivers/ide/it8213.c
@@ -50,7 +50,7 @@ static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
50 control |= 1; /* Programmable timing on */ 50 control |= 1; /* Programmable timing on */
51 if (drive->media != ide_disk) 51 if (drive->media != ide_disk)
52 control |= 4; /* ATAPI */ 52 control |= 4; /* ATAPI */
53 if (pio > 2) 53 if (ide_pio_need_iordy(drive, pio))
54 control |= 2; /* IORDY */ 54 control |= 2; /* IORDY */
55 if (is_slave) { 55 if (is_slave) {
56 master_data |= 0x4000; 56 master_data |= 0x4000;
diff --git a/drivers/ide/macide.c b/drivers/ide/macide.c
index 1447c8c90565..505ec43e5606 100644
--- a/drivers/ide/macide.c
+++ b/drivers/ide/macide.c
@@ -53,17 +53,20 @@
53 53
54volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR); 54volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR);
55 55
56int macide_ack_intr(ide_hwif_t* hwif) 56int macide_test_irq(ide_hwif_t *hwif)
57{ 57{
58 if (*ide_ifr & 0x20) { 58 if (*ide_ifr & 0x20)
59 *ide_ifr &= ~0x20;
60 return 1; 59 return 1;
61 }
62 return 0; 60 return 0;
63} 61}
64 62
63static void macide_clear_irq(ide_drive_t *drive)
64{
65 *ide_ifr &= ~0x20;
66}
67
65static void __init macide_setup_ports(struct ide_hw *hw, unsigned long base, 68static void __init macide_setup_ports(struct ide_hw *hw, unsigned long base,
66 int irq, ide_ack_intr_t *ack_intr) 69 int irq)
67{ 70{
68 int i; 71 int i;
69 72
@@ -75,10 +78,15 @@ static void __init macide_setup_ports(struct ide_hw *hw, unsigned long base,
75 hw->io_ports.ctl_addr = base + IDE_CONTROL; 78 hw->io_ports.ctl_addr = base + IDE_CONTROL;
76 79
77 hw->irq = irq; 80 hw->irq = irq;
78 hw->ack_intr = ack_intr;
79} 81}
80 82
83static const struct ide_port_ops macide_port_ops = {
84 .clear_irq = macide_clear_irq,
85 .test_irq = macide_test_irq,
86};
87
81static const struct ide_port_info macide_port_info = { 88static const struct ide_port_info macide_port_info = {
89 .port_ops = &macide_port_ops,
82 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, 90 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
83 .irq_flags = IRQF_SHARED, 91 .irq_flags = IRQF_SHARED,
84 .chipset = ide_generic, 92 .chipset = ide_generic,
@@ -93,10 +101,10 @@ static const char *mac_ide_name[] =
93 101
94static int __init macide_init(void) 102static int __init macide_init(void)
95{ 103{
96 ide_ack_intr_t *ack_intr;
97 unsigned long base; 104 unsigned long base;
98 int irq; 105 int irq;
99 struct ide_hw hw, *hws[] = { &hw }; 106 struct ide_hw hw, *hws[] = { &hw };
107 struct ide_port_info d = macide_port_info;
100 108
101 if (!MACH_IS_MAC) 109 if (!MACH_IS_MAC)
102 return -ENODEV; 110 return -ENODEV;
@@ -104,17 +112,15 @@ static int __init macide_init(void)
104 switch (macintosh_config->ide_type) { 112 switch (macintosh_config->ide_type) {
105 case MAC_IDE_QUADRA: 113 case MAC_IDE_QUADRA:
106 base = IDE_BASE; 114 base = IDE_BASE;
107 ack_intr = macide_ack_intr;
108 irq = IRQ_NUBUS_F; 115 irq = IRQ_NUBUS_F;
109 break; 116 break;
110 case MAC_IDE_PB: 117 case MAC_IDE_PB:
111 base = IDE_BASE; 118 base = IDE_BASE;
112 ack_intr = macide_ack_intr;
113 irq = IRQ_NUBUS_C; 119 irq = IRQ_NUBUS_C;
114 break; 120 break;
115 case MAC_IDE_BABOON: 121 case MAC_IDE_BABOON:
116 base = BABOON_BASE; 122 base = BABOON_BASE;
117 ack_intr = NULL; 123 d.port_ops = NULL;
118 irq = IRQ_BABOON_1; 124 irq = IRQ_BABOON_1;
119 break; 125 break;
120 default: 126 default:
@@ -124,9 +130,9 @@ static int __init macide_init(void)
124 printk(KERN_INFO "ide: Macintosh %s IDE controller\n", 130 printk(KERN_INFO "ide: Macintosh %s IDE controller\n",
125 mac_ide_name[macintosh_config->ide_type - 1]); 131 mac_ide_name[macintosh_config->ide_type - 1]);
126 132
127 macide_setup_ports(&hw, base, irq, ack_intr); 133 macide_setup_ports(&hw, base, irq);
128 134
129 return ide_host_add(&macide_port_info, hws, 1, NULL); 135 return ide_host_add(&d, hws, 1, NULL);
130} 136}
131 137
132module_init(macide_init); 138module_init(macide_init);
diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
index 6048eda3cd61..f1d70d6630fe 100644
--- a/drivers/ide/opti621.c
+++ b/drivers/ide/opti621.c
@@ -138,6 +138,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
138 ide_hwif_t *hwif = drive->hwif; 138 ide_hwif_t *hwif = drive->hwif;
139 ide_drive_t *pair = ide_get_pair_dev(drive); 139 ide_drive_t *pair = ide_get_pair_dev(drive);
140 unsigned long flags; 140 unsigned long flags;
141 unsigned long mode = XFER_PIO_0 + pio, pair_mode;
141 u8 tim, misc, addr_pio = pio, clk; 142 u8 tim, misc, addr_pio = pio, clk;
142 143
143 /* DRDY is default 2 (by OPTi Databook) */ 144 /* DRDY is default 2 (by OPTi Databook) */
@@ -150,11 +151,12 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
150 { 0x48, 0x34, 0x21, 0x10, 0x10 } /* 25 MHz */ 151 { 0x48, 0x34, 0x21, 0x10, 0x10 } /* 25 MHz */
151 }; 152 };
152 153
153 drive->drive_data = XFER_PIO_0 + pio; 154 ide_set_drivedata(drive, (void *)mode);
154 155
155 if (pair) { 156 if (pair) {
156 if (pair->drive_data && pair->drive_data < drive->drive_data) 157 pair_mode = (unsigned long)ide_get_drivedata(pair);
157 addr_pio = pair->drive_data - XFER_PIO_0; 158 if (pair_mode && pair_mode < mode)
159 addr_pio = pair_mode - XFER_PIO_0;
158 } 160 }
159 161
160 spin_lock_irqsave(&opti621_lock, flags); 162 spin_lock_irqsave(&opti621_lock, flags);
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index b6abf7e52cac..cb812f3700e8 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -73,7 +73,7 @@ static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed)
73 * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A 73 * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A
74 */ 74 */
75 AP &= ~0x3f; 75 AP &= ~0x3f;
76 if (ata_id_iordy_disable(drive->id)) 76 if (ide_pio_need_iordy(drive, speed - XFER_PIO_0))
77 AP |= 0x20; /* set IORDY_EN bit */ 77 AP |= 0x20; /* set IORDY_EN bit */
78 if (drive->media == ide_disk) 78 if (drive->media == ide_disk)
79 AP |= 0x10; /* set Prefetch_EN bit */ 79 AP |= 0x10; /* set Prefetch_EN bit */
@@ -104,6 +104,27 @@ static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
104 pdc202xx_set_mode(drive, XFER_PIO_0 + pio); 104 pdc202xx_set_mode(drive, XFER_PIO_0 + pio);
105} 105}
106 106
107static int pdc202xx_test_irq(ide_hwif_t *hwif)
108{
109 struct pci_dev *dev = to_pci_dev(hwif->dev);
110 unsigned long high_16 = pci_resource_start(dev, 4);
111 u8 sc1d = inb(high_16 + 0x1d);
112
113 if (hwif->channel) {
114 /*
115 * bit 7: error, bit 6: interrupting,
116 * bit 5: FIFO full, bit 4: FIFO empty
117 */
118 return ((sc1d & 0x50) == 0x40) ? 1 : 0;
119 } else {
120 /*
121 * bit 3: error, bit 2: interrupting,
122 * bit 1: FIFO full, bit 0: FIFO empty
123 */
124 return ((sc1d & 0x05) == 0x04) ? 1 : 0;
125 }
126}
127
107static u8 pdc2026x_cable_detect(ide_hwif_t *hwif) 128static u8 pdc2026x_cable_detect(ide_hwif_t *hwif)
108{ 129{
109 struct pci_dev *dev = to_pci_dev(hwif->dev); 130 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -231,6 +252,7 @@ static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev,
231static const struct ide_port_ops pdc20246_port_ops = { 252static const struct ide_port_ops pdc20246_port_ops = {
232 .set_pio_mode = pdc202xx_set_pio_mode, 253 .set_pio_mode = pdc202xx_set_pio_mode,
233 .set_dma_mode = pdc202xx_set_mode, 254 .set_dma_mode = pdc202xx_set_mode,
255 .test_irq = pdc202xx_test_irq,
234}; 256};
235 257
236static const struct ide_port_ops pdc2026x_port_ops = { 258static const struct ide_port_ops pdc2026x_port_ops = {
diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
index 69860dea3820..bf14f39bd3a7 100644
--- a/drivers/ide/piix.c
+++ b/drivers/ide/piix.c
@@ -98,7 +98,7 @@ static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio)
98 control |= 1; /* Programmable timing on */ 98 control |= 1; /* Programmable timing on */
99 if (drive->media == ide_disk) 99 if (drive->media == ide_disk)
100 control |= 4; /* Prefetch, post write */ 100 control |= 4; /* Prefetch, post write */
101 if (pio > 2) 101 if (ide_pio_need_iordy(drive, pio))
102 control |= 2; /* IORDY */ 102 control |= 2; /* IORDY */
103 if (is_slave) { 103 if (is_slave) {
104 master_data |= 0x4000; 104 master_data |= 0x4000;
diff --git a/drivers/ide/q40ide.c b/drivers/ide/q40ide.c
index ab49a97023d9..90786083b439 100644
--- a/drivers/ide/q40ide.c
+++ b/drivers/ide/q40ide.c
@@ -51,9 +51,7 @@ static int q40ide_default_irq(unsigned long base)
51/* 51/*
52 * Addresses are pretranslated for Q40 ISA access. 52 * Addresses are pretranslated for Q40 ISA access.
53 */ 53 */
54static void q40_ide_setup_ports(struct ide_hw *hw, unsigned long base, 54static void q40_ide_setup_ports(struct ide_hw *hw, unsigned long base, int irq)
55 ide_ack_intr_t *ack_intr,
56 int irq)
57{ 55{
58 memset(hw, 0, sizeof(*hw)); 56 memset(hw, 0, sizeof(*hw));
59 /* BIG FAT WARNING: 57 /* BIG FAT WARNING:
@@ -69,7 +67,6 @@ static void q40_ide_setup_ports(struct ide_hw *hw, unsigned long base,
69 hw->io_ports.ctl_addr = Q40_ISA_IO_B(base + 0x206); 67 hw->io_ports.ctl_addr = Q40_ISA_IO_B(base + 0x206);
70 68
71 hw->irq = irq; 69 hw->irq = irq;
72 hw->ack_intr = ack_intr;
73} 70}
74 71
75static void q40ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, 72static void q40ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
@@ -156,7 +153,7 @@ static int __init q40ide_init(void)
156 release_region(pcide_bases[i], 8); 153 release_region(pcide_bases[i], 8);
157 continue; 154 continue;
158 } 155 }
159 q40_ide_setup_ports(&hw[i], pcide_bases[i], NULL, 156 q40_ide_setup_ports(&hw[i], pcide_bases[i],
160 q40ide_default_irq(pcide_bases[i])); 157 q40ide_default_irq(pcide_bases[i]));
161 158
162 hws[i] = &hw[i]; 159 hws[i] = &hw[i];
diff --git a/drivers/ide/qd65xx.c b/drivers/ide/qd65xx.c
index c9a134986891..74696edc8d1d 100644
--- a/drivers/ide/qd65xx.c
+++ b/drivers/ide/qd65xx.c
@@ -180,8 +180,11 @@ static int qd_find_disk_type (ide_drive_t *drive,
180 180
181static void qd_set_timing (ide_drive_t *drive, u8 timing) 181static void qd_set_timing (ide_drive_t *drive, u8 timing)
182{ 182{
183 drive->drive_data &= 0xff00; 183 unsigned long data = (unsigned long)ide_get_drivedata(drive);
184 drive->drive_data |= timing; 184
185 data &= 0xff00;
186 data |= timing;
187 ide_set_drivedata(drive, (void *)data);
185 188
186 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing); 189 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing);
187} 190}
@@ -292,7 +295,7 @@ static void __init qd6500_init_dev(ide_drive_t *drive)
292 u8 base = (hwif->config_data & 0xff00) >> 8; 295 u8 base = (hwif->config_data & 0xff00) >> 8;
293 u8 config = QD_CONFIG(hwif); 296 u8 config = QD_CONFIG(hwif);
294 297
295 drive->drive_data = QD6500_DEF_DATA; 298 ide_set_drivedata(drive, (void *)QD6500_DEF_DATA);
296} 299}
297 300
298static void __init qd6580_init_dev(ide_drive_t *drive) 301static void __init qd6580_init_dev(ide_drive_t *drive)
@@ -308,7 +311,7 @@ static void __init qd6580_init_dev(ide_drive_t *drive)
308 } else 311 } else
309 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; 312 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA;
310 313
311 drive->drive_data = (drive->dn & 1) ? t2 : t1; 314 ide_set_drivedata(drive, (void *)((drive->dn & 1) ? t2 : t1));
312} 315}
313 316
314static const struct ide_tp_ops qd65xx_tp_ops = { 317static const struct ide_tp_ops qd65xx_tp_ops = {
diff --git a/drivers/ide/qd65xx.h b/drivers/ide/qd65xx.h
index d7e67a1a1dcc..1fba2a5f281c 100644
--- a/drivers/ide/qd65xx.h
+++ b/drivers/ide/qd65xx.h
@@ -31,8 +31,15 @@
31 31
32#define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff) 32#define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff)
33 33
34#define QD_TIMING(drive) (u8)(((drive)->drive_data) & 0x00ff) 34static inline u8 QD_TIMING(ide_drive_t *drive)
35#define QD_TIMREG(drive) (u8)((((drive)->drive_data) & 0xff00) >> 8) 35{
36 return (unsigned long)ide_get_drivedata(drive) & 0x00ff;
37}
38
39static inline u8 QD_TIMREG(ide_drive_t *drive)
40{
41 return ((unsigned long)ide_get_drivedata(drive) & 0xff00) >> 8;
42}
36 43
37#define QD6500_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0c : 0x08)) 44#define QD6500_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0c : 0x08))
38#define QD6580_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0a : 0x00)) 45#define QD6580_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0a : 0x00))
diff --git a/drivers/ide/sgiioc4.c b/drivers/ide/sgiioc4.c
index 5f37f168f944..b7d61dc64096 100644
--- a/drivers/ide/sgiioc4.c
+++ b/drivers/ide/sgiioc4.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (C) 2008 MontaVista Software, Inc. 3 * Copyright (C) 2008-2009 MontaVista Software, Inc.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License 6 * under the terms of version 2 of the GNU General Public License
@@ -29,8 +29,7 @@
29#include <linux/blkdev.h> 29#include <linux/blkdev.h>
30#include <linux/scatterlist.h> 30#include <linux/scatterlist.h>
31#include <linux/ioc4.h> 31#include <linux/ioc4.h>
32#include <asm/io.h> 32#include <linux/io.h>
33
34#include <linux/ide.h> 33#include <linux/ide.h>
35 34
36#define DRV_NAME "SGIIOC4" 35#define DRV_NAME "SGIIOC4"
@@ -72,7 +71,7 @@
72#define IOC4_CMD_CTL_BLK_SIZE 0x20 71#define IOC4_CMD_CTL_BLK_SIZE 0x20
73#define IOC4_SUPPORTED_FIRMWARE_REV 46 72#define IOC4_SUPPORTED_FIRMWARE_REV 46
74 73
75typedef struct { 74struct ioc4_dma_regs {
76 u32 timing_reg0; 75 u32 timing_reg0;
77 u32 timing_reg1; 76 u32 timing_reg1;
78 u32 low_mem_ptr; 77 u32 low_mem_ptr;
@@ -82,17 +81,18 @@ typedef struct {
82 u32 dev_byte_count; 81 u32 dev_byte_count;
83 u32 mem_byte_count; 82 u32 mem_byte_count;
84 u32 status; 83 u32 status;
85} ioc4_dma_regs_t; 84};
86 85
87/* Each Physical Region Descriptor Entry size is 16 bytes (2 * 64 bits) */ 86/* Each Physical Region Descriptor Entry size is 16 bytes (2 * 64 bits) */
88/* IOC4 has only 1 IDE channel */ 87/* IOC4 has only 1 IDE channel */
89#define IOC4_PRD_BYTES 16 88#define IOC4_PRD_BYTES 16
90#define IOC4_PRD_ENTRIES (PAGE_SIZE /(4*IOC4_PRD_BYTES)) 89#define IOC4_PRD_ENTRIES (PAGE_SIZE / (4 * IOC4_PRD_BYTES))
91 90
92 91
93static void 92static void sgiioc4_init_hwif_ports(struct ide_hw *hw,
94sgiioc4_init_hwif_ports(struct ide_hw *hw, unsigned long data_port, 93 unsigned long data_port,
95 unsigned long ctrl_port, unsigned long irq_port) 94 unsigned long ctrl_port,
95 unsigned long irq_port)
96{ 96{
97 unsigned long reg = data_port; 97 unsigned long reg = data_port;
98 int i; 98 int i;
@@ -105,13 +105,11 @@ sgiioc4_init_hwif_ports(struct ide_hw *hw, unsigned long data_port,
105 hw->io_ports.irq_addr = irq_port; 105 hw->io_ports.irq_addr = irq_port;
106} 106}
107 107
108static int 108static int sgiioc4_checkirq(ide_hwif_t *hwif)
109sgiioc4_checkirq(ide_hwif_t * hwif)
110{ 109{
111 unsigned long intr_addr = 110 unsigned long intr_addr = hwif->io_ports.irq_addr + IOC4_INTR_REG * 4;
112 hwif->io_ports.irq_addr + IOC4_INTR_REG * 4;
113 111
114 if ((u8)readl((void __iomem *)intr_addr) & 0x03) 112 if (readl((void __iomem *)intr_addr) & 0x03)
115 return 1; 113 return 1;
116 114
117 return 0; 115 return 0;
@@ -119,8 +117,7 @@ sgiioc4_checkirq(ide_hwif_t * hwif)
119 117
120static u8 sgiioc4_read_status(ide_hwif_t *); 118static u8 sgiioc4_read_status(ide_hwif_t *);
121 119
122static int 120static int sgiioc4_clearirq(ide_drive_t *drive)
123sgiioc4_clearirq(ide_drive_t * drive)
124{ 121{
125 u32 intr_reg; 122 u32 intr_reg;
126 ide_hwif_t *hwif = drive->hwif; 123 ide_hwif_t *hwif = drive->hwif;
@@ -158,12 +155,10 @@ sgiioc4_clearirq(ide_drive_t * drive)
158 readl((void __iomem *)(io_ports->irq_addr + 4)); 155 readl((void __iomem *)(io_ports->irq_addr + 4));
159 pci_read_config_dword(dev, PCI_COMMAND, 156 pci_read_config_dword(dev, PCI_COMMAND,
160 &pci_stat_cmd_reg); 157 &pci_stat_cmd_reg);
161 printk(KERN_ERR 158 printk(KERN_ERR "%s(%s): PCI Bus Error when doing DMA: "
162 "%s(%s) : PCI Bus Error when doing DMA:" 159 "status-cmd reg is 0x%x\n",
163 " status-cmd reg is 0x%x\n",
164 __func__, drive->name, pci_stat_cmd_reg); 160 __func__, drive->name, pci_stat_cmd_reg);
165 printk(KERN_ERR 161 printk(KERN_ERR "%s(%s): PCI Error Address is 0x%x%x\n",
166 "%s(%s) : PCI Error Address is 0x%x%x\n",
167 __func__, drive->name, 162 __func__, drive->name,
168 pci_err_addr_high, pci_err_addr_low); 163 pci_err_addr_high, pci_err_addr_low);
169 /* Clear the PCI Error indicator */ 164 /* Clear the PCI Error indicator */
@@ -189,8 +184,7 @@ static void sgiioc4_dma_start(ide_drive_t *drive)
189 writel(temp_reg, (void __iomem *)ioc4_dma_addr); 184 writel(temp_reg, (void __iomem *)ioc4_dma_addr);
190} 185}
191 186
192static u32 187static u32 sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
193sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
194{ 188{
195 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4; 189 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
196 u32 ioc4_dma; 190 u32 ioc4_dma;
@@ -227,7 +221,7 @@ static int sgiioc4_dma_end(ide_drive_t *drive)
227 } 221 }
228 222
229 /* 223 /*
230 * The IOC4 will DMA 1's to the ending dma area to indicate that 224 * The IOC4 will DMA 1's to the ending DMA area to indicate that
231 * previous data DMA is complete. This is necessary because of relaxed 225 * previous data DMA is complete. This is necessary because of relaxed
232 * ordering between register reads and DMA writes on the Altix. 226 * ordering between register reads and DMA writes on the Altix.
233 */ 227 */
@@ -265,7 +259,7 @@ static void sgiioc4_set_dma_mode(ide_drive_t *drive, const u8 speed)
265{ 259{
266} 260}
267 261
268/* returns 1 if dma irq issued, 0 otherwise */ 262/* Returns 1 if DMA IRQ issued, 0 otherwise */
269static int sgiioc4_dma_test_irq(ide_drive_t *drive) 263static int sgiioc4_dma_test_irq(ide_drive_t *drive)
270{ 264{
271 return sgiioc4_checkirq(drive->hwif); 265 return sgiioc4_checkirq(drive->hwif);
@@ -286,8 +280,7 @@ static void sgiioc4_resetproc(ide_drive_t *drive)
286 sgiioc4_clearirq(drive); 280 sgiioc4_clearirq(drive);
287} 281}
288 282
289static void 283static void sgiioc4_dma_lost_irq(ide_drive_t *drive)
290sgiioc4_dma_lost_irq(ide_drive_t * drive)
291{ 284{
292 sgiioc4_resetproc(drive); 285 sgiioc4_resetproc(drive);
293 286
@@ -313,13 +306,13 @@ static u8 sgiioc4_read_status(ide_hwif_t *hwif)
313 return reg; 306 return reg;
314} 307}
315 308
316/* Creates a dma map for the scatter-gather list entries */ 309/* Creates a DMA map for the scatter-gather list entries */
317static int __devinit 310static int __devinit ide_dma_sgiioc4(ide_hwif_t *hwif,
318ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d) 311 const struct ide_port_info *d)
319{ 312{
320 struct pci_dev *dev = to_pci_dev(hwif->dev); 313 struct pci_dev *dev = to_pci_dev(hwif->dev);
321 unsigned long dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET; 314 unsigned long dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET;
322 int num_ports = sizeof (ioc4_dma_regs_t); 315 int num_ports = sizeof(struct ioc4_dma_regs);
323 void *pad; 316 void *pad;
324 317
325 printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name); 318 printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name);
@@ -362,8 +355,7 @@ dma_pci_alloc_failure:
362} 355}
363 356
364/* Initializes the IOC4 DMA Engine */ 357/* Initializes the IOC4 DMA Engine */
365static void 358static void sgiioc4_configure_for_dma(int dma_direction, ide_drive_t *drive)
366sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
367{ 359{
368 u32 ioc4_dma; 360 u32 ioc4_dma;
369 ide_hwif_t *hwif = drive->hwif; 361 ide_hwif_t *hwif = drive->hwif;
@@ -374,31 +366,27 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
374 ioc4_dma = readl((void __iomem *)ioc4_dma_addr); 366 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
375 367
376 if (ioc4_dma & IOC4_S_DMA_ACTIVE) { 368 if (ioc4_dma & IOC4_S_DMA_ACTIVE) {
377 printk(KERN_WARNING 369 printk(KERN_WARNING "%s(%s): Warning!! DMA from previous "
378 "%s(%s):Warning!! DMA from previous transfer was still active\n", 370 "transfer was still active\n", __func__, drive->name);
379 __func__, drive->name);
380 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr); 371 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
381 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 372 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
382 373
383 if (ioc4_dma & IOC4_S_DMA_STOP) 374 if (ioc4_dma & IOC4_S_DMA_STOP)
384 printk(KERN_ERR 375 printk(KERN_ERR "%s(%s): IOC4 DMA STOP bit is "
385 "%s(%s) : IOC4 Dma STOP bit is still 1\n", 376 "still 1\n", __func__, drive->name);
386 __func__, drive->name);
387 } 377 }
388 378
389 ioc4_dma = readl((void __iomem *)ioc4_dma_addr); 379 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
390 if (ioc4_dma & IOC4_S_DMA_ERROR) { 380 if (ioc4_dma & IOC4_S_DMA_ERROR) {
391 printk(KERN_WARNING 381 printk(KERN_WARNING "%s(%s): Warning!! DMA Error during "
392 "%s(%s) : Warning!! - DMA Error during Previous" 382 "previous transfer, status 0x%x\n",
393 " transfer | status 0x%x\n",
394 __func__, drive->name, ioc4_dma); 383 __func__, drive->name, ioc4_dma);
395 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr); 384 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
396 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 385 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
397 386
398 if (ioc4_dma & IOC4_S_DMA_STOP) 387 if (ioc4_dma & IOC4_S_DMA_STOP)
399 printk(KERN_ERR 388 printk(KERN_ERR "%s(%s): IOC4 DMA STOP bit is "
400 "%s(%s) : IOC4 DMA STOP bit is still 1\n", 389 "still 1\n", __func__, drive->name);
401 __func__, drive->name);
402 } 390 }
403 391
404 /* Address of the Scatter Gather List */ 392 /* Address of the Scatter Gather List */
@@ -408,20 +396,22 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
408 /* Address of the Ending DMA */ 396 /* Address of the Ending DMA */
409 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE); 397 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE);
410 ending_dma_addr = cpu_to_le32(hwif->extra_base); 398 ending_dma_addr = cpu_to_le32(hwif->extra_base);
411 writel(ending_dma_addr, (void __iomem *)(dma_base + IOC4_DMA_END_ADDR * 4)); 399 writel(ending_dma_addr, (void __iomem *)(dma_base +
400 IOC4_DMA_END_ADDR * 4));
412 401
413 writel(dma_direction, (void __iomem *)ioc4_dma_addr); 402 writel(dma_direction, (void __iomem *)ioc4_dma_addr);
414} 403}
415 404
416/* IOC4 Scatter Gather list Format */ 405/* IOC4 Scatter Gather list Format */
417/* 128 Bit entries to support 64 bit addresses in the future */ 406/* 128 Bit entries to support 64 bit addresses in the future */
418/* The Scatter Gather list Entry should be in the BIG-ENDIAN Format */ 407/* The Scatter Gather list Entry should be in the BIG-ENDIAN Format */
419/* --------------------------------------------------------------------- */ 408/* --------------------------------------------------------------------- */
420/* | Upper 32 bits - Zero | Lower 32 bits- address | */ 409/* | Upper 32 bits - Zero | Lower 32 bits- address | */
421/* --------------------------------------------------------------------- */ 410/* --------------------------------------------------------------------- */
422/* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */ 411/* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */
423/* --------------------------------------------------------------------- */ 412/* --------------------------------------------------------------------- */
424/* Creates the scatter gather list, DMA Table */ 413/* Creates the scatter gather list, DMA Table */
414
425static int sgiioc4_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd) 415static int sgiioc4_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
426{ 416{
427 ide_hwif_t *hwif = drive->hwif; 417 ide_hwif_t *hwif = drive->hwif;
@@ -448,8 +438,10 @@ static int sgiioc4_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
448 if (bcount > cur_len) 438 if (bcount > cur_len)
449 bcount = cur_len; 439 bcount = cur_len;
450 440
451 /* put the addr, length in 441 /*
452 * the IOC4 dma-table format */ 442 * Put the address, length in
443 * the IOC4 dma-table format
444 */
453 *table = 0x0; 445 *table = 0x0;
454 table++; 446 table++;
455 *table = cpu_to_be32(cur_addr); 447 *table = cpu_to_be32(cur_addr);
@@ -540,8 +532,7 @@ static const struct ide_port_info sgiioc4_port_info __devinitconst = {
540 .mwdma_mask = ATA_MWDMA2_ONLY, 532 .mwdma_mask = ATA_MWDMA2_ONLY,
541}; 533};
542 534
543static int __devinit 535static int __devinit sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
544sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
545{ 536{
546 unsigned long cmd_base, irqport; 537 unsigned long cmd_base, irqport;
547 unsigned long bar0, cmd_phys_base, ctl; 538 unsigned long bar0, cmd_phys_base, ctl;
@@ -549,7 +540,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
549 struct ide_hw hw, *hws[] = { &hw }; 540 struct ide_hw hw, *hws[] = { &hw };
550 int rc; 541 int rc;
551 542
552 /* Get the CmdBlk and CtrlBlk Base Registers */ 543 /* Get the CmdBlk and CtrlBlk base registers */
553 bar0 = pci_resource_start(dev, 0); 544 bar0 = pci_resource_start(dev, 0);
554 virt_base = pci_ioremap_bar(dev, 0); 545 virt_base = pci_ioremap_bar(dev, 0);
555 if (virt_base == NULL) { 546 if (virt_base == NULL) {
@@ -557,9 +548,9 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
557 DRV_NAME, bar0); 548 DRV_NAME, bar0);
558 return -ENOMEM; 549 return -ENOMEM;
559 } 550 }
560 cmd_base = (unsigned long) virt_base + IOC4_CMD_OFFSET; 551 cmd_base = (unsigned long)virt_base + IOC4_CMD_OFFSET;
561 ctl = (unsigned long) virt_base + IOC4_CTRL_OFFSET; 552 ctl = (unsigned long)virt_base + IOC4_CTRL_OFFSET;
562 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET; 553 irqport = (unsigned long)virt_base + IOC4_INTR_OFFSET;
563 554
564 cmd_phys_base = bar0 + IOC4_CMD_OFFSET; 555 cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
565 if (request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, 556 if (request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
@@ -577,7 +568,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
577 hw.irq = dev->irq; 568 hw.irq = dev->irq;
578 hw.dev = &dev->dev; 569 hw.dev = &dev->dev;
579 570
580 /* Initializing chipset IRQ Registers */ 571 /* Initialize chipset IRQ registers */
581 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4)); 572 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
582 573
583 rc = ide_host_add(&sgiioc4_port_info, hws, 1, NULL); 574 rc = ide_host_add(&sgiioc4_port_info, hws, 1, NULL);
@@ -590,8 +581,7 @@ req_mem_rgn_err:
590 return rc; 581 return rc;
591} 582}
592 583
593static unsigned int __devinit 584static unsigned int __devinit pci_init_sgiioc4(struct pci_dev *dev)
594pci_init_sgiioc4(struct pci_dev *dev)
595{ 585{
596 int ret; 586 int ret;
597 587
@@ -611,10 +601,10 @@ out:
611 return ret; 601 return ret;
612} 602}
613 603
614int __devinit 604int __devinit ioc4_ide_attach_one(struct ioc4_driver_data *idd)
615ioc4_ide_attach_one(struct ioc4_driver_data *idd)
616{ 605{
617 /* PCI-RT does not bring out IDE connection. 606 /*
607 * PCI-RT does not bring out IDE connection.
618 * Do not attach to this particular IOC4. 608 * Do not attach to this particular IOC4.
619 */ 609 */
620 if (idd->idd_variant == IOC4_VARIANT_PCI_RT) 610 if (idd->idd_variant == IOC4_VARIANT_PCI_RT)
@@ -627,7 +617,6 @@ static struct ioc4_submodule __devinitdata ioc4_ide_submodule = {
627 .is_name = "IOC4_ide", 617 .is_name = "IOC4_ide",
628 .is_owner = THIS_MODULE, 618 .is_owner = THIS_MODULE,
629 .is_probe = ioc4_ide_attach_one, 619 .is_probe = ioc4_ide_attach_one,
630/* .is_remove = ioc4_ide_remove_one, */
631}; 620};
632 621
633static int __init ioc4_ide_init(void) 622static int __init ioc4_ide_init(void)
diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
index bd82d228608c..d95df528562f 100644
--- a/drivers/ide/siimage.c
+++ b/drivers/ide/siimage.c
@@ -32,7 +32,6 @@
32 * smarter code in libata. 32 * smarter code in libata.
33 * 33 *
34 * TODO: 34 * TODO:
35 * - IORDY fixes
36 * - VDMA support 35 * - VDMA support
37 */ 36 */
38 37
@@ -234,8 +233,7 @@ static u8 sil_sata_udma_filter(ide_drive_t *drive)
234 * @pio: PIO mode number 233 * @pio: PIO mode number
235 * 234 *
236 * Load the timing settings for this device mode into the 235 * Load the timing settings for this device mode into the
237 * controller. If we are in PIO mode 3 or 4 turn on IORDY 236 * controller.
238 * monitoring (bit 9). The TF timing is bits 31:16
239 */ 237 */
240 238
241static void sil_set_pio_mode(ide_drive_t *drive, u8 pio) 239static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
@@ -276,13 +274,16 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
276 /* now set up IORDY */ 274 /* now set up IORDY */
277 speedp = sil_ioread16(dev, tfaddr - 2); 275 speedp = sil_ioread16(dev, tfaddr - 2);
278 speedp &= ~0x200; 276 speedp &= ~0x200;
279 if (pio > 2)
280 speedp |= 0x200;
281 sil_iowrite16(dev, speedp, tfaddr - 2);
282 277
283 mode = sil_ioread8(dev, base + addr_mask); 278 mode = sil_ioread8(dev, base + addr_mask);
284 mode &= ~(unit ? 0x30 : 0x03); 279 mode &= ~(unit ? 0x30 : 0x03);
285 mode |= unit ? 0x10 : 0x01; 280
281 if (ide_pio_need_iordy(drive, pio)) {
282 speedp |= 0x200;
283 mode |= unit ? 0x10 : 0x01;
284 }
285
286 sil_iowrite16(dev, speedp, tfaddr - 2);
286 sil_iowrite8(dev, mode, base + addr_mask); 287 sil_iowrite8(dev, mode, base + addr_mask);
287} 288}
288 289
@@ -337,24 +338,14 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
337 sil_iowrite16(dev, ultra, ua); 338 sil_iowrite16(dev, ultra, ua);
338} 339}
339 340
340/* returns 1 if dma irq issued, 0 otherwise */ 341static int sil_test_irq(ide_hwif_t *hwif)
341static int siimage_io_dma_test_irq(ide_drive_t *drive)
342{ 342{
343 ide_hwif_t *hwif = drive->hwif;
344 struct pci_dev *dev = to_pci_dev(hwif->dev); 343 struct pci_dev *dev = to_pci_dev(hwif->dev);
345 u8 dma_altstat = 0;
346 unsigned long addr = siimage_selreg(hwif, 1); 344 unsigned long addr = siimage_selreg(hwif, 1);
345 u8 val = sil_ioread8(dev, addr);
347 346
348 /* return 1 if INTR asserted */ 347 /* Return 1 if INTRQ asserted */
349 if (inb(hwif->dma_base + ATA_DMA_STATUS) & 4) 348 return (val & 8) ? 1 : 0;
350 return 1;
351
352 /* return 1 if Device INTR asserted */
353 pci_read_config_byte(dev, addr, &dma_altstat);
354 if (dma_altstat & 8)
355 return 0; /* return 1; */
356
357 return 0;
358} 349}
359 350
360/** 351/**
@@ -368,7 +359,6 @@ static int siimage_io_dma_test_irq(ide_drive_t *drive)
368static int siimage_mmio_dma_test_irq(ide_drive_t *drive) 359static int siimage_mmio_dma_test_irq(ide_drive_t *drive)
369{ 360{
370 ide_hwif_t *hwif = drive->hwif; 361 ide_hwif_t *hwif = drive->hwif;
371 unsigned long addr = siimage_selreg(hwif, 0x1);
372 void __iomem *sata_error_addr 362 void __iomem *sata_error_addr
373 = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET]; 363 = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET];
374 364
@@ -397,10 +387,6 @@ static int siimage_mmio_dma_test_irq(ide_drive_t *drive)
397 if (readb((void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)) & 4) 387 if (readb((void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)) & 4)
398 return 1; 388 return 1;
399 389
400 /* return 1 if Device INTR asserted */
401 if (readb((void __iomem *)addr) & 8)
402 return 0; /* return 1; */
403
404 return 0; 390 return 0;
405} 391}
406 392
@@ -409,7 +395,7 @@ static int siimage_dma_test_irq(ide_drive_t *drive)
409 if (drive->hwif->host_flags & IDE_HFLAG_MMIO) 395 if (drive->hwif->host_flags & IDE_HFLAG_MMIO)
410 return siimage_mmio_dma_test_irq(drive); 396 return siimage_mmio_dma_test_irq(drive);
411 else 397 else
412 return siimage_io_dma_test_irq(drive); 398 return ide_dma_test_irq(drive);
413} 399}
414 400
415/** 401/**
@@ -694,6 +680,7 @@ static const struct ide_port_ops sil_pata_port_ops = {
694 .set_pio_mode = sil_set_pio_mode, 680 .set_pio_mode = sil_set_pio_mode,
695 .set_dma_mode = sil_set_dma_mode, 681 .set_dma_mode = sil_set_dma_mode,
696 .quirkproc = sil_quirkproc, 682 .quirkproc = sil_quirkproc,
683 .test_irq = sil_test_irq,
697 .udma_filter = sil_pata_udma_filter, 684 .udma_filter = sil_pata_udma_filter,
698 .cable_detect = sil_cable_detect, 685 .cable_detect = sil_cable_detect,
699}; 686};
@@ -704,6 +691,7 @@ static const struct ide_port_ops sil_sata_port_ops = {
704 .reset_poll = sil_sata_reset_poll, 691 .reset_poll = sil_sata_reset_poll,
705 .pre_reset = sil_sata_pre_reset, 692 .pre_reset = sil_sata_pre_reset,
706 .quirkproc = sil_quirkproc, 693 .quirkproc = sil_quirkproc,
694 .test_irq = sil_test_irq,
707 .udma_filter = sil_sata_udma_filter, 695 .udma_filter = sil_sata_udma_filter,
708 .cable_detect = sil_cable_detect, 696 .cable_detect = sil_cable_detect,
709}; 697};
diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
index 0924abff52ff..d698da470d6f 100644
--- a/drivers/ide/sl82c105.c
+++ b/drivers/ide/sl82c105.c
@@ -61,8 +61,7 @@ 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 (ide_pio_need_iordy(drive, pio))
65 !(pio > 4 && ata_id_is_cfa(drive->id)))
66 iordy = 0x40; 65 iordy = 0x40;
67 66
68 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy; 67 return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy;
@@ -74,6 +73,7 @@ static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
74static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio) 73static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
75{ 74{
76 struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 75 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
76 unsigned long timings = (unsigned long)ide_get_drivedata(drive);
77 int reg = 0x44 + drive->dn * 4; 77 int reg = 0x44 + drive->dn * 4;
78 u16 drv_ctrl; 78 u16 drv_ctrl;
79 79
@@ -83,8 +83,9 @@ static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
83 * Store the PIO timings so that we can restore them 83 * Store the PIO timings so that we can restore them
84 * in case DMA will be turned off... 84 * in case DMA will be turned off...
85 */ 85 */
86 drive->drive_data &= 0xffff0000; 86 timings &= 0xffff0000;
87 drive->drive_data |= drv_ctrl; 87 timings |= drv_ctrl;
88 ide_set_drivedata(drive, (void *)timings);
88 89
89 pci_write_config_word(dev, reg, drv_ctrl); 90 pci_write_config_word(dev, reg, drv_ctrl);
90 pci_read_config_word (dev, reg, &drv_ctrl); 91 pci_read_config_word (dev, reg, &drv_ctrl);
@@ -100,6 +101,7 @@ static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
100static void sl82c105_set_dma_mode(ide_drive_t *drive, const u8 speed) 101static void sl82c105_set_dma_mode(ide_drive_t *drive, const u8 speed)
101{ 102{
102 static u16 mwdma_timings[] = {0x0707, 0x0201, 0x0200}; 103 static u16 mwdma_timings[] = {0x0707, 0x0201, 0x0200};
104 unsigned long timings = (unsigned long)ide_get_drivedata(drive);
103 u16 drv_ctrl; 105 u16 drv_ctrl;
104 106
105 DBG(("sl82c105_tune_chipset(drive:%s, speed:%s)\n", 107 DBG(("sl82c105_tune_chipset(drive:%s, speed:%s)\n",
@@ -111,8 +113,19 @@ static void sl82c105_set_dma_mode(ide_drive_t *drive, const u8 speed)
111 * Store the DMA timings so that we can actually program 113 * Store the DMA timings so that we can actually program
112 * them when DMA will be turned on... 114 * them when DMA will be turned on...
113 */ 115 */
114 drive->drive_data &= 0x0000ffff; 116 timings &= 0x0000ffff;
115 drive->drive_data |= (unsigned long)drv_ctrl << 16; 117 timings |= (unsigned long)drv_ctrl << 16;
118 ide_set_drivedata(drive, (void *)timings);
119}
120
121static int sl82c105_test_irq(ide_hwif_t *hwif)
122{
123 struct pci_dev *dev = to_pci_dev(hwif->dev);
124 u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA;
125
126 pci_read_config_dword(dev, 0x40, &val);
127
128 return (val & mask) ? 1 : 0;
116} 129}
117 130
118/* 131/*
@@ -185,7 +198,8 @@ static void sl82c105_dma_start(ide_drive_t *drive)
185 198
186 DBG(("%s(drive:%s)\n", __func__, drive->name)); 199 DBG(("%s(drive:%s)\n", __func__, drive->name));
187 200
188 pci_write_config_word(dev, reg, drive->drive_data >> 16); 201 pci_write_config_word(dev, reg,
202 (unsigned long)ide_get_drivedata(drive) >> 16);
189 203
190 sl82c105_reset_host(dev); 204 sl82c105_reset_host(dev);
191 ide_dma_start(drive); 205 ide_dma_start(drive);
@@ -210,7 +224,8 @@ static int sl82c105_dma_end(ide_drive_t *drive)
210 224
211 ret = ide_dma_end(drive); 225 ret = ide_dma_end(drive);
212 226
213 pci_write_config_word(dev, reg, drive->drive_data); 227 pci_write_config_word(dev, reg,
228 (unsigned long)ide_get_drivedata(drive));
214 229
215 return ret; 230 return ret;
216} 231}
@@ -289,6 +304,7 @@ static const struct ide_port_ops sl82c105_port_ops = {
289 .set_pio_mode = sl82c105_set_pio_mode, 304 .set_pio_mode = sl82c105_set_pio_mode,
290 .set_dma_mode = sl82c105_set_dma_mode, 305 .set_dma_mode = sl82c105_set_dma_mode,
291 .resetproc = sl82c105_resetproc, 306 .resetproc = sl82c105_resetproc,
307 .test_irq = sl82c105_test_irq,
292}; 308};
293 309
294static const struct ide_dma_ops sl82c105_dma_ops = { 310static const struct ide_dma_ops sl82c105_dma_ops = {
diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
index f55d7d6313e8..9aec78d3bcff 100644
--- a/drivers/ide/slc90e66.c
+++ b/drivers/ide/slc90e66.c
@@ -44,7 +44,7 @@ static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
44 control |= 1; /* Programmable timing on */ 44 control |= 1; /* Programmable timing on */
45 if (drive->media == ide_disk) 45 if (drive->media == ide_disk)
46 control |= 4; /* Prefetch, post write */ 46 control |= 4; /* Prefetch, post write */
47 if (pio > 2) 47 if (ide_pio_need_iordy(drive, pio))
48 control |= 2; /* IORDY */ 48 control |= 2; /* IORDY */
49 if (is_slave) { 49 if (is_slave) {
50 master_data |= 0x4000; 50 master_data |= 0x4000;