Merge branch 'for-2.6.31' of git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
[safe/jmp/linux-2.6] / drivers / ide / ide-io.c
index 28ac463..41d8040 100644 (file)
@@ -71,50 +71,9 @@ int ide_end_rq(ide_drive_t *drive, struct request *rq, int error,
 }
 EXPORT_SYMBOL_GPL(ide_end_rq);
 
-/**
- *     ide_end_request         -       complete an IDE I/O
- *     @drive: IDE device for the I/O
- *     @uptodate:
- *     @nr_sectors: number of sectors completed
- *
- *     This is our end_request wrapper function. We complete the I/O
- *     update random number input and dequeue the request, which if
- *     it was tagged may be out of order.
- */
-
-int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
-{
-       unsigned int nr_bytes = nr_sectors << 9;
-       struct request *rq = drive->hwif->rq;
-       int rc, error = 0;
-
-       if (!nr_bytes) {
-               if (blk_pc_request(rq))
-                       nr_bytes = rq->data_len;
-               else
-                       nr_bytes = rq->hard_cur_sectors << 9;
-       }
-
-       /*
-        * if failfast is set on a request, override number of sectors
-        * and complete the whole request right now
-        */
-       if (blk_noretry_request(rq) && uptodate <= 0)
-               nr_bytes = rq->hard_nr_sectors << 9;
-
-       if (uptodate <= 0)
-               error = uptodate ? uptodate : -EIO;
-
-       rc = ide_end_rq(drive, rq, error, nr_bytes);
-       if (rc == 0)
-               drive->hwif->rq = NULL;
-
-       return rc;
-}
-EXPORT_SYMBOL(ide_end_request);
-
 void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
 {
+       const struct ide_tp_ops *tp_ops = drive->hwif->tp_ops;
        struct ide_taskfile *tf = &cmd->tf;
        struct request *rq = cmd->rq;
        u8 tf_cmd = tf->command;
@@ -122,34 +81,65 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
        tf->error = err;
        tf->status = stat;
 
-       drive->hwif->tp_ops->tf_read(drive, cmd);
+       if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
+               u8 data[2];
+
+               tp_ops->input_data(drive, cmd, data, 2);
+
+               cmd->tf.data  = data[0];
+               cmd->hob.data = data[1];
+       }
+
+       ide_tf_readback(drive, cmd);
 
        if ((cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) &&
            tf_cmd == ATA_CMD_IDLEIMMEDIATE) {
                if (tf->lbal != 0xc4) {
                        printk(KERN_ERR "%s: head unload failed!\n",
                               drive->name);
-                       ide_tf_dump(drive->name, tf);
+                       ide_tf_dump(drive->name, cmd);
                } else
                        drive->dev_flags |= IDE_DFLAG_PARKED;
        }
 
-       if (rq && rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
-               memcpy(rq->special, cmd, sizeof(*cmd));
+       if (rq && rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
+               struct ide_cmd *orig_cmd = rq->special;
+
+               if (cmd->tf_flags & IDE_TFLAG_DYN)
+                       kfree(orig_cmd);
+               else
+                       memcpy(orig_cmd, cmd, sizeof(*cmd));
+       }
+}
 
-       if (cmd->tf_flags & IDE_TFLAG_DYN)
-               kfree(cmd);
+/* obsolete, blk_rq_bytes() should be used instead */
+unsigned int ide_rq_bytes(struct request *rq)
+{
+       if (blk_pc_request(rq))
+               return rq->data_len;
+       else
+               return rq->hard_cur_sectors << 9;
 }
+EXPORT_SYMBOL_GPL(ide_rq_bytes);
 
-void ide_complete_rq(ide_drive_t *drive, int error)
+int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = hwif->rq;
+       int rc;
+
+       /*
+        * if failfast is set on a request, override number of sectors
+        * and complete the whole request right now
+        */
+       if (blk_noretry_request(rq) && error <= 0)
+               nr_bytes = rq->hard_nr_sectors << 9;
 
-       hwif->rq = NULL;
+       rc = ide_end_rq(drive, rq, error, nr_bytes);
+       if (rc == 0)
+               hwif->rq = NULL;
 
-       if (unlikely(blk_end_request(rq, error, blk_rq_bytes(rq))))
-               BUG();
+       return rc;
 }
 EXPORT_SYMBOL(ide_complete_rq);
 
@@ -162,13 +152,13 @@ void ide_kill_rq(ide_drive_t *drive, struct request *rq)
 
        if ((media == ide_floppy || media == ide_tape) && drv_req) {
                rq->errors = 0;
-               ide_complete_rq(drive, 0);
+               ide_complete_rq(drive, 0, blk_rq_bytes(rq));
        } else {
                if (media == ide_tape)
                        rq->errors = IDE_DRV_ERROR_GENERAL;
                else if (blk_fs_request(rq) == 0 && rq->errors == 0)
                        rq->errors = -EIO;
-               ide_end_request(drive, 0, 0);
+               ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
        }
 }
 
@@ -218,8 +208,9 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
                return ide_stopped;
        }
 
-       cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE |
-                      IDE_TFLAG_CUSTOM_HANDLER;
+       cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
+       cmd.valid.in.tf  = IDE_VALID_IN_TF  | IDE_VALID_DEVICE;
+       cmd.tf_flags = IDE_TFLAG_CUSTOM_HANDLER;
 
        do_rw_taskfile(drive, &cmd);
 
@@ -251,26 +242,19 @@ static ide_startstop_t do_special (ide_drive_t *drive)
        return ide_stopped;
 }
 
-void ide_map_sg(ide_drive_t *drive, struct request *rq)
+void ide_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
 {
        ide_hwif_t *hwif = drive->hwif;
-       struct ide_cmd *cmd = &hwif->cmd;
        struct scatterlist *sg = hwif->sg_table;
+       struct request *rq = cmd->rq;
 
-       if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
-               sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
-               cmd->sg_nents = 1;
-       } else if (!rq->bio) {
-               sg_init_one(sg, rq->data, rq->data_len);
-               cmd->sg_nents = 1;
-       } else
-               cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
+       cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
 }
 EXPORT_SYMBOL_GPL(ide_map_sg);
 
-void ide_init_sg_cmd(struct ide_cmd *cmd, int nsect)
+void ide_init_sg_cmd(struct ide_cmd *cmd, unsigned int nr_bytes)
 {
-       cmd->nsect = cmd->nleft = nsect;
+       cmd->nbytes = cmd->nleft = nr_bytes;
        cmd->cursg_ofs = 0;
        cmd->cursg = NULL;
 }
@@ -295,8 +279,8 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
 
        if (cmd) {
                if (cmd->protocol == ATA_PROT_PIO) {
-                       ide_init_sg_cmd(cmd, rq->nr_sectors);
-                       ide_map_sg(drive, rq);
+                       ide_init_sg_cmd(cmd, rq->nr_sectors << 9);
+                       ide_map_sg(drive, cmd);
                }
 
                return do_rw_taskfile(drive, cmd);
@@ -310,7 +294,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
        printk("%s: DRIVE_CMD (null)\n", drive->name);
 #endif
        rq->errors = 0;
-       ide_complete_rq(drive, 0);
+       ide_complete_rq(drive, 0, blk_rq_bytes(rq));
 
        return ide_stopped;
 }
@@ -361,7 +345,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
        if (blk_pm_request(rq))
                ide_check_pm_state(drive, rq);
 
-       SELECT_DRIVE(drive);
+       drive->hwif->tp_ops->dev_select(drive);
        if (ide_wait_stat(&startstop, drive, drive->ready_stat,
                          ATA_BUSY | ATA_DRQ, WAIT_READY)) {
                printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
@@ -380,7 +364,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
                if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
                        return execute_drive_cmd(drive, rq);
                else if (blk_pm_request(rq)) {
-                       struct request_pm_state *pm = rq->data;
+                       struct request_pm_state *pm = rq->special;
 #ifdef DEBUG_PM
                        printk("%s: start_power_step(step: %d)\n",
                                drive->name, pm->pm_step);
@@ -493,6 +477,9 @@ void do_ide_request(struct request_queue *q)
 
        spin_unlock_irq(q->queue_lock);
 
+       /* HLD do_request() callback might sleep, make sure it's okay */
+       might_sleep();
+
        if (ide_lock_host(host, hwif))
                goto plug_device_2;
 
@@ -504,11 +491,10 @@ repeat:
                prev_port = hwif->host->cur_port;
                hwif->rq = NULL;
 
-               if (drive->dev_flags & IDE_DFLAG_SLEEPING) {
-                       if (time_before(drive->sleep, jiffies)) {
-                               ide_unlock_port(hwif);
-                               goto plug_device;
-                       }
+               if (drive->dev_flags & IDE_DFLAG_SLEEPING &&
+                   time_after(drive->sleep, jiffies)) {
+                       ide_unlock_port(hwif);
+                       goto plug_device;
                }
 
                if ((hwif->host->host_flags & IDE_HFLAG_SERIALIZE) &&
@@ -518,7 +504,9 @@ repeat:
                         * quirk_list may not like intr setups/cleanups
                         */
                        if (prev_port && prev_port->cur_dev->quirk_list == 0)
-                               prev_port->tp_ops->set_irq(prev_port, 0);
+                               prev_port->tp_ops->write_devctl(prev_port,
+                                                               ATA_NIEN |
+                                                               ATA_DEVCTL_OBS);
 
                        hwif->host->cur_port = hwif;
                }
@@ -674,6 +662,7 @@ void ide_timer_expiry (unsigned long data)
                        }
                }
                hwif->handler = NULL;
+               hwif->expiry = NULL;
                /*
                 * We need to simulate a real interrupt when invoking
                 * the handler() function, which means we need to
@@ -703,7 +692,7 @@ void ide_timer_expiry (unsigned long data)
                }
                spin_lock_irq(&hwif->lock);
                enable_irq(hwif->irq);
-               if (startstop == ide_stopped) {
+               if (startstop == ide_stopped && hwif->polling == 0) {
                        ide_unlock_port(hwif);
                        plug_device = 1;
                }
@@ -853,6 +842,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
                goto out;
 
        hwif->handler = NULL;
+       hwif->expiry = NULL;
        hwif->req_gen++;
        del_timer(&hwif->timer);
        spin_unlock(&hwif->lock);
@@ -874,7 +864,7 @@ 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.
         */
-       if (startstop == ide_stopped) {
+       if (startstop == ide_stopped && hwif->polling == 0) {
                BUG_ON(hwif->handler);
                ide_unlock_port(hwif);
                plug_device = 1;