Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[safe/jmp/linux-2.6] / drivers / ide / ide-iops.c
index ae227dd..222c1ef 100644 (file)
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
-void SELECT_DRIVE(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       const struct ide_port_ops *port_ops = hwif->port_ops;
-       struct ide_cmd cmd;
-
-       if (port_ops && port_ops->selectproc)
-               port_ops->selectproc(drive);
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.tf_flags = IDE_TFLAG_OUT_DEVICE;
-
-       drive->hwif->tp_ops->tf_load(drive, &cmd);
-}
-
 void SELECT_MASK(ide_drive_t *drive, int mask)
 {
        const struct ide_port_ops *port_ops = drive->hwif->port_ops;
@@ -52,14 +37,11 @@ void SELECT_MASK(ide_drive_t *drive, int mask)
 
 u8 ide_read_error(ide_drive_t *drive)
 {
-       struct ide_cmd cmd;
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.tf_flags = IDE_TFLAG_IN_FEATURE;
+       struct ide_taskfile tf;
 
-       drive->hwif->tp_ops->tf_read(drive, &cmd);
+       drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_ERROR);
 
-       return cmd.tf.error;
+       return tf.error;
 }
 EXPORT_SYMBOL_GPL(ide_read_error);
 
@@ -120,8 +102,8 @@ EXPORT_SYMBOL(ide_fixstring);
  * setting a timer to wake up at half second intervals thereafter,
  * until timeout is achieved, before timing out.
  */
-static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad,
-                          unsigned long timeout, u8 *rstat)
+int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad,
+                   unsigned long timeout, u8 *rstat)
 {
        ide_hwif_t *hwif = drive->hwif;
        const struct ide_tp_ops *tp_ops = hwif->tp_ops;
@@ -224,12 +206,11 @@ EXPORT_SYMBOL_GPL(ide_in_drive_list);
 
 /*
  * Early UDMA66 devices don't set bit14 to 1, only bit13 is valid.
- * We list them here and depend on the device side cable detection for them.
- *
  * Some optical devices with the buggy firmwares have the same problem.
  */
 static const struct drive_list_entry ivb_list[] = {
        { "QUANTUM FIREBALLlct10 05"    , "A03.0900"    },
+       { "QUANTUM FIREBALLlct20 30"    , "APL.0900"    },
        { "TSSTcorp CDDVDW SH-S202J"    , "SB00"        },
        { "TSSTcorp CDDVDW SH-S202J"    , "SB01"        },
        { "TSSTcorp CDDVDW SH-S202N"    , "SB00"        },
@@ -269,10 +250,25 @@ u8 eighty_ninty_three(ide_drive_t *drive)
         * - force bit13 (80c cable present) check also for !ivb devices
         *   (unless the slave device is pre-ATA3)
         */
-       if ((id[ATA_ID_HW_CONFIG] & 0x4000) ||
-           (ivb && (id[ATA_ID_HW_CONFIG] & 0x2000)))
+       if (id[ATA_ID_HW_CONFIG] & 0x4000)
                return 1;
 
+       if (ivb) {
+               const char *model = (char *)&id[ATA_ID_PROD];
+
+               if (strstr(model, "TSSTcorp CDDVDW SH-S202")) {
+                       /*
+                        * These ATAPI devices always report 80c cable
+                        * so we have to depend on the host in this case.
+                        */
+                       if (hwif->cbl == ATA_CBL_PATA80)
+                               return 1;
+               } else {
+                       /* Depend on the device side cable detection. */
+                       if (id[ATA_ID_HW_CONFIG] & 0x2000)
+                               return 1;
+               }
+       }
 no_80w:
        if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
                return 0;
@@ -287,6 +283,30 @@ no_80w:
        return 0;
 }
 
+static const char *nien_quirk_list[] = {
+       "QUANTUM FIREBALLlct08 08",
+       "QUANTUM FIREBALLP KA6.4",
+       "QUANTUM FIREBALLP KA9.1",
+       "QUANTUM FIREBALLP KX13.6",
+       "QUANTUM FIREBALLP KX20.5",
+       "QUANTUM FIREBALLP KX27.3",
+       "QUANTUM FIREBALLP LM20.4",
+       "QUANTUM FIREBALLP LM20.5",
+       "FUJITSU MHZ2160BH G2",
+       NULL
+};
+
+void ide_check_nien_quirk_list(ide_drive_t *drive)
+{
+       const char **list, *m = (char *)&drive->id[ATA_ID_PROD];
+
+       for (list = nien_quirk_list; *list != NULL; list++)
+               if (strstr(m, *list) != NULL) {
+                       drive->dev_flags |= IDE_DFLAG_NIEN_QUIRK;
+                       return;
+               }
+}
+
 int ide_driveid_update(ide_drive_t *drive)
 {
        u16 *id;
@@ -297,7 +317,7 @@ int ide_driveid_update(ide_drive_t *drive)
                return 0;
 
        SELECT_MASK(drive, 1);
-       rc = ide_dev_read_id(drive, ATA_CMD_ID_ATA, id);
+       rc = ide_dev_read_id(drive, ATA_CMD_ID_ATA, id, 1);
        SELECT_MASK(drive, 0);
 
        if (rc)
@@ -311,12 +331,8 @@ int ide_driveid_update(ide_drive_t *drive)
 
        kfree(id);
 
-       if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
-               ide_dma_off(drive);
-
        return 1;
 out_err:
-       SELECT_MASK(drive, 0);
        if (rc == 2)
                printk(KERN_ERR "%s: %s: bad status\n", drive->name, __func__);
        kfree(id);
@@ -327,10 +343,10 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
 {
        ide_hwif_t *hwif = drive->hwif;
        const struct ide_tp_ops *tp_ops = hwif->tp_ops;
+       struct ide_taskfile tf;
        u16 *id = drive->id, i;
        int error = 0;
        u8 stat;
-       struct ide_cmd cmd;
 
 #ifdef CONFIG_BLK_DEV_IDEDMA
        if (hwif->dma_ops)      /* check if host supports DMA */
@@ -348,30 +364,21 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
         * this point (lost interrupt).
         */
 
-       /*
-        *      FIXME: we race against the running IRQ here if
-        *      this is called from non IRQ context. If we use
-        *      disable_irq() we hang on the error path. Work
-        *      is needed.
-        */
-       disable_irq_nosync(hwif->irq);
-
        udelay(1);
-       SELECT_DRIVE(drive);
+       tp_ops->dev_select(drive);
        SELECT_MASK(drive, 1);
        udelay(1);
        tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
 
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT;
-       cmd.tf.feature = SETFEATURES_XFER;
-       cmd.tf.nsect   = speed;
+       memset(&tf, 0, sizeof(tf));
+       tf.feature = SETFEATURES_XFER;
+       tf.nsect   = speed;
 
-       tp_ops->tf_load(drive, &cmd);
+       tp_ops->tf_load(drive, &tf, IDE_VALID_FEATURE | IDE_VALID_NSECT);
 
        tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES);
 
-       if (drive->quirk_list == 2)
+       if (drive->dev_flags & IDE_DFLAG_NIEN_QUIRK)
                tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
 
        error = __ide_wait_stat(drive, drive->ready_stat,
@@ -380,8 +387,6 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
 
        SELECT_MASK(drive, 0);
 
-       enable_irq(hwif->irq);
-
        if (error) {
                (void) ide_dump_status(drive, "set_drive_speed_status", stat);
                return error;