remove unused #include <version.h>'s
[safe/jmp/linux-2.6] / drivers / ide / ide-lib.c
index 7e053d2..9fc4cfb 100644 (file)
@@ -2,7 +2,6 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
-#include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/bitops.h>
 
@@ -75,142 +74,6 @@ static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
        return min(speed, mode);
 }
 
-/*
- * Standard (generic) timings for PIO modes, from ATA2 specification.
- * These timings are for access to the IDE data port register *only*.
- * Some drives may specify a mode, while also specifying a different
- * value for cycle_time (from drive identification data).
- */
-const ide_pio_timings_t ide_pio_timings[6] = {
-       { 70,   165,    600 },  /* PIO Mode 0 */
-       { 50,   125,    383 },  /* PIO Mode 1 */
-       { 30,   100,    240 },  /* PIO Mode 2 */
-       { 30,   80,     180 },  /* PIO Mode 3 with IORDY */
-       { 25,   70,     120 },  /* PIO Mode 4 with IORDY */
-       { 20,   50,     100 }   /* PIO Mode 5 with IORDY (nonstandard) */
-};
-
-EXPORT_SYMBOL_GPL(ide_pio_timings);
-
-/*
- * Shared data/functions for determining best PIO mode for an IDE drive.
- * Most of this stuff originally lived in cmd640.c, and changes to the
- * ide_pio_blacklist[] table should be made with EXTREME CAUTION to avoid
- * breaking the fragile cmd640.c support.
- */
-
-/*
- * Black list. Some drives incorrectly report their maximal PIO mode,
- * at least in respect to CMD640. Here we keep info on some known drives.
- */
-static struct ide_pio_info {
-       const char      *name;
-       int             pio;
-} ide_pio_blacklist [] = {
-       { "Conner Peripherals 540MB - CFS540A", 3 },
-
-       { "WDC AC2700",  3 },
-       { "WDC AC2540",  3 },
-       { "WDC AC2420",  3 },
-       { "WDC AC2340",  3 },
-       { "WDC AC2250",  0 },
-       { "WDC AC2200",  0 },
-       { "WDC AC21200", 4 },
-       { "WDC AC2120",  0 },
-       { "WDC AC2850",  3 },
-       { "WDC AC1270",  3 },
-       { "WDC AC1170",  1 },
-       { "WDC AC1210",  1 },
-       { "WDC AC280",   0 },
-       { "WDC AC31000", 3 },
-       { "WDC AC31200", 3 },
-
-       { "Maxtor 7131 AT", 1 },
-       { "Maxtor 7171 AT", 1 },
-       { "Maxtor 7213 AT", 1 },
-       { "Maxtor 7245 AT", 1 },
-       { "Maxtor 7345 AT", 1 },
-       { "Maxtor 7546 AT", 3 },
-       { "Maxtor 7540 AV", 3 },
-
-       { "SAMSUNG SHD-3121A", 1 },
-       { "SAMSUNG SHD-3122A", 1 },
-       { "SAMSUNG SHD-3172A", 1 },
-
-       { "ST5660A",  3 },
-       { "ST3660A",  3 },
-       { "ST3630A",  3 },
-       { "ST3655A",  3 },
-       { "ST3391A",  3 },
-       { "ST3390A",  1 },
-       { "ST3600A",  1 },
-       { "ST3290A",  0 },
-       { "ST3144A",  0 },
-       { "ST3491A",  1 },      /* reports 3, should be 1 or 2 (depending on */ 
-                               /* drive) according to Seagates FIND-ATA program */
-
-       { "QUANTUM ELS127A", 0 },
-       { "QUANTUM ELS170A", 0 },
-       { "QUANTUM LPS240A", 0 },
-       { "QUANTUM LPS210A", 3 },
-       { "QUANTUM LPS270A", 3 },
-       { "QUANTUM LPS365A", 3 },
-       { "QUANTUM LPS540A", 3 },
-       { "QUANTUM LIGHTNING 540A", 3 },
-       { "QUANTUM LIGHTNING 730A", 3 },
-
-        { "QUANTUM FIREBALL_540", 3 }, /* Older Quantum Fireballs don't work */
-        { "QUANTUM FIREBALL_640", 3 }, 
-        { "QUANTUM FIREBALL_1080", 3 },
-        { "QUANTUM FIREBALL_1280", 3 },
-       { NULL, 0 }
-};
-
-/**
- *     ide_scan_pio_blacklist  -       check for a blacklisted drive
- *     @model: Drive model string
- *
- *     This routine searches the ide_pio_blacklist for an entry
- *     matching the start/whole of the supplied model name.
- *
- *     Returns -1 if no match found.
- *     Otherwise returns the recommended PIO mode from ide_pio_blacklist[].
- */
-
-static int ide_scan_pio_blacklist (char *model)
-{
-       struct ide_pio_info *p;
-
-       for (p = ide_pio_blacklist; p->name != NULL; p++) {
-               if (strncmp(p->name, model, strlen(p->name)) == 0)
-                       return p->pio;
-       }
-       return -1;
-}
-
-unsigned int ide_pio_cycle_time(ide_drive_t *drive, u8 pio)
-{
-       struct hd_driveid *id = drive->id;
-       int cycle_time = 0;
-
-       if (id->field_valid & 2) {
-               if (id->capability & 8)
-                       cycle_time = id->eide_pio_iordy;
-               else
-                       cycle_time = id->eide_pio;
-       }
-
-       /* conservative "downgrade" for all pre-ATA2 drives */
-       if (pio < 3) {
-               if (cycle_time && cycle_time < ide_pio_timings[pio].cycle_time)
-                       cycle_time = 0; /* use standard timing */
-       }
-
-       return cycle_time ? cycle_time : ide_pio_timings[pio].cycle_time;
-}
-
-EXPORT_SYMBOL_GPL(ide_pio_cycle_time);
-
 /**
  *     ide_get_best_pio_mode   -       get PIO mode from drive
  *     @drive: drive to consider
@@ -226,29 +89,31 @@ EXPORT_SYMBOL_GPL(ide_pio_cycle_time);
 
 u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
 {
-       int pio_mode;
-       struct hd_driveid* id = drive->id;
-       int overridden  = 0;
+       u16 *id = drive->id;
+       int pio_mode = -1, overridden = 0;
 
        if (mode_wanted != 255)
                return min_t(u8, mode_wanted, max_mode);
 
-       if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0 &&
-           (pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
+       if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0)
+               pio_mode = ide_scan_pio_blacklist((char *)&id[ATA_ID_PROD]);
+
+       if (pio_mode != -1) {
                printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
        } else {
-               pio_mode = id->tPIO;
+               pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8;
                if (pio_mode > 2) {     /* 2 is maximum allowed tPIO value */
                        pio_mode = 2;
                        overridden = 1;
                }
-               if (id->field_valid & 2) {        /* drive implements ATA2? */
-                       if (id->capability & 8) { /* IORDY supported? */
-                               if (id->eide_pio_modes & 7) {
+
+               if (id[ATA_ID_FIELD_VALID] & 2) {             /* ATA2? */
+                       if (ata_id_has_iordy(id)) {
+                               if (id[ATA_ID_PIO_MODES] & 7) {
                                        overridden = 0;
-                                       if (id->eide_pio_modes & 4)
+                                       if (id[ATA_ID_PIO_MODES] & 4)
                                                pio_mode = 5;
-                                       else if (id->eide_pio_modes & 2)
+                                       else if (id[ATA_ID_PIO_MODES] & 2)
                                                pio_mode = 4;
                                        else
                                                pio_mode = 3;
@@ -402,22 +267,11 @@ int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
 
        rate = ide_rate_filter(drive, rate);
 
+       BUG_ON(rate < XFER_PIO_0);
+
        if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5)
                return ide_set_pio_mode(drive, rate);
 
-       /*
-        * TODO: transfer modes 0x00-0x07 passed from the user-space are
-        * currently handled here which needs fixing (please note that such
-        * case could happen iff the transfer mode has already been set on
-        * the device by ide-proc.c::set_xfer_rate()).
-        */
-       if (rate < XFER_PIO_0) {
-               if (hwif->host_flags & IDE_HFLAG_ABUSE_SET_DMA_MODE)
-                       return ide_set_dma_mode(drive, rate);
-               else
-                       return ide_config_drive_speed(drive, rate);
-       }
-
        return ide_set_dma_mode(drive, rate);
 }
 
@@ -463,7 +317,7 @@ static void ide_dump_sector(ide_drive_t *drive)
 {
        ide_task_t task;
        struct ide_taskfile *tf = &task.tf;
-       int lba48 = (drive->addressing == 1) ? 1 : 0;
+       u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
 
        memset(&task, 0, sizeof(task));
        if (lba48)
@@ -472,7 +326,7 @@ static void ide_dump_sector(ide_drive_t *drive)
        else
                task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
 
-       drive->hwif->tf_read(drive, &task);
+       drive->hwif->tp_ops->tf_read(drive, &task);
 
        if (lba48 || (tf->device & ATA_LBA))
                printk(", LBAsect=%llu",
@@ -485,16 +339,16 @@ static void ide_dump_sector(ide_drive_t *drive)
 static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
 {
        printk("{ ");
-       if (err & ABRT_ERR)     printk("DriveStatusError ");
-       if (err & ICRC_ERR)
-               printk((err & ABRT_ERR) ? "BadCRC " : "BadSector ");
-       if (err & ECC_ERR)      printk("UncorrectableError ");
-       if (err & ID_ERR)       printk("SectorIdNotFound ");
-       if (err & TRK0_ERR)     printk("TrackZeroNotFound ");
-       if (err & MARK_ERR)     printk("AddrMarkNotFound ");
+       if (err & ATA_ABORTED)  printk("DriveStatusError ");
+       if (err & ATA_ICRC)
+               printk((err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
+       if (err & ATA_UNC)      printk("UncorrectableError ");
+       if (err & ATA_IDNF)     printk("SectorIdNotFound ");
+       if (err & ATA_TRK0NF)   printk("TrackZeroNotFound ");
+       if (err & ATA_AMNF)     printk("AddrMarkNotFound ");
        printk("}");
-       if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR ||
-           (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
+       if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
+           (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
                ide_dump_sector(drive);
                if (HWGROUP(drive) && HWGROUP(drive)->rq)
                        printk(", sector=%llu",
@@ -506,12 +360,12 @@ static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
 static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
 {
        printk("{ ");
-       if (err & ILI_ERR)      printk("IllegalLengthIndication ");
-       if (err & EOM_ERR)      printk("EndOfMedia ");
-       if (err & ABRT_ERR)     printk("AbortedCommand ");
-       if (err & MCR_ERR)      printk("MediaChangeRequested ");
-       if (err & LFS_ERR)      printk("LastFailedSense=0x%02x ",
-                                      (err & LFS_ERR) >> 4);
+       if (err & ATAPI_ILI)    printk("IllegalLengthIndication ");
+       if (err & ATAPI_EOM)    printk("EndOfMedia ");
+       if (err & ATA_ABORTED)  printk("AbortedCommand ");
+       if (err & ATA_MCR)      printk("MediaChangeRequested ");
+       if (err & ATAPI_LFS)    printk("LastFailedSense=0x%02x ",
+                                      (err & ATAPI_LFS) >> 4);
        printk("}\n");
 }
 
@@ -533,19 +387,19 @@ u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
 
        local_irq_save(flags);
        printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
-       if (stat & BUSY_STAT)
+       if (stat & ATA_BUSY)
                printk("Busy ");
        else {
-               if (stat & READY_STAT)  printk("DriveReady ");
-               if (stat & WRERR_STAT)  printk("DeviceFault ");
-               if (stat & SEEK_STAT)   printk("SeekComplete ");
-               if (stat & DRQ_STAT)    printk("DataRequest ");
-               if (stat & ECC_STAT)    printk("CorrectedError ");
-               if (stat & INDEX_STAT)  printk("Index ");
-               if (stat & ERR_STAT)    printk("Error ");
+               if (stat & ATA_DRDY)    printk("DriveReady ");
+               if (stat & ATA_DF)      printk("DeviceFault ");
+               if (stat & ATA_DSC)     printk("SeekComplete ");
+               if (stat & ATA_DRQ)     printk("DataRequest ");
+               if (stat & ATA_CORR)    printk("CorrectedError ");
+               if (stat & ATA_IDX)     printk("Index ");
+               if (stat & ATA_ERR)     printk("Error ");
        }
        printk("}\n");
-       if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
+       if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
                err = ide_read_error(drive);
                printk("%s: %s: error=0x%02x ", drive->name, msg, err);
                if (drive->media == ide_disk)