]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-io.c
ide: use per-port IRQ handlers
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-io.c
index 72d0d702d5dace3e30ec53670d8fd23a730d0dc9..1fc739f4415485d2894b7981a8fb5c94ca8236af 100644 (file)
@@ -120,98 +120,6 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
 }
 EXPORT_SYMBOL(ide_end_request);
 
-static void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
-{
-       struct request_pm_state *pm = rq->data;
-
-#ifdef DEBUG_PM
-       printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
-               drive->name, pm->pm_step);
-#endif
-       if (drive->media != ide_disk)
-               return;
-
-       switch (pm->pm_step) {
-       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
-               if (pm->pm_state == PM_EVENT_FREEZE)
-                       pm->pm_step = IDE_PM_COMPLETED;
-               else
-                       pm->pm_step = IDE_PM_STANDBY;
-               break;
-       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
-               pm->pm_step = IDE_PM_COMPLETED;
-               break;
-       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
-               pm->pm_step = IDE_PM_IDLE;
-               break;
-       case IDE_PM_IDLE:               /* Resume step 2 (idle)*/
-               pm->pm_step = IDE_PM_RESTORE_DMA;
-               break;
-       }
-}
-
-static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
-{
-       struct request_pm_state *pm = rq->data;
-       ide_task_t *args = rq->special;
-
-       memset(args, 0, sizeof(*args));
-
-       switch (pm->pm_step) {
-       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
-               if (drive->media != ide_disk)
-                       break;
-               /* Not supported? Switch to next step now. */
-               if (ata_id_flush_enabled(drive->id) == 0 ||
-                   (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
-                       ide_complete_power_step(drive, rq);
-                       return ide_stopped;
-               }
-               if (ata_id_flush_ext_enabled(drive->id))
-                       args->tf.command = ATA_CMD_FLUSH_EXT;
-               else
-                       args->tf.command = ATA_CMD_FLUSH;
-               goto out_do_tf;
-       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
-               args->tf.command = ATA_CMD_STANDBYNOW1;
-               goto out_do_tf;
-       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
-               ide_set_max_pio(drive);
-               /*
-                * skip IDE_PM_IDLE for ATAPI devices
-                */
-               if (drive->media != ide_disk)
-                       pm->pm_step = IDE_PM_RESTORE_DMA;
-               else
-                       ide_complete_power_step(drive, rq);
-               return ide_stopped;
-       case IDE_PM_IDLE:               /* Resume step 2 (idle) */
-               args->tf.command = ATA_CMD_IDLEIMMEDIATE;
-               goto out_do_tf;
-       case IDE_PM_RESTORE_DMA:        /* Resume step 3 (restore DMA) */
-               /*
-                * Right now, all we do is call ide_set_dma(drive),
-                * we could be smarter and check for current xfer_speed
-                * in struct drive etc...
-                */
-               if (drive->hwif->dma_ops == NULL)
-                       break;
-               /*
-                * TODO: respect IDE_DFLAG_USING_DMA
-                */
-               ide_set_dma(drive);
-               break;
-       }
-
-       pm->pm_step = IDE_PM_COMPLETED;
-       return ide_stopped;
-
-out_do_tf:
-       args->tf_flags   = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-       args->data_phase = TASKFILE_NO_DATA;
-       return do_rw_taskfile(drive, args);
-}
-
 /**
  *     ide_end_dequeued_request        -       complete an IDE I/O
  *     @drive: IDE device for the I/O
@@ -236,39 +144,6 @@ int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
 }
 EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
 
-
-/**
- *     ide_complete_pm_request - end the current Power Management request
- *     @drive: target drive
- *     @rq: request
- *
- *     This function cleans up the current PM request and stops the queue
- *     if necessary.
- */
-static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
-{
-       struct request_queue *q = drive->queue;
-       unsigned long flags;
-
-#ifdef DEBUG_PM
-       printk("%s: completing PM request, %s\n", drive->name,
-              blk_pm_suspend_request(rq) ? "suspend" : "resume");
-#endif
-       spin_lock_irqsave(q->queue_lock, flags);
-       if (blk_pm_suspend_request(rq)) {
-               blk_stop_queue(q);
-       } else {
-               drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
-               blk_start_queue(q);
-       }
-       spin_unlock_irqrestore(q->queue_lock, flags);
-
-       drive->hwif->hwgroup->rq = NULL;
-
-       if (blk_end_request(rq, 0, 0))
-               BUG();
-}
-
 /**
  *     ide_end_drive_cmd       -       end an explicit drive command
  *     @drive: command 
@@ -291,9 +166,6 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
        if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
                ide_task_t *task = (ide_task_t *)rq->special;
 
-               if (rq->errors == 0)
-                       rq->errors = !OK_STAT(stat, ATA_DRDY, BAD_STAT);
-
                if (task) {
                        struct ide_taskfile *tf = &task->tf;
 
@@ -554,9 +426,6 @@ void ide_map_sg(ide_drive_t *drive, struct request *rq)
        ide_hwif_t *hwif = drive->hwif;
        struct scatterlist *sg = hwif->sg_table;
 
-       if (hwif->sg_mapped)    /* needed by ide-scsi */
-               return;
-
        if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) {
                hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
        } else {
@@ -700,40 +569,6 @@ static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
        }
 }
 
-static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
-{
-       struct request_pm_state *pm = rq->data;
-
-       if (blk_pm_suspend_request(rq) &&
-           pm->pm_step == IDE_PM_START_SUSPEND)
-               /* Mark drive blocked when starting the suspend sequence. */
-               drive->dev_flags |= IDE_DFLAG_BLOCKED;
-       else if (blk_pm_resume_request(rq) &&
-                pm->pm_step == IDE_PM_START_RESUME) {
-               /* 
-                * The first thing we do on wakeup is to wait for BSY bit to
-                * go away (with a looong timeout) as a drive on this hwif may
-                * just be POSTing itself.
-                * We do that before even selecting as the "other" device on
-                * the bus may be broken enough to walk on our toes at this
-                * point.
-                */
-               ide_hwif_t *hwif = drive->hwif;
-               int rc;
-#ifdef DEBUG_PM
-               printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
-#endif
-               rc = ide_wait_not_busy(hwif, 35000);
-               if (rc)
-                       printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
-               SELECT_DRIVE(drive);
-               hwif->tp_ops->set_irq(hwif, 1);
-               rc = ide_wait_not_busy(hwif, 100000);
-               if (rc)
-                       printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
-       }
-}
-
 /**
  *     start_request   -       start of I/O and command issuing for IDE
  *
@@ -829,85 +664,10 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
        drive->sleep = timeout + jiffies;
        drive->dev_flags |= IDE_DFLAG_SLEEPING;
 }
-
 EXPORT_SYMBOL(ide_stall_queue);
 
-#define WAKEUP(drive)  ((drive)->service_start + 2 * (drive)->service_time)
-
-/**
- *     choose_drive            -       select a drive to service
- *     @hwgroup: hardware group to select on
- *
- *     choose_drive() selects the next drive which will be serviced.
- *     This is necessary because the IDE layer can't issue commands
- *     to both drives on the same cable, unlike SCSI.
- */
-static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup)
-{
-       ide_drive_t *drive, *best;
-
-repeat:        
-       best = NULL;
-       drive = hwgroup->drive;
-
-       /*
-        * drive is doing pre-flush, ordered write, post-flush sequence. even
-        * though that is 3 requests, it must be seen as a single transaction.
-        * we must not preempt this drive until that is complete
-        */
-       if (blk_queue_flushing(drive->queue)) {
-               /*
-                * small race where queue could get replugged during
-                * the 3-request flush cycle, just yank the plug since
-                * we want it to finish asap
-                */
-               blk_remove_plug(drive->queue);
-               return drive;
-       }
-
-       do {
-               u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING);
-               u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING));
-
-               if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) &&
-                   !elv_queue_empty(drive->queue)) {
-                       if (best == NULL ||
-                           (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) ||
-                           (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) {
-                               if (!blk_queue_plugged(drive->queue))
-                                       best = drive;
-                       }
-               }
-       } while ((drive = drive->next) != hwgroup->drive);
-
-       if (best && (best->dev_flags & IDE_DFLAG_NICE1) &&
-           (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 &&
-           best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
-               long t = (signed long)(WAKEUP(best) - jiffies);
-               if (t >= WAIT_MIN_SLEEP) {
-               /*
-                * We *may* have some time to spare, but first let's see if
-                * someone can potentially benefit from our nice mood today..
-                */
-                       drive = best->next;
-                       do {
-                               if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0
-                                && time_before(jiffies - best->service_time, WAKEUP(drive))
-                                && time_before(WAKEUP(drive), jiffies + t))
-                               {
-                                       ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP));
-                                       goto repeat;
-                               }
-                       } while ((drive = drive->next) != best);
-               }
-       }
-       return best;
-}
-
 /*
  * Issue a new request to a drive from hwgroup
- * Caller must have already done spin_lock_irqsave(&hwgroup->lock, ..);
  *
  * A hwgroup is a serialized group of IDE interfaces.  Usually there is
  * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640)
@@ -919,8 +679,7 @@ repeat:
  * possibly along with many other devices.  This is especially common in
  * PCI-based systems with off-board IDE controller cards.
  *
- * The IDE driver uses a per-hwgroup spinlock to protect
- * access to the request queues, and to protect the hwgroup->busy flag.
+ * The IDE driver uses a per-hwgroup lock to protect the hwgroup->busy flag.
  *
  * The first thread into the driver for a particular hwgroup sets the
  * hwgroup->busy flag to indicate that this hwgroup is now active,
@@ -940,95 +699,70 @@ repeat:
  * the driver.  This makes the driver much more friendlier to shared IRQs
  * than previous designs, while remaining 100% (?) SMP safe and capable.
  */
-static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
+void do_ide_request(struct request_queue *q)
 {
-       ide_drive_t     *drive;
-       ide_hwif_t      *hwif;
+       ide_drive_t     *drive = q->queuedata;
+       ide_hwif_t      *hwif = drive->hwif;
+       ide_hwgroup_t   *hwgroup = hwif->hwgroup;
        struct request  *rq;
        ide_startstop_t startstop;
-       int             loops = 0;
-
-       /* caller must own hwgroup->lock */
-       BUG_ON(!irqs_disabled());
-
-       while (!hwgroup->busy) {
-               hwgroup->busy = 1;
-               /* for atari only */
-               ide_get_lock(ide_intr, hwgroup);
-               drive = choose_drive(hwgroup);
-               if (drive == NULL) {
-                       int sleeping = 0;
-                       unsigned long sleep = 0; /* shut up, gcc */
-                       hwgroup->rq = NULL;
-                       drive = hwgroup->drive;
-                       do {
-                               if ((drive->dev_flags & IDE_DFLAG_SLEEPING) &&
-                                   (sleeping == 0 ||
-                                    time_before(drive->sleep, sleep))) {
-                                       sleeping = 1;
-                                       sleep = drive->sleep;
-                               }
-                       } while ((drive = drive->next) != hwgroup->drive);
-                       if (sleeping) {
+
+       /*
+        * drive is doing pre-flush, ordered write, post-flush sequence. even
+        * though that is 3 requests, it must be seen as a single transaction.
+        * we must not preempt this drive until that is complete
+        */
+       if (blk_queue_flushing(q))
                /*
-                * Take a short snooze, and then wake up this hwgroup again.
-                * This gives other hwgroups on the same a chance to
-                * play fairly with us, just in case there are big differences
-                * in relative throughputs.. don't want to hog the cpu too much.
+                * small race where queue could get replugged during
+                * the 3-request flush cycle, just yank the plug since
+                * we want it to finish asap
                 */
-                               if (time_before(sleep, jiffies + WAIT_MIN_SLEEP))
-                                       sleep = jiffies + WAIT_MIN_SLEEP;
-#if 1
-                               if (timer_pending(&hwgroup->timer))
-                                       printk(KERN_CRIT "ide_set_handler: timer already active\n");
-#endif
-                               /* so that ide_timer_expiry knows what to do */
-                               hwgroup->sleeping = 1;
-                               hwgroup->req_gen_timer = hwgroup->req_gen;
-                               mod_timer(&hwgroup->timer, sleep);
-                               /* we purposely leave hwgroup->busy==1
-                                * while sleeping */
-                       } else {
-                               /* Ugly, but how can we sleep for the lock
-                                * otherwise? perhaps from tq_disk?
-                                */
+               blk_remove_plug(q);
 
-                               /* for atari only */
-                               ide_release_lock();
-                               hwgroup->busy = 0;
-                       }
+       spin_unlock_irq(q->queue_lock);
+       spin_lock_irq(&hwgroup->lock);
 
-                       /* no more work for this hwgroup (for now) */
-                       return;
+       if (!ide_lock_hwgroup(hwgroup, hwif)) {
+               ide_hwif_t *prev_port;
+repeat:
+               prev_port = hwif->host->cur_port;
+               hwgroup->rq = NULL;
+
+               if (drive->dev_flags & IDE_DFLAG_SLEEPING) {
+                       if (time_before(drive->sleep, jiffies)) {
+                               ide_unlock_hwgroup(hwgroup);
+                               goto plug_device;
+                       }
                }
-       again:
-               hwif = HWIF(drive);
-               if (hwgroup->hwif->sharing_irq && hwif != hwgroup->hwif) {
+
+               if ((hwif->host->host_flags & IDE_HFLAG_SERIALIZE) &&
+                   hwif != prev_port) {
                        /*
-                        * set nIEN for previous hwif, drives in the
+                        * set nIEN for previous port, drives in the
                         * quirk_list may not like intr setups/cleanups
                         */
-                       if (drive->quirk_list != 1)
-                               hwif->tp_ops->set_irq(hwif, 0);
+                       if (prev_port && hwgroup->drive->quirk_list == 0)
+                               prev_port->tp_ops->set_irq(prev_port, 0);
+
+                       hwif->host->cur_port = hwif;
                }
-               hwgroup->hwif = hwif;
                hwgroup->drive = drive;
                drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
-               drive->service_start = jiffies;
-
-               if (blk_queue_plugged(drive->queue)) {
-                       printk(KERN_ERR "ide: huh? queue was plugged!\n");
-                       break;
-               }
 
+               spin_unlock_irq(&hwgroup->lock);
+               spin_lock_irq(q->queue_lock);
                /*
                 * we know that the queue isn't empty, but this can happen
                 * if the q->prep_rq_fn() decides to kill a request
                 */
                rq = elv_next_request(drive->queue);
+               spin_unlock_irq(q->queue_lock);
+               spin_lock_irq(&hwgroup->lock);
+
                if (!rq) {
-                       hwgroup->busy = 0;
-                       break;
+                       ide_unlock_hwgroup(hwgroup);
+                       goto out;
                }
 
                /*
@@ -1043,53 +777,36 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
                 * though. I hope that doesn't happen too much, hopefully not
                 * unless the subdriver triggers such a thing in its own PM
                 * state machine.
-                *
-                * We count how many times we loop here to make sure we service
-                * all drives in the hwgroup without looping for ever
                 */
                if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
                    blk_pm_request(rq) == 0 &&
                    (rq->cmd_flags & REQ_PREEMPT) == 0) {
-                       drive = drive->next ? drive->next : hwgroup->drive;
-                       if (loops++ < 4 && !blk_queue_plugged(drive->queue))
-                               goto again;
-                       /* We clear busy, there should be no pending ATA command at this point. */
-                       hwgroup->busy = 0;
-                       break;
+                       /* there should be no pending command at this point */
+                       ide_unlock_hwgroup(hwgroup);
+                       goto plug_device;
                }
 
                hwgroup->rq = rq;
 
-               /*
-                * Some systems have trouble with IDE IRQs arriving while
-                * the driver is still setting things up.  So, here we disable
-                * the IRQ used by this interface while the request is being started.
-                * This may look bad at first, but pretty much the same thing
-                * happens anyway when any interrupt comes in, IDE or otherwise
-                *  -- the kernel masks the IRQ while it is being handled.
-                */
-               if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
-                       disable_irq_nosync(hwif->irq);
-               spin_unlock(&hwgroup->lock);
-               local_irq_enable_in_hardirq();
-                       /* allow other IRQs while we start this request */
+               spin_unlock_irq(&hwgroup->lock);
                startstop = start_request(drive, rq);
                spin_lock_irq(&hwgroup->lock);
-               if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
-                       enable_irq(hwif->irq);
+
                if (startstop == ide_stopped)
-                       hwgroup->busy = 0;
-       }
-}
+                       goto repeat;
+       } else
+               goto plug_device;
+out:
+       spin_unlock_irq(&hwgroup->lock);
+       spin_lock_irq(q->queue_lock);
+       return;
 
-/*
- * Passes the stuff to ide_do_request
- */
-void do_ide_request(struct request_queue *q)
-{
-       ide_drive_t *drive = q->queuedata;
+plug_device:
+       spin_unlock_irq(&hwgroup->lock);
+       spin_lock_irq(q->queue_lock);
 
-       ide_do_request(HWGROUP(drive), IDE_NO_IRQ);
+       if (!elv_queue_empty(q))
+               blk_plug_device(q);
 }
 
 /*
@@ -1150,6 +867,17 @@ out:
        return ret;
 }
 
+static void ide_plug_device(ide_drive_t *drive)
+{
+       struct request_queue *q = drive->queue;
+       unsigned long flags;
+
+       spin_lock_irqsave(q->queue_lock, flags);
+       if (!elv_queue_empty(q))
+               blk_plug_device(q);
+       spin_unlock_irqrestore(q->queue_lock, flags);
+}
+
 /**
  *     ide_timer_expiry        -       handle lack of an IDE interrupt
  *     @data: timer callback magic (hwgroup)
@@ -1167,10 +895,12 @@ out:
 void ide_timer_expiry (unsigned long data)
 {
        ide_hwgroup_t   *hwgroup = (ide_hwgroup_t *) data;
+       ide_drive_t     *uninitialized_var(drive);
        ide_handler_t   *handler;
        ide_expiry_t    *expiry;
        unsigned long   flags;
        unsigned long   wait = -1;
+       int             plug_device = 0;
 
        spin_lock_irqsave(&hwgroup->lock, flags);
 
@@ -1182,22 +912,15 @@ void ide_timer_expiry (unsigned long data)
                 * or we were "sleeping" to give other devices a chance.
                 * Either way, we don't really want to complain about anything.
                 */
-               if (hwgroup->sleeping) {
-                       hwgroup->sleeping = 0;
-                       hwgroup->busy = 0;
-               }
        } else {
-               ide_drive_t *drive = hwgroup->drive;
+               drive = hwgroup->drive;
                if (!drive) {
                        printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n");
                        hwgroup->handler = NULL;
                } else {
                        ide_hwif_t *hwif;
                        ide_startstop_t startstop = ide_stopped;
-                       if (!hwgroup->busy) {
-                               hwgroup->busy = 1;      /* paranoia */
-                               printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name);
-                       }
+
                        if ((expiry = hwgroup->expiry) != NULL) {
                                /* continue */
                                if ((wait = expiry(drive)) > 0) {
@@ -1238,21 +961,24 @@ void ide_timer_expiry (unsigned long data)
                                        ide_error(drive, "irq timeout",
                                                  hwif->tp_ops->read_status(hwif));
                        }
-                       drive->service_time = jiffies - drive->service_start;
                        spin_lock_irq(&hwgroup->lock);
                        enable_irq(hwif->irq);
-                       if (startstop == ide_stopped)
-                               hwgroup->busy = 0;
+                       if (startstop == ide_stopped) {
+                               ide_unlock_hwgroup(hwgroup);
+                               plug_device = 1;
+                       }
                }
        }
-       ide_do_request(hwgroup, IDE_NO_IRQ);
        spin_unlock_irqrestore(&hwgroup->lock, flags);
+
+       if (plug_device)
+               ide_plug_device(drive);
 }
 
 /**
  *     unexpected_intr         -       handle an unexpected IDE interrupt
  *     @irq: interrupt line
- *     @hwgroup: hwgroup being processed
+ *     @hwif: port being processed
  *
  *     There's nothing really useful we can do with an unexpected interrupt,
  *     other than reading the status register (to clear it), and logging it.
@@ -1276,51 +1002,37 @@ void ide_timer_expiry (unsigned long data)
  *     before completing the issuance of any new drive command, so we will not
  *     be accidentally invoked as a result of any valid command completion
  *     interrupt.
- *
- *     Note that we must walk the entire hwgroup here. We know which hwif
- *     is doing the current command, but we don't know which hwif burped
- *     mysteriously.
  */
-static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
-{
-       u8 stat;
-       ide_hwif_t *hwif = hwgroup->hwif;
 
-       /*
-        * handle the unexpected interrupt
-        */
-       do {
-               if (hwif->irq == irq) {
-                       stat = hwif->tp_ops->read_status(hwif);
-
-                       if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
-                               /* Try to not flood the console with msgs */
-                               static unsigned long last_msgtime, count;
-                               ++count;
-                               if (time_after(jiffies, last_msgtime + HZ)) {
-                                       last_msgtime = jiffies;
-                                       printk(KERN_ERR "%s%s: unexpected interrupt, "
-                                               "status=0x%02x, count=%ld\n",
-                                               hwif->name,
-                                               (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count);
-                               }
-                       }
+static void unexpected_intr(int irq, ide_hwif_t *hwif)
+{
+       u8 stat = hwif->tp_ops->read_status(hwif);
+
+       if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
+               /* Try to not flood the console with msgs */
+               static unsigned long last_msgtime, count;
+               ++count;
+
+               if (time_after(jiffies, last_msgtime + HZ)) {
+                       last_msgtime = jiffies;
+                       printk(KERN_ERR "%s: unexpected interrupt, "
+                               "status=0x%02x, count=%ld\n",
+                               hwif->name, stat, count);
                }
-       } while ((hwif = hwif->next) != hwgroup->hwif);
+       }
 }
 
 /**
  *     ide_intr        -       default IDE interrupt handler
  *     @irq: interrupt number
- *     @dev_id: hwif group
+ *     @dev_id: hwif
  *     @regs: unused weirdness from the kernel irq layer
  *
  *     This is the default IRQ handler for the IDE layer. You should
  *     not need to override it. If you do be aware it is subtle in
  *     places
  *
- *     hwgroup->hwif is the interface in the group currently performing
+ *     hwif is the interface in the group currently performing
  *     a command. hwgroup->drive is the drive and hwgroup->handler is
  *     the IRQ handler to call. As we issue a command the handlers
  *     step through multiple states, reassigning the handler to the
@@ -1337,13 +1049,19 @@ static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
  
 irqreturn_t ide_intr (int irq, void *dev_id)
 {
-       unsigned long flags;
-       ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id;
-       ide_hwif_t *hwif = hwgroup->hwif;
-       ide_drive_t *drive;
+       ide_hwif_t *hwif = (ide_hwif_t *)dev_id;
+       ide_hwgroup_t *hwgroup = hwif->hwgroup;
+       ide_drive_t *uninitialized_var(drive);
        ide_handler_t *handler;
+       unsigned long flags;
        ide_startstop_t startstop;
        irqreturn_t irq_ret = IRQ_NONE;
+       int plug_device = 0;
+
+       if (hwif->host->host_flags & IDE_HFLAG_SERIALIZE) {
+               if (hwif != hwif->host->cur_port)
+                       goto out_early;
+       }
 
        spin_lock_irqsave(&hwgroup->lock, flags);
 
@@ -1374,7 +1092,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
                         * Probably not a shared PCI interrupt,
                         * so we can safely try to do something about it:
                         */
-                       unexpected_intr(irq, hwgroup);
+                       unexpected_intr(irq, hwif);
 #ifdef CONFIG_BLK_DEV_IDEPCI
                } else {
                        /*
@@ -1408,10 +1126,6 @@ irqreturn_t ide_intr (int irq, void *dev_id)
                 */
                goto out;
 
-       if (!hwgroup->busy) {
-               hwgroup->busy = 1;      /* paranoia */
-               printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name);
-       }
        hwgroup->handler = NULL;
        hwgroup->req_gen++;
        del_timer(&hwgroup->timer);
@@ -1434,20 +1148,22 @@ irqreturn_t ide_intr (int irq, void *dev_id)
         * same irq as is currently being serviced here, and Linux
         * won't allow another of the same (on any CPU) until we return.
         */
-       drive->service_time = jiffies - drive->service_start;
        if (startstop == ide_stopped) {
                if (hwgroup->handler == NULL) { /* paranoia */
-                       hwgroup->busy = 0;
-                       ide_do_request(hwgroup, hwif->irq);
-               } else {
-                       printk(KERN_ERR "%s: ide_intr: huh? expected NULL handler "
-                               "on exit\n", drive->name);
-               }
+                       ide_unlock_hwgroup(hwgroup);
+                       plug_device = 1;
+               } else
+                       printk(KERN_ERR "%s: %s: huh? expected NULL handler "
+                                       "on exit\n", __func__, drive->name);
        }
 out_handled:
        irq_ret = IRQ_HANDLED;
 out:
        spin_unlock_irqrestore(&hwgroup->lock, flags);
+out_early:
+       if (plug_device)
+               ide_plug_device(drive);
+
        return irq_ret;
 }
 
@@ -1476,7 +1192,6 @@ void ide_do_drive_cmd(ide_drive_t *drive, struct request *rq)
 
        spin_lock_irqsave(q->queue_lock, flags);
        __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 0);
-       blk_start_queueing(q);
        spin_unlock_irqrestore(q->queue_lock, flags);
 }
 EXPORT_SYMBOL(ide_do_drive_cmd);