ieee1394: limit early node speed to host interface speed
[safe/jmp/linux-2.6] / drivers / ide / ide-io.c
index 0f3e2f4..7153796 100644 (file)
@@ -58,15 +58,19 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
                             int uptodate, unsigned int nr_bytes, int dequeue)
 {
        int ret = 1;
+       int error = 0;
+
+       if (uptodate <= 0)
+               error = uptodate ? uptodate : -EIO;
 
        /*
         * if failfast is set on a request, override number of sectors and
         * complete the whole request right now
         */
-       if (blk_noretry_request(rq) && end_io_error(uptodate))
+       if (blk_noretry_request(rq) && error)
                nr_bytes = rq->hard_nr_sectors << 9;
 
-       if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors)
+       if (!blk_fs_request(rq) && error && !rq->errors)
                rq->errors = -EIO;
 
        /*
@@ -78,14 +82,9 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
                ide_dma_on(drive);
        }
 
-       if (!end_that_request_chunk(rq, uptodate, nr_bytes)) {
-               add_disk_randomness(rq->rq_disk);
-               if (dequeue) {
-                       if (!list_empty(&rq->queuelist))
-                               blkdev_dequeue_request(rq);
+       if (!__blk_end_request(rq, error, nr_bytes)) {
+               if (dequeue)
                        HWGROUP(drive)->rq = NULL;
-               }
-               end_that_request_last(rq, uptodate);
                ret = 0;
        }
 
@@ -290,9 +289,9 @@ static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
                drive->blocked = 0;
                blk_start_queue(drive->queue);
        }
-       blkdev_dequeue_request(rq);
        HWGROUP(drive)->rq = NULL;
-       end_that_request_last(rq, 1);
+       if (__blk_end_request(rq, 0, 0))
+               BUG();
        spin_unlock_irqrestore(&ide_lock, flags);
 }
 
@@ -354,7 +353,6 @@ void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
  
 void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
 {
-       ide_hwif_t *hwif = HWIF(drive);
        unsigned long flags;
        struct request *rq;
 
@@ -362,30 +360,22 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
        rq = HWGROUP(drive)->rq;
        spin_unlock_irqrestore(&ide_lock, flags);
 
-       if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
-               u8 *args = (u8 *) rq->buffer;
-               if (rq->errors == 0)
-                       rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
-
-               if (args) {
-                       args[0] = stat;
-                       args[1] = err;
-                       /* be sure we're looking at the low order bits */
-                       hwif->OUTB(drive->ctl & ~0x80, IDE_CONTROL_REG);
-                       args[2] = hwif->INB(IDE_NSECTOR_REG);
-               }
-       } else if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
-               ide_task_t *args = (ide_task_t *) rq->special;
+       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,READY_STAT,BAD_STAT);
-                       
-               if (args) {
-                       struct ide_taskfile *tf = &args->tf;
+                       rq->errors = !OK_STAT(stat, READY_STAT, BAD_STAT);
+
+               if (task) {
+                       struct ide_taskfile *tf = &task->tf;
 
                        tf->error = err;
                        tf->status = stat;
 
-                       ide_tf_read(drive, args);
+                       ide_tf_read(drive, task);
+
+                       if (task->tf_flags & IDE_TFLAG_DYN)
+                               kfree(task);
                }
        } else if (blk_pm_request(rq)) {
                struct request_pm_state *pm = rq->data;
@@ -400,10 +390,11 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
        }
 
        spin_lock_irqsave(&ide_lock, flags);
-       blkdev_dequeue_request(rq);
        HWGROUP(drive)->rq = NULL;
        rq->errors = err;
-       end_that_request_last(rq, !rq->errors);
+       if (unlikely(__blk_end_request(rq, (rq->errors ? -EIO : 0),
+                                      blk_rq_bytes(rq))))
+               BUG();
        spin_unlock_irqrestore(&ide_lock, flags);
 }
 
@@ -480,7 +471,7 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
                return ide_stopped;
        }
 
-       if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
+       if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
                rq->errors |= ERROR_RESET;
 
        if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
@@ -507,7 +498,7 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
                /* add decoding error stuff */
        }
 
-       if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
+       if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
                /* force an abort */
                hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
 
@@ -624,42 +615,6 @@ ide_startstop_t ide_abort(ide_drive_t *drive, const char *msg)
                return __ide_abort(drive, rq);
 }
 
-/**
- *     drive_cmd_intr          -       drive command completion interrupt
- *     @drive: drive the completion interrupt occurred on
- *
- *     drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
- *     We do any necessary data reading and then wait for the drive to
- *     go non busy. At that point we may read the error data and complete
- *     the request
- */
-static ide_startstop_t drive_cmd_intr (ide_drive_t *drive)
-{
-       struct request *rq = HWGROUP(drive)->rq;
-       ide_hwif_t *hwif = HWIF(drive);
-       u8 *args = (u8 *) rq->buffer;
-       u8 stat = hwif->INB(IDE_STATUS_REG);
-       int retries = 10;
-
-       local_irq_enable_in_hardirq();
-       if (rq->cmd_type == REQ_TYPE_ATA_CMD &&
-           (stat & DRQ_STAT) && args && args[3]) {
-               u8 io_32bit = drive->io_32bit;
-               drive->io_32bit = 0;
-               hwif->ata_input_data(drive, &args[4], args[3] * SECTOR_WORDS);
-               drive->io_32bit = io_32bit;
-               while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
-                       udelay(100);
-       }
-
-       if (!OK_STAT(stat, READY_STAT, BAD_STAT))
-               return ide_error(drive, "drive_cmd", stat);
-               /* calls ide_end_drive_cmd */
-       ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
-       return ide_stopped;
-}
-
 static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
 {
        tf->nsect   = drive->sect;
@@ -845,16 +800,9 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
                struct request *rq)
 {
        ide_hwif_t *hwif = HWIF(drive);
-       u8 *args = rq->buffer;
-       ide_task_t ltask;
-       struct ide_taskfile *tf = &ltask.tf;
-
-       if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
-               ide_task_t *task = rq->special;
-               if (task == NULL)
-                       goto done;
+       ide_task_t *task = rq->special;
 
+       if (task) {
                hwif->data_phase = task->data_phase;
 
                switch (hwif->data_phase) {
@@ -871,33 +819,6 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
                return do_rw_taskfile(drive, task);
        }
 
-       if (args == NULL)
-               goto done;
-
-       memset(&ltask, 0, sizeof(ltask));
-       if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
-#ifdef DEBUG
-               printk("%s: DRIVE_CMD\n", drive->name);
-#endif
-               tf->feature = args[2];
-               if (args[0] == WIN_SMART) {
-                       tf->nsect = args[3];
-                       tf->lbal  = args[1];
-                       tf->lbam  = 0x4f;
-                       tf->lbah  = 0xc2;
-                       ltask.tf_flags = IDE_TFLAG_OUT_TF;
-               } else {
-                       tf->nsect = args[1];
-                       ltask.tf_flags = IDE_TFLAG_OUT_FEATURE |
-                                        IDE_TFLAG_OUT_NSECT;
-               }
-       }
-       tf->command = args[0];
-       ide_tf_load(drive, &ltask);
-       ide_execute_command(drive, args[0], &drive_cmd_intr, WAIT_WORSTCASE, NULL);
-       return ide_started;
-
-done:
        /*
         * NULL is actually a valid way of waiting for
         * all current requests to be flushed from the queue.
@@ -905,9 +826,8 @@ done:
 #ifdef DEBUG
        printk("%s: DRIVE_CMD (null)\n", drive->name);
 #endif
-       ide_end_drive_cmd(drive,
-                       hwif->INB(IDE_STATUS_REG),
-                       hwif->INB(IDE_ERROR_REG));
+       ide_end_drive_cmd(drive, ide_read_status(drive), ide_read_error(drive));
+
        return ide_stopped;
 }
 
@@ -1001,8 +921,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
                if (drive->current_speed == 0xff)
                        ide_config_drive_speed(drive, drive->desired_speed);
 
-               if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
-                   rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
+               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;
@@ -1316,7 +1235,7 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
                printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
                (void)HWIF(drive)->ide_dma_end(drive);
                ret = ide_error(drive, "dma timeout error",
-                                               hwif->INB(IDE_STATUS_REG));
+                               ide_read_status(drive));
        } else {
                printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
                hwif->dma_timeout(drive);
@@ -1440,7 +1359,8 @@ void ide_timer_expiry (unsigned long data)
                                        startstop = ide_dma_timeout_retry(drive, wait);
                                } else
                                        startstop =
-                                       ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG));
+                                       ide_error(drive, "irq timeout",
+                                                 ide_read_status(drive));
                        }
                        drive->service_time = jiffies - drive->service_start;
                        spin_lock_irq(&ide_lock);
@@ -1572,7 +1492,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
                 * remove all the ifdef PCI crap
                 */
 #ifdef CONFIG_BLK_DEV_IDEPCI
-               if (hwif->pci_dev && !hwif->pci_dev->vendor)
+               if (hwif->chipset != ide_pci)
 #endif /* CONFIG_BLK_DEV_IDEPCI */
                {
                        /*
@@ -1674,7 +1594,6 @@ irqreturn_t ide_intr (int irq, void *dev_id)
 void ide_init_drive_cmd (struct request *rq)
 {
        memset(rq, 0, sizeof(*rq));
-       rq->cmd_type = REQ_TYPE_ATA_CMD;
        rq->ref_count = 1;
 }