ALSA: hda - Remove old codec-probe limitation
[safe/jmp/linux-2.6] / drivers / ide / ide-taskfile.c
index 0518a2e..7fb6f1c 100644 (file)
@@ -8,83 +8,33 @@
  *  The big the bad and the ugly.
  */
 
-#include <linux/module.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/kernel.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/interrupt.h>
-#include <linux/major.h>
 #include <linux/errno.h>
-#include <linux/genhd.h>
-#include <linux/blkpg.h>
 #include <linux/slab.h>
-#include <linux/pci.h>
 #include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
-#include <linux/bitops.h>
 #include <linux/scatterlist.h>
 
-#include <asm/byteorder.h>
-#include <asm/irq.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
-void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
+void ide_tf_dump(const char *s, struct ide_taskfile *tf)
 {
-       ide_hwif_t *hwif = drive->hwif;
-       struct ide_taskfile *tf = &task->tf;
-       u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
-
-       if (task->tf_flags & IDE_TFLAG_FLAGGED)
-               HIHI = 0xFF;
-
 #ifdef DEBUG
        printk("%s: tf: feat 0x%02x nsect 0x%02x lbal 0x%02x "
                "lbam 0x%02x lbah 0x%02x dev 0x%02x cmd 0x%02x\n",
-               drive->name, tf->feature, tf->nsect, tf->lbal,
+               s, tf->feature, tf->nsect, tf->lbal,
                tf->lbam, tf->lbah, tf->device, tf->command);
        printk("%s: hob: nsect 0x%02x lbal 0x%02x "
                "lbam 0x%02x lbah 0x%02x\n",
-               drive->name, tf->hob_nsect, tf->hob_lbal,
+               s, tf->hob_nsect, tf->hob_lbal,
                tf->hob_lbam, tf->hob_lbah);
 #endif
-
-       ide_set_irq(drive, 1);
-
-       if ((task->tf_flags & IDE_TFLAG_NO_SELECT_MASK) == 0)
-               SELECT_MASK(drive, 0);
-
-       if (task->tf_flags & IDE_TFLAG_OUT_DATA)
-               hwif->OUTW((tf->hob_data << 8) | tf->data, IDE_DATA_REG);
-
-       if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
-               hwif->OUTB(tf->hob_feature, IDE_FEATURE_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
-               hwif->OUTB(tf->hob_nsect, IDE_NSECTOR_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
-               hwif->OUTB(tf->hob_lbal, IDE_SECTOR_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
-               hwif->OUTB(tf->hob_lbam, IDE_LCYL_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
-               hwif->OUTB(tf->hob_lbah, IDE_HCYL_REG);
-
-       if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
-               hwif->OUTB(tf->feature, IDE_FEATURE_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
-               hwif->OUTB(tf->nsect, IDE_NSECTOR_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
-               hwif->OUTB(tf->lbal, IDE_SECTOR_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
-               hwif->OUTB(tf->lbam, IDE_LCYL_REG);
-       if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
-               hwif->OUTB(tf->lbah, IDE_HCYL_REG);
-
-       if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
-               hwif->OUTB((tf->device & HIHI) | drive->select.all, IDE_SELECT_REG);
 }
 
 int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
@@ -102,25 +52,6 @@ int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
        return ide_raw_taskfile(drive, &args, buf, 1);
 }
 
-static int inline task_dma_ok(ide_task_t *task)
-{
-       if (blk_fs_request(task->rq) || (task->tf_flags & IDE_TFLAG_FLAGGED))
-               return 1;
-
-       switch (task->tf.command) {
-               case WIN_WRITEDMA_ONCE:
-               case WIN_WRITEDMA:
-               case WIN_WRITEDMA_EXT:
-               case WIN_READDMA_ONCE:
-               case WIN_READDMA:
-               case WIN_READDMA_EXT:
-               case WIN_IDENTIFY_DMA:
-                       return 1;
-       }
-
-       return 0;
-}
-
 static ide_startstop_t task_no_data_intr(ide_drive_t *);
 static ide_startstop_t set_geometry_intr(ide_drive_t *);
 static ide_startstop_t recal_intr(ide_drive_t *);
@@ -133,6 +64,8 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
        ide_hwif_t *hwif        = HWIF(drive);
        struct ide_taskfile *tf = &task->tf;
        ide_handler_t *handler = NULL;
+       const struct ide_tp_ops *tp_ops = hwif->tp_ops;
+       const struct ide_dma_ops *dma_ops = hwif->dma_ops;
 
        if (task->data_phase == TASKFILE_MULTI_IN ||
            task->data_phase == TASKFILE_MULTI_OUT) {
@@ -146,13 +79,17 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
        if (task->tf_flags & IDE_TFLAG_FLAGGED)
                task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS;
 
-       if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0)
-               ide_tf_load(drive, task);
+       if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
+               ide_tf_dump(drive->name, tf);
+               tp_ops->set_irq(hwif, 1);
+               SELECT_MASK(drive, 0);
+               tp_ops->tf_load(drive, task);
+       }
 
        switch (task->data_phase) {
        case TASKFILE_MULTI_OUT:
        case TASKFILE_OUT:
-               hwif->OUTBSYNC(drive, tf->command, IDE_COMMAND_REG);
+               tp_ops->exec_command(hwif, tf->command);
                ndelay(400);    /* FIXME */
                return pre_task_out_intr(drive, task->rq);
        case TASKFILE_MULTI_IN:
@@ -174,11 +111,10 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
                                    WAIT_WORSTCASE, NULL);
                return ide_started;
        default:
-               if (task_dma_ok(task) == 0 || drive->using_dma == 0 ||
-                   hwif->dma_setup(drive))
+               if (drive->using_dma == 0 || dma_ops->dma_setup(drive))
                        return ide_stopped;
-               hwif->dma_exec_cmd(drive, tf->command);
-               hwif->dma_start(drive);
+               dma_ops->dma_exec_cmd(drive, tf->command);
+               dma_ops->dma_start(drive);
                return ide_started;
        }
 }
@@ -189,7 +125,11 @@ EXPORT_SYMBOL_GPL(do_rw_taskfile);
  */
 static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
 {
-       u8 stat = ide_read_status(drive);
+       ide_hwif_t *hwif = drive->hwif;
+       u8 stat;
+
+       local_irq_enable_in_hardirq();
+       stat = hwif->tp_ops->read_status(hwif);
 
        if (OK_STAT(stat, READY_STAT, BAD_STAT))
                drive->mult_count = drive->mult_req;
@@ -206,11 +146,18 @@ static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
  */
 static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
 {
+       ide_hwif_t *hwif = drive->hwif;
        int retries = 5;
        u8 stat;
 
-       while (((stat = ide_read_status(drive)) & BUSY_STAT) && retries--)
+       local_irq_enable_in_hardirq();
+
+       while (1) {
+               stat = hwif->tp_ops->read_status(hwif);
+               if ((stat & BUSY_STAT) == 0 || retries-- == 0)
+                       break;
                udelay(10);
+       };
 
        if (OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_stopped;
@@ -218,7 +165,6 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
        if (stat & (ERR_STAT|DRQ_STAT))
                return ide_error(drive, "set_geometry_intr", stat);
 
-       BUG_ON(HWGROUP(drive)->handler != NULL);
        ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
        return ide_started;
 }
@@ -228,7 +174,11 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
  */
 static ide_startstop_t recal_intr(ide_drive_t *drive)
 {
-       u8 stat = ide_read_status(drive);
+       ide_hwif_t *hwif = drive->hwif;
+       u8 stat;
+
+       local_irq_enable_in_hardirq();
+       stat = hwif->tp_ops->read_status(hwif);
 
        if (!OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_error(drive, "recal_intr", stat);
@@ -240,11 +190,12 @@ static ide_startstop_t recal_intr(ide_drive_t *drive)
  */
 static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
 {
-       ide_task_t *args        = HWGROUP(drive)->rq->special;
+       ide_hwif_t *hwif = drive->hwif;
+       ide_task_t *args = hwif->hwgroup->rq->special;
        u8 stat;
 
        local_irq_enable_in_hardirq();
-       stat = ide_read_status(drive);
+       stat = hwif->tp_ops->read_status(hwif);
 
        if (!OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_error(drive, "task_no_data_intr", stat);
@@ -258,15 +209,16 @@ static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
 
 static u8 wait_drive_not_busy(ide_drive_t *drive)
 {
+       ide_hwif_t *hwif = drive->hwif;
        int retries;
        u8 stat;
 
        /*
-        * Last sector was transfered, wait until drive is ready.
-        * This can take up to 10 usec, but we will wait max 1 ms.
+        * Last sector was transfered, wait until device is ready.  This can
+        * take up to 6 ms on some ATAPI devices, so we will wait max 10 ms.
         */
-       for (retries = 0; retries < 100; retries++) {
-               stat = ide_read_status(drive);
+       for (retries = 0; retries < 1000; retries++) {
+               stat = hwif->tp_ops->read_status(hwif);
 
                if (stat & BUSY_STAT)
                        udelay(10);
@@ -280,7 +232,8 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
        return stat;
 }
 
-static void ide_pio_sector(ide_drive_t *drive, unsigned int write)
+static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
+                          unsigned int write)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct scatterlist *sg = hwif->sg_table;
@@ -320,9 +273,9 @@ static void ide_pio_sector(ide_drive_t *drive, unsigned int write)
 
        /* do the actual data transfer */
        if (write)
-               hwif->ata_output_data(drive, buf, SECTOR_WORDS);
+               hwif->tp_ops->output_data(drive, rq, buf, SECTOR_SIZE);
        else
-               hwif->ata_input_data(drive, buf, SECTOR_WORDS);
+               hwif->tp_ops->input_data(drive, rq, buf, SECTOR_SIZE);
 
        kunmap_atomic(buf, KM_BIO_SRC_IRQ);
 #ifdef CONFIG_HIGHMEM
@@ -330,13 +283,14 @@ static void ide_pio_sector(ide_drive_t *drive, unsigned int write)
 #endif
 }
 
-static void ide_pio_multi(ide_drive_t *drive, unsigned int write)
+static void ide_pio_multi(ide_drive_t *drive, struct request *rq,
+                         unsigned int write)
 {
        unsigned int nsect;
 
        nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count);
        while (nsect--)
-               ide_pio_sector(drive, write);
+               ide_pio_sector(drive, rq, write);
 }
 
 static void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
@@ -359,10 +313,10 @@ static void ide_pio_datablock(ide_drive_t *drive, struct request *rq,
        switch (drive->hwif->data_phase) {
        case TASKFILE_MULTI_IN:
        case TASKFILE_MULTI_OUT:
-               ide_pio_multi(drive, write);
+               ide_pio_multi(drive, rq, write);
                break;
        default:
-               ide_pio_sector(drive, write);
+               ide_pio_sector(drive, rq, write);
                break;
        }
 
@@ -423,30 +377,48 @@ void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
 }
 
 /*
+ * We got an interrupt on a task_in case, but no errors and no DRQ.
+ *
+ * It might be a spurious irq (shared irq), but it might be a
+ * command that had no output.
+ */
+static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
+{
+       /* Command all done? */
+       if (OK_STAT(stat, READY_STAT, BUSY_STAT)) {
+               task_end_request(drive, rq, stat);
+               return ide_stopped;
+       }
+
+       /* Assume it was a spurious irq */
+       ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
+       return ide_started;
+}
+
+/*
  * Handler for command with PIO data-in phase (Read/Read Multiple).
  */
 static ide_startstop_t task_in_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       struct request *rq = HWGROUP(drive)->rq;
-       u8 stat = ide_read_status(drive);
-
-       /* new way for dealing with premature shared PCI interrupts */
-       if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) {
-               if (stat & (ERR_STAT | DRQ_STAT))
-                       return task_error(drive, rq, __FUNCTION__, stat);
-               /* No data yet, so wait for another IRQ. */
-               ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
-               return ide_started;
-       }
+       struct request *rq = hwif->hwgroup->rq;
+       u8 stat = hwif->tp_ops->read_status(hwif);
+
+       /* Error? */
+       if (stat & ERR_STAT)
+               return task_error(drive, rq, __func__, stat);
+
+       /* Didn't want any data? Odd. */
+       if (!(stat & DRQ_STAT))
+               return task_in_unexpected(drive, rq, stat);
 
        ide_pio_datablock(drive, rq, 0);
 
-       /* If it was the last datablock check status and finish transfer. */
+       /* Are we done? Check status and finish transfer. */
        if (!hwif->nleft) {
                stat = wait_drive_not_busy(drive);
                if (!OK_STAT(stat, 0, BAD_STAT))
-                       return task_error(drive, rq, __FUNCTION__, stat);
+                       return task_error(drive, rq, __func__, stat);
                task_end_request(drive, rq, stat);
                return ide_stopped;
        }
@@ -464,14 +436,14 @@ static ide_startstop_t task_out_intr (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = HWGROUP(drive)->rq;
-       u8 stat = ide_read_status(drive);
+       u8 stat = hwif->tp_ops->read_status(hwif);
 
        if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
-               return task_error(drive, rq, __FUNCTION__, stat);
+               return task_error(drive, rq, __func__, stat);
 
        /* Deal with unexpected ATA data phase. */
        if (((stat & DRQ_STAT) == 0) ^ !hwif->nleft)
-               return task_error(drive, rq, __FUNCTION__, stat);
+               return task_error(drive, rq, __func__, stat);
 
        if (!hwif->nleft) {
                task_end_request(drive, rq, stat);
@@ -509,12 +481,12 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
 
 int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
 {
-       struct request rq;
+       struct request *rq;
+       int error;
 
-       memset(&rq, 0, sizeof(rq));
-       rq.ref_count = 1;
-       rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
-       rq.buffer = buf;
+       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
+       rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
+       rq->buffer = buf;
 
        /*
         * (ks) We transfer currently only whole sectors.
@@ -522,16 +494,19 @@ int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
         * if we would find a solution to transfer any size.
         * To support special commands like READ LONG.
         */
-       rq.hard_nr_sectors = rq.nr_sectors = nsect;
-       rq.hard_cur_sectors = rq.current_nr_sectors = nsect;
+       rq->hard_nr_sectors = rq->nr_sectors = nsect;
+       rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
 
        if (task->tf_flags & IDE_TFLAG_WRITE)
-               rq.cmd_flags |= REQ_RW;
+               rq->cmd_flags |= REQ_RW;
+
+       rq->special = task;
+       task->rq = rq;
 
-       rq.special = task;
-       task->rq = &rq;
+       error = blk_execute_rq(drive->queue, NULL, rq, 0);
+       blk_put_request(rq);
 
-       return ide_do_drive_cmd(drive, &rq, ide_wait);
+       return error;
 }
 
 EXPORT_SYMBOL(ide_raw_taskfile);
@@ -654,7 +629,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
                                /* (hs): give up if multcount is not set */
                                printk(KERN_ERR "%s: %s Multimode Write " \
                                        "multcount is not set\n",
-                                       drive->name, __FUNCTION__);
+                                       drive->name, __func__);
                                err = -EPERM;
                                goto abort;
                        }
@@ -671,7 +646,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
                                /* (hs): give up if multcount is not set */
                                printk(KERN_ERR "%s: %s Multimode Read failure " \
                                        "multcount is not set\n",
-                                       drive->name, __FUNCTION__);
+                                       drive->name, __func__);
                                err = -EPERM;
                                goto abort;
                        }
@@ -757,12 +732,14 @@ int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
        struct hd_driveid *id = drive->id;
 
        if (NULL == (void *) arg) {
-               struct request rq;
+               struct request *rq;
 
-               ide_init_drive_cmd(&rq);
-               rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
+               rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
+               rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
+               err = blk_execute_rq(drive->queue, NULL, rq, 0);
+               blk_put_request(rq);
 
-               return ide_do_drive_cmd(drive, &rq, ide_wait);
+               return err;
        }
 
        if (copy_from_user(args, (void __user *)arg, 4))